linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
@ 2019-12-11 22:26 Haiyang Zhang
  2019-12-14 19:30 ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Haiyang Zhang @ 2019-12-11 22:26 UTC (permalink / raw)
  To: sashal, linux-hyperv, netdev
  Cc: haiyangz, kys, sthemmin, olaf, vkuznets, davem, linux-kernel

Host can provide send indirection table messages anytime after RSS is
enabled by calling rndis_filter_set_rss_param(). So the host provided
table values may be overwritten by the initialization in
rndis_set_subchannel().

To prevent this problem, move the tx_table initialization before calling
rndis_filter_set_rss_param().

Fixes: a6fb6aa3cfa9 ("hv_netvsc: Set tx_table to equal weight after subchannels open")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>

---
 drivers/net/hyperv/rndis_filter.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 206b4e7..05bc5ec8 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1171,6 +1171,9 @@ int rndis_set_subchannel(struct net_device *ndev,
 	wait_event(nvdev->subchan_open,
 		   atomic_read(&nvdev->open_chn) == nvdev->num_chn);
 
+	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
+		ndev_ctx->tx_table[i] = i % nvdev->num_chn;
+
 	/* ignore failures from setting rss parameters, still have channels */
 	if (dev_info)
 		rndis_filter_set_rss_param(rdev, dev_info->rss_key);
@@ -1180,9 +1183,6 @@ int rndis_set_subchannel(struct net_device *ndev,
 	netif_set_real_num_tx_queues(ndev, nvdev->num_chn);
 	netif_set_real_num_rx_queues(ndev, nvdev->num_chn);
 
-	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
-		ndev_ctx->tx_table[i] = i % nvdev->num_chn;
-
 	return 0;
 }
 
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
  2019-12-11 22:26 [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel() Haiyang Zhang
@ 2019-12-14 19:30 ` Jakub Kicinski
  2019-12-15 16:38   ` Haiyang Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2019-12-14 19:30 UTC (permalink / raw)
  To: Haiyang Zhang
  Cc: sashal, linux-hyperv, netdev, kys, sthemmin, olaf, vkuznets,
	davem, linux-kernel

On Wed, 11 Dec 2019 14:26:27 -0800, Haiyang Zhang wrote:
> Host can provide send indirection table messages anytime after RSS is
> enabled by calling rndis_filter_set_rss_param(). So the host provided
> table values may be overwritten by the initialization in
> rndis_set_subchannel().
> 
> To prevent this problem, move the tx_table initialization before calling
> rndis_filter_set_rss_param().
> 
> Fixes: a6fb6aa3cfa9 ("hv_netvsc: Set tx_table to equal weight after subchannels open")
> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>

Applied, but there are two more problems with this code:
 - you should not reset the indirection table if it was configured by
   the user to something other than the default (use the
   netif_is_rxfh_configured() helper to check for that)
 - you should use the ethtool_rxfh_indir_default() wrapper

Please fix the former problem in the net tree, and after net is merged
into linux/master and net-next in a week or two please follow up with
the fix for the latter for net-next.

> diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
> index 206b4e7..05bc5ec8 100644
> --- a/drivers/net/hyperv/rndis_filter.c
> +++ b/drivers/net/hyperv/rndis_filter.c
> @@ -1171,6 +1171,9 @@ int rndis_set_subchannel(struct net_device *ndev,
>  	wait_event(nvdev->subchan_open,
>  		   atomic_read(&nvdev->open_chn) == nvdev->num_chn);
>  
> +	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
> +		ndev_ctx->tx_table[i] = i % nvdev->num_chn;
> +
>  	/* ignore failures from setting rss parameters, still have channels */
>  	if (dev_info)
>  		rndis_filter_set_rss_param(rdev, dev_info->rss_key);
> @@ -1180,9 +1183,6 @@ int rndis_set_subchannel(struct net_device *ndev,
>  	netif_set_real_num_tx_queues(ndev, nvdev->num_chn);
>  	netif_set_real_num_rx_queues(ndev, nvdev->num_chn);
>  
> -	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
> -		ndev_ctx->tx_table[i] = i % nvdev->num_chn;
> -
>  	return 0;
>  }
>  


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
  2019-12-14 19:30 ` Jakub Kicinski
@ 2019-12-15 16:38   ` Haiyang Zhang
  2019-12-15 17:11     ` Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: Haiyang Zhang @ 2019-12-15 16:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: sashal, linux-hyperv, netdev, KY Srinivasan, Stephen Hemminger,
	olaf, vkuznets, davem, linux-kernel



> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Saturday, December 14, 2019 2:30 PM
> To: Haiyang Zhang <haiyangz@microsoft.com>
> Cc: sashal@kernel.org; linux-hyperv@vger.kernel.org; netdev@vger.kernel.org;
> KY Srinivasan <kys@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; olaf@aepfle.de; vkuznets
> <vkuznets@redhat.com>; davem@davemloft.net; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
> 
> On Wed, 11 Dec 2019 14:26:27 -0800, Haiyang Zhang wrote:
> > Host can provide send indirection table messages anytime after RSS is
> > enabled by calling rndis_filter_set_rss_param(). So the host provided
> > table values may be overwritten by the initialization in
> > rndis_set_subchannel().
> >
> > To prevent this problem, move the tx_table initialization before calling
> > rndis_filter_set_rss_param().
> >
> > Fixes: a6fb6aa3cfa9 ("hv_netvsc: Set tx_table to equal weight after
> subchannels open")
> > Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
> 
> Applied, but there are two more problems with this code:
>  - you should not reset the indirection table if it was configured by
>    the user to something other than the default (use the
>    netif_is_rxfh_configured() helper to check for that)

For Send indirection table (tx_table) ethtool doesn't have the option 
to set it, and it's usually provided by the host. So we always initialize 
it...
But, yes, for Receive indirection table (rx_table), I will make a fix, so 
it will be set to default only for new devices, or changing the number 
of channels; otherwise it will remain the same during operations like 
changing MTU, ringparam.


>  - you should use the ethtool_rxfh_indir_default() wrapper
For rx_table, we already use it:
                rndis_device->rx_table[i] = ethtool_rxfh_indir_default(
For tx_table, I know it's the same operation (%, mod), but this wrapper 
function's name is for rx_table. Should we use it for tx_table too?

> 
> Please fix the former problem in the net tree, and after net is merged
> into linux/master and net-next in a week or two please follow up with
> the fix for the latter for net-next.

Sure.

Thanks,
- Haiyang


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
  2019-12-15 16:38   ` Haiyang Zhang
@ 2019-12-15 17:11     ` Stephen Hemminger
  2019-12-15 18:52       ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2019-12-15 17:11 UTC (permalink / raw)
  To: Haiyang Zhang
  Cc: Jakub Kicinski, sashal, linux-hyperv, netdev, KY Srinivasan,
	Stephen Hemminger, olaf, vkuznets, davem, linux-kernel

On Sun, 15 Dec 2019 16:38:00 +0000
Haiyang Zhang <haiyangz@microsoft.com> wrote:

> > -----Original Message-----
> > From: Jakub Kicinski <jakub.kicinski@netronome.com>
> > Sent: Saturday, December 14, 2019 2:30 PM
> > To: Haiyang Zhang <haiyangz@microsoft.com>
> > Cc: sashal@kernel.org; linux-hyperv@vger.kernel.org; netdev@vger.kernel.org;
> > KY Srinivasan <kys@microsoft.com>; Stephen Hemminger
> > <sthemmin@microsoft.com>; olaf@aepfle.de; vkuznets
> > <vkuznets@redhat.com>; davem@davemloft.net; linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
> > 
> > On Wed, 11 Dec 2019 14:26:27 -0800, Haiyang Zhang wrote:  
> > > Host can provide send indirection table messages anytime after RSS is
> > > enabled by calling rndis_filter_set_rss_param(). So the host provided
> > > table values may be overwritten by the initialization in
> > > rndis_set_subchannel().
> > >
> > > To prevent this problem, move the tx_table initialization before calling
> > > rndis_filter_set_rss_param().
> > >
> > > Fixes: a6fb6aa3cfa9 ("hv_netvsc: Set tx_table to equal weight after  
> > subchannels open")  
> > > Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>  
> > 
> > Applied, but there are two more problems with this code:
> >  - you should not reset the indirection table if it was configured by
> >    the user to something other than the default (use the
> >    netif_is_rxfh_configured() helper to check for that)  
> 
> For Send indirection table (tx_table) ethtool doesn't have the option 
> to set it, and it's usually provided by the host. So we always initialize 
> it...
> But, yes, for Receive indirection table (rx_table), I will make a fix, so 
> it will be set to default only for new devices, or changing the number 
> of channels; otherwise it will remain the same during operations like 
> changing MTU, ringparam.
> 
> 
> >  - you should use the ethtool_rxfh_indir_default() wrapper  
> For rx_table, we already use it:
>                 rndis_device->rx_table[i] = ethtool_rxfh_indir_default(
> For tx_table, I know it's the same operation (%, mod), but this wrapper 
> function's name is for rx_table. Should we use it for tx_table too?
> 
> > 
> > Please fix the former problem in the net tree, and after net is merged
> > into linux/master and net-next in a week or two please follow up with
> > the fix for the latter for net-next.  
> 
> Sure.
> 
> Thanks,
> - Haiyang
> 
As Haiyang said, this send indirection table is unique to Hyper-V it is not part of
any of the other device models. It is not supported by ethtool. It would not be
appropriate to repurpose the existing indirection tool; the device already uses
the receive indirection table for RSS.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel()
  2019-12-15 17:11     ` Stephen Hemminger
@ 2019-12-15 18:52       ` Jakub Kicinski
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2019-12-15 18:52 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Haiyang Zhang, sashal, linux-hyperv, netdev, KY Srinivasan,
	Stephen Hemminger, olaf, vkuznets, davem, linux-kernel

On Sun, 15 Dec 2019 09:11:20 -0800, Stephen Hemminger wrote:
> > > On Wed, 11 Dec 2019 14:26:27 -0800, Haiyang Zhang wrote:    
> > > > Host can provide send indirection table messages anytime after RSS is
> > > > enabled by calling rndis_filter_set_rss_param(). So the host provided
> > > > table values may be overwritten by the initialization in
> > > > rndis_set_subchannel().
> > > >
> > > > To prevent this problem, move the tx_table initialization before calling
> > > > rndis_filter_set_rss_param().
> > > >
> > > > Fixes: a6fb6aa3cfa9 ("hv_netvsc: Set tx_table to equal weight after    
> > > subchannels open")    
> > > > Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>    
> > > 
> > > Applied, but there are two more problems with this code:
> > >  - you should not reset the indirection table if it was configured by
> > >    the user to something other than the default (use the
> > >    netif_is_rxfh_configured() helper to check for that)    
> > 
> > For Send indirection table (tx_table) ethtool doesn't have the option 
> > to set it, and it's usually provided by the host. So we always initialize 
> > it...
> > But, yes, for Receive indirection table (rx_table), I will make a fix, so 
> > it will be set to default only for new devices, or changing the number 
> > of channels; otherwise it will remain the same during operations like 
> > changing MTU, ringparam.

Thank you!

> > >  - you should use the ethtool_rxfh_indir_default() wrapper    
> > For rx_table, we already use it:
> >                 rndis_device->rx_table[i] = ethtool_rxfh_indir_default(
> > For tx_table, I know it's the same operation (%, mod), but this wrapper 
> > function's name is for rx_table. Should we use it for tx_table too?
> >   
> > > 
> > > Please fix the former problem in the net tree, and after net is merged
> > > into linux/master and net-next in a week or two please follow up with
> > > the fix for the latter for net-next.    
> > 
> > Sure.
> > 
> > Thanks,
> > - Haiyang
> >   
> As Haiyang said, this send indirection table is unique to Hyper-V it is not part of
> any of the other device models. It is not supported by ethtool. It would not be
> appropriate to repurpose the existing indirection tool; the device already uses
> the receive indirection table for RSS.

I see, I got confused by the use of the term RSS.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-15 18:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 22:26 [PATCH v2,net] hv_netvsc: Fix tx_table init in rndis_set_subchannel() Haiyang Zhang
2019-12-14 19:30 ` Jakub Kicinski
2019-12-15 16:38   ` Haiyang Zhang
2019-12-15 17:11     ` Stephen Hemminger
2019-12-15 18:52       ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).