mm: Move set_pxd_safe() helpers from generic to platform
Subsystems (4)
PATCH RESEND 1/1 mm: Move set_pxd_safe() helpers from generic to platform
set_pxd_safe() helpers that serve a specific purpose for both x86 and riscv platforms, do not need to be in the common memory code. Otherwise they just unnecessarily make the common API more complicated. This moves the helpers from common code to platform instead.
---
This patch applies on v6.12-rc1
This patch is just a resend for an earlier patch
https://lore.kernel.org/all/[email protected]/
arch/riscv/include/asm/pgtable.h | 19 ++++++++++++++++ arch/x86/include/asm/pgtable.h | 37 +++++++++++++++++++++++++++++++ include/linux/pgtable.h | 38 -------------------------------- 3 files changed, 56 insertions(+), 38 deletions(-)
arch/riscv/include/asm/pgtable.h +19 -0
@@ -963,6 +963,25 @@ void misc_mem_init(void);extern unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )];#define ZERO_PAGE (vaddr) (virt_to_page(empty_zero_page)) +/* +* Use set_p*_safe(), and elide TLB flushing, when confident that *no* +* TLB flush will be required as a result of the "set". For example, use +* in scenarios where it is known ahead of time that the routine is +* setting non-present entries, or re-setting an existing entry to the +* same value. Otherwise, use the typical "set" helpers and flush the +* TLB. +*/ +#define set_p4d_safe (p4dp, p4d) \ +({ \ + WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ + set_p4d(p4dp, p4d); \ +}) + +#define set_pgd_safe (pgdp, pgd) \ +({ \ + WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ + set_pgd(pgdp, pgd); \ +})#endif /* !__ASSEMBLY__ */ #endif /* _ASM_RISCV_PGTABLE_H */
arch/x86/include/asm/pgtable.h +37 -0
@@ -1775,6 +1775,43 @@ bool arch_is_platform_page(u64 paddr);#define arch_is_platform_page arch_is_platform_page#endif +/* +* Use set_p*_safe(), and elide TLB flushing, when confident that *no* +* TLB flush will be required as a result of the "set". For example, use +* in scenarios where it is known ahead of time that the routine is +* setting non-present entries, or re-setting an existing entry to the +* same value. Otherwise, use the typical "set" helpers and flush the +* TLB. +*/ +#define set_pte_safe (ptep, pte) \ +({ \ + WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ + set_pte(ptep, pte); \ +}) + +#define set_pmd_safe (pmdp, pmd) \ +({ \ + WARN_ON_ONCE(pmd_present(*pmdp) && !pmd_same(*pmdp, pmd)); \ + set_pmd(pmdp, pmd); \ +}) + +#define set_pud_safe (pudp, pud) \ +({ \ + WARN_ON_ONCE(pud_present(*pudp) && !pud_same(*pudp, pud)); \ + set_pud(pudp, pud); \ +}) + +#define set_p4d_safe (p4dp, p4d) \ +({ \ + WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ + set_p4d(p4dp, p4d); \ +}) + +#define set_pgd_safe (pgdp, pgd) \ +({ \ + WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ + set_pgd(pgdp, pgd); \ +})#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_H */
include/linux/pgtable.h +0 -38
@@ -1056,44 +1056,6 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) }#endif -/* -* Use set_p*_safe(), and elide TLB flushing, when confident that *no* -* TLB flush will be required as a result of the "set". For example, use -* in scenarios where it is known ahead of time that the routine is -* setting non-present entries, or re-setting an existing entry to the -* same value. Otherwise, use the typical "set" helpers and flush the -* TLB. -*/ -#define set_pte_safe (ptep, pte) \ -({ \ - WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ - set_pte(ptep, pte); \ -}) - -#define set_pmd_safe (pmdp, pmd) \ -({ \ - WARN_ON_ONCE(pmd_present(*pmdp) && !pmd_same(*pmdp, pmd)); \ - set_pmd(pmdp, pmd); \ -}) - -#define set_pud_safe (pudp, pud) \ -({ \ - WARN_ON_ONCE(pud_present(*pudp) && !pud_same(*pudp, pud)); \ - set_pud(pudp, pud); \ -}) - -#define set_p4d_safe (p4dp, p4d) \ -({ \ - WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ - set_p4d(p4dp, p4d); \ -}) - -#define set_pgd_safe (pgdp, pgd) \ -({ \ - WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ - set_pgd(pgdp, pgd); \ -}) -#ifndef __HAVE_ARCH_DO_SWAP_PAGE static inline void arch_do_swap_page_nr(struct mm_struct *mm, struct vm_area_struct *vma,
Signature · 1 line
2.25.1
Quoted 4 lines · Anshuman Khandual
set_pxd_safe()helpers that serve a specific purpose for both x86 and riscv platforms, do not need to be in the common memory code. Otherwise they just unnecessarily make the common API more complicated. This moves the helpers from common code to platform instead.
I looked into the x86 side a bit. I'm pretty sure we can just remove the _safe variants. All they do is spew warnings that don't seem to be doing any good. They're not really safer in any meaningful way.
I've got a series cooked up to zap them, but I need to get some eyeballs on it.
But if Andrew wants to pick this up any carry it in the meantime since it's cross-arch I'm fine with it:
David Hildenbrand
Acked-byQuoted 9 lines · Dave Hansen
Quoted 4 lines · Anshuman Khandual
set_pxd_safe()helpers that serve a specific purpose for both x86 and riscv platforms, do not need to be in the common memory code. Otherwise they just unnecessarily make the common API more complicated. This moves the helpers from common code to platform instead.I looked into the x86 side a bit. I'm pretty sure we can just remove the
_safevariants. All they do is spew warnings that don't seem to be doing any good. They're not really safer in any meaningful way.
Yes, one reason I am happy that we are removing them from core code :)
Quoted 3 lines
I've got a series cooked up to zap them, but I need to get some eyeballs on it.
Feel free to CC me. If you're busy, let me know and I might have someone to tackle this.
Signature · 3 lines
Cheers, David / dhildenb
This patch was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Andrew Morton <[email protected]>:
Quoted 19 lines · On Thu, 3 Oct 2024 10:18:42 +0530 you wrote:
set_pxd_safe()helpers that serve a specific purpose for both x86 and riscv platforms, do not need to be in the common memory code. Otherwise they just unnecessarily make the common API more complicated. This moves the helpers from common code to platform instead.Cc Paul Walmsley <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Dave Hansen <[email protected]>Cc David Hildenbrand <[email protected]>Cc Ryan Roberts <[email protected]>Cc Andrew Morton <[email protected]>Suggested-by David Hildenbrand <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>
Quoted 1 line
[...]
Here is the summary with links:
- [RESEND] mm: Move set_pxd_safe() helpers from generic to platform
https://git.kernel.org/riscv/c/d7d65b103901
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html