Re: [PATCH 1/3] iommu/vt-d: Use ida to manage domain id
From: Baolu Lu
Date: Thu Apr 24 2025 - 05:01:49 EST
On 4/24/2025 3:37 PM, Tian, Kevin wrote:
From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Sent: Wednesday, April 23, 2025 11:10 AM
static void free_dmar_iommu(struct intel_iommu *iommu)
{
- if (iommu->domain_ids) {
- bitmap_free(iommu->domain_ids);
- iommu->domain_ids = NULL;
- }
+ ida_destroy(&iommu->domain_ida);
since ida_init() is in alloc_iommu() now, the destroy can be
moved to free_iommu().
Sure.
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c
index e25e8d3dedcb..9e17e8e56308 100644
--- a/drivers/iommu/intel/dmar.c
+++ b/drivers/iommu/intel/dmar.c
@@ -1198,6 +1198,7 @@ static void free_iommu(struct intel_iommu *iommu)
if (iommu->reg)
unmap_iommu(iommu);
+ ida_destroy(&iommu->domain_ida);
ida_free(&dmar_seq_ids, iommu->seq_id);
kfree(iommu);
}
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index f784df122d7a..0002511c561f 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1304,8 +1304,6 @@ static void disable_dmar_iommu(struct intel_iommu
*iommu)
static void free_dmar_iommu(struct intel_iommu *iommu)
{
- ida_destroy(&iommu->domain_ida);
-
if (iommu->copied_tables) {
bitmap_free(iommu->copied_tables);
iommu->copied_tables = NULL;
@@ -1399,14 +1356,13 @@ int domain_attach_iommu(struct dmar_domain
*domain, struct intel_iommu *iommu)
return 0;
}
- ndomains = cap_ndoms(iommu->cap);
- num = find_first_zero_bit(iommu->domain_ids, ndomains);
- if (num >= ndomains) {
+ num = ida_alloc_range(&iommu->domain_ida, FLPT_DEFAULT_DID +
1,
+ cap_ndoms(iommu->cap) - 1, GFP_ATOMIC);
let's define a macro e.g. FIRST_DID for min.
Okay, how about IDA_START_DID?
Thanks,
baolu
Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>