Skip to content

Commit 82a4758

Browse files
committed
Merge tag 'riscv-for-linus-7.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Paul Walmsley: - Call flush_cache_vmap() after populating new vmemmap pages, on all architectures. This avoids spurious faults on RISC-V microarchitectures that cache PTEs marked as non-present - Disable LTO for the vDSO to prevent the compiler from eliding functions that are used, but which don't appear to be - Fix an issue with libgcc's unwinder and signal handlers by dropping an unnecessary CFI landing pad instruction in __vdso_rt_sigreturn (similar to what was done on ARM64) - Avoid reading uninitialized memory under certain conditions in hwprobe_get_cpus() - Save some memory and I$ when CONFIG_DYNAMIC_FTRACE=n by avoiding our four-byte function alignment requirement in that case - Avoid clang warnings about null-pointer arithmetic in the I/O-port accessor macros (inb, outb, etc.) by ifdeffing them out when !CONFIG_HAS_IOPORT - Make the build of the lazy TLB flushing code in the vmalloc path depend on CONFIG_64BIT and CONFIG_MMU (since those platforms are the only ones that use it) * tag 'riscv-for-linus-7.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: hwprobe: Avoid uninitialized read in hwprobe_get_cpus() arch/riscv: vdso: remove CFI landing pad from rt_sigreturn riscv: vdso: Do not use LTO for the vDSO riscv: io: avoid null-pointer arithmetic in PIO helpers riscv: Gate FUNCTION_ALIGNMENT_4B on DYNAMIC_FTRACE mm/sparse-vmemmap: flush_cache_vmap() after hotplugging vmemmap riscv: mm: Make mark_new_valid_map() stuff depend on 64BIT && MMU
2 parents 980ab36 + 5caae1d commit 82a4758

9 files changed

Lines changed: 30 additions & 8 deletions

File tree

arch/riscv/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ config RISCV
157157
select HAVE_DEBUG_KMEMLEAK
158158
select HAVE_DMA_CONTIGUOUS if MMU
159159
select HAVE_DYNAMIC_FTRACE if MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
160-
select FUNCTION_ALIGNMENT_4B if HAVE_DYNAMIC_FTRACE && RISCV_ISA_C
160+
select FUNCTION_ALIGNMENT_4B if DYNAMIC_FTRACE && RISCV_ISA_C
161161
select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS if HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS
162162
select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS if (DYNAMIC_FTRACE_WITH_ARGS && !CFI)
163163
select HAVE_DYNAMIC_FTRACE_WITH_ARGS if HAVE_DYNAMIC_FTRACE

arch/riscv/include/asm/cacheflush.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ do { \
4040
flush_icache_mm(vma->vm_mm, 0); \
4141
} while (0)
4242

43-
#ifdef CONFIG_64BIT
43+
#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
4444
/* This is accessed in assembly code. cpumask_var_t would be too complex. */
4545
extern DECLARE_BITMAP(new_valid_map_cpus, NR_CPUS);
4646
extern char _end[];
@@ -56,7 +56,8 @@ static inline void mark_new_valid_map(void)
5656
#define flush_cache_vmap flush_cache_vmap
5757
static inline void flush_cache_vmap(unsigned long start, unsigned long end)
5858
{
59-
if (is_vmalloc_or_module_addr((void *)start))
59+
if (is_vmalloc_or_module_addr((void *)start) ||
60+
(start >= VMEMMAP_START && end <= VMEMMAP_END))
6061
mark_new_valid_map();
6162
}
6263
#define flush_cache_vmap_early(start, end) local_flush_tlb_kernel_range(start, end)

arch/riscv/include/asm/io.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ __io_reads_ins(reads, u32, l, __io_br(), __io_ar(addr))
102102
#define readsw(addr, buffer, count) __readsw(addr, buffer, count)
103103
#define readsl(addr, buffer, count) __readsl(addr, buffer, count)
104104

105+
#ifdef CONFIG_HAS_IOPORT
105106
__io_reads_ins(ins, u8, b, __io_pbr(), __io_par(addr))
106107
__io_reads_ins(ins, u16, w, __io_pbr(), __io_par(addr))
107108
__io_reads_ins(ins, u32, l, __io_pbr(), __io_par(addr))
108109
#define insb(addr, buffer, count) __insb(PCI_IOBASE + (addr), buffer, count)
109110
#define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count)
110111
#define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count)
112+
#endif
111113

112114
__io_writes_outs(writes, u8, b, __io_bw(), __io_aw())
113115
__io_writes_outs(writes, u16, w, __io_bw(), __io_aw())
@@ -116,26 +118,32 @@ __io_writes_outs(writes, u32, l, __io_bw(), __io_aw())
116118
#define writesw(addr, buffer, count) __writesw(addr, buffer, count)
117119
#define writesl(addr, buffer, count) __writesl(addr, buffer, count)
118120

121+
#ifdef CONFIG_HAS_IOPORT
119122
__io_writes_outs(outs, u8, b, __io_pbw(), __io_paw())
120123
__io_writes_outs(outs, u16, w, __io_pbw(), __io_paw())
121124
__io_writes_outs(outs, u32, l, __io_pbw(), __io_paw())
122125
#define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count)
123126
#define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count)
124127
#define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count)
128+
#endif
125129

126130
#ifdef CONFIG_64BIT
127131
__io_reads_ins(reads, u64, q, __io_br(), __io_ar(addr))
128132
#define readsq(addr, buffer, count) __readsq(addr, buffer, count)
129133

134+
#ifdef CONFIG_HAS_IOPORT
130135
__io_reads_ins(ins, u64, q, __io_pbr(), __io_par(addr))
131136
#define insq(addr, buffer, count) __insq(PCI_IOBASE + (addr), buffer, count)
137+
#endif
132138

133139
__io_writes_outs(writes, u64, q, __io_bw(), __io_aw())
134140
#define writesq(addr, buffer, count) __writesq(addr, buffer, count)
135141

142+
#ifdef CONFIG_HAS_IOPORT
136143
__io_writes_outs(outs, u64, q, __io_pbr(), __io_paw())
137144
#define outsq(addr, buffer, count) __outsq(PCI_IOBASE + (addr), buffer, count)
138145
#endif
146+
#endif
139147

140148
#include <asm-generic/io.h>
141149

arch/riscv/kernel/entry.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ SYM_CODE_START(handle_exception)
137137
.Lrestore_kernel_tpsp:
138138
csrr tp, CSR_SCRATCH
139139

140-
#ifdef CONFIG_64BIT
140+
#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
141141
/*
142142
* The RISC-V kernel does not flush TLBs on all CPUS after each new
143143
* vmalloc mapping or kfence_unprotect(), which may result in

arch/riscv/kernel/sys_hwprobe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ static int hwprobe_get_cpus(struct riscv_hwprobe __user *pairs,
450450
if (cpusetsize > cpumask_size())
451451
cpusetsize = cpumask_size();
452452

453+
cpumask_clear(&cpus);
453454
ret = copy_from_user(&cpus, cpus_user, cpusetsize);
454455
if (ret)
455456
return -EFAULT;

arch/riscv/kernel/vdso/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ CPPFLAGS_$(vdso_lds) += -DHAS_VGETTIMEOFDAY
6969
endif
7070

7171
# Disable -pg to prevent insert call site
72-
CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
73-
CFLAGS_REMOVE_getrandom.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
74-
CFLAGS_REMOVE_hwprobe.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS)
72+
CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_LTO)
73+
CFLAGS_REMOVE_getrandom.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_LTO)
74+
CFLAGS_REMOVE_hwprobe.o = $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS) $(CC_FLAGS_LTO)
7575

7676
# Force dependency
7777
$(obj)/$(vdso_o): $(obj)/$(vdso_so)

arch/riscv/kernel/vdso/rt_sigreturn.S

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
#include <asm/unistd.h>
88
#include <asm/assembler.h>
99

10+
/*
11+
* WARNING: Do NOT add a CFI landing pad at the start of this function.
12+
* Unwinders such as libgcc identify the sigreturn trampoline by matching the
13+
* instruction sequence. Adding a landing pad here would break unwinding from
14+
* signal handlers.
15+
*
16+
* This trampoline is used only for signal return and not via an indirect
17+
* call/jump from userspace, so adding CFI landing pad is unnecessary.
18+
*/
1019
.text
1120
SYM_FUNC_START(__vdso_rt_sigreturn)
1221
.cfi_startproc
1322
.cfi_signal_frame
14-
vdso_lpad
1523
li a7, __NR_rt_sigreturn
1624
ecall
1725
.cfi_endproc

arch/riscv/mm/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737

3838
#include "../kernel/head.h"
3939

40+
#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
4041
DECLARE_BITMAP(new_valid_map_cpus, NR_CPUS);
42+
#endif
4143

4244
struct kernel_mapping kernel_map __ro_after_init;
4345
EXPORT_SYMBOL(kernel_map);

mm/sparse-vmemmap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn,
564564
if (r < 0)
565565
return NULL;
566566

567+
flush_cache_vmap(start, end);
568+
567569
return pfn_to_page(pfn);
568570
}
569571

0 commit comments

Comments
 (0)