Drivers: hv: vmbus: Restructure architecture specific code
Subsystems (2)
cover Drivers: hv: vmbus: Restructure architecture specific code
From: K. Y. Srinivasan <[email protected]>
The current Hyper-V code under drivers/hv has bunch of X86 specific code. Restructure the code and move al architecture specific code to the appropriate files.
As I was working on this restructuring, Roman Kagan <[email protected]> has submitted patches to restructure the Hyper-V header files to address a different need - to share the definitions across all Hyper-V drivers including QEMU based drivers. Roman and I will coordinate our work.
K. Y. Srinivasan (18):
Drivers: hv: vmbus: Move the definition of
hv_x64_msr_hypercall_contents
Drivers: hv: vmbus: Move the definition of generate_guest_id()
Drivers: hv vmbus: Move Hypercall page setup out of common code
Drivers: hv: vmbus: Move Hypercall invocation code out of common code
Drivers: hv: vmbus: Consolidate all Hyper-V specific clocksource code
Drivers: hv: vmbus: Move the extracting of Hypervisor version
information
Drivers: hv: vmbus: Move the crash notification function
Drivers: hv: vmbus: Move the check for hypercall page setup
Drivers: hv: vmbus: Move the code to signal end of message
Drivers: hv: vmbus: Restructure the clockevents code
Drivers: hv: util: Use hv_get_current_tick() to get current tick
Drivers: hv: vmbus: Get rid of an unsused variable
Drivers: hv: vmbus: Define APIs to manipulate the message page
Drivers: hv: vmbus: Define APIs to manipulate the event page
Drivers: hv: vmbus: Define APIs to manipulate the synthetic interrupt
controller
Drivers: hv: vmbus: Define an API to retrieve virtual processor index
Drivers: hv: vmbus: Define an APIs to manage interrupt state
Drivers: hv: vmbus: Cleanup hyperv_vmbus.h
arch/x86/Kbuild | 3 + arch/x86/hyperv/Makefile | 1 + arch/x86/hyperv/hv_init.c | 251 ++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 147 ++++++++++++++++++ arch/x86/include/uapi/asm/hyperv.h | 8 + arch/x86/kernel/cpu/mshyperv.c | 50 ++++--- drivers/hv/channel_mgmt.c | 1 + drivers/hv/connection.c | 7 +- drivers/hv/hv.c | 296 ++++-------------------------------- drivers/hv/hv_util.c | 3 +- drivers/hv/hyperv_vmbus.h | 291 +----------------------------------- drivers/hv/vmbus_drv.c | 25 --- 12 files changed, 472 insertions(+), 611 deletions(-) create mode 100644 arch/x86/hyperv/Makefile create mode 100644 arch/x86/hyperv/hv_init.c
Signature · 1 line
1.7.4.1
PATCH 15/18 Drivers: hv: vmbus: Define APIs to manipulate the synthetic interrupt controller
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of cleaning up architecture specific code, define APIs to manipulate the interrupt controller state.
--- arch/x86/include/asm/mshyperv.h | 3 +++ drivers/hv/hv.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
arch/x86/include/asm/mshyperv.h +3 -0
@@ -146,6 +146,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)#define hv_get_siefp (val) rdmsrl(HV_X64_MSR_SIEFP, val)#define hv_set_siefp (val) wrmsrl(HV_X64_MSR_SIEFP, val) +#define hv_get_synic_state (val) rdmsrl(HV_X64_MSR_SCONTROL, val) +#define hv_set_synic_state (val) wrmsrl(HV_X64_MSR_SCONTROL, val) +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hv.c +4 -4
@@ -294,10 +294,10 @@ int hv_synic_init(unsigned int cpu)wrmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64);/* Enable the global synic bit */ -rdmsrl (HV_X64_MSR_SCONTROL , sctrl.as_uint64); +hv_get_synic_state (sctrl.as_uint64); sctrl.enable =1 ; -wrmsrl (HV_X64_MSR_SCONTROL , sctrl.as_uint64); +hv_set_synic_state (sctrl.as_uint64); hv_context.synic_initialized = true;
@@ -405,9 +405,9 @@ int hv_synic_cleanup(unsigned int cpu)hv_set_siefp (siefp.as_uint64);/* Disable the global synic bit */ -rdmsrl (HV_X64_MSR_SCONTROL , sctrl.as_uint64); +hv_get_synic_state (sctrl.as_uint64); sctrl.enable =0 ; -wrmsrl (HV_X64_MSR_SCONTROL , sctrl.as_uint64); +hv_set_synic_state (sctrl.as_uint64);return 0 ; }
Signature · 1 line
1.7.4.1
PATCH 2/18 Drivers: hv: vmbus: Move the definition of generate_guest_id()
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the definition of generate_guest_id() to x86 specific header file.
--- arch/x86/include/asm/mshyperv.h | 43 +++++++++++++++++++++++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 43 --------------------------------------- 2 files changed, 43 insertions(+), 43 deletions(-)
arch/x86/include/asm/mshyperv.h +43 -0
@@ -25,6 +25,49 @@ struct ms_hyperv_info { }; }; +/* +* The guest OS needs to register the guest ID with the hypervisor. +* The guest ID is a 64 bit entity and the structure of this ID is +* specified in the Hyper-V specification: +* +* msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx +* +* While the current guideline does not specify how Linux guest ID(s) +* need to be generated, our plan is to publish the guidelines for +* Linux and other guest operating systems that currently are hosted +* on Hyper-V. The implementation here conforms to this yet +* unpublished guidelines. +* +* +* Bit(s) +* 63 - Indicates if the OS is Open Source or not; 1 is Open Source +* 62:56 - Os Type; Linux is 0x100 +* 55:48 - Distro specific identification +* 47:16 - Linux kernel version number +* 15:0 - Distro specific identification +* +* +*/ + +#define HV_LINUX_VENDOR_ID 0x8800 + +/* +* Generate the guest ID based on the guideline described above. +*/ + +static inline __u64 generate_guest_id (__u64 d_info1,__u64 kernel_version, +__u64 d_info2) +{ +__u64 guest_id =0 ; + + guest_id = (((__u64 )HV_LINUX_VENDOR_ID ) <<56 ); + guest_id |= (d_info1 <<48 ); + guest_id |= (kernel_version <<16 ); + guest_id |= d_info2; + +return guest_id; +} +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hyperv_vmbus.h +0 -43
49 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 16/18 Drivers: hv: vmbus: Define an API to retrieve virtual processor index
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of cleaning up architecture specific code, define an API to retrieve the virtual procesor index.
--- arch/x86/include/asm/mshyperv.h | 2 ++ drivers/hv/hv.c | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-)
arch/x86/include/asm/mshyperv.h +2 -0
@@ -149,6 +149,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)#define hv_get_synic_state (val) rdmsrl(HV_X64_MSR_SCONTROL, val)#define hv_set_synic_state (val) wrmsrl(HV_X64_MSR_SCONTROL, val) +#define hv_get_vp_index (index) rdmsrl(HV_X64_MSR_VP_INDEX, index) +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hv.c +1 -1
@@ -306,7 +306,7 @@ int hv_synic_init(unsigned int cpu)* of cpuid and Linux' notion of cpuid. * This array will be indexed using Linux cpuid. */ -rdmsrl (HV_X64_MSR_VP_INDEX , vp_index); +hv_get_vp_index (vp_index); hv_context.vp_index[cpu] = (u32 )vp_index;/*
Signature · 1 line
1.7.4.1
PATCH 5/18 Drivers: hv: vmbus: Consolidate all Hyper-V specific clocksource code
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, consolidate all Hyper-V specific clocksource code to an architecture specific code.
--- arch/x86/hyperv/hv_init.c | 104 +++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 12 +++++ arch/x86/kernel/cpu/mshyperv.c | 23 --------- drivers/hv/hv.c | 95 ----------------------------------- drivers/hv/hyperv_vmbus.h | 8 --- 5 files changed, 116 insertions(+), 126 deletions(-)
arch/x86/hyperv/hv_init.c +104 -0
@@ -24,6 +24,79 @@#include <linux/version.h> #include <linux/vmalloc.h> #include <linux/mm.h> +#include <linux/clockchips.h> + + +#ifdef CONFIG_X86_64 + +static struct ms_hyperv_tsc_page *tsc_pg; + +static cycle_t read_hv_clock_tsc (struct clocksource *arg) +{ +cycle_t current_tick; + +if (tsc_pg->tsc_sequence !=0 ) { +/* +* Use the tsc page to compute the value. +*/ + +while (1 ) { +cycle_t tmp; +u32 sequence = tsc_pg->tsc_sequence; +u64 cur_tsc; +u64 scale = tsc_pg->tsc_scale; +s64 offset = tsc_pg->tsc_offset; + +rdtscll (cur_tsc); +/* current_tick = ((cur_tsc *scale) >> 64) + offset */ + asm("mulq %3" + :"=d" (current_tick),"=a" (tmp) + :"a" (cur_tsc),"r" (scale)); + + current_tick += offset; +if (tsc_pg->tsc_sequence == sequence) +return current_tick; + +if (tsc_pg->tsc_sequence !=0 ) +continue ; +/* +* Fallback using MSR method. +*/ +break ; + } + } +rdmsrl (HV_X64_MSR_TIME_REF_COUNT , current_tick); +return current_tick; +} + +static struct clocksource hyperv_cs_tsc = { + .name ="hyperv_clocksource_tsc_page" , + .rating =400 , + .read = read_hv_clock_tsc, + .mask =CLOCKSOURCE_MASK (64 ), + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +}; +#endif + +static cycle_t read_hv_clock_msr (struct clocksource *arg) +{ +cycle_t current_tick; +/* +* Read the partition counter to get the current tick count. This count +* is set to 0 when the partition is created and is incremented in +* 100 nanosecond units. +*/ +rdmsrl (HV_X64_MSR_TIME_REF_COUNT , current_tick); +return current_tick; +} + +static struct clocksource hyperv_cs_msr = { + .name ="hyperv_clocksource_msr" , + .rating =400 , + .read = read_hv_clock_msr, + .mask =CLOCKSOURCE_MASK (64 ), + .flags =CLOCK_SOURCE_IS_CONTINUOUS , +};static void *hypercall_pg;/*
@@ -31,6 +104,7 @@* hypervisor has been detected. * * 1. Setup the hypercall page. +* 2. Register Hyper-V specific clocksource. */ void hyperv_init (void ) {
@@ -58,6 +132,36 @@ void hyperv_init(void) hypercall_msr.enable =1 ; hypercall_msr.guest_physical_address =vmalloc_to_pfn (hypercall_pg);wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); + +/* +* Register Hyper-V specific clocksource. +*/ +#ifdef CONFIG_X86_64 +if (ms_hyperv.features &HV_X64_MSR_REFERENCE_TSC_AVAILABLE ) { +union hv_x64_msr_hypercall_contents tsc_msr; + + tsc_pg =__vmalloc (PAGE_SIZE ,GFP_KERNEL ,PAGE_KERNEL ); +if (!tsc_pg) +clocksource_register_hz (&hyperv_cs_msr,NSEC_PER_SEC /100 ); +return ; + +rdmsrl (HV_X64_MSR_REFERENCE_TSC , tsc_msr.as_uint64); + + tsc_msr.enable =1 ; + tsc_msr.guest_physical_address =vmalloc_to_pfn (tsc_pg); + +wrmsrl (HV_X64_MSR_REFERENCE_TSC , tsc_msr.as_uint64); +clocksource_register_hz (&hyperv_cs_tsc,NSEC_PER_SEC /100 ); +return ; + } +#endif +/* +* For 32 bit guests just use the MSR based mechanism for reading +* the partition counter. +*/ + +if (ms_hyperv.features &HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ) +clocksource_register_hz (&hyperv_cs_msr,NSEC_PER_SEC /100 ); }/*
arch/x86/include/asm/mshyperv.h +12 -0
@@ -26,6 +26,18 @@ struct ms_hyperv_info { };/* +* TSC page layout. +*/ + +struct ms_hyperv_tsc_page { +volatile u32 tsc_sequence; +u32 reserved1; +volatile u64 tsc_scale; +volatile s64 tsc_offset; +u64 reserved2[509 ]; +}; + +/* * The guest OS needs to register the guest ID with the hypervisor. * The guest ID is a 64 bit entity and the structure of this ID is * specified in the Hyper-V specification:
arch/x86/kernel/cpu/mshyperv.c +0 -23
@@ -133,26 +133,6 @@ static uint32_t __init ms_hyperv_platform(void)return 0 ; } -static cycle_t read_hv_clock (struct clocksource *arg) -{ -cycle_t current_tick; -/* -* Read the partition counter to get the current tick count. This count -* is set to 0 when the partition is created and is incremented in -* 100 nanosecond units. -*/ -rdmsrl (HV_X64_MSR_TIME_REF_COUNT , current_tick); -return current_tick; -} - -static struct clocksource hyperv_cs = { - .name ="hyperv_clocksource" , - .rating =400 ,/* use this when running on Hyperv*/ - .read = read_hv_clock, - .mask =CLOCKSOURCE_MASK (64 ), - .flags =CLOCK_SOURCE_IS_CONTINUOUS , -}; -static unsigned char hv_get_nmi_reason (void ) {return 0 ;
@@ -185,9 +165,6 @@ static void __init ms_hyperv_init_platform(void) }#endif -if (ms_hyperv.features &HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ) -clocksource_register_hz (&hyperv_cs,NSEC_PER_SEC /100 ); -#ifdef CONFIG_X86_IO_APIC no_timer_check =1 ;#endif
drivers/hv/hv.c +0 -95
114 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +0 -8
@@ -416,14 +416,6 @@ struct hv_context {extern struct hv_context hv_context; -struct ms_hyperv_tsc_page { -volatile u32 tsc_sequence; -u32 reserved1; -volatile u64 tsc_scale; -volatile s64 tsc_offset; -u64 reserved2[509 ]; -}; -struct hv_ring_buffer_debug_info {u32 current_interrupt_mask;u32 current_read_index;
Signature · 1 line
1.7.4.1
PATCH 3/18 Drivers: hv vmbus: Move Hypercall page setup out of common code
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the hypercall page setup to an architecture specific file.
--- arch/x86/Kbuild | 3 ++ arch/x86/hyperv/Makefile | 1 + arch/x86/hyperv/hv_init.c | 62 +++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 5 +++ arch/x86/kernel/cpu/mshyperv.c | 7 ++++ drivers/hv/hv.c | 45 ++-------------------------- 6 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 arch/x86/hyperv/Makefile create mode 100644 arch/x86/hyperv/hv_init.c
arch/x86/Kbuild +3 -0
@@ -7,6 +7,9 @@ obj-$(CONFIG_KVM) += kvm/ # Xen paravirtualization support obj-$(CONFIG_XEN) += xen/ +# Hyper-V paravirtualization support +obj-$(CONFIG_HYPERVISOR_GUEST) += hyperv/ + # lguest paravirtualization support obj-$(CONFIG_LGUEST_GUEST) += lguest/
arch/x86/hyperv/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y := hv_init.o
arch/x86/hyperv/hv_init.c new file +62 -0
62 lines not on this page · raw message
arch/x86/include/asm/mshyperv.h +5 -0
@@ -80,4 +80,9 @@ static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,void hv_remove_kexec_handler (void );void hv_setup_crash_handler (void (*handler)(struct pt_regs *regs));void hv_remove_crash_handler (void ); + +#if IS_ENABLED (CONFIG_HYPERV ) +void hyperv_init (void ); +extern void *hv_hypercall_pg; +#endif #endif
arch/x86/kernel/cpu/mshyperv.c +7 -0
@@ -204,6 +204,13 @@ static void __init ms_hyperv_init_platform(void)*/ if (efi_enabled (EFI_BOOT )) x86_platform.get_nmi_reason = hv_get_nmi_reason; + +#if IS_ENABLED (CONFIG_HYPERV ) +/* +* Setup the hook to get control post apic initialization. +*/ + x86_platform.apic_post_init = hyperv_init; +#endif }const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
drivers/hv/hv.c +3 -42
78 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 9/18 Drivers: hv: vmbus: Move the code to signal end of message
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the code for signaling end of message.
--- arch/x86/include/asm/mshyperv.h | 37 +++++++++++++++++++++++++++++++++++++ drivers/hv/channel_mgmt.c | 1 + drivers/hv/hyperv_vmbus.h | 35 ----------------------------------- 3 files changed, 38 insertions(+), 35 deletions(-)
arch/x86/include/asm/mshyperv.h +37 -0
@@ -99,6 +99,43 @@ static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,return guest_id; } + +/* Free the message slot and signal end-of-message if required */ +static inline void vmbus_signal_eom (struct hv_message *msg,u32 old_msg_type) +{ +/* +* On crash we're reading some other CPU's message page and we need +* to be careful: this other CPU may already had cleared the header +* and the host may already had delivered some other message there. +* In case we blindly write msg->header.message_type we're going +* to lose it. We can still lose a message of the same type but +* we count on the fact that there can only be one +* CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages +* on crash. +*/ +if (cmpxchg (&msg->header.message_type, old_msg_type, +HVMSG_NONE ) != old_msg_type) +return ; + +/* +* Make sure the write to MessageType (ie set to +* HVMSG_NONE) happens before we read the +* MessagePending and EOMing. Otherwise, the EOMing +* will not deliver any more messages since there is +* no empty slot +*/ +mb (); + +if (msg->header.message_flags.msg_pending) { +/* +* This will cause message queue rescan to +* possibly deliver another msg from the +* hypervisor +*/ +wrmsrl (HV_X64_MSR_EOM ,0 ); + } +} +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/channel_mgmt.c +1 -0
@@ -31,6 +31,7 @@#include <linux/completion.h> #include <linux/delay.h> #include <linux/hyperv.h> +#include <asm/mshyperv.h> #include "hyperv_vmbus.h"
drivers/hv/hyperv_vmbus.h +0 -35
@@ -521,41 +521,6 @@ struct vmbus_channel_message_table_entry {extern struct vmbus_channel_message_table_entry channel_message_table[CHANNELMSG_COUNT ]; -/* Free the message slot and signal end-of-message if required */ -static inline void vmbus_signal_eom (struct hv_message *msg,u32 old_msg_type) -{ -/* -* On crash we're reading some other CPU's message page and we need -* to be careful: this other CPU may already had cleared the header -* and the host may already had delivered some other message there. -* In case we blindly write msg->header.message_type we're going -* to lose it. We can still lose a message of the same type but -* we count on the fact that there can only be one -* CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages -* on crash. -*/ -if (cmpxchg (&msg->header.message_type, old_msg_type, -HVMSG_NONE ) != old_msg_type) -return ; - -/* -* Make sure the write to MessageType (ie set to -* HVMSG_NONE) happens before we read the -* MessagePending and EOMing. Otherwise, the EOMing -* will not deliver any more messages since there is -* no empty slot -*/ -mb (); - -if (msg->header.message_flags.msg_pending) { -/* -* This will cause message queue rescan to -* possibly deliver another msg from the -* hypervisor -*/ -wrmsrl (HV_X64_MSR_EOM ,0 ); - } -}/* General vmbus interface */
Signature · 1 line
1.7.4.1
PATCH 8/18 Drivers: hv: vmbus: Move the check for hypercall page setup
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the check for detecting if the hypercall page is setup.
--- arch/x86/hyperv/hv_init.c | 15 +++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + drivers/hv/hv.c | 7 +------ 3 files changed, 17 insertions(+), 6 deletions(-)
arch/x86/hyperv/hv_init.c +15 -0
@@ -234,3 +234,18 @@ void hyperv_report_panic(struct pt_regs *regs)wrmsrl (HV_X64_MSR_CRASH_CTL ,HV_CRASH_CTL_CRASH_NOTIFY ); }EXPORT_SYMBOL_GPL (hyperv_report_panic); + +bool hv_is_hypercall_page_setup (void ) +{ +union hv_x64_msr_hypercall_contents hypercall_msr; + +/* Check if the hypercall page is setup */ + hypercall_msr.as_uint64 =0 ; +rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); + +if (!hypercall_msr.enable) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (hv_is_hypercall_page_setup);
arch/x86/include/asm/mshyperv.h +1 -0
@@ -115,5 +115,6 @@ static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,#if IS_ENABLED (CONFIG_HYPERV )void hyperv_init (void );void hyperv_report_panic (struct pt_regs *regs); +bool hv_is_hypercall_page_setup (void );#endif #endif
drivers/hv/hv.c +1 -6
@@ -49,7 +49,6 @@ struct hv_context hv_context = {*/ int hv_init (void ) { -union hv_x64_msr_hypercall_contents hypercall_msr;memset (hv_context.synic_event_page,0 ,sizeof (void *) *NR_CPUS ); memset(hv_context.synic_message_page, 0,
@@ -65,11 +64,7 @@ int hv_init(void)memset (hv_context.clk_evt,0 ,sizeof (void *) *NR_CPUS ); -/* See if the hypercall page is already set */ - hypercall_msr.as_uint64 =0 ; -rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); - -if (!hypercall_msr.enable) +if (!hv_is_hypercall_page_setup ())return -ENOTSUPP ;return 0 ;
Signature · 1 line
1.7.4.1
PATCH 10/18 Drivers: hv: vmbus: Restructure the clockevents code
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
Move the relevant code that programs the hypervisor to an architecture specific file.
--- arch/x86/include/asm/mshyperv.h | 4 ++++ drivers/hv/hv.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-)
arch/x86/include/asm/mshyperv.h +4 -0
@@ -136,6 +136,10 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type) } } +#define hv_get_current_tick (tick) rdmsrl(HV_X64_MSR_TIME_REF_COUNT, tick) +#define hv_init_timer (timer, tick) wrmsrl(timer, tick) +#define hv_init_timer_config (config, val) wrmsrl(config, val) +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hv.c +5 -5
@@ -118,16 +118,16 @@ static int hv_ce_set_next_event(unsigned long delta,WARN_ON (!clockevent_state_oneshot (evt)); -rdmsrl (HV_X64_MSR_TIME_REF_COUNT , current_tick); +hv_get_current_tick (current_tick); current_tick += delta; -wrmsrl (HV_X64_MSR_STIMER0_COUNT , current_tick); +hv_init_timer (HV_X64_MSR_STIMER0_COUNT , current_tick);return 0 ; }static int hv_ce_shutdown (struct clock_event_device *evt) { -wrmsrl (HV_X64_MSR_STIMER0_COUNT ,0 ); -wrmsrl (HV_X64_MSR_STIMER0_CONFIG ,0 ); +hv_init_timer (HV_X64_MSR_STIMER0_COUNT ,0 ); +hv_init_timer_config (HV_X64_MSR_STIMER0_CONFIG ,0 );return 0 ; }
@@ -139,7 +139,7 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt) timer_cfg.enable =1 ; timer_cfg.auto_enable =1 ; timer_cfg.sintx =VMBUS_MESSAGE_SINT ; -wrmsrl (HV_X64_MSR_STIMER0_CONFIG , timer_cfg.as_uint64); +hv_init_timer_config (HV_X64_MSR_STIMER0_CONFIG , timer_cfg.as_uint64);return 0 ; }
Signature · 1 line
1.7.4.1
PATCH 18/18 Drivers: hv: vmbus: Cleanup hyperv_vmbus.h
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
Get rid of all unused definitions.
--- drivers/hv/hyperv_vmbus.h | 152 +-------------------------------------------- 1 files changed, 2 insertions(+), 150 deletions(-)
drivers/hv/hyperv_vmbus.h +2 -150
@@ -41,66 +41,11 @@#define HV_UTIL_NEGO_TIMEOUT 55 -/* Define version of the synthetic interrupt controller. */ -#define HV_SYNIC_VERSION (1) -#define HV_ANY_VP (0xFFFFFFFF) -/* Define synthetic interrupt controller flag constants. */ -#define HV_EVENT_FLAGS_COUNT (256 * 8)#define HV_EVENT_FLAGS_BYTE_COUNT (256)#define HV_EVENT_FLAGS_DWORD_COUNT (256 / sizeof(u32)) -/* Define invalid partition identifier. */ -#define HV_PARTITION_ID_INVALID ((u64)0x0) - -/* Define port type. */ -enum hv_port_type { -HVPORT_MSG =1 , -HVPORT_EVENT =2 , -HVPORT_MONITOR =3 -}; - -/* Define port information structure. */ -struct hv_port_info { -enum hv_port_type port_type; -u32 padding; -union { -struct { -u32 target_sint; -u32 target_vp; -u64 rsvdz; - } message_port_info; -struct { -u32 target_sint; -u32 target_vp; -u16 base_flag_number; -u16 flag_count; -u32 rsvdz; - } event_port_info; -struct { -u64 monitor_address; -u64 rsvdz; - } monitor_port_info; - }; -}; - -struct hv_connection_info { -enum hv_port_type port_type; -u32 padding; -union { -struct { -u64 rsvdz; - } message_connection_info; -struct { -u64 rsvdz; - } event_connection_info; -struct { -u64 monitor_address; - } monitor_connection_info; - }; -}; -/* * Timer configuration register. */
@@ -117,8 +62,6 @@ struct hv_connection_info { }; }; -/* Define the number of message buffers associated with each port. */ -#define HV_PORT_MESSAGE_BUFFER_COUNT (16)/* Define the synthetic interrupt controller event flags format. */ union hv_synic_event_flags {
@@ -126,11 +69,6 @@ struct hv_connection_info {u32 flags32[HV_EVENT_FLAGS_DWORD_COUNT ]; }; -/* Define the synthetic interrupt flags page layout. */ -struct hv_synic_event_flags_page { -union hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT ]; -}; -/* Define SynIC control register. */ union hv_synic_scontrol {u64 as_uint64;
@@ -232,6 +170,8 @@ struct hv_monitor_page {u8 rsvdz4[1984 ]; }; +#define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) +/* Definition of the hv_post_message hypercall input structure. */ struct hv_input_post_message {union hv_connection_id connectionid;
@@ -241,41 +181,6 @@ struct hv_input_post_message {u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT ]; }; -/* -* Versioning definitions used for guests reporting themselves to the -* hypervisor, and visa versa. -*/ - -/* Version info reported by guest OS's */ -enum hv_guest_os_vendor { -HVGUESTOS_VENDOR_MICROSOFT =0x0001 -}; - -enum hv_guest_os_microsoft_ids { -HVGUESTOS_MICROSOFT_UNDEFINED =0x00 , -HVGUESTOS_MICROSOFT_MSDOS =0x01 , -HVGUESTOS_MICROSOFT_WINDOWS3X =0x02 , -HVGUESTOS_MICROSOFT_WINDOWS9X =0x03 , -HVGUESTOS_MICROSOFT_WINDOWSNT =0x04 , -HVGUESTOS_MICROSOFT_WINDOWSCE =0x05 -}; - -/* -* Declare the MSR used to identify the guest OS. -*/ -#define HV_X64_MSR_GUEST_OS_ID 0x40000000 - -union hv_x64_msr_guest_os_id_contents { -u64 as_uint64; -struct { -u64 build_number:16 ; -u64 service_version:8 ;/* Service Pack, etc. */ -u64 minor_version:8 ; -u64 major_version:8 ; -u64 os_id:8 ;/* enum hv_guest_os_microsoft_ids (if Vendor=MS) */ -u64 vendor_id:16 ;/* enum hv_guest_os_vendor */ - }; -};enum {VMBUS_MESSAGE_CONNECTION_ID =1 ,
@@ -287,55 +192,6 @@ enum { VMBUS_MESSAGE_SINT = 2, }; -/* #defines */ - -#define HV_PRESENT_BIT 0x80000000 - - -#define HV_CPU_POWER_MANAGEMENT (1 << 0) -#define HV_RECOMMENDATIONS_MAX 4 - -#define HV_X64_MAX 5 -#define HV_CAPS_MAX 8 - - -#define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) - - -/* Service definitions */ - -#define HV_SERVICE_PARENT_PORT (0) -#define HV_SERVICE_PARENT_CONNECTION (0) - -#define HV_SERVICE_CONNECT_RESPONSE_SUCCESS (0) -#define HV_SERVICE_CONNECT_RESPONSE_INVALID_PARAMETER (1) -#define HV_SERVICE_CONNECT_RESPONSE_UNKNOWN_SERVICE (2) -#define HV_SERVICE_CONNECT_RESPONSE_CONNECTION_REJECTED (3) - -#define HV_SERVICE_CONNECT_REQUEST_MESSAGE_ID (1) -#define HV_SERVICE_CONNECT_RESPONSE_MESSAGE_ID (2) -#define HV_SERVICE_DISCONNECT_REQUEST_MESSAGE_ID (3) -#define HV_SERVICE_DISCONNECT_RESPONSE_MESSAGE_ID (4) -#define HV_SERVICE_MAX_MESSAGE_ID (4) - -#define HV_SERVICE_PROTOCOL_VERSION (0x0010) -#define HV_CONNECT_PAYLOAD_BYTE_COUNT 64 - -/* #define VMBUS_REVISION_NUMBER 6 */ - -/* Our local vmbus's port and connection id. Anything >0 is fine */ -/* #define VMBUS_PORT_ID 11 */ - -/* 628180B8-308D-4c5e-B7DB-1BEB62E62EF4 */ -static const uuid_le VMBUS_SERVICE_ID = { - .b = { -0xb8 ,0x80 ,0x81 ,0x62 ,0x8d ,0x30 ,0x5e ,0x4c , -0xb7 ,0xdb ,0x1b ,0xeb ,0x62 ,0xe6 ,0x2e ,0xf4 - }, -}; - - -struct hv_context {/* We only support running on top of Hyper-V * So at this point this really can only contain the Hyper-V ID
@@ -531,10 +387,6 @@ struct hv_device *vmbus_device_create(const uuid_le *type,int vmbus_device_register (struct hv_device *child_device_obj);void vmbus_device_unregister (struct hv_device *device_obj); -/* static void */ -/* VmbusChildDeviceDestroy( */ -/* struct hv_device *); */ -struct vmbus_channel *relid2channel (u32 relid);void vmbus_free_channels (void );
Signature · 1 line
1.7.4.1
PATCH 11/18 Drivers: hv: util: Use hv_get_current_tick() to get current tick
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to interact with Hyper-V in an instruction set architecture independent way, use the new API to get the current tick.
--- drivers/hv/hv_util.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/hv/hv_util.c +2 -1
@@ -27,6 +27,7 @@#include <linux/sysctl.h> #include <linux/reboot.h> #include <linux/hyperv.h> +#include <asm/mshyperv.h> #include "hyperv_vmbus.h"
@@ -199,7 +200,7 @@ static void hv_set_host_time(struct work_struct *work)*/ u64 current_tick; -rdmsrl (HV_X64_MSR_TIME_REF_COUNT , current_tick); +hv_get_current_tick (current_tick); newtime += (current_tick - wrk->ref_time); } host_tns = (newtime -WLTIMEDELTA ) *100 ;
Signature · 1 line
1.7.4.1
PATCH 14/18 Drivers: hv: vmbus: Define APIs to manipulate the event page
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of cleaning up architecture specific code, define APIs to manipulate the event page.
--- arch/x86/include/asm/mshyperv.h | 3 +++ drivers/hv/hv.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
arch/x86/include/asm/mshyperv.h +3 -0
@@ -143,6 +143,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)#define hv_get_simp (val) rdmsrl(HV_X64_MSR_SIMP, val)#define hv_set_simp (val) wrmsrl(HV_X64_MSR_SIMP, val) +#define hv_get_siefp (val) rdmsrl(HV_X64_MSR_SIEFP, val) +#define hv_set_siefp (val) wrmsrl(HV_X64_MSR_SIEFP, val) +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hv.c +4 -4
@@ -276,12 +276,12 @@ int hv_synic_init(unsigned int cpu)hv_set_simp (simp.as_uint64);/* Setup the Synic's event page */ -rdmsrl (HV_X64_MSR_SIEFP , siefp.as_uint64); +hv_get_siefp (siefp.as_uint64); siefp.siefp_enabled =1 ; siefp.base_siefp_gpa =virt_to_phys (hv_context.synic_event_page[cpu]) >>PAGE_SHIFT ; -wrmsrl (HV_X64_MSR_SIEFP , siefp.as_uint64); +hv_set_siefp (siefp.as_uint64);/* Setup the shared SINT. */ rdmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64);
@@ -398,11 +398,11 @@ int hv_synic_cleanup(unsigned int cpu)hv_set_simp (simp.as_uint64); -rdmsrl (HV_X64_MSR_SIEFP , siefp.as_uint64); +hv_get_siefp (siefp.as_uint64); siefp.siefp_enabled =0 ; siefp.base_siefp_gpa =0 ; -wrmsrl (HV_X64_MSR_SIEFP , siefp.as_uint64); +hv_set_siefp (siefp.as_uint64);/* Disable the global synic bit */ rdmsrl (HV_X64_MSR_SCONTROL , sctrl.as_uint64);
Signature · 1 line
1.7.4.1
PATCH 4/18 Drivers: hv: vmbus: Move Hypercall invocation code out of common code
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the hypercall invocation code to an architecture specific file.
--- arch/x86/hyperv/hv_init.c | 54 +++++++++++++++++++++++++++++++++++--- arch/x86/include/asm/mshyperv.h | 1 - drivers/hv/hv.c | 52 ------------------------------------- drivers/hv/hyperv_vmbus.h | 1 - 4 files changed, 49 insertions(+), 59 deletions(-)
arch/x86/hyperv/hv_init.c +49 -5
@@ -25,7 +25,7 @@#include <linux/vmalloc.h> #include <linux/mm.h> -void *hv_hypercall_pg; +static void *hypercall_pg;/* * This function is to be invoked early in the boot sequence after the * hypervisor has been detected.
@@ -48,15 +48,59 @@ void hyperv_init(void) guest_id =generate_guest_id (0 ,LINUX_VERSION_CODE ,0 );wrmsrl (HV_X64_MSR_GUEST_OS_ID , guest_id); - hv_hypercall_pg =__vmalloc (PAGE_SIZE ,GFP_KERNEL ,PAGE_KERNEL_EXEC ); -if (hv_hypercall_pg ==NULL ) { + hypercall_pg =__vmalloc (PAGE_SIZE ,GFP_KERNEL ,PAGE_KERNEL_EXEC ); +if (hypercall_pg ==NULL ) {wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 );return ; }rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); hypercall_msr.enable =1 ; - hypercall_msr.guest_physical_address =vmalloc_to_pfn (hv_hypercall_pg); + hypercall_msr.guest_physical_address =vmalloc_to_pfn (hypercall_pg);wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); } -EXPORT_SYMBOL_GPL (hv_hypercall_pg); + +/* +* hv_do_hypercall- Invoke the specified hypercall +*/ +u64 hv_do_hypercall (u64 control,void *input,void *output) +{ +u64 input_address = (input) ?virt_to_phys (input) :0 ; +u64 output_address = (output) ?virt_to_phys (output) :0 ; +#ifdef CONFIG_X86_64 +u64 hv_status =0 ; + +if (!hypercall_pg) +return (u64 )ULLONG_MAX ; + + __asm__ __volatile__("mov %0, %%r8" : :"r" (output_address) :"r8" ); + __asm__ __volatile__("call *%3" :"=a" (hv_status) : +"c" (control),"d" (input_address), +"m" (hypercall_pg)); + +return hv_status; + +#else + +u32 control_hi = control >>32 ; +u32 control_lo = control &0xFFFFFFFF ; +u32 hv_status_hi =1 ; +u32 hv_status_lo =1 ; +u32 input_address_hi = input_address >>32 ; +u32 input_address_lo = input_address &0xFFFFFFFF ; +u32 output_address_hi = output_address >>32 ; +u32 output_address_lo = output_address &0xFFFFFFFF ; + +if (!hypercall_pg) +return (u64 )ULLONG_MAX ; + + __asm__ __volatile__ ("call *%8" :"=d" (hv_status_hi), +"=a" (hv_status_lo) :"d" (control_hi), +"a" (control_lo),"b" (input_address_hi), +"c" (input_address_lo),"D" (output_address_hi), +"S" (output_address_lo),"m" (hypercall_pg)); + +return hv_status_lo | ((u64 )hv_status_hi <<32 ); +#endif /* !x86_64 */ +} +EXPORT_SYMBOL_GPL (hv_do_hypercall);
arch/x86/include/asm/mshyperv.h +0 -1
@@ -83,6 +83,5 @@ static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,#if IS_ENABLED (CONFIG_HYPERV )void hyperv_init (void ); -extern void *hv_hypercall_pg;#endif #endif
drivers/hv/hv.c +0 -52
76 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +0 -1
@@ -371,7 +371,6 @@ struct hv_context {*/ u64 guestid; -void *hypercall_page;void *tsc_page;bool synic_initialized;
Signature · 1 line
1.7.4.1
PATCH 12/18 Drivers: hv: vmbus: Get rid of an unsused variable
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
The version variable while it is initialized is not used; get rid of it.
--- drivers/hv/hv.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
drivers/hv/hv.c +0 -4
@@ -261,16 +261,12 @@ void hv_synic_free(void)*/ int hv_synic_init (unsigned int cpu) { -u64 version;union hv_synic_simp simp;union hv_synic_siefp siefp;union hv_synic_sint shared_sint;union hv_synic_scontrol sctrl;u64 vp_index; -/* Check the version */ -rdmsrl (HV_X64_MSR_SVERSION , version); -/* Setup the Synic's message page */ rdmsrl (HV_X64_MSR_SIMP , simp.as_uint64); simp.simp_enabled =1 ;
Signature · 1 line
1.7.4.1
PATCH 6/18 Drivers: hv: vmbus: Move the extracting of Hypervisor version information
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, extract hypervisor version information in an architecture specific file.
--- arch/x86/include/asm/mshyperv.h | 19 +++++++++++++++ arch/x86/kernel/cpu/mshyperv.c | 20 ++++++++++++++++ drivers/hv/connection.c | 7 +---- drivers/hv/hv.c | 49 --------------------------------------- drivers/hv/hyperv_vmbus.h | 27 --------------------- 5 files changed, 41 insertions(+), 81 deletions(-)
arch/x86/include/asm/mshyperv.h +19 -0
@@ -5,6 +5,25 @@#include <linux/interrupt.h> #include <asm/hyperv.h> +/* +* The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent +* is set by CPUID(HVCPUID_VERSION_FEATURES). +*/ +enum hv_cpuid_function { +HVCPUID_VERSION_FEATURES =0x00000001 , +HVCPUID_VENDOR_MAXFUNCTION =0x40000000 , +HVCPUID_INTERFACE =0x40000001 , + +/* +* The remaining functions depend on the value of +* HVCPUID_INTERFACE +*/ +HVCPUID_VERSION =0x40000002 , +HVCPUID_FEATURES =0x40000003 , +HVCPUID_ENLIGHTENMENT_INFO =0x40000004 , +HVCPUID_IMPLEMENTATION_LIMITS =0x40000005 , +}; +struct ms_hyperv_info {u32 features;u32 misc_features;
arch/x86/kernel/cpu/mshyperv.c +20 -0
@@ -140,6 +140,11 @@ static unsigned char hv_get_nmi_reason(void)static void __init ms_hyperv_init_platform (void ) { +int hv_host_info_eax; +int hv_host_info_ebx; +int hv_host_info_ecx; +int hv_host_info_edx; +/* * Extract the features and hints */
@@ -150,6 +155,21 @@ static void __init ms_hyperv_init_platform(void)pr_info ("HyperV: features 0x%x, hints 0x%x\n" , ms_hyperv.features, ms_hyperv.hints); +/* +* Extract host information. +*/ +if (cpuid_eax (HVCPUID_VENDOR_MAXFUNCTION ) >=HVCPUID_VERSION ) { + hv_host_info_eax =cpuid_eax (HVCPUID_VERSION ); + hv_host_info_ebx =cpuid_ebx (HVCPUID_VERSION ); + hv_host_info_ecx =cpuid_ecx (HVCPUID_VERSION ); + hv_host_info_edx =cpuid_edx (HVCPUID_VERSION ); + +pr_info ("Hyper-V Host Build:%d-%d.%d-%d-%d.%d\n" , + hv_host_info_eax, hv_host_info_ebx >>16 , + hv_host_info_ebx &0xFFFF , hv_host_info_ecx, + hv_host_info_edx >>24 , hv_host_info_edx &0xFFFFFF ); + } +#ifdef CONFIG_X86_LOCAL_APIC if (ms_hyperv.features &HV_X64_MSR_APIC_FREQUENCY_AVAILABLE ) {/*
drivers/hv/connection.c +2 -5
@@ -221,11 +221,8 @@ int vmbus_connect(void) goto cleanup; vmbus_proto_version = version; -pr_info ("Hyper-V Host Build:%d-%d.%d-%d-%d.%d; Vmbus version:%d.%d\n" , - host_info_eax, host_info_ebx >>16 , - host_info_ebx &0xFFFF , host_info_ecx, - host_info_edx >>24 , host_info_edx &0xFFFFFF , - version >>16 , version &0xFFFF ); +pr_info ("Vmbus version:%d.%d\n" , + version >>16 , version &0xFFFF );kfree (msginfo);return 0 ;
drivers/hv/hv.c +0 -49
67 lines not on this page · raw message
drivers/hv/hyperv_vmbus.h +0 -27
@@ -40,25 +40,6 @@*/ #define HV_UTIL_NEGO_TIMEOUT 55 -/* -* The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent -* is set by CPUID(HVCPUID_VERSION_FEATURES). -*/ -enum hv_cpuid_function { -HVCPUID_VERSION_FEATURES =0x00000001 , -HVCPUID_VENDOR_MAXFUNCTION =0x40000000 , -HVCPUID_INTERFACE =0x40000001 , - -/* -* The remaining functions depend on the value of -* HVCPUID_INTERFACE -*/ -HVCPUID_VERSION =0x40000002 , -HVCPUID_FEATURES =0x40000003 , -HVCPUID_ENLIGHTENMENT_INFO =0x40000004 , -HVCPUID_IMPLEMENTATION_LIMITS =0x40000005 , -}; -#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE 0x400#define HV_X64_MSR_CRASH_P0 0x40000100
@@ -444,14 +425,6 @@ extern int hv_post_message(union hv_connection_id connection_id,extern void hv_synic_clockevents_cleanup (void ); -/* -* Host version information. -*/ -extern unsigned int host_info_eax; -extern unsigned int host_info_ebx; -extern unsigned int host_info_ecx; -extern unsigned int host_info_edx; -/* Interface */
Signature · 1 line
1.7.4.1
PATCH 1/18 Drivers: hv: vmbus: Move the definition of hv_x64_msr_hypercall_contents
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the definition of hv_x64_msr_hypercall_contents to x86 specific header file.
--- arch/x86/include/asm/mshyperv.h | 12 ++++++++++++ drivers/hv/hyperv_vmbus.h | 15 --------------- 2 files changed, 12 insertions(+), 15 deletions(-)
arch/x86/include/asm/mshyperv.h +12 -0
@@ -13,6 +13,18 @@ struct ms_hyperv_info {extern struct ms_hyperv_info ms_hyperv; +/* +* Declare the MSR used to setup pages used to communicate with the hypervisor. +*/ +union hv_x64_msr_hypercall_contents { +u64 as_uint64; +struct { +u64 enable:1 ; +u64 reserved:11 ; +u64 guest_physical_address:52 ; + }; +}; +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hyperv_vmbus.h +0 -15
@@ -306,21 +306,6 @@ enum hv_guest_os_microsoft_ids { }; }; -/* -* Declare the MSR used to setup pages used to communicate with the hypervisor. -*/ -#define HV_X64_MSR_HYPERCALL 0x40000001 - -union hv_x64_msr_hypercall_contents { -u64 as_uint64; -struct { -u64 enable:1 ; -u64 reserved:11 ; -u64 guest_physical_address:52 ; - }; -}; - -enum {VMBUS_MESSAGE_CONNECTION_ID =1 ,VMBUS_MESSAGE_PORT_ID =1 ,
Signature · 1 line
1.7.4.1
PATCH 17/18 Drivers: hv: vmbus: Define an APIs to manage interrupt state
From: K. Y. Srinivasan <[email protected]>
As part of cleaning up architecture specific code, define APIs to manage interrupt state.
--- arch/x86/include/asm/mshyperv.h | 3 +++ drivers/hv/hv.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)
arch/x86/include/asm/mshyperv.h +3 -0
@@ -151,6 +151,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)#define hv_get_vp_index (index) rdmsrl(HV_X64_MSR_VP_INDEX, index) +#define hv_get_synint_state (int_num, val) rdmsrl(int_num, val) +#define hv_set_synint_state (int_num, val) wrmsrl(int_num, val) +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hv.c +8 -4
@@ -284,14 +284,16 @@ int hv_synic_init(unsigned int cpu)hv_set_siefp (siefp.as_uint64);/* Setup the shared SINT. */ -rdmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); +hv_get_synint_state (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , + shared_sint.as_uint64); shared_sint.as_uint64 =0 ; shared_sint.vector =HYPERVISOR_CALLBACK_VECTOR ; shared_sint.masked = false; shared_sint.auto_eoi = true; -wrmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); +hv_set_synint_state (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , + shared_sint.as_uint64);/* Enable the global synic bit */ hv_get_synic_state (sctrl.as_uint64);
@@ -384,13 +386,15 @@ int hv_synic_cleanup(unsigned int cpu)hv_ce_shutdown (hv_context.clk_evt[cpu]); } -rdmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); +hv_get_synint_state (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , + shared_sint.as_uint64); shared_sint.masked =1 ;/* Need to correctly cleanup in the case of SMP!!! */ /* Disable the interrupt */ -wrmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); +hv_set_synint_state (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , + shared_sint.as_uint64);hv_get_simp (simp.as_uint64); simp.simp_enabled =0 ;
Signature · 1 line
1.7.4.1
PATCH 13/18 Drivers: hv: vmbus: Define APIs to manipulate the message page
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of cleaning up architecture specific code, define APIs to manipulate the message page.
--- arch/x86/include/asm/mshyperv.h | 3 +++ drivers/hv/hv.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
arch/x86/include/asm/mshyperv.h +3 -0
@@ -140,6 +140,9 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)#define hv_init_timer (timer, tick) wrmsrl(timer, tick)#define hv_init_timer_config (config, val) wrmsrl(config, val) +#define hv_get_simp (val) rdmsrl(HV_X64_MSR_SIMP, val) +#define hv_set_simp (val) wrmsrl(HV_X64_MSR_SIMP, val) +void hyperv_callback_vector (void );#ifdef CONFIG_TRACING #define trace_hyperv_callback_vector hyperv_callback_vector
drivers/hv/hv.c +4 -4
@@ -268,12 +268,12 @@ int hv_synic_init(unsigned int cpu)u64 vp_index;/* Setup the Synic's message page */ -rdmsrl (HV_X64_MSR_SIMP , simp.as_uint64); +hv_get_simp (simp.as_uint64); simp.simp_enabled =1 ; simp.base_simp_gpa =virt_to_phys (hv_context.synic_message_page[cpu]) >>PAGE_SHIFT ; -wrmsrl (HV_X64_MSR_SIMP , simp.as_uint64); +hv_set_simp (simp.as_uint64);/* Setup the Synic's event page */ rdmsrl (HV_X64_MSR_SIEFP , siefp.as_uint64);
@@ -392,11 +392,11 @@ int hv_synic_cleanup(unsigned int cpu)/* Disable the interrupt */ wrmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64); -rdmsrl (HV_X64_MSR_SIMP , simp.as_uint64); +hv_get_simp (simp.as_uint64); simp.simp_enabled =0 ; simp.base_simp_gpa =0 ; -wrmsrl (HV_X64_MSR_SIMP , simp.as_uint64); +hv_set_simp (simp.as_uint64);rdmsrl (HV_X64_MSR_SIEFP , siefp.as_uint64); siefp.siefp_enabled =0 ;
Signature · 1 line
1.7.4.1
PATCH 7/18 Drivers: hv: vmbus: Move the crash notification function
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the crash notification function.
--- arch/x86/hyperv/hv_init.c | 26 ++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + arch/x86/include/uapi/asm/hyperv.h | 8 ++++++++ drivers/hv/hyperv_vmbus.h | 10 ---------- drivers/hv/vmbus_drv.c | 25 ------------------------- 5 files changed, 35 insertions(+), 35 deletions(-)
arch/x86/hyperv/hv_init.c +26 -0
@@ -208,3 +208,29 @@ u64 hv_do_hypercall(u64 control, void *input, void *output)#endif /* !x86_64 */ }EXPORT_SYMBOL_GPL (hv_do_hypercall); + +void hyperv_report_panic (struct pt_regs *regs) +{ +static bool panic_reported; + +/* +* We prefer to report panic on 'die' chain as we have proper +* registers to report, but if we miss it (e.g. on BUG()) we need +* to report it on 'panic'. +*/ +if (panic_reported) +return ; + panic_reported = true; + +wrmsrl (HV_X64_MSR_CRASH_P0 , regs->ip); +wrmsrl (HV_X64_MSR_CRASH_P1 , regs->ax); +wrmsrl (HV_X64_MSR_CRASH_P2 , regs->bx); +wrmsrl (HV_X64_MSR_CRASH_P3 , regs->cx); +wrmsrl (HV_X64_MSR_CRASH_P4 , regs->dx); + +/* +* Let Hyper-V know there is crash data available +*/ +wrmsrl (HV_X64_MSR_CRASH_CTL ,HV_CRASH_CTL_CRASH_NOTIFY ); +} +EXPORT_SYMBOL_GPL (hyperv_report_panic);
arch/x86/include/asm/mshyperv.h +1 -0
@@ -114,5 +114,6 @@ static inline __u64 generate_guest_id(__u64 d_info1, __u64 kernel_version,#if IS_ENABLED (CONFIG_HYPERV )void hyperv_init (void ); +void hyperv_report_panic (struct pt_regs *regs);#endif #endif
arch/x86/include/uapi/asm/hyperv.h +8 -0
@@ -73,6 +73,9 @@*/ #define HV_X64_MSR_STAT_PAGES_AVAILABLE (1 << 8) +/* Crash MSR available */ +#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE (1 << 10) +/* * Feature identification: EBX indicates which flags were specified at * partition creation. The format is the same as the partition creation
@@ -144,6 +147,11 @@*/ #define HV_X64_RELAXED_TIMING_RECOMMENDED (1 << 5) +/* +* Crash notification flag. +*/ +#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63) +/* MSR used to identify the guest OS. */ #define HV_X64_MSR_GUEST_OS_ID 0x40000000
drivers/hv/hyperv_vmbus.h +0 -10
@@ -40,16 +40,6 @@*/ #define HV_UTIL_NEGO_TIMEOUT 55 -#define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE 0x400 - -#define HV_X64_MSR_CRASH_P0 0x40000100 -#define HV_X64_MSR_CRASH_P1 0x40000101 -#define HV_X64_MSR_CRASH_P2 0x40000102 -#define HV_X64_MSR_CRASH_P3 0x40000103 -#define HV_X64_MSR_CRASH_P4 0x40000104 -#define HV_X64_MSR_CRASH_CTL 0x40000105 - -#define HV_CRASH_CTL_CRASH_NOTIFY (1ULL << 63)/* Define version of the synthetic interrupt controller. */ #define HV_SYNIC_VERSION (1)
drivers/hv/vmbus_drv.c +0 -25
@@ -56,31 +56,6 @@ struct vmbus_dynid {static int hyperv_cpuhp_online; -static void hyperv_report_panic (struct pt_regs *regs) -{ -static bool panic_reported; - -/* -* We prefer to report panic on 'die' chain as we have proper -* registers to report, but if we miss it (e.g. on BUG()) we need -* to report it on 'panic'. -*/ -if (panic_reported) -return ; - panic_reported = true; - -wrmsrl (HV_X64_MSR_CRASH_P0 , regs->ip); -wrmsrl (HV_X64_MSR_CRASH_P1 , regs->ax); -wrmsrl (HV_X64_MSR_CRASH_P2 , regs->bx); -wrmsrl (HV_X64_MSR_CRASH_P3 , regs->cx); -wrmsrl (HV_X64_MSR_CRASH_P4 , regs->dx); - -/* -* Let Hyper-V know there is crash data available -*/ -wrmsrl (HV_X64_MSR_CRASH_CTL ,HV_CRASH_CTL_CRASH_NOTIFY ); -} -static int hyperv_panic_event (struct notifier_block *nb,unsigned long val,void *args) {
Signature · 1 line
1.7.4.1
Re: [PATCH 01/18] Drivers: hv: vmbus: Move the definition of hv_x64_msr_hypercall_contents
In reply to [email protected]Quoted 10 lines · On Fri, Dec 30, 2016 at 01:35:55PM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the definition of
hv_x64_msr_hypercall_contentsto x86 specific header file.Signed-off-by K. Y. Srinivasan <[email protected]>--- arch/x86/include/asm/mshyperv.h | 12 ++++++++++++ drivers/hv/hyperv_vmbus.h | 15 --------------- 2 files changed, 12 insertions(+), 15 deletions(-)
This series doesn't apply against my tree. Can you please refresh it and resend?
thanks,
greg k-h
RE: [PATCH 01/18] Drivers: hv: vmbus: Move the definition of hv_x64_msr_hypercall_contents
Quoted 20 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, January 10, 2017 9:27 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 01/18] Drivers: hv: vmbus: Move the definition ofhv_x64_msr_hypercall_contentsQuoted 5 lines · On Fri, Dec 30, 2016 at 01:35:55PM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the definition of
hv_x64_msr_hypercall_contentsto x86 specific header file.
Quoted 8 lines
Quoted 5 lines
Signed-off-by K. Y. Srinivasan <[email protected]>--- arch/x86/include/asm/mshyperv.h | 12 ++++++++++++ drivers/hv/hyperv_vmbus.h | 15 --------------- 2 files changed, 12 insertions(+), 15 deletions(-)This series doesn't apply against my tree. Can you please refresh it and resend?
Will do.
K. Y
Quoted 4 lines
thanks,
greg k-h
Re: [PATCH 01/18] Drivers: hv: vmbus: Move the definition of hv_x64_msr_hypercall_contents
Quoted 24 lines · On Thu, 12 Jan 2017 02:32:24 +0000 KY Srinivasan <[email protected]> wrote:
Quoted 24 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, January 10, 2017 9:27 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 01/18] Drivers: hv: vmbus: Move the definition ofhv_x64_msr_hypercall_contentsQuoted 10 lines · On Fri, Dec 30, 2016 at 01:35:55PM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
As part of the effort to separate out architecture specific code, move the definition of
hv_x64_msr_hypercall_contentsto x86 specific header file.Signed-off-by K. Y. Srinivasan <[email protected]>--- arch/x86/include/asm/mshyperv.h | 12 ++++++++++++ drivers/hv/hyperv_vmbus.h | 15 --------------- 2 files changed, 12 insertions(+), 15 deletions(-)
Quoted 6 lines
Quoted 2 lines
This series doesn't apply against my tree. Can you please refresh it and resend?
Will do.
K. Y
Send me the patches, I have a vmbus-next tree ready for pull request.