mprotect: drop overprotective lock_pte_protection()
Subsystems (2)
PATCH 1/1 mprotect: drop overprotective lock_pte_protection()
lock_pte_protection() uses pmd_lock() to make sure that we have stable PTE page table before walking pte range.
That's not necessary. We only need to make sure that PTE page table is established. It cannot vanish under us as long as we hold mmap_sem at least for read.
And we already have helper for that -- pmd_trans_unstable().
--- mm/mprotect.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-)
mm/mprotect.c +12 -31
@@ -33,34 +33,6 @@#include "internal.h" -/* -* For a prot_numa update we only hold mmap_sem for read so there is a -* potential race with faulting where a pmd was temporarily none. This -* function checks for a transhuge pmd under the appropriate lock. It -* returns a pte if it was successfully locked or NULL if it raced with -* a transhuge insertion. -*/ -static pte_t *lock_pte_protection (struct vm_area_struct *vma,pmd_t *pmd, -unsigned long addr,int prot_numa,spinlock_t **ptl) -{ -pte_t *pte; -spinlock_t *pmdl; - -/* !prot_numa is protected by mmap_sem held for write */ -if (!prot_numa) -return pte_offset_map_lock (vma->vm_mm, pmd, addr, ptl); - - pmdl =pmd_lock (vma->vm_mm, pmd); -if (unlikely (pmd_trans_huge (*pmd) ||pmd_none (*pmd))) { -spin_unlock (pmdl); -return NULL ; - } - - pte =pte_offset_map_lock (vma->vm_mm, pmd, addr, ptl); -spin_unlock (pmdl); -return pte; -} -static unsigned long change_pte_range (struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t newprot,int dirty_accountable,int prot_numa)
@@ -71,7 +43,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,unsigned long pages =0 ;int target_node =NUMA_NO_NODE ; - pte =lock_pte_protection (vma, pmd, addr, prot_numa, &ptl); + pte =pte_offset_map_lock (vma->vm_mm, pmd, addr, &ptl);if (!pte)return 0 ;
@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,if (pmd_trans_huge (*pmd) ||pmd_devmap (*pmd)) {if (next - addr !=HPAGE_PMD_SIZE ) {__split_huge_pmd (vma, pmd, addr, false,NULL ); -if (pmd_trans_unstable (pmd)) -continue ; }else {int nr_ptes =change_huge_pmd (vma, pmd, addr, newprot, prot_numa);
@@ -195,6 +165,17 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma, }/* fall through, the trans huge pmd just split */ } + +/* +* For prot_numa update we only hold mmap_sem for read so there +* is a potential race with faulting where a pmd was +* temporarily none. +* Make sure we have PTE page table, before moving forward. +* Page tables cannot go away under us as long as we hold +* mmap_sem at least for read. +*/ +if (pmd_trans_unstable (pmd)) +continue ; this_pages =change_pte_range (vma, pmd, addr, next, newprot, dirty_accountable, prot_numa); pages += this_pages;
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>
Quoted 54 lines · Kirill A. Shutemov
lock_pte_protection()usespmd_lock()to make sure that we have stable PTE page table before walking pte range.That's not necessary. We only need to make sure that PTE page table is established. It cannot vanish under us as long as we hold
mmap_semat least for read.And we already have helper for that --
pmd_trans_unstable().Signed-off-by Kirill A. Shutemov <[email protected]>--- mm/mprotect.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-)mm/mprotect.c +0
-28@@ -33,34 +33,6 @@#include "internal.h" -/* -* For a prot_numa update we only hold mmap_sem for read so there is a -* potential race with faulting where a pmd was temporarily none. This -* function checks for a transhuge pmd under the appropriate lock. It -* returns a pte if it was successfully locked or NULL if it raced with -* a transhuge insertion. -*/ -static pte_t *lock_pte_protection (struct vm_area_struct *vma,pmd_t *pmd, -unsigned long addr,int prot_numa,spinlock_t **ptl) -{ -pte_t *pte; -spinlock_t *pmdl; - -/* !prot_numa is protected by mmap_sem held for write */ -if (!prot_numa) -return pte_offset_map_lock (vma->vm_mm, pmd, addr, ptl); - - pmdl =pmd_lock (vma->vm_mm, pmd); -if (unlikely (pmd_trans_huge (*pmd) ||pmd_none (*pmd))) { -spin_unlock (pmdl); -return NULL ; - } - - pte =pte_offset_map_lock (vma->vm_mm, pmd, addr, ptl); -spin_unlock (pmdl); -return pte; -} -static unsigned long change_pte_range (struct vm_area_struct *vma,pmd_t *pmd,unsigned long addr,unsigned long end,pgprot_t newprot,int dirty_accountable,int prot_numa)
mm/mprotect.c static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, · line 47
Quoted 6 lines
mm/mprotect.c +1
-1@@ -71,7 +43,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,unsigned long pages =0 ;int target_node =NUMA_NO_NODE ; - pte =lock_pte_protection (vma, pmd, addr, prot_numa, &ptl); + pte =pte_offset_map_lock (vma->vm_mm, pmd, addr, &ptl);if (!pte)
I cleaned it up too but I moved the pmd_trans_unstable in the caller above instead of the callee, otherwise it's the same.
mm/mprotect.c static inline unsigned long change_pmd_range(struct vm_area_struct *vma, · line 181
Quoted 7 lines
mm/mprotect.c +0
-2@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,if (pmd_trans_huge (*pmd) ||pmd_devmap (*pmd)) {if (next - addr !=HPAGE_PMD_SIZE ) {__split_huge_pmd (vma, pmd, addr, false,NULL ); -if (pmd_trans_unstable (pmd)) -continue ;
Agree it can be removed too, but I only removed lock_pte_protection in my version.
If you prefer this version to be merged so we don't have to cleanup the above superfluous check in a incremental patch that's fine of course, otherwise at runtime they're equivalent as far as I can tell. The version in -mm is here.
Thanks,
Andrea
--
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>
Andrew Morton
maintainerQuoted 8 lines · On Tue, 7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov"…
lock_pte_protection()usespmd_lock()to make sure that we have stable PTE page table before walking pte range.That's not necessary. We only need to make sure that PTE page table is established. It cannot vanish under us as long as we hold
mmap_semat least for read.And we already have helper for that --
pmd_trans_unstable().
http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
already did this?
--
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>
Quoted 5 lines · Andrew Morton
Quoted 3 lines · On Tue, 7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov"…
lock_pte_protection()usespmd_lock()to make sure that we have stable PTE page table before walking pte range.
Quoted 8 lines
Quoted 5 lines
That's not necessary. We only need to make sure that PTE page table is established. It cannot vanish under us as long as we hold
mmap_semat least for read.And we already have helper for that --
pmd_trans_unstable().http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
already did this?
Right. Except, it doesn't drop unneeded pmd_trans_unstable(pmd) check after __split_huge_pmd().
Could you fold this part of my patch into Andrea's?
mm/mprotect.c +0 -2
@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,if (pmd_trans_huge (*pmd) ||pmd_devmap (*pmd)) {if (next - addr !=HPAGE_PMD_SIZE ) {__split_huge_pmd (vma, pmd, addr, false,NULL ); -if (pmd_trans_unstable (pmd)) -continue ; }else {int nr_ptes =change_huge_pmd (vma, pmd, addr, newprot, prot_numa);
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>
Andrea Arcangeli
Reviewed-byQuoted 12 lines · Kirill A. Shutemov
Quoted 11 lines · Andrew Morton
Quoted 8 lines · On Tue, 7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov"…
lock_pte_protection()usespmd_lock()to make sure that we have stable PTE page table before walking pte range.That's not necessary. We only need to make sure that PTE page table is established. It cannot vanish under us as long as we hold
mmap_semat least for read.And we already have helper for that --
pmd_trans_unstable().
Quoted 7 lines
Quoted 2 lines
http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
already did this?Right. Except, it doesn't drop unneeded
pmd_trans_unstable(pmd)check after__split_huge_pmd().Could you fold this part of my patch into Andrea's?
Quoted 6 lines
mm/mprotect.c +0
-0
mm/mprotect.c static inline unsigned long change_pmd_range(struct vm_area_struct *vma, · line 154
Quoted 8 lines
mm/mprotect.c +0
-2@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,if (pmd_trans_huge (*pmd) ||pmd_devmap (*pmd)) {if (next - addr !=HPAGE_PMD_SIZE ) {__split_huge_pmd (vma, pmd, addr, false,NULL ); -if (pmd_trans_unstable (pmd)) -continue ; }else {int nr_ptes =change_huge_pmd (vma, pmd, addr, newprot, prot_numa);
Yes this check was an harmless noop, but it's definitely good to clean up this bit too after the other more important change that has a positive runtime effect, or it could be a source of confusion to the reader if left in there.
Thanks!
Andrea
--
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>