Linux Trace Kernel
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: <mikeba@sentinelone.com>,
	"Mike Bazov via B4 Relay"
	<devnull+mikeba.sentinelone.com@kernel.org>,
	<bpf@vger.kernel.org>, "Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>
Cc: "Martin KaFai Lau" <martin.lau@linux.dev>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"JP Kobryn" <jp.kobryn@linux.dev>,
	<linux-trace-kernel@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v4 4/6] bpf: Check program recursion per task via bpf_ctx
Date: Tue, 01 Dec 2026 03:53:32 +0000	[thread overview]
Message-ID: <DN93BON4ODR5.15PN6OM09J5H8@gmail.com> (raw)
In-Reply-To: <20261130-bpf-preempt-v2-r2-v4-4-bd28389dfd64@sentinelone.com>

On Mon, Nov 30, 2026 at 03:54 AM Mike Bazov via B4 Relay <devnull+mikeba.sentinelone.com@kernel.org> wrote:
> +static inline struct bpf_run_ctx *bpf_set_run_ctx_prog(struct bpf_run_ctx *new_ctx,
> +						       const struct bpf_prog *prog)

Pls use __always_inline to avoid future headaches.

> +	case BPF_PROG_TYPE_TRACING:
> +	case BPF_PROG_TYPE_STRUCT_OPS:
> +		return bpf_prog_check_recur(prog);

Dead code. bpf_check_attach_target() rejects these targets.
Drop both helpers and check three prog types in
bpf_tracing_prog_attach().

> +	if (prog->type == BPF_PROG_TYPE_EXT && prog->percpu_state &&
> +	    bpf_prog_recur_per_task(tgt_prog)) {
> +		err = -EINVAL;

A sleepable target is preemptible with or without the mark:

  raw_tp.s target  runs          attach of a marked extension
  ---------------  ------------  ----------------------------
  not marked       preemptibly   -EINVAL
  marked           preemptibly   ok

Reject both. Also add bpf_log().

> -	bpf_reset_run_ctx(run_ctx->saved_run_ctx);
> +	bpf_prog_exit_run_ctx(prog, &run_ctx->run_ctx);
> +	bpf_reset_run_ctx(run_ctx->run_ctx.saved_run_ctx);

The order is wrong. Marked progs still lose events.
The deferred preemption fires while the frame is linked.
P is one raw_tp prog on sys_enter and sched_switch:

  bpf_prog_exit_run_ctx(P)
    preempt_enable_notrace()
      __schedule()
        trace_sched_switch()
          bpf_prog_enter_run_ctx(P, old_ctx)
            old_ctx->prog == P   <- dropped, P has exited already

Same for an fentry.multi prog that covers the scheduler.
Unlink the frame first in all runners, like in the diff in v3 thread.
In the trampoline enable preemption after update_prog_stats().
Otherwise off-cpu time goes into run_time_ns.
Nothing reads the run_ctx argument. Drop it.

pw-bot: cr

  parent reply	other threads:[~2026-12-01  3:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:54 [PATCH bpf-next v4 0/6] bpf: Check recursion per task for preemptible programs Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 1/6] bpf: Avoid per-CPU private stack in preemptible tracing progs Mike Bazov via B4 Relay
2026-11-30 12:07   ` sashiko-bot
2026-11-30 11:54 ` [PATCH bpf-next v4 2/6] bpf: Mark programs that keep per-CPU state Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 3/6] bpf: Link the async run context without writing to it Mike Bazov via B4 Relay
2026-12-01  3:49   ` Alexei Starovoitov
2026-11-30 11:54 ` [PATCH bpf-next v4 4/6] bpf: Check program recursion per task via bpf_ctx Mike Bazov via B4 Relay
2026-11-30 12:26   ` sashiko-bot
2026-12-01  3:53   ` Alexei Starovoitov [this message]
2026-11-30 11:54 ` [PATCH bpf-next v4 5/6] bpf: Remove the per-CPU recursion counter of programs Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 6/6] selftests/bpf: Add preemption recursion test for tracing programs Mike Bazov via B4 Relay
2026-12-01  3:54 ` [PATCH bpf-next v4 0/6] bpf: Check recursion per task for preemptible programs Alexei Starovoitov

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=DN93BON4ODR5.15PN6OM09J5H8@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=devnull+mikeba.sentinelone.com@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jp.kobryn@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=memxor@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=mikeba@sentinelone.com \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox