* Re: [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count() [not found] ` <20260420133532.4973DC2BCB4@smtp.kernel.org> @ 2026-04-21 0:47 ` Tiezhu Yang 2026-05-15 17:45 ` Ihor Solodrai 0 siblings, 1 reply; 3+ messages in thread From: Tiezhu Yang @ 2026-04-21 0:47 UTC (permalink / raw) To: sashiko; +Cc: bpf On 2026/4/20 下午9:35, sashiko-bot@kernel.org wrote: > Sashiko AI review found 1 potential issue(s): > - [High] BPF programs including `bpf_experimental.h` will fail to compile on LoongArch due to a non-existent `thread_info` field in `struct task_struct`. > -- > > commit 82453686fe5eacd9f219e2a050dc016b297cfc79 > Author: Tiezhu Yang <yangtiezhu@loongson.cn> > > selftests/bpf: Add LoongArch support for get_preempt_count() > > This commit adds LoongArch support for get_preempt_count() in the BPF > experimental helpers. It enables bpf_in_interrupt() and related macros to > work properly on LoongArch systems. > >> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h >> index e5c039bc44cb4..5847bbf12d240 100644 >> --- a/tools/testing/selftests/bpf/bpf_experimental.h >> +++ b/tools/testing/selftests/bpf/bpf_experimental.h >> @@ -507,6 +507,8 @@ static inline int get_preempt_count(void) >> return bpf_get_lowcore()->preempt_count; >> #elif defined(bpf_target_riscv) >> return bpf_get_current_task_btf()->thread_info.preempt_count; >> +#elif defined(bpf_target_loongarch) >> + return bpf_get_current_task_btf()->thread_info.preempt_count; > > Will this compile successfully on LoongArch? > > Since LoongArch does not select CONFIG_THREAD_INFO_IN_TASK, struct > thread_info is allocated on the kernel stack rather than being embedded > within struct task_struct. Because of this, the generated BTF and vmlinux.h > for LoongArch will not contain a thread_info field in task_struct. > > Could this lead to a compiler error indicating that there is no member named > thread_info in struct task_struct when building BPF selftests? As mentioned in the cover letter, it needs to apply the kernel patch "LoongArch: Implement CONFIG_THREAD_INFO_IN_TASK" [1] before testing. [1] https://lore.kernel.org/loongarch/20260420102907.4617-1-yangtiezhu@loongson.cn/ Thanks, Tiezhu ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count() 2026-04-21 0:47 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count() Tiezhu Yang @ 2026-05-15 17:45 ` Ihor Solodrai 2026-05-19 3:30 ` Tiezhu Yang 0 siblings, 1 reply; 3+ messages in thread From: Ihor Solodrai @ 2026-05-15 17:45 UTC (permalink / raw) To: Tiezhu Yang, sashiko; +Cc: bpf On 4/20/26 5:47 PM, Tiezhu Yang wrote: > On 2026/4/20 下午9:35, sashiko-bot@kernel.org wrote: >> Sashiko AI review found 1 potential issue(s): >> - [High] BPF programs including `bpf_experimental.h` will fail to compile on LoongArch due to a non-existent `thread_info` field in `struct task_struct`. >> -- >> >> commit 82453686fe5eacd9f219e2a050dc016b297cfc79 >> Author: Tiezhu Yang <yangtiezhu@loongson.cn> >> >> selftests/bpf: Add LoongArch support for get_preempt_count() >> >> This commit adds LoongArch support for get_preempt_count() in the BPF >> experimental helpers. It enables bpf_in_interrupt() and related macros to >> work properly on LoongArch systems. >> >>> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h >>> index e5c039bc44cb4..5847bbf12d240 100644 >>> --- a/tools/testing/selftests/bpf/bpf_experimental.h >>> +++ b/tools/testing/selftests/bpf/bpf_experimental.h >>> @@ -507,6 +507,8 @@ static inline int get_preempt_count(void) >>> return bpf_get_lowcore()->preempt_count; >>> #elif defined(bpf_target_riscv) >>> return bpf_get_current_task_btf()->thread_info.preempt_count; >>> +#elif defined(bpf_target_loongarch) >>> + return bpf_get_current_task_btf()->thread_info.preempt_count; >> >> Will this compile successfully on LoongArch? >> >> Since LoongArch does not select CONFIG_THREAD_INFO_IN_TASK, struct >> thread_info is allocated on the kernel stack rather than being embedded >> within struct task_struct. Because of this, the generated BTF and vmlinux.h >> for LoongArch will not contain a thread_info field in task_struct. >> >> Could this lead to a compiler error indicating that there is no member named >> thread_info in struct task_struct when building BPF selftests? > > As mentioned in the cover letter, it needs to apply the kernel patch > "LoongArch: Implement CONFIG_THREAD_INFO_IN_TASK" [1] before testing. Hi Tiezhu, I think it makes sense to include the selftests changes in the series implementing CONFIG_THREAD_INFO_IN_TASK for loongarch [1]. With respect to riscv part of this, I suggest you drop it unless you have the means to run the tests. Landing without any testing is silly. Also I think you may drop the RFC tag. AFAIU you're trying to bring loongarch to parity with mainstream arch-es, and that shouldn't be controversial. Thanks. [1] https://lore.kernel.org/bpf/20260428072021.7289-1-yangtiezhu@loongson.cn/ > > [1] https://lore.kernel.org/loongarch/20260420102907.4617-1-yangtiezhu@loongson.cn/ > > Thanks, > Tiezhu > ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count() 2026-05-15 17:45 ` Ihor Solodrai @ 2026-05-19 3:30 ` Tiezhu Yang 0 siblings, 0 replies; 3+ messages in thread From: Tiezhu Yang @ 2026-05-19 3:30 UTC (permalink / raw) To: Ihor Solodrai, sashiko; +Cc: bpf On 2026/5/16 上午1:45, Ihor Solodrai wrote: > On 4/20/26 5:47 PM, Tiezhu Yang wrote: ... > Hi Tiezhu, > > I think it makes sense to include the selftests changes in the > series implementing CONFIG_THREAD_INFO_IN_TASK for loongarch [1]. > > With respect to riscv part of this, I suggest you drop it unless you > have the means to run the tests. Landing without any testing is silly. > > Also I think you may drop the RFC tag. AFAIU you're trying to bring > loongarch to parity with mainstream arch-es, and that shouldn't be > controversial. Hi Ihor, Thanks for your reply and suggestions. 1. riscv part: Given that riscv already supports CONFIG_THREAD_INFO_IN_TASK and there is preempt_count member in struct thread_info, it can get the preempt count via bpf_get_current_task_btf()->thread_info.preempt_count. But this is only in theory, I did not test it on riscv TBH and there is no "Tested-by" from the community so far. I will drop it in the next version. 2. loongarch part: Since LoongArch is transitioning to CONFIG_THREAD_INFO_IN_TASK, I have found a proper way to handle this special status. Use bpf_core_field_exists() to provide compatibility for both legacy and future kernels. A struct flavor "task_struct___local" is introduced to bypass static compiler checks when thread_info is missing from the base task_struct. For the newer kernels that select CONFIG_THREAD_INFO_IN_TASK, it reads preempt_count from the thread_info embedded within task_struct. For the older kernels without selecting CONFIG_THREAD_INFO_IN_TASK, it retrieves the thread_info pointer from the bottom of the kernel stack(task->stack) and then reads the preempt_count. This ensures the BPF selftests remain functional across various LoongArch kernel versions. "./test_progs -t exe_ctx" passes on LoongArch regardless of whether CONFIG_THREAD_INFO_IN_TASK is set. I will send new version ASAP. Thanks, Tiezhu ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-19 3:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260420111516.19982-3-yangtiezhu@loongson.cn>
[not found] ` <20260420133532.4973DC2BCB4@smtp.kernel.org>
2026-04-21 0:47 ` [PATCH RFC bpf-next 2/2] selftests/bpf: Add LoongArch support for get_preempt_count() Tiezhu Yang
2026-05-15 17:45 ` Ihor Solodrai
2026-05-19 3:30 ` Tiezhu Yang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox