From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796096991; b=oYkI5WSWUgpPF7sE3bmSZE/GJt1YKUqjScSgnOj/ZZDFaXdW4IMfTIygk6moG2Ii57JY JelITgPEApsYcMeLLRjer49ss5sAecqej3krM/UtO/ZUU8gT+QIACiMjTuOqlgkC4NcIc orr3Mw/oiKn5SPGhFVNCf+nA9J3uVKviRe3MZa3lmy2BMjAphYDb/YC0P5bTdaltWaOwN qO3HGb0nKtul8KWh5BMICnsmCROIHPognKeiAuc8Pv2S3ENeTi0cRgsDVLLerCOUckOv5 1McEsq9+Pqt27oxXDPmFSm62oUb+LvlKHBhp1bK/41SlB3I2zC/3Gb1it0xK3cmWKOg== 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=B5STTNWCMvOnrfj3LF2l4vQvsbCBCL+SevvwLjjxwB+6mofmCF37B8hBhcA99hni46hb O5f69ae0j9BLRJKmAk5O7SjhvSMkDEJphJ3A10uSoWYZnjDOo4ivM6WbogqL17DaSOC6P 5s80RliEP8qV035EC7pNG9huGJEGhw03FNHxChxALUf0k5ICHJVbqa/P2NJujzUvOZ8IY nMwFB21afhkmq8iP4d5EupLpqqiBXPWexA4/8v3SC1nNQjveJ4DbhEfvz2+HNU/hMuVxQ 2Sdv1NrEnGjqyNNvFfMtmvyo8muCvYQYonebXy4NGxBNPDTcmTw+N5NJqSWf8ByGljg== 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.171 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 882E8606A32D for ; Tue, 1 Dec 2026 03:49:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 882E8606A32D 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-f171.google.com with SMTP id 41be03b00d2f7-cdadf7e248aso5055864a12.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=mESC1fGN4KHldMQym/7jUruPLRweprIGovJbRCPaWQywtpDTY+yIN8m69mEhC4p9rf GgUXpumDNxYkA0onj1Htj5dO6eVAogrgRMl8Rr92fB/OLQfekr4xJQKg51ofhV2WXhHY fWMT2y8U6eNcHdmx5cZslg6AckEfewyXrcfoK1vcSDhDKciEWY7wrmZbHijvAsKcSH8w Ua21Cuq3jQhRkFl3BcjS64biIi8P+rZpGCrHBMqxs/bbXK7foOPPmsok4R4kQSt95rAF gnZk9sOm63gnB0sNsi661CerJ0wZn1RSxmIA9ZcpFb4coHuEQR0Zwl+oLR/HWctBbgiO kVOw== X-Forwarded-Encrypted: i=1; AL+hErFF1yZC9EvI0gV2gLhDthyafLXCFPTske2Uk9jYCcWfC5+Ce1SwQRoenfcD3mOmhHoFbiPk0UhmdzLxpcVPXOcII08=@vger.kernel.org X-Gm-Message-State: APuU4Z+tg+xeLzmY+nbwgkqK2fIavG8EELlMdwVNypyo1gEBGL36WE0j Qxaqun2ryJuqFNCvKI3BB5AIRejVeH5azrzHF+BHvv1pWg9BnlVOGwwX X-Gm-Gg: AZFdTZd3P8hb1QWIJKIAzImK89O6uOHdyZZsaRKNfXMvLrhyVMyQQrvwPzdAOTYXTWX qrHW8mrZ5wJENQ98i+bGDok2ewKhG5TwEfN9EfM47i0QlaeWv7YTSWWbmTIBIgROpQJl87KFhA8 kW995zvHDAy7FjlCfQVir+X6GeLM9c12XLlFr6Y8p1X1Nt7+oHw4qG/qcXKB0s+lwvPJCC1vS3a ADmYlqao23i46ZKDazizErIXxdP9bqpB8XgRRv8tyvybz+zOC5S0Y82r7ITaXQHu3XrDuTPHyq2 7NihIc6W66RK3Gvs2TazGhlFI9x792MTcx2thD7sbIK8Ko1XgcYGun+zSPucj4m9SgK6GUoYKsj 1/nI2aGwIno40DvOCf48R0uTNTMdLUqTvESsWWQaUFwggtXLGz6J/J75UUVndgYsBdPwi4jkE8O 3PA6IS6k6B287TufvY8AZxLr0NVSsOWwTL2aVMwGALwc5YU8rLiHT1dPcz/ofiZhPfxuGuLyxOS 8vXwn+JxwTMh8q77SYR+KfgPba0aqLjWuAF6Dq5Lhu3+g8/wQIsfHnOYqdWljUyoRhcX8LHU/5d rJAhFWoqKw6J4qckCNim+h6t9V4YFXb/pHmAgihvk2ItLF5qWb7ohc5kqlQ/Ix8rU1zwWw7fiC8 z9imANq7130iQZqI0sgvNfGF7HEPrgvL7og== 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-trace-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);