[PATCH] mm: catch swap_slot_free_notify's misuse

From: Minchan Kim
Date: Mon Mar 28 2016 - 00:34:50 EST


swap_slot_free_notify works with synchronous rw_page driver(i.e,
zram) but someday, if someone implements asynchonous rw_page
driver and he want to hook swap_slot_free_notify to remove
dulicate memory, it will break current swap_slot_free_notify.
This patch catches the situation.

Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
Acked-by: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>
---
mm/page_io.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/mm/page_io.c b/mm/page_io.c
index 18aac7819cc9..32c82cdbed8e 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -105,6 +105,13 @@ static void swap_slot_free_notify(struct page *page)
swp_entry_t entry;
unsigned long offset;

+ /*
+ * If a driver supports async rw_page and
+ * swap_slot_free_notify, swap_slot_free_notify
+ * will not work rightly.
+ */
+ WARN_ON_ONCE(!PageUptodate(page));
+
entry.val = page_private(page);
offset = swp_offset(entry);

--
1.9.1