Skip to content

Commit 0299a1a

Browse files
jpbruckerwilldeacon
authored andcommitted
iommu/arm-smmu-v3: Manage ASIDs with xarray
In preparation for sharing some ASIDs with the CPU, use a global xarray to store ASIDs and their context. ASID#0 is now reserved, and the ASID space is global. Signed-off-by: Jean-Philippe Brucker <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 52f3fab commit 0299a1a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

drivers/iommu/arm-smmu-v3.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ struct arm_smmu_device {
667667

668668
#define ARM_SMMU_MAX_ASIDS (1 << 16)
669669
unsigned int asid_bits;
670-
DECLARE_BITMAP(asid_map, ARM_SMMU_MAX_ASIDS);
671670

672671
#define ARM_SMMU_MAX_VMIDS (1 << 16)
673672
unsigned int vmid_bits;
@@ -727,6 +726,8 @@ struct arm_smmu_option_prop {
727726
const char *prop;
728727
};
729728

729+
static DEFINE_XARRAY_ALLOC1(asid_xa);
730+
730731
static struct arm_smmu_option_prop arm_smmu_options[] = {
731732
{ ARM_SMMU_OPT_SKIP_PREFETCH, "hisilicon,broken-prefetch-cmd" },
732733
{ ARM_SMMU_OPT_PAGE0_REGS_ONLY, "cavium,cn9900-broken-page1-regspace"},
@@ -1765,6 +1766,14 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain)
17651766
cdcfg->cdtab = NULL;
17661767
}
17671768

1769+
static void arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd)
1770+
{
1771+
if (!cd->asid)
1772+
return;
1773+
1774+
xa_erase(&asid_xa, cd->asid);
1775+
}
1776+
17681777
/* Stream table manipulation functions */
17691778
static void
17701779
arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc)
@@ -2450,10 +2459,9 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
24502459
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
24512460
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
24522461

2453-
if (cfg->cdcfg.cdtab) {
2462+
if (cfg->cdcfg.cdtab)
24542463
arm_smmu_free_cd_tables(smmu_domain);
2455-
arm_smmu_bitmap_free(smmu->asid_map, cfg->cd.asid);
2456-
}
2464+
arm_smmu_free_asid(&cfg->cd);
24572465
} else {
24582466
struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg;
24592467
if (cfg->vmid)
@@ -2468,14 +2476,15 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
24682476
struct io_pgtable_cfg *pgtbl_cfg)
24692477
{
24702478
int ret;
2471-
int asid;
2479+
u32 asid;
24722480
struct arm_smmu_device *smmu = smmu_domain->smmu;
24732481
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
24742482
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
24752483

2476-
asid = arm_smmu_bitmap_alloc(smmu->asid_map, smmu->asid_bits);
2477-
if (asid < 0)
2478-
return asid;
2484+
ret = xa_alloc(&asid_xa, &asid, &cfg->cd,
2485+
XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL);
2486+
if (ret)
2487+
return ret;
24792488

24802489
cfg->s1cdmax = master->ssid_bits;
24812490

@@ -2508,7 +2517,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
25082517
out_free_cd_tables:
25092518
arm_smmu_free_cd_tables(smmu_domain);
25102519
out_free_asid:
2511-
arm_smmu_bitmap_free(smmu->asid_map, asid);
2520+
arm_smmu_free_asid(&cfg->cd);
25122521
return ret;
25132522
}
25142523

0 commit comments

Comments
 (0)