[PATCH 0/5] riscv: Cleanup and deduplicate unaligned access speed probe

Michael Neuling mikey at neuling.org
Mon Apr 6 18:38:52 PDT 2026


> This series was applied to riscv/linux.git (for-next)
> by Paul Walmsley <pjw at kernel.org>:

> Here is the summary with links:
>   - [1/5] riscv: Clean up & optimize unaligned scalar access probe
>     https://git.kernel.org/riscv/c/c202d70b2244

I think this is causing a regression (SHA1 actually 6455c6c11827) .
Fast unaligned accesses are no longer being set ever.

Analysis from Claude (Opus 4.6) with Chris Masons kernel patch review skills:
--
  > diff --git a/arch/riscv/kernel/unaligned_access_speed.c
b/arch/riscv/kernel/unaligned_access_speed.c
  > index b36a6a56f4..1f4c128d73 100644
  > --- a/arch/riscv/kernel/unaligned_access_speed.c
  > +++ b/arch/riscv/kernel/unaligned_access_speed.c

  [ ... ]

  > -arch_initcall(check_unaligned_access_all_cpus);
  > +late_initcall(check_unaligned_access_all_cpus);

  With this change, check_unaligned_access_all_cpus() now runs at
  late_initcall (level 7), but lock_and_set_unaligned_access_static_branch()
  remains at arch_initcall_sync (level 3s):

  arch/riscv/kernel/unaligned_access_speed.c:
      static int __init lock_and_set_unaligned_access_static_branch(void)
      {
              cpus_read_lock();
              set_unaligned_access_static_branches();
              cpus_read_unlock();
              return 0;
      }
      arch_initcall_sync(lock_and_set_unaligned_access_static_branch);

  Before this patch, the ordering was:

      arch_initcall:      check_unaligned_access_all_cpus()  -> measures
      arch_initcall_sync: lock_and_set_unaligned_access_static_branch()
                                                           -> sets branch

  After this patch:

      arch_initcall_sync: lock_and_set_unaligned_access_static_branch()
                                                  -> empty cpumask -> off
     late_initcall:      check_unaligned_access_all_cpus()  -> measures
                                                  -> never re-evaluates

  Does this mean fast_unaligned_access_speed_key is never enabled at boot,
  even on hardware with fast unaligned access? The comment in
  set_unaligned_access_static_branches() says "This will be called after
  check_unaligned_access_all_cpus" which is no longer true with this
  ordering change.
--
I confirmed this by booting (qemu) the below patch before and after
this change, and I get this:

Before this change fast_misaligned access is set when setting the
static branches
   [    0.117326] TEST: lock_and_set running, fast_misaligned_access weight: 4/4
After this change fast_misaligned access is unset when setting the
static branches:
  [    0.168865] TEST: lock_and_set running, fast_misaligned_access weight: 0/4

So I think this confirms the regression.

Mikey

--- a/arch/riscv/kernel/unaligned_access_speed.c
+++ b/arch/riscv/kernel/unaligned_access_speed.c
@@ @@
 static int __init lock_and_set_unaligned_access_static_branch(void)
 {
+ pr_info("TEST: lock_and_set running, fast_misaligned_access cpumask
weight: %u/%u\n",
+ cpumask_weight(&fast_misaligned_access), num_online_cpus());
  cpus_read_lock();
  set_unaligned_access_static_branches();
  cpus_read_unlock();



More information about the linux-riscv mailing list