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 4/6] bpf, arm64: Defer JIT instruction sync
Date: Sun, 06 Dec 2026 10:14:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-252342@kernel.org> (raw)
In-Reply-To: <190c80959b4e35c8eadaa06dd0ed199c9500ebb4.1796545068.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] bpf, arm64: bpf_arch_text_synchronize() omits local CPU ISB
  after migration
--

commit 8b2bf7fd475c1e8e55dccee21aa58f89891e3c3e
Author: Xu Kuohai <xukuohai@huawei.com>

bpf, arm64: Defer JIT instruction sync

This commit implements bpf_arch_text_copy_nosync() and
bpf_arch_text_synchronize() on arm64 to support deferred JIT instruction
synchronization, and switches the JIT error path to the nosync copy.

> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 3ac287580d224..76d25947ace65 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c

[ ... ]

> @@ -3288,6 +3288,18 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
>  	return dst;
>  }
>  
> +void *bpf_arch_text_copy_nosync(void *dst, void *src, size_t len)
> +{
> +	if (!aarch64_insn_copy_nosync(dst, src, len))
> +		return ERR_PTR(-EINVAL);
> +	return dst;
> +}
> +
> +void bpf_arch_text_synchronize(void)
> +{
> +	kick_all_cpus_sync();
> +}

[Severity: High]
Can bpf_arch_text_synchronize() return without executing an isb() on the
calling CPU if the task migrated after bpf_arch_text_copy_nosync()?

bpf_arch_text_copy_nosync() runs caches_clean_inval_pou(), which only
executes isb() on the CPU performing the copy.  Because synchronization is
deferred across preemptible work, the task can migrate before calling
bpf_arch_text_synchronize():

CPU0                                CPU1
bpf_arch_text_copy_nosync()
  caches_clean_inval_pou() (isb)
  ... (task migrates to CPU1) ...
                                    __switch_to() (dsb, no isb)
                                    bpf_arch_text_synchronize()
                                      kick_all_cpus_sync() (skips CPU1)
                                    dummy_ops_call_op()  <-- stale prefetch

On arm64, __switch_to() emits dsb(ish) without guaranteeing an isb() (as
documented in emit_pte_barriers()).  kick_all_cpus_sync() executes
smp_mb() (dmb(ish)) and smp_call_function(), which clears this_cpu from
the target mask and skips SCF_RUN_LOCAL.

Sending the remote IPI does not guarantee an isb() on CPU1 either, for
example on GICv2 or when no remote IPI needs to be dispatched.

A caller such as bpf_struct_ops_test_run() can then immediately execute
newly patched code on CPU1 with stale prefetched instructions from a
reused bpf_prog_pack slot, hitting AARCH64_BREAK_FAULT (kernel oops) or
stale code from a freed program.

Executing isb() on the local CPU in the same non-migratable region as
kick_all_cpus_sync() (e.g. under preempt_disable(), or via on_each_cpu()
with an isb() callback) would close both migration windows.

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

  reply	other threads:[~2026-12-06 10:14 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 [this message]
2026-12-06  9:23 ` [PATCH bpf-next 5/6] bpf, arm64: Defer trampoline creation " Xu Kuohai
2026-12-06 10:12   ` sashiko-bot
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-252342@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