Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Leon Hwang <hffilwlqm@gmail.com>
Link: https://lore.kernel.org/r/20230801142621.7925-2-hffilwlqm@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Leon Hwang and committed by
Alexei Starovoitov
bf4ea1d0 416c6d01

+21 -1
+17
include/trace/events/xdp.h
··· 404 404 ) 405 405 ); 406 406 407 + TRACE_EVENT(bpf_xdp_link_attach_failed, 408 + 409 + TP_PROTO(const char *msg), 410 + 411 + TP_ARGS(msg), 412 + 413 + TP_STRUCT__entry( 414 + __string(msg, msg) 415 + ), 416 + 417 + TP_fast_assign( 418 + __assign_str(msg, msg); 419 + ), 420 + 421 + TP_printk("errmsg=%s", __get_str(msg)) 422 + ); 423 + 407 424 #endif /* _TRACE_XDP_H */ 408 425 409 426 #include <trace/define_trace.h>
+4 -1
net/core/dev.c
··· 133 133 #include <trace/events/net.h> 134 134 #include <trace/events/skb.h> 135 135 #include <trace/events/qdisc.h> 136 + #include <trace/events/xdp.h> 136 137 #include <linux/inetdevice.h> 137 138 #include <linux/cpu_rmap.h> 138 139 #include <linux/static_key.h> ··· 9471 9470 { 9472 9471 struct net *net = current->nsproxy->net_ns; 9473 9472 struct bpf_link_primer link_primer; 9473 + struct netlink_ext_ack extack = {}; 9474 9474 struct bpf_xdp_link *link; 9475 9475 struct net_device *dev; 9476 9476 int err, fd; ··· 9499 9497 goto unlock; 9500 9498 } 9501 9499 9502 - err = dev_xdp_attach_link(dev, NULL, link); 9500 + err = dev_xdp_attach_link(dev, &extack, link); 9503 9501 rtnl_unlock(); 9504 9502 9505 9503 if (err) { 9506 9504 link->dev = NULL; 9507 9505 bpf_link_cleanup(&link_primer); 9506 + trace_bpf_xdp_link_attach_failed(extack._msg); 9508 9507 goto out_put_dev; 9509 9508 } 9510 9509