From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47031C3F2CD for ; Sat, 29 Feb 2020 18:07:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EBFEC2467D for ; Sat, 29 Feb 2020 18:07:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DzOsEVcn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBFEC2467D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 77DF06B0005; Sat, 29 Feb 2020 13:07:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72F156B0006; Sat, 29 Feb 2020 13:07:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F7F66B0007; Sat, 29 Feb 2020 13:07:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 45E086B0005 for ; Sat, 29 Feb 2020 13:07:21 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EDB593D19 for ; Sat, 29 Feb 2020 18:07:20 +0000 (UTC) X-FDA: 76543946640.10.sign15_5d39cb4c3ce4d X-HE-Tag: sign15_5d39cb4c3ce4d X-Filterd-Recvd-Size: 7386 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Sat, 29 Feb 2020 18:07:20 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id j16so7356410wrt.3 for ; Sat, 29 Feb 2020 10:07:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Hm4cXoI43gAgA4nrBIzRUu2EXt/W1xMMI5Bz6Dkvkes=; b=DzOsEVcnoPDDcnCrYbqOwyMAfCHTk4hVp350pagLtf0e8yUqiX4bYAB6arg9Ha1HaZ fxx5/OuZVKTC/u5SxkwkduKZzr1wfgY9wwL077PralTWgckdDaostS3XFsADegvqHpnX TRRbpfQYRfqDGXMyaEzPDTQH0Ru6v8K4OgI0AO2c9gFdbqgI+8ERgWP+pWzIVqgJ1pc0 +FXw5/YqH3X1ooa1YLP7YmBIeRLTYzIA62LuA/Hr/Pve9pFjwkBoiH8IfyQoxdn+CRnf HNnEM/Bj0gjgCOzMNBvJt+qphVXaJpmhQVtIsC7iTSJMbPxk/JSErOlsicQ6nfr0Nug9 PqOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=Hm4cXoI43gAgA4nrBIzRUu2EXt/W1xMMI5Bz6Dkvkes=; b=fHwfwjNLmwebRz/WiPMDJG52ta6cR3HsNX7y2DaZUTb1NT8dZrjhoG2LTQW68g+mp7 tmLu5Lwnn9185f0T5rQ1OHs/k3O3u50EEsTem134aoHCYhNld586E5D0ey2KEIB8E/Ip 36PVkh/B9fWTrw4FRrsh8y56QQk5X72W9MQ1Y0LoPJYYxKuug32dDD3zNnJGGRLDzMIb nCzzqZVKtJIKF2g1OfNV5PuujU2RElV1zgj5l0DZK6TZNttdCg/oHmC2PscUUEq5acm6 TCpNj/jzI8JjGpoEVERvT/LgISiwKzmbVPQtAkg/hOctmv+1Syj+gwgcQUA7OIPYVEdq HaOA== X-Gm-Message-State: APjAAAW2b6f3RqGDsdHH9uFxCh8ZDDonb8EDJ7NQqSdjIqLNNHv0k5hy EBemhiwJixD0XWJrOf3REvE= X-Google-Smtp-Source: APXvYqwUneac0lxNm13oGXPVtzsZ9kIY4PmsP3KRqDCEIl7C9+O/clOnE6+5Bbu2z+3/hHY7U3cMuA== X-Received: by 2002:adf:9521:: with SMTP id 30mr11361559wrs.349.1582999639162; Sat, 29 Feb 2020 10:07:19 -0800 (PST) Received: from dumbo (ip4da2e549.direct-adsl.nl. [77.162.229.73]) by smtp.gmail.com with ESMTPSA id m19sm7272467wmc.34.2020.02.29.10.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Feb 2020 10:07:18 -0800 (PST) Date: Sat, 29 Feb 2020 19:07:16 +0100 From: Domenico Andreoli To: "Darrick J. Wong" Cc: linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, mkleinsoft@gmail.com, hch@lst.de, akpm@linux-foundation.org, rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz Subject: Re: [PATCH] hibernate: unlock swap bdev for writing when uswsusp is active Message-ID: <20200229180716.GA31323@dumbo> References: <20200229170825.GX8045@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200229170825.GX8045@magnolia> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, Feb 29, 2020 at 09:08:25AM -0800, Darrick J. Wong wrote: > From: Darrick J. Wong > > 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. The > uswsusp ioctls allow userspace to lease parts of swap devices, so turn > S_SWAPFILE off when invoking suspend. > > Fixes: 1638045c3677 ("mm: set S_SWAPFILE on blockdev swap devices") > Reported-by: Domenico Andreoli > Reported-by: Marian Klein I also tested it yesterday but was not satisfied, unfortunately I did not come with my comment in time. Yes, I confirm that the uswsusp works again but also checked that swap_relockall() is not triggered at all and therefore after the first hibernation cycle the S_SWAPFILE bit remains cleared and the whole swap_relockall() is useless. I'm not sure this patch should be merged in the current form. Regards, Domenico > Tested-by: Marian Klein > Signed-off-by: Darrick J. Wong > --- > include/linux/swap.h | 1 + > kernel/power/user.c | 11 ++++++++++- > mm/swapfile.c | 26 ++++++++++++++++++++++++++ > 3 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index 1e99f7ac1d7e..add93e205850 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -458,6 +458,7 @@ extern void swap_free(swp_entry_t); > extern void swapcache_free_entries(swp_entry_t *entries, int n); > extern int free_swap_and_cache(swp_entry_t); > extern int swap_type_of(dev_t, sector_t, struct block_device **); > +extern void swap_relockall(void); > extern unsigned int count_swap_pages(int, int); > extern sector_t map_swap_page(struct page *, struct block_device **); > extern sector_t swapdev_block(int, pgoff_t); > diff --git a/kernel/power/user.c b/kernel/power/user.c > index 77438954cc2b..b11f7037ce5e 100644 > --- a/kernel/power/user.c > +++ b/kernel/power/user.c > @@ -271,6 +271,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, > break; > } > error = hibernation_restore(data->platform_support); > + if (!error) > + swap_relockall(); > break; > > case SNAPSHOT_FREE: > @@ -372,10 +374,17 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, > */ > swdev = new_decode_dev(swap_area.dev); > if (swdev) { > + struct block_device *bd; > + > offset = swap_area.offset; > - data->swap = swap_type_of(swdev, offset, NULL); > + data->swap = swap_type_of(swdev, offset, &bd); > if (data->swap < 0) > error = -ENODEV; > + > + inode_lock(bd->bd_inode); > + bd->bd_inode->i_flags &= ~S_SWAPFILE; > + inode_unlock(bd->bd_inode); > + bdput(bd); > } else { > data->swap = -1; > error = -EINVAL; > diff --git a/mm/swapfile.c b/mm/swapfile.c > index b2a2e45c9a36..439bfb7263d3 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1799,6 +1799,32 @@ int swap_type_of(dev_t device, sector_t offset, struct block_device **bdev_p) > return -ENODEV; > } > > +/* Re-lock swap devices after resuming from userspace suspend. */ > +void swap_relockall(void) > +{ > + int type; > + > + spin_lock(&swap_lock); > + for (type = 0; type < nr_swapfiles; type++) { > + struct swap_info_struct *sis = swap_info[type]; > + struct block_device *bdev = bdgrab(sis->bdev); > + > + /* > + * uswsusp only knows how to suspend to block devices, so we > + * can skip swap files. > + */ > + if (!(sis->flags & SWP_WRITEOK) || > + !(sis->flags & SWP_BLKDEV)) > + continue; > + > + inode_lock(bdev->bd_inode); > + bdev->bd_inode->i_flags |= S_SWAPFILE; > + inode_unlock(bdev->bd_inode); > + bdput(bdev); > + } > + spin_unlock(&swap_lock); > +} > + > /* > * Get the (PAGE_SIZE) block corresponding to given offset on the swapdev > * corresponding to given index in swap_info (swap type). -- rsa4096: 3B10 0CA1 8674 ACBA B4FE FCD2 CE5B CF17 9960 DE13 ed25519: FFB4 0CC3 7F2E 091D F7DA 356E CC79 2832 ED38 CB05