[kvm-unit-tests PATCH 3/3] x86:hyperv: use vp_index interacting with SynIC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hyper-V SynIC uses Hyper-V-specific processor numbering; each processor
can learn its number by reading from a dedicated synthetic MSR.
Accidentally it conincides with apic_id but this is not guaranteed in
future.

Use the value of the MSR instead of apic_id when interacting with SynIC.

Signed-off-by: Roman Kagan <rkagan@xxxxxxxxxxxxx>
---
 x86/hyperv.h |  1 +
 x86/hyperv.c | 13 +++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/x86/hyperv.h b/x86/hyperv.h
index e135221..723a2bc 100644
--- a/x86/hyperv.h
+++ b/x86/hyperv.h
@@ -12,6 +12,7 @@
 
 #define HV_X64_MSR_GUEST_OS_ID                  0x40000000
 #define HV_X64_MSR_HYPERCALL                    0x40000001
+#define HV_X64_MSR_VP_INDEX                     0x40000002
 
 #define HV_X64_MSR_TIME_REF_COUNT               0x40000020
 #define HV_X64_MSR_REFERENCE_TSC                0x40000021
diff --git a/x86/hyperv.c b/x86/hyperv.c
index 60f7645..05a175b 100644
--- a/x86/hyperv.c
+++ b/x86/hyperv.c
@@ -12,6 +12,11 @@ enum {
     HV_TEST_DEV_EVT_CONN_DESTROY,
 };
 
+static u32 vp_idx(void)
+{
+    return rdmsr(HV_X64_MSR_VP_INDEX);
+}
+
 static void synic_ctl(u32 ctl, u32 vcpu_id, u32 sint, u32 conn_id)
 {
     outl((conn_id << 24) | (ctl << 16) | (vcpu_id << 8) | sint, 0x3000);
@@ -30,7 +35,7 @@ static void sint_disable(u8 sint)
 
 void synic_sint_create(u8 sint, u8 vec, bool auto_eoi)
 {
-    synic_ctl(HV_TEST_DEV_SINT_ROUTE_CREATE, smp_id(), sint, 0);
+    synic_ctl(HV_TEST_DEV_SINT_ROUTE_CREATE, vp_idx(), sint, 0);
     sint_enable(sint, vec, auto_eoi);
 }
 
@@ -42,12 +47,12 @@ void synic_sint_set(u8 vcpu, u8 sint)
 void synic_sint_destroy(u8 sint)
 {
     sint_disable(sint);
-    synic_ctl(HV_TEST_DEV_SINT_ROUTE_DESTROY, smp_id(), sint, 0);
+    synic_ctl(HV_TEST_DEV_SINT_ROUTE_DESTROY, vp_idx(), sint, 0);
 }
 
 void msg_conn_create(u8 sint, u8 vec, u8 conn_id)
 {
-    synic_ctl(HV_TEST_DEV_MSG_CONN_CREATE, smp_id(), sint, conn_id);
+    synic_ctl(HV_TEST_DEV_MSG_CONN_CREATE, vp_idx(), sint, conn_id);
     sint_enable(sint, vec, true);
 }
 
@@ -59,7 +64,7 @@ void msg_conn_destroy(u8 sint, u8 conn_id)
 
 void evt_conn_create(u8 sint, u8 vec, u8 conn_id)
 {
-    synic_ctl(HV_TEST_DEV_EVT_CONN_CREATE, smp_id(), sint, conn_id);
+    synic_ctl(HV_TEST_DEV_EVT_CONN_CREATE, vp_idx(), sint, conn_id);
     sint_enable(sint, vec, true);
 }
 
-- 
2.17.0




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux