All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	kernel-patches-bot@fb.com
Subject: Re: [PATCH bpf-next v2 1/2] bpf: Introduce bpf_in_interrupt kfunc
Date: Wed, 3 Sep 2025 13:22:17 +0800	[thread overview]
Message-ID: <e612ad80-2cfc-4531-99dc-958ffe7c407e@linux.dev> (raw)
In-Reply-To: <CAADnVQ+FxdMBKb-sv3Mu04eCpsKwS7pieNSpUUvNRCDxVCr6KA@mail.gmail.com>



On 2/9/25 10:29, Alexei Starovoitov wrote:
> On Mon, Sep 1, 2025 at 8:12 AM Leon Hwang <leon.hwang@linux.dev> 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 ?
> 

bpf_target_x86 is a macro defined in bpf_tracing.h:

#if defined(__TARGET_ARCH_x86)
        #define bpf_target_x86
...
#if defined(__x86_64__)
        #define 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.
> 

No problem.

I'll add support for arm64.

>>  */
>> 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.

Yes, it works for PREEMPT_RT too.

It is able to get retval of bpf_in_interrupt() by running a simple demo.

However, it's really difficult to add selftest case for PREEMPT_RT, as
I'm not familiar with PREEMPT_RT.

Thanks,
Leon

[...]


  reply	other threads:[~2025-09-03  5:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-25 13:14 [PATCH bpf-next v2 0/2] bpf: Introduce bpf_in_interrupt kfunc Leon Hwang
2025-08-25 13:15 ` [PATCH bpf-next v2 1/2] " Leon Hwang
2025-08-25 15:17   ` Alexei Starovoitov
2025-08-26  3:00     ` Leon Hwang
2025-08-26 22:18       ` Alexei Starovoitov
2025-09-01 15:12         ` Leon Hwang
2025-09-02  2:29           ` Alexei Starovoitov
2025-09-03  5:22             ` Leon Hwang [this message]
2025-08-25 13:15 ` [PATCH bpf-next v2 2/2] selftests/bpf: Add case to test " Leon Hwang
2025-08-25 17:26   ` Eduard Zingerman
2025-08-26  3:05     ` Leon Hwang
2025-08-26 22:31       ` Eduard Zingerman

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=e612ad80-2cfc-4531-99dc-958ffe7c407e@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=eddyz87@gmail.com \
    --cc=kernel-patches-bot@fb.com \
    --cc=martin.lau@linux.dev \
    --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.