Switch x86 to generic get_user_pages_fast() implementation
Subsystems (11)
cover Switch x86 to generic get_user_pages_fast() implementation
Hi,
The patcheset generalize mm/gup.c implementation of get_user_pages_fast() to be usable for x86 and switches x86 over.
Please review and consider applying.
Kirill A. Shutemov (7):
mm: Drop arch_pte_access_permitted() mmu hook
mm/gup: Move permission checks into helpers
mm/gup: Move page table entry dereference into helper mm/gup: Make pages referenced during generic get_user_pages_fast() mm/gup: Implement dev_pagemap logic in generic get_user_pages_fast() mm/gup: Provide hook to check if __GUP_fast() is allowed for the range x86/mm: Switch to generic get_user_page_fast() implementation
arch/powerpc/include/asm/mmu_context.h | 6 - arch/s390/include/asm/mmu_context.h | 6 - arch/um/include/asm/mmu_context.h | 6 - arch/unicore32/include/asm/mmu_context.h | 6 - arch/x86/Kconfig | 3 + arch/x86/include/asm/mmu_context.h | 16 - arch/x86/include/asm/pgtable-3level.h | 45 +++ arch/x86/include/asm/pgtable.h | 53 ++++ arch/x86/include/asm/pgtable_64.h | 16 +- arch/x86/mm/Makefile | 2 +- arch/x86/mm/gup.c | 496 ------------------------------- include/asm-generic/mm_hooks.h | 6 - include/asm-generic/pgtable.h | 25 ++ include/linux/mm.h | 4 + mm/gup.c | 134 +++++++-- 15 files changed, 262 insertions(+), 562 deletions(-) delete mode 100644 arch/x86/mm/gup.c
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/7 mm: Drop arch_pte_access_permitted() mmu hook
The only arch that defines it to something meaningful is x86. But x86 doesn't use generic GUP_fast() implementation -- the only place where the hook is called.
Let's drop it.
--- arch/powerpc/include/asm/mmu_context.h | 6 ------ arch/s390/include/asm/mmu_context.h | 6 ------ arch/um/include/asm/mmu_context.h | 6 ------ arch/unicore32/include/asm/mmu_context.h | 6 ------ arch/x86/include/asm/mmu_context.h | 4 ---- include/asm-generic/mm_hooks.h | 6 ------ mm/gup.c | 3 --- 7 files changed, 37 deletions(-)
arch/powerpc/include/asm/mmu_context.h +0 -6
@@ -163,11 +163,5 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif /* __KERNEL__ */ #endif /* __ASM_POWERPC_MMU_CONTEXT_H */
arch/s390/include/asm/mmu_context.h +0 -6
@@ -156,10 +156,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif /* __S390_MMU_CONTEXT_H */
arch/um/include/asm/mmu_context.h +0 -6
@@ -37,12 +37,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,return true; } -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -} -/* * end asm-generic/mm_hooks.h functions */
arch/unicore32/include/asm/mmu_context.h +0 -6
@@ -103,10 +103,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif
arch/x86/include/asm/mmu_context.h +0 -4
@@ -268,8 +268,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, return __pkru_allows_pkey(vma_pkey(vma), write); } -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -return __pkru_allows_pkey (pte_flags_pkey (pte_flags (pte)), write); -}#endif /* _ASM_X86_MMU_CONTEXT_H */
include/asm-generic/mm_hooks.h +0 -6
@@ -32,10 +32,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif /* _ASM_GENERIC_MM_HOOKS_H */
mm/gup.c +0 -3
@@ -1216,9 +1216,6 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, pte_protnone(pte) || (write && !pte_write(pte))) goto pte_unmap; -if (!arch_pte_access_permitted (pte, write)) - goto pte_unmap; -VM_BUG_ON (!pfn_valid (pte_pfn (pte))); page =pte_page (pte); head =compound_head (page);
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] mm/gup: Drop the arch_pte_access_permitted() MMU callback
mm/gup: Drop the arch_pte_access_permitted() MMU callback
Commit-ID: 9a804fecee232e71b47ac37d62fd3d5d66b08b91 Gitweb: http://git.kernel.org/tip/9a804fecee232e71b47ac37d62fd3d5d66b08b91 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Thu, 16 Mar 2017 18:26:49 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:01 +0100
mm/gup: Drop the arch_pte_access_permitted() MMU callback
The only arch that defines it to something meaningful is x86. But x86 doesn't use the generic GUP_fast() implementation -- the only place where the callback is called.
Let's drop it.
--- arch/powerpc/include/asm/mmu_context.h | 6 ------ arch/s390/include/asm/mmu_context.h | 6 ------ arch/um/include/asm/mmu_context.h | 6 ------ arch/unicore32/include/asm/mmu_context.h | 6 ------ arch/x86/include/asm/mmu_context.h | 4 ---- include/asm-generic/mm_hooks.h | 6 ------ mm/gup.c | 3 --- 7 files changed, 37 deletions(-)
arch/powerpc/include/asm/mmu_context.h +0 -6
@@ -163,11 +163,5 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif /* __KERNEL__ */ #endif /* __ASM_POWERPC_MMU_CONTEXT_H */
arch/s390/include/asm/mmu_context.h +0 -6
@@ -156,10 +156,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif /* __S390_MMU_CONTEXT_H */
arch/um/include/asm/mmu_context.h +0 -6
@@ -37,12 +37,6 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,return true; } -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -} -/* * end asm-generic/mm_hooks.h functions */
arch/unicore32/include/asm/mmu_context.h +0 -6
@@ -103,10 +103,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif
arch/x86/include/asm/mmu_context.h +0 -4
@@ -268,8 +268,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, return __pkru_allows_pkey(vma_pkey(vma), write); } -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -return __pkru_allows_pkey (pte_flags_pkey (pte_flags (pte)), write); -}#endif /* _ASM_X86_MMU_CONTEXT_H */
include/asm-generic/mm_hooks.h +0 -6
@@ -32,10 +32,4 @@ static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,/* by default, allow everything */ return true; } - -static inline bool arch_pte_access_permitted (pte_t pte,bool write) -{ -/* by default, allow everything */ -return true; -}#endif /* _ASM_GENERIC_MM_HOOKS_H */
mm/gup.c +0 -3
@@ -1216,9 +1216,6 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, pte_protnone(pte) || (write && !pte_write(pte))) goto pte_unmap; -if (!arch_pte_access_permitted (pte, write)) - goto pte_unmap; -VM_BUG_ON (!pfn_valid (pte_pfn (pte))); page =pte_page (pte); head =compound_head (page);
PATCH 2/7 mm/gup: Move permission checks into helpers
In reply to Kirill A. ShutemovThis is preparation patch for transition of x86 to generic GUP_fast() implementation.
On x86, we would need to do additional permission checks to determinate if access is allowed.
Let's abstract it out into separate helpers.
--- include/asm-generic/pgtable.h | 25 +++++++++++++++++++++++++ mm/gup.c | 15 ++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-)
include/asm-generic/pgtable.h +25 -0
@@ -341,6 +341,31 @@ static inline int pte_unused(pte_t pte) }#endif +#ifndef pte_access_permitted +#define pte_access_permitted (pte, write) \ + (pte_present(pte) && (!(write) || pte_write(pte))) +#endif + +#ifndef pmd_access_permitted +#define pmd_access_permitted (pmd, write) \ + (pmd_present(pmd) && (!(write) || pmd_write(pmd))) +#endif + +#ifndef pud_access_permitted +#define pud_access_permitted (pud, write) \ + (pud_present(pud) && (!(write) || pud_write(pud))) +#endif + +#ifndef p4d_access_permitted +#define p4d_access_permitted (p4d, write) \ + (p4d_present(p4d) && (!(write) || p4d_write(p4d))) +#endif + +#ifndef pgd_access_permitted +#define pgd_access_permitted (pgd, write) \ + (pgd_present(pgd) && (!(write) || pgd_write(pgd))) +#endif +#ifndef __HAVE_ARCH_PMD_SAME#ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline int pmd_same (pmd_t pmd_a,pmd_t pmd_b)
mm/gup.c +10 -5
@@ -1212,8 +1212,13 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,* Similar to the PMD case below, NUMA hinting must take slow * path using the pte_protnone check. */ -if (!pte_present (pte) ||pte_special (pte) || -pte_protnone (pte) || (write && !pte_write (pte))) +if (pte_protnone (pte)) + goto pte_unmap; + +if (!pte_access_permitted (pte, write)) + goto pte_unmap; + +if (pte_special (pte)) goto pte_unmap;VM_BUG_ON (!pfn_valid (pte_pfn (pte)));
@@ -1264,7 +1269,7 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,struct page *head, *page;int refs; -if (write && !pmd_write (orig)) +if (!pmd_access_permitted (orig, write))return 0 ; refs =0 ;
@@ -1299,7 +1304,7 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,struct page *head, *page;int refs; -if (write && !pud_write (orig)) +if (!pud_access_permitted (orig, write))return 0 ; refs =0 ;
@@ -1335,7 +1340,7 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,int refs;struct page *head, *page; -if (write && !pgd_write (orig)) +if (!pgd_access_permitted (orig, write))return 0 ; refs =0 ;
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] mm/gup: Move permission checks into helpers
mm/gup: Move permission checks into helpers
Commit-ID: e7884f8ead4a301b04687a3238527b06feef8ea0 Gitweb: http://git.kernel.org/tip/e7884f8ead4a301b04687a3238527b06feef8ea0 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Thu, 16 Mar 2017 18:26:50 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:01 +0100
mm/gup: Move permission checks into helpers
This is a preparation patch for the transition of x86 to the generic GUP_fast() implementation.
On x86, we would need to do additional permission checks to determine if access is allowed.
Let's abstract it out into separate helpers.
--- include/asm-generic/pgtable.h | 25 +++++++++++++++++++++++++ mm/gup.c | 15 ++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-)
include/asm-generic/pgtable.h +25 -0
@@ -341,6 +341,31 @@ static inline int pte_unused(pte_t pte) }#endif +#ifndef pte_access_permitted +#define pte_access_permitted (pte, write) \ + (pte_present(pte) && (!(write) || pte_write(pte))) +#endif + +#ifndef pmd_access_permitted +#define pmd_access_permitted (pmd, write) \ + (pmd_present(pmd) && (!(write) || pmd_write(pmd))) +#endif + +#ifndef pud_access_permitted +#define pud_access_permitted (pud, write) \ + (pud_present(pud) && (!(write) || pud_write(pud))) +#endif + +#ifndef p4d_access_permitted +#define p4d_access_permitted (p4d, write) \ + (p4d_present(p4d) && (!(write) || p4d_write(p4d))) +#endif + +#ifndef pgd_access_permitted +#define pgd_access_permitted (pgd, write) \ + (pgd_present(pgd) && (!(write) || pgd_write(pgd))) +#endif +#ifndef __HAVE_ARCH_PMD_SAME#ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline int pmd_same (pmd_t pmd_a,pmd_t pmd_b)
mm/gup.c +10 -5
@@ -1212,8 +1212,13 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,* Similar to the PMD case below, NUMA hinting must take slow * path using the pte_protnone check. */ -if (!pte_present (pte) ||pte_special (pte) || -pte_protnone (pte) || (write && !pte_write (pte))) +if (pte_protnone (pte)) + goto pte_unmap; + +if (!pte_access_permitted (pte, write)) + goto pte_unmap; + +if (pte_special (pte)) goto pte_unmap;VM_BUG_ON (!pfn_valid (pte_pfn (pte)));
@@ -1264,7 +1269,7 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,struct page *head, *page;int refs; -if (write && !pmd_write (orig)) +if (!pmd_access_permitted (orig, write))return 0 ; refs =0 ;
@@ -1299,7 +1304,7 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,struct page *head, *page;int refs; -if (write && !pud_write (orig)) +if (!pud_access_permitted (orig, write))return 0 ; refs =0 ;
@@ -1335,7 +1340,7 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,int refs;struct page *head, *page; -if (write && !pgd_write (orig)) +if (!pgd_access_permitted (orig, write))return 0 ; refs =0 ;
PATCH 3/7 mm/gup: Move page table entry dereference into helper
In reply to Kirill A. ShutemovThis is preparation patch for transition of x86 to generic GUP_fast() implementation.
On x86 PAE, page table entry is larger than sizeof(long) and we would need to provide helper that can read the entry atomically.
--- mm/gup.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
mm/gup.c +12 -8
@@ -1189,6 +1189,17 @@ struct page *get_dump_page(unsigned long addr)*/ #ifdef CONFIG_HAVE_GENERIC_RCU_GUP +#ifndef gup_get_pte +/* +* We assume that the pte can be read atomically. If this is not the case for +* your architecture, please provide the helper. +*/ +static inline pte_t gup_get_pte (pte_t *ptep) +{ +return READ_ONCE (*ptep); +} +#endif +#ifdef __HAVE_ARCH_PTE_SPECIALstatic int gup_pte_range (pmd_t pmd,unsigned long addr,unsigned long end,int write,struct page **pages,int *nr)
@@ -1198,14 +1209,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, ptem = ptep =pte_offset_map (&pmd, addr); do { - /* - * In the line below we are assuming that the pte can be read - * atomically. If this is not the case for your architecture, - * please wrap this in a helper function! - * - * for an example see gup_get_pte in arch/x86/mm/gup.c - */ - pte_t pte = READ_ONCE(*ptep); + pte_t pte = gup_get_pte(ptep); struct page *head, *page; /*
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] mm/gup: Move page table entry dereference into helper function
mm/gup: Move page table entry dereference into helper function
Commit-ID: 0005d20b2ff1e501e186b3b3bc587085ac305fdc Gitweb: http://git.kernel.org/tip/0005d20b2ff1e501e186b3b3bc587085ac305fdc Author: Kirill A. Shutemov <[email protected]> AuthorDate: Thu, 16 Mar 2017 18:26:51 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:02 +0100
mm/gup: Move page table entry dereference into helper function
This is a preparation patch for the transition of x86 to the generic GUP_fast() implementation.
On x86 PAE, page table entry is larger than sizeof(long) and we would need to provide a helper that can read the entry atomically.
--- mm/gup.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
mm/gup.c +12 -8
@@ -1189,6 +1189,17 @@ struct page *get_dump_page(unsigned long addr)*/ #ifdef CONFIG_HAVE_GENERIC_RCU_GUP +#ifndef gup_get_pte +/* +* We assume that the PTE can be read atomically. If this is not the case for +* your architecture, please provide the helper. +*/ +static inline pte_t gup_get_pte (pte_t *ptep) +{ +return READ_ONCE (*ptep); +} +#endif +#ifdef __HAVE_ARCH_PTE_SPECIALstatic int gup_pte_range (pmd_t pmd,unsigned long addr,unsigned long end,int write,struct page **pages,int *nr)
@@ -1198,14 +1209,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, ptem = ptep =pte_offset_map (&pmd, addr); do { - /* - * In the line below we are assuming that the pte can be read - * atomically. If this is not the case for your architecture, - * please wrap this in a helper function! - * - * for an example see gup_get_pte in arch/x86/mm/gup.c - */ - pte_t pte = READ_ONCE(*ptep); + pte_t pte = gup_get_pte(ptep); struct page *head, *page; /*
PATCH 4/7 mm/gup: Make pages referenced during generic get_user_pages_fast()
In reply to Kirill A. ShutemovThis is preparation patch for transition of x86 to generic GUP_fast() implementation.
Unlike generic GUP_fast(), x86 version makes all pages it touches referenced. It seems required for GRU and EPT.
See commit 8ee53820edfd ("thp: mmu_notifier_test_young").
--- mm/gup.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/gup.c +5 -0
@@ -1238,6 +1238,8 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, }VM_BUG_ON_PAGE (compound_head (page) != head, page); + +SetPageReferenced (page); pages[*nr] = page; (*nr)++;
@@ -1299,6 +1301,7 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,return 0 ; } +SetPageReferenced (head);return 1 ; }
@@ -1334,6 +1337,7 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,return 0 ; } +SetPageReferenced (head);return 1 ; }
@@ -1370,6 +1374,7 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,return 0 ; } +SetPageReferenced (head);return 1 ; }
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] mm/gup: Mark all pages PageReferenced in generic get_user_pages_fast()
mm/gup: Mark all pages PageReferenced in generic get_user_pages_fast()
Commit-ID: e93480537fd7ecaf5ed1a662a979376f6fee50e3 Gitweb: http://git.kernel.org/tip/e93480537fd7ecaf5ed1a662a979376f6fee50e3 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Thu, 16 Mar 2017 18:26:52 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:02 +0100
mm/gup: Mark all pages PageReferenced in generic get_user_pages_fast()
This is a preparation patch for the transition of x86 to the generic GUP_fast() implementation.
Unlike generic GUP_fast(), the x86 version makes all pages it touches referenced. It seems required for GRU and EPT.
See the following commit:
8ee53820edfd ("thp: mmu_notifier_test_young")
--- mm/gup.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/gup.c +5 -0
@@ -1238,6 +1238,8 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, }VM_BUG_ON_PAGE (compound_head (page) != head, page); + +SetPageReferenced (page); pages[*nr] = page; (*nr)++;
@@ -1299,6 +1301,7 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,return 0 ; } +SetPageReferenced (head);return 1 ; }
@@ -1334,6 +1337,7 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,return 0 ; } +SetPageReferenced (head);return 1 ; }
@@ -1370,6 +1374,7 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr,return 0 ; } +SetPageReferenced (head);return 1 ; }
PATCH 5/7 mm/gup: Implement dev_pagemap logic in generic get_user_pages_fast()
In reply to Kirill A. ShutemovThis is preparation patch for transition of x86 to generic GUP_fast() implementation.
Prepare generic GUP_fast() to handle dev_mapmap. At the moment, it's only implemented on x86. On non-x86, the new code will be compiled out.
--- include/linux/mm.h | 4 +++ mm/gup.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-)
include/linux/mm.h +4 -0
@@ -430,6 +430,10 @@ static inline int pud_devmap(pud_t pud) {return 0 ; } +static inline int pgd_devmap (pgd_t pgd) +{ +return 0 ; +}#endif /*
mm/gup.c +71 -2
120 lines not on this page · raw message
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 5/7] mm/gup: Implement dev_pagemap logic in generic get_user_pages_fast()
Quoted 8 lines · Kirill A. Shutemov
(quoted diff) +8
-0+static int __gup_device_huge_pmd(pmd_t pmd, unsigned long addr, + unsigned long end, struct page **pages, int *nr) +{ + unsigned long fault_pfn; + + fault_pfn = pmd_pfn(pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); + return __gup_device_huge(fault_pfn, addr, end, pages, nr); +}
Review
Quoted 10 lines
(quoted diff) +10
-0+ +static int __gup_device_huge_pud(pud_t pud, unsigned long addr, + unsigned long end, struct page **pages, int *nr) +{ + unsigned long fault_pfn; + + fault_pfn = pud_pfn(pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); + return __gup_device_huge(fault_pfn, addr, end, pages, nr); +} +
PowerPC doesn't [always] provide pmd_pfn() and pud_pfn().
Fixup:
mm/gup.c +16 -2
@@ -1287,6 +1287,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, }#endif /* __HAVE_ARCH_PTE_SPECIAL */ +#ifdef __HAVE_ARCH_PTE_DEVMAPstatic int __gup_device_huge (unsigned long pfn,unsigned long addr,unsigned long end,struct page **pages,int *nr) {
@@ -1328,6 +1329,21 @@ static int __gup_device_huge_pud(pud_t pud, unsigned long addr, fault_pfn =pud_pfn (pud) + ((addr & ~PUD_MASK ) >>PAGE_SHIFT ); return __gup_device_huge(fault_pfn, addr, end, pages, nr); } +#else +static int __gup_device_huge_pmd (pmd_t pmd,unsigned long addr, +unsigned long end,struct page **pages,int *nr) +{ +BUILD_BUG (); +return 0 ; +} + +static int __gup_device_huge_pud (pud_t pud,unsigned long addr, +unsigned long end,struct page **pages,int *nr) +{ +BUILD_BUG (); +return 0 ; +} +#endif static int gup_huge_pmd (pmd_t orig,pmd_t *pmdp,unsigned long addr,unsigned long end,int write,struct page **pages,int *nr)
@@ -1338,7 +1354,6 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr,if (!pmd_access_permitted (orig, write))return 0 ; -VM_BUG_ON (!pfn_valid (pmd_pfn (orig)));if (pmd_devmap (orig))return __gup_device_huge_pmd (orig, addr, end, pages, nr);
@@ -1378,7 +1393,6 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr,if (!pud_access_permitted (orig, write))return 0 ; -VM_BUG_ON (!pfn_valid (pud_pfn (orig)));if (pud_devmap (orig))return __gup_device_huge_pud (orig, addr, end, pages, nr);
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] mm/gup: Implement the dev_pagemap() logic in the generic get_user_pages_fast() function
In reply to Kirill A. Shutemovmm/gup: Implement the dev_pagemap() logic in the generic get_user_pages_fast() function
Commit-ID: b59f65fa076a8eac2ff3a8ab7f8e1705b9fa86cb Gitweb: http://git.kernel.org/tip/b59f65fa076a8eac2ff3a8ab7f8e1705b9fa86cb Author: Kirill A. Shutemov <[email protected]> AuthorDate: Thu, 16 Mar 2017 18:26:53 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:02 +0100
mm/gup: Implement the dev_pagemap() logic in the generic get_user_pages_fast() function
This is a preparation patch for the transition of x86 to the generic GUP_fast() implementation.
Prepare generic GUP_fast() to handle dev_pagemap(). At the moment, it's only implemented on x86. On non-x86, the new code will be compiled out.
--- include/linux/mm.h | 4 +++ mm/gup.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 2 deletions(-)
include/linux/mm.h +4 -0
@@ -430,6 +430,10 @@ static inline int pud_devmap(pud_t pud) {return 0 ; } +static inline int pgd_devmap (pgd_t pgd) +{ +return 0 ; +}#endif /*
mm/gup.c +85 -2
134 lines not on this page · raw message
PATCH 6/7 mm/gup: Provide hook to check if __GUP_fast() is allowed for the range
In reply to Kirill A. ShutemovThis is preparation patch for transition of x86 to generic GUP_fast() implementation.
On x86, get_user_pages_fast() does few sanity checks to see if we can call __get_user_pages_fast() for the range.
Wrapping protection should be useful for generic code too.
--- mm/gup.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
mm/gup.c +21 -3
@@ -1600,6 +1600,21 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,return nr; } +#ifndef gup_fast_permitted +/* +* Check if it's allowed to use __get_user_pages_fast() for the range or +* need to fallback to non-fast version. +*/ +bool gup_fast_permitted (unsigned long start,int nr_pages,int write) +{ +unsigned long len, end; + + len = (unsigned long ) nr_pages <<PAGE_SHIFT ; + end = start + len; +return end >= start; +} +#endif +/** * get_user_pages_fast() - pin user pages in memory * @start: starting user address
@@ -1619,11 +1634,14 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,int get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages) { -int nr, ret; +int nr =0 , ret =0 ; start &=PAGE_MASK ; - nr =__get_user_pages_fast (start, nr_pages, write, pages); - ret = nr; + +if (gup_fast_permitted (start, nr_pages, write)) { + nr =__get_user_pages_fast (start, nr_pages, write, pages); + ret = nr; + }if (nr < nr_pages) {/* Try to get the remaining pages with get_user_pages */
Signature · 1 line
2.11.0
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] mm/gup: Provide callback to check if __GUP_fast() is allowed for the range
mm/gup: Provide callback to check if __GUP_fast() is allowed for the range
Commit-ID: 73e10a61817dfc97fe7418bfad1f608e562d7348 Gitweb: http://git.kernel.org/tip/73e10a61817dfc97fe7418bfad1f608e562d7348 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Thu, 16 Mar 2017 18:26:54 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:03 +0100
mm/gup: Provide callback to check if __GUP_fast() is allowed for the range
This is a preparation patch for the transition of x86 to the generic GUP_fast() implementation.
On x86, get_user_pages_fast() does a couple of sanity checks to see if we can call __get_user_pages_fast() for the range.
This kind of wrapping protection should be useful for the generic code too.
--- mm/gup.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
mm/gup.c +21 -3
@@ -1614,6 +1614,21 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,return nr; } +#ifndef gup_fast_permitted +/* +* Check if it's allowed to use __get_user_pages_fast() for the range, or +* we need to fall back to the slow version: +*/ +bool gup_fast_permitted (unsigned long start,int nr_pages,int write) +{ +unsigned long len, end; + + len = (unsigned long ) nr_pages <<PAGE_SHIFT ; + end = start + len; +return end >= start; +} +#endif +/** * get_user_pages_fast() - pin user pages in memory * @start: starting user address
@@ -1633,11 +1648,14 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,int get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages) { -int nr, ret; +int nr =0 , ret =0 ; start &=PAGE_MASK ; - nr =__get_user_pages_fast (start, nr_pages, write, pages); - ret = nr; + +if (gup_fast_permitted (start, nr_pages, write)) { + nr =__get_user_pages_fast (start, nr_pages, write, pages); + ret = nr; + }if (nr < nr_pages) {/* Try to get the remaining pages with get_user_pages */
PATCH 7/7 x86/mm: Switch to generic get_user_page_fast() implementation
In reply to Kirill A. ShutemovThe patch provides all required hooks to match generic get_user_pages_fast() behaviour to x86 and switch x86 over.
--- arch/x86/Kconfig | 3 + arch/x86/include/asm/mmu_context.h | 12 - arch/x86/include/asm/pgtable-3level.h | 45 +++ arch/x86/include/asm/pgtable.h | 53 ++++ arch/x86/include/asm/pgtable_64.h | 16 +- arch/x86/mm/Makefile | 2 +- arch/x86/mm/gup.c | 496 ---------------------------------- 7 files changed, 117 insertions(+), 510 deletions(-) delete mode 100644 arch/x86/mm/gup.c
arch/x86/Kconfig +3 -0
@@ -2788,6 +2788,9 @@ config X86_DMA_REMAP bool depends on STA2X11 +config HAVE_GENERIC_RCU_GUP + def_bool y + source "net/Kconfig" source "drivers/Kconfig"
arch/x86/include/asm/mmu_context.h +0 -12
@@ -220,18 +220,6 @@ static inline int vma_pkey(struct vm_area_struct *vma) }#endif -static inline bool __pkru_allows_pkey (u16 pkey,bool write) -{ -u32 pkru =read_pkru (); - -if (!__pkru_allows_read (pkru, pkey)) -return false; -if (write && !__pkru_allows_write (pkru, pkey)) -return false; - -return true; -} -/* * We only want to enforce protection keys on the current process * because we effectively have no access to PKRU for other
arch/x86/include/asm/pgtable-3level.h +45 -0
49 lines not on this page · raw message
arch/x86/include/asm/pgtable.h +53 -0
65 lines not on this page · raw message
arch/x86/include/asm/pgtable_64.h +15 -1
@@ -206,6 +206,20 @@ extern void cleanup_highmap(void);extern void init_extra_mapping_uc (unsigned long phys,unsigned long size);extern void init_extra_mapping_wb (unsigned long phys,unsigned long size); -#endif /* !__ASSEMBLY__ */ +#define gup_fast_permitted gup_fast_permitted +static inline bool gup_fast_permitted (unsigned long start,int nr_pages, +int write) +{ +unsigned long len, end; + + len = (unsigned long )nr_pages <<PAGE_SHIFT ; + end = start + len; +if (end < start) +return false; +if (end >> __VIRTUAL_MASK_SHIFT) +return false; +return true; +} +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_64_H */
arch/x86/mm/Makefile +1 -1
@@ -2,7 +2,7 @@ KCOV_INSTRUMENT_tlb.o := n obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ - pat.o pgtable.o physaddr.o gup.o setup_nx.o tlb.o + pat.o pgtable.o physaddr.o setup_nx.o tlb.o # Make sure __phys_addr has no stackprotector nostackp := $(call cc-option, -fno-stack-protector)
arch/x86/mm/gup.c deleted +0 -496
496 lines not on this page · raw message
Signature · 1 line
2.11.0
Peter Zijlstra
maintainerRe: [PATCH 7/7] x86/mm: Switch to generic get_user_page_fast() implementation
arch/x86/Kconfig config X86_DMA_REMAP · line 2793
Quoted 3 lines · Kirill A. Shutemov
arch/x86/Kconfig +3
-0+config HAVE_GENERIC_RCU_GUP + def_bool y +
Nothing immediately jumped out to me; except that this option might be misnamed.
AFAICT that code does not in fact rely on HAVE_RCU_TABLE_FREE; it will happily work with the (x86) broadcast IPI invalidate model, as you show here.
Architectures that do not do that obviously need HAVE_RCU_TABLE_FREE, but that is not the point I feel.
Also, this code hard relies on IRQ-disable delaying grace periods, which is mostly true I think, but has always been something Paul didn't really want to commit too firmly to.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 7/7] x86/mm: Switch to generic get_user_page_fast() implementation
Quoted 12 lines · Peter Zijlstra
arch/x86/Kconfig config X86_DMA_REMAP · line 2793
Quoted 3 lines · Kirill A. Shutemov
arch/x86/Kconfig +3
-0+config HAVE_GENERIC_RCU_GUP + def_bool y +Nothing immediately jumped out to me; except that this option might be misnamed.
AFAICT that code does not in fact rely on
HAVE_RCU_TABLE_FREE; it will happily work with the (x86) broadcast IPI invalidate model, as you show here.
Quoted 6 lines
Architectures that do not do that obviously need
HAVE_RCU_TABLE_FREE, but that is not the point I feel.Also, this code hard relies on IRQ-disable delaying grace periods, which is mostly true I think, but has always been something Paul didn't really want to commit too firmly to.
That is quite true!
The only case where IRQ-disable is guaranteed to delay grace periods is when you are using RCU-sched, in other words synchronize_sched() and call_rcu_sched(). And even then, the CPU cannot be in the idle loop, cannot be offline, and cannot be a nohz_full CPU on its way to/from userspace execution.
Thanx, Paul
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 7/7 x86/mm: Switch to generic get_user_page_fast() implementation
In reply to Kirill A. ShutemovThe patch provides all required hooks to match generic get_user_pages_fast() behaviour to x86 and switch x86 over.
---
v2:
- Fix build on non-PAE 32-bit x86;
- Rename HAVE_GENERIC_RCU_GUP to HAVE_GENERIC_GUP and update comment;
--- arch/arm/Kconfig | 2 +- arch/arm64/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- arch/x86/Kconfig | 3 + arch/x86/include/asm/mmu_context.h | 12 - arch/x86/include/asm/pgtable-3level.h | 45 +++ arch/x86/include/asm/pgtable.h | 53 ++++ arch/x86/include/asm/pgtable_64.h | 16 +- arch/x86/mm/Makefile | 2 +- arch/x86/mm/gup.c | 496 ---------------------------------- mm/Kconfig | 2 +- mm/gup.c | 10 +- 12 files changed, 126 insertions(+), 519 deletions(-) delete mode 100644 arch/x86/mm/gup.c
arch/arm/Kconfig +1 -1
@@ -1666,7 +1666,7 @@ config ARCH_SELECT_MEMORY_MODEL config HAVE_ARCH_PFN_VALID def_bool ARCH_HAS_HOLES_MEMORYMODEL || !SPARSEMEM -config HAVE_GENERIC_RCU_GUP +config HAVE_GENERIC_GUP def_bool y depends on ARM_LPAE
arch/arm64/Kconfig +1 -1
@@ -205,7 +205,7 @@ config GENERIC_CALIBRATE_DELAY config ZONE_DMA def_bool y -config HAVE_GENERIC_RCU_GUP +config HAVE_GENERIC_GUP def_bool y config ARCH_DMA_ADDR_T_64BIT
arch/powerpc/Kconfig +1 -1
@@ -135,7 +135,7 @@ config PPC select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS - select HAVE_GENERIC_RCU_GUP + select HAVE_GENERIC_GUP select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx) select HAVE_IDE select HAVE_IOREMAP_PROT
arch/x86/Kconfig +3 -0
@@ -2788,6 +2788,9 @@ config X86_DMA_REMAP bool depends on STA2X11 +config HAVE_GENERIC_GUP + def_bool y + source "net/Kconfig" source "drivers/Kconfig"
arch/x86/include/asm/mmu_context.h +0 -12
@@ -220,18 +220,6 @@ static inline int vma_pkey(struct vm_area_struct *vma) }#endif -static inline bool __pkru_allows_pkey (u16 pkey,bool write) -{ -u32 pkru =read_pkru (); - -if (!__pkru_allows_read (pkru, pkey)) -return false; -if (write && !__pkru_allows_write (pkru, pkey)) -return false; - -return true; -} -/* * We only want to enforce protection keys on the current process * because we effectively have no access to PKRU for other
arch/x86/include/asm/pgtable-3level.h +45 -0
49 lines not on this page · raw message
arch/x86/include/asm/pgtable.h +53 -0
65 lines not on this page · raw message
arch/x86/include/asm/pgtable_64.h +15 -1
@@ -206,6 +206,20 @@ extern void cleanup_highmap(void);extern void init_extra_mapping_uc (unsigned long phys,unsigned long size);extern void init_extra_mapping_wb (unsigned long phys,unsigned long size); -#endif /* !__ASSEMBLY__ */ +#define gup_fast_permitted gup_fast_permitted +static inline bool gup_fast_permitted (unsigned long start,int nr_pages, +int write) +{ +unsigned long len, end; + + len = (unsigned long )nr_pages <<PAGE_SHIFT ; + end = start + len; +if (end < start) +return false; +if (end >> __VIRTUAL_MASK_SHIFT) +return false; +return true; +} +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_64_H */
arch/x86/mm/Makefile +1 -1
@@ -2,7 +2,7 @@ KCOV_INSTRUMENT_tlb.o := n obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ - pat.o pgtable.o physaddr.o gup.o setup_nx.o tlb.o + pat.o pgtable.o physaddr.o setup_nx.o tlb.o # Make sure __phys_addr has no stackprotector nostackp := $(call cc-option, -fno-stack-protector)
arch/x86/mm/gup.c deleted +0 -496
496 lines not on this page · raw message
mm/Kconfig +1 -1
@@ -137,7 +137,7 @@ config HAVE_MEMBLOCK_NODE_MAP config HAVE_MEMBLOCK_PHYS_MAP bool -config HAVE_GENERIC_RCU_GUP +config HAVE_GENERIC_GUP bool config ARCH_DISCARD_MEMBLOCK
mm/gup.c +5 -5
@@ -1155,7 +1155,7 @@ struct page *get_dump_page(unsigned long addr)#endif /* CONFIG_ELF_CORE */ /* -* Generic RCU Fast GUP +* Generic Fast GUP * * get_user_pages_fast attempts to pin user pages by walking the page * tables directly and avoids taking locks. Thus the walker needs to be
@@ -1176,8 +1176,8 @@ struct page *get_dump_page(unsigned long addr)* Before activating this code, please be aware that the following assumptions * are currently made: * -* *) HAVE_RCU_TABLE_FREE is enabled, and tlb_remove_table is used to free -* pages containing page tables. +* *) Either HAVE_RCU_TABLE_FREE is enabled, and tlb_remove_table is used to +* free pages containing page tables or TLB flushing requires IPI broadcast. * * *) ptes can be read atomically by the architecture. *
@@ -1187,7 +1187,7 @@ struct page *get_dump_page(unsigned long addr)* * This code is based heavily on the PowerPC implementation by Nick Piggin. */ -#ifdef CONFIG_HAVE_GENERIC_RCU_GUP +#ifdef CONFIG_HAVE_GENERIC_GUP #ifndef gup_get_pte/*
@@ -1663,4 +1663,4 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, return ret; } -#endif /* CONFIG_HAVE_GENERIC_RCU_GUP */ +#endif /* CONFIG_HAVE_GENERIC_GUP */
Signature · 1 line
2.11.0
Re: [PATCHv2 7/7] x86/mm: Switch to generic get_user_page_fast() implementation
Quoted 7 lines · Kirill A. Shutemov
The patch provides all required hooks to match generic
get_user_pages_fast()behaviour to x86 and switch x86 over.Signed-off-by Kirill A. Shutemov <[email protected]>---
v2:
- Fix build on non-PAE 32-bit x86;
Fixup for allmodconfig on x86-64:
arch/x86/include/asm/pgtable.h +1 -1
@@ -230,13 +230,13 @@ static inline int pud_devmap(pud_t pud) {return 0 ; } +#endif static inline int pgd_devmap (pgd_t pgd) {return 0 ; }#endif -#endif #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline pte_t pte_set_flags (pte_t pte,pteval_t set)
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
tip-bot for Kirill A. Shutemov
merge bot[tip:x86/mm] x86/mm/gup: Switch GUP to the generic get_user_page_fast() implementation
In reply to Kirill A. Shutemovx86/mm/gup: Switch GUP to the generic get_user_page_fast() implementation
Commit-ID: 2947ba054a4dabbd82848728d765346886050029 Gitweb: http://git.kernel.org/tip/2947ba054a4dabbd82848728d765346886050029 Author: Kirill A. Shutemov <[email protected]> AuthorDate: Fri, 17 Mar 2017 00:39:06 +0300 Committer: Ingo Molnar <[email protected]> CommitDate: Sat, 18 Mar 2017 09:48:03 +0100
x86/mm/gup: Switch GUP to the generic get_user_page_fast() implementation
This patch provides all required callbacks required by the generic get_user_pages_fast() code and switches x86 over - and removes the platform specific implementation.
--- arch/arm/Kconfig | 2 +- arch/arm64/Kconfig | 2 +- arch/powerpc/Kconfig | 2 +- arch/x86/Kconfig | 3 + arch/x86/include/asm/mmu_context.h | 12 - arch/x86/include/asm/pgtable-3level.h | 47 ++++ arch/x86/include/asm/pgtable.h | 53 ++++ arch/x86/include/asm/pgtable_64.h | 16 +- arch/x86/mm/Makefile | 2 +- arch/x86/mm/gup.c | 496 ---------------------------------- mm/Kconfig | 2 +- mm/gup.c | 10 +- 12 files changed, 128 insertions(+), 519 deletions(-)
arch/arm/Kconfig +1 -1
@@ -1666,7 +1666,7 @@ config ARCH_SELECT_MEMORY_MODEL config HAVE_ARCH_PFN_VALID def_bool ARCH_HAS_HOLES_MEMORYMODEL || !SPARSEMEM -config HAVE_GENERIC_RCU_GUP +config HAVE_GENERIC_GUP def_bool y depends on ARM_LPAE
arch/arm64/Kconfig +1 -1
@@ -205,7 +205,7 @@ config GENERIC_CALIBRATE_DELAY config ZONE_DMA def_bool y -config HAVE_GENERIC_RCU_GUP +config HAVE_GENERIC_GUP def_bool y config ARCH_DMA_ADDR_T_64BIT
arch/powerpc/Kconfig +1 -1
@@ -135,7 +135,7 @@ config PPC select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS - select HAVE_GENERIC_RCU_GUP + select HAVE_GENERIC_GUP select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx) select HAVE_IDE select HAVE_IOREMAP_PROT
arch/x86/Kconfig +3 -0
@@ -2788,6 +2788,9 @@ config X86_DMA_REMAP bool depends on STA2X11 +config HAVE_GENERIC_GUP + def_bool y + source "net/Kconfig" source "drivers/Kconfig"
arch/x86/include/asm/mmu_context.h +0 -12
@@ -220,18 +220,6 @@ static inline int vma_pkey(struct vm_area_struct *vma) }#endif -static inline bool __pkru_allows_pkey (u16 pkey,bool write) -{ -u32 pkru =read_pkru (); - -if (!__pkru_allows_read (pkru, pkey)) -return false; -if (write && !__pkru_allows_write (pkru, pkey)) -return false; - -return true; -} -/* * We only want to enforce protection keys on the current process * because we effectively have no access to PKRU for other
arch/x86/include/asm/pgtable-3level.h +47 -0
51 lines not on this page · raw message
arch/x86/include/asm/pgtable.h +53 -0
65 lines not on this page · raw message
arch/x86/include/asm/pgtable_64.h +15 -1
@@ -207,6 +207,20 @@ extern void cleanup_highmap(void);extern void init_extra_mapping_uc (unsigned long phys,unsigned long size);extern void init_extra_mapping_wb (unsigned long phys,unsigned long size); -#endif /* !__ASSEMBLY__ */ +#define gup_fast_permitted gup_fast_permitted +static inline bool gup_fast_permitted (unsigned long start,int nr_pages, +int write) +{ +unsigned long len, end; + + len = (unsigned long )nr_pages <<PAGE_SHIFT ; + end = start + len; +if (end < start) +return false; +if (end >> __VIRTUAL_MASK_SHIFT) +return false; +return true; +} +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_64_H */
arch/x86/mm/Makefile +1 -1
@@ -2,7 +2,7 @@ KCOV_INSTRUMENT_tlb.o := n obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ - pat.o pgtable.o physaddr.o gup.o setup_nx.o tlb.o + pat.o pgtable.o physaddr.o setup_nx.o tlb.o # Make sure __phys_addr has no stackprotector nostackp := $(call cc-option, -fno-stack-protector)
arch/x86/mm/gup.c deleted +0 -496
496 lines not on this page · raw message
mm/Kconfig +1 -1
@@ -137,7 +137,7 @@ config HAVE_MEMBLOCK_NODE_MAP config HAVE_MEMBLOCK_PHYS_MAP bool -config HAVE_GENERIC_RCU_GUP +config HAVE_GENERIC_GUP bool config ARCH_DISCARD_MEMBLOCK
mm/gup.c +5 -5
@@ -1155,7 +1155,7 @@ struct page *get_dump_page(unsigned long addr)#endif /* CONFIG_ELF_CORE */ /* -* Generic RCU Fast GUP +* Generic Fast GUP * * get_user_pages_fast attempts to pin user pages by walking the page * tables directly and avoids taking locks. Thus the walker needs to be
@@ -1176,8 +1176,8 @@ struct page *get_dump_page(unsigned long addr)* Before activating this code, please be aware that the following assumptions * are currently made: * -* *) HAVE_RCU_TABLE_FREE is enabled, and tlb_remove_table is used to free -* pages containing page tables. +* *) Either HAVE_RCU_TABLE_FREE is enabled, and tlb_remove_table() is used to +* free pages containing page tables or TLB flushing requires IPI broadcast. * * *) ptes can be read atomically by the architecture. *
@@ -1187,7 +1187,7 @@ struct page *get_dump_page(unsigned long addr)* * This code is based heavily on the PowerPC implementation by Nick Piggin. */ -#ifdef CONFIG_HAVE_GENERIC_RCU_GUP +#ifdef CONFIG_HAVE_GENERIC_GUP #ifndef gup_get_pte/*
@@ -1677,4 +1677,4 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, return ret; } -#endif /* CONFIG_HAVE_GENERIC_RCU_GUP */ +#endif /* CONFIG_HAVE_GENERIC_GUP */
Quoted 3 lines · Kirill A. Shutemov
The patcheset generalize
mm/gup.cimplementation ofget_user_pages_fast()to be usable for x86 and switches x86 over.
Thanks for doing this, it looks good and removes more lines than it adds.
And despite removing lines, it should make it easier for other architectures to support devmap if they ever want to. I hadn't even noticed that difference in the GUP implementations.
Linus
Quoted 25 lines · Kirill A. Shutemov
Hi,
The patcheset generalize
mm/gup.cimplementation ofget_user_pages_fast()to be usable for x86 and switches x86 over.Please review and consider applying.
Kirill A. Shutemov (7):
mm: Droparch_pte_access_permitted()mmu hook
mm/gup: Move permission checks into helpers
mm/gup: Move page table entry dereference into helper mm/gup: Make pages referenced during genericget_user_pages_fast()mm/gup: Implementdev_pagemaplogic in genericget_user_pages_fast()mm/gup: Provide hook to check if__GUP_fast()is allowed for the range x86/mm: Switch to genericget_user_page_fast()implementationarch/powerpc/include/asm/mmu_context.h | 6 - arch/s390/include/asm/mmu_context.h | 6 - arch/um/include/asm/mmu_context.h | 6 - arch/unicore32/include/asm/mmu_context.h | 6 - arch/x86/Kconfig | 3 + arch/x86/include/asm/mmu_context.h | 16 - arch/x86/include/asm/pgtable-3level.h | 45 +++ arch/x86/include/asm/pgtable.h | 53 ++++ arch/x86/include/asm/pgtable_64.h | 16 +-
Quoted 8 lines
arch/x86/mm/Makefile | 2 +- arch/x86/mm/gup.c | 496 ------------------------------- include/asm-generic/mm_hooks.h | 6 - include/asm-generic/pgtable.h | 25 ++ include/linux/mm.h | 4 + mm/gup.c | 134 +++++++-- 15 files changed, 262 insertions(+), 562 deletions(-) delete mode 100644 arch/x86/mm/gup.c
It fails to build on x86-64 defconfig/allyesconfig/allmodconfig:
mm/gup.c:1422:15: error: implicit declaration of function ‘pgd_devmap’ [-Werror=implicit-function-declaration]
The PowerPC allnoconfig build broke as well:
/home/mingo/tip/mm/gup.c: In function '__gup_device_huge_pmd':/home/mingo/tip/mm/gup.c:1319:2: error: implicit declaration of function 'pmd_pfn' [-Werror=implicit-function-declaration]
Please send delta fixes, because I've already done many small readability edits to the patches.
Thanks,
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>