Skip to content

Commit 4b82886

Browse files
committed
Merge tag 'riscv-for-linus-6.15-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A fix for an issue where C instructions ended up in non-C builds, due to some broken inline assembly in the KGDB breakpoint insertion code - A fix to avoid spurious printk messages about misaligned access performance probing - A fix for a handful of issues with /proc/iomem's reserved region handling - A pair of fixes for module relocation processing - A few build-time fixes * tag 'riscv-for-linus-6.15-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break riscv: KGDB: Do not inline arch_kgdb_breakpoint() riscv: Avoid fortify warning in syscall_get_arguments() riscv: Provide all alternative macros all the time riscv: module: Allocate PLT entries for R_RISCV_PLT32 riscv: module: Fix out-of-bounds relocation access riscv: Properly export reserved regions in /proc/iomem riscv: Fix unaligned access info messages riscv: Avoid fortify warning in syscall_get_arguments() Documentation: riscv: Fix typo MIMPLID -> MIMPID riscv: Use kvmalloc_array on relocation_hashtable
2 parents 7f424c6 + 615e705 commit 4b82886

File tree

9 files changed

+89
-49
lines changed

9 files changed

+89
-49
lines changed

Documentation/arch/riscv/hwprobe.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The following keys are defined:
5151
* :c:macro:`RISCV_HWPROBE_KEY_MARCHID`: Contains the value of ``marchid``, as
5252
defined by the RISC-V privileged architecture specification.
5353

54-
* :c:macro:`RISCV_HWPROBE_KEY_MIMPLID`: Contains the value of ``mimplid``, as
54+
* :c:macro:`RISCV_HWPROBE_KEY_MIMPID`: Contains the value of ``mimpid``, as
5555
defined by the RISC-V privileged architecture specification.
5656

5757
* :c:macro:`RISCV_HWPROBE_KEY_BASE_BEHAVIOR`: A bitmask containing the base

arch/riscv/include/asm/alternative-macros.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,19 @@
115115
\old_c
116116
.endm
117117

118-
#define _ALTERNATIVE_CFG(old_c, ...) \
119-
ALTERNATIVE_CFG old_c
120-
121-
#define _ALTERNATIVE_CFG_2(old_c, ...) \
122-
ALTERNATIVE_CFG old_c
118+
#define __ALTERNATIVE_CFG(old_c, ...) ALTERNATIVE_CFG old_c
119+
#define __ALTERNATIVE_CFG_2(old_c, ...) ALTERNATIVE_CFG old_c
123120

124121
#else /* !__ASSEMBLY__ */
125122

126-
#define __ALTERNATIVE_CFG(old_c) \
127-
old_c "\n"
123+
#define __ALTERNATIVE_CFG(old_c, ...) old_c "\n"
124+
#define __ALTERNATIVE_CFG_2(old_c, ...) old_c "\n"
128125

129-
#define _ALTERNATIVE_CFG(old_c, ...) \
130-
__ALTERNATIVE_CFG(old_c)
126+
#endif /* __ASSEMBLY__ */
131127

132-
#define _ALTERNATIVE_CFG_2(old_c, ...) \
133-
__ALTERNATIVE_CFG(old_c)
128+
#define _ALTERNATIVE_CFG(old_c, ...) __ALTERNATIVE_CFG(old_c)
129+
#define _ALTERNATIVE_CFG_2(old_c, ...) __ALTERNATIVE_CFG_2(old_c)
134130

135-
#endif /* __ASSEMBLY__ */
136131
#endif /* CONFIG_RISCV_ALTERNATIVE */
137132

138133
/*

arch/riscv/include/asm/kgdb.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@
1919

2020
#ifndef __ASSEMBLY__
2121

22+
void arch_kgdb_breakpoint(void);
2223
extern unsigned long kgdb_compiled_break;
2324

24-
static inline void arch_kgdb_breakpoint(void)
25-
{
26-
asm(".global kgdb_compiled_break\n"
27-
".option norvc\n"
28-
"kgdb_compiled_break: ebreak\n"
29-
".option rvc\n");
30-
}
31-
3225
#endif /* !__ASSEMBLY__ */
3326

3427
#define DBG_REG_ZERO "zero"

arch/riscv/include/asm/syscall.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ static inline void syscall_get_arguments(struct task_struct *task,
6262
unsigned long *args)
6363
{
6464
args[0] = regs->orig_a0;
65-
args++;
66-
memcpy(args, &regs->a1, 5 * sizeof(args[0]));
65+
args[1] = regs->a1;
66+
args[2] = regs->a2;
67+
args[3] = regs->a3;
68+
args[4] = regs->a4;
69+
args[5] = regs->a5;
6770
}
6871

6972
static inline int syscall_get_arch(struct task_struct *task)

arch/riscv/kernel/kgdb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
254254
regs->epc = pc;
255255
}
256256

257+
noinline void arch_kgdb_breakpoint(void)
258+
{
259+
asm(".global kgdb_compiled_break\n"
260+
"kgdb_compiled_break: ebreak\n");
261+
}
262+
257263
void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
258264
char *remcom_out_buffer)
259265
{

arch/riscv/kernel/module-sections.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ static bool duplicate_rela(const Elf_Rela *rela, int idx)
7373
static void count_max_entries(Elf_Rela *relas, int num,
7474
unsigned int *plts, unsigned int *gots)
7575
{
76-
unsigned int type, i;
77-
78-
for (i = 0; i < num; i++) {
79-
type = ELF_RISCV_R_TYPE(relas[i].r_info);
80-
if (type == R_RISCV_CALL_PLT) {
76+
for (int i = 0; i < num; i++) {
77+
switch (ELF_R_TYPE(relas[i].r_info)) {
78+
case R_RISCV_CALL_PLT:
79+
case R_RISCV_PLT32:
8180
if (!duplicate_rela(relas, i))
8281
(*plts)++;
83-
} else if (type == R_RISCV_GOT_HI20) {
82+
break;
83+
case R_RISCV_GOT_HI20:
8484
if (!duplicate_rela(relas, i))
8585
(*gots)++;
86+
break;
8687
}
8788
}
8889
}

arch/riscv/kernel/module.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ process_accumulated_relocations(struct module *me,
648648
kfree(bucket_iter);
649649
}
650650

651-
kfree(*relocation_hashtable);
651+
kvfree(*relocation_hashtable);
652652
}
653653

654654
static int add_relocation_to_accumulate(struct module *me, int type,
@@ -752,9 +752,10 @@ initialize_relocation_hashtable(unsigned int num_relocations,
752752

753753
hashtable_size <<= should_double_size;
754754

755-
*relocation_hashtable = kmalloc_array(hashtable_size,
756-
sizeof(**relocation_hashtable),
757-
GFP_KERNEL);
755+
/* Number of relocations may be large, so kvmalloc it */
756+
*relocation_hashtable = kvmalloc_array(hashtable_size,
757+
sizeof(**relocation_hashtable),
758+
GFP_KERNEL);
758759
if (!*relocation_hashtable)
759760
return 0;
760761

@@ -859,7 +860,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
859860
}
860861

861862
j++;
862-
if (j > sechdrs[relsec].sh_size / sizeof(*rel))
863+
if (j == num_relocations)
863864
j = 0;
864865

865866
} while (j_idx != j);

arch/riscv/kernel/setup.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ static struct resource bss_res = { .name = "Kernel bss", };
6666
static struct resource elfcorehdr_res = { .name = "ELF Core hdr", };
6767
#endif
6868

69+
static int num_standard_resources;
70+
static struct resource *standard_resources;
71+
6972
static int __init add_resource(struct resource *parent,
7073
struct resource *res)
7174
{
@@ -139,7 +142,7 @@ static void __init init_resources(void)
139142
struct resource *res = NULL;
140143
struct resource *mem_res = NULL;
141144
size_t mem_res_sz = 0;
142-
int num_resources = 0, res_idx = 0;
145+
int num_resources = 0, res_idx = 0, non_resv_res = 0;
143146
int ret = 0;
144147

145148
/* + 1 as memblock_alloc() might increase memblock.reserved.cnt */
@@ -193,6 +196,7 @@ static void __init init_resources(void)
193196
/* Add /memory regions to the resource tree */
194197
for_each_mem_region(region) {
195198
res = &mem_res[res_idx--];
199+
non_resv_res++;
196200

197201
if (unlikely(memblock_is_nomap(region))) {
198202
res->name = "Reserved";
@@ -210,6 +214,9 @@ static void __init init_resources(void)
210214
goto error;
211215
}
212216

217+
num_standard_resources = non_resv_res;
218+
standard_resources = &mem_res[res_idx + 1];
219+
213220
/* Clean-up any unused pre-allocated resources */
214221
if (res_idx >= 0)
215222
memblock_free(mem_res, (res_idx + 1) * sizeof(*mem_res));
@@ -221,6 +228,33 @@ static void __init init_resources(void)
221228
memblock_free(mem_res, mem_res_sz);
222229
}
223230

231+
static int __init reserve_memblock_reserved_regions(void)
232+
{
233+
u64 i, j;
234+
235+
for (i = 0; i < num_standard_resources; i++) {
236+
struct resource *mem = &standard_resources[i];
237+
phys_addr_t r_start, r_end, mem_size = resource_size(mem);
238+
239+
if (!memblock_is_region_reserved(mem->start, mem_size))
240+
continue;
241+
242+
for_each_reserved_mem_range(j, &r_start, &r_end) {
243+
resource_size_t start, end;
244+
245+
start = max(PFN_PHYS(PFN_DOWN(r_start)), mem->start);
246+
end = min(PFN_PHYS(PFN_UP(r_end)) - 1, mem->end);
247+
248+
if (start > mem->end || end < mem->start)
249+
continue;
250+
251+
reserve_region_with_split(mem, start, end, "Reserved");
252+
}
253+
}
254+
255+
return 0;
256+
}
257+
arch_initcall(reserve_memblock_reserved_regions);
224258

225259
static void __init parse_dtb(void)
226260
{

arch/riscv/kernel/unaligned_access_speed.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -439,29 +439,36 @@ static int __init check_unaligned_access_all_cpus(void)
439439
{
440440
int cpu;
441441

442-
if (unaligned_scalar_speed_param == RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN &&
443-
!check_unaligned_access_emulated_all_cpus()) {
444-
check_unaligned_access_speed_all_cpus();
445-
} else {
446-
pr_info("scalar unaligned access speed set to '%s' by command line\n",
447-
speed_str[unaligned_scalar_speed_param]);
442+
if (unaligned_scalar_speed_param != RISCV_HWPROBE_MISALIGNED_SCALAR_UNKNOWN) {
443+
pr_info("scalar unaligned access speed set to '%s' (%lu) by command line\n",
444+
speed_str[unaligned_scalar_speed_param], unaligned_scalar_speed_param);
448445
for_each_online_cpu(cpu)
449446
per_cpu(misaligned_access_speed, cpu) = unaligned_scalar_speed_param;
447+
} else if (!check_unaligned_access_emulated_all_cpus()) {
448+
check_unaligned_access_speed_all_cpus();
449+
}
450+
451+
if (unaligned_vector_speed_param != RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN) {
452+
if (!has_vector() &&
453+
unaligned_vector_speed_param != RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED) {
454+
pr_warn("vector support is not available, ignoring unaligned_vector_speed=%s\n",
455+
speed_str[unaligned_vector_speed_param]);
456+
} else {
457+
pr_info("vector unaligned access speed set to '%s' (%lu) by command line\n",
458+
speed_str[unaligned_vector_speed_param], unaligned_vector_speed_param);
459+
}
450460
}
451461

452462
if (!has_vector())
453463
unaligned_vector_speed_param = RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED;
454464

455-
if (unaligned_vector_speed_param == RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN &&
456-
!check_vector_unaligned_access_emulated_all_cpus() &&
457-
IS_ENABLED(CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS)) {
458-
kthread_run(vec_check_unaligned_access_speed_all_cpus,
459-
NULL, "vec_check_unaligned_access_speed_all_cpus");
460-
} else {
461-
pr_info("vector unaligned access speed set to '%s' by command line\n",
462-
speed_str[unaligned_vector_speed_param]);
465+
if (unaligned_vector_speed_param != RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN) {
463466
for_each_online_cpu(cpu)
464467
per_cpu(vector_misaligned_access, cpu) = unaligned_vector_speed_param;
468+
} else if (!check_vector_unaligned_access_emulated_all_cpus() &&
469+
IS_ENABLED(CONFIG_RISCV_PROBE_VECTOR_UNALIGNED_ACCESS)) {
470+
kthread_run(vec_check_unaligned_access_speed_all_cpus,
471+
NULL, "vec_check_unaligned_access_speed_all_cpus");
465472
}
466473

467474
/*

0 commit comments

Comments
 (0)