From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53125C79FB6 for ; Sat, 12 Sep 2026 05:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=b7gamaM3ocBB+4O2hg6ustnV02tbiSJQKUzLHib6YK0=; b=hJl+khIH1HiHLw1b2oeLPDnYPs MIzSaAjwWu3xL/q8Ghv+aI3iIb81OHNv/FfZIUnkeO1qKclLX1fBTP5eM0sL1YBzX0G3RVSm1AFHl Npi/cUedOkWrd+QPZPAiMgYtINsK4KtuldSbnMOafTQtm7uADYrP6orKMxHDGxUa2wSZCOvrm1334 ErPorCczqrPfzEYgHF9dAe9BFz3YCj4M/CYVTq9FpKCfmSZij99wH/UdnRNuFlC+ENxu+WG3LQg5Y OzvAzErUrdNDHn7eWC2C/ZrHqnxNuo1ZLn50accjV7p4xJXngQ2mIdQKJvOzFwnzl/JdFrQFSrsAv daFomo5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5G0j-00000000Y1e-0PRv; Sat, 12 Sep 2026 05:10:45 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x5G0g-00000000Y1W-48VI for linux-arm-kernel@lists.infradead.org; Sat, 12 Sep 2026 05:10:43 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id A83AA600D4; Sat, 12 Sep 2026 05:10:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F2201F000FF; Sat, 12 Sep 2026 05:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789189841; bh=b7gamaM3ocBB+4O2hg6ustnV02tbiSJQKUzLHib6YK0=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To; b=OEZphzm3wMMRqTwmUnagcM+KkWkkTEvAT3wcp93TZCJkN2dazyFetMFqVZVuf+zV7 drMfqy3/azCvyRO4GZwYRU62gKX9R/h4JnLkota4GImeWvztGmQ6gwzOEl9t+pkiVf BDyS7frnNnG5/bK6UOHkPheXHOc+Ms5TmGLMpESOjUDdK4nK60SgDxKyQ8zj52lyzc wcMR2QrQ2oOSEEYg/HXgIsIeY8gxve2Ade2bJEbOR4QQA4BcQ9oOAbXJ23ExBEaMJr fjuNwfEtxx9Jn4UMZiVSKI/wMEB0jAsmzu3W4RnVLmA/qTJBuYAwblXEdcX6uU/UsY 1IvqTxEnYzpUg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C2B99CE1580; Fri, 11 Sep 2026 22:10:40 -0700 (PDT) Date: Fri, 11 Sep 2026 22:10:40 -0700 From: "Paul E. McKenney" To: Alexei Starovoitov Cc: Josef Bacik , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Boqun Feng , Thomas Gleixner , Peter Zijlstra , Steven Rostedt , Masami Hiramatsu , Mark Rutland , Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , x86@kernel.org, Catalin Marinas , Will Deacon , Puranjay Mohan , Xu Kuohai , Andy Lutomirski , Josh Triplett , Uladzislau Rezki , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Juergen Gross , Luis Chamberlain , Ihor Solodrai , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH RFC v2 08/15] bpf, x86: Maintain Tasks RCU trampoline nesting in the BPF trampoline Message-ID: <14cb8a91-497d-49f5-aa20-c6cb8b9a27fc@paulmck-laptop> References: <20260911-b4-rcu-tasks-preempt-qs-v2-0-eaaa61ed2da4@toxicpanda.com> <20260911-b4-rcu-tasks-preempt-qs-v2-8-eaaa61ed2da4@toxicpanda.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: paulmck@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Sep 11, 2026 at 08:27:56PM -0700, Alexei Starovoitov wrote: > On Fri Sep 11, 2026 at 7:08 AM PDT, Josef Bacik wrote: > > Emit an increment of current->rcu_tramp_nesting once the trampoline's > > frame is set up and a decrement before the final register restore, so > > that a task preempted while running fentry/fexit/fmod_ret/LSM programs > > or the __bpf_tramp_enter()/__bpf_tramp_exit() glue is not treated as > > Tasks-RCU quiescent. Drop the count around the call to the original > > function: that may run arbitrarily long without sleeping and must not pin > > a Tasks RCU grace period, and the trampoline frame above it is held by > > im->pcref rather than by Tasks RCU (see bpf_tramp_image_put()). The > > fmod_ret early-exit branch and the ip_after_call -> ip_epilogue poke both > > skip the decrement/increment pair around the original call, so the count > > stays balanced on every path. > > > > The sequence is "mov r11, gs:[current_task]; inc/dec dword [r11 + off]"; > > r11 is scratch at every emission point and (u32)¤t_task is a valid > > sign-extended %gs-absolute with the current per-CPU layout, the same form > > the JIT already uses for this_cpu_off. The image is dynamically > > allocated text, so the instructions outside the bracketed region are > > covered by the irq-exit IP check. > > > > Assisted-by: LLM > > Signed-off-by: Josef Bacik > > --- > > arch/x86/net/bpf_jit_comp.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 43 insertions(+) > > > > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c > > index 2853e87797a7..a375c1b7bd50 100644 > > --- a/arch/x86/net/bpf_jit_comp.c > > +++ b/arch/x86/net/bpf_jit_comp.c > > @@ -722,6 +722,31 @@ static void emit_indirect_jump(u8 **pprog, int bpf_reg, u8 *ip) > > *pprog = prog; > > } > > > > +/* > > + * Tasks RCU trampoline nesting, see rcu_tasks_trampoline_enter(). > > + * > > + * mov r11, QWORD PTR gs:[current_task] > > + * inc/dec DWORD PTR [r11 + offsetof(struct task_struct, rcu_tramp_nesting)] > > + * > > + * r11 (AUX_REG) is scratch in the trampoline at every point this is emitted. > > + */ > > +static void emit_rcu_tasks_tramp_nesting(u8 **pprog, bool enter) > > +{ > > +#ifdef CONFIG_TASKS_RCU > > + u8 *prog = *pprog; > > + > > + /* mov r11, gs:[abs32] */ > > + EMIT2(0x65, 0x4C); > > + EMIT3(0x8B, 0x1C, 0x25); > > + EMIT((u32)(unsigned long)¤t_task, 4); > > + /* inc/dec dword ptr [r11 + disp32] */ > > + EMIT3(0x41, 0xFF, enter ? 0x83 : 0x8B); > > + EMIT(offsetof(struct task_struct, rcu_tramp_nesting), 4); > > + > > + *pprog = prog; > > +#endif > > It's not a lot of overhead, but I feel it will be the death by thousand cuts. > rcu_read_lock_trace() in bpf_prog_enter_sleepable is doing the same thing... > increamenting a variable inside current. > Can they be combined? Like treat current->trc_reader_nesting > 0 as > current->rcu_tramp_nesting > 0 ? > Or replace one with the other? > Two current->foo++ operations look redundant. > > bpf trampoline is already quite heavy. I'd like to find ways to reduce > its overhead instead of adding more. Replace rcu_read_lock_trace() with Josef's rcu_tasks_trampoline_enter)? But if this means reverting the re-implementation of RCU Tasks Trace in terms of SRCU, I will be rather annoyed with myself. ;-) Thanx, Paul