Skip to contentSkip to conversation

hyperv: own protocol header instead of kernel's

PATCH Applied Roman Kagan 2 participants 5 messages Jul 13, 2017 – Sep 12, 2017

lore
Share & tools
lore
#0 lore raw

cover hyperv: own protocol header instead of kernel's

Supersede kernel's header for Hyper-V protocol definitions with our own. The reason is that, since this is a third-party protocol and not a kernel API, the kernel folks are not happy exposing it in the kernel uapi.

The patchset is done to allow gradual transition from the kernel's hyperv.h to the new one: the first patch introduces the new header that doesn't conflict with the old one, and the second makes sure the old one isn't imported from the kernel any longer, so that the maintainers can do the next round of kernel header import at their leisure and things will keep working.

Once (if) this lands in QEMU I'll post patches to KVM to move its hyperv.h out of uapi.

This is the first part split out of my former biggish "hyperv fixes and enhancements" series. The only change is the underscore replaced with a dash in the header file name.

Roman Kagan (2):
hyperv: add header with protocol definitions
update-linux-headers: prepare for hyperv.h removal

 target/i386/cpu.h               |  10 +-
 target/i386/hyperv-proto.h      | 257 ++++++++++++++++++++++++++++++++++++++++
 target/i386/cpu.c               |   4 +-
 target/i386/hyperv.c            |   6 +-
 target/i386/kvm.c               |  57 +++++----
 target/i386/machine.c           |  15 +--
 scripts/update-linux-headers.sh |   4 +-
 7 files changed, 304 insertions(+), 49 deletions(-)
 create mode 100644 target/i386/hyperv-proto.h
Signature · 1 line
2.13.0
#2 lore raw

PATCH 2/2 update-linux-headers: prepare for hyperv.h removal

All definitions related to Hyper-V emulation are now taken from the QEMU own header, so the one imported from the kernel is no longer needed.

Unfortunately it's included by kvm_para.h.

So, until this is fixed in the kernel, teach the header harvesting script to substitute kernel's hyperv.h with a dummy.

---
 scripts/update-linux-headers.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/update-linux-headers.sh +3 -1
index 2f906c4d16..ad80fe3fca 100755
@@ -104,7 +104,9 @@ for arch in $ARCHLIST; do
         cp "$tmpdir/include/asm/unistd-common.h" "$output/linux-headers/asm-arm/"
     fi
     if [ $arch = x86 ]; then
-        cp_portable "$tmpdir/include/asm/hyperv.h" "$output/include/standard-headers/asm-x86/"
+        cat <<-EOF >"$output/include/standard-headers/asm-x86/hyperv.h"
+        /* this is a temporary placeholder until kvm_para.h stops including it */
+        EOF
         cp "$tmpdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/"
         cp "$tmpdir/include/asm/unistd_x32.h" "$output/linux-headers/asm-x86/"
         cp "$tmpdir/include/asm/unistd_64.h" "$output/linux-headers/asm-x86/"
Signature · 1 line
2.13.0
#1 lore raw

PATCH 1/2 hyperv: add header with protocol definitions

In reply to Roman Kagan

The definitions for Hyper-V emulation are currently taken from a header imported from the Linux kernel.

However, as these describe a third-party protocol rather than a kernel API, it probably wasn't a good idea to publish it in the kernel uapi.

This patch introduces a header that provides all the necessary definitions, superseding the one coming from the kernel.

The new header supports (temporary) coexistence with the kernel one. The constants explicitly named in the Hyper-V specification (e.g. msr numbers) are defined in a non-conflicting way. Other constants and types have got new names.

While at this, the protocol data structures are defined in a more conventional way, without bitfields, enums, and excessive unions.

The code using this stuff is adjusted, too; it can now be built both with and without the kernel header in the tree.

---
 target/i386/cpu.h          |  10 +-
 target/i386/hyperv-proto.h | 257 +++++++++++++++++++++++++++++++++++++++++++++
 target/i386/cpu.c          |   4 +-
 target/i386/hyperv.c       |   6 +-
 target/i386/kvm.c          |  57 +++++-----
 target/i386/machine.c      |  15 ++-
 6 files changed, 301 insertions(+), 48 deletions(-)
 create mode 100644 target/i386/hyperv-proto.h
target/i386/cpu.h +5 -5
index 7a228afd04..b65d6a5d70 100644
@@ -22,7 +22,7 @@
 
 #include "qemu-common.h"
 #include "cpu-qom.h"
-#include "standard-headers/asm-x86/hyperv.h"
+#include "hyperv-proto.h"
 
 #ifdef TARGET_X86_64
 #define TARGET_LONG_BITS 64
@@ -1095,15 +1095,15 @@ typedef struct CPUX86State {
     uint64_t msr_hv_guest_os_id;
     uint64_t msr_hv_vapic;
     uint64_t msr_hv_tsc;
-    uint64_t msr_hv_crash_params[HV_X64_MSR_CRASH_PARAMS];
+    uint64_t msr_hv_crash_params[HV_CRASH_PARAMS];
     uint64_t msr_hv_runtime;
     uint64_t msr_hv_synic_control;
     uint64_t msr_hv_synic_version;
     uint64_t msr_hv_synic_evt_page;
     uint64_t msr_hv_synic_msg_page;
-    uint64_t msr_hv_synic_sint[HV_SYNIC_SINT_COUNT];
-    uint64_t msr_hv_stimer_config[HV_SYNIC_STIMER_COUNT];
-    uint64_t msr_hv_stimer_count[HV_SYNIC_STIMER_COUNT];
+    uint64_t msr_hv_synic_sint[HV_SINT_COUNT];
+    uint64_t msr_hv_stimer_config[HV_STIMER_COUNT];
+    uint64_t msr_hv_stimer_count[HV_STIMER_COUNT];
 
     /* exception/interrupt handling */
     int error_code;
target/i386/hyperv-proto.h new file +257 -0

257 lines not on this page · raw message

target/i386/cpu.c +2 -2
index c57177278b..d35a894825 100644
@@ -3808,12 +3808,12 @@ static GuestPanicInformation *x86_cpu_get_crash_info(CPUState *cs)
     CPUX86State *env = &cpu->env;
     GuestPanicInformation *panic_info = NULL;
 
-    if (env->features[FEAT_HYPERV_EDX] & HV_X64_GUEST_CRASH_MSR_AVAILABLE) {
+    if (env->features[FEAT_HYPERV_EDX] & HV_GUEST_CRASH_MSR_AVAILABLE) {
         panic_info = g_malloc0(sizeof(GuestPanicInformation));
 
         panic_info->type = GUEST_PANIC_INFORMATION_TYPE_HYPER_V;
 
-        assert(HV_X64_MSR_CRASH_PARAMS >= 5);
+        assert(HV_CRASH_PARAMS >= 5);
         panic_info->u.hyper_v.arg1 = env->msr_hv_crash_params[0];
         panic_info->u.hyper_v.arg2 = env->msr_hv_crash_params[1];
         panic_info->u.hyper_v.arg3 = env->msr_hv_crash_params[2];
target/i386/hyperv.c +3 -3
index 8545574568..a050c9d2d1 100644
@@ -14,7 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
 #include "hyperv.h"
-#include "standard-headers/asm-x86/hyperv.h"
+#include "hyperv-proto.h"
 
 int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
 {
@@ -50,8 +50,8 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit)
 
         code  = exit->u.hcall.input & 0xffff;
         switch (code) {
-        case HVCALL_POST_MESSAGE:
-        case HVCALL_SIGNAL_EVENT:
+        case HV_POST_MESSAGE:
+        case HV_SIGNAL_EVENT:
         default:
             exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE;
             return 0;
target/i386/kvm.c +28 -29

155 lines not on this page · raw message

target/i386/machine.c +6 -9
index eab33725a3..29cc58eda9 100644
@@ -587,7 +587,7 @@ static bool hyperv_crash_enable_needed(void *opaque)
     CPUX86State *env = &cpu->env;
     int i;
 
-    for (i = 0; i < HV_X64_MSR_CRASH_PARAMS; i++) {
+    for (i = 0; i < HV_CRASH_PARAMS; i++) {
         if (env->msr_hv_crash_params[i]) {
             return true;
         }
@@ -601,8 +601,7 @@ static const VMStateDescription vmstate_msr_hyperv_crash = {
     .minimum_version_id = 1,
     .needed = hyperv_crash_enable_needed,
     .fields = (VMStateField[]) {
-        VMSTATE_UINT64_ARRAY(env.msr_hv_crash_params,
-                             X86CPU, HV_X64_MSR_CRASH_PARAMS),
+        VMSTATE_UINT64_ARRAY(env.msr_hv_crash_params, X86CPU, HV_CRASH_PARAMS),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -660,8 +659,7 @@ static const VMStateDescription vmstate_msr_hyperv_synic = {
         VMSTATE_UINT64(env.msr_hv_synic_control, X86CPU),
         VMSTATE_UINT64(env.msr_hv_synic_evt_page, X86CPU),
         VMSTATE_UINT64(env.msr_hv_synic_msg_page, X86CPU),
-        VMSTATE_UINT64_ARRAY(env.msr_hv_synic_sint, X86CPU,
-                             HV_SYNIC_SINT_COUNT),
+        VMSTATE_UINT64_ARRAY(env.msr_hv_synic_sint, X86CPU, HV_SINT_COUNT),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -686,10 +684,9 @@ static const VMStateDescription vmstate_msr_hyperv_stimer = {
     .minimum_version_id = 1,
     .needed = hyperv_stimer_enable_needed,
     .fields = (VMStateField[]) {
-        VMSTATE_UINT64_ARRAY(env.msr_hv_stimer_config,
-                             X86CPU, HV_SYNIC_STIMER_COUNT),
-        VMSTATE_UINT64_ARRAY(env.msr_hv_stimer_count,
-                             X86CPU, HV_SYNIC_STIMER_COUNT),
+        VMSTATE_UINT64_ARRAY(env.msr_hv_stimer_config, X86CPU,
+                             HV_STIMER_COUNT),
+        VMSTATE_UINT64_ARRAY(env.msr_hv_stimer_count, X86CPU, HV_STIMER_COUNT),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
2.13.0
#3 lore raw
In reply to Roman Kagan
Quoted 23 lines · Roman Kagan

Supersede kernel's header for Hyper-V protocol definitions with our own. The reason is that, since this is a third-party protocol and not a kernel API, the kernel folks are not happy exposing it in the kernel uapi.

The patchset is done to allow gradual transition from the kernel's hyperv.h to the new one: the first patch introduces the new header that doesn't conflict with the old one, and the second makes sure the old one isn't imported from the kernel any longer, so that the maintainers can do the next round of kernel header import at their leisure and things will keep working.

Once (if) this lands in QEMU I'll post patches to KVM to move its hyperv.h out of uapi.

This is the first part split out of my former biggish "hyperv fixes and enhancements" series. The only change is the underscore replaced with a dash in the header file name.

Roman Kagan (2):
hyperv: add header with protocol definitions
update-linux-headers: prepare for hyperv.h removal

Quoted 14 lines
 target/i386/cpu.h               |  10 +-
 target/i386/hyperv-proto.h      | 257 ++++++++++++++++++++++++++++++++++++++++
 target/i386/cpu.c               |   4 +-
 target/i386/hyperv.c            |   6 +-
 target/i386/kvm.c               |  57 +++++----
 target/i386/machine.c           |  15 +--
 scripts/update-linux-headers.sh |   4 +-
 7 files changed, 304 insertions(+), 49 deletions(-)
 create mode 100644 target/i386/hyperv-proto.h
Signature · 1 line
2.13.0

Ping?

Roman.

#4 lore raw
Quoted 13 lines · Roman Kagan
Quoted 12 lines · Roman Kagan

Supersede kernel's header for Hyper-V protocol definitions with our own. The reason is that, since this is a third-party protocol and not a kernel API, the kernel folks are not happy exposing it in the kernel uapi.

The patchset is done to allow gradual transition from the kernel's hyperv.h to the new one: the first patch introduces the new header that doesn't conflict with the old one, and the second makes sure the old one isn't imported from the kernel any longer, so that the maintainers can do the next round of kernel header import at their leisure and things will keep working.

Quoted 6 lines
Quoted 6 lines

Once (if) this lands in QEMU I'll post patches to KVM to move its hyperv.h out of uapi.

This is the first part split out of my former biggish "hyperv fixes and enhancements" series. The only change is the underscore replaced with a dash in the header file name.

Queued, thanks.

Paolo

Quoted 23 lines
Quoted 4 lines

Roman Kagan (2):
hyperv: add header with protocol definitions
update-linux-headers: prepare for hyperv.h removal

Quoted 14 lines
 target/i386/cpu.h               |  10 +-
 target/i386/hyperv-proto.h      | 257 ++++++++++++++++++++++++++++++++++++++++
 target/i386/cpu.c               |   4 +-
 target/i386/hyperv.c            |   6 +-
 target/i386/kvm.c               |  57 +++++----
 target/i386/machine.c           |  15 +--
 scripts/update-linux-headers.sh |   4 +-
 7 files changed, 304 insertions(+), 49 deletions(-)
 create mode 100644 target/i386/hyperv-proto.h
Signature · 1 line
2.13.0

Ping?

Roman.