Skip to content

Commit 01261e2

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Only flush the mm icache when setting an exec pte
We used to emit a flush_icache_all() whenever a dirty executable mapping is set in the page table but we can instead call flush_icache_mm() which will only send IPIs to cores that currently run this mm and add a deferred icache flush to the others. The number of calls to sbi_remote_fence_i() (tested without IPI support): With a simple buildroot rootfs: * Before: ~5k * After : 4 (!) Tested on HW, the boot to login is ~4.5% faster. With an ubuntu rootfs: * Before: ~24k * After : ~13k Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20240202124711.256146-1-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 28e4748 commit 01261e2

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,12 @@ static inline void set_pte(pte_t *ptep, pte_t pteval)
513513
WRITE_ONCE(*ptep, pteval);
514514
}
515515

516-
void flush_icache_pte(pte_t pte);
516+
void flush_icache_pte(struct mm_struct *mm, pte_t pte);
517517

518-
static inline void __set_pte_at(pte_t *ptep, pte_t pteval)
518+
static inline void __set_pte_at(struct mm_struct *mm, pte_t *ptep, pte_t pteval)
519519
{
520520
if (pte_present(pteval) && pte_exec(pteval))
521-
flush_icache_pte(pteval);
521+
flush_icache_pte(mm, pteval);
522522

523523
set_pte(ptep, pteval);
524524
}
@@ -529,7 +529,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
529529
page_table_check_ptes_set(mm, ptep, pteval, nr);
530530

531531
for (;;) {
532-
__set_pte_at(ptep, pteval);
532+
__set_pte_at(mm, ptep, pteval);
533533
if (--nr == 0)
534534
break;
535535
ptep++;
@@ -541,7 +541,7 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,
541541
static inline void pte_clear(struct mm_struct *mm,
542542
unsigned long addr, pte_t *ptep)
543543
{
544-
__set_pte_at(ptep, __pte(0));
544+
__set_pte_at(mm, ptep, __pte(0));
545545
}
546546

547547
#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS /* defined in mm/pgtable.c */
@@ -713,14 +713,14 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
713713
pmd_t *pmdp, pmd_t pmd)
714714
{
715715
page_table_check_pmd_set(mm, pmdp, pmd);
716-
return __set_pte_at((pte_t *)pmdp, pmd_pte(pmd));
716+
return __set_pte_at(mm, (pte_t *)pmdp, pmd_pte(pmd));
717717
}
718718

719719
static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
720720
pud_t *pudp, pud_t pud)
721721
{
722722
page_table_check_pud_set(mm, pudp, pud);
723-
return __set_pte_at((pte_t *)pudp, pud_pte(pud));
723+
return __set_pte_at(mm, (pte_t *)pudp, pud_pte(pud));
724724
}
725725

726726
#ifdef CONFIG_PAGE_TABLE_CHECK

arch/riscv/mm/cacheflush.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void flush_icache_mm(struct mm_struct *mm, bool local)
8282
#endif /* CONFIG_SMP */
8383

8484
#ifdef CONFIG_MMU
85-
void flush_icache_pte(pte_t pte)
85+
void flush_icache_pte(struct mm_struct *mm, pte_t pte)
8686
{
8787
struct folio *folio = page_folio(pte_page(pte));
8888

8989
if (!test_bit(PG_dcache_clean, &folio->flags)) {
90-
flush_icache_all();
90+
flush_icache_mm(mm, false);
9191
set_bit(PG_dcache_clean, &folio->flags);
9292
}
9393
}

arch/riscv/mm/pgtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
1010
pte_t entry, int dirty)
1111
{
1212
if (!pte_same(ptep_get(ptep), entry))
13-
__set_pte_at(ptep, entry);
13+
__set_pte_at(vma->vm_mm, ptep, entry);
1414
/*
1515
* update_mmu_cache will unconditionally execute, handling both
1616
* the case that the PTE changed and the spurious fault case.

0 commit comments

Comments
 (0)