fixes for hash key setting issues
Subsystems (3)
cover fixes for hash key setting issues
From: Haiyang Zhang <[email protected]>
Using ethtool to change Hash key failed on Linux VM runnig on Hyper-V. This patch set fix them.
It targets Hyper-V tree, hyperv-fixes branch managed by Sasha Levin <[email protected]>.
Haiyang Zhang (3):
Fix ethtool change hash key error Refactor assignments of struct netvsc_device_info Fix hash key value reset after other ops
drivers/net/hyperv/hyperv_net.h | 10 ++- drivers/net/hyperv/netvsc.c | 2 +- drivers/net/hyperv/netvsc_drv.c | 139 +++++++++++++++++++----------- drivers/net/hyperv/rndis_filter.c | 34 ++++++-- 4 files changed, 123 insertions(+), 62 deletions(-)
Signature · 1 line
2.19.1
PATCH 1/3 Fix ethtool change hash key error
From: Haiyang Zhang <[email protected]>
Hyper-V hosts require us to disable RSS before changing RSS key, otherwise the changing request will fail. This patch fixes the coding error.
--- drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/net/hyperv/rndis_filter.c +19 -6
@@ -774,8 +774,8 @@ rndis_filter_set_offload_params(struct net_device *ndev,return ret; } -int rndis_filter_set_rss_param (struct rndis_device *rdev, -const u8 *rss_key) +static int rndis_set_rss_param_msg (struct rndis_device *rdev, +const u8 *rss_key,u16 flag) {struct net_device *ndev = rdev->ndev;struct rndis_request *request;
@@ -804,7 +804,7 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev, rssp->hdr.type =NDIS_OBJECT_TYPE_RSS_PARAMETERS ; rssp->hdr.rev =NDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 ; rssp->hdr.size =sizeof (struct ndis_recv_scale_param ); - rssp->flag =0 ; + rssp->flag = flag; rssp->hashinfo =NDIS_HASH_FUNC_TOEPLITZ |NDIS_HASH_IPV4 |NDIS_HASH_TCP_IPV4 |NDIS_HASH_IPV6 |NDIS_HASH_TCP_IPV6 ;
@@ -829,9 +829,12 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,wait_for_completion (&request->wait_event); set_complete = &request->response_msg.msg.set_complete; -if (set_complete->status ==RNDIS_STATUS_SUCCESS ) -memcpy (rdev->rss_key, rss_key,NETVSC_HASH_KEYLEN ); -else { +if (set_complete->status ==RNDIS_STATUS_SUCCESS ) { +if (!(flag &NDIS_RSS_PARAM_FLAG_DISABLE_RSS ) && + !(flag &NDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED )) +memcpy (rdev->rss_key, rss_key,NETVSC_HASH_KEYLEN ); + + }else {netdev_err (ndev,"Fail to set RSS parameters:0x%x\n" , set_complete->status); ret = -EINVAL ;
@@ -842,6 +845,16 @@ int rndis_filter_set_rss_param(struct rndis_device *rdev,return ret; } +int rndis_filter_set_rss_param (struct rndis_device *rdev, +const u8 *rss_key) +{ +/* Disable RSS before change */ +rndis_set_rss_param_msg (rdev, rss_key, +NDIS_RSS_PARAM_FLAG_DISABLE_RSS ); + +return rndis_set_rss_param_msg (rdev, rss_key,0 ); +} +static int rndis_filter_query_device_link_status (struct rndis_device *dev,struct netvsc_device *net_device) {
Signature · 1 line
2.19.1
RE: [PATCH hyperv-fixes,1/3] Fix ethtool change hash key error
From: Haiyang Zhang <[email protected]> Sent: Monday, January 14, 2019 4:52 PM
Quoted 5 lines
Hyper-V hosts require us to disable RSS before changing RSS key, otherwise the changing request will fail. This patch fixes the coding error.
Quoted 7 lines
Fixes ff4a44199012 ("netvsc: allow get/set of RSS indirection table")Reported-by Wei Hu <[email protected]>Signed-off-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/rndis_filter.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
PATCH 2/3 Refactor assignments of struct netvsc_device_info
In reply to Haiyang ZhangFrom: Haiyang Zhang <[email protected]>
These assignments occur in multiple places. The patch refactor them to a function for simplicity. It also puts the struct to heap area for future expension.
--- drivers/net/hyperv/netvsc_drv.c | 134 ++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 49 deletions(-)
drivers/net/hyperv/netvsc_drv.c +85 -49
@@ -858,6 +858,36 @@ static void netvsc_get_channels(struct net_device *net, } } +/* Alloc struct netvsc_device_info, and initialize it from either existing +* struct netvsc_device, or from default values. +*/ +static struct netvsc_device_info *netvsc_devinfo_get + (struct netvsc_device *nvdev) +{ +struct netvsc_device_info *dev_info; + + dev_info =kzalloc (sizeof (*dev_info),GFP_ATOMIC ); + +if (!dev_info) +return NULL ; + +if (nvdev) { + dev_info->num_chn = nvdev->num_chn; + dev_info->send_sections = nvdev->send_section_cnt; + dev_info->send_section_size = nvdev->send_section_size; + dev_info->recv_sections = nvdev->recv_section_cnt; + dev_info->recv_section_size = nvdev->recv_section_size; + }else { + dev_info->num_chn =VRSS_CHANNEL_DEFAULT ; + dev_info->send_sections =NETVSC_DEFAULT_TX ; + dev_info->send_section_size =NETVSC_SEND_SECTION_SIZE ; + dev_info->recv_sections =NETVSC_DEFAULT_RX ; + dev_info->recv_section_size =NETVSC_RECV_SECTION_SIZE ; + } + +return dev_info; +} +static int netvsc_detach (struct net_device *ndev,struct netvsc_device *nvdev) {
@@ -943,7 +973,7 @@ static int netvsc_set_channels(struct net_device *net,struct net_device_context *net_device_ctx =netdev_priv (net);struct netvsc_device *nvdev =rtnl_dereference (net_device_ctx->nvdev);unsigned int orig, count = channels->combined_count; -struct netvsc_device_info device_info; +struct netvsc_device_info *device_info;int ret;/* We do not support separate count for rx, tx, or other */
@@ -962,24 +992,26 @@ static int netvsc_set_channels(struct net_device *net, orig = nvdev->num_chn; -memset (&device_info,0 ,sizeof (device_info)); - device_info.num_chn = count; - device_info.send_sections = nvdev->send_section_cnt; - device_info.send_section_size = nvdev->send_section_size; - device_info.recv_sections = nvdev->recv_section_cnt; - device_info.recv_section_size = nvdev->recv_section_size; + device_info =netvsc_devinfo_get (nvdev); + +if (!device_info) +return -ENOMEM ; + + device_info->num_chn = count; ret =netvsc_detach (net, nvdev);if (ret) -return ret; + goto out; - ret =netvsc_attach (net, &device_info); + ret =netvsc_attach (net, device_info);if (ret) { - device_info.num_chn = orig; -if (netvsc_attach (net, &device_info)) + device_info->num_chn = orig; +if (netvsc_attach (net, device_info))netdev_err (net,"restoring channel setting failed\n" ); } +out: +kfree (device_info);return ret; }
@@ -1048,48 +1080,45 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)struct net_device *vf_netdev =rtnl_dereference (ndevctx->vf_netdev);struct netvsc_device *nvdev =rtnl_dereference (ndevctx->nvdev);int orig_mtu = ndev->mtu; -struct netvsc_device_info device_info; +struct netvsc_device_info *device_info;int ret =0 ;if (!nvdev || nvdev->destroy)return -ENODEV ; + device_info =netvsc_devinfo_get (nvdev); + +if (!device_info) +return -ENOMEM ; +/* Change MTU of underlying VF netdev first. */ if (vf_netdev) { ret =dev_set_mtu (vf_netdev, mtu);if (ret) -return ret; + goto out; } -memset (&device_info,0 ,sizeof (device_info)); - device_info.num_chn = nvdev->num_chn; - device_info.send_sections = nvdev->send_section_cnt; - device_info.send_section_size = nvdev->send_section_size; - device_info.recv_sections = nvdev->recv_section_cnt; - device_info.recv_section_size = nvdev->recv_section_size; - ret =netvsc_detach (ndev, nvdev);if (ret) goto rollback_vf; ndev->mtu = mtu; - ret =netvsc_attach (ndev, &device_info); -if (ret) - goto rollback; - -return 0 ; + ret =netvsc_attach (ndev, device_info); +if (!ret) + goto out; -rollback:/* Attempt rollback to original MTU */ ndev->mtu = orig_mtu; -if (netvsc_attach (ndev, &device_info)) +if (netvsc_attach (ndev, device_info))netdev_err (ndev,"restoring mtu failed\n" ); rollback_vf:if (vf_netdev)dev_set_mtu (vf_netdev, orig_mtu); +out: +kfree (device_info);return ret; }
@@ -1674,7 +1703,7 @@ static int netvsc_set_ringparam(struct net_device *ndev, {struct net_device_context *ndevctx =netdev_priv (ndev);struct netvsc_device *nvdev =rtnl_dereference (ndevctx->nvdev); -struct netvsc_device_info device_info; +struct netvsc_device_info *device_info;struct ethtool_ringparam orig;u32 new_tx, new_rx;int ret =0 ;
@@ -1694,26 +1723,29 @@ static int netvsc_set_ringparam(struct net_device *ndev, new_rx == orig.rx_pending)return 0 ;/* no change */ -memset (&device_info,0 ,sizeof (device_info)); - device_info.num_chn = nvdev->num_chn; - device_info.send_sections = new_tx; - device_info.send_section_size = nvdev->send_section_size; - device_info.recv_sections = new_rx; - device_info.recv_section_size = nvdev->recv_section_size; + device_info =netvsc_devinfo_get (nvdev); + +if (!device_info) +return -ENOMEM ; + + device_info->send_sections = new_tx; + device_info->recv_sections = new_rx; ret =netvsc_detach (ndev, nvdev);if (ret) -return ret; + goto out; - ret =netvsc_attach (ndev, &device_info); + ret =netvsc_attach (ndev, device_info);if (ret) { - device_info.send_sections = orig.tx_pending; - device_info.recv_sections = orig.rx_pending; + device_info->send_sections = orig.tx_pending; + device_info->recv_sections = orig.rx_pending; -if (netvsc_attach (ndev, &device_info)) +if (netvsc_attach (ndev, device_info))netdev_err (ndev,"restoring ringparam failed" ); } +out: +kfree (device_info);return ret; }
@@ -2167,7 +2199,7 @@ static int netvsc_probe(struct hv_device *dev, {struct net_device *net =NULL ;struct net_device_context *net_device_ctx; -struct netvsc_device_info device_info; +struct netvsc_device_info *device_info =NULL ;struct netvsc_device *nvdev;int ret = -ENOMEM ;
@@ -2214,21 +2246,21 @@ static int netvsc_probe(struct hv_device *dev,netif_set_real_num_rx_queues (net,1 );/* Notify the netvsc driver of the new device */ -memset (&device_info,0 ,sizeof (device_info)); - device_info.num_chn =VRSS_CHANNEL_DEFAULT ; - device_info.send_sections =NETVSC_DEFAULT_TX ; - device_info.send_section_size =NETVSC_SEND_SECTION_SIZE ; - device_info.recv_sections =NETVSC_DEFAULT_RX ; - device_info.recv_section_size =NETVSC_RECV_SECTION_SIZE ; - - nvdev =rndis_filter_device_add (dev, &device_info); + device_info =netvsc_devinfo_get (NULL ); + +if (!device_info) { + ret = -ENOMEM ; + goto devinfo_failed; + } + + nvdev =rndis_filter_device_add (dev, device_info);if (IS_ERR (nvdev)) { ret =PTR_ERR (nvdev);netdev_err (net,"unable to add netvsc device (ret %d)\n" , ret); goto rndis_failed; } -memcpy (net->dev_addr, device_info.mac_adr,ETH_ALEN ); +memcpy (net->dev_addr, device_info->mac_adr,ETH_ALEN );/* We must get rtnl lock before scheduling nvdev->subchan_work, * otherwise netvsc_subchan_work() can get rtnl lock first and wait
@@ -2266,12 +2298,16 @@ static int netvsc_probe(struct hv_device *dev,list_add (&net_device_ctx->list, &netvsc_dev_list);rtnl_unlock (); + +kfree (device_info);return 0 ; register_failed:rtnl_unlock ();rndis_filter_device_remove (dev, nvdev); rndis_failed: +kfree (device_info); +devinfo_failed:free_percpu (net_device_ctx->vf_stats); no_stats:hv_set_drvdata (dev,NULL );
Signature · 1 line
2.19.1
RE: [PATCH hyperv-fixes,2/3] Refactor assignments of struct netvsc_device_info
From: Haiyang Zhang <[email protected]> Sent: Monday, January 14, 2019 4:52 PM
Quoted 10 lines
These assignments occur in multiple places. The patch refactor them to a function for simplicity. It also puts the struct to heap area for future expension.
Signed-off-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/netvsc_drv.c | 134 ++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 49 deletions(-)
PATCH 3/3 Fix hash key value reset after other ops
In reply to Haiyang ZhangFrom: Haiyang Zhang <[email protected]>
Changing mtu, channels, or buffer sizes ops call to netvsc_attach(), rndis_set_subchannel(), which always reset the hash key to default value. That will override hash key changed previously. This patch fixes the problem by save the hash key, then restore it when we re- add the netvsc device.
--- drivers/net/hyperv/hyperv_net.h | 10 +++++++--- drivers/net/hyperv/netvsc.c | 2 +- drivers/net/hyperv/netvsc_drv.c | 5 ++++- drivers/net/hyperv/rndis_filter.c | 9 +++++++-- 4 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/hyperv/hyperv_net.h +7 -3
@@ -144,6 +144,8 @@ struct hv_netvsc_packet {u32 total_data_buflen; }; +#define NETVSC_HASH_KEYLEN 40 +struct netvsc_device_info {unsigned char mac_adr[ETH_ALEN ];u32 num_chn;
@@ -151,6 +153,8 @@ struct netvsc_device_info {u32 recv_sections;u32 send_section_size;u32 recv_section_size; + +u8 rss_key[NETVSC_HASH_KEYLEN ]; };enum rndis_device_state {
@@ -160,8 +164,6 @@ enum rndis_device_state { RNDIS_DEV_DATAINITIALIZED, }; -#define NETVSC_HASH_KEYLEN 40 -struct rndis_device {struct net_device *ndev;
@@ -209,7 +211,9 @@ int netvsc_recv_callback(struct net_device *net,void netvsc_channel_cb (void *context);int netvsc_poll (struct napi_struct *napi,int budget); -int rndis_set_subchannel (struct net_device *ndev,struct netvsc_device *nvdev); +int rndis_set_subchannel (struct net_device *ndev, +struct netvsc_device *nvdev, +struct netvsc_device_info *dev_info);int rndis_filter_open (struct netvsc_device *nvdev);int rndis_filter_close (struct netvsc_device *nvdev); struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
drivers/net/hyperv/netvsc.c +1 -1
@@ -84,7 +84,7 @@ static void netvsc_subchan_work(struct work_struct *w) rdev = nvdev->extension;if (rdev) { - ret =rndis_set_subchannel (rdev->ndev, nvdev); + ret =rndis_set_subchannel (rdev->ndev, nvdev,NULL );if (ret ==0 ) {netif_device_attach (rdev->ndev); }else {
drivers/net/hyperv/netvsc_drv.c +4 -1
@@ -877,6 +877,9 @@ static struct netvsc_device_info *netvsc_devinfo_get dev_info->send_section_size = nvdev->send_section_size; dev_info->recv_sections = nvdev->recv_section_cnt; dev_info->recv_section_size = nvdev->recv_section_size; + +memcpy (dev_info->rss_key, nvdev->extension->rss_key, +NETVSC_HASH_KEYLEN ); }else { dev_info->num_chn =VRSS_CHANNEL_DEFAULT ; dev_info->send_sections =NETVSC_DEFAULT_TX ;
@@ -939,7 +942,7 @@ static int netvsc_attach(struct net_device *ndev,return PTR_ERR (nvdev);if (nvdev->num_chn >1 ) { - ret =rndis_set_subchannel (ndev, nvdev); + ret =rndis_set_subchannel (ndev, nvdev, dev_info);/* if unavailable, just proceed with one queue */ if (ret) {
drivers/net/hyperv/rndis_filter.c +7 -2
@@ -1134,7 +1134,9 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)* This breaks overlap of processing the host message for the * new primary channel with the initialization of sub-channels. */ -int rndis_set_subchannel (struct net_device *ndev,struct netvsc_device *nvdev) +int rndis_set_subchannel (struct net_device *ndev, +struct netvsc_device *nvdev, +struct netvsc_device_info *dev_info) {struct nvsp_message *init_packet = &nvdev->channel_init_pkt;struct net_device_context *ndev_ctx =netdev_priv (ndev);
@@ -1175,7 +1177,10 @@ int rndis_set_subchannel(struct net_device *ndev, struct netvsc_device *nvdev) atomic_read(&nvdev->open_chn) == nvdev->num_chn);/* ignore failues from setting rss parameters, still have channels */ -rndis_filter_set_rss_param (rdev, netvsc_hash_key); +if (dev_info) +rndis_filter_set_rss_param (rdev, dev_info->rss_key); +else +rndis_filter_set_rss_param (rdev, netvsc_hash_key);netif_set_real_num_tx_queues (ndev, nvdev->num_chn);netif_set_real_num_rx_queues (ndev, nvdev->num_chn);
Signature · 1 line
2.19.1
RE: [PATCH hyperv-fixes,3/3] Fix hash key value reset after other ops
From: Haiyang Zhang <[email protected]> Sent: Monday, January 14, 2019 4:52 PM
Quoted 7 lines
Changing mtu, channels, or buffer sizes ops call to
netvsc_attach(),rndis_set_subchannel(), which always reset the hash key to default value. That will override hash key changed previously. This patch fixes the problem by save the hash key, then restore it when we re- add the netvsc device.
Quoted 9 lines
Fixes ff4a44199012 ("netvsc: allow get/set of RSS indirection table")Signed-off-by Haiyang Zhang <[email protected]>--- drivers/net/hyperv/hyperv_net.h | 10 +++++++--- drivers/net/hyperv/netvsc.c | 2 +- drivers/net/hyperv/netvsc_drv.c | 5 ++++- drivers/net/hyperv/rndis_filter.c | 9 +++++++-- 4 files changed, 19 insertions(+), 7 deletions(-)
Sasha Levin
AppliedQuoted 6 lines · Haiyang Zhang
From: Haiyang Zhang <[email protected]>
Using ethtool to change Hash key failed on Linux VM runnig on Hyper-V. This patch set fix them.
It targets Hyper-V tree, hyperv-fixes branch managed by Sasha Levin <[email protected]>.
Queued all 3 for hyperv-fixes, thank you.