From: Steven Rostedt <rostedt@goodmis.org>
To: Jim Cromie via B4 Relay <devnull+jim.cromie.gmail.com@kernel.org>
Cc: jim.cromie@gmail.com, Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Jason Baron <jbaron@akamai.com>,
Alice Ryhl <aliceryhl@google.com>,
Ard Biesheuvel <ardb@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/7] x86/alternatives: Keep text-poke batch sorted on insert
Date: Mon, 30 Nov 2026 11:13:15 -0500 [thread overview]
Message-ID: <20261130111315.1cbcd11c@gandalf.local.home> (raw)
In-Reply-To: <20261129-jump-batch-261128-v2-1-b1829d2429f0@gmail.com>
On Sun, 29 Nov 2026 00:44:14 -0700
Jim Cromie via B4 Relay <devnull+jim.cromie.gmail.com@kernel.org> wrote:
Please clean up the AI output because AI sucks at writing control flow in a
human readable way. The below is absolute garbage for understanding what is
going on.
> 0. Replace text_poke_addr_ordered() with
> text_poke_find_slot(addr, &pos). Fast-path '!nr || addr > tail' in
> one comparison (*pos = nr), which also catches adjacent addr == tail
> duplicates missed by the old '>' check.
I mean mentioning "(*pos = nr)" after saying "in one comparison" is very
confusing. It makes no sense without reading the code. The change log is to
understand the code, not the other way around. I'm really hating the AI
change logs because I have to read the code to reverse engineer what the
change log is talking about.
> 1. On out-of-order arrivals, binary-search vec[] (<= 8 steps for 256
> entries) using 64-bit text_poke_addr() pointers to match patch_cmp()
> across core and module text. If @addr is already present, return
> false so smp_text_poke_batch_add() finish()es before queueing it.
You really understand what the above is saying?
> 2. In __smp_text_poke_batch_add(), shift vec[pos .. nr_entries - 1] up
> one slot via memmove() when pos < nr_entries; vec[] fits in one 4 KB
> page, moving ~1 KB on average.
When submitting AI created patches, update the wording better. For example
the above should have been:
[ and start with 1. not 0. as this isn't a C array, as well as space them ]
1. Rename text_poke_addr_order() to text_poke_find_slot().
Update the index to the nr_entries immediately and return if either
there are no current entries or the addr is greater than the tail.
This catches adjacent addr == tail duplicates missed by just updating if
the tail is greater than the addr.
2. For out-of-order entries, binary search the vec[] using the
text_poke_addr() pointer. If found, return false so that
smp_text_poke_batch_add() calls finish() before queuing it.
3. In __smp_text_poke_batch_add() use memmove to shift the vec[] array to
add the new entry. This moves ~1 KB on average.
See how much easier it is to read. The above translation between AI slop
output to human readable messages is up to the submitter. Not the
maintainer or reviewer.
>
> What's Unchanged:
>
> 0. Pre-sorted callers -- ftrace_replace_code() and single-key
> jump_label updates -- take the 1-comparison 'addr > tail' fastpath
> with zero binary searches and zero memmove() calls.
> 1. smp_text_poke_batch_finish(), smp_text_poke_int3_handler(), and
> struct smp_text_poke_array are unchanged.
I personally do not think the "unchanged" section is useful. I have no idea
why AI wants to tell us this.
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index efbc11f8c336..d924c3e891b6 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -2955,13 +2955,17 @@ void smp_text_poke_batch_finish(void)
> text_poke_array.nr_entries = 0;
> }
>
> -static void __smp_text_poke_batch_add(void *addr, const void *opcode, size_t len, const void *emulate)
> +static void __smp_text_poke_batch_add(void *addr, const void *opcode,
> + size_t len, const void *emulate, int pos)
> {
> - struct smp_text_poke_loc *tpl;
> + struct smp_text_poke_loc *tpl = &text_poke_array.vec[pos];
Why make the assignment here and not just replace the assignment below but
without the nr_entries update?
> struct insn insn;
> int ret, i = 0;
>
> - tpl = &text_poke_array.vec[text_poke_array.nr_entries++];
> + if (pos < text_poke_array.nr_entries)
> + memmove(tpl + 1, tpl,
> + (text_poke_array.nr_entries - pos) * sizeof(*tpl));
> + text_poke_array.nr_entries++;
>
> if (len == 6)
> i = 1;
> @@ -3032,26 +3036,43 @@ static void __smp_text_poke_batch_add(void *addr, const void *opcode, size_t len
> }
> }
>
> -/*
> - * We hard rely on the text_poke_array.vec being ordered; ensure this is so by flushing
> - * early if needed.
> +/**
> + * text_poke_find_slot() -- find sorted insertion index for @addr in vec[]
> + * @addr: address to patch
> + * @pos: output insertion index in text_poke_array.vec[]
> + *
> + * smp_text_poke_int3_handler() binary-searches text_poke_array.vec[], so
> + * entries must stay strictly sorted with no duplicates. Append at nr_entries
> + * when @addr exceeds the tail entry; otherwise binary-search vec[].
> + *
> + * Return: true with *@pos set if @addr is not yet queued, or false if @addr
> + * is already in vec[] (caller must finish() the current batch first).
> */
> -static bool text_poke_addr_ordered(void *addr)
> +static bool text_poke_find_slot(void *addr, int *pos)
> {
> + int nr = text_poke_array.nr_entries;
> + int lo = 0, hi = nr;
> +
> WARN_ON_ONCE(!addr);
>
> - if (!text_poke_array.nr_entries)
> + if (!nr || addr > text_poke_addr(&text_poke_array.vec[nr - 1])) {
> + *pos = nr;
> return true;
> + }
>
> - /*
> - * If the last current entry's address is higher than the
> - * new entry's address we'd like to add, then ordering
> - * is violated and we must first flush all pending patching
> - * requests:
> - */
> - if (text_poke_addr(text_poke_array.vec + text_poke_array.nr_entries-1) > addr)
> + while (lo < hi) {
> + int mid = (lo + hi) >> 1;
> +
> + if (addr > text_poke_addr(&text_poke_array.vec[mid]))
> + lo = mid + 1;
> + else
> + hi = mid;
> + }
> +
> + if (addr == text_poke_addr(&text_poke_array.vec[lo]))
> return false;
>
> + *pos = lo;
> return true;
> }
>
> @@ -3068,11 +3089,17 @@ static bool text_poke_addr_ordered(void *addr)
> * execution. All pending patching requests will be executed on the next
> * smp_text_poke_batch_finish() call.
> */
> -void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t len, const void *emulate)
> +void __ref smp_text_poke_batch_add(void *addr, const void *opcode,
> + size_t len, const void *emulate)
Please do not add line breaks to code you do not touch. If the maintainer
had it that way, it may be what they prefer.
-- Steve
> {
> - if (text_poke_array.nr_entries == TEXT_POKE_ARRAY_MAX || !text_poke_addr_ordered(addr))
> + int pos = 0;
> +
> + if (text_poke_array.nr_entries == TEXT_POKE_ARRAY_MAX ||
> + !text_poke_find_slot(addr, &pos)) {
> smp_text_poke_batch_finish();
> - __smp_text_poke_batch_add(addr, opcode, len, emulate);
> + pos = 0;
> + }
> + __smp_text_poke_batch_add(addr, opcode, len, emulate, pos);
> }
>
> /**
next prev parent reply other threads:[~2026-11-30 16:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 7:44 [PATCH v2 0/7] jump_label, x86, dyndbg: Batch multi-key static branch updates Jim Cromie via B4 Relay
2026-11-29 7:44 ` [PATCH v2 1/7] x86/alternatives: Keep text-poke batch sorted on insert Jim Cromie via B4 Relay
2026-11-30 16:13 ` Steven Rostedt [this message]
2026-11-29 7:44 ` [PATCH v2 2/7] x86/jump_label: Sync arch_jump_label_transform_queue() with batch limit Jim Cromie via B4 Relay
2026-11-29 7:44 ` [PATCH v2 3/7] jump_label: Plumb bool apply through jump_label_update_key() Jim Cromie via B4 Relay
2026-11-29 7:44 ` [PATCH v2 4/7] jump_label: Add batching API for queued static key updates Jim Cromie via B4 Relay
2026-11-30 11:55 ` Peter Zijlstra
2026-11-30 13:51 ` Peter Zijlstra
2026-11-29 7:44 ` [PATCH v2 5/7] dyndbg: Use queued static-key batching in ddebug_change() Jim Cromie via B4 Relay
2026-11-29 7:44 ` [PATCH v2 6/7] dyndbg: Batch classmap param bit-changes into multi-query Jim Cromie via B4 Relay
2026-11-29 7:44 ` [PATCH v2 7/7] dyndbg: Hoist lock and static_key_batch across queries Jim Cromie via B4 Relay
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=20261130111315.1cbcd11c@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=devnull+jim.cromie.gmail.com@kernel.org \
--cc=hpa@zytor.com \
--cc=jbaron@akamai.com \
--cc=jim.cromie@gmail.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®