Skip to content

Commit 6beb6bc

Browse files
Merge patch series "RISC-V: Test th.sxstatus.MAEE bit before enabling MAEE"
Christoph Müllner <[email protected]> says: Currently, the Linux kernel suffers from a boot regression when running on the c906 QEMU emulation. Details have been reported here by Björn Töpel: https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg04766.html The main issue is, that Linux enables XTheadMae for CPUs that have a T-Head mvendorid but QEMU maintainers don't want to emulate a CPU that uses reserved bits in PTEs. See also the following discussion for more context: https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html This series renames "T-Head PBMT" to "MAE"/"XTheadMae" and only enables it if the th.sxstatus.MAEE bit is set. The th.sxstatus CSR is documented here: https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc XTheadMae is documented here: https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadmae.adoc The QEMU patch to emulate th.sxstatus with the MAEE bit not set is here: https://lore.kernel.org/all/[email protected]/ After applying the referenced QEMU patch, this patchset allows to successfully boot a C906 QEMU system emulation ("-cpu thead-c906"). * b4-shazam-lts: riscv: T-Head: Test availability bit before enabling MAE errata riscv: thead: Rename T-Head PBMT to MAE Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents 4940840 + 65b71cc commit 6beb6bc

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
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)

0 commit comments

Comments
 (0)