Skip to content

Commit c42e2f0

Browse files
evangreenpalmer-dabbelt
authored andcommitted
RISC-V: hwprobe: Add MISALIGNED_PERF key
RISCV_HWPROBE_KEY_CPUPERF_0 was mistakenly flagged as a bitmask in hwprobe_key_is_bitmask(), when in reality it was an enum value. This causes problems when used in conjunction with RISCV_HWPROBE_WHICH_CPUS, since SLOW, FAST, and EMULATED have values whose bits overlap with each other. If the caller asked for the set of CPUs that was SLOW or EMULATED, the returned set would also include CPUs that were FAST. Introduce a new hwprobe key, RISCV_HWPROBE_KEY_MISALIGNED_PERF, which returns the same values in response to a direct query (with no flags), but is properly handled as an enumerated value. As a result, SLOW, FAST, and EMULATED are all correctly treated as distinct values under the new key when queried with the WHICH_CPUS flag. Leave the old key in place to avoid disturbing applications which may have already come to rely on the key, with or without its broken behavior with respect to the WHICH_CPUS flag. Fixes: e178bf1 ("RISC-V: hwprobe: Introduce which-cpus flag") Signed-off-by: Evan Green <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 8400291 commit c42e2f0

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,13 @@ The following keys are defined:
239239
ratified in commit 98918c844281 ("Merge pull request #1217 from
240240
riscv/zawrs") of riscv-isa-manual.
241241

242-
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance
243-
information about the selected set of processors.
242+
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
243+
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
244+
mistakenly classified as a bitmask rather than a value.
245+
246+
* :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`: An enum value describing
247+
the performance of misaligned scalar native word accesses on the selected set
248+
of processors.
244249

245250
* :c:macro:`RISCV_HWPROBE_MISALIGNED_UNKNOWN`: The performance of misaligned
246251
accesses is unknown.
@@ -249,12 +254,13 @@ The following keys are defined:
249254
emulated via software, either in or below the kernel. These accesses are
250255
always extremely slow.
251256

252-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SLOW`: Misaligned accesses are slower
253-
than equivalent byte accesses. Misaligned accesses may be supported
254-
directly in hardware, or trapped and emulated by software.
257+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SLOW`: Misaligned native word
258+
sized accesses are slower than the equivalent quantity of byte accesses.
259+
Misaligned accesses may be supported directly in hardware, or trapped and
260+
emulated by software.
255261

256-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_FAST`: Misaligned accesses are faster
257-
than equivalent byte accesses.
262+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_FAST`: Misaligned native word
263+
sized accesses are faster than the equivalent quantity of byte accesses.
258264

259265
* :c:macro:`RISCV_HWPROBE_MISALIGNED_UNSUPPORTED`: Misaligned accesses are
260266
not supported at all and will generate a misaligned address fault.

arch/riscv/include/asm/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <uapi/asm/hwprobe.h>
1010

11-
#define RISCV_HWPROBE_MAX_KEY 8
11+
#define RISCV_HWPROBE_MAX_KEY 9
1212

1313
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1414
{

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct riscv_hwprobe {
8282
#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6
8383
#define RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS 7
8484
#define RISCV_HWPROBE_KEY_TIME_CSR_FREQ 8
85+
#define RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF 9
8586
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
8687

8788
/* Flags */

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair,
225225
break;
226226

227227
case RISCV_HWPROBE_KEY_CPUPERF_0:
228+
case RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF:
228229
pair->value = hwprobe_misaligned(cpus);
229230
break;
230231

0 commit comments

Comments
 (0)