Subject: Re: [PATCH] hv_netvsc: Allocate rx indirection table size dynamically

From: Simon Horman <[email-masked]>
Date: Wed, 24 May 2023 09:03:59 +0200

On Tue, May 23, 2023 at 10:57:24PM -0700, Shradha Gupta wrote:
> Allocate the size of rx indirection table dynamically in netvsc
> from the value of size provided by OID_GEN_RECEIVE_SCALE_CAPABILITIES
> query instead of using a constant value of ITAB_NUM.
> 
> Signed-off-by: Shradha Gupta <[email-masked]>

Hi Shradha,

thanks for your patch.

> @@ -1548,6 +1548,21 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
>  	if (ret || rsscap.num_recv_que < 2)
>  		goto out;
>  
> +	if (rsscap.num_indirect_tabent &&
> +		rsscap.num_indirect_tabent <= ITAB_NUM_MAX) {

nit: the line above is not indented correctly,
     it should line up with the inside of the opening parentheses
     on the preceding line.

     Also, I don't think the curly-brackets are needed.

	if (rsscap.num_indirect_tabent &&
	    rsscap.num_indirect_tabent <= ITAB_NUM_MAX) {

> +		ndc->rx_table_sz = rsscap.num_indirect_tabent;
> +	} else {
> +		ndc->rx_table_sz = ITAB_NUM;
> +	}
> +
> +	ndc->rx_table = kzalloc(sizeof(u16) * ndc->rx_table_sz,
> +				GFP_KERNEL);
> +	if (ndc->rx_table) {

More importantly, it looks like the condition is inverted here.
Which seems unlikely to lead to anything good happening.

	if (!ndc->rx_table) {

> +		netdev_err(net, "Error in allocating rx indirection table of size %d\n",
> +				ndc->rx_table_sz);
> +		goto out;
> +	}
> +
>  	/* This guarantees that num_possible_rss_qs <= num_online_cpus */
>  	num_possible_rss_qs = min_t(u32, num_online_cpus(),
>  				    rsscap.num_recv_que);
> @@ -1558,7 +1573,7 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
>  	net_device->num_chn = min(net_device->max_chn, device_info->num_chn);
>  
>  	if (!netif_is_rxfh_configured(net)) {
> -		for (i = 0; i < ITAB_NUM; i++)
> +		for (i = 0; i < ndc->rx_table_sz; i++)
>  			ndc->rx_table[i] = ethtool_rxfh_indir_default(
>  						i, net_device->num_chn);
>  	}

-- 
pw-bot: cr