The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Shuai Xue <xueshuai@linux.alibaba.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"will@kernel.org" <will@kernel.org>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>,
	"jgg@ziepe.ca" <jgg@ziepe.ca>
Cc: "iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"oliver.yang@linux.alibaba.com" <oliver.yang@linux.alibaba.com>,
	"zhuo.song@linux.alibaba.com" <zhuo.song@linux.alibaba.com>
Subject: Re: [PATCH 1/4] iommu/sva: Set handle->dev before the SVA handle is visible
Date: Mon, 27 Jul 2026 18:14:57 +0800	[thread overview]
Message-ID: <5da226e5-4e84-4b9e-8f46-140323d22706@linux.alibaba.com> (raw)
In-Reply-To: <CO1PR11MB4835CBEA67280A7722E8DCA68CCC2@CO1PR11MB4835.namprd11.prod.outlook.com>



On 7/27/26 5:38 PM, Tian, Kevin wrote:
>> From: Shuai Xue <xueshuai@linux.alibaba.com>
>> Sent: Sunday, July 26, 2026 3:43 PM
>>
>> iommu_attach_device_pasid() installs the new SVA attach handle in the
>> group PASID lookup before iommu_sva_bind_device() returns. A concurrent
>> bind can therefore find and reuse the same handle after iommu_sva_lock is
>> dropped.
>>
>> handle->dev was initialized after dropping iommu_sva_lock. This leaves a
>> window where a racing bind can return a handle whose dev pointer is still
>> NULL. A subsequent iommu_sva_unbind_device() can then dereference it via
>> handle->dev->iommu_group.
> 
> ideally this will bail out early:
> 
>          mutex_lock(&iommu_sva_lock);
>          if (!refcount_dec_and_test(&handle->users)) {
>                  mutex_unlock(&iommu_sva_lock);
>                  return;
>          }
> 

Thanks Kevin for pointing this out.

Yes, the non-last reference case should bail out before using
handle->dev. I will wait a bit for other review comments and then decide
whether a v2 is needed to clarify the commit message.

>>
>> Initialize handle->dev before releasing iommu_sva_lock so any visible SVA
>> handle is fully initialized.
>>
>> Fixes: be51b1d6bbff ("iommu/sva: Refactoring
>> iommu_sva_bind/unbind_device()")
>> Cc: stable@vger.kernel.org
>> Assisted-by: Qoder:Qwen-3.8-MAX-Preview
>> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
> 
> but the fix is correct.
> 
> Reviewed-by: Kevin Tian <kevin.tian@intel.com>

Thanks for the review.

Best Regards,
Shuai

  reply	other threads:[~2026-07-27 10:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-26  7:43 [PATCH 0/4] iommu: Fix SVA, iommufd, and iommupt error paths Shuai Xue
2026-07-26  7:43 ` [PATCH 1/4] iommu/sva: Set handle->dev before the SVA handle is visible Shuai Xue
2026-07-27  9:38   ` Tian, Kevin
2026-07-27 10:14     ` Shuai Xue [this message]
2026-07-29  2:59   ` Baolu Lu
2026-07-26  7:43 ` [PATCH 2/4] iommufd: Avoid locking internal accesses during unmap Shuai Xue
2026-07-27  9:38   ` Tian, Kevin
2026-07-26  7:43 ` [PATCH 3/4] iommufd: Release current IOAS on xa_store() failure Shuai Xue
2026-07-27  9:39   ` Tian, Kevin
2026-07-26  7:43 ` [PATCH 4/4] iommupt: Return zero for invalid iova_to_phys() ranges Shuai Xue
2026-07-27  9:39   ` Tian, Kevin
2026-07-29  2:59   ` Baolu Lu
2026-08-07 22:45 ` [PATCH 0/4] iommu: Fix SVA, iommufd, and iommupt error paths Jason Gunthorpe
2026-08-10  7:52 ` Jörg Rödel

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=5da226e5-4e84-4b9e-8f46-140323d22706@linux.alibaba.com \
    --to=xueshuai@linux.alibaba.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=oliver.yang@linux.alibaba.com \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    --cc=zhuo.song@linux.alibaba.com \
    /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