Linux virtualization list
 help / color / mirror / Atom feed
From: Shahar Shitrit <shshitrit@nvidia.com>
To: netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com,
	pabeni@redhat.com, virtualization@lists.linux.dev,
	parav@nvidia.com, yohadt@nvidia.com, xuanzhuo@linux.alibaba.com,
	eperezma@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com,
	kuba@kernel.org, andrew+netdev@lunn.ch, edumazet@google.com,
	danielj@nvidia.com
Subject: Re: [net-next,v23,14/14] virtio_net: Add get ethtool flow rules ops
Date: Tue, 1 Dec 2026 16:58:23 +0200	[thread overview]
Message-ID: <ada20ae6-2613-49db-a7bc-3c76bc85009d@nvidia.com> (raw)
In-Reply-To: <178835475172.3394541.12012371134538467117@kernel.org>



On 02/09/2026 16:12, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider:
> 
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
> 
> - [Medium] The two new getters report the UAPI-documented "size of the
>   rule table" (struct ethtool_rxnfc::data) with two contradictory values.
> 
> --
> 
> virtio_net: Add get ethtool flow rules ops
> 
> This adds a get_rxnfc ethtool op to virtio_net handling
> ETHTOOL_GRXCLSRLCNT, ETHTOOL_GRXCLSRULE and ETHTOOL_GRXCLSRLALL, so
> userspace can query the rule count, a single rule, and the list of rule
> locations.
> 
>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
>> index a1e042f356f5e..911a5142605bd 100644
>> --- a/drivers/net/virtio_net.c
>> +++ b/drivers/net/virtio_net.c
>> @@ -6575,6 +6575,60 @@ static int virtnet_ethtool_flow_remove(struct virtnet_ff *ff, int location)
>>  	return err;
>>  }
>>  
>> +static int virtnet_ethtool_get_flow_count(struct virtnet_ff *ff,
>> +					  struct ethtool_rxnfc *info)
>> +{
>> +	if (!ff->ff_supported)
>> +		return -EOPNOTSUPP;
>> +
>> +	info->rule_cnt = ff->ethtool.num_rules;
>> +	info->data = min(le32_to_cpu(ff->ff_caps->rules_limit),
>> +			 le32_to_cpu(ff->ff_caps->rules_per_group_limit)) |
>> +		     RX_CLS_LOC_SPECIAL;
>> +
>> +	return 0;
>> +}
>> +
> 
> [ ... ]
> 
>> +static int
>> +virtnet_ethtool_get_all_flows(struct virtnet_ff *ff,
>> +			      struct ethtool_rxnfc *info, u32 *rule_locs)
>> +{
>> +	struct virtnet_ethtool_rule *eth_rule;
>> +	unsigned long i = 0;
>> +	int idx = 0;
>> +
>> +	if (!ff->ff_supported)
>> +		return -EOPNOTSUPP;
>> +
>> +	xa_for_each(&ff->ethtool.rules, i, eth_rule) {
>> +		if (idx == info->rule_cnt)
>> +			return -EMSGSIZE;
>> +		rule_locs[idx++] = i;
>> +	}
>> +
>> +	info->data = le32_to_cpu(ff->ff_caps->rules_limit);
> 
> [Severity: Medium]
> Should these two handlers report the same value in info->data?
> 
> include/uapi/linux/ethtool.h documents the field the same way for both
> commands:
> 
>  * For %ETHTOOL_GRXCLSRLCNT, ... If @data is non-zero on return then it is the
>  * size of the rule table, plus the flag %RX_CLS_LOC_SPECIAL ...
>  * For %ETHTOOL_GRXCLSRLALL, ... On return, @data is the size of the rule table
> 
> virtnet_ethtool_get_flow_count() reports:
> 
> 	info->data = min(le32_to_cpu(ff->ff_caps->rules_limit),
> 			 le32_to_cpu(ff->ff_caps->rules_per_group_limit)) |
> 		     RX_CLS_LOC_SPECIAL;
> 
> while virtnet_ethtool_get_all_flows() reports the unclamped
> ff_caps->rules_limit.  On a device that advertises
> rules_per_group_limit < rules_limit these two answers differ for the same
> table.
> 
> Since every ethtool rule goes into one group (VIRTNET_FF_MAX_GROUPS is 1
> and insert_rule() hardcodes the group), isn't the usable capacity
> min(rules_limit, rules_per_group_limit)?
> 
> 	ff_rule->group_id = cpu_to_le32(VIRTNET_FF_ETHTOOL_GROUP_PRIORITY);
> 
> If so, does ETHTOOL_GRXCLSRLALL overstate the table size here, so that
> inserts past rules_per_group_limit get refused by the device?
> 
> There is a related question about the location space itself.
> virtnet_ethtool_flow_insert() allocates locations from the unclamped
> limit:
> 
> 	err = xa_alloc(&ff->ethtool.rules, &fs->location, eth_rule,
> 		       XA_LIMIT(0, le32_to_cpu(ff->ff_caps->rules_limit) - 1),
> 		       GFP_KERNEL);
> 
> so locations handed back in fs.location, and then reported in
> rule_locs[] by virtnet_ethtool_get_all_flows(), can exceed the table size
> now advertised by ETHTOOL_GRXCLSRLCNT.  Should all three sites use the
> same limit?
> 
>> +	info->rule_cnt = idx;
>> +
>> +	return 0;
>> +}
>> +

Will fix by adding virtnet_ff_rules_limit(), which returns
min(rules_limit, rules_per_group_limit), and used it in xa_alloc(),
GRXCLSRLCNT and GRXCLSRLALL, so all three agree.
> 
> [ ... ]
> 


  reply	other threads:[~2026-12-01 14:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 16:10 [PATCH net-next v23 00/14] virtio_net: Add ethtool flow rules support Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 01/14] virtio_pci: Remove supported_caps cache and build assert Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 02/14] virtio_pci: Fix sleeping under spinlock in admin command path Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,02/14] " netdev-bot+sashiko
2026-09-03  9:25     ` Paolo Abeni
2026-12-01 14:27     ` Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 03/14] virtio: Add config_op for admin commands Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,03/14] " netdev-bot+sashiko
2026-12-01 14:35     ` Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 04/14] virtio: Expose generic device capability operations Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,04/14] " netdev-bot+sashiko
2026-08-31 16:11 ` [PATCH net-next v23 05/14] virtio: Expose object create and destroy API Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,05/14] " netdev-bot+sashiko
2026-08-31 16:11 ` [PATCH net-next v23 06/14] virtio_net: Query and set flow filter caps Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,06/14] " netdev-bot+sashiko
2026-12-01 14:39     ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 07/14] virtio_net: Create a FF group for ethtool steering Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,07/14] " netdev-bot+sashiko
2026-12-01 14:40     ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 08/14] ethtool: Introduce ethtool_flow_type_mask() Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 09/14] virtio_net: Implement layer 2 ethtool flow rules Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,09/14] " netdev-bot+sashiko
2026-12-01 14:51     ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 10/14] virtio_net: Use existing classifier if possible Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,10/14] " netdev-bot+sashiko
2026-12-01 14:56     ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 11/14] virtio_net: Implement IPv4 ethtool flow rules Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,11/14] " netdev-bot+sashiko
2026-12-01 14:57     ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 12/14] virtio_net: Add support for IPv6 ethtool steering Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,12/14] " netdev-bot+sashiko
2026-12-01 14:57     ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 13/14] virtio_net: Add support for TCP and UDP ethtool rules Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 14/14] virtio_net: Add get ethtool flow rules ops Shahar Shitrit
2026-09-02 13:12   ` [net-next,v23,14/14] " netdev-bot+sashiko
2026-12-01 14:58     ` Shahar Shitrit [this message]
2026-08-31 16:37 ` [PATCH net-next v23 00/14] virtio_net: Add ethtool flow rules support Michael S. Tsirkin
2026-08-31 19:45 ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ada20ae6-2613-49db-a7bc-3c76bc85009d@nvidia.com \
    --to=shshitrit@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=danielj@nvidia.com \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=yohadt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox