From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796096991; b=VJN0nRdmHg0RLTtH3Wmx5AgF1rGxAr9xsWtrBmdVDLS9wXDkS9SFfcvMjX25P179rKLo HwcU/l41L/0mBkxTBjNXyCZhmm/Em0yJoNDhTYPnvCws0UxieFNg9PnuE4oKftaO9LsR3 NtgxjTiMhUlSdiF89qGVd/RGaERxxojGLmu2ffcmBkA2QXImx2cSl4B/HDp8AFfMlxH/g bM5G6KtKHRWke+vWGlSkb3i8roVcksJAcG1k3/Su266teiiW96aKuVyQEknqv49j7oD5c ZiZ4ZJSqK3gGSZZC/QUAshRWjdaUaV7n0yFMai4qH1viuQPQ68Zt04V/oEl8CjfmNwQ== 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=0QxVi75W6BA0E0CsmV6DawmRgDkycy1vzs5WeuKC31drh0LV00VTD5S5qzziIzK0VRZT 5HIvX4jD8eRLNgja/PZM4n4aofn4jflAaxZ28ZfueVHy+vaHsZjCfS9we39J31V9Is2ea SYhFctCEauIrKGZt1tH1oIkLMkMwNJ3F/DaIj/h2Da4b1Hg/lGltCicAmpwYbtTUBXj19 GNrd1+CzrxajV+8uZ0HYAMhPfS10UZLJ2bLlVlTbc0nZ3VkQnQznA0SGm5TaH2LSililo /F+fjJmIPXJ08L5aq8PqHoFw0C/swCr6WmtR2J0wI9m+4rE5o0dZwhle+q+Z/CcmRWA== 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.215.172 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 7EC4E606A325 for ; Tue, 1 Dec 2026 03:49:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7EC4E606A325 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-pg1-f172.google.com with SMTP id 41be03b00d2f7-cdadf7e248aso5055863a12.3 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=SbJRr/NHF5LCa3vo7YuSZSiQvIDTCnI9PvESsWinIyQlCIpe7A3IAGI0UZQMjiCPs9 A7M2Wr7s498blh3ueWFOCjdmR1vATbb80eedJNZoPafMJyMay9KVIMXQAUVdJ/AublKg LrQ9uWmtxFZPR4dxLAJxQKMEJN0eZjmf9z1Vt7Zjnwuio/KsoixgfHiDP9kN8WJWLZl9 OfDt+HgxEJ6X4dNv/vmGLu7vaDwMOK1ez5GgzBcipInQjfWCVxeTDDm3mWWq3e0doVSc 4S4shUBbbuM9OU/r0uEfhxKHTIMxNqOexX/TZsIGC2mll8ipxrtbN2YzG0QgZ3ViXMN3 WIag== X-Forwarded-Encrypted: i=1; AL+hErE0ZeRLswtZOq9Sh8ndcRS5oNrSuFqfca/KvOcdtV/KzN/1DTAjBlUQZh7G7lIxFIHIhzc=@vger.kernel.org X-Gm-Message-State: APuU4Z8IWW2XZqQ4aoo/o17+g+Fjuj29IW6TUvAqHvlvOV9280QqbEKh QPVlG2U+t3D13CIUX+AcWSSjH03ZQ0JNd58lZKu8vthk67mbgKQRQraC X-Gm-Gg: AZFdTZeM4v8ahRYqUzT5ezDMTdchWwRFLlPL5/UOlZqhrpjArgYmBOkiDAtzLJ1txNG YdgyzZButE7mkzO2ydDyEAX8vi6CDkyBu1Zp2aS3X3Itk+oH91Wk2RajAvw8WSGbo1cngM0vWK6 hKIlHt2TjRS8DNLBX8rnv3PatNhfyP5QVexCgV1LqtUTydvl6tTcMA8cHdLo9kfoXyOQ6HkW/+w UdnnPwAN5Kv/ANlhHygyF2w7Efl+Il4aJlGDKFw26soTAKfxL66sOXIhDyY9Bn9fWYiBrHZDFyJ sPNOY3zRwEnY8u7ZIbKDoQLDFmpc9wokA3PV13MX/CFr6bg75p1XNnHmEgg2I0ZpU/Oldl9Z2yy g5tlhu41KVOFLiPqqDYzOR+OcZq8yUAHWkftUuY3Azi++BrkfJuyzhw5KMpLpeqA90DUOaKMYqU XToo7suYVJc6qchD405M3mg45/2RSQK5gGCJ2j38VRcQ8hS1co9M9ou5hQ2jPNiVmF2KprnjF09 YX5DKhXepA90G5E1Th/Z5jjr/DvcEzRN2rLDz/nZXbcwfGlAM9ba3qrxtuEwSLPyk2xLdNOMVR6 EVS6rTvoAn6gazYnf0ekTy4Re1p7xhRkWx1p8RGTYcCd4KOfX6pfh1W0SyNLGUbcAHZ/qB52ph+ ISkaKFGM5vHoSkrNinfz98kLYGLr12Lu9zA== 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: bpf@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);