public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sairaj Kodilkar <sarunkod@amd.com>
To: <joro@8bytes.org>, <suravee.suthikulpanit@amd.com>,
	<will@kernel.org>, <robin.murphy@arm.com>, <jgg@ziepe.ca>,
	<kevin.tian@intel.com>, <iommu@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>, <vasant.hegde@amd.com>
Cc: Sairaj Kodilkar <sarunkod@amd.com>
Subject: [RFC PATCH] iommu/amd: Add control register in `struct iommu_hw_info_amd`
Date: Wed, 29 Oct 2025 15:28:46 +0530	[thread overview]
Message-ID: <20251029095846.4486-1-sarunkod@amd.com> (raw)

When user does IOMMU_GET_HW_INFO ioctl, read the IOMMU control
register (MMIO offset 0x0018) and return it as part of
`struct iommu_hw_info_amd`.

Userspace can use this information to determine the features
supported by the underlying host kernel.

Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
---

The patch exposes the control register to the user space so that QEMU
can determine the list of features enabled by the host IOMMU driver
when there are passthrough devices. QEMU can use this information to
selectively enable the guest feature. One example of such feature is
enabling upto 2048 MSIs for passthrough devices. QEMU must not enable
this feature for passthrough devices when host IOMMU driver has not
enabled it.

The patch is based on top v6.17 (e5f0a698b34e) and patch [1] by Suravee

[1] https://lore.kernel.org/linux-iommu/20250926141901.511313-1-suravee.suthikulpanit@amd.com/

---

 drivers/iommu/amd/iommufd.c  | 3 +++
 include/uapi/linux/iommufd.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/iommu/amd/iommufd.c b/drivers/iommu/amd/iommufd.c
index 72eaaa923d04..83f34fc77ae8 100644
--- a/drivers/iommu/amd/iommufd.c
+++ b/drivers/iommu/amd/iommufd.c
@@ -12,6 +12,7 @@
 void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type)
 {
 	struct iommu_hw_info_amd *hwinfo;
+	struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
 
 	if (*type != IOMMU_HW_INFO_TYPE_DEFAULT &&
 	    *type != IOMMU_HW_INFO_TYPE_AMD)
@@ -26,6 +27,8 @@ void *amd_iommufd_hw_info(struct device *dev, u32 *length, u32 *type)
 
 	hwinfo->efr = amd_iommu_efr;
 	hwinfo->efr2 = amd_iommu_efr2;
+	hwinfo->control_register = readq(iommu->mmio_base
+					 + MMIO_CONTROL_OFFSET);
 
 	return hwinfo;
 }
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index efb52709c0a2..9435b2d877e7 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -637,6 +637,7 @@ struct iommu_hw_info_tegra241_cmdqv {
 struct iommu_hw_info_amd {
 	__aligned_u64 efr;
 	__aligned_u64 efr2;
+	__aligned_u64 control_register;
 };
 
 /**
-- 
2.34.1


             reply	other threads:[~2025-10-29  9:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29  9:58 Sairaj Kodilkar [this message]
2025-11-21 23:35 ` [RFC PATCH] iommu/amd: Add control register in `struct iommu_hw_info_amd` Jason Gunthorpe
2025-11-26  5:07   ` Sairaj Kodilkar

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=20251029095846.4486-1-sarunkod@amd.com \
    --to=sarunkod@amd.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=robin.murphy@arm.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@amd.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