public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Pavel Machek <pavel@ucw.cz>
Cc: LKML <linux-kernel@vger.kernel.org>, Andrew Morton <akpm@osdl.org>
Subject: [PATCH][Fix] swsusp: avoid problems if there are too many pages to save
Date: Mon, 26 Sep 2005 21:29:07 +0200	[thread overview]
Message-ID: <200509262129.08316.rjw@sisk.pl> (raw)
In-Reply-To: <20050926142608.GA32249@elf.ucw.cz>

Hi,

The following patch makes swsusp avoid problems during resume if there are too many
pages to save on suspend.  It adds a constant that allows us to verify if we are going to
save too many pages and implements the check (this is done as early as we can tell that
the check will trigger, which is in swsusp_alloc()).

This is to replace swsusp-prevent-swsusp-from-failing-if-theres-too-many-pagedir-pages.patch

Please consider for applying.

Greetings,
Rafael


Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

Index: linux-2.6.14-rc2-git6/kernel/power/power.h
===================================================================
--- linux-2.6.14-rc2-git6.orig/kernel/power/power.h	2005-09-26 20:58:33.000000000 +0200
+++ linux-2.6.14-rc2-git6/kernel/power/power.h	2005-09-26 21:05:37.000000000 +0200
@@ -9,6 +9,9 @@
 #define SUSPEND_CONSOLE	(MAX_NR_CONSOLES-1)
 #endif
 
+#define MAX_PBES	((PAGE_SIZE - sizeof(struct new_utsname) \
+			- 4 - 3*sizeof(unsigned long) - sizeof(int) \
+			- sizeof(void *)) / sizeof(swp_entry_t))
 
 struct swsusp_info {
 	struct new_utsname	uts;
@@ -18,7 +21,7 @@
 	unsigned long		image_pages;
 	unsigned long		pagedir_pages;
 	suspend_pagedir_t	* suspend_pagedir;
-	swp_entry_t		pagedir[768];
+	swp_entry_t		pagedir[MAX_PBES];
 } __attribute__((aligned(PAGE_SIZE)));
 
 
Index: linux-2.6.14-rc2-git6/kernel/power/swsusp.c
===================================================================
--- linux-2.6.14-rc2-git6.orig/kernel/power/swsusp.c	2005-09-26 20:59:30.000000000 +0200
+++ linux-2.6.14-rc2-git6/kernel/power/swsusp.c	2005-09-26 21:05:13.000000000 +0200
@@ -931,6 +931,10 @@
 	if (!enough_swap())
 		return -ENOSPC;
 
+	if (MAX_PBES < nr_copy_pages / PBES_PER_PAGE +
+	    !!(nr_copy_pages % PBES_PER_PAGE))
+		return -ENOSPC;
+
 	if (!(pagedir_save = alloc_pagedir(nr_copy_pages))) {
 		printk(KERN_ERR "suspend: Allocating pagedir failed.\n");
 		return -ENOMEM;

  parent reply	other threads:[~2005-09-26 19:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-25 18:18 [PATCH 0/3] swsusp: fix some obscure bugs Rafael J. Wysocki
2005-09-25 18:24 ` [PATCH 1/3][Fix] swsusp: remove wrong code from data_free Rafael J. Wysocki
2005-09-25 18:30 ` [PATCH 2/3][Fix] swsusp: prevent possible memory leak Rafael J. Wysocki
2005-09-25 18:44 ` [PATCH 3/3][Fix] swsusp: prevent swsusp from failing if there's too many pagedir pages Rafael J. Wysocki
2005-09-26 10:33   ` Pavel Machek
2005-09-26 11:11     ` Rafael J. Wysocki
2005-09-26 11:20       ` Pavel Machek
2005-09-26 12:54         ` Rafael J. Wysocki
2005-09-26 14:26           ` Pavel Machek
2005-09-26 19:19             ` Rafael J. Wysocki
2005-09-26 23:22               ` Pavel Machek
2005-09-26 19:29             ` Rafael J. Wysocki [this message]
2005-09-26 23:14               ` [PATCH][Fix] swsusp: avoid problems if there are too many pages to save Pavel Machek
2005-09-25 21:47 ` [PATCH 0/3] swsusp: fix some obscure bugs Pavel Machek
2005-09-25 21:59   ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200509262129.08316.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox