diff options
| author | Dan Williams <dan.j.williams@intel.com> | 2018-12-04 16:37:16 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2018-12-05 03:03:06 -0500 |
| commit | 4369deaa2f022ef92da45a0e7eec8a4a52e8e8a4 (patch) | |
| tree | 6732d7f5dd26688e96eaf9d93fd406cadf54e8c8 /include | |
| parent | 0cebbb60f759a709dabb3c87b9704f9844878850 (diff) | |
generic/pgtable: Introduce set_pte_safe()
Commit:
f77084d96355 "x86/mm/pat: Disable preemption around __flush_tlb_all()"
introduced a warning to capture cases __flush_tlb_all() is called without
pre-emption disabled. It triggers a false positive warning in the memory
hotplug path.
On investigation it was found that the __flush_tlb_all() calls are not
necessary. However, they are only "not necessary" in practice provided
the ptes are being initially populated from the !present state.
Introduce set_pte_safe() as a sanity check that the pte is being updated
in a way that does not require a TLB flush.
Forgive the macro, the availability of the various of set_pte() levels
is hit and miss across architectures.
[ mingo: Minor readability edits. ]
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Suggested-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/279dadae-9148-465c-7ec6-3f37e026c6c9@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/asm-generic/pgtable.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index dae7f98babed..a9cac82e9a7a 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h | |||
| @@ -400,6 +400,44 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) | |||
| 400 | } | 400 | } |
| 401 | #endif | 401 | #endif |
| 402 | 402 | ||
| 403 | /* | ||
| 404 | * Use set_p*_safe(), and elide TLB flushing, when confident that *no* | ||
| 405 | * TLB flush will be required as a result of the "set". For example, use | ||
| 406 | * in scenarios where it is known ahead of time that the routine is | ||
| 407 | * setting non-present entries, or re-setting an existing entry to the | ||
| 408 | * same value. Otherwise, use the typical "set" helpers and flush the | ||
| 409 | * TLB. | ||
| 410 | */ | ||
| 411 | #define set_pte_safe(ptep, pte) \ | ||
| 412 | ({ \ | ||
| 413 | WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ | ||
| 414 | set_pte(ptep, pte); \ | ||
| 415 | }) | ||
| 416 | |||
| 417 | #define set_pmd_safe(pmdp, pmd) \ | ||
| 418 | ({ \ | ||
| 419 | WARN_ON_ONCE(pmd_present(*pmdp) && !pmd_same(*pmdp, pmd)); \ | ||
| 420 | set_pmd(pmdp, pmd); \ | ||
| 421 | }) | ||
| 422 | |||
| 423 | #define set_pud_safe(pudp, pud) \ | ||
| 424 | ({ \ | ||
| 425 | WARN_ON_ONCE(pud_present(*pudp) && !pud_same(*pudp, pud)); \ | ||
| 426 | set_pud(pudp, pud); \ | ||
| 427 | }) | ||
| 428 | |||
| 429 | #define set_p4d_safe(p4dp, p4d) \ | ||
| 430 | ({ \ | ||
| 431 | WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ | ||
| 432 | set_p4d(p4dp, p4d); \ | ||
| 433 | }) | ||
| 434 | |||
| 435 | #define set_pgd_safe(pgdp, pgd) \ | ||
| 436 | ({ \ | ||
| 437 | WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ | ||
| 438 | set_pgd(pgdp, pgd); \ | ||
| 439 | }) | ||
| 440 | |||
| 403 | #ifndef __HAVE_ARCH_DO_SWAP_PAGE | 441 | #ifndef __HAVE_ARCH_DO_SWAP_PAGE |
| 404 | /* | 442 | /* |
| 405 | * Some architectures support metadata associated with a page. When a | 443 | * Some architectures support metadata associated with a page. When a |
