diff mbox

[kvm-unit-tests,2/5] hyperv: don't take vcpu where inappropriate

Message ID 20170606191959.16987-3-rkagan@virtuozzo.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roman Kagan June 6, 2017, 7:19 p.m. UTC
MSRs can not be written on a forein cpu, so the functions to create /
destroy sint routes, which also enable / disable the respective SINTs,
can only run on the current cpu.  To avoid confusion, stop taking vcpu
argument and use smp_id() internally.

While chaning the function signatures, also adjust them to be explicit
about the width of input values.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 x86/hyperv.h        |  6 +++---
 x86/hyperv.c        | 24 +++++++++++++++++-------
 x86/hyperv_stimer.c | 12 ++++--------
 x86/hyperv_synic.c  |  6 ++----
 4 files changed, 26 insertions(+), 22 deletions(-)
diff mbox

Patch

diff --git a/x86/hyperv.h b/x86/hyperv.h
index 553c588..2331325 100644
--- a/x86/hyperv.h
+++ b/x86/hyperv.h
@@ -170,9 +170,9 @@  static inline bool hv_time_ref_counter_supported(void)
     return cpuid(HYPERV_CPUID_FEATURES).a & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE;
 }
 
-void synic_sint_create(int vcpu, int sint, int vec, bool auto_eoi);
-void synic_sint_set(int vcpu, int sint);
-void synic_sint_destroy(int vcpu, int sint);
+void synic_sint_create(u8 sint, u8 vec, bool auto_eoi);
+void synic_sint_set(u8 vcpu, u8 sint);
+void synic_sint_destroy(u8 sint);
 
 struct hv_reference_tsc_page {
         uint32_t tsc_sequence;
diff --git a/x86/hyperv.c b/x86/hyperv.c
index aa55614..78f5fb5 100644
--- a/x86/hyperv.c
+++ b/x86/hyperv.c
@@ -13,20 +13,30 @@  static void synic_ctl(u32 ctl, u32 vcpu_id, u32 sint)
     outl((ctl << 16)|((vcpu_id) << 8)|sint, 0x3000);
 }
 
-void synic_sint_create(int vcpu, int sint, int vec, bool auto_eoi)
+static void sint_enable(u8 sint, u8 vec, bool auto_eoi)
 {
     wrmsr(HV_X64_MSR_SINT0 + sint,
-          (u64)vec | ((auto_eoi) ? HV_SYNIC_SINT_AUTO_EOI : 0));
-    synic_ctl(HV_TEST_DEV_SINT_ROUTE_CREATE, vcpu, sint);
+          (u64)vec | (auto_eoi ? HV_SYNIC_SINT_AUTO_EOI : 0));
 }
 
-void synic_sint_set(int vcpu, int sint)
+static void sint_disable(u8 sint)
+{
+    wrmsr(HV_X64_MSR_SINT0 + sint, 0xff | HV_SYNIC_SINT_MASKED);
+}
+
+void synic_sint_create(u8 sint, u8 vec, bool auto_eoi)
+{
+    synic_ctl(HV_TEST_DEV_SINT_ROUTE_CREATE, smp_id(), sint);
+    sint_enable(sint, vec, auto_eoi);
+}
+
+void synic_sint_set(u8 vcpu, u8 sint)
 {
     synic_ctl(HV_TEST_DEV_SINT_ROUTE_SET_SINT, vcpu, sint);
 }
 
-void synic_sint_destroy(int vcpu, int sint)
+void synic_sint_destroy(u8 sint)
 {
-    wrmsr(HV_X64_MSR_SINT0 + sint, 0xFF|HV_SYNIC_SINT_MASKED);
-    synic_ctl(HV_TEST_DEV_SINT_ROUTE_DESTROY, vcpu, sint);
+    sint_disable(sint);
+    synic_ctl(HV_TEST_DEV_SINT_ROUTE_DESTROY, smp_id(), sint);
 }
diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c
index 5292523..2ec3842 100644
--- a/x86/hyperv_stimer.c
+++ b/x86/hyperv_stimer.c
@@ -223,12 +223,10 @@  static void cpu_comp(void)
 
 static void stimer_test_prepare(void *ctx)
 {
-    int vcpu = smp_id();
-
     write_cr3((ulong)ctx);
     synic_enable();
-    synic_sint_create(vcpu, SINT1_NUM, SINT1_VEC, false);
-    synic_sint_create(vcpu, SINT2_NUM, SINT2_VEC, true);
+    synic_sint_create(SINT1_NUM, SINT1_VEC, false);
+    synic_sint_create(SINT2_NUM, SINT2_VEC, true);
     cpu_comp();
 }
 
@@ -302,11 +300,9 @@  static void stimer_test(void *ctx)
 
 static void stimer_test_cleanup(void *ctx)
 {
-    int vcpu = smp_id();
-
     stimers_shutdown();
-    synic_sint_destroy(vcpu, SINT1_NUM);
-    synic_sint_destroy(vcpu, SINT2_NUM);
+    synic_sint_destroy(SINT1_NUM);
+    synic_sint_destroy(SINT2_NUM);
     synic_disable();
     cpu_comp();
 }
diff --git a/x86/hyperv_synic.c b/x86/hyperv_synic.c
index a08e69f..e0fb6e8 100644
--- a/x86/hyperv_synic.c
+++ b/x86/hyperv_synic.c
@@ -69,7 +69,7 @@  static void synic_sints_prepare(int vcpu)
     for (i = 0; i < HV_SYNIC_SINT_COUNT; i++) {
         vec = sint_vecs[i].vec;
         auto_eoi = sint_vecs[i].auto_eoi;
-        synic_sint_create(vcpu, i, vec, auto_eoi);
+        synic_sint_create(i, vec, auto_eoi);
     }
 }
 
@@ -130,13 +130,11 @@  static void synic_test(void *ctx)
 
 static void synic_test_cleanup(void *ctx)
 {
-    int vcpu = smp_id();
     int i;
 
     irq_enable();
     for (i = 0; i < HV_SYNIC_SINT_COUNT; i++) {
-        synic_sint_destroy(vcpu, i);
-        wrmsr(HV_X64_MSR_SINT0 + i, 0xFF|HV_SYNIC_SINT_MASKED);
+        synic_sint_destroy(i);
     }
 
     wrmsr(HV_X64_MSR_SCONTROL, 0);