iommu/amd: Add support for hw_info for iommu capability query
Subsystems (3)
Suravee Suthikulpanit
reviewerPATCH v4 1/1 iommu/amd: Add support for hw_info for iommu capability query
AMD IOMMU Extended Feature (EFR) and Extended Feature 2 (EFR2) registers specify features supported by each IOMMU hardware instance. The IOMMU driver checks each feature-specific bits before enabling each feature at run time.
For IOMMUFD, the hypervisor passes the raw value of amd_iommu_efr and amd_iommu_efr2 to VMM via iommufd IOMMU_DEVICE_GET_HW_INFO ioctl.
---
Change in v4:
* Add CONFIG_AMD_IOMMU_IOMMUFD
* Update comment regarding EFR/EFR2 from struct iommu_hw_info_amd.
Change in v3:
* Remove extern
* Fix link to IOMMU spec
* Update kdoc
Change in v2:
* Do not mask the EFR/EFR2 and simply return the value reported by hardware
* Move amd_iommufd_hw_info() to drivers/iommu/amd/iommufd.c
* Also support IOMMU_HW_INFO_TYPE_DEFAULT
drivers/iommu/amd/Kconfig | 10 ++++++++++ drivers/iommu/amd/Makefile | 1 + drivers/iommu/amd/iommu.c | 2 ++ drivers/iommu/amd/iommufd.c | 31 +++++++++++++++++++++++++++++++ drivers/iommu/amd/iommufd.h | 15 +++++++++++++++ include/uapi/linux/iommufd.h | 28 ++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 drivers/iommu/amd/iommufd.c create mode 100644 drivers/iommu/amd/iommufd.h
drivers/iommu/amd/Kconfig +10 -0
@@ -27,6 +27,16 @@ config AMD_IOMMU your BIOS for an option to enable it or if you have an IVRS ACPI table. +config AMD_IOMMU_IOMMUFD + bool "Enable IOMMUFD features for AMD IOMMU (EXPERIMENTAL)" + depends on IOMMUFD + depends on AMD_IOMMU + help + Support for IOMMUFD features intended to support virtual machines + with accelerated virtual IOMMUs. + + Say Y here if you are doing development and testing on this feature. + config AMD_IOMMU_DEBUGFS bool "Enable AMD IOMMU internals in DebugFS" depends on AMD_IOMMU && IOMMU_DEBUGFS
drivers/iommu/amd/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += iommu.o init.o quirks.o io_pgtable.o io_pgtable_v2.o ppr.o pasid.o +obj-$(CONFIG_AMD_IOMMU_IOMMUFD) += iommufd.o obj-$(CONFIG_AMD_IOMMU_DEBUGFS) += debugfs.o
drivers/iommu/amd/iommu.c +2 -0
@@ -42,6 +42,7 @@#include <uapi/linux/iommufd.h> #include "amd_iommu.h" +#include "iommufd.h" #include "../dma-iommu.h" #include "../irq_remapping.h" #include "../iommu-pages.h"
@@ -3040,6 +3041,7 @@ static const struct iommu_dirty_ops amd_dirty_ops = {const struct iommu_ops amd_iommu_ops = { .capable = amd_iommu_capable, + .hw_info = amd_iommufd_hw_info, .blocked_domain = &blocked_domain, .release_domain = &release_domain, .identity_domain = &identity_domain.domain,
drivers/iommu/amd/iommufd.c new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. +*/ + +#include <linux/iommu.h> + +#include "iommufd.h" +#include "amd_iommu.h" +#include "amd_iommu_types.h" + +void *amd_iommufd_hw_info (struct device *dev,u32 *length,u32 *type) +{ +struct iommu_hw_info_amd *hwinfo; + +if (*type !=IOMMU_HW_INFO_TYPE_DEFAULT && + *type !=IOMMU_HW_INFO_TYPE_AMD ) +return ERR_PTR (-EOPNOTSUPP ); + + hwinfo =kzalloc (sizeof (*hwinfo),GFP_KERNEL ); +if (!hwinfo) +return ERR_PTR (-ENOMEM ); + + *length =sizeof (*hwinfo); + *type =IOMMU_HW_INFO_TYPE_AMD ; + + hwinfo->efr = amd_iommu_efr; + hwinfo->efr2 = amd_iommu_efr2; + +return hwinfo; +}
drivers/iommu/amd/iommufd.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. +*/ + +#ifndef AMD_IOMMUFD_H +#define AMD_IOMMUFD_H + +#if IS_ENABLED (CONFIG_IOMMUFD ) +void *amd_iommufd_hw_info (struct device *dev,u32 *length,u32 *type); +#else +#define amd_iommufd_hw_info NULL +#endif + +#endif /* AMD_IOMMUFD_H */
include/uapi/linux/iommufd.h +28 -0
@@ -613,6 +613,32 @@ struct iommu_hw_info_tegra241_cmdqv {__u8 __reserved; }; +/** +* struct iommu_hw_info_amd - AMD IOMMU device info +* +* @efr : Value of AMD IOMMU Extended Feature Register (EFR) +* @efr2: Value of AMD IOMMU Extended Feature 2 Register (EFR2) +* +* Please See description of these registers in the following sections of +* the AMD I/O Virtualization Technology (IOMMU) Specification. +* (https://docs.amd.com/v/u/en-US/48882_3.10_PUB) +* +* - MMIO Offset 0030h IOMMU Extended Feature Register +* - MMIO Offset 01A0h IOMMU Extended Feature 2 Register +* +* Note: The EFR and EFR2 are raw values reported by hardware. +* VMM is responsible to determine the appropriate flags to be exposed to +* the VM since cetertain features are not currently supported by the kernel +* for HW-vIOMMU. +* +* Current VMM-allowed list of feature flags are: +* - EFR[GTSup, GASup, GioSup, PPRSup, EPHSup, GATS, GLX, PASmax] +*/ +struct iommu_hw_info_amd { +__aligned_u64 efr; +__aligned_u64 efr2; +}; +/** * enum iommu_hw_info_type - IOMMU Hardware Info Types * @IOMMU_HW_INFO_TYPE_NONE: Output by the drivers that do not report hardware
@@ -622,6 +648,7 @@ struct iommu_hw_info_tegra241_cmdqv {* @IOMMU_HW_INFO_TYPE_ARM_SMMUV3: ARM SMMUv3 iommu info type * @IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV: NVIDIA Tegra241 CMDQV (extension for ARM * SMMUv3) info type +* @IOMMU_HW_INFO_TYPE_AMD: AMD IOMMU info type */ enum iommu_hw_info_type {IOMMU_HW_INFO_TYPE_NONE =0 ,
@@ -629,6 +656,7 @@ enum iommu_hw_info_type {IOMMU_HW_INFO_TYPE_INTEL_VTD =1 ,IOMMU_HW_INFO_TYPE_ARM_SMMUV3 =2 ,IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV =3 , + IOMMU_HW_INFO_TYPE_AMD = 4, };/**
Signature · 1 line
2.34.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Suravee,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.17-rc5 next-20250908]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Suravee-Suthikulpanit/iommu-amd-Add-support-for-hw_info-for-iommu-capability-query/20250905-033352 base: linus/master patch link: https://lore.kernel.org/r/20250904193112.7418-1-suravee.suthikulpanit%40amd.com patch subject: [PATCH v4] iommu/amd: Add support for hw_info for iommu capability query config: x86_64-rhel-9.4-func (https://download.01.org/0day-ci/archive/20250909/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250909/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> ld: drivers/iommu/amd/iommu.o:(.rodata+0x25a8): undefined reference to `amd_iommufd_hw_info'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 11 lines · Suravee Suthikulpanit
AMD IOMMU Extended Feature (EFR) and Extended Feature 2 (EFR2) registers specify features supported by each IOMMU hardware instance. The IOMMU driver checks each feature-specific bits before enabling each feature at run time.
For IOMMUFD, the hypervisor passes the raw value of
amd_iommu_efrandamd_iommu_efr2to VMM via iommufdIOMMU_DEVICE_GET_HW_INFOioctl.Reviewed-by Nicolin Chen <[email protected]>Signed-off-by Suravee Suthikulpanit <[email protected]>---
.../...
Quoted 43 lines
drivers/iommu/amd/iommufd.c new file +31
-0@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. +*/ + +#include <linux/iommu.h> + +#include "iommufd.h" +#include "amd_iommu.h" +#include "amd_iommu_types.h" + +void *amd_iommufd_hw_info (struct device *dev,u32 *length,u32 *type) +{ +struct iommu_hw_info_amd *hwinfo; + +if (*type !=IOMMU_HW_INFO_TYPE_DEFAULT && + *type !=IOMMU_HW_INFO_TYPE_AMD ) +return ERR_PTR (-EOPNOTSUPP ); + + hwinfo =kzalloc (sizeof (*hwinfo),GFP_KERNEL ); +if (!hwinfo) +return ERR_PTR (-ENOMEM ); + + *length =sizeof (*hwinfo); + *type =IOMMU_HW_INFO_TYPE_AMD ; + + hwinfo->efr = amd_iommu_efr; + hwinfo->efr2 = amd_iommu_efr2; + +return hwinfo; +}drivers/iommu/amd/iommufd.h new file +0
-0
drivers/iommu/amd/iommufd.h line 9
Quoted 9 lines
drivers/iommu/amd/iommufd.h new file +9
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. +*/ + +#ifndef AMD_IOMMUFD_H +#define AMD_IOMMUFD_H + +#if IS_ENABLED (CONFIG_IOMMUFD )
It should be CONFIG_AMD_IOMMU_IOMMUFD
Otherwise patch looks good to me.
-Vasant
Quoted 25 lines · Suravee Suthikulpanit
AMD IOMMU Extended Feature (EFR) and Extended Feature 2 (EFR2) registers specify features supported by each IOMMU hardware instance. The IOMMU driver checks each feature-specific bits before enabling each feature at run time.
For IOMMUFD, the hypervisor passes the raw value of
amd_iommu_efrandamd_iommu_efr2to VMM via iommufdIOMMU_DEVICE_GET_HW_INFOioctl.Reviewed-by Nicolin Chen <[email protected]>Signed-off-by Suravee Suthikulpanit <[email protected]>---
Change in v4:
* AddCONFIG_AMD_IOMMU_IOMMUFD
* Update comment regarding EFR/EFR2 from structiommu_hw_info_amd.Change in v3:
* Remove extern
* Fix link to IOMMU spec
* Update kdocChange in v2:
* Do not mask the EFR/EFR2 and simply return the value reported by hardware
* Moveamd_iommufd_hw_info()todrivers/iommu/amd/iommufd.c
* Also supportIOMMU_HW_INFO_TYPE_DEFAULT
Quoted 9 lines
drivers/iommu/amd/Kconfig | 10 ++++++++++ drivers/iommu/amd/Makefile | 1 + drivers/iommu/amd/iommu.c | 2 ++ drivers/iommu/amd/iommufd.c | 31 +++++++++++++++++++++++++++++++ drivers/iommu/amd/iommufd.h | 15 +++++++++++++++ include/uapi/linux/iommufd.h | 28 ++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 drivers/iommu/amd/iommufd.c create mode 100644 drivers/iommu/amd/iommufd.h
There was a kbuild issue so this needs to be resent, but
Jason