diff mbox series

[net-next,v4,8/9] net: check for driver support in netmem TX

Message ID 20250220020914.895431-9-almasrymina@google.com
State New
Headers show
Series Device memory TCP TX | expand

Commit Message

Mina Almasry Feb. 20, 2025, 2:09 a.m. UTC
We should not enable netmem TX for drivers that don't declare support.

Check for driver netmem TX support during devmem TX binding and fail if
the driver does not have the functionality.

Check for driver support in validate_xmit_skb as well.

Signed-off-by: Mina Almasry <almasrymina@google.com>

---

v4:
- New patch

---
 net/core/dev.c         | 3 +++
 net/core/netdev-genl.c | 7 +++++++
 2 files changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index ebc000b56828..f65a2b41a2c3 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3850,6 +3850,9 @@  static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
 
 	skb = validate_xmit_xfrm(skb, features, again);
 
+	if (!skb_frags_readable(skb) && !dev->netmem_tx)
+		goto out_kfree_skb;
+
 	return skb;
 
 out_kfree_skb:
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 1faa2cf4057f..a154480a6e22 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -970,6 +970,13 @@  int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_unlock;
 	}
 
+	if (!netdev->netmem_tx) {
+		err = -EOPNOTSUPP;
+		NL_SET_ERR_MSG(info->extack,
+			       "Driver does not support netmem TX");
+		goto err_unlock;
+	}
+
 	binding = net_devmem_bind_dmabuf(netdev, DMA_TO_DEVICE, dmabuf_fd,
 					 info->extack);
 	if (IS_ERR(binding)) {