BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 5/6] bpf, arm64: Defer trampoline creation instruction sync
Date: Sun, 06 Dec 2026 10:12:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-252336@kernel.org> (raw)
In-Reply-To: <5bcb02d50e4690d53db0e108e03d892ac0c2cf89.1796545068.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf, arm64: bpf_arch_text_synchronize() misses local isb() on
  CPU migration
--

commit 3e973e1a645e674c6e02bd2b7e8f11e0c65b2a35
Author: Xu Kuohai <xukuohai@huawei.com>

bpf, arm64: Defer trampoline creation instruction sync

This commit switches arch_prepare_bpf_trampoline() to use
bpf_arch_text_copy_nosync() so instruction synchronization is deferred
to generic code, and returns immediately when prepare_trampoline()
fails.

> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 76d25947ace65..7b5519f1159cc 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -4002,6 +4002,8 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image,
[ ... ]
>  	if (ret > 0)
>  		ret *= AARCH64_INSN_SIZE;
>  
> -	tmp = bpf_arch_text_copy(ro_image, image, size);
> +	tmp = bpf_arch_text_copy_nosync(ro_image, image, size);

[Severity: Medium]
Can task migration between bpf_arch_text_copy_nosync() and
bpf_arch_text_synchronize() leave the destination CPU without a context
synchronization event before it executes the new trampoline?

aarch64_insn_copy_nosync() runs caches_clean_inval_pou(), which emits
isb only on the local CPU.  Because preemption is enabled and callers
sleep before bpf_arch_text_synchronize() (e.g. kvfree() here, or the
allocations in __bpf_struct_ops_map_update_elem()), the task can migrate:

CPU0                              CPU1
                                  (speculatively prefetches recycled
                                   bpf_prog_pack ROX slot)
arch_prepare_bpf_trampoline()
  bpf_arch_text_copy_nosync()
    caches_clean_inval_pou()
      isb (CPU0 only)
  kvfree(image)
  ... (task migrates) ---------->
                                  __switch_to() (dsb, no isb)
                                  bpf_arch_text_synchronize()
                                    kick_all_cpus_sync() (skips CPU1)
                                  dummy_ops_call_op()  <-- stale insns

On arm64, __switch_to() emits dsb(ish) without guaranteeing an isb, and
bpf_arch_text_synchronize() only calls kick_all_cpus_sync().  That calls
smp_call_function(), which skips the calling CPU and does not guarantee
a local isb on the sender (e.g. on GICv2, or when no remote IPI is sent).

If CPU1 then executes the new trampoline (such as dummy_ops_call_op()
right after bpf_arch_text_synchronize() in bpf_struct_ops_test_run()),
it can execute stale prefetched instructions from the recycled
bpf_prog_pack slot, trapping on AARCH64_BREAK_FAULT or running old code.

Disabling preemption around kick_all_cpus_sync() and issuing a local
isb() in bpf_arch_text_synchronize() would ensure the calling CPU is
synchronized as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796545068.git.xukuohai@huawei.com?part=5

  reply	other threads:[~2026-12-06 10:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  9:23 [PATCH bpf-next 0/6] bpf, arm64: Reduce instruction sync IPIs Xu Kuohai
2026-12-06  9:23 ` [PATCH bpf-next 1/6] bpf: Defer instruction sync to the end of load time Xu Kuohai
2026-12-06  9:23 ` [PATCH bpf-next 2/6] bpf: Defer trampoline creation instruction sync Xu Kuohai
2026-12-06  9:23 ` [PATCH bpf-next 3/6] arm64: patching: Add nosync helpers for instruction copy and set Xu Kuohai
2026-12-06 10:12   ` sashiko-bot
2026-12-06  9:23 ` [PATCH bpf-next 4/6] bpf, arm64: Defer JIT instruction sync Xu Kuohai
2026-12-06 10:14   ` sashiko-bot
2026-12-06  9:23 ` [PATCH bpf-next 5/6] bpf, arm64: Defer trampoline creation " Xu Kuohai
2026-12-06 10:12   ` sashiko-bot [this message]
2026-12-06  9:23 ` [PATCH bpf-next 6/6] bpf, arm64: Remove instruction sync when invalidating freed memory Xu Kuohai
2026-12-06 10:19   ` bot+bpf-ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-252336@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xukuohai@huaweicloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox