* [PATCH] bpf: Add BPF CO-RE compatibility for older kernels
@ 2025-11-04 14:11 Wander Lairson Costa
2025-11-04 19:57 ` Clark Williams
0 siblings, 1 reply; 2+ messages in thread
From: Wander Lairson Costa @ 2025-11-04 14:11 UTC (permalink / raw)
To: williams
Cc: linux-rt-users, Wander Lairson Costa, Derek Barbosa, John Kacur,
Juri Lelli, Chunsheng Luo
Introduce a `thread_info___legacy` struct to provide BPF CO-RE
compatibility for older kernels (e.g., RHEL 8.x with 4.18) where the
`thread_info` struct lacks the `cpu` field. This allows `bpf_core_field_exists()`
checks to correctly determine the availability of this field at runtime,
preventing build failures on such systems.
The `task_cpu` helper function is updated to utilize this new legacy
struct when accessing the `cpu` field from `thread_info`, ensuring
that the BPF program can adapt to different kernel versions.
Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Cc: Derek Barbosa <debarbos@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Chunsheng Luo <luochunsheng@ustc.edu>
---
bpf/stalld.bpf.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/bpf/stalld.bpf.c b/bpf/stalld.bpf.c
index b0a62ac..bf55f5b 100644
--- a/bpf/stalld.bpf.c
+++ b/bpf/stalld.bpf.c
@@ -49,6 +49,16 @@ struct {
#define log_task(p) log_task_prefix("", p)
#define log_task_error(p) log_task_prefix("error: ", p)
+/*
+ * BPF CO-RE compatibility: In older kernels (e.g., RHEL 8.x with 4.18),
+ * thread_info lacks the cpu field. We define it here to enable
+ * bpf_core_field_exists() checks, allowing runtime detection of whether
+ * this field is available on the target kernel.
+ */
+struct thread_info___legacy {
+ int cpu;
+};
+
/*
* BPF CO-RE "weak" or "candidate" definition.
*
@@ -105,10 +115,11 @@ static inline bool task_is_rt(const struct task_struct *p)
static inline int task_cpu(const struct task_struct *p)
{
const struct task_struct___legacy *lp = (const void *) p;
+ const struct thread_info___legacy *lt = (const void *) &p->thread_info;
return bpf_core_field_exists(lp->cpu)
? BPF_CORE_READ(lp, cpu)
- : BPF_CORE_READ(p, thread_info.cpu);
+ : BPF_CORE_READ(lt, cpu);
}
/**
--
2.51.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] bpf: Add BPF CO-RE compatibility for older kernels
2025-11-04 14:11 [PATCH] bpf: Add BPF CO-RE compatibility for older kernels Wander Lairson Costa
@ 2025-11-04 19:57 ` Clark Williams
0 siblings, 0 replies; 2+ messages in thread
From: Clark Williams @ 2025-11-04 19:57 UTC (permalink / raw)
To: Wander Lairson Costa
Cc: linux-rt-users, Derek Barbosa, John Kacur, Juri Lelli,
Chunsheng Luo
On Tue, Nov 04, 2025 at 11:11:44AM -0300, Wander Lairson Costa wrote:
> Introduce a `thread_info___legacy` struct to provide BPF CO-RE
> compatibility for older kernels (e.g., RHEL 8.x with 4.18) where the
> `thread_info` struct lacks the `cpu` field. This allows `bpf_core_field_exists()`
> checks to correctly determine the availability of this field at runtime,
> preventing build failures on such systems.
>
> The `task_cpu` helper function is updated to utilize this new legacy
> struct when accessing the `cpu` field from `thread_info`, ensuring
> that the BPF program can adapt to different kernel versions.
>
> Signed-off-by: Wander Lairson Costa <wander@redhat.com>
> Cc: Derek Barbosa <debarbos@redhat.com>
> Cc: John Kacur <jkacur@redhat.com>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Chunsheng Luo <luochunsheng@ustc.edu>
Applied to my devel branch along with the BPF verbose patch to the
Makefile. I'm assembling the v1.25.1 release which will be these two
changes and the current test-suite. Hopefully will go out today or
tomorrow.
Clark
--
The United States Coast Guard
Ruining Natural Selection since 1790
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-04 19:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 14:11 [PATCH] bpf: Add BPF CO-RE compatibility for older kernels Wander Lairson Costa
2025-11-04 19:57 ` Clark Williams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).