linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sukrit Bhatnagar <Sukrit.Bhatnagar@sony.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Pavel Machek <pavel@ucw.cz>,
	Christian Brauner <brauner@kernel.org>,
	"Darrick J. Wong" <djwong@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-xfs@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, Sukrit.Bhatnagar@sony.com
Subject: [PATCH 1/2] iomap: swap: print warning for unaligned swapfile
Date: Wed, 22 May 2024 16:46:57 +0900	[thread overview]
Message-ID: <20240522074658.2420468-2-Sukrit.Bhatnagar@sony.com> (raw)
In-Reply-To: <20240522074658.2420468-1-Sukrit.Bhatnagar@sony.com>

When creating a swapfile on a filesystem with block size less than the
PAGE_SIZE, there is a possibility that the starting physical block is not
page-aligned, which results in rounding up that value before setting it
in the first swap extent. But now that the value is rounded up, we have
lost the actual offset location of the first physical block.

The starting physical block value is needed in hibernation when using a
swapfile, i.e., the resume_offset. After we have written the snapshot
pages, some values will be set in the swap header which is accessed using
that offset location. However, it will not find the swap header if the
offset value was rounded up and results in an error.

The swapfile offset being unaligned should not fail the swapon activation
as the swap extents will always have the alignment.

Therefore, just print a warning if an unaligned swapfile is activated
when hibernation is enabled.

Signed-off-by: Sukrit Bhatnagar <Sukrit.Bhatnagar@sony.com>
---
 fs/iomap/swapfile.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c
index 5fc0ac36dee3..1f7b189089dd 100644
--- a/fs/iomap/swapfile.c
+++ b/fs/iomap/swapfile.c
@@ -49,6 +49,16 @@ static int iomap_swapfile_add_extent(struct iomap_swapfile_info *isi)
 	next_ppage = ALIGN_DOWN(iomap->addr + iomap->length, PAGE_SIZE) >>
 			PAGE_SHIFT;
 
+#ifdef CONFIG_HIBERNATION
+	/*
+	 * Print a warning if the starting physical block is not aligned
+	 * to PAGE_SIZE (for filesystems using smaller block sizes).
+	 * This will fail the hibernation suspend as we need to read
+	 * the swap header later using the starting block offset.
+	 */
+	if (!iomap->offset && iomap->addr & PAGE_MASK)
+		pr_warn("swapon: starting physical offset not page-aligned\n");
+#endif
 	/* Skip too-short physical extents. */
 	if (first_ppage >= next_ppage)
 		return 0;
-- 
2.34.1



  reply	other threads:[~2024-05-22  7:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22  7:46 [PATCH 0/2] Improve dmesg output for swapfile+hibernation Sukrit Bhatnagar
2024-05-22  7:46 ` Sukrit Bhatnagar [this message]
2024-05-22 18:02   ` [PATCH 1/2] iomap: swap: print warning for unaligned swapfile Chris Li
2024-05-27 10:54     ` Sukrit.Bhatnagar
2024-05-22  7:46 ` [PATCH 2/2] mm: swap: print starting physical block offset in swapon Sukrit Bhatnagar
2024-05-22 14:56   ` Darrick J. Wong
2024-05-22 14:59     ` Christoph Hellwig
2024-05-27 11:02     ` Sukrit.Bhatnagar
2024-05-23 19:45 ` [PATCH 0/2] Improve dmesg output for swapfile+hibernation Pavel Machek
2024-05-27 11:06   ` Sukrit.Bhatnagar
2024-05-27 11:20     ` Christoph Hellwig
2024-05-27 12:51       ` Sukrit.Bhatnagar
2024-05-27 12:58         ` Christoph Hellwig
2024-05-31 14:15           ` Sukrit.Bhatnagar

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=20240522074658.2420468-2-Sukrit.Bhatnagar@sony.com \
    --to=sukrit.bhatnagar@sony.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=djwong@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    /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