[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aQ5VXORy6nQ9yfwF@Asurada-Nvidia>
Date: Fri, 7 Nov 2025 12:23:56 -0800
From: Nicolin Chen <nicolinc@...dia.com>
To: Jason Gunthorpe <jgg@...dia.com>
CC: <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 v4 3/7] iommu/arm-smmu-v3: Introduce a per-domain
arm_smmu_invs array
On Fri, Nov 07, 2025 at 03:41:58PM -0400, Jason Gunthorpe wrote:
> On Mon, Oct 27, 2025 at 11:54:17AM -0700, Nicolin Chen wrote:
> > +struct arm_smmu_invs *arm_smmu_invs_merge(struct arm_smmu_invs *invs,
> > + struct arm_smmu_invs *to_merge)
> > +{
> > + struct arm_smmu_invs *new_invs;
> > + struct arm_smmu_inv *new;
> > + size_t num_trashes = 0;
> > + size_t num_adds = 0;
> > + size_t i, j;
> > +
> > + for (i = j = 0; i != invs->num_invs || j != to_merge->num_invs;) {
> > + int cmp = arm_smmu_invs_cmp(invs, i, to_merge, j);
> > +
> > + /* Skip any unwanted trash entry */
> > + if (cmp < 0 && !refcount_read(&invs->inv[i].users)) {
>
> Do we need cmp < 0 here and in all these other similar ifs? Can't we
> just fully ignore trash entries no matter how they cmopare to the
> other list?
The index "i" might overflow in case of cmp > 1. So, if we don't
check cmp, we'd need to check "i != invs->num_invs" instead.
> If cmp ==0 and we do num_trash++ then the next iteration will see j
> ass cmp > 1 so it will do num_adds++ and the two will cancel out.
Yea, cmp == 0 should work with an additional iteration.
Perhaps we can do this:
+ int cmp;
+
+ /* Skip any trash entry */
+ if (i != invs->num_invs && !refcount_read(&invs->inv[i].users)) {
+ num_trashes++;
+ i++;
+ continue;
+ }
+
+ cmp = arm_smmu_invs_cmp(invs, i, to_merge, j);
And I will fix the other two places too.
Thanks
Nicolin
Powered by blists - more mailing lists