riscv: ASID-related and UP-related TLB flush enhancements
Subsystems (2)
cover riscv: ASID-related and UP-related TLB flush enhancements
While reviewing Alexandre Ghiti's "riscv: tlb flush improvements" series[1], I noticed that the TLB flushing functions mostly end up as flush_tlb_all() when SMP is disabled. This series resolves that. Along the way, I realized that we should be using single-ASID flushes wherever possible, so I implemented that as well. This series is mostly orthogonal to Alexandre's series, though it does remove the non-ASID code path from tlbflush.c, which turns out to be required for flush_tlb_kernel_range().
[1]: https://lore.kernel.org/linux-riscv/[email protected]/
Samuel Holland (7):
riscv: Apply SiFive CIP-1200 workaround to single-ASID sfence.vma
riscv: mm: Introduce cntx2asid/cntx2version helper macros
riscv: mm: Use a fixed layout for the MM context ID
riscv: mm: Make asid_bits a local variable
riscv: mm: Preserve global TLB entries when switching contexts
riscv: mm: Always flush a single MM context by ASID
riscv: mm: Combine the SMP and non-SMP TLB flushing code
arch/riscv/include/asm/errata_list.h | 12 +++- arch/riscv/include/asm/mmu.h | 3 + arch/riscv/include/asm/mmu_context.h | 2 - arch/riscv/include/asm/tlbflush.h | 41 ++++++------- arch/riscv/mm/Makefile | 5 +- arch/riscv/mm/context.c | 26 ++++---- arch/riscv/mm/tlbflush.c | 92 +++++++--------------------- 7 files changed, 67 insertions(+), 114 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/7 riscv: Apply SiFive CIP-1200 workaround to single-ASID sfence.vma
commit 3f1e782998cd ("riscv: add ASID-based tlbflushing methods") added calls to the sfence.vma instruction with rs2 != x0. These single-ASID instruction variants are also affected by SiFive errata CIP-1200.
Until now, the errata workaround was not needed for the single-ASID sfence.vma variants, because they were only used when the ASID allocator was enabled, and the affected SiFive platforms do not support multiple ASIDs. However, we are going to start using those sfence.vma variants regardless of ASID support, so now we need alternatives covering them.
---
arch/riscv/include/asm/errata_list.h | 12 +++++++++++- arch/riscv/include/asm/tlbflush.h | 13 ++++++++++++- arch/riscv/mm/tlbflush.c | 17 ----------------- 3 files changed, 23 insertions(+), 19 deletions(-)
arch/riscv/include/asm/errata_list.h +11 -1
@@ -39,11 +39,21 @@ ALTERNATIVE(__stringify(RISCV_PTR do_page_fault), \ CONFIG_ERRATA_SIFIVE_CIP_453)#else /* !__ASSEMBLY__ */ -#define ALT_FLUSH_TLB_PAGE (x) \ +#define ALT_SFENCE_VMA_ASID (asid) \ +asm(ALTERNATIVE("sfence.vma x0, %0", "sfence.vma", SIFIVE_VENDOR_ID, \ + ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200) \ + : : "r" (asid) : "memory") + +#define ALT_SFENCE_VMA_ADDR (addr) \ asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_VENDOR_ID, \ ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200) \ : : "r" (addr) : "memory") +#define ALT_SFENCE_VMA_ADDR_ASID (addr, asid) \ +asm(ALTERNATIVE("sfence.vma %0, %1", "sfence.vma", SIFIVE_VENDOR_ID, \ + ERRATA_SIFIVE_CIP_1200, CONFIG_ERRATA_SIFIVE_CIP_1200) \ + : : "r" (addr), "r" (asid) : "memory") +/* * _val is marked as "will be overwritten", so need to set it to 0 * in the default case.
arch/riscv/include/asm/tlbflush.h +12 -1
@@ -19,10 +19,21 @@ static inline void local_flush_tlb_all(void) __asm__ __volatile__ ("sfence.vma" : : : "memory"); } +static inline void local_flush_tlb_all_asid (unsigned long asid) +{ +ALT_SFENCE_VMA_ASID (asid); +} +/* Flush one page from local TLB */ static inline void local_flush_tlb_page (unsigned long addr) { -ALT_FLUSH_TLB_PAGE (__asm__ __volatile__ ("sfence.vma %0" : :"r" (addr) :"memory" )); +ALT_SFENCE_VMA_ADDR (addr); +} + +static inline void local_flush_tlb_page_asid (unsigned long addr, +unsigned long asid) +{ +ALT_SFENCE_VMA_ADDR_ASID (addr, asid); }#else /* CONFIG_MMU */ #define local_flush_tlb_all () do { } while (0)
arch/riscv/mm/tlbflush.c +0 -17
@@ -6,23 +6,6 @@#include <asm/sbi.h> #include <asm/mmu_context.h> -static inline void local_flush_tlb_all_asid (unsigned long asid) -{ - __asm__ __volatile__ ("sfence.vma x0, %0" - : - :"r" (asid) - :"memory" ); -} - -static inline void local_flush_tlb_page_asid (unsigned long addr, -unsigned long asid) -{ - __asm__ __volatile__ ("sfence.vma %0, %1" - : - :"r" (addr),"r" (asid) - :"memory" ); -} -static inline void local_flush_tlb_range (unsigned long start,unsigned long size,unsigned long stride) {
Signature · 1 line
2.41.0
PATCH 2/7 riscv: mm: Introduce cntx2asid/cntx2version helper macros
In reply to Samuel HollandWhen using the ASID allocator, the MM context ID contains two values:
the ASID in the lower bits, and the allocator version number in the remaining bits. Use macros to make this separation more obvious.
---
arch/riscv/include/asm/mmu.h | 3 +++ arch/riscv/mm/context.c | 12 ++++++------ arch/riscv/mm/tlbflush.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-)
arch/riscv/include/asm/mmu.h +3 -0
@@ -26,6 +26,9 @@ typedef struct { #endif } mm_context_t; +#define cntx2asid (cntx) ((cntx) & asid_mask) +#define cntx2version (cntx) ((cntx) & ~asid_mask) +void __init create_pgd_mapping (pgd_t *pgdp,uintptr_t va,phys_addr_t pa,phys_addr_t sz,pgprot_t prot);#endif /* __ASSEMBLY__ */
arch/riscv/mm/context.c +6 -6
@@ -81,7 +81,7 @@ static void __flush_context(void)if (cntx ==0 ) cntx =per_cpu (reserved_context, i); -__set_bit (cntx & asid_mask, context_asid_map); +__set_bit (cntx2asid (cntx), context_asid_map);per_cpu (reserved_context, i) = cntx; }
@@ -102,7 +102,7 @@ static unsigned long __new_context(struct mm_struct *mm)lockdep_assert_held (&context_lock);if (cntx !=0 ) { -unsigned long newcntx = ver | (cntx & asid_mask); +unsigned long newcntx = ver |cntx2asid (cntx);/* * If our current CONTEXT was active during a rollover, we
@@ -115,7 +115,7 @@ static unsigned long __new_context(struct mm_struct *mm)* We had a valid CONTEXT in a previous life, so try to * re-use it if possible. */ -if (!__test_and_set_bit (cntx & asid_mask, context_asid_map)) +if (!__test_and_set_bit (cntx2asid (cntx), context_asid_map))return newcntx; }
@@ -168,7 +168,7 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu)*/ old_active_cntx =atomic_long_read (&per_cpu (active_context, cpu));if (old_active_cntx && - ((cntx & ~asid_mask) ==atomic_long_read (¤t_version)) && + (cntx2version (cntx) ==atomic_long_read (¤t_version)) &&atomic_long_cmpxchg_relaxed (&per_cpu (active_context, cpu), old_active_cntx, cntx)) goto switch_mm_fast;
@@ -177,7 +177,7 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu)/* Check that our ASID belongs to the current_version. */ cntx =atomic_long_read (&mm->context.id); -if ((cntx & ~asid_mask) !=atomic_long_read (¤t_version)) { +if (cntx2version (cntx) !=atomic_long_read (¤t_version)) { cntx =__new_context (mm);atomic_long_set (&mm->context.id, cntx); }
@@ -191,7 +191,7 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu) switch_mm_fast:csr_write (CSR_SATP ,virt_to_pfn (mm->pgd) | - ((cntx & asid_mask) <<SATP_ASID_SHIFT ) | + (cntx2asid (cntx) <<SATP_ASID_SHIFT ) | satp_mode);if (need_flush_tlb)
arch/riscv/mm/tlbflush.c +1 -1
@@ -73,7 +73,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start,/* check if the tlbflush needs to be sent to other CPUs */ broadcast =cpumask_any_but (cmask, cpuid) < nr_cpu_ids;if (static_branch_unlikely (&use_asid_allocator)) { -unsigned long asid =atomic_long_read (&mm->context.id) & asid_mask; +unsigned long asid =cntx2asid (atomic_long_read (&mm->context.id));if (broadcast) {if (riscv_use_ipi_for_rfence ()) {
Signature · 1 line
2.41.0
PATCH 3/7 riscv: mm: Use a fixed layout for the MM context ID
In reply to Samuel HollandCurrently, the size of the ASID field in the MM context ID dynamically depends on the number of hardware-supported ASID bits. This requires reading a global variable to extract either field from the context ID. Instead, allocate the maximum possible number of bits to the ASID field, so the layout of the context ID is known at compile-time.
---
arch/riscv/include/asm/mmu.h | 4 ++-- arch/riscv/include/asm/tlbflush.h | 2 -- arch/riscv/mm/context.c | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-)
arch/riscv/include/asm/mmu.h +2 -2
@@ -26,8 +26,8 @@ typedef struct {#endif } mm_context_t; -#define cntx2asid (cntx) ((cntx) & asid_mask) -#define cntx2version (cntx) ((cntx) & ~asid_mask) +#define cntx2asid (cntx) ((cntx) & SATP_ASID_MASK) +#define cntx2version (cntx) ((cntx) & ~SATP_ASID_MASK)void __init create_pgd_mapping (pgd_t *pgdp,uintptr_t va,phys_addr_t pa,phys_addr_t sz,pgprot_t prot);
arch/riscv/include/asm/tlbflush.h +0 -2
@@ -12,8 +12,6 @@#include <asm/errata_list.h> #ifdef CONFIG_MMU -extern unsigned long asid_mask; -static inline void local_flush_tlb_all (void ) { __asm__ __volatile__ ("sfence.vma" : : :"memory" );
arch/riscv/mm/context.c +2 -4
@@ -22,7 +22,6 @@ DEFINE_STATIC_KEY_FALSE(use_asid_allocator);static unsigned long asid_bits;static unsigned long num_asids; -unsigned long asid_mask;static atomic_long_t current_version;
@@ -128,7 +127,7 @@ static unsigned long __new_context(struct mm_struct *mm) goto set_asid;/* We're out of ASIDs, so increment current_version */ - ver =atomic_long_add_return_relaxed (num_asids, ¤t_version); + ver =atomic_long_add_return_relaxed (BIT (SATP_ASID_BITS ), ¤t_version);/* Flush everything */ __flush_context ();
@@ -247,7 +246,6 @@ static int __init asids_init(void)/* Pre-compute ASID details */ if (asid_bits) { num_asids =1 << asid_bits; - asid_mask = num_asids -1 ; }/*
@@ -255,7 +253,7 @@ static int __init asids_init(void)* at-least twice more than CPUs */ if (num_asids > (2 *num_possible_cpus ())) { -atomic_long_set (¤t_version, num_asids); +atomic_long_set (¤t_version,BIT (SATP_ASID_BITS )); context_asid_map =bitmap_zalloc (num_asids,GFP_KERNEL );if (!context_asid_map)
Signature · 1 line
2.41.0
PATCH 4/7 riscv: mm: Make asid_bits a local variable
In reply to Samuel HollandThis variable is only used inside asids_init().
---
arch/riscv/mm/context.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/riscv/mm/context.c +1 -2
@@ -20,7 +20,6 @@DEFINE_STATIC_KEY_FALSE (use_asid_allocator); -static unsigned long asid_bits;static unsigned long num_asids;static atomic_long_t current_version;
@@ -226,7 +225,7 @@ static inline void set_mm(struct mm_struct *prev,static int __init asids_init (void ) { -unsigned long old; +unsigned long asid_bits, old;/* Figure-out number of ASID bits in HW */ old =csr_read (CSR_SATP );
Signature · 1 line
2.41.0
PATCH 5/7 riscv: mm: Preserve global TLB entries when switching contexts
In reply to Samuel HollandIf the CPU does not support multiple ASIDs, all MM contexts use ASID 0. In this case, it is still beneficial to flush the TLB by ASID, as the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages.
This optimization is recommended by the RISC-V privileged specification:
If the implementation does not provide ASIDs, or software chooses to always use ASID 0, then after every satp write, software should execute SFENCE.VMA with rs1=x0. In the common case that no global translations have been modified, rs2 should be set to a register other than x0 but which contains the value zero, so that global translations are not flushed.
It is not possible to apply this optimization when using the ASID allocator, because that code must flush the TLB for all ASIDs at once when incrementing the version number.
---
arch/riscv/mm/context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/context.c +1 -1
@@ -200,7 +200,7 @@ static void set_mm_noasid(struct mm_struct *mm) {/* Switch the page table and blindly nuke entire local TLB */ csr_write (CSR_SATP ,virt_to_pfn (mm->pgd) | satp_mode); -local_flush_tlb_all (); +local_flush_tlb_all_asid (0 ); } static inline void set_mm(struct mm_struct *prev,
Signature · 1 line
2.41.0
PATCH 6/7 riscv: mm: Always flush a single MM context by ASID
In reply to Samuel HollandEven if ASIDs are not supported, using the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages. So it is always most efficient to use the single-ASID code path.
---
arch/riscv/include/asm/mmu_context.h | 2 - arch/riscv/include/asm/tlbflush.h | 11 +++-- arch/riscv/mm/context.c | 3 +- arch/riscv/mm/tlbflush.c | 68 ++++++---------------------- 4 files changed, 24 insertions(+), 60 deletions(-)
arch/riscv/include/asm/mmu_context.h +0 -2
@@ -33,8 +33,6 @@ static inline int init_new_context(struct task_struct *tsk, return 0; } -DECLARE_STATIC_KEY_FALSE (use_asid_allocator); -#include <asm-generic/mmu_context.h> #endif /* _ASM_RISCV_MMU_CONTEXT_H */
arch/riscv/include/asm/tlbflush.h +8 -3
@@ -54,13 +54,18 @@ void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start,#define flush_tlb_all () local_flush_tlb_all()#define flush_tlb_page (vma, addr) local_flush_tlb_page(addr) +static inline void flush_tlb_mm (struct mm_struct *mm) +{ +unsigned long asid =cntx2asid (atomic_long_read (&mm->context.id)); + +local_flush_tlb_all_asid (asid); +} +static inline void flush_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end) { -local_flush_tlb_all (); +flush_tlb_mm (vma->vm_mm); } - -#define flush_tlb_mm (mm) flush_tlb_all()#endif /* !CONFIG_SMP || !CONFIG_MMU */ /* Flush a range of kernel pages */
arch/riscv/mm/context.c +1 -2
@@ -18,8 +18,7 @@#ifdef CONFIG_MMU -DEFINE_STATIC_KEY_FALSE (use_asid_allocator); - +static DEFINE_STATIC_KEY_FALSE (use_asid_allocator);static unsigned long num_asids;static atomic_long_t current_version;
arch/riscv/mm/tlbflush.c +15 -53
92 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH 6/7] riscv: mm: Always flush a single MM context by ASID
Quoted 5 lines · Samuel Holland
Even if ASIDs are not supported, using the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages. So it is always most efficient to use the single-ASID code path.
Signed-off-by Samuel Holland <[email protected]>
On nommu:arch/riscv/include/asm/tlbflush.h:59:69: error: 'mm_context_t' has no member named 'id'arch/riscv/include/asm/tlbflush.h:61:9: error: implicit declaration of function 'local_flush_tlb_all_asid'; did you mean 'local_flush_tlb_all'? [-Werror=implicit-function-declaration]
Cheers,
Conor.
Palmer Dabbelt
maintainerRe: [PATCH 6/7] riscv: mm: Always flush a single MM context by ASID
Quoted 10 lines · Conor Dooley
Quoted 5 lines · Samuel Holland
Even if ASIDs are not supported, using the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages. So it is always most efficient to use the single-ASID code path.
Signed-off-by Samuel Holland <[email protected]>On nommu:
arch/riscv/include/asm/tlbflush.h:59:69: error: 'mm_context_t' has no member named 'id'arch/riscv/include/asm/tlbflush.h:61:9: error: implicit declaration of function 'local_flush_tlb_all_asid'; did you mean 'local_flush_tlb_all'? [-Werror=implicit-function-declaration]
I'm getting a few more build issues as well. One's over here https://lore.kernel.org/r/[email protected] , but I'm also getting
In file included from /scratch/merges/ko-linux-next/linux/arch/riscv/include/asm/pgalloc.h:11,
from /scratch/merges/ko-linux-next/linux/arch/riscv/include/asm/efi.h:13,
from /scratch/merges/ko-linux-next/linux/arch/riscv/kernel/setup.c:40:
/scratch/merges/ko-linux-next/linux/arch/riscv/include/asm/tlb.h: In function 'tlb_flush':
/scratch/merges/ko-linux-next/linux/arch/riscv/include/asm/tlb.h:18:9: error: implicit declaration of function 'flush_tlb_mm'; did you mean 'flush_tlb_all'? [-Werror=implicit-function-declaration]
18 | flush_tlb_mm(tlb->mm);
| ^~~~~~~~~~~~
| flush_tlb_all/scratch/merges/ko-linux-next/linux/arch/riscv/include/asm/tlb.h:18:25: error: invalid use of undefined type 'struct mmu_gather'
18 | flush_tlb_mm(tlb->mm);
| ^~
cc1: some warnings being treated as errors
Quoted 3 lines
Cheers,
Conor.
PATCH 7/7 riscv: mm: Combine the SMP and non-SMP TLB flushing code
In reply to Samuel HollandThis allows non-SMP configurations to take advantage of improvements to the code in tlbflush.c, such as support for huge pages and flushing multiple-page ranges.
---
arch/riscv/include/asm/tlbflush.h | 31 ++++++++----------------------- arch/riscv/mm/Makefile | 5 +---- arch/riscv/mm/tlbflush.c | 7 ++++++- 3 files changed, 15 insertions(+), 28 deletions(-)
arch/riscv/include/asm/tlbflush.h +8 -23
@@ -33,13 +33,12 @@ static inline void local_flush_tlb_page_asid(unsigned long addr, {ALT_SFENCE_VMA_ADDR_ASID (addr, asid); } -#else /* CONFIG_MMU */ -#define local_flush_tlb_all () do { } while (0) -#define local_flush_tlb_page (addr) do { } while (0) -#endif /* CONFIG_MMU */ -#if defined(CONFIG_SMP ) && defined(CONFIG_MMU ) +#ifdef CONFIG_SMP void flush_tlb_all (void ); +#else +#define flush_tlb_all () local_flush_tlb_all() +#endif void flush_tlb_mm (struct mm_struct *mm);void flush_tlb_page (struct vm_area_struct *vma,unsigned long addr); void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
@@ -49,24 +48,10 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,void flush_pmd_tlb_range (struct vm_area_struct *vma,unsigned long start,unsigned long end);#endif -#else /* CONFIG_SMP && CONFIG_MMU */ - -#define flush_tlb_all () local_flush_tlb_all() -#define flush_tlb_page (vma, addr) local_flush_tlb_page(addr) - -static inline void flush_tlb_mm (struct mm_struct *mm) -{ -unsigned long asid =cntx2asid (atomic_long_read (&mm->context.id)); - -local_flush_tlb_all_asid (asid); -} - -static inline void flush_tlb_range (struct vm_area_struct *vma, -unsigned long start,unsigned long end) -{ -flush_tlb_mm (vma->vm_mm); -} -#endif /* !CONFIG_SMP || !CONFIG_MMU */ +#else /* CONFIG_MMU */ +#define local_flush_tlb_all () do { } while (0) +#define local_flush_tlb_page (addr) do { } while (0) +#endif /* CONFIG_MMU */ /* Flush a range of kernel pages */ static inline void flush_tlb_kernel_range(unsigned long start,
arch/riscv/mm/Makefile +1 -4
@@ -13,15 +13,12 @@ endif KCOV_INSTRUMENT_init.o := n obj-y += init.o -obj-$(CONFIG_MMU) += extable.o fault.o pageattr.o +obj-$(CONFIG_MMU) += extable.o fault.o pageattr.o tlbflush.o obj-y += cacheflush.o obj-y += context.o obj-y += pgtable.o obj-y += pmem.o -ifeq ($(CONFIG_MMU),y) -obj-$(CONFIG_SMP) += tlbflush.o -endif obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_PTDUMP_CORE) += ptdump.o obj-$(CONFIG_KASAN) += kasan_init.o
arch/riscv/mm/tlbflush.c +6 -1
@@ -15,6 +15,7 @@ static inline void local_flush_tlb_range_asid(unsigned long start,local_flush_tlb_all_asid (asid); } +#ifdef CONFIG_SMP static void __ipi_flush_tlb_all (void *info) {local_flush_tlb_all ();
@@ -41,12 +42,12 @@ static void __ipi_flush_tlb_range_asid(void *info) local_flush_tlb_range_asid(d->start, d->size, d->stride, d->asid); } +#endif static void __flush_tlb_range (struct mm_struct *mm,unsigned long start,unsigned long size,unsigned long stride) {unsigned long asid =cntx2asid (atomic_long_read (&mm->context.id)); -struct flush_tlb_range_data ftd;struct cpumask *cmask =mm_cpumask (mm);unsigned int cpuid;
@@ -54,9 +55,12 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start,return ; cpuid =get_cpu (); +#ifdef CONFIG_SMP /* check if the tlbflush needs to be sent to other CPUs */ if (cpumask_any_but (cmask, cpuid) < nr_cpu_ids) {if (riscv_use_ipi_for_rfence ()) { +struct flush_tlb_range_data ftd; + ftd.asid = asid; ftd.start = start; ftd.size = size;
@@ -68,6 +72,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start,sbi_remote_sfence_vma_asid (cmask, start, size, asid); } else +#endif local_flush_tlb_range_asid (start, size, stride, asid);put_cpu (); }
Signature · 1 line
2.41.0
kernel test robot
build botRe: [PATCH 7/7] riscv: mm: Combine the SMP and non-SMP TLB flushing code
kernel test robot noticed the following build warnings:
Hi Samuel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.5 next-20230908]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Samuel-Holland/riscv-Apply-SiFive-CIP-1200-workaround-to-single-ASID-sfence-vma/20230910-042028 base: linus/master patch link: https://lore.kernel.org/r/20230909201727.10909-8-samuel%40sholland.org patch subject: [PATCH 7/7] riscv: mm: Combine the SMP and non-SMP TLB flushing code config: riscv-allnoconfig (https://download.01.org/0day-ci/archive/20230910/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230910/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
arch/riscv/mm/tlbflush.c: In function '__flush_tlb_range':
>> arch/riscv/mm/tlbflush.c:52:22: warning: variable 'cpuid' set but not used [-Wunused-but-set-variable]
52 | unsigned int cpuid;
| ^~~~~vim +/cpuid +52 arch/riscv/mm/tlbflush.c
18d2199d81054f Anup Patel 2023-03-28 46
18d2199d81054f Anup Patel 2023-03-28 47 static void __flush_tlb_range(struct mm_struct *mm, unsigned long start,
c3b2d67046d236 Nanyong Sun 2021-04-30 48 unsigned long size, unsigned long stride)
95594cb40c6e01 Christoph Hellwig 2019-08-21 49 {
ff15058bb4eb32 Samuel Holland 2023-09-09 50 unsigned long asid = cntx2asid(atomic_long_read(&mm->context.id));
70c7605c08c597 Christoph Hellwig 2021-06-06 51 struct cpumask *cmask = mm_cpumask(mm);
31738ede9b339c Atish Patra 2019-08-22 @52 unsigned int cpuid;
95594cb40c6e01 Christoph Hellwig 2019-08-21 53
6384423f49c804 Atish Patra 2019-08-22 54 if (cpumask_empty(cmask))
6384423f49c804 Atish Patra 2019-08-22 55 return;
6384423f49c804 Atish Patra 2019-08-22 56
31738ede9b339c Atish Patra 2019-08-22 57 cpuid = get_cpu();
047bf3010ac2de Samuel Holland 2023-09-09 58 #ifdef CONFIG_SMP
3f1e782998cdf6 Guo Ren 2021-06-06 59 /* check if the tlbflush needs to be sent to other CPUs */
ff15058bb4eb32 Samuel Holland 2023-09-09 60 if (cpumask_any_but(cmask, cpuid) < nr_cpu_ids) {
18d2199d81054f Anup Patel 2023-03-28 61 if (riscv_use_ipi_for_rfence()) {
047bf3010ac2de Samuel Holland 2023-09-09 62 struct flush_tlb_range_data ftd;
047bf3010ac2de Samuel Holland 2023-09-09 63
18d2199d81054f Anup Patel 2023-03-28 64 ftd.asid = asid;
18d2199d81054f Anup Patel 2023-03-28 65 ftd.start = start;
18d2199d81054f Anup Patel 2023-03-28 66 ftd.size = size;
18d2199d81054f Anup Patel 2023-03-28 67 ftd.stride = stride;
18d2199d81054f Anup Patel 2023-03-28 68 on_each_cpu_mask(cmask,
18d2199d81054f Anup Patel 2023-03-28 69 __ipi_flush_tlb_range_asid,
18d2199d81054f Anup Patel 2023-03-28 70 &ftd, 1);
18d2199d81054f Anup Patel 2023-03-28 71 } else
18d2199d81054f Anup Patel 2023-03-28 72 sbi_remote_sfence_vma_asid(cmask,
18d2199d81054f Anup Patel 2023-03-28 73 start, size, asid);
18d2199d81054f Anup Patel 2023-03-28 74 } else
047bf3010ac2de Samuel Holland 2023-09-09 75 #endif
ff15058bb4eb32 Samuel Holland 2023-09-09 76 local_flush_tlb_range_asid(start, size, stride, asid);
31738ede9b339c Atish Patra 2019-08-22 77 put_cpu();
95594cb40c6e01 Christoph Hellwig 2019-08-21 78 }
95594cb40c6e01 Christoph Hellwig 2019-08-21 79 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 7/7] riscv: mm: Combine the SMP and non-SMP TLB flushing code
In reply to Samuel Hollandkernel test robot noticed the following build errors:
Hi Samuel,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.6-rc1 next-20230911]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Samuel-Holland/riscv-Apply-SiFive-CIP-1200-workaround-to-single-ASID-sfence-vma/20230910-042028 base: linus/master patch link: https://lore.kernel.org/r/20230909201727.10909-8-samuel%40sholland.org patch subject: [PATCH 7/7] riscv: mm: Combine the SMP and non-SMP TLB flushing code config: riscv-randconfig-r005-20230912 (https://download.01.org/0day-ci/archive/20230912/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230912/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:29:
In file included from include/linux/pgtable.h:6:
In file included from arch/riscv/include/asm/pgtable.h:117:
>> arch/riscv/include/asm/tlbflush.h:60:2: error: call to undeclared function 'flush_tlb_all'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
60 | flush_tlb_all();
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:97:11: warning: array index 3 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
97 | return (set->sig[3] | set->sig[2] |
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:97:25: warning: array index 2 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
97 | return (set->sig[3] | set->sig[2] |
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:98:4: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
98 | set->sig[1] | set->sig[0]) == 0;
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:100:11: warning: array index 1 is past the end of the array (that has type 'unsigned long[1]') [-Warray-bounds]
100 | return (set->sig[1] | set->sig[0]) == 0;
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:113:11: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
113 | return (set1->sig[3] == set2->sig[3]) &&
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:113:27: warning: array index 3 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
113 | return (set1->sig[3] == set2->sig[3]) &&
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^
In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
include/linux/signal.h:114:5: warning: array index 2 is past the end of the array (that has type 'const unsigned long[1]') [-Warray-bounds]
114 | (set1->sig[2] == set2->sig[2]) &&
| ^ ~
include/uapi/asm-generic/signal.h:62:2: note: array 'sig' declared here
62 | unsigned long sig[_NSIG_WORDS];
| ^ In file included from arch/riscv/kernel/asm-offsets.c:10:
In file included from include/linux/mm.h:1075:
In file included from include/linux/huge_mm.h:8:
In file included from include/linux/fs.h:33:
In file included from include/linux/percpu-rwsem.h:7:
In file included from include/linux/rcuwait.h:6:
In file included from include/linux/sched/signal.h:6:
vim +/flush_tlb_all +60 arch/riscv/include/asm/tlbflush.h
fab957c11efe2f4 Palmer Dabbelt 2017-07-10 55
fab957c11efe2f4 Palmer Dabbelt 2017-07-10 56 /* Flush a range of kernel pages */
fab957c11efe2f4 Palmer Dabbelt 2017-07-10 57 static inline void flush_tlb_kernel_range(unsigned long start,
fab957c11efe2f4 Palmer Dabbelt 2017-07-10 58 unsigned long end)
fab957c11efe2f4 Palmer Dabbelt 2017-07-10 59 {fab957c11efe2f4 Palmer Dabbelt 2017-07-10 @60 flush_tlb_all();fab957c11efe2f4 Palmer Dabbelt 2017-07-10 61 }fab957c11efe2f4 Palmer Dabbelt 2017-07-10 62
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 7/7] riscv: mm: Combine the SMP and non-SMP TLB flushing code
In reply to Samuel Hollandkernel test robot noticed the following build errors:
Hi Samuel,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.6-rc1 next-20230911]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Samuel-Holland/riscv-Apply-SiFive-CIP-1200-workaround-to-single-ASID-sfence-vma/20230910-042028 base: linus/master patch link: https://lore.kernel.org/r/20230909201727.10909-8-samuel%40sholland.org patch subject: [PATCH 7/7] riscv: mm: Combine the SMP and non-SMP TLB flushing code config: riscv-nommu_k210_sdcard_defconfig (https://download.01.org/0day-ci/archive/20230912/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230912/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from arch/riscv/include/asm/pgtable.h:117,
from include/linux/pgtable.h:6,
from include/linux/mm.h:29,
from arch/riscv/kernel/asm-offsets.c:10:
arch/riscv/include/asm/tlbflush.h: In function 'flush_tlb_kernel_range':
>> arch/riscv/include/asm/tlbflush.h:60:9: error: implicit declaration of function 'flush_tlb_all' [-Werror=implicit-function-declaration]
60 | flush_tlb_all();
| ^~~~~~~~~~~~~ cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:116: arch/riscv/kernel/asm-offsets.s] Error 1 make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [Makefile:1202: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:234: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/flush_tlb_all +60 arch/riscv/include/asm/tlbflush.h
fab957c11efe2f Palmer Dabbelt 2017-07-10 55
fab957c11efe2f Palmer Dabbelt 2017-07-10 56 /* Flush a range of kernel pages */
fab957c11efe2f Palmer Dabbelt 2017-07-10 57 static inline void flush_tlb_kernel_range(unsigned long start,
fab957c11efe2f Palmer Dabbelt 2017-07-10 58 unsigned long end)
fab957c11efe2f Palmer Dabbelt 2017-07-10 59 {fab957c11efe2f Palmer Dabbelt 2017-07-10 @60 flush_tlb_all();fab957c11efe2f Palmer Dabbelt 2017-07-10 61 }fab957c11efe2f Palmer Dabbelt 2017-07-10 62
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki