patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: "Clément Léger" <cleger@rivosinc.com>,
	"Charlie Jenkins" <charlie@rivosinc.com>,
	"Andrew Jones" <ajones@ventanamicro.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Sasha Levin" <sashal@kernel.org>,
	paul.walmsley@sifive.com, aou@eecs.berkeley.edu,
	conor.dooley@microchip.com, alexghiti@rivosinc.com,
	jesse@rivosinc.com, samuel.holland@sifive.com,
	nylon.chen@sifive.com, evan@rivosinc.com,
	linux-riscv@lists.infradead.org
Subject: [PATCH AUTOSEL 6.14 03/11] riscv: misaligned: declare misaligned_access_speed under CONFIG_RISCV_MISALIGNED
Date: Mon,  9 Jun 2025 18:52:37 -0400	[thread overview]
Message-ID: <20250609225246.1443679-3-sashal@kernel.org> (raw)
In-Reply-To: <20250609225246.1443679-1-sashal@kernel.org>

From: Clément Léger <cleger@rivosinc.com>

[ Upstream commit 1317045a7d6f397904d105f6d40dc9787876a34b ]

While misaligned_access_speed was defined in a file compile with
CONFIG_RISCV_MISALIGNED, its definition was under
CONFIG_RISCV_SCALAR_MISALIGNED. This resulted in compilation problems
when using it in a file compiled with CONFIG_RISCV_MISALIGNED.

Move the declaration under CONFIG_RISCV_MISALIGNED so that it can be
used unconditionnally when compiled with that config and remove the check
for that variable in traps_misaligned.c.

Signed-off-by: Clément Léger <cleger@rivosinc.com>
Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
Tested-by: Charlie Jenkins <charlie@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20250523101932.1594077-9-cleger@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

**YES**

This commit should be backported to stable kernel trees.

## Analysis

This commit fixes a **compilation configuration dependency issue** in
the RISC-V architecture's misaligned access handling code. Here's my
detailed analysis:

### The Problem Fixed
The commit addresses a compilation issue where:

1. **Variable Declaration Mismatch**: The `misaligned_access_speed` per-
   CPU variable was defined in `unaligned_access_speed.c` under
   `CONFIG_RISCV_MISALIGNED`, but its declaration in `cpufeature.h` was
   under `CONFIG_RISCV_SCALAR_MISALIGNED`.

2. **Configuration Hierarchy**: From the Kconfig analysis:
   - `CONFIG_RISCV_MISALIGNED` is a broader umbrella config
   - `CONFIG_RISCV_SCALAR_MISALIGNED` selects `CONFIG_RISCV_MISALIGNED`
   - Both `traps_misaligned.c` and `unaligned_access_speed.c` are
     compiled under `CONFIG_RISCV_MISALIGNED`

3. **Compilation Failure**: When `CONFIG_RISCV_MISALIGNED` is enabled
   but `CONFIG_RISCV_SCALAR_MISALIGNED` is not, code in
   `traps_misaligned.c` tries to use `misaligned_access_speed` (line
   372: `*this_cpu_ptr(&misaligned_access_speed) =
   RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED;`) but the variable isn't
   declared in the header.

### The Fix
The commit makes two key changes:

1. **In `cpufeature.h`**: Moves the `DECLARE_PER_CPU(long,
   misaligned_access_speed);` declaration from
   `CONFIG_RISCV_SCALAR_MISALIGNED` to `CONFIG_RISCV_MISALIGNED` (lines
   82-84 in the new version)

2. **In `traps_misaligned.c`**: Removes the conditional `#ifdef
   CONFIG_RISCV_PROBE_UNALIGNED_ACCESS` guard around the assignment to
   `misaligned_access_speed` (line 372), making it unconditional when
   compiled under `CONFIG_RISCV_MISALIGNED`

### Why This Should Be Backported

1. **Fixes Compilation Errors**: This is a clear build fix for valid
   kernel configurations, preventing compilation failures that would
   break the kernel build.

2. **Small and Contained**: The changes are minimal - just moving a
   declaration to the correct config section and removing an unnecessary
   guard.

3. **No Functional Changes**: This doesn't change runtime behavior, only
   fixes the build system configuration dependencies.

4. **Low Risk**: The fix aligns the declaration with where the variable
   is actually used, making the code more consistent and correct.

5. **Matches Stable Criteria**: Similar to **Similar Commit #4** which
   was marked as backport candidate (YES), this fixes compilation issues
   in configuration management without introducing new features or
   architectural changes.

6. **Critical Subsystem**: Unaligned access handling is important for
   RISC-V platforms, and build failures in this area prevent kernel
   compilation for affected configurations.

This is exactly the type of build fix that stable trees should include -
it resolves compilation errors without changing functionality or
introducing regression risks.

 arch/riscv/include/asm/cpufeature.h  | 5 ++++-
 arch/riscv/kernel/traps_misaligned.c | 2 --
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h
index f56b409361fbe..7201da46694f7 100644
--- a/arch/riscv/include/asm/cpufeature.h
+++ b/arch/riscv/include/asm/cpufeature.h
@@ -71,7 +71,6 @@ bool __init check_unaligned_access_emulated_all_cpus(void);
 void check_unaligned_access_emulated(struct work_struct *work __always_unused);
 void unaligned_emulation_finish(void);
 bool unaligned_ctl_available(void);
-DECLARE_PER_CPU(long, misaligned_access_speed);
 #else
 static inline bool unaligned_ctl_available(void)
 {
@@ -79,6 +78,10 @@ static inline bool unaligned_ctl_available(void)
 }
 #endif
 
+#if defined(CONFIG_RISCV_MISALIGNED)
+DECLARE_PER_CPU(long, misaligned_access_speed);
+#endif
+
 bool __init check_vector_unaligned_access_emulated_all_cpus(void);
 #if defined(CONFIG_RISCV_VECTOR_MISALIGNED)
 void check_vector_unaligned_access_emulated(struct work_struct *work __always_unused);
diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c
index dde5d11dc1b50..1295fb9d74abf 100644
--- a/arch/riscv/kernel/traps_misaligned.c
+++ b/arch/riscv/kernel/traps_misaligned.c
@@ -368,9 +368,7 @@ static int handle_scalar_misaligned_load(struct pt_regs *regs)
 
 	perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, addr);
 
-#ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS
 	*this_cpu_ptr(&misaligned_access_speed) = RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED;
-#endif
 
 	if (!unaligned_enabled)
 		return -1;
-- 
2.39.5


  parent reply	other threads:[~2025-06-09 22:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09 22:52 [PATCH AUTOSEL 6.14 01/11] riscv: add a data fence for CMODX in the kernel mode Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 02/11] s390/mm: Fix in_atomic() handling in do_secure_storage_access() Sasha Levin
2025-06-09 22:52 ` Sasha Levin [this message]
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 04/11] ALSA: hda: Ignore unsol events for cards being shut down Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 05/11] ALSA: hda: Add new pci id for AMD GPU display HD audio controller Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 06/11] ALSA: usb-audio: Add a quirk for Lenovo Thinkpad Thunderbolt 3 dock Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 07/11] ASoC: rt1320: fix speaker noise when volume bar is 100% Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 08/11] ceph: fix possible integer overflow in ceph_zero_objects() Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 09/11] scsi: ufs: core: Don't perform UFS clkscaling during host async scan Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 10/11] riscv: save the SR_SUM status over switches Sasha Levin
2025-06-09 22:52 ` [PATCH AUTOSEL 6.14 11/11] ovl: Check for NULL d_inode() in ovl_dentry_upper() Sasha Levin

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=20250609225246.1443679-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ajones@ventanamicro.com \
    --cc=alexghiti@rivosinc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=charlie@rivosinc.com \
    --cc=cleger@rivosinc.com \
    --cc=conor.dooley@microchip.com \
    --cc=evan@rivosinc.com \
    --cc=jesse@rivosinc.com \
    --cc=linux-riscv@lists.infradead.org \
    --cc=nylon.chen@sifive.com \
    --cc=palmer@dabbelt.com \
    --cc=patches@lists.linux.dev \
    --cc=paul.walmsley@sifive.com \
    --cc=samuel.holland@sifive.com \
    --cc=stable@vger.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;
as well as URLs for NNTP newsgroup(s).