Skip to contentSkip to conversation

hwpoison: Fix race with changing page during offlining v2

PATCH In review Andi Kleen 3 participants 5 messages Jul 1, 2014 – Jul 2, 2014

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 hwpoison: Fix race with changing page during offlining v2

From: Andi Kleen <[email protected]>

When a hwpoison page is locked it could change state due to parallel modifications. Check after the lock if the page is still the same compound page.

[v2: Removed earlier non LRU check which should be already covered elsewhere]

Cc Naoya Horiguchi <[email protected]>
---
 mm/memory-failure.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
mm/memory-failure.c +10 -0
index cd8989c..99e5077 100644
@@ -1168,6 +1168,16 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
 	lock_page(hpage);
 
 	/*
+	 * The page could have changed compound pages during the locking.
+	 * If this happens just bail out.
+	 */
+	if (compound_head(p) != hpage) {
+		action_result(pfn, "different compound page after locking", IGNORED);
+		res = -EBUSY;
+		goto out;
+	}
+
+	/*
 	 * We use page flags to determine what action should be taken, but
 	 * the flags can be modified by the error containment action.  One
 	 * example is an mlocked page, where PG_mlocked is cleared by
Signature · 7 lines
1.9.3

--
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>
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andi Kleen

From: Andi Kleen <[email protected]>

When a hwpoison page is locked it could change state due to parallel modifications. Check after the lock if the page is still the same compound page.

[v2: Removed earlier non LRU check which should be already covered elsewhere]

Cc Naoya Horiguchi <[email protected]>

Is it -stable matter?
Maybe 2.6.38+ can profit from this.

Thanks,
Naoya Horiguchi

Quoted 34 lines
---
 mm/memory-failure.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
mm/memory-failure.c +10 -0
index cd8989c..99e5077 100644
@@ -1168,6 +1168,16 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
 	lock_page(hpage);
 
 	/*
+	 * The page could have changed compound pages during the locking.
+	 * If this happens just bail out.
+	 */
+	if (compound_head(p) != hpage) {
+		action_result(pfn, "different compound page after locking", IGNORED);
+		res = -EBUSY;
+		goto out;
+	}
+
+	/*
 	 * We use page flags to determine what action should be taken, but
 	 * the flags can be modified by the error containment action.  One
 	 * example is an mlocked page, where PG_mlocked is cleared by
Signature · 7 lines
1.9.3

--
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>

--
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>

maintainer
#3 lore raw
In reply to Andi Kleen
Quoted 11 lines · On Mon, 30 Jun 2014 17:32:16 -0700 Andi Kleen <[email protected]> wrote:

From: Andi Kleen <[email protected]>

When a hwpoison page is locked it could change state due to parallel modifications. Check after the lock if the page is still the same compound page.

...

mm/memory-failure.c int memory_failure(unsigned long pfn, int trapno, int flags) · line 1174

Quoted 7 lines
mm/memory-failure.c +4 -0
@@ -1168,6 +1168,16 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
 	lock_page(hpage);
 
 	/*
+	 * The page could have changed compound pages during the locking.
+	 * If this happens just bail out.
+	 */
+	if (compound_head(p) != hpage) {

How can a 4k page change compound pages? The original compound page was torn down and then this 4k page became part of a differently-sized compound page?

mm/memory-failure.c int memory_failure(unsigned long pfn, int trapno, int flags) · line 1180

Quoted 6 lines
mm/memory-failure.c +6 -0
+		action_result(pfn, "different compound page after locking", IGNORED);
+		res = -EBUSY;
+		goto out;
+	}
+
+	/*

I don't get it. We just go and fail the poisoning attempt? Shouldn't we go back, grab the new hpage and try again?

--
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>

author
#4 lore raw
Quoted 5 lines
Quoted 5 lines
mm/memory-failure.c +0 -0
@@ -1168,6 +1168,16 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
 	lock_page(hpage);
 
Quoted 9 lines

mm/memory-failure.c int memory_failure(unsigned long pfn, int trapno, int flags) · line 1174

Quoted 5 lines
mm/memory-failure.c +4 -0
 	/*
+	 * The page could have changed compound pages during the locking.
+	 * If this happens just bail out.
+	 */
+	if (compound_head(p) != hpage) {

How can a 4k page change compound pages? The original compound page was torn down and then this 4k page became part of a differently-size compound page?

Yes or it was torn down and now it's its own page.

Quoted 10 lines

mm/memory-failure.c int memory_failure(unsigned long pfn, int trapno, int flags) · line 1180

Quoted 7 lines
mm/memory-failure.c +6 -0
+		action_result(pfn, "different compound page after locking", IGNORED);
+		res = -EBUSY;
+		goto out;
+	}
+
+	/*

I don't get it. We just go and fail the poisoning attempt? Shouldn't we go back, grab the new hpage and try again?

It should be quite rare, so I thought this was safest. An retry loop would be more difficult to test and may have more side effects.

The hwpoison code by design only tries to handle cases that are reasonably common in workloads, as visible in page-flags.

I'm not really that concerned about handling this (likely rare case), just not crashing on it.

-Andi

--
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>