From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796393865; b=n6+d5LAjDoFnDJWeFrjKI/7vz5y+KkFdUB+kI050wLpj0WQ0umthenAVExwK/YCE/ZU0 C5iYcQr49Qbfgzy1ezkgYpp94jEYctZt+8BA5sPThaBGgQy64suVHqkkku3B6SiR5paDn HcSLVPsGbQEFXmxoWoSRA1wd+OW1GMIT1x02nxbC1YO2VczN5XGKgg4fLNtTvRHgNOxF8 mCqiv7e3dlYQRsOPkVDh30mf9FHDp3H+NXxyHp4mop4z2DHIdkfBSzs/fwpLoFsylS+VR fzGLdvaHwxiJE2tiZA7IkA0BjsGrzAgz7nnVPdxVucD2yQuofZWKjm2XTN8djdAYoQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796393865; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=qx3a9r8Qk8LqqIFXWoAcu3JWobvo2yHO4BlJRjgLc1w=; b=UA6IxlDf1szVYuX4YgTWox9zVYhsYn5NsyFWS+5u6lRd/e+aIrC8+8iNfDMuuY/9KmDN anFMzNSQI76A0tUwKKfDisbTCLWve5rpcG3YTYV4yaeze7AZqAeMoOVQreYIIv4s046j4 1Iq//WgSK0SCEd77x3w96rSzuJxKDqJUbAOUsUxLPJ/gQjo/ibfWOZ/N0XqFGHaNWi/a0 8IhgFULnnAHqvE37gMZgHeFcU+JzskNjNGY4YzN7RFGGjQ8RCvFwKtpUQyhmfZ4jajWCa 19bZZu2Is1/AVcXuol0zHLcDcMxtm4de8yRdVhsQx4V/cGTw4CtpOHYccL+CjvPVX/Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YwFQbf0x; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD861606A330 for ; Fri, 4 Dec 2026 14:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YwFQbf0x Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B5201F00897; Fri, 4 Dec 2026 14:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796393865; bh=qx3a9r8Qk8LqqIFXWoAcu3JWobvo2yHO4BlJRjgLc1w=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=YwFQbf0xaAu52qdxY5BHvkLCGlb1rudhQ00X1/swAV+DLPAXtl6TMszLGLVrvFYa4 OrwNCxvBaIlzS2Ai1m56NiWLkd5LJd3FQ7ZXkAZVNya4lmwYrHK/iAOcinmBmIxf19 FVditE5OXBjvzCYV/U02xqdSMxU0x6wMYwBBzSvsV2gBzeQoy2jMX3NRYA0RNF4gmw D9YSdRT5sBfHaPeUPeiSRs4hz9tWJapoQynn0mkcE7dktOYI5Auv9YzV17tTSWS+Zq 7E9LnyPxBBKZdGHd7KSNSmq0QEVtkQ/U0CeJ4abUR3P+OwblXNOTBomnp5bUp+xV8r ssIEjzFddQrJA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf-next 2/2] x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF Reply-To: sashiko-reviews@lists.linux.dev To: "Viktor Malik" , bpf@vger.kernel.org In-Reply-To: <7ac95882a7218a0494304189d4f500fa589a651d.1796391323.git.vmalik@redhat.com> References: <7ac95882a7218a0494304189d4f500fa589a651d.1796391323.git.vmalik@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:17:45 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] bpf: link failure on CONFIG_BPF_JIT=3Dn from bpf_prog_mark_ran() - [Medium] x86/bugs: bpf_arch_ibpb() skips CPUs that ran bpf_run_async_cb() - [Medium] x86/bugs: bpf_arch_ibpb() skips CPUs that ran BPF trampolines - [Medium] x86/bugs: bpf_arch_ibpb() skips CPUs for reused non-BPF execmem VAs -- commit 781f81166f8975129aeee336798a4632f98a3a71 Author: Viktor Malik x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF This commit changes bpf_arch_ibpb() to use on_each_cpu_cond() with the per-CPU bpf_prog_ran flag so that only CPUs that have executed a BPF program since the last flush receive an IPI and IBPB, clearing the flag before issuing write_ibpb(). > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c > index 4ced10c6ba0db..08eac5cf2c32d 100644 > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -2253,12 +2253,18 @@ static void __init spectre_v2_update_mitigation(v= oid) > #ifdef CONFIG_BPF_JIT > static void __bpf_arch_ibpb(void *unused) > { > + WRITE_ONCE(*raw_cpu_ptr(&bpf_prog_ran), false); > write_ibpb(); > } [Severity: High] Does commit "bpf: Track CPUs that have executed a BPF program" break linking when CONFIG_BPF_JIT=3Dn? kernel/bpf/core.c defines bpf_pred_flush_enabled and bpf_prog_ran inside #ifdef CONFIG_BPF_JIT, while include/linux/filter.h defines bpf_prog_mark_ran() outside that guard and calls it unconditionally from __bpf_prog_run(). Any build with CONFIG_BPF_JIT=3Dn that compiles a caller such as __seccomp_filter() in kernel/seccomp.c fails to link with undefined references to both symbols. Guarding bpf_prog_mark_ran() with #ifdef CONFIG_BPF_JIT and providing an empty stub otherwise would avoid this. > =20 > +static bool bpf_ibpb_needed(int cpu, void *unused) > +{ > + return READ_ONCE(per_cpu(bpf_prog_ran, cpu)); > +} > + > void bpf_arch_ibpb(void) > { > - on_each_cpu(__bpf_arch_ibpb, NULL, 1); > + on_each_cpu_cond(bpf_ibpb_needed, __bpf_arch_ibpb, NULL, 1); > } [Severity: Medium] Can bpf_arch_ibpb() skip a CPU that executed a JITed async BPF callback? Async callbacks (such as bpf_timer_cb() and bpf_wq_work()) are JITed as subprograms into bpf_prog_pack chunks and invoked directly through bpf_run_async_cb() in kernel/bpf/helpers.c, bypassing __bpf_prog_run() and the trampoline exit helpers. Because bpf_run_async_cb() does not call bpf_prog_mark_ran(), bpf_prog_ran remains false on that CPU. When a freed chunk is later reused for an unprivileged cBPF program, bpf_arch_ibpb() skips flushing that CPU and leaves stale branch predictions intact. Calling bpf_prog_mark_ran() after callback_fn() returns in bpf_run_async_cb() would close this gap. [Severity: Medium] Will bpf_arch_ibpb() also skip CPUs that executed a JITed BPF trampoline image? On x86_64, arch_alloc_bpf_trampoline() allocates trampoline images from bpf_prog_pack, while bpf_prog_mark_ran() is only called in the per-program __bpf_prog_exit*() helpers and not in __bpf_tramp_exit(). During __bpf_trampoline_unlink_prog(), bpf_trampoline_skip_prog() patches the skip target past bpf_trampoline_exit(), so a CPU running the trampoline before detach executes JITed trampoline branches (including call *rbx under BPF_TRAMP_F_ORIG_STACK) with bpf_prog_ran left false. A task running a BPF_TRAMP_F_CALL_ORIG trampoline without fexit can also migrate or take a clearing IPI during orig_call before executing the trampoline epilogue. When the trampoline chunk is later reused for cBPF, bpf_arch_ibpb() skips flushing that CPU and leaves stale predictions. [Severity: Medium] Does restricting bpf_arch_ibpb() to CPUs with bpf_prog_ran set miss stale predictions from non-BPF code when a new pack reuses virtual addresses? On x86, execmem_arch_setup() places EXECMEM_BPF in the same virtual address range and shared EXECMEM_ROX_CACHE pool as EXECMEM_MODULE_TEXT, EXECMEM_KPROBES, and EXECMEM_FTRACE, and execmem_free() does not issue an IBPB. When alloc_new_pack() reuses addresses freed by an unloaded module or module .init.text, the first cBPF allocation calls bpf_arch_ibpb() and clears pack->dirty_map. CPUs that executed that unloaded code without running BPF have bpf_prog_ran false and are skipped without being flushed. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796391323.gi= t.vmalik@redhat.com?part=3D2