Skip to content

Commit e0152e7

Browse files
committed
Merge tag 'riscv-for-linus-6.6-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V updates from Palmer Dabbelt: - Support for the new "riscv,isa-extensions" and "riscv,isa-base" device tree interfaces for probing extensions - Support for userspace access to the performance counters - Support for more instructions in kprobes - Crash kernels can be allocated above 4GiB - Support for KCFI - Support for ELFs in !MMU configurations - ARCH_KMALLOC_MINALIGN has been reduced to 8 - mmap() defaults to sv48-sized addresses, with longer addresses hidden behind a hint (similar to Arm and Intel) - Also various fixes and cleanups * tag 'riscv-for-linus-6.6-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (51 commits) lib/Kconfig.debug: Restrict DEBUG_INFO_SPLIT for RISC-V riscv: support PREEMPT_DYNAMIC with static keys riscv: Move create_tmp_mapping() to init sections riscv: Mark KASAN tmp* page tables variables as static riscv: mm: use bitmap_zero() API riscv: enable DEBUG_FORCE_FUNCTION_ALIGN_64B riscv: remove redundant mv instructions RISC-V: mm: Document mmap changes RISC-V: mm: Update pgtable comment documentation RISC-V: mm: Add tests for RISC-V mm RISC-V: mm: Restrict address space for sv39,sv48,sv57 riscv: enable DMA_BOUNCE_UNALIGNED_KMALLOC for !dma_coherent riscv: allow kmalloc() caches aligned to the smallest value riscv: support the elf-fdpic binfmt loader binfmt_elf_fdpic: support 64-bit systems riscv: Allow CONFIG_CFI_CLANG to be selected riscv/purgatory: Disable CFI riscv: Add CFI error handling riscv: Add ftrace_stub_graph riscv: Add types to indirectly called assembly functions ...
2 parents a031eba + 89775a2 commit e0152e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1707
-407
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@
873873
memory region [offset, offset + size] for that kernel
874874
image. If '@offset' is omitted, then a suitable offset
875875
is selected automatically.
876-
[KNL, X86-64, ARM64] Select a region under 4G first, and
876+
[KNL, X86-64, ARM64, RISCV] Select a region under 4G first, and
877877
fall back to reserve region above 4G when '@offset'
878878
hasn't been specified.
879879
See Documentation/admin-guide/kdump/kdump.rst for further details.
@@ -886,14 +886,14 @@
886886
Documentation/admin-guide/kdump/kdump.rst for an example.
887887

888888
crashkernel=size[KMG],high
889-
[KNL, X86-64, ARM64] range could be above 4G. Allow kernel
890-
to allocate physical memory region from top, so could
891-
be above 4G if system have more than 4G ram installed.
892-
Otherwise memory region will be allocated below 4G, if
893-
available.
889+
[KNL, X86-64, ARM64, RISCV] range could be above 4G.
890+
Allow kernel to allocate physical memory region from top,
891+
so could be above 4G if system have more than 4G ram
892+
installed. Otherwise memory region will be allocated
893+
below 4G, if available.
894894
It will be ignored if crashkernel=X is specified.
895895
crashkernel=size[KMG],low
896-
[KNL, X86-64, ARM64] range under 4G. When crashkernel=X,high
896+
[KNL, X86-64, ARM64, RISCV] range under 4G. When crashkernel=X,high
897897
is passed, kernel could allocate physical memory region
898898
above 4G, that cause second kernel crash on system
899899
that require some amount of low memory, e.g. swiotlb
@@ -904,6 +904,7 @@
904904
size is platform dependent.
905905
--> x86: max(swiotlb_size_or_default() + 8MiB, 256MiB)
906906
--> arm64: 128MiB
907+
--> riscv: 128MiB
907908
This one lets the user specify own low range under 4G
908909
for second kernel instead.
909910
0: to disable low allocation.
@@ -5554,6 +5555,13 @@
55545555
[KNL] Disable ring 3 MONITOR/MWAIT feature on supported
55555556
CPUs.
55565557

5558+
riscv_isa_fallback [RISCV]
5559+
When CONFIG_RISCV_ISA_FALLBACK is not enabled, permit
5560+
falling back to detecting extension support by parsing
5561+
"riscv,isa" property on devicetree systems when the
5562+
replacement properties are not found. See the Kconfig
5563+
entry for RISCV_ISA_FALLBACK.
5564+
55575565
ro [KNL] Mount root device read-only on boot
55585566

55595567
rodata= [KNL]

Documentation/admin-guide/sysctl/kernel.rst

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,16 +941,35 @@ enabled, otherwise writing to this file will return ``-EBUSY``.
941941
The default value is 8.
942942

943943

944-
perf_user_access (arm64 only)
945-
=================================
944+
perf_user_access (arm64 and riscv only)
945+
=======================================
946+
947+
Controls user space access for reading perf event counters.
946948

947-
Controls user space access for reading perf event counters. When set to 1,
948-
user space can read performance monitor counter registers directly.
949+
arm64
950+
=====
949951

950952
The default value is 0 (access disabled).
951953

954+
When set to 1, user space can read performance monitor counter registers
955+
directly.
956+
952957
See Documentation/arch/arm64/perf.rst for more information.
953958

959+
riscv
960+
=====
961+
962+
When set to 0, user space access is disabled.
963+
964+
The default value is 1, user space can read performance monitor counter
965+
registers through perf, any direct access without perf intervention will trigger
966+
an illegal instruction.
967+
968+
When set to 2, which enables legacy mode (user space has direct access to cycle
969+
and insret CSRs only). Note that this legacy value is deprecated and will be
970+
removed once all user space applications are fixed.
971+
972+
Note that the time CSR is always directly accessible to all modes.
954973

955974
pid_max
956975
=======

Documentation/riscv/vm-layout.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,25 @@ RISC-V Linux Kernel SV57
133133
ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
134134
ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
135135
__________________|____________|__________________|_________|____________________________________________________________
136+
137+
138+
Userspace VAs
139+
--------------------
140+
To maintain compatibility with software that relies on the VA space with a
141+
maximum of 48 bits the kernel will, by default, return virtual addresses to
142+
userspace from a 48-bit range (sv48). This default behavior is achieved by
143+
passing 0 into the hint address parameter of mmap. On CPUs with an address space
144+
smaller than sv48, the CPU maximum supported address space will be the default.
145+
146+
Software can "opt-in" to receiving VAs from another VA space by providing
147+
a hint address to mmap. A hint address passed to mmap will cause the largest
148+
address space that fits entirely into the hint to be used, unless there is no
149+
space left in the address space. If there is no space available in the requested
150+
address space, an address in the next smallest available address space will be
151+
returned.
152+
153+
For example, in order to obtain 48-bit VA space, a hint address greater than
154+
:code:`1 << 47` must be provided. Note that this is 47 due to sv48 userspace
155+
ending at :code:`1 << 47` and the addresses beyond this are reserved for the
156+
kernel. Similarly, to obtain 57-bit VA space addresses, a hint address greater
157+
than or equal to :code:`1 << 56` must be provided.

arch/riscv/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@ config RISCV
3535
select ARCH_HAS_SET_MEMORY if MMU
3636
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
3737
select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL
38+
select ARCH_HAS_SYSCALL_WRAPPER
3839
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
3940
select ARCH_HAS_UBSAN_SANITIZE_ALL
4041
select ARCH_HAS_VDSO_DATA
4142
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
4243
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
4344
select ARCH_STACKWALK
4445
select ARCH_SUPPORTS_ATOMIC_RMW
46+
select ARCH_SUPPORTS_CFI_CLANG
4547
select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
4648
select ARCH_SUPPORTS_HUGETLBFS if MMU
4749
select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
4850
select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
4951
select ARCH_USE_MEMTEST
5052
select ARCH_USE_QUEUED_RWLOCKS
53+
select ARCH_USES_CFI_TRAPS if CFI_CLANG
5154
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
5255
select ARCH_WANT_FRAME_POINTERS
5356
select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT
@@ -62,6 +65,7 @@ config RISCV
6265
select COMMON_CLK
6366
select CPU_PM if CPU_IDLE || HIBERNATION
6467
select EDAC_SUPPORT
68+
select FRAME_POINTER if PERF_EVENTS || (FUNCTION_TRACER && !DYNAMIC_FTRACE)
6569
select GENERIC_ARCH_TOPOLOGY
6670
select GENERIC_ATOMIC64 if !64BIT
6771
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
@@ -130,6 +134,7 @@ config RISCV
130134
select HAVE_PERF_REGS
131135
select HAVE_PERF_USER_STACK_DUMP
132136
select HAVE_POSIX_CPU_TIMERS_TASK_WORK
137+
select HAVE_PREEMPT_DYNAMIC_KEY if !XIP_KERNEL
133138
select HAVE_REGS_AND_STACK_ACCESS_API
134139
select HAVE_RETHOOK if !XIP_KERNEL
135140
select HAVE_RSEQ
@@ -267,6 +272,7 @@ config RISCV_DMA_NONCOHERENT
267272
select ARCH_HAS_SETUP_DMA_OPS
268273
select ARCH_HAS_SYNC_DMA_FOR_CPU
269274
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
275+
select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
270276
select DMA_DIRECT_REMAP
271277

272278
config AS_HAS_INSN
@@ -836,6 +842,24 @@ config XIP_PHYS_ADDR
836842
be linked for and stored to. This address is dependent on your
837843
own flash usage.
838844

845+
config RISCV_ISA_FALLBACK
846+
bool "Permit falling back to parsing riscv,isa for extension support by default"
847+
default y
848+
help
849+
Parsing the "riscv,isa" devicetree property has been deprecated and
850+
replaced by a list of explicitly defined strings. For compatibility
851+
with existing platforms, the kernel will fall back to parsing the
852+
"riscv,isa" property if the replacements are not found.
853+
854+
Selecting N here will result in a kernel that does not use the
855+
fallback, unless the commandline "riscv_isa_fallback" parameter is
856+
present.
857+
858+
Please see the dt-binding, located at
859+
Documentation/devicetree/bindings/riscv/extensions.yaml for details
860+
on the replacement properties, "riscv,isa-base" and
861+
"riscv,isa-extensions".
862+
839863
endmenu # "Boot options"
840864

841865
config BUILTIN_DTB

arch/riscv/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ endif
8787
ifeq ($(CONFIG_CMODEL_MEDANY),y)
8888
KBUILD_CFLAGS += -mcmodel=medany
8989
endif
90-
ifeq ($(CONFIG_PERF_EVENTS),y)
91-
KBUILD_CFLAGS += -fno-omit-frame-pointer
92-
endif
9390

9491
# Avoid generating .eh_frame sections.
9592
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables

arch/riscv/include/asm/alternative-macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
* vendor_id: The CPU vendor ID.
147147
* patch_id: The patch ID (erratum ID or cpufeature ID).
148148
* CONFIG_k: The Kconfig of this patch ID. When Kconfig is disabled, the old
149-
* content will alwyas be executed.
149+
* content will always be executed.
150150
*/
151151
#define ALTERNATIVE(old_content, new_content, vendor_id, patch_id, CONFIG_k) \
152152
_ALTERNATIVE_CFG(old_content, new_content, vendor_id, patch_id, CONFIG_k)

arch/riscv/include/asm/cache.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#ifdef CONFIG_RISCV_DMA_NONCOHERENT
1515
#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
16+
#define ARCH_KMALLOC_MINALIGN (8)
1617
#endif
1718

1819
/*
@@ -23,4 +24,17 @@
2324
#define ARCH_SLAB_MINALIGN 16
2425
#endif
2526

27+
#ifndef __ASSEMBLY__
28+
29+
#ifdef CONFIG_RISCV_DMA_NONCOHERENT
30+
extern int dma_cache_alignment;
31+
#define dma_get_cache_alignment dma_get_cache_alignment
32+
static inline int dma_get_cache_alignment(void)
33+
{
34+
return dma_cache_alignment;
35+
}
36+
#endif
37+
38+
#endif /* __ASSEMBLY__ */
39+
2640
#endif /* _ASM_RISCV_CACHE_H */

arch/riscv/include/asm/cacheflush.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ void riscv_init_cbo_blocksizes(void);
5858

5959
#ifdef CONFIG_RISCV_DMA_NONCOHERENT
6060
void riscv_noncoherent_supported(void);
61+
void __init riscv_set_dma_cache_alignment(void);
6162
#else
6263
static inline void riscv_noncoherent_supported(void) {}
64+
static inline void riscv_set_dma_cache_alignment(void) {}
6365
#endif
6466

6567
/*

arch/riscv/include/asm/cfi.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_RISCV_CFI_H
3+
#define _ASM_RISCV_CFI_H
4+
5+
/*
6+
* Clang Control Flow Integrity (CFI) support.
7+
*
8+
* Copyright (C) 2023 Google LLC
9+
*/
10+
11+
#include <linux/cfi.h>
12+
13+
#ifdef CONFIG_CFI_CLANG
14+
enum bug_trap_type handle_cfi_failure(struct pt_regs *regs);
15+
#else
16+
static inline enum bug_trap_type handle_cfi_failure(struct pt_regs *regs)
17+
{
18+
return BUG_TRAP_TYPE_NONE;
19+
}
20+
#endif /* CONFIG_CFI_CLANG */
21+
22+
#endif /* _ASM_RISCV_CFI_H */

arch/riscv/include/asm/elf.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
4141
#define compat_elf_check_arch compat_elf_check_arch
4242

4343
#define CORE_DUMP_USE_REGSET
44+
#define ELF_FDPIC_CORE_EFLAGS 0
4445
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
4546

4647
/*
@@ -49,7 +50,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
4950
* the loader. We need to make sure that it is out of the way of the program
5051
* that it will "exec", and that there is sufficient room for the brk.
5152
*/
52-
#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
53+
#define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2)
5354

5455
#ifdef CONFIG_64BIT
5556
#ifdef CONFIG_COMPAT
@@ -69,6 +70,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
6970
#define ELF_HWCAP riscv_get_elf_hwcap()
7071
extern unsigned long elf_hwcap;
7172

73+
#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
74+
do { \
75+
(_r)->a1 = _exec_map_addr; \
76+
(_r)->a2 = _interp_map_addr; \
77+
(_r)->a3 = dynamic_addr; \
78+
} while (0)
79+
7280
/*
7381
* This yields a string that ld.so will use to load implementation
7482
* specific libraries for optimization. This is more specific in
@@ -78,7 +86,6 @@ extern unsigned long elf_hwcap;
7886

7987
#define COMPAT_ELF_PLATFORM (NULL)
8088

81-
#ifdef CONFIG_MMU
8289
#define ARCH_DLINFO \
8390
do { \
8491
/* \
@@ -115,6 +122,8 @@ do { \
115122
else \
116123
NEW_AUX_ENT(AT_IGNORE, 0); \
117124
} while (0)
125+
126+
#ifdef CONFIG_MMU
118127
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
119128
struct linux_binprm;
120129
extern int arch_setup_additional_pages(struct linux_binprm *bprm,

0 commit comments

Comments
 (0)