From: Leon Hwang <leon.hwang@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Song Liu <song@kernel.org>, Eddy Z <eddyz87@gmail.com>,
Quentin Monnet <qmo@kernel.org>, Daniel Xu <dxu@dxuuu.xyz>,
kernel-patches-bot@fb.com
Subject: Re: [RESEND PATCH bpf-next v2 4/4] selftests/bpf: Add cases to test global percpu data
Date: Mon, 24 Feb 2025 13:40:46 +0800 [thread overview]
Message-ID: <fd1b3f58-c27f-403d-ad99-644b7d06ecb3@linux.dev> (raw)
In-Reply-To: <CAADnVQKtNg898X-n+LrRQ+1RHnTiEWGTppfm=QLauyjne24-8Q@mail.gmail.com>
On 2025/2/19 09:54, Alexei Starovoitov wrote:
> On Thu, Feb 13, 2025 at 8:20 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
[...]
>> +
>> + ASSERT_EQ(skel->percpu->data, -1, "skel->percpu->data");
>> + ASSERT_FALSE(skel->percpu->run, "skel->percpu->run");
>> + ASSERT_EQ(skel->percpu->data2, 0, "skel->percpu->data2");
>
> this will only check the value on cpu0, right?
> Let's check it on all ?
>
skel->percpu keeps only one image of the initial .percpu data for all CPUs.
Then, before .percpu map's bpf_map_update_elem(), libbpf prepares a
def.value_sz*num_cpus bytes buffer and fills the buffer with
skel->percpu, which is same as map->mmaped.
>> + map = skel->maps.percpu;
>> + if (!ASSERT_EQ(bpf_map__type(map), BPF_MAP_TYPE_PERCPU_ARRAY, "bpf_map__type"))
>> + goto out;
>> + if (!ASSERT_TRUE(bpf_map__is_internal_percpu(map), "bpf_map__is_internal_percpu"))
>> + goto out;
>> +
>> + init_value.data = 2;
>> + init_value.run = false;
>> + err = bpf_map__set_initial_value(map, &init_value, sizeof(init_value));
>> + if (!ASSERT_OK(err, "bpf_map__set_initial_value"))
>> + goto out;
>> +
>> + init_data = bpf_map__initial_value(map, &init_data_sz);
>> + if (!ASSERT_OK_PTR(init_data, "bpf_map__initial_value"))
>> + goto out;
>> +
[...]
>> +
>> + comm_fd = open("/proc/self/comm", O_WRONLY|O_TRUNC);
>> + if (!ASSERT_GE(comm_fd, 0, "open /proc/self/comm"))
>> + goto out;
>> +
>> + err = write(comm_fd, buf, sizeof(buf));
>> + if (!ASSERT_GE(err, 0, "task rename"))
>> + goto out;
>
> why this odd double run of bpf prog?
> First via task_rename and then directly?
> Only use bpf_prog_test_run_opts() and avoiding attaching to a tracepoint?
>
Oh, sorry. I copied it from raw_tp blindly.
I'll remove task_rename in patch v3.
>> +
>> + prog_fd = lskel->progs.update_percpu_data.prog_fd;
>> +
>> + /* run on every CPU */
>> + for (i = 0; i < num_online; i++) {
>> + if (!online[i])
>> + continue;
>> +
>> + topts.cpu = i;
>> + topts.retval = 0;
>> + err = bpf_prog_test_run_opts(prog_fd, &topts);
>> + ASSERT_OK(err, "bpf_prog_test_run_opts");
>> + ASSERT_EQ(topts.retval, 0, "bpf_prog_test_run_opts retval");
>> + }
>> +
>> + key = 0;
>> + map_fd = lskel->maps.percpu.map_fd;
>> + err = bpf_map_lookup_elem(map_fd, &key, percpu_data);
>> + if (!ASSERT_OK(err, "bpf_map_lookup_elem"))
>> + goto out;
>> +
>> + for (i = 0; i < num_online; i++) {
>> + if (!online[i])
>> + continue;
>> +
>> + data = percpu_data + i;
>> + ASSERT_EQ(data->data, 1, "percpu_data->data");
>> + ASSERT_TRUE(data->run, "percpu_data->run");
>> + ASSERT_EQ(data->data2, 0xc0de, "percpu_data->data2");
>> + }
>> +
>> +out:
>> + close(comm_fd);
>> + test_global_percpu_data_lskel__destroy(lskel);
>> + if (percpu_data)
>> + free(percpu_data);
>> + free(online);
>> +}
>> diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
>> new file mode 100644
>> index 0000000000000..ada292d3a164c
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
>> @@ -0,0 +1,20 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright Leon Hwang */
>
> Are you sure you can do it in your country?
> Often enough copyright belongs to the company you work for.
>
I don't think I should put my company name here, because this patch is
done at my spare time, not for my company at work time.
>> +#include <linux/bpf.h>
>> +#include <bpf/bpf_helpers.h>
>> +
>> +int data SEC(".percpu") = -1;
>> +int run SEC(".percpu") = 0;
>> +int data2 SEC(".percpu");
>
> Pls add u8, array of ints and struct { .. } vars for completeness.
>
After adding char, it hits a clang-17 BUG:
2025-02-23T13:32:30.6128324Z fatal error: error in backend: unable to
write nop sequence of 3 bytes
2025-02-23T13:32:30.6129623Z PLEASE submit a bug report to
https://github.com/llvm/llvm-project/issues/ and include the crash
backtrace, preprocessed source, and associated run script.
2025-02-23T13:32:30.6130688Z Stack dump:
2025-02-23T13:32:30.6135010Z 0. Program arguments: clang-17 -g -Wall
-Werror -D__TARGET_ARCH_arm64 -mlittle-endian
-I/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include
-I/tmp/work/bpf/bpf/tools/testing/selftests/bpf
-I/tmp/work/bpf/bpf/tools/include/uapi
-I/tmp/work/bpf/bpf/tools/testing/selftests/usr/include -std=gnu11
-fno-strict-aliasing -Wno-compare-distinct-pointer-types -idirafter
/usr/lib/llvm-17/lib/clang/17/include -idirafter /usr/local/include
-idirafter /usr/include/aarch64-linux-gnu -idirafter /usr/include
-DENABLE_ATOMICS_TESTS -O2 --target=bpfel -c
progs/test_global_percpu_data.c -mcpu=v3 -o
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/test_global_percpu_data.bpf.o
2025-02-23T13:32:30.6139287Z 1. <eof> parser at end of file
2025-02-23T13:32:30.6139669Z 2. Code generation
2025-02-23T13:32:30.6140548Z Stack dump without symbol names (ensure you
have llvm-symbolizer in your PATH or set the environment var
`LLVM_SYMBOLIZER_PATH` to point to it):
2025-02-23T13:32:30.6155286Z CLNG-BPF [test_progs]
test_ksyms_btf_null_check.bpf.o
2025-02-23T13:32:30.6183127Z CLNG-BPF [test_progs]
test_ksyms_btf_write_check.bpf.o
2025-02-23T13:32:30.6246698Z 0 libLLVM-17.so.1 0x0000ffffb2b64654
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 84
2025-02-23T13:32:30.6250241Z 1 libLLVM-17.so.1 0x0000ffffb2b62890
llvm::sys::RunSignalHandlers() + 116
2025-02-23T13:32:30.6253698Z 2 libLLVM-17.so.1 0x0000ffffb2ab73a0
2025-02-23T13:32:30.6257316Z 3 libLLVM-17.so.1 0x0000ffffb2ab734c
2025-02-23T13:32:30.6261230Z 4 libLLVM-17.so.1 0x0000ffffb2b5f3dc
llvm::sys::Process::Exit(int, bool) + 52
2025-02-23T13:32:30.6261860Z 5 clang-17 0x0000aaaae8ff2210
2025-02-23T13:32:30.6265004Z 6 libLLVM-17.so.1 0x0000ffffb2ac4ea0
llvm::report_fatal_error(llvm::Twine const&, bool) + 252
2025-02-23T13:32:30.6270377Z 7 libLLVM-17.so.1 0x0000ffffb3fb92c8
llvm::MCAssembler::writeSectionData(llvm::raw_ostream&, llvm::MCSection
const*, llvm::MCAsmLayout const&) const + 3324
2025-02-23T13:32:30.6274705Z 8 libLLVM-17.so.1 0x0000ffffb3fa44fc
2025-02-23T13:32:30.6279671Z 9 libLLVM-17.so.1 0x0000ffffb3fa2fc8
2025-02-23T13:32:30.6284761Z 10 libLLVM-17.so.1 0x0000ffffb3fb9af0
llvm::MCAssembler::Finish() + 92
2025-02-23T13:32:30.6289758Z 11 libLLVM-17.so.1 0x0000ffffb3fd73e4
llvm::MCELFStreamer::finishImpl() + 204
2025-02-23T13:32:30.6294422Z 12 libLLVM-17.so.1 0x0000ffffb337f408
llvm::AsmPrinter::doFinalization(llvm::Module&) + 4812
2025-02-23T13:32:30.6298295Z 13 libLLVM-17.so.1 0x0000ffffb2cb79e4
llvm::FPPassManager::doFinalization(llvm::Module&) + 76
2025-02-23T13:32:30.6302285Z 14 libLLVM-17.so.1 0x0000ffffb2cb2564
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1004
2025-02-23T13:32:30.6308831Z 15 libclang-cpp.so.17 0x0000ffffbabaacdc
clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef,
llvm::Module*, clang::BackendAction,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream>>) + 2560
2025-02-23T13:32:30.6311547Z 16 libclang-cpp.so.17 0x0000ffffbaeb387c
2025-02-23T13:32:30.6314141Z 17 libclang-cpp.so.17 0x0000ffffb9be5240
clang::ParseAST(clang::Sema&, bool, bool) + 572
2025-02-23T13:32:30.6318163Z 18 libclang-cpp.so.17 0x0000ffffbb8744a4
clang::FrontendAction::Execute() + 116
2025-02-23T13:32:30.6322561Z 19 libclang-cpp.so.17 0x0000ffffbb804cb8
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 768
2025-02-23T13:32:30.6326549Z 20 libclang-cpp.so.17 0x0000ffffbb8edc44
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 528
2025-02-23T13:32:30.6327641Z 21 clang-17 0x0000aaaae8ff1e44
cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2016
2025-02-23T13:32:30.6328373Z 22 clang-17 0x0000aaaae8fefe7c
2025-02-23T13:32:30.6330474Z 23 libclang-cpp.so.17 0x0000ffffbb50776c
2025-02-23T13:32:30.6333026Z CLNG-BPF [test_progs] test_ksyms.bpf.o
2025-02-23T13:32:30.6334773Z 24 libLLVM-17.so.1 0x0000ffffb2ab731c
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 168
2025-02-23T13:32:30.6339524Z 25 libclang-cpp.so.17 0x0000ffffbb506e74
clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>,
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char>>*, bool*) const + 348
2025-02-23T13:32:30.6343604Z 26 libclang-cpp.so.17 0x0000ffffbb4d5d08
clang::driver::Compilation::ExecuteCommand(clang::driver::Command
const&, clang::driver::Command const*&, bool) const + 760
2025-02-23T13:32:30.6348046Z 27 libclang-cpp.so.17 0x0000ffffbb4d5f18
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&,
bool) const + 140
2025-02-23T13:32:30.6352317Z 28 libclang-cpp.so.17 0x0000ffffbb4edc18
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 340
2025-02-23T13:32:30.6353837Z 29 clang-17 0x0000aaaae8fef5f0
clang_main(int, char**, llvm::ToolContext const&) + 9904
2025-02-23T13:32:30.6354564Z 30 clang-17 0x0000aaaae8ffa868
main + 52
2025-02-23T13:32:30.6355047Z 31 libc.so.6 0x0000ffffb19784c4
2025-02-23T13:32:30.6355559Z 32 libc.so.6 0x0000ffffb1978598
__libc_start_main + 152
2025-02-23T13:32:30.6356118Z 33 clang-17 0x0000aaaae8fecb70
_start + 48
2025-02-23T13:32:30.6356859Z clang-17: error: clang frontend command
failed with exit code 70 (use -v to see invocation)
For more details, pls check the failed jobs at
https://github.com/kernel-patches/bpf/pull/8543
Thanks,
Leon
prev parent reply other threads:[~2025-02-24 5:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 16:19 [RESEND PATCH bpf-next v2 0/4] bpf: Introduce global percpu data Leon Hwang
2025-02-13 16:19 ` [RESEND PATCH bpf-next v2 1/4] " Leon Hwang
2025-02-19 1:47 ` Alexei Starovoitov
2025-02-24 5:25 ` Leon Hwang
2025-02-26 2:19 ` Hou Tao
2025-02-26 4:26 ` Hou Tao
2025-02-26 14:54 ` Leon Hwang
2025-02-26 15:31 ` Alexei Starovoitov
2025-02-26 16:12 ` Leon Hwang
2025-02-27 2:11 ` Hou Tao
2025-02-13 16:19 ` [RESEND PATCH bpf-next v2 2/4] bpf, libbpf: Support " Leon Hwang
2025-02-13 16:19 ` [RESEND PATCH bpf-next v2 3/4] bpf, bpftool: Generate skeleton for " Leon Hwang
2025-02-14 9:49 ` Leon Hwang
2025-02-13 16:19 ` [RESEND PATCH bpf-next v2 4/4] selftests/bpf: Add cases to test " Leon Hwang
2025-02-19 1:54 ` Alexei Starovoitov
2025-02-24 5:40 ` Leon Hwang [this message]
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=fd1b3f58-c27f-403d-ad99-644b7d06ecb3@linux.dev \
--to=leon.hwang@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=eddyz87@gmail.com \
--cc=kernel-patches-bot@fb.com \
--cc=qmo@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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.