x86/kvm/hyper-v: add support for synthetic debugger
Subsystems (7)
v5 cover x86/kvm/hyper-v: add support for synthetic debugger
Add support for the synthetic debugger interface of hyper-v, the synthetic debugger has 2 modes.
1. Use a set of MSRs to send/recv information (undocumented so it's not going to the hyperv-tlfs.h)
2. Use hypercalls
The first mode is based the following MSRs:
1. Control/Status MSRs which either asks for a send/recv .
2. Send/Recv MSRs each holds GPA where the send/recv buffers are.
3. Pending MSR, holds a GPA to a PAGE that simply has a boolean that indicates if there is data pending to issue a recv VMEXIT.
The first mode implementation is to simply exit to user-space when either the control MSR or the pending MSR are being set.
Then it's up-to userspace to implement the rest of the logic of sending/recving.
In the second mode instead of using MSRs KNet will simply issue Hypercalls with the information to send/recv, in this mode the data being transferred is UDP encapsulated, unlike in the previous mode in which you get just the data to send.
The new hypercalls will exit to userspace which will be incharge of re-encapsulating if needed the UDP packets to be sent.
There is an issue though in which KDNet does not respect the hypercall page and simply issues vmcall/vmmcall instructions depending on the cpu type expecting them to be handled as it a real hypercall was issued.
Jon Doron (5):
x86/kvm/hyper-v: Explicitly align hcall param for kvm_hyperv_exit x86/hyper-v: Add synthetic debugger definitions x86/kvm/hyper-v: Add support for synthetic debugger capability x86/kvm/hyper-v: enable hypercalls regardless of hypercall page x86/kvm/hyper-v: Add support for synthetic debugger via hypercalls
Documentation/virt/kvm/api.rst | 18 ++++ arch/x86/include/asm/hyperv-tlfs.h | 6 ++ arch/x86/include/asm/kvm_host.h | 13 +++ arch/x86/kvm/hyperv.c | 162 ++++++++++++++++++++++++++++- arch/x86/kvm/hyperv.h | 27 +++++ arch/x86/kvm/trace.h | 51 +++++++++ arch/x86/kvm/x86.c | 9 ++ include/uapi/linux/kvm.h | 13 +++ 8 files changed, 297 insertions(+), 2 deletions(-)
Signature · 1 line
2.24.1
PATCH v5 1/5 x86/kvm/hyper-v: Explicitly align hcall param for kvm_hyperv_exit
--- Documentation/virt/kvm/api.rst | 2 ++ include/uapi/linux/kvm.h | 2 ++ 2 files changed, 4 insertions(+)
Documentation/virt/kvm/api.rst +2 -0
@@ -5025,9 +5025,11 @@ EOI was received. #define KVM_EXIT_HYPERV_SYNIC 1 #define KVM_EXIT_HYPERV_HCALL 2 __u32 type; + __u32 pad1; union { struct { __u32 msr; + __u32 pad2; __u64 control; __u64 evt_page; __u64 msg_page;
include/uapi/linux/kvm.h +2 -0
@@ -189,9 +189,11 @@ struct kvm_hyperv_exit {#define KVM_EXIT_HYPERV_SYNIC 1#define KVM_EXIT_HYPERV_HCALL 2__u32 type; +__u32 pad1;union {struct {__u32 msr; +__u32 pad2;__u64 control;__u64 evt_page;__u64 msg_page;
Signature · 1 line
2.24.1
PATCH v5 2/5 x86/hyper-v: Add synthetic debugger definitions
In reply to Jon DoronHyper-V synthetic debugger has two modes, one that uses MSRs and the other that use Hypercalls.
Add all the required definitions to both types of synthetic debugger interface.
Some of the required new CPUIDs and MSRs are not documented in the TLFS so they are in hyperv.h instead.
--- arch/x86/include/asm/hyperv-tlfs.h | 6 ++++++ arch/x86/kvm/hyperv.h | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)
arch/x86/include/asm/hyperv-tlfs.h +6 -0
@@ -131,6 +131,8 @@#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)/* Crash MSR available */ #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10) +/* Support for debug MSRs available */ +#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11)/* stimer Direct Mode is available */ #define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19)
@@ -376,6 +378,9 @@ struct hv_tsc_emulation_status {#define HVCALL_SEND_IPI_EX 0x0015#define HVCALL_POST_MESSAGE 0x005c#define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_POST_DEBUG_DATA 0x0069 +#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a +#define HVCALL_RESET_DEBUG_SESSION 0x006b#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
@@ -419,6 +424,7 @@ enum HV_GENERIC_SET_FORMAT {#define HV_STATUS_INVALID_HYPERCALL_INPUT 3#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INVALID_PARAMETER 5 +#define HV_STATUS_OPERATION_DENIED 8#define HV_STATUS_INSUFFICIENT_MEMORY 11#define HV_STATUS_INVALID_PORT_ID 17#define HV_STATUS_INVALID_CONNECTION_ID 18
arch/x86/kvm/hyperv.h +22 -0
@@ -23,6 +23,28 @@#include <linux/kvm_host.h> +/* These defines are required by KDNet and they are not part of Hyper-V TLFS */ +#define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 0x40000080 +#define HYPERV_CPUID_SYNDBG_INTERFACE 0x40000081 +#define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 0x40000082 + +/* +* Hyper-V synthetic debugger platform capabilities +* These are HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits. +*/ +#define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING BIT(1) + +/* Hyper-V Synthetic debug options MSR */ +#define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1 +#define HV_X64_MSR_SYNDBG_STATUS 0x400000F2 +#define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3 +#define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4 +#define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5 +#define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF + +/* Hyper-V HV_X64_MSR_SYNDBG_OPTIONS bits */ +#define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2) +static inline struct kvm_vcpu_hv *vcpu_to_hv_vcpu (struct kvm_vcpu *vcpu) {return &vcpu->arch.hyperv;
Signature · 1 line
2.24.1
RE: [PATCH v5 2/5] x86/hyper-v: Add synthetic debugger definitions
From: Jon Doron <[email protected]> Sent: Friday, March 13, 2020 6:21 AM
Quoted 52 lines
Hyper-V synthetic debugger has two modes, one that uses MSRs and the other that use Hypercalls.
Add all the required definitions to both types of synthetic debugger interface.
Some of the required new CPUIDs and MSRs are not documented in the TLFS so they are in
hyperv.hinstead.Signed-off-by Jon Doron <[email protected]>--- arch/x86/include/asm/hyperv-tlfs.h | 6 ++++++ arch/x86/kvm/hyperv.h | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)arch/x86/include/asm/hyperv-tlfs.h +6
-0@@ -131,6 +131,8 @@#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)/* Crash MSR available */ #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10) +/* Support for debug MSRs available */ +#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11)/* stimer Direct Mode is available */ #define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19)@@ -376,6 +378,9 @@ struct hv_tsc_emulation_status {#define HVCALL_SEND_IPI_EX 0x0015#define HVCALL_POST_MESSAGE 0x005c#define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_POST_DEBUG_DATA 0x0069 +#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a +#define HVCALL_RESET_DEBUG_SESSION 0x006b#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0@@ -419,6 +424,7 @@ enum HV_GENERIC_SET_FORMAT {#define HV_STATUS_INVALID_HYPERCALL_INPUT 3#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INVALID_PARAMETER 5 +#define HV_STATUS_OPERATION_DENIED 8#define HV_STATUS_INSUFFICIENT_MEMORY 11#define HV_STATUS_INVALID_PORT_ID 17#define HV_STATUS_INVALID_CONNECTION_ID 18arch/x86/kvm/hyperv.h +0
-0
arch/x86/kvm/hyperv.h line 26
Quoted 4 lines
arch/x86/kvm/hyperv.h +1
-0@@ -23,6 +23,28 @@#include <linux/kvm_host.h> +/* These defines are required by KDNet and they are not part of Hyper-V TLFS */
I'm looking for a bit more info in the comment so that it's clear that the synthetic debugger functionality is not committed to be available going forward. Perhaps something along the lines of:
/* The #defines related to the synthetic debugger are required by KDNet, but
* they are not documented in the Hyper-V TLFS because the synthetic debugger
* functionality has been deprecated and is subject to removal in future versions
* of Windows.
*/
But with that additional comment text,
Quoted 26 lines
arch/x86/kvm/hyperv.h +21
-1+#define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 0x40000080 +#define HYPERV_CPUID_SYNDBG_INTERFACE 0x40000081 +#define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 0x40000082 + +/* +* Hyper-V synthetic debugger platform capabilities +* These are HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits. +*/ +#define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING BIT(1) + +/* Hyper-V Synthetic debug options MSR */ +#define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1 +#define HV_X64_MSR_SYNDBG_STATUS 0x400000F2 +#define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3 +#define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4 +#define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5 +#define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF + +/* Hyper-V HV_X64_MSR_SYNDBG_OPTIONS bits */ +#define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2) +static inline struct kvm_vcpu_hv *vcpu_to_hv_vcpu (struct kvm_vcpu *vcpu) {return &vcpu->arch.hyperv; --2.24.1
Re: [PATCH v5 2/5] x86/hyper-v: Add synthetic debugger definitions
Quoted 68 lines · Michael Kelley
From: Jon Doron <[email protected]> Sent: Friday, March 13, 2020 6:21 AM
Quoted 52 lines
Hyper-V synthetic debugger has two modes, one that uses MSRs and the other that use Hypercalls.
Add all the required definitions to both types of synthetic debugger interface.
Some of the required new CPUIDs and MSRs are not documented in the TLFS so they are in
hyperv.hinstead.Signed-off-by Jon Doron <[email protected]>--- arch/x86/include/asm/hyperv-tlfs.h | 6 ++++++ arch/x86/kvm/hyperv.h | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)arch/x86/include/asm/hyperv-tlfs.h +6
-0@@ -131,6 +131,8 @@#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)/* Crash MSR available */ #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10) +/* Support for debug MSRs available */ +#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11)/* stimer Direct Mode is available */ #define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19)@@ -376,6 +378,9 @@ struct hv_tsc_emulation_status {#define HVCALL_SEND_IPI_EX 0x0015#define HVCALL_POST_MESSAGE 0x005c#define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_POST_DEBUG_DATA 0x0069 +#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a +#define HVCALL_RESET_DEBUG_SESSION 0x006b#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0@@ -419,6 +424,7 @@ enum HV_GENERIC_SET_FORMAT {#define HV_STATUS_INVALID_HYPERCALL_INPUT 3#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INVALID_PARAMETER 5 +#define HV_STATUS_OPERATION_DENIED 8#define HV_STATUS_INSUFFICIENT_MEMORY 11#define HV_STATUS_INVALID_PORT_ID 17#define HV_STATUS_INVALID_CONNECTION_ID 18arch/x86/kvm/hyperv.h +0
-0arch/x86/kvm/hyperv.h line 26
Quoted 4 lines
arch/x86/kvm/hyperv.h +1
-0@@ -23,6 +23,28 @@#include <linux/kvm_host.h> +/* These defines are required by KDNet and they are not part of Hyper-V TLFS */ I'm looking for a bit more info in the comment so that it's clear that the synthetic debugger functionality is not committed to be available going forward. Perhaps something along the lines of:
/* The #defines related to the synthetic debugger are required by KDNet, but
* they are not documented in the Hyper-V TLFS because the synthetic debugger
* functionality has been deprecated and is subject to removal in future versions
* of Windows.
*/
Quoted 4 lines
But with that additional comment text,
Reviewed-by Michael Kelley <[email protected]>
Sure thing, but one quick question I have noticed that in the 6.0 TLFS the bit indicating the DEBUG_MSRS are available is still documented is that intentional or a juss a miss?
Cheers,
-- Jon.
Quoted 27 lines
Quoted 26 lines
arch/x86/kvm/hyperv.h +21
-1+#define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 0x40000080 +#define HYPERV_CPUID_SYNDBG_INTERFACE 0x40000081 +#define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 0x40000082 + +/* +* Hyper-V synthetic debugger platform capabilities +* These are HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits. +*/ +#define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING BIT(1) + +/* Hyper-V Synthetic debug options MSR */ +#define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1 +#define HV_X64_MSR_SYNDBG_STATUS 0x400000F2 +#define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3 +#define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4 +#define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5 +#define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF + +/* Hyper-V HV_X64_MSR_SYNDBG_OPTIONS bits */ +#define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2) +static inline struct kvm_vcpu_hv *vcpu_to_hv_vcpu (struct kvm_vcpu *vcpu) {return &vcpu->arch.hyperv; --2.24.1
RE: [PATCH v5 2/5] x86/hyper-v: Add synthetic debugger definitions
From: Jon Doron <[email protected]> Sent: Friday, March 13, 2020 9:45 PM
Quoted 70 lines · Michael Kelley
Quoted 68 lines
From: Jon Doron <[email protected]> Sent: Friday, March 13, 2020 6:21 AM
Quoted 52 lines
Hyper-V synthetic debugger has two modes, one that uses MSRs and the other that use Hypercalls.
Add all the required definitions to both types of synthetic debugger interface.
Some of the required new CPUIDs and MSRs are not documented in the TLFS so they are in
hyperv.hinstead.Signed-off-by Jon Doron <[email protected]>--- arch/x86/include/asm/hyperv-tlfs.h | 6 ++++++ arch/x86/kvm/hyperv.h | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)arch/x86/include/asm/hyperv-tlfs.h +6
-0@@ -131,6 +131,8 @@#define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8)/* Crash MSR available */ #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10) +/* Support for debug MSRs available */ +#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11)/* stimer Direct Mode is available */ #define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19)@@ -376,6 +378,9 @@ struct hv_tsc_emulation_status {#define HVCALL_SEND_IPI_EX 0x0015#define HVCALL_POST_MESSAGE 0x005c#define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_POST_DEBUG_DATA 0x0069 +#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a +#define HVCALL_RESET_DEBUG_SESSION 0x006b#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0@@ -419,6 +424,7 @@ enum HV_GENERIC_SET_FORMAT {#define HV_STATUS_INVALID_HYPERCALL_INPUT 3#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INVALID_PARAMETER 5 +#define HV_STATUS_OPERATION_DENIED 8#define HV_STATUS_INSUFFICIENT_MEMORY 11#define HV_STATUS_INVALID_PORT_ID 17#define HV_STATUS_INVALID_CONNECTION_ID 18arch/x86/kvm/hyperv.h +0
-0arch/x86/kvm/hyperv.h line 26
Quoted 4 lines
arch/x86/kvm/hyperv.h +1
-0@@ -23,6 +23,28 @@#include <linux/kvm_host.h> +/* These defines are required by KDNet and they are not part of Hyper-V TLFS */ I'm looking for a bit more info in the comment so that it's clear that the synthetic debugger functionality is not committed to be available going forward. Perhaps something along the lines of:
/* The #defines related to the synthetic debugger are required by KDNet, but
* they are not documented in the Hyper-V TLFS because the synthetic debugger
* functionality has been deprecated and is subject to removal in future versions
* of Windows.
*/
Quoted 8 lines
Quoted 4 lines
But with that additional comment text,
Reviewed-by Michael Kelley <[email protected]>Sure thing, but one quick question I have noticed that in the 6.0 TLFS the bit indicating the
DEBUG_MSRSare available is still documented is that intentional or a juss a miss?
From the side conversation I had with the Hyper-V people, I think this is just a miss. They took out the MSR definitions, but forgot to take out the flag indicating the presence of the MSRs. As I think I mentioned in an earlier email, there will be future updates to the TLFS, and I've put this topic on my list of things to make sure get cleaned up.
Michael
Quoted 31 lines
Cheers,
-- Jon.Quoted 27 lines
Quoted 26 lines
arch/x86/kvm/hyperv.h +21
-1+#define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 0x40000080 +#define HYPERV_CPUID_SYNDBG_INTERFACE 0x40000081 +#define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 0x40000082 + +/* +* Hyper-V synthetic debugger platform capabilities +* These are HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits. +*/ +#define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING BIT(1) + +/* Hyper-V Synthetic debug options MSR */ +#define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1 +#define HV_X64_MSR_SYNDBG_STATUS 0x400000F2 +#define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3 +#define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4 +#define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5 +#define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF + +/* Hyper-V HV_X64_MSR_SYNDBG_OPTIONS bits */ +#define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2) +static inline struct kvm_vcpu_hv *vcpu_to_hv_vcpu (struct kvm_vcpu *vcpu) {return &vcpu->arch.hyperv; --2.24.1
PATCH v5 3/5 x86/kvm/hyper-v: Add support for synthetic debugger capability
In reply to Jon DoronAdd support for Hyper-V synthetic debugger (syndbg) interface. The syndbg interface is using MSRs to emulate a way to send/recv packets data.
The debug transport dll (kdvm/kdnet) will identify if Hyper-V is enabled and if it supports the synthetic debugger interface it will attempt to use it, instead of trying to initialize a network adapter.
--- Documentation/virt/kvm/api.rst | 16 ++++ arch/x86/include/asm/kvm_host.h | 13 +++ arch/x86/kvm/hyperv.c | 135 +++++++++++++++++++++++++++++++- arch/x86/kvm/hyperv.h | 5 ++ arch/x86/kvm/trace.h | 51 ++++++++++++ arch/x86/kvm/x86.c | 9 +++ include/uapi/linux/kvm.h | 11 +++ 7 files changed, 239 insertions(+), 1 deletion(-)
Documentation/virt/kvm/api.rst +16 -0
@@ -5024,6 +5024,7 @@ EOI was received. struct kvm_hyperv_exit { #define KVM_EXIT_HYPERV_SYNIC 1 #define KVM_EXIT_HYPERV_HCALL 2 + #define KVM_EXIT_HYPERV_SYNDBG 3 __u32 type; __u32 pad1; union {
@@ -5039,6 +5040,15 @@ EOI was received. __u64 result; __u64 params[2]; } hcall; + struct { + __u32 msr; + __u32 pad2; + __u64 control; + __u64 status; + __u64 send_page; + __u64 recv_page; + __u64 pending_page; + } syndbg; } u; }; /* KVM_EXIT_HYPERV */
@@ -5055,6 +5065,12 @@ Hyper-V SynIC state change. Notification is used to remap SynIC event/message pages and to enable/disable SynIC messages/events processing in userspace. + - KVM_EXIT_HYPERV_SYNDBG -- synchronously notify user-space about + +Hyper-V Synthetic debugger state change. Notification is used to either update +the pending_page location or to send a control command (send the buffer located +in send_page or recv a buffer to recv_page). + :: /* KVM_EXIT_ARM_NISV */
arch/x86/include/asm/kvm_host.h +13 -0
@@ -854,6 +854,18 @@ struct kvm_apic_map {struct kvm_lapic *phys_map[]; }; +/* Hyper-V synthetic debugger (SynDbg)*/ +struct kvm_hv_syndbg { +struct { +u64 control; +u64 status; +u64 send_page; +u64 recv_page; +u64 pending_page; + } control; +u64 options; +}; +/* Hyper-V emulation context */ struct kvm_hv {struct mutex hv_lock;
@@ -877,6 +889,7 @@ struct kvm_hv {atomic_t num_mismatched_vp_indexes;struct hv_partition_assist_pg *hv_pa_pg; +struct kvm_hv_syndbg hv_syndbg; };enum kvm_irqchip_mode {
arch/x86/kvm/hyperv.c +134 -1
186 lines not on this page · raw message
arch/x86/kvm/hyperv.h +5 -0
@@ -68,6 +68,11 @@ static inline struct kvm_vcpu *synic_to_vcpu(struct kvm_vcpu_hv_synic *synic) return hv_vcpu_to_vcpu(container_of(synic, struct kvm_vcpu_hv, synic)); } +static inline struct kvm_hv_syndbg *vcpu_to_hv_syndbg (struct kvm_vcpu *vcpu) +{ +return &vcpu->kvm->arch.hyperv.hv_syndbg; +} +int kvm_hv_set_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 data,bool host);int kvm_hv_get_msr_common (struct kvm_vcpu *vcpu,u32 msr,u64 *pdata,bool host);
arch/x86/kvm/trace.h +51 -0
57 lines not on this page · raw message
arch/x86/kvm/x86.c +9 -0
@@ -1214,6 +1214,10 @@ static const u32 emulated_msrs_all[] = {HV_X64_MSR_VP_ASSIST_PAGE ,HV_X64_MSR_REENLIGHTENMENT_CONTROL ,HV_X64_MSR_TSC_EMULATION_CONTROL ,HV_X64_MSR_TSC_EMULATION_STATUS , +HV_X64_MSR_SYNDBG_OPTIONS , +HV_X64_MSR_SYNDBG_CONTROL ,HV_X64_MSR_SYNDBG_STATUS , +HV_X64_MSR_SYNDBG_SEND_BUFFER ,HV_X64_MSR_SYNDBG_RECV_BUFFER , +HV_X64_MSR_SYNDBG_PENDING_BUFFER ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME , MSR_KVM_PV_EOI_EN,
@@ -2906,6 +2910,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)*/ break ; case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: +case HV_X64_MSR_SYNDBG_OPTIONS : case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:case HV_X64_MSR_CRASH_CTL : case HV_X64_MSR_STIMER0_CONFIG ... HV_X64_MSR_STIMER3_COUNT:
@@ -3151,6 +3157,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data =0x20000000 ;break ; case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: +case HV_X64_MSR_SYNDBG_OPTIONS : case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:case HV_X64_MSR_CRASH_CTL : case HV_X64_MSR_STIMER0_CONFIG ... HV_X64_MSR_STIMER3_COUNT:
@@ -3323,6 +3331,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_HYPERV_TLBFLUSH :case KVM_CAP_HYPERV_SEND_IPI :case KVM_CAP_HYPERV_CPUID : +case KVM_CAP_HYPERV_DEBUGGING :case KVM_CAP_PCI_SEGMENT :case KVM_CAP_DEBUGREGS :case KVM_CAP_X86_ROBUST_SINGLESTEP :
include/uapi/linux/kvm.h +11 -0
@@ -188,6 +188,7 @@ struct kvm_s390_cmma_log {struct kvm_hyperv_exit {#define KVM_EXIT_HYPERV_SYNIC 1#define KVM_EXIT_HYPERV_HCALL 2 +#define KVM_EXIT_HYPERV_SYNDBG 3__u32 type;__u32 pad1;union {
@@ -203,6 +204,15 @@ struct kvm_hyperv_exit {__u64 result;__u64 params[2 ]; } hcall; +struct { +__u32 msr; +__u32 pad2; +__u64 control; +__u64 status; +__u64 send_page; +__u64 recv_page; +__u64 pending_page; + } syndbg; } u; };
@@ -1012,6 +1022,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_ARM_NISV_TO_USER 177#define KVM_CAP_ARM_INJECT_EXT_DABT 178#define KVM_CAP_S390_VCPU_RESETS 179 +#define KVM_CAP_HYPERV_DEBUGGING 180#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.24.1
PATCH v5 4/5 x86/kvm/hyper-v: enable hypercalls regardless of hypercall page
In reply to Jon DoronMicrosoft's kdvm.dll dbgtransport module does not respect the hypercall page and simply identifies the CPU being used (AMD/Intel) and according to it simply makes hypercalls with the relevant instruction (vmmcall/vmcall respectively).
The relevant function in kdvm is KdHvConnectHypervisor which first checks if the hypercall page has been enabled via HV_X64_MSR_HYPERCALL_ENABLE, and in case it was not it simply sets the HV_X64_MSR_GUEST_OS_ID to 0x1000101010001 which means:build_number = 0x0001service_version = 0x01minor_version = 0x01major_version = 0x01os_id = 0x00 (Undefined)vendor_id = 1 (Microsoft)os_type = 0 (A value of 0 indicates a proprietary, closed source OS)
and starts issuing the hypercall without setting the hypercall page.
To resolve this issue simply enable hypercalls also if the guest_os_id is not 0.
--- arch/x86/kvm/hyperv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kvm/hyperv.c +4 -1
@@ -1639,7 +1639,10 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *current_vcpu, u64 ingpa, u64 outgpa,bool kvm_hv_hypercall_enabled (struct kvm *kvm) { -return READ_ONCE (kvm->arch.hyperv.hv_hypercall) &HV_X64_MSR_HYPERCALL_ENABLE ; +struct kvm_hv *hv = &kvm->arch.hyperv; + +return READ_ONCE (hv->hv_hypercall) &HV_X64_MSR_HYPERCALL_ENABLE || +READ_ONCE (hv->hv_guest_os_id) !=0 ; }static void kvm_hv_hypercall_set_result (struct kvm_vcpu *vcpu,u64 result)
Signature · 1 line
2.24.1
PATCH v5 5/5 x86/kvm/hyper-v: Add support for synthetic debugger via hypercalls
In reply to Jon DoronThere is another mode for the synthetic debugger which uses hypercalls to send/recv network data instead of the MSR interface.
This interface is much slower and less recommended since you might get a lot of VMExits while KDVM polling for new packets to recv, rather than simply checking the pending page to see if there is data avialble and then request.
--- arch/x86/kvm/hyperv.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/x86/kvm/hyperv.c +22 -0
@@ -1821,6 +1821,28 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) } ret =kvm_hv_send_ipi (vcpu, ingpa, outgpa, true, false);break ; +case HVCALL_POST_DEBUG_DATA : +case HVCALL_RETRIEVE_DEBUG_DATA : +if (unlikely (fast)) { + ret =HV_STATUS_INVALID_PARAMETER ; +break ; + } +/* fallthrough */ +case HVCALL_RESET_DEBUG_SESSION : { +struct kvm_hv_syndbg *syndbg =vcpu_to_hv_syndbg (vcpu); +if (!(syndbg->options &HV_X64_SYNDBG_OPTION_USE_HCALLS )) { + ret =HV_STATUS_OPERATION_DENIED ; +break ; + } + vcpu->run->exit_reason =KVM_EXIT_HYPERV ; + vcpu->run->hyperv.type =KVM_EXIT_HYPERV_HCALL ; + vcpu->run->hyperv.u.hcall.input = param; + vcpu->run->hyperv.u.hcall.params[0 ] = ingpa; + vcpu->run->hyperv.u.hcall.params[1 ] = outgpa; + vcpu->arch.complete_userspace_io = + kvm_hv_hypercall_complete_userspace; +return 0 ; + }default : ret =HV_STATUS_INVALID_HYPERCALL_CODE ;break ;
Signature · 1 line
2.24.1