Commit bf4ea1d0 authored by Leon Hwang's avatar Leon Hwang Committed by Alexei Starovoitov

bpf, xdp: Add tracepoint to xdp attaching failure

When error happens in dev_xdp_attach(), it should have a way to tell
users the error message like the netlink approach.

To avoid breaking uapi, adding a tracepoint in bpf_xdp_link_attach() is
an appropriate way to notify users the error message.

Hence, bpf libraries are able to retrieve the error message by this
tracepoint, and then report the error message to users.
Signed-off-by: default avatarLeon Hwang <hffilwlqm@gmail.com>
Link: https://lore.kernel.org/r/20230801142621.7925-2-hffilwlqm@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 416c6d01
...@@ -404,6 +404,23 @@ TRACE_EVENT(mem_return_failed, ...@@ -404,6 +404,23 @@ TRACE_EVENT(mem_return_failed,
) )
); );
TRACE_EVENT(bpf_xdp_link_attach_failed,
TP_PROTO(const char *msg),
TP_ARGS(msg),
TP_STRUCT__entry(
__string(msg, msg)
),
TP_fast_assign(
__assign_str(msg, msg);
),
TP_printk("errmsg=%s", __get_str(msg))
);
#endif /* _TRACE_XDP_H */ #endif /* _TRACE_XDP_H */
#include <trace/define_trace.h> #include <trace/define_trace.h>
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
#include <trace/events/net.h> #include <trace/events/net.h>
#include <trace/events/skb.h> #include <trace/events/skb.h>
#include <trace/events/qdisc.h> #include <trace/events/qdisc.h>
#include <trace/events/xdp.h>
#include <linux/inetdevice.h> #include <linux/inetdevice.h>
#include <linux/cpu_rmap.h> #include <linux/cpu_rmap.h>
#include <linux/static_key.h> #include <linux/static_key.h>
...@@ -9470,6 +9471,7 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) ...@@ -9470,6 +9471,7 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
{ {
struct net *net = current->nsproxy->net_ns; struct net *net = current->nsproxy->net_ns;
struct bpf_link_primer link_primer; struct bpf_link_primer link_primer;
struct netlink_ext_ack extack = {};
struct bpf_xdp_link *link; struct bpf_xdp_link *link;
struct net_device *dev; struct net_device *dev;
int err, fd; int err, fd;
...@@ -9497,12 +9499,13 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) ...@@ -9497,12 +9499,13 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
goto unlock; goto unlock;
} }
err = dev_xdp_attach_link(dev, NULL, link); err = dev_xdp_attach_link(dev, &extack, link);
rtnl_unlock(); rtnl_unlock();
if (err) { if (err) {
link->dev = NULL; link->dev = NULL;
bpf_link_cleanup(&link_primer); bpf_link_cleanup(&link_primer);
trace_bpf_xdp_link_attach_failed(extack._msg);
goto out_put_dev; goto out_put_dev;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment