From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796096991; b=0tRfbrOjhwrK8qPCfyt8U9k/awRuZff2T6iElnAf5ZJBde2MgRNIEy5iCOGim9xy1mkS ZEwUxXlxxcnH003E0Z81rTQChL/TQ5ZmMQzNFtbeDHnh2WUA5x4VApls3VoI5Qea70gMA Q0rwXhJiyzos9z5b4X+S1PHB1iKjwc5bmqUEY9DEL0DSrBy7hu16nxiRVTCdn42fQYQe2 kPS3adX7afc33iIAoFhMS+OmS9ZKwuicBS0KC/fp+XxFR7sS5esKWJ0+TT6ivu0J/Bz5B S/Aqj4uyk6wBd/1PMCfbugSBbvC0OpsDZ5YS05aY5CU9gIiN5cHgeiykRS2GofNdaOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796096991; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Content-Type:Date:Message-Id:Cc:Subject:From:To:In-Reply-To: References:Content-Transfer-Encoding:MIME-Version; bh=Oe8ui4P/HovZLgk7EUu6zbx8gPW5WY2PL1FaiSn5+lo=; b=CabDmsOSkDgpeH5TaZ/4h8NVj3FoiFLq6Aaipxh6v3h0Wuh21v55fmDK66Ghlggyl3Jy T4nf8QAsgo2VF++onxw9wUNWiwfnU0ESNpJKwHu+ART8HTC+X37LbLvwkzevWNI2LZr47 6uBtBV1YKnpldEJtynPvciclJOXgmG5lV90WQutVY7H6slKBoq40asKj0cLQC2x1nz2kI mARABZLOIn25i6kdibFNqFs9uxvA4eeAt7LvRJxU4fPeatlLicoEqeBCbGmVB2LXGI5ZK tmYVqPp8RLF2g2FCO9XkI7wKTuXvZ/7YTkOY4kkxw1lviZzHyQHrZKqMhaPzOhfUegg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=SzRwjELK; arc=none smtp.remote-ip=209.85.216.43 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CFF6606A320 for ; Tue, 1 Dec 2026 03:49:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7CFF6606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=SzRwjELK Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b4cd193b50so3787767a91.1 for ; Mon, 30 Nov 2026 19:49:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796096991; x=1796701791; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Oe8ui4P/HovZLgk7EUu6zbx8gPW5WY2PL1FaiSn5+lo=; b=SzRwjELKJkhQk0Jdh8kUTKS8qDhh/j9auTgxNCOG5WIUEJQWuWNqcJVCZ/iRcH08RD sJtYH/L4gFZOq3L0QA6S32oaurnU9ICyVkbmNxVBIHzd7BJzz9eeIfJz+wY3X7pLM/q1 /mXjhRGhbLX69qN4AkbWjTBPBLbDjEqQAgMUAAQr8xc+OTWDZaDVL5F2SCy9Og01gKXM eSguDZMU4tAQNIfP+0ndwUkr4RKoVhAXdc8Y8zdybdK83ow6TKm4MuW/TRrtbnEBpmUR tghQX4sisHQm8x0J2I67EjHV7W145uZPjjdGPjMc5JQZxyduXmBtXffuhRAGfKyDtiVb uYpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096991; x=1796701791; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Oe8ui4P/HovZLgk7EUu6zbx8gPW5WY2PL1FaiSn5+lo=; b=TRm4T5VMPWLQVkkAgIvIKI5tDn1VCM9xUpmoYnvPKy7s8+1ib+pdK6mqV0MXSsmV5W lYNJmb1JMYy1O410LCtdkx0JZwwyZaYdf7bY0v6ptTNgrZTeWH6nvBDLbM0NBJQSRJ1K NSbITHo8fsYnd/i/TCNjLOGN8YgXx7zYnVXn4cxoMvgsBht+OLygpFjRWNeapTSArmgU ZytZRCcol30MePp785kdTR7BCXHo0TvaSxh/liI3V8RWQx8BjRbkTA43KiOfNCC913EW a8kPX2Wn10SlJX/hpQIul48xm5hutvRyVL9gVsz9jV/7IUG8Z6+t8z1kxH+C9txT+Q7W RffQ== X-Forwarded-Encrypted: i=1; AL+hErHqS5pQmEKzvQL/OzpGfR0Vc0EjZhON8dFK3o4dMkEP4Vlj5SSaY6RLNix9r5ql5qqThlwKXC/61tREM5g=@vger.kernel.org X-Gm-Message-State: APuU4Z/IoFAInaljse64oX/rgIu2inwBl3wuPF61OPn6Yb3wzWbsEVqZ V3C+EyYh0R4PwZ+P4UqtpEGKRp2tGY6WbzXKrJ3dnjgbRtOBDLPYEOoj X-Gm-Gg: AZFdTZfB269EtBp9LtpK4icxXw9CnbSgDDv50F/JdakiOcMOvycw2ehaPvkqM69Y995 Lm9fYapgA2tDUTKPE8H9OHJjK7vIka4C1MlnPKeExXBXPh7lHlyJwQ2jl/9+w2uS8OzE+UqlHc1 NxUim079CGqMs/xamfWeQu9cNy8mXaqIsdXE5B8aawQ3LxvPmRBWYK7aGqsck1euF+acYq1rq9S qrnl/wngwE5HhPJIJX3UvnBWuDxWszQAL0+/AvCvX8/5aOQO9mOPKJq70/0fuiLsvdt0EpXlZiK ZyquNFBP5TxlhWF6VYOhKI8oPHkc+fw5c55MP5ieSmW1Do2SV5RHRHmBcW+hpfQ8lDch9Fiui+s mFw1nwU1ui9BHNBgP1eEOC7xPQ0zW0ThDsbcvM05oa5LzMhyQwh5smvvH1EOtcIv8TJsxzjVNcA hZcWXc6sGfs57sdNYNDoDPy0bZCqLfD9wwQqd7uKk0z4C38H3cBvj+k5qrCi3Ywk/6Xdp2jO1T3 zHbaMrNIMbA8LOi77xEG97eQanrTmSpNegmbdz5nwaxL8n+1MJw+St9VIvhqG2v2n416Qbn9xC0 CBh0+peAah0t9mJLYMVtAvHfrEozf54e05saWDVQf8lYWVb+f1CZu8V7vcn3TMUTIkOp63h8vNJ aR6IIkTpgLKGeNSwVUXJRNrfMLoKBzlk+yQ== X-Received: by 2002:a17:90b:2f8c:b0:3ac:b867:81df with SMTP id 98e67ed59e1d1-3b41c959e23mr34282836a91.39.1796096990628; Mon, 30 Nov 2026 19:49:50 -0800 (PST) Received: from localhost ([153.61.198.248]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41ad0a34asm55065457a91.3.2026.11.30.19.49.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 19:49:50 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 03:49:49 +0000 Message-Id: Cc: "Martin KaFai Lau" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "John Fastabend" , "Emil Tsalapatis" , "Ihor Solodrai" , "Steven Rostedt" , "Masami Hiramatsu" , "Mathieu Desnoyers" , "JP Kobryn" , , Subject: Re: [PATCH bpf-next v4 3/6] bpf: Link the async run context without writing to it From: "Alexei Starovoitov" To: , , "Daniel Borkmann" , "Andrii Nakryiko" In-Reply-To: <20261130-bpf-preempt-v2-r2-v4-3-bd28389dfd64@sentinelone.com> References: <20261130-bpf-preempt-v2-r2-v4-0-bd28389dfd64@sentinelone.com> <20261130-bpf-preempt-v2-r2-v4-3-bd28389dfd64@sentinelone.com> Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Mon, Nov 30, 2026 at 03:54 AM Mike Bazov via B4 Relay wrote: > Set current->bpf_ctx directly instead, so that the frame is never > written. No functional change. This doens't look right. Consider: task A, cpu 0 X runs, marked, preemption is off irq softirq on irq exit bpf_timer_cb() or bpf_rcu_run_callback() the callback hits the hook of X the chain is X -> bpf_async_run_ctx -> NULL X runs, overwrites the per-cpu data of the first run preempt_disable() doesn't hold softirqs back. A softirq that hits the hook of X without a callback is refused. bpf_in_async_cb() only needs a way to recognize the frame. Put the frame on the stack and link it like the other frames. Then this patch and its trade-off in the cover letter go away. Pls fold it into patch 4. I built it together with patch 4 and didn't run it. The first hunk repeats struct bpf_run_ctx of patch 4, the define is the new part: diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 4f9c2bf..e42705b 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2800,7 +2801,19 @@ int bpf_prog_array_copy(struct bpf_prog_array *old_array, struct bpf_prog_array **new_array); struct bpf_prog *bpf_prog_dummy(void); -struct bpf_run_ctx {}; +/* + * A frame in the chain of the programs that a task is running, from + * current->bpf_ctx to the outermost one. + */ +struct bpf_run_ctx { + /* The next outer frame, NULL in the outermost one */ + struct bpf_run_ctx *saved_run_ctx; + /* The program that runs in the frame, see bpf_prog_enter_run_ctx() */ + const struct bpf_prog *prog; +}; + +/* ->prog of the frame of an async callback, see bpf_in_async_cb() */ +#define BPF_PROG_ASYNC_CB ((const struct bpf_prog *)1) struct bpf_cg_run_ctx { struct bpf_run_ctx run_ctx; @@ -3497,11 +3567,11 @@ static inline bool has_current_bpf_ctx(void) } /* An async callback runs in no hook, and current is not the task that has armed it */ -extern struct bpf_run_ctx bpf_async_run_ctx; - static inline bool bpf_in_async_cb(void) { - return current->bpf_ctx == &bpf_async_run_ctx; + struct bpf_run_ctx *ctx = current->bpf_ctx; + + return ctx && ctx->prog == BPF_PROG_ASYNC_CB; } void notrace bpf_prog_inc_misses_counter(struct bpf_prog *prog); diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 7b3e10a..aea624c 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1235,14 +1235,13 @@ static DEFINE_PER_CPU(struct bpf_hrtimer *, hrtimer_running); static void bpf_async_refcount_put(struct bpf_async_cb *cb); -struct bpf_run_ctx bpf_async_run_ctx; - static void bpf_run_async_cb(struct bpf_prog *prog, bpf_callback_t callback_fn, struct bpf_map *map, void *key, void *value) { - struct bpf_run_ctx *old_ctx = bpf_set_run_ctx(&bpf_async_run_ctx); + struct bpf_run_ctx run_ctx, *old_ctx; struct bpf_timed_may_goto saved; + old_ctx = bpf_set_run_ctx_prog(&run_ctx, BPF_PROG_ASYNC_CB); bpf_timed_may_goto_save(prog, &saved); callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0); bpf_timed_may_goto_restore(prog, &saved);