[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230809165418.2831456-6-sdf@google.com>
Date: Wed, 9 Aug 2023 09:54:14 -0700
From: Stanislav Fomichev <sdf@...gle.com>
To: bpf@...r.kernel.org
Cc: ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
martin.lau@...ux.dev, song@...nel.org, yhs@...com, john.fastabend@...il.com,
kpsingh@...nel.org, sdf@...gle.com, haoluo@...gle.com, jolsa@...nel.org,
kuba@...nel.org, toke@...nel.org, willemb@...gle.com, dsahern@...nel.org,
magnus.karlsson@...el.com, bjorn@...nel.org, maciej.fijalkowski@...el.com,
hawk@...nel.org, netdev@...r.kernel.org, xdp-hints@...-project.net
Subject: [PATCH bpf-next 5/9] selftests/xsk: Support XDP_TX_METADATA_LEN
Add new config field and call setsockopt.
Signed-off-by: Stanislav Fomichev <sdf@...gle.com>
---
tools/testing/selftests/bpf/xsk.c | 17 +++++++++++++++++
tools/testing/selftests/bpf/xsk.h | 1 +
2 files changed, 18 insertions(+)
diff --git a/tools/testing/selftests/bpf/xsk.c b/tools/testing/selftests/bpf/xsk.c
index d9fb2b730a2c..cb7e48f24289 100644
--- a/tools/testing/selftests/bpf/xsk.c
+++ b/tools/testing/selftests/bpf/xsk.c
@@ -49,6 +49,10 @@
#define PF_XDP AF_XDP
#endif
+#ifndef XDP_TX_METADATA_LEN
+#define XDP_TX_METADATA_LEN 9
+#endif
+
#define pr_warn(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#define XSKMAP_SIZE 1
@@ -132,12 +136,14 @@ static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
cfg->rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
cfg->tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
cfg->bind_flags = 0;
+ cfg->tx_metadata_len = 0;
return 0;
}
cfg->rx_size = usr_cfg->rx_size;
cfg->tx_size = usr_cfg->tx_size;
cfg->bind_flags = usr_cfg->bind_flags;
+ cfg->tx_metadata_len = usr_cfg->tx_metadata_len;
return 0;
}
@@ -613,6 +619,17 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
umem->tx_ring_setup_done = true;
}
+ if (xsk->config.tx_metadata_len) {
+ int optval = xsk->config.tx_metadata_len;
+
+ err = setsockopt(xsk->fd, SOL_XDP, XDP_TX_METADATA_LEN,
+ &optval, sizeof(optval));
+ if (err) {
+ err = -errno;
+ goto out_put_ctx;
+ }
+ }
+
err = xsk_get_mmap_offsets(xsk->fd, &off);
if (err) {
err = -errno;
diff --git a/tools/testing/selftests/bpf/xsk.h b/tools/testing/selftests/bpf/xsk.h
index d93200fdaa8d..325fe0c83e5d 100644
--- a/tools/testing/selftests/bpf/xsk.h
+++ b/tools/testing/selftests/bpf/xsk.h
@@ -212,6 +212,7 @@ struct xsk_socket_config {
__u32 rx_size;
__u32 tx_size;
__u16 bind_flags;
+ __u8 tx_metadata_len;
};
/* Set config to NULL to get the default configuration. */
--
2.41.0.640.ga95def55d0-goog
Powered by blists - more mailing lists