public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: baolu.lu@linux.intel.com, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Kevin Tian <kevin.tian@intel.com>,
	Huang Jiaqing <jiaqing.huang@intel.com>,
	Ethan Zhao <haifeng.zhao@linux.intel.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iommu/vt-d: Use rbtree to track iommu probed devices
Date: Sun, 18 Feb 2024 12:22:59 +0800	[thread overview]
Message-ID: <83010db4-d8f7-4ddd-a0dd-9d839ed32232@linux.intel.com> (raw)
In-Reply-To: <20240215174708.GC1299735@ziepe.ca>

On 2024/2/16 1:47, Jason Gunthorpe wrote:
> On Thu, Feb 15, 2024 at 03:22:48PM +0800, Lu Baolu wrote:
>> Use a red-black tree(rbtree) to track devices probed by the driver's
>> probe_device callback. These devices need to be looked up quickly by
>> a source ID when the hardware reports a fault, either recoverable or
>> unrecoverable.
>>
>> Fault reporting paths are critical. Searching a list in this scenario
>> is inefficient, with an algorithm complexity of O(n). An rbtree is a
>> self-balancing binary search tree, offering an average search time
>> complexity of O(log(n)). This significant performance improvement
>> makes rbtrees a better choice.
>>
>> Furthermore, rbtrees are implemented on a per-iommu basis, eliminating
>> the need for global searches and further enhancing efficiency in
>> critical fault paths. The rbtree is protected by a spin lock with
>> interrupts disabled to ensure thread-safe access even within interrupt
>> contexts.
>>
>> Co-developed-by: Huang Jiaqing<jiaqing.huang@intel.com>
>> Signed-off-by: Huang Jiaqing<jiaqing.huang@intel.com>
>> Signed-off-by: Lu Baolu<baolu.lu@linux.intel.com>
>> ---
>>   drivers/iommu/intel/iommu.h |  7 +++++
>>   drivers/iommu/intel/dmar.c  |  3 +-
>>   drivers/iommu/intel/iommu.c | 62 +++++++++++++++++++++++++++++++++++--
>>   3 files changed, 69 insertions(+), 3 deletions(-)
> Reviewed-by: Jason Gunthorpe<jgg@nvidia.com>
> 
>> +static int device_rbtree_insert(struct intel_iommu *iommu,
>> +				struct device_domain_info *info)
>> +{
>> +	struct rb_node *curr;
>> +	unsigned long flags;
>> +
>> +	spin_lock_irqsave(&iommu->device_rbtree_lock, flags);
>> +	curr = rb_find_add(&info->node, &iommu->device_rbtree, device_rid_cmp);
>> +	spin_unlock_irqrestore(&iommu->device_rbtree_lock, flags);
>> +	if (curr)
>> +		dev_warn(info->dev, "device already in rbtree\n");
> I would suggest
> 
> WARN_ON(curr);
> 
> Something has gone really wonky at this point, right?

Yes. This is not expected, and it is worth a WARN_ON().

Best regards,
baolu

  reply	other threads:[~2024-02-18  4:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15  7:22 [PATCH 0/2] iommu/vt-d: Introduce rbtree for probed devices Lu Baolu
2024-02-15  7:22 ` [PATCH 1/2] iommu/vt-d: Use rbtree to track iommu " Lu Baolu
2024-02-15 17:47   ` Jason Gunthorpe
2024-02-18  4:22     ` Baolu Lu [this message]
2024-02-19  2:45   ` Ethan Zhao
2024-02-19  4:04     ` Baolu Lu
2024-02-19  5:33       ` Ethan Zhao
2024-02-19  6:47         ` Baolu Lu
2024-02-19  7:24           ` Ethan Zhao
2024-02-15  7:22 ` [PATCH 2/2] iommu/vt-d: Use device rbtree in iopf reporting path Lu Baolu
2024-02-15 17:55   ` Jason Gunthorpe
2024-02-18  7:02     ` Baolu Lu
2024-02-21 15:31       ` Jason Gunthorpe
2024-02-21  7:04     ` Ethan Zhao
2024-02-21  7:37       ` Baolu Lu
2024-02-19  6:54   ` Ethan Zhao
2024-02-19  6:58     ` Baolu Lu
2024-02-19  7:06       ` Ethan Zhao
2024-02-19  7:22         ` 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=83010db4-d8f7-4ddd-a0dd-9d839ed32232@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=haifeng.zhao@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=jiaqing.huang@intel.com \
    --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