All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 11/11] virtio_net: Add get ethtool flow rules ops
  2025-08-27 18:38 [PATCH net-next 00/11] virtio_net: Add ethtool flow rules support Daniel Jurgens
@ 2025-08-27 18:38 ` Daniel Jurgens
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jurgens @ 2025-08-27 18:38 UTC (permalink / raw)
  To: netdev, mst, jasowang, alex.williamson, virtualization, pabeni
  Cc: parav, shshitrit, yohadt, Daniel Jurgens

- Get total number of rules. There's no user interface for this. It is
  used to allocate an appropriately sized buffer for getting all the
  rules.

- Get specific rule
$ ethtool -u ens9 rule 0
	Filter: 0
		Rule Type: UDP over IPv4
		Src IP addr: 0.0.0.0 mask: 255.255.255.255
		Dest IP addr: 192.168.5.2 mask: 0.0.0.0
		TOS: 0x0 mask: 0xff
		Src port: 0 mask: 0xffff
		Dest port: 4321 mask: 0x0
		Action: Direct to queue 16

- Get all rules:
$ ethtool -u ens9
31 RX rings available
Total 2 rules

Filter: 0
        Rule Type: UDP over IPv4
        Src IP addr: 0.0.0.0 mask: 255.255.255.255
        Dest IP addr: 192.168.5.2 mask: 0.0.0.0
...

Filter: 1
        Flow Type: Raw Ethernet
        Src MAC addr: 00:00:00:00:00:00 mask: FF:FF:FF:FF:FF:FF
        Dest MAC addr: 08:11:22:33:44:54 mask: 00:00:00:00:00:00

Signed-off-by: Daniel Jurgens <danielj@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Shahar Shitrit <shshitrit@nvidia.com>
---
 drivers/net/virtio_net/virtio_net_ff.c   | 48 ++++++++++++++++++++++++
 drivers/net/virtio_net/virtio_net_ff.h   |  6 +++
 drivers/net/virtio_net/virtio_net_main.c |  9 +++++
 3 files changed, 63 insertions(+)

diff --git a/drivers/net/virtio_net/virtio_net_ff.c b/drivers/net/virtio_net/virtio_net_ff.c
index a1f5c913bf08..2a76de5f7f32 100644
--- a/drivers/net/virtio_net/virtio_net_ff.c
+++ b/drivers/net/virtio_net/virtio_net_ff.c
@@ -807,6 +807,54 @@ int virtnet_ethtool_flow_remove(struct virtnet_ff *ff, int location)
 	return err;
 }
 
+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 = le32_to_cpu(ff->ff_caps->rules_limit) | RX_CLS_LOC_SPECIAL;
+
+	return 0;
+}
+
+int virtnet_ethtool_get_flow(struct virtnet_ff *ff,
+			     struct ethtool_rxnfc *info)
+{
+	struct virtnet_ethtool_rule *eth_rule;
+
+	if (!ff->ff_supported)
+		return -EOPNOTSUPP;
+
+	eth_rule = xa_load(&ff->ethtool.rules, info->fs.location);
+	if (!eth_rule)
+		return -ENOENT;
+
+	info->fs = eth_rule->flow_spec;
+
+	return 0;
+}
+
+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)
+		rule_locs[idx++] = i;
+
+	info->data = le32_to_cpu(ff->ff_caps->rules_limit);
+
+	return 0;
+}
+
 static size_t get_mask_size(u16 type)
 {
 	switch (type) {
diff --git a/drivers/net/virtio_net/virtio_net_ff.h b/drivers/net/virtio_net/virtio_net_ff.h
index 94b575fbd9ed..4bb41e64cc59 100644
--- a/drivers/net/virtio_net/virtio_net_ff.h
+++ b/drivers/net/virtio_net/virtio_net_ff.h
@@ -28,6 +28,12 @@ void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev);
 
 void virtnet_ff_cleanup(struct virtnet_ff *ff);
 
+int virtnet_ethtool_get_flow_count(struct virtnet_ff *ff,
+				   struct ethtool_rxnfc *info);
+int virtnet_ethtool_get_all_flows(struct virtnet_ff *ff,
+				  struct ethtool_rxnfc *info, u32 *rule_locs);
+int virtnet_ethtool_get_flow(struct virtnet_ff *ff,
+			     struct ethtool_rxnfc *info);
 int virtnet_ethtool_flow_insert(struct virtnet_ff *ff,
 				struct ethtool_rx_flow_spec *fs,
 				u16 curr_queue_pairs);
diff --git a/drivers/net/virtio_net/virtio_net_main.c b/drivers/net/virtio_net/virtio_net_main.c
index 14ee26fc9ef3..63bf5fdc084f 100644
--- a/drivers/net/virtio_net/virtio_net_main.c
+++ b/drivers/net/virtio_net/virtio_net_main.c
@@ -5619,6 +5619,15 @@ static int virtnet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
 	int rc = 0;
 
 	switch (info->cmd) {
+	case ETHTOOL_GRXCLSRLCNT:
+		rc = virtnet_ethtool_get_flow_count(&vi->ff, info);
+		break;
+	case ETHTOOL_GRXCLSRULE:
+		rc = virtnet_ethtool_get_flow(&vi->ff, info);
+		break;
+	case ETHTOOL_GRXCLSRLALL:
+		rc = virtnet_ethtool_get_all_flows(&vi->ff, info, rule_locs);
+		break;
 	case ETHTOOL_GRXRINGS:
 		info->data = vi->curr_queue_pairs;
 		break;
-- 
2.50.1


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

* Re: [PATCH net-next 11/11] virtio_net: Add get ethtool flow rules ops
@ 2025-08-28 18:40 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2025-08-28 18:40 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250827183852.2471-12-danielj@nvidia.com>
References: <20250827183852.2471-12-danielj@nvidia.com>
TO: Daniel Jurgens <danielj@nvidia.com>
TO: netdev@vger.kernel.org
TO: mst@redhat.com
TO: jasowang@redhat.com
TO: alex.williamson@redhat.com
TO: virtualization@lists.linux.dev
TO: pabeni@redhat.com
CC: parav@nvidia.com
CC: shshitrit@nvidia.com
CC: yohadt@nvidia.com
CC: Daniel Jurgens <danielj@nvidia.com>

Hi Daniel,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniel-Jurgens/virtio-pci-Expose-generic-device-capability-operations/20250828-024128
base:   net-next/main
patch link:    https://lore.kernel.org/r/20250827183852.2471-12-danielj%40nvidia.com
patch subject: [PATCH net-next 11/11] virtio_net: Add get ethtool flow rules ops
:::::: branch date: 24 hours ago
:::::: commit date: 24 hours ago
config: x86_64-randconfig-r073-20250828 (https://download.01.org/0day-ci/archive/20250829/202508290203.AzlaAntz-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202508290203.AzlaAntz-lkp@intel.com/

New smatch warnings:
drivers/net/virtio_net/virtio_net_ff.c:850 virtnet_ethtool_get_all_flows() warn: iterator 'i' not incremented

Old smatch warnings:
drivers/net/virtio_net/virtio_net_ff.c:321 setup_classifier() warn: iterator 'i' not incremented
drivers/net/virtio_net/virtio_net_ff.c:1014 virtnet_ff_cleanup() warn: iterator 'i' not incremented

vim +/i +850 drivers/net/virtio_net/virtio_net_ff.c

5e0d228c07c140 Daniel Jurgens 2025-08-27  838  
5e0d228c07c140 Daniel Jurgens 2025-08-27  839  int
5e0d228c07c140 Daniel Jurgens 2025-08-27  840  virtnet_ethtool_get_all_flows(struct virtnet_ff *ff,
5e0d228c07c140 Daniel Jurgens 2025-08-27  841  			      struct ethtool_rxnfc *info, u32 *rule_locs)
5e0d228c07c140 Daniel Jurgens 2025-08-27  842  {
5e0d228c07c140 Daniel Jurgens 2025-08-27  843  	struct virtnet_ethtool_rule *eth_rule;
5e0d228c07c140 Daniel Jurgens 2025-08-27  844  	unsigned long i = 0;
5e0d228c07c140 Daniel Jurgens 2025-08-27  845  	int idx = 0;
5e0d228c07c140 Daniel Jurgens 2025-08-27  846  
5e0d228c07c140 Daniel Jurgens 2025-08-27  847  	if (!ff->ff_supported)
5e0d228c07c140 Daniel Jurgens 2025-08-27  848  		return -EOPNOTSUPP;
5e0d228c07c140 Daniel Jurgens 2025-08-27  849  
5e0d228c07c140 Daniel Jurgens 2025-08-27 @850  	xa_for_each(&ff->ethtool.rules, i, eth_rule)
5e0d228c07c140 Daniel Jurgens 2025-08-27  851  		rule_locs[idx++] = i;
5e0d228c07c140 Daniel Jurgens 2025-08-27  852  
5e0d228c07c140 Daniel Jurgens 2025-08-27  853  	info->data = le32_to_cpu(ff->ff_caps->rules_limit);
5e0d228c07c140 Daniel Jurgens 2025-08-27  854  
5e0d228c07c140 Daniel Jurgens 2025-08-27  855  	return 0;
5e0d228c07c140 Daniel Jurgens 2025-08-27  856  }
5e0d228c07c140 Daniel Jurgens 2025-08-27  857  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2025-08-28 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-28 18:40 [PATCH net-next 11/11] virtio_net: Add get ethtool flow rules ops kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-08-27 18:38 [PATCH net-next 00/11] virtio_net: Add ethtool flow rules support Daniel Jurgens
2025-08-27 18:38 ` [PATCH net-next 11/11] virtio_net: Add get ethtool flow rules ops Daniel Jurgens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.