Skip to content

Commit 57865f3

Browse files
committed
Merge tag 'riscv-for-linus-6.9-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - A fix for TASK_SIZE on rv64/NOMMU, to reflect the lack of user/kernel separation - A fix to avoid loading rv64/NOMMU kernel past the start of RAM - A fix for RISCV_HWPROBE_EXT_ZVFHMIN on ilp32 to avoid signed integer overflow in the bitmask - The sud_test kselftest has been fixed to properly swizzle the syscall number into the return register, which are not the same on RISC-V - A fix for a build warning in the perf tools on rv32 - A fix for the CBO selftests, to avoid non-constants leaking into the inline asm - A pair of fixes for T-Head PBMT errata probing, which has been renamed MAE by the vendor * tag 'riscv-for-linus-6.9-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: RISC-V: selftests: cbo: Ensure asm operands match constraints, take 2 perf riscv: Fix the warning due to the incompatible type riscv: T-Head: Test availability bit before enabling MAE errata riscv: thead: Rename T-Head PBMT to MAE selftests: sud_test: return correct emulated syscall value on RISC-V riscv: hwprobe: fix invalid sign extension for RISCV_HWPROBE_EXT_ZVFHMIN riscv: Fix loading 64-bit NOMMU kernels past the start of RAM riscv: Fix TASK_SIZE on 64-bit NOMMU
2 parents d43df69 + 6beb6bc commit 57865f3

File tree

11 files changed

+59
-29
lines changed

11 files changed

+59
-29
lines changed

arch/riscv/Kconfig.errata

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ config ERRATA_THEAD
8282

8383
Otherwise, please say "N" here to avoid unnecessary overhead.
8484

85-
config ERRATA_THEAD_PBMT
86-
bool "Apply T-Head memory type errata"
85+
config ERRATA_THEAD_MAE
86+
bool "Apply T-Head's memory attribute extension (XTheadMae) errata"
8787
depends on ERRATA_THEAD && 64BIT && MMU
8888
select RISCV_ALTERNATIVE_EARLY
8989
default y
9090
help
91-
This will apply the memory type errata to handle the non-standard
92-
memory type bits in page-table-entries on T-Head SoCs.
91+
This will apply the memory attribute extension errata to handle the
92+
non-standard PTE utilization on T-Head SoCs (XTheadMae).
9393

9494
If you don't know what to do here, say "Y".
9595

arch/riscv/errata/thead/errata.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@
1919
#include <asm/patch.h>
2020
#include <asm/vendorid_list.h>
2121

22-
static bool errata_probe_pbmt(unsigned int stage,
23-
unsigned long arch_id, unsigned long impid)
22+
#define CSR_TH_SXSTATUS 0x5c0
23+
#define SXSTATUS_MAEE _AC(0x200000, UL)
24+
25+
static bool errata_probe_mae(unsigned int stage,
26+
unsigned long arch_id, unsigned long impid)
2427
{
25-
if (!IS_ENABLED(CONFIG_ERRATA_THEAD_PBMT))
28+
if (!IS_ENABLED(CONFIG_ERRATA_THEAD_MAE))
2629
return false;
2730

2831
if (arch_id != 0 || impid != 0)
2932
return false;
3033

31-
if (stage == RISCV_ALTERNATIVES_EARLY_BOOT ||
32-
stage == RISCV_ALTERNATIVES_MODULE)
33-
return true;
34+
if (stage != RISCV_ALTERNATIVES_EARLY_BOOT &&
35+
stage != RISCV_ALTERNATIVES_MODULE)
36+
return false;
37+
38+
if (!(csr_read(CSR_TH_SXSTATUS) & SXSTATUS_MAEE))
39+
return false;
3440

35-
return false;
41+
return true;
3642
}
3743

3844
/*
@@ -140,8 +146,8 @@ static u32 thead_errata_probe(unsigned int stage,
140146
{
141147
u32 cpu_req_errata = 0;
142148

143-
if (errata_probe_pbmt(stage, archid, impid))
144-
cpu_req_errata |= BIT(ERRATA_THEAD_PBMT);
149+
if (errata_probe_mae(stage, archid, impid))
150+
cpu_req_errata |= BIT(ERRATA_THEAD_MAE);
145151

146152
errata_probe_cmo(stage, archid, impid);
147153

arch/riscv/include/asm/errata_list.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#endif
2424

2525
#ifdef CONFIG_ERRATA_THEAD
26-
#define ERRATA_THEAD_PBMT 0
26+
#define ERRATA_THEAD_MAE 0
2727
#define ERRATA_THEAD_PMU 1
2828
#define ERRATA_THEAD_NUMBER 2
2929
#endif
@@ -53,20 +53,20 @@ asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_VENDOR_ID, \
5353
* in the default case.
5454
*/
5555
#define ALT_SVPBMT_SHIFT 61
56-
#define ALT_THEAD_PBMT_SHIFT 59
56+
#define ALT_THEAD_MAE_SHIFT 59
5757
#define ALT_SVPBMT(_val, prot) \
5858
asm(ALTERNATIVE_2("li %0, 0\t\nnop", \
5959
"li %0, %1\t\nslli %0,%0,%3", 0, \
6060
RISCV_ISA_EXT_SVPBMT, CONFIG_RISCV_ISA_SVPBMT, \
6161
"li %0, %2\t\nslli %0,%0,%4", THEAD_VENDOR_ID, \
62-
ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \
62+
ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE) \
6363
: "=r"(_val) \
6464
: "I"(prot##_SVPBMT >> ALT_SVPBMT_SHIFT), \
65-
"I"(prot##_THEAD >> ALT_THEAD_PBMT_SHIFT), \
65+
"I"(prot##_THEAD >> ALT_THEAD_MAE_SHIFT), \
6666
"I"(ALT_SVPBMT_SHIFT), \
67-
"I"(ALT_THEAD_PBMT_SHIFT))
67+
"I"(ALT_THEAD_MAE_SHIFT))
6868

69-
#ifdef CONFIG_ERRATA_THEAD_PBMT
69+
#ifdef CONFIG_ERRATA_THEAD_MAE
7070
/*
7171
* IO/NOCACHE memory types are handled together with svpbmt,
7272
* so on T-Head chips, check if no other memory type is set,
@@ -83,11 +83,11 @@ asm volatile(ALTERNATIVE( \
8383
"slli t3, t3, %3\n\t" \
8484
"or %0, %0, t3\n\t" \
8585
"2:", THEAD_VENDOR_ID, \
86-
ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \
86+
ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE) \
8787
: "+r"(_val) \
88-
: "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_PBMT_SHIFT), \
89-
"I"(_PAGE_PMA_THEAD >> ALT_THEAD_PBMT_SHIFT), \
90-
"I"(ALT_THEAD_PBMT_SHIFT) \
88+
: "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_MAE_SHIFT), \
89+
"I"(_PAGE_PMA_THEAD >> ALT_THEAD_MAE_SHIFT), \
90+
"I"(ALT_THEAD_MAE_SHIFT) \
9191
: "t3")
9292
#else
9393
#define ALT_THEAD_PMA(_val)

arch/riscv/include/asm/page.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ typedef struct page *pgtable_t;
8989
#define PTE_FMT "%08lx"
9090
#endif
9191

92-
#ifdef CONFIG_64BIT
92+
#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
9393
/*
9494
* We override this value as its generic definition uses __pa too early in
9595
* the boot process (before kernel_map.va_pa_offset is set).

arch/riscv/include/asm/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
896896
#define PAGE_SHARED __pgprot(0)
897897
#define PAGE_KERNEL __pgprot(0)
898898
#define swapper_pg_dir NULL
899-
#define TASK_SIZE 0xffffffffUL
899+
#define TASK_SIZE _AC(-1, UL)
900900
#define VMALLOC_START _AC(0, UL)
901901
#define VMALLOC_END TASK_SIZE
902902

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct riscv_hwprobe {
5454
#define RISCV_HWPROBE_EXT_ZFHMIN (1 << 28)
5555
#define RISCV_HWPROBE_EXT_ZIHINTNTL (1 << 29)
5656
#define RISCV_HWPROBE_EXT_ZVFH (1 << 30)
57-
#define RISCV_HWPROBE_EXT_ZVFHMIN (1 << 31)
57+
#define RISCV_HWPROBE_EXT_ZVFHMIN (1ULL << 31)
5858
#define RISCV_HWPROBE_EXT_ZFA (1ULL << 32)
5959
#define RISCV_HWPROBE_EXT_ZTSO (1ULL << 33)
6060
#define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34)

arch/riscv/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static void __init setup_bootmem(void)
231231
* In 64-bit, any use of __va/__pa before this point is wrong as we
232232
* did not know the start of DRAM before.
233233
*/
234-
if (IS_ENABLED(CONFIG_64BIT))
234+
if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_MMU))
235235
kernel_map.va_pa_offset = PAGE_OFFSET - phys_ram_base;
236236

237237
/*

tools/perf/arch/riscv/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static char *_get_cpuid(void)
4141
char *mimpid = NULL;
4242
char *cpuid = NULL;
4343
int read;
44-
unsigned long line_sz;
44+
size_t line_sz;
4545
FILE *cpuinfo;
4646

4747
cpuinfo = fopen(CPUINFO, "r");

tools/testing/selftests/riscv/hwprobe/cbo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "hwprobe.h"
2020
#include "../../kselftest.h"
2121

22-
#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
22+
#define MK_CBO(fn) le32_bswap((uint32_t)(fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
2323

2424
static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 };
2525

tools/testing/selftests/riscv/hwprobe/hwprobe.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#include <stddef.h>
55
#include <asm/hwprobe.h>
66

7+
#if __BYTE_ORDER == __BIG_ENDIAN
8+
# define le32_bswap(_x) \
9+
((((_x) & 0x000000ffU) << 24) | \
10+
(((_x) & 0x0000ff00U) << 8) | \
11+
(((_x) & 0x00ff0000U) >> 8) | \
12+
(((_x) & 0xff000000U) >> 24))
13+
#else
14+
# define le32_bswap(_x) (_x)
15+
#endif
16+
717
/*
818
* Rather than relying on having a new enough libc to define this, just do it
919
* ourselves. This way we don't need to be coupled to a new-enough libc to

tools/testing/selftests/syscall_user_dispatch/sud_test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ static void handle_sigsys(int sig, siginfo_t *info, void *ucontext)
158158

159159
/* In preparation for sigreturn. */
160160
SYSCALL_DISPATCH_OFF(glob_sel);
161+
162+
/*
163+
* The tests for argument handling assume that `syscall(x) == x`. This
164+
* is a NOP on x86 because the syscall number is passed in %rax, which
165+
* happens to also be the function ABI return register. Other
166+
* architectures may need to swizzle the arguments around.
167+
*/
168+
#if defined(__riscv)
169+
/* REG_A7 is not defined in libc headers */
170+
# define REG_A7 (REG_A0 + 7)
171+
172+
((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] =
173+
((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7];
174+
#endif
161175
}
162176

163177
TEST(dispatch_and_return)

0 commit comments

Comments
 (0)