Skip to contentSkip to conversation

x86: extended destination ID support

PATCH In review Roger Pau Monne 4 participants 19 messages Feb 16, 2022 – Feb 21, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover x86: extended destination ID support

Hello,

The following series provide a tentative implementation of extended destination ID support for HVM/PVH guests. A specification for the feature can be found at:

http://david.woodhou.se/15-bit-msi.pdf

Patch 4 is the one I'm having more doubts about: it's the best thing I could come up in order for emulators to signal Xen whether they support parsing the extended destination ID in MSI message address field. This is only required for device models that support PCI passthrough:
injection of MSI interrupts from emulated devices is done using XEN_DMOP_inject_msi which already passes the MSI address and data fields to Xen for processing.

I think we should likely consider patch 1, as it would allow the OS side of this to make progress (since it's an already present feature in other hypervisors) independently of the Xen side work.

Thanks, Roger.

Roger Pau Monne (5):
x86/cpuid: add CPUID flag for Extended Destination ID support xen/vioapic: add support for the extended destination ID field x86/vmsi: add support for extended destination ID in address field x86/ioreq: report extended destination ID support by emulators x86/cpuid: expose EXT_DEST_ID feature if supported

 docs/man/xl.cfg.5.pod.in               | 10 ++++++
 tools/include/libxl.h                  |  8 +++++
 tools/libs/light/libxl_create.c        |  6 ++++
 tools/libs/light/libxl_types.idl       |  1 +
 tools/libs/light/libxl_x86.c           | 12 +++++++
 tools/xl/xl_parse.c                    |  3 ++
 xen/arch/arm/ioreq.c                   |  5 +++
 xen/arch/x86/domain.c                  | 10 +++++-
 xen/arch/x86/hvm/ioreq.c               |  7 +++++
 xen/arch/x86/hvm/irq.c                 |  5 ++-
 xen/arch/x86/hvm/vioapic.c             |  3 ++
 xen/arch/x86/hvm/vmsi.c                | 43 +++++++++++++++++++-------
 xen/arch/x86/include/asm/domain.h      |  3 ++
 xen/arch/x86/include/asm/hvm/hvm.h     |  5 +--
 xen/arch/x86/include/asm/msi.h         |  7 +++++
 xen/arch/x86/setup.c                   |  1 +
 xen/arch/x86/traps.c                   |  3 ++
 xen/common/ioreq.c                     |  8 +++--
 xen/drivers/passthrough/x86/hvm.c      | 11 ++++++-
 xen/drivers/vpci/msi.c                 |  2 +-
 xen/include/public/arch-x86/cpuid.h    |  6 ++++
 xen/include/public/arch-x86/hvm/save.h |  4 ++-
 xen/include/public/arch-x86/xen.h      |  2 ++
 xen/include/public/domctl.h            |  3 +-
 xen/include/public/hvm/dm_op.h         |  6 +++-
 xen/include/xen/ioreq.h                |  2 ++
 xen/include/xen/vpci.h                 |  2 +-
 27 files changed, 153 insertions(+), 25 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/5 x86/cpuid: add CPUID flag for Extended Destination ID support

Introduce the CPUID flag to be used in order to signal the support for using an extended destination ID in IO-APIC RTEs and MSI address fields. Such format expands the maximum target APIC ID from 255 to 32768 without requiring the usage of interrupt remapping.

The design document describing the feature can be found at:

http://david.woodhou.se/15-bit-msi.pdf

---
Changes since v1:
- New in this version.

---
 xen/include/public/arch-x86/cpuid.h | 6 ++++++
 1 file changed, 6 insertions(+)
xen/include/public/arch-x86/cpuid.h +6 -0
index ce46305bee..49bcc93b6b 100644
@@ -102,6 +102,12 @@
 #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)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

xen/include/public/arch-x86/cpuid.h line 110

Quoted 12 lines · Roger Pau Monne
xen/include/public/arch-x86/cpuid.h +6 -0
@@ -102,6 +102,12 @@
 #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)

Would the comment perhaps better include "in the absence of (guest visible) interrupt remapping", since otherwise the layout / meaning changes anyway? Apart from this I'd be fine with this going in ahead of the rest of this series.

Jan

#3 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
xen/include/public/arch-x86/cpuid.h +3 -0
@@ -102,6 +102,12 @@
 #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
Quoted 8 lines

xen/include/public/arch-x86/cpuid.h line 110

Quoted 3 lines
xen/include/public/arch-x86/cpuid.h +3 -0
+ * ID field from 8 to 15 bits, allowing to target APIC IDs up 32768.
+ */
+#define XEN_HVM_CPUID_EXT_DEST_ID      (1u << 5)

Would the comment perhaps better include "in the absence of (guest visible) interrupt remapping", since otherwise the layout / meaning changes anyway? Apart from this I'd be fine with this going in ahead of the rest of this series.

No, this still works even if the guest has a vIOMMU with interrupt remapping. The Compatibility Format and Remappable Format MSI messages are distinct because the low bit of the Ext Dest ID is used to indicate Remappable Format.

If you wanted to add "… without having to use interrupt remapping in the guest" to the end of the comment then I suppose you could, but I don't think it adds much.

#4 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

Quoted 20 lines · David Woodhouse
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
xen/include/public/arch-x86/cpuid.h +3 -0
@@ -102,6 +102,12 @@
 #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
Quoted 8 lines

xen/include/public/arch-x86/cpuid.h line 110

Quoted 3 lines
xen/include/public/arch-x86/cpuid.h +3 -0
+ * ID field from 8 to 15 bits, allowing to target APIC IDs up 32768.
+ */
+#define XEN_HVM_CPUID_EXT_DEST_ID      (1u << 5)

Would the comment perhaps better include "in the absence of (guest visible) interrupt remapping", since otherwise the layout / meaning changes anyway? Apart from this I'd be fine with this going in ahead of the rest of this series.

Quoted 4 lines

No, this still works even if the guest has a vIOMMU with interrupt remapping. The Compatibility Format and Remappable Format MSI messages are distinct because the low bit of the Ext Dest ID is used to indicate Remappable Format.

Well, yes, that was my point: With that bit set bits 55:49 / 11:5 change meaning. As an alternative to my initial proposal the comment could also state that bit 48 / 4 needs to be clear for this feature to take effect.

Jan

#5 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

Quoted 21 lines · Jan Beulich
Quoted 20 lines · David Woodhouse
Quoted 18 lines · Jan Beulich

xen/include/public/arch-x86/cpuid.h line 110

Quoted 12 lines · Roger Pau Monne
xen/include/public/arch-x86/cpuid.h +6 -0
@@ -102,6 +102,12 @@
 #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)

Would the comment perhaps better include "in the absence of (guest visible) interrupt remapping", since otherwise the layout / meaning changes anyway? Apart from this I'd be fine with this going in ahead of the rest of this series.

Quoted 7 lines
Quoted 4 lines

No, this still works even if the guest has a vIOMMU with interrupt remapping. The Compatibility Format and Remappable Format MSI messages are distinct because the low bit of the Ext Dest ID is used to indicate Remappable Format.

Well, yes, that was my point: With that bit set bits 55:49 / 11:5 change meaning.

Bits 55:49/11:5 become reserved again with the interrupt format bit set to remappable.

Quoted 2 lines

As an alternative to my initial proposal the comment could also state that bit 48 / 4 needs to be clear for this feature to take effect.

I've always assumed that setting the IF to remappable invalidates extended destination ID, as the format of the interrupt is different then and there's no destination ID anymore, just a handle field. Maybe I could make it more explicit:

/*
* With interrupt format set to 0 (non-remappable) 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. */

Thanks, Roger.

Reviewed-by
#6 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

Quoted 41 lines · Roger Pau Monné
Quoted 21 lines · Jan Beulich
Quoted 20 lines · David Woodhouse
Quoted 18 lines · Jan Beulich

xen/include/public/arch-x86/cpuid.h line 110

Quoted 12 lines · Roger Pau Monne
xen/include/public/arch-x86/cpuid.h +6 -0
@@ -102,6 +102,12 @@
 #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)

Would the comment perhaps better include "in the absence of (guest visible) interrupt remapping", since otherwise the layout / meaning changes anyway? Apart from this I'd be fine with this going in ahead of the rest of this series.

Quoted 7 lines
Quoted 4 lines

No, this still works even if the guest has a vIOMMU with interrupt remapping. The Compatibility Format and Remappable Format MSI messages are distinct because the low bit of the Ext Dest ID is used to indicate Remappable Format.

Well, yes, that was my point: With that bit set bits 55:49 / 11:5 change meaning.

Bits 55:49/11:5 become reserved again with the interrupt format bit set to remappable.

Quoted 2 lines

As an alternative to my initial proposal the comment could also state that bit 48 / 4 needs to be clear for this feature to take effect.

I've always assumed that setting the IF to remappable invalidates extended destination ID, as the format of the interrupt is different then and there's no destination ID anymore, just a handle field. Maybe I could make it more explicit:

Quoted 6 lines

/*
* With interrupt format set to 0 (non-remappable) 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. */

Yes, this disambiguates things enough to address my concern. Then

and I'd be fine making the adjustment while committing, if no other concerns arise.

Jan

#7 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

In reply to Roger Pau Monné
Quoted 8 lines

/*
* With interrupt format set to 0 (non-remappable) 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. */

I am not keen on that wording because it doesn't seem to fully reflect the fact that the I/OAPIC is just a device to turn line interrupts into MSIs. The values in bits 55:49 of the RTE *are* what go into bits 11:5 of the resulting MSI address. Perhaps make it more parenthetical to make it clearer that they are not independent... "bits 11:5 of the MSI address (which come from bits 55:49 of the I/OAPIC RTE)..."

Signature · 1 line
dwmw2
#8 lore raw

Re: [PATCH v2 1/5] x86/cpuid: add CPUID flag for Extended Destination ID support

Quoted 11 lines · David Woodhouse
Quoted 8 lines

/*
* With interrupt format set to 0 (non-remappable) 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. */

I am not keen on that wording because it doesn't seem to fully reflect the fact that the I/OAPIC is just a device to turn line interrupts into MSIs.

But that's an architecture implementation detail, I'm not sure I've seen this written down explicitly in any specification.

Quoted 4 lines

The values in bits 55:49 of the RTE *are* what go into bits 11:5 of the resulting MSI address. Perhaps make it more parenthetical to make it clearer that they are not independent... "bits 11:5 of the MSI address (which come from bits 55:49 of the I/OAPIC RTE)..."

That could be an option also, as long as it's clear to which bits of the IO-APIC RTE this affects.

Thanks, Roger.

#9 lore raw

PATCH v2 2/5 xen/vioapic: add support for the extended destination ID field

In reply to Roger Pau Monne

Such field uses bits 55:48, but for the purposes the register will be used use bits 55:49 instead. Bit 48 is used to signal an RTE entry is in remappable format which is not supported by the vIO-APIC.

Use the extended destination ID to store the high bits from the destination ID, thus expanding the size of the destination ID field to 15 bits, allowing an IO-APIC to target APIC IDs up to 32768. A description of the feature can be found at:

http://david.woodhou.se/15-bit-msi.pdf

Note this is already supported by QEMU/KVM and HyperV.

Introduce an option in xl.cfg to allow switching off the feature.

---
Changes since v1:
- Expand commit message, add reference document.
- Add xl option to disable the feature.

---
 docs/man/xl.cfg.5.pod.in               | 10 ++++++++++
 tools/include/libxl.h                  |  8 ++++++++
 tools/libs/light/libxl_create.c        |  6 ++++++
 tools/libs/light/libxl_types.idl       |  1 +
 tools/libs/light/libxl_x86.c           | 12 ++++++++++++
 tools/xl/xl_parse.c                    |  3 +++
 xen/arch/x86/domain.c                  | 10 +++++++++-
 xen/arch/x86/hvm/vioapic.c             |  3 +++
 xen/arch/x86/include/asm/domain.h      |  3 +++
 xen/arch/x86/setup.c                   |  1 +
 xen/include/public/arch-x86/hvm/save.h |  4 +++-
 xen/include/public/arch-x86/xen.h      |  2 ++
 xen/include/public/domctl.h            |  2 +-
 13 files changed, 62 insertions(+), 3 deletions(-)
docs/man/xl.cfg.5.pod.in +10 -0
index b98d161398..349e0b432a 100644
@@ -2901,6 +2901,16 @@ option.
 
 If using this option is necessary to fix an issue, please report a bug.
 
+=item B<ext_dest_id=BOOLEAN>
+
+(HVM/PVH only) Signal the hypervisor whether the guest should be allowed to use
+extended destination ID for interrupt messages. Such feature allow expanding
+the target APIC ID from 8 to 15bits without requiring the usage of an emulated
+IOMMU with interrupt remapping. Note this requires guest support and might not
+be exposed to the guest even if explicitly set due to other constrains.
+
+Default: enabled
+
 =back
 
 =head1 SEE ALSO
tools/include/libxl.h +8 -0
index 51a9b6cfac..35329bca50 100644
@@ -527,6 +527,14 @@
  */
 #define LIBXL_HAVE_MAX_GRANT_VERSION 1
 
+/*
+ * LIBXL_HAVE_X86_EXT_DEST_ID indicates the toolstack can signal to the
+ * hypervisor whether the domain wants to use the extended destination ID mode
+ * for interrupt messages. This is done by setting the libxl_domain_build_info
+ * arch_x86.ext_dest_id field.
+ */
+#define LIBXL_HAVE_X86_EST_DEST_ID 1
+
 /*
  * libxl ABI compatibility
  *
tools/libs/light/libxl_create.c +6 -0
index 7499922088..66ecfbdf4d 100644
@@ -2330,6 +2330,12 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
      */
     libxl_defbool_setdefault(&d_config->b_info.arch_x86.msr_relaxed, true);
 
+    /*
+     * Do not enable the extended destination ID for restored domains unless
+     * explicitly set.
+     */
+    libxl_defbool_setdefault(&d_config->b_info.arch_x86.ext_dest_id, false);
+
     return do_domain_create(ctx, d_config, domid, restore_fd, send_back_fd,
                             params, ao_how, aop_console_how);
 }
tools/libs/light/libxl_types.idl +1 -0
index 2a42da2f7d..bbfe218c48 100644
@@ -648,6 +648,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                ("vuart", libxl_vuart_type),
                               ])),
     ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool),
+                               ("ext_dest_id", libxl_defbool),
                               ])),
     # Alternate p2m is not bound to any architecture or guest type, as it is
     # supported by x86 HVM and ARM support is planned.
tools/libs/light/libxl_x86.c +12 -0
index 1feadebb18..68f4de7ea9 100644
@@ -14,6 +14,11 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
         break;
     case LIBXL_DOMAIN_TYPE_PV:
         config->arch.emulation_flags = 0;
+        if (libxl_defbool_val(d_config->b_info.arch_x86.ext_dest_id))
+        {
+            LOG(ERROR, "Extended Destination ID not supported for PV guests");
+            return ERROR_INVAL;
+        }
         break;
     default:
         abort();
@@ -22,6 +27,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
     config->arch.misc_flags = 0;
     if (libxl_defbool_val(d_config->b_info.arch_x86.msr_relaxed))
         config->arch.misc_flags |= XEN_X86_MSR_RELAXED;
+    if (libxl_defbool_val(d_config->b_info.arch_x86.ext_dest_id))
+        config->arch.misc_flags |= XEN_X86_EXT_DEST_ID;
 
     return 0;
 }
@@ -824,6 +831,8 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
 {
     libxl_defbool_setdefault(&b_info->acpi, true);
     libxl_defbool_setdefault(&b_info->arch_x86.msr_relaxed, false);
+    libxl_defbool_setdefault(&b_info->arch_x86.ext_dest_id,
+                             b_info->type != LIBXL_DOMAIN_TYPE_PV);
 }
 
 int libxl__arch_passthrough_mode_setdefault(libxl__gc *gc,
@@ -880,6 +889,9 @@ void libxl__arch_update_domain_config(libxl__gc *gc,
      */
     libxl_defbool_setdefault(&dst->b_info.arch_x86.msr_relaxed,
                     libxl_defbool_val(src->b_info.arch_x86.msr_relaxed));
+    /* Force Extended Destination ID so it's part of the migration data. */
+    libxl_defbool_setdefault(&dst->b_info.arch_x86.ext_dest_id,
+                    libxl_defbool_val(src->b_info.arch_x86.ext_dest_id));
 }
 
 /*
tools/xl/xl_parse.c +3 -0
index 117fcdcb2b..b609b76779 100644
@@ -2761,6 +2761,9 @@ skip_usbdev:
 
     xlu_cfg_get_defbool(config, "vpmu", &b_info->vpmu, 0);
 
+    xlu_cfg_get_defbool(config, "ext_dest_id", &b_info->arch_x86.ext_dest_id,
+                        0);
+
     xlu_cfg_destroy(config);
 }
 
xen/arch/x86/domain.c +9 -1
index ef1812dc14..9764f42878 100644
@@ -685,12 +685,19 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
         }
     }
 
-    if ( config->arch.misc_flags & ~XEN_X86_MSR_RELAXED )
+    if ( config->arch.misc_flags &
+         ~(XEN_X86_MSR_RELAXED | XEN_X86_EXT_DEST_ID) )
     {
         dprintk(XENLOG_INFO, "Invalid arch misc flags %#x\n",
                 config->arch.misc_flags);
         return -EINVAL;
     }
+    if ( !hvm && (config->arch.misc_flags & XEN_X86_EXT_DEST_ID) )
+    {
+        dprintk(XENLOG_INFO,
+                "Extended Destination ID only supported for HVM\n");
+        return -EINVAL;
+    }
 
     return 0;
 }
@@ -862,6 +869,7 @@ int arch_domain_create(struct domain *d,
     domain_cpu_policy_changed(d);
 
     d->arch.msr_relaxed = config->arch.misc_flags & XEN_X86_MSR_RELAXED;
+    d->arch.ext_dest_id = config->arch.misc_flags & XEN_X86_EXT_DEST_ID;
 
     return 0;
 
xen/arch/x86/hvm/vioapic.c +3 -0
index 553c0f76ef..a02bd16b4b 100644
@@ -424,6 +424,9 @@ static void vioapic_deliver(struct hvm_vioapic *vioapic, unsigned int pin)
 
     ASSERT(spin_is_locked(&d->arch.hvm.irq_lock));
 
+    if ( d->arch.ext_dest_id )
+        dest |= vioapic->redirtbl[pin].fields.virt_ext_dest_id << 8;
+
     HVM_DBG_LOG(DBG_LEVEL_IOAPIC,
                 "dest=%x dest_mode=%x delivery_mode=%x "
                 "vector=%x trig_mode=%x",
xen/arch/x86/include/asm/domain.h +3 -0
index e62e109598..83a1608212 100644
@@ -440,6 +440,9 @@ struct arch_domain
     /* Don't unconditionally inject #GP for unhandled MSRs. */
     bool msr_relaxed;
 
+    /* Use the Extended Destination ID to expand APIC ID. */
+    bool ext_dest_id;
+
     /* Emulated devices enabled bitmap. */
     uint32_t emulation_flags;
 } __cacheline_aligned;
xen/arch/x86/setup.c +1 -0
index 115f8f6517..4aaa6ebc07 100644
@@ -782,6 +782,7 @@ static struct domain *__init create_dom0(const module_t *image,
 
         dom0_cfg.arch.emulation_flags |=
             XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI;
+        dom0_cfg.arch.misc_flags |= XEN_X86_EXT_DEST_ID;
     }
 
     if ( iommu_enabled )
xen/include/public/arch-x86/hvm/save.h +3 -1
index 773a380bc2..253dc89a04 100644
@@ -376,7 +376,9 @@ union vioapic_redir_entry
         uint8_t trig_mode:1;
         uint8_t mask:1;
         uint8_t reserve:7;
-        uint8_t reserved[4];
+        uint8_t reserved[3];
+        uint8_t :1;
+        uint8_t virt_ext_dest_id:7;
         uint8_t dest_id;
     } fields;
 };
xen/include/public/arch-x86/xen.h +2 -0
index 7acd94c8eb..06d64a309f 100644
@@ -317,6 +317,8 @@ struct xen_arch_domainconfig {
  * doesn't allow the guest to read or write to the underlying MSR.
  */
 #define XEN_X86_MSR_RELAXED (1u << 0)
+/* Select whether to use Extended Destination ID for interrupt messages. */
+#define XEN_X86_EXT_DEST_ID (1u << 1)
     uint32_t misc_flags;
 };
 
xen/include/public/domctl.h +1 -1
index b85e6170b0..31ec083cb0 100644
@@ -38,7 +38,7 @@
 #include "hvm/save.h"
 #include "memory.h"
 
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000014
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000015
 
 /*
  * NB. xen_domctl.domain is an IN/OUT parameter for this operation.
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v2 2/5] xen/vioapic: add support for the extended destination ID field

Quoted 3 lines · Roger Pau Monne

Such field uses bits 55:48, but for the purposes the register will be used use bits 55:49 instead. Bit 48 is used to signal an RTE entry is in remappable format which is not supported by the vIO-APIC.

Nit: The first sentence looks to have some stray words.

tools/include/libxl.h line 536

Quoted 13 lines
tools/include/libxl.h +7 -0
@@ -527,6 +527,14 @@
  */
 #define LIBXL_HAVE_MAX_GRANT_VERSION 1
 
+/*
+ * LIBXL_HAVE_X86_EXT_DEST_ID indicates the toolstack can signal to the
+ * hypervisor whether the domain wants to use the extended destination ID mode
+ * for interrupt messages. This is done by setting the libxl_domain_build_info
+ * arch_x86.ext_dest_id field.
+ */
+#define LIBXL_HAVE_X86_EST_DEST_ID 1

Did you mean LIBXL_HAVE_X86_EXT_DEST_ID, as the comment has it?

tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 651

Quoted 7 lines
tools/libs/light/libxl_types.idl +1 -0
@@ -648,6 +648,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                ("vuart", libxl_vuart_type),
                               ])),
     ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool),
+                               ("ext_dest_id", libxl_defbool),

Let's hope there's not going to appear any other meaning of "dest ID". I would have suggested to add "apic" to the name, but this would get it a little longish for my taste.

xen/arch/x86/setup.c static struct domain *__init create_dom0(const module_t *image, · line 786

Quoted 8 lines
xen/arch/x86/setup.c +1 -0
@@ -782,6 +782,7 @@ static struct domain *__init create_dom0(const module_t *image,
 
         dom0_cfg.arch.emulation_flags |=
             XEN_X86_EMU_LAPIC | XEN_X86_EMU_IOAPIC | XEN_X86_EMU_VPCI;
+        dom0_cfg.arch.misc_flags |= XEN_X86_EXT_DEST_ID;
     }

Without any way to suppress this?

xen/include/public/domctl.h line 41

Quoted 8 lines
xen/include/public/domctl.h +1 -1
@@ -38,7 +38,7 @@
 #include "hvm/save.h"
 #include "memory.h"
 
-#define XEN_DOMCTL_INTERFACE_VERSION 0x00000014
+#define XEN_DOMCTL_INTERFACE_VERSION 0x00000015

I'm struggling to figure which binary incompatible change in here requires this bumping. Does this perhaps belong in a later patch?

Jan

#11 lore raw

PATCH v2 3/5 x86/vmsi: add support for extended destination ID in address field

In reply to Roger Pau Monne

Both QEMU/KVM and HyperV support using bits 11:5 from the MSI address field in order to store the high part of the target APIC ID. This allows expanding the maximum APIC ID usable without interrupt remapping support from 255 to 32768.

Note the interface used by QEMU for emulated devices (via the XEN_DMOP_inject_msi hypercall) already passes both the address and data fields into Xen for processing, so there's no need for any change to QEMU there.

However for PCI passthrough devices QEMU uses the XEN_DOMCTL_bind_pt_irq hypercall which does need a modification to the gflags field in order to pass an APIC destination ID greater than 255.

Take the opportunity to make the domain parameter of hvm_girq_dest_2_vcpu_id const while modifying the other function parameters. Also adjust dest_mode when touching related code to make it bool.

---
Changes since v1:
- Do not expose extended destination ID support.
- Use d->arch.ext_dest_id.
- Add comment clarifying the usage of MSI_ADDR_VIRT_EXT_DEST_ID_MASK.

---
 xen/arch/x86/hvm/irq.c             |  5 +++-
 xen/arch/x86/hvm/vmsi.c            | 43 +++++++++++++++++++++---------
 xen/arch/x86/include/asm/hvm/hvm.h |  5 ++--
 xen/arch/x86/include/asm/msi.h     |  7 +++++
 xen/drivers/passthrough/x86/hvm.c  | 11 +++++++-
 xen/drivers/vpci/msi.c             |  2 +-
 xen/include/public/domctl.h        |  1 +
 xen/include/xen/vpci.h             |  2 +-
 8 files changed, 58 insertions(+), 18 deletions(-)
xen/arch/x86/hvm/irq.c +4 -1
index 52aae4565f..e10e085a55 100644
@@ -383,7 +383,7 @@ int hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq)
 int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data)
 {
     uint32_t tmp = (uint32_t) addr;
-    uint8_t  dest = (tmp & MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT;
+    unsigned int dest = MASK_EXTR(tmp, MSI_ADDR_DEST_ID_MASK);
     uint8_t  dest_mode = !!(tmp & MSI_ADDR_DESTMODE_MASK);
     uint8_t  delivery_mode = (data & MSI_DATA_DELIVERY_MODE_MASK)
         >> MSI_DATA_DELIVERY_MODE_SHIFT;
@@ -391,6 +391,9 @@ int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data)
         >> MSI_DATA_TRIGGER_SHIFT;
     uint8_t vector = data & MSI_DATA_VECTOR_MASK;
 
+    if ( vector && d->arch.ext_dest_id )
+        dest |= MASK_EXTR(tmp, MSI_ADDR_VIRT_EXT_DEST_ID_MASK) << 8;
+
     if ( !vector )
     {
         int pirq = ((addr >> 32) & 0xffffff00) | dest;
xen/arch/x86/hvm/vmsi.c +31 -12

113 lines not on this page · raw message

xen/arch/x86/include/asm/hvm/hvm.h +3 -2
index b44bbdeb21..37e9d4c0fc 100644
@@ -270,11 +270,12 @@ uint64_t hvm_get_guest_time_fixed(const struct vcpu *v, uint64_t at_tsc);
 
 int vmsi_deliver(
     struct domain *d, int vector,
-    uint8_t dest, uint8_t dest_mode,
+    unsigned int dest, bool dest_mode,
     uint8_t delivery_mode, uint8_t trig_mode);
 struct hvm_pirq_dpci;
 void vmsi_deliver_pirq(struct domain *d, const struct hvm_pirq_dpci *);
-int hvm_girq_dest_2_vcpu_id(struct domain *d, uint8_t dest, uint8_t dest_mode);
+int hvm_girq_dest_2_vcpu_id(const struct domain *d, unsigned int dest,
+                            bool dest_mode);
 
 enum hvm_intblk
 hvm_interrupt_blocked(struct vcpu *v, struct hvm_intack intack);
xen/arch/x86/include/asm/msi.h +7 -0
index e228b0f3f3..9d9509a368 100644
@@ -54,6 +54,13 @@
 #define MSI_ADDR_DEST_ID_SHIFT		12
 #define	 MSI_ADDR_DEST_ID_MASK		0x00ff000
 #define  MSI_ADDR_DEST_ID(dest)		(((dest) << MSI_ADDR_DEST_ID_SHIFT) & MSI_ADDR_DEST_ID_MASK)
+/*
+ * Use the reserved bits 11:5 to store the high part of the APIC ID, that
+ * allows expanding the destination field from 8 to 15 bits. Note this is a
+ * feature only present in virtualized hardware and currently only exposed to
+ * guests but not used by the hypervisor itself.
+ */
+#define	 MSI_ADDR_VIRT_EXT_DEST_ID_MASK	0x0000fe0
 
 /* MAX fixed pages reserved for mapping MSIX tables. */
 #define FIX_MSIX_MAX_PAGES              512
xen/drivers/passthrough/x86/hvm.c +10 -1
index 0b37cd145b..9c42ebe17a 100644
@@ -269,7 +269,8 @@ int pt_irq_create_bind(
     {
     case PT_IRQ_TYPE_MSI:
     {
-        uint8_t dest, delivery_mode;
+        unsigned int dest;
+        bool delivery_mode;
         bool dest_mode;
         int dest_vcpu_id;
         const struct vcpu *vcpu;
@@ -346,6 +347,10 @@ int pt_irq_create_bind(
         /* Calculate dest_vcpu_id for MSI-type pirq migration. */
         dest = MASK_EXTR(pirq_dpci->gmsi.gflags,
                          XEN_DOMCTL_VMSI_X86_DEST_ID_MASK);
+        if ( d->arch.ext_dest_id )
+            dest |= MASK_EXTR(pirq_dpci->gmsi.gflags,
+                              XEN_DOMCTL_VMSI_X86_EXT_DEST_ID_MASK);
+
         dest_mode = pirq_dpci->gmsi.gflags & XEN_DOMCTL_VMSI_X86_DM_MASK;
         delivery_mode = MASK_EXTR(pirq_dpci->gmsi.gflags,
                                   XEN_DOMCTL_VMSI_X86_DELIV_MASK);
@@ -789,6 +794,10 @@ static int _hvm_dpci_msi_eoi(struct domain *d,
                                       XEN_DOMCTL_VMSI_X86_DEST_ID_MASK);
         bool dest_mode = pirq_dpci->gmsi.gflags & XEN_DOMCTL_VMSI_X86_DM_MASK;
 
+        if ( d->arch.ext_dest_id )
+            dest |= MASK_EXTR(pirq_dpci->gmsi.gflags,
+                              XEN_DOMCTL_VMSI_X86_EXT_DEST_ID_MASK);
+
         if ( vlapic_match_dest(vcpu_vlapic(current), NULL, 0, dest,
                                dest_mode) )
         {
xen/drivers/vpci/msi.c +1 -1
index 5757a7aed2..e1d8c1d6f2 100644
@@ -297,7 +297,7 @@ void vpci_dump_msi(void)
                 printk(" vectors max: %u enabled: %u\n",
                        pdev->msi_maxvec, msi->vectors);
 
-                vpci_msi_arch_print(msi);
+                vpci_msi_arch_print(msi, d);
             }
 
             msix = pdev->vpci->msix;
xen/include/public/domctl.h +1 -0
index 31ec083cb0..ba71ce1148 100644
@@ -588,6 +588,7 @@ struct xen_domctl_bind_pt_irq {
 #define XEN_DOMCTL_VMSI_X86_DELIV_MASK   0x007000
 #define XEN_DOMCTL_VMSI_X86_TRIG_MASK    0x008000
 #define XEN_DOMCTL_VMSI_X86_UNMASKED     0x010000
+#define XEN_DOMCTL_VMSI_X86_EXT_DEST_ID_MASK 0xfe0000
 
             uint64_aligned_t gtable;
         } msi;
xen/include/xen/vpci.h +1 -1
index e8ac1eb395..354b37ef9c 100644
@@ -162,7 +162,7 @@ int __must_check vpci_msi_arch_enable(struct vpci_msi *msi,
 void vpci_msi_arch_disable(struct vpci_msi *msi, const struct pci_dev *pdev);
 void vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev);
 void vpci_msi_arch_init(struct vpci_msi *msi);
-void vpci_msi_arch_print(const struct vpci_msi *msi);
+void vpci_msi_arch_print(const struct vpci_msi *msi, const struct domain *d);
 
 /* Arch-specific vPCI MSI-X helpers. */
 void vpci_msix_arch_mask_entry(struct vpci_msix_entry *entry,
Signature · 1 line
2.34.1
Reviewed-by on v2 3/5
#12 lore raw

Re: [PATCH v2 3/5] x86/vmsi: add support for extended destination ID in address field

xen/include/public/domctl.h struct xen_domctl_bind_pt_irq { · line 591

Quoted 7 lines · Roger Pau Monne
xen/include/public/domctl.h +1 -0
@@ -588,6 +588,7 @@ struct xen_domctl_bind_pt_irq {
 #define XEN_DOMCTL_VMSI_X86_DELIV_MASK   0x007000
 #define XEN_DOMCTL_VMSI_X86_TRIG_MASK    0x008000
 #define XEN_DOMCTL_VMSI_X86_UNMASKED     0x010000
+#define XEN_DOMCTL_VMSI_X86_EXT_DEST_ID_MASK 0xfe0000

I think this is what requires the interface version bump. With that moved here:

Jan

#13 lore raw

RFC PATCH v2 4/5 x86/ioreq: report extended destination ID support by emulators

In reply to Roger Pau Monne

Introduce a new arch specific field to report whether an emulator supports the Extended Destination ID field, so that the hypervisor can refrain from exposing the feature if one of the emulators doesn't support it.

---
Changes since v1:
- New in this version.
---
RFC: I find this kind of clumsy. In fact fully emulated devices should already support Extended Destination ID without any modifications, because XEN_DMOP_inject_msi gets passed the address and data fields, so the hypervisor extracts the extended destination ID from there.

PCI passthrough devices however use xc_domain_update_msi_irq and that has leaked the gflags parameter in the API, even worse the position of the flags are hardcoded in QEMU.

Should the clearing of ext_dest_id be limited to the domain using an IOMMU?

RFC: Only enable ext_dest_id if max_cpu > 128? So the device model is aware the domain must use ext_dest_id? (implies device model knows APIC ID = CPU ID * 2)

---
 xen/arch/arm/ioreq.c           | 5 +++++
 xen/arch/x86/hvm/ioreq.c       | 7 +++++++
 xen/common/ioreq.c             | 8 +++++---
 xen/include/public/hvm/dm_op.h | 6 +++++-
 xen/include/xen/ioreq.h        | 2 ++
 5 files changed, 24 insertions(+), 4 deletions(-)
xen/arch/arm/ioreq.c +5 -0
index 308650b400..7d56d022c8 100644
@@ -185,6 +185,11 @@ void arch_ioreq_domain_init(struct domain *d)
 {
 }
 
+void arch_ioreq_server_create(struct domain *d, int bufioreq_handling,
+                              ioservid_t *id, unsigned int arch_flags)
+{
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/hvm/ioreq.c +7 -0
index 02ad9db565..3276f0360d 100644
@@ -336,6 +336,13 @@ void arch_ioreq_domain_init(struct domain *d)
     register_portio_handler(d, 0xcf8, 4, hvm_access_cf8);
 }
 
+void arch_ioreq_server_create(struct domain *d, int bufioreq_handling,
+                              ioservid_t *id, unsigned int arch_flags)
+{
+    if ( !(arch_flags & X86_SUPPORTS_EXT_DEST_ID) )
+        d->arch.ext_dest_id = false;
+}
+
 /*
  * Local variables:
  * mode: C
xen/common/ioreq.c +5 -3
index 689d256544..d4d5c653c7 100644
@@ -636,7 +636,7 @@ static void ioreq_server_deinit(struct ioreq_server *s)
 }
 
 static int ioreq_server_create(struct domain *d, int bufioreq_handling,
-                               ioservid_t *id)
+                               ioservid_t *id, unsigned int arch_flags)
 {
     struct ioreq_server *s;
     unsigned int i;
@@ -681,6 +681,8 @@ static int ioreq_server_create(struct domain *d, int bufioreq_handling,
     if ( id )
         *id = i;
 
+    arch_ioreq_server_create(d, bufioreq_handling, id, arch_flags);
+
     spin_unlock_recursive(&d->ioreq_server.lock);
     domain_unpause(d);
 
@@ -1340,11 +1342,11 @@ int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op)
         *const_op = false;
 
         rc = -EINVAL;
-        if ( data->pad[0] || data->pad[1] || data->pad[2] )
+        if ( data->pad[0] || data->pad[1] )
             break;
 
         rc = ioreq_server_create(d, data->handle_bufioreq,
-                                 &data->id);
+                                 &data->id, data->arch_flags);
         break;
     }
 
xen/include/public/hvm/dm_op.h +5 -1
index fa3f083fed..c6c575328b 100644
@@ -67,7 +67,11 @@ typedef uint16_t ioservid_t;
 struct xen_dm_op_create_ioreq_server {
     /* IN - should server handle buffered ioreqs */
     uint8_t handle_bufioreq;
-    uint8_t pad[3];
+
+/* Signals Xen the emulator supports the Extended Destination ID field. */
+#define X86_SUPPORTS_EXT_DEST_ID (1u << 0)
+    uint8_t arch_flags;
+    uint8_t pad[2];
     /* OUT - server id */
     ioservid_t id;
 };
xen/include/xen/ioreq.h +2 -0
index a26614d331..f4566a1254 100644
@@ -127,6 +127,8 @@ bool arch_ioreq_server_destroy_all(struct domain *d);
 bool arch_ioreq_server_get_type_addr(const struct domain *d, const ioreq_t *p,
                                      uint8_t *type, uint64_t *addr);
 void arch_ioreq_domain_init(struct domain *d);
+void arch_ioreq_server_create(struct domain *d, int bufioreq_handling,
+                              ioservid_t *id, unsigned int arch_flags);
 
 #endif /* __XEN_IOREQ_H__ */
 
Signature · 1 line
2.34.1
#14 lore raw

Re: [PATCH v2 RFC 4/5] x86/ioreq: report extended destination ID support by emulators

Quoted 20 lines · Roger Pau Monne

Introduce a new arch specific field to report whether an emulator supports the Extended Destination ID field, so that the hypervisor can refrain from exposing the feature if one of the emulators doesn't support it.

---
Changes since v1:
- New in this version.
---
RFC: I find this kind of clumsy. In fact fully emulated devices should already support Extended Destination ID without any modifications, because XEN_DMOP_inject_msi gets passed the address and data fields, so the hypervisor extracts the extended destination ID from there.

PCI passthrough devices however use xc_domain_update_msi_irq and that has leaked the gflags parameter in the API, even worse the position of the flags are hardcoded in QEMU.

Quoted 6 lines

Should the clearing of ext_dest_id be limited to the domain using an IOMMU?

RFC: Only enable ext_dest_id if max_cpu > 128? So the device model is aware the domain must use ext_dest_id? (implies device model knows APIC ID = CPU ID * 2)

There is still only a single sync ioreq server page, so 128 vCPUs is the max possible.

Paul

#15 lore raw

Re: [PATCH v2 RFC 4/5] x86/ioreq: report extended destination ID support by emulators

Quoted 24 lines · Paul
Quoted 23 lines · Roger Pau Monne

Introduce a new arch specific field to report whether an emulator supports the Extended Destination ID field, so that the hypervisor can refrain from exposing the feature if one of the emulators doesn't support it.

---
Changes since v1:
- New in this version.
---
RFC: I find this kind of clumsy. In fact fully emulated devices should already support Extended Destination ID without any modifications, because XEN_DMOP_inject_msi gets passed the address and data fields, so the hypervisor extracts the extended destination ID from there.

PCI passthrough devices however use xc_domain_update_msi_irq and that has leaked the gflags parameter in the API, even worse the position of the flags are hardcoded in QEMU.

Should the clearing of ext_dest_id be limited to the domain using an IOMMU?

Quoted 6 lines
Quoted 3 lines

RFC: Only enable ext_dest_id if max_cpu > 128? So the device model is aware the domain must use ext_dest_id? (implies device model knows APIC ID = CPU ID * 2)

There is still only a single sync ioreq server page, so 128 vCPUs is the max possible.

Right - so device models wanting to support > 128 vCPUs will already need to be modified, and hence we could assume that any HVM guests with > 128 vCPUs is using a device model capable of handling extended destination ID?

Thanks, Roger.

#16 lore raw

Re: [PATCH v2 RFC 4/5] x86/ioreq: report extended destination ID support by emulators

Quoted 29 lines · Roger Pau Monné
Quoted 28 lines · Paul
Quoted 26 lines · Roger Pau Monne

Introduce a new arch specific field to report whether an emulator supports the Extended Destination ID field, so that the hypervisor can refrain from exposing the feature if one of the emulators doesn't support it.

---
Changes since v1:
- New in this version.
---
RFC: I find this kind of clumsy. In fact fully emulated devices should already support Extended Destination ID without any modifications, because XEN_DMOP_inject_msi gets passed the address and data fields, so the hypervisor extracts the extended destination ID from there.

PCI passthrough devices however use xc_domain_update_msi_irq and that has leaked the gflags parameter in the API, even worse the position of the flags are hardcoded in QEMU.

Should the clearing of ext_dest_id be limited to the domain using an IOMMU?

RFC: Only enable ext_dest_id if max_cpu > 128? So the device model is aware the domain must use ext_dest_id? (implies device model knows APIC ID = CPU ID * 2)

Quoted 8 lines
Quoted 2 lines

There is still only a single sync ioreq server page, so 128 vCPUs is the max possible.

Right - so device models wanting to support > 128 vCPUs will already need to be modified, and hence we could assume that any HVM guests with > 128 vCPUs is using a device model capable of handling extended destination ID?

Yes, exactly.

Paul

#17 lore raw

PATCH v2 5/5 x86/cpuid: expose EXT_DEST_ID feature if supported

In reply to Roger Pau Monne

Expose the feature if available for the domain.

---
Note: con not be committed ahead of the rest of the series.
---
Changes since v1:
- New in this version (split from previous patch).

---
 xen/arch/x86/traps.c | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/traps.c +3 -0
index 485bd66971..5b24688b07 100644
@@ -1150,6 +1150,9 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
         res->a |= XEN_HVM_CPUID_DOMID_PRESENT;
         res->c = d->domain_id;
 
+        if ( d->arch.ext_dest_id )
+            res->a |= XEN_HVM_CPUID_EXT_DEST_ID;
+
         break;
 
     case 5: /* PV-specific parameters */
Signature · 1 line
2.34.1