Skip to content

Commit cd479d9

Browse files
committed
Merge tag 'riscv-for-linus-6.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - avoid excessive rejections from seccomp RET_ERRNO rules - compressed jal/jalr decoding fix - fixes for independent irq/softirq stacks on kernels built with CONFIG_FRAME_POINTER=n - avoid a hang handling uaccess fixups - another build fix for toolchain ISA strings, this time for Zicsr and Zifenci on old GNU toolchains * tag 'riscv-for-linus-6.5-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Handle zicsr/zifencei issue between gcc and binutils riscv: uaccess: Return the number of bytes effectively not copied riscv: stack: Fixup independent softirq stack for CONFIG_FRAME_POINTER=n riscv: stack: Fixup independent irq stack for CONFIG_FRAME_POINTER=n riscv: correct riscv_insn_is_c_jr() and riscv_insn_is_c_jalr() riscv: entry: set a0 = -ENOSYS only when syscall != -1
2 parents ce03e18 + ca09f77 commit cd479d9

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
lines changed

arch/riscv/Kconfig

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -570,24 +570,30 @@ config TOOLCHAIN_HAS_ZIHINTPAUSE
570570
config TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
571571
def_bool y
572572
# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc
573-
depends on AS_IS_GNU && AS_VERSION >= 23800
574-
help
575-
Newer binutils versions default to ISA spec version 20191213 which
576-
moves some instructions from the I extension to the Zicsr and Zifencei
577-
extensions.
573+
# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd
574+
depends on AS_IS_GNU && AS_VERSION >= 23600
575+
help
576+
Binutils-2.38 and GCC-12.1.0 bumped the default ISA spec to the newer
577+
20191213 version, which moves some instructions from the I extension to
578+
the Zicsr and Zifencei extensions. This requires explicitly specifying
579+
Zicsr and Zifencei when binutils >= 2.38 or GCC >= 12.1.0. Zicsr
580+
and Zifencei are supported in binutils from version 2.36 onwards.
581+
To make life easier, and avoid forcing toolchains that default to a
582+
newer ISA spec to version 2.2, relax the check to binutils >= 2.36.
583+
For clang < 17 or GCC < 11.1.0, for which this is not possible, this is
584+
dealt with in CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC.
578585

579586
config TOOLCHAIN_NEEDS_OLD_ISA_SPEC
580587
def_bool y
581588
depends on TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
582589
# https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16
583-
depends on CC_IS_CLANG && CLANG_VERSION < 170000
584-
help
585-
Certain versions of clang do not support zicsr and zifencei via -march
586-
but newer versions of binutils require it for the reasons noted in the
587-
help text of CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI. This
588-
option causes an older ISA spec compatible with these older versions
589-
of clang to be passed to GAS, which has the same result as passing zicsr
590-
and zifencei to -march.
590+
# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b03be74bad08c382da47e048007a78fa3fb4ef49
591+
depends on (CC_IS_CLANG && CLANG_VERSION < 170000) || (CC_IS_GCC && GCC_VERSION < 110100)
592+
help
593+
Certain versions of clang and GCC do not support zicsr and zifencei via
594+
-march. This option causes an older ISA spec compatible with these older
595+
versions of clang and GCC to be passed to GAS, which has the same result
596+
as passing zicsr and zifencei to -march.
591597

592598
config FPU
593599
bool "FPU support"

arch/riscv/include/asm/insn.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
#define RVC_INSN_FUNCT4_OPOFF 12
111111
#define RVC_INSN_FUNCT3_MASK GENMASK(15, 13)
112112
#define RVC_INSN_FUNCT3_OPOFF 13
113+
#define RVC_INSN_J_RS1_MASK GENMASK(11, 7)
113114
#define RVC_INSN_J_RS2_MASK GENMASK(6, 2)
114115
#define RVC_INSN_OPCODE_MASK GENMASK(1, 0)
115116
#define RVC_ENCODE_FUNCT3(f_) (RVC_FUNCT3_##f_ << RVC_INSN_FUNCT3_OPOFF)
@@ -245,8 +246,6 @@ __RISCV_INSN_FUNCS(c_jal, RVC_MASK_C_JAL, RVC_MATCH_C_JAL)
245246
__RISCV_INSN_FUNCS(auipc, RVG_MASK_AUIPC, RVG_MATCH_AUIPC)
246247
__RISCV_INSN_FUNCS(jalr, RVG_MASK_JALR, RVG_MATCH_JALR)
247248
__RISCV_INSN_FUNCS(jal, RVG_MASK_JAL, RVG_MATCH_JAL)
248-
__RISCV_INSN_FUNCS(c_jr, RVC_MASK_C_JR, RVC_MATCH_C_JR)
249-
__RISCV_INSN_FUNCS(c_jalr, RVC_MASK_C_JALR, RVC_MATCH_C_JALR)
250249
__RISCV_INSN_FUNCS(c_j, RVC_MASK_C_J, RVC_MATCH_C_J)
251250
__RISCV_INSN_FUNCS(beq, RVG_MASK_BEQ, RVG_MATCH_BEQ)
252251
__RISCV_INSN_FUNCS(bne, RVG_MASK_BNE, RVG_MATCH_BNE)
@@ -273,6 +272,18 @@ static __always_inline bool riscv_insn_is_branch(u32 code)
273272
return (code & RV_INSN_OPCODE_MASK) == RVG_OPCODE_BRANCH;
274273
}
275274

275+
static __always_inline bool riscv_insn_is_c_jr(u32 code)
276+
{
277+
return (code & RVC_MASK_C_JR) == RVC_MATCH_C_JR &&
278+
(code & RVC_INSN_J_RS1_MASK) != 0;
279+
}
280+
281+
static __always_inline bool riscv_insn_is_c_jalr(u32 code)
282+
{
283+
return (code & RVC_MASK_C_JALR) == RVC_MATCH_C_JALR &&
284+
(code & RVC_INSN_J_RS1_MASK) != 0;
285+
}
286+
276287
#define RV_IMM_SIGN(x) (-(((x) >> 31) & 1))
277288
#define RVC_IMM_SIGN(x) (-(((x) >> 12) & 1))
278289
#define RV_X(X, s, mask) (((X) >> (s)) & (mask))

arch/riscv/kernel/compat_vdso/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ compat_vdso-syms += flush_icache
1111
COMPAT_CC := $(CC)
1212
COMPAT_LD := $(LD)
1313

14-
COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
14+
# binutils 2.35 does not support the zifencei extension, but in the ISA
15+
# spec 20191213, G stands for IMAFD_ZICSR_ZIFENCEI.
16+
ifdef CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
17+
COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
18+
else
19+
COMPAT_CC_FLAGS := -march=rv32imafd -mabi=ilp32
20+
endif
1521
COMPAT_LD_FLAGS := -melf32lriscv
1622

1723
# Disable attributes, as they're useless and break the build.

arch/riscv/kernel/irq.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ void do_softirq_own_stack(void)
8484
: [sp] "r" (sp)
8585
: "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8686
"t0", "t1", "t2", "t3", "t4", "t5", "t6",
87+
#ifndef CONFIG_FRAME_POINTER
88+
"s0",
89+
#endif
8790
"memory");
8891
} else
8992
#endif

arch/riscv/kernel/traps.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ asmlinkage __visible __trap_section void do_trap_break(struct pt_regs *regs)
297297
asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs)
298298
{
299299
if (user_mode(regs)) {
300-
ulong syscall = regs->a7;
300+
long syscall = regs->a7;
301301

302302
regs->epc += 4;
303303
regs->orig_a0 = regs->a0;
@@ -306,9 +306,9 @@ asmlinkage __visible __trap_section void do_trap_ecall_u(struct pt_regs *regs)
306306

307307
syscall = syscall_enter_from_user_mode(regs, syscall);
308308

309-
if (syscall < NR_syscalls)
309+
if (syscall >= 0 && syscall < NR_syscalls)
310310
syscall_handler(regs, syscall);
311-
else
311+
else if (syscall != -1)
312312
regs->a0 = -ENOSYS;
313313

314314
syscall_exit_to_user_mode(regs);
@@ -372,6 +372,9 @@ asmlinkage void noinstr do_irq(struct pt_regs *regs)
372372
: [sp] "r" (sp), [regs] "r" (regs)
373373
: "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
374374
"t0", "t1", "t2", "t3", "t4", "t5", "t6",
375+
#ifndef CONFIG_FRAME_POINTER
376+
"s0",
377+
#endif
375378
"memory");
376379
} else
377380
#endif

arch/riscv/lib/uaccess.S

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ ENTRY(__asm_copy_from_user)
1717
li t6, SR_SUM
1818
csrs CSR_STATUS, t6
1919

20-
/* Save for return value */
21-
mv t5, a2
20+
/*
21+
* Save the terminal address which will be used to compute the number
22+
* of bytes copied in case of a fixup exception.
23+
*/
24+
add t5, a0, a2
2225

2326
/*
2427
* Register allocation for code below:
@@ -176,7 +179,7 @@ ENTRY(__asm_copy_from_user)
176179
10:
177180
/* Disable access to user memory */
178181
csrc CSR_STATUS, t6
179-
mv a0, t5
182+
sub a0, t5, a0
180183
ret
181184
ENDPROC(__asm_copy_to_user)
182185
ENDPROC(__asm_copy_from_user)
@@ -228,7 +231,7 @@ ENTRY(__clear_user)
228231
11:
229232
/* Disable access to user memory */
230233
csrc CSR_STATUS, t6
231-
mv a0, a1
234+
sub a0, a3, a0
232235
ret
233236
ENDPROC(__clear_user)
234237
EXPORT_SYMBOL(__clear_user)

0 commit comments

Comments
 (0)