Skip to content

Commit f8c6263

Browse files
committed
Merge tag 'riscv-for-linus-6.13-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - a handful of selftest fixes - fix a memory leak in relocation processing during module loading - avoid sleeping in die() - fix kprobe instruction slot address calculations - fix DT node reference leak in SBI idle probing - avoid initializing out of bounds pages on sparse vmemmap systems with a gap at the start of their physical memory map - fix backtracing through exceptions - _Q_PENDING_LOOPS is now defined whenever QUEUED_SPINLOCKS=y - local labels in entry.S are now marked with ".L", which prevents them from trashing backtraces - a handful of fixes for SBI-based performance counters * tag 'riscv-for-linus-6.13-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: drivers/perf: riscv: Do not allow invalid raw event config drivers/perf: riscv: Return error for default case drivers/perf: riscv: Fix Platform firmware event data tools: selftests: riscv: Add test count for vstate_prctl tools: selftests: riscv: Add pass message for v_initval_nolibc riscv: use local label names instead of global ones in assembly riscv: qspinlock: Fixup _Q_PENDING_LOOPS definition riscv: stacktrace: fix backtracing through exceptions riscv: mm: Fix the out of bound issue of vmemmap address cpuidle: riscv-sbi: fix device node release in early exit of for_each_possible_cpu riscv: kprobes: Fix incorrect address calculation riscv: Fix sleeping in invalid context in die() riscv: module: remove relocation_head rel_entry member allocation riscv: selftests: Fix warnings pointer masking test
2 parents 7110f24 + 6f6ecce commit f8c6263

File tree

15 files changed

+87
-50
lines changed

15 files changed

+87
-50
lines changed

arch/riscv/include/asm/page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct kernel_mapping {
122122

123123
extern struct kernel_mapping kernel_map;
124124
extern phys_addr_t phys_ram_base;
125+
extern unsigned long vmemmap_start_pfn;
125126

126127
#define is_kernel_mapping(x) \
127128
((x) >= kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_map.size))

arch/riscv/include/asm/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
* Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
8888
* is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
8989
*/
90-
#define vmemmap ((struct page *)VMEMMAP_START - (phys_ram_base >> PAGE_SHIFT))
90+
#define vmemmap ((struct page *)VMEMMAP_START - vmemmap_start_pfn)
9191

9292
#define PCI_IO_SIZE SZ_16M
9393
#define PCI_IO_END VMEMMAP_START

arch/riscv/include/asm/sbi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct riscv_pmu_snapshot_data {
159159
};
160160

161161
#define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0)
162+
#define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0)
162163
#define RISCV_PMU_RAW_EVENT_IDX 0x20000
163164
#define RISCV_PLAT_FW_EVENT 0xFFFF
164165

arch/riscv/include/asm/spinlock.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
#ifndef __ASM_RISCV_SPINLOCK_H
44
#define __ASM_RISCV_SPINLOCK_H
55

6-
#ifdef CONFIG_RISCV_COMBO_SPINLOCKS
6+
#ifdef CONFIG_QUEUED_SPINLOCKS
77
#define _Q_PENDING_LOOPS (1 << 9)
8+
#endif
9+
10+
#ifdef CONFIG_RISCV_COMBO_SPINLOCKS
811

912
#define __no_arch_spinlock_redefine
1013
#include <asm/ticket_spinlock.h>

arch/riscv/kernel/entry.S

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
REG_S a0, TASK_TI_A0(tp)
2424
csrr a0, CSR_CAUSE
2525
/* Exclude IRQs */
26-
blt a0, zero, _new_vmalloc_restore_context_a0
26+
blt a0, zero, .Lnew_vmalloc_restore_context_a0
2727

2828
REG_S a1, TASK_TI_A1(tp)
2929
/* Only check new_vmalloc if we are in page/protection fault */
3030
li a1, EXC_LOAD_PAGE_FAULT
31-
beq a0, a1, _new_vmalloc_kernel_address
31+
beq a0, a1, .Lnew_vmalloc_kernel_address
3232
li a1, EXC_STORE_PAGE_FAULT
33-
beq a0, a1, _new_vmalloc_kernel_address
33+
beq a0, a1, .Lnew_vmalloc_kernel_address
3434
li a1, EXC_INST_PAGE_FAULT
35-
bne a0, a1, _new_vmalloc_restore_context_a1
35+
bne a0, a1, .Lnew_vmalloc_restore_context_a1
3636

37-
_new_vmalloc_kernel_address:
37+
.Lnew_vmalloc_kernel_address:
3838
/* Is it a kernel address? */
3939
csrr a0, CSR_TVAL
40-
bge a0, zero, _new_vmalloc_restore_context_a1
40+
bge a0, zero, .Lnew_vmalloc_restore_context_a1
4141

4242
/* Check if a new vmalloc mapping appeared that could explain the trap */
4343
REG_S a2, TASK_TI_A2(tp)
@@ -69,7 +69,7 @@ _new_vmalloc_kernel_address:
6969
/* Check the value of new_vmalloc for this cpu */
7070
REG_L a2, 0(a0)
7171
and a2, a2, a1
72-
beq a2, zero, _new_vmalloc_restore_context
72+
beq a2, zero, .Lnew_vmalloc_restore_context
7373

7474
/* Atomically reset the current cpu bit in new_vmalloc */
7575
amoxor.d a0, a1, (a0)
@@ -83,11 +83,11 @@ _new_vmalloc_kernel_address:
8383
csrw CSR_SCRATCH, x0
8484
sret
8585

86-
_new_vmalloc_restore_context:
86+
.Lnew_vmalloc_restore_context:
8787
REG_L a2, TASK_TI_A2(tp)
88-
_new_vmalloc_restore_context_a1:
88+
.Lnew_vmalloc_restore_context_a1:
8989
REG_L a1, TASK_TI_A1(tp)
90-
_new_vmalloc_restore_context_a0:
90+
.Lnew_vmalloc_restore_context_a0:
9191
REG_L a0, TASK_TI_A0(tp)
9292
.endm
9393

@@ -278,6 +278,7 @@ SYM_CODE_START_NOALIGN(ret_from_exception)
278278
#else
279279
sret
280280
#endif
281+
SYM_INNER_LABEL(ret_from_exception_end, SYM_L_GLOBAL)
281282
SYM_CODE_END(ret_from_exception)
282283
ASM_NOKPROBE(ret_from_exception)
283284

arch/riscv/kernel/module.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct used_bucket {
2323

2424
struct relocation_head {
2525
struct hlist_node node;
26-
struct list_head *rel_entry;
26+
struct list_head rel_entry;
2727
void *location;
2828
};
2929

@@ -634,7 +634,7 @@ process_accumulated_relocations(struct module *me,
634634
location = rel_head_iter->location;
635635
list_for_each_entry_safe(rel_entry_iter,
636636
rel_entry_iter_tmp,
637-
rel_head_iter->rel_entry,
637+
&rel_head_iter->rel_entry,
638638
head) {
639639
curr_type = rel_entry_iter->type;
640640
reloc_handlers[curr_type].reloc_handler(
@@ -704,16 +704,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
704704
return -ENOMEM;
705705
}
706706

707-
rel_head->rel_entry =
708-
kmalloc(sizeof(struct list_head), GFP_KERNEL);
709-
710-
if (!rel_head->rel_entry) {
711-
kfree(entry);
712-
kfree(rel_head);
713-
return -ENOMEM;
714-
}
715-
716-
INIT_LIST_HEAD(rel_head->rel_entry);
707+
INIT_LIST_HEAD(&rel_head->rel_entry);
717708
rel_head->location = location;
718709
INIT_HLIST_NODE(&rel_head->node);
719710
if (!current_head->first) {
@@ -722,7 +713,6 @@ static int add_relocation_to_accumulate(struct module *me, int type,
722713

723714
if (!bucket) {
724715
kfree(entry);
725-
kfree(rel_head->rel_entry);
726716
kfree(rel_head);
727717
return -ENOMEM;
728718
}
@@ -735,7 +725,7 @@ static int add_relocation_to_accumulate(struct module *me, int type,
735725
}
736726

737727
/* Add relocation to head of discovered rel_head */
738-
list_add_tail(&entry->head, rel_head->rel_entry);
728+
list_add_tail(&entry->head, &rel_head->rel_entry);
739729

740730
return 0;
741731
}

arch/riscv/kernel/probes/kprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
3030
p->ainsn.api.restore = (unsigned long)p->addr + len;
3131

3232
patch_text_nosync(p->ainsn.api.insn, &p->opcode, len);
33-
patch_text_nosync(p->ainsn.api.insn + len, &insn, GET_INSN_LENGTH(insn));
33+
patch_text_nosync((void *)p->ainsn.api.insn + len, &insn, GET_INSN_LENGTH(insn));
3434
}
3535

3636
static void __kprobes arch_prepare_simulate(struct kprobe *p)

arch/riscv/kernel/stacktrace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifdef CONFIG_FRAME_POINTER
1818

1919
extern asmlinkage void handle_exception(void);
20+
extern unsigned long ret_from_exception_end;
2021

2122
static inline int fp_is_valid(unsigned long fp, unsigned long sp)
2223
{
@@ -71,7 +72,8 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
7172
fp = frame->fp;
7273
pc = ftrace_graph_ret_addr(current, &graph_idx, frame->ra,
7374
&frame->ra);
74-
if (pc == (unsigned long)handle_exception) {
75+
if (pc >= (unsigned long)handle_exception &&
76+
pc < (unsigned long)&ret_from_exception_end) {
7577
if (unlikely(!__kernel_text_address(pc) || !fn(arg, pc)))
7678
break;
7779

arch/riscv/kernel/traps.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
int show_unhandled_signals = 1;
3737

38-
static DEFINE_SPINLOCK(die_lock);
38+
static DEFINE_RAW_SPINLOCK(die_lock);
3939

4040
static int copy_code(struct pt_regs *regs, u16 *val, const u16 *insns)
4141
{
@@ -81,7 +81,7 @@ void die(struct pt_regs *regs, const char *str)
8181

8282
oops_enter();
8383

84-
spin_lock_irqsave(&die_lock, flags);
84+
raw_spin_lock_irqsave(&die_lock, flags);
8585
console_verbose();
8686
bust_spinlocks(1);
8787

@@ -100,7 +100,7 @@ void die(struct pt_regs *regs, const char *str)
100100

101101
bust_spinlocks(0);
102102
add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
103-
spin_unlock_irqrestore(&die_lock, flags);
103+
raw_spin_unlock_irqrestore(&die_lock, flags);
104104
oops_exit();
105105

106106
if (in_interrupt())

arch/riscv/mm/init.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/pgtable.h>
3434
#include <asm/sections.h>
3535
#include <asm/soc.h>
36+
#include <asm/sparsemem.h>
3637
#include <asm/tlbflush.h>
3738

3839
#include "../kernel/head.h"
@@ -62,6 +63,13 @@ EXPORT_SYMBOL(pgtable_l5_enabled);
6263
phys_addr_t phys_ram_base __ro_after_init;
6364
EXPORT_SYMBOL(phys_ram_base);
6465

66+
#ifdef CONFIG_SPARSEMEM_VMEMMAP
67+
#define VMEMMAP_ADDR_ALIGN (1ULL << SECTION_SIZE_BITS)
68+
69+
unsigned long vmemmap_start_pfn __ro_after_init;
70+
EXPORT_SYMBOL(vmemmap_start_pfn);
71+
#endif
72+
6573
unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
6674
__page_aligned_bss;
6775
EXPORT_SYMBOL(empty_zero_page);
@@ -240,8 +248,12 @@ static void __init setup_bootmem(void)
240248
* Make sure we align the start of the memory on a PMD boundary so that
241249
* at worst, we map the linear mapping with PMD mappings.
242250
*/
243-
if (!IS_ENABLED(CONFIG_XIP_KERNEL))
251+
if (!IS_ENABLED(CONFIG_XIP_KERNEL)) {
244252
phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
253+
#ifdef CONFIG_SPARSEMEM_VMEMMAP
254+
vmemmap_start_pfn = round_down(phys_ram_base, VMEMMAP_ADDR_ALIGN) >> PAGE_SHIFT;
255+
#endif
256+
}
245257

246258
/*
247259
* In 64-bit, any use of __va/__pa before this point is wrong as we
@@ -1101,6 +1113,9 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
11011113
kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom);
11021114

11031115
phys_ram_base = CONFIG_PHYS_RAM_BASE;
1116+
#ifdef CONFIG_SPARSEMEM_VMEMMAP
1117+
vmemmap_start_pfn = round_down(phys_ram_base, VMEMMAP_ADDR_ALIGN) >> PAGE_SHIFT;
1118+
#endif
11041119
kernel_map.phys_addr = (uintptr_t)CONFIG_PHYS_RAM_BASE;
11051120
kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_start);
11061121

0 commit comments

Comments
 (0)