Drivers: hv: vmbbus: Miscellaneous cleanup
Subsystems (2)
cover Drivers: hv: vmbbus: Miscellaneous cleanup
From: K. Y. Srinivasan <[email protected]>
Miscellaneous cleanup.
Michael Kelley (1):
Drivers: hv: vmbus: Remove x86-isms from arch independent drivers
Stephen Hemminger (1):
vmbus: make hv_get_ringbuffer_availbytes local
arch/x86/hyperv/hv_init.c | 21 ++++++++++++++------- arch/x86/include/asm/mshyperv.h | 4 ++-- drivers/hv/hv.c | 3 --- drivers/hv/ring_buffer.c | 23 +++++++++++++++++++++++ drivers/hv/vmbus_drv.c | 5 ++--- include/linux/hyperv.h | 22 ---------------------- 6 files changed, 41 insertions(+), 37 deletions(-)
PATCH 1/2 Drivers: hv: vmbus: Remove x86-isms from arch independent drivers
From: Michael Kelley <[email protected]>
hv_is_hypercall_page_setup() is used to check if Hyper-V is initialized, but a 'hypercall page' is an x86 implementation detail that isn't necessarily present on other architectures. Rename to the architecture independent hv_is_hyperv_initialized() and add check that x86_hyper is pointing to Hyper-V. Use this function instead of direct references to x86-specific data structures in vmbus_drv.c, and remove now redundant call in hv_init(). Also remove 'x86' from the string name passed to cpuhp_setup_state().
--- arch/x86/hyperv/hv_init.c | 21 ++++++++++++++------- arch/x86/include/asm/mshyperv.h | 4 ++-- drivers/hv/hv.c | 3 --- drivers/hv/vmbus_drv.c | 5 ++--- 4 files changed, 18 insertions(+), 15 deletions(-)
arch/x86/hyperv/hv_init.c +14 -7
@@ -239,17 +239,24 @@ void hyperv_report_panic(struct pt_regs *regs, long err) }EXPORT_SYMBOL_GPL (hyperv_report_panic); -bool hv_is_hypercall_page_setup (void ) +bool hv_is_hyperv_initialized (void ) {union hv_x64_msr_hypercall_contents hypercall_msr; -/* Check if the hypercall page is setup */ +/* +* Ensure that we're really on Hyper-V, and not a KVM or Xen +* emulation of Hyper-V +*/ +if (x86_hyper != &x86_hyper_ms_hyperv) +return false; + +/* +* Verify that earlier initialization succeeded by checking +* that the hypercall page is setup +*/ hypercall_msr.as_uint64 =0 ;rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); -if (!hypercall_msr.enable) -return false; - -return true; +return hypercall_msr.enable; } -EXPORT_SYMBOL_GPL (hv_is_hypercall_page_setup); +EXPORT_SYMBOL_GPL (hv_is_hyperv_initialized);
arch/x86/include/asm/mshyperv.h +2 -2
@@ -311,11 +311,11 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number)void hyperv_setup_mmu_ops (void );void hyper_alloc_mmu (void );void hyperv_report_panic (struct pt_regs *regs,long err); -bool hv_is_hypercall_page_setup (void ); +bool hv_is_hyperv_initialized (void );void hyperv_cleanup (void );#else /* CONFIG_HYPERV */ static inline void hyperv_init (void ) {} -static inline bool hv_is_hypercall_page_setup (void ) {return false; } +static inline bool hv_is_hyperv_initialized (void ) {return false; }static inline void hyperv_cleanup (void ) {}static inline void hyperv_setup_mmu_ops (void ) {}#endif /* CONFIG_HYPERV */
drivers/hv/hv.c +0 -3
@@ -49,9 +49,6 @@ struct hv_context hv_context = {*/ int hv_init (void ) { -if (!hv_is_hypercall_page_setup ()) -return -ENOTSUPP ; - hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context);if (!hv_context.cpu_context)return -ENOMEM ;
drivers/hv/vmbus_drv.c +2 -3
@@ -37,7 +37,6 @@#include <linux/sched/task_stack.h> #include <asm/hyperv.h> -#include <asm/hypervisor.h> #include <asm/mshyperv.h> #include <linux/notifier.h> #include <linux/ptrace.h>
@@ -1053,7 +1052,7 @@ static int vmbus_bus_init(void)* Initialize the per-cpu interrupt state and * connect to the host. */ - ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"x86/hyperv:online" , + ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"hyperv/vmbus:online" , hv_synic_init, hv_synic_cleanup);if (ret <0 ) goto err_alloc;
@@ -1717,7 +1716,7 @@ static int __init hv_acpi_init(void) {int ret, t; -if (x86_hyper != &x86_hyper_ms_hyperv) +if (!hv_is_hyperv_initialized ())return -ENODEV ;init_completion (&probe_event);
Signature · 1 line
1.7.1
Re: [PATCH 1/2] Drivers: hv: vmbus: Remove x86-isms from arch independent drivers
Quoted 120 lines · On Tue, Nov 14, 2017 at 10:52:07AM -0700, [email protected] wrote:
From: Michael Kelley <[email protected]>
hv_is_hypercall_page_setup()is used to check if Hyper-V is initialized, but a 'hypercall page' is an x86 implementation detail that isn't necessarily present on other architectures. Rename to the architecture independenthv_is_hyperv_initialized()and add check thatx86_hyperis pointing to Hyper-V. Use this function instead of direct references to x86-specific data structures invmbus_drv.c, and remove now redundant call inhv_init(). Also remove 'x86' from the string name passed tocpuhp_setup_state().Signed-off-by Michael Kelley <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- arch/x86/hyperv/hv_init.c | 21 ++++++++++++++------- arch/x86/include/asm/mshyperv.h | 4 ++-- drivers/hv/hv.c | 3 --- drivers/hv/vmbus_drv.c | 5 ++--- 4 files changed, 18 insertions(+), 15 deletions(-)arch/x86/hyperv/hv_init.c +14
-7@@ -239,17 +239,24 @@ void hyperv_report_panic(struct pt_regs *regs, long err) }EXPORT_SYMBOL_GPL (hyperv_report_panic); -bool hv_is_hypercall_page_setup (void ) +bool hv_is_hyperv_initialized (void ) {union hv_x64_msr_hypercall_contents hypercall_msr; -/* Check if the hypercall page is setup */ +/* +* Ensure that we're really on Hyper-V, and not a KVM or Xen +* emulation of Hyper-V +*/ +if (x86_hyper != &x86_hyper_ms_hyperv) +return false; + +/* +* Verify that earlier initialization succeeded by checking +* that the hypercall page is setup +*/ hypercall_msr.as_uint64 =0 ;rdmsrl (HV_X64_MSR_HYPERCALL , hypercall_msr.as_uint64); -if (!hypercall_msr.enable) -return false; - -return true; +return hypercall_msr.enable; } -EXPORT_SYMBOL_GPL (hv_is_hypercall_page_setup); +EXPORT_SYMBOL_GPL (hv_is_hyperv_initialized);arch/x86/include/asm/mshyperv.h +2
-2@@ -311,11 +311,11 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number)void hyperv_setup_mmu_ops (void );void hyper_alloc_mmu (void );void hyperv_report_panic (struct pt_regs *regs,long err); -bool hv_is_hypercall_page_setup (void ); +bool hv_is_hyperv_initialized (void );void hyperv_cleanup (void );#else /* CONFIG_HYPERV */ static inline void hyperv_init (void ) {} -static inline bool hv_is_hypercall_page_setup (void ) {return false; } +static inline bool hv_is_hyperv_initialized (void ) {return false; }static inline void hyperv_cleanup (void ) {}static inline void hyperv_setup_mmu_ops (void ) {}#endif /* CONFIG_HYPERV */ drivers/hv/hv.c +0
-3@@ -49,9 +49,6 @@ struct hv_context hv_context = {*/ int hv_init (void ) { -if (!hv_is_hypercall_page_setup ()) -return -ENOTSUPP ; - hv_context.cpu_context = alloc_percpu(struct hv_per_cpu_context);if (!hv_context.cpu_context)return -ENOMEM ;drivers/hv/vmbus_drv.c +2
-3@@ -37,7 +37,6 @@#include <linux/sched/task_stack.h> #include <asm/hyperv.h> -#include <asm/hypervisor.h> #include <asm/mshyperv.h> #include <linux/notifier.h> #include <linux/ptrace.h> @@ -1053,7 +1052,7 @@ static int vmbus_bus_init(void)* Initialize the per-cpu interrupt state and * connect to the host. */ - ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"x86/hyperv:online" , + ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"hyperv/vmbus:online" , hv_synic_init, hv_synic_cleanup);if (ret <0 ) goto err_alloc;@@ -1717,7 +1716,7 @@ static int __init hv_acpi_init(void) {int ret, t; -if (x86_hyper != &x86_hyper_ms_hyperv) +if (!hv_is_hyperv_initialized ())return -ENODEV ;init_completion (&probe_event);Signature · 1 line
1.7.1
Does not apply to 4.15-rc1 :(
PATCH 2/2 vmbus: make hv_get_ringbuffer_availbytes local
In reply to [email protected]From: Stephen Hemminger <[email protected]>
hv_get_ringbuffer_availbytes is only used by the debug info routine so make it static. Also, add READ_ONCE() to avoid any possible issues with potentially volatile index values.
--- drivers/hv/ring_buffer.c | 23 +++++++++++++++++++++++ include/linux/hyperv.h | 22 ---------------------- 2 files changed, 23 insertions(+), 22 deletions(-)
drivers/hv/ring_buffer.c +23 -0
@@ -140,6 +140,29 @@ static u32 hv_copyto_ringbuffer(return start_write_offset; } +/* +* +* hv_get_ringbuffer_availbytes() +* +* Get number of bytes available to read and to write to +* for the specified ring buffer +*/ +static void +hv_get_ringbuffer_availbytes (const struct hv_ring_buffer_info *rbi, +u32 *read,u32 *write) +{ +u32 read_loc, write_loc, dsize; + +/* Capture the read/write indices before they changed */ + read_loc =READ_ONCE (rbi->ring_buffer->read_index); + write_loc =READ_ONCE (rbi->ring_buffer->write_index); + dsize = rbi->ring_datasize; + + *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : + read_loc - write_loc; + *read = dsize - *write; +} +/* Get various debug metrics for the specified ring buffer. */ void hv_ringbuffer_get_debuginfo (const struct hv_ring_buffer_info *ring_info,struct hv_ring_buffer_debug_info *debug_info)
include/linux/hyperv.h +0 -22
@@ -127,28 +127,6 @@ struct hv_ring_buffer_info {u32 priv_read_index; }; -/* -* -* hv_get_ringbuffer_availbytes() -* -* Get number of bytes available to read and to write to -* for the specified ring buffer -*/ -static inline void -hv_get_ringbuffer_availbytes (const struct hv_ring_buffer_info *rbi, -u32 *read,u32 *write) -{ -u32 read_loc, write_loc, dsize; - -/* Capture the read/write indices before they changed */ - read_loc = rbi->ring_buffer->read_index; - write_loc = rbi->ring_buffer->write_index; - dsize = rbi->ring_datasize; - - *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : - read_loc - write_loc; - *read = dsize - *write; -}static inline u32 hv_get_bytes_to_read (const struct hv_ring_buffer_info *rbi) {
Signature · 1 line
1.7.1
Re: [PATCH 2/2] vmbus: make hv_get_ringbuffer_availbytes local
Quoted 82 lines · On Tue, Nov 14, 2017 at 10:52:08AM -0700, [email protected] wrote:
From: Stephen Hemminger <[email protected]>
hv_get_ringbuffer_availbytesis only used by the debug info routine so make it static. Also, addREAD_ONCE()to avoid any possible issues with potentially volatile index values.Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/ring_buffer.c | 23 +++++++++++++++++++++++ include/linux/hyperv.h | 22 ---------------------- 2 files changed, 23 insertions(+), 22 deletions(-)drivers/hv/ring_buffer.c +23
-0@@ -140,6 +140,29 @@ static u32 hv_copyto_ringbuffer(return start_write_offset; } +/* +* +* hv_get_ringbuffer_availbytes() +* +* Get number of bytes available to read and to write to +* for the specified ring buffer +*/ +static void +hv_get_ringbuffer_availbytes (const struct hv_ring_buffer_info *rbi, +u32 *read,u32 *write) +{ +u32 read_loc, write_loc, dsize; + +/* Capture the read/write indices before they changed */ + read_loc =READ_ONCE (rbi->ring_buffer->read_index); + write_loc =READ_ONCE (rbi->ring_buffer->write_index); + dsize = rbi->ring_datasize; + + *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : + read_loc - write_loc; + *read = dsize - *write; +} +/* Get various debug metrics for the specified ring buffer. */ void hv_ringbuffer_get_debuginfo (const struct hv_ring_buffer_info *ring_info,struct hv_ring_buffer_debug_info *debug_info)include/linux/hyperv.h +0
-22@@ -127,28 +127,6 @@ struct hv_ring_buffer_info {u32 priv_read_index; }; -/* -* -* hv_get_ringbuffer_availbytes() -* -* Get number of bytes available to read and to write to -* for the specified ring buffer -*/ -static inline void -hv_get_ringbuffer_availbytes (const struct hv_ring_buffer_info *rbi, -u32 *read,u32 *write) -{ -u32 read_loc, write_loc, dsize; - -/* Capture the read/write indices before they changed */ - read_loc = rbi->ring_buffer->read_index; - write_loc = rbi->ring_buffer->write_index; - dsize = rbi->ring_datasize; - - *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : - read_loc - write_loc; - *read = dsize - *write; -}static inline u32 hv_get_bytes_to_read (const struct hv_ring_buffer_info *rbi) {Signature · 1 line
1.7.1
This breaks the build.
Please be more careful...
greg k-h
RE: [PATCH 2/2] vmbus: make hv_get_ringbuffer_availbytes local
Quoted 98 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, November 28, 2017 7:35 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; Stephen Hemminger <[email protected]>
Subject: Re: [PATCH 2/2] vmbus: makehv_get_ringbuffer_availbyteslocalQuoted 36 lines · On Tue, Nov 14, 2017 at 10:52:08AM -0700, [email protected] wrote:
From: Stephen Hemminger <[email protected]>
hv_get_ringbuffer_availbytesis only used by the debug info routine so make it static. Also, addREAD_ONCE()to avoid any possible issues with potentially volatile index values.Signed-off-by Stephen Hemminger <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/ring_buffer.c | 23 +++++++++++++++++++++++ include/linux/hyperv.h | 22 ---------------------- 2 files changed, 23 insertions(+), 22 deletions(-)drivers/hv/ring_buffer.c +15
-0@@ -140,6 +140,29 @@ static u32 hv_copyto_ringbuffer(return start_write_offset; } +/* +* +* hv_get_ringbuffer_availbytes() +* +* Get number of bytes available to read and to write to +* for the specified ring buffer +*/ +static void +hv_get_ringbuffer_availbytes (const struct hv_ring_buffer_info *rbi, +u32 *read,u32 *write) +{ +u32 read_loc, write_loc, dsize; + +/* Capture the read/write indices before they changed */ + read_loc =READ_ONCE (rbi->ring_buffer->read_index);drivers/hv/ring_buffer.c static u32 hv_copyto_ringbuffer( · line 167
Quoted 10 lines
drivers/hv/ring_buffer.c +8
-0+ write_loc =READ_ONCE (rbi->ring_buffer->write_index); + dsize = rbi->ring_datasize; + + *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : + read_loc - write_loc; + *read = dsize - *write; +} +/* Get various debug metrics for the specified ring buffer. */ void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info
*ring_info,drivers/hv/ring_buffer.c static u32 hv_copyto_ringbuffer( · line 168
Quoted 1 line
drivers/hv/ring_buffer.c +0
-0struct hv_ring_buffer_debug_info
*debug_info)Quoted 22 lines
include/linux/hyperv.h +0
-14@@ -127,28 +127,6 @@ struct hv_ring_buffer_info {u32 priv_read_index; }; -/* -* -* hv_get_ringbuffer_availbytes() -* -* Get number of bytes available to read and to write to -* for the specified ring buffer -*/ -static inline void -hv_get_ringbuffer_availbytes (const struct hv_ring_buffer_info *rbi, -u32 *read,u32 *write) -{ -u32 read_loc, write_loc, dsize; - -/* Capture the read/write indices before they changed */ include/linux/hyperv.h struct hv_ring_buffer_info { · line 131
Quoted 10 lines
include/linux/hyperv.h +0
-8- read_loc = rbi->ring_buffer->read_index; - write_loc = rbi->ring_buffer->write_index; - dsize = rbi->ring_datasize; - - *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : - read_loc - write_loc; - *read = dsize - *write; -} static inline u32 hv_get_bytes_to_read(const struct hv_ring_buffer_info*rbi)
Quoted 7 lines
Quoted 3 lines
include/linux/hyperv.h +0
-1{ --1.7.1
This breaks the build.
Please be more careful...
Sorry about that. I did not have a build issue on the tree I tested. I will rebase and send.
K. Y
Quoted 2 lines
greg k-h
RE: [PATCH 2/2] vmbus: make hv_get_ringbuffer_availbytes local
This patch required a patch that is still going through net-next.