lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251125130712.GP153257@nvidia.com>
Date: Tue, 25 Nov 2025 09:07:12 -0400
From: Jason Gunthorpe <jgg@...dia.com>
To: Nicolin Chen <nicolinc@...dia.com>
Cc: Will Deacon <will@...nel.org>, jean-philippe@...aro.org,
	robin.murphy@....com, joro@...tes.org, balbirs@...dia.com,
	miko.lenczewski@....com, peterz@...radead.org, kevin.tian@...el.com,
	praan@...gle.com, linux-arm-kernel@...ts.infradead.org,
	iommu@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 4/7] iommu/arm-smmu-v3: Pre-allocate a per-master
 invalidation array

On Mon, Nov 24, 2025 at 03:31:15PM -0800, Nicolin Chen wrote:
> > If you want to be conservative then the thing to do is sort the
> > master->streams that arm_smmu_insert_master() copies the fwspec
> > into. It just has to be sorted prior to feeding it into the rbtree.
> > 
> > Then consistently use master->streams as the sorted list.
> 
> How about kmemdup() an local id array to bridge betwen fwspec->ids
> and rbtree?

Not needed, just like this:

--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -3454,15 +3454,21 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,
        if (!master->streams)
                return -ENOMEM;
        master->num_streams = fwspec->num_ids;
-
-       mutex_lock(&smmu->streams_mutex);
        for (i = 0; i < fwspec->num_ids; i++) {
                struct arm_smmu_stream *new_stream = &master->streams[i];
-               struct rb_node *existing;
-               u32 sid = fwspec->ids[i];
 
-               new_stream->id = sid;
+               new_stream->id = fwspec->ids[i];
                new_stream->master = master;
+       }
+
+       sort_nonatomic(master->streams, master->num_streams,
+                      sizeof(master->streams[0]), arm_smmu_ids_cmp, NULL);
+
+       mutex_lock(&smmu->streams_mutex);
+       for (i = 0; i < master->num_streams; i++) {
+               struct arm_smmu_stream *new_stream = &master->streams[i];
+               struct rb_node *existing;
+               u32 sid = new_stream->id;
 
                ret = arm_smmu_init_sid_strtab(smmu, sid);
                if (ret)

cmp would work on a struct arm_smmu_stream.

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ