Skip to content

Commit 5b179fe

Browse files
committed
Merge tag 'riscv-for-linus-6.11-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - reintroduce the text patching global icache flush - fix syscall entry code to correctly initialize a0, which manifested as a strace bug - XIP kernels now map the entire kernel, which fixes boot under at least DEBUG_VIRTUAL=y - initialize all nodes in the acpi_early_node_map initializer - fix OOB access in the Andes vendor extension probing code - A new key for scalar misaligned access performance in hwprobe, which correctly treat the values as an enum (as opposed to a bitmap) * tag 'riscv-for-linus-6.11-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Fix out-of-bounds when accessing Andes per hart vendor extension array RISC-V: hwprobe: Add SCALAR to misaligned perf defines RISC-V: hwprobe: Add MISALIGNED_PERF key RISC-V: ACPI: NUMA: initialize all values of acpi_early_node_map to NUMA_NO_NODE riscv: change XIP's kernel_map.size to be size of the entire kernel riscv: entry: always initialize regs->a0 to -ENOSYS riscv: Re-introduce global icache flush in patch_text_XXX()
2 parents 4a621e2 + 32d5f7a commit 5b179fe

File tree

11 files changed

+54
-35
lines changed

11 files changed

+54
-35
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,33 @@ 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.
244245

245-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_UNKNOWN`: The performance of misaligned
246-
accesses is unknown.
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.
247249

248-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_EMULATED`: Misaligned accesses are
249-
emulated via software, either in or below the kernel. These accesses are
250-
always extremely slow.
250+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN`: The performance of
251+
misaligned scalar accesses is unknown.
251252

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.
253+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED`: Misaligned scalar
254+
accesses are emulated via software, either in or below the kernel. These
255+
accesses are always extremely slow.
255256

256-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_FAST`: Misaligned accesses are faster
257-
than equivalent byte accesses.
257+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW`: Misaligned scalar native
258+
word sized accesses are slower than the equivalent quantity of byte
259+
accesses. Misaligned accesses may be supported directly in hardware, or
260+
trapped and emulated by software.
258261

259-
* :c:macro:`RISCV_HWPROBE_MISALIGNED_UNSUPPORTED`: Misaligned accesses are
260-
not supported at all and will generate a misaligned address fault.
262+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_FAST`: Misaligned scalar native
263+
word sized accesses are faster than the equivalent quantity of byte
264+
accesses.
265+
266+
* :c:macro:`RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED`: Misaligned scalar
267+
accesses are not supported at all and will generate a misaligned address
268+
fault.
261269

262270
* :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which
263271
represents the size of the Zicboz block in bytes.

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ 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
86+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN 0
87+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED 1
88+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW 2
89+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_FAST 3
90+
#define RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED 4
8591
/* Increase RISCV_HWPROBE_MAX_KEY when adding items. */
8692

8793
/* Flags */

arch/riscv/kernel/acpi_numa.c

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

2929
#include <asm/numa.h>
3030

31-
static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
31+
static int acpi_early_node_map[NR_CPUS] __initdata = { [0 ... NR_CPUS - 1] = NUMA_NO_NODE };
3232

3333
int __init acpi_numa_get_nid(unsigned int cpu)
3434
{

arch/riscv/kernel/patch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ int patch_text_set_nosync(void *addr, u8 c, size_t len)
205205
int ret;
206206

207207
ret = patch_insn_set(addr, c, len);
208+
if (!ret)
209+
flush_icache_range((uintptr_t)addr, (uintptr_t)addr + len);
208210

209211
return ret;
210212
}
@@ -239,6 +241,8 @@ int patch_text_nosync(void *addr, const void *insns, size_t len)
239241
int ret;
240242

241243
ret = patch_insn_write(addr, insns, len);
244+
if (!ret)
245+
flush_icache_range((uintptr_t)addr, (uintptr_t)addr + len);
242246

243247
return ret;
244248
}

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,26 @@ static u64 hwprobe_misaligned(const struct cpumask *cpus)
178178
perf = this_perf;
179179

180180
if (perf != this_perf) {
181-
perf = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
181+
perf = RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN;
182182
break;
183183
}
184184
}
185185

186186
if (perf == -1ULL)
187-
return RISCV_HWPROBE_MISALIGNED_UNKNOWN;
187+
return RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN;
188188

189189
return perf;
190190
}
191191
#else
192192
static u64 hwprobe_misaligned(const struct cpumask *cpus)
193193
{
194194
if (IS_ENABLED(CONFIG_RISCV_EFFICIENT_UNALIGNED_ACCESS))
195-
return RISCV_HWPROBE_MISALIGNED_FAST;
195+
return RISCV_HWPROBE_MISALIGNED_SCALAR_FAST;
196196

197197
if (IS_ENABLED(CONFIG_RISCV_EMULATED_UNALIGNED_ACCESS) && unaligned_ctl_available())
198-
return RISCV_HWPROBE_MISALIGNED_EMULATED;
198+
return RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED;
199199

200-
return RISCV_HWPROBE_MISALIGNED_SLOW;
200+
return RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW;
201201
}
202202
#endif
203203

@@ -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

arch/riscv/kernel/traps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ void do_trap_ecall_u(struct pt_regs *regs)
319319

320320
regs->epc += 4;
321321
regs->orig_a0 = regs->a0;
322+
regs->a0 = -ENOSYS;
322323

323324
riscv_v_vstate_discard(regs);
324325

@@ -328,8 +329,7 @@ void do_trap_ecall_u(struct pt_regs *regs)
328329

329330
if (syscall >= 0 && syscall < NR_syscalls)
330331
syscall_handler(regs, syscall);
331-
else if (syscall != -1)
332-
regs->a0 = -ENOSYS;
332+
333333
/*
334334
* Ultimately, this value will get limited by KSTACK_OFFSET_MAX(),
335335
* so the maximum stack offset is 1k bytes (10 bits).

arch/riscv/kernel/traps_misaligned.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ int handle_misaligned_load(struct pt_regs *regs)
338338
perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS, 1, regs, addr);
339339

340340
#ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS
341-
*this_cpu_ptr(&misaligned_access_speed) = RISCV_HWPROBE_MISALIGNED_EMULATED;
341+
*this_cpu_ptr(&misaligned_access_speed) = RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED;
342342
#endif
343343

344344
if (!unaligned_enabled)
@@ -532,13 +532,13 @@ static bool check_unaligned_access_emulated(int cpu)
532532
unsigned long tmp_var, tmp_val;
533533
bool misaligned_emu_detected;
534534

535-
*mas_ptr = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
535+
*mas_ptr = RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN;
536536

537537
__asm__ __volatile__ (
538538
" "REG_L" %[tmp], 1(%[ptr])\n"
539539
: [tmp] "=r" (tmp_val) : [ptr] "r" (&tmp_var) : "memory");
540540

541-
misaligned_emu_detected = (*mas_ptr == RISCV_HWPROBE_MISALIGNED_EMULATED);
541+
misaligned_emu_detected = (*mas_ptr == RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED);
542542
/*
543543
* If unaligned_ctl is already set, this means that we detected that all
544544
* CPUS uses emulated misaligned access at boot time. If that changed

arch/riscv/kernel/unaligned_access_speed.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static int check_unaligned_access(void *param)
3434
struct page *page = param;
3535
void *dst;
3636
void *src;
37-
long speed = RISCV_HWPROBE_MISALIGNED_SLOW;
37+
long speed = RISCV_HWPROBE_MISALIGNED_SCALAR_SLOW;
3838

39-
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_UNKNOWN)
39+
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN)
4040
return 0;
4141

4242
/* Make an unaligned destination buffer. */
@@ -95,22 +95,22 @@ static int check_unaligned_access(void *param)
9595
}
9696

9797
if (word_cycles < byte_cycles)
98-
speed = RISCV_HWPROBE_MISALIGNED_FAST;
98+
speed = RISCV_HWPROBE_MISALIGNED_SCALAR_FAST;
9999

100100
ratio = div_u64((byte_cycles * 100), word_cycles);
101101
pr_info("cpu%d: Ratio of byte access time to unaligned word access is %d.%02d, unaligned accesses are %s\n",
102102
cpu,
103103
ratio / 100,
104104
ratio % 100,
105-
(speed == RISCV_HWPROBE_MISALIGNED_FAST) ? "fast" : "slow");
105+
(speed == RISCV_HWPROBE_MISALIGNED_SCALAR_FAST) ? "fast" : "slow");
106106

107107
per_cpu(misaligned_access_speed, cpu) = speed;
108108

109109
/*
110110
* Set the value of fast_misaligned_access of a CPU. These operations
111111
* are atomic to avoid race conditions.
112112
*/
113-
if (speed == RISCV_HWPROBE_MISALIGNED_FAST)
113+
if (speed == RISCV_HWPROBE_MISALIGNED_SCALAR_FAST)
114114
cpumask_set_cpu(cpu, &fast_misaligned_access);
115115
else
116116
cpumask_clear_cpu(cpu, &fast_misaligned_access);
@@ -188,7 +188,7 @@ static int riscv_online_cpu(unsigned int cpu)
188188
static struct page *buf;
189189

190190
/* We are already set since the last check */
191-
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_UNKNOWN)
191+
if (per_cpu(misaligned_access_speed, cpu) != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN)
192192
goto exit;
193193

194194
buf = alloc_pages(GFP_KERNEL, MISALIGNED_BUFFER_ORDER);

arch/riscv/kernel/vendor_extensions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig
3838
#ifdef CONFIG_RISCV_ISA_VENDOR_EXT_ANDES
3939
case ANDES_VENDOR_ID:
4040
bmap = &riscv_isa_vendor_ext_list_andes.all_harts_isa_bitmap;
41-
cpu_bmap = &riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap[cpu];
41+
cpu_bmap = riscv_isa_vendor_ext_list_andes.per_hart_isa_bitmap;
4242
break;
4343
#endif
4444
default:

0 commit comments

Comments
 (0)