Skip to contentSkip to conversation

swap: __swap_duplicate check bad swap entry

PATCH Superseded Shaohua Li 2 participants 2 messages Feb 21, 2013 – Mar 12, 2013

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH v3 2/4 swap: __swap_duplicate check bad swap entry

Sorry if you receive this one twice, last mail get mail address messed.

In swapin_readahead(), read_swap_cache_async() can read a bad swap entry, because we don't check if readahead swap entry is bad. This doesn't break anything but such swapin page is wasteful and can only be freed at page reclaim. We avoid read such swap entry.

And next patch will mark a swap entry bad temporarily for discard. Without this patch, swap entry count will be messed.

Thanks Hugh to inspire swapin_readahead could use bad swap entry.

---
 mm/swapfile.c |    5 +++++
 1 file changed, 5 insertions(+)
mm/swapfile.c +5 -0
Index: linux/mm/swapfile.c
===================================================================
@@ -2374,6 +2374,11 @@ static int __swap_duplicate(swp_entry_t
 		goto unlock_out;
 
 	count = p->swap_map[offset];
+	if (unlikely(swap_count(count) == SWAP_MAP_BAD)) {
+		err = -ENOENT;
+		goto unlock_out;
+	}
+
 	has_cache = count & SWAP_HAS_CACHE;
 	count &= ~SWAP_HAS_CACHE;
 	err = 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>

Acked-by on v3 2/4
#1 lore raw
Quoted 7 lines · Shaohua Li

Sorry if you receive this one twice, last mail get mail address messed.

In swapin_readahead(), read_swap_cache_async() can read a bad swap entry, because we don't check if readahead swap entry is bad. This doesn't break anything but such swapin page is wasteful and can only be freed at page reclaim. We avoid read such swap entry.

Quoted 28 lines

And next patch will mark a swap entry bad temporarily for discard. Without this patch, swap entry count will be messed.

Thanks Hugh to inspire swapin_readahead could use bad swap entry.

---
 mm/swapfile.c |    5 +++++
 1 file changed, 5 insertions(+)

Index: linux/mm/swapfile.c
===================================================================

mm/swapfile.c +5 -1
@@ -2374,6 +2374,11 @@ static int __swap_duplicate(swp_entry_t
 		goto unlock_out;
 
 	count = p->swap_map[offset];
+	if (unlikely(swap_count(count) == SWAP_MAP_BAD)) {
+		err = -ENOENT;
+		goto unlock_out;
+	}
+
 	has_cache = count & SWAP_HAS_CACHE;
 	count &= ~SWAP_HAS_CACHE;
 	err = 0;
 
--
Quoted 4 lines

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>