BPF atomic macros require CONFIG_X86_64 to determine barrier
instructions. Reading this from the system Kconfig can fail if the
configuration is missing or in an unexpected location, causing the
loading phase to fail.

Since the rv tool is compiled for the target architecture, the
architecture is known at compile-time. Define the CONFIG_X86_64 value
statically via the libbpf open options to bypass Kconfig dependency and
ensure reliable loading.

Signed-off-by: Gabriele Monaco <[email protected]>
---
 tools/verification/rv/src/bpf_monitor.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/verification/rv/src/bpf_monitor.c 
b/tools/verification/rv/src/bpf_monitor.c
index 9a3f00febfeb..d43ee75d3904 100644
--- a/tools/verification/rv/src/bpf_monitor.c
+++ b/tools/verification/rv/src/bpf_monitor.c
@@ -719,7 +719,16 @@ static struct bpf_object *open_bpf_monitor(const char 
*path, struct bpf_monitor_
        struct bpf_object *obj = NULL;
        int res;
 
-       obj = bpf_object__open_file(path, NULL);
+       LIBBPF_OPTS(bpf_object_open_opts, opts,
+               /* Define statically as arch is known, Kconfig may not be 
available */
+#ifdef __x86_64__
+               .kconfig = "CONFIG_X86_64=y\n",
+#else
+               .kconfig = "CONFIG_X86_64=n\n",
+#endif
+       );
+
+       obj = bpf_object__open_file(path, &opts);
        if (!obj) {
                err_msg("bpf: error opening object: %s\n", strerror(errno));
                return NULL;
-- 
2.55.0


Reply via email to