linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leon Hwang <hffilwlqm@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Eduard Zingerman <eddyz87@gmail.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Menglong Dong <menglong.dong@linux.dev>,
	Menglong Dong <menglong8.dong@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>, bpf <bpf@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-trace-kernel <linux-trace-kernel@vger.kernel.org>,
	jiang.biao@linux.dev
Subject: Re: bpf_errno. Was: [PATCH RFC bpf-next 1/3] bpf: report probe fault to BPF stderr
Date: Thu, 9 Oct 2025 23:15:40 +0800	[thread overview]
Message-ID: <6485d7de-2af6-48d6-b427-66d3697ec2b2@gmail.com> (raw)
In-Reply-To: <5766a834-3b21-47b0-8793-2673c25ab6b0@gmail.com>


>>
>> Since we're piling on ideas, one of the other things that I think
>> could be useful in general (and maybe should be done orthogonally to
>> bpf_errno)
>> is making some empty nop function and making it not traceable reliably
>> across arches and invoke it in the bpf exception handler.
> 
> No new traceable function is needed, since ex_handler_bpf itself can
> already be traced via fentry.
> 
> If users really want to detect whether a fault occurred, they could
> attach a program to ex_handler_bpf and record fault events into a map.
> However, this approach would be too heavyweight just to check for a
> simple fault condition.
> 

As ex_handler_bpf can already be traced using fentry, a potential
approach without modifying the kernel would be:

1. In the fentry program:

int is_fault SEC(".percpu.fault");

SEC("fentry/ex_handler_bpf")
int BPF_PROG(f__ex, const struct exception_table_entry *x, struct
pt_regs *regs)
{
    is_fault = 1;
    return 0;
}

2. In the main program:

int is_fault SEC(".percpu.fault");

is_fault = 0;
/* probe read */
if (is_fault)
    /* handle fault */;

The main idea is that both programs share the same ".percpu.fault" map,
so the variable 'is_fault' can be accessed from both sides.

Here, ".percpu.fault" represents a percpu_array map section, which is
expected to be supported in the future.
In the meantime, it can simply be replaced with a regular percpu_array map.

Finally, this approach is conceptually similar to the idea of using a
global errno.

Thanks,
Leon


  reply	other threads:[~2025-10-09 15:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-27  6:12 [PATCH RFC bpf-next 0/3] bpf: report probe fault to BPF stderr Menglong Dong
2025-09-27  6:12 ` [PATCH RFC bpf-next 1/3] " Menglong Dong
2025-10-02  2:03   ` Alexei Starovoitov
2025-10-07  6:14     ` Menglong Dong
2025-10-08 14:40       ` Leon Hwang
2025-10-08 16:27         ` bpf_errno. Was: " Alexei Starovoitov
2025-10-08 17:08           ` Kumar Kartikeya Dwivedi
2025-10-08 19:34             ` Eduard Zingerman
2025-10-08 20:08               ` Kumar Kartikeya Dwivedi
2025-10-08 20:30                 ` Eduard Zingerman
2025-10-08 20:59                   ` Kumar Kartikeya Dwivedi
2025-10-09 14:29                 ` Leon Hwang
2025-10-09 15:15                   ` Leon Hwang [this message]
2025-10-10 12:05                 ` Menglong Dong
2025-10-10 15:10                   ` Menglong Dong
2025-10-10 18:55                   ` Eduard Zingerman
2025-10-11  1:23                     ` Menglong Dong
2025-10-09 14:15           ` Leon Hwang
2025-10-09 14:45             ` Alexei Starovoitov
2025-10-10 14:22               ` Leon Hwang
2025-09-27  6:12 ` [PATCH RFC bpf-next 2/3] x86,bpf: use bpf_prog_report_probe_violation for x86 Menglong Dong
2025-09-27  6:12 ` [PATCH RFC bpf-next 3/3] selftests/bpf: add testcase for probe read fault Menglong Dong

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=6485d7de-2af6-48d6-b427-66d3697ec2b2@gmail.com \
    --to=hffilwlqm@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=jiang.biao@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=menglong.dong@linux.dev \
    --cc=menglong8.dong@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).