Skip to contentSkip to conversation

xen/x86: use extended destination mode if available

PATCH In review Roger Pau Monne 3 participants 8 messages Jan 20, 2022 – Feb 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover xen/x86: use extended destination mode if available

Hello,

Following two patches enable the usage of the extended destination ID if supported by Xen. This is the same feature already supported by QEMU/KVM and HyperV.

First patch can probably go in regardless of whether Xen ends up implementing the extended destination ID, there's no reason to prevent a VM from using x2APIC mode.

Thanks, Roger.

Roger Pau Monne (2):
xen/x2apic: enable x2apic mode when supported xen/x86: detect support for extended destination ID

 arch/x86/include/asm/xen/cpuid.h | 7 +++++++
 arch/x86/xen/enlighten_hvm.c     | 9 ++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 xen/x2apic: enable x2apic mode when supported

There's no point in disabling x2APIC mode when running as a Xen HVM guest, just enable it when available.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/xen/enlighten_hvm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/enlighten_hvm.c +2 -1
index 42300941ec29..ab8171cbee23 100644
@@ -9,6 +9,7 @@
 #include <xen/events.h>
 #include <xen/interface/memory.h>
 
+#include <asm/apic.h>
 #include <asm/cpu.h>
 #include <asm/smp.h>
 #include <asm/io_apic.h>
@@ -248,7 +249,7 @@ bool __init xen_hvm_need_lapic(void)
 		return false;
 	if (!xen_hvm_domain())
 		return false;
-	if (xen_feature(XENFEAT_hvm_pirqs) && xen_have_vector_callback)
+	if (!x2apic_supported())
 		return false;
 	return true;
 }
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] xen/x2apic: enable x2apic mode when supported

Quoted 32 lines · Roger Pau Monne

There's no point in disabling x2APIC mode when running as a Xen HVM guest, just enable it when available.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
  arch/x86/xen/enlighten_hvm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/enlighten_hvm.c +1 -0
index 42300941ec29..ab8171cbee23 100644
@@ -9,6 +9,7 @@
  #include <xen/events.h>
  #include <xen/interface/memory.h>
 
+#include <asm/apic.h>
  #include <asm/cpu.h>
  #include <asm/smp.h>
  #include <asm/io_apic.h>

arch/x86/xen/enlighten_hvm.c bool __init xen_hvm_need_lapic(void) · line 255

Quoted 8 lines
arch/x86/xen/enlighten_hvm.c +1 -1
@@ -248,7 +249,7 @@ bool __init xen_hvm_need_lapic(void)
  		return false;
  	if (!xen_hvm_domain())
  		return false;
-	if (xen_feature(XENFEAT_hvm_pirqs) && xen_have_vector_callback)
+	if (!x2apic_supported())
  		return false;
  	return true;
  }

Then it seems this whole routine can be reduced to just

	return x2apic_supported();

and then dropped altogether and x2apic_supported() moved to xen_x2apic_para_available(). Domain type checks here are not really needed since this can only be called on HVM guests.

-boris

#3 lore raw

PATCH 1/1 xen/x2apic: enable x2apic mode when supported for HVM

There's no point in disabling x2APIC mode when running as a Xen HVM guest, just enable it when available.

Remove some unneeded wrapping around the detection functions, and simply provide a xen_x2apic_available helper that's a wrapper around x2apic_supported.

---
Changes since v1:
- Remove useless code around x2APIC detection for Xen.
---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/xen/hypervisor.h | 14 --------------
 arch/x86/xen/enlighten_hvm.c          | 13 ++++---------
 2 files changed, 4 insertions(+), 23 deletions(-)
arch/x86/include/asm/xen/hypervisor.h +0 -14
index 1bf2ad34188a..16f548a661cf 100644
@@ -43,20 +43,6 @@ static inline uint32_t xen_cpuid_base(void)
 	return hypervisor_cpuid_base("XenVMMXenVMM", 2);
 }
 
-#ifdef CONFIG_XEN
-extern bool __init xen_hvm_need_lapic(void);
-
-static inline bool __init xen_x2apic_para_available(void)
-{
-	return xen_hvm_need_lapic();
-}
-#else
-static inline bool __init xen_x2apic_para_available(void)
-{
-	return (xen_cpuid_base() != 0);
-}
-#endif
-
 struct pci_dev;
 
 #ifdef CONFIG_XEN_PV_DOM0
arch/x86/xen/enlighten_hvm.c +4 -9
index 42300941ec29..6448c5071117 100644
@@ -9,6 +9,7 @@
 #include <xen/events.h>
 #include <xen/interface/memory.h>
 
+#include <asm/apic.h>
 #include <asm/cpu.h>
 #include <asm/smp.h>
 #include <asm/io_apic.h>
@@ -242,15 +243,9 @@ static __init int xen_parse_no_vector_callback(char *arg)
 }
 early_param("xen_no_vector_callback", xen_parse_no_vector_callback);
 
-bool __init xen_hvm_need_lapic(void)
+static __init bool xen_x2apic_available(void)
 {
-	if (xen_pv_domain())
-		return false;
-	if (!xen_hvm_domain())
-		return false;
-	if (xen_feature(XENFEAT_hvm_pirqs) && xen_have_vector_callback)
-		return false;
-	return true;
+	return x2apic_supported();
 }
 
 static __init void xen_hvm_guest_late_init(void)
@@ -312,7 +307,7 @@ struct hypervisor_x86 x86_hyper_xen_hvm __initdata = {
 	.detect                 = xen_platform_hvm,
 	.type			= X86_HYPER_XEN_HVM,
 	.init.init_platform     = xen_hvm_guest_init,
-	.init.x2apic_available  = xen_x2apic_para_available,
+	.init.x2apic_available  = xen_x2apic_available,
 	.init.init_mem_mapping	= xen_hvm_init_mem_mapping,
 	.init.guest_late_init	= xen_hvm_guest_late_init,
 	.runtime.pin_vcpu       = xen_pin_vcpu,
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] xen/x2apic: enable x2apic mode when supported for HVM

Quoted 8 lines · Roger Pau Monne

There's no point in disabling x2APIC mode when running as a Xen HVM guest, just enable it when available.

Remove some unneeded wrapping around the detection functions, and simply provide a xen_x2apic_available helper that's a wrapper around x2apic_supported.

maintainer Applied
#5 lore raw

Re: [PATCH] xen/x2apic: enable x2apic mode when supported for HVM

In reply to Roger Pau Monne
Quoted 8 lines · Roger Pau Monne

There's no point in disabling x2APIC mode when running as a Xen HVM guest, just enable it when available.

Remove some unneeded wrapping around the detection functions, and simply provide a xen_x2apic_available helper that's a wrapper around x2apic_supported.

Pushed to xen/tip.git for-linus-5.17a

Juergen

#6 lore raw

PATCH 2/2 xen/x86: detect support for extended destination ID

In reply to Roger Pau Monne

Xen allows the usage of some previously reserved bits in the IO-APIC RTE and the MSI address fields in order to store high bits for the target APIC ID. Such feature is already implemented by QEMU/KVM and HyperV, so in order to enable it just add the handler that checks for it's presence.

---
Must not be applied until the public headers are changed in Xen.
---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: [email protected]

---
 arch/x86/include/asm/xen/cpuid.h | 7 +++++++
 arch/x86/xen/enlighten_hvm.c     | 6 ++++++
 2 files changed, 13 insertions(+)
arch/x86/include/asm/xen/cpuid.h +7 -0
index a9630104f1c4..78e667a31d6c 100644
@@ -100,6 +100,13 @@
 /* Memory mapped from other domains has valid IOMMU entries */
 #define XEN_HVM_CPUID_IOMMU_MAPPINGS   (1u << 2)
 #define XEN_HVM_CPUID_VCPU_ID_PRESENT  (1u << 3) /* vcpu id is present in EBX */
+#define XEN_HVM_CPUID_DOMID_PRESENT    (1u << 4) /* domid is present in ECX */
+/*
+ * Bits 55:49 from the IO-APIC RTE and bits 11:5 from the MSI address can be
+ * used to store high bits for the Destination ID. This expands the Destination
+ * ID field from 8 to 15 bits, allowing to target APIC IDs up 32768.
+ */
+#define XEN_HVM_CPUID_EXT_DEST_ID      (1u << 5)
 
 /*
  * Leaf 6 (0x40000x05)
arch/x86/xen/enlighten_hvm.c +6 -0
index ab8171cbee23..0c5b0ee3a02a 100644
@@ -254,6 +254,11 @@ bool __init xen_hvm_need_lapic(void)
 	return true;
 }
 
+static bool __init msi_ext_dest_id(void)
+{
+       return cpuid_eax(xen_cpuid_base() + 4) & XEN_HVM_CPUID_EXT_DEST_ID;
+}
+
 static __init void xen_hvm_guest_late_init(void)
 {
 #ifdef CONFIG_XEN_PVH
@@ -316,6 +321,7 @@ struct hypervisor_x86 x86_hyper_xen_hvm __initdata = {
 	.init.x2apic_available  = xen_x2apic_para_available,
 	.init.init_mem_mapping	= xen_hvm_init_mem_mapping,
 	.init.guest_late_init	= xen_hvm_guest_late_init,
+	.init.msi_ext_dest_id   = msi_ext_dest_id,
 	.runtime.pin_vcpu       = xen_pin_vcpu,
 	.ignore_nopv            = true,
 };
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] xen/x86: detect support for extended destination ID

Quoted 7 lines · Roger Pau Monne

Xen allows the usage of some previously reserved bits in the IO-APIC RTE and the MSI address fields in order to store high bits for the target APIC ID. Such feature is already implemented by QEMU/KVM and HyperV, so in order to enable it just add the handler that checks for it's presence.

Juergen