Skip to content

Commit 2631ed0

Browse files
Peter Zijlstra (Intel)ctmarinas
authored andcommitted
tlb: mmu_gather: add tlb_flush_*_range APIs
tlb_flush_{pte|pmd|pud|p4d}_range() adjust the tlb->start and tlb->end, then set corresponding cleared_*. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Zhenyu Ye <[email protected]> Acked-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent e735b98 commit 2631ed0

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

include/asm-generic/tlb.h

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,38 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm
512512
}
513513
#endif
514514

515+
/*
516+
* tlb_flush_{pte|pmd|pud|p4d}_range() adjust the tlb->start and tlb->end,
517+
* and set corresponding cleared_*.
518+
*/
519+
static inline void tlb_flush_pte_range(struct mmu_gather *tlb,
520+
unsigned long address, unsigned long size)
521+
{
522+
__tlb_adjust_range(tlb, address, size);
523+
tlb->cleared_ptes = 1;
524+
}
525+
526+
static inline void tlb_flush_pmd_range(struct mmu_gather *tlb,
527+
unsigned long address, unsigned long size)
528+
{
529+
__tlb_adjust_range(tlb, address, size);
530+
tlb->cleared_pmds = 1;
531+
}
532+
533+
static inline void tlb_flush_pud_range(struct mmu_gather *tlb,
534+
unsigned long address, unsigned long size)
535+
{
536+
__tlb_adjust_range(tlb, address, size);
537+
tlb->cleared_puds = 1;
538+
}
539+
540+
static inline void tlb_flush_p4d_range(struct mmu_gather *tlb,
541+
unsigned long address, unsigned long size)
542+
{
543+
__tlb_adjust_range(tlb, address, size);
544+
tlb->cleared_p4ds = 1;
545+
}
546+
515547
#ifndef __tlb_remove_tlb_entry
516548
#define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0)
517549
#endif
@@ -525,19 +557,17 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm
525557
*/
526558
#define tlb_remove_tlb_entry(tlb, ptep, address) \
527559
do { \
528-
__tlb_adjust_range(tlb, address, PAGE_SIZE); \
529-
tlb->cleared_ptes = 1; \
560+
tlb_flush_pte_range(tlb, address, PAGE_SIZE); \
530561
__tlb_remove_tlb_entry(tlb, ptep, address); \
531562
} while (0)
532563

533564
#define tlb_remove_huge_tlb_entry(h, tlb, ptep, address) \
534565
do { \
535566
unsigned long _sz = huge_page_size(h); \
536-
__tlb_adjust_range(tlb, address, _sz); \
537567
if (_sz == PMD_SIZE) \
538-
tlb->cleared_pmds = 1; \
568+
tlb_flush_pmd_range(tlb, address, _sz); \
539569
else if (_sz == PUD_SIZE) \
540-
tlb->cleared_puds = 1; \
570+
tlb_flush_pud_range(tlb, address, _sz); \
541571
__tlb_remove_tlb_entry(tlb, ptep, address); \
542572
} while (0)
543573

@@ -551,8 +581,7 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm
551581

552582
#define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \
553583
do { \
554-
__tlb_adjust_range(tlb, address, HPAGE_PMD_SIZE); \
555-
tlb->cleared_pmds = 1; \
584+
tlb_flush_pmd_range(tlb, address, HPAGE_PMD_SIZE); \
556585
__tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \
557586
} while (0)
558587

@@ -566,8 +595,7 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm
566595

567596
#define tlb_remove_pud_tlb_entry(tlb, pudp, address) \
568597
do { \
569-
__tlb_adjust_range(tlb, address, HPAGE_PUD_SIZE); \
570-
tlb->cleared_puds = 1; \
598+
tlb_flush_pud_range(tlb, address, HPAGE_PUD_SIZE); \
571599
__tlb_remove_pud_tlb_entry(tlb, pudp, address); \
572600
} while (0)
573601

@@ -592,29 +620,26 @@ static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vm
592620
#ifndef pte_free_tlb
593621
#define pte_free_tlb(tlb, ptep, address) \
594622
do { \
595-
__tlb_adjust_range(tlb, address, PAGE_SIZE); \
623+
tlb_flush_pmd_range(tlb, address, PAGE_SIZE); \
596624
tlb->freed_tables = 1; \
597-
tlb->cleared_pmds = 1; \
598625
__pte_free_tlb(tlb, ptep, address); \
599626
} while (0)
600627
#endif
601628

602629
#ifndef pmd_free_tlb
603630
#define pmd_free_tlb(tlb, pmdp, address) \
604631
do { \
605-
__tlb_adjust_range(tlb, address, PAGE_SIZE); \
632+
tlb_flush_pud_range(tlb, address, PAGE_SIZE); \
606633
tlb->freed_tables = 1; \
607-
tlb->cleared_puds = 1; \
608634
__pmd_free_tlb(tlb, pmdp, address); \
609635
} while (0)
610636
#endif
611637

612638
#ifndef pud_free_tlb
613639
#define pud_free_tlb(tlb, pudp, address) \
614640
do { \
615-
__tlb_adjust_range(tlb, address, PAGE_SIZE); \
641+
tlb_flush_p4d_range(tlb, address, PAGE_SIZE); \
616642
tlb->freed_tables = 1; \
617-
tlb->cleared_p4ds = 1; \
618643
__pud_free_tlb(tlb, pudp, address); \
619644
} while (0)
620645
#endif

0 commit comments

Comments
 (0)