diff mbox series

hibernate: Allow uswsusp to write to swap

Message ID 20200304082327.GA14236@dumbo (mailing list archive)
State New, archived
Headers show
Series hibernate: Allow uswsusp to write to swap | expand

Commit Message

Domenico Andreoli March 4, 2020, 8:23 a.m. UTC
From: Domenico Andreoli <domenico.andreoli@linux.com>

It turns out that there is one use case for programs being able to
write to swap devices, and that is the userspace hibernation code.

Quick fix: disable the S_SWAPFILE check if hibernation is configured.

Fixes: 1638045c3677 ("mm: set S_SWAPFILE on blockdev swap devices")
Reported-by: Domenico Andreoli <domenico.andreoli@linux.com>
Reported-by: Marian Klein <mkleinsoft@gmail.com>
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>

---
 fs/block_dev.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Darrick J. Wong March 4, 2020, 3:45 p.m. UTC | #1
On Wed, Mar 04, 2020 at 09:23:27AM +0100, Domenico Andreoli wrote:
> From: Domenico Andreoli <domenico.andreoli@linux.com>
> 
> It turns out that there is one use case for programs being able to
> write to swap devices, and that is the userspace hibernation code.

You might want to start a separate thread for this... :)

> Quick fix: disable the S_SWAPFILE check if hibernation is configured.
> 
> Fixes: 1638045c3677 ("mm: set S_SWAPFILE on blockdev swap devices")

Also, this should be

Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")

since we still want to set S_SWAPFILE on active swap devices.

> Reported-by: Domenico Andreoli <domenico.andreoli@linux.com>
> Reported-by: Marian Klein <mkleinsoft@gmail.com>
> Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
> 
> ---
>  fs/block_dev.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> Index: b/fs/block_dev.c
> ===================================================================
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -2001,7 +2001,8 @@ ssize_t blkdev_write_iter(struct kiocb *
>  	if (bdev_read_only(I_BDEV(bd_inode)))
>  		return -EPERM;
>  
> -	if (IS_SWAPFILE(bd_inode))
> +	/* uswsusp needs to write to the swap */
> +	if (IS_SWAPFILE(bd_inode) && !IS_ENABLED(CONFIG_HIBERNATION))

...&& hibernation_available() ?  That way we can configure this
dynamically.

Thanks for taking this on, I'll go self-NAK the revert patch I sent
yesterday.

--D

>  		return -ETXTBSY;
>  
>  	if (!iov_iter_count(from))
Domenico Andreoli March 4, 2020, 4:31 p.m. UTC | #2
On Wed, Mar 4, 2020 at 4:45 PM Darrick J. Wong <darrick.wong@oracle.com>
wrote:

> On Wed, Mar 04, 2020 at 09:23:27AM +0100, Domenico Andreoli wrote:
> > From: Domenico Andreoli <domenico.andreoli@linux.com>
> >
> > It turns out that there is one use case for programs being able to
> > write to swap devices, and that is the userspace hibernation code.
>
> You might want to start a separate thread for this... :)
>

Right

> Quick fix: disable the S_SWAPFILE check if hibernation is configured.
> >
> > Fixes: 1638045c3677 ("mm: set S_SWAPFILE on blockdev swap devices")
>
> Also, this should be
>
> Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")
>

Of course

since we still want to set S_SWAPFILE on active swap devices.
>
> > Reported-by: Domenico Andreoli <domenico.andreoli@linux.com>
> > Reported-by: Marian Klein <mkleinsoft@gmail.com>
> > Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
> >
> > ---
> >  fs/block_dev.c |    3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > Index: b/fs/block_dev.c
> > ===================================================================
> > --- a/fs/block_dev.c
> > +++ b/fs/block_dev.c
> > @@ -2001,7 +2001,8 @@ ssize_t blkdev_write_iter(struct kiocb *
> >       if (bdev_read_only(I_BDEV(bd_inode)))
> >               return -EPERM;
> >
> > -     if (IS_SWAPFILE(bd_inode))
> > +     /* uswsusp needs to write to the swap */
> > +     if (IS_SWAPFILE(bd_inode) && !IS_ENABLED(CONFIG_HIBERNATION))
>
> ...&& hibernation_available() ?  That way we can configure this
> dynamically.
>

Then it would just be "if (IS_SWAPFILE(bd_inode) &&
!hibernation_available())", right?

Thanks for taking this on, I'll go self-NAK the revert patch I sent
> yesterday.
>

Thanks,
Dom
diff mbox series

Patch

Index: b/fs/block_dev.c
===================================================================
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -2001,7 +2001,8 @@  ssize_t blkdev_write_iter(struct kiocb *
 	if (bdev_read_only(I_BDEV(bd_inode)))
 		return -EPERM;
 
-	if (IS_SWAPFILE(bd_inode))
+	/* uswsusp needs to write to the swap */
+	if (IS_SWAPFILE(bd_inode) && !IS_ENABLED(CONFIG_HIBERNATION))
 		return -ETXTBSY;
 
 	if (!iov_iter_count(from))