[PATCH] swap: warn when a swap area overflows the maximum size (resent)

Raymond Jennings
2013-07-07T11:53:05Z

Silly me, wrong email address

On Sun, 2013-07-07 at 04:44 -0700, Raymond Jennings wrote:
swap: warn when a swap area overflows the maximum size

It is possible to swapon a swap area that is too big for the pte width
to handle.

Presently this failure happens silently.

Instead, emit a diagnostic to warn the user.

Signed-off-by: Raymond Jennings <shentino@gmail.com>
Acked-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>

----

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 36af6ee..5a4ce53 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1953,6 +1953,12 @@ static unsigned long read_swap_header(struct
swap_info_struct *p,
*/
maxpages = swp_offset(pte_to_swp_entry(
swp_entry_to_pte(swp_entry(0, ~0UL)))) + 1;
+ if (maxpages < swap_header->info.last_page) {
+ printk(KERN_WARNING
+ "Truncating oversized swap area, only using %luk out of %luk
\n",
+ maxpages << (PAGE_SHIFT - 10),
+ swap_header->info.last_page << (PAGE_SHIFT - 10));