Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit f1f9984

Browse files
committed
Merge tag 'riscv-for-linus-6.10-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull more RISC-V updates from Palmer Dabbelt: - The compression format used for boot images is now configurable at build time, and these formats are shown in `make help` - access_ok() has been optimized - A pair of performance bugs have been fixed in the uaccess handlers - Various fixes and cleanups, including one for the IMSIC build failure and one for the early-boot ftrace illegal NOPs bug * tag 'riscv-for-linus-6.10-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Fix early ftrace nop patching irqchip: riscv-imsic: Fixup riscv_ipi_set_virq_range() conflict riscv: selftests: Add signal handling vector tests riscv: mm: accelerate pagefault when badaccess riscv: uaccess: Relax the threshold for fast path riscv: uaccess: Allow the last potential unrolled copy riscv: typo in comment for get_f64_reg Use bool value in set_cpu_online() riscv: selftests: Add hwprobe binaries to .gitignore riscv: stacktrace: fixed walk_stackframe() ftrace: riscv: move from REGS to ARGS riscv: do not select MODULE_SECTIONS by default riscv: show help string for riscv-specific targets riscv: make image compression configurable riscv: cpufeature: Fix extension subset checking riscv: cpufeature: Fix thead vector hwcap removal riscv: rewrite __kernel_map_pages() to fix sleeping in invalid context riscv: force PAGE_SIZE linear mapping if debug_pagealloc is enabled riscv: Define TASK_SIZE_MAX for __access_ok() riscv: Remove PGDIR_SIZE_L3 and TASK_SIZE_MIN
2 parents 9351f13 + 6ca445d commit f1f9984

File tree

27 files changed

+395
-184
lines changed

27 files changed

+395
-184
lines changed

arch/riscv/Kconfig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ config RISCV
129129
select HAVE_DMA_CONTIGUOUS if MMU
130130
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
131131
select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
132-
select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
132+
select HAVE_DYNAMIC_FTRACE_WITH_ARGS if HAVE_DYNAMIC_FTRACE
133133
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
134134
select HAVE_FUNCTION_GRAPH_TRACER
135135
select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
@@ -141,6 +141,13 @@ config RISCV
141141
select HAVE_GCC_PLUGINS
142142
select HAVE_GENERIC_VDSO if MMU && 64BIT
143143
select HAVE_IRQ_TIME_ACCOUNTING
144+
select HAVE_KERNEL_BZIP2 if !XIP_KERNEL && !EFI_ZBOOT
145+
select HAVE_KERNEL_GZIP if !XIP_KERNEL && !EFI_ZBOOT
146+
select HAVE_KERNEL_LZ4 if !XIP_KERNEL && !EFI_ZBOOT
147+
select HAVE_KERNEL_LZMA if !XIP_KERNEL && !EFI_ZBOOT
148+
select HAVE_KERNEL_LZO if !XIP_KERNEL && !EFI_ZBOOT
149+
select HAVE_KERNEL_UNCOMPRESSED if !XIP_KERNEL && !EFI_ZBOOT
150+
select HAVE_KERNEL_ZSTD if !XIP_KERNEL && !EFI_ZBOOT
144151
select HAVE_KPROBES if !XIP_KERNEL
145152
select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
146153
select HAVE_KRETPROBES if !XIP_KERNEL
@@ -170,7 +177,6 @@ config RISCV
170177
select LOCK_MM_AND_FIND_VMA
171178
select MMU_GATHER_RCU_TABLE_FREE if SMP && MMU
172179
select MODULES_USE_ELF_RELA if MODULES
173-
select MODULE_SECTIONS if MODULES
174180
select OF
175181
select OF_EARLY_FLATTREE
176182
select OF_IRQ
@@ -861,6 +867,7 @@ config PARAVIRT_TIME_ACCOUNTING
861867
config RELOCATABLE
862868
bool "Build a relocatable kernel"
863869
depends on MMU && 64BIT && !XIP_KERNEL
870+
select MODULE_SECTIONS if MODULES
864871
help
865872
This builds a kernel as a Position Independent Executable (PIE),
866873
which retains all relocation metadata required to relocate the

arch/riscv/Makefile

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ endif
154154
endif
155155
endif
156156

157+
boot := arch/riscv/boot
158+
boot-image-y := Image
159+
boot-image-$(CONFIG_KERNEL_BZIP2) := Image.bz2
160+
boot-image-$(CONFIG_KERNEL_GZIP) := Image.gz
161+
boot-image-$(CONFIG_KERNEL_LZ4) := Image.lz4
162+
boot-image-$(CONFIG_KERNEL_LZMA) := Image.lzma
163+
boot-image-$(CONFIG_KERNEL_LZO) := Image.lzo
164+
boot-image-$(CONFIG_KERNEL_ZSTD) := Image.zst
165+
ifdef CONFIG_RISCV_M_MODE
166+
boot-image-$(CONFIG_ARCH_CANAAN) := loader.bin
167+
endif
168+
boot-image-$(CONFIG_EFI_ZBOOT) := vmlinuz.efi
169+
boot-image-$(CONFIG_XIP_KERNEL) := xipImage
170+
KBUILD_IMAGE := $(boot)/$(boot-image-y)
171+
157172
libs-y += arch/riscv/lib/
158173
libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
159174

@@ -171,21 +186,19 @@ endif
171186
vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg
172187
vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
173188

174-
BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
189+
BOOT_TARGETS := Image Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst loader loader.bin xipImage vmlinuz.efi
175190

176191
all: $(notdir $(KBUILD_IMAGE))
177192

178193
loader.bin: loader
179-
Image.gz loader vmlinuz.efi: Image
194+
Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst loader xipImage vmlinuz.efi: Image
195+
180196
$(BOOT_TARGETS): vmlinux
181197
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
182198
@$(kecho) ' Kernel: $(boot)/$@ is ready'
183199

184-
Image.%: Image
185-
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
186-
187-
install: KBUILD_IMAGE := $(boot)/Image
188-
zinstall: KBUILD_IMAGE := $(boot)/Image.gz
200+
# the install target always installs KBUILD_IMAGE (which may be compressed)
201+
# but keep the zinstall target for compatibility with older releases
189202
install zinstall:
190203
$(call cmd,install)
191204

@@ -206,3 +219,20 @@ rv32_defconfig:
206219
PHONY += rv32_nommu_virt_defconfig
207220
rv32_nommu_virt_defconfig:
208221
$(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config
222+
223+
define archhelp
224+
echo ' Image - Uncompressed kernel image (arch/riscv/boot/Image)'
225+
echo ' Image.gz - Compressed kernel image (arch/riscv/boot/Image.gz)'
226+
echo ' Image.bz2 - Compressed kernel image (arch/riscv/boot/Image.bz2)'
227+
echo ' Image.lz4 - Compressed kernel image (arch/riscv/boot/Image.lz4)'
228+
echo ' Image.lzma - Compressed kernel image (arch/riscv/boot/Image.lzma)'
229+
echo ' Image.lzo - Compressed kernel image (arch/riscv/boot/Image.lzo)'
230+
echo ' Image.zst - Compressed kernel image (arch/riscv/boot/Image.zst)'
231+
echo ' vmlinuz.efi - Compressed EFI kernel image (arch/riscv/boot/vmlinuz.efi)'
232+
echo ' Default when CONFIG_EFI_ZBOOT=y'
233+
echo ' xipImage - Execute-in-place kernel image (arch/riscv/boot/xipImage)'
234+
echo ' Default when CONFIG_XIP_KERNEL=y'
235+
echo ' install - Install kernel using (your) ~/bin/$(INSTALLKERNEL) or'
236+
echo ' (distribution) /sbin/$(INSTALLKERNEL) or install to '
237+
echo ' $$(INSTALL_PATH)'
238+
endef

arch/riscv/boot/install.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
# $3 - kernel map file
1818
# $4 - default install path (blank if root directory)
1919

20-
if [ "$(basename $2)" = "Image.gz" ]; then
20+
case "${2##*/}" in
2121
# Compressed install
22+
Image.*|vmlinuz.efi)
2223
echo "Installing compressed kernel"
2324
base=vmlinuz
24-
else
25+
;;
2526
# Normal install
27+
*)
2628
echo "Installing normal kernel"
2729
base=vmlinux
28-
fi
30+
;;
31+
esac
2932

3033
if [ -f $4/$base-$1 ]; then
3134
mv $4/$base-$1 $4/$base-$1.old

arch/riscv/include/asm/cacheflush.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ static inline void local_flush_icache_all(void)
1313
asm volatile ("fence.i" ::: "memory");
1414
}
1515

16+
static inline void local_flush_icache_range(unsigned long start,
17+
unsigned long end)
18+
{
19+
local_flush_icache_all();
20+
}
21+
1622
#define PG_dcache_clean PG_arch_1
1723

1824
static inline void flush_dcache_folio(struct folio *folio)

arch/riscv/include/asm/ftrace.h

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,82 @@ struct dyn_ftrace;
124124
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
125125
#define ftrace_init_nop ftrace_init_nop
126126

127-
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
127+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
128+
#define arch_ftrace_get_regs(regs) NULL
128129
struct ftrace_ops;
129-
struct ftrace_regs;
130+
struct ftrace_regs {
131+
unsigned long epc;
132+
unsigned long ra;
133+
unsigned long sp;
134+
unsigned long s0;
135+
unsigned long t1;
136+
union {
137+
unsigned long args[8];
138+
struct {
139+
unsigned long a0;
140+
unsigned long a1;
141+
unsigned long a2;
142+
unsigned long a3;
143+
unsigned long a4;
144+
unsigned long a5;
145+
unsigned long a6;
146+
unsigned long a7;
147+
};
148+
};
149+
};
150+
151+
static __always_inline unsigned long ftrace_regs_get_instruction_pointer(const struct ftrace_regs
152+
*fregs)
153+
{
154+
return fregs->epc;
155+
}
156+
157+
static __always_inline void ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
158+
unsigned long pc)
159+
{
160+
fregs->epc = pc;
161+
}
162+
163+
static __always_inline unsigned long ftrace_regs_get_stack_pointer(const struct ftrace_regs *fregs)
164+
{
165+
return fregs->sp;
166+
}
167+
168+
static __always_inline unsigned long ftrace_regs_get_argument(struct ftrace_regs *fregs,
169+
unsigned int n)
170+
{
171+
if (n < 8)
172+
return fregs->args[n];
173+
return 0;
174+
}
175+
176+
static __always_inline unsigned long ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
177+
{
178+
return fregs->a0;
179+
}
180+
181+
static __always_inline void ftrace_regs_set_return_value(struct ftrace_regs *fregs,
182+
unsigned long ret)
183+
{
184+
fregs->a0 = ret;
185+
}
186+
187+
static __always_inline void ftrace_override_function_with_return(struct ftrace_regs *fregs)
188+
{
189+
fregs->epc = fregs->ra;
190+
}
191+
192+
int ftrace_regs_query_register_offset(const char *name);
193+
130194
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
131195
struct ftrace_ops *op, struct ftrace_regs *fregs);
132196
#define ftrace_graph_func ftrace_graph_func
133197

134-
static inline void __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
198+
static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsigned long addr)
135199
{
136-
regs->t1 = addr;
200+
fregs->t1 = addr;
137201
}
138-
#define arch_ftrace_set_direct_caller(fregs, addr) \
139-
__arch_ftrace_set_direct_caller(&(fregs)->regs, addr)
140-
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
202+
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_ARGS */
141203

142204
#endif /* __ASSEMBLY__ */
143205

arch/riscv/include/asm/pgtable-64.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ extern bool pgtable_l5_enabled;
1616
#define PGDIR_SHIFT_L3 30
1717
#define PGDIR_SHIFT_L4 39
1818
#define PGDIR_SHIFT_L5 48
19-
#define PGDIR_SIZE_L3 (_AC(1, UL) << PGDIR_SHIFT_L3)
20-
2119
#define PGDIR_SHIFT (pgtable_l5_enabled ? PGDIR_SHIFT_L5 : \
2220
(pgtable_l4_enabled ? PGDIR_SHIFT_L4 : PGDIR_SHIFT_L3))
2321
/* Size of region mapped by a page global directory */

arch/riscv/include/asm/pgtable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
880880
*/
881881
#ifdef CONFIG_64BIT
882882
#define TASK_SIZE_64 (PGDIR_SIZE * PTRS_PER_PGD / 2)
883-
#define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2)
883+
#define TASK_SIZE_MAX LONG_MAX
884884

885885
#ifdef CONFIG_COMPAT
886886
#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE)
@@ -892,7 +892,6 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
892892

893893
#else
894894
#define TASK_SIZE FIXADDR_START
895-
#define TASK_SIZE_MIN TASK_SIZE
896895
#endif
897896

898897
#else /* CONFIG_MMU */

arch/riscv/include/asm/sbi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return -1
382382
static inline void sbi_init(void) {}
383383
#endif /* CONFIG_RISCV_SBI */
384384

385+
unsigned long riscv_get_mvendorid(void);
386+
unsigned long riscv_get_marchid(void);
385387
unsigned long riscv_cached_mvendorid(unsigned int cpu_id);
386388
unsigned long riscv_cached_marchid(unsigned int cpu_id);
387389
unsigned long riscv_cached_mimpid(unsigned int cpu_id);

arch/riscv/kernel/asm-offsets.c

Lines changed: 18 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/ftrace.h>
1213
#include <linux/suspend.h>
1314
#include <asm/kvm_host.h>
1415
#include <asm/thread_info.h>
@@ -488,4 +489,21 @@ void asm_offsets(void)
488489
DEFINE(STACKFRAME_SIZE_ON_STACK, ALIGN(sizeof(struct stackframe), STACK_ALIGN));
489490
OFFSET(STACKFRAME_FP, stackframe, fp);
490491
OFFSET(STACKFRAME_RA, stackframe, ra);
492+
493+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
494+
DEFINE(FREGS_SIZE_ON_STACK, ALIGN(sizeof(struct ftrace_regs), STACK_ALIGN));
495+
DEFINE(FREGS_EPC, offsetof(struct ftrace_regs, epc));
496+
DEFINE(FREGS_RA, offsetof(struct ftrace_regs, ra));
497+
DEFINE(FREGS_SP, offsetof(struct ftrace_regs, sp));
498+
DEFINE(FREGS_S0, offsetof(struct ftrace_regs, s0));
499+
DEFINE(FREGS_T1, offsetof(struct ftrace_regs, t1));
500+
DEFINE(FREGS_A0, offsetof(struct ftrace_regs, a0));
501+
DEFINE(FREGS_A1, offsetof(struct ftrace_regs, a1));
502+
DEFINE(FREGS_A2, offsetof(struct ftrace_regs, a2));
503+
DEFINE(FREGS_A3, offsetof(struct ftrace_regs, a3));
504+
DEFINE(FREGS_A4, offsetof(struct ftrace_regs, a4));
505+
DEFINE(FREGS_A5, offsetof(struct ftrace_regs, a5));
506+
DEFINE(FREGS_A6, offsetof(struct ftrace_regs, a6));
507+
DEFINE(FREGS_A7, offsetof(struct ftrace_regs, a7));
508+
#endif
491509
}

arch/riscv/kernel/cpu.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,34 @@ int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid)
139139
return -1;
140140
}
141141

142+
unsigned long __init riscv_get_marchid(void)
143+
{
144+
struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
145+
146+
#if IS_ENABLED(CONFIG_RISCV_SBI)
147+
ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
148+
#elif IS_ENABLED(CONFIG_RISCV_M_MODE)
149+
ci->marchid = csr_read(CSR_MARCHID);
150+
#else
151+
ci->marchid = 0;
152+
#endif
153+
return ci->marchid;
154+
}
155+
156+
unsigned long __init riscv_get_mvendorid(void)
157+
{
158+
struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
159+
160+
#if IS_ENABLED(CONFIG_RISCV_SBI)
161+
ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
162+
#elif IS_ENABLED(CONFIG_RISCV_M_MODE)
163+
ci->mvendorid = csr_read(CSR_MVENDORID);
164+
#else
165+
ci->mvendorid = 0;
166+
#endif
167+
return ci->mvendorid;
168+
}
169+
142170
DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo);
143171

144172
unsigned long riscv_cached_mvendorid(unsigned int cpu_id)
@@ -170,12 +198,16 @@ static int riscv_cpuinfo_starting(unsigned int cpu)
170198
struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo);
171199

172200
#if IS_ENABLED(CONFIG_RISCV_SBI)
173-
ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
174-
ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
201+
if (!ci->mvendorid)
202+
ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid();
203+
if (!ci->marchid)
204+
ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid();
175205
ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid();
176206
#elif IS_ENABLED(CONFIG_RISCV_M_MODE)
177-
ci->mvendorid = csr_read(CSR_MVENDORID);
178-
ci->marchid = csr_read(CSR_MARCHID);
207+
if (!ci->mvendorid)
208+
ci->mvendorid = csr_read(CSR_MVENDORID);
209+
if (!ci->marchid)
210+
ci->marchid = csr_read(CSR_MARCHID);
179211
ci->mimpid = csr_read(CSR_MIMPID);
180212
#else
181213
ci->mvendorid = 0;

0 commit comments

Comments
 (0)