[PATCH net-next 01/11] net: add netmem_tx modes that indicate dma capability
#UpdatedFrom:Bobby Eshleman <bobbyeshleman@gmail.com>
Date:
Message-ID:<20260428-tcp-dm-netkit-v1-1-719280eba4d2@meta.com>
Patch:v1 · 1/11
Language:zh_CN
Patch-ID:e4e708027a88aff343159731a93b47e4852972d9
Files:
Documentation/networking/net_cachelines/net_device.rstDocumentation/networking/netmem.rstDocumentation/translations/zh_CN/networking/netmem.rstinclude/linux/netdevice.hLinks:lore message ↗ · raw mail ↗
Patch content 4 changed files
From: Bobby Eshleman <bobbyeshleman@meta.com> Devices that support netmem TX previously set dev->netmem_tx = true.This was checked in validate_xmit_unreadable_skb() to drop unreadableskbs (skbs with dmabuf-backed frags) before they reach drivers thatwould mishandle them or devices that would not have the iommu mappingsfor them. Some virtual devices like netkit (or ifb) never DMA and never touch fragcontents, as they essentially just forward the skb to another device.They are unable to forward unreadable skbs, however, because they failto pass TX validation checks on dev->netmem_tx. This single bit flagdoesn't give the TX validator enough information to differentiatedevices that will attempt DMA on the unreadable skb and those that willsimply route it untouched. This patch fixes this issue by adding an additional bit to netmem_tx, sothat drivers can indicate 1) if they have netmem support, and 2) if theydo, are they DMA-capable or not? Replace the boolean with a 2-bit enum: NETMEM_TX_NONE - no netmem TX support (drop unreadable skbs)NETMEM_TX_DMA - full support, device does DMANETMEM_TX_NO_DMA - pass-through, device never DMAs Subsequent patches update netmem drivers to the new flags. Assisted-by: Claude Code:claude-sonnet-4-6Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>--- Documentation/networking/net_cachelines/net_device.rst | 2 +- Documentation/networking/netmem.rst | 8 +++++++- Documentation/translations/zh_CN/networking/netmem.rst | 7 ++++++- include/linux/netdevice.h | 11 +++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rstindex 1c19bb7705df..c85784259544 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 b63aded46337..217869d1108d 100644--- a/Documentation/networking/netmem.rst+++ b/Documentation/networking/netmem.rst@@ -95,4 +95,10 @@ Driver TX Requirements netdev@, or reach out to the maintainers and/or almasrymina@google.com for help adding the netmem API. -2. Driver should declare support by setting `netdev->netmem_tx = true`+2. Driver should declare support by setting `netdev->netmem_tx` to the+ 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 fe351a240f02..320f3eacf51b 100644--- a/Documentation/translations/zh_CN/networking/netmem.rst+++ b/Documentation/translations/zh_CN/networking/netmem.rst@@ -89,4 +89,9 @@ dma-mapping API 去处理。 使用某个还不存在的 netmem API,你可以自行添加并提交到 netdev@,也可以联系维护 人员或者发送邮件至 almasrymina@google.com 寻求帮助。 -2. 驱动程序应通过设置 netdev->netmem_tx = true 来表明自身支持 netmem 功能。+2. 驱动程序应将 `netdev->netmem_tx` 设置为适当的模式:++ - `NETMEM_TX_DMA`:适用于执行 DMA 的物理设备。++ - `NETMEM_TX_NO_DMA`:适用于不执行 DMA 的虚拟或透传设备,但仍支持+ 处理 netmem 支持的 skb。diff --git a/include/linux/netdevice.h b/include/linux/netdevice.hindex 0e1e581efc5a..11d68e75eb4f 100644--- a/include/linux/netdevice.h+++ b/include/linux/netdevice.h@@ -1788,6 +1788,12 @@ enum netdev_stat_type { NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */ }; +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 { NETREG_UNINITIALIZED = 0, NETREG_REGISTERED, /* completed register_netdevice */@@ -1809,7 +1815,8 @@ enum netdev_reg_state { * @lltx: device supports lockless Tx. Deprecated for real HW * drivers. Mainly used by logical interfaces, such as * bonding and tunnels- * @netmem_tx: device support netmem_tx.+ * @netmem_tx: device netmem TX mode (NETMEM_TX_NONE, NETMEM_TX_DMA,+ * or NETMEM_TX_NO_DMA). * * @name: This is the first field of the "visible" part of this structure * (i.e. as seen by users in the "Space.c" file). It is the name@@ -2132,7 +2139,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.52.0