1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* include/asm-generic/tlb.h 3 * 4 * Generic TLB shootdown code 5 * 6 * Copyright 2001 Red Hat, Inc. 7 * Based on code from mm/memory.c Copyright Linus Torvalds and others. 8 * 9 * Copyright 2011 Red Hat, Inc., Peter Zijlstra 10 */ 11 #ifndef _ASM_GENERIC__TLB_H 12 #define _ASM_GENERIC__TLB_H 13 14 #include <linux/mmu_notifier.h> 15 #include <linux/swap.h> 16 #include <linux/hugetlb_inline.h> 17 #include <asm/tlbflush.h> 18 #include <asm/cacheflush.h> 19 20 /* 21 * Blindly accessing user memory from NMI context can be dangerous 22 * if we're in the middle of switching the current user task or switching 23 * the loaded mm. 24 */ 25 #ifndef nmi_uaccess_okay 26 # define nmi_uaccess_okay() true 27 #endif 28 29 #ifdef CONFIG_MMU 30 31 /* 32 * Generic MMU-gather implementation. 33 * 34 * The mmu_gather data structure is used by the mm code to implement the 35 * correct and efficient ordering of freeing pages and TLB invalidations. 36 * 37 * This correct ordering is: 38 * 39 * 1) unhook page 40 * 2) TLB invalidate page 41 * 3) free page 42 * 43 * That is, we must never free a page before we have ensured there are no live 44 * translations left to it. Otherwise it might be possible to observe (or 45 * worse, change) the page content after it has been reused. 46 * 47 * The mmu_gather API consists of: 48 * 49 * - tlb_gather_mmu() / tlb_gather_mmu_fullmm() / tlb_finish_mmu() 50 * 51 * start and finish a mmu_gather 52 * 53 * Finish in particular will issue a (final) TLB invalidate and free 54 * all (remaining) queued pages. 55 * 56 * - tlb_start_vma() / tlb_end_vma(); marks the start / end of a VMA 57 * 58 * Defaults to flushing at tlb_end_vma() to reset the range; helps when 59 * there's large holes between the VMAs. 60 * 61 * - tlb_remove_table() 62 * 63 * tlb_remove_table() is the basic primitive to free page-table directories 64 * (__p*_free_tlb()). In it's most primitive form it is an alias for 65 * tlb_remove_page() below, for when page directories are pages and have no 66 * additional constraints. 67 * 68 * See also MMU_GATHER_TABLE_FREE and MMU_GATHER_RCU_TABLE_FREE. 69 * 70 * - tlb_remove_page() / __tlb_remove_page() 71 * - tlb_remove_page_size() / __tlb_remove_page_size() 72 * - __tlb_remove_folio_pages() 73 * 74 * __tlb_remove_page_size() is the basic primitive that queues a page for 75 * freeing. __tlb_remove_page() assumes PAGE_SIZE. Both will return a 76 * boolean indicating if the queue is (now) full and a call to 77 * tlb_flush_mmu() is required. 78 * 79 * tlb_remove_page() and tlb_remove_page_size() imply the call to 80 * tlb_flush_mmu() when required and has no return value. 81 * 82 * __tlb_remove_folio_pages() is similar to __tlb_remove_page(), however, 83 * instead of removing a single page, remove the given number of consecutive 84 * pages that are all part of the same (large) folio: just like calling 85 * __tlb_remove_page() on each page individually. 86 * 87 * - tlb_change_page_size() 88 * 89 * call before __tlb_remove_page*() to set the current page-size; implies a 90 * possible tlb_flush_mmu() call. 91 * 92 * - tlb_flush_mmu() / tlb_flush_mmu_tlbonly() 93 * 94 * tlb_flush_mmu_tlbonly() - does the TLB invalidate (and resets 95 * related state, like the range) 96 * 97 * tlb_flush_mmu() - in addition to the above TLB invalidate, also frees 98 * whatever pages are still batched. 99 * 100 * - mmu_gather::fullmm 101 * 102 * A flag set by tlb_gather_mmu_fullmm() to indicate we're going to free 103 * the entire mm; this allows a number of optimizations. 104 * 105 * - We can ignore tlb_{start,end}_vma(); because we don't 106 * care about ranges. Everything will be shot down. 107 * 108 * - (RISC) architectures that use ASIDs can cycle to a new ASID 109 * and delay the invalidation until ASID space runs out. 110 * 111 * - mmu_gather::need_flush_all 112 * 113 * A flag that can be set by the arch code if it wants to force 114 * flush the entire TLB irrespective of the range. For instance 115 * x86-PAE needs this when changing top-level entries. 116 * 117 * And allows the architecture to provide and implement tlb_flush(): 118 * 119 * tlb_flush() may, in addition to the above mentioned mmu_gather fields, make 120 * use of: 121 * 122 * - mmu_gather::start / mmu_gather::end 123 * 124 * which provides the range that needs to be flushed to cover the pages to 125 * be freed. 126 * 127 * - mmu_gather::freed_tables 128 * 129 * set when we freed page table pages 130 * 131 * - tlb_get_unmap_shift() / tlb_get_unmap_size() 132 * 133 * returns the smallest TLB entry size unmapped in this range. 134 * 135 * If an architecture does not provide tlb_flush() a default implementation 136 * based on flush_tlb_range() will be used, unless MMU_GATHER_NO_RANGE is 137 * specified, in which case we'll default to flush_tlb_mm(). 138 * 139 * Additionally there are a few opt-in features: 140 * 141 * MMU_GATHER_PAGE_SIZE 142 * 143 * This ensures we call tlb_flush() every time tlb_change_page_size() actually 144 * changes the size and provides mmu_gather::page_size to tlb_flush(). 145 * 146 * This might be useful if your architecture has size specific TLB 147 * invalidation instructions. 148 * 149 * MMU_GATHER_TABLE_FREE 150 * 151 * This provides tlb_remove_table(), to be used instead of tlb_remove_page() 152 * for page directores (__p*_free_tlb()). 153 * 154 * Useful if your architecture has non-page page directories. 155 * 156 * When used, an architecture is expected to provide __tlb_remove_table() or 157 * use the generic __tlb_remove_table(), which does the actual freeing of these 158 * pages. 159 * 160 * MMU_GATHER_RCU_TABLE_FREE 161 * 162 * Like MMU_GATHER_TABLE_FREE, and adds semi-RCU semantics to the free (see 163 * comment below). 164 * 165 * Useful if your architecture doesn't use IPIs for remote TLB invalidates 166 * and therefore doesn't naturally serialize with software page-table walkers. 167 * 168 * MMU_GATHER_NO_FLUSH_CACHE 169 * 170 * Indicates the architecture has flush_cache_range() but it needs *NOT* be called 171 * before unmapping a VMA. 172 * 173 * NOTE: strictly speaking we shouldn't have this knob and instead rely on 174 * flush_cache_range() being a NOP, except Sparc64 seems to be 175 * different here. 176 * 177 * MMU_GATHER_MERGE_VMAS 178 * 179 * Indicates the architecture wants to merge ranges over VMAs; typical when 180 * multiple range invalidates are more expensive than a full invalidate. 181 * 182 * MMU_GATHER_NO_RANGE 183 * 184 * Use this if your architecture lacks an efficient flush_tlb_range(). This 185 * option implies MMU_GATHER_MERGE_VMAS above. 186 * 187 * MMU_GATHER_NO_GATHER 188 * 189 * If the option is set the mmu_gather will not track individual pages for 190 * delayed page free anymore. A platform that enables the option needs to 191 * provide its own implementation of the __tlb_remove_page_size() function to 192 * free pages. 193 * 194 * This is useful if your architecture already flushes TLB entries in the 195 * various ptep_get_and_clear() functions. 196 */ 197 198 #ifdef CONFIG_MMU_GATHER_TABLE_FREE 199 200 struct mmu_table_batch { 201 #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE 202 struct rcu_head rcu; 203 #endif 204 unsigned int nr; 205 void *tables[]; 206 }; 207 208 #define MAX_TABLE_BATCH \ 209 ((PAGE_SIZE - sizeof(struct mmu_table_batch)) / sizeof(void *)) 210 211 #ifndef __HAVE_ARCH_TLB_REMOVE_TABLE 212 static inline void __tlb_remove_table(void *table) 213 { 214 struct ptdesc *ptdesc = (struct ptdesc *)table; 215 216 pagetable_dtor_free(ptdesc); 217 } 218 #endif 219 220 extern void tlb_remove_table(struct mmu_gather *tlb, void *table); 221 222 #else /* !CONFIG_MMU_GATHER_TABLE_FREE */ 223 224 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page); 225 /* 226 * Without MMU_GATHER_TABLE_FREE the architecture is assumed to have page based 227 * page directories and we can use the normal page batching to free them. 228 */ 229 static inline void tlb_remove_table(struct mmu_gather *tlb, void *table) 230 { 231 struct page *page = (struct page *)table; 232 233 pagetable_dtor(page_ptdesc(page)); 234 tlb_remove_page(tlb, page); 235 } 236 #endif /* CONFIG_MMU_GATHER_TABLE_FREE */ 237 238 #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE 239 /* 240 * This allows an architecture that does not use the linux page-tables for 241 * hardware to skip the TLBI when freeing page tables. 242 */ 243 #ifndef tlb_needs_table_invalidate 244 #define tlb_needs_table_invalidate() (true) 245 #endif 246 247 void tlb_remove_table_sync_one(void); 248 249 #else 250 251 #ifdef tlb_needs_table_invalidate 252 #error tlb_needs_table_invalidate() requires MMU_GATHER_RCU_TABLE_FREE 253 #endif 254 255 static inline void tlb_remove_table_sync_one(void) { } 256 257 #endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ 258 259 260 #ifndef CONFIG_MMU_GATHER_NO_GATHER 261 /* 262 * If we can't allocate a page to make a big batch of page pointers 263 * to work on, then just handle a few from the on-stack structure. 264 */ 265 #define MMU_GATHER_BUNDLE 8 266 267 struct mmu_gather_batch { 268 struct mmu_gather_batch *next; 269 unsigned int nr; 270 unsigned int max; 271 struct encoded_page *encoded_pages[]; 272 }; 273 274 #define MAX_GATHER_BATCH \ 275 ((PAGE_SIZE - sizeof(struct mmu_gather_batch)) / sizeof(void *)) 276 277 /* 278 * Limit the maximum number of mmu_gather batches to reduce a risk of soft 279 * lockups for non-preemptible kernels on huge machines when a lot of memory 280 * is zapped during unmapping. 281 * 10K pages freed at once should be safe even without a preemption point. 282 */ 283 #define MAX_GATHER_BATCH_COUNT (10000UL/MAX_GATHER_BATCH) 284 285 extern bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, 286 bool delay_rmap, int page_size); 287 bool __tlb_remove_folio_pages(struct mmu_gather *tlb, struct page *page, 288 unsigned int nr_pages, bool delay_rmap); 289 290 #ifdef CONFIG_SMP 291 /* 292 * This both sets 'delayed_rmap', and returns true. It would be an inline 293 * function, except we define it before the 'struct mmu_gather'. 294 */ 295 #define tlb_delay_rmap(tlb) (((tlb)->delayed_rmap = 1), true) 296 extern void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma); 297 #endif 298 299 #endif 300 301 /* 302 * We have a no-op version of the rmap removal that doesn't 303 * delay anything. That is used on S390, which flushes remote 304 * TLBs synchronously, and on UP, which doesn't have any 305 * remote TLBs to flush and is not preemptible due to this 306 * all happening under the page table lock. 307 */ 308 #ifndef tlb_delay_rmap 309 #define tlb_delay_rmap(tlb) (false) 310 static inline void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma) { } 311 #endif 312 313 /* 314 * struct mmu_gather is an opaque type used by the mm code for passing around 315 * any data needed by arch specific code for tlb_remove_page. 316 */ 317 struct mmu_gather { 318 struct mm_struct *mm; 319 320 #ifdef CONFIG_MMU_GATHER_TABLE_FREE 321 struct mmu_table_batch *batch; 322 #endif 323 324 unsigned long start; 325 unsigned long end; 326 /* 327 * we are in the middle of an operation to clear 328 * a full mm and can make some optimizations 329 */ 330 unsigned int fullmm : 1; 331 332 /* 333 * we have performed an operation which 334 * requires a complete flush of the tlb 335 */ 336 unsigned int need_flush_all : 1; 337 338 /* 339 * we have removed page directories 340 */ 341 unsigned int freed_tables : 1; 342 343 /* 344 * Do we have pending delayed rmap removals? 345 */ 346 unsigned int delayed_rmap : 1; 347 348 /* 349 * at which levels have we cleared entries? 350 */ 351 unsigned int cleared_ptes : 1; 352 unsigned int cleared_pmds : 1; 353 unsigned int cleared_puds : 1; 354 unsigned int cleared_p4ds : 1; 355 356 /* 357 * tracks VM_EXEC | VM_HUGETLB in tlb_start_vma 358 */ 359 unsigned int vma_exec : 1; 360 unsigned int vma_huge : 1; 361 unsigned int vma_pfn : 1; 362 363 unsigned int batch_count; 364 365 #ifndef CONFIG_MMU_GATHER_NO_GATHER 366 struct mmu_gather_batch *active; 367 struct mmu_gather_batch local; 368 struct page *__pages[MMU_GATHER_BUNDLE]; 369 370 #ifdef CONFIG_MMU_GATHER_PAGE_SIZE 371 unsigned int page_size; 372 #endif 373 #endif 374 }; 375 376 void tlb_flush_mmu(struct mmu_gather *tlb); 377 378 static inline void __tlb_adjust_range(struct mmu_gather *tlb, 379 unsigned long address, 380 unsigned int range_size) 381 { 382 tlb->start = min(tlb->start, address); 383 tlb->end = max(tlb->end, address + range_size); 384 } 385 386 static inline void __tlb_reset_range(struct mmu_gather *tlb) 387 { 388 if (tlb->fullmm) { 389 tlb->start = tlb->end = ~0; 390 } else { 391 tlb->start = TASK_SIZE; 392 tlb->end = 0; 393 } 394 tlb->freed_tables = 0; 395 tlb->cleared_ptes = 0; 396 tlb->cleared_pmds = 0; 397 tlb->cleared_puds = 0; 398 tlb->cleared_p4ds = 0; 399 /* 400 * Do not reset mmu_gather::vma_* fields here, we do not 401 * call into tlb_start_vma() again to set them if there is an 402 * intermediate flush. 403 */ 404 } 405 406 #ifdef CONFIG_MMU_GATHER_NO_RANGE 407 408 #if defined(tlb_flush) 409 #error MMU_GATHER_NO_RANGE relies on default tlb_flush() 410 #endif 411 412 /* 413 * When an architecture does not have efficient means of range flushing TLBs 414 * there is no point in doing intermediate flushes on tlb_end_vma() to keep the 415 * range small. We equally don't have to worry about page granularity or other 416 * things. 417 * 418 * All we need to do is issue a full flush for any !0 range. 419 */ 420 static inline void tlb_flush(struct mmu_gather *tlb) 421 { 422 if (tlb->end) 423 flush_tlb_mm(tlb->mm); 424 } 425 426 #else /* CONFIG_MMU_GATHER_NO_RANGE */ 427 428 #ifndef tlb_flush 429 /* 430 * When an architecture does not provide its own tlb_flush() implementation 431 * but does have a reasonably efficient flush_vma_range() implementation 432 * use that. 433 */ 434 static inline void tlb_flush(struct mmu_gather *tlb) 435 { 436 if (tlb->fullmm || tlb->need_flush_all) { 437 flush_tlb_mm(tlb->mm); 438 } else if (tlb->end) { 439 struct vm_area_struct vma = { 440 .vm_mm = tlb->mm, 441 .vm_flags = (tlb->vma_exec ? VM_EXEC : 0) | 442 (tlb->vma_huge ? VM_HUGETLB : 0), 443 }; 444 445 flush_tlb_range(&vma, tlb->start, tlb->end); 446 } 447 } 448 #endif 449 450 #endif /* CONFIG_MMU_GATHER_NO_RANGE */ 451 452 static inline void 453 tlb_update_vma_flags(struct mmu_gather *tlb, struct vm_area_struct *vma) 454 { 455 /* 456 * flush_tlb_range() implementations that look at VM_HUGETLB (tile, 457 * mips-4k) flush only large pages. 458 * 459 * flush_tlb_range() implementations that flush I-TLB also flush D-TLB 460 * (tile, xtensa, arm), so it's ok to just add VM_EXEC to an existing 461 * range. 462 * 463 * We rely on tlb_end_vma() to issue a flush, such that when we reset 464 * these values the batch is empty. 465 */ 466 tlb->vma_huge = is_vm_hugetlb_page(vma); 467 tlb->vma_exec = !!(vma->vm_flags & VM_EXEC); 468 tlb->vma_pfn = !!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)); 469 } 470 471 static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) 472 { 473 /* 474 * Anything calling __tlb_adjust_range() also sets at least one of 475 * these bits. 476 */ 477 if (!(tlb->freed_tables || tlb->cleared_ptes || tlb->cleared_pmds || 478 tlb->cleared_puds || tlb->cleared_p4ds)) 479 return; 480 481 tlb_flush(tlb); 482 __tlb_reset_range(tlb); 483 } 484 485 static inline void tlb_remove_page_size(struct mmu_gather *tlb, 486 struct page *page, int page_size) 487 { 488 if (__tlb_remove_page_size(tlb, page, false, page_size)) 489 tlb_flush_mmu(tlb); 490 } 491 492 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page) 493 { 494 return tlb_remove_page_size(tlb, page, PAGE_SIZE); 495 } 496 497 static inline void tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) 498 { 499 tlb_remove_table(tlb, pt); 500 } 501 502 /* Like tlb_remove_ptdesc, but for page-like page directories. */ 503 static inline void tlb_remove_page_ptdesc(struct mmu_gather *tlb, struct ptdesc *pt) 504 { 505 tlb_remove_page(tlb, ptdesc_page(pt)); 506 } 507 508 static inline void tlb_change_page_size(struct mmu_gather *tlb, 509 unsigned int page_size) 510 { 511 #ifdef CONFIG_MMU_GATHER_PAGE_SIZE 512 if (tlb->page_size && tlb->page_size != page_size) { 513 if (!tlb->fullmm && !tlb->need_flush_all) 514 tlb_flush_mmu(tlb); 515 } 516 517 tlb->page_size = page_size; 518 #endif 519 } 520 521 static inline unsigned long tlb_get_unmap_shift(struct mmu_gather *tlb) 522 { 523 if (tlb->cleared_ptes) 524 return PAGE_SHIFT; 525 if (tlb->cleared_pmds) 526 return PMD_SHIFT; 527 if (tlb->cleared_puds) 528 return PUD_SHIFT; 529 if (tlb->cleared_p4ds) 530 return P4D_SHIFT; 531 532 return PAGE_SHIFT; 533 } 534 535 static inline unsigned long tlb_get_unmap_size(struct mmu_gather *tlb) 536 { 537 return 1UL << tlb_get_unmap_shift(tlb); 538 } 539 540 /* 541 * In the case of tlb vma handling, we can optimise these away in the 542 * case where we're doing a full MM flush. When we're doing a munmap, 543 * the vmas are adjusted to only cover the region to be torn down. 544 */ 545 static inline void tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) 546 { 547 if (tlb->fullmm) 548 return; 549 550 tlb_update_vma_flags(tlb, vma); 551 #ifndef CONFIG_MMU_GATHER_NO_FLUSH_CACHE 552 flush_cache_range(vma, vma->vm_start, vma->vm_end); 553 #endif 554 } 555 556 static inline void tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) 557 { 558 if (tlb->fullmm) 559 return; 560 561 /* 562 * VM_PFNMAP is more fragile because the core mm will not track the 563 * page mapcount -- there might not be page-frames for these PFNs after 564 * all. Force flush TLBs for such ranges to avoid munmap() vs 565 * unmap_mapping_range() races. 566 */ 567 if (tlb->vma_pfn || !IS_ENABLED(CONFIG_MMU_GATHER_MERGE_VMAS)) { 568 /* 569 * Do a TLB flush and reset the range at VMA boundaries; this avoids 570 * the ranges growing with the unused space between consecutive VMAs. 571 */ 572 tlb_flush_mmu_tlbonly(tlb); 573 } 574 } 575 576 /* 577 * tlb_flush_{pte|pmd|pud|p4d}_range() adjust the tlb->start and tlb->end, 578 * and set corresponding cleared_*. 579 */ 580 static inline void tlb_flush_pte_range(struct mmu_gather *tlb, 581 unsigned long address, unsigned long size) 582 { 583 __tlb_adjust_range(tlb, address, size); 584 tlb->cleared_ptes = 1; 585 } 586 587 static inline void tlb_flush_pmd_range(struct mmu_gather *tlb, 588 unsigned long address, unsigned long size) 589 { 590 __tlb_adjust_range(tlb, address, size); 591 tlb->cleared_pmds = 1; 592 } 593 594 static inline void tlb_flush_pud_range(struct mmu_gather *tlb, 595 unsigned long address, unsigned long size) 596 { 597 __tlb_adjust_range(tlb, address, size); 598 tlb->cleared_puds = 1; 599 } 600 601 static inline void tlb_flush_p4d_range(struct mmu_gather *tlb, 602 unsigned long address, unsigned long size) 603 { 604 __tlb_adjust_range(tlb, address, size); 605 tlb->cleared_p4ds = 1; 606 } 607 608 #ifndef __tlb_remove_tlb_entry 609 static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address) 610 { 611 } 612 #endif 613 614 /** 615 * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation. 616 * 617 * Record the fact that pte's were really unmapped by updating the range, 618 * so we can later optimise away the tlb invalidate. This helps when 619 * userspace is unmapping already-unmapped pages, which happens quite a lot. 620 */ 621 #define tlb_remove_tlb_entry(tlb, ptep, address) \ 622 do { \ 623 tlb_flush_pte_range(tlb, address, PAGE_SIZE); \ 624 __tlb_remove_tlb_entry(tlb, ptep, address); \ 625 } while (0) 626 627 /** 628 * tlb_remove_tlb_entries - remember unmapping of multiple consecutive ptes for 629 * later tlb invalidation. 630 * 631 * Similar to tlb_remove_tlb_entry(), but remember unmapping of multiple 632 * consecutive ptes instead of only a single one. 633 */ 634 static inline void tlb_remove_tlb_entries(struct mmu_gather *tlb, 635 pte_t *ptep, unsigned int nr, unsigned long address) 636 { 637 tlb_flush_pte_range(tlb, address, PAGE_SIZE * nr); 638 for (;;) { 639 __tlb_remove_tlb_entry(tlb, ptep, address); 640 if (--nr == 0) 641 break; 642 ptep++; 643 address += PAGE_SIZE; 644 } 645 } 646 647 #define tlb_remove_huge_tlb_entry(h, tlb, ptep, address) \ 648 do { \ 649 unsigned long _sz = huge_page_size(h); \ 650 if (_sz >= P4D_SIZE) \ 651 tlb_flush_p4d_range(tlb, address, _sz); \ 652 else if (_sz >= PUD_SIZE) \ 653 tlb_flush_pud_range(tlb, address, _sz); \ 654 else if (_sz >= PMD_SIZE) \ 655 tlb_flush_pmd_range(tlb, address, _sz); \ 656 else \ 657 tlb_flush_pte_range(tlb, address, _sz); \ 658 __tlb_remove_tlb_entry(tlb, ptep, address); \ 659 } while (0) 660 661 /** 662 * tlb_remove_pmd_tlb_entry - remember a pmd mapping for later tlb invalidation 663 * This is a nop so far, because only x86 needs it. 664 */ 665 #ifndef __tlb_remove_pmd_tlb_entry 666 #define __tlb_remove_pmd_tlb_entry(tlb, pmdp, address) do {} while (0) 667 #endif 668 669 #define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \ 670 do { \ 671 tlb_flush_pmd_range(tlb, address, HPAGE_PMD_SIZE); \ 672 __tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \ 673 } while (0) 674 675 /** 676 * tlb_remove_pud_tlb_entry - remember a pud mapping for later tlb 677 * invalidation. This is a nop so far, because only x86 needs it. 678 */ 679 #ifndef __tlb_remove_pud_tlb_entry 680 #define __tlb_remove_pud_tlb_entry(tlb, pudp, address) do {} while (0) 681 #endif 682 683 #define tlb_remove_pud_tlb_entry(tlb, pudp, address) \ 684 do { \ 685 tlb_flush_pud_range(tlb, address, HPAGE_PUD_SIZE); \ 686 __tlb_remove_pud_tlb_entry(tlb, pudp, address); \ 687 } while (0) 688 689 /* 690 * For things like page tables caches (ie caching addresses "inside" the 691 * page tables, like x86 does), for legacy reasons, flushing an 692 * individual page had better flush the page table caches behind it. This 693 * is definitely how x86 works, for example. And if you have an 694 * architected non-legacy page table cache (which I'm not aware of 695 * anybody actually doing), you're going to have some architecturally 696 * explicit flushing for that, likely *separate* from a regular TLB entry 697 * flush, and thus you'd need more than just some range expansion.. 698 * 699 * So if we ever find an architecture 700 * that would want something that odd, I think it is up to that 701 * architecture to do its own odd thing, not cause pain for others 702 * http://lkml.kernel.org/r/CA+55aFzBggoXtNXQeng5d_mRoDnaMBE5Y+URs+PHR67nUpMtaw@mail.gmail.com 703 * 704 * For now w.r.t page table cache, mark the range_size as PAGE_SIZE 705 */ 706 707 #ifndef pte_free_tlb 708 #define pte_free_tlb(tlb, ptep, address) \ 709 do { \ 710 tlb_flush_pmd_range(tlb, address, PAGE_SIZE); \ 711 tlb->freed_tables = 1; \ 712 __pte_free_tlb(tlb, ptep, address); \ 713 } while (0) 714 #endif 715 716 #ifndef pmd_free_tlb 717 #define pmd_free_tlb(tlb, pmdp, address) \ 718 do { \ 719 tlb_flush_pud_range(tlb, address, PAGE_SIZE); \ 720 tlb->freed_tables = 1; \ 721 __pmd_free_tlb(tlb, pmdp, address); \ 722 } while (0) 723 #endif 724 725 #ifndef pud_free_tlb 726 #define pud_free_tlb(tlb, pudp, address) \ 727 do { \ 728 tlb_flush_p4d_range(tlb, address, PAGE_SIZE); \ 729 tlb->freed_tables = 1; \ 730 __pud_free_tlb(tlb, pudp, address); \ 731 } while (0) 732 #endif 733 734 #ifndef p4d_free_tlb 735 #define p4d_free_tlb(tlb, pudp, address) \ 736 do { \ 737 __tlb_adjust_range(tlb, address, PAGE_SIZE); \ 738 tlb->freed_tables = 1; \ 739 __p4d_free_tlb(tlb, pudp, address); \ 740 } while (0) 741 #endif 742 743 #ifndef pte_needs_flush 744 static inline bool pte_needs_flush(pte_t oldpte, pte_t newpte) 745 { 746 return true; 747 } 748 #endif 749 750 #ifndef huge_pmd_needs_flush 751 static inline bool huge_pmd_needs_flush(pmd_t oldpmd, pmd_t newpmd) 752 { 753 return true; 754 } 755 #endif 756 757 #endif /* CONFIG_MMU */ 758 759 #endif /* _ASM_GENERIC__TLB_H */ 760