[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <83010db4-d8f7-4ddd-a0dd-9d839ed32232@linux.intel.com>
Date: Sun, 18 Feb 2024 12:22:59 +0800
From: Baolu Lu <baolu.lu@...ux.intel.com>
To: Jason Gunthorpe <jgg@...pe.ca>
Cc: baolu.lu@...ux.intel.com, Joerg Roedel <joro@...tes.org>,
Will Deacon <will@...nel.org>, Robin Murphy <robin.murphy@....com>,
Kevin Tian <kevin.tian@...el.com>, Huang Jiaqing <jiaqing.huang@...el.com>,
Ethan Zhao <haifeng.zhao@...ux.intel.com>, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] iommu/vt-d: Use rbtree to track iommu probed devices
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@...el.com>
>> Signed-off-by: Huang Jiaqing<jiaqing.huang@...el.com>
>> Signed-off-by: Lu Baolu<baolu.lu@...ux.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@...dia.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
Powered by blists - more mailing lists