mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/1] PM/Hibernate: fix "swap breaks after hibernation failures"
@ 2009-01-27 22:17 Rafael J. Wysocki
  2009-01-27 22:18 ` [PATCH 1/1] " Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2009-01-27 22:17 UTC (permalink / raw)
  To: Len Brown; +Cc: LKML, pm list, Pavel Machek, Alan Jenkins

Hi Len,

The following patch fixes a long-standing bug in the hibernate code related to
swap, which causes the swap partition used for saving hibernation images to
become unusable after two consecutive failing attempts to hibernate.

Please add to the suspend branch as 2.6.29 material.

Thanks,
Rafael


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/1] PM/Hibernate: fix "swap breaks after hibernation failures"
  2009-01-27 22:17 [PATCH 0/1] PM/Hibernate: fix "swap breaks after hibernation failures" Rafael J. Wysocki
@ 2009-01-27 22:18 ` Rafael J. Wysocki
  2009-01-28  9:27   ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2009-01-27 22:18 UTC (permalink / raw)
  To: Len Brown; +Cc: LKML, pm list, Pavel Machek, Alan Jenkins

From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>

http://bugzilla.kernel.org/show_bug.cgi?id=12239

The image writing code dropped a reference to the current swap device.
This doesn't show up if the hibernation succeeds - because it doesn't
affect the image which gets resumed.  But it means multiple _failed_
hibernations end up freeing the swap device while it is still use!

swsusp_write() finds the block device for the swap file using swap_type_of().
It then uses blkdev_get() / blkdev_put() to open and close the block device.

Unfortunately, blkdev_get() assumes ownership of the inode of the block_device
passed to it.  So blkdev_put() calls iput() on the inode.  This is by design
and other callers expect this behaviour.  The fix is for swap_type_of() to take
a reference on the inode using bdget().

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

diff --git a/mm/swapfile.c b/mm/swapfile.c
index f48b831..7740478 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -635,7 +635,7 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)
 
 		if (!bdev) {
 			if (bdev_p)
-				*bdev_p = sis->bdev;
+				*bdev_p = bdget(sis->bdev->bd_dev);
 
 			spin_unlock(&swap_lock);
 			return i;
@@ -647,7 +647,7 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)
 					struct swap_extent, list);
 			if (se->start_block == offset) {
 				if (bdev_p)
-					*bdev_p = sis->bdev;
+					*bdev_p = bdget(sis->bdev->bd_dev);
 
 				spin_unlock(&swap_lock);
 				bdput(bdev);





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] PM/Hibernate: fix "swap breaks after hibernation failures"
  2009-01-27 22:18 ` [PATCH 1/1] " Rafael J. Wysocki
@ 2009-01-28  9:27   ` Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2009-01-28  9:27 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Len Brown, LKML, pm list, Alan Jenkins

On Tue 2009-01-27 23:18:59, Rafael J. Wysocki wrote:
> From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
> 
> http://bugzilla.kernel.org/show_bug.cgi?id=12239
> 
> The image writing code dropped a reference to the current swap device.
> This doesn't show up if the hibernation succeeds - because it doesn't
> affect the image which gets resumed.  But it means multiple _failed_
> hibernations end up freeing the swap device while it is still use!
> 
> swsusp_write() finds the block device for the swap file using swap_type_of().
> It then uses blkdev_get() / blkdev_put() to open and close the block device.
> 
> Unfortunately, blkdev_get() assumes ownership of the inode of the block_device
> passed to it.  So blkdev_put() calls iput() on the inode.  This is by design
> and other callers expect this behaviour.  The fix is for swap_type_of() to take
> a reference on the inode using bdget().
> 
> Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

Acked-by: Pavel Machek <pavel@suse.cz>

> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index f48b831..7740478 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -635,7 +635,7 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)
>  
>  		if (!bdev) {
>  			if (bdev_p)
> -				*bdev_p = sis->bdev;
> +				*bdev_p = bdget(sis->bdev->bd_dev);
>  
>  			spin_unlock(&swap_lock);
>  			return i;
> @@ -647,7 +647,7 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p)
>  					struct swap_extent, list);
>  			if (se->start_block == offset) {
>  				if (bdev_p)
> -					*bdev_p = sis->bdev;
> +					*bdev_p = bdget(sis->bdev->bd_dev);
>  
>  				spin_unlock(&swap_lock);
>  				bdput(bdev);
> 
> 
> 
> 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-28  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-27 22:17 [PATCH 0/1] PM/Hibernate: fix "swap breaks after hibernation failures" Rafael J. Wysocki
2009-01-27 22:18 ` [PATCH 1/1] " Rafael J. Wysocki
2009-01-28  9:27   ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®