From: Wander Lairson Costa <wander@redhat.com>
To: williams@redhat.com
Cc: linux-rt-users@vger.kernel.org,
Wander Lairson Costa <wander@redhat.com>,
Derek Barbosa <debarbos@redhat.com>,
John Kacur <jkacur@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Chunsheng Luo <luochunsheng@ustc.edu>
Subject: [PATCH] bpf: Add BPF CO-RE compatibility for older kernels
Date: Tue, 4 Nov 2025 11:11:44 -0300 [thread overview]
Message-ID: <20251104141144.31173-1-wander@redhat.com> (raw)
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
next reply other threads:[~2025-11-04 14:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 14:11 Wander Lairson Costa [this message]
2025-11-04 19:57 ` [PATCH] bpf: Add BPF CO-RE compatibility for older kernels Clark Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251104141144.31173-1-wander@redhat.com \
--to=wander@redhat.com \
--cc=debarbos@redhat.com \
--cc=jkacur@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=luochunsheng@ustc.edu \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.