virtio_net: Add ethtool flow rules support
Subsystems (7)
cover virtio_net: Add ethtool flow rules support
This series implements ethtool flow rules support for virtio_net using the virtio flow filter (FF) specification. The implementation allows users to configure packet filtering rules through ethtool commands, directing packets to specific receive queues, or dropping them based on various header fields.
The series starts with infrastructure changes to expose virtio PCI admin capabilities and object management APIs. It then creates the virtio_net directory structure and implements the flow filter functionality with support for:
- Layer 2 (Ethernet) flow rules
- IPv4 and IPv6 flow rules
- TCP and UDP flow rules (both IPv4 and IPv6)
- Rule querying and management operations
Setting, deleting and viewing flow filters, -1 action is drop, postive integers steer to that RQ:
$ ethtool -u ens9 4 RX rings available Total 0 rules
$ ethtool -U ens9 flow-type ether src 1c:34:da:4a:33:dd action 0 Added rule with ID 0 $ ethtool -U ens9 flow-type udp4 dst-port 5001 action 3 Added rule with ID 1 $ ethtool -U ens9 flow-type tcp6 src-ip fc00::2 dst-port 5001 action 2 Added rule with ID 2 $ ethtool -U ens9 flow-type ip4 src-ip 192.168.51.101 action 1 Added rule with ID 3 $ ethtool -U ens9 flow-type ip6 dst-ip fc00::1 action -1 Added rule with ID 4 $ ethtool -U ens9 flow-type ip6 src-ip fc00::2 action -1 Added rule with ID 5 $ ethtool -U ens9 delete 4 $ ethtool -u ens9 4 RX rings available Total 5 rules
Filter: 0
Flow Type: Raw Ethernet
Src MAC addr: 1C:34:DA:4A:33:DD mask: 00:00:00:00:00:00
Dest MAC addr: 00:00:00:00:00:00 mask: FF:FF:FF:FF:FF:FF
Ethertype: 0x0 mask: 0xFFFF
Action: Direct to queue 0Filter: 1
Rule Type: UDP over IPv4
Src IP addr: 0.0.0.0 mask: 255.255.255.255
Dest IP addr: 0.0.0.0 mask: 255.255.255.255
TOS: 0x0 mask: 0xff
Src port: 0 mask: 0xffff
Dest port: 5001 mask: 0x0
Action: Direct to queue 3Filter: 2
Rule Type: TCP over IPv6
Src IP addr: fc00::2 mask: ::
Dest IP addr: :: mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
Traffic Class: 0x0 mask: 0xff
Src port: 0 mask: 0xffff
Dest port: 5001 mask: 0x0
Action: Direct to queue 2Filter: 3
Rule Type: Raw IPv4
Src IP addr: 192.168.51.101 mask: 0.0.0.0
Dest IP addr: 0.0.0.0 mask: 255.255.255.255
TOS: 0x0 mask: 0xff
Protocol: 0 mask: 0xff
L4 bytes: 0x0 mask: 0xffffffff
Action: Direct to queue 1Filter: 5
Rule Type: Raw IPv6
Src IP addr: fc00::2 mask: ::
Dest IP addr: :: mask: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
Traffic Class: 0x0 mask: 0xff
Protocol: 0 mask: 0xff
L4 bytes: 0x0 mask: 0xffffffff
Action: DropDaniel Jurgens (11):
virtio-pci: Expose generic device capability operations
virtio-pci: Expose object create and destroy API
virtio_net: Create virtio_net directory
virtio_net: Query and set flow filter caps
virtio_net: Create a FF group for ethtool steering
virtio_net: Implement layer 2 ethtool flow rules
virtio_net: Use existing classifier if possible
virtio_net: Implement IPv4 ethtool flow rules
virtio_net: Add support for IPv6 ethtool steering
virtio_net: Add support for TCP and UDP ethtool rules
virtio_net: Add get ethtool flow rules ops
MAINTAINERS | 2 +-
drivers/net/Makefile | 2 +-
drivers/net/virtio_net/Makefile | 8 +
drivers/net/virtio_net/virtio_net_ff.c | 1027 +++++++++++++++++
drivers/net/virtio_net/virtio_net_ff.h | 42 +
.../virtio_net_main.c} | 32 +
drivers/vfio/pci/virtio/migrate.c | 8 +-
drivers/virtio/virtio.c | 141 +++
drivers/virtio/virtio_pci_common.h | 1 -
drivers/virtio/virtio_pci_modern.c | 320 ++---
include/linux/virtio.h | 21 +
include/linux/virtio_admin.h | 101 ++
include/linux/virtio_pci_admin.h | 7 +-
include/uapi/linux/virtio_net_ff.h | 82 ++
include/uapi/linux/virtio_pci.h | 7 +-
15 files changed, 1660 insertions(+), 141 deletions(-)
create mode 100644 drivers/net/virtio_net/Makefile
create mode 100644 drivers/net/virtio_net/virtio_net_ff.c
create mode 100644 drivers/net/virtio_net/virtio_net_ff.h
rename drivers/net/{virtio_net.c => virtio_net/virtio_net_main.c} (99%)
create mode 100644 include/linux/virtio_admin.h
create mode 100644 include/uapi/linux/virtio_net_ff.hSignature · 1 line
2.50.1
PATCH 1/11 virtio-pci: Expose generic device capability operations
Currently querying and setting capabilities is restricted to a single capability and contained within the virtio PCI driver. However, each device type has generic and device specific capabilities, that may be queried and set. In subsequent patches virtio_net will query and set flow filter capabilities.
Move the admin related definitions to a new header file. It needs to be abstracted away from the PCI specifics to be used by upper layer drivers.
--- drivers/virtio/virtio.c | 82 ++++++++++++++++ drivers/virtio/virtio_pci_common.h | 1 - drivers/virtio/virtio_pci_modern.c | 145 +++++++++++++++++------------ include/linux/virtio.h | 13 +++ include/linux/virtio_admin.h | 68 ++++++++++++++ include/uapi/linux/virtio_pci.h | 7 +- 6 files changed, 254 insertions(+), 62 deletions(-) create mode 100644 include/linux/virtio_admin.h
drivers/virtio/virtio.c +82 -0
@@ -706,6 +706,88 @@ int virtio_device_reset_done(struct virtio_device *dev) }EXPORT_SYMBOL_GPL (virtio_device_reset_done); +/** +* virtio_device_cap_id_list_query - Query the list of available capability IDs +* @vdev: the virtio device +* @data: pointer to store the capability ID list result +* +* This function queries the virtio device for the list of available capability +* IDs that can be used with virtio_device_cap_get() and virtio_device_cap_set(). +* The result is stored in the provided data structure. +* +* Return: 0 on success, -EOPNOTSUPP if the device doesn't support admin +* operations or capability queries, or a negative error code on other failures. +*/ +int +virtio_device_cap_id_list_query (struct virtio_device *vdev, +struct virtio_admin_cmd_query_cap_id_result *data) +{ +const struct virtio_admin_ops *admin = vdev->admin_ops; + +if (!admin || !admin->cap_id_list_query) +return -EOPNOTSUPP ; + +return admin->cap_id_list_query (vdev, data); +} +EXPORT_SYMBOL_GPL (virtio_device_cap_id_list_query); + +/** +* virtio_device_cap_get - Get a capability from a virtio device +* @vdev: the virtio device +* @id: capability ID to retrieve +* @caps: buffer to store the capability data +* @cap_size: size of the capability buffer in bytes +* +* This function retrieves a specific capability from the virtio device. +* The capability data is stored in the provided buffer. The caller must +* ensure the buffer is large enough to hold the capability data. +* +* Return: 0 on success, -EOPNOTSUPP if the device doesn't support admin +* operations or capability retrieval, or a negative error code on other failures. +*/ +int virtio_device_cap_get (struct virtio_device *vdev, +u16 id, +void *caps, +size_t cap_size) +{ +const struct virtio_admin_ops *admin = vdev->admin_ops; + +if (!admin || !admin->cap_get) +return -EOPNOTSUPP ; + +return admin->cap_get (vdev, id, caps, cap_size); +} +EXPORT_SYMBOL_GPL (virtio_device_cap_get); + +/** +* virtio_device_cap_set - Set a capability on a virtio device +* @vdev: the virtio device +* @id: capability ID to set +* @caps: buffer containing the capability data to set +* @cap_size: size of the capability data in bytes +* +* This function sets a specific capability on the virtio device. +* The capability data is read from the provided buffer and applied +* to the device. The device may validate the capability data before +* applying it. +* +* Return: 0 on success, -EOPNOTSUPP if the device doesn't support admin +* operations or capability setting, or a negative error code on other failures. +*/ +int virtio_device_cap_set (struct virtio_device *vdev, +u16 id, +const void *caps, +size_t cap_size) +{ +const struct virtio_admin_ops *admin = vdev->admin_ops; + +if (!admin || !admin->cap_set) +return -EOPNOTSUPP ; + +return admin->cap_set (vdev, id, caps, cap_size); +} +EXPORT_SYMBOL_GPL (virtio_device_cap_set); +static int virtio_init (void ) { BUILD_BUG_ON(offsetof(struct virtio_device, features) !=
drivers/virtio/virtio_pci_common.h +0 -1
@@ -48,7 +48,6 @@ struct virtio_pci_admin_vq {/* Protects virtqueue access. */ spinlock_t lock;u64 supported_cmds; -u64 supported_caps;u8 max_dev_parts_objects;struct ida dev_parts_ida;/* Name of the admin queue: avq.$vq_index. */
drivers/virtio/virtio_pci_modern.c +86 -59
207 lines not on this page · raw message
include/linux/virtio.h +13 -0
@@ -12,6 +12,7 @@#include <linux/dma-mapping.h> #include <linux/completion.h> #include <linux/virtio_features.h> +#include <linux/virtio_admin.h> /** * struct virtqueue - a queue to register buffers for sending or receiving.
@@ -161,6 +162,7 @@ struct virtio_device {struct virtio_device_id id;const struct virtio_config_ops *config;const struct vringh_config_ops *vringh_config; +const struct virtio_admin_ops *admin_ops;struct list_head vqs;VIRTIO_DECLARE_FEATURES (features);void *priv;
@@ -195,6 +197,17 @@ int virtio_device_restore(struct virtio_device *dev);void virtio_reset_device (struct virtio_device *dev);int virtio_device_reset_prepare (struct virtio_device *dev);int virtio_device_reset_done (struct virtio_device *dev); +int +virtio_device_cap_id_list_query (struct virtio_device *vdev, +struct virtio_admin_cmd_query_cap_id_result *data); +int virtio_device_cap_get (struct virtio_device *vdev, +u16 id, +void *caps, +size_t cap_size); +int virtio_device_cap_set (struct virtio_device *vdev, +u16 id, +const void *caps, +size_t cap_size);size_t virtio_max_dma_size (const struct virtio_device *vdev);
include/linux/virtio_admin.h new file +68 -0
68 lines not on this page · raw message
include/uapi/linux/virtio_pci.h +5 -2
@@ -315,15 +315,18 @@ struct virtio_admin_cmd_notify_info_result {#define VIRTIO_DEV_PARTS_CAP 0x0000 +/* Update this value to largest implemented cap number. */ +#define VIRTIO_ADMIN_MAX_CAP 0x0fff +struct virtio_dev_parts_cap {__u8 get_parts_resource_objects_limit;__u8 set_parts_resource_objects_limit; }; -#define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64) +#define VIRTIO_ADMIN_CAP_ID_ARRAY_SIZE __KERNEL_DIV_ROUND_UP(VIRTIO_ADMIN_MAX_CAP, 64)struct virtio_admin_cmd_query_cap_id_result { -__le64 supported_caps[MAX_CAP_ID ]; +__le64 supported_caps[VIRTIO_ADMIN_CAP_ID_ARRAY_SIZE ]; };struct virtio_admin_cmd_cap_get_data {
Signature · 1 line
2.50.1
PATCH 2/11 virtio-pci: Expose object create and destroy API
In reply to Daniel JurgensObject create and destroy were implemented specifically for dev parts device objects. Create general purpose APIs for use by upper layer drivers.
--- drivers/vfio/pci/virtio/migrate.c | 8 +- drivers/virtio/virtio.c | 59 ++++++++++ drivers/virtio/virtio_pci_modern.c | 175 +++++++++++++++++------------ include/linux/virtio.h | 8 ++ include/linux/virtio_admin.h | 32 ++++++ include/linux/virtio_pci_admin.h | 7 +- 6 files changed, 212 insertions(+), 77 deletions(-)
drivers/vfio/pci/virtio/migrate.c +4 -4
@@ -152,15 +152,15 @@ static int virtiovf_pci_alloc_obj_id(struct virtiovf_pci_core_device *virtvdev, u8 type, u32 *obj_id) { - return virtio_pci_admin_obj_create(virtvdev->core_device.pdev, - VIRTIO_RESOURCE_OBJ_DEV_PARTS, type, obj_id); + return virtio_pci_admin_dev_parts_obj_create(virtvdev->core_device.pdev, + type, obj_id); }static void virtiovf_pci_free_obj_id (struct virtiovf_pci_core_device *virtvdev,u32 obj_id) { -virtio_pci_admin_obj_destroy (virtvdev->core_device.pdev, -VIRTIO_RESOURCE_OBJ_DEV_PARTS , obj_id); +virtio_pci_admin_dev_parts_obj_destroy (virtvdev->core_device.pdev, + obj_id); } static struct virtiovf_data_buffer *
drivers/virtio/virtio.c +59 -0
65 lines not on this page · raw message
drivers/virtio/virtio_pci_modern.c +105 -70
230 lines not on this page · raw message
include/linux/virtio.h +8 -0
@@ -208,6 +208,14 @@ int virtio_device_cap_set(struct virtio_device *vdev,u16 id, const void *caps, size_t cap_size); +int virtio_device_object_create (struct virtio_device *virtio_dev, +u16 obj_type, +u32 obj_id, +const void *obj_specific_data, +size_t obj_specific_data_size); +int virtio_device_object_destroy (struct virtio_device *virtio_dev, +u16 obj_type, +u32 obj_id);size_t virtio_max_dma_size (const struct virtio_device *vdev);
include/linux/virtio_admin.h +32 -0
@@ -63,6 +63,38 @@ struct virtio_admin_ops {u16 id, const void *caps, size_t cap_size); +/** +* @object_create: Create a new object of specified type +* @virtio_dev: The virtio device +* @obj_type: Type of object to create +* @obj_id: ID to assign to the created object +* @group_type: Type of group the object belongs to +* @group_member_id: Member ID within the group +* @obj_specific_data: Object-specific data (must be heap allocated) +* @obj_specific_data_size: Size of the object-specific data +* Returns: 0 on success, negative error code on failure +*/ +int (*object_create)(struct virtio_device *virtio_dev, +u16 obj_type, +u32 obj_id, +u16 group_type, +u64 group_member_id, +const void *obj_specific_data, +size_t obj_specific_data_size); +/** +* @object_destroy: Destroy an existing object +* @virtio_dev: The virtio device +* @obj_type: Type of object to destroy +* @obj_id: ID of the object to destroy +* @group_type: Type of group the object belongs to +* @group_member_id: Member ID within the group +* Returns: 0 on success, negative error code on failure +*/ +int (*object_destroy)(struct virtio_device *virtio_dev, +u16 obj_type, +u32 obj_id, +u16 group_type, + u64 group_member_id); };#endif /* _LINUX_VIRTIO_ADMIN_H */
include/linux/virtio_pci_admin.h +4 -3
@@ -22,9 +22,10 @@ int virtio_pci_admin_legacy_io_notify_info(struct pci_dev *pdev,bool virtio_pci_admin_has_dev_parts (struct pci_dev *pdev);int virtio_pci_admin_mode_set (struct pci_dev *pdev,u8 mode); -int virtio_pci_admin_obj_create (struct pci_dev *pdev,u16 obj_type,u8 operation_type, -u32 *obj_id); -int virtio_pci_admin_obj_destroy (struct pci_dev *pdev,u16 obj_type,u32 id); +int virtio_pci_admin_dev_parts_obj_create (struct pci_dev *pdev, +u8 operation_type, +u32 *obj_id); +int virtio_pci_admin_dev_parts_obj_destroy (struct pci_dev *pdev,u32 obj_id);int virtio_pci_admin_dev_parts_metadata_get (struct pci_dev *pdev,u16 obj_type,u32 id,u8 metadata_type,u32 *out); int virtio_pci_admin_dev_parts_get(struct pci_dev *pdev, u16 obj_type, u32 id,
Signature · 1 line
2.50.1
PATCH 3/11 virtio_net: Create virtio_net directory
In reply to Daniel JurgensThe flow filter implementaion requires minimal changes to the existing virtio_net implementation. It's cleaner to separate it into another file. In order to do so, move virtio_net.c into the new virtio_net directory, and create a makefile for it. Note the name is changed to virtio_net_main.c, so the module can retain the name virtio_net.
---
MAINTAINERS | 2 +-
drivers/net/Makefile | 2 +-
drivers/net/virtio_net/Makefile | 8 ++++++++
.../net/{virtio_net.c => virtio_net/virtio_net_main.c} | 0
4 files changed, 10 insertions(+), 2 deletions(-)
create mode 100644 drivers/net/virtio_net/Makefile
rename drivers/net/{virtio_net.c => virtio_net/virtio_net_main.c} (100%)MAINTAINERS +1 -1
@@ -26625,7 +26625,7 @@ F: Documentation/devicetree/bindings/virtio/ F: Documentation/driver-api/virtio/ F: drivers/block/virtio_blk.c F: drivers/crypto/virtio/ -F: drivers/net/virtio_net.c +F: drivers/net/virtio_net/ F: drivers/vdpa/ F: drivers/virtio/ F: include/linux/vdpa.h
drivers/net/Makefile +1 -1
@@ -33,7 +33,7 @@ obj-$(CONFIG_NET_TEAM) += team/ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_TAP) += tap.o obj-$(CONFIG_VETH) += veth.o -obj-$(CONFIG_VIRTIO_NET) += virtio_net.o +obj-$(CONFIG_VIRTIO_NET) += virtio_net/ obj-$(CONFIG_VXLAN) += vxlan/ obj-$(CONFIG_GENEVE) += geneve.o obj-$(CONFIG_BAREUDP) += bareudp.o
drivers/net/virtio_net/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the VirtIO Net driver +# + +obj-$(CONFIG_VIRTIO_NET) += virtio_net.o + +virtio_net-objs := virtio_net_main.o
drivers/net/virtio_net/virtio_net_main.c renamed from drivers/net/virtio_net.c +0 -0
Signature · 1 line
2.50.1
PATCH 4/11 virtio_net: Query and set flow filter caps
In reply to Daniel JurgensWhen probing a virtnet device, attempt to read the flow filter capabilities. In order to use the feature the caps must also be set. For now setting what was read is sufficient.
--- drivers/net/virtio_net/Makefile | 2 +- drivers/net/virtio_net/virtio_net_ff.c | 145 +++++++++++++++++++++++ drivers/net/virtio_net/virtio_net_ff.h | 22 ++++ drivers/net/virtio_net/virtio_net_main.c | 7 ++ include/linux/virtio_admin.h | 1 + include/uapi/linux/virtio_net_ff.h | 55 +++++++++ 6 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 drivers/net/virtio_net/virtio_net_ff.c create mode 100644 drivers/net/virtio_net/virtio_net_ff.h create mode 100644 include/uapi/linux/virtio_net_ff.h
drivers/net/virtio_net/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_VIRTIO_NET) += virtio_net.o -virtio_net-objs := virtio_net_main.o +virtio_net-objs := virtio_net_main.o virtio_net_ff.o
drivers/net/virtio_net/virtio_net_ff.c new file +145 -0
145 lines not on this page · raw message
drivers/net/virtio_net/virtio_net_ff.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Header file for virtio_net flow filters +*/ +#include <linux/virtio_admin.h> + +#ifndef _VIRTIO_NET_FF_H +#define _VIRTIO_NET_FF_H + +struct virtnet_ff { +struct virtio_device *vdev; +bool ff_supported; +struct virtio_net_ff_cap_data *ff_caps; +struct virtio_net_ff_cap_mask_data *ff_mask; +struct virtio_net_ff_actions *ff_actions; +}; + +void virtnet_ff_init (struct virtnet_ff *ff,struct virtio_device *vdev); + +void virtnet_ff_cleanup (struct virtnet_ff *ff); + +#endif /* _VIRTIO_NET_FF_H */
drivers/net/virtio_net/virtio_net_main.c +7 -0
@@ -26,6 +26,7 @@#include <net/netdev_rx_queue.h> #include <net/netdev_queues.h> #include <net/xdp_sock_drv.h> +#include "virtio_net_ff.h" static int napi_weight =NAPI_POLL_WEIGHT ;module_param (napi_weight, int,0444 );
@@ -493,6 +494,8 @@ struct virtnet_info {struct failover *failover;u64 device_stats_cap; + +struct virtnet_ff ff; };struct padded_vnet_hdr {
@@ -7125,6 +7128,8 @@ static int virtnet_probe(struct virtio_device *vdev) } vi->guest_offloads_capable = vi->guest_offloads; +virtnet_ff_init (&vi->ff, vi->vdev); +rtnl_unlock (); err =virtnet_cpu_notif_add (vi);
@@ -7140,6 +7145,7 @@ static int virtnet_probe(struct virtio_device *vdev) free_unregister_netdev:unregister_netdev (dev); +virtnet_ff_cleanup (&vi->ff); free_failover:net_failover_destroy (vi->failover); free_vqs:
@@ -7189,6 +7195,7 @@ static void virtnet_remove(struct virtio_device *vdev)virtnet_free_irq_moder (vi);unregister_netdev (vi->dev); +virtnet_ff_cleanup (&vi->ff);net_failover_destroy (vi->failover);
include/linux/virtio_admin.h +1 -0
@@ -3,6 +3,7 @@* Header file for virtio admin operations */ #include <uapi/linux/virtio_pci.h> +#include <uapi/linux/virtio_net_ff.h> #ifndef _LINUX_VIRTIO_ADMIN_H#define _LINUX_VIRTIO_ADMIN_H
include/uapi/linux/virtio_net_ff.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.50.1
kernel test robot
build botRe: [PATCH net-next 04/11] virtio_net: Query and set flow filter caps
kernel test robot noticed the following build errors:
Hi Daniel,
kernel test robot noticed the following build errors:
[auto build test ERROR 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-5-danielj%40nvidia.com patch subject: [PATCH net-next 04/11] virtio_net: Query and set flow filter caps config: i386-buildonly-randconfig-002-20250828 (https://download.01.org/0day-ci/archive/20250828/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250828/[email protected]/reproduce)
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> error: include/uapi/linux/virtio_net_ff.h: missing "WITH Linux-syscall-note" for SPDX-License-Identifier
make[3]: *** [scripts/Makefile.headersinst:63: usr/include/linux/virtio_net_ff.h] Error 1 shuffle=2238678394 make[3]: Target '__headers' not remade because of errors.
make[2]: *** [Makefile:1380: headers] Error 2 shuffle=2238678394
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2 shuffle=2238678394
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2 shuffle=2238678394
make: Target 'prepare' not remade because of errors.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 5/11 virtio_net: Create a FF group for ethtool steering
In reply to Daniel JurgensAll ethtool steering rules will go in one group, create it during initialization.
--- drivers/net/virtio_net/virtio_net_ff.c | 25 +++++++++++++++++++++++++ include/uapi/linux/virtio_net_ff.h | 7 +++++++ 2 files changed, 32 insertions(+)
drivers/net/virtio_net/virtio_net_ff.c +25 -0
@@ -6,6 +6,9 @@#include <net/ip.h> #include "virtio_net_ff.h" +#define VIRTNET_FF_ETHTOOL_GROUP_PRIORITY 1 +#define VIRTNET_FF_MAX_GROUPS 1 +static size_t get_mask_size (u16 type) {switch (type) {
@@ -30,6 +33,7 @@ void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)size_t ff_mask_size =sizeof (struct virtio_net_ff_cap_mask_data ) +sizeof (struct virtio_net_ff_selector ) *VIRTIO_NET_FF_MASK_TYPE_MAX ; +struct virtio_net_resource_obj_ff_group ethtool_group = {};struct virtio_net_ff_selector *sel;int err;int i;
@@ -92,6 +96,12 @@ void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)if (err) goto err_ff_action; +if (le32_to_cpu (ff->ff_caps->groups_limit <VIRTNET_FF_MAX_GROUPS )) { + err = -ENOSPC ; + goto err_ff_action; + } + ff->ff_caps->groups_limit =VIRTNET_FF_MAX_GROUPS ; + err = virtio_device_cap_set(vdev, VIRTIO_NET_FF_RESOURCE_CAP, ff->ff_caps,
@@ -121,6 +131,17 @@ void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)if (err) goto err_ff_action; + ethtool_group.group_priority =cpu_to_le16 (VIRTNET_FF_ETHTOOL_GROUP_PRIORITY ); + +/* Use priority for the object ID. */ + err =virtio_device_object_create (vdev, +VIRTIO_NET_RESOURCE_OBJ_FF_GROUP , +VIRTNET_FF_ETHTOOL_GROUP_PRIORITY , + ðtool_group, +sizeof (ethtool_group)); +if (err) + goto err_ff_action; + ff->vdev = vdev; ff->ff_supported = true;
@@ -139,6 +160,10 @@ void virtnet_ff_cleanup(struct virtnet_ff *ff)if (!ff->ff_supported)return ; +virtio_device_object_destroy (ff->vdev, +VIRTIO_NET_RESOURCE_OBJ_FF_GROUP , +VIRTNET_FF_ETHTOOL_GROUP_PRIORITY ); +kfree (ff->ff_actions);kfree (ff->ff_mask);kfree (ff->ff_caps);
include/uapi/linux/virtio_net_ff.h +7 -0
@@ -12,6 +12,8 @@#define VIRTIO_NET_FF_SELECTOR_CAP 0x801#define VIRTIO_NET_FF_ACTION_CAP 0x802 +#define VIRTIO_NET_RESOURCE_OBJ_FF_GROUP 0x0200 +struct virtio_net_ff_cap_data {__le32 groups_limit;__le32 classifiers_limit;
@@ -52,4 +54,9 @@ struct virtio_net_ff_actions {__u8 reserved[7 ]; __u8 actions[]; }; + +struct virtio_net_resource_obj_ff_group { +__le16 group_priority; +}; +#endif
Signature · 1 line
2.50.1
kernel test robot
build botRe: [PATCH net-next 05/11] virtio_net: Create a FF group for ethtool steering
kernel test robot noticed the following build warnings:
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-6-danielj%40nvidia.com patch subject: [PATCH net-next 05/11] virtio_net: Create a FF group for ethtool steering config: x86_64-randconfig-121-20250828 (https://download.01.org/0day-ci/archive/20250829/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250829/[email protected]/reproduce)
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
drivers/net/virtio_net/virtio_net_ff.c: note: in included file (through include/linux/virtio_admin.h):
include/uapi/linux/virtio_net_ff.h:45:48: sparse: sparse: array of flexible structures
>> drivers/net/virtio_net/virtio_net_ff.c:99:13: sparse: sparse: restricted __le32 degrades to integer >> drivers/net/virtio_net/virtio_net_ff.c:99:13: sparse: sparse: cast to restricted __le32 >> drivers/net/virtio_net/virtio_net_ff.c:103:35: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] groups_limit @@ got int @@
drivers/net/virtio_net/virtio_net_ff.c:103:35: sparse: expected restricted __le32 [usertype] groups_limit
drivers/net/virtio_net/virtio_net_ff.c:103:35: sparse: got int
vim +99 drivers/net/virtio_net/virtio_net_ff.c
29
30 void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)
31 {
32 struct virtio_admin_cmd_query_cap_id_result *cap_id_list __free(kfree) = NULL;
33 size_t ff_mask_size = sizeof(struct virtio_net_ff_cap_mask_data) +
34 sizeof(struct virtio_net_ff_selector) *
35 VIRTIO_NET_FF_MASK_TYPE_MAX;
36 struct virtio_net_resource_obj_ff_group ethtool_group = {};
37 struct virtio_net_ff_selector *sel;
38 int err;
39 int i;
40
41 cap_id_list = kzalloc(sizeof(*cap_id_list), GFP_KERNEL);
42 if (!cap_id_list)
43 return;
44
45 err = virtio_device_cap_id_list_query(vdev, cap_id_list);
46 if (err)
47 return;
48
49 if (!(VIRTIO_CAP_IN_LIST(cap_id_list,
50 VIRTIO_NET_FF_RESOURCE_CAP) &&
51 VIRTIO_CAP_IN_LIST(cap_id_list,
52 VIRTIO_NET_FF_SELECTOR_CAP) &&
53 VIRTIO_CAP_IN_LIST(cap_id_list,
54 VIRTIO_NET_FF_ACTION_CAP)))
55 return;
56
57 ff->ff_caps = kzalloc(sizeof(*ff->ff_caps), GFP_KERNEL);
58 if (!ff->ff_caps)
59 return;
60
61 err = virtio_device_cap_get(vdev,
62 VIRTIO_NET_FF_RESOURCE_CAP,
63 ff->ff_caps,
64 sizeof(*ff->ff_caps));
65
66 if (err)
67 goto err_ff;
68
69 /* VIRTIO_NET_FF_MASK_TYPE start at 1 */
70 for (i = 1; i <= VIRTIO_NET_FF_MASK_TYPE_MAX; i++)
71 ff_mask_size += get_mask_size(i);
72
73 ff->ff_mask = kzalloc(ff_mask_size, GFP_KERNEL);
74 if (!ff->ff_mask)
75 goto err_ff;
76
77 err = virtio_device_cap_get(vdev,
78 VIRTIO_NET_FF_SELECTOR_CAP,
79 ff->ff_mask,
80 ff_mask_size);
81
82 if (err)
83 goto err_ff_mask;
84
85 ff->ff_actions = kzalloc(sizeof(*ff->ff_actions) +
86 VIRTIO_NET_FF_ACTION_MAX,
87 GFP_KERNEL);
88 if (!ff->ff_actions)
89 goto err_ff_mask;
90
91 err = virtio_device_cap_get(vdev,
92 VIRTIO_NET_FF_ACTION_CAP,
93 ff->ff_actions,
94 sizeof(*ff->ff_actions) + VIRTIO_NET_FF_ACTION_MAX);
95
96 if (err)
97 goto err_ff_action;
98
> 99 if (le32_to_cpu(ff->ff_caps->groups_limit < VIRTNET_FF_MAX_GROUPS)) {
100 err = -ENOSPC;
101 goto err_ff_action;
102 }
> 103 ff->ff_caps->groups_limit = VIRTNET_FF_MAX_GROUPS;
104
105 err = virtio_device_cap_set(vdev,
106 VIRTIO_NET_FF_RESOURCE_CAP,
107 ff->ff_caps,
108 sizeof(*ff->ff_caps));
109 if (err)
110 goto err_ff_action;
111
112 ff_mask_size = sizeof(struct virtio_net_ff_cap_mask_data);
113 sel = &ff->ff_mask->selectors[0];
114
115 for (int i = 0; i < ff->ff_mask->count; i++) {
116 ff_mask_size += sizeof(struct virtio_net_ff_selector) + sel->length;
117 sel = (struct virtio_net_ff_selector *)((u8 *)sel + sizeof(*sel) + sel->length);
118 }
119
120 err = virtio_device_cap_set(vdev,
121 VIRTIO_NET_FF_SELECTOR_CAP,
122 ff->ff_mask,
123 ff_mask_size);
124 if (err)
125 goto err_ff_action;
126
127 err = virtio_device_cap_set(vdev,
128 VIRTIO_NET_FF_ACTION_CAP,
129 ff->ff_actions,
130 sizeof(*ff->ff_actions) + VIRTIO_NET_FF_ACTION_MAX);
131 if (err)
132 goto err_ff_action;
133
134 ethtool_group.group_priority = cpu_to_le16(VIRTNET_FF_ETHTOOL_GROUP_PRIORITY);
135
136 /* Use priority for the object ID. */
137 err = virtio_device_object_create(vdev,
138 VIRTIO_NET_RESOURCE_OBJ_FF_GROUP,
139 VIRTNET_FF_ETHTOOL_GROUP_PRIORITY,
140 ðtool_group,
141 sizeof(ethtool_group)); 142 if (err)
143 goto err_ff_action;
144
145 ff->vdev = vdev;
146 ff->ff_supported = true;
147
148 return;
149
150 err_ff_action:
151 kfree(ff->ff_actions);
152 err_ff_mask:
153 kfree(ff->ff_mask);
154 err_ff:
155 kfree(ff->ff_caps);
156 }
157
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 6/11 virtio_net: Implement layer 2 ethtool flow rules
In reply to Daniel JurgensFiltering a flow requires a classifier to match the packets, and a rule to filter on the matches.
A classifier consists of one or more selectors. There is one selector per header type. A selector must only use fields set in the selector capabality. If partial matching is supported, the classifier mask for a particular field can be a subset of the mask for that field in the capability.
The rule consists of a priority, an action and a key. The key is a byte array containing headers corresponding to the selectors in the classifier.
This patch implements ethtool rules for ethernet headers.
Example:
$ ethtool -U ens9 flow-type ether dst 08:11:22:33:44:54 action 30 Added rule with ID 1
The rule in the example directs received packets with the specified destination MAC address to rq 30.
--- drivers/net/virtio_net/virtio_net_ff.c | 421 +++++++++++++++++++++++ drivers/net/virtio_net/virtio_net_ff.h | 14 + drivers/net/virtio_net/virtio_net_main.c | 16 + include/uapi/linux/virtio_net_ff.h | 20 ++ 4 files changed, 471 insertions(+)
drivers/net/virtio_net/virtio_net_ff.c +421 -0
@@ -9,6 +9,416 @@#define VIRTNET_FF_ETHTOOL_GROUP_PRIORITY 1#define VIRTNET_FF_MAX_GROUPS 1 +struct virtnet_ethtool_rule { +struct ethtool_rx_flow_spec flow_spec; +u32 classifier_id; +}; + +/* New fields must be added before the classifier struct */ +struct virtnet_classifier { +size_t size; +u32 id; +struct virtio_net_resource_obj_ff_classifier classifier; +}; + +static bool check_mask_vs_cap (const void *m,const void *c, +u16 len,bool partial) +{ +const u8 *mask = m; +const u8 *cap = c; +int i; + +for (i =0 ; i < len; i++) { +if (partial && ((mask[i] & cap[i]) != mask[i])) +return false; +if (!partial && mask[i] != cap[i]) +return false; + } + +return true; +} + +static +struct virtio_net_ff_selector *get_selector_cap (const struct virtnet_ff *ff, +u8 selector_type) +{ +struct virtio_net_ff_selector *sel; +u8 *buf; +int i; + + buf = (u8 *)&ff->ff_mask->selectors; + sel = (struct virtio_net_ff_selector *)buf; + +for (i =0 ; i < ff->ff_mask->count; i++) { +if (sel->type == selector_type) +return sel; + + buf +=sizeof (struct virtio_net_ff_selector ) + sel->length; + sel = (struct virtio_net_ff_selector *)buf; + } + +return NULL ; +} + +static bool validate_eth_mask (const struct virtnet_ff *ff, +const struct virtio_net_ff_selector *sel, +const struct virtio_net_ff_selector *sel_cap) +{ +bool partial_mask = !!(sel_cap->flags &VIRTIO_NET_FF_MASK_F_PARTIAL_MASK ); +struct ethhdr *cap, *mask; +struct ethhdr zeros = {0 }; + + cap = (struct ethhdr *)&sel_cap->mask; + mask = (struct ethhdr *)&sel->mask; + +if (memcmp (&zeros.h_dest, mask->h_dest,sizeof (zeros.h_dest)) && + !check_mask_vs_cap (mask->h_dest, cap->h_dest, +sizeof (mask->h_dest), partial_mask)) +return false; + +if (memcmp (&zeros.h_source, mask->h_source,sizeof (zeros.h_source)) && + !check_mask_vs_cap (mask->h_source, cap->h_source, +sizeof (mask->h_source), partial_mask)) +return false; + +if (mask->h_proto && + !check_mask_vs_cap (&mask->h_proto, &cap->h_proto, +sizeof (__be16), partial_mask)) +return false; + +return true; +} + +static bool validate_mask (const struct virtnet_ff *ff, +const struct virtio_net_ff_selector *sel) +{ +struct virtio_net_ff_selector *sel_cap =get_selector_cap (ff, sel->type); + +if (!sel_cap) +return false; + +switch (sel->type) { +case VIRTIO_NET_FF_MASK_TYPE_ETH : +return validate_eth_mask (ff, sel, sel_cap); + } + +return false; +} + +static int setup_classifier (struct virtnet_ff *ff,struct virtnet_classifier *c) +{ +int err; + + err =xa_alloc (&ff->classifiers, &c->id, c, +XA_LIMIT (0 , ff->ff_caps->classifiers_limit -1 ), +GFP_KERNEL ); +if (err) +return err; + + err =virtio_device_object_create (ff->vdev, +VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER , + c->id, + &c->classifier, + c->size); +if (err) + goto err_xarray; + +return 0 ; + +err_xarray: +xa_erase (&ff->classifiers, c->id); + +return err; +} + +static void destroy_classifier (struct virtnet_ff *ff, +u32 classifier_id) +{ +struct virtnet_classifier *c; + + c =xa_load (&ff->classifiers, classifier_id); +if (c) { +virtio_device_object_destroy (ff->vdev, +VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER , + c->id); + +xa_erase (&ff->classifiers, c->id); +kfree (c); + } +} + +static void destroy_ethtool_rule (struct virtnet_ff *ff, +struct virtnet_ethtool_rule *eth_rule) +{ + ff->ethtool.num_rules--; + +virtio_device_object_destroy (ff->vdev, +VIRTIO_NET_RESOURCE_OBJ_FF_RULE , + eth_rule->flow_spec.location); + +xa_erase (&ff->ethtool.rules, eth_rule->flow_spec.location); +destroy_classifier (ff, eth_rule->classifier_id); +kfree (eth_rule); +} + +static int insert_rule (struct virtnet_ff *ff, +struct virtnet_ethtool_rule *eth_rule, +u32 classifier_id, +const u8 *key, +size_t key_size) +{ +struct ethtool_rx_flow_spec *fs = ð_rule->flow_spec; +struct virtio_net_resource_obj_ff_rule *ff_rule; +int err; + + ff_rule =kzalloc (sizeof (*ff_rule) + key_size,GFP_KERNEL ); +if (!ff_rule) { + err = -ENOMEM ; + goto err_eth_rule; + } +/* +* Intentionally leave the priority as 0. All rules have the same +* priority. +*/ + ff_rule->group_id =cpu_to_le32 (VIRTNET_FF_ETHTOOL_GROUP_PRIORITY ); + ff_rule->classifier_id =cpu_to_le32 (classifier_id); + ff_rule->key_length = (u8 )key_size; + ff_rule->action = fs->ring_cookie ==RX_CLS_FLOW_DISC ? +VIRTIO_NET_FF_ACTION_DROP : +VIRTIO_NET_FF_ACTION_RX_VQ ; + ff_rule->vq_index = fs->ring_cookie !=RX_CLS_FLOW_DISC ? + fs->ring_cookie :0 ; +memcpy (&ff_rule->keys, key, key_size); + + err =virtio_device_object_create (ff->vdev, +VIRTIO_NET_RESOURCE_OBJ_FF_RULE , + fs->location, + ff_rule, +sizeof (*ff_rule) + key_size); +if (err) + goto err_ff_rule; + + eth_rule->classifier_id = classifier_id; + ff->ethtool.num_rules++; +kfree (ff_rule); + +return 0 ; + +err_ff_rule: +kfree (ff_rule); +err_eth_rule: +xa_erase (&ff->ethtool.rules, eth_rule->flow_spec.location); +kfree (eth_rule); + +return err; +} + +static u32 flow_type_mask (u32 flow_type) +{ +return flow_type & ~(FLOW_EXT |FLOW_MAC_EXT |FLOW_RSS ); +} + +static bool supported_flow_type (const struct ethtool_rx_flow_spec *fs) +{ +switch (fs->flow_type) { +case ETHER_FLOW : +return true; + } + +return false; +} + +static int validate_flow_input (struct virtnet_ff *ff, +const struct ethtool_rx_flow_spec *fs, +u16 curr_queue_pairs) +{ +/* Force users to use RX_CLS_LOC_ANY - don't allow specific locations */ +if (fs->location !=RX_CLS_LOC_ANY ) +return -EOPNOTSUPP ; + +if (fs->ring_cookie !=RX_CLS_FLOW_DISC && + fs->ring_cookie >= curr_queue_pairs) +return -EINVAL ; + +if (fs->flow_type !=flow_type_mask (fs->flow_type)) +return -EOPNOTSUPP ; + +if (!supported_flow_type (fs)) +return -EOPNOTSUPP ; + +return 0 ; +} + +static void calculate_flow_sizes (struct ethtool_rx_flow_spec *fs, +size_t *key_size,size_t *classifier_size, +int *num_hdrs) +{ + *num_hdrs =1 ; + *key_size =sizeof (struct ethhdr ); +/* +* The classifier size is the size of the classifier header, a selector +* header for each type of header in the match critea, and each header +* providing the mask for matching against. +*/ + *classifier_size = *key_size + +sizeof (struct virtio_net_resource_obj_ff_classifier ) + +sizeof (struct virtio_net_ff_selector ) * (*num_hdrs); +} + +static void setup_eth_hdr_key_mask (struct virtio_net_ff_selector *selector, +u8 *key, +const struct ethtool_rx_flow_spec *fs) +{ +struct ethhdr *eth_m = (struct ethhdr *)&selector->mask; +struct ethhdr *eth_k = (struct ethhdr *)key; + + selector->type =VIRTIO_NET_FF_MASK_TYPE_ETH ; + selector->length =sizeof (struct ethhdr ); + +memcpy (eth_m, &fs->m_u.ether_spec,sizeof (*eth_m)); +memcpy (eth_k, &fs->h_u.ether_spec,sizeof (*eth_k)); +} + +static int +validate_classifier_selectors (struct virtnet_ff *ff, +struct virtio_net_resource_obj_ff_classifier *classifier, +int num_hdrs) +{ +struct virtio_net_ff_selector *selector = classifier->selectors; + +for (int i =0 ; i < num_hdrs; i++) { +if (!validate_mask (ff, selector)) +return -EINVAL ; + + selector = (struct virtio_net_ff_selector *)(((u8 *)selector) + +sizeof (*selector) + selector->length); + } + +return 0 ; +} + +static int build_and_insert (struct virtnet_ff *ff, +struct virtnet_ethtool_rule *eth_rule) +{ +struct virtio_net_resource_obj_ff_classifier *classifier; +struct ethtool_rx_flow_spec *fs = ð_rule->flow_spec; +struct virtio_net_ff_selector *selector; +struct virtnet_classifier *c; +size_t classifier_size; +size_t key_size; +int num_hdrs; +u8 *key; +int err; + +calculate_flow_sizes (fs, &key_size, &classifier_size, &num_hdrs); + + key =kzalloc (key_size,GFP_KERNEL ); +if (!key) +return -ENOMEM ; + +/* +* virio_net_ff_obj_ff_classifier is already included in the +* classifier_size. +*/ + c =kzalloc (classifier_size + +sizeof (struct virtnet_classifier ) - +sizeof (struct virtio_net_resource_obj_ff_classifier ), +GFP_KERNEL ); +if (!c) +return -ENOMEM ; + + c->size = classifier_size; + classifier = &c->classifier; + classifier->count = num_hdrs; + selector = &classifier->selectors[0 ]; + +setup_eth_hdr_key_mask (selector, key, fs); + + err =validate_classifier_selectors (ff, classifier, num_hdrs); +if (err) + goto err_key; + + err =setup_classifier (ff, c); +if (err) + goto err_classifier; + + err =insert_rule (ff, eth_rule, c->id, key, key_size); +if (err) { +destroy_classifier (ff, c->id); + goto err_key; + } + +return 0 ; + +err_classifier: +kfree (c); +err_key: +kfree (key); + +return err; +} + +int virtnet_ethtool_flow_insert (struct virtnet_ff *ff, +struct ethtool_rx_flow_spec *fs, +u16 curr_queue_pairs) +{ +struct virtnet_ethtool_rule *eth_rule; +int err; + +if (!ff->ff_supported) +return -EOPNOTSUPP ; + + err =validate_flow_input (ff, fs, curr_queue_pairs); +if (err) +return err; + + eth_rule =kzalloc (sizeof (*eth_rule),GFP_KERNEL ); +if (!eth_rule) +return -ENOMEM ; + + err =xa_alloc (&ff->ethtool.rules, &fs->location, eth_rule, +XA_LIMIT (0 , ff->ff_caps->rules_limit -1 ), +GFP_KERNEL ); +if (err) + goto err_rule; + + eth_rule->flow_spec = *fs; + + err =build_and_insert (ff, eth_rule); +if (err) + goto err_xa; + +return err; + +err_xa: +xa_erase (&ff->ethtool.rules, eth_rule->flow_spec.location); + +err_rule: + fs->location =RX_CLS_LOC_ANY ; +kfree (eth_rule); + +return err; +} + +int virtnet_ethtool_flow_remove (struct virtnet_ff *ff,int location) +{ +struct virtnet_ethtool_rule *eth_rule; +int err =0 ; + +if (!ff->ff_supported) +return -EOPNOTSUPP ; + + eth_rule =xa_load (&ff->ethtool.rules, location); +if (!eth_rule) { + err = -ENOENT ; + goto out; + } + +destroy_ethtool_rule (ff, eth_rule); +out: +return err; +} +static size_t get_mask_size (u16 type) {switch (type) {
@@ -142,6 +552,8 @@ void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)if (err) goto err_ff_action; +xa_init_flags (&ff->classifiers,XA_FLAGS_ALLOC ); +xa_init_flags (&ff->ethtool.rules,XA_FLAGS_ALLOC ); ff->vdev = vdev; ff->ff_supported = true;
@@ -157,9 +569,18 @@ void virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)void virtnet_ff_cleanup (struct virtnet_ff *ff) { +struct virtnet_ethtool_rule *eth_rule; +unsigned long i; +if (!ff->ff_supported)return ; +xa_for_each (&ff->ethtool.rules, i, eth_rule) +destroy_ethtool_rule (ff, eth_rule); + +xa_destroy (&ff->ethtool.rules); +xa_destroy (&ff->classifiers); +virtio_device_object_destroy (ff->vdev,VIRTIO_NET_RESOURCE_OBJ_FF_GROUP ,VIRTNET_FF_ETHTOOL_GROUP_PRIORITY );
drivers/net/virtio_net/virtio_net_ff.h +14 -0
@@ -3,20 +3,34 @@* Header file for virtio_net flow filters */ #include <linux/virtio_admin.h> +#include <uapi/linux/ethtool.h> #ifndef _VIRTIO_NET_FF_H#define _VIRTIO_NET_FF_H +struct virtnet_ethtool_ff { +struct xarray rules; +int num_rules; +}; +struct virtnet_ff {struct virtio_device *vdev;bool ff_supported;struct virtio_net_ff_cap_data *ff_caps;struct virtio_net_ff_cap_mask_data *ff_mask;struct virtio_net_ff_actions *ff_actions; +struct xarray classifiers; +int num_classifiers; +struct virtnet_ethtool_ff ethtool; };void virtnet_ff_init (struct virtnet_ff *ff,struct virtio_device *vdev);void virtnet_ff_cleanup (struct virtnet_ff *ff); +int virtnet_ethtool_flow_insert (struct virtnet_ff *ff, +struct ethtool_rx_flow_spec *fs, +u16 curr_queue_pairs); +int virtnet_ethtool_flow_remove (struct virtnet_ff *ff,int location); +#endif /* _VIRTIO_NET_FF_H */
drivers/net/virtio_net/virtio_net_main.c +16 -0
@@ -5629,6 +5629,21 @@ static int virtnet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,return rc; } +static int virtnet_set_rxnfc (struct net_device *dev,struct ethtool_rxnfc *info) +{ +struct virtnet_info *vi =netdev_priv (dev); + +switch (info->cmd) { +case ETHTOOL_SRXCLSRLINS : +return virtnet_ethtool_flow_insert (&vi->ff, &info->fs, + vi->curr_queue_pairs); +case ETHTOOL_SRXCLSRLDEL : +return virtnet_ethtool_flow_remove (&vi->ff, info->fs.location); + } + +return -EOPNOTSUPP ; +} +static const struct ethtool_ops virtnet_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_MAX_FRAMES |ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_USE_ADAPTIVE_RX ,
@@ -5655,6 +5670,7 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .get_rxfh_fields = virtnet_get_hashflow, .set_rxfh_fields = virtnet_set_hashflow, .get_rxnfc = virtnet_get_rxnfc, + .set_rxnfc = virtnet_set_rxnfc, }; static void virtnet_get_queue_stats_rx(struct net_device *dev, int i,
include/uapi/linux/virtio_net_ff.h +20 -0
@@ -13,6 +13,8 @@#define VIRTIO_NET_FF_ACTION_CAP 0x802#define VIRTIO_NET_RESOURCE_OBJ_FF_GROUP 0x0200 +#define VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER 0x0201 +#define VIRTIO_NET_RESOURCE_OBJ_FF_RULE 0x0202struct virtio_net_ff_cap_data {__le32 groups_limit;
@@ -59,4 +61,22 @@ struct virtio_net_resource_obj_ff_group { __le16 group_priority; }; +struct virtio_net_resource_obj_ff_classifier { +__u8 count; +__u8 reserved[7 ]; +struct virtio_net_ff_selector selectors[]; +}; + +struct virtio_net_resource_obj_ff_rule { +__le32 group_id; +__le32 classifier_id; +__u8 rule_priority; +__u8 key_length;/* length of key in bytes */ +__u8 action; +__u8 reserved; +__le16 vq_index; +__u8 reserved1[2 ]; +__u8 keys[]; +}; +#endif
Signature · 1 line
2.50.1
kernel test robot
build botRe: [PATCH net-next 06/11] virtio_net: Implement layer 2 ethtool flow rules
kernel test robot noticed the following build warnings:
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-7-danielj%40nvidia.com patch subject: [PATCH net-next 06/11] virtio_net: Implement layer 2 ethtool flow rules config: x86_64-randconfig-121-20250828 (https://download.01.org/0day-ci/archive/20250829/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250829/[email protected]/reproduce)
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
drivers/net/virtio_net/virtio_net_ff.c: note: in included file (through include/linux/virtio_admin.h):
include/uapi/linux/virtio_net_ff.h:47:48: sparse: sparse: array of flexible structures include/uapi/linux/virtio_net_ff.h:67:48: sparse: sparse: array of flexible structures drivers/net/virtio_net/virtio_net_ff.c:113:24: sparse: sparse: restricted __le32 degrades to integer
>> drivers/net/virtio_net/virtio_net_ff.c:189:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le16 [usertype] vq_index @@ got unsigned long long @@
drivers/net/virtio_net/virtio_net_ff.c:189:27: sparse: expected restricted __le16 [usertype] vq_index
drivers/net/virtio_net/virtio_net_ff.c:189:27: sparse: got unsigned long long
drivers/net/virtio_net/virtio_net_ff.c:380:24: sparse: sparse: restricted __le32 degrades to integer drivers/net/virtio_net/virtio_net_ff.c:509:13: sparse: sparse: restricted __le32 degrades to integer drivers/net/virtio_net/virtio_net_ff.c:509:13: sparse: sparse: cast to restricted __le32
drivers/net/virtio_net/virtio_net_ff.c:513:35: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] groups_limit @@ got int @@
drivers/net/virtio_net/virtio_net_ff.c:513:35: sparse: expected restricted __le32 [usertype] groups_limit
drivers/net/virtio_net/virtio_net_ff.c:513:35: sparse: got int
vim +189 drivers/net/virtio_net/virtio_net_ff.c
163
164 static int insert_rule(struct virtnet_ff *ff,
165 struct virtnet_ethtool_rule *eth_rule,
166 u32 classifier_id,
167 const u8 *key,
168 size_t key_size)
169 {
170 struct ethtool_rx_flow_spec *fs = ð_rule->flow_spec;
171 struct virtio_net_resource_obj_ff_rule *ff_rule;
172 int err;
173
174 ff_rule = kzalloc(sizeof(*ff_rule) + key_size, GFP_KERNEL);
175 if (!ff_rule) {
176 err = -ENOMEM;
177 goto err_eth_rule;
178 }
179 /*
180 * Intentionally leave the priority as 0. All rules have the same
181 * priority.
182 */
183 ff_rule->group_id = cpu_to_le32(VIRTNET_FF_ETHTOOL_GROUP_PRIORITY);
184 ff_rule->classifier_id = cpu_to_le32(classifier_id);
185 ff_rule->key_length = (u8)key_size;
186 ff_rule->action = fs->ring_cookie == RX_CLS_FLOW_DISC ?
187 VIRTIO_NET_FF_ACTION_DROP :
188 VIRTIO_NET_FF_ACTION_RX_VQ;
> 189 ff_rule->vq_index = fs->ring_cookie != RX_CLS_FLOW_DISC ?
190 fs->ring_cookie : 0;
191 memcpy(&ff_rule->keys, key, key_size);
192
193 err = virtio_device_object_create(ff->vdev,
194 VIRTIO_NET_RESOURCE_OBJ_FF_RULE,
195 fs->location,
196 ff_rule,
197 sizeof(*ff_rule) + key_size); 198 if (err)
199 goto err_ff_rule;
200
201 eth_rule->classifier_id = classifier_id;
202 ff->ethtool.num_rules++;
203 kfree(ff_rule);
204
205 return 0;
206
207 err_ff_rule:
208 kfree(ff_rule);
209 err_eth_rule:
210 xa_erase(&ff->ethtool.rules, eth_rule->flow_spec.location);
211 kfree(eth_rule);
212
213 return err;
214 }
215
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next 06/11] virtio_net: Implement layer 2 ethtool flow rules
In reply to Daniel Jurgensdrivers/net/virtio_net/virtio_net_ff.c line 260
Quoted 11 lines
drivers/net/virtio_net/virtio_net_ff.c +9
-0+static void calculate_flow_sizes (struct ethtool_rx_flow_spec *fs, +size_t *key_size,size_t *classifier_size, +int *num_hdrs) +{ + *num_hdrs =1 ; + *key_size =sizeof (struct ethhdr ); +/* +* The classifier size is the size of the classifier header, a selector +* header for each type of header in the match critea, and each header
typo critea -> criteria
Quoted 50 lines
drivers/net/virtio_net/virtio_net_ff.c +50
-0+* providing the mask for matching against. +*/ + *classifier_size = *key_size + +sizeof (struct virtio_net_resource_obj_ff_classifier ) + +sizeof (struct virtio_net_ff_selector ) * (*num_hdrs); +} + +static void setup_eth_hdr_key_mask (struct virtio_net_ff_selector *selector, +u8 *key, +const struct ethtool_rx_flow_spec *fs) +{ +struct ethhdr *eth_m = (struct ethhdr *)&selector->mask; +struct ethhdr *eth_k = (struct ethhdr *)key; + + selector->type =VIRTIO_NET_FF_MASK_TYPE_ETH ; + selector->length =sizeof (struct ethhdr ); + +memcpy (eth_m, &fs->m_u.ether_spec,sizeof (*eth_m)); +memcpy (eth_k, &fs->h_u.ether_spec,sizeof (*eth_k)); +} + +static int +validate_classifier_selectors (struct virtnet_ff *ff, +struct virtio_net_resource_obj_ff_classifier *classifier, +int num_hdrs) +{ +struct virtio_net_ff_selector *selector = classifier->selectors; + +for (int i =0 ; i < num_hdrs; i++) { +if (!validate_mask (ff, selector)) +return -EINVAL ; + + selector = (struct virtio_net_ff_selector *)(((u8 *)selector) + +sizeof (*selector) + selector->length); + } + +return 0 ; +} + +static int build_and_insert (struct virtnet_ff *ff, +struct virtnet_ethtool_rule *eth_rule) +{ +struct virtio_net_resource_obj_ff_classifier *classifier; +struct ethtool_rx_flow_spec *fs = ð_rule->flow_spec; +struct virtio_net_ff_selector *selector; +struct virtnet_classifier *c; +size_t classifier_size; +size_t key_size; +int num_hdrs; +u8 *key;
drivers/net/virtio_net/virtio_net_ff.c line 320
Quoted 10 lines
drivers/net/virtio_net/virtio_net_ff.c +10
-0+int err; + +calculate_flow_sizes (fs, &key_size, &classifier_size, &num_hdrs); + + key =kzalloc (key_size,GFP_KERNEL ); +if (!key) +return -ENOMEM ; + +/* +* virio_net_ff_obj_ff_classifier is already included in the
virio_net_ff_obj_ff_classifier -> virtio_net_ff_obj_ff_classifier
drivers/net/virtio_net/virtio_net_ff.c line 328
Quoted 8 lines
drivers/net/virtio_net/virtio_net_ff.c +8
-0+* classifier_size. +*/ + c =kzalloc (classifier_size + +sizeof (struct virtnet_classifier ) - +sizeof (struct virtio_net_resource_obj_ff_classifier ), +GFP_KERNEL ); +if (!c) +return -ENOMEM ;
kfree(key) before returning -ENOMEM
Quoted 22 lines
drivers/net/virtio_net/virtio_net_ff.c +22
-0+ + c->size = classifier_size; + classifier = &c->classifier; + classifier->count = num_hdrs; + selector = &classifier->selectors[0 ]; + +setup_eth_hdr_key_mask (selector, key, fs); + + err =validate_classifier_selectors (ff, classifier, num_hdrs); +if (err) + goto err_key; + + err =setup_classifier (ff, c); +if (err) + goto err_classifier; + + err =insert_rule (ff, eth_rule, c->id, key, key_size); +if (err) { +destroy_classifier (ff, c->id); + goto err_key; + } +
drivers/net/virtio_net/virtio_net_ff.c line 360
Quoted 10 lines
drivers/net/virtio_net/virtio_net_ff.c +10
-0+return 0 ; + +err_classifier: +kfree (c); +err_key: +kfree (key); + +return err; +} +
Thanks,
Alok
Re: [PATCH net-next 06/11] virtio_net: Implement layer 2 ethtool flow rules
Quoted 31 lines · ALOK TIWARI
Quoted 5 lines
+static void calculate_flow_sizes(struct
ethtool_rx_flow_spec*fs, + * header for each type of header in the match critea, and each headertypo critea -> criteria
drivers/net/virtio_net/virtio_net_ff.c line 320
Quoted 11 lines
+ * providing the mask for matching against.
+ */+
calculate_flow_sizes(fs, &key_size, &classifier_size, &num_hdrs);drivers/net/virtio_net/virtio_net_ff.c +7
-0+ + key = kzalloc(key_size, GFP_KERNEL); + if (!key) + return -ENOMEM; + + /* +* virio_net_ff_obj_ff_classifier is already included in the
virio_net_ff_obj_ff_classifier->virtio_net_ff_obj_ff_classifierQuoted 8 lines
+ *
classifier_size.
+ */
+ c = kzalloc(classifier_size +
+sizeof(struct virtnet_classifier)-
+sizeof(struct virtio_net_resource_obj_ff_classifier), +GFP_KERNEL);
+ if (!c)
+ return-ENOMEM;
Quoted 6 lines
kfree(key) before returning
-ENOMEMThanks,
Alok
Thanks Alok. Applied those changes for v2.
PATCH 7/11 virtio_net: Use existing classifier if possible
In reply to Daniel JurgensClassifiers can be used by more than one rule. If there is an exisitng classifier, use it instead of creating a new one.
--- drivers/net/virtio_net/virtio_net_ff.c | 39 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 12 deletions(-)
drivers/net/virtio_net/virtio_net_ff.c +27 -12
@@ -17,6 +17,7 @@ struct virtnet_ethtool_rule {/* New fields must be added before the classifier struct */ struct virtnet_classifier {size_t size; +refcount_t refcount;u32 id;struct virtio_net_resource_obj_ff_classifier classifier; };
@@ -105,11 +106,24 @@ static bool validate_mask(const struct virtnet_ff *ff,return false; } -static int setup_classifier (struct virtnet_ff *ff,struct virtnet_classifier *c) +static int setup_classifier (struct virtnet_ff *ff, +struct virtnet_classifier **c) { +struct virtnet_classifier *tmp; +unsigned long i;int err; - err =xa_alloc (&ff->classifiers, &c->id, c, +xa_for_each (&ff->classifiers, i, tmp) { +if ((*c)->size == tmp->size && + !memcmp (&tmp->classifier, &(*c)->classifier, tmp->size)) { +refcount_inc (&tmp->refcount); +kfree (*c); + *c = tmp; + goto out; + } + } + + err =xa_alloc (&ff->classifiers, &(*c)->id, *c,XA_LIMIT (0 , ff->ff_caps->classifiers_limit -1 ),GFP_KERNEL );if (err)
@@ -117,27 +131,28 @@ static int setup_classifier(struct virtnet_ff *ff, struct virtnet_classifier *c) err =virtio_device_object_create (ff->vdev,VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER , - c->id, - &c->classifier, - c->size); + (*c)->id, + &(*c)->classifier, + (*c)->size);if (err) goto err_xarray; +refcount_set (&(*c)->refcount,1 ); +out:return 0 ; err_xarray: -xa_erase (&ff->classifiers, c->id); +xa_erase (&ff->classifiers, (*c)->id);return err; } -static void destroy_classifier (struct virtnet_ff *ff, -u32 classifier_id) +static void try_destroy_classifier (struct virtnet_ff *ff,u32 classifier_id) {struct virtnet_classifier *c; c =xa_load (&ff->classifiers, classifier_id); -if (c) { +if (c &&refcount_dec_and_test (&c->refcount)) {virtio_device_object_destroy (ff->vdev,VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER , c->id);
@@ -157,7 +172,7 @@ static void destroy_ethtool_rule(struct virtnet_ff *ff, eth_rule->flow_spec.location);xa_erase (&ff->ethtool.rules, eth_rule->flow_spec.location); -destroy_classifier (ff, eth_rule->classifier_id); +try_destroy_classifier (ff, eth_rule->classifier_id);kfree (eth_rule); }
@@ -338,13 +353,13 @@ static int build_and_insert(struct virtnet_ff *ff,if (err) goto err_key; - err =setup_classifier (ff, c); + err =setup_classifier (ff, &c);if (err) goto err_classifier; err =insert_rule (ff, eth_rule, c->id, key, key_size);if (err) { -destroy_classifier (ff, c->id); +try_destroy_classifier (ff, c->id); goto err_key; }
Signature · 1 line
2.50.1
PATCH 8/11 virtio_net: Implement IPv4 ethtool flow rules
In reply to Daniel JurgensAdd support for IP_USER type rules from ethtool.
Example:
$ ethtool -U ens9 flow-type ip4 src-ip 192.168.51.101 action -1 Added rule with ID 1
The example rule will drop packets with the source IP specified.
--- drivers/net/virtio_net/virtio_net_ff.c | 127 +++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 8 deletions(-)
drivers/net/virtio_net/virtio_net_ff.c +119 -8
@@ -90,6 +90,34 @@ static bool validate_eth_mask(const struct virtnet_ff *ff,return true; } +static bool validate_ip4_mask (const struct virtnet_ff *ff, +const struct virtio_net_ff_selector *sel, +const struct virtio_net_ff_selector *sel_cap) +{ +bool partial_mask = !!(sel_cap->flags &VIRTIO_NET_FF_MASK_F_PARTIAL_MASK ); +struct iphdr *cap, *mask; + + cap = (struct iphdr *)&sel_cap->mask; + mask = (struct iphdr *)&sel->mask; + +if (mask->saddr && + !check_mask_vs_cap (&mask->saddr, &cap->saddr, +sizeof (__be32), partial_mask)) +return false; + +if (mask->daddr && + !check_mask_vs_cap (&mask->daddr, &cap->daddr, +sizeof (__be32), partial_mask)) +return false; + +if (mask->protocol && + !check_mask_vs_cap (&mask->protocol, &cap->protocol, +sizeof (u8), partial_mask)) +return false; + +return true; +} +static bool validate_mask (const struct virtnet_ff *ff,const struct virtio_net_ff_selector *sel) {
@@ -101,11 +129,36 @@ static bool validate_mask(const struct virtnet_ff *ff,switch (sel->type) {case VIRTIO_NET_FF_MASK_TYPE_ETH :return validate_eth_mask (ff, sel, sel_cap); + +case VIRTIO_NET_FF_MASK_TYPE_IPV4 : +return validate_ip4_mask (ff, sel, sel_cap); }return false; } +static void parse_ip4 (struct iphdr *mask,struct iphdr *key, +const struct ethtool_rx_flow_spec *fs) +{ +const struct ethtool_usrip4_spec *l3_mask = &fs->m_u.usr_ip4_spec; +const struct ethtool_usrip4_spec *l3_val = &fs->h_u.usr_ip4_spec; + + mask->saddr = l3_mask->ip4src; + mask->daddr = l3_mask->ip4dst; + key->saddr = l3_val->ip4src; + key->daddr = l3_val->ip4dst; + +if (mask->protocol) { + mask->protocol = l3_mask->proto; + key->protocol = l3_val->proto; + } +} + +static bool has_ipv4 (u32 flow_type) +{ +return flow_type ==IP_USER_FLOW ; +} +static int setup_classifier (struct virtnet_ff *ff,struct virtnet_classifier **c) {
@@ -237,6 +290,7 @@ static bool supported_flow_type(const struct ethtool_rx_flow_spec *fs) {switch (fs->flow_type) {case ETHER_FLOW : +case IP_USER_FLOW :return true; }
@@ -260,16 +314,27 @@ static int validate_flow_input(struct virtnet_ff *ff,if (!supported_flow_type (fs))return -EOPNOTSUPP ; -return 0 ; }static void calculate_flow_sizes (struct ethtool_rx_flow_spec *fs, -size_t *key_size,size_t *classifier_size, -int *num_hdrs) +size_t *key_size,size_t *classifier_size, +int *num_hdrs) { +size_t size =sizeof (struct ethhdr ); + *num_hdrs =1 ; *key_size =sizeof (struct ethhdr ); + +if (fs->flow_type ==ETHER_FLOW ) + goto done; + + (*num_hdrs)++; +if (has_ipv4 (fs->flow_type)) + size +=sizeof (struct iphdr ); + +done: + *key_size = size;/* * The classifier size is the size of the classifier header, a selector * header for each type of header in the match critea, and each header
@@ -281,8 +346,9 @@ static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs, }static void setup_eth_hdr_key_mask (struct virtio_net_ff_selector *selector, -u8 *key, -const struct ethtool_rx_flow_spec *fs) +u8 *key, +const struct ethtool_rx_flow_spec *fs, +int num_hdrs) {struct ethhdr *eth_m = (struct ethhdr *)&selector->mask;struct ethhdr *eth_k = (struct ethhdr *)key;
@@ -290,8 +356,33 @@ static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector, selector->type =VIRTIO_NET_FF_MASK_TYPE_ETH ; selector->length =sizeof (struct ethhdr ); -memcpy (eth_m, &fs->m_u.ether_spec,sizeof (*eth_m)); -memcpy (eth_k, &fs->h_u.ether_spec,sizeof (*eth_k)); +if (num_hdrs >1 ) { + eth_m->h_proto =cpu_to_be16 (0xffff ); + eth_k->h_proto =ETH_P_IP ; + }else { +memcpy (eth_m, &fs->m_u.ether_spec,sizeof (*eth_m)); +memcpy (eth_k, &fs->h_u.ether_spec,sizeof (*eth_k)); + } +} + +static int setup_ip_key_mask (struct virtio_net_ff_selector *selector, +u8 *key, +const struct ethtool_rx_flow_spec *fs) +{ +struct iphdr *v4_m = (struct iphdr *)&selector->mask; +struct iphdr *v4_k = (struct iphdr *)key; + + selector->type =VIRTIO_NET_FF_MASK_TYPE_IPV4 ; + selector->length =sizeof (struct iphdr ); + +if (fs->h_u.usr_ip4_spec.l4_4_bytes || + fs->h_u.usr_ip4_spec.tos || + fs->h_u.usr_ip4_spec.ip_ver !=ETH_RX_NFC_IP4 ) +return -EOPNOTSUPP ; + +parse_ip4 (v4_m, v4_k, fs); + +return 0 ; } static int
@@ -312,6 +403,17 @@ validate_classifier_selectors(struct virtnet_ff *ff,return 0 ; } +static +struct virtio_net_ff_selector *next_selector (struct virtio_net_ff_selector *sel) +{ +void *nextsel; + + nextsel = (u8 *)sel +sizeof (struct virtio_net_ff_selector ) + + sel->length; + +return nextsel; +} +static int build_and_insert (struct virtnet_ff *ff,struct virtnet_ethtool_rule *eth_rule) {
@@ -347,8 +449,17 @@ static int build_and_insert(struct virtnet_ff *ff, classifier->count = num_hdrs; selector = &classifier->selectors[0 ]; -setup_eth_hdr_key_mask (selector, key, fs); +setup_eth_hdr_key_mask (selector, key, fs, num_hdrs); +if (num_hdrs ==1 ) + goto validate; + + selector =next_selector (selector); + + err =setup_ip_key_mask (selector, key +sizeof (struct ethhdr ), fs); +if (err) + goto err_classifier; +validate: err =validate_classifier_selectors (ff, classifier, num_hdrs);if (err) goto err_key;
Signature · 1 line
2.50.1
kernel test robot
build botRe: [PATCH net-next 08/11] virtio_net: Implement IPv4 ethtool flow rules
kernel test robot noticed the following build warnings:
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-9-danielj%40nvidia.com patch subject: [PATCH net-next 08/11] virtio_net: Implement IPv4 ethtool flow rules config: x86_64-randconfig-121-20250828 (https://download.01.org/0day-ci/archive/20250829/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250829/[email protected]/reproduce)
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
drivers/net/virtio_net/virtio_net_ff.c: note: in included file (through include/linux/virtio_admin.h):
include/uapi/linux/virtio_net_ff.h:47:48: sparse: sparse: array of flexible structures include/uapi/linux/virtio_net_ff.h:67:48: sparse: sparse: array of flexible structures drivers/net/virtio_net/virtio_net_ff.c:180:24: sparse: sparse: restricted __le32 degrades to integer
drivers/net/virtio_net/virtio_net_ff.c:257:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le16 [usertype] vq_index @@ got unsigned long long @@
drivers/net/virtio_net/virtio_net_ff.c:257:27: sparse: expected restricted __le16 [usertype] vq_index
drivers/net/virtio_net/virtio_net_ff.c:257:27: sparse: got unsigned long long
>> drivers/net/virtio_net/virtio_net_ff.c:361:32: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __be16 [usertype] h_proto @@ got int @@
drivers/net/virtio_net/virtio_net_ff.c:361:32: sparse: expected restricted __be16 [usertype] h_proto
drivers/net/virtio_net/virtio_net_ff.c:361:32: sparse: got int
drivers/net/virtio_net/virtio_net_ff.c:506:24: sparse: sparse: restricted __le32 degrades to integer drivers/net/virtio_net/virtio_net_ff.c:635:13: sparse: sparse: restricted __le32 degrades to integer drivers/net/virtio_net/virtio_net_ff.c:635:13: sparse: sparse: cast to restricted __le32
drivers/net/virtio_net/virtio_net_ff.c:639:35: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] groups_limit @@ got int @@
drivers/net/virtio_net/virtio_net_ff.c:639:35: sparse: expected restricted __le32 [usertype] groups_limit
drivers/net/virtio_net/virtio_net_ff.c:639:35: sparse: got int
vim +361 drivers/net/virtio_net/virtio_net_ff.c
347
348 static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector,
349 u8 *key,
350 const struct ethtool_rx_flow_spec *fs,
351 int num_hdrs)
352 {
353 struct ethhdr *eth_m = (struct ethhdr *)&selector->mask;
354 struct ethhdr *eth_k = (struct ethhdr *)key;
355
356 selector->type = VIRTIO_NET_FF_MASK_TYPE_ETH;
357 selector->length = sizeof(struct ethhdr);
358
359 if (num_hdrs > 1) {
360 eth_m->h_proto = cpu_to_be16(0xffff);
> 361 eth_k->h_proto = ETH_P_IP; 362 } else {
363 memcpy(eth_m, &fs->m_u.ether_spec, sizeof(*eth_m));
364 memcpy(eth_k, &fs->h_u.ether_spec, sizeof(*eth_k));
365 }
366 }
367
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 9/11 virtio_net: Add support for IPv6 ethtool steering
In reply to Daniel JurgensImplement support for IPV6_USER_FLOW type rules.
Example:
$ ethtool -U ens9 flow-type ip6 src-ip fe80::2 dst-ip fe80::4 action 3 Added rule with ID 0
The example rule will forward packets with the specified soure and destination IP addresses to RX ring 3.
--- drivers/net/virtio_net/virtio_net_ff.c | 89 +++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 8 deletions(-)
drivers/net/virtio_net/virtio_net_ff.c +81 -8
@@ -118,6 +118,34 @@ static bool validate_ip4_mask(const struct virtnet_ff *ff,return true; } +static bool validate_ip6_mask (const struct virtnet_ff *ff, +const struct virtio_net_ff_selector *sel, +const struct virtio_net_ff_selector *sel_cap) +{ +bool partial_mask = !!(sel_cap->flags &VIRTIO_NET_FF_MASK_F_PARTIAL_MASK ); +struct ipv6hdr *cap, *mask; + + cap = (struct ipv6hdr *)&sel_cap->mask; + mask = (struct ipv6hdr *)&sel->mask; + +if (!ipv6_addr_any (&mask->saddr) && + !check_mask_vs_cap (&mask->saddr, &cap->saddr, +sizeof (cap->saddr), partial_mask)) +return false; + +if (!ipv6_addr_any (&mask->daddr) && + !check_mask_vs_cap (&mask->daddr, &cap->daddr, +sizeof (cap->daddr), partial_mask)) +return false; + +if (mask->nexthdr && + !check_mask_vs_cap (&mask->nexthdr, &cap->nexthdr, +sizeof (cap->nexthdr), partial_mask)) +return false; + +return true; +} +static bool validate_mask (const struct virtnet_ff *ff,const struct virtio_net_ff_selector *sel) {
@@ -132,6 +160,9 @@ static bool validate_mask(const struct virtnet_ff *ff,case VIRTIO_NET_FF_MASK_TYPE_IPV4 :return validate_ip4_mask (ff, sel, sel_cap); + +case VIRTIO_NET_FF_MASK_TYPE_IPV6 : +return validate_ip6_mask (ff, sel, sel_cap); }return false;
@@ -154,11 +185,38 @@ static void parse_ip4(struct iphdr *mask, struct iphdr *key, } } +static void parse_ip6 (struct ipv6hdr *mask,struct ipv6hdr *key, +const struct ethtool_rx_flow_spec *fs) +{ +const struct ethtool_usrip6_spec *l3_mask = &fs->m_u.usr_ip6_spec; +const struct ethtool_usrip6_spec *l3_val = &fs->h_u.usr_ip6_spec; + +if (!ipv6_addr_any ((struct in6_addr *)l3_mask->ip6src)) { +memcpy (&mask->saddr, l3_mask->ip6src,sizeof (mask->saddr)); +memcpy (&key->saddr, l3_val->ip6src,sizeof (key->saddr)); + } + +if (!ipv6_addr_any ((struct in6_addr *)l3_mask->ip6dst)) { +memcpy (&mask->daddr, l3_mask->ip6dst,sizeof (mask->daddr)); +memcpy (&key->daddr, l3_val->ip6dst,sizeof (key->daddr)); + } + +if (l3_mask->l4_proto) { + mask->nexthdr = l3_mask->l4_proto; + key->nexthdr = l3_val->l4_proto; + } +} +static bool has_ipv4 (u32 flow_type) {return flow_type ==IP_USER_FLOW ; } +static bool has_ipv6 (u32 flow_type) +{ +return flow_type ==IPV6_USER_FLOW ; +} +static int setup_classifier (struct virtnet_ff *ff,struct virtnet_classifier **c) {
@@ -291,6 +349,7 @@ static bool supported_flow_type(const struct ethtool_rx_flow_spec *fs)switch (fs->flow_type) {case ETHER_FLOW :case IP_USER_FLOW : +case IPV6_USER_FLOW :return true; }
@@ -332,7 +391,8 @@ static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs, (*num_hdrs)++;if (has_ipv4 (fs->flow_type)) size +=sizeof (struct iphdr ); - +else if (has_ipv6 (fs->flow_type)) + size +=sizeof (struct ipv6hdr ); done: *key_size = size;/*
@@ -369,18 +429,31 @@ static int setup_ip_key_mask(struct virtio_net_ff_selector *selector,u8 *key, const struct ethtool_rx_flow_spec *fs) { + struct ipv6hdr *v6_m = (struct ipv6hdr *)&selector->mask;struct iphdr *v4_m = (struct iphdr *)&selector->mask; +struct ipv6hdr *v6_k = (struct ipv6hdr *)key;struct iphdr *v4_k = (struct iphdr *)key; - selector->type =VIRTIO_NET_FF_MASK_TYPE_IPV4 ; - selector->length =sizeof (struct iphdr ); +if (has_ipv6 (fs->flow_type)) { + selector->type =VIRTIO_NET_FF_MASK_TYPE_IPV6 ; + selector->length =sizeof (struct ipv6hdr ); -if (fs->h_u.usr_ip4_spec.l4_4_bytes || - fs->h_u.usr_ip4_spec.tos || - fs->h_u.usr_ip4_spec.ip_ver !=ETH_RX_NFC_IP4 ) -return -EOPNOTSUPP ; +if (fs->h_u.usr_ip6_spec.l4_4_bytes || + fs->h_u.usr_ip6_spec.tclass) +return -EOPNOTSUPP ; -parse_ip4 (v4_m, v4_k, fs); +parse_ip6 (v6_m, v6_k, fs); + }else { + selector->type =VIRTIO_NET_FF_MASK_TYPE_IPV4 ; + selector->length =sizeof (struct iphdr ); + +if (fs->h_u.usr_ip4_spec.l4_4_bytes || + fs->h_u.usr_ip4_spec.tos || + fs->h_u.usr_ip4_spec.ip_ver !=ETH_RX_NFC_IP4 ) +return -EOPNOTSUPP ; + +parse_ip4 (v4_m, v4_k, fs); + }return 0 ; }
Signature · 1 line
2.50.1
PATCH 10/11 virtio_net: Add support for TCP and UDP ethtool rules
In reply to Daniel JurgensImplement TCP and UDP V4/V6 ethtools flow types.
Examples:
$ ethtool -U ens9 flow-type udp4 dst-ip 192.168.5.2 dst-port\ 4321 action 20 Added rule with ID 4
This example directs IPv4 UDP traffic with the specified address and port to queue 20.
$ ethtool -U ens9 flow-type tcp6 src-ip 2001:db8::1 src-port 1234 dst-ip\ 2001:db8::2 dst-port 4321 action 12 Added rule with ID 5
This example directs IPv6 TCP traffic with the specified address and port to queue 12.
--- drivers/net/virtio_net/virtio_net_ff.c | 207 +++++++++++++++++++++++-- 1 file changed, 198 insertions(+), 9 deletions(-)
drivers/net/virtio_net/virtio_net_ff.c +198 -9
@@ -146,6 +146,52 @@ static bool validate_ip6_mask(const struct virtnet_ff *ff,return true; } +static bool validate_tcp_mask (const struct virtnet_ff *ff, +const struct virtio_net_ff_selector *sel, +const struct virtio_net_ff_selector *sel_cap) +{ +bool partial_mask = !!(sel_cap->flags &VIRTIO_NET_FF_MASK_F_PARTIAL_MASK ); +struct tcphdr *cap, *mask; + + cap = (struct tcphdr *)&sel_cap->mask; + mask = (struct tcphdr *)&sel->mask; + +if (mask->source && + !check_mask_vs_cap (&mask->source, &cap->source, +sizeof (cap->source), partial_mask)) +return false; + +if (mask->dest && + !check_mask_vs_cap (&mask->dest, &cap->dest, +sizeof (cap->dest), partial_mask)) +return false; + +return true; +} + +static bool validate_udp_mask (const struct virtnet_ff *ff, +const struct virtio_net_ff_selector *sel, +const struct virtio_net_ff_selector *sel_cap) +{ +bool partial_mask = !!(sel_cap->flags &VIRTIO_NET_FF_MASK_F_PARTIAL_MASK ); +struct udphdr *cap, *mask; + + cap = (struct udphdr *)&sel_cap->mask; + mask = (struct udphdr *)&sel->mask; + +if (mask->source && + !check_mask_vs_cap (&mask->source, &cap->source, +sizeof (cap->source), partial_mask)) +return false; + +if (mask->dest && + !check_mask_vs_cap (&mask->dest, &cap->dest, +sizeof (cap->dest), partial_mask)) +return false; + +return true; +} +static bool validate_mask (const struct virtnet_ff *ff,const struct virtio_net_ff_selector *sel) {
@@ -163,11 +209,45 @@ static bool validate_mask(const struct virtnet_ff *ff,case VIRTIO_NET_FF_MASK_TYPE_IPV6 :return validate_ip6_mask (ff, sel, sel_cap); + +case VIRTIO_NET_FF_MASK_TYPE_TCP : +return validate_tcp_mask (ff, sel, sel_cap); + +case VIRTIO_NET_FF_MASK_TYPE_UDP : +return validate_udp_mask (ff, sel, sel_cap); }return false; } +static void set_tcp (struct tcphdr *mask,struct tcphdr *key, +__be16 psrc_m,__be16 psrc_k, +__be16 pdst_m,__be16 pdst_k) +{ +if (psrc_m) { + mask->source = psrc_m; + key->source = psrc_k; + } +if (pdst_m) { + mask->dest = pdst_m; + key->dest = pdst_k; + } +} + +static void set_udp (struct udphdr *mask,struct udphdr *key, +__be16 psrc_m,__be16 psrc_k, +__be16 pdst_m,__be16 pdst_k) +{ +if (psrc_m) { + mask->source = psrc_m; + key->source = psrc_k; + } +if (pdst_m) { + mask->dest = pdst_m; + key->dest = pdst_k; + } +} +static void parse_ip4 (struct iphdr *mask,struct iphdr *key,const struct ethtool_rx_flow_spec *fs) {
@@ -209,12 +289,26 @@ static void parse_ip6(struct ipv6hdr *mask, struct ipv6hdr *key,static bool has_ipv4 (u32 flow_type) { -return flow_type ==IP_USER_FLOW ; +return flow_type ==TCP_V4_FLOW || + flow_type ==UDP_V4_FLOW || + flow_type ==IP_USER_FLOW ; }static bool has_ipv6 (u32 flow_type) { -return flow_type ==IPV6_USER_FLOW ; +return flow_type ==TCP_V6_FLOW || + flow_type ==UDP_V6_FLOW || + flow_type ==IPV6_USER_FLOW ; +} + +static bool has_tcp (u32 flow_type) +{ +return flow_type ==TCP_V4_FLOW || flow_type ==TCP_V6_FLOW ; +} + +static bool has_udp (u32 flow_type) +{ +return flow_type ==UDP_V4_FLOW || flow_type ==UDP_V6_FLOW ; } static int setup_classifier(struct virtnet_ff *ff,
@@ -350,6 +444,10 @@ static bool supported_flow_type(const struct ethtool_rx_flow_spec *fs)case ETHER_FLOW :case IP_USER_FLOW :case IPV6_USER_FLOW : +case TCP_V4_FLOW : +case TCP_V6_FLOW : +case UDP_V4_FLOW : +case UDP_V6_FLOW :return true; }
@@ -393,6 +491,12 @@ static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs, size +=sizeof (struct iphdr ); else if (has_ipv6(fs->flow_type)) size += sizeof(struct ipv6hdr); + +if (has_tcp (fs->flow_type) ||has_udp (fs->flow_type)) { + (*num_hdrs)++; + size +=has_tcp (fs->flow_type) ?sizeof (struct tcphdr ) : +sizeof (struct udphdr ); + } done: *key_size = size;/*
@@ -427,7 +531,8 @@ static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector,static int setup_ip_key_mask (struct virtio_net_ff_selector *selector,u8 *key, -const struct ethtool_rx_flow_spec *fs) +const struct ethtool_rx_flow_spec *fs, +int num_hdrs) {struct ipv6hdr *v6_m = (struct ipv6hdr *)&selector->mask;struct iphdr *v4_m = (struct iphdr *)&selector->mask;
@@ -438,21 +543,93 @@ static int setup_ip_key_mask(struct virtio_net_ff_selector *selector, selector->type =VIRTIO_NET_FF_MASK_TYPE_IPV6 ; selector->length =sizeof (struct ipv6hdr ); -if (fs->h_u.usr_ip6_spec.l4_4_bytes || - fs->h_u.usr_ip6_spec.tclass) +if (num_hdrs ==2 && (fs->h_u.usr_ip6_spec.l4_4_bytes || + fs->h_u.usr_ip6_spec.tclass))return -EOPNOTSUPP ;parse_ip6 (v6_m, v6_k, fs); + +if (num_hdrs >2 ) { + v6_m->nexthdr =0xff ; +if (has_tcp (fs->flow_type)) + v6_k->nexthdr =IPPROTO_TCP ; +else + v6_k->nexthdr =IPPROTO_UDP ; + } }else { selector->type =VIRTIO_NET_FF_MASK_TYPE_IPV4 ; selector->length =sizeof (struct iphdr ); -if (fs->h_u.usr_ip4_spec.l4_4_bytes || - fs->h_u.usr_ip4_spec.tos || - fs->h_u.usr_ip4_spec.ip_ver !=ETH_RX_NFC_IP4 ) +if (num_hdrs ==2 && + (fs->h_u.usr_ip4_spec.l4_4_bytes || + fs->h_u.usr_ip4_spec.tos || + fs->h_u.usr_ip4_spec.ip_ver !=ETH_RX_NFC_IP4 ))return -EOPNOTSUPP ;parse_ip4 (v4_m, v4_k, fs); + +if (num_hdrs >2 ) { + v4_m->protocol =0xff ; +if (has_tcp (fs->flow_type)) + v4_k->protocol =IPPROTO_TCP ; +else + v4_k->protocol =IPPROTO_UDP ; + } + } + +return 0 ; +} + +static int setup_transport_key_mask (struct virtio_net_ff_selector *selector, +u8 *key, +struct ethtool_rx_flow_spec *fs) +{ +struct tcphdr *tcp_m = (struct tcphdr *)&selector->mask; +struct udphdr *udp_m = (struct udphdr *)&selector->mask; +const struct ethtool_tcpip6_spec *v6_l4_mask; +const struct ethtool_tcpip4_spec *v4_l4_mask; +const struct ethtool_tcpip6_spec *v6_l4_key; +const struct ethtool_tcpip4_spec *v4_l4_key; +struct tcphdr *tcp_k = (struct tcphdr *)key; +struct udphdr *udp_k = (struct udphdr *)key; + +if (has_tcp (fs->flow_type)) { + selector->type =VIRTIO_NET_FF_MASK_TYPE_TCP ; + selector->length =sizeof (struct tcphdr ); + +if (has_ipv6 (fs->flow_type)) { + v6_l4_mask = &fs->m_u.tcp_ip6_spec; + v6_l4_key = &fs->h_u.tcp_ip6_spec; + +set_tcp (tcp_m, tcp_k, v6_l4_mask->psrc, v6_l4_key->psrc, + v6_l4_mask->pdst, v6_l4_key->pdst); + }else { + v4_l4_mask = &fs->m_u.tcp_ip4_spec; + v4_l4_key = &fs->h_u.tcp_ip4_spec; + +set_tcp (tcp_m, tcp_k, v4_l4_mask->psrc, v4_l4_key->psrc, + v4_l4_mask->pdst, v4_l4_key->pdst); + } + + }else if (has_udp (fs->flow_type)) { + selector->type =VIRTIO_NET_FF_MASK_TYPE_UDP ; + selector->length =sizeof (struct udphdr ); + +if (has_ipv6 (fs->flow_type)) { + v6_l4_mask = &fs->m_u.udp_ip6_spec; + v6_l4_key = &fs->h_u.udp_ip6_spec; + +set_udp (udp_m, udp_k, v6_l4_mask->psrc, v6_l4_key->psrc, + v6_l4_mask->pdst, v6_l4_key->pdst); + }else { + v4_l4_mask = &fs->m_u.udp_ip4_spec; + v4_l4_key = &fs->h_u.udp_ip4_spec; + +set_udp (udp_m, udp_k, v4_l4_mask->psrc, v4_l4_key->psrc, + v4_l4_mask->pdst, v4_l4_key->pdst); + } + }else { +return -EOPNOTSUPP ; }return 0 ;
@@ -495,6 +672,7 @@ static int build_and_insert(struct virtnet_ff *ff,struct virtio_net_ff_selector *selector;struct virtnet_classifier *c;size_t classifier_size; +size_t key_offset;size_t key_size;int num_hdrs;u8 *key;
@@ -526,9 +704,20 @@ static int build_and_insert(struct virtnet_ff *ff,if (num_hdrs ==1 ) goto validate; + key_offset = selector->length; + selector =next_selector (selector); + + err =setup_ip_key_mask (selector, key + key_offset, fs, num_hdrs); +if (err) + goto err_classifier; + +if (num_hdrs ==2 ) + goto validate; + + key_offset += selector->length; selector =next_selector (selector); - err =setup_ip_key_mask (selector, key +sizeof (struct ethhdr ), fs); + err =setup_transport_key_mask (selector, key + key_offset, fs);if (err) goto err_classifier;
Signature · 1 line
2.50.1
PATCH 11/11 virtio_net: Add get ethtool flow rules ops
In reply to 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--- 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(+)
drivers/net/virtio_net/virtio_net_ff.c +48 -0
@@ -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) {
drivers/net/virtio_net/virtio_net_ff.h +6 -0
@@ -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);
drivers/net/virtio_net/virtio_net_main.c +9 -0
@@ -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 ;
Signature · 1 line
2.50.1