mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolin Chen <nicolinc@nvidia.com>
To: <jgg@nvidia.com>, <kevin.tian@intel.com>
Cc: <robin.murphy@arm.com>, <joro@8bytes.org>, <will@kernel.org>,
	<iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<shuah@kernel.org>, <linux-kselftest@vger.kernel.org>,
	<shyamsaini@linux.microsoft.com>
Subject: [PATCH v2 3/7] iommufd/device: Make iommufd_device_is_attached non-static
Date: Tue, 14 Oct 2025 17:29:35 -0700	[thread overview]
Message-ID: <dbe30ea6ba1122a96c515ab14c34eb98fdf5c6af.1760487869.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1760487869.git.nicolinc@nvidia.com>

A new SET_OPTION will reuse this helper for a sanity check before setting
a per-idev property.

Given that the attach handle can be NULL if device is not attached, add a
pointer check prior to the xa_load(). This is not a problem currently, as
the only caller iommufd_device_do_replace() verifies the attach handle.

Also, add lockdep_assert_held on igroup's mutex;

Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
 drivers/iommu/iommufd/iommufd_private.h | 1 +
 drivers/iommu/iommufd/device.c          | 7 ++++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index cc758610b9f7c..c458ab16736b6 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -502,6 +502,7 @@ iommufd_get_device(struct iommufd_ucmd *ucmd, u32 id)
 
 void iommufd_device_pre_destroy(struct iommufd_object *obj);
 void iommufd_device_destroy(struct iommufd_object *obj);
+bool iommufd_device_is_attached(struct iommufd_device *idev, ioasid_t pasid);
 int iommufd_get_hw_info(struct iommufd_ucmd *ucmd);
 
 struct iommufd_access {
diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
index 2a816533dc10e..45a1d1603c009 100644
--- a/drivers/iommu/iommufd/device.c
+++ b/drivers/iommu/iommufd/device.c
@@ -436,13 +436,14 @@ iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
 
 /* The device attach/detach/replace helpers for attach_handle */
 
-static bool iommufd_device_is_attached(struct iommufd_device *idev,
-				       ioasid_t pasid)
+bool iommufd_device_is_attached(struct iommufd_device *idev, ioasid_t pasid)
 {
 	struct iommufd_attach *attach;
 
+	lockdep_assert_held(&idev->igroup->lock);
+
 	attach = xa_load(&idev->igroup->pasid_attach, pasid);
-	return xa_load(&attach->device_array, idev->obj.id);
+	return attach && xa_load(&attach->device_array, idev->obj.id);
 }
 
 static int iommufd_hwpt_pasid_compat(struct iommufd_hw_pagetable *hwpt,
-- 
2.43.0


  parent reply	other threads:[~2025-10-15  0:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15  0:29 [PATCH v2 0/7] iommufd: Add MSI mapping support with nested SMMU (Part-2 RMR) Nicolin Chen
2025-10-15  0:29 ` [PATCH v2 1/7] iommufd/device: Move sw_msi_start from igroup to idev Nicolin Chen
2025-10-15  0:29 ` [PATCH v2 2/7] iommufd: Pass in idev to iopt_table_enforce_dev_resv_regions Nicolin Chen
2025-10-15  0:29 ` Nicolin Chen [this message]
2025-10-15  0:29 ` [PATCH v2 4/7] iommufd: Add IOMMU_OPTION_SW_MSI_START/SIZE ioctls Nicolin Chen
2025-10-15 11:58   ` kernel test robot
2025-10-15 17:20   ` Nicolin Chen
2025-10-15  0:29 ` [PATCH v2 5/7] iommufd/selftest: Add MOCK_FLAGS_DEVICE_NO_ATTACH Nicolin Chen
2025-10-15  0:29 ` [PATCH v2 6/7] iommufd/selftest: Add a testing reserved region Nicolin Chen
2025-10-15  0:29 ` [PATCH v2 7/7] iommufd/selftest: Add coverage for IOMMU_OPTION_SW_MSI_START/SIZE Nicolin Chen

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=dbe30ea6ba1122a96c515ab14c34eb98fdf5c6af.1760487869.git.nicolinc@nvidia.com \
    --to=nicolinc@nvidia.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=shuah@kernel.org \
    --cc=shyamsaini@linux.microsoft.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

all inboxes | Powered by JetHome®