mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
Merge tag 'riscv-for-linus-6.8-mw4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull more RISC-V updates from Palmer Dabbelt: - Support for tuning for systems with fast misaligned accesses. - Support for SBI-based suspend. - Support for the new SBI debug console extension. - The T-Head CMOs now use PA-based flushes. - Support for enabling the V extension in kernel code. - Optimized IP checksum routines. - Various ftrace improvements. - Support for archrandom, which depends on the Zkr extension. - The build is no longer broken under NET=n, KUNIT=y for ports that don't define their own ipv6 checksum. * tag 'riscv-for-linus-6.8-mw4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: (56 commits) lib: checksum: Fix build with CONFIG_NET=n riscv: lib: Check if output in asm goto supported riscv: Fix build error on rv32 + XIP riscv: optimize ELF relocation function in riscv RISC-V: Implement archrandom when Zkr is available riscv: Optimize hweight API with Zbb extension riscv: add dependency among Image(.gz), loader(.bin), and vmlinuz.efi samples: ftrace: Add RISC-V support for SAMPLE_FTRACE_DIRECT[_MULTI] riscv: ftrace: Add DYNAMIC_FTRACE_WITH_DIRECT_CALLS support riscv: ftrace: Make function graph use ftrace directly riscv: select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY lib/Kconfig.debug: Update AS_HAS_NON_CONST_LEB128 comment and name riscv: Restrict DWARF5 when building with LLVM to known working versions riscv: Hoist linker relaxation disabling logic into Kconfig kunit: Add tests for csum_ipv6_magic and ip_fast_csum riscv: Add checksum library riscv: Add checksum header riscv: Add static key for misaligned accesses asm-generic: Improve csum_fold RISC-V: selftests: cbo: Ensure asm operands match constraints ...
This commit is contained in:
@@ -63,8 +63,8 @@ properties:
|
||||
|
||||
mmu-type:
|
||||
description:
|
||||
Identifies the MMU address translation mode used on this
|
||||
hart. These values originate from the RISC-V Privileged
|
||||
Identifies the largest MMU address translation mode supported by
|
||||
this hart. These values originate from the RISC-V Privileged
|
||||
Specification document, available from
|
||||
https://riscv.org/specifications/
|
||||
$ref: /schemas/types.yaml#/definitions/string
|
||||
@@ -80,6 +80,11 @@ properties:
|
||||
description:
|
||||
The blocksize in bytes for the Zicbom cache operations.
|
||||
|
||||
riscv,cbop-block-size:
|
||||
$ref: /schemas/types.yaml#/definitions/uint32
|
||||
description:
|
||||
The blocksize in bytes for the Zicbop cache operations.
|
||||
|
||||
riscv,cboz-block-size:
|
||||
$ref: /schemas/types.yaml#/definitions/uint32
|
||||
description:
|
||||
|
||||
@@ -48,7 +48,7 @@ properties:
|
||||
insensitive, letters in the riscv,isa string must be all
|
||||
lowercase.
|
||||
$ref: /schemas/types.yaml#/definitions/string
|
||||
pattern: ^rv(?:64|32)imaf?d?q?c?b?k?j?p?v?h?(?:[hsxz](?:[a-z])+)?(?:_[hsxz](?:[a-z])+)*$
|
||||
pattern: ^rv(?:64|32)imaf?d?q?c?b?k?j?p?v?h?(?:[hsxz](?:[0-9a-z])+)?(?:_[hsxz](?:[0-9a-z])+)*$
|
||||
deprecated: true
|
||||
|
||||
riscv,isa-base:
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
| openrisc: | .. |
|
||||
| parisc: | TODO |
|
||||
| powerpc: | TODO |
|
||||
| riscv: | TODO |
|
||||
| riscv: | ok |
|
||||
| s390: | TODO |
|
||||
| sh: | TODO |
|
||||
| sparc: | TODO |
|
||||
|
||||
@@ -53,6 +53,7 @@ config RISCV
|
||||
select ARCH_USE_MEMTEST
|
||||
select ARCH_USE_QUEUED_RWLOCKS
|
||||
select ARCH_USES_CFI_TRAPS if CFI_CLANG
|
||||
select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH if SMP && MMU
|
||||
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
|
||||
select ARCH_WANT_FRAME_POINTERS
|
||||
select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT
|
||||
@@ -66,9 +67,10 @@ config RISCV
|
||||
select CLINT_TIMER if !MMU
|
||||
select CLONE_BACKWARDS
|
||||
select COMMON_CLK
|
||||
select CPU_PM if CPU_IDLE || HIBERNATION
|
||||
select CPU_PM if CPU_IDLE || HIBERNATION || SUSPEND
|
||||
select EDAC_SUPPORT
|
||||
select FRAME_POINTER if PERF_EVENTS || (FUNCTION_TRACER && !DYNAMIC_FTRACE)
|
||||
select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE
|
||||
select GENERIC_ARCH_TOPOLOGY
|
||||
select GENERIC_ATOMIC64 if !64BIT
|
||||
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
|
||||
@@ -115,6 +117,7 @@ config RISCV
|
||||
select HAVE_DEBUG_KMEMLEAK
|
||||
select HAVE_DMA_CONTIGUOUS if MMU
|
||||
select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
|
||||
select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
|
||||
select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
|
||||
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
|
||||
select HAVE_FUNCTION_GRAPH_TRACER
|
||||
@@ -142,6 +145,8 @@ config RISCV
|
||||
select HAVE_REGS_AND_STACK_ACCESS_API
|
||||
select HAVE_RETHOOK if !XIP_KERNEL
|
||||
select HAVE_RSEQ
|
||||
select HAVE_SAMPLE_FTRACE_DIRECT
|
||||
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
|
||||
select HAVE_STACKPROTECTOR
|
||||
select HAVE_SYSCALL_TRACEPOINTS
|
||||
select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU
|
||||
@@ -183,6 +188,20 @@ config HAVE_SHADOW_CALL_STACK
|
||||
# https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/a484e843e6eeb51f0cb7b8819e50da6d2444d769
|
||||
depends on $(ld-option,--no-relax-gp)
|
||||
|
||||
config RISCV_USE_LINKER_RELAXATION
|
||||
def_bool y
|
||||
# https://github.com/llvm/llvm-project/commit/6611d58f5bbcbec77262d392e2923e1d680f6985
|
||||
depends on !LD_IS_LLD || LLD_VERSION >= 150000
|
||||
|
||||
# https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
|
||||
config ARCH_HAS_BROKEN_DWARF5
|
||||
def_bool y
|
||||
depends on RISCV_USE_LINKER_RELAXATION
|
||||
# https://github.com/llvm/llvm-project/commit/1df5ea29b43690b6622db2cad7b745607ca4de6a
|
||||
depends on AS_IS_LLVM && AS_VERSION < 180000
|
||||
# https://github.com/llvm/llvm-project/commit/7ffabb61a5569444b5ac9322e22e5471cc5e4a77
|
||||
depends on LD_IS_LLD && LLD_VERSION < 180000
|
||||
|
||||
config ARCH_MMAP_RND_BITS_MIN
|
||||
default 18 if 64BIT
|
||||
default 8
|
||||
@@ -529,6 +548,28 @@ config RISCV_ISA_V_DEFAULT_ENABLE
|
||||
|
||||
If you don't know what to do here, say Y.
|
||||
|
||||
config RISCV_ISA_V_UCOPY_THRESHOLD
|
||||
int "Threshold size for vectorized user copies"
|
||||
depends on RISCV_ISA_V
|
||||
default 768
|
||||
help
|
||||
Prefer using vectorized copy_to_user()/copy_from_user() when the
|
||||
workload size exceeds this value.
|
||||
|
||||
config RISCV_ISA_V_PREEMPTIVE
|
||||
bool "Run kernel-mode Vector with kernel preemption"
|
||||
depends on PREEMPTION
|
||||
depends on RISCV_ISA_V
|
||||
default y
|
||||
help
|
||||
Usually, in-kernel SIMD routines are run with preemption disabled.
|
||||
Functions which envoke long running SIMD thus must yield core's
|
||||
vector unit to prevent blocking other tasks for too long.
|
||||
|
||||
This config allows kernel to run SIMD without explicitly disable
|
||||
preemption. Enabling this config will result in higher memory
|
||||
consumption due to the allocation of per-task's kernel Vector context.
|
||||
|
||||
config TOOLCHAIN_HAS_ZBB
|
||||
bool
|
||||
default y
|
||||
@@ -655,6 +696,20 @@ config RISCV_MISALIGNED
|
||||
load/store for both kernel and userspace. When disable, misaligned
|
||||
accesses will generate SIGBUS in userspace and panic in kernel.
|
||||
|
||||
config RISCV_EFFICIENT_UNALIGNED_ACCESS
|
||||
bool "Assume the CPU supports fast unaligned memory accesses"
|
||||
depends on NONPORTABLE
|
||||
select DCACHE_WORD_ACCESS if MMU
|
||||
select HAVE_EFFICIENT_UNALIGNED_ACCESS
|
||||
help
|
||||
Say Y here if you want the kernel to assume that the CPU supports
|
||||
efficient unaligned memory accesses. When enabled, this option
|
||||
improves the performance of the kernel on such CPUs. However, the
|
||||
kernel will run much more slowly, or will not be able to run at all,
|
||||
on CPUs that do not support efficient unaligned memory accesses.
|
||||
|
||||
If unsure what to do here, say N.
|
||||
|
||||
endmenu # "Platform type"
|
||||
|
||||
menu "Kernel features"
|
||||
|
||||
@@ -98,6 +98,7 @@ config ERRATA_THEAD_CMO
|
||||
depends on ERRATA_THEAD && MMU
|
||||
select DMA_DIRECT_REMAP
|
||||
select RISCV_DMA_NONCOHERENT
|
||||
select RISCV_NONSTANDARD_CACHE_OPS
|
||||
default y
|
||||
help
|
||||
This will apply the cache management errata to handle the
|
||||
|
||||
@@ -43,8 +43,7 @@ else
|
||||
KBUILD_LDFLAGS += -melf32lriscv
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LD_IS_LLD),y)
|
||||
ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y)
|
||||
ifndef CONFIG_RISCV_USE_LINKER_RELAXATION
|
||||
KBUILD_CFLAGS += -mno-relax
|
||||
KBUILD_AFLAGS += -mno-relax
|
||||
ifndef CONFIG_AS_IS_LLVM
|
||||
@@ -52,7 +51,6 @@ ifndef CONFIG_AS_IS_LLVM
|
||||
KBUILD_AFLAGS += -Wa,-mno-relax
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SHADOW_CALL_STACK),y)
|
||||
KBUILD_LDFLAGS += --no-relax-gp
|
||||
@@ -108,7 +106,9 @@ KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
|
||||
# unaligned accesses. While unaligned accesses are explicitly allowed in the
|
||||
# RISC-V ISA, they're emulated by machine mode traps on all extant
|
||||
# architectures. It's faster to have GCC emit only aligned accesses.
|
||||
ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y)
|
||||
KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
|
||||
prepare: stack_protector_prepare
|
||||
@@ -163,6 +163,8 @@ BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
|
||||
|
||||
all: $(notdir $(KBUILD_IMAGE))
|
||||
|
||||
loader.bin: loader
|
||||
Image.gz loader vmlinuz.efi: Image
|
||||
$(BOOT_TARGETS): vmlinux
|
||||
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
|
||||
@$(kecho) ' Kernel: $(boot)/$@ is ready'
|
||||
|
||||
@@ -149,6 +149,7 @@ CONFIG_SERIAL_8250_CONSOLE=y
|
||||
CONFIG_SERIAL_8250_DW=y
|
||||
CONFIG_SERIAL_OF_PLATFORM=y
|
||||
CONFIG_SERIAL_SH_SCI=y
|
||||
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
|
||||
CONFIG_VIRTIO_CONSOLE=y
|
||||
CONFIG_HW_RANDOM=y
|
||||
CONFIG_HW_RANDOM_VIRTIO=y
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
#include <asm/alternative.h>
|
||||
#include <asm/cacheflush.h>
|
||||
#include <asm/cpufeature.h>
|
||||
#include <asm/dma-noncoherent.h>
|
||||
#include <asm/errata_list.h>
|
||||
#include <asm/hwprobe.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/patch.h>
|
||||
#include <asm/vendorid_list.h>
|
||||
|
||||
@@ -33,6 +35,69 @@ static bool errata_probe_pbmt(unsigned int stage,
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* th.dcache.ipa rs1 (invalidate, physical address)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000001 01010 rs1 000 00000 0001011
|
||||
* th.dcache.iva rs1 (invalidate, virtual address)
|
||||
* 0000001 00110 rs1 000 00000 0001011
|
||||
*
|
||||
* th.dcache.cpa rs1 (clean, physical address)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000001 01001 rs1 000 00000 0001011
|
||||
* th.dcache.cva rs1 (clean, virtual address)
|
||||
* 0000001 00101 rs1 000 00000 0001011
|
||||
*
|
||||
* th.dcache.cipa rs1 (clean then invalidate, physical address)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000001 01011 rs1 000 00000 0001011
|
||||
* th.dcache.civa rs1 (clean then invalidate, virtual address)
|
||||
* 0000001 00111 rs1 000 00000 0001011
|
||||
*
|
||||
* th.sync.s (make sure all cache operations finished)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000000 11001 00000 000 00000 0001011
|
||||
*/
|
||||
#define THEAD_INVAL_A0 ".long 0x02a5000b"
|
||||
#define THEAD_CLEAN_A0 ".long 0x0295000b"
|
||||
#define THEAD_FLUSH_A0 ".long 0x02b5000b"
|
||||
#define THEAD_SYNC_S ".long 0x0190000b"
|
||||
|
||||
#define THEAD_CMO_OP(_op, _start, _size, _cachesize) \
|
||||
asm volatile("mv a0, %1\n\t" \
|
||||
"j 2f\n\t" \
|
||||
"3:\n\t" \
|
||||
THEAD_##_op##_A0 "\n\t" \
|
||||
"add a0, a0, %0\n\t" \
|
||||
"2:\n\t" \
|
||||
"bltu a0, %2, 3b\n\t" \
|
||||
THEAD_SYNC_S \
|
||||
: : "r"(_cachesize), \
|
||||
"r"((unsigned long)(_start) & ~((_cachesize) - 1UL)), \
|
||||
"r"((unsigned long)(_start) + (_size)) \
|
||||
: "a0")
|
||||
|
||||
static void thead_errata_cache_inv(phys_addr_t paddr, size_t size)
|
||||
{
|
||||
THEAD_CMO_OP(INVAL, paddr, size, riscv_cbom_block_size);
|
||||
}
|
||||
|
||||
static void thead_errata_cache_wback(phys_addr_t paddr, size_t size)
|
||||
{
|
||||
THEAD_CMO_OP(CLEAN, paddr, size, riscv_cbom_block_size);
|
||||
}
|
||||
|
||||
static void thead_errata_cache_wback_inv(phys_addr_t paddr, size_t size)
|
||||
{
|
||||
THEAD_CMO_OP(FLUSH, paddr, size, riscv_cbom_block_size);
|
||||
}
|
||||
|
||||
static const struct riscv_nonstd_cache_ops thead_errata_cmo_ops = {
|
||||
.wback = &thead_errata_cache_wback,
|
||||
.inv = &thead_errata_cache_inv,
|
||||
.wback_inv = &thead_errata_cache_wback_inv,
|
||||
};
|
||||
|
||||
static bool errata_probe_cmo(unsigned int stage,
|
||||
unsigned long arch_id, unsigned long impid)
|
||||
{
|
||||
@@ -48,6 +113,7 @@ static bool errata_probe_cmo(unsigned int stage,
|
||||
if (stage == RISCV_ALTERNATIVES_BOOT) {
|
||||
riscv_cbom_block_size = L1_CACHE_BYTES;
|
||||
riscv_noncoherent_supported();
|
||||
riscv_noncoherent_register_cache_ops(&thead_errata_cmo_ops);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -77,8 +143,7 @@ static u32 thead_errata_probe(unsigned int stage,
|
||||
if (errata_probe_pbmt(stage, archid, impid))
|
||||
cpu_req_errata |= BIT(ERRATA_THEAD_PBMT);
|
||||
|
||||
if (errata_probe_cmo(stage, archid, impid))
|
||||
cpu_req_errata |= BIT(ERRATA_THEAD_CMO);
|
||||
errata_probe_cmo(stage, archid, impid);
|
||||
|
||||
if (errata_probe_pmu(stage, archid, impid))
|
||||
cpu_req_errata |= BIT(ERRATA_THEAD_PMU);
|
||||
|
||||
78
arch/riscv/include/asm/arch_hweight.h
Normal file
78
arch/riscv/include/asm/arch_hweight.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Based on arch/x86/include/asm/arch_hweight.h
|
||||
*/
|
||||
|
||||
#ifndef _ASM_RISCV_HWEIGHT_H
|
||||
#define _ASM_RISCV_HWEIGHT_H
|
||||
|
||||
#include <asm/alternative-macros.h>
|
||||
#include <asm/hwcap.h>
|
||||
|
||||
#if (BITS_PER_LONG == 64)
|
||||
#define CPOPW "cpopw "
|
||||
#elif (BITS_PER_LONG == 32)
|
||||
#define CPOPW "cpop "
|
||||
#else
|
||||
#error "Unexpected BITS_PER_LONG"
|
||||
#endif
|
||||
|
||||
static __always_inline unsigned int __arch_hweight32(unsigned int w)
|
||||
{
|
||||
#ifdef CONFIG_RISCV_ISA_ZBB
|
||||
asm_volatile_goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
|
||||
RISCV_ISA_EXT_ZBB, 1)
|
||||
: : : : legacy);
|
||||
|
||||
asm (".option push\n"
|
||||
".option arch,+zbb\n"
|
||||
CPOPW "%0, %0\n"
|
||||
".option pop\n"
|
||||
: "+r" (w) : :);
|
||||
|
||||
return w;
|
||||
|
||||
legacy:
|
||||
#endif
|
||||
return __sw_hweight32(w);
|
||||
}
|
||||
|
||||
static inline unsigned int __arch_hweight16(unsigned int w)
|
||||
{
|
||||
return __arch_hweight32(w & 0xffff);
|
||||
}
|
||||
|
||||
static inline unsigned int __arch_hweight8(unsigned int w)
|
||||
{
|
||||
return __arch_hweight32(w & 0xff);
|
||||
}
|
||||
|
||||
#if BITS_PER_LONG == 64
|
||||
static __always_inline unsigned long __arch_hweight64(__u64 w)
|
||||
{
|
||||
# ifdef CONFIG_RISCV_ISA_ZBB
|
||||
asm_volatile_goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
|
||||
RISCV_ISA_EXT_ZBB, 1)
|
||||
: : : : legacy);
|
||||
|
||||
asm (".option push\n"
|
||||
".option arch,+zbb\n"
|
||||
"cpop %0, %0\n"
|
||||
".option pop\n"
|
||||
: "+r" (w) : :);
|
||||
|
||||
return w;
|
||||
|
||||
legacy:
|
||||
# endif
|
||||
return __sw_hweight64(w);
|
||||
}
|
||||
#else /* BITS_PER_LONG == 64 */
|
||||
static inline unsigned long __arch_hweight64(__u64 w)
|
||||
{
|
||||
return __arch_hweight32((u32)w) +
|
||||
__arch_hweight32((u32)(w >> 32));
|
||||
}
|
||||
#endif /* !(BITS_PER_LONG == 64) */
|
||||
|
||||
#endif /* _ASM_RISCV_HWEIGHT_H */
|
||||
72
arch/riscv/include/asm/archrandom.h
Normal file
72
arch/riscv/include/asm/archrandom.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Kernel interface for the RISCV arch_random_* functions
|
||||
*
|
||||
* Copyright (c) 2023 Rivos Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ASM_RISCV_ARCHRANDOM_H
|
||||
#define ASM_RISCV_ARCHRANDOM_H
|
||||
|
||||
#include <asm/csr.h>
|
||||
#include <asm/processor.h>
|
||||
|
||||
#define SEED_RETRY_LOOPS 100
|
||||
|
||||
static inline bool __must_check csr_seed_long(unsigned long *v)
|
||||
{
|
||||
unsigned int retry = SEED_RETRY_LOOPS, valid_seeds = 0;
|
||||
const int needed_seeds = sizeof(long) / sizeof(u16);
|
||||
u16 *entropy = (u16 *)v;
|
||||
|
||||
do {
|
||||
/*
|
||||
* The SEED CSR must be accessed with a read-write instruction.
|
||||
*/
|
||||
unsigned long csr_seed = csr_swap(CSR_SEED, 0);
|
||||
unsigned long opst = csr_seed & SEED_OPST_MASK;
|
||||
|
||||
switch (opst) {
|
||||
case SEED_OPST_ES16:
|
||||
entropy[valid_seeds++] = csr_seed & SEED_ENTROPY_MASK;
|
||||
if (valid_seeds == needed_seeds)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SEED_OPST_DEAD:
|
||||
pr_err_once("archrandom: Unrecoverable error\n");
|
||||
return false;
|
||||
|
||||
case SEED_OPST_BIST:
|
||||
case SEED_OPST_WAIT:
|
||||
default:
|
||||
cpu_relax();
|
||||
continue;
|
||||
}
|
||||
} while (--retry);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs)
|
||||
{
|
||||
if (!max_longs)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* If Zkr is supported and csr_seed_long succeeds, we return one long
|
||||
* worth of entropy.
|
||||
*/
|
||||
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZKR) && csr_seed_long(v))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* ASM_RISCV_ARCHRANDOM_H */
|
||||
@@ -6,6 +6,7 @@
|
||||
#define EX_TYPE_FIXUP 1
|
||||
#define EX_TYPE_BPF 2
|
||||
#define EX_TYPE_UACCESS_ERR_ZERO 3
|
||||
#define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 4
|
||||
|
||||
#ifdef CONFIG_MMU
|
||||
|
||||
@@ -47,6 +48,11 @@
|
||||
#define EX_DATA_REG_ZERO_SHIFT 5
|
||||
#define EX_DATA_REG_ZERO GENMASK(9, 5)
|
||||
|
||||
#define EX_DATA_REG_DATA_SHIFT 0
|
||||
#define EX_DATA_REG_DATA GENMASK(4, 0)
|
||||
#define EX_DATA_REG_ADDR_SHIFT 5
|
||||
#define EX_DATA_REG_ADDR GENMASK(9, 5)
|
||||
|
||||
#define EX_DATA_REG(reg, gpr) \
|
||||
"((.L__gpr_num_" #gpr ") << " __stringify(EX_DATA_REG_##reg##_SHIFT) ")"
|
||||
|
||||
@@ -62,6 +68,15 @@
|
||||
#define _ASM_EXTABLE_UACCESS_ERR(insn, fixup, err) \
|
||||
_ASM_EXTABLE_UACCESS_ERR_ZERO(insn, fixup, err, zero)
|
||||
|
||||
#define _ASM_EXTABLE_LOAD_UNALIGNED_ZEROPAD(insn, fixup, data, addr) \
|
||||
__DEFINE_ASM_GPR_NUMS \
|
||||
__ASM_EXTABLE_RAW(#insn, #fixup, \
|
||||
__stringify(EX_TYPE_LOAD_UNALIGNED_ZEROPAD), \
|
||||
"(" \
|
||||
EX_DATA_REG(DATA, data) " | " \
|
||||
EX_DATA_REG(ADDR, addr) \
|
||||
")")
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#else /* CONFIG_MMU */
|
||||
|
||||
@@ -9,6 +9,33 @@ long long __lshrti3(long long a, int b);
|
||||
long long __ashrti3(long long a, int b);
|
||||
long long __ashlti3(long long a, int b);
|
||||
|
||||
#ifdef CONFIG_RISCV_ISA_V
|
||||
|
||||
#ifdef CONFIG_MMU
|
||||
asmlinkage int enter_vector_usercopy(void *dst, void *src, size_t n);
|
||||
#endif /* CONFIG_MMU */
|
||||
|
||||
void xor_regs_2_(unsigned long bytes, unsigned long *__restrict p1,
|
||||
const unsigned long *__restrict p2);
|
||||
void xor_regs_3_(unsigned long bytes, unsigned long *__restrict p1,
|
||||
const unsigned long *__restrict p2,
|
||||
const unsigned long *__restrict p3);
|
||||
void xor_regs_4_(unsigned long bytes, unsigned long *__restrict p1,
|
||||
const unsigned long *__restrict p2,
|
||||
const unsigned long *__restrict p3,
|
||||
const unsigned long *__restrict p4);
|
||||
void xor_regs_5_(unsigned long bytes, unsigned long *__restrict p1,
|
||||
const unsigned long *__restrict p2,
|
||||
const unsigned long *__restrict p3,
|
||||
const unsigned long *__restrict p4,
|
||||
const unsigned long *__restrict p5);
|
||||
|
||||
#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE
|
||||
asmlinkage void riscv_v_context_nesting_start(struct pt_regs *regs);
|
||||
asmlinkage void riscv_v_context_nesting_end(struct pt_regs *regs);
|
||||
#endif /* CONFIG_RISCV_ISA_V_PREEMPTIVE */
|
||||
|
||||
#endif /* CONFIG_RISCV_ISA_V */
|
||||
|
||||
#define DECLARE_DO_ERROR_INFO(name) asmlinkage void name(struct pt_regs *regs)
|
||||
|
||||
|
||||
@@ -271,7 +271,9 @@ legacy:
|
||||
#include <asm-generic/bitops/fls64.h>
|
||||
#include <asm-generic/bitops/sched.h>
|
||||
|
||||
#include <asm-generic/bitops/hweight.h>
|
||||
#include <asm/arch_hweight.h>
|
||||
|
||||
#include <asm-generic/bitops/const_hweight.h>
|
||||
|
||||
#if (BITS_PER_LONG == 64)
|
||||
#define __AMO(op) "amo" #op ".d"
|
||||
|
||||
93
arch/riscv/include/asm/checksum.h
Normal file
93
arch/riscv/include/asm/checksum.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Checksum routines
|
||||
*
|
||||
* Copyright (C) 2023 Rivos Inc.
|
||||
*/
|
||||
#ifndef __ASM_RISCV_CHECKSUM_H
|
||||
#define __ASM_RISCV_CHECKSUM_H
|
||||
|
||||
#include <linux/in6.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
||||
#define ip_fast_csum ip_fast_csum
|
||||
|
||||
extern unsigned int do_csum(const unsigned char *buff, int len);
|
||||
#define do_csum do_csum
|
||||
|
||||
/* Default version is sufficient for 32 bit */
|
||||
#ifndef CONFIG_32BIT
|
||||
#define _HAVE_ARCH_IPV6_CSUM
|
||||
__sum16 csum_ipv6_magic(const struct in6_addr *saddr,
|
||||
const struct in6_addr *daddr,
|
||||
__u32 len, __u8 proto, __wsum sum);
|
||||
#endif
|
||||
|
||||
/* Define riscv versions of functions before importing asm-generic/checksum.h */
|
||||
#include <asm-generic/checksum.h>
|
||||
|
||||
/**
|
||||
* Quickly compute an IP checksum with the assumption that IPv4 headers will
|
||||
* always be in multiples of 32-bits, and have an ihl of at least 5.
|
||||
*
|
||||
* @ihl: the number of 32 bit segments and must be greater than or equal to 5.
|
||||
* @iph: assumed to be word aligned given that NET_IP_ALIGN is set to 2 on
|
||||
* riscv, defining IP headers to be aligned.
|
||||
*/
|
||||
static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
|
||||
{
|
||||
unsigned long csum = 0;
|
||||
int pos = 0;
|
||||
|
||||
do {
|
||||
csum += ((const unsigned int *)iph)[pos];
|
||||
if (IS_ENABLED(CONFIG_32BIT))
|
||||
csum += csum < ((const unsigned int *)iph)[pos];
|
||||
} while (++pos < ihl);
|
||||
|
||||
/*
|
||||
* ZBB only saves three instructions on 32-bit and five on 64-bit so not
|
||||
* worth checking if supported without Alternatives.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
|
||||
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
|
||||
unsigned long fold_temp;
|
||||
|
||||
asm_volatile_goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0,
|
||||
RISCV_ISA_EXT_ZBB, 1)
|
||||
:
|
||||
:
|
||||
:
|
||||
: no_zbb);
|
||||
|
||||
if (IS_ENABLED(CONFIG_32BIT)) {
|
||||
asm(".option push \n\
|
||||
.option arch,+zbb \n\
|
||||
not %[fold_temp], %[csum] \n\
|
||||
rori %[csum], %[csum], 16 \n\
|
||||
sub %[csum], %[fold_temp], %[csum] \n\
|
||||
.option pop"
|
||||
: [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp));
|
||||
} else {
|
||||
asm(".option push \n\
|
||||
.option arch,+zbb \n\
|
||||
rori %[fold_temp], %[csum], 32 \n\
|
||||
add %[csum], %[fold_temp], %[csum] \n\
|
||||
srli %[csum], %[csum], 32 \n\
|
||||
not %[fold_temp], %[csum] \n\
|
||||
roriw %[csum], %[csum], 16 \n\
|
||||
subw %[csum], %[fold_temp], %[csum] \n\
|
||||
.option pop"
|
||||
: [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp));
|
||||
}
|
||||
return (__force __sum16)(csum >> 16);
|
||||
}
|
||||
no_zbb:
|
||||
#ifndef CONFIG_32BIT
|
||||
csum += ror64(csum, 32);
|
||||
csum >>= 32;
|
||||
#endif
|
||||
return csum_fold((__force __wsum)csum);
|
||||
}
|
||||
|
||||
#endif /* __ASM_RISCV_CHECKSUM_H */
|
||||
@@ -135,4 +135,6 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi
|
||||
return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
|
||||
}
|
||||
|
||||
DECLARE_STATIC_KEY_FALSE(fast_misaligned_access_speed_key);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -411,6 +411,15 @@
|
||||
#define CSR_VTYPE 0xc21
|
||||
#define CSR_VLENB 0xc22
|
||||
|
||||
/* Scalar Crypto Extension - Entropy */
|
||||
#define CSR_SEED 0x015
|
||||
#define SEED_OPST_MASK _AC(0xC0000000, UL)
|
||||
#define SEED_OPST_BIST _AC(0x00000000, UL)
|
||||
#define SEED_OPST_WAIT _AC(0x40000000, UL)
|
||||
#define SEED_OPST_ES16 _AC(0x80000000, UL)
|
||||
#define SEED_OPST_DEAD _AC(0xC0000000, UL)
|
||||
#define SEED_ENTROPY_MASK _AC(0xFFFF, UL)
|
||||
|
||||
#ifdef CONFIG_RISCV_M_MODE
|
||||
# define CSR_STATUS CSR_MSTATUS
|
||||
# define CSR_IE CSR_MIE
|
||||
|
||||
@@ -4,6 +4,23 @@
|
||||
#define _ASM_RISCV_ENTRY_COMMON_H
|
||||
|
||||
#include <asm/stacktrace.h>
|
||||
#include <asm/thread_info.h>
|
||||
#include <asm/vector.h>
|
||||
|
||||
static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
|
||||
unsigned long ti_work)
|
||||
{
|
||||
if (ti_work & _TIF_RISCV_V_DEFER_RESTORE) {
|
||||
clear_thread_flag(TIF_RISCV_V_DEFER_RESTORE);
|
||||
/*
|
||||
* We are already called with irq disabled, so go without
|
||||
* keeping track of riscv_v_flags.
|
||||
*/
|
||||
riscv_v_vstate_restore(¤t->thread.vstate, regs);
|
||||
}
|
||||
}
|
||||
|
||||
#define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
|
||||
|
||||
void handle_page_fault(struct pt_regs *regs);
|
||||
void handle_break(struct pt_regs *regs);
|
||||
|
||||
@@ -24,9 +24,8 @@
|
||||
|
||||
#ifdef CONFIG_ERRATA_THEAD
|
||||
#define ERRATA_THEAD_PBMT 0
|
||||
#define ERRATA_THEAD_CMO 1
|
||||
#define ERRATA_THEAD_PMU 2
|
||||
#define ERRATA_THEAD_NUMBER 3
|
||||
#define ERRATA_THEAD_PMU 1
|
||||
#define ERRATA_THEAD_NUMBER 2
|
||||
#endif
|
||||
|
||||
#ifdef __ASSEMBLY__
|
||||
@@ -94,54 +93,17 @@ asm volatile(ALTERNATIVE( \
|
||||
#define ALT_THEAD_PMA(_val)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* th.dcache.ipa rs1 (invalidate, physical address)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000001 01010 rs1 000 00000 0001011
|
||||
* th.dache.iva rs1 (invalida, virtual address)
|
||||
* 0000001 00110 rs1 000 00000 0001011
|
||||
*
|
||||
* th.dcache.cpa rs1 (clean, physical address)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000001 01001 rs1 000 00000 0001011
|
||||
* th.dcache.cva rs1 (clean, virtual address)
|
||||
* 0000001 00101 rs1 000 00000 0001011
|
||||
*
|
||||
* th.dcache.cipa rs1 (clean then invalidate, physical address)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000001 01011 rs1 000 00000 0001011
|
||||
* th.dcache.civa rs1 (... virtual address)
|
||||
* 0000001 00111 rs1 000 00000 0001011
|
||||
*
|
||||
* th.sync.s (make sure all cache operations finished)
|
||||
* | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 |
|
||||
* 0000000 11001 00000 000 00000 0001011
|
||||
*/
|
||||
#define THEAD_INVAL_A0 ".long 0x0265000b"
|
||||
#define THEAD_CLEAN_A0 ".long 0x0255000b"
|
||||
#define THEAD_FLUSH_A0 ".long 0x0275000b"
|
||||
#define THEAD_SYNC_S ".long 0x0190000b"
|
||||
|
||||
#define ALT_CMO_OP(_op, _start, _size, _cachesize) \
|
||||
asm volatile(ALTERNATIVE_2( \
|
||||
__nops(6), \
|
||||
asm volatile(ALTERNATIVE( \
|
||||
__nops(5), \
|
||||
"mv a0, %1\n\t" \
|
||||
"j 2f\n\t" \
|
||||
"3:\n\t" \
|
||||
CBO_##_op(a0) \
|
||||
"add a0, a0, %0\n\t" \
|
||||
"2:\n\t" \
|
||||
"bltu a0, %2, 3b\n\t" \
|
||||
"nop", 0, RISCV_ISA_EXT_ZICBOM, CONFIG_RISCV_ISA_ZICBOM, \
|
||||
"mv a0, %1\n\t" \
|
||||
"j 2f\n\t" \
|
||||
"3:\n\t" \
|
||||
THEAD_##_op##_A0 "\n\t" \
|
||||
"add a0, a0, %0\n\t" \
|
||||
"2:\n\t" \
|
||||
"bltu a0, %2, 3b\n\t" \
|
||||
THEAD_SYNC_S, THEAD_VENDOR_ID, \
|
||||
ERRATA_THEAD_CMO, CONFIG_ERRATA_THEAD_CMO) \
|
||||
"bltu a0, %2, 3b\n\t", \
|
||||
0, RISCV_ISA_EXT_ZICBOM, CONFIG_RISCV_ISA_ZICBOM) \
|
||||
: : "r"(_cachesize), \
|
||||
"r"((unsigned long)(_start) & ~((_cachesize) - 1UL)), \
|
||||
"r"((unsigned long)(_start) + (_size)) \
|
||||
|
||||
@@ -128,7 +128,23 @@ do { \
|
||||
struct dyn_ftrace;
|
||||
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
|
||||
#define ftrace_init_nop ftrace_init_nop
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
|
||||
struct ftrace_ops;
|
||||
struct ftrace_regs;
|
||||
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
|
||||
struct ftrace_ops *op, struct ftrace_regs *fregs);
|
||||
#define ftrace_graph_func ftrace_graph_func
|
||||
|
||||
static inline void __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
|
||||
{
|
||||
regs->t1 = addr;
|
||||
}
|
||||
#define arch_ftrace_set_direct_caller(fregs, addr) \
|
||||
__arch_ftrace_set_direct_caller(&(fregs)->regs, addr)
|
||||
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#endif /* CONFIG_DYNAMIC_FTRACE */
|
||||
|
||||
|
||||
@@ -865,7 +865,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
|
||||
#define TASK_SIZE_MIN (PGDIR_SIZE_L3 * PTRS_PER_PGD / 2)
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
#define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE)
|
||||
#define TASK_SIZE_32 (_AC(0x80000000, UL))
|
||||
#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
|
||||
TASK_SIZE_32 : TASK_SIZE_64)
|
||||
#else
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user