Skip to contentSkip to conversation

mm/ksm: Don't WARN if page is still mapped in remove_stable_node()

PATCH Applied Andrey Ryabinin 2 participants 2 messages Nov 19, 2019 – Nov 21, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/ksm: Don't WARN if page is still mapped in remove_stable_node()

It's possible to hit the WARN_ON_ONCE(page_mapped(page)) in remove_stable_node() when it races with __mmput() and squeezes in between ksm_exit() and exit_mmap().

 WARNING: CPU: 0 PID: 3295 at mm/ksm.c:888 remove_stable_node+0x10c/0x150

 Call Trace:
  remove_all_stable_nodes+0x12b/0x330
  run_store+0x4ef/0x7b0
  kernfs_fop_write+0x200/0x420
  vfs_write+0x154/0x450
  ksys_write+0xf9/0x1d0
  do_syscall_64+0x99/0x510
  entry_SYSCALL_64_after_hwframe+0x49/0xbe

Remove the warning as there is nothing scary going on.

Fixes cbf86cfe04a6 ("ksm: remove old stable nodes more thoroughly")
---
 mm/ksm.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mm/ksm.c +7 -7
index dbee2eb4dd05..7905934cd3ad 100644
@@ -885,13 +885,13 @@ static int remove_stable_node(struct stable_node *stable_node)
 		return 0;
 	}
 
-	if (WARN_ON_ONCE(page_mapped(page))) {
-		/*
-		 * This should not happen: but if it does, just refuse to let
-		 * merge_across_nodes be switched - there is no need to panic.
-		 */
-		err = -EBUSY;
-	} else {
+	/*
+	 * Page could be still mapped if this races with __mmput() running in
+	 * between ksm_exit() and exit_mmap(). Just refuse to let
+	 * merge_across_nodes/max_page_sharing be switched.
+	 */
+	err = -EBUSY;
+	if (!page_mapped(page)) {
 		/*
 		 * The stable node did not yet appear stale to get_ksm_page(),
 		 * since that allows for an unmapped ksm page to be recognized
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Andrey Ryabinin

It's possible to hit the WARN_ON_ONCE(page_mapped(page)) in remove_stable_node() when it races with __mmput() and squeezes in between ksm_exit() and exit_mmap().

 WARNING: CPU: 0 PID: 3295 at mm/ksm.c:888 remove_stable_node+0x10c/0x150

 Call Trace:
  remove_all_stable_nodes+0x12b/0x330
  run_store+0x4ef/0x7b0
  kernfs_fop_write+0x200/0x420
  vfs_write+0x154/0x450
  ksys_write+0xf9/0x1d0
  do_syscall_64+0x99/0x510
  entry_SYSCALL_64_after_hwframe+0x49/0xbe
Quoted 4 lines

Remove the warning as there is nothing scary going on.

Fixes cbf86cfe04a6 ("ksm: remove old stable nodes more thoroughly")

Thanks -

Quoted 1 line

For removing a WARN_ON_ONCE? No, I don't think this needs to go to stable; but I won't resist if Andrew or autobot insist otherwise.

Quoted 13 lines
---
 mm/ksm.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mm/ksm.c +0 -1
index dbee2eb4dd05..7905934cd3ad 100644
@@ -885,13 +885,13 @@ static int remove_stable_node(struct stable_node *stable_node)
 		return 0;
 	}
 
-	if (WARN_ON_ONCE(page_mapped(page))) {

mm/ksm.c static int remove_stable_node(struct stable_node *stable_node) · line 891

Quoted 10 lines
mm/ksm.c +4 -6
-		/*
-		 * This should not happen: but if it does, just refuse to let
-		 * merge_across_nodes be switched - there is no need to panic.
-		 */
-		err = -EBUSY;
-	} else {
+	/*
+	 * Page could be still mapped if this races with __mmput() running in
+	 * between ksm_exit() and exit_mmap(). Just refuse to let
+	 * merge_across_nodes/max_page_sharing be switched.

Good comment, thank you.

Quoted 8 lines
mm/ksm.c +3 -0
+	 */
+	err = -EBUSY;
+	if (!page_mapped(page)) {
 		/*
 		 * The stable node did not yet appear stale to get_ksm_page(),
 		 * since that allows for an unmapped ksm page to be recognized
Signature · 1 line
2.23.0