hyperv: more stuff to uapi + cleanup
Subsystems (5)
cover hyperv: more stuff to uapi + cleanup
Expose more Hyper-V-related definitions in the uapi header for consumption by userspace.
While doing so, get rid of a number of duplications between the KVM and the guest driver code. Also a few other cleanups are made which are not strictly necessary for the main purpose of the series but appear reasonable to do at the same time.
The most controversial is the last patch which modifies the stuff already published in the uapi header, in the hope that no userspace applications have started relying on it; I'm ok dropping it if this is unacceptable.
Roman Kagan (15):
hyperv: consolidate TSC ref page definitions
hyperv: uapi-fy synic event flags definitions
hyperv: use standard bitops
hyperv: define VMBus message type
hyperv: GFP_ATOMIC -> GFP_KERNEL
hyperv: avoid unnecessary vmalloc
hyperv: dedup cpuid definitions
hyperv: dedup crash msr related definitions
hyperv: unify Hyper-V msr definitions
hyperv: uapi-fy PostMessage and SignalEvent hypercall structures
hyperv: uapi-fy monitored notification structures
hyperv: move VMBus connection ids to uapi
hyperv: move function close to its only callsite
hyperv_vmbus: drop unused definitions
hyperv: redefine hv_message without bitfields
arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/uapi/asm/hyperv.h | 101 +++++++--- drivers/hv/hyperv_vmbus.h | 399 +------------------------------------ include/linux/hyperv.h | 24 +-- arch/x86/kvm/hyperv.c | 14 +- drivers/hv/channel.c | 8 +- drivers/hv/channel_mgmt.c | 30 +-- drivers/hv/connection.c | 65 ++---- drivers/hv/hv.c | 300 +++++++++++++--------------- drivers/hv/vmbus_drv.c | 67 +++---- 10 files changed, 288 insertions(+), 722 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/15 hyperv: consolidate TSC ref page definitions
Consolidate the guest-side and kvm-side definitions for Hyper-V TSC reference page.
While at this, rewrite read_hv_clock_tsc using the existing helpers.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/uapi/asm/hyperv.h | 4 +-- drivers/hv/hyperv_vmbus.h | 8 ------ arch/x86/kvm/hyperv.c | 4 +-- drivers/hv/hv.c | 54 +++++++++++++++----------------------- 5 files changed, 26 insertions(+), 46 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -713,7 +713,7 @@ struct kvm_hv {u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS ];u64 hv_crash_ctl; -HV_REFERENCE_TSC_PAGE tsc_ref; +struct hv_ref_tsc_page tsc_ref; };struct kvm_arch {
arch/x86/include/uapi/asm/hyperv.h +2 -2
@@ -252,12 +252,12 @@#define HV_STATUS_INVALID_CONNECTION_ID 18#define HV_STATUS_INSUFFICIENT_BUFFERS 19 -typedef struct _HV_REFERENCE_TSC_PAGE { +struct hv_ref_tsc_page {__u32 tsc_sequence;__u32 res1;__u64 tsc_scale;__s64 tsc_offset; -}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; +};/* Define the number of synthetic interrupt sources. */ #define HV_SYNIC_SINT_COUNT (16)
drivers/hv/hyperv_vmbus.h +0 -8
@@ -475,14 +475,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;
arch/x86/kvm/hyperv.c +2 -2
@@ -806,7 +806,7 @@ static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,* These two equivalencies are implemented in this function. */ static bool compute_tsc_page_parameters (struct pvclock_vcpu_time_info *hv_clock, -HV_REFERENCE_TSC_PAGE *tsc_ref) +struct hv_ref_tsc_page *tsc_ref) {u64 max_mul;
@@ -847,7 +847,7 @@ void kvm_hv_setup_tsc_page(struct kvm *kvm,u64 gfn;BUILD_BUG_ON (sizeof (tsc_seq) !=sizeof (hv->tsc_ref.tsc_sequence)); -BUILD_BUG_ON (offsetof(HV_REFERENCE_TSC_PAGE , tsc_sequence) !=0 ); +BUILD_BUG_ON (offsetof(struct hv_ref_tsc_page , tsc_sequence) !=0 );if (!(hv->hv_tsc_page &HV_X64_MSR_TSC_REFERENCE_ENABLE ))return ;
drivers/hv/hv.c +21 -33
62 lines not on this page · raw message
Signature · 1 line
2.9.3
RE: [PATCH 01/15] hyperv: consolidate TSC ref page definitions
Quoted 15 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 01/15] hyperv: consolidate TSC ref page definitions
Quoted 4 lines
Consolidate the guest-side and kvm-side definitions for Hyper-V TSC reference page.
While at this, rewrite
read_hv_clock_tscusing the existing helpers.
Why not beak this into separate patches.
Quoted 160 lines
Signed-off-by Roman Kagan <[email protected]>--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/uapi/asm/hyperv.h | 4 +-- drivers/hv/hyperv_vmbus.h | 8 ------ arch/x86/kvm/hyperv.c | 4 +-- drivers/hv/hv.c | 54 +++++++++++++++----------------------- 5 files changed, 26 insertions(+), 46 deletions(-)arch/x86/include/asm/kvm_host.h +1
-1@@ -713,7 +713,7 @@ struct kvm_hv {u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS ];u64 hv_crash_ctl; -HV_REFERENCE_TSC_PAGE tsc_ref; +struct hv_ref_tsc_page tsc_ref; };struct kvm_arch {arch/x86/include/uapi/asm/hyperv.h +2
-2@@ -252,12 +252,12 @@#define HV_STATUS_INVALID_CONNECTION_ID 18#define HV_STATUS_INSUFFICIENT_BUFFERS 19 -typedef struct _HV_REFERENCE_TSC_PAGE { +struct hv_ref_tsc_page {__u32 tsc_sequence;__u32 res1;__u64 tsc_scale;__s64 tsc_offset; -}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; +};/* Define the number of synthetic interrupt sources. */ #define HV_SYNIC_SINT_COUNT (16)drivers/hv/hyperv_vmbus.h +0
-8@@ -475,14 +475,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;arch/x86/kvm/hyperv.c +1
-1@@ -806,7 +806,7 @@ static int kvm_hv_msr_set_crash_data(structkvm_vcpu *vcpu, * These two equivalencies are implemented in this function. */ static bool compute_tsc_page_parameters (struct pvclock_vcpu_time_info *hv_clock, -HV_REFERENCE_TSC_PAGE *tsc_ref) +struct hv_ref_tsc_page *tsc_ref) {arch/x86/kvm/hyperv.c +1
-1u64 max_mul;@@ -847,7 +847,7 @@ void kvm_hv_setup_tsc_page(struct kvm *kvm,u64 gfn;BUILD_BUG_ON (sizeof (tsc_seq) !=sizeof (hv- >tsc_ref.tsc_sequence)); -BUILD_BUG_ON (offsetof(HV_REFERENCE_TSC_PAGE , tsc_sequence) != 0); +BUILD_BUG_ON (offsetof(struct hv_ref_tsc_page , tsc_sequence) !=0 );arch/x86/kvm/hyperv.c +0
-0if (!(hv->hv_tsc_page &HV_X64_MSR_TSC_REFERENCE_ENABLE ))return ;drivers/hv/hv.c +21
-33@@ -137,41 +137,29 @@ EXPORT_SYMBOL_GPL(hv_do_hypercall);#ifdef CONFIG_X86_64 static cycle_t read_hv_clock_tsc (struct clocksource *arg) { -cycle_t current_tick; -struct ms_hyperv_tsc_page *tsc_pg = hv_context.tsc_page; +struct hv_ref_tsc_page *tsc_pg = hv_context.tsc_page; +u32 sequence; +u64 scale; +s64 offset; + +do { + sequence = tsc_pg->tsc_sequence; +virt_rmb (); + +if (!sequence) { +/* fallback to MSR */ +cycle_t current_tick; +rdmsrl (HV_X64_MSR_TIME_REF_COUNT , current_tick); +return current_tick; + } -if (tsc_pg->tsc_sequence !=0 ) { -/* -* Use the tsc page to compute the value. -*/ + scale = tsc_pg->tsc_scale; + offset = tsc_pg->tsc_offset; -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; +virt_rmb (); + }while (tsc_pg->tsc_sequence != sequence); + +return mul_u64_u64_shr (rdtsc_ordered (), scale,64 ) + offset; }static struct clocksource
hyperv_cs_tsc= {
--
2.9.3
Re: [PATCH 01/15] hyperv: consolidate TSC ref page definitions
Quoted 15 lines · KY Srinivasan
Quoted 15 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 01/15] hyperv: consolidate TSC ref page definitions
Quoted 6 lines
Quoted 4 lines
Consolidate the guest-side and kvm-side definitions for Hyper-V TSC reference page.
While at this, rewrite
read_hv_clock_tscusing the existing helpers.Why not beak this into separate patches.
Agreed, I'll do it in the next iteration.
Thanks,
Roman.
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
PATCH 2/15 hyperv: uapi-fy synic event flags definitions
In reply to Roman KaganMove definitions related to the Hyper-V SynIC event flags to a header where they can be consumed by userspace.
While doing so, also clean up their use by switching to standard bitops and struct-based dereferencing. The latter is also done for message pages.
--- arch/x86/include/uapi/asm/hyperv.h | 13 +++++++++ drivers/hv/hyperv_vmbus.h | 24 ++-------------- drivers/hv/channel_mgmt.c | 10 +++---- drivers/hv/connection.c | 47 ++++++++++--------------------- drivers/hv/vmbus_drv.c | 57 ++++++++++++++------------------------ 5 files changed, 54 insertions(+), 97 deletions(-)
arch/x86/include/uapi/asm/hyperv.h +13 -0
@@ -363,4 +363,17 @@ struct hv_timer_message_payload {#define HV_STIMER_AUTOENABLE (1ULL << 3)#define HV_STIMER_SINT (config) (__u8)(((config) >> 16) & 0x0F) +/* Define synthetic interrupt controller flag constants. */ +#define HV_EVENT_FLAGS_COUNT (256 * 8) + +/* Define the synthetic interrupt controller event flags format. */ +struct hv_synic_event_flags { +__u64 flags[HV_EVENT_FLAGS_COUNT /64 ]; +}; + +/* Define the synthetic interrupt flags page layout. */ +struct hv_synic_event_flags_page { +struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT ]; +}; +#endif
drivers/hv/hyperv_vmbus.h +2 -22
@@ -26,7 +26,6 @@#define _HYPERV_VMBUS_H#include <linux/list.h> -#include <asm/sync_bitops.h> #include <linux/atomic.h> #include <linux/hyperv.h>
@@ -75,11 +74,6 @@ enum hv_cpuid_function {#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)
@@ -146,20 +140,6 @@ union hv_timer_config { }; }; -/* 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 { -u8 flags8[HV_EVENT_FLAGS_BYTE_COUNT ]; -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;
@@ -434,8 +414,8 @@ struct hv_context {bool synic_initialized; -void *synic_message_page[NR_CPUS ]; -void *synic_event_page[NR_CPUS ]; +struct hv_message_page *synic_message_page[NR_CPUS ]; +struct hv_synic_event_flags_page *synic_event_page[NR_CPUS ];/* * Hypervisor's notion of virtual processor ID is different from * Linux' notion of CPU ID. This information can only be retrieved
drivers/hv/channel_mgmt.c +4 -6
@@ -654,7 +654,6 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type)static void vmbus_wait_for_unload (void ) {int cpu; -void *page_addr;struct hv_message *msg;struct vmbus_channel_message_header *hdr;u32 message_type;
@@ -673,9 +672,8 @@ static void vmbus_wait_for_unload(void)break ;for_each_online_cpu (cpu) { - page_addr = hv_context.synic_message_page[cpu]; - msg = (struct hv_message *)page_addr + -VMBUS_MESSAGE_SINT ; + msg = &hv_context.synic_message_page[cpu]-> + sint_message[VMBUS_MESSAGE_SINT ]; message_type =READ_ONCE (msg->header.message_type);if (message_type ==HVMSG_NONE )
@@ -699,8 +697,8 @@ static void vmbus_wait_for_unload(void)* messages after we reconnect. */ for_each_online_cpu (cpu) { - page_addr = hv_context.synic_message_page[cpu]; - msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ; + msg = &hv_context.synic_message_page[cpu]-> + sint_message[VMBUS_MESSAGE_SINT ]; msg->header.message_type =HVMSG_NONE ; } }
drivers/hv/connection.c +14 -33
67 lines not on this page · raw message
drivers/hv/vmbus_drv.c +21 -36
84 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions
Quoted 28 lines · On Tue, 20 Dec 2016 18:55:49 +0300 Roman Kagan <[email protected]> wrote:
Move definitions related to the Hyper-V SynIC event flags to a header where they can be consumed by userspace.
While doing so, also clean up their use by switching to standard bitops and struct-based dereferencing. The latter is also done for message pages.
Signed-off-by Roman Kagan <[email protected]>--- arch/x86/include/uapi/asm/hyperv.h | 13 +++++++++ drivers/hv/hyperv_vmbus.h | 24 ++-------------- drivers/hv/channel_mgmt.c | 10 +++---- drivers/hv/connection.c | 47 ++++++++++--------------------- drivers/hv/vmbus_drv.c | 57 ++++++++++++++------------------------ 5 files changed, 54 insertions(+), 97 deletions(-)arch/x86/include/uapi/asm/hyperv.h +4
-0@@ -363,4 +363,17 @@ struct hv_timer_message_payload {#define HV_STIMER_AUTOENABLE (1ULL << 3)#define HV_STIMER_SINT (config) (__u8)(((config) >> 16) & 0x0F) +/* Define synthetic interrupt controller flag constants. */ +#define HV_EVENT_FLAGS_COUNT (256 * 8) + +/* Define the synthetic interrupt controller event flags format. */
arch/x86/include/uapi/asm/hyperv.h struct hv_timer_message_payload { · line 379
Quoted 10 lines
arch/x86/include/uapi/asm/hyperv.h +9
-0+struct hv_synic_event_flags { +__u64 flags[HV_EVENT_FLAGS_COUNT /64 ]; +}; + +/* Define the synthetic interrupt flags page layout. */ +struct hv_synic_event_flags_page { +struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT ]; +}; +#endif
How are these going to be exposed to user space?
They should really be unsigned long since there is no guarantee of atomic operation on 64 bit values on 32 bit architectures.
Re: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions
Quoted 44 lines · Stephen Hemminger
Quoted 28 lines · On Tue, 20 Dec 2016 18:55:49 +0300 Roman Kagan <[email protected]> wrote:
Move definitions related to the Hyper-V SynIC event flags to a header where they can be consumed by userspace.
While doing so, also clean up their use by switching to standard bitops and struct-based dereferencing. The latter is also done for message pages.
Signed-off-by Roman Kagan <[email protected]>--- arch/x86/include/uapi/asm/hyperv.h | 13 +++++++++ drivers/hv/hyperv_vmbus.h | 24 ++-------------- drivers/hv/channel_mgmt.c | 10 +++---- drivers/hv/connection.c | 47 ++++++++++--------------------- drivers/hv/vmbus_drv.c | 57 ++++++++++++++------------------------ 5 files changed, 54 insertions(+), 97 deletions(-)arch/x86/include/uapi/asm/hyperv.h +4
-0@@ -363,4 +363,17 @@ struct hv_timer_message_payload {#define HV_STIMER_AUTOENABLE (1ULL << 3)#define HV_STIMER_SINT (config) (__u8)(((config) >> 16) & 0x0F) +/* Define synthetic interrupt controller flag constants. */ +#define HV_EVENT_FLAGS_COUNT (256 * 8) + +/* Define the synthetic interrupt controller event flags format. */ arch/x86/include/uapi/asm/hyperv.h struct hv_timer_message_payload { · line 379
Quoted 10 lines
arch/x86/include/uapi/asm/hyperv.h +9
-0+struct hv_synic_event_flags { +__u64 flags[HV_EVENT_FLAGS_COUNT /64 ]; +}; + +/* Define the synthetic interrupt flags page layout. */ +struct hv_synic_event_flags_page { +struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT ]; +}; +#endif How are these going to be exposed to user space?
Quoted 2 lines
They should really be unsigned long since there is no guarantee of atomic operation on 64 bit values on 32 bit architectures.
Indeed, absolutely. These are bitmaps and should be unsigned long[], of course. I'll fix it in the next iteration.
Thanks,
Roman.
kbuild test robot
build botRe: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions
In reply to Roman Kaganurl: https://github.com/0day-ci/linux/commits/Roman-Kagan/hyperv-more-stuff-to-uapi-cleanup/20161221-130415 config: x86_64-rhel (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901…
Hi Roman,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.9 next-20161221]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Roman-Kagan/hyperv-more-stuff-to-uapi-cleanup/20161221-130415
config: x86_64-rhel (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 Note: the linux-review/Roman-Kagan/hyperv-more-stuff-to-uapi-cleanup/20161221-130415 HEAD 35a54cd6795c4aa6f101c58ab076c6bdd63b3779 builds fine.
It only hurts bisectibility.
All errors (new ones prefixed by >>):
drivers/hv/connection.c: In function 'vmbus_set_event':
>> drivers/hv/connection.c:473:3: error: implicit declaration of function 'sync_set_bit' [-Werror=implicit-function-declaration]
sync_set_bit(child_relid & 31,
^~~~~~~~~~~~
cc1: some warnings being treated as errors
--
drivers/hv/channel.c: In function 'vmbus_setevent':
>> drivers/hv/channel.c:53:3: error: implicit declaration of function 'sync_set_bit' [-Werror=implicit-function-declaration]
sync_set_bit(channel->offermsg.child_relid & 31,
^~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/sync_set_bit +473 drivers/hv/connection.c
1b807e101 drivers/hv/connection.c K. Y. Srinivasan 2015-12-21 467 void vmbus_set_event(struct vmbus_channel *channel)
3e7ee4902 drivers/staging/hv/Connection.c Hank Janssen 2009-07-13 468 {
21c3bef5d drivers/hv/connection.c K. Y. Srinivasan 2012-12-01 469 u32 child_relid = channel->offermsg.child_relid;
3be777740 drivers/hv/connection.c K. Y. Srinivasan 2012-12-01 470
3be777740 drivers/hv/connection.c K. Y. Srinivasan 2012-12-01 471 if (!channel->is_dedicated_interrupt) {
454f18a96 drivers/staging/hv/Connection.c Bill Pemberton 2009-07-27 472 /* Each u32 represents 32 channels */
223565857 drivers/staging/hv/connection.c Olaf Hering 2011-03-21 @473 sync_set_bit(child_relid & 31,
da9fcb726 drivers/staging/hv/connection.c Haiyang Zhang 2011-01-26 474 (unsigned long *)vmbus_connection.send_int_page +
15b2f6479 drivers/staging/hv/connection.c Haiyang Zhang 2011-01-26 475 (child_relid >> 5));
3be777740 drivers/hv/connection.c K. Y. Srinivasan 2012-12-01 476 }:::::: The code at line 473 was first introduced by commit
:::::: 22356585712d1ff08fbfed152edd8b386873b238 staging: hv: use sync_bitops when interacting with the hypervisor
:::::: TO: Olaf Hering <[email protected]> :::::: CC: Greg Kroah-Hartman <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
RE: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions
In reply to Roman KaganQuoted 15 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 02/15] hyperv: uapi-fy synic event flags definitions
Quoted 6 lines
Move definitions related to the Hyper-V SynIC event flags to a header where they can be consumed by userspace.
While doing so, also clean up their use by switching to standard bitops and struct-based dereferencing. The latter is also done for message pages.
Please breakup this patch.
Quoted 190 lines
Signed-off-by Roman Kagan <[email protected]>--- arch/x86/include/uapi/asm/hyperv.h | 13 +++++++++ drivers/hv/hyperv_vmbus.h | 24 ++-------------- drivers/hv/channel_mgmt.c | 10 +++---- drivers/hv/connection.c | 47 ++++++++++--------------------- drivers/hv/vmbus_drv.c | 57 ++++++++++++++------------------------ 5 files changed, 54 insertions(+), 97 deletions(-)arch/x86/include/uapi/asm/hyperv.h +11
-0@@ -363,4 +363,17 @@ struct hv_timer_message_payload {#define HV_STIMER_AUTOENABLE (1ULL << 3)#define HV_STIMER_SINT (config) (__u8)(((config) >> 16) & 0x0F) +/* Define synthetic interrupt controller flag constants. */ +#define HV_EVENT_FLAGS_COUNT (256 * 8) + +/* Define the synthetic interrupt controller event flags format. */ +struct hv_synic_event_flags { +__u64 flags[HV_EVENT_FLAGS_COUNT /64 ]; +}; + +/* Define the synthetic interrupt flags page layout. */ +struct hv_synic_event_flags_page { +struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT];
arch/x86/include/uapi/asm/hyperv.h +2
-0+}; +#endif drivers/hv/hyperv_vmbus.h +0
-20@@ -26,7 +26,6 @@#define _HYPERV_VMBUS_H#include <linux/list.h> -#include <asm/sync_bitops.h> #include <linux/atomic.h> #include <linux/hyperv.h> @@ -75,11 +74,6 @@ enum hv_cpuid_function {#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)@@ -146,20 +140,6 @@ union hv_timer_config { }; }; -/* 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 { -u8 flags8[HV_EVENT_FLAGS_BYTE_COUNT ]; -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 {drivers/hv/hyperv_vmbus.h +2
-2u64 as_uint64;@@ -434,8 +414,8 @@ struct hv_context {bool synic_initialized; -void *synic_message_page[NR_CPUS ]; -void *synic_event_page[NR_CPUS ]; +struct hv_message_page *synic_message_page[NR_CPUS ]; +struct hv_synic_event_flags_page *synic_event_page[NR_CPUS ];/* * Hypervisor's notion of virtual processor ID is different from * Linux' notion of CPU ID. This information can only be retrieved drivers/hv/channel_mgmt.c +0
-1@@ -654,7 +654,6 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type)static void vmbus_wait_for_unload (void ) {int cpu; -void *page_addr;struct hv_message *msg;struct vmbus_channel_message_header *hdr;drivers/hv/channel_mgmt.c +2
-3u32 message_type;@@ -673,9 +672,8 @@ static void vmbus_wait_for_unload(void)break ;for_each_online_cpu (cpu) { - page_addr = hv_context.synic_message_page[cpu]; - msg = (struct hv_message *)page_addr + -VMBUS_MESSAGE_SINT ; + msg = &hv_context.synic_message_page[cpu]-> + sint_message[VMBUS_MESSAGE_SINT ]; message_type = READ_ONCE(msg-Quoted 1 line
header.message_type);
drivers/hv/channel_mgmt.c +2
-2if (message_type ==HVMSG_NONE )@@ -699,8 +697,8 @@ static void vmbus_wait_for_unload(void)* messages after we reconnect. */ for_each_online_cpu (cpu) { - page_addr = hv_context.synic_message_page[cpu]; - msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ; + msg = &hv_context.synic_message_page[cpu]-> + sint_message[VMBUS_MESSAGE_SINT ]; msg->header.message_type =HVMSG_NONE ; }}
drivers/hv/connection.c +8
-28@@ -381,17 +381,12 @@ static void process_chn_event(u32 relid)*/ void vmbus_on_event (unsigned long data) { -u32 dword; -u32 maxdword; -int bit; -u32 relid; -u32 *recv_int_page =NULL ; -void *page_addr; +u32 relid, max_relid; +unsigned long *recv_int_page;int cpu =smp_processor_id (); -union hv_synic_event_flags *event;if (vmbus_proto_version <VERSION_WIN8 ) { - maxdword =MAX_NUM_CHANNELS_SUPPORTED >>5 ; + max_relid =MAX_NUM_CHANNELS_SUPPORTED ; recv_int_page = vmbus_connection.recv_int_page; }else {/* @@ -399,36 +394,22 @@ void vmbus_on_event(unsigned long data)* can be directly checked to get the id of the channel * that has the interrupt pending. */ - maxdword =HV_EVENT_FLAGS_DWORD_COUNT ; - page_addr = hv_context.synic_event_page[cpu]; - event = (union hv_synic_event_flags *)page_addr + -VMBUS_MESSAGE_SINT ; - recv_int_page = event->flags32; +struct hv_synic_event_flags *event = + &hv_context.synic_event_page[cpu]-> + sintevent_flags[VMBUS_MESSAGE_SINT ]; + max_relid =HV_EVENT_FLAGS_COUNT ; + recv_int_page = (unsigned long *)event->flags; } - -/* Check events */ if (!recv_int_page)return ; -for (dword =0 ; dword < maxdword; dword++) { -if (!recv_int_page[dword]) -continue ; -for (bit =0 ; bit <32 ; bit++) { -if (sync_test_and_clear_bit (bit, - (unsigned long *)&recv_int_page[dword])) { - relid = (dword <<5 ) + bit; - -if (relid ==0 ) -/* -* Special case - vmbus -* channel protocol msg -*/
drivers/hv/connection.c void vmbus_on_event(unsigned long data) · line 411
Quoted 10 lines
drivers/hv/connection.c +5
-5-continue ; - -process_chn_event (relid); - } - } + +/* relid == 0 is vmbus channel protocol msg */ + relid =1 ; +for_each_set_bit_from (relid, recv_int_page, max_relid) { +clear_bit (relid, recv_int_page);
We are using this test_and_clear_bit paradigm for locking. The current code used the sync variant to ensure the host saw the changes we were making here (clearing the bit). You may want to add a barrier here or use the sync variant.
Quoted 62 lines
drivers/hv/connection.c +1
-0+process_chn_event (relid); } }drivers/hv/vmbus_drv.c +1
-3@@ -872,9 +872,8 @@ static void hv_process_timer_expiration(struct hv_message *msg, int cpu) void vmbus_on_msg_dpc(unsigned long data) { int cpu = smp_processor_id(); -void *page_addr = hv_context.synic_message_page[cpu]; -struct hv_message *msg = (struct hv_message *)page_addr + -VMBUS_MESSAGE_SINT ; + struct hv_message *msg = &hv_context.synic_message_page[cpu]-Quoted 1 line
+
sint_message[VMBUS_MESSAGE_SINT];drivers/hv/vmbus_drv.c +8
-16struct vmbus_channel_message_header *hdr;struct vmbus_channel_message_table_entry *entry;struct onmessage_work_context *ctx;@@ -911,54 +910,40 @@ void vmbus_on_msg_dpc(unsigned long data)static void vmbus_isr (void ) {int cpu =smp_processor_id (); -void *page_addr;struct hv_message *msg; -union hv_synic_event_flags *event; -bool handled = false; +struct hv_synic_event_flags *event; - page_addr = hv_context.synic_event_page[cpu]; -if (page_addr ==NULL ) +if (!hv_context.synic_event_page[cpu])return ; - event = (union hv_synic_event_flags *)page_addr + -VMBUS_MESSAGE_SINT ; + event = &hv_context.synic_event_page[cpu]-> + sintevent_flags[VMBUS_MESSAGE_SINT ];/* * Check for events before checking for messages. This is the order * in which events and messages are checked in Windows guests on * Hyper-V, and the Windows team suggested we do the same. */ -if ((vmbus_proto_version ==VERSION_WS2008 ) || - (vmbus_proto_version ==VERSION_WIN7 )) { - +/* On win8 and above the channel interrupts are signaled directly in +* the event page and will be checked in the .event_dpc +*/ + if (vmbus_proto_version >= VERSION_WIN8 ||/* Since we are a child, we only need to check bit 0 */ -if (sync_test_and_clear_bit (0 , - (unsigned long *) &event->flags32[0 ])) { - handled = true; - } - }else { -/*
drivers/hv/vmbus_drv.c void vmbus_on_msg_dpc(unsigned long data) · line 932
Quoted 10 lines
drivers/hv/vmbus_drv.c +1
-9-* Our host is win8 or above. The signaling mechanism -* has changed and we can directly look at the event page. -* If bit n is set then we have an interrup on the channel -* whose id is n. -*/ - handled = true; - } - -if (handled) + test_and_clear_bit(0, (unsigned long *)event->flags))
Don't we need the sync variant of test_and_clear_bit here.
Quoted 27 lines
drivers/hv/vmbus_drv.c +10
-9tasklet_schedule (hv_context.event_dpc[cpu]); - - page_addr = hv_context.synic_message_page[cpu]; - msg = (struct hv_message *)page_addr +VMBUS_MESSAGE_SINT ; + msg = &hv_context.synic_message_page[cpu]-> + sint_message[VMBUS_MESSAGE_SINT ];/* Check if there are actual msgs to be processed */ -if (msg->header.message_type !=HVMSG_NONE ) { -if (msg->header.message_type ==HVMSG_TIMER_EXPIRED ) -hv_process_timer_expiration (msg, cpu); -else -tasklet_schedule (hv_context.msg_dpc[cpu]); +switch (READ_ONCE (msg->header.message_type)) { +case HVMSG_NONE : +break ; +case HVMSG_TIMER_EXPIRED : +hv_process_timer_expiration (msg, cpu); +break ; +default : +tasklet_schedule (hv_context.msg_dpc[cpu]); }add_interrupt_randomness (HYPERVISOR_CALLBACK_VECTOR ,0 ); --2.9.3
PATCH 3/15 hyperv: use standard bitops
In reply to Roman Kagan--- drivers/hv/channel.c | 8 +++----- drivers/hv/connection.c | 9 +++------ 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/hv/channel.c +3 -5
@@ -49,15 +49,13 @@ void vmbus_setevent(struct vmbus_channel *channel)*/ if ((channel->offermsg.monitor_allocated) && (!channel->low_latency)) { -/* Each u32 represents 32 channels */ -sync_set_bit (channel->offermsg.child_relid &31 , - (unsigned long *) vmbus_connection.send_int_page + - (channel->offermsg.child_relid >>5 )); +set_bit (channel->offermsg.child_relid, + (unsigned long *)vmbus_connection.send_int_page);/* Get the child to parent monitor page */ monitorpage = vmbus_connection.monitor_pages[1 ]; -sync_set_bit (channel->monitor_bit, +set_bit (channel->monitor_bit, (unsigned long *)&monitorpage->trigger_group [channel->monitor_grp].pending);
drivers/hv/connection.c +3 -6
@@ -468,12 +468,9 @@ void vmbus_set_event(struct vmbus_channel *channel) {u32 child_relid = channel->offermsg.child_relid; -if (!channel->is_dedicated_interrupt) { -/* Each u32 represents 32 channels */ -sync_set_bit (child_relid &31 , - (unsigned long *)vmbus_connection.send_int_page + - (child_relid >>5 )); - } +if (!channel->is_dedicated_interrupt) +set_bit (child_relid, + (unsigned long *)vmbus_connection.send_int_page);hv_do_hypercall (HVCALL_SIGNAL_EVENT , channel->sig_event,NULL ); }
Signature · 1 line
2.9.3
Re: [PATCH 03/15] hyperv: use standard bitops
On Tue, Dec 20, Roman Kagan wrote:
Reverting commit 22356585712d ("staging: hv: use sync_bitops when interacting with the hypervisor") is save because .......
drivers/hv/channel.c void vmbus_setevent(struct vmbus_channel *channel) · line 58
Quoted 2 lines
drivers/hv/channel.c +1
-1- sync_set_bit(channel->monitor_bit, + set_bit(channel->monitor_bit,
Olaf
Re: [PATCH 03/15] hyperv: use standard bitops
Quoted 7 lines · Olaf Hering
On Tue, Dec 20, Roman Kagan wrote:
Reverting commit
22356585712d("staging: hv: usesync_bitopswhen interacting with the hypervisor") is save because .......drivers/hv/channel.c void vmbus_setevent(struct vmbus_channel *channel) · line 58
Quoted 2 lines
drivers/hv/channel.c +1
-1- sync_set_bit(channel->monitor_bit, + set_bit(channel->monitor_bit,
It isn't indeed. I didn't realize there was a UP case where it made a difference, and failed to locate the commit where it changed.
I'll drop this part, thanks.
Roman.
Paolo Bonzini
maintainerRe: [PATCH 03/15] hyperv: use standard bitops
Quoted 6 lines · Roman Kagan
Quoted 5 lines · Olaf Hering
On Tue, Dec 20, Roman Kagan wrote:
Reverting commit
22356585712d("staging: hv: usesync_bitopswhen interacting with the hypervisor") is save because .......
Quoted 7 lines
Quoted 2 lines
drivers/hv/channel.c void vmbus_setevent(struct vmbus_channel *channel) · line 58
Quoted 2 lines
drivers/hv/channel.c +1
-1- sync_set_bit(channel->monitor_bit, + set_bit(channel->monitor_bit,It isn't indeed. I didn't realize there was a UP case where it made a difference, and failed to locate the commit where it changed.
I'll drop this part, thanks.
Perhaps the sync_bitops should be renamed to virt_bitops. This would match virt_* memory barriers and would make their usage much more obvious.
Paolo
RE: [PATCH 03/15] hyperv: use standard bitops
In reply to Roman KaganQuoted 15 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 03/15] hyperv: use standard bitops
No commit log?
Quoted 14 lines
Signed-off-by Roman Kagan <[email protected]>--- drivers/hv/channel.c | 8 +++----- drivers/hv/connection.c | 9 +++------ 2 files changed, 6 insertions(+), 11 deletions(-)drivers/hv/channel.c +0
-0@@ -49,15 +49,13 @@ void vmbus_setevent(struct vmbus_channel*channel) */ if ((channel->offermsg.monitor_allocated) &&
drivers/hv/channel.c void vmbus_setevent(struct vmbus_channel · line 57
Quoted 10 lines
drivers/hv/channel.c +3
-4(!channel->low_latency)) { -/* Each u32 represents 32 channels */ -sync_set_bit (channel->offermsg.child_relid &31 , - (unsigned long *) vmbus_connection.send_int_page + - (channel->offermsg.child_relid >>5 )); +set_bit (channel->offermsg.child_relid, + (unsigned long *)vmbus_connection.send_int_page);
What is the rationale for dropping the sync variant?
drivers/hv/channel.c void vmbus_setevent(struct vmbus_channel *channel) · line 60
Quoted 8 lines
drivers/hv/channel.c +1
-1/* Get the child to parent monitor page */ monitorpage = vmbus_connection.monitor_pages[1 ]; -sync_set_bit (channel->monitor_bit, +set_bit (channel->monitor_bit, (unsigned long *)&monitorpage->trigger_group [channel->monitor_grp].pending);
Same comment as before.
Quoted 26 lines
drivers/hv/connection.c +4
-6@@ -468,12 +468,9 @@ void vmbus_set_event(struct vmbus_channel *channel) {u32 child_relid = channel->offermsg.child_relid; -if (!channel->is_dedicated_interrupt) { -/* Each u32 represents 32 channels */ -sync_set_bit (child_relid &31 , - (unsigned long *)vmbus_connection.send_int_page + - (child_relid >>5 )); - } +if (!channel->is_dedicated_interrupt) +set_bit (child_relid, + (unsigned long *)vmbus_connection.send_int_page); hv_do_hypercall(HVCALL_SIGNAL_EVENT, channel->sig_event,NULL);
}
--
2.9.3
PATCH 4/15 hyperv: define VMBus message type
In reply to Roman KaganGive a name to the constant (1) already used in the code.
--- arch/x86/include/uapi/asm/hyperv.h | 2 ++ drivers/hv/connection.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/uapi/asm/hyperv.h +2 -0
@@ -282,6 +282,8 @@ struct hv_ref_tsc_page {enum hv_message_type {HVMSG_NONE =0x00000000 , +HVMSG_VMBUS =0x00000001 , +/* Memory access messages. */ HVMSG_UNMAPPED_GPA =0x80000000 ,HVMSG_GPA_INTERCEPT =0x80000001 ,
drivers/hv/connection.c +1 -1
@@ -432,7 +432,7 @@ int vmbus_post_msg(void *buffer, size_t buflen)* times before giving up. */ while (retries <20 ) { - ret =hv_post_message (conn_id,1 , buffer, buflen); + ret =hv_post_message (conn_id,HVMSG_VMBUS , buffer, buflen);switch (ret) {case HV_STATUS_INVALID_CONNECTION_ID :
Signature · 1 line
2.9.3
PATCH 5/15 hyperv: GFP_ATOMIC -> GFP_KERNEL
In reply to Roman KaganThere's no need in GFP_ATOMIC when initializing the driver state.
While at this, also rely on free_page() to take null argument.
--- drivers/hv/hv.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/hv/hv.c +10 -13
@@ -393,28 +393,28 @@ int hv_synic_alloc(void)int cpu; hv_context.hv_numa_map =kzalloc (sizeof (struct cpumask ) * nr_node_ids, -GFP_ATOMIC ); +GFP_KERNEL );if (hv_context.hv_numa_map ==NULL ) {pr_err ("Unable to allocate NUMA map\n" ); goto err; }for_each_online_cpu (cpu) { - hv_context.event_dpc[cpu] =kmalloc (size,GFP_ATOMIC ); + hv_context.event_dpc[cpu] =kmalloc (size,GFP_KERNEL );if (hv_context.event_dpc[cpu] ==NULL ) {pr_err ("Unable to allocate event dpc\n" ); goto err; }tasklet_init (hv_context.event_dpc[cpu], vmbus_on_event, cpu); - hv_context.msg_dpc[cpu] =kmalloc (size,GFP_ATOMIC ); + hv_context.msg_dpc[cpu] =kmalloc (size,GFP_KERNEL );if (hv_context.msg_dpc[cpu] ==NULL ) {pr_err ("Unable to allocate event dpc\n" ); goto err; }tasklet_init (hv_context.msg_dpc[cpu], vmbus_on_msg_dpc, cpu); - hv_context.clk_evt[cpu] =kzalloc (ced_size,GFP_ATOMIC ); + hv_context.clk_evt[cpu] =kzalloc (ced_size,GFP_KERNEL );if (hv_context.clk_evt[cpu] ==NULL ) {pr_err ("Unable to allocate clock event device\n" ); goto err;
@@ -423,7 +423,7 @@ int hv_synic_alloc(void)hv_init_clockevent_device (hv_context.clk_evt[cpu], cpu); hv_context.synic_message_page[cpu] = - (void *)get_zeroed_page (GFP_ATOMIC ); + (void *)get_zeroed_page (GFP_KERNEL );if (hv_context.synic_message_page[cpu] ==NULL ) {pr_err ("Unable to allocate SYNIC message page\n" );
@@ -431,7 +431,7 @@ int hv_synic_alloc(void) } hv_context.synic_event_page[cpu] = - (void *)get_zeroed_page (GFP_ATOMIC ); + (void *)get_zeroed_page (GFP_KERNEL );if (hv_context.synic_event_page[cpu] ==NULL ) {pr_err ("Unable to allocate SYNIC event page\n" );
@@ -439,7 +439,7 @@ int hv_synic_alloc(void) } hv_context.post_msg_page[cpu] = - (void *)get_zeroed_page (GFP_ATOMIC ); + (void *)get_zeroed_page (GFP_KERNEL );if (hv_context.post_msg_page[cpu] ==NULL ) {pr_err ("Unable to allocate post msg page\n" );
@@ -457,12 +457,9 @@ static void hv_synic_free_cpu(int cpu)kfree (hv_context.event_dpc[cpu]);kfree (hv_context.msg_dpc[cpu]);kfree (hv_context.clk_evt[cpu]); -if (hv_context.synic_event_page[cpu]) -free_page ((unsigned long )hv_context.synic_event_page[cpu]); -if (hv_context.synic_message_page[cpu]) -free_page ((unsigned long )hv_context.synic_message_page[cpu]); -if (hv_context.post_msg_page[cpu]) -free_page ((unsigned long )hv_context.post_msg_page[cpu]); +free_page ((unsigned long )hv_context.synic_event_page[cpu]); +free_page ((unsigned long )hv_context.synic_message_page[cpu]); +free_page ((unsigned long )hv_context.post_msg_page[cpu]); }void hv_synic_free (void )
Signature · 1 line
2.9.3
PATCH 6/15 hyperv: avoid unnecessary vmalloc
In reply to Roman KaganMake hypercall and tsc page allocation similar to the rest of the Hyper-V shared memory stuff instead of vmalloc-ing them.
Also perform cleanup unconditionally which is safe.
TODO: the skipping of free in case of a crash is probably no longer necessary, too.
--- drivers/hv/hv.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-)
drivers/hv/hv.c +18 -24
@@ -29,6 +29,7 @@#include <linux/version.h> #include <linux/interrupt.h> #include <linux/clockchips.h> +#include <asm/cacheflush.h> #include <asm/hyperv.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h"
@@ -208,14 +209,15 @@ int hv_init(void)/* See if the hypercall page is already set */ rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); - virtaddr =__vmalloc (PAGE_SIZE ,GFP_KERNEL ,PAGE_KERNEL_EXEC ); - -if (!virtaddr) + virtaddr = (void *)get_zeroed_page (GFP_KERNEL ); +if (!virtaddr ||set_memory_x ((unsigned long )virtaddr,1 )) goto cleanup; + hv_context.hypercall_page = virtaddr; hypercall_msr.enable =1 ; - hypercall_msr.guest_physical_address =vmalloc_to_pfn (virtaddr); + hypercall_msr.guest_physical_address = +virt_to_phys (virtaddr) >>PAGE_SHIFT ;wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);/* Confirm that hypercall page did get setup. */
@@ -225,14 +227,12 @@ int hv_init(void)if (!hypercall_msr.enable) goto cleanup; - hv_context.hypercall_page = virtaddr; -#ifdef CONFIG_X86_64 if (ms_hyperv.features &HV_X64_MSR_REFERENCE_TSC_AVAILABLE ) {union hv_x64_msr_hypercall_contents tsc_msr;void *va_tsc; - va_tsc =__vmalloc (PAGE_SIZE ,GFP_KERNEL ,PAGE_KERNEL ); + va_tsc = (void *)get_zeroed_page (GFP_KERNEL );if (!va_tsc) goto cleanup; hv_context.tsc_page = va_tsc;
@@ -240,7 +240,8 @@ int hv_init(void)rdmsrl (HV_X64_MSR_REFERENCE_TSC , tsc_msr.as_uint64); tsc_msr.enable =1 ; - tsc_msr.guest_physical_address =vmalloc_to_pfn (va_tsc); + tsc_msr.guest_physical_address = +virt_to_phys (va_tsc) >>PAGE_SHIFT ;wrmsrl (HV_X64_MSR_REFERENCE_TSC , tsc_msr.as_uint64);clocksource_register_hz (&hyperv_cs_tsc,NSEC_PER_SEC /100 );
@@ -249,14 +250,9 @@ int hv_init(void)return 0 ; cleanup: -if (virtaddr) { -if (hypercall_msr.enable) { - hypercall_msr.as_uint64 =0 ; -wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); - } - -vfree (virtaddr); - } + hypercall_msr.as_uint64 =0 ; +wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); +free_page ((unsigned long )virtaddr);return -ENOTSUPP ; }
@@ -273,13 +269,11 @@ void hv_cleanup(bool crash)/* Reset our OS id */ wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 ); -if (hv_context.hypercall_page) { - hypercall_msr.as_uint64 =0 ; -wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); -if (!crash) -vfree (hv_context.hypercall_page); - hv_context.hypercall_page =NULL ; - } + hypercall_msr.as_uint64 =0 ; +wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); +if (!crash) +free_page ((unsigned long )hv_context.hypercall_page); + hv_context.hypercall_page =NULL ;#ifdef CONFIG_X86_64 /*
@@ -298,7 +292,7 @@ void hv_cleanup(bool crash) hypercall_msr.as_uint64 =0 ;wrmsrl (HV_X64_MSR_REFERENCE_TSC , hypercall_msr.as_uint64);if (!crash) -vfree (hv_context.tsc_page); +free_page ((unsigned long )hv_context.tsc_page); hv_context.tsc_page = NULL; }#endif
Signature · 1 line
2.9.3
RE: [PATCH 06/15] hyperv: avoid unnecessary vmalloc
Quoted 15 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 06/15] hyperv: avoid unnecessary vmalloc
Quoted 7 lines
Make hypercall and tsc page allocation similar to the rest of the Hyper-V shared memory stuff instead of vmalloc-ing them.
Also perform cleanup unconditionally which is safe.
TODO: the skipping of free in case of a crash is probably no longer necessary, too.
Please breakup these patches.
Quoted 19 lines
Signed-off-by Roman Kagan <[email protected]>--- drivers/hv/hv.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-)drivers/hv/hv.c +1
-0@@ -29,6 +29,7 @@#include <linux/version.h> #include <linux/interrupt.h> #include <linux/clockchips.h> +#include <asm/cacheflush.h> #include <asm/hyperv.h> #include <asm/mshyperv.h> #include "hyperv_vmbus.h"
drivers/hv/hv.c int hv_init(void) · line 215
Quoted 10 lines
drivers/hv/hv.c +2
-3@@ -208,14 +209,15 @@ int hv_init(void)/* See if the hypercall page is already set */ rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); - virtaddr =__vmalloc (PAGE_SIZE ,GFP_KERNEL , PAGE_KERNEL_EXEC); - -if (!virtaddr) + virtaddr = (void *)get_zeroed_page (GFP_KERNEL ); +if (!virtaddr ||set_memory_x ((unsigned long )virtaddr,1 )) goto cleanup;
Have you tested this patch.
Quoted 89 lines
drivers/hv/hv.c +3
-1+ hv_context.hypercall_page = virtaddr; hypercall_msr.enable =1 ; - hypercall_msr.guest_physical_address =vmalloc_to_pfn (virtaddr); + hypercall_msr.guest_physical_address = +virt_to_phys (virtaddr) >>PAGE_SHIFT ;wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64);drivers/hv/hv.c +1
-3/* Confirm that hypercall page did get setup. */ @@ -225,14 +227,12 @@ int hv_init(void)if (!hypercall_msr.enable) goto cleanup; - hv_context.hypercall_page = virtaddr; -#ifdef CONFIG_X86_64 if (ms_hyperv.features &HV_X64_MSR_REFERENCE_TSC_AVAILABLE ) {union hv_x64_msr_hypercall_contents tsc_msr;void *va_tsc; - va_tsc =__vmalloc (PAGE_SIZE ,GFP_KERNEL , PAGE_KERNEL); + va_tsc = (void *)get_zeroed_page (GFP_KERNEL );if (!va_tsc)drivers/hv/hv.c +2
-1goto cleanup; hv_context.tsc_page = va_tsc;@@ -240,7 +240,8 @@ int hv_init(void)rdmsrl (HV_X64_MSR_REFERENCE_TSC , tsc_msr.as_uint64); tsc_msr.enable =1 ; - tsc_msr.guest_physical_address =vmalloc_to_pfn (va_tsc); + tsc_msr.guest_physical_address = +virt_to_phys (va_tsc) >>PAGE_SHIFT ;wrmsrl (HV_X64_MSR_REFERENCE_TSC , tsc_msr.as_uint64); clocksource_register_hz(&hyperv_cs_tsc,NSEC_PER_SEC/100);
drivers/hv/hv.c +3
-8@@ -249,14 +250,9 @@ int hv_init(void)return 0 ; cleanup: -if (virtaddr) { -if (hypercall_msr.enable) { - hypercall_msr.as_uint64 =0 ; -wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); - } - -vfree (virtaddr); - } + hypercall_msr.as_uint64 =0 ; +wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); +free_page ((unsigned long )virtaddr);return -ENOTSUPP ;}
drivers/hv/hv.c +6
-8@@ -273,13 +269,11 @@ void hv_cleanup(bool crash)/* Reset our OS id */ wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 ); -if (hv_context.hypercall_page) { - hypercall_msr.as_uint64 =0 ; -wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); -if (!crash) -vfree (hv_context.hypercall_page); - hv_context.hypercall_page =NULL ; - } + hypercall_msr.as_uint64 =0 ; +wrmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); +if (!crash) +free_page ((unsigned long )hv_context.hypercall_page); + hv_context.hypercall_page =NULL ;#ifdef CONFIG_X86_64 /* @@ -298,7 +292,7 @@ void hv_cleanup(bool crash) hypercall_msr.as_uint64 =0 ;wrmsrl (HV_X64_MSR_REFERENCE_TSC , hypercall_msr.as_uint64);if (!crash) -vfree (hv_context.tsc_page); +free_page ((unsigned long )hv_context.tsc_page); hv_context.tsc_page =NULL ; }#endif
--
2.9.3
PATCH 7/15 hyperv: dedup cpuid definitions
In reply to Roman KaganUse the definitions already present in the uapi header throughout the guest driver, too.
--- drivers/hv/hyperv_vmbus.h | 19 ------------------- drivers/hv/hv.c | 6 +++--- 2 files changed, 3 insertions(+), 22 deletions(-)
drivers/hv/hyperv_vmbus.h +0 -19
@@ -39,25 +39,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
drivers/hv/hv.c +3 -3
@@ -69,17 +69,17 @@ static int query_hypervisor_info(void) ebx =0 ; ecx =0 ; edx =0 ; - op =HVCPUID_VENDOR_MAXFUNCTION ; + op =HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS ;cpuid (op, &eax, &ebx, &ecx, &edx); max_leaf = eax; -if (max_leaf >=HVCPUID_VERSION ) { +if (max_leaf >=HYPERV_CPUID_VERSION ) { eax =0 ; ebx =0 ; ecx =0 ; edx =0 ; - op =HVCPUID_VERSION ; + op =HYPERV_CPUID_VERSION ;cpuid (op, &eax, &ebx, &ecx, &edx); host_info_eax = eax; host_info_ebx = ebx;
Signature · 1 line
2.9.3
PATCH 8/15 hyperv: dedup crash msr related definitions
In reply to Roman KaganUse the definitions already present in the uapi header throughout the guest driver, too.
--- drivers/hv/hyperv_vmbus.h | 11 ----------- drivers/hv/vmbus_drv.c | 6 +++--- 2 files changed, 3 insertions(+), 14 deletions(-)
drivers/hv/hyperv_vmbus.h +0 -11
@@ -39,17 +39,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 +3 -3
@@ -77,7 +77,7 @@ static void hyperv_report_panic(struct pt_regs *regs)/* * Let Hyper-V know there is crash data available */ -wrmsrl (HV_X64_MSR_CRASH_CTL ,HV_CRASH_CTL_CRASH_NOTIFY ); +wrmsrl (HV_X64_MSR_CRASH_CTL ,HV_X64_MSR_CRASH_CTL_NOTIFY ); } static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
@@ -993,7 +993,7 @@ static int vmbus_bus_init(void)/* * Only register if the crash MSRs are available */ -if (ms_hyperv.misc_features &HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE ) { +if (ms_hyperv.misc_features &HV_X64_GUEST_CRASH_MSR_AVAILABLE ) {register_die_notifier (&hyperv_die_block);atomic_notifier_chain_register (&panic_notifier_list, &hyperv_panic_block);
@@ -1535,7 +1535,7 @@ static void __exit vmbus_exit(void)for_each_online_cpu (cpu)tasklet_kill (hv_context.msg_dpc[cpu]);vmbus_free_channels (); -if (ms_hyperv.misc_features &HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE ) { +if (ms_hyperv.misc_features &HV_X64_GUEST_CRASH_MSR_AVAILABLE ) {unregister_die_notifier (&hyperv_die_block);atomic_notifier_chain_unregister (&panic_notifier_list, &hyperv_panic_block);
Signature · 1 line
2.9.3
PATCH 9/15 hyperv: unify Hyper-V msr definitions
In reply to Roman KaganUse the definitions already present in the uapi header. Besides, drop all bitfields for the msr values and use bitwise operations instead.
--- drivers/hv/hyperv_vmbus.h | 88 --------------------------- drivers/hv/hv.c | 150 ++++++++++++++++++---------------------------- 2 files changed, 59 insertions(+), 179 deletions(-)
drivers/hv/hyperv_vmbus.h +0 -88
@@ -94,63 +94,6 @@ struct hv_connection_info { }; }; -/* -* Timer configuration register. -*/ -union hv_timer_config { -u64 as_uint64; -struct { -u64 enable:1 ; -u64 periodic:1 ; -u64 lazy:1 ; -u64 auto_enable:1 ; -u64 reserved_z0:12 ; -u64 sintx:4 ; -u64 reserved_z1:44 ; - }; -}; - -/* Define SynIC control register. */ -union hv_synic_scontrol { -u64 as_uint64; -struct { -u64 enable:1 ; -u64 reserved:63 ; - }; -}; - -/* Define synthetic interrupt source. */ -union hv_synic_sint { -u64 as_uint64; -struct { -u64 vector:8 ; -u64 reserved1:8 ; -u64 masked:1 ; -u64 auto_eoi:1 ; -u64 reserved2:46 ; - }; -}; - -/* Define the format of the SIMP register */ -union hv_synic_simp { -u64 as_uint64; -struct { -u64 simp_enabled:1 ; -u64 preserved:11 ; -u64 base_simp_gpa:52 ; - }; -}; - -/* Define the format of the SIEFP register */ -union hv_synic_siefp { -u64 as_uint64; -struct { -u64 siefp_enabled:1 ; -u64 preserved:11 ; -u64 base_siefp_gpa:52 ; - }; -}; -/* Definitions for the monitored notification facility */ union hv_monitor_trigger_group {u64 as_uint64;
@@ -239,37 +182,6 @@ enum hv_guest_os_microsoft_ids {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 */ - }; -}; - -/* -* 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 ,
drivers/hv/hv.c +59 -91
248 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 10/15 hyperv: uapi-fy PostMessage and SignalEvent hypercall structures
In reply to Roman KaganExpose structures used for PostMessage and SignalEvent hypercalls in a uapi header. While doing so, simplify alignment handling and drop unnecessary complications in the connectionid field.
--- arch/x86/include/uapi/asm/hyperv.h | 18 ++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 16 ++-------------- include/linux/hyperv.h | 24 +----------------------- drivers/hv/channel_mgmt.c | 14 ++++---------- drivers/hv/connection.c | 9 +++------ drivers/hv/hv.c | 2 +- drivers/hv/vmbus_drv.c | 2 +- 7 files changed, 30 insertions(+), 55 deletions(-)
arch/x86/include/uapi/asm/hyperv.h +18 -0
@@ -378,4 +378,22 @@ struct hv_synic_event_flags_page { struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT]; }; +#define HV_HYPERCALL_PARAM_ALIGN 8 + +/* Definition of the hv_post_message hypercall input structure. */ +struct hv_input_post_message { +__u32 connectionid; +__u32 reserved; +__u32 message_type; +__u32 payload_size; +__u64 payload[HV_MESSAGE_PAYLOAD_BYTE_COUNT ]; +} __attribute__((aligned (HV_HYPERCALL_PARAM_ALIGN ))); + +/* Definition of the hv_signal_event hypercall input structure. */ +struct hv_input_signal_event { +__u32 connectionid; +__u16 flag_number; +__u16 rsvdz; +} __attribute__((aligned (HV_HYPERCALL_PARAM_ALIGN ))); +#endif
drivers/hv/hyperv_vmbus.h +2 -14
@@ -104,7 +104,7 @@ union hv_monitor_trigger_group { };struct hv_monitor_parameter { -union hv_connection_id connectionid; +u32 connectionid;u16 flagnumber;u16 rsvdz; };
@@ -154,15 +154,6 @@ struct hv_monitor_page {u8 rsvdz4[1984 ]; }; -/* Definition of the hv_post_message hypercall input structure. */ -struct hv_input_post_message { -union hv_connection_id connectionid; -u32 reserved; -u32 message_type; -u32 payload_size; -u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT ]; -}; -/* * Versioning definitions used for guests reporting themselves to the * hypervisor, and visa versa.
@@ -248,9 +239,6 @@ static inline __u64 generate_guest_id(__u8 d_info1, __u32 kernel_version,#define HV_CAPS_MAX 8 -#define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) - -/* Service definitions */ #define HV_SERVICE_PARENT_PORT (0)
@@ -351,7 +339,7 @@ extern int hv_init(void);extern void hv_cleanup (bool crash); -extern int hv_post_message (union hv_connection_id connection_id, +extern int hv_post_message (u32 connection_id,enum hv_message_type message_type,void *payload,size_t payload_size);
include/linux/hyperv.h +1 -23
@@ -648,27 +648,6 @@ struct vmbus_close_msg {struct vmbus_channel_close_channel msg; }; -/* Define connection identifier type. */ -union hv_connection_id { -u32 asu32; -struct { -u32 id:24 ; -u32 reserved:8 ; - } u; -}; - -/* Definition of the hv_signal_event hypercall input structure. */ -struct hv_input_signal_event { -union hv_connection_id connectionid; -u16 flag_number; -u16 rsvdz; -}; - -struct hv_input_signal_event_buffer { -u64 align8; -struct hv_input_signal_event event; -}; -enum hv_signal_policy {HV_SIGNAL_POLICY_DEFAULT =0 ,HV_SIGNAL_POLICY_EXPLICIT ,
@@ -755,8 +734,7 @@ struct vmbus_channel {bool batched_reading;bool is_dedicated_interrupt; -struct hv_input_signal_event_buffer sig_buf; -struct hv_input_signal_event *sig_event; +struct hv_input_signal_event sig_event;/* * Starting with win8, this field will be used to specify
drivers/hv/channel_mgmt.c +4 -10
@@ -766,20 +766,14 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)/* * Setup state for signalling the host. */ - newchannel->sig_event = (struct hv_input_signal_event *) - (ALIGN ((unsigned long ) - &newchannel->sig_buf, -HV_HYPERCALL_PARAM_ALIGN )); - - newchannel->sig_event->connectionid.asu32 =0 ; - newchannel->sig_event->connectionid.u.id =VMBUS_EVENT_CONNECTION_ID ; - newchannel->sig_event->flag_number =0 ; - newchannel->sig_event->rsvdz =0 ; + newchannel->sig_event.connectionid =VMBUS_EVENT_CONNECTION_ID ; + newchannel->sig_event.flag_number =0 ; + newchannel->sig_event.rsvdz =0 ;if (vmbus_proto_version !=VERSION_WS2008 ) { newchannel->is_dedicated_interrupt = (offer->is_dedicated_interrupt !=0 ); - newchannel->sig_event->connectionid.u.id = + newchannel->sig_event.connectionid = offer->connection_id; }
drivers/hv/connection.c +3 -6
@@ -418,21 +418,18 @@ void vmbus_on_event(unsigned long data)*/ int vmbus_post_msg (void *buffer,size_t buflen) { -union hv_connection_id conn_id;int ret =0 ;int retries =0 ;u32 usec =1 ; - conn_id.asu32 =0 ; - conn_id.u.id =VMBUS_MESSAGE_CONNECTION_ID ; -/* * hv_post_message() can have transient failures because of * insufficient resources. Retry the operation a couple of * times before giving up. */ while (retries <20 ) { - ret =hv_post_message (conn_id,HVMSG_VMBUS , buffer, buflen); + ret =hv_post_message (VMBUS_MESSAGE_CONNECTION_ID ,HVMSG_VMBUS , + buffer, buflen);switch (ret) {case HV_STATUS_INVALID_CONNECTION_ID :
@@ -472,6 +469,6 @@ void vmbus_set_event(struct vmbus_channel *channel)set_bit (child_relid, (unsigned long *)vmbus_connection.send_int_page); -hv_do_hypercall (HVCALL_SIGNAL_EVENT , channel->sig_event,NULL ); +hv_do_hypercall (HVCALL_SIGNAL_EVENT , &channel->sig_event,NULL ); }EXPORT_SYMBOL_GPL (vmbus_set_event);
drivers/hv/hv.c +1 -1
@@ -297,7 +297,7 @@ void hv_cleanup(bool crash)* * This involves a hypercall. */ -int hv_post_message (union hv_connection_id connection_id, +int hv_post_message (u32 connection_id,enum hv_message_type message_type,void *payload,size_t payload_size) {
drivers/hv/vmbus_drv.c +1 -1
@@ -159,7 +159,7 @@ static u32 channel_conn_id(struct vmbus_channel *channel, {u8 monitor_group =channel_monitor_group (channel);u8 monitor_offset =channel_monitor_offset (channel); -return monitor_page->parameter[monitor_group][monitor_offset].connectionid.u.id; +return monitor_page->parameter[monitor_group][monitor_offset].connectionid; } static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr,
Signature · 1 line
2.9.3
RE: [PATCH 10/15] hyperv: uapi-fy PostMessage and SignalEvent hypercall structures
Quoted 16 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 10/15] hyperv: uapi-fy PostMessage and SignalEvent hypercall structures
Quoted 3 lines
Expose structures used for PostMessage and SignalEvent hypercalls in a uapi header. While doing so, simplify alignment handling and drop unnecessary complications in the connectionid field.
Split up the patch.
Quoted 237 lines
Signed-off-by Roman Kagan <[email protected]>--- arch/x86/include/uapi/asm/hyperv.h | 18 ++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 16 ++-------------- include/linux/hyperv.h | 24 +----------------------- drivers/hv/channel_mgmt.c | 14 ++++---------- drivers/hv/connection.c | 9 +++------ drivers/hv/hv.c | 2 +- drivers/hv/vmbus_drv.c | 2 +- 7 files changed, 30 insertions(+), 55 deletions(-)arch/x86/include/uapi/asm/hyperv.h +18
-0@@ -378,4 +378,22 @@ struct hv_synic_event_flags_page {struct hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT ]; }; +#define HV_HYPERCALL_PARAM_ALIGN 8 + +/* Definition of the hv_post_message hypercall input structure. */ +struct hv_input_post_message { +__u32 connectionid; +__u32 reserved; +__u32 message_type; +__u32 payload_size; +__u64 payload[HV_MESSAGE_PAYLOAD_BYTE_COUNT ]; +} __attribute__((aligned (HV_HYPERCALL_PARAM_ALIGN ))); + +/* Definition of the hv_signal_event hypercall input structure. */ +struct hv_input_signal_event { +__u32 connectionid; +__u16 flag_number; +__u16 rsvdz; +} __attribute__((aligned (HV_HYPERCALL_PARAM_ALIGN ))); +#endif
drivers/hv/hyperv_vmbus.h +1
-13@@ -104,7 +104,7 @@ union hv_monitor_trigger_group { };struct hv_monitor_parameter { -union hv_connection_id connectionid; +u32 connectionid;u16 flagnumber;u16 rsvdz; };@@ -154,15 +154,6 @@ struct hv_monitor_page {u8 rsvdz4[1984 ]; }; -/* Definition of the hv_post_message hypercall input structure. */ -struct hv_input_post_message { -union hv_connection_id connectionid; -u32 reserved; -u32 message_type; -u32 payload_size; -u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT ]; -}; -/* * Versioning definitions used for guests reporting themselves to the * hypervisor, and visa versa. @@ -248,9 +239,6 @@ static inline __u64 generate_guest_id(__u8 d_info1, __u32 kernel_version,#define HV_CAPS_MAX 8 -#define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) - -/* Service definitions */ #define
HV_SERVICE_PARENT_PORT(0)drivers/hv/hyperv_vmbus.h +1
-1@@ -351,7 +339,7 @@ extern int hv_init(void);extern void hv_cleanup (bool crash); -extern int hv_post_message (union hv_connection_id connection_id, +extern int hv_post_message (u32 connection_id,enum hv_message_type message_type,void *payload,size_t payload_size);include/linux/hyperv.h +1
-23@@ -648,27 +648,6 @@ struct vmbus_close_msg {struct vmbus_channel_close_channel msg; }; -/* Define connection identifier type. */ -union hv_connection_id { -u32 asu32; -struct { -u32 id:24 ; -u32 reserved:8 ; - } u; -}; - -/* Definition of the hv_signal_event hypercall input structure. */ -struct hv_input_signal_event { -union hv_connection_id connectionid; -u16 flag_number; -u16 rsvdz; -}; - -struct hv_input_signal_event_buffer { -u64 align8; -struct hv_input_signal_event event; -}; -enum hv_signal_policy {HV_SIGNAL_POLICY_DEFAULT =0 ,HV_SIGNAL_POLICY_EXPLICIT ,@@ -755,8 +734,7 @@ struct vmbus_channel {bool batched_reading;bool is_dedicated_interrupt; -struct hv_input_signal_event_buffer sig_buf; -struct hv_input_signal_event *sig_event; +struct hv_input_signal_event sig_event;/* * Starting with win8, this field will be used to specify drivers/hv/channel_mgmt.c +4
-10@@ -766,20 +766,14 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)/* * Setup state for signalling the host. */ - newchannel->sig_event = (struct hv_input_signal_event *) - (ALIGN ((unsigned long ) - &newchannel->sig_buf, -HV_HYPERCALL_PARAM_ALIGN )); - - newchannel->sig_event->connectionid.asu32 =0 ; - newchannel->sig_event->connectionid.u.id =VMBUS_EVENT_CONNECTION_ID ; - newchannel->sig_event->flag_number =0 ; - newchannel->sig_event->rsvdz =0 ; + newchannel->sig_event.connectionid =VMBUS_EVENT_CONNECTION_ID ; + newchannel->sig_event.flag_number =0 ; + newchannel->sig_event.rsvdz =0 ;if (vmbus_proto_version !=VERSION_WS2008 ) { newchannel->is_dedicated_interrupt = (offer->is_dedicated_interrupt !=0 ); - newchannel->sig_event->connectionid.u.id = + newchannel->sig_event.connectionid =drivers/hv/channel_mgmt.c +0
-0offer->connection_id; }drivers/hv/connection.c +2
-5@@ -418,21 +418,18 @@ void vmbus_on_event(unsigned long data)*/ int vmbus_post_msg (void *buffer,size_t buflen) { -union hv_connection_id conn_id;int ret =0 ;int retries =0 ;u32 usec =1 ; - conn_id.asu32 =0 ; - conn_id.u.id =VMBUS_MESSAGE_CONNECTION_ID ; -/* * hv_post_message() can have transient failures because of * insufficient resources. Retry the operation a couple of * times before giving up. */ while (retries <20 ) { - ret =hv_post_message (conn_id,HVMSG_VMBUS , buffer, buflen); + ret =hv_post_message (VMBUS_MESSAGE_CONNECTION_ID ,HVMSG_VMBUS , + buffer, buflen);drivers/hv/connection.c +0
-1switch (ret) {case HV_STATUS_INVALID_CONNECTION_ID :@@ -472,6 +469,6 @@ void vmbus_set_event(struct vmbus_channel *channel)set_bit (child_relid, (unsigned long *)vmbus_connection.send_int_page); - hv_do_hypercall(HVCALL_SIGNAL_EVENT, channel->sig_event,NULL);
drivers/hv/connection.c +1
-0+ hv_do_hypercall(HVCALL_SIGNAL_EVENT, &channel->sig_event,NULL);
}
EXPORT_SYMBOL_GPL(vmbus_set_event);drivers/hv/hv.c +1
-1@@ -297,7 +297,7 @@ void hv_cleanup(bool crash)* * This involves a hypercall. */ -int hv_post_message (union hv_connection_id connection_id, +int hv_post_message (u32 connection_id,enum hv_message_type message_type,void *payload,size_t payload_size) {drivers/hv/vmbus_drv.c +1
-1@@ -159,7 +159,7 @@ static u32 channel_conn_id(struct vmbus_channel *channel, {u8 monitor_group =channel_monitor_group (channel);u8 monitor_offset =channel_monitor_offset (channel); -return monitor_page- >parameter[monitor_group][monitor_offset].connectionid.u.id; +return monitor_page- >parameter[monitor_group][monitor_offset].connectionid;}
static
ssize_tid_show(struct device *dev, structdevice_attribute*dev_attr,
--
2.9.3
PATCH 11/15 hyperv: uapi-fy monitored notification structures
In reply to Roman KaganMove structures for monitored notifications to the uapi header for userspace to be able to consume. Also observe that hv_monitor_parameter is by definition the same as hv_input_signal_event so use the latter and nuke the former.
--- arch/x86/include/uapi/asm/hyperv.h | 23 +++++++++++++++ drivers/hv/hyperv_vmbus.h | 60 -------------------------------------- 2 files changed, 23 insertions(+), 60 deletions(-)
arch/x86/include/uapi/asm/hyperv.h +23 -0
@@ -396,4 +396,27 @@ struct hv_input_signal_event {__u16 rsvdz; } __attribute__((aligned(HV_HYPERCALL_PARAM_ALIGN))); +/* Definitions for the monitored notification facility */ +struct hv_monitor_trigger_group { +__u32 pending; +__u32 armed; +}; + +struct hv_monitor_page { +__u32 trigger_state; +__u32 rsvdz1; + +struct hv_monitor_trigger_group trigger_group[4 ]; +__u64 rsvdz2[3 ]; + +__s32 next_checktime[4 ][32 ]; + +__u16 latency[4 ][32 ]; +__u64 rsvdz3[32 ]; + +struct hv_input_signal_event parameter[4 ][32 ]; + +__u8 rsvdz4[1984 ]; +}; +#endif
drivers/hv/hyperv_vmbus.h +0 -60
66 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 12/15 hyperv: move VMBus connection ids to uapi
In reply to Roman KaganUserspace will need them too.
--- arch/x86/include/uapi/asm/hyperv.h | 9 +++++++++ drivers/hv/hyperv_vmbus.h | 10 ---------- 2 files changed, 9 insertions(+), 10 deletions(-)
arch/x86/include/uapi/asm/hyperv.h +9 -0
@@ -419,4 +419,13 @@ struct hv_monitor_page { __u8 rsvdz4[1984]; }; +/* VMBus expects pre-established communication with the following IDs */ +#define VMBUS_MESSAGE_CONNECTION_ID 1 +#define VMBUS_MESSAGE_PORT_ID 1 +#define VMBUS_EVENT_CONNECTION_ID 2 +#define VMBUS_EVENT_PORT_ID 2 +#define VMBUS_MONITOR_CONNECTION_ID 3 +#define VMBUS_MONITOR_PORT_ID 3 +#define VMBUS_MESSAGE_SINT 2 +#endif
drivers/hv/hyperv_vmbus.h +0 -10
@@ -114,16 +114,6 @@ enum hv_guest_os_microsoft_ids { }; -enum { -VMBUS_MESSAGE_CONNECTION_ID =1 , -VMBUS_MESSAGE_PORT_ID =1 , -VMBUS_EVENT_CONNECTION_ID =2 , -VMBUS_EVENT_PORT_ID =2 , -VMBUS_MONITOR_CONNECTION_ID =3 , -VMBUS_MONITOR_PORT_ID =3 , -VMBUS_MESSAGE_SINT =2 , -}; -/* #defines */ #define HV_PRESENT_BIT 0x80000000
Signature · 1 line
2.9.3
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 3 lines · On Tue, 20 Dec 2016 18:55:59 +0300 Roman Kagan <[email protected]> wrote:
Userspace will need them too.
Signed-off-by Roman Kagan <[email protected]>
What userspace? I am worried about creating more stable API's that can't change.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 8 lines · Stephen Hemminger
Quoted 3 lines · On Tue, 20 Dec 2016 18:55:59 +0300 Roman Kagan <[email protected]> wrote:
Userspace will need them too.
Signed-off-by Roman Kagan <[email protected]>What userspace? I am worried about creating more stable API's that can't change.
QEMU in particular. We're planning to implement VMBus devices in QEMU and would like to have the definitions shared with the Linux guest drivers for Hyper-V.
Roman.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 3 lines · Roman Kagan
QEMU in particular. We're planning to implement VMBus devices in QEMU and would like to have the definitions shared with the Linux guest drivers for Hyper-V.
And that's everything but a userspace API. The way to go for protocol constants is to have a normal kernel header that is not exported, and a copy of it wherever else you need it.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Roman Kagan
QEMU in particular. We're planning to implement VMBus devices in QEMU and would like to have the definitions shared with the Linux guest drivers for Hyper-V.
And that's everything but a userspace API. The way to go for protocol constants is to have a normal kernel header that is not exported, and a copy of it wherever else you need it.
That's fine by me.
I guess the series should then start with a complete move arch/x86/include/uapi/asm/hyperv.h -> arch/x86/include/asm/hyperv_proto.h, and the remaining patches have to change the latter instead of the former?
Thanks,
Roman.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 6 lines · Roman Kagan
That's fine by me.
I guess the series should then start with a complete move
arch/x86/include/uapi/asm/hyperv.h->arch/x86/include/asm/hyperv_proto.h, and the remaining patches have to change the latter instead of the former?
That would be my preference, but we'll need to figure out why hyperv has ever been a UABI header, and if anyone is using it.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Roman Kagan
That's fine by me.
I guess the series should then start with a complete move
arch/x86/include/uapi/asm/hyperv.h->arch/x86/include/asm/hyperv_proto.h, and the remaining patches have to change the latter instead of the former?That would be my preference, but we'll need to figure out why hyperv has ever been a UABI header, and if anyone is using it.
It was initially done by my former teammate, and I guess only QEMU (outside kernel) is using some of it.
Roman.
Paolo Bonzini
maintainerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Quoted 6 lines · Roman Kagan
That's fine by me.
I guess the series should then start with a complete move
arch/x86/include/uapi/asm/hyperv.h->arch/x86/include/asm/hyperv_proto.h, and the remaining patches have to change the latter instead of the former?That would be my preference, but we'll need to figure out why hyperv has ever been a UABI header, and if anyone is using it.
QEMU uses it, but we already bundle the header files and update them periodically from the files that Linux installs. So any change in Linux would not break the QEMU build; having the header in UAPI is convenient but I guess our update scripts could do whatever Linux's scripts/headers_install.sh does.
That said, there are precedents in using UAPI this way for PV interfaces. See for example include/uapi/linux/virtio*.h and arch/x86/include/uapi/asm/kvm_para.h.
Paolo
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 3 lines · Paolo Bonzini
That said, there are precedents in using UAPI this way for PV interfaces. See for example
include/uapi/linux/virtio*.handarch/x86/include/uapi/asm/kvm_para.h.
We have all kinds of historical examples, but most of them turned into a major pain sooner or later - my favourite example are the SCSI protocol headers.
Protocols needs to stay compatible on the (virtual) wire, but not on the language level. Locking us into the strict UABI policies for them just make someone life horrible further down the road.
Paolo Bonzini
maintainerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Paolo Bonzini
That said, there are precedents in using UAPI this way for PV interfaces. See for example
include/uapi/linux/virtio*.handarch/x86/include/uapi/asm/kvm_para.h.We have all kinds of historical examples, but most of them turned into a major pain sooner or later - my favourite example are the SCSI protocol headers.
Mine too, and because of how uapi/ was created there are quite a few such historical headers (my favourite is cuda.h, just because of the name).
Quoted 3 lines
Protocols needs to stay compatible on the (virtual) wire, but not on the language level. Locking us into the strict UABI policies for them just make someone life horrible further down the road.
The ABI for this kind of thing is not changing much anyway, because it's the hardware or processor or (as in this case) hypervisor ABI.
The more interesting question is about the API, and here in the end it seems to be up to the maintainer.
Some have explicitly asked to move stuff *out* of UAPI, for example the x86 guys have removed msr-index.h from UAPI recently. Others are okay with it and they simply aren't strict on cleanups that might break the *programming* interface, as in patch 15 of this series. See for example pci_regs.h commit 846fc70986a6, "PCI/AER: Rename PCI_ERR_UNC_TRAIN to PCI_ERR_UNC_UND", everybody just moved on and QEMU adjusted its use of PCI_ERR_UNC_TRAIN.
Having this in UAPI has been convenient for QEMU, but of course the kernel couldn't care less. So if KY prefers to have the header outside UAPI, we will just follow suit...
Paolo
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
In reply to Christoph HellwigQuoted 5 lines · On Wed, 21 Dec 2016 07:43:48 -0800 Christoph Hellwig <[email protected]> wrote:
Quoted 3 lines · Paolo Bonzini
That said, there are precedents in using UAPI this way for PV interfaces. See for example
include/uapi/linux/virtio*.handarch/x86/include/uapi/asm/kvm_para.h.
Quoted 7 lines
We have all kinds of historical examples, but most of them turned into a major pain sooner or later - my favourite example are the SCSI protocol headers.
Protocols needs to stay compatible on the (virtual) wire, but not on the language level. Locking us into the strict UABI policies for them just make someone life horrible further down the road.
If the the protocols come from external sources (like the current NDIS definitions), then it is not a big deal. There is some overlap already where NDIS is used multiple places and there are multiple header files with same definition. That could be fixed.
The bigger problem is that some of the API's between guest and host could be implemented multiple ways and don't want userspace ABI files constraining how something like atomic bit operation for wakeup is done.
The other problem with the hyperv headers is they were initially done with only the Linux driver usage in mind. This made perfect sense at the time, the problem is that they mix internal state with protocol definitions.
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD and DPDK drivers could use them directly. Right now each one reinvents.
Paolo Bonzini
maintainerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 3 lines · Stephen Hemminger
The other problem with the hyperv headers is they were initially done with only the Linux driver usage in mind. This made perfect sense at the time, the problem is that they mix internal state with protocol definitions.
Yes, and this was partly fixed when KVM started to use some of those definitions too (the implementation of Hyper-V protocols is split between kernel and userspace).
Quoted 3 lines
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD and DPDK drivers could use them directly. Right now each one reinvents.
Other projects are using sanitized userspace ABI headers just fine, so this is something that lawyers should sort out before kernel hackers do.
Paolo
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
In reply to Stephen HemmingerQuoted 3 lines · Stephen Hemminger
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD and DPDK drivers could use them directly. Right now each one reinvents.
Microsoft could easily solves this problem by offering a suitably liberally licensed header documenting the full HyperV guest protocol that Linux and other projects could use.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 8 lines · On Wed, 21 Dec 2016 09:58:36 -0800 Christoph Hellwig <[email protected]> wrote:
Quoted 3 lines · Stephen Hemminger
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD and DPDK drivers could use them directly. Right now each one reinvents.
Microsoft could easily solves this problem by offering a suitably liberally licensed header documenting the full HyperV guest protocol that Linux and other projects could use.
The issue is if same header file mixes kernel and userspace API stuff.
Once the files are arranged right, I will submit trivial change to comments to indicate the liberal licensing of userspace API headers.
RE: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 25 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:03 AM
To: Christoph Hellwig <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Roman Kagan <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>; [email protected]; Denis V . Lunev <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Thomas Gleixner <[email protected]>
Subject: Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapiQuoted 3 lines · On Wed, 21 Dec 2016 09:58:36 -0800 Christoph Hellwig <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD
and DPDK drivers
Quoted 2 lines
Quoted 1 line
could use them directly. Right now each one reinvents.
Quoted 8 lines
Quoted 3 lines
Microsoft could easily solves this problem by offering a suitably liberally licensed header documenting the full HyperV guest protocol that Linux and other projects could use.
The issue is if same header file mixes kernel and userspace API stuff.
Once the files are arranged right, I will submit trivial change to comments to indicate the liberal licensing of userspace API headers.
Let us take this one step at a time. I know for a fact that not all the guest host protocols on Hyper-V are guaranteed to be stable. Some of the protocols are part of the published MSFT standards such RNDIS and these obviously are guaranteed to be stable. For the rest it is less clear. The fact that we need to ensure compatibility of existing Windows guests tells me that any host side changes will be versioned and the hosts will always support older guests.
I would like to minimize what we include in the uapi header; especially when MSFT has made no guarantees with regards how they may be evolved. I will also work on getting some clarity on both stability and under what license we would expose the uapi header.
Regards,
K. Y
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 41 lines · KY Srinivasan
Quoted 25 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:03 AM
To: Christoph Hellwig <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Roman Kagan <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>; [email protected]; Denis V . Lunev <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Thomas Gleixner <[email protected]>
Subject: Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapiQuoted 3 lines · On Wed, 21 Dec 2016 09:58:36 -0800 Christoph Hellwig <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD
and DPDK drivers
Quoted 2 lines
Quoted 1 line
could use them directly. Right now each one reinvents.
Quoted 8 lines
Quoted 3 lines
Microsoft could easily solves this problem by offering a suitably liberally licensed header documenting the full HyperV guest protocol that Linux and other projects could use.
The issue is if same header file mixes kernel and userspace API stuff.
Once the files are arranged right, I will submit trivial change to comments to indicate the liberal licensing of userspace API headers.
Let us take this one step at a time. I know for a fact that not all the guest host protocols on Hyper-V are guaranteed to be stable. Some of the protocols are part of the published MSFT standards such RNDIS and these obviously are guaranteed to be stable. For the rest it is less clear. The fact that we need to ensure compatibility of existing Windows guests tells me that any host side changes will be versioned and the hosts will always support older guests.
Quoted 3 lines
I would like to minimize what we include in the uapi header; especially when MSFT has made no guarantees with regards how they may be evolved. I will also work on getting some clarity on both stability and under what license we would expose the uapi header.
Am I correct assuming that QEMU is currently the only user of arch/x86/include/uapi/asm/hyperv.h?
Then I think we're fine withdrawing it from uapi as a whole and letting QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Roman.
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 46 lines · On Wed, 28 Dec 2016 20:09:44 +0300 Roman Kagan <[email protected]> wrote:
Quoted 41 lines · KY Srinivasan
Quoted 25 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:03 AM
To: Christoph Hellwig <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Roman Kagan <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>; [email protected]; Denis V . Lunev <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Thomas Gleixner <[email protected]>
Subject: Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapiQuoted 3 lines · On Wed, 21 Dec 2016 09:58:36 -0800 Christoph Hellwig <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD
and DPDK drivers
Quoted 2 lines
Quoted 1 line
could use them directly. Right now each one reinvents.
Quoted 8 lines
Quoted 3 lines
Microsoft could easily solves this problem by offering a suitably liberally licensed header documenting the full HyperV guest protocol that Linux and other projects could use.
The issue is if same header file mixes kernel and userspace API stuff.
Once the files are arranged right, I will submit trivial change to comments to indicate the liberal licensing of userspace API headers.
Let us take this one step at a time. I know for a fact that not all the guest host protocols on Hyper-V are guaranteed to be stable. Some of the protocols are part of the published MSFT standards such RNDIS and these obviously are guaranteed to be stable. For the rest it is less clear. The fact that we need to ensure compatibility of existing Windows guests tells me that any host side changes will be versioned and the hosts will always support older guests.
Quoted 3 lines
I would like to minimize what we include in the uapi header; especially when MSFT has made no guarantees with regards how they may be evolved. I will also work on getting some clarity on both stability and under what license we would expose the uapi header.
Quoted 7 lines
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?Then I think we're fine withdrawing it from uapi as a whole and letting QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
That makes sense, but if it is not in uapi then any changes may break QEMU in future (without regret).
If QEMU is diving in and extracting non UAPI headers then that is a bad idea. It is outside the scope of this.
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Paolo Bonzini
maintainerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
In reply to Roman KaganQuoted 7 lines · Roman Kagan
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?Then I think we're fine withdrawing it from uapi as a whole and letting QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Actually, QEMU's header-harvesting scripts use uapi/ headers exclusively, since they are built on "make headers_install".
The extra cleanups that QEMU does on top are to allow compilation of the headers on non-Linux machines. They don't really do much more than changing Linux (linux/types.h) integer types to the C99 (stdint.h) equivalents.
Paolo
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 9 lines · Paolo Bonzini
Quoted 7 lines · Roman Kagan
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?Then I think we're fine withdrawing it from uapi as a whole and letting QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Quoted 7 lines
Actually, QEMU's header-harvesting scripts use uapi/ headers exclusively, since they are built on "make
headers_install".The extra cleanups that QEMU does on top are to allow compilation of the headers on non-Linux machines. They don't really do much more than changing Linux (
linux/types.h) integer types to the C99 (stdint.h) equivalents.
Ouch, I stand corrected.
So what should we do with it then? I'm sorta lost...
We certainly can give it up and live with a private copy of the definitions in the QEMU tree but that doesn't sound optimal in any sense.
Thanks,
Roman.
[email protected]
reviewerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 22 lines · Roman Kagan
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Roman Kagan
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?Then I think we're fine withdrawing it from uapi as a whole and
letting
Quoted 8 lines
Quoted 3 lines
QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Actually, QEMU's header-harvesting scripts use uapi/ headers exclusively, since they are built on "make
headers_install".The extra cleanups that QEMU does on top are to allow compilation of
the
Quoted 3 lines
headers on non-Linux machines. They don't really do much more than changing Linux (
linux/types.h) integer types to the C99 (stdint.h) equivalents.Ouch, I stand corrected.
Quoted 8 lines
So what should we do with it then? I'm sorta lost...
We certainly can give it up and live with a private copy of the definitions in the QEMU tree but that doesn't sound optimal in any sense.
Thanks,
Roman.
Why do that through header mangling rather than typedef?
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 25 lines · On Mon, Jan 09, 2017 at 12:40:48AM -0800, [email protected] wrote:
Quoted 24 lines · Roman Kagan
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Roman Kagan
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?Then I think we're fine withdrawing it from uapi as a whole and
letting
Quoted 8 lines
Quoted 3 lines
QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Actually, QEMU's header-harvesting scripts use uapi/ headers exclusively, since they are built on "make
headers_install".The extra cleanups that QEMU does on top are to allow compilation of
the
Quoted 3 lines
headers on non-Linux machines. They don't really do much more than changing Linux (
linux/types.h) integer types to the C99 (stdint.h) equivalents.Ouch, I stand corrected.
So what should we do with it then? I'm sorta lost...
Quoted 8 lines
Quoted 6 lines
We certainly can give it up and live with a private copy of the definitions in the QEMU tree but that doesn't sound optimal in any sense.
Thanks,
Roman.Why do that through header mangling rather than typedef?
Sorry for not being clear, I actually asked what to do with the Hyper-V and VMBus protocol definitions.
The typedef vs mangling is a different matter; I guess mangling was chosen to avoid conflicts with system-provided definitions on non-Linux systems, but I think Paolo can tell more.
Roman.
Paolo Bonzini
maintainerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
In reply to [email protected]Quoted 23 lines · On 09/01/2017 09:40, [email protected] wrote:
Quoted 22 lines · Roman Kagan
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Roman Kagan
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?Then I think we're fine withdrawing it from uapi as a whole and
letting
Quoted 8 lines
Quoted 3 lines
QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Actually, QEMU's header-harvesting scripts use uapi/ headers exclusively, since they are built on "make
headers_install".The extra cleanups that QEMU does on top are to allow compilation of
the
Quoted 3 lines
headers on non-Linux machines. They don't really do much more than changing Linux (
linux/types.h) integer types to the C99 (stdint.h) equivalents.Ouch, I stand corrected.
Quoted 7 lines
Quoted 5 lines
So what should we do with it then? I'm sorta lost...
We certainly can give it up and live with a private copy of the definitions in the QEMU tree but that doesn't sound optimal in any sense.
Why do that through header mangling rather than typedef?
Because you are not suppose to typedef identifiers that start with "__", and because it does do a few other ad-hoc changes:
-e 's/<linux\/\([^>]*\)>/"standard-headers\/linux\/\1"/' \
-e 's/__bitwise__//' \
-e 's/__attribute__((packed))/QEMU_PACKED/' \
-e 's/__inline__/inline/' \
-e '/sys\/ioctl.h/d' \
-e 's/SW_MAX/SW_MAX_/' \Paolo
Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
In reply to Roman KaganQuoted 49 lines · On Wed, 28 Dec 2016 20:09:44 +0300 Roman Kagan <[email protected]> wrote:
Quoted 41 lines · KY Srinivasan
Quoted 25 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, December 21, 2016 10:03 AM
To: Christoph Hellwig <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Roman Kagan <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>; [email protected]; Denis V . Lunev <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Thomas Gleixner <[email protected]>
Subject: Re: [PATCH 12/15] hyperv: move VMBus connection ids to uapiQuoted 3 lines · On Wed, 21 Dec 2016 09:58:36 -0800 Christoph Hellwig <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
Lastly, there is licensing issues on headers. It would be good to have any userspace ABI headers licensed with a more liberal license so that BSD
and DPDK drivers
Quoted 2 lines
Quoted 1 line
could use them directly. Right now each one reinvents.
Quoted 8 lines
Quoted 3 lines
Microsoft could easily solves this problem by offering a suitably liberally licensed header documenting the full HyperV guest protocol that Linux and other projects could use.
The issue is if same header file mixes kernel and userspace API stuff.
Once the files are arranged right, I will submit trivial change to comments to indicate the liberal licensing of userspace API headers.
Let us take this one step at a time. I know for a fact that not all the guest host protocols on Hyper-V are guaranteed to be stable. Some of the protocols are part of the published MSFT standards such RNDIS and these obviously are guaranteed to be stable. For the rest it is less clear. The fact that we need to ensure compatibility of existing Windows guests tells me that any host side changes will be versioned and the hosts will always support older guests.
Quoted 3 lines
I would like to minimize what we include in the uapi header; especially when MSFT has made no guarantees with regards how they may be evolved. I will also work on getting some clarity on both stability and under what license we would expose the uapi header.
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?
Quoted 6 lines
Then I think we're fine withdrawing it from uapi as a whole and letting QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Roman.
Thanks, that prevents lots of problems.
That is how I handle iproute2 as well.
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Paolo Bonzini
maintainerRe: [PATCH 12/15] hyperv: move VMBus connection ids to uapi
Quoted 7 lines · Stephen Hemminger
Quoted 7 lines
Quoted 4 lines
I would like to minimize what we include in the uapi header; especially when MSFT has made no guarantees with regards how they may be evolved. I will also work on getting some clarity on both stability and under what license we would expose the uapi header.
Am I correct assuming that QEMU is currently the only user of
arch/x86/include/uapi/asm/hyperv.h?
Quoted 7 lines
Quoted 4 lines
Then I think we're fine withdrawing it from uapi as a whole and letting QEMU pull it in through its header-harvesting scripts (as does now anyway). This would lift all licensing and longterm API stability expectations.
Thanks, that prevents lots of problems.
That is how I handle iproute2 as well.
Except it wouldn't work. But no big deal, I guess we'll just synchronize hyperv.h manually. :((
Paolo
PATCH 13/15 hyperv: move function close to its only callsite
In reply to Roman Kagan--- drivers/hv/hyperv_vmbus.h | 44 -------------------------------------------- drivers/hv/hv.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 44 deletions(-)
drivers/hv/hyperv_vmbus.h +0 -44
@@ -118,50 +118,6 @@ enum hv_guest_os_microsoft_ids {#define HV_PRESENT_BIT 0x80000000 -/* -* 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: -* -* http://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 0x8100 - -/* -* Generate the guest ID based on the guideline described above. -*/ - -static inline __u64 generate_guest_id (__u8 d_info1,__u32 kernel_version, -__u16 d_info2) -{ -__u64 guest_id =0 ; - - guest_id = (((__u64 )HV_LINUX_VENDOR_ID ) <<48 ); - guest_id |= (((__u64)(d_info1)) <<48 ); - guest_id |= (((__u64)(kernel_version)) <<16 ); - guest_id |= ((__u64)(d_info2)); - -return guest_id; -} - -#define HV_CPU_POWER_MANAGEMENT (1 << 0)#define HV_RECOMMENDATIONS_MAX 4
drivers/hv/hv.c +39 -0
@@ -45,6 +45,45 @@ struct hv_context hv_context = {#define HV_MIN_DELTA_TICKS 1/* +* 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: +* +* http://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 0x8100 + +/* +* Generate the guest ID based on the guideline described above. +*/ + +static u64 generate_guest_id (u8 d_info1,u32 kernel_version,u16 d_info2) +{ +u64 guest_id; + + guest_id = ((u64 )HV_LINUX_VENDOR_ID ) <<48 ; + guest_id |= ((u64 )d_info1) <<48 ; + guest_id |= ((u64 )kernel_version) <<16 ; + guest_id |= (u64 )d_info2; + +return guest_id; +} + +/* * query_hypervisor_info - Get version info of the windows hypervisor */ unsigned int host_info_eax;
Signature · 1 line
2.9.3
PATCH 14/15 hyperv_vmbus: drop unused definitions
In reply to Roman KaganNone of these is used in the kernel.
--- drivers/hv/hyperv_vmbus.h | 119 ---------------------------------------------- 1 file changed, 119 deletions(-)
drivers/hv/hyperv_vmbus.h +0 -119
@@ -39,125 +39,6 @@*/ #define HV_UTIL_NEGO_TIMEOUT 55 -/* Define version of the synthetic interrupt controller. */ -#define HV_SYNIC_VERSION (1) - -#define HV_ANY_VP (0xFFFFFFFF) - -/* 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; - }; -}; - -/* -* 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 -}; - - -/* #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 - - -/* 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
Signature · 1 line
2.9.3
PATCH 15/15 hyperv: redefine hv_message without bitfields
In reply to Roman KaganThis brings more symmetry in the API.
The downside is that this changes the userspace-visible structure. Hopefully no userspace code had a chance to use it yet.
--- arch/x86/include/uapi/asm/hyperv.h | 32 +++++--------------------------- drivers/hv/hyperv_vmbus.h | 2 +- arch/x86/kvm/hyperv.c | 10 +++++----- drivers/hv/channel_mgmt.c | 6 +++--- drivers/hv/vmbus_drv.c | 2 +- 5 files changed, 15 insertions(+), 37 deletions(-)
arch/x86/include/uapi/asm/hyperv.h +5 -27
@@ -276,7 +276,8 @@ struct hv_ref_tsc_page {/* Define synthetic interrupt controller message constants. */ #define HV_MESSAGE_SIZE (256)#define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240) -#define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30) + +#define HV_MESSAGE_FLAG_PENDING (1)/* Define hypervisor message types. */ enum hv_message_type {
@@ -308,42 +309,19 @@ enum hv_message_type { HVMSG_X64_LEGACY_FP_ERROR = 0x80010005 }; -/* Define synthetic interrupt controller message flags. */ -union hv_message_flags { -__u8 asu8; -struct { -__u8 msg_pending:1 ; -__u8 reserved:7 ; - }; -}; - -/* Define port identifier type. */ -union hv_port_id { -__u32 asu32; -struct { -__u32 id:24 ; -__u32 reserved:8 ; - } u; -}; -/* Define synthetic interrupt controller message header. */ struct hv_message_header {__u32 message_type;__u8 payload_size; -union hv_message_flags message_flags; +__u8 message_flags;__u8 reserved[2 ]; -union { -__u64 sender; -union hv_port_id port; - }; +__u64 origination_id; };/* Define synthetic interrupt controller message format. */ struct hv_message {struct hv_message_header header; -union { -__u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT ]; - } u; +__u64 payload[HV_MESSAGE_PAYLOAD_BYTE_COUNT /8 ]; };/* Define the synthetic interrupt message page layout. */
drivers/hv/hyperv_vmbus.h +1 -1
@@ -260,7 +260,7 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)*/ mb (); -if (msg->header.message_flags.msg_pending) { +if (msg->header.message_flags &HV_MESSAGE_FLAG_PENDING ) {/* * This will cause message queue rescan to * possibly deliver another msg from the
arch/x86/kvm/hyperv.c +5 -5
@@ -137,7 +137,7 @@ static void synic_clear_sint_msg_pending(struct kvm_vcpu_hv_synic *synic, msg_page =kmap_atomic (page); msg = &msg_page->sint_message[sint]; - msg->header.message_flags.msg_pending =0 ; + msg->header.message_flags &= ~HV_MESSAGE_FLAG_PENDING ;kunmap_atomic (msg_page);kvm_release_page_dirty (page);
@@ -564,10 +564,10 @@ static int synic_deliver_msg(struct kvm_vcpu_hv_synic *synic, u32 sint, dst_msg = &msg_page->sint_message[sint];if (sync_cmpxchg (&dst_msg->header.message_type,HVMSG_NONE , src_msg->header.message_type) !=HVMSG_NONE ) { - dst_msg->header.message_flags.msg_pending =1 ; + dst_msg->header.message_flags |=HV_MESSAGE_FLAG_PENDING ; r = -EAGAIN ; }else { -memcpy (&dst_msg->u.payload, &src_msg->u.payload, +memcpy (&dst_msg->payload, &src_msg->payload, src_msg->header.payload_size); dst_msg->header.message_type = src_msg->header.message_type; dst_msg->header.payload_size = src_msg->header.payload_size;
@@ -588,7 +588,7 @@ static int stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer)struct kvm_vcpu *vcpu =stimer_to_vcpu (stimer);struct hv_message *msg = &stimer->msg;struct hv_timer_message_payload *payload = - (struct hv_timer_message_payload *)&msg->u.payload; + (struct hv_timer_message_payload *)&msg->payload; payload->expiration_time = stimer->exp_time; payload->delivery_time =get_time_ref_counter (vcpu->kvm);
@@ -653,7 +653,7 @@ static void stimer_prepare_msg(struct kvm_vcpu_hv_stimer *stimer) {struct hv_message *msg = &stimer->msg;struct hv_timer_message_payload *payload = - (struct hv_timer_message_payload *)&msg->u.payload; + (struct hv_timer_message_payload *)&msg->payload;memset (&msg->header,0 ,sizeof (msg->header)); msg->header.message_type =HVMSG_TIMER_EXPIRED ;
drivers/hv/channel_mgmt.c +3 -3
@@ -680,7 +680,7 @@ static void vmbus_wait_for_unload(void)continue ; hdr = (struct vmbus_channel_message_header *) - msg->u.payload; + msg->payload;if (hdr->msgtype ==CHANNELMSG_UNLOAD_RESPONSE )complete (&vmbus_connection.unload_event);
@@ -1071,14 +1071,14 @@ void vmbus_onmessage(void *context)struct vmbus_channel_message_header *hdr;int size; - hdr = (struct vmbus_channel_message_header *)msg->u.payload; + hdr = (struct vmbus_channel_message_header *)msg->payload; size = msg->header.payload_size;if (hdr->msgtype >=CHANNELMSG_COUNT ) {pr_err ("Received invalid channel message type %d size %d\n" , hdr->msgtype, size);print_hex_dump_bytes ("" ,DUMP_PREFIX_NONE , - (unsigned char *)msg->u.payload, size); + (unsigned char *)msg->payload, size);return ; }
drivers/hv/vmbus_drv.c +1 -1
@@ -883,7 +883,7 @@ void vmbus_on_msg_dpc(unsigned long data)/* no msg */ return ; - hdr = (struct vmbus_channel_message_header *)msg->u.payload; + hdr = (struct vmbus_channel_message_header *)msg->payload;if (hdr->msgtype >=CHANNELMSG_COUNT ) {WARN_ONCE (1 ,"unknown msgtype=%d\n" , hdr->msgtype);
Signature · 1 line
2.9.3
Quoted 23 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
To: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; KY Srinivasan <[email protected]>; Vitaly Kuznetsov <[email protected]>
Cc: Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>; Roman Kagan <[email protected]>
Subject: [PATCH 00/15] hyperv: more stuff to uapi + cleanupExpose more Hyper-V-related definitions in the uapi header for consumption by userspace.
While doing so, get rid of a number of duplications between the KVM and the guest driver code. Also a few other cleanups are made which are not strictly necessary for the main purpose of the series but appear reasonable to do at the same time.
Quoted 4 lines
The most controversial is the last patch which modifies the stuff already published in the uapi header, in the hope that no userspace applications have started relying on it; I'm ok dropping it if this is unacceptable.
Roman,
First, let me thank you. Broadly, this patch-set can be broken into
1. Moving existing definitions around - (to make it possible to share these between Hyper-V guest drivers and KVM)
2. Cleanup of the existing code in the VMBUS driver (under drivers/hv).
To the extent possible, I want to take all non-KVM code through Greg's tree. We can then modify the KVM code to use these common definitions. Currently, I too am working on restructuring VMBUS driver code to fully isolate all x86 dependencies. I can work with you on integration as I too am moving things around.
Regards,
K. Y
Quoted 32 lines
Roman Kagan (15):
hyperv: consolidate TSC ref page definitions
hyperv: uapi-fy synic event flags definitions
hyperv: use standard bitops
hyperv: define VMBus message type
hyperv:GFP_ATOMIC->GFP_KERNEL
hyperv: avoid unnecessary vmalloc
hyperv: dedup cpuid definitions
hyperv: dedup crash msr related definitions
hyperv: unify Hyper-V msr definitions
hyperv: uapi-fy PostMessage and SignalEvent hypercall structures
hyperv: uapi-fy monitored notification structures
hyperv: move VMBus connection ids to uapi
hyperv: move function close to its only callsite
hyperv_vmbus: drop unused definitions
hyperv: redefinehv_messagewithout bitfieldsarch/x86/include/asm/kvm_host.h | 2 +- arch/x86/include/uapi/asm/hyperv.h | 101 +++++++--- drivers/hv/hyperv_vmbus.h | 399 +------------------------------------ include/linux/hyperv.h | 24 +-- arch/x86/kvm/hyperv.c | 14 +- drivers/hv/channel.c | 8 +- drivers/hv/channel_mgmt.c | 30 +-- drivers/hv/connection.c | 65 ++---- drivers/hv/hv.c | 300 +++++++++++++--------------- drivers/hv/vmbus_drv.c | 67 +++---- 10 files changed, 288 insertions(+), 722 deletions(-)--
2.9.3
[ Sorry for such a slow reply; flu and office relocation knocked me out for a while ]
Quoted 18 lines · KY Srinivasan
Quoted 13 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
Subject: [PATCH 00/15] hyperv: more stuff to uapi + cleanupExpose more Hyper-V-related definitions in the uapi header for consumption by userspace.
While doing so, get rid of a number of duplications between the KVM and the guest driver code. Also a few other cleanups are made which are not strictly necessary for the main purpose of the series but appear reasonable to do at the same time.
Quoted 4 lines
The most controversial is the last patch which modifies the stuff already published in the uapi header, in the hope that no userspace applications have started relying on it; I'm ok dropping it if this is unacceptable.
Quoted 4 lines
First, let me thank you. Broadly, this patch-set can be broken into
1. Moving existing definitions around - (to make it possible to share these between Hyper-V guest drivers and KVM)
2. Cleanup of the existing code in the VMBUS driver (underdrivers/hv).
Right. Another significant part of the series is, where two sets of definitions exist for the same entity, consolidate on the one that looks more Linux-style, usually the one in the (currently) uapi header.
Quoted 2 lines
To the extent possible, I want to take all non-KVM code through Greg's tree. We can then modify the KVM code to use these common definitions.
Well, this patchset touches almost no KVM code, so we're fine here I think.
Quoted 3 lines
Currently, I too am working on restructuring VMBUS driver code to fully isolate all x86 dependencies. I can work with you on integration as I too am moving things around.
Great! Do you want me to rebase on some your public tree? (Once I split the patches as you requested, of course)?
Thanks,
Roman.
Quoted 53 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Wednesday, December 28, 2016 8:57 AM
To: KY Srinivasan <[email protected]>
Cc: Paolo Bonzini <[email protected]>; Radim Krčmář <[email protected]>; Vitaly Kuznetsov <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; H. Peter Anvin <[email protected]>; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Denis V . Lunev <[email protected]>
Subject: Re: [PATCH 00/15] hyperv: more stuff to uapi + cleanup[ Sorry for such a slow reply; flu and office relocation knocked me out for a while ]
Quoted 18 lines · KY Srinivasan
Quoted 13 lines
-----Original Message-----
From: Roman Kagan [mailto:[email protected]]
Sent: Tuesday, December 20, 2016 7:56 AM
Subject: [PATCH 00/15] hyperv: more stuff to uapi + cleanupExpose more Hyper-V-related definitions in the uapi header for consumption by userspace.
While doing so, get rid of a number of duplications between the KVM and the guest driver code. Also a few other cleanups are made which are not strictly necessary for the main purpose of the series but appear reasonable to do at the same time.
Quoted 4 lines
The most controversial is the last patch which modifies the stuff already published in the uapi header, in the hope that no userspace applications have started relying on it; I'm ok dropping it if this is unacceptable.
Quoted 4 lines
First, let me thank you. Broadly, this patch-set can be broken into
1. Moving existing definitions around - (to make it possible to share these between Hyper-V guest drivers and KVM)
2. Cleanup of the existing code in the VMBUS driver (underdrivers/hv).Right. Another significant part of the series is, where two sets of definitions exist for the same entity, consolidate on the one that looks more Linux-style, usually the one in the (currently) uapi header.
Quoted 1 line
To the extent possible, I want to take all non-KVM code through Greg's
tree.
Quoted 1 line
We can then modify the KVM code to use these common definitions.
Well, this patchset touches almost no KVM code, so we're fine here I think.
Quoted 6 lines
Quoted 3 lines
Currently, I too am working on restructuring VMBUS driver code to fully isolate all x86 dependencies. I can work with you on integration as I too am moving things around.
Great! Do you want me to rebase on some your public tree? (Once I split the patches as you requested, of course)?
I just sent out the patches that I have been working on. These are based on Greg's char-misc tree. I do have a bunch of patches in flight that have not been checked in yet. Sorry, I don't have a public tree I can point you to. I will work with you and coordinate our work here.
Happy New Year!
K. Y