libbpf: Don't error out if getsockopt() fails for XDP_OPTIONS
Subsystems (4)
PATCH 1/1 libbpf: Don't error out if getsockopt() fails for XDP_OPTIONS
The xsk_socket__create() function fails and returns an error if it cannot get the XDP_OPTIONS through getsockopt(). However, support for XDP_OPTIONS was not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.
Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the getsockopt() call fails.
--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
tools/lib/bpf/xsk.c +2 -6
@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) { - err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);
Signature · 1 line
2.23.0
Quoted 22 lines · Toke Høiland-Jørgensen
The
xsk_socket__create()function fails and returns an error if it cannot get theXDP_OPTIONSthroughgetsockopt(). However, support forXDP_OPTIONSwas not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the
getsockopt()call fails.Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/lib/bpf/xsk.c +0
-1@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) {
tools/lib/bpf/xsk.c int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, · line 610
Quoted 10 lines
tools/lib/bpf/xsk.c +2
-5- err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);
Since 'zc' is not used by anybody, maybe all codes 'zc' related can be removed? It can be added back back once there is an interface to use 'zc'?
tools/lib/bpf/xsk.c +0 -1
@@ -65,7 +65,6 @@ struct xsk_socket {int xsks_map_fd;__u32 queue_id;char ifname[IFNAMSIZ ]; -bool zc; };struct xsk_nl_info {
@@ -491,7 +490,6 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr,
const char *ifname,
void *rx_map = NULL, *tx_map = NULL;
struct sockaddr_xdp sxdp = {};
struct xdp_mmap_offsets off;
- struct xdp_options opts;
struct xsk_socket *xsk;
socklen_t optlen;
int err;@@ -611,15 +609,6 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
xsk->prog_fd = -1;
- optlen = sizeof(opts);
- err = getsockopt(xsk->fd, SOL_XDP, XDP_OPTIONS, &opts, &optlen);
- if (err) {- err = -errno;
- goto out_mmap_tx;
- }
-
- xsk->zc = opts.flags & XDP_OPTIONS_ZEROCOPY;
-
if (!(xsk->config.libbpf_flags &
XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD)) {
err = xsk_setup_xdp_prog(xsk);
if (err)Quoted 31 lines · Yonghong Song
Quoted 30 lines · Toke Høiland-Jørgensen
The
xsk_socket__create()function fails and returns an error if it cannot get theXDP_OPTIONSthroughgetsockopt(). However, support forXDP_OPTIONSwas not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the
getsockopt()call fails.Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/lib/bpf/xsk.c +2
-6@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) { - err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;
Quoted 6 lines
tools/lib/bpf/xsk.c int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, · line 610
Quoted 2 lines
tools/lib/bpf/xsk.c +0
-0if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);Since 'zc' is not used by anybody, maybe all codes 'zc' related can be removed? It can be added back back once there is an interface to use 'zc'?
Fine with me; up to the maintainers what they prefer, I guess? :)
-Toke
Quoted 33 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Yonghong Song
Quoted 30 lines · Toke Høiland-Jørgensen
The
xsk_socket__create()function fails and returns an error if it cannot get theXDP_OPTIONSthroughgetsockopt(). However, support forXDP_OPTIONSwas not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the
getsockopt()call fails.Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/lib/bpf/xsk.c +2
-6@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) { - err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;
Quoted 8 lines
Quoted 6 lines
tools/lib/bpf/xsk.c int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, · line 610
Quoted 2 lines
tools/lib/bpf/xsk.c +0
-0if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);Since 'zc' is not used by anybody, maybe all codes 'zc' related can be removed? It can be added back back once there is an interface to use 'zc'?
Fine with me; up to the maintainers what they prefer, I guess? :)
Maxim,
Your originally introduced `'zc' and getting XDP_OPTIONS. What is your opinion of how to deal with the unused xsk->zc?
Quoted 3 lines
-Toke
Quoted 44 lines · Yonghong Song
Quoted 40 lines · Toke Høiland-Jørgensen
Quoted 37 lines · Yonghong Song
Quoted 22 lines · Toke Høiland-Jørgensen
The
xsk_socket__create()function fails and returns an error if it cannot get theXDP_OPTIONSthroughgetsockopt(). However, support forXDP_OPTIONSwas not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the
getsockopt()call fails.Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/lib/bpf/xsk.c +0
-1@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) {tools/lib/bpf/xsk.c int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, · line 610
Quoted 10 lines
tools/lib/bpf/xsk.c +2
-5- err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);Since 'zc' is not used by anybody, maybe all codes 'zc' related can be removed? It can be added back back once there is an interface to use 'zc'?
Quoted 7 lines
Quoted 1 line
Fine with me; up to the maintainers what they prefer, I guess? :)
Maxim,
Your originally introduced `'zc' and getting
XDP_OPTIONS. What is your opinion of how to deal with the unusedxsk->zc?
This was previously discussed here [1]. The TL;DR version is "stay tuned for a proper interface". :-)
Björn
[1] https://lore.kernel.org/bpf/CAJ8uoz1qhaHwebmjOOS9xfJe93Eq0v=SXhQUnjHv7imVL3ONsQ@mail.gmail.com/#t
Quoted 3 lines
Quoted 3 lines
-Toke
Daniel Borkmann
maintainerQuoted 33 lines · Yonghong Song
Quoted 32 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Yonghong Song
Quoted 30 lines · Toke Høiland-Jørgensen
The
xsk_socket__create()function fails and returns an error if it cannot get theXDP_OPTIONSthroughgetsockopt(). However, support forXDP_OPTIONSwas not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the
getsockopt()call fails.Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/lib/bpf/xsk.c +2
-6@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) { - err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
tools/lib/bpf/xsk.c int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, · line 610
Quoted 2 lines
tools/lib/bpf/xsk.c +0
-0if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);Since 'zc' is not used by anybody, maybe all codes 'zc' related can be removed? It can be added back back once there is an interface to use 'zc'?
Fine with me; up to the maintainers what they prefer, I guess? :)
Given this is not exposed to applications at this point and we don't do anything useful with it, lets just remove the zc cruft until there is a proper interface added to libbpf. Toke, please respin with the suggested removal, thanks!
Quoted 41 lines · Daniel Borkmann
Quoted 40 lines · Yonghong Song
Quoted 39 lines · Toke Høiland-Jørgensen
Quoted 37 lines · Yonghong Song
Quoted 22 lines · Toke Høiland-Jørgensen
The
xsk_socket__create()function fails and returns an error if it cannot get theXDP_OPTIONSthroughgetsockopt(). However, support forXDP_OPTIONSwas not added until kernel 5.3, so this means that creating XSK sockets always fails on older kernels.Since the option is just used to set the zero-copy flag in the xsk struct, there really is no need to error out if the
getsockopt()call fails.Signed-off-by Toke Høiland-Jørgensen <[email protected]>--- tools/lib/bpf/xsk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)tools/lib/bpf/xsk.c +0
-1@@ -603,12 +603,8 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, optlen =sizeof (opts); err =getsockopt (xsk->fd,SOL_XDP ,XDP_OPTIONS , &opts, &optlen); -if (err) {tools/lib/bpf/xsk.c int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, · line 610
Quoted 10 lines
tools/lib/bpf/xsk.c +2
-5- err = -errno; - goto out_mmap_tx; - } - - xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ; +if (!err) + xsk->zc = opts.flags &XDP_OPTIONS_ZEROCOPY ;if (!(xsk->config.libbpf_flags &XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD )) { err =xsk_setup_xdp_prog (xsk);Since 'zc' is not used by anybody, maybe all codes 'zc' related can be removed? It can be added back back once there is an interface to use 'zc'?
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Fine with me; up to the maintainers what they prefer, I guess? :)
Given this is not exposed to applications at this point and we don't do anything useful with it, lets just remove the zc cruft until there is a proper interface added to libbpf. Toke, please respin with the suggested removal, thanks!
Sure, can do :)
-Toke