public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Jason Gunthorpe <jgg@ziepe.ca>
Cc: baolu.lu@linux.intel.com,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] iommu/vt-d: Use ida to manage domain id
Date: Thu, 24 Apr 2025 17:01:35 +0800	[thread overview]
Message-ID: <4541dba3-1a4b-45f6-a607-fe2fe9a9f014@linux.intel.com> (raw)
In-Reply-To: <BN9PR11MB527656492CD69CA4EA0EC7338C852@BN9PR11MB5276.namprd11.prod.outlook.com>

On 4/24/2025 3:37 PM, Tian, Kevin wrote:
>> From: Lu Baolu <baolu.lu@linux.intel.com>
>> 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@intel.com>


  reply	other threads:[~2025-04-24  9:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23  3:10 [PATCH 0/3] iommu/vt-d: Use ida for domain ID management Lu Baolu
2025-04-23  3:10 ` [PATCH 1/3] iommu/vt-d: Use ida to manage domain id Lu Baolu
2025-04-24  7:37   ` Tian, Kevin
2025-04-24  9:01     ` Baolu Lu [this message]
2025-04-24  8:16   ` Baolu Lu
2025-04-23  3:10 ` [PATCH 2/3] iommu/vt-d: Replace spin_lock with mutex to protect domain ida Lu Baolu
2025-04-24  7:38   ` Tian, Kevin
2025-04-23  3:10 ` [PATCH 3/3] iommu/vt-d: Simplify domain_attach_iommu() Lu Baolu
2025-04-24  7:46   ` Tian, Kevin
2025-04-24  9:22     ` Baolu Lu
2025-04-24 13:37       ` Jason Gunthorpe
2025-04-24 14:47         ` Baolu Lu
2025-04-25 18:49   ` Dan Williams
2025-04-27  5:10     ` Baolu Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4541dba3-1a4b-45f6-a607-fe2fe9a9f014@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox