netkit: Support for io_uring zero-copy and AF_XDP
Subsystems (9)
Daniel Borkmann
maintainerPATCH v7 4/16 net, ethtool: Disallow leased real rxqs to be resized
In reply to Daniel BorkmannSimilar to AF_XDP, do not allow queues in a physical netdev to be resized by ethtool -L when they are leased.
--- net/ethtool/channels.c | 12 +++++++----- net/ethtool/ioctl.c | 9 +++++---- 2 files changed, 12 insertions(+), 9 deletions(-)
net/ethtool/channels.c +7 -5
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only -#include <net/xdp_sock_drv.h> +#include <net/netdev_queues.h> #include "netlink.h" #include "common.h"
@@ -169,14 +169,16 @@ ethnl_set_channels(struct ethnl_req_info *req_info, struct genl_info *info)if (ret)return ret; -/* Disabling channels, query zero-copy AF_XDP sockets */ +/* ensure channels are not busy at the moment */ from_channel = channels.combined_count +min (channels.rx_count, channels.tx_count); -for (i = from_channel; i < old_total; i++) -if (xsk_get_pool_from_qid (dev, i)) { -GENL_SET_ERR_MSG (info,"requested channel counts are too low for existing zerocopy AF_XDP sockets" ); +for (i = from_channel; i < old_total; i++) { +if (netdev_queue_busy (dev, i,NULL )) { +GENL_SET_ERR_MSG (info, +"requested channel counts are too low due to busy queues (AF_XDP or queue leasing)" );return -EINVAL ; } + } ret = dev->ethtool_ops->set_channels (dev, &channels);return ret <0 ? ret :1 ;
net/ethtool/ioctl.c +5 -4
@@ -27,12 +27,13 @@#include <linux/net.h> #include <linux/pm_runtime.h> #include <linux/utsname.h> +#include <linux/ethtool_netlink.h> #include <net/devlink.h> #include <net/ipv6.h> -#include <net/xdp_sock_drv.h> #include <net/flow_offload.h> #include <net/netdev_lock.h> -#include <linux/ethtool_netlink.h> +#include <net/netdev_queues.h> +#include "common.h" /* State held across locks and calls for commands which have devlink fallback */
@@ -2282,12 +2283,12 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev,if (ret)return ret; -/* Disabling channels, query zero-copy AF_XDP sockets */ +/* Disabling channels, query busy queues (AF_XDP, queue leasing) */ from_channel = channels.combined_count +min (channels.rx_count, channels.tx_count); to_channel = curr.combined_count +max (curr.rx_count, curr.tx_count);for (i = from_channel; i < to_channel; i++) -if (xsk_get_pool_from_qid (dev, i)) +if (netdev_queue_busy (dev, i,NULL ))return -EINVAL ; ret = dev->ethtool_ops->set_channels (dev, &channels);
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerv7 cover netkit: Support for io_uring zero-copy and AF_XDP
Containers use virtual netdevs to route traffic from a physical netdev in the host namespace. They do not have access to the physical netdev in the host and thus can't use memory providers or AF_XDP that require reconfiguring/restarting queues in the physical netdev.
This patchset adds the concept of queue leasing to virtual netdevs that allow containers to use memory providers and AF_XDP at native speed. Leased queues are bound to a real queue in a physical netdev and act as a proxy.
Memory providers and AF_XDP operations take an ifindex and queue id, so containers would pass in an ifindex for a virtual netdev and a queue id of a leased queue, which then gets proxied to the underlying real queue.
We have implemented support for this concept in netkit and tested the latter against Nvidia ConnectX-6 (mlx5) as well as Broadcom BCM957504 (bnxt_en) 100G NICs. For more details see the individual patches.
v6->v7:
- Add xsk_dev_queue_valid real_num_rx_queues check given bound xs->queue_id could be from a TX queue (AI review bot)
- Fix up exception path in queue leasing selftest (AI review bot)
- Rebase and retested everything with mlx5 + bnxt_env5->v6:
- Fix nest_queue test in netdev_nl_queue_fill_one (Jakub/AI review bot)
- Fix netdev notifier locking leak (Jakub/AI review bot)
- Drop NETREG_UNREGISTERING WARN_ON_ONCE to avoid confusion (Stan)
- Remove slipped-in .gitignore cruft in net selftest (Stan)
- Fix Pylint warnings in net selftest (Jakub)
- Rebase and retested everything with mlx5 + bnxt_env4->v5:
- Rework of the core API into queue-create op (Jakub)
- Rename from queue peering to queue leasing (Jakub)
- Add net selftests for queue leasing (Stan, Jakub)
- Move netkit_queue_get_dma_dev into core (Jakub)
- Dropped netkit_get_channels (Jakub)
- Moved ndo_queue_create back to return index or error (Jakub)
- Inline __netdev_rx_queue_{peer,unpeer} helpers (Jakub)
- Adding helpers in patches where they are used (Jakub)
- Undo inline for netdev_put_lock (Jakub)
- Factoring out checks whether device can lease (Jakub)
- Fix up return codes in netdev_nl_bind_queue_doit (Jakub)
- Reject when AF_XDP or mp already bound (Jakub)
- Switch some error cases to NL_SET_BAD_ATTR() (Jakub)
- Rebase and retested everything with mlx5 + bnxt_env3->v4:
- ndo_queue_create store dst queue via arg (Nikolay)
- Small nits like a spelling issue + rev xmas (Nikolay)
- admin-perm flag in bind-queue spec (Jakub)
- Fix potential ABBA deadlock situation in bind (Jakub, Paolo, Stan)
- Add a peer dev_tracker to not reuse the sysfs one (Jakub)
- New patch (12/14) to handle the underlying device going away (Jakub)
- Improve commit message on queue-get (Jakub)
- Do not expose phys dev info from container on queue-get (Jakub)
- Add netif_put_rx_queue_peer_locked to simplify code (Stan)
- Rework xsk handling to simplify the code and drop a few patches
- Rebase and retested everything with mlx5 + bnxt_env2->v3:
- Use netdev_ops_assert_locked instead of netdev_assert_locked (syzbot)
- Add missing netdev_lockdep_set_classes in netkitv1->v2:
- Removed bind sample ynl code (Stan)
- Reworked netdev locking to have consistent order (Stan, Kuba)
- Return 'not supported' in API patch (Stan)
- Improved ynl documentation (Kuba)
- Added 'max: s32-max' in ynl spec for ifindex (Kuba)
- Added also queue type in ynl to have user specify rx to make it obvious (Kuba)
- Use of netdev_hold (Kuba)
- Avoid static inlines from another header (Kuba)
- Squashed some commits (Kuba, Stan)
- Removed ndo_{peer,unpeer}_queues callback and simplified code (Kuba)
- Improved commit messages (Toke, Kuba, Stan, zf)
- Got rid of locking genl_sk_priv_get (Stan)
- Removed af_xdp cleanup churn (Maciej)
- Added netdev locking asserts (Stan)
- Reject ethtool ioctl path queue resizing (Kuba)
- Added kdoc for ndo_queue_create (Stan)
- Uninvert logic in netkit single dev mode (Jordan)
- Added binding support for multiple queues
Daniel Borkmann (9):
net: Add queue-create operation
net: Implement netdev_nl_queue_create_doit
net: Add lease info to queue-get response
net, ethtool: Disallow leased real rxqs to be resized
xsk: Extend xsk_rcv_check validation
xsk: Proxy pool management for leased queues
netkit: Add single device mode for netkit
netkit: Add netkit notifier to check for unregistering devices
netkit: Add xsk support for af_xdp applications
David Wei (7):
net: Proxy net_mp_{open,close}_rxq for leased queues
net: Proxy netdev_queue_get_dma_dev for leased queues
netkit: Implement rtnl_link_ops->alloc and ndo_queue_create selftests/net: Add bpf skb forwarding program selftests/net: Add env for container based tests selftests/net: Make NetDrvContEnv support queue leasing selftests/net: Add netkit container tests
Documentation/netlink/specs/netdev.yaml | 44 +++ drivers/net/netkit.c | 360 +++++++++++++++--- include/linux/netdevice.h | 6 + include/net/netdev_queues.h | 19 +- include/net/netdev_rx_queue.h | 21 +- include/net/page_pool/memory_provider.h | 4 +- include/net/xdp_sock_drv.h | 2 +- include/uapi/linux/if_link.h | 6 + include/uapi/linux/netdev.h | 11 + net/core/dev.c | 7 + net/core/dev.h | 2 + net/core/netdev-genl-gen.c | 20 + net/core/netdev-genl-gen.h | 2 + net/core/netdev-genl.c | 185 +++++++++ net/core/netdev_queues.c | 74 +++- net/core/netdev_rx_queue.c | 169 ++++++-- net/ethtool/channels.c | 12 +- net/ethtool/ioctl.c | 9 +- net/xdp/xsk.c | 79 +++- tools/include/uapi/linux/netdev.h | 11 + .../testing/selftests/drivers/net/README.rst | 7 + .../testing/selftests/drivers/net/hw/Makefile | 2 + .../drivers/net/hw/lib/py/__init__.py | 7 +- .../selftests/drivers/net/hw/nk_forward.bpf.c | 49 +++ .../selftests/drivers/net/hw/nk_netns.py | 23 ++ .../selftests/drivers/net/hw/nk_qlease.py | 55 +++ .../selftests/drivers/net/lib/py/__init__.py | 7 +- .../selftests/drivers/net/lib/py/env.py | 157 ++++++++ 28 files changed, 1233 insertions(+), 117 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c create mode 100755 tools/testing/selftests/drivers/net/hw/nk_netns.py create mode 100755 tools/testing/selftests/drivers/net/hw/nk_qlease.py
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 5/16 net: Proxy net_mp_{open,close}_rxq for leased queues
From: David Wei <[email protected]>
When a process in a container wants to setup a memory provider, it will use the virtual netdev and a leased rxq, and call net_mp_{open,close}_rxq to try and restart the queue. At this point, proxy the queue restart on the real rxq in the physical netdev.
For memory providers (io_uring zero-copy rx and devmem), it causes the real rxq in the physical netdev to be filled from a memory provider that has DMA mapped memory from a process within a container.
--- include/net/netdev_rx_queue.h | 4 ++ include/net/page_pool/memory_provider.h | 4 +- net/core/netdev_rx_queue.c | 78 +++++++++++++++++++------ 3 files changed, 66 insertions(+), 20 deletions(-)
include/net/netdev_rx_queue.h +4 -0
@@ -73,4 +73,8 @@ enum netif_lease_dir {struct netdev_rx_queue *__netif_get_rx_queue_lease (struct net_device **dev,unsigned int *rxq,enum netif_lease_dir dir); +struct netdev_rx_queue * +netif_get_rx_queue_lease_locked (struct net_device **dev,unsigned int *rxq); +void netif_put_rx_queue_lease_locked (struct net_device *orig_dev, +struct net_device *dev);#endif /* _LINUX_NETDEV_RX_QUEUE_H */
include/net/page_pool/memory_provider.h +2 -2
@@ -23,12 +23,12 @@ bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr);void net_mp_niov_set_page_pool (struct page_pool *pool,struct net_iov *niov);void net_mp_niov_clear_page_pool (struct net_iov *niov); -int net_mp_open_rxq (struct net_device *dev,unsigned ifq_idx, +int net_mp_open_rxq (struct net_device *dev,unsigned int rxq_idx,struct pp_memory_provider_params *p);int __net_mp_open_rxq (struct net_device *dev,unsigned int rxq_idx,const struct pp_memory_provider_params *p,struct netlink_ext_ack *extack); -void net_mp_close_rxq (struct net_device *dev,unsigned ifq_idx, +void net_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx,struct pp_memory_provider_params *old_p);void __net_mp_close_rxq (struct net_device *dev,unsigned int rxq_idx,const struct pp_memory_provider_params *old_p);
net/core/netdev_rx_queue.c +60 -18
153 lines not on this page · raw message
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 1/16 net: Add queue-create operation
In reply to Daniel BorkmannAdd a ynl netdev family operation called queue-create that creates a new queue on a netdevice:
name: queue-create
attribute-set: queue
flags: [admin-perm]
do:
request:
attributes:
- ifindex
- type
- lease
reply: &queue-create-op
attributes:
- id
This is a generic operation such that it can be extended for various use cases in future. Right now it is mandatory to specify ifindex, the queue type which is enforced to rx and a lease. The newly created queue id is returned to the caller.
A queue from a virtual device can have a lease which refers to another queue from a physical device. This is useful for memory providers and AF_XDP operations which take an ifindex and queue id to allow applications to bind against virtual devices in containers. The lease couples both queues together and allows to proxy the operations from a virtual device in a container to the physical device.
In future, the nested lease attribute can be lifted and made optional for other use-cases such as dynamic queue creation for physical netdevs. The lack of lease and the specification of the physical device as an ifindex will imply that we need a real queue to be allocated. Similarly, the queue type enforcement to rx can then be lifted as well to support tx.
An early implementation had only driver-specific integration [0], but in order for other virtual devices to reuse, it makes sense to have this as a generic API in core net.
For leasing queues, the virtual netdev must have real_num_rx_queue less than num_rx_queues at the time of calling queue-create. The queue-type must be rx as only rx queues are supported for leasing for now. We also enforce that the queue-create ifindex must point to a virtual device, and that the nested lease attribute's ifindex must point to a physical device. The nested lease attribute set contains a netns-id attribute which is currently only intended for dumping as part of the queue-get operation. Also, it is modeled as an s32 type similarly as done elsewhere in the stack.
--- Documentation/netlink/specs/netdev.yaml | 44 +++++++++++++++++++++++++ include/uapi/linux/netdev.h | 11 +++++++ net/core/netdev-genl-gen.c | 20 +++++++++++ net/core/netdev-genl-gen.h | 2 ++ net/core/netdev-genl.c | 5 +++ tools/include/uapi/linux/netdev.h | 11 +++++++ 6 files changed, 93 insertions(+)
Documentation/netlink/specs/netdev.yaml +44 -0
@@ -339,6 +339,15 @@ attribute-sets: doc: XSK information for this queue, if any. type: nest nested-attributes: xsk-info + - + name: lease + doc: | + A queue from a virtual device can have a lease which refers to + another queue from a physical device. This is useful for memory + providers and AF_XDP operations which take an ifindex and queue id + to allow applications to bind against virtual devices in containers. + type: nest + nested-attributes: lease - name: qstats doc: |
@@ -537,6 +546,24 @@ attribute-sets: name: id - name: type + - + name: lease + attributes: + - + name: ifindex + doc: The netdev ifindex to lease the queue from. + type: u32 + checks: + min: 1 + - + name: queue + doc: The netdev queue to lease from. + type: nest + nested-attributes: queue-id + - + name: netns-id + doc: The network namespace id of the netdev. + type: s32 - name: dmabuf attributes:
@@ -686,6 +713,7 @@ operations: - dmabuf - io-uring - xsk + - lease dump: request: attributes:
@@ -797,6 +825,22 @@ operations: reply: attributes: - id + - + name: queue-create + doc: | + Create a new queue for the given netdevice. Whether this operation + is supported depends on the device and the driver. + attribute-set: queue + flags: [admin-perm] + do: + request: + attributes: + - ifindex + - type + - lease + reply: &queue-create-op + attributes: + - id kernel-family: headers: ["net/netdev_netlink.h"]
include/uapi/linux/netdev.h +11 -0
@@ -160,6 +160,7 @@ enum {NETDEV_A_QUEUE_DMABUF ,NETDEV_A_QUEUE_IO_URING ,NETDEV_A_QUEUE_XSK , +NETDEV_A_QUEUE_LEASE , __NETDEV_A_QUEUE_MAX,NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX -1 )
@@ -202,6 +203,15 @@ enum {NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX -1 ) }; +enum { +NETDEV_A_LEASE_IFINDEX =1 , +NETDEV_A_LEASE_QUEUE , +NETDEV_A_LEASE_NETNS_ID , + + __NETDEV_A_LEASE_MAX, +NETDEV_A_LEASE_MAX = (__NETDEV_A_LEASE_MAX -1 ) +}; +enum {NETDEV_A_DMABUF_IFINDEX =1 ,NETDEV_A_DMABUF_QUEUES ,
@@ -228,6 +238,7 @@ enum {NETDEV_CMD_BIND_RX ,NETDEV_CMD_NAPI_SET ,NETDEV_CMD_BIND_TX , +NETDEV_CMD_QUEUE_CREATE , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )
net/core/netdev-genl-gen.c +20 -0
@@ -28,6 +28,12 @@ static const struct netlink_range_validation netdev_a_napi_defer_hard_irqs_range };/* Common nested types */ +const struct nla_policy netdev_lease_nl_policy[NETDEV_A_LEASE_NETNS_ID +1 ] = { + [NETDEV_A_LEASE_IFINDEX ] =NLA_POLICY_MIN (NLA_U32 ,1 ), + [NETDEV_A_LEASE_QUEUE ] =NLA_POLICY_NESTED (netdev_queue_id_nl_policy), + [NETDEV_A_LEASE_NETNS_ID ] = { .type =NLA_S32 , }, +}; +const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX +1 ] = { [NETDEV_A_PAGE_POOL_ID ] =NLA_POLICY_FULL_RANGE (NLA_UINT , &netdev_a_page_pool_id_range), [NETDEV_A_PAGE_POOL_IFINDEX ] =NLA_POLICY_FULL_RANGE (NLA_U32 , &netdev_a_page_pool_ifindex_range),
@@ -107,6 +113,13 @@ static const struct nla_policy netdev_bind_tx_nl_policy[NETDEV_A_DMABUF_FD + 1] [NETDEV_A_DMABUF_FD] = { .type = NLA_U32, }, }; +/* NETDEV_CMD_QUEUE_CREATE - do */ +static const struct nla_policy netdev_queue_create_nl_policy[NETDEV_A_QUEUE_LEASE +1 ] = { + [NETDEV_A_QUEUE_IFINDEX ] =NLA_POLICY_MIN (NLA_U32 ,1 ), + [NETDEV_A_QUEUE_TYPE ] =NLA_POLICY_MAX (NLA_U32 ,1 ), + [NETDEV_A_QUEUE_LEASE ] =NLA_POLICY_NESTED (netdev_lease_nl_policy), +}; +/* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { {
@@ -205,6 +218,13 @@ static const struct genl_split_ops netdev_nl_ops[] = { .maxattr = NETDEV_A_DMABUF_FD, .flags = GENL_CMD_CAP_DO, }, + { + .cmd = NETDEV_CMD_QUEUE_CREATE, + .doit = netdev_nl_queue_create_doit, + .policy = netdev_queue_create_nl_policy, + .maxattr = NETDEV_A_QUEUE_LEASE, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, };static const struct genl_multicast_group netdev_nl_mcgrps[] = {
net/core/netdev-genl-gen.h +2 -0
@@ -14,6 +14,7 @@#include <net/netdev_netlink.h> /* Common nested types */ +extern const struct nla_policy netdev_lease_nl_policy[NETDEV_A_LEASE_NETNS_ID +1 ];extern const struct nla_policy netdev_page_pool_info_nl_policy[NETDEV_A_PAGE_POOL_IFINDEX +1 ];extern const struct nla_policy netdev_queue_id_nl_policy[NETDEV_A_QUEUE_TYPE +1 ];
@@ -36,6 +37,7 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,int netdev_nl_bind_rx_doit (struct sk_buff *skb,struct genl_info *info);int netdev_nl_napi_set_doit (struct sk_buff *skb,struct genl_info *info);int netdev_nl_bind_tx_doit (struct sk_buff *skb,struct genl_info *info); +int netdev_nl_queue_create_doit (struct sk_buff *skb,struct genl_info *info);enum {NETDEV_NLGRP_MGMT ,
net/core/netdev-genl.c +5 -0
@@ -1120,6 +1120,11 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)return err; } +int netdev_nl_queue_create_doit (struct sk_buff *skb,struct genl_info *info) +{ +return -EOPNOTSUPP ; +} +void netdev_nl_sock_priv_init (struct netdev_nl_sock *priv) {INIT_LIST_HEAD (&priv->bindings);
tools/include/uapi/linux/netdev.h +11 -0
@@ -160,6 +160,7 @@ enum {NETDEV_A_QUEUE_DMABUF ,NETDEV_A_QUEUE_IO_URING ,NETDEV_A_QUEUE_XSK , +NETDEV_A_QUEUE_LEASE , __NETDEV_A_QUEUE_MAX,NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX -1 )
@@ -202,6 +203,15 @@ enum {NETDEV_A_QSTATS_MAX = (__NETDEV_A_QSTATS_MAX -1 ) }; +enum { +NETDEV_A_LEASE_IFINDEX =1 , +NETDEV_A_LEASE_QUEUE , +NETDEV_A_LEASE_NETNS_ID , + + __NETDEV_A_LEASE_MAX, +NETDEV_A_LEASE_MAX = (__NETDEV_A_LEASE_MAX -1 ) +}; +enum {NETDEV_A_DMABUF_IFINDEX =1 ,NETDEV_A_DMABUF_QUEUES ,
@@ -228,6 +238,7 @@ enum {NETDEV_CMD_BIND_RX ,NETDEV_CMD_NAPI_SET ,NETDEV_CMD_BIND_TX , +NETDEV_CMD_QUEUE_CREATE , __NETDEV_CMD_MAX,NETDEV_CMD_MAX = (__NETDEV_CMD_MAX -1 )
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 3/16 net: Add lease info to queue-get response
In reply to Daniel BorkmannPopulate nested lease info to the queue-get response that returns the ifindex, queue id with type and optionally netns id if the device resides in a different netns.
Example with ynl client:
# ip a
[...]
4: enp10s0f0np0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp/id:24 qdisc mq state UP group default qlen 1000
link/ether e8:eb:d3:a3:43:f6 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.2/24 scope global enp10s0f0np0
valid_lft forever preferred_lft forever
inet6 fe80::eaeb:d3ff:fea3:43f6/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
[...]# ethtool -i enp10s0f0np0 driver: mlx5_core [...]
# ./pyynl/cli.py \
--spec ~/netlink/specs/netdev.yaml \
--do queue-get \
--json '{"ifindex": 4, "id": 15, "type": "rx"}'
{'id': 15,
'ifindex': 4,
'lease': {'ifindex': 8, 'netns-id': 0, 'queue': {'id': 1, 'type': 'rx'}},
'napi-id': 8227,
'type': 'rx',
'xsk': {}}# ip netns list foo (id: 0)
# ip netns exec foo ip a
[...]
8: nk@NONE: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
inet6 fe80::200:ff:fe00:0/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
[...]# ip netns exec foo ethtool -i nk driver: netkit [...]
# ip netns exec foo ls /sys/class/net/nk/queues/ rx-0 rx-1 tx-0
# ip netns exec foo ./pyynl/cli.py \
--spec ~/netlink/specs/netdev.yaml \
--do queue-get \
--json '{"ifindex": 8, "id": 1, "type": "rx"}'
{'id': 1, 'ifindex': 8, 'type': 'rx'}Note that the caller of netdev_nl_queue_fill_one() holds the netdevice lock. For the queue-get we do not lock both devices. When queues get {un,}leased, both devices are locked, thus if __netif_get_rx_queue_peer() returns true, the peer pointer points to a valid device. The netns-id is fetched via peernet2id_alloc() similarly as done in OVS.
--- include/net/netdev_rx_queue.h | 10 ++++++++ net/core/netdev-genl.c | 36 ++++++++++++++++++++++++++++ net/core/netdev_rx_queue.c | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)
include/net/netdev_rx_queue.h +10 -0
@@ -63,4 +63,14 @@ void netdev_rx_queue_lease(struct netdev_rx_queue *rxq_dst, struct netdev_rx_queue *rxq_src);void netdev_rx_queue_unlease (struct netdev_rx_queue *rxq_dst,struct netdev_rx_queue *rxq_src); +bool netif_rx_queue_lease_get_owner (struct net_device **dev,unsigned int *rxq); + +enum netif_lease_dir { +NETIF_VIRT_TO_PHYS , +NETIF_PHYS_TO_VIRT , +}; + +struct netdev_rx_queue * +__netif_get_rx_queue_lease (struct net_device **dev,unsigned int *rxq, +enum netif_lease_dir dir);#endif /* _LINUX_NETDEV_RX_QUEUE_H */
net/core/netdev-genl.c +36 -0
@@ -391,8 +391,11 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, u32 q_idx, u32 q_type, const struct genl_info *info) { struct pp_memory_provider_params *params; +struct net_device *orig_netdev = netdev; +struct nlattr *nest_lease, *nest_queue;struct netdev_rx_queue *rxq;struct netdev_queue *txq; +u32 lease_q_idx = q_idx;void *hdr; hdr =genlmsg_iput (rsp, info);
@@ -410,6 +413,37 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,if (nla_put_napi_id (rsp, rxq->napi)) goto nla_put_failure; +if (netif_rx_queue_lease_get_owner (&netdev, &lease_q_idx)) { +struct net *net, *peer_net; + + nest_lease =nla_nest_start (rsp,NETDEV_A_QUEUE_LEASE ); +if (!nest_lease) + goto nla_put_failure; + nest_queue =nla_nest_start (rsp,NETDEV_A_LEASE_QUEUE ); +if (!nest_queue) + goto nla_put_failure; +if (nla_put_u32 (rsp,NETDEV_A_QUEUE_ID , lease_q_idx)) + goto nla_put_failure; +if (nla_put_u32 (rsp,NETDEV_A_QUEUE_TYPE , q_type)) + goto nla_put_failure; +nla_nest_end (rsp, nest_queue); +if (nla_put_u32 (rsp,NETDEV_A_LEASE_IFINDEX , +READ_ONCE (netdev->ifindex))) + goto nla_put_failure; +rcu_read_lock (); + peer_net =dev_net_rcu (netdev); + net =dev_net_rcu (orig_netdev); +if (!net_eq (net, peer_net)) { +s32 id =peernet2id_alloc (net, peer_net,GFP_ATOMIC ); + +if (nla_put_s32 (rsp,NETDEV_A_LEASE_NETNS_ID , id)) + goto nla_put_failure_unlock; + } +rcu_read_unlock (); +nla_nest_end (rsp, nest_lease); + netdev = orig_netdev; + } + params = &rxq->mp_params;if (params->mp_ops && params->mp_ops->nl_fill (params->mp_priv, rsp, rxq))
@@ -437,6 +471,8 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,return 0 ; +nla_put_failure_unlock: +rcu_read_unlock (); nla_put_failure:genlmsg_cancel (rsp, hdr);return -EMSGSIZE ;
net/core/netdev_rx_queue.c +45 -0
51 lines not on this page · raw message
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 6/16 net: Proxy netdev_queue_get_dma_dev for leased queues
In reply to Daniel BorkmannFrom: David Wei <[email protected]>
Extend netdev_queue_get_dma_dev to return the physical device of the real rxq for DMA in case the queue was leased. This allows memory providers like io_uring zero-copy or devmem to bind to the physically leased rxq via virtual devices such as netkit.
--- net/core/netdev_queues.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
net/core/netdev_queues.c +15 -2
@@ -9,16 +9,29 @@* @dev: net_device * @idx: queue index * -* Get dma device for zero-copy operations to be used for this queue. +* Get dma device for zero-copy operations to be used for this queue. If the +* queue is leased to a physical queue, we retrieve the latter's dma device. * When such device is not available or valid, the function will return NULL. * * Return: Device or NULL on error */ struct device *netdev_queue_get_dma_dev (struct net_device *dev,int idx) { -const struct netdev_queue_mgmt_ops *queue_ops = dev->queue_mgmt_ops; +const struct netdev_queue_mgmt_ops *queue_ops;struct device *dma_dev; +if (idx < dev->real_num_rx_queues) { +struct netdev_rx_queue *rxq =__netif_get_rx_queue (dev, idx); + +if (rxq->lease) { + rxq = rxq->lease; + dev = rxq->dev; + idx =get_netdev_rx_queue_index (rxq); + } + } + + queue_ops = dev->queue_mgmt_ops; +if (queue_ops && queue_ops->ndo_queue_get_dma_dev) dma_dev = queue_ops->ndo_queue_get_dma_dev (dev, idx);else
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 7/16 xsk: Extend xsk_rcv_check validation
In reply to Daniel Borkmannxsk_rcv_check tests for inbound packets to see whether they match the bound AF_XDP socket. Refactor the test into a small helper xsk_dev_queue_valid and move the validation against xs->dev and xs->queue_id there.
The fast-path case stays in place and allows for quick return in xsk_dev_queue_valid. If it fails, the validation is extended to check whether the AF_XDP socket is bound against a leased queue, and if the case then the test is redone.
--- net/xdp/xsk.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
net/xdp/xsk.c +26 -3
@@ -324,14 +324,37 @@ static bool xsk_is_bound(struct xdp_sock *xs)return false; } +static bool xsk_dev_queue_valid (const struct xdp_sock *xs, +const struct xdp_rxq_info *info) +{ +struct net_device *dev = xs->dev; +u32 queue_index = xs->queue_id; +struct netdev_rx_queue *rxq; + +if (info->dev == dev && + info->queue_index == queue_index) +return true; + +if (queue_index < dev->real_num_rx_queues) { + rxq =READ_ONCE (__netif_get_rx_queue (dev, queue_index)->lease); +if (!rxq) +return false; + + dev = rxq->dev; + queue_index =get_netdev_rx_queue_index (rxq); + +return info->dev == dev && + info->queue_index == queue_index; + } +return false; +} +static int xsk_rcv_check (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len) {if (!xsk_is_bound (xs))return -ENXIO ; - -if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index) +if (!xsk_dev_queue_valid (xs, xdp->rxq))return -EINVAL ; -if (len >xsk_pool_get_rx_frame_size (xs->pool) && !xs->sg) { xs->rx_dropped++;return -ENOSPC ;
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 8/16 xsk: Proxy pool management for leased queues
In reply to Daniel BorkmannSimilarly to the net_mp_{open,close}_rxq handling for leased queues, proxy the xsk_{reg,clear}_pool_at_qid via netif_get_rx_queue_lease_locked such that in case a virtual netdev picked a leased rxq, the request gets through to the real rxq in the physical netdev. The proxying is only relevant for queue_id < dev->real_num_rx_queues since right now its only supported for rxqs.
--- net/xdp/xsk.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-)
net/xdp/xsk.c +35 -13
@@ -23,6 +23,8 @@#include <linux/netdevice.h> #include <linux/rculist.h> #include <linux/vmalloc.h> + +#include <net/netdev_queues.h> #include <net/xdp_sock_drv.h> #include <net/busy_poll.h> #include <net/netdev_lock.h>
@@ -117,10 +119,18 @@ EXPORT_SYMBOL(xsk_get_pool_from_qid);void xsk_clear_pool_at_qid (struct net_device *dev,u16 queue_id) { -if (queue_id < dev->num_rx_queues) - dev->_rx[queue_id].pool =NULL ; -if (queue_id < dev->num_tx_queues) - dev->_tx[queue_id].pool =NULL ; +struct net_device *orig_dev = dev; +unsigned int id = queue_id; + +if (id < dev->real_num_rx_queues) +WARN_ON_ONCE (!netif_get_rx_queue_lease_locked (&dev, &id)); + +if (id < dev->real_num_rx_queues) + dev->_rx[id].pool =NULL ; +if (id < dev->real_num_tx_queues) + dev->_tx[id].pool =NULL ; + +netif_put_rx_queue_lease_locked (orig_dev, dev); }/* The buffer pool is stored both in the _rx struct and the _tx struct as we do
@@ -130,17 +140,29 @@ void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id)int xsk_reg_pool_at_qid (struct net_device *dev,struct xsk_buff_pool *pool,u16 queue_id) { - if (queue_id >= max_t(unsigned int, - dev->real_num_rx_queues, - dev->real_num_tx_queues)) -return -EINVAL ; +struct net_device *orig_dev = dev; +unsigned int id = queue_id; +int ret =0 ; -if (queue_id < dev->real_num_rx_queues) - dev->_rx[queue_id].pool = pool; -if (queue_id < dev->real_num_tx_queues) - dev->_tx[queue_id].pool = pool; +if (id >=max (dev->real_num_rx_queues, + dev->real_num_tx_queues)) +return -EINVAL ; +if (id < dev->real_num_rx_queues) { +if (!netif_get_rx_queue_lease_locked (&dev, &id)) +return -EBUSY ; +if (xsk_get_pool_from_qid (dev, id)) { + ret = -EBUSY ; + goto out; + } + } -return 0 ; +if (id < dev->real_num_rx_queues) + dev->_rx[id].pool = pool; +if (id < dev->real_num_tx_queues) + dev->_tx[id].pool = pool; +out: +netif_put_rx_queue_lease_locked (orig_dev, dev); +return ret; } static int __xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff_xsk *xskb, u32 len,
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 10/16 netkit: Implement rtnl_link_ops->alloc and ndo_queue_create
In reply to Daniel BorkmannFrom: David Wei <[email protected]>
Implement rtnl_link_ops->alloc that allows the number of rx queues to be set when netkit is created. By default, netkit has only a single rxq (and single txq). The number of queues is deliberately not allowed to be changed via ethtool -L and is fixed for the lifetime of a netkit instance.
For netkit device creation, numrxqueues with larger than one rxq can be specified. These rxqs are leasable to real rxqs in physical netdevs:
ip link add type netkit peer numrxqueues 64 # for device pair
ip link add numrxqueues 64 type netkit single # for single device
The limit of numrxqueues for netkit is currently set to 1024, which allows leasing multiple real rxqs from physical netdevs.
The implementation of ndo_queue_create() adds a new rxq during the queue lease operation. We allow to create queues either in single device mode or for the case of dual device mode for the netkit peer device which gets placed into the target network namespace. For dual device mode the lease against the primary device does not make sense for the targeted use cases, and therefore gets rejected.
We also need to add a lockdep class for netkit, such that lockdep does not trip over us, similarly done as in commit 0bef512012b1 ("net: add netdev_lockdep_set_classes() to virtual drivers").
This is also the last missing bit to netkit for supporting io_uring with zero-copy mode [0]. Up until this point it was not possible to consume the latter out of containers or Kubernetes Pods where applications are in their own network namespace.
io_uring example with eth0 being a physical device with 16 queues where netkit is bound to the last queue, iou-zcrx.c is binary from selftests. Flow steering to that queue is based on the service VIP:port of the server utilizing io_uring:
# ethtool -X eth0 start 0 equal 15
# ethtool -X eth0 start 15 equal 1 context new
# ethtool --config-ntuple eth0 flow-type tcp4 dst-ip 1.2.3.4 dst-port 5000 action 15
# ip netns add foo
# ip link add type netkit peer numrxqueues 2
# ./pyynl/cli.py --spec ~/netlink/specs/netdev.yaml \
--do queue-create \
--json "{"ifindex": $(ifindex nk0), "type": "rx", \
"lease": { "ifindex": $(ifindex eth0), \
"queue": { "type": "rx", "id": 15 } } }"
{'id': 1}
# ip link set nk0 netns foo
# ip link set nk1 up
# ip netns exec foo ip link set lo up
# ip netns exec foo ip link set nk0 up
# ip netns exec foo ip addr add 1.2.3.4/32 dev nk0
[ ... setup routing etc to get external traffic into the netns ... ]
# ip netns exec foo ./iou-zcrx -s -p 5000 -i nk0 -q 1Remote io_uring client:
# ./iou-zcrx -c -h 1.2.3.4 -p 5000 -l 12840 -z 65536
We have tested the above against a Broadcom BCM957504 (bnxt_en) 100G NIC, supporting TCP header/data split.
Similarly, this also works for devmem which we tested using ncdevmem:
# ip netns exec foo ./ncdevmem -s 1.2.3.4 -l -p 5000 -f nk0 -t 1 -q 1
And on the remote client:
# ./ncdevmem -s 1.2.3.4 -p 5000 -f eth0
For Cilium, the plan is to open up support for the various memory providers for regular Kubernetes Pods when Cilium is configured with netkit datapath mode.
--- drivers/net/netkit.c | 117 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 105 insertions(+), 12 deletions(-)
drivers/net/netkit.c +105 -12
@@ -9,11 +9,20 @@#include <linux/bpf_mprog.h> #include <linux/indirect_call_wrapper.h> +#include <net/netdev_lock.h> +#include <net/netdev_queues.h> +#include <net/netdev_rx_queue.h> #include <net/netkit.h> #include <net/dst.h> #include <net/tcx.h> -#define DRV_NAME "netkit" +#define NETKIT_DRV_NAME "netkit" + +#define NETKIT_NUM_RX_QUEUES_MAX 1024 +#define NETKIT_NUM_TX_QUEUES_MAX 1 + +#define NETKIT_NUM_RX_QUEUES_REAL 1 +#define NETKIT_NUM_TX_QUEUES_REAL 1struct netkit {__cacheline_group_begin (netkit_fastpath);
@@ -37,6 +46,8 @@ struct netkit_link {struct net_device *dev; }; +static struct rtnl_link_ops netkit_link_ops; + static __always_inline intnetkit_run (const struct bpf_mprog_entry *entry,struct sk_buff *skb,enum netkit_action ret)
@@ -224,9 +235,16 @@ static void netkit_get_stats(struct net_device *dev, stats->tx_dropped =DEV_STATS_READ (dev, tx_dropped); } +static int netkit_init (struct net_device *dev) +{ +netdev_lockdep_set_classes (dev); +return 0 ; +} +static void netkit_uninit (struct net_device *dev);static const struct net_device_ops netkit_netdev_ops = { + .ndo_init = netkit_init, .ndo_open = netkit_open, .ndo_stop = netkit_close, .ndo_start_xmit = netkit_xmit,
@@ -243,13 +261,87 @@ static const struct net_device_ops netkit_netdev_ops = {static void netkit_get_drvinfo (struct net_device *dev,struct ethtool_drvinfo *info) { -strscpy (info->driver,DRV_NAME ,sizeof (info->driver)); +strscpy (info->driver,NETKIT_DRV_NAME ,sizeof (info->driver)); }static const struct ethtool_ops netkit_ethtool_ops = { .get_drvinfo = netkit_get_drvinfo, }; +static int netkit_queue_create (struct net_device *dev) +{ +struct netkit *nk =netkit_priv (dev); +u32 rxq_count_old, rxq_count_new; +int err; + + rxq_count_old = dev->real_num_rx_queues; + rxq_count_new = rxq_count_old +1 ; + +/* Only allow to lease a queue in single device mode or to +* lease against the peer device which then ends up in the +* target netns. +*/ +if (nk->pair ==NETKIT_DEVICE_PAIR && nk->primary) +return -EOPNOTSUPP ; + +if (netif_running (dev)) +netif_carrier_off (dev); + err =netif_set_real_num_rx_queues (dev, rxq_count_new); +if (netif_running (dev)) +netif_carrier_on (dev); + +return err ? : rxq_count_old; +} + +static const struct netdev_queue_mgmt_ops netkit_queue_mgmt_ops = { + .ndo_queue_create = netkit_queue_create, +}; + +static struct net_device *netkit_alloc (struct nlattr *tb[], +const char *ifname, +unsigned char name_assign_type, +unsigned int num_tx_queues, +unsigned int num_rx_queues) +{ +const struct rtnl_link_ops *ops = &netkit_link_ops; +struct net_device *dev; + +if (num_tx_queues >NETKIT_NUM_TX_QUEUES_MAX || + num_rx_queues >NETKIT_NUM_RX_QUEUES_MAX ) +return ERR_PTR (-EOPNOTSUPP ); + + dev =alloc_netdev_mqs (ops->priv_size, ifname, + name_assign_type, ops->setup, + num_tx_queues, num_rx_queues); +if (dev) { + dev->real_num_tx_queues =NETKIT_NUM_TX_QUEUES_REAL ; + dev->real_num_rx_queues =NETKIT_NUM_RX_QUEUES_REAL ; + } +return dev; +} + +static void netkit_queue_unlease (struct net_device *dev) +{ +struct netdev_rx_queue *rxq, *rxq_lease; +struct net_device *dev_lease; +int i; + +if (dev->real_num_rx_queues ==1 ) +return ; + +netdev_lock (dev); +for (i =1 ; i < dev->real_num_rx_queues; i++) { + rxq =__netif_get_rx_queue (dev, i); + rxq_lease = rxq->lease; + dev_lease = rxq_lease->dev; + +netdev_lock (dev_lease); +netdev_rx_queue_unlease (rxq, rxq_lease); +netdev_unlock (dev_lease); + } +netdev_unlock (dev); +} +static void netkit_setup (struct net_device *dev) { static const netdev_features_t netkit_features_hw_vlan =
@@ -280,8 +372,9 @@ static void netkit_setup(struct net_device *dev) dev->priv_flags |=IFF_DISABLE_NETPOLL ; dev->lltx = true; - dev->ethtool_ops = &netkit_ethtool_ops; - dev->netdev_ops = &netkit_netdev_ops; + dev->netdev_ops = &netkit_netdev_ops; + dev->ethtool_ops = &netkit_ethtool_ops; + dev->queue_mgmt_ops = &netkit_queue_mgmt_ops; dev->features |= netkit_features; dev->hw_features = netkit_features;
@@ -330,8 +423,6 @@ static int netkit_validate(struct nlattr *tb[], struct nlattr *data[],return 0 ; } -static struct rtnl_link_ops netkit_link_ops; -static int netkit_new_link (struct net_device *dev,struct rtnl_newlink_params *params,struct netlink_ext_ack *extack)
@@ -867,6 +958,7 @@ static void netkit_release_all(struct net_device *dev)static void netkit_uninit (struct net_device *dev) {netkit_release_all (dev); +netkit_queue_unlease (dev); }static void netkit_del_link (struct net_device *dev,struct list_head *head)
@@ -1007,8 +1099,9 @@ static const struct nla_policy netkit_policy[IFLA_NETKIT_MAX + 1] = { };static struct rtnl_link_ops netkit_link_ops = { - .kind =DRV_NAME , + .kind =NETKIT_DRV_NAME , .priv_size =sizeof (struct netkit ), + .alloc = netkit_alloc, .setup = netkit_setup, .newlink = netkit_new_link, .dellink = netkit_del_link,
@@ -1022,7 +1115,7 @@ static struct rtnl_link_ops netkit_link_ops = { .maxtype = IFLA_NETKIT_MAX, }; -static __init int netkit_init (void ) +static __init int netkit_mod_init (void ) { BUILD_BUG_ON((int)NETKIT_NEXT != (int)TCX_NEXT || (int)NETKIT_PASS != (int)TCX_PASS ||
@@ -1032,16 +1125,16 @@ static __init int netkit_init(void)return rtnl_link_register (&netkit_link_ops); } -static __exit void netkit_exit(void) +static __exit void netkit_mod_exit(void) {rtnl_link_unregister (&netkit_link_ops); } -module_init (netkit_init); -module_exit (netkit_exit); +module_init (netkit_mod_init); +module_exit (netkit_mod_exit);MODULE_DESCRIPTION ("BPF-programmable network device" );MODULE_AUTHOR ("Daniel Borkmann <[email protected]>" );MODULE_AUTHOR ("Nikolay Aleksandrov <[email protected]>" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS_RTNL_LINK (DRV_NAME ); +MODULE_ALIAS_RTNL_LINK (NETKIT_DRV_NAME );
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 2/16 net: Implement netdev_nl_queue_create_doit
In reply to Daniel BorkmannImplement netdev_nl_queue_create_doit which creates a new rx queue in a virtual netdev and then leases it to a rx queue in a physical netdev.
Example with ynl client:
# ./pyynl/cli.py \
--spec ~/netlink/specs/netdev.yaml \
--do queue-create \
--json '{"ifindex": 8, "type": "rx", "lease": {"ifindex": 4, "queue": {"type": "rx", "id": 15}}}'
{'id': 1}Note that the netdevice locking order is always from the virtual to the physical device.
--- include/net/netdev_queues.h | 19 ++++- include/net/netdev_rx_queue.h | 9 ++- include/net/xdp_sock_drv.h | 2 +- net/core/dev.c | 7 ++ net/core/dev.h | 2 + net/core/netdev-genl.c | 146 +++++++++++++++++++++++++++++++++- net/core/netdev_queues.c | 57 +++++++++++++ net/core/netdev_rx_queue.c | 46 ++++++++++- net/xdp/xsk.c | 2 +- 9 files changed, 278 insertions(+), 12 deletions(-)
include/net/netdev_queues.h +16 -3
@@ -130,6 +130,11 @@ void netdev_stat_queue_sum(struct net_device *netdev,* @ndo_queue_get_dma_dev: Get dma device for zero-copy operations to be used * for this queue. Return NULL on error. * +* @ndo_queue_create: Create a new RX queue which can be leased to another queue. +* Ops on this queue are redirected to the leased queue e.g. +* when opening a memory provider. Return the new queue id on +* success. Return negative error code on failure. +* * Note that @ndo_queue_mem_alloc and @ndo_queue_mem_free may be called while * the interface is closed. @ndo_queue_start and @ndo_queue_stop will only * be called for an interface which is open.
@@ -149,9 +154,12 @@ struct netdev_queue_mgmt_ops { int idx);struct device * (*ndo_queue_get_dma_dev)(struct net_device *dev,int idx); +int (*ndo_queue_create)(struct net_device *dev); }; -bool netif_rxq_has_unreadable_mp (struct net_device *dev,int idx); +bool netif_rxq_has_unreadable_mp (struct net_device *dev,unsigned int rxq_idx); +bool netif_rxq_has_mp (struct net_device *dev,unsigned int rxq_idx); +bool netif_rxq_is_leased (struct net_device *dev,unsigned int rxq_idx);/** * DOC: Lockless queue stopping / waking helpers.
@@ -329,5 +337,10 @@ static inline void netif_subqueue_sent(const struct net_device *dev, })struct device *netdev_queue_get_dma_dev (struct net_device *dev,int idx); - -#endif +bool netdev_can_create_queue (const struct net_device *dev, +struct netlink_ext_ack *extack); +bool netdev_can_lease_queue (const struct net_device *dev, +struct netlink_ext_ack *extack); +bool netdev_queue_busy (struct net_device *dev,int idx, +struct netlink_ext_ack *extack); +#endif /* _LINUX_NET_QUEUES_H */
include/net/netdev_rx_queue.h +7 -2
@@ -28,6 +28,8 @@ struct netdev_rx_queue {#endif struct napi_struct *napi;struct pp_memory_provider_params mp_params; +struct netdev_rx_queue *lease; +netdevice_tracker lease_tracker; }____cacheline_aligned_in_smp ;/*
@@ -57,5 +59,8 @@ get_netdev_rx_queue_index(struct netdev_rx_queue *queue) }int netdev_rx_queue_restart (struct net_device *dev,unsigned int rxq); - -#endif +void netdev_rx_queue_lease (struct netdev_rx_queue *rxq_dst, +struct netdev_rx_queue *rxq_src); +void netdev_rx_queue_unlease (struct netdev_rx_queue *rxq_dst, +struct netdev_rx_queue *rxq_src); +#endif /* _LINUX_NETDEV_RX_QUEUE_H */
include/net/xdp_sock_drv.h +1 -1
@@ -28,7 +28,7 @@ void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries);bool xsk_tx_peek_desc (struct xsk_buff_pool *pool,struct xdp_desc *desc);u32 xsk_tx_peek_release_desc_batch (struct xsk_buff_pool *pool,u32 max);void xsk_tx_release (struct xsk_buff_pool *pool); -struct xsk_buff_pool *xsk_get_pool_from_qid (struct net_device *dev, +struct xsk_buff_pool *xsk_get_pool_from_qid (const struct net_device *dev,u16 queue_id);void xsk_set_rx_need_wakeup (struct xsk_buff_pool *pool);void xsk_set_tx_need_wakeup (struct xsk_buff_pool *pool);
net/core/dev.c +7 -0
@@ -1101,6 +1101,13 @@ netdev_get_by_index_lock_ops_compat(struct net *net, int ifindex)return __netdev_put_lock_ops_compat (dev, net); } +struct net_device * +netdev_put_lock (struct net_device *dev,netdevice_tracker *tracker) +{ +netdev_tracker_free (dev, tracker); +return __netdev_put_lock (dev,dev_net (dev)); +} +struct net_device *netdev_xa_find_lock (struct net *net,struct net_device *dev,unsigned long *index)
net/core/dev.h +2 -0
@@ -30,6 +30,8 @@ netdev_napi_by_id_lock(struct net *net, unsigned int napi_id);struct net_device *dev_get_by_napi_id (unsigned int napi_id);struct net_device *__netdev_put_lock (struct net_device *dev,struct net *net); +struct net_device *netdev_put_lock (struct net_device *dev, +netdevice_tracker *tracker);struct net_device *netdev_xa_find_lock (struct net *net,struct net_device *dev,unsigned long *index);
net/core/netdev-genl.c +145 -1
152 lines not on this page · raw message
net/core/netdev_queues.c +57 -0
66 lines not on this page · raw message
net/core/netdev_rx_queue.c +42 -4
57 lines not on this page · raw message
net/xdp/xsk.c +1 -1
@@ -103,7 +103,7 @@ bool xsk_uses_need_wakeup(struct xsk_buff_pool *pool) }EXPORT_SYMBOL (xsk_uses_need_wakeup); -struct xsk_buff_pool *xsk_get_pool_from_qid (struct net_device *dev, +struct xsk_buff_pool *xsk_get_pool_from_qid (const struct net_device *dev,u16 queue_id) {if (queue_id < dev->real_num_rx_queues)
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 11/16 netkit: Add netkit notifier to check for unregistering devices
In reply to Daniel BorkmannAdd a netdevice notifier in netkit to watch for NETDEV_UNREGISTER events. If the target device is indeed NETREG_UNREGISTERING and previously leased a queue to a netkit device, then collect the related netkit devices and batch-unregister_netdevice_many() them.
If this would not be done, then the netkit device would hold a reference on the physical device preventing it from going away. However, in case of both io_uring zero-copy as well as AF_XDP this situation is handled gracefully and the allocated resources are torn down.
In the case where mentioned infra is used through netkit, the applications have a reference on netkit, and netkit in turn holds a reference on the physical device. In order to have netkit release the reference on the physical device, we need such watcher to then unregister the netkit ones.
This is generally quite similar to the dependency handling in case of tunnels (e.g. vxlan bound to a underlying netdev) where the tunnel device gets removed along with the physical device.
# ip a
[...]
4: enp10s0f0np0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether e8:eb:d3:a3:43:f6 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.2/24 scope global enp10s0f0np0
valid_lft forever preferred_lft forever
[...]
8: nk@NONE: <BROADCAST,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
[...]# rmmod mlx5_ib # rmmod mlx5_core
[ 309.261822] mlx5_core 0000:0a:00.0 mlx5_0: Port: 1 Link DOWN [ 344.235236] mlx5_core 0000:0a:00.1: E-Switch: Unload vfs: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 344.246948] mlx5_core 0000:0a:00.1: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 344.463754] mlx5_core 0000:0a:00.1: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 344.770155] mlx5_core 0000:0a:00.1: E-Switch: cleanup [ 345.345709] mlx5_core 0000:0a:00.0: E-Switch: Unload vfs: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 345.357524] mlx5_core 0000:0a:00.0: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 350.995989] mlx5_core 0000:0a:00.0: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 351.574396] mlx5_core 0000:0a:00.0: E-Switch: cleanup
# ip a [...] [ both enp10s0f0np0 and nk gone ] [...]
--- drivers/net/netkit.c | 57 ++++++++++++++++++++++++++++++++++++++- include/linux/netdevice.h | 6 +++++ 2 files changed, 62 insertions(+), 1 deletion(-)
drivers/net/netkit.c +56 -1
@@ -1039,6 +1039,48 @@ static int netkit_change_link(struct net_device *dev, struct nlattr *tb[],return 0 ; } +static void netkit_check_lease_unregister (struct net_device *dev) +{ +LIST_HEAD (list_kill); +u32 q_idx; + +if (READ_ONCE (dev->reg_state) !=NETREG_UNREGISTERING || + !dev->dev.parent) +return ; + +netdev_lock_ops (dev); +for (q_idx =0 ; q_idx < dev->real_num_rx_queues; q_idx++) { +struct net_device *tmp = dev; +u32 tmp_q_idx = q_idx; + +if (netif_rx_queue_lease_get_owner (&tmp, &tmp_q_idx)) { +if (tmp->netdev_ops != &netkit_netdev_ops) +continue ; +/* A single phys device can have multiple queues leased +* to one netkit device. We can only queue that netkit +* device once to the list_kill. Queues of that phys +* device can be leased with different individual netkit +* devices, hence we batch via list_kill. +*/ +if (unregister_netdevice_queued (tmp)) +continue ; +netkit_del_link (tmp, &list_kill); + } + } +netdev_unlock_ops (dev); +unregister_netdevice_many (&list_kill); +} + +static int netkit_notifier (struct notifier_block *this, +unsigned long event,void *ptr) +{ +struct net_device *dev =netdev_notifier_info_to_dev (ptr); + +if (event ==NETDEV_UNREGISTER ) +netkit_check_lease_unregister (dev); +return NOTIFY_DONE ; +} +static size_t netkit_get_size (const struct net_device *dev) { return nla_total_size(sizeof(u32)) + /* IFLA_NETKIT_POLICY */
@@ -1115,18 +1157,31 @@ static struct rtnl_link_ops netkit_link_ops = { .maxtype = IFLA_NETKIT_MAX, }; +static struct notifier_block netkit_netdev_notifier = { + .notifier_call = netkit_notifier, +}; +static __init int netkit_mod_init (void ) { +int ret; +BUILD_BUG_ON ((int )NETKIT_NEXT != (int )TCX_NEXT || (int )NETKIT_PASS != (int )TCX_PASS || (int )NETKIT_DROP != (int )TCX_DROP || (int )NETKIT_REDIRECT != (int )TCX_REDIRECT ); -return rtnl_link_register (&netkit_link_ops); + ret =rtnl_link_register (&netkit_link_ops); +if (ret) +return ret; + ret =register_netdevice_notifier (&netkit_netdev_notifier); +if (ret) +rtnl_link_unregister (&netkit_link_ops); +return ret; } static __exit void netkit_mod_exit(void) { +unregister_netdevice_notifier (&netkit_netdev_notifier);rtnl_link_unregister (&netkit_link_ops); }
include/linux/netdevice.h +6 -0
@@ -3400,11 +3400,17 @@ static inline int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)int register_netdevice (struct net_device *dev);void unregister_netdevice_queue (struct net_device *dev,struct list_head *head);void unregister_netdevice_many (struct list_head *head); +static inline void unregister_netdevice (struct net_device *dev) {unregister_netdevice_queue (dev,NULL ); } +static inline bool unregister_netdevice_queued (const struct net_device *dev) +{ +return !list_empty (&dev->unreg_list); +} +int netdev_refcnt_read (const struct net_device *dev);void free_netdev (struct net_device *dev);
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 14/16 selftests/net: Add env for container based tests
In reply to Daniel BorkmannFrom: David Wei <[email protected]>
Add an env NetDrvContEnv for container based selftests. This automates the setup of a netns, netkit pair with one inside the netns, and a BPF program that forwards skbs from the NETIF host inside the container.
Currently only netkit is used, but other virtual netdevs e.g. veth can be used too.
Expect netkit container datapath selftests to have a publicly routable IP prefix to assign to netkit in a container, such that packets will land on eth0. The BPF skb forward program will then forward such packets from the host netns to the container netns.
--- .../testing/selftests/drivers/net/README.rst | 7 ++ .../drivers/net/hw/lib/py/__init__.py | 7 +- .../selftests/drivers/net/lib/py/__init__.py | 7 +- .../selftests/drivers/net/lib/py/env.py | 112 ++++++++++++++++++ 4 files changed, 127 insertions(+), 6 deletions(-)
tools/testing/selftests/drivers/net/README.rst +7 -0
@@ -62,6 +62,13 @@ LOCAL_V4, LOCAL_V6, REMOTE_V4, REMOTE_V6 Local and remote endpoint IP addresses. +LOCAL_PREFIX_V4, LOCAL_PREFIX_V6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Local IP prefix/subnet which can be used to allocate extra IP addresses (for +network name spaces behind macvlan, veth, netkit devices). DUT must be +reachable using these addresses from the endpoint. + REMOTE_TYPE ~~~~~~~~~~~
tools/testing/selftests/drivers/net/hw/lib/py/__init__.py +4 -3
@@ -3,6 +3,7 @@ """ Driver test environment (hardware-only tests). NetDrvEnv and NetDrvEpEnv are the main environment classes. +NetDrvContEnv extends NetDrvEpEnv with netkit container support. Former is for local host only tests, latter creates / connects to a remote endpoint. See NIPA wiki for more information about running and writing driver tests.
@@ -29,7 +30,7 @@ try: from net.lib.py import ksft_eq, ksft_ge, ksft_in, ksft_is, ksft_lt, \ ksft_ne, ksft_not_in, ksft_raises, ksft_true, ksft_gt, ksft_not_none from drivers.net.lib.py import GenerateTraffic, Remote, Iperf3Runner - from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv + from drivers.net.lib.py import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv __all__ = ["NetNS", "NetNSEnter", "NetdevSimDev", "EthtoolFamily", "NetdevFamily", "NetshaperFamily",
@@ -44,8 +45,8 @@ try: "ksft_eq", "ksft_ge", "ksft_in", "ksft_is", "ksft_lt", "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt", "ksft_not_none", "ksft_not_none", - "NetDrvEnv", "NetDrvEpEnv", "GenerateTraffic", "Remote", - "Iperf3Runner"] + "NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic", + "Remote", "Iperf3Runner"] except ModuleNotFoundError as e: print("Failed importing `net` library from kernel sources") print(str(e))
tools/testing/selftests/drivers/net/lib/py/__init__.py +4 -3
@@ -3,6 +3,7 @@ """ Driver test environment. NetDrvEnv and NetDrvEpEnv are the main environment classes. +NetDrvContEnv extends NetDrvEpEnv with netkit container support. Former is for local host only tests, latter creates / connects to a remote endpoint. See NIPA wiki for more information about running and writing driver tests.
@@ -43,12 +44,12 @@ try: "ksft_ne", "ksft_not_in", "ksft_raises", "ksft_true", "ksft_gt", "ksft_not_none", "ksft_not_none"] - from .env import NetDrvEnv, NetDrvEpEnv + from .env import NetDrvEnv, NetDrvEpEnv, NetDrvContEnv from .load import GenerateTraffic, Iperf3Runner from .remote import Remote - __all__ += ["NetDrvEnv", "NetDrvEpEnv", "GenerateTraffic", "Remote", - "Iperf3Runner"] + __all__ += ["NetDrvEnv", "NetDrvEpEnv", "NetDrvContEnv", "GenerateTraffic", + "Remote", "Iperf3Runner"] except ModuleNotFoundError as e: print("Failed importing `net` library from kernel sources") print(str(e))
tools/testing/selftests/drivers/net/lib/py/env.py +112 -0
127 lines not on this page · raw message
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 15/16 selftests/net: Make NetDrvContEnv support queue leasing
In reply to Daniel BorkmannFrom: David Wei <[email protected]>
Add a new parameter lease to NetDrvContEnv that sets up queue leasing in the env.
The NETIF also has some ethtool parameters changed to support memory provider tests. This is needed in NetDrvContEnv rather than individual test cases since the cleanup to restore NETIF can't be done, until the netns in the env is gone.
--- .../selftests/drivers/net/lib/py/env.py | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/lib/py/env.py +46 -1
@@ -9,6 +9,7 @@ from lib.py import KsftSkipEx, KsftXfailEx from lib.py import ksft_setup, wait_file from lib.py import cmd, ethtool, ip, CmdExitFailure from lib.py import NetNS, NetdevSimDev +from lib.py import NetdevFamily, EthtoolFamily from .remote import Remote from . import bpftool
@@ -300,7 +301,7 @@ class NetDrvContEnv(NetDrvEpEnv): between the physical interface and a network namespace. """ - def __init__(self, src_path, nk_rxqueues=1, **kwargs): + def __init__(self, src_path, lease=False, **kwargs): super().__init__(src_path, **kwargs) self.require_ipver("6")
@@ -308,6 +309,9 @@ class NetDrvContEnv(NetDrvEpEnv): if not local_prefix: raise KsftSkipEx("LOCAL_PREFIX_V6 required") + self.netdevnl = NetdevFamily() + self.ethnl = EthtoolFamily() + local_prefix = local_prefix.rstrip("/64").rstrip("::").rstrip(":") self.ipv6_prefix = f"{local_prefix}::" self.nk_host_ipv6 = f"{local_prefix}::2:1"
@@ -319,7 +323,11 @@ class NetDrvContEnv(NetDrvEpEnv): self._tc_attached = False self._bpf_prog_pref = None self._bpf_prog_id = None + self._leased = False + nk_rxqueues = 1 + if lease: + nk_rxqueues = 2 ip(f"link add type netkit mode l2 forward peer forward numrxqueues {nk_rxqueues}") all_links = ip("-d link show", json=True)
@@ -336,6 +344,9 @@ class NetDrvContEnv(NetDrvEpEnv): self.nk_host_ifindex = netkit_links[1]['ifindex'] self.nk_guest_ifindex = netkit_links[0]['ifindex'] + if lease: + self._lease_queues() + self._setup_ns() self._attach_bpf()
@@ -353,8 +364,42 @@ class NetDrvContEnv(NetDrvEpEnv): del self.netns self.netns = None + if self._leased: + self.ethnl.rings_set({'header': {'dev-index': self.ifindex}, + 'tcp-data-split': 'unknown', + 'hds-thresh': self._hds_thresh, + 'rx': self._rx_rings}) + self._leased = False + super().__del__() + def _lease_queues(self): + channels = self.ethnl.channels_get({'header': {'dev-index': self.ifindex}}) + channels = channels['combined-count'] + if channels < 2: + raise KsftSkipEx('Test requires NETIF with at least 2 combined channels') + + rings = self.ethnl.rings_get({'header': {'dev-index': self.ifindex}}) + self._rx_rings = rings['rx'] + self._hds_thresh = rings.get('hds-thresh', 0) + self.ethnl.rings_set({'header': {'dev-index': self.ifindex}, + 'tcp-data-split': 'enabled', + 'hds-thresh': 0, + 'rx': 64}) + self.src_queue = channels - 1 + bind_result = self.netdevnl.queue_create( + { + "ifindex": self.nk_guest_ifindex, + "type": "rx", + "lease": { + "ifindex": self.ifindex, + "queue": {"id": self.src_queue, "type": "rx"}, + }, + } + ) + self.nk_queue = bind_result['id'] + self._leased = True + def _setup_ns(self): self.netns = NetNS() ip(f"link set dev {self._nk_guest_ifname} netns {self.netns.name}")
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 16/16 selftests/net: Add netkit container tests
In reply to Daniel BorkmannFrom: David Wei <[email protected]>
Add two tests using NetDrvContEnv. One basic test that sets up a netkit pair, with one end in a netns. Use LOCAL_PREFIX_V6 and nk_forward BPF program to ping from a remote host to the netkit in netns.
Second is a selftest for netkit queue leasing, using io_uring zero copy test binary inside of a netns with netkit. This checks that memory providers can be bound against virtual queues in a netkit within a netns that are leasing from a physical netdev in the default netns.
--- .../testing/selftests/drivers/net/hw/Makefile | 2 + .../selftests/drivers/net/hw/nk_netns.py | 23 ++++++++ .../selftests/drivers/net/hw/nk_qlease.py | 55 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/nk_netns.py create mode 100755 tools/testing/selftests/drivers/net/hw/nk_qlease.py
tools/testing/selftests/drivers/net/hw/Makefile +2 -0
@@ -32,6 +32,8 @@ TEST_PROGS = \ irq.py \ loopback.sh \ nic_timestamp.py \ + nk_netns.py \ + nk_qlease.py \ pp_alloc_fail.py \ rss_api.py \ rss_ctx.py \
tools/testing/selftests/drivers/net/hw/nk_netns.py new file +23 -0
@@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +from lib.py import ksft_run, ksft_exit +from lib.py import NetDrvContEnv +from lib.py import cmd + + +def test_ping(cfg) -> None: + cfg.require_ipver("6") + + cmd(f"ping -c 1 -W5 {cfg.nk_guest_ipv6}", host=cfg.remote) + cmd(f"ping -c 1 -W5 {cfg.remote_addr_v['6']}", ns=cfg.netns) + + +def main() -> None: + with NetDrvContEnv(__file__) as cfg: + ksft_run([test_ping], args=(cfg,)) + ksft_exit() + + +if __name__ == "__main__": + main()
tools/testing/selftests/drivers/net/hw/nk_qlease.py new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 13/16 selftests/net: Add bpf skb forwarding program
In reply to Daniel BorkmannFrom: David Wei <[email protected]>
Add nk_forward.bpf.c, a BPF program that forwards skbs matching some IPv6 prefix received on eth0 ifindex to a specified netkit ifindex. This will be needed by netkit container tests.
--- .../selftests/drivers/net/hw/nk_forward.bpf.c | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c
tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c new file +49 -0
@@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/bpf.h> +#include <linux/pkt_cls.h> +#include <linux/if_ether.h> +#include <linux/ipv6.h> +#include <linux/in6.h> +#include <bpf/bpf_endian.h> +#include <bpf/bpf_helpers.h> + +#define TC_ACT_OK 0 +#define ETH_P_IPV6 0x86DD + +#define ctx_ptr (field) ((void *)(long)(field)) + +#define v6_p64_equal (a, b) (a.s6_addr32[0] == b.s6_addr32[0] && \ + a.s6_addr32[1] == b.s6_addr32[1]) + +volatile __u32 netkit_ifindex; +volatile __u8 ipv6_prefix[16 ]; + +SEC("tc/ingress") +int tc_redirect_peer (struct __sk_buff *skb) +{ +void *data_end =ctx_ptr (skb->data_end); +void *data =ctx_ptr (skb->data); +struct in6_addr *peer_addr; +struct ipv6hdr *ip6h; +struct ethhdr *eth; + + peer_addr = (struct in6_addr *)ipv6_prefix; + +if (skb->protocol !=bpf_htons (ETH_P_IPV6 )) +return TC_ACT_OK ; + + eth = data; +if ((void *)(eth +1 ) > data_end) +return TC_ACT_OK ; + + ip6h = data +sizeof (struct ethhdr ); +if ((void *)(ip6h +1 ) > data_end) +return TC_ACT_OK ; + +if (!v6_p64_equal (ip6h->daddr, (*peer_addr))) +return TC_ACT_OK ; + +return bpf_redirect_peer (netkit_ifindex,0 ); +} + +char __license[] SEC("license") = "GPL";
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 9/16 netkit: Add single device mode for netkit
In reply to Daniel BorkmannAdd a single device mode for netkit instead of netkit pairs. The primary target for the paired devices is to connect network namespaces, of course, and support has been implemented in projects like Cilium [0]. For the rxq leasing the plan is to support two main scenarios related to single device mode:
* For the use-case of io_uring zero-copy, the control plane can either set up a netkit pair where the peer device can perform rxq leasing which is then tied to the lifetime of the peer device, or the control plane can use a regular netkit pair to connect the hostns to a Pod/container and dynamically add/remove rxq leasing through a single device without having to interrupt the device pair. In the case of io_uring, the memory pool is used as skb non-linear pages, and thus the skb will go its way through the regular stack into netkit. Things like the netkit policy when no BPF is attached or skb scrubbing etc apply as-is in case the paired devices are used, or if the backend memory is tied to the single device and traffic goes through a paired device.
* For the use-case of AF_XDP, the control plane needs to use netkit in the single device mode. The single device mode currently enforces only a pass policy when no BPF is attached, and does not yet support BPF link attachments for AF_XDP. skbs sent to that device get dropped at the moment. Given AF_XDP operates at a lower layer of the stack tying this to the netkit pair did not make sense. In future, the plan is to allow BPF at the XDP layer which can: i) process traffic coming from the AF_XDP application (e.g. QEMU with AF_XDP backend) to filter egress traffic or to push selected egress traffic up to the single netkit device to the local stack (e.g. DHCP requests), and ii) vice-versa skbs sent to the single netkit into the AF_XDP application (e.g. DHCP replies). Also, the control-plane can dynamically manage rxq leasing for the single netkit device without having to interrupt (e.g. down/up cycle) the main netkit pair for the Pod which has traffic going in and out.
--- drivers/net/netkit.c | 110 ++++++++++++++++++++++------------- include/uapi/linux/if_link.h | 6 ++ 2 files changed, 76 insertions(+), 40 deletions(-)
drivers/net/netkit.c +70 -40
@@ -26,6 +26,7 @@ struct netkit {__cacheline_group_begin (netkit_slowpath);enum netkit_mode mode; +enum netkit_pairing pair;bool primary;u32 headroom;__cacheline_group_end (netkit_slowpath);
@@ -135,6 +136,10 @@ static int netkit_open(struct net_device *dev)struct netkit *nk =netkit_priv (dev);struct net_device *peer =rtnl_dereference (nk->peer); +if (nk->pair ==NETKIT_DEVICE_SINGLE ) { +netif_carrier_on (dev); +return 0 ; + }if (!peer)return -ENOTCONN ;if (peer->flags &IFF_UP ) {
@@ -335,6 +340,7 @@ static int netkit_new_link(struct net_device *dev,enum netkit_scrub scrub_prim =NETKIT_SCRUB_DEFAULT ;enum netkit_scrub scrub_peer =NETKIT_SCRUB_DEFAULT ;struct nlattr *peer_tb[IFLA_MAX +1 ], **tbp, *attr; +enum netkit_pairing pair =NETKIT_DEVICE_PAIR ;enum netkit_action policy_prim =NETKIT_PASS ;enum netkit_action policy_peer =NETKIT_PASS ;struct nlattr **data = params->data;
@@ -343,7 +349,8 @@ static int netkit_new_link(struct net_device *dev,struct nlattr **tb = params->tb;u16 headroom =0 , tailroom =0 ;struct ifinfomsg *ifmp =NULL ; -struct net_device *peer; +struct net_device *peer =NULL ; +bool seen_peer = false;char ifname[IFNAMSIZ ];struct netkit *nk;int err;
@@ -380,6 +387,12 @@ static int netkit_new_link(struct net_device *dev, headroom =nla_get_u16 (data[IFLA_NETKIT_HEADROOM ]);if (data[IFLA_NETKIT_TAILROOM ]) tailroom =nla_get_u16 (data[IFLA_NETKIT_TAILROOM ]); +if (data[IFLA_NETKIT_PAIRING ]) + pair =nla_get_u32 (data[IFLA_NETKIT_PAIRING ]); + + seen_peer = data[IFLA_NETKIT_PEER_INFO ] || + data[IFLA_NETKIT_PEER_SCRUB ] || + data[IFLA_NETKIT_PEER_POLICY ]; }if (ifmp && tbp[IFLA_IFNAME ]) {
@@ -392,45 +405,46 @@ static int netkit_new_link(struct net_device *dev,if (mode !=NETKIT_L2 && (tb[IFLA_ADDRESS ] || tbp[IFLA_ADDRESS ]))return -EOPNOTSUPP ; +if (pair ==NETKIT_DEVICE_SINGLE && + (tb != tbp || seen_peer || policy_prim !=NETKIT_PASS )) +return -EOPNOTSUPP ; - peer =rtnl_create_link (peer_net, ifname, ifname_assign_type, - &netkit_link_ops, tbp, extack); -if (IS_ERR (peer)) -return PTR_ERR (peer); - -netif_inherit_tso_max (peer, dev); -if (headroom) { - peer->needed_headroom = headroom; - dev->needed_headroom = headroom; - } -if (tailroom) { - peer->needed_tailroom = tailroom; - dev->needed_tailroom = tailroom; - } - -if (mode ==NETKIT_L2 && !(ifmp && tbp[IFLA_ADDRESS ])) -eth_hw_addr_random (peer); -if (ifmp && dev->ifindex) - peer->ifindex = ifmp->ifi_index; - - nk =netkit_priv (peer); - nk->primary = false; - nk->policy = policy_peer; - nk->scrub = scrub_peer; - nk->mode = mode; - nk->headroom = headroom; -bpf_mprog_bundle_init (&nk->bundle); +if (pair ==NETKIT_DEVICE_PAIR ) { + peer =rtnl_create_link (peer_net, ifname, ifname_assign_type, + &netkit_link_ops, tbp, extack); +if (IS_ERR (peer)) +return PTR_ERR (peer); + +netif_inherit_tso_max (peer, dev); +if (headroom) + peer->needed_headroom = headroom; +if (tailroom) + peer->needed_tailroom = tailroom; +if (mode ==NETKIT_L2 && !(ifmp && tbp[IFLA_ADDRESS ])) +eth_hw_addr_random (peer); +if (ifmp && dev->ifindex) + peer->ifindex = ifmp->ifi_index; - err =register_netdevice (peer); -if (err <0 ) - goto err_register_peer; -netif_carrier_off (peer); -if (mode ==NETKIT_L2 ) -dev_change_flags (peer, peer->flags & ~IFF_NOARP ,NULL ); + nk =netkit_priv (peer); + nk->primary = false; + nk->policy = policy_peer; + nk->scrub = scrub_peer; + nk->mode = mode; + nk->pair = pair; + nk->headroom = headroom; +bpf_mprog_bundle_init (&nk->bundle); + + err =register_netdevice (peer); +if (err <0 ) + goto err_register_peer; +netif_carrier_off (peer); +if (mode ==NETKIT_L2 ) +dev_change_flags (peer, peer->flags & ~IFF_NOARP ,NULL ); - err =rtnl_configure_link (peer,NULL ,0 ,NULL ); -if (err <0 ) - goto err_configure_peer; + err =rtnl_configure_link (peer,NULL ,0 ,NULL ); +if (err <0 ) + goto err_configure_peer; + }if (mode ==NETKIT_L2 && !tb[IFLA_ADDRESS ])eth_hw_addr_random (dev);
@@ -438,12 +452,17 @@ static int netkit_new_link(struct net_device *dev,nla_strscpy (dev->name, tb[IFLA_IFNAME ],IFNAMSIZ ); else strscpy(dev->name, "nk%d", IFNAMSIZ); +if (headroom) + dev->needed_headroom = headroom; +if (tailroom) + dev->needed_tailroom = tailroom; nk =netkit_priv (dev); nk->primary = true; nk->policy = policy_prim; nk->scrub = scrub_prim; nk->mode = mode; + nk->pair = pair; nk->headroom = headroom;bpf_mprog_bundle_init (&nk->bundle);
@@ -455,10 +474,12 @@ static int netkit_new_link(struct net_device *dev,dev_change_flags (dev, dev->flags & ~IFF_NOARP ,NULL );rcu_assign_pointer (netkit_priv (dev)->peer, peer); -rcu_assign_pointer (netkit_priv (peer)->peer, dev); +if (peer) +rcu_assign_pointer (netkit_priv (peer)->peer, dev);return 0 ; err_configure_peer: -unregister_netdevice (peer); +if (peer) +unregister_netdevice (peer);return err; err_register_peer:free_netdev (peer);
@@ -518,6 +539,8 @@ static struct net_device *netkit_dev_fetch(struct net *net, u32 ifindex, u32 whi nk =netkit_priv (dev);if (!nk->primary)return ERR_PTR (-EACCES ); +if (nk->pair ==NETKIT_DEVICE_SINGLE ) +return ERR_PTR (-EOPNOTSUPP );if (which ==BPF_NETKIT_PEER ) { dev =rcu_dereference_rtnl (nk->peer);if (!dev)
@@ -879,6 +902,7 @@ static int netkit_change_link(struct net_device *dev, struct nlattr *tb[], { IFLA_NETKIT_PEER_INFO, "peer info" }, { IFLA_NETKIT_HEADROOM, "headroom" }, { IFLA_NETKIT_TAILROOM, "tailroom" }, + { IFLA_NETKIT_PAIRING, "pairing" }, };if (!nk->primary) {
@@ -898,9 +922,11 @@ static int netkit_change_link(struct net_device *dev, struct nlattr *tb[], }if (data[IFLA_NETKIT_POLICY ]) { + err = -EOPNOTSUPP ; attr = data[IFLA_NETKIT_POLICY ]; policy =nla_get_u32 (attr); - err =netkit_check_policy (policy, attr, extack); +if (nk->pair ==NETKIT_DEVICE_PAIR ) + err =netkit_check_policy (policy, attr, extack);if (err)return err;WRITE_ONCE (nk->policy, policy);
@@ -931,6 +957,7 @@ static size_t netkit_get_size(const struct net_device *dev)nla_total_size (sizeof (u8)) +/* IFLA_NETKIT_PRIMARY */ nla_total_size (sizeof (u16)) +/* IFLA_NETKIT_HEADROOM */ nla_total_size (sizeof (u16)) +/* IFLA_NETKIT_TAILROOM */ +nla_total_size (sizeof (u32)) +/* IFLA_NETKIT_PAIRING */ 0 ; }
@@ -951,6 +978,8 @@ static int netkit_fill_info(struct sk_buff *skb, const struct net_device *dev)return -EMSGSIZE ;if (nla_put_u16 (skb,IFLA_NETKIT_TAILROOM , dev->needed_tailroom))return -EMSGSIZE ; +if (nla_put_u32 (skb,IFLA_NETKIT_PAIRING , nk->pair)) +return -EMSGSIZE ;if (peer) { nk =netkit_priv (peer);
@@ -972,6 +1001,7 @@ static const struct nla_policy netkit_policy[IFLA_NETKIT_MAX + 1] = { [IFLA_NETKIT_TAILROOM] = { .type = NLA_U16 }, [IFLA_NETKIT_SCRUB] = NLA_POLICY_MAX(NLA_U32, NETKIT_SCRUB_DEFAULT), [IFLA_NETKIT_PEER_SCRUB] = NLA_POLICY_MAX(NLA_U32, NETKIT_SCRUB_DEFAULT), + [IFLA_NETKIT_PAIRING] = NLA_POLICY_MAX(NLA_U32, NETKIT_DEVICE_SINGLE), [IFLA_NETKIT_PRIMARY ] = { .type =NLA_REJECT , .reject_message = "Primary attribute is read-only" }, };
include/uapi/linux/if_link.h +6 -0
@@ -1296,6 +1296,11 @@ enum netkit_mode { NETKIT_L3, }; +enum netkit_pairing { +NETKIT_DEVICE_PAIR , +NETKIT_DEVICE_SINGLE , +}; +/* NETKIT_SCRUB_NONE leaves clearing skb->{mark,priority} up to * the BPF program if attached. This also means the latter can * consume the two fields if they were populated earlier.
@@ -1320,6 +1325,7 @@ enum {IFLA_NETKIT_PEER_SCRUB ,IFLA_NETKIT_HEADROOM ,IFLA_NETKIT_TAILROOM , +IFLA_NETKIT_PAIRING , __IFLA_NETKIT_MAX, };#define IFLA_NETKIT_MAX (__IFLA_NETKIT_MAX - 1)
Signature · 1 line
2.43.0
Daniel Borkmann
maintainerPATCH v7 12/16 netkit: Add xsk support for af_xdp applications
In reply to Daniel BorkmannEnable support for AF_XDP applications to operate on a netkit device. The goal is that AF_XDP applications can natively consume AF_XDP from network namespaces. The use-case from Cilium side is to support Kubernetes KubeVirt VMs through QEMU's AF_XDP backend. KubeVirt is a virtual machine management add-on for Kubernetes which aims to provide a common ground for virtualization. KubeVirt spawns the VMs inside Kubernetes Pods which reside in their own network namespace just like regular Pods.
Raw QEMU AF_XDP backend example with eth0 being a physical device with 16 queues where netkit is bound to the last queue (for multi-queue RSS context can be used if supported by the driver):
# ethtool -X eth0 start 0 equal 15
# ethtool -X eth0 start 15 equal 1 context new
# ethtool --config-ntuple eth0 flow-type ether \
src 00:00:00:00:00:00 \
src-mask ff:ff:ff:ff:ff:ff \
dst $mac dst-mask 00:00:00:00:00:00 \
proto 0 proto-mask 0xffff action 15
[ ... setup BPF/XDP prog on eth0 to steer into shared xsk map ... ]
# ip netns add foo
# ip link add numrxqueues 2 nk type netkit single
# ./pyynl/cli.py --spec ~/netlink/specs/netdev.yaml \
--do queue-create \
--json "{"ifindex": $(ifindex nk), "type": "rx", \
"lease": { "ifindex": $(ifindex eth0), \
"queue": { "type": "rx", "id": 15 } } }"
{'id': 1}
# ip link set nk netns foo
# ip netns exec foo ip link set lo up
# ip netns exec foo ip link set nk up
# ip netns exec foo qemu-system-x86_64 \
-kernel $kernel \
-drive file=${image_name},index=0,media=disk,format=raw \
-append "root=/dev/sda rw console=ttyS0" \
-cpu host \
-m $memory \
-enable-kvm \
-device virtio-net-pci,netdev=net0,mac=$mac \
-netdev af-xdp,ifname=nk,id=net0,mode=native,queues=1,start-queue=1,inhibit=on,map-path=$dir/xsks_map \
-nographicWe have tested the above against a dual-port Nvidia ConnectX-6 (mlx5) 100G NIC with successful network connectivity out of QEMU. An earlier iteration of this work was presented at LSF/MM/BPF [0] and more recently at LPC [1].
For getting to a first starting point to connect all things with KubeVirt, bind mounting the xsk map from Cilium into the VM launcher Pod which acts as a regular Kubernetes Pod while not perfect, is not a big problem given its out of reach from the application sitting inside the VM (and some of the control plane aspects are baked in the launcher Pod already), so the isolation barrier is still the VM. Eventually the goal is to have a XDP/XSK redirect extension where there is no need to have the xsk map, and the BPF program can just derive the target xsk through the queue where traffic was received on.
The exposure through netkit is because Cilium should not act as a proxy handing out xsk sockets. Existing applications expect a netdev from kernel side and should not need to rewrite just to implement against a CNI's protocol. Also, all the memory should not be accounted against Cilium but rather the application Pod itself which is consuming AF_XDP. Further, on up/downgrades we expect the data plane to being completely decoupled from the control plane; if Cilium would own the sockets that would be disruptive. Another use-case which opens up and is regularly asked from users would be to have DPDK applications on top of AF_XDP in regular Kubernetes Pods.
--- drivers/net/netkit.c | 76 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-)
drivers/net/netkit.c +75 -1
@@ -12,6 +12,7 @@#include <net/netdev_lock.h> #include <net/netdev_queues.h> #include <net/netdev_rx_queue.h> +#include <net/xdp_sock_drv.h> #include <net/netkit.h> #include <net/dst.h> #include <net/tcx.h>
@@ -235,6 +236,76 @@ static void netkit_get_stats(struct net_device *dev, stats->tx_dropped =DEV_STATS_READ (dev, tx_dropped); } +static bool netkit_xsk_supported_at_phys (const struct net_device *dev) +{ +if (!dev->netdev_ops->ndo_bpf || + !dev->netdev_ops->ndo_xdp_xmit || + !dev->netdev_ops->ndo_xsk_wakeup) +return false; +if ((dev->xdp_features &NETDEV_XDP_ACT_XSK ) !=NETDEV_XDP_ACT_XSK ) +return false; +return true; +} + +static int netkit_xsk (struct net_device *dev,struct netdev_bpf *xdp) +{ +struct netkit *nk =netkit_priv (dev); +struct netdev_bpf xdp_lower; +struct netdev_rx_queue *rxq; +struct net_device *phys; +int ret = -EBUSY ; + +switch (xdp->command) { +case XDP_SETUP_XSK_POOL : +if (nk->pair ==NETKIT_DEVICE_PAIR ) +return -EOPNOTSUPP ; +if (xdp->xsk.queue_id >= dev->real_num_rx_queues) +return -EINVAL ; + + rxq =__netif_get_rx_queue (dev, xdp->xsk.queue_id); +if (!rxq->lease) +return -EOPNOTSUPP ; + + phys = rxq->lease->dev; +if (!netkit_xsk_supported_at_phys (phys)) +return -EOPNOTSUPP ; + +memcpy (&xdp_lower, xdp,sizeof (xdp_lower)); + xdp_lower.xsk.queue_id =get_netdev_rx_queue_index (rxq->lease); +break ; +case XDP_SETUP_PROG : +return -EPERM ; +default : +return -EINVAL ; + } + +netdev_lock (phys); +if (!dev_get_min_mp_channel_count (phys)) + ret = phys->netdev_ops->ndo_bpf (phys, &xdp_lower); +netdev_unlock (phys); +return ret; +} + +static int netkit_xsk_wakeup (struct net_device *dev,u32 queue_id,u32 flags) +{ +struct netdev_rx_queue *rxq; +struct net_device *phys; + +if (queue_id >= dev->real_num_rx_queues) +return -EINVAL ; + + rxq =__netif_get_rx_queue (dev, queue_id); +if (!rxq->lease) +return -EOPNOTSUPP ; + + phys = rxq->lease->dev; +if (!netkit_xsk_supported_at_phys (phys)) +return -EOPNOTSUPP ; + +return phys->netdev_ops->ndo_xsk_wakeup (phys, +get_netdev_rx_queue_index (rxq->lease), flags); +} +static int netkit_init (struct net_device *dev) {netdev_lockdep_set_classes (dev);
@@ -255,6 +326,8 @@ static const struct net_device_ops netkit_netdev_ops = { .ndo_get_peer_dev = netkit_peer_dev, .ndo_get_stats64 = netkit_get_stats, .ndo_uninit = netkit_uninit, + .ndo_bpf = netkit_xsk, + .ndo_xsk_wakeup = netkit_xsk_wakeup, .ndo_features_check = passthru_features_check, };
@@ -381,10 +454,11 @@ static void netkit_setup(struct net_device *dev) dev->hw_enc_features = netkit_features; dev->mpls_features =NETIF_F_HW_CSUM |NETIF_F_GSO_SOFTWARE ; dev->vlan_features = dev->features & ~netkit_features_hw_vlan; - dev->needs_free_netdev = true;netif_set_tso_max_size (dev,GSO_MAX_SIZE ); + +xdp_set_features_flag (dev,NETDEV_XDP_ACT_XSK ); }static struct net *netkit_get_link_net (const struct net_device *dev)
Signature · 1 line
2.43.0
Re: [PATCH net-next v7 01/16] net: Add queue-create operation
In reply to Daniel BorkmannQuoted 49 lines · Daniel Borkmann
Add a ynl netdev family operation called queue-create that creates a new queue on a netdevice:
name: queue-create
attribute-set: queue
flags: [admin-perm]
do:
request:
attributes:
- ifindex
- type
- lease
reply: &queue-create-op
attributes:
- idThis is a generic operation such that it can be extended for various use cases in future. Right now it is mandatory to specify ifindex, the queue type which is enforced to rx and a lease. The newly created queue id is returned to the caller.
A queue from a virtual device can have a lease which refers to another queue from a physical device. This is useful for memory providers and
AF_XDPoperations which take an ifindex and queue id to allow applications to bind against virtual devices in containers. The lease couples both queues together and allows to proxy the operations from a virtual device in a container to the physical device.In future, the nested lease attribute can be lifted and made optional for other use-cases such as dynamic queue creation for physical netdevs. The lack of lease and the specification of the physical device as an ifindex will imply that we need a real queue to be allocated. Similarly, the queue type enforcement to rx can then be lifted as well to support tx.
An early implementation had only driver-specific integration [0], but in order for other virtual devices to reuse, it makes sense to have this as a generic API in core net.
For leasing queues, the virtual netdev must have
real_num_rx_queueless thannum_rx_queuesat the time of calling queue-create. The queue-type must be rx as only rx queues are supported for leasing for now. We also enforce that the queue-create ifindex must point to a virtual device, and that the nested lease attribute's ifindex must point to a physical device. The nested lease attribute set contains a netns-id attribute which is currently only intended for dumping as part of the queue-get operation. Also, it is modeled as an s32 type similarly as done elsewhere in the stack.
Quoted 4 lines
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>
Re: [PATCH net-next v7 02/16] net: Implement netdev_nl_queue_create_doit
In reply to Daniel BorkmannQuoted 11 lines · Daniel Borkmann
Implement
netdev_nl_queue_create_doitwhich creates a new rx queue in a virtual netdev and then leases it to a rx queue in a physical netdev.Example with ynl client:
# ./pyynl/cli.py \ --spec ~/netlink/specs/netdev.yaml \ --do queue-create \ --json '{"ifindex": 8, "type": "rx", "lease": {"ifindex": 4, "queue": {"type": "rx", "id": 15}}}' {'id': 1}
Quoted 6 lines
Note that the netdevice locking order is always from the virtual to the physical device.
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>
Re: [PATCH net-next v7 03/16] net: Add lease info to queue-get response
In reply to Daniel BorkmannQuoted 61 lines · Daniel Borkmann
Populate nested lease info to the queue-get response that returns the ifindex, queue id with type and optionally netns id if the device resides in a different netns.
Example with ynl client:
# ip a [...] 4: enp10s0f0np0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp/id:24 qdisc mq state UP group default qlen 1000 link/ether e8:eb:d3:a3:43:f6 brd ff:ff:ff:ff:ff:ff inet 10.0.0.2/24 scope global enp10s0f0np0 valid_lft forever preferred_lft forever inet6 fe80::eaeb:d3ff:fea3:43f6/64 scope link proto kernel_ll valid_lft forever preferred_lft forever [...]# ethtool -i enp10s0f0np0 driver: mlx5_core [...]# ./pyynl/cli.py \ --spec ~/netlink/specs/netdev.yaml \ --do queue-get \ --json '{"ifindex": 4, "id": 15, "type": "rx"}' {'id': 15, 'ifindex': 4, 'lease': {'ifindex': 8, 'netns-id': 0, 'queue': {'id': 1, 'type': 'rx'}}, 'napi-id': 8227, 'type': 'rx', 'xsk': {}}# ip netns list foo (id: 0)# ip netns exec foo ip a [...] 8: nk@NONE: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff inet6 fe80::200:ff:fe00:0/64 scope link proto kernel_ll valid_lft forever preferred_lft forever [...]# ip netns exec foo ethtool -i nk driver: netkit [...]# ip netns exec foo ls /sys/class/net/nk/queues/ rx-0 rx-1 tx-0# ip netns exec foo ./pyynl/cli.py \ --spec ~/netlink/specs/netdev.yaml \ --do queue-get \ --json '{"ifindex": 8, "id": 1, "type": "rx"}' {'id': 1, 'ifindex': 8, 'type': 'rx'}Note that the caller of
netdev_nl_queue_fill_one()holds the netdevice lock. For the queue-get we do not lock both devices. When queues get {un,}leased, both devices are locked, thus if__netif_get_rx_queue_peer()returns true, the peer pointer points to a valid device. The netns-id is fetched viapeernet2id_alloc()similarly as done in OVS.
Quoted 4 lines
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>Reviewed-by Nikolay Aleksandrov <[email protected]>
Re: [PATCH net-next v7 04/16] net, ethtool: Disallow leased real rxqs to be resized
In reply to Daniel BorkmannQuoted 7 lines · Daniel Borkmann
Similar to
AF_XDP, do not allow queues in a physical netdev to be resized by ethtool -L when they are leased.Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>Reviewed-by Nikolay Aleksandrov <[email protected]>
Re: [PATCH net-next v7 05/16] net: Proxy net_mp_{open,close}_rxq for leased queues
In reply to Daniel BorkmannQuoted 7 lines · Daniel Borkmann
From: David Wei <[email protected]>
When a process in a container wants to setup a memory provider, it will use the virtual netdev and a leased rxq, and call net_mp_{open,close}_rxq to try and restart the queue. At this point, proxy the queue restart on the real rxq in the physical netdev.
Quoted 8 lines
For memory providers (
io_uringzero-copy rx and devmem), it causes the real rxq in the physical netdev to be filled from a memory provider that has DMA mapped memory from a process within a container.Signed-off-by David Wei <[email protected]>Co-developed-by Daniel Borkmann <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>Reviewed-by Nikolay Aleksandrov <[email protected]>
Re: [PATCH net-next v7 06/16] net: Proxy netdev_queue_get_dma_dev for leased queues
In reply to Daniel BorkmannQuoted 10 lines · Daniel Borkmann
From: David Wei <[email protected]>
Extend
netdev_queue_get_dma_devto return the physical device of the real rxq for DMA in case the queue was leased. This allows memory providers likeio_uringzero-copy or devmem to bind to the physically leased rxq via virtual devices such as netkit.Signed-off-by David Wei <[email protected]>Co-developed-by Daniel Borkmann <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Re: [PATCH net-next v7 07/16] xsk: Extend xsk_rcv_check validation
In reply to Daniel BorkmannQuoted 5 lines · Daniel Borkmann
xsk_rcv_checktests for inbound packets to see whether they match the boundAF_XDPsocket. Refactor the test into a small helperxsk_dev_queue_validand move the validation againstxs->devandxs->queue_idthere.
Quoted 8 lines
The fast-path case stays in place and allows for quick return in
xsk_dev_queue_valid. If it fails, the validation is extended to check whether theAF_XDPsocket is bound against a leased queue, and if the case then the test is redone.Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>
Re: [PATCH net-next v7 08/16] xsk: Proxy pool management for leased queues
In reply to Daniel BorkmannQuoted 10 lines · Daniel Borkmann
Similarly to the net_mp_{open,close}_rxq handling for leased queues, proxy the xsk_{reg,clear}_pool_at_qid via
netif_get_rx_queue_lease_lockedsuch that in case a virtual netdev picked a leased rxq, the request gets through to the real rxq in the physical netdev. The proxying is only relevant forqueue_id<dev->real_num_rx_queuessince right now its only supported for rxqs.Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>
Re: [PATCH net-next v7 13/16] selftests/net: Add bpf skb forwarding program
In reply to Daniel BorkmannQuoted 8 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add
nk_forward.bpf.c, a BPF program that forwards skbs matching some IPv6 prefix received on eth0 ifindex to a specified netkit ifindex. This will be needed by netkit container tests.Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Re: [PATCH net-next v7 14/16] selftests/net: Add env for container based tests
In reply to Daniel BorkmannQuoted 9 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add an env NetDrvContEnv for container based selftests. This automates the setup of a netns, netkit pair with one inside the netns, and a BPF program that forwards skbs from the NETIF host inside the container.
Currently only netkit is used, but other virtual netdevs e.g. veth can be used too.
Quoted 7 lines
Expect netkit container datapath selftests to have a publicly routable IP prefix to assign to netkit in a container, such that packets will land on eth0. The BPF skb forward program will then forward such packets from the host netns to the container netns.
Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Re: [PATCH net-next v7 15/16] selftests/net: Make NetDrvContEnv support queue leasing
In reply to Daniel BorkmannQuoted 5 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add a new parameter
leaseto NetDrvContEnv that sets up queue leasing in the env.
Quoted 7 lines
The NETIF also has some ethtool parameters changed to support memory provider tests. This is needed in NetDrvContEnv rather than individual test cases since the cleanup to restore NETIF can't be done, until the netns in the env is gone.
Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Re: [PATCH net-next v7 16/16] selftests/net: Add netkit container tests
In reply to Daniel BorkmannQuoted 6 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add two tests using NetDrvContEnv. One basic test that sets up a netkit pair, with one end in a netns. Use
LOCAL_PREFIX_V6andnk_forwardBPF program to ping from a remote host to the netkit in netns.
Quoted 7 lines
Second is a selftest for netkit queue leasing, using
io_uringzero copy test binary inside of a netns with netkit. This checks that memory providers can be bound against virtual queues in a netkit within a netns that are leasing from a physical netdev in the default netns.Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Re: [PATCH net-next v7 01/16] net: Add queue-create operation
In reply to Daniel BorkmannQuoted 53 lines · Daniel Borkmann
Add a ynl netdev family operation called queue-create that creates a new queue on a netdevice:
name: queue-create
attribute-set: queue
flags: [admin-perm]
do:
request:
attributes:
- ifindex
- type
- lease
reply: &queue-create-op
attributes:
- idThis is a generic operation such that it can be extended for various use cases in future. Right now it is mandatory to specify ifindex, the queue type which is enforced to rx and a lease. The newly created queue id is returned to the caller.
A queue from a virtual device can have a lease which refers to another queue from a physical device. This is useful for memory providers and
AF_XDPoperations which take an ifindex and queue id to allow applications to bind against virtual devices in containers. The lease couples both queues together and allows to proxy the operations from a virtual device in a container to the physical device.In future, the nested lease attribute can be lifted and made optional for other use-cases such as dynamic queue creation for physical netdevs. The lack of lease and the specification of the physical device as an ifindex will imply that we need a real queue to be allocated. Similarly, the queue type enforcement to rx can then be lifted as well to support tx.
An early implementation had only driver-specific integration [0], but in order for other virtual devices to reuse, it makes sense to have this as a generic API in core net.
For leasing queues, the virtual netdev must have
real_num_rx_queueless thannum_rx_queuesat the time of calling queue-create. The queue-type must be rx as only rx queues are supported for leasing for now. We also enforce that the queue-create ifindex must point to a virtual device, and that the nested lease attribute's ifindex must point to a physical device. The nested lease attribute set contains a netns-id attribute which is currently only intended for dumping as part of the queue-get operation. Also, it is modeled as an s32 type similarly as done elsewhere in the stack.Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>
Quoted 9 lines
--- Documentation/netlink/specs/netdev.yaml | 44 +++++++++++++++++++++++++ include/uapi/linux/netdev.h | 11 +++++++ net/core/netdev-genl-gen.c | 20 +++++++++++ net/core/netdev-genl-gen.h | 2 ++ net/core/netdev-genl.c | 5 +++ tools/include/uapi/linux/netdev.h | 11 +++++++ 6 files changed, 93 insertions(+)
Re: [PATCH net-next v7 02/16] net: Implement netdev_nl_queue_create_doit
In reply to Daniel BorkmannQuoted 17 lines · Daniel Borkmann
Implement
netdev_nl_queue_create_doitwhich creates a new rx queue in a virtual netdev and then leases it to a rx queue in a physical netdev.Example with ynl client:
# ./pyynl/cli.py \ --spec ~/netlink/specs/netdev.yaml \ --do queue-create \ --json '{"ifindex": 8, "type": "rx", "lease": {"ifindex": 4, "queue": {"type": "rx", "id": 15}}}' {'id': 1}Note that the netdevice locking order is always from the virtual to the physical device.
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>
Quoted 12 lines
--- include/net/netdev_queues.h | 19 ++++- include/net/netdev_rx_queue.h | 9 ++- include/net/xdp_sock_drv.h | 2 +- net/core/dev.c | 7 ++ net/core/dev.h | 2 + net/core/netdev-genl.c | 146 +++++++++++++++++++++++++++++++++- net/core/netdev_queues.c | 57 +++++++++++++ net/core/netdev_rx_queue.c | 46 ++++++++++- net/xdp/xsk.c | 2 +- 9 files changed, 278 insertions(+), 12 deletions(-)
Re: [PATCH net-next v7 06/16] net: Proxy netdev_queue_get_dma_dev for leased queues
In reply to Daniel BorkmannQuoted 7 lines · Daniel Borkmann
From: David Wei <[email protected]>
Extend
netdev_queue_get_dma_devto return the physical device of the real rxq for DMA in case the queue was leased. This allows memory providers likeio_uringzero-copy or devmem to bind to the physically leased rxq via virtual devices such as netkit.
Quoted 7 lines
Signed-off-by David Wei <[email protected]>Co-developed-by Daniel Borkmann <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- net/core/netdev_queues.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
Re: [PATCH net-next v7 07/16] xsk: Extend xsk_rcv_check validation
In reply to Daniel BorkmannQuoted 10 lines · Daniel Borkmann
xsk_rcv_checktests for inbound packets to see whether they match the boundAF_XDPsocket. Refactor the test into a small helperxsk_dev_queue_validand move the validation againstxs->devandxs->queue_idthere.The fast-path case stays in place and allows for quick return in
xsk_dev_queue_valid. If it fails, the validation is extended to check whether theAF_XDPsocket is bound against a leased queue, and if the case then the test is redone.
Quoted 7 lines
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>--- net/xdp/xsk.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
Re: [PATCH net-next v7 08/16] xsk: Proxy pool management for leased queues
In reply to Daniel BorkmannQuoted 7 lines · Daniel Borkmann
Similarly to the net_mp_{open,close}_rxq handling for leased queues, proxy the xsk_{reg,clear}_pool_at_qid via
netif_get_rx_queue_lease_lockedsuch that in case a virtual netdev picked a leased rxq, the request gets through to the real rxq in the physical netdev. The proxying is only relevant forqueue_id<dev->real_num_rx_queuessince right now its only supported for rxqs.
Quoted 7 lines
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>--- net/xdp/xsk.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-)
Re: [PATCH net-next v7 11/16] netkit: Add netkit notifier to check for unregistering devices
In reply to Daniel BorkmannQuoted 48 lines · Daniel Borkmann
Add a netdevice notifier in netkit to watch for
NETDEV_UNREGISTERevents. If the target device is indeedNETREG_UNREGISTERINGand previously leased a queue to a netkit device, then collect the related netkit devices and batch-unregister_netdevice_many() them.If this would not be done, then the netkit device would hold a reference on the physical device preventing it from going away. However, in case of both
io_uringzero-copy as well asAF_XDPthis situation is handled gracefully and the allocated resources are torn down.In the case where mentioned infra is used through netkit, the applications have a reference on netkit, and netkit in turn holds a reference on the physical device. In order to have netkit release the reference on the physical device, we need such watcher to then unregister the netkit ones.
This is generally quite similar to the dependency handling in case of tunnels (e.g. vxlan bound to a underlying netdev) where the tunnel device gets removed along with the physical device.
# ip a [...] 4: enp10s0f0np0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether e8:eb:d3:a3:43:f6 brd ff:ff:ff:ff:ff:ff inet 10.0.0.2/24 scope global enp10s0f0np0 valid_lft forever preferred_lft forever [...] 8: nk@NONE: <BROADCAST,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff [...]# rmmod mlx5_ib # rmmod mlx5_core[ 309.261822] mlx5_core 0000:0a:00.0 mlx5_0: Port: 1 Link DOWN [ 344.235236] mlx5_core 0000:0a:00.1: E-Switch: Unload vfs: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 344.246948] mlx5_core 0000:0a:00.1: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 344.463754] mlx5_core 0000:0a:00.1: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 344.770155] mlx5_core 0000:0a:00.1: E-Switch: cleanup [ 345.345709] mlx5_core 0000:0a:00.0: E-Switch: Unload vfs: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 345.357524] mlx5_core 0000:0a:00.0: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 350.995989] mlx5_core 0000:0a:00.0: E-Switch: Disable: mode(LEGACY), nvfs(0), necvfs(0), active vports(0) [ 351.574396] mlx5_core 0000:0a:00.0: E-Switch: cleanup# ip a [...] [ both enp10s0f0np0 and nk gone ] [...]
Quoted 8 lines
Signed-off-by Daniel Borkmann <[email protected]>Co-developed-by David Wei <[email protected]>Signed-off-by David Wei <[email protected]>--- drivers/net/netkit.c | 57 ++++++++++++++++++++++++++++++++++++++- include/linux/netdevice.h | 6 +++++ 2 files changed, 62 insertions(+), 1 deletion(-)
Re: [PATCH net-next v7 13/16] selftests/net: Add bpf skb forwarding program
In reply to Daniel BorkmannQuoted 6 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add
nk_forward.bpf.c, a BPF program that forwards skbs matching some IPv6 prefix received on eth0 ifindex to a specified netkit ifindex. This will be needed by netkit container tests.
Quoted 7 lines
Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- .../selftests/drivers/net/hw/nk_forward.bpf.c | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+)create mode 100644
tools/testing/selftests/drivers/net/hw/nk_forward.bpf.c
Re: [PATCH net-next v7 14/16] selftests/net: Add env for container based tests
In reply to Daniel BorkmannQuoted 14 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add an env NetDrvContEnv for container based selftests. This automates the setup of a netns, netkit pair with one inside the netns, and a BPF program that forwards skbs from the NETIF host inside the container.
Currently only netkit is used, but other virtual netdevs e.g. veth can be used too.
Expect netkit container datapath selftests to have a publicly routable IP prefix to assign to netkit in a container, such that packets will land on eth0. The BPF skb forward program will then forward such packets from the host netns to the container netns.
Quoted 9 lines
Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- .../testing/selftests/drivers/net/README.rst | 7 ++ .../drivers/net/hw/lib/py/__init__.py | 7 +- .../selftests/drivers/net/lib/py/__init__.py | 7 +- .../selftests/drivers/net/lib/py/env.py | 112 ++++++++++++++++++ 4 files changed, 127 insertions(+), 6 deletions(-)
Re: [PATCH net-next v7 15/16] selftests/net: Make NetDrvContEnv support queue leasing
In reply to Daniel BorkmannQuoted 10 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add a new parameter
leaseto NetDrvContEnv that sets up queue leasing in the env.The NETIF also has some ethtool parameters changed to support memory provider tests. This is needed in NetDrvContEnv rather than individual test cases since the cleanup to restore NETIF can't be done, until the netns in the env is gone.
Quoted 6 lines
Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>--- .../selftests/drivers/net/lib/py/env.py | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
Re: [PATCH net-next v7 16/16] selftests/net: Add netkit container tests
In reply to Daniel BorkmannQuoted 13 lines · Daniel Borkmann
From: David Wei <[email protected]>
Add two tests using NetDrvContEnv. One basic test that sets up a netkit pair, with one end in a netns. Use
LOCAL_PREFIX_V6andnk_forwardBPF program to ping from a remote host to the netkit in netns.Second is a selftest for netkit queue leasing, using
io_uringzero copy test binary inside of a netns with netkit. This checks that memory providers can be bound against virtual queues in a netkit within a netns that are leasing from a physical netdev in the default netns.Signed-off-by David Wei <[email protected]>Signed-off-by Daniel Borkmann <[email protected]>
Quoted 8 lines
--- .../testing/selftests/drivers/net/hw/Makefile | 2 + .../selftests/drivers/net/hw/nk_netns.py | 23 ++++++++ .../selftests/drivers/net/hw/nk_qlease.py | 55 +++++++++++++++++++ 3 files changed, 80 insertions(+)create mode 100755
tools/testing/selftests/drivers/net/hw/nk_netns.pycreate mode 100755tools/testing/selftests/drivers/net/hw/nk_qlease.py
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Thu, 15 Jan 2026 09:25:47 +0100 you wrote:
Containers use virtual netdevs to route traffic from a physical netdev in the host namespace. They do not have access to the physical netdev in the host and thus can't use memory providers or
AF_XDPthat require reconfiguring/restarting queues in the physical netdev.This patchset adds the concept of queue leasing to virtual netdevs that allow containers to use memory providers and
AF_XDPat native speed. Leased queues are bound to a real queue in a physical netdev and act as a proxy.[...]
Here is the summary with links:
- [net-next,v7,01/16] net: Add queue-create operation
https://git.kernel.org/netdev/net-next/c/a5546e18f77c - [net-next,v7,02/16] net: Implement netdev_nl_queue_create_doit https://git.kernel.org/netdev/net-next/c/31127deddef4 - [net-next,v7,03/16] net: Add lease info to queue-get response https://git.kernel.org/netdev/net-next/c/9e2103f36110 - [net-next,v7,04/16] net, ethtool: Disallow leased real rxqs to be resized https://git.kernel.org/netdev/net-next/c/ff8889ff9107 - [net-next,v7,05/16] net: Proxy net_mp_{open,close}_rxq for leased queues https://git.kernel.org/netdev/net-next/c/0caa9a8ddec3 - [net-next,v7,06/16] net: Proxy netdev_queue_get_dma_dev for leased queues https://git.kernel.org/netdev/net-next/c/804bf334d08a - [net-next,v7,07/16] xsk: Extend xsk_rcv_check validation https://git.kernel.org/netdev/net-next/c/1ecea95dd3b5 - [net-next,v7,08/16] xsk: Proxy pool management for leased queues https://git.kernel.org/netdev/net-next/c/0073d2fd679d - [net-next,v7,09/16] netkit: Add single device mode for netkit https://git.kernel.org/netdev/net-next/c/b5c3fa4a0b16 - [net-next,v7,10/16] netkit: Implement rtnl_link_ops->alloc and ndo_queue_create https://git.kernel.org/netdev/net-next/c/b5ef109d22d4 - [net-next,v7,11/16] netkit: Add netkit notifier to check for unregistering devices https://git.kernel.org/netdev/net-next/c/eef51113f8af - [net-next,v7,12/16] netkit: Add xsk support for af_xdp applications https://git.kernel.org/netdev/net-next/c/920da3634194 - [net-next,v7,13/16] selftests/net: Add bpf skb forwarding program https://git.kernel.org/netdev/net-next/c/61d99ce3dfc2 - [net-next,v7,14/16] selftests/net: Add env for container based tests https://git.kernel.org/netdev/net-next/c/6be87fbb2776 - [net-next,v7,15/16] selftests/net: Make NetDrvContEnv support queue leasing https://git.kernel.org/netdev/net-next/c/ab771c938d9a - [net-next,v7,16/16] selftests/net: Add netkit container tests https://git.kernel.org/netdev/net-next/c/931420a2fc36
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Jakub Kicinski
maintainerRe: [PATCH net-next v7 15/16] selftests/net: Make NetDrvContEnv support queue leasing
In reply to Daniel BorkmannQuoted 16 lines · On Thu, 15 Jan 2026 09:26:02 +0100 Daniel Borkmann wrote:
tools/testing/selftests/drivers/net/lib/py/env.py +16
-0+ def _lease_queues(self): + channels = self.ethnl.channels_get({'header': {'dev-index': self.ifindex}}) + channels = channels['combined-count'] + if channels < 2: + raise KsftSkipEx('Test requires NETIF with at least 2 combined channels') + + rings = self.ethnl.rings_get({'header': {'dev-index': self.ifindex}}) + self._rx_rings = rings['rx'] + self._hds_thresh = rings.get('hds-thresh', 0) + self.ethnl.rings_set({'header': {'dev-index': self.ifindex}, + 'tcp-data-split': 'enabled', + 'hds-thresh': 0, + 'rx': 64}) + self.src_queue = channels - 1 + bind_result = self.netdevnl.queue_create( + {
tools/testing/selftests/drivers/net/lib/py/env.py class NetDrvContEnv(NetDrvEpEnv): · line 401
Quoted 10 lines
tools/testing/selftests/drivers/net/lib/py/env.py +10
-0+ "ifindex": self.nk_guest_ifindex, + "type": "rx", + "lease": { + "ifindex": self.ifindex, + "queue": {"id": self.src_queue, "type": "rx"}, + }, + } + ) + self.nk_queue = bind_result['id'] + self._leased = True
No frameworks, please, this belongs in the test itself.
Re: [PATCH net-next v7 15/16] selftests/net: Make NetDrvContEnv support queue leasing
Quoted 28 lines · Jakub Kicinski
Quoted 16 lines · On Thu, 15 Jan 2026 09:26:02 +0100 Daniel Borkmann wrote:
tools/testing/selftests/drivers/net/lib/py/env.py +16
-0+ def _lease_queues(self): + channels = self.ethnl.channels_get({'header': {'dev-index': self.ifindex}}) + channels = channels['combined-count'] + if channels < 2: + raise KsftSkipEx('Test requires NETIF with at least 2 combined channels') + + rings = self.ethnl.rings_get({'header': {'dev-index': self.ifindex}}) + self._rx_rings = rings['rx'] + self._hds_thresh = rings.get('hds-thresh', 0) + self.ethnl.rings_set({'header': {'dev-index': self.ifindex}, + 'tcp-data-split': 'enabled', + 'hds-thresh': 0, + 'rx': 64}) + self.src_queue = channels - 1 + bind_result = self.netdevnl.queue_create( + {tools/testing/selftests/drivers/net/lib/py/env.py class NetDrvContEnv(NetDrvEpEnv): · line 401
Quoted 10 lines
tools/testing/selftests/drivers/net/lib/py/env.py +10
-0+ "ifindex": self.nk_guest_ifindex, + "type": "rx", + "lease": { + "ifindex": self.ifindex, + "queue": {"id": self.src_queue, "type": "rx"}, + }, + } + ) + self.nk_queue = bind_result['id'] + self._leased = True
Quoted 1 line
No frameworks, please, this belongs in the test itself.
The timing of this is challenging. It has to be done after creating the netns/netkit, but before moving one of the netkits into the netns.
I could make this a functor that a test caller passes in. Would you be okay with that?
Jakub Kicinski
maintainerRe: [PATCH net-next v7 05/16] net: Proxy net_mp_{open,close}_rxq for leased queues
In reply to Daniel Borkmannnet/core/netdev_rx_queue.c int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, · line 220
Quoted 10 lines · On Thu, 15 Jan 2026 09:25:52 +0100 Daniel Borkmann wrote:
net/core/netdev_rx_queue.c +1
-2if (!netdev_need_ops_lock (dev))return -EOPNOTSUPP ; -if (rxq_idx >= dev->real_num_rx_queues) {NL_SET_ERR_MSG (extack,"rx queue index out of range" );return -ERANGE ; } - rxq_idx =array_index_nospec (rxq_idx, dev->real_num_rx_queues); + rxq_idx =array_index_nospec (rxq_idx, dev->real_num_rx_queues);
The white space changes here look haphazard.
Review
Quoted 1 line
(quoted diff) +1
-0+ rxq = netif_get_rx_queue_lease_locked(&dev, &rxq_idx);
I really hate this function but I don't have any great suggestion on how to make it better. I'd prefer if there was a clear separation between the case where we call directly, vs where swapped the queue. Instead of replacing pointers passed in by reference :| And that'd remove the conditional locking too.
net/core/netdev_rx_queue.c int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, · line 223
Quoted 2 lines
net/core/netdev_rx_queue.c +2
-0+if (!rxq) { +NL_SET_ERR_MSG (extack,"rx queue peered to a virtual netdev" );
The fact the !rxq means the queue was leased is also fairly random vs all the subsequent checks.
net/core/netdev_rx_queue.c int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, · line 227
Quoted 4 lines
net/core/netdev_rx_queue.c +4
-0+return -EBUSY ; + } +if (!dev->dev.parent) { +NL_SET_ERR_MSG (extack,"rx queue is mapped to a virtual netdev" );
mapped? Or belongs?
Quoted 25 lines
net/core/netdev_rx_queue.c +9
-5+ ret = -EBUSY ; + goto out; + }if (dev->cfg->hds_config !=ETHTOOL_TCP_DATA_SPLIT_ENABLED ) {NL_SET_ERR_MSG (extack,"tcp-data-split is disabled" ); -return -EINVAL ; + ret = -EINVAL ; + goto out; }if (dev->cfg->hds_thresh) {NL_SET_ERR_MSG (extack,"hds-thresh is not zero" ); -return -EINVAL ; + ret = -EINVAL ; + goto out; }if (dev_xdp_prog_count (dev)) {NL_SET_ERR_MSG (extack,"unable to custom memory provider to device with XDP program attached" ); -return -EEXIST ; + ret = -EEXIST ; + goto out; } - - rxq =__netif_get_rx_queue (dev, rxq_idx);if (rxq->mp_params.mp_ops) {NL_SET_ERR_MSG (extack,"designated queue already memory provider bound" );
net/core/netdev_rx_queue.c int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, · line 255
Quoted 10 lines
net/core/netdev_rx_queue.c +4
-2-return -EEXIST ; + ret = -EEXIST ; + goto out; }#ifdef CONFIG_XDP_SOCKETS if (rxq->pool) {NL_SET_ERR_MSG (extack,"designated queue already in use by AF_XDP" ); -return -EBUSY ; + ret = -EBUSY ; + goto out;
All these checks can be factored out to avoid making this function long and having 5 gotos.
net/core/netdev_rx_queue.c int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, · line 222
Quoted 3 lines
net/core/netdev_rx_queue.c +0
-1}#endif -
Please lease my whitespace be.
Quoted 6 lines
net/core/netdev_rx_queue.c +0
-0rxq->mp_params = *p; ret =netdev_rx_queue_restart (dev, rxq_idx);if (ret) { rxq->mp_params.mp_ops =NULL ; rxq->mp_params.mp_priv =NULL ; }
Jakub Kicinski
maintainerQuoted 3 lines · On Tue, 20 Jan 2026 11:50:25 +0000 [email protected] wrote:
Here is the summary with links:
- [net-next,v7,01/16] net: Add queue-create operationhttps://git.kernel.org/netdev/net-next/c/a5546e18f77c
I'm going to revert this, I sort of promised Pavel I will pull his work and he has the cross-dependency with io_uring. Y'all can rebase. Plus what this series does to "the code I wrote" saddens me deeply.
Re: [PATCH net-next v7 05/16] net: Proxy net_mp_{open,close}_rxq for leased queues
In reply to Jakub KicinskiQuoted 14 lines · Jakub Kicinski
net/core/netdev_rx_queue.c int __net_mp_open_rxq(struct net_device *dev, unsigned int rxq_idx, · line 220
Quoted 10 lines · On Thu, 15 Jan 2026 09:25:52 +0100 Daniel Borkmann wrote:
if (!netdev_need_ops_lock(dev))
return-EOPNOTSUPP;net/core/netdev_rx_queue.c +1
-2-if (rxq_idx >= dev->real_num_rx_queues) {NL_SET_ERR_MSG (extack,"rx queue index out of range" );return -ERANGE ; } - rxq_idx =array_index_nospec (rxq_idx, dev->real_num_rx_queues); + rxq_idx =array_index_nospec (rxq_idx, dev->real_num_rx_queues);The white space changes here look haphazard.
Quoted 7 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ rxq = netif_get_rx_queue_lease_locked(&dev, &rxq_idx);I really hate this function but I don't have any great suggestion on how to make it better. I'd prefer if there was a clear separation between the case where we call directly, vs where swapped the queue. Instead of replacing pointers passed in by reference :| And that'd remove the conditional locking too.
Yeah :/ I will clean up the unnecessary whitespace changes and pull out the checks at least. The current way makes it easier for the callers as they don't need to distinguish between direct vs swapped. But, I do appreciate how awful it feels.
I can try moving netif_get_rx_queue_lease_locked() out into the callers and see how that feels instead. __net_mp_open_rxq() will then fail for virtual netdevs.
Quoted 8 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 20 Jan 2026 11:50:25 +0000 [email protected] wrote:
Here is the summary with links:
- [net-next,v7,01/16] net: Add queue-create operationhttps://git.kernel.org/netdev/net-next/c/a5546e18f77cI'm going to revert this, I sort of promised Pavel I will pull his work and he has the cross-dependency with
io_uring. Y'all can rebase.
No problem, that's the ordering I expected anyway.
Quoted 1 line
Plus what this series does to "the code I wrote" saddens me deeply.
Yes, that's always sad. LMK once you learn how to clone yourself. I wanna do the same, too.