-
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 'writeable-bpf-tracepoints'
Matt Mullins says: ==================== This adds an opt-in interface for tracepoints to expose a writable context to BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE programs that are attached, while supporting read-only access from existing BPF_PROG_TYPE_RAW_TRACEPOINT programs, as well as from non-BPF-based tracepoints. The initial motivation is to support tracing that can be observed from the remote end of an NBD socket, e.g. by adding flags to the struct nbd_request header. Earlier attempts included adding an NBD-specific tracepoint fd, but in code review, I was recommended to implement it more generically -- as a result, this patchset is far simpler than my initial try. v4->v5: * rebased onto bpf-next/master and fixed merge conflicts * "tools: sync bpf.h" also syncs comments that have previously changed in bpf-next v3->v4: * fixed a silly copy/paste typo in include/trace/events/bpf_test_run.h (_TRACE_NBD_H -> _TRACE_BPF_TEST_RUN_H) * fixed incorrect/misleading wording in patch 1's commit message, since the pointer cannot be directly dereferenced in a BPF_PROG_TYPE_RAW_TRACEPOINT * cleaned up the error message wording if the prog_tests fail * Addressed feedback from Yonghong * reject non-pointer-sized accesses to the buffer pointer * use sizeof(struct nbd_request) as one-byte-past-the-end in raw_tp_writable_reject_nbd_invalid.c * use BPF_MOV64_IMM instead of BPF_LD_IMM64 v2->v3: * Andrew addressed Josef's comments: * C-style commenting in nbd.c * Collapsed identical events into a single DECLARE_EVENT_CLASS. This saves about 2kB of kernel text v1->v2: * add selftests * sync tools/include/uapi/linux/bpf.h * reject variable offset into the buffer * add string representation of PTR_TO_TP_BUFFER to reg_type_str ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Showing
19 changed files
with
433 additions
and
5 deletions.
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
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,50 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#undef TRACE_SYSTEM | ||
#define TRACE_SYSTEM bpf_test_run | ||
|
||
#if !defined(_TRACE_BPF_TEST_RUN_H) || defined(TRACE_HEADER_MULTI_READ) | ||
#define _TRACE_BPF_TEST_RUN_H | ||
|
||
#include <linux/tracepoint.h> | ||
|
||
DECLARE_EVENT_CLASS(bpf_test_finish, | ||
|
||
TP_PROTO(int *err), | ||
|
||
TP_ARGS(err), | ||
|
||
TP_STRUCT__entry( | ||
__field(int, err) | ||
), | ||
|
||
TP_fast_assign( | ||
__entry->err = *err; | ||
), | ||
|
||
TP_printk("bpf_test_finish with err=%d", __entry->err) | ||
); | ||
|
||
#ifdef DEFINE_EVENT_WRITABLE | ||
#undef BPF_TEST_RUN_DEFINE_EVENT | ||
#define BPF_TEST_RUN_DEFINE_EVENT(template, call, proto, args, size) \ | ||
DEFINE_EVENT_WRITABLE(template, call, PARAMS(proto), \ | ||
PARAMS(args), size) | ||
#else | ||
#undef BPF_TEST_RUN_DEFINE_EVENT | ||
#define BPF_TEST_RUN_DEFINE_EVENT(template, call, proto, args, size) \ | ||
DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args)) | ||
#endif | ||
|
||
BPF_TEST_RUN_DEFINE_EVENT(bpf_test_finish, bpf_test_finish, | ||
|
||
TP_PROTO(int *err), | ||
|
||
TP_ARGS(err), | ||
|
||
sizeof(int) | ||
); | ||
|
||
#endif | ||
|
||
/* This part must be outside protection */ | ||
#include <trace/define_trace.h> |
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,107 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#undef TRACE_SYSTEM | ||
#define TRACE_SYSTEM nbd | ||
|
||
#if !defined(_TRACE_NBD_H) || defined(TRACE_HEADER_MULTI_READ) | ||
#define _TRACE_NBD_H | ||
|
||
#include <linux/tracepoint.h> | ||
|
||
DECLARE_EVENT_CLASS(nbd_transport_event, | ||
|
||
TP_PROTO(struct request *req, u64 handle), | ||
|
||
TP_ARGS(req, handle), | ||
|
||
TP_STRUCT__entry( | ||
__field(struct request *, req) | ||
__field(u64, handle) | ||
), | ||
|
||
TP_fast_assign( | ||
__entry->req = req; | ||
__entry->handle = handle; | ||
), | ||
|
||
TP_printk( | ||
"nbd transport event: request %p, handle 0x%016llx", | ||
__entry->req, | ||
__entry->handle | ||
) | ||
); | ||
|
||
DEFINE_EVENT(nbd_transport_event, nbd_header_sent, | ||
|
||
TP_PROTO(struct request *req, u64 handle), | ||
|
||
TP_ARGS(req, handle) | ||
); | ||
|
||
DEFINE_EVENT(nbd_transport_event, nbd_payload_sent, | ||
|
||
TP_PROTO(struct request *req, u64 handle), | ||
|
||
TP_ARGS(req, handle) | ||
); | ||
|
||
DEFINE_EVENT(nbd_transport_event, nbd_header_received, | ||
|
||
TP_PROTO(struct request *req, u64 handle), | ||
|
||
TP_ARGS(req, handle) | ||
); | ||
|
||
DEFINE_EVENT(nbd_transport_event, nbd_payload_received, | ||
|
||
TP_PROTO(struct request *req, u64 handle), | ||
|
||
TP_ARGS(req, handle) | ||
); | ||
|
||
DECLARE_EVENT_CLASS(nbd_send_request, | ||
|
||
TP_PROTO(struct nbd_request *nbd_request, int index, | ||
struct request *rq), | ||
|
||
TP_ARGS(nbd_request, index, rq), | ||
|
||
TP_STRUCT__entry( | ||
__field(struct nbd_request *, nbd_request) | ||
__field(u64, dev_index) | ||
__field(struct request *, request) | ||
), | ||
|
||
TP_fast_assign( | ||
__entry->nbd_request = 0; | ||
__entry->dev_index = index; | ||
__entry->request = rq; | ||
), | ||
|
||
TP_printk("nbd%lld: request %p", __entry->dev_index, __entry->request) | ||
); | ||
|
||
#ifdef DEFINE_EVENT_WRITABLE | ||
#undef NBD_DEFINE_EVENT | ||
#define NBD_DEFINE_EVENT(template, call, proto, args, size) \ | ||
DEFINE_EVENT_WRITABLE(template, call, PARAMS(proto), \ | ||
PARAMS(args), size) | ||
#else | ||
#undef NBD_DEFINE_EVENT | ||
#define NBD_DEFINE_EVENT(template, call, proto, args, size) \ | ||
DEFINE_EVENT(template, call, PARAMS(proto), PARAMS(args)) | ||
#endif | ||
|
||
NBD_DEFINE_EVENT(nbd_send_request, nbd_send_request, | ||
|
||
TP_PROTO(struct nbd_request *nbd_request, int index, | ||
struct request *rq), | ||
|
||
TP_ARGS(nbd_request, index, rq), | ||
|
||
sizeof(struct nbd_request) | ||
); | ||
|
||
#endif | ||
|
||
/* This part must be outside protection */ | ||
#include <trace/define_trace.h> |
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
Oops, something went wrong.