Skip to content

Commit 982365a

Browse files
committed
Merge tag 'riscv-for-linus-6.4-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull more RISC-V updates from Palmer Dabbelt: - Support for hibernation - The .rela.dyn section has been moved to the init area - A fix for the SBI probing to allow for implementation-defined behavior - Various other fixes and cleanups throughout the tree * tag 'riscv-for-linus-6.4-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: RISC-V: include cpufeature.h in cpufeature.c riscv: Move .rela.dyn to the init sections dt-bindings: riscv: explicitly mention assumption of Zicsr & Zifencei support riscv: compat_syscall_table: Fixup compile warning RISC-V: fixup in-flight collision with ARCH_WANT_OPTIMIZE_VMEMMAP rename RISC-V: fix sifive and thead section mismatches in errata RISC-V: Align SBI probe implementation with spec riscv: mm: remove redundant parameter of create_fdt_early_page_table riscv: Adjust dependencies of HAVE_DYNAMIC_FTRACE selection RISC-V: Add arch functions to support hibernation/suspend-to-disk RISC-V: mm: Enable huge page support to kernel_page_present() function RISC-V: Factor out common code of __cpu_resume_enter() RISC-V: Change suspend_save_csrs and suspend_restore_csrs to public function
2 parents 493804a + c2d3c84 commit 982365a

File tree

22 files changed

+682
-68
lines changed

22 files changed

+682
-68
lines changed

Documentation/devicetree/bindings/riscv/cpus.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ properties:
8686
User-Level ISA document, available from
8787
https://riscv.org/specifications/
8888

89+
Due to revisions of the ISA specification, some deviations
90+
have arisen over time.
91+
Notably, riscv,isa was defined prior to the creation of the
92+
Zicsr and Zifencei extensions and thus "i" implies
93+
"zicsr_zifencei".
94+
8995
While the isa strings in ISA specification are case
9096
insensitive, letters in the riscv,isa string must be all
9197
lowercase to simplify parsing.

arch/riscv/Kconfig

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ config RISCV
4747
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
4848
select ARCH_WANT_FRAME_POINTERS
4949
select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT
50-
select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
5150
select ARCH_WANT_HUGE_PMD_SHARE if 64BIT
5251
select ARCH_WANT_LD_ORPHAN_WARN if !XIP_KERNEL
52+
select ARCH_WANT_OPTIMIZE_VMEMMAP
5353
select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE
5454
select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU
5555
select BUILDTIME_TABLE_SORT if MMU
5656
select CLINT_TIMER if !MMU
5757
select CLONE_BACKWARDS
5858
select COMMON_CLK
59-
select CPU_PM if CPU_IDLE
59+
select CPU_PM if CPU_IDLE || HIBERNATION
6060
select EDAC_SUPPORT
6161
select GENERIC_ARCH_TOPOLOGY
6262
select GENERIC_ATOMIC64 if !64BIT
@@ -142,12 +142,23 @@ config RISCV
142142
select TRACE_IRQFLAGS_SUPPORT
143143
select UACCESS_MEMCPY if !MMU
144144
select ZONE_DMA32 if 64BIT
145-
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8)
145+
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
146146
select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
147147
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
148148
select HAVE_FUNCTION_GRAPH_TRACER
149149
select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
150150

151+
config CLANG_SUPPORTS_DYNAMIC_FTRACE
152+
def_bool CC_IS_CLANG
153+
# https://github.com/llvm/llvm-project/commit/6ab8927931851bb42b2c93a00801dc499d7d9b1e
154+
depends on CLANG_VERSION >= 130000
155+
# https://github.com/ClangBuiltLinux/linux/issues/1817
156+
depends on AS_IS_GNU || (AS_IS_LLVM && (LD_IS_LLD || LD_VERSION >= 23600))
157+
158+
config GCC_SUPPORTS_DYNAMIC_FTRACE
159+
def_bool CC_IS_GCC
160+
depends on $(cc-option,-fpatchable-function-entry=8)
161+
151162
config ARCH_MMAP_RND_BITS_MIN
152163
default 18 if 64BIT
153164
default 8
@@ -788,6 +799,12 @@ menu "Power management options"
788799

789800
source "kernel/power/Kconfig"
790801

802+
config ARCH_HIBERNATION_POSSIBLE
803+
def_bool y
804+
805+
config ARCH_HIBERNATION_HEADER
806+
def_bool HIBERNATION
807+
791808
endmenu # "Power management options"
792809

793810
menu "CPU Power Management"

arch/riscv/errata/sifive/errata.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ static void __init_or_module warn_miss_errata(u32 miss_errata)
8282
pr_warn("----------------------------------------------------------------\n");
8383
}
8484

85-
void __init_or_module sifive_errata_patch_func(struct alt_entry *begin,
86-
struct alt_entry *end,
87-
unsigned long archid,
88-
unsigned long impid,
89-
unsigned int stage)
85+
void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
86+
unsigned long archid, unsigned long impid,
87+
unsigned int stage)
9088
{
9189
struct alt_entry *alt;
9290
u32 cpu_req_errata;

arch/riscv/errata/thead/errata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ static u32 thead_errata_probe(unsigned int stage,
8383
return cpu_req_errata;
8484
}
8585

86-
void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
87-
unsigned long archid, unsigned long impid,
88-
unsigned int stage)
86+
void thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
87+
unsigned long archid, unsigned long impid,
88+
unsigned int stage)
8989
{
9090
struct alt_entry *alt;
9191
u32 cpu_req_errata = thead_errata_probe(stage, archid, impid);

arch/riscv/include/asm/assembler.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright (C) 2023 StarFive Technology Co., Ltd.
4+
*
5+
* Author: Jee Heng Sia <jeeheng.sia@starfivetech.com>
6+
*/
7+
8+
#ifndef __ASSEMBLY__
9+
#error "Only include this from assembly code"
10+
#endif
11+
12+
#ifndef __ASM_ASSEMBLER_H
13+
#define __ASM_ASSEMBLER_H
14+
15+
#include <asm/asm.h>
16+
#include <asm/asm-offsets.h>
17+
#include <asm/csr.h>
18+
19+
/*
20+
* suspend_restore_csrs - restore CSRs
21+
*/
22+
.macro suspend_restore_csrs
23+
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_EPC)(a0)
24+
csrw CSR_EPC, t0
25+
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_STATUS)(a0)
26+
csrw CSR_STATUS, t0
27+
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_BADADDR)(a0)
28+
csrw CSR_TVAL, t0
29+
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_CAUSE)(a0)
30+
csrw CSR_CAUSE, t0
31+
.endm
32+
33+
/*
34+
* suspend_restore_regs - Restore registers (except A0 and T0-T6)
35+
*/
36+
.macro suspend_restore_regs
37+
REG_L ra, (SUSPEND_CONTEXT_REGS + PT_RA)(a0)
38+
REG_L sp, (SUSPEND_CONTEXT_REGS + PT_SP)(a0)
39+
REG_L gp, (SUSPEND_CONTEXT_REGS + PT_GP)(a0)
40+
REG_L tp, (SUSPEND_CONTEXT_REGS + PT_TP)(a0)
41+
REG_L s0, (SUSPEND_CONTEXT_REGS + PT_S0)(a0)
42+
REG_L s1, (SUSPEND_CONTEXT_REGS + PT_S1)(a0)
43+
REG_L a1, (SUSPEND_CONTEXT_REGS + PT_A1)(a0)
44+
REG_L a2, (SUSPEND_CONTEXT_REGS + PT_A2)(a0)
45+
REG_L a3, (SUSPEND_CONTEXT_REGS + PT_A3)(a0)
46+
REG_L a4, (SUSPEND_CONTEXT_REGS + PT_A4)(a0)
47+
REG_L a5, (SUSPEND_CONTEXT_REGS + PT_A5)(a0)
48+
REG_L a6, (SUSPEND_CONTEXT_REGS + PT_A6)(a0)
49+
REG_L a7, (SUSPEND_CONTEXT_REGS + PT_A7)(a0)
50+
REG_L s2, (SUSPEND_CONTEXT_REGS + PT_S2)(a0)
51+
REG_L s3, (SUSPEND_CONTEXT_REGS + PT_S3)(a0)
52+
REG_L s4, (SUSPEND_CONTEXT_REGS + PT_S4)(a0)
53+
REG_L s5, (SUSPEND_CONTEXT_REGS + PT_S5)(a0)
54+
REG_L s6, (SUSPEND_CONTEXT_REGS + PT_S6)(a0)
55+
REG_L s7, (SUSPEND_CONTEXT_REGS + PT_S7)(a0)
56+
REG_L s8, (SUSPEND_CONTEXT_REGS + PT_S8)(a0)
57+
REG_L s9, (SUSPEND_CONTEXT_REGS + PT_S9)(a0)
58+
REG_L s10, (SUSPEND_CONTEXT_REGS + PT_S10)(a0)
59+
REG_L s11, (SUSPEND_CONTEXT_REGS + PT_S11)(a0)
60+
.endm
61+
62+
/*
63+
* copy_page - copy 1 page (4KB) of data from source to destination
64+
* @a0 - destination
65+
* @a1 - source
66+
*/
67+
.macro copy_page a0, a1
68+
lui a2, 0x1
69+
add a2, a2, a0
70+
1 :
71+
REG_L t0, 0(a1)
72+
REG_L t1, SZREG(a1)
73+
74+
REG_S t0, 0(a0)
75+
REG_S t1, SZREG(a0)
76+
77+
addi a0, a0, 2 * SZREG
78+
addi a1, a1, 2 * SZREG
79+
bne a2, a0, 1b
80+
.endm
81+
82+
#endif /* __ASM_ASSEMBLER_H */

arch/riscv/include/asm/sbi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ int sbi_remote_hfence_vvma_asid(const struct cpumask *cpu_mask,
295295
unsigned long start,
296296
unsigned long size,
297297
unsigned long asid);
298-
int sbi_probe_extension(int ext);
298+
long sbi_probe_extension(int ext);
299299

300300
/* Check if current SBI specification version is 0.1 or not */
301301
static inline int sbi_spec_is_0_1(void)

arch/riscv/include/asm/suspend.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ struct suspend_context {
2121
#endif
2222
};
2323

24+
/*
25+
* Used by hibernation core and cleared during resume sequence
26+
*/
27+
extern int in_suspend;
28+
2429
/* Low-level CPU suspend entry function */
2530
int __cpu_suspend_enter(struct suspend_context *context);
2631

@@ -33,4 +38,21 @@ int cpu_suspend(unsigned long arg,
3338
/* Low-level CPU resume entry function */
3439
int __cpu_resume_enter(unsigned long hartid, unsigned long context);
3540

41+
/* Used to save and restore the CSRs */
42+
void suspend_save_csrs(struct suspend_context *context);
43+
void suspend_restore_csrs(struct suspend_context *context);
44+
45+
/* Low-level API to support hibernation */
46+
int swsusp_arch_suspend(void);
47+
int swsusp_arch_resume(void);
48+
int arch_hibernation_header_save(void *addr, unsigned int max_size);
49+
int arch_hibernation_header_restore(void *addr);
50+
int __hibernate_cpu_resume(void);
51+
52+
/* Used to resume on the CPU we hibernated on */
53+
int hibernate_resume_nonboot_cpu_disable(void);
54+
55+
asmlinkage void hibernate_restore_image(unsigned long resume_satp, unsigned long satp_temp,
56+
unsigned long cpu_resume);
57+
asmlinkage int hibernate_core_restore_code(void);
3658
#endif

arch/riscv/kernel/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CFLAGS_REMOVE_patch.o = $(CC_FLAGS_FTRACE)
99
CFLAGS_REMOVE_sbi.o = $(CC_FLAGS_FTRACE)
1010
endif
1111
CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,)
12+
CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,)
1213

1314
ifdef CONFIG_KEXEC
1415
AFLAGS_kexec_relocate.o := -mcmodel=medany $(call cc-option,-mno-relax)
@@ -64,6 +65,7 @@ obj-$(CONFIG_MODULES) += module.o
6465
obj-$(CONFIG_MODULE_SECTIONS) += module-sections.o
6566

6667
obj-$(CONFIG_CPU_PM) += suspend_entry.o suspend.o
68+
obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o
6769

6870
obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o
6971
obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o

arch/riscv/kernel/asm-offsets.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/kbuild.h>
1010
#include <linux/mm.h>
1111
#include <linux/sched.h>
12+
#include <linux/suspend.h>
1213
#include <asm/kvm_host.h>
1314
#include <asm/thread_info.h>
1415
#include <asm/ptrace.h>
@@ -116,6 +117,10 @@ void asm_offsets(void)
116117

117118
OFFSET(SUSPEND_CONTEXT_REGS, suspend_context, regs);
118119

120+
OFFSET(HIBERN_PBE_ADDR, pbe, address);
121+
OFFSET(HIBERN_PBE_ORIG, pbe, orig_address);
122+
OFFSET(HIBERN_PBE_NEXT, pbe, next);
123+
119124
OFFSET(KVM_ARCH_GUEST_ZERO, kvm_vcpu_arch, guest_context.zero);
120125
OFFSET(KVM_ARCH_GUEST_RA, kvm_vcpu_arch, guest_context.ra);
121126
OFFSET(KVM_ARCH_GUEST_SP, kvm_vcpu_arch, guest_context.sp);

arch/riscv/kernel/cpu_ops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const struct cpu_operations cpu_ops_spinwait = {
2727
void __init cpu_set_ops(int cpuid)
2828
{
2929
#if IS_ENABLED(CONFIG_RISCV_SBI)
30-
if (sbi_probe_extension(SBI_EXT_HSM) > 0) {
30+
if (sbi_probe_extension(SBI_EXT_HSM)) {
3131
if (!cpuid)
3232
pr_info("SBI HSM extension detected\n");
3333
cpu_ops[cpuid] = &cpu_ops_sbi;

0 commit comments

Comments
 (0)