Re: [PATCH bpf-next v2 1/2] bpf: Introduce bpf_in_interrupt kfunc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 1, 2025 at 8:12 AM Leon Hwang <leon.hwang@xxxxxxxxx> wrote:
>
>
> I do a PoC of adding bpf_in_interrupt() to bpf_experimental.h.

lgtm

> It works:
>
> extern bool CONFIG_PREEMPT_RT __kconfig __weak;
> #ifdef bpf_target_x86

what is bpf_target_x86 ?

> extern const int __preempt_count __ksym;
> #endif
>
> struct task_struct__preempt_rt {
>         int softirq_disable_cnt;
> } __attribute__((preserve_access_index));
>
> /* Description
>  *      Report whether it is in interrupt context. Only works on x86.

arm64 shouldn't be hard to support either.

>  */
> static inline int bpf_in_interrupt(void)
> {
> #ifdef bpf_target_x86
>         int pcnt;
>
>         pcnt = *(int *) bpf_this_cpu_ptr(&__preempt_count);
>         if (!CONFIG_PREEMPT_RT) {
>                 return pcnt & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_MASK);
>         } else {
>                 struct task_struct__preempt_rt *tsk;
>
>                 tsk = (void *) bpf_get_current_task_btf();
>                 return (pcnt & (NMI_MASK | HARDIRQ_MASK)) |
>                        (tsk->softirq_disable_cnt | SOFTIRQ_MASK);
>         }
> #else
>         return 0;
> #endif
> }
>
> However, I only test it for !PREEMPT_RT on x86.
>
> I'd like to respin the patchset by moving bpf_in_interrupt() to
> bpf_experimental.h.

I think the approach should work for PREEMPT_RT too.
Test it and send it.
imo this is better than a new kfunc.
Users can start using it right away without waiting for a new kernel.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux