linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mm: thp: check pmd_trans_unstable() after split_huge_pmd()
@ 2016-06-01  0:36 Naoya Horiguchi
  2016-06-01  9:39 ` Kirill A. Shutemov
  0 siblings, 1 reply; 3+ messages in thread
From: Naoya Horiguchi @ 2016-06-01  0:36 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kirill A. Shutemov, Hugh Dickins, Mel Gorman, linux-mm,
	linux-kernel, Naoya Horiguchi, Naoya Horiguchi

split_huge_pmd() doesn't guarantee that the pmd is normal pmd pointing to
pte entries, which can be checked with pmd_trans_unstable(). Some callers
of split_huge_pmd() don't have the check, so let's add it.

Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
---
 mm/gup.c       | 2 ++
 mm/mempolicy.c | 2 ++
 mm/mprotect.c  | 2 +-
 mm/mremap.c    | 3 +--
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git v4.6-mmotm-2016-05-27-15-19/mm/gup.c v4.6-mmotm-2016-05-27-15-19_patched/mm/gup.c
index c057784..dee142e 100644
--- v4.6-mmotm-2016-05-27-15-19/mm/gup.c
+++ v4.6-mmotm-2016-05-27-15-19_patched/mm/gup.c
@@ -279,6 +279,8 @@ struct page *follow_page_mask(struct vm_area_struct *vma,
 			spin_unlock(ptl);
 			ret = 0;
 			split_huge_pmd(vma, pmd, address);
+			if (pmd_trans_unstable(pmd))
+				ret = -EBUSY;
 		} else {
 			get_page(page);
 			spin_unlock(ptl);
diff --git v4.6-mmotm-2016-05-27-15-19/mm/mempolicy.c v4.6-mmotm-2016-05-27-15-19_patched/mm/mempolicy.c
index 297d685..fe90e50 100644
--- v4.6-mmotm-2016-05-27-15-19/mm/mempolicy.c
+++ v4.6-mmotm-2016-05-27-15-19_patched/mm/mempolicy.c
@@ -512,6 +512,8 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr,
 		}
 	}
 
+	if (pmd_trans_unstable(pmd))
+		return 0;
 retry:
 	pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
 	for (; addr != end; pte++, addr += PAGE_SIZE) {
diff --git v4.6-mmotm-2016-05-27-15-19/mm/mprotect.c v4.6-mmotm-2016-05-27-15-19_patched/mm/mprotect.c
index 5019a1e..a4830f0 100644
--- v4.6-mmotm-2016-05-27-15-19/mm/mprotect.c
+++ v4.6-mmotm-2016-05-27-15-19_patched/mm/mprotect.c
@@ -163,7 +163,7 @@ 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);
-				if (pmd_none(*pmd))
+				if (pmd_trans_unstable(pmd))
 					continue;
 			} else {
 				int nr_ptes = change_huge_pmd(vma, pmd, addr,
diff --git v4.6-mmotm-2016-05-27-15-19/mm/mremap.c v4.6-mmotm-2016-05-27-15-19_patched/mm/mremap.c
index 1f157ad..da22ad2 100644
--- v4.6-mmotm-2016-05-27-15-19/mm/mremap.c
+++ v4.6-mmotm-2016-05-27-15-19_patched/mm/mremap.c
@@ -210,9 +210,8 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
 				}
 			}
 			split_huge_pmd(vma, old_pmd, old_addr);
-			if (pmd_none(*old_pmd))
+			if (pmd_trans_unstable(old_pmd))
 				continue;
-			VM_BUG_ON(pmd_trans_huge(*old_pmd));
 		}
 		if (pte_alloc(new_vma->vm_mm, new_pmd, new_addr))
 			break;
-- 
2.7.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] mm: thp: check pmd_trans_unstable() after split_huge_pmd()
  2016-06-01  0:36 [PATCH v1] mm: thp: check pmd_trans_unstable() after split_huge_pmd() Naoya Horiguchi
@ 2016-06-01  9:39 ` Kirill A. Shutemov
  2016-06-02  0:37   ` Naoya Horiguchi
  0 siblings, 1 reply; 3+ messages in thread
From: Kirill A. Shutemov @ 2016-06-01  9:39 UTC (permalink / raw)
  To: Naoya Horiguchi
  Cc: Andrew Morton, Hugh Dickins, Mel Gorman, linux-mm, linux-kernel,
	Naoya Horiguchi

On Wed, Jun 01, 2016 at 09:36:40AM +0900, Naoya Horiguchi wrote:
> split_huge_pmd() doesn't guarantee that the pmd is normal pmd pointing to
> pte entries, which can be checked with pmd_trans_unstable().

Could you be more specific on when we don't have normal ptes after
split_huge_pmd? Race with other thread? DAX?

I guess we can modify split_huge_pmd() to return if the pmd was split or
not.

-- 
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] mm: thp: check pmd_trans_unstable() after split_huge_pmd()
  2016-06-01  9:39 ` Kirill A. Shutemov
@ 2016-06-02  0:37   ` Naoya Horiguchi
  0 siblings, 0 replies; 3+ messages in thread
From: Naoya Horiguchi @ 2016-06-02  0:37 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Andrew Morton, Hugh Dickins, Mel Gorman, linux-mm, linux-kernel,
	Naoya Horiguchi

On Wed, Jun 01, 2016 at 12:39:57PM +0300, Kirill A. Shutemov wrote:
> On Wed, Jun 01, 2016 at 09:36:40AM +0900, Naoya Horiguchi wrote:
> > split_huge_pmd() doesn't guarantee that the pmd is normal pmd pointing to
> > pte entries, which can be checked with pmd_trans_unstable().
> 
> Could you be more specific on when we don't have normal ptes after
> split_huge_pmd? Race with other thread? DAX?

Actually I don't have any such specific case in mind.
__split_huge_pmd could skip real split code. In most case the skip happens
when the pmd is already split and pointing to normal ptes, and I'm not sure
when the pmd could be none or bad ...

So my above description seems misstatement, I should say "some caller does
assertion and some does differently and some not, so let's do it in unified
manner".

- Naoya

>
> I guess we can modify split_huge_pmd() to return if the pmd was split or
> not.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-02  0:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-01  0:36 [PATCH v1] mm: thp: check pmd_trans_unstable() after split_huge_pmd() Naoya Horiguchi
2016-06-01  9:39 ` Kirill A. Shutemov
2016-06-02  0:37   ` Naoya Horiguchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).