From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 3/6] arm64: patching: Add nosync helpers for instruction copy and set
Date: Sun, 06 Dec 2026 10:12:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-252337@kernel.org> (raw)
In-Reply-To: <bbcaf7df94dcdd01625a78ad3038fbe8fc6bac65.1796545068.git.xukuohai@huawei.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] arm64: missing local ISB on task migration before
kick_all_cpus_sync()
- [Low] arm64: __text_poke() duplicates flush_icache_range() and its
KGDB check
--
commit f0adbfc81bbc8b0254c57fd9e19c900c17d58113
Author: Xu Kuohai <xukuohai@huawei.com>
arm64: patching: Add nosync helpers for instruction copy and set
This commit adds aarch64_insn_copy_nosync() and aarch64_insn_set_nosync()
so callers can defer cross-CPU instruction synchronization instead of
sending an IPI on every poke.
> diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c
> index 09f019c6547a0..5e28476db046c 100644
> --- a/arch/arm64/kernel/patching.c
> +++ b/arch/arm64/kernel/patching.c
[ ... ]
> @@ -126,7 +127,15 @@ static void *__text_poke(text_poke_f func, void *addr, void *src, size_t len)
> }
> raw_spin_unlock_irqrestore(&patch_lock, flags);
>
> - flush_icache_range((uintptr_t)addr, (uintptr_t)addr + len);
> + caches_clean_inval_pou((uintptr_t)addr, (uintptr_t)addr + len);
> + /*
> + * IPI all online CPUs to force them to refetch the new instructions.
> + * KGDB uses IPIs to round-up the secondary CPUs during the patching
> + * operation, so we don't need extra IPIs here. See the comments in
> + * flush_icache_range() in arch/arm64/include/asm/cacheflush.h.
> + */
> + if (sync && !in_dbg_master())
> + kick_all_cpus_sync();
>
> return addr;
> }
[Severity: Low]
Can this call flush_icache_range() when sync is true and
caches_clean_inval_pou() otherwise, instead of duplicating
flush_icache_range() and its in_dbg_master() check here?
arch/arm64/include/asm/cacheflush.h already implements this exact
sequence in flush_icache_range(). Calling it directly keeps the KGDB
workaround in one place and avoids relying on a transitive include of
linux/kgdb.h in patching.c.
[ ... ]
> +/**
> + * aarch64_insn_copy_nosync - Copy instructions into RX memory, no sync
> + * @dst: address to modify
> + * @src: source of the copy
> + * @len: length to copy
> + *
> + * Same as aarch64_insn_copy(), but does not IPI other CPUs to refetch
> + * the new instructions. The caller must do the synchronization before
> + * the text is executed.
> + */
> +noinstr void *aarch64_insn_copy_nosync(void *dst, void *src, size_t len)
> +{
> + return __aarch64_insn_copy(dst, src, len, false);
> +}
[Severity: Medium]
Can a task that migrates between caches_clean_inval_pou() and
kick_all_cpus_sync() execute stale prefetched instructions on the new
CPU?
caches_clean_inval_pou() only executes isb on the local CPU. If the
caller migrates to another CPU via a voluntary switch from a thread
sharing the same mm, switch_mm() is skipped and __switch_to() issues
dsb(ish) without an unconditional isb().
CPU0 CPU1
aarch64_insn_copy_nosync()
caches_clean_inval_pou()
isb (CPU0 only)
... task migrates to CPU1 ...
__switch_to() (same mm, no isb)
kick_all_cpus_sync()
skips this_cpu (CPU1)
execute new text <-- stale prefetch
kick_all_cpus_sync() calls smp_call_function_many_cond(), which excludes
this_cpu, and sending the IPI does not guarantee a local isb() (for
example, GICv2 gic_ipi_send_mask() uses dmb(ishst) and writel_relaxed()).
Executing newly written text on CPU1, such as a reused BPF prog pack slot
that held AARCH64_BREAK_FAULT, can hit stale prefetched instructions and
cause unexpected BRK faults or corrupted execution.
The same preemptible window exists in __text_poke() when sync is true,
and aarch64_insn_set_nosync() shares this contract. Using on_each_cpu()
to run a local isb(), and documenting that callers of the nosync helpers
must also synchronize the local CPU, would cover every online CPU.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796545068.git.xukuohai@huawei.com?part=3
next prev parent 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 [this message]
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
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-252337@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