Drivers: hv: Miscellaneous fixes
Subsystems (2)
cover Drivers: hv: Miscellaneous fixes
From: "K. Y. Srinivasan" <[email protected]>
Miscellaneous fixes.
Dexuan Cui (3):
Drivers: hv: kvp: Fix the recent regression caused by incorrect
clean-up
Drivers: hv: kvp: Use %u to print U32
Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1
Haiyang Zhang (1):
hv_utils: update name in struct hv_driver util_drv
K. Y. Srinivasan (1):
Drivers: hv: vmbus: Get rid of unnecessary state in hv_context
drivers/hv/hv.c | 10 +++------- drivers/hv/hv_kvp.c | 28 +++++++++++++++++++++++----- drivers/hv/hv_util.c | 2 +- drivers/hv/hyperv_vmbus.h | 2 -- tools/hv/hv_kvp_daemon.c | 2 +- 5 files changed, 28 insertions(+), 16 deletions(-)
Signature · 1 line
2.18.0
PATCH 2/5 hv_utils: update name in struct hv_driver util_drv
In reply to [email protected]From: Haiyang Zhang <[email protected]>
The correct module name is hv_utils. This patch corrects the name in struct hv_driver util_drv.
--- drivers/hv/hv_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_util.c +1 -1
@@ -483,7 +483,7 @@ MODULE_DEVICE_TABLE(vmbus, id_table);/* The one and only one */ static struct hv_driver util_drv = { - .name ="hv_util" , + .name ="hv_utils" , .id_table = id_table, .probe = util_probe, .remove = util_remove,
Signature · 1 line
2.18.0
PATCH 1/5 Drivers: hv: vmbus: Get rid of unnecessary state in hv_context
In reply to [email protected]From: "K. Y. Srinivasan" <[email protected]>
Currently we are replicating state in struct hv_context that is unnecessary - this state can be retrieved from the hypervisor. Furthermore, this is a per-cpu state that is being maintained as a global state in struct hv_context. Get rid of this state in struct hv_context.
Reply-To: [email protected]
--- drivers/hv/hv.c | 10 +++------- drivers/hv/hyperv_vmbus.h | 2 -- 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/hv/hv.c +3 -7
@@ -33,9 +33,7 @@#include "hyperv_vmbus.h" /* The one and only */ -struct hv_context hv_context = { - .synic_initialized = false, -}; +struct hv_context hv_context;/* * If false, we're using the old mechanism for stimer0 interrupts
@@ -326,8 +324,6 @@ int hv_synic_init(unsigned int cpu)hv_set_synic_state (sctrl.as_uint64); - hv_context.synic_initialized = true; -/* * Register the per-cpu clockevent source. */
@@ -373,7 +369,8 @@ int hv_synic_cleanup(unsigned int cpu)bool channel_found = false;unsigned long flags; -if (!hv_context.synic_initialized) +hv_get_synic_state (sctrl.as_uint64); +if (sctrl.enable !=1 )return -EFAULT ;/*
@@ -435,7 +432,6 @@ int hv_synic_cleanup(unsigned int cpu)hv_set_siefp (siefp.as_uint64);/* Disable the global synic bit */ -hv_get_synic_state (sctrl.as_uint64); sctrl.enable =0 ;hv_set_synic_state (sctrl.as_uint64);
drivers/hv/hyperv_vmbus.h +0 -2
@@ -230,8 +230,6 @@ struct hv_context {void *tsc_page; -bool synic_initialized; -struct hv_per_cpu_context __percpu *cpu_context;/*
Signature · 1 line
2.18.0
PATCH 4/5 Drivers: hv: kvp: Use %u to print U32
From: Dexuan Cui <[email protected]>
I didn't find a real issue. Let's just make it consistent with the next "case REG_U64:" where %llu is used.
--- drivers/hv/hv_kvp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_kvp.c +1 -1
@@ -437,7 +437,7 @@ kvp_send_key(struct work_struct *dummy) val32 = in_msg->body.kvp_set.data.value_u32; message->body.kvp_set.data.value_size =sprintf (message->body.kvp_set.data.value, -"%d" , val32) +1 ; +"%u" , val32) +1 ;break ;case REG_U64 :
Signature · 1 line
2.18.0
PATCH 3/5 Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to [email protected]From: Dexuan Cui <[email protected]>
In kvp_send_key(), we do need call process_ib_ipinfo() if message->kvp_hdr.operation is KVP_OP_GET_IP_INFO, because it turns out the userland hv_kvp_daemon needs the info of operation, adapter_id and addr_family. With the incorrect fc62c3b1977d, the host can't get the VM's IP via KVP.
And, fc62c3b1977d added a "break;", but actually forgot to initialize the key_size/value in the case of KVP_OP_SET, so the default key_size of 0 is passed to the kvp daemon, and the pool files /var/lib/hyperv/.kvp_pool_* can't be updated.
This patch effectively rolls back the previous fc62c3b1977d, and correctly fixes the "this statement may fall through" warnings.
This patch is tested on WS 2012 R2 and 2016.
--- drivers/hv/hv_kvp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/hv/hv_kvp.c +22 -4
@@ -353,6 +353,9 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled; + __attribute__ ((fallthrough)); + +case KVP_OP_GET_IP_INFO : utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id, MAX_ADAPTER_ID_SIZE, UTF16_LITTLE_ENDIAN,
@@ -405,7 +408,11 @@ kvp_send_key(struct work_struct *dummy)process_ib_ipinfo (in_msg, message,KVP_OP_SET_IP_INFO );break ;case KVP_OP_GET_IP_INFO : -/* We only need to pass on message->kvp_hdr.operation. */ +/* +* We only need to pass on the info of operation, adapter_id +* and addr_family to the userland kvp daemon. +*/ +process_ib_ipinfo (in_msg, message,KVP_OP_GET_IP_INFO );break ;case KVP_OP_SET :switch (in_msg->body.kvp_set.data.value_type) {
@@ -446,9 +453,9 @@ kvp_send_key(struct work_struct *dummy) } -break ; - -case KVP_OP_GET : +/* +* The key is always a string - utf16 encoding. +*/ message->body.kvp_set.data.key_size = utf16s_to_utf8s( (wchar_t *)in_msg->body.kvp_set.data.key,
@@ -456,6 +463,17 @@ kvp_send_key(struct work_struct *dummy)UTF16_LITTLE_ENDIAN , message->body.kvp_set.data.key, HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1; + +break ; + +case KVP_OP_GET : + message->body.kvp_get.data.key_size = +utf16s_to_utf8s ( + (wchar_t *)in_msg->body.kvp_get.data.key, + in_msg->body.kvp_get.data.key_size, +UTF16_LITTLE_ENDIAN , + message->body.kvp_get.data.key, +HV_KVP_EXCHANGE_MAX_KEY_SIZE -1 ) +1 ;break ;case KVP_OP_DELETE :
Signature · 1 line
2.18.0
PATCH 5/5 Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1
In reply to [email protected]From: Dexuan Cui <[email protected]>
The patch fixes:
hv_kvp_daemon.c: In function 'kvp_set_ip_info':
hv_kvp_daemon.c:1305:2: note: 'snprintf' output between 41 and 4136 bytes into a destination of size 4096
--- tools/hv/hv_kvp_daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/hv/hv_kvp_daemon.c +1 -1
@@ -1176,7 +1176,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)int error =0 ;char if_file[PATH_MAX ];FILE *file; -char cmd[PATH_MAX ]; +char cmd[PATH_MAX *2 ];char *mac_addr;/*
Signature · 1 line
2.18.0
Greg KH
maintainerRe: [PATCH 4/5] Drivers: hv: kvp: Use %u to print U32
In reply to [email protected]Quoted 10 lines · On Wed, Oct 17, 2018 at 03:14:05AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
I didn't find a real issue. Let's just make it consistent with the next "case
REG_U64:" where %llu is used.Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>
Why is this a stable patch?
confused,
greg k-h
Greg KH
maintainerRe: [PATCH 1/5] Drivers: hv: vmbus: Get rid of unnecessary state in hv_context
In reply to [email protected]Quoted 8 lines · On Wed, Oct 17, 2018 at 03:14:02AM +0000, [email protected] wrote:
From: "K. Y. Srinivasan" <[email protected]>
Currently we are replicating state in struct
hv_contextthat is unnecessary - this state can be retrieved from the hypervisor. Furthermore, this is a per-cpu state that is being maintained as a global state in structhv_context. Get rid of this state in structhv_context.Reply-To: [email protected]
Why is this here?
greg k-h
Greg KH
maintainerRe: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to [email protected]Quoted 34 lines · On Wed, Oct 17, 2018 at 03:14:04AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
In
kvp_send_key(), we do need callprocess_ib_ipinfo()ifmessage->kvp_hdr.operationisKVP_OP_GET_IP_INFO, because it turns out the userlandhv_kvp_daemonneeds the info of operation,adapter_idandaddr_family. With the incorrectfc62c3b1977d, the host can't get the VM's IP via KVP.And,
fc62c3b1977dadded a "break;", but actually forgot to initialize the key_size/value in the case ofKVP_OP_SET, so the defaultkey_sizeof 0 is passed to the kvp daemon, and the pool files/var/lib/hyperv/.kvp_pool_*can't be updated.This patch effectively rolls back the previous
fc62c3b1977d, and correctly fixes the "this statement may fall through" warnings.This patch is tested on WS 2012 R2 and 2016.
Fixes fc62c3b1977d ("Drivers: hv: kvp: Fix two "this statement may fall through" warnings")Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/hv_kvp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/hv/hv_kvp.c +0
-0
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) · line 356
Quoted 4 lines
drivers/hv/hv_kvp.c +1
-0@@ -353,6 +353,9 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled; + __attribute__ ((fallthrough));
The comment should be sufficient for this, right? I haven't seen many uses of this attribute before, how common is it?
Quoted 36 lines
drivers/hv/hv_kvp.c +11
-4+ +case KVP_OP_GET_IP_INFO : utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id, MAX_ADAPTER_ID_SIZE, UTF16_LITTLE_ENDIAN,@@ -405,7 +408,11 @@ kvp_send_key(struct work_struct *dummy)process_ib_ipinfo (in_msg, message,KVP_OP_SET_IP_INFO );break ;case KVP_OP_GET_IP_INFO : -/* We only need to pass on message->kvp_hdr.operation. */ +/* +* We only need to pass on the info of operation, adapter_id +* and addr_family to the userland kvp daemon. +*/ +process_ib_ipinfo (in_msg, message,KVP_OP_GET_IP_INFO );break ;case KVP_OP_SET :switch (in_msg->body.kvp_set.data.value_type) {@@ -446,9 +453,9 @@ kvp_send_key(struct work_struct *dummy) } -break ; - -case KVP_OP_GET : +/* +* The key is always a string - utf16 encoding. +*/ message->body.kvp_set.data.key_size = utf16s_to_utf8s( (wchar_t *)in_msg->body.kvp_set.data.key,@@ -456,6 +463,17 @@ kvp_send_key(struct work_struct *dummy)UTF16_LITTLE_ENDIAN , message->body.kvp_set.data.key, HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1; +
drivers/hv/hv_kvp.c kvp_send_key(struct work_struct *dummy) · line 476
Quoted 10 lines
drivers/hv/hv_kvp.c +10
-0+break ; + +case KVP_OP_GET : + message->body.kvp_get.data.key_size = +utf16s_to_utf8s ( + (wchar_t *)in_msg->body.kvp_get.data.key, + in_msg->body.kvp_get.data.key_size, +UTF16_LITTLE_ENDIAN , + message->body.kvp_get.data.key, +HV_KVP_EXCHANGE_MAX_KEY_SIZE -1 ) +1 ;
Worst indentation ever :(
Yeah, I know it follows the others above it, but you should reconsider it in the future...
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH 5/5] Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1
In reply to [email protected]Quoted 23 lines · On Wed, Oct 17, 2018 at 03:14:06AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
The patch fixes:
hv_kvp_daemon.c: In function 'kvp_set_ip_info':
hv_kvp_daemon.c:1305:2: note: 'snprintf' output between 41 and 4136 bytes into a destination of size 4096Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- tools/hv/hv_kvp_daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/hv/hv_kvp_daemon.c +0
-0
tools/hv/hv_kvp_daemon.c static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) · line 1179
Quoted 5 lines
tools/hv/hv_kvp_daemon.c +1
-1@@ -1176,7 +1176,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)int error =0 ;char if_file[PATH_MAX ];FILE *file; -char cmd[PATH_MAX ]; +char cmd[PATH_MAX *2 ];
Overkill?
Re: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to Greg KHQuoted 36 lines · Greg KH
Quoted 35 lines · On Wed, Oct 17, 2018 at 03:14:04AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
In
kvp_send_key(), we do need callprocess_ib_ipinfo()ifmessage->kvp_hdr.operationisKVP_OP_GET_IP_INFO, because it turns out the userlandhv_kvp_daemonneeds the info of operation,adapter_idandaddr_family. With the incorrectfc62c3b1977d, the host can't get the VM's IP via KVP.And,
fc62c3b1977dadded a "break;", but actually forgot to initialize the key_size/value in the case ofKVP_OP_SET, so the defaultkey_sizeof 0 is passed to the kvp daemon, and the pool files/var/lib/hyperv/.kvp_pool_*can't be updated.This patch effectively rolls back the previous
fc62c3b1977d, and correctly fixes the "this statement may fall through" warnings.This patch is tested on WS 2012 R2 and 2016.
Fixes fc62c3b1977d ("Drivers: hv: kvp: Fix two "this statement may fall through" warnings")Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/hv_kvp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/hv/hv_kvp.c +0
-0@@ -353,6 +353,9 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, int op)
Quoted 7 lines
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) · line 356
Quoted 3 lines
drivers/hv/hv_kvp.c +1
-0out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled; + __attribute__ ((fallthrough));The comment should be sufficient for this, right? I haven't seen many uses of this attribute before, how common is it?
It's not common at all.
Dexuan, please use a comment instead: /* fall through */
Thanks
--
Gustavo
Quoted 57 lines
Quoted 37 lines
drivers/hv/hv_kvp.c +11
-4+ +case KVP_OP_GET_IP_INFO : utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id, MAX_ADAPTER_ID_SIZE, UTF16_LITTLE_ENDIAN,@@ -405,7 +408,11 @@ kvp_send_key(struct work_struct *dummy)process_ib_ipinfo (in_msg, message,KVP_OP_SET_IP_INFO );break ;case KVP_OP_GET_IP_INFO : -/* We only need to pass on message->kvp_hdr.operation. */ +/* +* We only need to pass on the info of operation, adapter_id +* and addr_family to the userland kvp daemon. +*/ +process_ib_ipinfo (in_msg, message,KVP_OP_GET_IP_INFO );break ;case KVP_OP_SET :switch (in_msg->body.kvp_set.data.value_type) {@@ -446,9 +453,9 @@ kvp_send_key(struct work_struct *dummy) } -break ; - -case KVP_OP_GET : +/* +* The key is always a string - utf16 encoding. +*/ message->body.kvp_set.data.key_size = utf16s_to_utf8s( (wchar_t *)in_msg->body.kvp_set.data.key,@@ -456,6 +463,17 @@ kvp_send_key(struct work_struct *dummy)UTF16_LITTLE_ENDIAN , message->body.kvp_set.data.key, HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1; +drivers/hv/hv_kvp.c kvp_send_key(struct work_struct *dummy) · line 476
Quoted 10 lines
drivers/hv/hv_kvp.c +10
-0+break ; + +case KVP_OP_GET : + message->body.kvp_get.data.key_size = +utf16s_to_utf8s ( + (wchar_t *)in_msg->body.kvp_get.data.key, + in_msg->body.kvp_get.data.key_size, +UTF16_LITTLE_ENDIAN , + message->body.kvp_get.data.key, +HV_KVP_EXCHANGE_MAX_KEY_SIZE -1 ) +1 ;Worst indentation ever :(
Yeah, I know it follows the others above it, but you should reconsider it in the future...
thanks,
greg k-h
RE: [PATCH 1/5] Drivers: hv: vmbus: Get rid of unnecessary state in hv_context
In reply to Greg KHQuoted 18 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Tuesday, October 16, 2018 10:05 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; Michael Kelley (EOSG) <[email protected]>; vkuznets <[email protected]>
Subject: Re: [PATCH 1/5] Drivers: hv: vmbus: Get rid of unnecessary state inhv_contextQuoted 4 lines · On Wed, Oct 17, 2018 at 03:14:02AM +0000, [email protected] wrote:
From: "K. Y. Srinivasan" <[email protected]>
Currently we are replicating state in struct
hv_contextthat is unnecessary - this state can be retrieved from the hypervisor. Furthermore, this is a per-
Quoted 7 lines
cpu
Quoted 4 lines
state that is being maintained as a global state in struct
hv_context. Get rid of this state in structhv_context.Reply-To: [email protected]
Why is this here?
No sure how this happened; will fix it and resend.
K. Y
Quoted 2 lines
greg k-h
RE: [PATCH 4/5] Drivers: hv: kvp: Use %u to print U32
In reply to Greg KHQuoted 19 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Tuesday, October 16, 2018 10:04 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; Michael Kelley (EOSG) <[email protected]>; vkuznets <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]
Subject: Re: [PATCH 4/5] Drivers: hv: kvp: Use %u to print U32Quoted 5 lines · On Wed, Oct 17, 2018 at 03:14:05AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
I didn't find a real issue. Let's just make it consistent with the next "case
REG_U64:" where %llu is used.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>Why is this a stable patch?
My mistake; I will resend.
K. Y
Quoted 4 lines
confused,
greg k-h
RE: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to Greg KHQuoted 53 lines
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Tuesday, October 16, 2018 10:07 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; Michael Kelley (EOSG) <[email protected]>; vkuznets <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]
Subject: Re: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-upQuoted 4 lines · On Wed, Oct 17, 2018 at 03:14:04AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
In
kvp_send_key(), we do need callprocess_ib_ipinfo()ifmessage->kvp_hdr.operationisKVP_OP_GET_IP_INFO, because it turnsout
Quoted 9 lines
the userland
hv_kvp_daemonneeds the info of operation,adapter_idandaddr_family. With the incorrectfc62c3b1977d, the host can't get the VM's IP via KVP.And,
fc62c3b1977dadded a "break;", but actually forgot to initialize the key_size/value in the case ofKVP_OP_SET, so the defaultkey_sizeof 0 is passed to the kvp daemon, and the pool files/var/lib/hyperv/.kvp_pool_*can't be updated.Quoted 6 lines
This patch effectively rolls back the previous
fc62c3b1977d, and correctly fixes the "this statement may fall through" warnings.This patch is tested on WS 2012 R2 and 2016.
Fixes fc62c3b1977d ("Drivers: hv: kvp: Fix two "this statement may fallthrough" warnings")
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void
Quoted 15 lines
Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/hv_kvp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/hv/hv_kvp.c +0
-0@@ -353,6 +353,9 @@ static void process_ib_ipinfo(void *in_msg, void
*out_msg, int op)Quoted 1 line
Quoted 7 lines
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) · line 356
Quoted 4 lines
out->body.kvp_ip_val.dhcp_enabled= in-
kvp_ip_val.dhcp_enabled;drivers/hv/hv_kvp.c +1
-0+ __attribute__ ((fallthrough));The comment should be sufficient for this, right? I haven't seen many uses of this attribute before, how common is it?
Yes; a common should be sufficient.
Quoted 59 lines
drivers/hv/hv_kvp.c kvp_send_key(struct work_struct *dummy) · line 408
Quoted 12 lines
drivers/hv/hv_kvp.c +2
-1+ +case KVP_OP_GET_IP_INFO : utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id, MAX_ADAPTER_ID_SIZE, UTF16_LITTLE_ENDIAN,@@ -405,7 +408,11 @@ kvp_send_key(struct work_struct *dummy)process_ib_ipinfo (in_msg, message,KVP_OP_SET_IP_INFO );break ;case KVP_OP_GET_IP_INFO : -/* We only need to pass on message->kvp_hdr.operation. */
drivers/hv/hv_kvp.c kvp_send_key(struct work_struct *dummy)
Quoted 5 lines
drivers/hv/hv_kvp.c +5
-0+/* +* We only need to pass on the info of operation, adapter_id +* and addr_family to the userland kvp daemon. +*/ + process_ib_ipinfo(in_msg, message,
KVP_OP_GET_IP_INFO);Quoted 21 lines
drivers/hv/hv_kvp.c +4
-3break ;case KVP_OP_SET :switch (in_msg->body.kvp_set.data.value_type) {@@ -446,9 +453,9 @@ kvp_send_key(struct work_struct *dummy) } -break ; - -case KVP_OP_GET : +/* +* The key is always a string - utf16 encoding. +*/ message->body.kvp_set.data.key_size = utf16s_to_utf8s( (wchar_t *)in_msg->body.kvp_set.data.key,@@ -456,6 +463,17 @@ kvp_send_key(struct work_struct *dummy)UTF16_LITTLE_ENDIAN , message->body.kvp_set.data.key, HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1; +drivers/hv/hv_kvp.c kvp_send_key(struct work_struct *dummy) · line 476
Quoted 10 lines
drivers/hv/hv_kvp.c +10
-0+break ; + +case KVP_OP_GET : + message->body.kvp_get.data.key_size = +utf16s_to_utf8s ( + (wchar_t *)in_msg->body.kvp_get.data.key, + in_msg->body.kvp_get.data.key_size, +UTF16_LITTLE_ENDIAN , + message->body.kvp_get.data.key, +HV_KVP_EXCHANGE_MAX_KEY_SIZE -1 ) +1 ;Worst indentation ever :(
Yeah, I know it follows the others above it, but you should reconsider it in the future...
thanks,
greg k-h
Re: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to Greg KHQuoted 36 lines · Greg KH
Quoted 35 lines · On Wed, Oct 17, 2018 at 03:14:04AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
In
kvp_send_key(), we do need callprocess_ib_ipinfo()ifmessage->kvp_hdr.operationisKVP_OP_GET_IP_INFO, because it turns out the userlandhv_kvp_daemonneeds the info of operation,adapter_idandaddr_family. With the incorrectfc62c3b1977d, the host can't get the VM's IP via KVP.And,
fc62c3b1977dadded a "break;", but actually forgot to initialize the key_size/value in the case ofKVP_OP_SET, so the defaultkey_sizeof 0 is passed to the kvp daemon, and the pool files/var/lib/hyperv/.kvp_pool_*can't be updated.This patch effectively rolls back the previous
fc62c3b1977d, and correctly fixes the "this statement may fall through" warnings.This patch is tested on WS 2012 R2 and 2016.
Fixes fc62c3b1977d ("Drivers: hv: kvp: Fix two "this statement may fall through" warnings")Signed-off-by Dexuan Cui <[email protected]>Cc K. Y. Srinivasan <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Stephen Hemminger <[email protected]>Cc <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/hv_kvp.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/hv/hv_kvp.c +0
-0@@ -353,6 +353,9 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, int op)
Quoted 7 lines
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) · line 356
Quoted 3 lines
drivers/hv/hv_kvp.c +1
-0out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled; + __attribute__ ((fallthrough));The comment should be sufficient for this, right? I haven't seen many uses of this attribute before, how common is it?
It's not common at all. It should be wrapped in a macro and put into compiler.h.
But I hope it does become adopted. It's better than randomly grepping for non-standard comments.
regards,
dan carpenter
Dexuan Cui
maintainerRE: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to KY SrinivasanQuoted 11 lines
From: devel <[email protected]> On Behalf Of KY Srinivasan
Sent: Tuesday, October 16, 2018 23:02Quoted 8 lines
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void
Quoted 3 lines
drivers/hv/hv_kvp.c +0
-0@@ -353,6 +353,9 @@ static void process_ib_ipinfo(void *in_msg, void
*out_msg, int op)Quoted 4 lines
drivers/hv/hv_kvp.c +0
-0out->body.kvp_ip_val.dhcp_enabled = in- kvp_ip_val.dhcp_enabled;
Quoted 6 lines
Quoted 4 lines
drivers/hv/hv_kvp.c static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) · line 356
Quoted 1 line
drivers/hv/hv_kvp.c +1
-0+ __attribute__ ((fallthrough));The comment should be sufficient for this, right? I haven't seen many uses of this attribute before, how common is it?
Yes; a common should be sufficient.
You all are right.
Right now, I realized the gcc warning can also be suppressed by a simple line of comment:
/* fallthrough */
It looks gcc treats this comment specially.
If I add something more in the comment, like
/* add fallthrough */
, the warning can not be suppressed. :-)
I'll do a new version for KY.
Thank you all!
-- Dexuan
Dexuan Cui
maintainerRE: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to Greg KHQuoted 15 lines
From: devel <[email protected]> On Behalf Of Greg KH
Sent: Tuesday, October 16, 2018 22:07drivers/hv/hv_kvp.c kvp_send_key(struct work_struct *dummy) · line 476
Quoted 9 lines
...
drivers/hv/hv_kvp.c +8
-0+case KVP_OP_GET : + message->body.kvp_get.data.key_size = +utf16s_to_utf8s ( + (wchar_t *)in_msg->body.kvp_get.data.key, + in_msg->body.kvp_get.data.key_size, +UTF16_LITTLE_ENDIAN , + message->body.kvp_get.data.key, +HV_KVP_EXCHANGE_MAX_KEY_SIZE -1 ) +1 ;Worst indentation ever :(
Quoted 3 lines
Yeah, I know it follows the others above it, but you should reconsider it in the future...
greg k-h
Agreed. We should consider improving this in future.
-- Dexuan
Dexuan Cui
maintainerRE: [PATCH 5/5] Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1
In reply to Greg KHQuoted 17 lines
From: devel <[email protected]> On Behalf Of Greg KH
Sent: Tuesday, October 16, 2018 22:07tools/hv/hv_kvp_daemon.c static int kvp_set_ip_info(char *if_name, struct
Quoted 11 lines · On Wed, Oct 17, 2018 at 03:14:06AM +0000, [email protected] wrote:
From: Dexuan Cui <[email protected]>
The patch fixes:
hv_kvp_daemon.c: In function 'kvp_set_ip_info':
hv_kvp_daemon.c:1305:2: note: 'snprintf' output between 41 and 4136 bytes into a destination of size 4096
...tools/hv/hv_kvp_daemon.c +0
-0@@ -1176,7 +1176,7 @@ static int kvp_set_ip_info(char *if_name, struct
hv_kvp_ipaddr_value*new_val)
Quoted 7 lines
tools/hv/hv_kvp_daemon.c static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) · line 1179
Quoted 5 lines
tools/hv/hv_kvp_daemon.c +1
-1int error =0 ;char if_file[PATH_MAX ];FILE *file; -char cmd[PATH_MAX ]; +char cmd[PATH_MAX *2 ];Overkill?
Well, I found the -Wformat-truncation warning can be suppressed by checking the return value of snprintf, so I'm going to do a new patch for KY to resend like this:
@@ -1178,6 +1178,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
FILE *file;
char cmd[PATH_MAX];
char *mac_addr;+ int str_len;
/*
* Set the configuration for the specified interface with
@@ -1301,8 +1302,19 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
* invoke the external script to do its magic.
*/
- snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s",
- "hv_set_ifconfig", if_file);
+ str_len = snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s",
+ "hv_set_ifconfig", if_file);
+
+ /*
+ * This is a little overcautious, but it's necessary to suppress some + * false warnings from gcc 8.0.1. + */
+ if (str_len <= 0 || (unsigned int)str_len >= sizeof(cmd)) {
+ syslog(LOG_ERR, "Cmd '%s' (len=%d) may be too long",
+ cmd, str_len);
+ return HV_E_FAIL;
+ }
Thanks,
-- Dexuan
Re: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
In reply to Dan CarpenterQuoted 6 lines · Dan Carpenter
It's not common at all. It should be wrapped in a macro and put into
compiler.h.But I hope it does become adopted. It's better than randomly grepping for non-standard comments.
Using an attribute is indeed better whenever possible. In C++17 it is an standard attribute and there have been proposals to include some of them for C as well since 2016 at least, e.g. the latest for fallthrough at:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2268.pdf
I have taken a quick look into supporting it (typing it here to save it on the mailing list :-), and we have:
* gcc >= 7.1 supports -Wimplicit-fallthrough with
__attribute__((fallthrough)), the comment syntax and the C++ [[fallthrough]] syntax.
* gcc < 7.1 complains about empty declarations (it does not know
about attributes for null statements) and also -Wdeclaration-after-statement.
* clang 7 supports -Wimplicit-fallthrough (not enabled in
-Wall/extra/pedantic like gcc, though) but *only* in C++ mode and with the C++ syntax [[fallthrough]]. In other words, in C mode, no syntax works and no diagnostics are emitted. It complains about Wmissing-declarations. [IMO they should allow the __attribute__ syntax for fallthrough (and enable it on C mode) to be compatible with gcc. Maybe they are simply waiting for the C2x attributes... :-)]
* icc 19 does not know about -Wimplicit-fallthrough at all (but
seems to allow [[fallthrough]] on C++17 mode to comply with the standard).
Therefore, the only improvement we could do right now is starting to use the attribute for gcc > 7.1, and a comment for everybody else. However, even if that was worth the trouble of changing the 2500+ instances of fall through markings that we have, comments are replaced before the preprocessor stage, so we would need some (probably non-portable) macro magic.
So, I would say, let's revisit this again in a few years. Possibly, when we move the minimum version to gcc 7.1, clang and icc may both support the fallthrough warning in C mode; so that we can always use the __attribute__((fallthrough)) unconditionally under a __fallthrough #define.
Cheers,
Miguel
Re: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
Quoted 18 lines · Miguel Ojeda
Quoted 6 lines · Dan Carpenter
It's not common at all. It should be wrapped in a macro and put into
compiler.h.But I hope it does become adopted. It's better than randomly grepping for non-standard comments.
Using an attribute is indeed better whenever possible. In C++17 it is an standard attribute and there have been proposals to include some of them for C as well since 2016 at least, e.g. the latest for fallthrough at:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2268.pdf
I have taken a quick look into supporting it (typing it here to save it on the mailing list :-), and we have:
Quoted 6 lines
* gcc >= 7.1 supports -Wimplicit-fallthrough with
__attribute__((fallthrough)), the comment syntax and the C++ [[fallthrough]] syntax.
* gcc < 7.1 complains about empty declarations (it does not know
about attributes for null statements) and also -Wdeclaration-after-statement.
I'm not sure I understand about empty decalarations. The idea is that we would do:
case 3: frob(); __fall_through(); case 4: frob();
#if GCC > 7.1
#define __fall_through() __attribute__((fallthrough)) #else
#define __fall_through()
#endif
So long as GCC and static analysis tools understand about the attribute that's enought to catch the bugs. No one cares what clang and icc do. We would just disable the fall through warnings on those until they are updated to support the fallthrough attribute.
We wouldn't update all the fall through comments until later, but going forward people could use the __fall_through() macro if they want.
regards,
dan carpenter
Re: [PATCH 3/5] Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up
Hi Dan,
Quoted 19 lines · Dan Carpenter
Quoted 10 lines · Miguel Ojeda
Using an attribute is indeed better whenever possible. In C++17 it is an standard attribute and there have been proposals to include some of them for C as well since 2016 at least, e.g. the latest for fallthrough at:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2268.pdf
I have taken a quick look into supporting it (typing it here to save it on the mailing list :-), and we have:
Quoted 6 lines
* gcc >= 7.1 supports -Wimplicit-fallthrough with
__attribute__((fallthrough)), the comment syntax and the C++ [[fallthrough]] syntax.
* gcc < 7.1 complains about empty declarations (it does not know
about attributes for null statements) and also -Wdeclaration-after-statement.
Quoted 2 lines
I'm not sure I understand about empty decalarations. The idea is that we would do:
That paragraph tried to explain that gcc < 7.1 did not know about __attribute__((fallthrough)); i.e. that everything was introduced in gcc 7.1.
Anyway, the conclusion was a neuron misfiring of mine -- in my mind I was thinking clang supported the comment syntax (when I clearly wrote that it didn't). Never mind --- thanks for pointing it out!
Quoted 7 lines
case 3:
frob();
__fall_through();
case 4:
frob();Quoted 5 lines
#if GCC > 7.1
#define__fall_through()__attribute__((fallthrough)) #else
#define__fall_through()
#endif
Yes, of course, that is what we do for other attributes -- actually in -next we have pending a better way for checking, using __has_attribute:
#if __has_attribute(fallthrough) #define __fallthrough __attribute__((fallthrough)) #else #define __fallthrough #endif
Quoted 3 lines
So long as GCC and static analysis tools understand about the attribute that's enought to catch the bugs. No one cares what clang and icc do.
Not so sure about that -- there are quite some people looking forward to building Linux with clang, even if only to have another compiler to check for warnings and to use the clang/llvm-related tools (and to write new ones).
Quoted 2 lines
We would just disable the fall through warnings on those until they are updated to support the fallthrough attribute.
You mean if they start supporting the warning but not the attribute? I don't think that would be likely (i.e. if clang enables the warning on C mode, they will have to introduce a way to suppress it; which should be the attribute (at least), since they typically like to be compatible with gcc and since they already support it in C++ >= 11), but everything is possible.
Quoted 3 lines
We wouldn't update all the fall through comments until later, but going forward people could use the
__fall_through()macro if they want.
Agreed. I will introduce it in the compiler-attributes tree -- should be there for -rc1 if no one complains. CC'ing all of you in the patch.
Cheers,
Miguel