]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommu/arm-smmu-v3: Shrink the strtab l1_desc array
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 11 Jun 2024 00:31:11 +0000 (21:31 -0300)
committerWill Deacon <will@kernel.org>
Tue, 2 Jul 2024 15:34:16 +0000 (16:34 +0100)
The top of the 2 level stream table is (at most) 128k entries big, and two
high order allocations are required. One of __le64 which is programmed
into the HW (1M), and one of struct arm_smmu_strtab_l1_desc which holds
the CPU pointer (3M).

There is no reason to store the l2ptr_dma as nothing reads it. devm stores
a copy of it and the DMA memory will be freed via devm mechanisms. span is
a constant of 8+1. Remove both.

This removes 16 bytes from each arm_smmu_l1_ctx_desc and saves up to 2M of
memory per iommu instance.

Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Link: https://lore.kernel.org/r/2-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h

index bb2d9b0c0f6342eaadfd5b89f3f8b3c4e3692db7..fbb7eb152d82f458ea8b1c67405b6fa29f792c09 100644 (file)
@@ -1448,13 +1448,12 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master)
 }
 
 /* Stream table manipulation functions */
-static void
-arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc)
+static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma)
 {
        u64 val = 0;
 
-       val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, desc->span);
-       val |= desc->l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK;
+       val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, STRTAB_SPLIT + 1);
+       val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK;
 
        /* The HW has 64 bit atomicity with stores to the L2 STE table */
        WRITE_ONCE(*dst, cpu_to_le64(val));
@@ -1663,6 +1662,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid)
 {
        size_t size;
        void *strtab;
+       dma_addr_t l2ptr_dma;
        struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
        struct arm_smmu_strtab_l1_desc *desc = &cfg->l1_desc[sid >> STRTAB_SPLIT];
 
@@ -1672,8 +1672,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid)
        size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3);
        strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS];
 
-       desc->span = STRTAB_SPLIT + 1;
-       desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma,
+       desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma,
                                          GFP_KERNEL);
        if (!desc->l2ptr) {
                dev_err(smmu->dev,
@@ -1683,7 +1682,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid)
        }
 
        arm_smmu_init_initial_stes(desc->l2ptr, 1 << STRTAB_SPLIT);
-       arm_smmu_write_strtab_l1_desc(strtab, desc);
+       arm_smmu_write_strtab_l1_desc(strtab, l2ptr_dma);
        return 0;
 }
 
index 91ec2d49ecbf2e4c14d2ad9fe4d6b9727c6e94e1..a05e02d6afd1db56321b2dbe99f5b0c612b7de38 100644 (file)
@@ -579,10 +579,7 @@ struct arm_smmu_priq {
 
 /* High-level stream table and context descriptor structures */
 struct arm_smmu_strtab_l1_desc {
-       u8                              span;
-
        struct arm_smmu_ste             *l2ptr;
-       dma_addr_t                      l2ptr_dma;
 };
 
 struct arm_smmu_ctx_desc {