Skip to content

Commit dbf8381

Browse files
committed
Merge tag 'riscv-for-linus-5.9-mw0' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V updates from Palmer Dabbelt: "We have a lot of new kernel features for this merge window: - ARCH_SUPPORTS_ATOMIC_RMW, to allow OSQ locks to be enabled - The ability to enable NO_HZ_FULL - Support for enabling kcov, kmemleak, stack protector, and VM debugging - JUMP_LABEL support There are also a handful of cleanups" * tag 'riscv-for-linus-5.9-mw0' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (24 commits) riscv: disable stack-protector for vDSO RISC-V: Fix build warning for smpboot.c riscv: fix build warning of mm/pageattr riscv: Fix build warning for mm/init RISC-V: Setup exception vector early riscv: Select ARCH_HAS_DEBUG_VM_PGTABLE riscv: Use generic pgprot_* macros from <linux/pgtable.h> mm: pgtable: Make generic pgprot_* macros available for no-MMU riscv: Cleanup unnecessary define in asm-offset.c riscv: Add jump-label implementation riscv: Support R_RISCV_ADD64 and R_RISCV_SUB64 relocs Replace HTTP links with HTTPS ones: RISC-V riscv: Add STACKPROTECTOR supported riscv: Fix typo in asm/hwcap.h uapi header riscv: Add kmemleak support riscv: Allow building with kcov coverage riscv: Enable context tracking riscv: Support irq_work via self IPIs riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT riscv: Fixup lockdep_assert_held with wrong param cpu_running ...
2 parents e1ec517 + 40284a0 commit dbf8381

File tree

32 files changed

+356
-71
lines changed

32 files changed

+356
-71
lines changed

Documentation/features/core/jump-labels/arch-support.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| openrisc: | TODO |
2424
| parisc: | ok |
2525
| powerpc: | ok |
26-
| riscv: | TODO |
26+
| riscv: | ok |
2727
| s390: | ok |
2828
| sh: | TODO |
2929
| sparc: | ok |

Documentation/features/debug/debug-vm-pgtable/arch-support.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| openrisc: | TODO |
2424
| parisc: | TODO |
2525
| powerpc: | ok |
26-
| riscv: | TODO |
26+
| riscv: | ok |
2727
| s390: | ok |
2828
| sh: | TODO |
2929
| sparc: | TODO |

arch/riscv/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ config 32BIT
1313
config RISCV
1414
def_bool y
1515
select ARCH_CLOCKSOURCE_INIT
16+
select ARCH_SUPPORTS_ATOMIC_RMW
1617
select ARCH_HAS_BINFMT_FLAT
18+
select ARCH_HAS_DEBUG_VM_PGTABLE
1719
select ARCH_HAS_DEBUG_VIRTUAL if MMU
1820
select ARCH_HAS_DEBUG_WX
1921
select ARCH_HAS_GCOV_PROFILE_ALL
2022
select ARCH_HAS_GIGANTIC_PAGE
23+
select ARCH_HAS_KCOV
2124
select ARCH_HAS_MMIOWB
2225
select ARCH_HAS_PTE_SPECIAL
2326
select ARCH_HAS_SET_DIRECT_MAP
@@ -47,21 +50,27 @@ config RISCV
4750
select GENERIC_TIME_VSYSCALL if MMU && 64BIT
4851
select HANDLE_DOMAIN_IRQ
4952
select HAVE_ARCH_AUDITSYSCALL
53+
select HAVE_ARCH_JUMP_LABEL
54+
select HAVE_ARCH_JUMP_LABEL_RELATIVE
5055
select HAVE_ARCH_KASAN if MMU && 64BIT
5156
select HAVE_ARCH_KGDB
5257
select HAVE_ARCH_KGDB_QXFER_PKT
5358
select HAVE_ARCH_MMAP_RND_BITS if MMU
5459
select HAVE_ARCH_SECCOMP_FILTER
5560
select HAVE_ARCH_TRACEHOOK
5661
select HAVE_ASM_MODVERSIONS
62+
select HAVE_CONTEXT_TRACKING
63+
select HAVE_DEBUG_KMEMLEAK
5764
select HAVE_DMA_CONTIGUOUS if MMU
5865
select HAVE_EBPF_JIT if MMU
5966
select HAVE_FUTEX_CMPXCHG if FUTEX
67+
select HAVE_GCC_PLUGINS
6068
select HAVE_GENERIC_VDSO if MMU && 64BIT
6169
select HAVE_PCI
6270
select HAVE_PERF_EVENTS
6371
select HAVE_PERF_REGS
6472
select HAVE_PERF_USER_STACK_DUMP
73+
select HAVE_STACKPROTECTOR
6574
select HAVE_SYSCALL_TRACEPOINTS
6675
select IRQ_DOMAIN
6776
select MODULES_USE_ELF_RELA if MODULES
@@ -179,6 +188,9 @@ config PGTABLE_LEVELS
179188
default 3 if 64BIT
180189
default 2
181190

191+
config LOCKDEP_SUPPORT
192+
def_bool y
193+
182194
source "arch/riscv/Kconfig.socs"
183195

184196
menu "Platform type"

arch/riscv/boot/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# Based on the ia64 and arm64 boot/Makefile.
1515
#
1616

17+
KCOV_INSTRUMENT := n
18+
1719
OBJCOPYFLAGS_Image :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
1820

1921
targets := Image loader

arch/riscv/configs/defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CONFIG_BPF_SYSCALL=y
1717
CONFIG_SOC_SIFIVE=y
1818
CONFIG_SOC_VIRT=y
1919
CONFIG_SMP=y
20+
CONFIG_JUMP_LABEL=y
2021
CONFIG_MODULES=y
2122
CONFIG_MODULE_UNLOAD=y
2223
CONFIG_NET=y

arch/riscv/configs/nommu_k210_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CONFIG_SMP=y
3333
CONFIG_NR_CPUS=2
3434
CONFIG_CMDLINE="earlycon console=ttySIF0"
3535
CONFIG_CMDLINE_FORCE=y
36+
CONFIG_JUMP_LABEL=y
3637
# CONFIG_BLOCK is not set
3738
CONFIG_BINFMT_FLAT=y
3839
# CONFIG_COREDUMP is not set

arch/riscv/configs/nommu_virt_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CONFIG_MAXPHYSMEM_2GB=y
3030
CONFIG_SMP=y
3131
CONFIG_CMDLINE="root=/dev/vda rw earlycon=uart8250,mmio,0x10000000,115200n8 console=ttyS0"
3232
CONFIG_CMDLINE_FORCE=y
33+
CONFIG_JUMP_LABEL=y
3334
# CONFIG_BLK_DEV_BSG is not set
3435
CONFIG_PARTITION_ADVANCED=y
3536
# CONFIG_MSDOS_PARTITION is not set

arch/riscv/configs/rv32_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CONFIG_BPF_SYSCALL=y
1717
CONFIG_SOC_VIRT=y
1818
CONFIG_ARCH_RV32I=y
1919
CONFIG_SMP=y
20+
CONFIG_JUMP_LABEL=y
2021
CONFIG_MODULES=y
2122
CONFIG_MODULE_UNLOAD=y
2223
CONFIG_NET=y

arch/riscv/include/asm/irq_work.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_RISCV_IRQ_WORK_H
3+
#define _ASM_RISCV_IRQ_WORK_H
4+
5+
static inline bool arch_irq_work_has_interrupt(void)
6+
{
7+
return true;
8+
}
9+
extern void arch_irq_work_raise(void);
10+
#endif /* _ASM_RISCV_IRQ_WORK_H */

arch/riscv/include/asm/jump_label.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2020 Emil Renner Berthing
4+
*
5+
* Based on arch/arm64/include/asm/jump_label.h
6+
*/
7+
#ifndef __ASM_JUMP_LABEL_H
8+
#define __ASM_JUMP_LABEL_H
9+
10+
#ifndef __ASSEMBLY__
11+
12+
#include <linux/types.h>
13+
#include <asm/asm.h>
14+
15+
#define JUMP_LABEL_NOP_SIZE 4
16+
17+
static __always_inline bool arch_static_branch(struct static_key *key,
18+
bool branch)
19+
{
20+
asm_volatile_goto(
21+
" .option push \n\t"
22+
" .option norelax \n\t"
23+
" .option norvc \n\t"
24+
"1: nop \n\t"
25+
" .option pop \n\t"
26+
" .pushsection __jump_table, \"aw\" \n\t"
27+
" .align " RISCV_LGPTR " \n\t"
28+
" .long 1b - ., %l[label] - . \n\t"
29+
" " RISCV_PTR " %0 - . \n\t"
30+
" .popsection \n\t"
31+
: : "i"(&((char *)key)[branch]) : : label);
32+
33+
return false;
34+
label:
35+
return true;
36+
}
37+
38+
static __always_inline bool arch_static_branch_jump(struct static_key *key,
39+
bool branch)
40+
{
41+
asm_volatile_goto(
42+
" .option push \n\t"
43+
" .option norelax \n\t"
44+
" .option norvc \n\t"
45+
"1: jal zero, %l[label] \n\t"
46+
" .option pop \n\t"
47+
" .pushsection __jump_table, \"aw\" \n\t"
48+
" .align " RISCV_LGPTR " \n\t"
49+
" .long 1b - ., %l[label] - . \n\t"
50+
" " RISCV_PTR " %0 - . \n\t"
51+
" .popsection \n\t"
52+
: : "i"(&((char *)key)[branch]) : : label);
53+
54+
return false;
55+
label:
56+
return true;
57+
}
58+
59+
#endif /* __ASSEMBLY__ */
60+
#endif /* __ASM_JUMP_LABEL_H */

arch/riscv/include/asm/mmio.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
#include <linux/types.h>
1515
#include <asm/mmiowb.h>
1616

17-
#ifndef CONFIG_MMU
18-
#define pgprot_noncached(x) (x)
19-
#define pgprot_writecombine(x) (x)
20-
#define pgprot_device(x) (x)
21-
#endif /* CONFIG_MMU */
22-
2317
/* Generic IO read/write. These perform native-endian accesses. */
2418
#define __raw_writeb __raw_writeb
2519
static inline void __raw_writeb(u8 val, volatile void __iomem *addr)

arch/riscv/include/asm/smp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ void arch_send_call_function_single_ipi(int cpu);
4040
int riscv_hartid_to_cpuid(int hartid);
4141
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
4242

43+
/* Secondary hart entry */
44+
asmlinkage void smp_callin(void);
45+
4346
/*
4447
* Obtains the hart ID of the currently executing task. This relies on
4548
* THREAD_INFO_IN_TASK, but we define that unconditionally.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef _ASM_RISCV_STACKPROTECTOR_H
4+
#define _ASM_RISCV_STACKPROTECTOR_H
5+
6+
#include <linux/random.h>
7+
#include <linux/version.h>
8+
#include <asm/timex.h>
9+
10+
extern unsigned long __stack_chk_guard;
11+
12+
/*
13+
* Initialize the stackprotector canary value.
14+
*
15+
* NOTE: this must only be called from functions that never return,
16+
* and it must always be inlined.
17+
*/
18+
static __always_inline void boot_init_stack_canary(void)
19+
{
20+
unsigned long canary;
21+
unsigned long tsc;
22+
23+
/* Try to get a semi random initial value. */
24+
get_random_bytes(&canary, sizeof(canary));
25+
tsc = get_cycles();
26+
canary += tsc + (tsc << BITS_PER_LONG/2);
27+
canary ^= LINUX_VERSION_CODE;
28+
canary &= CANARY_MASK;
29+
30+
current->stack_canary = canary;
31+
__stack_chk_guard = current->stack_canary;
32+
}
33+
#endif /* _ASM_RISCV_STACKPROTECTOR_H */

arch/riscv/include/uapi/asm/hwcap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/*
1212
* Linux saves the floating-point registers according to the ISA Linux is
1313
* executing on, as opposed to the ISA the user program is compiled for. This
14-
* is necessary for a handful of esoteric use cases: for example, userpsace
14+
* is necessary for a handful of esoteric use cases: for example, userspace
1515
* threading libraries must be able to examine the actual machine state in
1616
* order to fully reconstruct the state of a thread.
1717
*/

arch/riscv/include/uapi/asm/unistd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* GNU General Public License for more details.
1313
*
1414
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

1818
#ifdef __LP64__

arch/riscv/kernel/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ endif
5353
obj-$(CONFIG_HOTPLUG_CPU) += cpu-hotplug.o
5454
obj-$(CONFIG_KGDB) += kgdb.o
5555

56+
obj-$(CONFIG_JUMP_LABEL) += jump_label.o
57+
5658
clean:

arch/riscv/kernel/asm-offsets.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ void asm_offsets(void)
2727
OFFSET(TASK_THREAD_S9, task_struct, thread.s[9]);
2828
OFFSET(TASK_THREAD_S10, task_struct, thread.s[10]);
2929
OFFSET(TASK_THREAD_S11, task_struct, thread.s[11]);
30-
OFFSET(TASK_THREAD_SP, task_struct, thread.sp);
31-
OFFSET(TASK_STACK, task_struct, stack);
32-
OFFSET(TASK_TI, task_struct, thread_info);
3330
OFFSET(TASK_TI_FLAGS, task_struct, thread_info.flags);
3431
OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count);
3532
OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp);

arch/riscv/kernel/entry.S

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,36 @@ _save_context:
9797
la gp, __global_pointer$
9898
.option pop
9999

100-
la ra, ret_from_exception
100+
#ifdef CONFIG_TRACE_IRQFLAGS
101+
call trace_hardirqs_off
102+
#endif
103+
104+
#ifdef CONFIG_CONTEXT_TRACKING
105+
/* If previous state is in user mode, call context_tracking_user_exit. */
106+
li a0, SR_PP
107+
and a0, s1, a0
108+
bnez a0, skip_context_tracking
109+
call context_tracking_user_exit
110+
skip_context_tracking:
111+
#endif
112+
101113
/*
102114
* MSB of cause differentiates between
103115
* interrupts and exceptions
104116
*/
105117
bge s4, zero, 1f
106118

119+
la ra, ret_from_exception
120+
107121
/* Handle interrupts */
108122
move a0, sp /* pt_regs */
109123
la a1, handle_arch_irq
110124
REG_L a1, (a1)
111125
jr a1
112126
1:
127+
#ifdef CONFIG_TRACE_IRQFLAGS
128+
call trace_hardirqs_on
129+
#endif
113130
/*
114131
* Exceptions run with interrupts enabled or disabled depending on the
115132
* state of SR_PIE in m/sstatus.
@@ -119,6 +136,7 @@ _save_context:
119136
csrs CSR_STATUS, SR_IE
120137

121138
1:
139+
la ra, ret_from_exception
122140
/* Handle syscalls */
123141
li t0, EXC_SYSCALL
124142
beq s4, t0, handle_syscall
@@ -137,6 +155,17 @@ _save_context:
137155
tail do_trap_unknown
138156

139157
handle_syscall:
158+
#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
159+
/* Recover a0 - a7 for system calls */
160+
REG_L a0, PT_A0(sp)
161+
REG_L a1, PT_A1(sp)
162+
REG_L a2, PT_A2(sp)
163+
REG_L a3, PT_A3(sp)
164+
REG_L a4, PT_A4(sp)
165+
REG_L a5, PT_A5(sp)
166+
REG_L a6, PT_A6(sp)
167+
REG_L a7, PT_A7(sp)
168+
#endif
140169
/* save the initial A0 value (needed in signal handlers) */
141170
REG_S a0, PT_ORIG_A0(sp)
142171
/*
@@ -190,6 +219,9 @@ ret_from_syscall_rejected:
190219
ret_from_exception:
191220
REG_L s0, PT_STATUS(sp)
192221
csrc CSR_STATUS, SR_IE
222+
#ifdef CONFIG_TRACE_IRQFLAGS
223+
call trace_hardirqs_off
224+
#endif
193225
#ifdef CONFIG_RISCV_M_MODE
194226
/* the MPP value is too large to be used as an immediate arg for addi */
195227
li t0, SR_MPP
@@ -205,6 +237,10 @@ resume_userspace:
205237
andi s1, s0, _TIF_WORK_MASK
206238
bnez s1, work_pending
207239

240+
#ifdef CONFIG_CONTEXT_TRACKING
241+
call context_tracking_user_enter
242+
#endif
243+
208244
/* Save unwound kernel stack pointer in thread_info */
209245
addi s0, sp, PT_SIZE_ON_STACK
210246
REG_S s0, TASK_TI_KERNEL_SP(tp)
@@ -216,6 +252,16 @@ resume_userspace:
216252
csrw CSR_SCRATCH, tp
217253

218254
restore_all:
255+
#ifdef CONFIG_TRACE_IRQFLAGS
256+
REG_L s1, PT_STATUS(sp)
257+
andi t0, s1, SR_PIE
258+
beqz t0, 1f
259+
call trace_hardirqs_on
260+
j 2f
261+
1:
262+
call trace_hardirqs_off
263+
2:
264+
#endif
219265
REG_L a0, PT_STATUS(sp)
220266
/*
221267
* The current load reservation is effectively part of the processor's
@@ -389,12 +435,8 @@ ENTRY(__switch_to)
389435
lw a4, TASK_TI_CPU(a1)
390436
sw a3, TASK_TI_CPU(a1)
391437
sw a4, TASK_TI_CPU(a0)
392-
#if TASK_TI != 0
393-
#error "TASK_TI != 0: tp will contain a 'struct thread_info', not a 'struct task_struct' so get_current() won't work."
394-
addi tp, a1, TASK_TI
395-
#else
438+
/* The offset of thread_info in task_struct is zero. */
396439
move tp, a1
397-
#endif
398440
ret
399441
ENDPROC(__switch_to)
400442

0 commit comments

Comments
 (0)