-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bpf-xdp-add-tracepoint-to-xdp-attaching-failure'
Leon Hwang says: ==================== bpf, xdp: Add tracepoint to xdp attaching failure This series introduces a new tracepoint in bpf_xdp_link_attach(). By this tracepoint, error message will be captured when error happens in dev_xdp_attach(), e.g. invalid attaching flags. v4 -> v5: * Initialise the extack variable. * Fix code style issue of variable declaration lines. v3 -> v4: * Fix selftest-crashed issue. ==================== Link: https://lore.kernel.org/r/20230801142621.7925-1-hffilwlqm@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Showing
4 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright Leon Hwang */ | ||
|
||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
|
||
#define ERRMSG_LEN 64 | ||
|
||
struct xdp_errmsg { | ||
char msg[ERRMSG_LEN]; | ||
}; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); | ||
__type(key, int); | ||
__type(value, int); | ||
} xdp_errmsg_pb SEC(".maps"); | ||
|
||
struct xdp_attach_error_ctx { | ||
unsigned long unused; | ||
|
||
/* | ||
* bpf does not support tracepoint __data_loc directly. | ||
* | ||
* Actually, this field is a 32 bit integer whose value encodes | ||
* information on where to find the actual data. The first 2 bytes is | ||
* the size of the data. The last 2 bytes is the offset from the start | ||
* of the tracepoint struct where the data begins. | ||
* -- https://github.com/iovisor/bpftrace/pull/1542 | ||
*/ | ||
__u32 msg; // __data_loc char[] msg; | ||
}; | ||
|
||
/* | ||
* Catch the error message at the tracepoint. | ||
*/ | ||
|
||
SEC("tp/xdp/bpf_xdp_link_attach_failed") | ||
int tp__xdp__bpf_xdp_link_attach_failed(struct xdp_attach_error_ctx *ctx) | ||
{ | ||
char *msg = (void *)(__u64) ((void *) ctx + (__u16) ctx->msg); | ||
struct xdp_errmsg errmsg = {}; | ||
|
||
bpf_probe_read_kernel_str(&errmsg.msg, ERRMSG_LEN, msg); | ||
bpf_perf_event_output(ctx, &xdp_errmsg_pb, BPF_F_CURRENT_CPU, &errmsg, | ||
ERRMSG_LEN); | ||
return 0; | ||
} | ||
|
||
/* | ||
* Reuse the XDP program in xdp_dummy.c. | ||
*/ | ||
|
||
char LICENSE[] SEC("license") = "GPL"; |