Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libxdp: Modify semantic of fill and comp in xsk_socket_opts, with tests edited #462

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions headers/xdp/xsk.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,9 @@ struct xsk_socket_config {
*
* @fill, @comp, @rx_size, @tx_size, @libxdp_flags, @xdp_flags,
* @bind_flags
* If a socket with exclusive ownership of a umem is going to be
* created, keep @fill and @comp unset. If the umem is to be shared
* with other sockets, set @fill and @comp to the corresponding
* fields of the umem.
* If @fill and @comp are both unset, they will be set to umem's
* fill_save and comp_save respectively. Note that it is invalid
* to set only one of them.
* If the remaining fields are unset, they will be set to
* default value (see `xsk_set_xdp_socket_config()`).
*
Expand Down
20 changes: 11 additions & 9 deletions lib/libxdp/tests/test_xsk_non_privileged.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,22 @@ static struct xsk_socket *create_xsk_non_privileged(const char *ifname,
struct xsk_umem *umem,
int queue_id)
{
struct xsk_socket_config cfg = {
struct xsk_socket *xsk = NULL;
struct xsk_ring_cons rx;
struct xsk_ring_prod tx;

DECLARE_LIBXDP_OPTS(xsk_socket_opts, opts,
.rx = &rx,
.tx = &tx,
.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.libxdp_flags = XSK_LIBXDP_FLAGS__INHIBIT_PROG_LOAD,
.bind_flags = XDP_USE_NEED_WAKEUP,
.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST,
};
struct xsk_socket *xsk = NULL;
struct xsk_ring_cons rx;
struct xsk_ring_prod tx;

if (xsk_socket__create(&xsk, ifname, queue_id,
umem, &rx, &tx, &cfg) || !xsk) {
perror("xsk_socket__create failed");
);
xsk = xsk_socket__create_opts(ifname, queue_id, umem, &opts);
if (!xsk) {
perror("xsk_socket__create_opts failed");
exit(EXIT_FAILURE);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/libxdp/tests/test_xsk_refcnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
unsigned int qid)
{
struct xsk_socket_config cfg = {};
struct xsk_socket_info *xsk;
struct xsk_ring_cons *rxr;

Expand All @@ -134,11 +133,12 @@ static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
exit(EXIT_FAILURE);

xsk->umem = umem;
cfg.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;

rxr = &xsk->rx;
xsk_socket__create(&xsk->xsk, opt_if, qid, umem->umem,
rxr, NULL, &cfg);
DECLARE_LIBXDP_OPTS(xsk_socket_opts, opts,
.rx = rxr,
.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
);
xsk->xsk = xsk_socket__create_opts(opt_if, qid, umem->umem, &opts);

return xsk;
}
Expand Down
10 changes: 7 additions & 3 deletions lib/libxdp/xsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,13 +1072,17 @@ struct xsk_socket *xsk_socket__create_opts(const char *ifname,
}
rx = OPTS_GET(opts, rx, NULL);
tx = OPTS_GET(opts, tx, NULL);
fill = OPTS_GET(opts, fill, umem->fill_save);
comp = OPTS_GET(opts, comp, umem->comp_save);
fill = OPTS_GET(opts, fill, NULL);
comp = OPTS_GET(opts, comp, NULL);

if (!umem || !(rx || tx)) {
if (!umem || !(rx || tx) || (fill == NULL) ^ (comp == NULL)) {
err = -EFAULT;
goto err;
}
if (!fill && !comp) {
fill = umem->fill_save;
comp = umem->comp_save;
}

xsk = calloc(1, sizeof(*xsk));
if (!xsk) {
Expand Down