Skip to content

Commit 9ed18b0

Browse files
committed
Merge tag 'riscv-for-linus-6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: - fix missing TLB flush during early boot on SPARSEMEM_VMEMMAP configurations - fixes to correctly implement the break-before-make behavior requried by the ISA for NAPOT mappings - fix a missing TLB flush on intermediate mapping changes - fix build warning about a missing declaration of overflow_stack - fix performace regression related to incorrect tracking of completed batch TLB flushes * tag 'riscv-for-linus-6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Fix arch_tlbbatch_flush() by clearing the batch cpumask riscv: declare overflow_stack as exported from traps.c riscv: Fix arch_hugetlb_migration_supported() for NAPOT riscv: Flush the tlb when a page directory is freed riscv: Fix hugetlb_mask_last_page() when NAPOT is enabled riscv: Fix set_huge_pte_at() for NAPOT mapping riscv: mm: execute local TLB flush after populating vmemmap
2 parents ca8a667 + 3951f6a commit 9ed18b0

File tree

7 files changed

+89
-6
lines changed

7 files changed

+89
-6
lines changed

arch/riscv/include/asm/hugetlb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ static inline void arch_clear_hugepage_flags(struct page *page)
1111
}
1212
#define arch_clear_hugepage_flags arch_clear_hugepage_flags
1313

14+
bool arch_hugetlb_migration_supported(struct hstate *h);
15+
#define arch_hugetlb_migration_supported arch_hugetlb_migration_supported
16+
1417
#ifdef CONFIG_RISCV_ISA_SVNAPOT
1518
#define __HAVE_ARCH_HUGE_PTE_CLEAR
1619
void huge_pte_clear(struct mm_struct *mm, unsigned long addr,

arch/riscv/include/asm/stacktrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ static inline bool on_thread_stack(void)
2121
return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
2222
}
2323

24+
25+
#ifdef CONFIG_VMAP_STACK
26+
DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack);
27+
#endif /* CONFIG_VMAP_STACK */
28+
2429
#endif /* _ASM_RISCV_STACKTRACE_H */

arch/riscv/include/asm/tlb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void tlb_flush(struct mmu_gather *tlb);
1616
static inline void tlb_flush(struct mmu_gather *tlb)
1717
{
1818
#ifdef CONFIG_MMU
19-
if (tlb->fullmm || tlb->need_flush_all)
19+
if (tlb->fullmm || tlb->need_flush_all || tlb->freed_tables)
2020
flush_tlb_mm(tlb->mm);
2121
else
2222
flush_tlb_mm_range(tlb->mm, tlb->start, tlb->end,

arch/riscv/include/asm/tlbflush.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static inline void flush_tlb_kernel_range(unsigned long start,
7575

7676
#define flush_tlb_mm(mm) flush_tlb_all()
7777
#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all()
78+
#define local_flush_tlb_kernel_range(start, end) flush_tlb_all()
7879
#endif /* !CONFIG_SMP || !CONFIG_MMU */
7980

8081
#endif /* _ASM_RISCV_TLBFLUSH_H */

arch/riscv/mm/hugetlbpage.c

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ pte_t *huge_pte_offset(struct mm_struct *mm,
125125
return pte;
126126
}
127127

128+
unsigned long hugetlb_mask_last_page(struct hstate *h)
129+
{
130+
unsigned long hp_size = huge_page_size(h);
131+
132+
switch (hp_size) {
133+
#ifndef __PAGETABLE_PMD_FOLDED
134+
case PUD_SIZE:
135+
return P4D_SIZE - PUD_SIZE;
136+
#endif
137+
case PMD_SIZE:
138+
return PUD_SIZE - PMD_SIZE;
139+
case napot_cont_size(NAPOT_CONT64KB_ORDER):
140+
return PMD_SIZE - napot_cont_size(NAPOT_CONT64KB_ORDER);
141+
default:
142+
break;
143+
}
144+
145+
return 0UL;
146+
}
147+
128148
static pte_t get_clear_contig(struct mm_struct *mm,
129149
unsigned long addr,
130150
pte_t *ptep,
@@ -177,13 +197,36 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
177197
return entry;
178198
}
179199

200+
static void clear_flush(struct mm_struct *mm,
201+
unsigned long addr,
202+
pte_t *ptep,
203+
unsigned long pgsize,
204+
unsigned long ncontig)
205+
{
206+
struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0);
207+
unsigned long i, saddr = addr;
208+
209+
for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
210+
ptep_get_and_clear(mm, addr, ptep);
211+
212+
flush_tlb_range(&vma, saddr, addr);
213+
}
214+
215+
/*
216+
* When dealing with NAPOT mappings, the privileged specification indicates that
217+
* "if an update needs to be made, the OS generally should first mark all of the
218+
* PTEs invalid, then issue SFENCE.VMA instruction(s) covering all 4 KiB regions
219+
* within the range, [...] then update the PTE(s), as described in Section
220+
* 4.2.1.". That's the equivalent of the Break-Before-Make approach used by
221+
* arm64.
222+
*/
180223
void set_huge_pte_at(struct mm_struct *mm,
181224
unsigned long addr,
182225
pte_t *ptep,
183226
pte_t pte,
184227
unsigned long sz)
185228
{
186-
unsigned long hugepage_shift;
229+
unsigned long hugepage_shift, pgsize;
187230
int i, pte_num;
188231

189232
if (sz >= PGDIR_SIZE)
@@ -198,7 +241,22 @@ void set_huge_pte_at(struct mm_struct *mm,
198241
hugepage_shift = PAGE_SHIFT;
199242

200243
pte_num = sz >> hugepage_shift;
201-
for (i = 0; i < pte_num; i++, ptep++, addr += (1 << hugepage_shift))
244+
pgsize = 1 << hugepage_shift;
245+
246+
if (!pte_present(pte)) {
247+
for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
248+
set_ptes(mm, addr, ptep, pte, 1);
249+
return;
250+
}
251+
252+
if (!pte_napot(pte)) {
253+
set_ptes(mm, addr, ptep, pte, 1);
254+
return;
255+
}
256+
257+
clear_flush(mm, addr, ptep, pgsize, pte_num);
258+
259+
for (i = 0; i < pte_num; i++, ptep++, addr += pgsize)
202260
set_pte_at(mm, addr, ptep, pte);
203261
}
204262

@@ -306,7 +364,7 @@ void huge_pte_clear(struct mm_struct *mm,
306364
pte_clear(mm, addr, ptep);
307365
}
308366

309-
static __init bool is_napot_size(unsigned long size)
367+
static bool is_napot_size(unsigned long size)
310368
{
311369
unsigned long order;
312370

@@ -334,7 +392,7 @@ arch_initcall(napot_hugetlbpages_init);
334392

335393
#else
336394

337-
static __init bool is_napot_size(unsigned long size)
395+
static bool is_napot_size(unsigned long size)
338396
{
339397
return false;
340398
}
@@ -351,7 +409,7 @@ int pmd_huge(pmd_t pmd)
351409
return pmd_leaf(pmd);
352410
}
353411

354-
bool __init arch_hugetlb_valid_size(unsigned long size)
412+
static bool __hugetlb_valid_size(unsigned long size)
355413
{
356414
if (size == HPAGE_SIZE)
357415
return true;
@@ -363,6 +421,16 @@ bool __init arch_hugetlb_valid_size(unsigned long size)
363421
return false;
364422
}
365423

424+
bool __init arch_hugetlb_valid_size(unsigned long size)
425+
{
426+
return __hugetlb_valid_size(size);
427+
}
428+
429+
bool arch_hugetlb_migration_supported(struct hstate *h)
430+
{
431+
return __hugetlb_valid_size(huge_page_size(h));
432+
}
433+
366434
#ifdef CONFIG_CONTIG_ALLOC
367435
static __init int gigantic_pages_init(void)
368436
{

arch/riscv/mm/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,10 @@ void __init misc_mem_init(void)
13851385
early_memtest(min_low_pfn << PAGE_SHIFT, max_low_pfn << PAGE_SHIFT);
13861386
arch_numa_init();
13871387
sparse_init();
1388+
#ifdef CONFIG_SPARSEMEM_VMEMMAP
1389+
/* The entire VMEMMAP region has been populated. Flush TLB for this region */
1390+
local_flush_tlb_kernel_range(VMEMMAP_START, VMEMMAP_END);
1391+
#endif
13881392
zone_sizes_init();
13891393
arch_reserve_crashkernel();
13901394
memblock_dump_all();

arch/riscv/mm/tlbflush.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static inline void local_flush_tlb_range_asid(unsigned long start,
6666
local_flush_tlb_range_threshold_asid(start, size, stride, asid);
6767
}
6868

69+
/* Flush a range of kernel pages without broadcasting */
6970
void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
7071
{
7172
local_flush_tlb_range_asid(start, end - start, PAGE_SIZE, FLUSH_TLB_NO_ASID);
@@ -233,4 +234,5 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
233234
{
234235
__flush_tlb_range(&batch->cpumask, FLUSH_TLB_NO_ASID, 0,
235236
FLUSH_TLB_MAX_SIZE, PAGE_SIZE);
237+
cpumask_clear(&batch->cpumask);
236238
}

0 commit comments

Comments
 (0)