Skip to content

Commit 615e705

Browse files
Merge tag 'riscv-fixes-6.15-rc3' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/alexghiti/linux into fixes
riscv fixes for 6.15-rc3 - A couple of fixes regarding module relocations - Fix a build error by implementing missing alternative macros - Another fix for kexec by fixing /proc/iomem * tag 'riscv-fixes-6.15-rc3' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/alexghiti/linux: 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
2 parents dc3e30b + 1413708 commit 615e705

File tree

5 files changed

+71
-34
lines changed

5 files changed

+71
-34
lines changed

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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
860860
}
861861

862862
j++;
863-
if (j > sechdrs[relsec].sh_size / sizeof(*rel))
863+
if (j == num_relocations)
864864
j = 0;
865865

866866
} 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)