Skip to content

Commit 1d41d2e

Browse files
committed
Merge tag 'riscv-for-linus-5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A fix to avoid undefined behavior when stack backtracing, which manifests in GCC as incorrect stack addresses - A few fixes for the XIP kernels - A fix to tracking NUMA state on CPU hotplug - Support for the recently relesaed binutils-2.38, which changed the default ISA version to one without CSRs or fence.i in 'I' extension * tag 'riscv-for-linus-5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: fix build with binutils 2.38 riscv: cpu-hotplug: clear cpu from numa map when teardown riscv: extable: fix err reg writing in dedicated uaccess handler riscv/mm: Add XIP_FIXUP for riscv_pfn_base riscv/mm: Add XIP_FIXUP for phys_ram_base riscv: Fix XIP_FIXUP_FLASH_OFFSET riscv: eliminate unreliable __builtin_frame_address(1)
2 parents e47ca40 + 6df2a01 commit 1d41d2e

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

arch/riscv/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
5050
riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
5151
riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
5252
riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
53+
54+
# Newer binutils versions default to ISA spec version 20191213 which moves some
55+
# instructions from the I extension to the Zicsr and Zifencei extensions.
56+
toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zicsr_zifencei)
57+
riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
58+
5359
KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
5460
KBUILD_AFLAGS += -march=$(riscv-march-y)
5561

arch/riscv/kernel/cpu-hotplug.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/sched/hotplug.h>
1313
#include <asm/irq.h>
1414
#include <asm/cpu_ops.h>
15+
#include <asm/numa.h>
1516
#include <asm/sbi.h>
1617

1718
bool cpu_has_hotplug(unsigned int cpu)
@@ -40,6 +41,7 @@ int __cpu_disable(void)
4041
return ret;
4142

4243
remove_cpu_topology(cpu);
44+
numa_remove_cpu(cpu);
4345
set_cpu_online(cpu, false);
4446
irq_migrate_all_off_this_cpu();
4547

arch/riscv/kernel/head.S

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
add \reg, \reg, t0
2323
.endm
2424
.macro XIP_FIXUP_FLASH_OFFSET reg
25-
la t1, __data_loc
26-
li t0, XIP_OFFSET_MASK
27-
and t1, t1, t0
28-
li t1, XIP_OFFSET
29-
sub t0, t0, t1
30-
sub \reg, \reg, t0
25+
la t0, __data_loc
26+
REG_L t1, _xip_phys_offset
27+
sub \reg, \reg, t1
28+
add \reg, \reg, t0
3129
.endm
3230
_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
31+
_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET
3332
#else
3433
.macro XIP_FIXUP_OFFSET reg
3534
.endm

arch/riscv/kernel/stacktrace.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
2222
bool (*fn)(void *, unsigned long), void *arg)
2323
{
2424
unsigned long fp, sp, pc;
25+
int level = 0;
2526

2627
if (regs) {
2728
fp = frame_pointer(regs);
2829
sp = user_stack_pointer(regs);
2930
pc = instruction_pointer(regs);
3031
} else if (task == NULL || task == current) {
31-
fp = (unsigned long)__builtin_frame_address(1);
32-
sp = (unsigned long)__builtin_frame_address(0);
33-
pc = (unsigned long)__builtin_return_address(0);
32+
fp = (unsigned long)__builtin_frame_address(0);
33+
sp = sp_in_global;
34+
pc = (unsigned long)walk_stackframe;
3435
} else {
3536
/* task blocked in __switch_to */
3637
fp = task->thread.s[0];
@@ -42,7 +43,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
4243
unsigned long low, high;
4344
struct stackframe *frame;
4445

45-
if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
46+
if (unlikely(!__kernel_text_address(pc) || (level++ >= 1 && !fn(arg, pc))))
4647
break;
4748

4849
/* Validate frame pointer */

arch/riscv/mm/extable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline void regs_set_gpr(struct pt_regs *regs, unsigned int offset,
3333
if (unlikely(offset > MAX_REG_OFFSET))
3434
return;
3535

36-
if (!offset)
36+
if (offset)
3737
*(unsigned long *)((unsigned long)regs + offset) = val;
3838
}
3939

@@ -43,8 +43,8 @@ static bool ex_handler_uaccess_err_zero(const struct exception_table_entry *ex,
4343
int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
4444
int reg_zero = FIELD_GET(EX_DATA_REG_ZERO, ex->data);
4545

46-
regs_set_gpr(regs, reg_err, -EFAULT);
47-
regs_set_gpr(regs, reg_zero, 0);
46+
regs_set_gpr(regs, reg_err * sizeof(unsigned long), -EFAULT);
47+
regs_set_gpr(regs, reg_zero * sizeof(unsigned long), 0);
4848

4949
regs->epc = get_ex_fixup(ex);
5050
return true;

arch/riscv/mm/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAG
232232

233233
#ifdef CONFIG_XIP_KERNEL
234234
#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops))
235+
#define riscv_pfn_base (*(unsigned long *)XIP_FIXUP(&riscv_pfn_base))
235236
#define trampoline_pg_dir ((pgd_t *)XIP_FIXUP(trampoline_pg_dir))
236237
#define fixmap_pte ((pte_t *)XIP_FIXUP(fixmap_pte))
237238
#define early_pg_dir ((pgd_t *)XIP_FIXUP(early_pg_dir))
@@ -522,6 +523,7 @@ static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size)
522523
}
523524

524525
#ifdef CONFIG_XIP_KERNEL
526+
#define phys_ram_base (*(phys_addr_t *)XIP_FIXUP(&phys_ram_base))
525527
extern char _xiprom[], _exiprom[], __data_loc;
526528

527529
/* called from head.S with MMU off */

0 commit comments

Comments
 (0)