diff mbox series

[RFC,net-next,1/2] netdev-genl: Add an XSK attribute to queues

Message ID 20250129172431.65773-2-jdamato@fastly.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series netdevgenl: Add an xsk attribute to queues | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; GEN HAS DIFF 2 files changed, 8 insertions(+);
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 41 this patch: 41
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 7102 this patch: 7102
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4116 this patch: 4116
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 60 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 12 this patch: 12
netdev/source_inline success Was 0 now: 0

Commit Message

Joe Damato Jan. 29, 2025, 5:24 p.m. UTC
Expose a new per-queue attribute, xsk, which indicates that a queue is
being used for AF_XDP. Update the documentation to more explicitly state
which queue types are linked.

Signed-off-by: Joe Damato <jdamato@fastly.com>
---
 Documentation/netlink/specs/netdev.yaml | 10 +++++++++-
 include/uapi/linux/netdev.h             |  1 +
 net/core/netdev-genl.c                  |  6 ++++++
 tools/include/uapi/linux/netdev.h       |  1 +
 4 files changed, 17 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski Jan. 30, 2025, 1:52 a.m. UTC | #1
On Wed, 29 Jan 2025 17:24:24 +0000 Joe Damato wrote:
> Expose a new per-queue attribute, xsk, which indicates that a queue is
> being used for AF_XDP. Update the documentation to more explicitly state
> which queue types are linked.

Let's do the same thing we did for io_uring queues? An empty nest:
https://lore.kernel.org/all/20250116231704.2402455-6-dw@davidwei.uk/

At the protocol level nest is both smaller and more flexible.
It's just 4B with zero length and a "this is a nest" flag.
We can add attributes to it as we think of things to express.
Joe Damato Jan. 30, 2025, 4:26 p.m. UTC | #2
On Wed, Jan 29, 2025 at 05:52:24PM -0800, Jakub Kicinski wrote:
> On Wed, 29 Jan 2025 17:24:24 +0000 Joe Damato wrote:
> > Expose a new per-queue attribute, xsk, which indicates that a queue is
> > being used for AF_XDP. Update the documentation to more explicitly state
> > which queue types are linked.
> 
> Let's do the same thing we did for io_uring queues? An empty nest:
> https://lore.kernel.org/all/20250116231704.2402455-6-dw@davidwei.uk/
> 
> At the protocol level nest is both smaller and more flexible.
> It's just 4B with zero length and a "this is a nest" flag.
> We can add attributes to it as we think of things to express.

Thanks for the pointer; will do.
Joe Damato Jan. 30, 2025, 6:06 p.m. UTC | #3
On Wed, Jan 29, 2025 at 05:52:24PM -0800, Jakub Kicinski wrote:
> On Wed, 29 Jan 2025 17:24:24 +0000 Joe Damato wrote:
> > Expose a new per-queue attribute, xsk, which indicates that a queue is
> > being used for AF_XDP. Update the documentation to more explicitly state
> > which queue types are linked.
> 
> Let's do the same thing we did for io_uring queues? An empty nest:
> https://lore.kernel.org/all/20250116231704.2402455-6-dw@davidwei.uk/
> 
> At the protocol level nest is both smaller and more flexible.
> It's just 4B with zero length and a "this is a nest" flag.
> We can add attributes to it as we think of things to express.

I got a thing working locally, but just to make sure I'm
following... you are saying that the attribute will exist (but have
nothing in it) when the queue has a pool, and when !q->pool the
attribute will not exist?

For example:

[{'id': 0, 'ifindex': 5, 'napi-id': 8266, 'type': 'rx', 'xsk': {}},
 {'id': 1, 'ifindex': 5, 'napi-id': 8267, 'type': 'rx'},
 ...

Is that what you are thinking?

Completely fine with me as I haven't read enough of the xsk code to
really have a good sense of what attributes might be helpful to
expose at this point.
Jakub Kicinski Jan. 30, 2025, 6:13 p.m. UTC | #4
On Thu, 30 Jan 2025 13:06:47 -0500 Joe Damato wrote:
> On Wed, Jan 29, 2025 at 05:52:24PM -0800, Jakub Kicinski wrote:
> > On Wed, 29 Jan 2025 17:24:24 +0000 Joe Damato wrote:  
> > > Expose a new per-queue attribute, xsk, which indicates that a queue is
> > > being used for AF_XDP. Update the documentation to more explicitly state
> > > which queue types are linked.  
> > 
> > Let's do the same thing we did for io_uring queues? An empty nest:
> > https://lore.kernel.org/all/20250116231704.2402455-6-dw@davidwei.uk/
> > 
> > At the protocol level nest is both smaller and more flexible.
> > It's just 4B with zero length and a "this is a nest" flag.
> > We can add attributes to it as we think of things to express.  
> 
> I got a thing working locally, but just to make sure I'm
> following... you are saying that the attribute will exist (but have
> nothing in it) when the queue has a pool, and when !q->pool the
> attribute will not exist?
> 
> For example:
> 
> [{'id': 0, 'ifindex': 5, 'napi-id': 8266, 'type': 'rx', 'xsk': {}},
>  {'id': 1, 'ifindex': 5, 'napi-id': 8267, 'type': 'rx'},
>  ...
> 
> Is that what you are thinking?

Yup! That's it.

> Completely fine with me as I haven't read enough of the xsk code to
> really have a good sense of what attributes might be helpful to
> expose at this point.
diff mbox series

Patch

diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index cbb544bd6c84..7a72788cce03 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -286,6 +286,8 @@  attribute-sets:
       -
         name: type
         doc: Queue type as rx, tx. Each queue type defines a separate ID space.
+             XDP TX queues allocated in the kernel are not linked to NAPIs and
+             thus not listed. AF_XDP queues have the xsk attribute set.
         type: u32
         enum: queue-type
       -
@@ -296,7 +298,12 @@  attribute-sets:
         name: dmabuf
         doc: ID of the dmabuf attached to this queue, if any.
         type: u32
-
+      -
+        name: xsk
+        doc: Non-zero for queues which are used for XSK (AF_XDP), 0 otherwise.
+        type: u32
+        checks:
+          max: 1
   -
     name: qstats
     doc: |
@@ -637,6 +644,7 @@  operations:
             - napi-id
             - ifindex
             - dmabuf
+            - xsk
       dump:
         request:
           attributes:
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index e4be227d3ad6..4d2dcf4960ec 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -136,6 +136,7 @@  enum {
 	NETDEV_A_QUEUE_TYPE,
 	NETDEV_A_QUEUE_NAPI_ID,
 	NETDEV_A_QUEUE_DMABUF,
+	NETDEV_A_QUEUE_XSK,
 
 	__NETDEV_A_QUEUE_MAX,
 	NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 715f85c6b62e..964aebfcb079 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -394,12 +394,18 @@  netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev,
 		    nla_put_u32(rsp, NETDEV_A_QUEUE_DMABUF, binding->id))
 			goto nla_put_failure;
 
+		if (nla_put_u32(rsp, NETDEV_A_QUEUE_XSK, !!rxq->pool))
+			goto nla_put_failure;
+
 		break;
 	case NETDEV_QUEUE_TYPE_TX:
 		txq = netdev_get_tx_queue(netdev, q_idx);
 		if (txq->napi && nla_put_u32(rsp, NETDEV_A_QUEUE_NAPI_ID,
 					     txq->napi->napi_id))
 			goto nla_put_failure;
+
+		if (nla_put_u32(rsp, NETDEV_A_QUEUE_XSK, !!txq->pool))
+			goto nla_put_failure;
 	}
 
 	genlmsg_end(rsp, hdr);
diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h
index e4be227d3ad6..4d2dcf4960ec 100644
--- a/tools/include/uapi/linux/netdev.h
+++ b/tools/include/uapi/linux/netdev.h
@@ -136,6 +136,7 @@  enum {
 	NETDEV_A_QUEUE_TYPE,
 	NETDEV_A_QUEUE_NAPI_ID,
 	NETDEV_A_QUEUE_DMABUF,
+	NETDEV_A_QUEUE_XSK,
 
 	__NETDEV_A_QUEUE_MAX,
 	NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1)