Lines Matching +full:i +full:- +full:tlb +full:- +full:sets

1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* include/asm-generic/tlb.h
4 * Generic TLB shootdown code
32 * Generic MMU-gather implementation.
35 * correct and efficient ordering of freeing pages and TLB invalidations.
40 * 2) TLB invalidate page
49 * - tlb_gather_mmu() / tlb_gather_mmu_fullmm() / tlb_finish_mmu()
53 * Finish in particular will issue a (final) TLB invalidate and free
56 * - tlb_start_vma() / tlb_end_vma(); marks the start / end of a VMA
61 * - tlb_remove_table()
63 * tlb_remove_table() is the basic primitive to free page-table directories
70 * - tlb_remove_page() / __tlb_remove_page()
71 * - tlb_remove_page_size() / __tlb_remove_page_size()
72 * - __tlb_remove_folio_pages()
87 * - tlb_change_page_size()
89 * call before __tlb_remove_page*() to set the current page-size; implies a
92 * - tlb_flush_mmu() / tlb_flush_mmu_tlbonly()
94 * tlb_flush_mmu_tlbonly() - does the TLB invalidate (and resets
97 * tlb_flush_mmu() - in addition to the above TLB invalidate, also frees
100 * - mmu_gather::fullmm
105 * - We can ignore tlb_{start,end}_vma(); because we don't
108 * - (RISC) architectures that use ASIDs can cycle to a new ASID
111 * - mmu_gather::need_flush_all
114 * flush the entire TLB irrespective of the range. For instance
115 * x86-PAE needs this when changing top-level entries.
122 * - mmu_gather::start / mmu_gather::end
127 * - mmu_gather::freed_tables
131 * - tlb_get_unmap_shift() / tlb_get_unmap_size()
133 * returns the smallest TLB entry size unmapped in this range.
139 * Additionally there are a few opt-in features:
146 * This might be useful if your architecture has size specific TLB
154 * Useful if your architecture has non-page page directories.
161 * Like MMU_GATHER_TABLE_FREE, and adds semi-RCU semantics to the free (see
164 * Useful if your architecture doesn't use IPIs for remote TLB invalidates
165 * and therefore doesn't naturally serialize with software page-table walkers.
193 * This is useful if your architecture already flushes TLB entries in the
208 ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *))
210 extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
218 #define tlb_remove_table(tlb, page) tlb_remove_page((tlb), (page)) argument
224 * This allows an architecture that does not use the linux page-tables for
247 * to work on, then just handle a few from the on-stack structure.
259 ((PAGE_SIZE - sizeof(struct mmu_gather_batch)) / sizeof(void *))
263 * lockups for non-preemptible kernels on huge machines when a lot of memory
269 extern bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page,
271 bool __tlb_remove_folio_pages(struct mmu_gather *tlb, struct page *page,
276 * This both sets 'delayed_rmap', and returns true. It would be an inline
279 #define tlb_delay_rmap(tlb) (((tlb)->delayed_rmap = 1), true) argument
280 extern void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma);
286 * We have a no-op version of the rmap removal that doesn't
293 #define tlb_delay_rmap(tlb) (false) argument
294 static inline void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma) { } in tlb_flush_rmaps() argument
318 * requires a complete flush of the tlb
360 void tlb_flush_mmu(struct mmu_gather *tlb);
362 static inline void __tlb_adjust_range(struct mmu_gather *tlb, in __tlb_adjust_range() argument
366 tlb->start = min(tlb->start, address); in __tlb_adjust_range()
367 tlb->end = max(tlb->end, address + range_size); in __tlb_adjust_range()
370 static inline void __tlb_reset_range(struct mmu_gather *tlb) in __tlb_reset_range() argument
372 if (tlb->fullmm) { in __tlb_reset_range()
373 tlb->start = tlb->end = ~0; in __tlb_reset_range()
375 tlb->start = TASK_SIZE; in __tlb_reset_range()
376 tlb->end = 0; in __tlb_reset_range()
378 tlb->freed_tables = 0; in __tlb_reset_range()
379 tlb->cleared_ptes = 0; in __tlb_reset_range()
380 tlb->cleared_pmds = 0; in __tlb_reset_range()
381 tlb->cleared_puds = 0; in __tlb_reset_range()
382 tlb->cleared_p4ds = 0; in __tlb_reset_range()
404 static inline void tlb_flush(struct mmu_gather *tlb) in tlb_flush() argument
406 if (tlb->end) in tlb_flush()
407 flush_tlb_mm(tlb->mm); in tlb_flush()
418 static inline void tlb_flush(struct mmu_gather *tlb) in tlb_flush() argument
420 if (tlb->fullmm || tlb->need_flush_all) { in tlb_flush()
421 flush_tlb_mm(tlb->mm); in tlb_flush()
422 } else if (tlb->end) { in tlb_flush()
424 .vm_mm = tlb->mm, in tlb_flush()
425 .vm_flags = (tlb->vma_exec ? VM_EXEC : 0) | in tlb_flush()
426 (tlb->vma_huge ? VM_HUGETLB : 0), in tlb_flush()
429 flush_tlb_range(&vma, tlb->start, tlb->end); in tlb_flush()
437 tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) in tlb_update_vma_flags() argument
441 * mips-4k) flush only large pages. in tlb_update_vma_flags()
443 * flush_tlb_range() implementations that flush I-TLB also flush D-TLB in tlb_update_vma_flags()
450 tlb->vma_huge = is_vm_hugetlb_page(vma); in tlb_update_vma_flags()
451 tlb->vma_exec = !!(vma->vm_flags & VM_EXEC); in tlb_update_vma_flags()
452 tlb->vma_pfn = !!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)); in tlb_update_vma_flags()
455 static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) in tlb_flush_mmu_tlbonly() argument
458 * Anything calling __tlb_adjust_range() also sets at least one of in tlb_flush_mmu_tlbonly()
461 if (!(tlb->freed_tables || tlb->cleared_ptes || tlb->cleared_pmds || in tlb_flush_mmu_tlbonly()
462 tlb->cleared_puds || tlb->cleared_p4ds)) in tlb_flush_mmu_tlbonly()
465 tlb_flush(tlb); in tlb_flush_mmu_tlbonly()
466 __tlb_reset_range(tlb); in tlb_flush_mmu_tlbonly()
469 static inline void tlb_remove_page_size(struct mmu_gather *tlb, in tlb_remove_page_size() argument
472 if (__tlb_remove_page_size(tlb, page, false, page_size)) in tlb_remove_page_size()
473 tlb_flush_mmu(tlb); in tlb_remove_page_size()
476 static __always_inline bool __tlb_remove_page(struct mmu_gather *tlb, in __tlb_remove_page() argument
479 return __tlb_remove_page_size(tlb, page, delay_rmap, PAGE_SIZE); in __tlb_remove_page()
486 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) in tlb_remove_page() argument
488 return tlb_remove_page_size(tlb, page, PAGE_SIZE); in tlb_remove_page()
491 static inline void tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) in tlb_remove_ptdesc() argument
493 tlb_remove_table(tlb, pt); in tlb_remove_ptdesc()
496 /* Like tlb_remove_ptdesc, but for page-like page directories. */
497 static inline void tlb_remove_page_ptdesc(struct mmu_gather *tlb, struct ptdesc *pt) in tlb_remove_page_ptdesc() argument
499 tlb_remove_page(tlb, ptdesc_page(pt)); in tlb_remove_page_ptdesc()
502 static inline void tlb_change_page_size(struct mmu_gather *tlb, in tlb_change_page_size() argument
506 if (tlb->page_size && tlb->page_size != page_size) { in tlb_change_page_size()
507 if (!tlb->fullmm && !tlb->need_flush_all) in tlb_change_page_size()
508 tlb_flush_mmu(tlb); in tlb_change_page_size()
511 tlb->page_size = page_size; in tlb_change_page_size()
515 static inline unsigned long tlb_get_unmap_shift(struct mmu_gather *tlb) in tlb_get_unmap_shift() argument
517 if (tlb->cleared_ptes) in tlb_get_unmap_shift()
519 if (tlb->cleared_pmds) in tlb_get_unmap_shift()
521 if (tlb->cleared_puds) in tlb_get_unmap_shift()
523 if (tlb->cleared_p4ds) in tlb_get_unmap_shift()
529 static inline unsigned long tlb_get_unmap_size(struct mmu_gather *tlb) in tlb_get_unmap_size() argument
531 return 1UL << tlb_get_unmap_shift(tlb); in tlb_get_unmap_size()
535 * In the case of tlb vma handling, we can optimise these away in the
539 static inline void tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) in tlb_start_vma() argument
541 if (tlb->fullmm) in tlb_start_vma()
544 tlb_update_vma_flags(tlb, vma); in tlb_start_vma()
546 flush_cache_range(vma, vma->vm_start, vma->vm_end); in tlb_start_vma()
550 static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) in tlb_end_vma() argument
552 if (tlb->fullmm) in tlb_end_vma()
557 * page mapcount -- there might not be page-frames for these PFNs after in tlb_end_vma()
561 if (tlb->vma_pfn || !IS_ENABLED(CONFIG_MMU_GATHER_MERGE_VMAS)) { in tlb_end_vma()
563 * Do a TLB flush and reset the range at VMA boundaries; this avoids in tlb_end_vma()
566 tlb_flush_mmu_tlbonly(tlb); in tlb_end_vma()
571 * tlb_flush_{pte|pmd|pud|p4d}_range() adjust the tlb->start and tlb->end,
574 static inline void tlb_flush_pte_range(struct mmu_gather *tlb, in tlb_flush_pte_range() argument
577 __tlb_adjust_range(tlb, address, size); in tlb_flush_pte_range()
578 tlb->cleared_ptes = 1; in tlb_flush_pte_range()
581 static inline void tlb_flush_pmd_range(struct mmu_gather *tlb, in tlb_flush_pmd_range() argument
584 __tlb_adjust_range(tlb, address, size); in tlb_flush_pmd_range()
585 tlb->cleared_pmds = 1; in tlb_flush_pmd_range()
588 static inline void tlb_flush_pud_range(struct mmu_gather *tlb, in tlb_flush_pud_range() argument
591 __tlb_adjust_range(tlb, address, size); in tlb_flush_pud_range()
592 tlb->cleared_puds = 1; in tlb_flush_pud_range()
595 static inline void tlb_flush_p4d_range(struct mmu_gather *tlb, in tlb_flush_p4d_range() argument
598 __tlb_adjust_range(tlb, address, size); in tlb_flush_p4d_range()
599 tlb->cleared_p4ds = 1; in tlb_flush_p4d_range()
603 static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long addres… in __tlb_remove_tlb_entry() argument
609 * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
612 * so we can later optimise away the tlb invalidate. This helps when
613 * userspace is unmapping already-unmapped pages, which happens quite a lot.
615 #define tlb_remove_tlb_entry(tlb, ptep, address) \ argument
617 tlb_flush_pte_range(tlb, address, PAGE_SIZE); \
618 __tlb_remove_tlb_entry(tlb, ptep, address); \
622 * tlb_remove_tlb_entries - remember unmapping of multiple consecutive ptes for
623 * later tlb invalidation.
628 static inline void tlb_remove_tlb_entries(struct mmu_gather *tlb, in tlb_remove_tlb_entries() argument
631 tlb_flush_pte_range(tlb, address, PAGE_SIZE * nr); in tlb_remove_tlb_entries()
633 __tlb_remove_tlb_entry(tlb, ptep, address); in tlb_remove_tlb_entries()
634 if (--nr == 0) in tlb_remove_tlb_entries()
641 #define tlb_remove_huge_tlb_entry(h, tlb, ptep, address) \ argument
645 tlb_flush_p4d_range(tlb, address, _sz); \
647 tlb_flush_pud_range(tlb, address, _sz); \
649 tlb_flush_pmd_range(tlb, address, _sz); \
651 tlb_flush_pte_range(tlb, address, _sz); \
652 __tlb_remove_tlb_entry(tlb, ptep, address); \
656 * tlb_remove_pmd_tlb_entry - remember a pmd mapping for later tlb invalidation
660 #define __tlb_remove_pmd_tlb_entry(tlb, pmdp, address) do {} while (0) argument
663 #define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \ argument
665 tlb_flush_pmd_range(tlb, address, HPAGE_PMD_SIZE); \
666 __tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \
670 * tlb_remove_pud_tlb_entry - remember a pud mapping for later tlb
674 #define __tlb_remove_pud_tlb_entry(tlb, pudp, address) do {} while (0) argument
677 #define tlb_remove_pud_tlb_entry(tlb, pudp, address) \ argument
679 tlb_flush_pud_range(tlb, address, HPAGE_PUD_SIZE); \
680 __tlb_remove_pud_tlb_entry(tlb, pudp, address); \
688 * architected non-legacy page table cache (which I'm not aware of
690 * explicit flushing for that, likely *separate* from a regular TLB entry
694 * that would want something that odd, I think it is up to that
702 #define pte_free_tlb(tlb, ptep, address) \ argument
704 tlb_flush_pmd_range(tlb, address, PAGE_SIZE); \
705 tlb->freed_tables = 1; \
706 __pte_free_tlb(tlb, ptep, address); \
711 #define pmd_free_tlb(tlb, pmdp, address) \ argument
713 tlb_flush_pud_range(tlb, address, PAGE_SIZE); \
714 tlb->freed_tables = 1; \
715 __pmd_free_tlb(tlb, pmdp, address); \
720 #define pud_free_tlb(tlb, pudp, address) \ argument
722 tlb_flush_p4d_range(tlb, address, PAGE_SIZE); \
723 tlb->freed_tables = 1; \
724 __pud_free_tlb(tlb, pudp, address); \
729 #define p4d_free_tlb(tlb, pudp, address) \ argument
731 __tlb_adjust_range(tlb, address, PAGE_SIZE); \
732 tlb->freed_tables = 1; \
733 __p4d_free_tlb(tlb, pudp, address); \