[PATCH net-next v4 2/8] net: netkit: declare NETMEM_TX_NO_DMA mode

Updated
From:Bobby Eshleman <bobbyeshleman@gmail.com>
Date:
Message-ID:<20260511-tcp-dm-netkit-v4-2-841b78b99d74@meta.com>
Patch:v4 · 2/8
Language:zh_CN
Patch-ID:d44c9cd76d469f5e346166d4b0f08595ead10487
Files:Documentation/networking/net_cachelines/net_device.rstDocumentation/networking/netmem.rstDocumentation/translations/zh_CN/networking/netmem.rstdrivers/net/netkit.cinclude/linux/netdevice.h

Patch content 5 changed files

From: Bobby Eshleman <bobbyeshleman@meta.com> Some virtual devices like netkit (or ifb) never DMA and never touch fragcontents, they just forward the skb to another device. They are unableto forward unreadable skbs, however, because they fail to pass TXvalidation checks on dev->netmem_tx. The existing two-stateNETMEM_TX_NONE / NETMEM_TX_DMA doesn't give the TX validator enoughinformation to differentiate devices that will attempt DMA on theunreadable skb from those that will simply route it untouched. Add a third mode to the enum so drivers can indicate 1) if they havenetmem TX support, and 2) if they do, whether they are DMA-capable: NETMEM_TX_NO_DMA - pass-through, device never DMAs Widen dev->netmem_tx from a 1-bit field to 2 bits to fit the new value,and declare netkit as NETMEM_TX_NO_DMA. Devmem TX support over thesedevices comes in a follow-up patch. Acked-by: Stanislav Fomichev <sdf@fomichev.me>Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>---Changes in v3:- net_cachelines/net_device.rst: align the netmem_tx row's type column  with the rest of the table by using "unsigned_long:2" instead of  "unsigned long:2"- Split this into a distinct patch (Jakub)--- Documentation/networking/net_cachelines/net_device.rst | 2 +- Documentation/networking/netmem.rst                    | 3 +++ Documentation/translations/zh_CN/networking/netmem.rst | 3 +++ drivers/net/netkit.c                                   | 1 + include/linux/netdevice.h                              | 3 ++- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rstindex 1c19bb7705df..7b3392553fd6 100644--- a/Documentation/networking/net_cachelines/net_device.rst+++ b/Documentation/networking/net_cachelines/net_device.rst@@ -10,7 +10,7 @@ Type                                Name                        fastpath_tx_acce =================================== =========================== =================== =================== =================================================================================== unsigned_long:32                    priv_flags                  read_mostly                             __dev_queue_xmit(tx) unsigned_long:1                     lltx                        read_mostly                             HARD_TX_LOCK,HARD_TX_TRYLOCK,HARD_TX_UNLOCK(tx)-unsigned long:1                     netmem_tx:1;                read_mostly+unsigned_long:2                     netmem_tx:2;                read_mostly char                                name[16] struct netdev_name_node*            name_node struct dev_ifalias*                 ifaliasdiff --git a/Documentation/networking/netmem.rst b/Documentation/networking/netmem.rstindex 5ccadba4f373..217869d1108d 100644--- a/Documentation/networking/netmem.rst+++ b/Documentation/networking/netmem.rst@@ -99,3 +99,6 @@ Driver TX Requirements    appropriate mode:     - `NETMEM_TX_DMA`: for physical devices that perform DMA.++   - `NETMEM_TX_NO_DMA`: for virtual or passthrough devices that do+     not DMA, but still support handling of netmem-backed skbs.diff --git a/Documentation/translations/zh_CN/networking/netmem.rst b/Documentation/translations/zh_CN/networking/netmem.rstindex 9c84423b7528..320f3eacf51b 100644--- a/Documentation/translations/zh_CN/networking/netmem.rst+++ b/Documentation/translations/zh_CN/networking/netmem.rst@@ -92,3 +92,6 @@ dma-mapping API 去处理。 2. 驱动程序应将 `netdev->netmem_tx` 设置为适当的模式:     - `NETMEM_TX_DMA`:适用于执行 DMA 的物理设备。++   - `NETMEM_TX_NO_DMA`:适用于不执行 DMA 的虚拟或透传设备,但仍支持+     处理 netmem 支持的 skb。diff --git a/drivers/net/netkit.c b/drivers/net/netkit.cindex 5e2eecc3165d..0ad6a806d7d5 100644--- a/drivers/net/netkit.c+++ b/drivers/net/netkit.c@@ -466,6 +466,7 @@ static void netkit_setup(struct net_device *dev) 	dev->priv_flags |= IFF_NO_QUEUE; 	dev->priv_flags |= IFF_DISABLE_NETPOLL; 	dev->lltx = true;+	dev->netmem_tx = NETMEM_TX_NO_DMA;  	dev->netdev_ops     = &netkit_netdev_ops; 	dev->ethtool_ops    = &netkit_ethtool_ops;diff --git a/include/linux/netdevice.h b/include/linux/netdevice.hindex a54a37fab8d9..8ece36815ff9 100644--- a/include/linux/netdevice.h+++ b/include/linux/netdevice.h@@ -1791,6 +1791,7 @@ enum netdev_stat_type { enum netmem_tx_mode { 	NETMEM_TX_NONE,		/* no netmem TX support */ 	NETMEM_TX_DMA,		/* DMA-capable netmem TX (real HW) */+	NETMEM_TX_NO_DMA,	/* no DMA, e.g. passthrough for virtual devs */ };  enum netdev_reg_state {@@ -2137,7 +2138,7 @@ struct net_device { 	struct_group(priv_flags_fast, 		unsigned long		priv_flags:32; 		unsigned long		lltx:1;-		unsigned long		netmem_tx:1;+		unsigned long		netmem_tx:2; 	); 	const struct net_device_ops *netdev_ops; 	const struct header_ops *header_ops; -- 2.53.0-Meta