Skip to content

Commit bff3ff5

Browse files
VincentZWCpalmer-dabbelt
authored andcommitted
riscv: sifive: Apply errata "cip-1200" patch
For certain SiFive CPUs, "sfence.vma addr" cannot exactly flush addr from TLB in the particular cases. The details could be found here: https://sifive.cdn.prismic.io/sifive/167a1a56-03f4-4615-a79e-b2a86153148f_FU740_errata_20210205.pdf In order to ensure the functionality, this patch uses the Alternative scheme to replace all "sfence.vma addr" with "sfence.vma" at runtime. Signed-off-by: Vincent Chen <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 800149a commit bff3ff5

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

arch/riscv/Kconfig.erratas

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,15 @@ config ERRATA_SIFIVE_CIP_453
3030

3131
If you don't know what to do here, say "Y".
3232

33+
config ERRATA_SIFIVE_CIP_1200
34+
bool "Apply SiFive errata CIP-1200"
35+
depends on ERRATA_SIFIVE
36+
default y
37+
help
38+
This will apply the SiFive CIP-1200 errata to repalce all
39+
"sfence.vma addr" with "sfence.vma" to ensure that the addr
40+
has been flushed from TLB.
41+
42+
If you don't know what to do here, say "Y".
43+
3344
endmenu

arch/riscv/errata/sifive/errata.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,29 @@ static bool errata_cip_453_check_func(unsigned long arch_id, unsigned long impi
2929
return true;
3030
}
3131

32+
static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long impid)
33+
{
34+
/*
35+
* Affected cores:
36+
* Architecture ID: 0x8000000000000007 or 0x1
37+
* Implement ID: mimpid[23:0] <= 0x200630 and mimpid != 0x01200626
38+
*/
39+
if (arch_id != 0x8000000000000007 && arch_id != 0x1)
40+
return false;
41+
if ((impid & 0xffffff) > 0x200630 || impid == 0x1200626)
42+
return false;
43+
return true;
44+
}
45+
3246
static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = {
3347
{
3448
.name = "cip-453",
3549
.check_func = errata_cip_453_check_func
3650
},
51+
{
52+
.name = "cip-1200",
53+
.check_func = errata_cip_1200_check_func
54+
},
3755
};
3856

3957
static u32 __init sifive_errata_probe(unsigned long archid, unsigned long impid)

arch/riscv/include/asm/errata_list.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#ifdef CONFIG_ERRATA_SIFIVE
1212
#define ERRATA_SIFIVE_CIP_453 0
13-
#define ERRATA_SIFIVE_NUMBER 1
13+
#define ERRATA_SIFIVE_CIP_1200 1
14+
#define ERRATA_SIFIVE_NUMBER 2
1415
#endif
1516

1617
#ifdef __ASSEMBLY__
@@ -26,6 +27,13 @@ ALTERNATIVE(__stringify(RISCV_PTR do_page_fault), \
2627
__stringify(RISCV_PTR sifive_cip_453_page_fault_trp), \
2728
SIFIVE_VENDOR_ID, ERRATA_SIFIVE_CIP_453, \
2829
CONFIG_ERRATA_SIFIVE_CIP_453)
30+
#else /* !__ASSEMBLY__ */
31+
32+
#define ALT_FLUSH_TLB_PAGE(x) \
33+
asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_VENDOR_ID, \
34+
ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200) \
35+
: : "r" (addr) : "memory")
36+
2937
#endif /* __ASSEMBLY__ */
3038

3139
#endif

arch/riscv/include/asm/tlbflush.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/mm_types.h>
1111
#include <asm/smp.h>
12+
#include <asm/errata_list.h>
1213

1314
#ifdef CONFIG_MMU
1415
static inline void local_flush_tlb_all(void)
@@ -19,7 +20,7 @@ static inline void local_flush_tlb_all(void)
1920
/* Flush one page from local TLB */
2021
static inline void local_flush_tlb_page(unsigned long addr)
2122
{
22-
__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
23+
ALT_FLUSH_TLB_PAGE(__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory"));
2324
}
2425
#else /* CONFIG_MMU */
2526
#define local_flush_tlb_all() do { } while (0)

0 commit comments

Comments
 (0)