Skip to contentSkip to conversation

Make x86 IOMMU driver support configurable

PATCH Superseded Xenia Ragiadakou 3 participants 33 messages Jan 4, 2023 – Jan 13, 2023

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Make x86 IOMMU driver support configurable

This series aims to provide a means to render the iommu driver support for x86 configurable. Currently, irrespectively of the target platform, both AMD and Intel iommu drivers are built. This is the case because the existent Kconfig infrastructure does not provide any facilities for finer-grained configuration.

The series adds two new Kconfig options, AMD_IOMMU and INTEL_IOMMU, that can be used to generate a tailored iommu configuration for a given platform.

This version of the series addresses the initial comments made in the RFC version to facilitate further review of the parts that need more feedback.

Xenia Ragiadakou (8):
x86/iommu: introduce AMD-Vi and Intel VT-d Kconfig options x86/iommu: amd_iommu_perdev_intremap is AMD-Vi specific x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific x86/acpi: separate AMD-Vi and VT-d specific functions x86/iommu: the code addressing CVE-2011-1898 is VT-d specific x86/iommu: call pi_update_irte through an hvm_function callback x86/dpci: move hvm_dpci_isairq_eoi() to generic HVM code x86/iommu: make AMD-Vi and Intel VT-d support configurable

 xen/arch/x86/hvm/vmx/vmx.c               | 10 ++++
 xen/arch/x86/include/asm/acpi.h          | 14 ++++++
 xen/arch/x86/include/asm/hvm/hvm.h       | 15 ++++++
 xen/arch/x86/include/asm/hvm/vmx/vmx.h   | 11 ++++
 xen/arch/x86/include/asm/iommu.h         |  5 +-
 xen/arch/x86/pv/hypercall.c              |  2 +
 xen/arch/x86/x86_64/entry.S              |  2 +
 xen/drivers/passthrough/Kconfig          | 24 +++++++++
 xen/drivers/passthrough/Makefile         |  4 +-
 xen/drivers/passthrough/amd/iommu_init.c |  2 +
 xen/drivers/passthrough/iommu.c          |  9 +++-
 xen/drivers/passthrough/vtd/x86/Makefile |  1 -
 xen/drivers/passthrough/vtd/x86/hvm.c    | 64 ------------------------
 xen/drivers/passthrough/x86/hvm.c        | 48 ++++++++++++++++--
 xen/include/xen/acpi.h                   |  3 --
 xen/include/xen/iommu.h                  |  7 ++-
 16 files changed, 141 insertions(+), 80 deletions(-)
 delete mode 100644 xen/drivers/passthrough/vtd/x86/hvm.c
Signature · 1 line
2.37.2
#1 lore raw

PATCH v2 1/8 x86/iommu: introduce AMD-Vi and Intel VT-d Kconfig options

Introduce two new Kconfig options, AMD_IOMMU and INTEL_IOMMU, to allow code specific to each IOMMU technology to be separated and, when not required, stripped. AMD_IOMMU will be used to enable IOMMU support for platforms that implement the AMD I/O Virtualization Technology. INTEL_IOMMU will be used to enable IOMMU support for platforms that implement the Intel Virtualization Technology for Directed I/O.

Since, at this point, disabling any of them would cause Xen to not compile, the options are not visible to the user and are enabled by default if X86.

---

Changes in v2:
- just introduce the new options but not make them selectable by the user
- adjust commit message
- replace CONFIG_INTEL_VTD with CONFIG_INTEL_IOMMU

 xen/drivers/passthrough/Kconfig  | 6 ++++++
 xen/drivers/passthrough/Makefile | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)
xen/drivers/passthrough/Kconfig +6 -0
index 479d7de57a..5c65567744 100644
@@ -37,6 +37,12 @@ config IPMMU_VMSA
 
 endif
 
+config AMD_IOMMU
+	def_bool y if X86
+
+config INTEL_IOMMU
+	def_bool y if X86
+
 config IOMMU_FORCE_PT_SHARE
 	bool
 
xen/drivers/passthrough/Makefile +2 -2
index a5efa22714..a1621540b7 100644
@@ -1,5 +1,5 @@
-obj-$(CONFIG_X86) += vtd/
-obj-$(CONFIG_X86) += amd/
+obj-$(CONFIG_INTEL_IOMMU) += vtd/
+obj-$(CONFIG_AMD_IOMMU) += amd/
 obj-$(CONFIG_X86) += x86/
 obj-$(CONFIG_ARM) += arm/
 
Signature · 1 line
2.37.2
Reviewed-by on v2 1/8
#2 lore raw

Re: [PATCH v2 1/8] x86/iommu: introduce AMD-Vi and Intel VT-d Kconfig options

Quoted 11 lines · Xenia Ragiadakou

Introduce two new Kconfig options, AMD_IOMMU and INTEL_IOMMU, to allow code specific to each IOMMU technology to be separated and, when not required, stripped. AMD_IOMMU will be used to enable IOMMU support for platforms that implement the AMD I/O Virtualization Technology. INTEL_IOMMU will be used to enable IOMMU support for platforms that implement the Intel Virtualization Technology for Directed I/O.

Since, at this point, disabling any of them would cause Xen to not compile, the options are not visible to the user and are enabled by default if X86.

#3 lore raw

PATCH v2 2/8 x86/iommu: amd_iommu_perdev_intremap is AMD-Vi specific

In reply to Xenia Ragiadakou

Move its definition to the AMD-Vi driver and use CONFIG_AMD_IOMMU to guard its usage in common code.

Take the opportunity to replace bool_t with bool, __read_mostly with __ro_after_init and 1 with true.

No functional change intended.

---

Changes in v2:
- declare amd_iommu_perdev_intremap __ro_after_init
- use no_config_param() to print a warning when the user sets an AMD_IOMMU specific string in the iommu boot parameter and AMD_IOMMU is disabled
- remove the #ifdef CONFIG_AMD_IOMMU guard from the declaration of amd_iommu_perdev_intremap in xen/iommu.h

 xen/drivers/passthrough/amd/iommu_init.c | 2 ++
 xen/drivers/passthrough/iommu.c          | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
xen/drivers/passthrough/amd/iommu_init.c +2 -0
index 1f14aaf49e..9773ccfcb4 100644
@@ -36,6 +36,8 @@ static struct radix_tree_root ivrs_maps;
 LIST_HEAD_READ_MOSTLY(amd_iommu_head);
 bool_t iommuv2_enabled;
 
+bool __ro_after_init amd_iommu_perdev_intremap = true;
+
 static bool iommu_has_ht_flag(struct amd_iommu *iommu, u8 mask)
 {
     return iommu->ht_flags & mask;
xen/drivers/passthrough/iommu.c +4 -1
index 5e2a720d29..998dfaf20d 100644
@@ -58,7 +58,6 @@ bool __read_mostly iommu_hap_pt_share = true;
 #endif
 
 bool_t __read_mostly iommu_debug;
-bool_t __read_mostly amd_iommu_perdev_intremap = 1;
 
 DEFINE_PER_CPU(bool_t, iommu_dont_flush_iotlb);
 
@@ -116,7 +115,11 @@ static int __init cf_check parse_iommu_param(const char *s)
                 iommu_verbose = 1;
         }
         else if ( (val = parse_boolean("amd-iommu-perdev-intremap", s, ss)) >= 0 )
+#ifdef CONFIG_AMD_IOMMU
             amd_iommu_perdev_intremap = val;
+#else
+            no_config_param("AMD_IOMMU", "amd-iommu-perdev-intremap", s, ss);
+#endif
         else if ( (val = parse_boolean("dom0-passthrough", s, ss)) >= 0 )
             iommu_hwdom_passthrough = val;
         else if ( (val = parse_boolean("dom0-strict", s, ss)) >= 0 )
Signature · 1 line
2.37.2
#4 lore raw

Re: [PATCH v2 2/8] x86/iommu: amd_iommu_perdev_intremap is AMD-Vi specific

xen/drivers/passthrough/iommu.c static int __init cf_check parse_iommu_param(const char *s) · line 121

Quoted 8 lines · Xenia Ragiadakou
xen/drivers/passthrough/iommu.c +3 -0
@@ -116,7 +115,11 @@ static int __init cf_check parse_iommu_param(const char *s)
                 iommu_verbose = 1;
         }
         else if ( (val = parse_boolean("amd-iommu-perdev-intremap", s, ss)) >= 0 )
+#ifdef CONFIG_AMD_IOMMU
             amd_iommu_perdev_intremap = val;
+#else
+            no_config_param("AMD_IOMMU", "amd-iommu-perdev-intremap", s, ss);

The string literal wants to be "iommu", I think. Please see other uses of no_config_param().

Jan

#5 lore raw

Re: [PATCH v2 2/8] x86/iommu: amd_iommu_perdev_intremap is AMD-Vi specific

Quoted 12 lines · Jan Beulich

xen/drivers/passthrough/iommu.c static int __init cf_check parse_iommu_param(const char *s) · line 121

Quoted 8 lines · Xenia Ragiadakou
xen/drivers/passthrough/iommu.c +3 -0
@@ -116,7 +115,11 @@ static int __init cf_check parse_iommu_param(const char *s)
                  iommu_verbose = 1;
          }
          else if ( (val = parse_boolean("amd-iommu-perdev-intremap", s, ss)) >= 0 )
+#ifdef CONFIG_AMD_IOMMU
              amd_iommu_perdev_intremap = val;
+#else
+            no_config_param("AMD_IOMMU", "amd-iommu-perdev-intremap", s, ss);

The string literal wants to be "iommu", I think. Please see other uses of no_config_param().

Thanks for reviewing this. You are right. I will fix it.

Signature · 1 line
Xenia
#6 lore raw

PATCH v2 3/8 x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

In reply to Xenia Ragiadakou

Use CONFIG_INTEL_IOMMU to guard their usage in common code.

No functional change intended.

---

Changes in v2:
- replace CONFIG_INTEL_VTD with CONFIG_INTEL_IOMMU

 xen/drivers/passthrough/iommu.c | 4 +++-
 xen/include/xen/iommu.h         | 6 +++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
xen/drivers/passthrough/iommu.c +3 -1
index 998dfaf20d..a2c67a17cd 100644
@@ -82,11 +82,13 @@ static int __init cf_check parse_iommu_param(const char *s)
         else if ( ss == s + 23 && !strncmp(s, "quarantine=scratch-page", 23) )
             iommu_quarantine = IOMMU_quarantine_scratch_page;
 #endif
-#ifdef CONFIG_X86
+#ifdef CONFIG_INTEL_IOMMU
         else if ( (val = parse_boolean("igfx", s, ss)) >= 0 )
             iommu_igfx = val;
         else if ( (val = parse_boolean("qinval", s, ss)) >= 0 )
             iommu_qinval = val;
+#endif
+#ifdef CONFIG_X86
         else if ( (val = parse_boolean("superpages", s, ss)) >= 0 )
             iommu_superpages = val;
 #endif
xen/include/xen/iommu.h +5 -1
index 4f22fc1bed..aa924541d5 100644
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
    iommu_intremap_restricted,
    iommu_intremap_full,
 } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
 #else
 # define iommu_intremap false
+#endif
+
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
 # define iommu_snoop false
 #endif
 
Signature · 1 line
2.37.2
#7 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

xen/drivers/passthrough/iommu.c static int __init cf_check parse_iommu_param(const char *s) · line 90

Quoted 13 lines · Xenia Ragiadakou
xen/drivers/passthrough/iommu.c +2 -1
@@ -82,11 +82,13 @@ static int __init cf_check parse_iommu_param(const char *s)
         else if ( ss == s + 23 && !strncmp(s, "quarantine=scratch-page", 23) )
             iommu_quarantine = IOMMU_quarantine_scratch_page;
 #endif
-#ifdef CONFIG_X86
+#ifdef CONFIG_INTEL_IOMMU
         else if ( (val = parse_boolean("igfx", s, ss)) >= 0 )
             iommu_igfx = val;
         else if ( (val = parse_boolean("qinval", s, ss)) >= 0 )
             iommu_qinval = val;
+#endif

You want to use no_config_param() here as well then.

Quoted 6 lines
xen/include/xen/iommu.h +0 -0
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
    iommu_intremap_restricted,
    iommu_intremap_full,
 } iommu_intremap;

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 10 lines
xen/include/xen/iommu.h +5 -1
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
 #else
 # define iommu_intremap false
+#endif
+
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
 # define iommu_snoop false
 #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Jan

#8 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

Quoted 16 lines · Jan Beulich

xen/drivers/passthrough/iommu.c static int __init cf_check parse_iommu_param(const char *s) · line 90

Quoted 13 lines · Xenia Ragiadakou
xen/drivers/passthrough/iommu.c +2 -1
@@ -82,11 +82,13 @@ static int __init cf_check parse_iommu_param(const char *s)
          else if ( ss == s + 23 && !strncmp(s, "quarantine=scratch-page", 23) )
              iommu_quarantine = IOMMU_quarantine_scratch_page;
  #endif
-#ifdef CONFIG_X86
+#ifdef CONFIG_INTEL_IOMMU
          else if ( (val = parse_boolean("igfx", s, ss)) >= 0 )
              iommu_igfx = val;
          else if ( (val = parse_boolean("qinval", s, ss)) >= 0 )
              iommu_qinval = val;
+#endif

You want to use no_config_param() here as well then.

Yes. I will fix it.

Quoted 12 lines
Quoted 12 lines
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
     iommu_intremap_restricted,
     iommu_intremap_full,
  } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
  #else
  # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
  # define iommu_snoop false
  #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Signature · 1 line
Xenia
#9 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

Quoted 43 lines · Xenia Ragiadakou
Quoted 17 lines · Jan Beulich
Quoted 4 lines · Xenia Ragiadakou
xen/drivers/passthrough/iommu.c +0 -0
@@ -82,11 +82,13 @@ static int __init cf_check 
 parse_iommu_param(const char *s)

xen/drivers/passthrough/iommu.c static int __init cf_check · line 91

Quoted 10 lines
xen/drivers/passthrough/iommu.c +2 -1
           else if ( ss == s + 23 && !strncmp(s, "quarantine=scratch-page", 23) )
               iommu_quarantine = IOMMU_quarantine_scratch_page;
   #endif
-#ifdef CONFIG_X86
+#ifdef CONFIG_INTEL_IOMMU
           else if ( (val = parse_boolean("igfx", s, ss)) >= 0 )
               iommu_igfx = val;
           else if ( (val = parse_boolean("qinval", s, ss)) >= 0 )
               iommu_qinval = val;
+#endif

You want to use no_config_param() here as well then.

Yes. I will fix it.

Quoted 12 lines
Quoted 12 lines
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
      iommu_intremap_restricted,
      iommu_intremap_full,
   } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
   #else
   # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
   # define iommu_snoop false
   #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Quoted 1 line

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Actually, my patch was altering the current behavior by defining iommu_snoop as false when !INTEL_IOMMU.

IIUC, there is no control over snoop behavior when using the AMD iommu. Hence, iommu_snoop should evaluate to true for AMD iommu. However, when using the INTEL iommu the user can disable it via the "iommu" param, right?

If that's the case then iommu_snoop needs to be moved from vtd/iommu.c to x86/iommu.c and iommu_snoop assignment via iommu param needs to be guarded by CONFIG_INTEL_IOMMU.

Signature · 1 line
Xenia
#10 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

Quoted 26 lines · Xenia Ragiadakou
Quoted 22 lines · Xenia Ragiadakou
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
      iommu_intremap_restricted,
      iommu_intremap_full,
   } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
   #else
   # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
   # define iommu_snoop false
   #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Quoted 2 lines

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Quoted 7 lines

Actually, my patch was altering the current behavior by defining iommu_snoop as false when !INTEL_IOMMU.

IIUC, there is no control over snoop behavior when using the AMD iommu. Hence, iommu_snoop should evaluate to true for AMD iommu. However, when using the INTEL iommu the user can disable it via the "iommu" param, right?

That's the intended behavior, yes, but right now we allow the option to also affect behavior on AMD - perhaps wrongly so, as there's one use outside of VT-x and VT-d code. But of course the option is documented to be there for VT-d only, so one can view it as user error if it's used on a non-VT-d system.

Quoted 3 lines

If that's the case then iommu_snoop needs to be moved from vtd/iommu.c to x86/iommu.c and iommu_snoop assignment via iommu param needs to be guarded by CONFIG_INTEL_IOMMU.

Or #define to true when !INTEL_IOMMU and keep the variable where it is.

Jan

#11 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

Quoted 41 lines · Jan Beulich
Quoted 26 lines · Xenia Ragiadakou
Quoted 22 lines · Xenia Ragiadakou
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
      iommu_intremap_restricted,
      iommu_intremap_full,
   } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
   #else
   # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
   # define iommu_snoop false
   #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Quoted 2 lines

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Quoted 7 lines

Actually, my patch was altering the current behavior by defining iommu_snoop as false when !INTEL_IOMMU.

IIUC, there is no control over snoop behavior when using the AMD iommu. Hence, iommu_snoop should evaluate to true for AMD iommu. However, when using the INTEL iommu the user can disable it via the "iommu" param, right?

That's the intended behavior, yes, but right now we allow the option to also affect behavior on AMD - perhaps wrongly so, as there's one use outside of VT-x and VT-d code. But of course the option is documented to be there for VT-d only, so one can view it as user error if it's used on a non-VT-d system.

Quoted 6 lines
Quoted 3 lines

If that's the case then iommu_snoop needs to be moved from vtd/iommu.c to x86/iommu.c and iommu_snoop assignment via iommu param needs to be guarded by CONFIG_INTEL_IOMMU.

Or #define to true when !INTEL_IOMMU and keep the variable where it is.

Given the current implementation, if defined to true, it will be true even when !iommu_enabled.

Signature · 1 line
Xenia
#12 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

Quoted 47 lines · Xenia Ragiadakou
Quoted 45 lines · Jan Beulich
Quoted 26 lines · Xenia Ragiadakou
Quoted 22 lines · Xenia Ragiadakou
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
      iommu_intremap_restricted,
      iommu_intremap_full,
   } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
   #else
   # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
   # define iommu_snoop false
   #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Quoted 2 lines

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Quoted 7 lines

Actually, my patch was altering the current behavior by defining iommu_snoop as false when !INTEL_IOMMU.

IIUC, there is no control over snoop behavior when using the AMD iommu. Hence, iommu_snoop should evaluate to true for AMD iommu. However, when using the INTEL iommu the user can disable it via the "iommu" param, right?

That's the intended behavior, yes, but right now we allow the option to also affect behavior on AMD - perhaps wrongly so, as there's one use outside of VT-x and VT-d code. But of course the option is documented to be there for VT-d only, so one can view it as user error if it's used on a non-VT-d system.

Quoted 3 lines

If that's the case then iommu_snoop needs to be moved from vtd/iommu.c to x86/iommu.c and iommu_snoop assignment via iommu param needs to be guarded by CONFIG_INTEL_IOMMU.

Quoted 5 lines
Quoted 2 lines

Or #define to true when !INTEL_IOMMU and keep the variable where it is.

Given the current implementation, if defined to true, it will be true even when !iommu_enabled.

Which is supposed to be benign; I'm about to send a patch to actually make it benign in shadow code as well (which is the one place where I notice it isn't right now).

Jan

#13 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

In reply to Xenia Ragiadakou
Quoted 32 lines · Xenia Ragiadakou
Quoted 24 lines · Xenia Ragiadakou
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
      iommu_intremap_restricted,
      iommu_intremap_full,
   } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
   #else
   # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
   # define iommu_snoop false
   #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Quoted 2 lines

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Actually, my patch was altering the current behavior by defining iommu_snoop as false when !INTEL_IOMMU.

Quoted 9 lines

IIUC, there is no control over snoop behavior when using the AMD iommu. Hence, iommu_snoop should evaluate to true for AMD iommu. However, when using the INTEL iommu the user can disable it via the "iommu" param, right?

If that's the case then iommu_snoop needs to be moved from vtd/iommu.c to x86/iommu.c and iommu_snoop assignment via iommu param needs to be guarded by CONFIG_INTEL_IOMMU.

Pretty much everything Xen thinks it knows about iommu_snoop is broken.

AMD IOMMUs have had this capability since the outset, but it's the FC bit (Force Coherent).  On Intel, the capability is optional, and typically differs between IOMMUs in the same system.

Treating iommu_snoop as a single global is buggy, because (when available) it's always a per-SBDF control.  It is used to take a TLP and force it to be coherent even when the device was trying to issue a non-coherent access.

Intel systems typically have a dedicated IOMMU for the IGD, which always issues coherent accesses (its memory access happens as an adjunct to the LLC, not as something that communicates with the memory controller directly), so the IOMMU doesn't offer snoop control, and Xen "levels" this down to "the system can't do snoop control".

Xen is very confused when it comes to cacheability correctness.  I still have a pile of post-XSA-402 work pending, and it needs to start with splitting Xen's idea of "domain can use reduced cacheability" from "domain has a device", and work incrementally from there.

But in terms of snoop_control, it's strictly necessary for the cases where the guest kernel thinks it is using reduced cacheability, but it isn't because of something the hypervisor has done.  But beyond that, forcing snoop behind the back of a guest which is using reduced cacheability is just a waste of performance.

~Andrew

#14 lore raw

Re: [PATCH v2 3/8] x86/iommu: iommu_igfx, iommu_qinval and iommu_snoop are VT-d specific

Quoted 66 lines · Andrew Cooper
Quoted 32 lines · Xenia Ragiadakou
Quoted 24 lines · Xenia Ragiadakou
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Xenia Ragiadakou
xen/include/xen/iommu.h +2 -1
@@ -74,9 +74,13 @@ extern enum __packed iommu_intremap {
      iommu_intremap_restricted,
      iommu_intremap_full,
   } iommu_intremap;
-extern bool iommu_igfx, iommu_qinval, iommu_snoop;
   #else
   # define iommu_intremap false
+#endif
+
Quoted 8 lines

xen/include/xen/iommu.h extern enum __packed iommu_intremap { · line 85

Quoted 5 lines
xen/include/xen/iommu.h +3 -0
+#ifdef CONFIG_INTEL_IOMMU
+extern bool iommu_igfx, iommu_qinval, iommu_snoop;
+#else
   # define iommu_snoop false
   #endif

Do these declarations really need touching? In patch 2 you didn't move amd_iommu_perdev_intremap's either.

Quoted 2 lines

Ok, I will revert this change (as I did in v2 of patch 2) since it is not needed.

Actually, my patch was altering the current behavior by defining iommu_snoop as false when !INTEL_IOMMU.

Quoted 9 lines

IIUC, there is no control over snoop behavior when using the AMD iommu. Hence, iommu_snoop should evaluate to true for AMD iommu. However, when using the INTEL iommu the user can disable it via the "iommu" param, right?

If that's the case then iommu_snoop needs to be moved from vtd/iommu.c to x86/iommu.c and iommu_snoop assignment via iommu param needs to be guarded by CONFIG_INTEL_IOMMU.

Pretty much everything Xen thinks it knows about iommu_snoop is broken.

AMD IOMMUs have had this capability since the outset, but it's the FC bit (Force Coherent).  On Intel, the capability is optional, and typically differs between IOMMUs in the same system.

Treating iommu_snoop as a single global is buggy, because (when available) it's always a per-SBDF control.  It is used to take a TLP and force it to be coherent even when the device was trying to issue a non-coherent access.

Intel systems typically have a dedicated IOMMU for the IGD, which always issues coherent accesses (its memory access happens as an adjunct to the LLC, not as something that communicates with the memory controller directly), so the IOMMU doesn't offer snoop control, and Xen "levels" this down to "the system can't do snoop control".

Xen is very confused when it comes to cacheability correctness.  I still have a pile of post-XSA-402 work pending, and it needs to start with splitting Xen's idea of "domain can use reduced cacheability" from "domain has a device", and work incrementally from there.

Quoted 5 lines

But in terms of snoop_control, it's strictly necessary for the cases where the guest kernel thinks it is using reduced cacheability, but it isn't because of something the hypervisor has done.  But beyond that, forcing snoop behind the back of a guest which is using reduced cacheability is just a waste of performance.

I guess I agree with most/all you say, but that's all orthogonal to Xenia's work (and also to the patch I'm about to send to address the one issue that I've spotted while reviewing Xenia's patch).

Jan

#15 lore raw

PATCH v2 4/8 x86/acpi: separate AMD-Vi and VT-d specific functions

In reply to Xenia Ragiadakou

The functions acpi_dmar_init() and acpi_dmar_zap/reinstate() are VT-d specific while the function acpi_ivrs_init() is AMD-Vi specific. To eliminate dead code, they need to be guarded under CONFIG_INTEL_IOMMU and CONFIG_AMD_IOMMU, respectively.

Instead of adding #ifdef guards around the function calls, implement them as empty static inline functions.

Take the opportunity to move the declarations of acpi_dmar_zap/reinstate() to the arch specific header.

No functional change intended.

---

Changes in v2:
- replace CONFIG_INTEL_VTD with CONFIG_INTEL_IOMMU

 xen/arch/x86/include/asm/acpi.h | 14 ++++++++++++++
 xen/include/xen/acpi.h          |  3 ---
 2 files changed, 14 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/acpi.h +14 -0
index c453450a74..ca8529a7c8 100644
@@ -140,8 +140,22 @@ extern u32 pmtmr_ioport;
 extern unsigned int pmtmr_width;
 
 void acpi_iommu_init(void);
+
+#ifdef CONFIG_INTEL_IOMMU
 int acpi_dmar_init(void);
+void acpi_dmar_zap(void);
+void acpi_dmar_reinstate(void);
+#else
+static inline int acpi_dmar_init(void) { return -ENODEV; }
+static inline void acpi_dmar_zap(void) {}
+static inline void acpi_dmar_reinstate(void) {}
+#endif
+
+#ifdef CONFIG_AMD_IOMMU
 int acpi_ivrs_init(void);
+#else
+static inline int acpi_ivrs_init(void) { return -ENODEV; }
+#endif
 
 void acpi_mmcfg_init(void);
 
xen/include/xen/acpi.h +0 -3
index 1b9c75e68f..82b24a5ef0 100644
@@ -206,9 +206,6 @@ static inline int acpi_get_pxm(acpi_handle handle)
 
 void acpi_reboot(void);
 
-void acpi_dmar_zap(void);
-void acpi_dmar_reinstate(void);
-
 #endif /* __ASSEMBLY__ */
 
 #endif /*_LINUX_ACPI_H*/
Signature · 1 line
2.37.2
#16 lore raw

Re: [PATCH v2 4/8] x86/acpi: separate AMD-Vi and VT-d specific functions

Quoted 8 lines · Xenia Ragiadakou

The functions acpi_dmar_init() and acpi_dmar_zap/reinstate() are VT-d specific while the function acpi_ivrs_init() is AMD-Vi specific. To eliminate dead code, they need to be guarded under CONFIG_INTEL_IOMMU and CONFIG_AMD_IOMMU, respectively.

Instead of adding #ifdef guards around the function calls, implement them as empty static inline functions.

Quoted 6 lines

Take the opportunity to move the declarations of acpi_dmar_zap/reinstate() to the arch specific header.

No functional change intended.

While I'm not opposed to ack the change in this form, I have a question first:

Quoted 6 lines
xen/arch/x86/include/asm/acpi.h +0 -0
@@ -140,8 +140,22 @@ extern u32 pmtmr_ioport;
 extern unsigned int pmtmr_width;
 
 void acpi_iommu_init(void);

xen/arch/x86/include/asm/acpi.h extern u32 pmtmr_ioport; · line 152

Quoted 10 lines
xen/arch/x86/include/asm/acpi.h +9 -0
+
+#ifdef CONFIG_INTEL_IOMMU
 int acpi_dmar_init(void);
+void acpi_dmar_zap(void);
+void acpi_dmar_reinstate(void);
+#else
+static inline int acpi_dmar_init(void) { return -ENODEV; }
+static inline void acpi_dmar_zap(void) {}
+static inline void acpi_dmar_reinstate(void) {}
+#endif

Leaving aside my request to drop that part of patch 3, you've kept declarations for VT-d in the common header there. Which I consider correct, knowing that VT-d was also used on IA-64 at the time. As a result I would suppose movement might better be done in the other direction here.

xen/arch/x86/include/asm/acpi.h extern u32 pmtmr_ioport; · line 158

Quoted 5 lines
xen/arch/x86/include/asm/acpi.h +4 -0
+#ifdef CONFIG_AMD_IOMMU
 int acpi_ivrs_init(void);
+#else
+static inline int acpi_ivrs_init(void) { return -ENODEV; }
+#endif

For AMD, otoh, without there being a 2nd architecture re-using their IOMMU, moving into the x86-specific header is certainly fine, no matter that there's a slim chance that this may need moving the other direction down the road.

Jan

#17 lore raw

Re: [PATCH v2 4/8] x86/acpi: separate AMD-Vi and VT-d specific functions

Quoted 33 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

The functions acpi_dmar_init() and acpi_dmar_zap/reinstate() are VT-d specific while the function acpi_ivrs_init() is AMD-Vi specific. To eliminate dead code, they need to be guarded under CONFIG_INTEL_IOMMU and CONFIG_AMD_IOMMU, respectively.

Instead of adding #ifdef guards around the function calls, implement them as empty static inline functions.

Quoted 6 lines

Take the opportunity to move the declarations of acpi_dmar_zap/reinstate() to the arch specific header.

No functional change intended.

While I'm not opposed to ack the change in this form, I have a question first:

Quoted 14 lines
xen/arch/x86/include/asm/acpi.h +7 -0
@@ -140,8 +140,22 @@ extern u32 pmtmr_ioport;
  extern unsigned int pmtmr_width;
 
  void acpi_iommu_init(void);
+
+#ifdef CONFIG_INTEL_IOMMU
  int acpi_dmar_init(void);
+void acpi_dmar_zap(void);
+void acpi_dmar_reinstate(void);
+#else
+static inline int acpi_dmar_init(void) { return -ENODEV; }
+static inline void acpi_dmar_zap(void) {}
Quoted 8 lines

xen/arch/x86/include/asm/acpi.h extern u32 pmtmr_ioport; · line 152

Quoted 2 lines
xen/arch/x86/include/asm/acpi.h +2 -0
+static inline void acpi_dmar_reinstate(void) {}
+#endif

Leaving aside my request to drop that part of patch 3, you've kept declarations for VT-d in the common header there. Which I consider correct, knowing that VT-d was also used on IA-64 at the time. As a result I would suppose movement might better be done in the other direction here.

I moved it to the x86-specific header because acpi_dmar_init() was declared there. I can move all of them to the common header.

Quoted 11 lines

xen/arch/x86/include/asm/acpi.h extern u32 pmtmr_ioport; · line 158

Quoted 6 lines
xen/arch/x86/include/asm/acpi.h +4 -0
+#ifdef CONFIG_AMD_IOMMU
  int acpi_ivrs_init(void);
+#else
+static inline int acpi_ivrs_init(void) { return -ENODEV; }
+#endif

For AMD, otoh, without there being a 2nd architecture re-using their IOMMU, moving into the x86-specific header is certainly fine, no matter that there's a slim chance that this may need moving the other direction down the road.

Signature · 1 line
Xenia
#18 lore raw

Re: [PATCH v2 4/8] x86/acpi: separate AMD-Vi and VT-d specific functions

Quoted 25 lines · Xenia Ragiadakou
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Xenia Ragiadakou
xen/arch/x86/include/asm/acpi.h +7 -0
@@ -140,8 +140,22 @@ extern u32 pmtmr_ioport;
  extern unsigned int pmtmr_width;
 
  void acpi_iommu_init(void);
+
+#ifdef CONFIG_INTEL_IOMMU
  int acpi_dmar_init(void);
+void acpi_dmar_zap(void);
+void acpi_dmar_reinstate(void);
+#else
+static inline int acpi_dmar_init(void) { return -ENODEV; }
+static inline void acpi_dmar_zap(void) {}
Quoted 8 lines

xen/arch/x86/include/asm/acpi.h extern u32 pmtmr_ioport; · line 152

Quoted 2 lines
xen/arch/x86/include/asm/acpi.h +2 -0
+static inline void acpi_dmar_reinstate(void) {}
+#endif

Leaving aside my request to drop that part of patch 3, you've kept declarations for VT-d in the common header there. Which I consider correct, knowing that VT-d was also used on IA-64 at the time. As a result I would suppose movement might better be done in the other direction here.

Quoted 3 lines

I moved it to the x86-specific header because acpi_dmar_init() was declared there.
I can move all of them to the common header.

I would prefer you doing so, yes, of course unless others object.

Jan

#19 lore raw

PATCH v2 5/8 x86/iommu: the code addressing CVE-2011-1898 is VT-d specific

In reply to Xenia Ragiadakou

The variable untrusted_msi indicates whether the system is vulnerable to CVE-2011-1898. This vulnerablity is VT-d specific.
Place the code that addresses the issue under CONFIG_INTEL_IOMMU.

No functional change intended.

---

Changes in v2:
- replace CONFIG_INTEL_VTD with CONFIG_INTEL_IOMMU

 xen/arch/x86/include/asm/iommu.h | 2 ++
 xen/arch/x86/pv/hypercall.c      | 2 ++
 xen/arch/x86/x86_64/entry.S      | 2 ++
 3 files changed, 6 insertions(+)
xen/arch/x86/include/asm/iommu.h +2 -0
index fc0afe35bf..fb5fe4e1bf 100644
@@ -127,7 +127,9 @@ int iommu_identity_mapping(struct domain *d, p2m_access_t p2ma,
                            unsigned int flag);
 void iommu_identity_map_teardown(struct domain *d);
 
+#ifdef CONFIG_INTEL_IOMMU
 extern bool untrusted_msi;
+#endif
 
 int pi_update_irte(const struct pi_desc *pi_desc, const struct pirq *pirq,
                    const uint8_t gvec);
xen/arch/x86/pv/hypercall.c +2 -0
index 2eedfbfae8..9d616a0fc5 100644
@@ -193,8 +193,10 @@ void pv_ring1_init_hypercall_page(void *p)
 
 void do_entry_int82(struct cpu_user_regs *regs)
 {
+#ifdef CONFIG_INTEL_IOMMU
     if ( unlikely(untrusted_msi) )
         check_for_unexpected_msi((uint8_t)regs->entry_vector);
+#endif
 
     _pv_hypercall(regs, true /* compat */);
 }
xen/arch/x86/x86_64/entry.S +2 -0
index ae01285181..8f2fb36770 100644
@@ -406,11 +406,13 @@ ENTRY(int80_direct_trap)
 .Lint80_cr3_okay:
         sti
 
+#ifdef CONFIG_INTEL_IOMMU
         cmpb  $0,untrusted_msi(%rip)
 UNLIKELY_START(ne, msi_check)
         movl  $0x80,%edi
         call  check_for_unexpected_msi
 UNLIKELY_END(msi_check)
+#endif
 
         movq  STACK_CPUINFO_FIELD(current_vcpu)(%rbx), %rbx
 
Signature · 1 line
2.37.2
#20 lore raw

Re: [PATCH v2 5/8] x86/iommu: the code addressing CVE-2011-1898 is VT-d specific

Quoted 2 lines · Xenia Ragiadakou

The variable untrusted_msi indicates whether the system is vulnerable to CVE-2011-1898. This vulnerablity is VT-d specific.

As per the reply by Andrew to v1, this vulnerability is generic to intremap- incapable or intremap-disabled configurations. You want to say so. In turn I wonder whether instead of the changes you're making you wouldn't want to move the definition of the variable to xen/drivers/passthrough/x86/iommu.c. A useful further step might be to guard its definition (not necessarily its declaration; see replies to earlier patches) by CONFIG_PV instead (of course I understand that's largely orthogonal to your series here, yet it would fit easily with moving the definition).

xen/arch/x86/include/asm/iommu.h int iommu_identity_mapping(struct domain *d, p2m_access_t p2ma, · line 132

Quoted 9 lines
xen/arch/x86/include/asm/iommu.h +2 -0
@@ -127,7 +127,9 @@ int iommu_identity_mapping(struct domain *d, p2m_access_t p2ma,
                            unsigned int flag);
 void iommu_identity_map_teardown(struct domain *d);
 
+#ifdef CONFIG_INTEL_IOMMU
 extern bool untrusted_msi;
+#endif

As per above / earlier comments I don't think this part is needed in any event.

Quoted 31 lines
xen/arch/x86/pv/hypercall.c +2 -0
@@ -193,8 +193,10 @@ void pv_ring1_init_hypercall_page(void *p)
 
 void do_entry_int82(struct cpu_user_regs *regs)
 {
+#ifdef CONFIG_INTEL_IOMMU
     if ( unlikely(untrusted_msi) )
         check_for_unexpected_msi((uint8_t)regs->entry_vector);
+#endif
 
     _pv_hypercall(regs, true /* compat */);
 }
xen/arch/x86/x86_64/entry.S +2 -0
index ae01285181..8f2fb36770 100644
@@ -406,11 +406,13 @@ ENTRY(int80_direct_trap)
 .Lint80_cr3_okay:
         sti
 
+#ifdef CONFIG_INTEL_IOMMU
         cmpb  $0,untrusted_msi(%rip)
 UNLIKELY_START(ne, msi_check)
         movl  $0x80,%edi
         call  check_for_unexpected_msi
 UNLIKELY_END(msi_check)
+#endif
 
         movq  STACK_CPUINFO_FIELD(current_vcpu)(%rbx), %rbx
 
#21 lore raw

Re: [PATCH v2 5/8] x86/iommu: the code addressing CVE-2011-1898 is VT-d specific

Quoted 4 lines · Jan Beulich
Quoted 2 lines · Xenia Ragiadakou

The variable untrusted_msi indicates whether the system is vulnerable to CVE-2011-1898. This vulnerablity is VT-d specific.

Quoted 8 lines

As per the reply by Andrew to v1, this vulnerability is generic to intremap- incapable or intremap-disabled configurations. You want to say so. In turn I wonder whether instead of the changes you're making you wouldn't want to move the definition of the variable to xen/drivers/passthrough/x86/iommu.c. A useful further step might be to guard its definition (not necessarily its declaration; see replies to earlier patches) by CONFIG_PV instead (of course I understand that's largely orthogonal to your series here, yet it would fit easily with moving the definition).

Sure I can do that.

Quoted 46 lines

xen/arch/x86/include/asm/iommu.h int iommu_identity_mapping(struct domain *d, p2m_access_t p2ma, · line 132

Quoted 10 lines
xen/arch/x86/include/asm/iommu.h +2 -0
@@ -127,7 +127,9 @@ int iommu_identity_mapping(struct domain *d, p2m_access_t p2ma,
                             unsigned int flag);
  void iommu_identity_map_teardown(struct domain *d);
 
+#ifdef CONFIG_INTEL_IOMMU
  extern bool untrusted_msi;
+#endif

As per above / earlier comments I don't think this part is needed in any event.

Quoted 31 lines
xen/arch/x86/pv/hypercall.c +2 -0
@@ -193,8 +193,10 @@ void pv_ring1_init_hypercall_page(void *p)
 
  void do_entry_int82(struct cpu_user_regs *regs)
  {
+#ifdef CONFIG_INTEL_IOMMU
      if ( unlikely(untrusted_msi) )
          check_for_unexpected_msi((uint8_t)regs->entry_vector);
+#endif
 
      _pv_hypercall(regs, true /* compat */);
  }
xen/arch/x86/x86_64/entry.S +2 -0
index ae01285181..8f2fb36770 100644
@@ -406,11 +406,13 @@ ENTRY(int80_direct_trap)
  .Lint80_cr3_okay:
          sti
 
+#ifdef CONFIG_INTEL_IOMMU
          cmpb  $0,untrusted_msi(%rip)
  UNLIKELY_START(ne, msi_check)
          movl  $0x80,%edi
          call  check_for_unexpected_msi
  UNLIKELY_END(msi_check)
+#endif
 
          movq  STACK_CPUINFO_FIELD(current_vcpu)(%rbx), %rbx
 
Signature · 1 line
Xenia
#22 lore raw

PATCH v2 6/8 x86/iommu: call pi_update_irte through an hvm_function callback

In reply to Xenia Ragiadakou

Posted interrupt support in Xen is currently implemented only for the Intel platforms. Instead of calling directly pi_update_irte() from the common hvm code, add a pi_update_irte callback to the hvm_function_table. Then, create a wrapper function hvm_pi_update_irte() to be used by the common hvm code.

In the pi_update_irte callback prototype, pass the vcpu as first parameter instead of the posted-interrupt descriptor that is platform specific, and remove the const qualifier from the parameter gvec since it is not needed and because it does not compile with the alternative code patching in use.

Move the declaration of pi_update_irte() from asm/iommu.h to asm/hvm/vmx/vmx.h since it is hvm and Intel specific.

No functional change intended.

---

Changes in v2:
- remove the definition of hvm_pi_update_irte() for !CONFIG_HVM
- replace CONFIG_INTEL_VTD with CONFIG_INTEL_IOMMU

 xen/arch/x86/hvm/vmx/vmx.c             | 10 ++++++++++
 xen/arch/x86/include/asm/hvm/hvm.h     | 15 +++++++++++++++
 xen/arch/x86/include/asm/hvm/vmx/vmx.h | 11 +++++++++++
 xen/arch/x86/include/asm/iommu.h       |  3 ---
 xen/drivers/passthrough/x86/hvm.c      |  5 ++---
 5 files changed, 38 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +10 -0
index 43a4865d1c..cb6b325e41 100644
@@ -2143,6 +2143,14 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec)
     return pi_test_pir(vec, &v->arch.hvm.vmx.pi_desc);
 }
 
+static int cf_check vmx_pi_update_irte(const struct vcpu *v,
+                                       const struct pirq *pirq, uint8_t gvec)
+{
+    const struct pi_desc *pi_desc = v ? &v->arch.hvm.vmx.pi_desc : NULL;
+
+    return pi_update_irte(pi_desc, pirq, gvec);
+}
+
 static void cf_check vmx_handle_eoi(uint8_t vector, int isr)
 {
     uint8_t old_svi = set_svi(isr);
@@ -2591,6 +2599,8 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = {
     .tsc_scaling = {
         .max_ratio = VMX_TSC_MULTIPLIER_MAX,
     },
+
+    .pi_update_irte = vmx_pi_update_irte,
 };
 
 /* Handle VT-d posted-interrupt when VCPU is blocked. */
xen/arch/x86/include/asm/hvm/hvm.h +15 -0
index 93254651f2..b3fe0663f9 100644
@@ -28,6 +28,8 @@
 #include <asm/x86_emulate.h>
 #include <asm/hvm/asid.h>
 
+struct pirq; /* needed by pi_update_irte */
+
 #ifdef CONFIG_HVM_FEP
 /* Permit use of the Forced Emulation Prefix in HVM guests */
 extern bool_t opt_hvm_fep;
@@ -250,6 +252,9 @@ struct hvm_function_table {
         /* Architecture function to setup TSC scaling ratio */
         void (*setup)(struct vcpu *v);
     } tsc_scaling;
+
+    int (*pi_update_irte)(const struct vcpu *v,
+                          const struct pirq *pirq, uint8_t gvec);
 };
 
 extern struct hvm_function_table hvm_funcs;
@@ -774,6 +779,16 @@ static inline void hvm_set_nonreg_state(struct vcpu *v,
         alternative_vcall(hvm_funcs.set_nonreg_state, v, nrs);
 }
 
+static inline int hvm_pi_update_irte(const struct vcpu *v,
+                                     const struct pirq *pirq, uint8_t gvec)
+{
+    if ( hvm_funcs.pi_update_irte )
+        return alternative_call(hvm_funcs.pi_update_irte, v, pirq, gvec);
+
+    return -EOPNOTSUPP;
+}
+
+
 #else  /* CONFIG_HVM */
 
 #define hvm_enabled false
xen/arch/x86/include/asm/hvm/vmx/vmx.h +11 -0
index 96a9f07ca5..e827fece07 100644
@@ -146,6 +146,17 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc)
     clear_bit(POSTED_INTR_SN, &pi_desc->control);
 }
 
+#ifdef CONFIG_INTEL_IOMMU
+int pi_update_irte(const struct pi_desc *pi_desc,
+                   const struct pirq *pirq, const uint8_t gvec);
+#else
+static inline int pi_update_irte(const struct pi_desc *pi_desc,
+                                 const struct pirq *pirq, const uint8_t gvec)
+{
+    return -EOPNOTSUPP;
+}
+#endif
+
 /*
  * Exit Reasons
  */
xen/arch/x86/include/asm/iommu.h +0 -3
index fb5fe4e1bf..b432790d24 100644
@@ -131,9 +131,6 @@ void iommu_identity_map_teardown(struct domain *d);
 extern bool untrusted_msi;
 #endif
 
-int pi_update_irte(const struct pi_desc *pi_desc, const struct pirq *pirq,
-                   const uint8_t gvec);
-
 extern bool iommu_non_coherent, iommu_superpages;
 
 static inline void iommu_sync_cache(const void *addr, unsigned int size)
xen/drivers/passthrough/x86/hvm.c +2 -3
index a16e0e5344..e720461a14 100644
@@ -381,8 +381,7 @@ int pt_irq_create_bind(
 
         /* Use interrupt posting if it is supported. */
         if ( iommu_intpost )
-            pi_update_irte(vcpu ? &vcpu->arch.hvm.vmx.pi_desc : NULL,
-                           info, pirq_dpci->gmsi.gvec);
+            hvm_pi_update_irte(vcpu, info, pirq_dpci->gmsi.gvec);
 
         if ( pt_irq_bind->u.msi.gflags & XEN_DOMCTL_VMSI_X86_UNMASKED )
         {
@@ -672,7 +671,7 @@ int pt_irq_destroy_bind(
             what = "bogus";
     }
     else if ( pirq_dpci && pirq_dpci->gmsi.posted )
-        pi_update_irte(NULL, pirq, 0);
+        hvm_pi_update_irte(NULL, pirq, 0);
 
     if ( pirq_dpci && (pirq_dpci->flags & HVM_IRQ_DPCI_MAPPED) &&
          list_empty(&pirq_dpci->digl_list) )
Signature · 1 line
2.37.2
#23 lore raw

Re: [PATCH v2 6/8] x86/iommu: call pi_update_irte through an hvm_function callback

xen/arch/x86/hvm/vmx/vmx.c static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec) · line 2152

Quoted 13 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/vmx.c +7 -0
@@ -2143,6 +2143,14 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec)
     return pi_test_pir(vec, &v->arch.hvm.vmx.pi_desc);
 }
 
+static int cf_check vmx_pi_update_irte(const struct vcpu *v,
+                                       const struct pirq *pirq, uint8_t gvec)
+{
+    const struct pi_desc *pi_desc = v ? &v->arch.hvm.vmx.pi_desc : NULL;
+
+    return pi_update_irte(pi_desc, pirq, gvec);
+}

This being the only caller of pi_update_irte(), I don't see the point in having the extra wrapper. Adjust pi_update_irte() such that it can be used as the intended hook directly. Plus perhaps prefix it with vtd_.

xen/arch/x86/hvm/vmx/vmx.c static struct hvm_function_table __initdata_cf_clobber vmx_function_table = { · line 2603

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -2591,6 +2599,8 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = {
     .tsc_scaling = {
         .max_ratio = VMX_TSC_MULTIPLIER_MAX,
     },
+
+    .pi_update_irte = vmx_pi_update_irte,

You want to install this hook only when iommu_intpost (i.e. the only case when it can actually be called, and only when INTEL_IOMMU=y (avoiding the need for an inline stub of pi_update_irte() or whatever its final name is going to be.

xen/arch/x86/hvm/vmx/vmx.c struct hvm_function_table { · line 258

Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
@@ -250,6 +252,9 @@ struct hvm_function_table {
         /* Architecture function to setup TSC scaling ratio */
         void (*setup)(struct vcpu *v);
     } tsc_scaling;
+
+    int (*pi_update_irte)(const struct vcpu *v,
+                          const struct pirq *pirq, uint8_t gvec);
 };

Please can this be moved higher up, e.g. next to .

xen/arch/x86/hvm/vmx/vmx.c static inline void hvm_set_nonreg_state(struct vcpu *v, · line 788

Quoted 11 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
@@ -774,6 +779,16 @@ static inline void hvm_set_nonreg_state(struct vcpu *v,
         alternative_vcall(hvm_funcs.set_nonreg_state, v, nrs);
 }
 
+static inline int hvm_pi_update_irte(const struct vcpu *v,
+                                     const struct pirq *pirq, uint8_t gvec)
+{
+    if ( hvm_funcs.pi_update_irte )
+        return alternative_call(hvm_funcs.pi_update_irte, v, pirq, gvec);
+
+    return -EOPNOTSUPP;

I don't think the conditional is needed, at least not with the other suggested adjustments. Plus the way alternative patching works, a NULL hook will be converted to some equivalent of BUG() anyway, so ASSERT_UNREACHABLE() should also be unnecessary.

xen/arch/x86/hvm/vmx/vmx.c static inline void hvm_set_nonreg_state(struct vcpu *v, · line 792

Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+}
+
+
 #else  /* CONFIG_HVM */

Please don't add double blank lines.

Quoted 6 lines
xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -0
@@ -146,6 +146,17 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc)
     clear_bit(POSTED_INTR_SN, &pi_desc->control);
 }
 

xen/arch/x86/include/asm/hvm/vmx/vmx.h static inline void pi_clear_sn(struct pi_desc *pi_desc) · line 158

Quoted 10 lines
xen/arch/x86/include/asm/hvm/vmx/vmx.h +10 -0
+#ifdef CONFIG_INTEL_IOMMU
+int pi_update_irte(const struct pi_desc *pi_desc,
+                   const struct pirq *pirq, const uint8_t gvec);
+#else
+static inline int pi_update_irte(const struct pi_desc *pi_desc,
+                                 const struct pirq *pirq, const uint8_t gvec)
+{
+    return -EOPNOTSUPP;
+}
+#endif

This still is a VT-d function, so I think its declaration would better remain in asm/iommu.h.

Jan

#24 lore raw

Re: [PATCH v2 6/8] x86/iommu: call pi_update_irte through an hvm_function callback

Quoted 7 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -2143,6 +2143,14 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec)
     return pi_test_pir(vec, &v->arch.hvm.vmx.pi_desc);
 }
 
Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec) · line 2152

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+static int cf_check vmx_pi_update_irte(const struct vcpu *v,
+                                       const struct pirq *pirq, uint8_t gvec)
+{
+    const struct pi_desc *pi_desc = v ? &v->arch.hvm.vmx.pi_desc : NULL;
+
+    return pi_update_irte(pi_desc, pirq, gvec);
+}

This being the only caller of pi_update_irte(), I don't see the point in having the extra wrapper. Adjust pi_update_irte() such that it can be used as the intended hook directly. Plus perhaps prefix it with vtd_.

Plus move it to vtd/x86/hvm.c (!HVM builds shouldn't need it), albeit I realize this could be done independent of your work. In principle the function shouldn't be VT-d specific (and could hence live in x86/hvm.c), as msi_msg_write_remap_rte() is already available as IOMMU hook anyway, provided struct pi_desc turns out compatible with what's going to be needed for AMD.

Jan

#25 lore raw

Re: [PATCH v2 6/8] x86/iommu: call pi_update_irte through an hvm_function callback

Quoted 20 lines · Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -2143,6 +2143,14 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec)
      return pi_test_pir(vec, &v->arch.hvm.vmx.pi_desc);
  }
 
Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec) · line 2152

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+static int cf_check vmx_pi_update_irte(const struct vcpu *v,
+                                       const struct pirq *pirq, uint8_t gvec)
+{
+    const struct pi_desc *pi_desc = v ? &v->arch.hvm.vmx.pi_desc : NULL;
+
+    return pi_update_irte(pi_desc, pirq, gvec);
+}

This being the only caller of pi_update_irte(), I don't see the point in having the extra wrapper. Adjust pi_update_irte() such that it can be used as the intended hook directly. Plus perhaps prefix it with vtd_.

Quoted 6 lines

Plus move it to vtd/x86/hvm.c (!HVM builds shouldn't need it), albeit I realize this could be done independent of your work. In principle the function shouldn't be VT-d specific (and could hence live in x86/hvm.c), as msi_msg_write_remap_rte() is already available as IOMMU hook anyway, provided struct pi_desc turns out compatible with what's going to be needed for AMD.

Since the posted interrupt descriptor is vmx specific while msi_msg_write_remap_rte is iommu specific, can I propose the following:

- Keep the name as is (i.e vmx_pi_update_irte) and keep its definition in xen/arch/x86/hvm/vmx/vmx.c

- Open code pi_update_irte() inside the body of vmx_pi_update_irte() but replace intel-specific msi_msg_write_remap_rte() with generic iommu_update_ire_from_msi().

Does this approach make sense?

Signature · 1 line
Xenia
#26 lore raw

Re: [PATCH v2 6/8] x86/iommu: call pi_update_irte through an hvm_function callback

Quoted 32 lines · Xenia Ragiadakou
Quoted 20 lines · Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -2143,6 +2143,14 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec)
      return pi_test_pir(vec, &v->arch.hvm.vmx.pi_desc);
  }
 
Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec) · line 2152

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+static int cf_check vmx_pi_update_irte(const struct vcpu *v,
+                                       const struct pirq *pirq, uint8_t gvec)
+{
+    const struct pi_desc *pi_desc = v ? &v->arch.hvm.vmx.pi_desc : NULL;
+
+    return pi_update_irte(pi_desc, pirq, gvec);
+}

This being the only caller of pi_update_irte(), I don't see the point in having the extra wrapper. Adjust pi_update_irte() such that it can be used as the intended hook directly. Plus perhaps prefix it with vtd_.

Quoted 6 lines

Plus move it to vtd/x86/hvm.c (!HVM builds shouldn't need it), albeit I realize this could be done independent of your work. In principle the function shouldn't be VT-d specific (and could hence live in x86/hvm.c), as msi_msg_write_remap_rte() is already available as IOMMU hook anyway, provided struct pi_desc turns out compatible with what's going to be needed for AMD.

Since the posted interrupt descriptor is vmx specific while msi_msg_write_remap_rte is iommu specific, can I propose the following:

Quoted 8 lines

- Keep the name as is (i.e vmx_pi_update_irte) and keep its definition in xen/arch/x86/hvm/vmx/vmx.c

- Open code pi_update_irte() inside the body of vmx_pi_update_irte() but replace intel-specific msi_msg_write_remap_rte() with generic iommu_update_ire_from_msi().

Does this approach make sense?

Why not - decouples one place of the assumed "CPU vendor" == "IOMMU vendor".

Jan

#27 lore raw

Re: [PATCH v2 6/8] x86/iommu: call pi_update_irte through an hvm_function callback

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Xenia Ragiadakou
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -2143,6 +2143,14 @@ static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec)
      return pi_test_pir(vec, &v->arch.hvm.vmx.pi_desc);
  }
 
Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c static bool cf_check vmx_test_pir(const struct vcpu *v, uint8_t vec) · line 2152

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+static int cf_check vmx_pi_update_irte(const struct vcpu *v,
+                                       const struct pirq *pirq, uint8_t gvec)
+{
+    const struct pi_desc *pi_desc = v ? &v->arch.hvm.vmx.pi_desc : NULL;
+
+    return pi_update_irte(pi_desc, pirq, gvec);
+}

This being the only caller of pi_update_irte(), I don't see the point in having the extra wrapper. Adjust pi_update_irte() such that it can be used as the intended hook directly. Plus perhaps prefix it with vtd_.

Ok I will remove the extra wrapper.

Quoted 12 lines

xen/arch/x86/hvm/vmx/vmx.c static struct hvm_function_table __initdata_cf_clobber vmx_function_table = { · line 2603

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +2 -0
@@ -2591,6 +2599,8 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = {
      .tsc_scaling = {
          .max_ratio = VMX_TSC_MULTIPLIER_MAX,
      },
+
+    .pi_update_irte = vmx_pi_update_irte,

You want to install this hook only when iommu_intpost (i.e. the only case when it can actually be called, and only when INTEL_IOMMU=y (avoiding the need for an inline stub of pi_update_irte() or whatever its final name is going to be.

Ok will do.

Quoted 11 lines

xen/arch/x86/hvm/vmx/vmx.c struct hvm_function_table { · line 258

Quoted 9 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
@@ -250,6 +252,9 @@ struct hvm_function_table {
          /* Architecture function to setup TSC scaling ratio */
          void (*setup)(struct vcpu *v);
      } tsc_scaling;
+
+    int (*pi_update_irte)(const struct vcpu *v,
+                          const struct pirq *pirq, uint8_t gvec);
  };

Please can this be moved higher up, e.g. next to .

Right after handle_eoi would be ok? or higher up?

Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -774,6 +779,16 @@ static inline void hvm_set_nonreg_state(struct vcpu *v,
          alternative_vcall(hvm_funcs.set_nonreg_state, v, nrs);
  }
 
Quoted 12 lines

xen/arch/x86/hvm/vmx/vmx.c static inline void hvm_set_nonreg_state(struct vcpu *v, · line 788

Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7 -0
+static inline int hvm_pi_update_irte(const struct vcpu *v,
+                                     const struct pirq *pirq, uint8_t gvec)
+{
+    if ( hvm_funcs.pi_update_irte )
+        return alternative_call(hvm_funcs.pi_update_irte, v, pirq, gvec);
+
+    return -EOPNOTSUPP;

I don't think the conditional is needed, at least not with the other suggested adjustments. Plus the way alternative patching works, a NULL hook will be converted to some equivalent of BUG() anyway, so ASSERT_UNREACHABLE() should also be unnecessary.

Ok will remove it.

Quoted 7 lines

xen/arch/x86/hvm/vmx/vmx.c static inline void hvm_set_nonreg_state(struct vcpu *v, · line 792

Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -0
+}
+
+
  #else  /* CONFIG_HVM */

Please don't add double blank lines.

Ok will fix.

Quoted 22 lines
Quoted 7 lines
xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -0
@@ -146,6 +146,17 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc)
      clear_bit(POSTED_INTR_SN, &pi_desc->control);
  }
 

xen/arch/x86/include/asm/hvm/vmx/vmx.h static inline void pi_clear_sn(struct pi_desc *pi_desc) · line 158

Quoted 10 lines
xen/arch/x86/include/asm/hvm/vmx/vmx.h +10 -0
+#ifdef CONFIG_INTEL_IOMMU
+int pi_update_irte(const struct pi_desc *pi_desc,
+                   const struct pirq *pirq, const uint8_t gvec);
+#else
+static inline int pi_update_irte(const struct pi_desc *pi_desc,
+                                 const struct pirq *pirq, const uint8_t gvec)
+{
+    return -EOPNOTSUPP;
+}
+#endif

This still is a VT-d function, so I think its declaration would better remain in asm/iommu.h.

Jan

Signature · 1 line
Xenia
#28 lore raw

Re: [PATCH v2 6/8] x86/iommu: call pi_update_irte through an hvm_function callback

Quoted 13 lines · Xenia Ragiadakou
Quoted 11 lines · Jan Beulich

xen/arch/x86/include/asm/hvm/hvm.h struct hvm_function_table { · line 258

Quoted 8 lines · Xenia Ragiadakou
xen/arch/x86/include/asm/hvm/hvm.h +3 -0
@@ -250,6 +252,9 @@ struct hvm_function_table {
          /* Architecture function to setup TSC scaling ratio */
          void (*setup)(struct vcpu *v);
      } tsc_scaling;
+
+    int (*pi_update_irte)(const struct vcpu *v,
+                          const struct pirq *pirq, uint8_t gvec);
  };

Please can this be moved higher up, e.g. next to .

Quoted 1 line

Right after handle_eoi would be ok?

Yes. I'm sorry for sending out the earlier mail without completing the sentence.

Jan

#29 lore raw

PATCH v2 7/8 x86/dpci: move hvm_dpci_isairq_eoi() to generic HVM code

In reply to Xenia Ragiadakou

The function hvm_dpci_isairq_eoi() has no dependencies on VT-d driver code and can be moved from xen/drivers/passthrough/vtd/x86/hvm.c to xen/drivers/passthrough/x86/hvm.c, along with the corresponding copyrights.

Remove the now empty xen/drivers/passthrough/vtd/x86/hvm.c.

Since the funcion is used only in this file, declare it static.

No functional change intended.

---

Changes in v2:
- update the copyright
- declare hvm_dpci_isairq_eoi() static

 xen/drivers/passthrough/vtd/x86/Makefile |  1 -
 xen/drivers/passthrough/vtd/x86/hvm.c    | 64 ------------------------
 xen/drivers/passthrough/x86/hvm.c        | 43 ++++++++++++++++
 xen/include/xen/iommu.h                  |  1 -
 4 files changed, 43 insertions(+), 66 deletions(-)
 delete mode 100644 xen/drivers/passthrough/vtd/x86/hvm.c
xen/drivers/passthrough/vtd/x86/Makefile +0 -1
index 4ef00a4c5b..fe20a0b019 100644
@@ -1,3 +1,2 @@
 obj-y += ats.o
-obj-$(CONFIG_HVM) += hvm.o
 obj-y += vtd.o
xen/drivers/passthrough/vtd/x86/hvm.c deleted +0 -64

64 lines not on this page · raw message

xen/drivers/passthrough/x86/hvm.c +43 -0

55 lines not on this page · raw message

xen/include/xen/iommu.h +0 -1
index aa924541d5..f08bc2a4a5 100644
@@ -200,7 +200,6 @@ int hvm_do_IRQ_dpci(struct domain *, struct pirq *);
 int pt_irq_create_bind(struct domain *, const struct xen_domctl_bind_pt_irq *);
 int pt_irq_destroy_bind(struct domain *, const struct xen_domctl_bind_pt_irq *);
 
-void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq);
 struct hvm_irq_dpci *domain_get_irq_dpci(const struct domain *);
 void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci);
 
Signature · 1 line
2.37.2
Reviewed-by on v2 7/8
#30 lore raw

Re: [PATCH v2 7/8] x86/dpci: move hvm_dpci_isairq_eoi() to generic HVM code

Quoted 11 lines · Xenia Ragiadakou

The function hvm_dpci_isairq_eoi() has no dependencies on VT-d driver code and can be moved from xen/drivers/passthrough/vtd/x86/hvm.c to xen/drivers/passthrough/x86/hvm.c, along with the corresponding copyrights.

Remove the now empty xen/drivers/passthrough/vtd/x86/hvm.c.

Since the funcion is used only in this file, declare it static.

No functional change intended.

with a couple of cosmetic suggestions since you're touching this code anyway:

xen/drivers/passthrough/x86/hvm.c static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) · line 931

Quoted 8 lines
xen/drivers/passthrough/x86/hvm.c +4 -0
@@ -924,6 +925,48 @@ static void hvm_gsi_eoi(struct domain *d, unsigned int gsi)
     hvm_pirq_eoi(pirq);
 }
 
+static int cf_check _hvm_dpci_isairq_eoi(
+    struct domain *d, struct hvm_pirq_dpci *pirq_dpci, void *arg)
+{
+    struct hvm_irq *hvm_irq = hvm_domain_irq(d);

I think this could become pointer-to-const.

Quoted 11 lines
xen/drivers/passthrough/x86/hvm.c +11 -0
+    unsigned int isairq = (long)arg;
+    const struct dev_intx_gsi_link *digl;
+
+    list_for_each_entry ( digl, &pirq_dpci->digl_list, list )
+    {
+        unsigned int link = hvm_pci_intx_link(digl->device, digl->intx);
+
+        if ( hvm_irq->pci_link.route[link] == isairq )
+        {
+            hvm_pci_intx_deassert(d, digl->device, digl->intx);
+            if ( --pirq_dpci->pending == 0 )

xen/drivers/passthrough/x86/hvm.c static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) · line 952

Quoted 10 lines
xen/drivers/passthrough/x86/hvm.c +10 -0
+                pirq_guest_eoi(dpci_pirq(pirq_dpci));
+        }
+    }
+
+    return 0;
+}
+
+static void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
+{
+    struct hvm_irq_dpci *dpci = NULL;

And this too.

xen/drivers/passthrough/x86/hvm.c static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) · line 955

Quoted 2 lines
xen/drivers/passthrough/x86/hvm.c +2 -0
+    ASSERT(isairq < NR_ISAIRQS);
+    if ( !is_iommu_enabled(d) )

A blank line between the above two would be nice.

xen/drivers/passthrough/x86/hvm.c static void hvm_gsi_eoi(struct domain *d, unsigned int gsi) · line 967

Quoted 12 lines
xen/drivers/passthrough/x86/hvm.c +12 -0
+        return;
+
+    write_lock(&d->event_lock);
+
+    dpci = domain_get_irq_dpci(d);
+
+    if ( dpci && test_bit(isairq, dpci->isairq_map) )
+    {
+        /* Multiple mirq may be mapped to one isa irq */
+        pt_pirq_iterate(d, _hvm_dpci_isairq_eoi, (void *)(long)isairq);
+    }
+    write_unlock(&d->event_lock);

For symmetry with code above this could to with a blank line ahead of it.

Jan

#31 lore raw

PATCH v2 8/8 x86/iommu: make AMD-Vi and Intel VT-d support configurable

In reply to Xenia Ragiadakou

Provide the user with configuration control over the IOMMU support by making AMD_IOMMU and INTEL_IOMMU options user selectable and able to be turned off.

However, there are cases where the IOMMU support is required, for instance for a system with more than 254 CPUs. In order to prevent users from unknowingly disabling it and ending up with a broken hypervisor, make the support user selectable only if EXPERT is enabled.

To preserve the current default configuration of an x86 system, both options depend on X86 and default to Y.

---

Changes in v2:
- new patch that derives from patch 1/7 of v1
- replace --help-- with help
- make the options visible if EXPERT is enabled
- indicate the cases where the options need to be enabled

 xen/drivers/passthrough/Kconfig | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
xen/drivers/passthrough/Kconfig +20 -2
index 5c65567744..864fcf3b0c 100644
@@ -38,10 +38,28 @@ config IPMMU_VMSA
 endif
 
 config AMD_IOMMU
-	def_bool y if X86
+	bool "AMD IOMMU" if EXPERT
+	depends on X86
+	default y
+	help
+	  Enables I/O virtualization on platforms that implement the
+	  AMD I/O Virtualization Technology (IOMMU).
+
+	  If your system includes an IOMMU implementing AMD-Vi, say Y.
+	  This is required if your system has more than 254 CPUs.
+	  If in doubt, say Y.
 
 config INTEL_IOMMU
-	def_bool y if X86
+	bool "Intel VT-d" if EXPERT
+	depends on X86
+	default y
+	help
+	  Enables I/O virtualization on platforms that implement the
+	  Intel Virtualization Technology for Directed I/O (Intel VT-d).
+
+	  If your system includes an IOMMU implementing Intel VT-d, say Y.
+	  This is required if your system has more than 254 CPUs.
+	  If in doubt, say Y.
 
 config IOMMU_FORCE_PT_SHARE
 	bool
Signature · 1 line
2.37.2
Acked-by on v2 8/8
#32 lore raw

Re: [PATCH v2 8/8] x86/iommu: make AMD-Vi and Intel VT-d support configurable

Quoted 8 lines · Xenia Ragiadakou

Provide the user with configuration control over the IOMMU support by making AMD_IOMMU and INTEL_IOMMU options user selectable and able to be turned off.

However, there are cases where the IOMMU support is required, for instance for a system with more than 254 CPUs. In order to prevent users from unknowingly disabling it and ending up with a broken hypervisor, make the support user selectable only if EXPERT is enabled.

Quoted 4 lines

To preserve the current default configuration of an x86 system, both options depend on X86 and default to Y.