Skip to contentSkip to conversation

x86/hvm: Extend HVM cpuid leaf with vcpu id

PATCH In review Paul Durrant 2 participants 3 messages Nov 6, 2014 – Dec 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/hvm: Extend HVM cpuid leaf with vcpu id

To perform certain hypercalls HVM guests need to use Xen's idea of vcpu id, which may well not match the guest OS idea of CPU id. This patch adds vcpu id to the HVM cpuid leaf allowing the guest to build a mapping.

---
 xen/arch/x86/hvm/hvm.c              |    4 ++++
 xen/include/public/arch-x86/cpuid.h |    5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/hvm.c +4 -0
index 78f519d..d9a5706 100644
@@ -4189,6 +4189,10 @@ void hvm_hypervisor_cpuid_leaf(uint32_t sub_idx,
          * foreign pages) has valid IOMMU entries.
          */
         *eax |= XEN_HVM_CPUID_IOMMU_MAPPINGS;
+
+        /* Indicate presence of vcpu id and set it in ebx */
+        *eax |= XEN_HVM_CPUID_VCPU_ID_PRESENT;
+        *ebx = current->vcpu_id;
     }
 }
 
xen/include/public/arch-x86/cpuid.h +3 -2
index 6005dfe..d709340 100644
@@ -76,13 +76,14 @@
 /*
  * Leaf 5 (0x40000x04)
  * HVM-specific features
+ * EAX: Features
+ * EBX: vcpu id (iff EAX has XEN_HVM_CPUID_VCPU_ID_PRESENT flag)
  */
-
-/* EAX Features */
 #define XEN_HVM_CPUID_APIC_ACCESS_VIRT (1u << 0) /* Virtualized APIC registers */
 #define XEN_HVM_CPUID_X2APIC_VIRT      (1u << 1) /* Virtualized x2APIC accesses */
 /* 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_CPUID_MAX_NUM_LEAVES 4
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · Paul Durrant

To perform certain hypercalls HVM guests need to use Xen's idea of vcpu id, which may well not match the guest OS idea of CPU id. This patch adds vcpu id to the HVM cpuid leaf allowing the guest to build a mapping.

One more tangent on this, since this is partially considered in a Windows context. Why not use the existing Viridian virtual processor index MSR for this, since that would work on Xen today.

xen/arch/x86/hvm/viridian.c:

Quoted 6 lines

#define VIRIDIAN_MSR_VP_INDEX 0x40000002
...

    case VIRIDIAN_MSR_VP_INDEX:
       perfc_incr(mshv_rdmsr_vp_index);
       *val = v->vcpu_id;
       break;

--msw

#2 lore raw
Quoted 14 lines

-----Original Message-----
From: Matt Wilson [mailto:[email protected]] On Behalf Of Matt Wilson
Sent: 11 December 2014 23:17
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org); Jan Beulich
Subject: Re: [Xen-devel] [PATCH v2] x86/hvm: Extend HVM cpuid leaf with vcpu id

Quoted 4 lines · Paul Durrant

To perform certain hypercalls HVM guests need to use Xen's idea of vcpu id, which may well not match the guest OS idea of CPU id. This patch adds vcpu id to the HVM cpuid leaf allowing the guest to build a mapping.

Quoted 12 lines

One more tangent on this, since this is partially considered in a Windows context. Why not use the existing Viridian virtual processor index MSR for this, since that would work on Xen today.

xen/arch/x86/hvm/viridian.c:

Quoted 6 lines

#define VIRIDIAN_MSR_VP_INDEX 0x40000002
...

    case VIRIDIAN_MSR_VP_INDEX:
       perfc_incr(mshv_rdmsr_vp_index);
       *val = v->vcpu_id;
       break;

Yes, that would work for VMs where viridian is enabled, but there's no requirement that viridian is enabled to install PV drivers even in Windows. I guess ACPI is the only robust way to get vcpu id in an HVM guest in the absence of the new cpuid leaf.

Paul

Quoted 1 line

--msw