Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for CORE type matches relocation #1360

Closed
Tracked by #2542
alban opened this issue Feb 26, 2024 · 0 comments · Fixed by #1366
Closed
Tracked by #2542

Support for CORE type matches relocation #1360

alban opened this issue Feb 26, 2024 · 0 comments · Fixed by #1366
Assignees
Labels
enhancement New feature or request

Comments

@alban
Copy link
Contributor

alban commented Feb 26, 2024

Describe the bug

Type matches relocation are currently not supported.

bpf_core_type_matches() (using BPF_TYPE_MATCHES) is defined in libbpf:
https://github.com/libbpf/libbpf/blob/v1.3.0/src/bpf_core_read.h#L194

Type match relocations was added in llvm/clang 15:
llvm/llvm-project@d129ac2

Example of usage:
https://github.com/torvalds/linux/blob/v6.6/tools/perf/util/bpf_skel/lock_contention.bpf.c#L215

Relocations of type BPF_CORE_TYPE_MATCHES are explained in:
https://docs.kernel.org/bpf/llvm_reloc.html

cilium/ebpf supports the following relocations:

enum bpf_core_relo_kind {
...
       BPF_CORE_ENUMVAL_VALUE     = 11, /* enum value integer value */
       BPF_CORE_TYPE_MATCHES      = 12, /* type match in target kernel */
};

It stops at BPF_CORE_ENUMVAL_VALUE / reloEnumvalValue:
https://github.com/cilium/ebpf/blob/v0.13.0/btf/core.go#L121

cc @eiffel-fl @mauriciovasquezbernal

How to reproduce

Code inspired from:

// https://github.com/torvalds/linux/commit/a54895fa057c67700270777f7661d8d3c7fda88a
// -       TP_PROTO(struct request_queue *q, struct request *rq),
// +       TP_PROTO(struct request *rq),
typedef void (*btf_trace_block_rq_insert___new)(void *, struct request *);
typedef void (*btf_trace_block_rq_insert___old)(void *, struct request_queue *q, struct request *);
typedef void (*btf_trace_block_rq_issue___new)(void *, struct request *);
typedef void (*btf_trace_block_rq_issue___old)(void *, struct request_queue *q, struct request *);

static void (*bpf_unreachable)(void) = (void *) 0xbad2310;

SEC("raw_tp/block_rq_insert")
int ig_profio_ins(u64 *ctx)
{
        if (bpf_core_type_matches(btf_trace_block_rq_insert___new)) {
                // After commit a54895fa (v5.11-rc1)
                return trace_rq_start((void *)ctx[0], true);
        } else if (bpf_core_type_matches(btf_trace_block_rq_insert___old)) {
                // Before commit a54895fa (v5.11-rc1)
                return trace_rq_start((void *)ctx[1], false);
        } else {
                // Couldn't detect block/block_rq_insert tracepoint
                bpf_unreachable();
                return 0;
        }
}

cilium/ebpf gives the following error:

installing tracer: loading ebpf program: field IgProfioIns: program ig_profio_ins: apply CO-RE relocations: relocate Typedef:"btf_trace_block_rq_insert___new": target Typedef:"btf_trace_block_rq_insert": unknown: not supported

Version information

github.com/cilium/ebpf v0.13.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants