ARM: mm: make UACCESS_WITH_MEMCPY huge page aware
RFC v2 1/1 ARM: mm: make UACCESS_WITH_MEMCPY huge page aware
The memory pinning code in uaccess_with_memcpy.c does not check for HugeTLB or THP pmds, and will enter an infinite loop should a __copy_to_user or __clear_user occur against a huge page.
This patch adds detection code for huge pages to pin_page_for_write. As this code can be executed in a fast path it refers to the actual pmds rather than the vma. If a HugeTLB or THP is found (they have the same pmd representation on ARM), the page table spinlock is taken to prevent modification whilst the page is pinned.
On ARM, huge pages are only represented as pmds, thus no huge pud checks are performed. (For huge puds one would lock the page table in a similar manner as in the pmd case).
Two helper functions are introduced; pmd_thp_or_huge will check whether or not a page is huge or transparent huge (which have the same pmd layout on ARM), and pmd_hugewillfault will detect whether or not a page fault will occur on write to the page.
Changes since first RFC:
* The page mask is widened for hugepages to reduce the number of potential locks/unlocks.
(A knobbled /dev/zero with its latency reduction chunks
removed shows a 2x data rate boost with hugepages backing:
dd if=/dev/zero of=/dev/null bs=10M count=1024 )
--- arch/arm/include/asm/pgtable-3level.h | 3 ++ arch/arm/lib/uaccess_with_memcpy.c | 57 ++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-)
arch/arm/include/asm/pgtable-3level.h +3 -0
@@ -206,6 +206,9 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)#define __HAVE_ARCH_PMD_WRITE#define pmd_write (pmd) (!(pmd_val(pmd) & PMD_SECT_RDONLY)) +#define pmd_hugewillfault (pmd) (!pmd_young(pmd) || !pmd_write(pmd)) +#define pmd_thp_or_huge (pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) +#ifdef CONFIG_TRANSPARENT_HUGEPAGE #define pmd_trans_huge (pmd) (pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT))#define pmd_trans_splitting (pmd) (pmd_val(pmd) & PMD_SECT_SPLITTING)
arch/arm/lib/uaccess_with_memcpy.c +49 -8
127 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Quoted 26 lines · Steve Capper
The memory pinning code in
uaccess_with_memcpy.cdoes not check for HugeTLB or THP pmds, and will enter an infinite loop should a__copy_to_useror__clear_useroccur against a huge page.This patch adds detection code for huge pages to
pin_page_for_write. As this code can be executed in a fast path it refers to the actual pmds rather than the vma. If a HugeTLB or THP is found (they have the same pmd representation on ARM), the page table spinlock is taken to prevent modification whilst the page is pinned.On ARM, huge pages are only represented as pmds, thus no huge pud checks are performed. (For huge puds one would lock the page table in a similar manner as in the pmd case).
Two helper functions are introduced;
pmd_thp_or_hugewill check whether or not a page is huge or transparent huge (which have the same pmd layout on ARM), andpmd_hugewillfaultwill detect whether or not a page fault will occur on write to the page.Changes since first RFC:
* The page mask is widened for hugepages to reduce the number of potential locks/unlocks.
(A knobbled/dev/zerowith its latency reduction chunks
removed shows a 2x data rate boost with hugepages backing:
dd if=/dev/zero of=/dev/null bs=10M count=1024 )
Quoted 2 lines
Signed-off-by Steve Capper <[email protected]>---
A ping to see if anyone had any questions/comments/flames :-)?
Should it go into the patch system?
Thanks,
Signature · 1 line
Steve
Quoted 27 lines · Steve Capper
Quoted 26 lines · Steve Capper
The memory pinning code in
uaccess_with_memcpy.cdoes not check for HugeTLB or THP pmds, and will enter an infinite loop should a__copy_to_useror__clear_useroccur against a huge page.This patch adds detection code for huge pages to
pin_page_for_write. As this code can be executed in a fast path it refers to the actual pmds rather than the vma. If a HugeTLB or THP is found (they have the same pmd representation on ARM), the page table spinlock is taken to prevent modification whilst the page is pinned.On ARM, huge pages are only represented as pmds, thus no huge pud checks are performed. (For huge puds one would lock the page table in a similar manner as in the pmd case).
Two helper functions are introduced;
pmd_thp_or_hugewill check whether or not a page is huge or transparent huge (which have the same pmd layout on ARM), andpmd_hugewillfaultwill detect whether or not a page fault will occur on write to the page.Changes since first RFC:
* The page mask is widened for hugepages to reduce the number of potential locks/unlocks.
(A knobbled/dev/zerowith its latency reduction chunks
removed shows a 2x data rate boost with hugepages backing:
dd if=/dev/zero of=/dev/null bs=10M count=1024 )
Quoted 6 lines
Quoted 2 lines
Signed-off-by Steve Capper <[email protected]>---
A ping to see if anyone had any questions/comments/flames :-)?
Should it go into the patch system?
IIRC Nicolas wrote the original support, so he should probably be Cc'd with this patch.
Quoted 31 lines · Russell King - ARM Linux
Quoted 30 lines · Steve Capper
Quoted 28 lines · Steve Capper
The memory pinning code in
uaccess_with_memcpy.cdoes not check for HugeTLB or THP pmds, and will enter an infinite loop should a__copy_to_useror__clear_useroccur against a huge page.This patch adds detection code for huge pages to
pin_page_for_write. As this code can be executed in a fast path it refers to the actual pmds rather than the vma. If a HugeTLB or THP is found (they have the same pmd representation on ARM), the page table spinlock is taken to prevent modification whilst the page is pinned.On ARM, huge pages are only represented as pmds, thus no huge pud checks are performed. (For huge puds one would lock the page table in a similar manner as in the pmd case).
Two helper functions are introduced;
pmd_thp_or_hugewill check whether or not a page is huge or transparent huge (which have the same pmd layout on ARM), andpmd_hugewillfaultwill detect whether or not a page fault will occur on write to the page.Changes since first RFC:
* The page mask is widened for hugepages to reduce the number of potential locks/unlocks.
(A knobbled/dev/zerowith its latency reduction chunks
removed shows a 2x data rate boost with hugepages backing:
dd if=/dev/zero of=/dev/null bs=10M count=1024 )Signed-off-by Steve Capper <[email protected]>---
Quoted 7 lines
Quoted 3 lines
A ping to see if anyone had any questions/comments/flames :-)?
Should it go into the patch system?
IIRC Nicolas wrote the original support, so he should probably be Cc'd with this patch.
Thank you, I will resend the patch with Nicolas on CC.