From patchwork Wed May 22 07:46:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sukrit.Bhatnagar@sony.com" X-Patchwork-Id: 13670532 Received: from jpms-ob02.noc.sony.co.jp (jpms-ob02.noc.sony.co.jp [211.125.140.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FC5080025; Wed, 22 May 2024 07:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.125.140.165 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716364385; cv=none; b=kH2+3v54qm0fDZniCeMJUQvyOcY3w0mKR1r+A0FqkmwQIw314h5gwbplis65lH5ecsg6K/2pudP6dkiDcdwulhOTjRBqc02Udln4pe7GczJLA2TmWd2AMpInWOnzTMKSxkL3kP+6+M6VynjJCRApH4+U0S6OnOpNl0dG5em0S/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716364385; c=relaxed/simple; bh=u/nje6kivX57y9Efk6JRMSDlSj6Fx4OLxIkreKTXcoY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NA0eexVsfFEmwDl9d2XOixoPK6iSaWmvPeQrzyw4Izotot3p/BnXslMbldeE+fIodQGwKpVw7YwkuZq/0+46EoCM0DRL3X4Gua3YcdAgARmce1oNeOpX8GBtJ073Z02nLli8RM49dh/YqQ/rGhZ1sgDIROybbTyQnXCXJ6NjCoc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=CmV4swUx; arc=none smtp.client-ip=211.125.140.165 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="CmV4swUx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; s=s1jp; t=1716364384; x=1747900384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ATSJTIQ7YlfNHhI2J03NerUHdvI37i6ERHqni1M7vn4=; b=CmV4swUxDU6eAPw5sx0gh/dW9eZuRbnPUkIcMSPf4vxeaktqcXm2TV3O +fRN8TZz6beWQzjwYsdWwZ0NqsiZKtlqecPjl1Kxx5A4SFrc+/dvZrBxn Fh0AfIbnqSGugxLB1nc5GQxFVxXfxrWvyuQ3sM0rggroSKvRJZP6IVIsH akd0nA1WbIjvNHJpNSwmWwYC/p9Vy7/ygwcfm4qh2M3yzuRdU49Mceioj BfU6Dj8s6ZaKkVJAJYF6CoE+Dlv5tsrpyD3DYT+yhX7Idqh+/jn5azoH9 S8JFvAEYmMU+QC0ZOE2L75k25A+jkpioomUCNVgDVYG0trtK/U2z84Kup A==; Received: from unknown (HELO jpmta-ob1.noc.sony.co.jp) ([IPv6:2001:cf8:0:6e7::6]) by jpms-ob02.noc.sony.co.jp with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2024 16:42:51 +0900 X-IronPort-AV: E=Sophos;i="6.08,179,1712588400"; d="scan'208";a="415026696" Received: from unknown (HELO OptiPlex-7080..) ([IPv6:2001:cf8:1:5f1:0:dddd:6fe5:f4d0]) by jpmta-ob1.noc.sony.co.jp with ESMTP; 22 May 2024 16:42:51 +0900 From: Sukrit Bhatnagar To: "Rafael J. Wysocki" , Pavel Machek , Christian Brauner , "Darrick J. Wong" , Andrew Morton 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 Message-Id: <20240522074658.2420468-2-Sukrit.Bhatnagar@sony.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522074658.2420468-1-Sukrit.Bhatnagar@sony.com> References: <20240522074658.2420468-1-Sukrit.Bhatnagar@sony.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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; From patchwork Wed May 22 07:46:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sukrit.Bhatnagar@sony.com" X-Patchwork-Id: 13670533 Received: from jpms-ob02.noc.sony.co.jp (jpms-ob02.noc.sony.co.jp [211.125.140.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DBDA8003A; Wed, 22 May 2024 07:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.125.140.165 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716364386; cv=none; b=pwspLI3rSE+O+oGoGCxnRyxjdVn1O4P3VULL4lsd+/ColgwnPukdcgQe849KDAFWL8sTbczOKdozRJ1f0WtrT3mYSIc53ZPxlimVJOTCbzqvmLsGzB+1yM/ZfPm645k8JUlFckJTCgco8vfDoBAks2e2unD8+dDsnhyOVIomlC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716364386; c=relaxed/simple; bh=Xj30BspwB2ZJM37mRWm/eSDeD9On/18YKbKVZJZ6Bjg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P9veCyz2HH1WqS/qQfLYWxnnDnunQ/IqSOQNMn1aVFA2V+V0M8ziHZI71rfybUfzsbzH0q8kxt7Von5tjKfjdxQ0mLZAKFQ935VC41/Tll/Z/pzOTIo+wqipsG3FVACFZurdK4xGLISlejmcSe2ip7NDtkMN85I5KCrj6LZ9SZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=fxmmeEfh; arc=none smtp.client-ip=211.125.140.165 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="fxmmeEfh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; s=s1jp; t=1716364385; x=1747900385; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tcuh+p5nJoghdQBJL3ji43C7DQTD/lzlQqzzKUPARXQ=; b=fxmmeEfhvk90lanVuO6bLRo37ZXx+aXkcJ3u1EhxrMmqY0UyV3bHuUx+ EB7wfFUKMiCsyNSZDzLKQC6xSHvgC3mPaB5+fHA1LGBRb/d/dTS3DfGGA XGx6hYaGnnKWBo5aZStug25P7y6qbQIuE/6fgH/K1ugDQC4oVyjMx4L25 aIYrH0YKDA8KwzCQoq76kNm3wtLY8tCiX+/RXGnpQY7KBDrYBAgTq+FW1 wIzscznnjaildtJG9b8WxY0IzndUkoFeTIwsHgVXptI5d505bqj01PAF1 QPCVwLDzCIXxNonmU3g1sviHwyV+7/YJScg77xKB5GyoPf0WDhCEQ3v3u w==; Received: from unknown (HELO jpmta-ob1.noc.sony.co.jp) ([IPv6:2001:cf8:0:6e7::6]) by jpms-ob02.noc.sony.co.jp with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2024 16:42:51 +0900 X-IronPort-AV: E=Sophos;i="6.08,179,1712588400"; d="scan'208";a="415026697" Received: from unknown (HELO OptiPlex-7080..) ([IPv6:2001:cf8:1:5f1:0:dddd:6fe5:f4d0]) by jpmta-ob1.noc.sony.co.jp with ESMTP; 22 May 2024 16:42:51 +0900 From: Sukrit Bhatnagar To: "Rafael J. Wysocki" , Pavel Machek , Christian Brauner , "Darrick J. Wong" , Andrew Morton 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 2/2] mm: swap: print starting physical block offset in swapon Date: Wed, 22 May 2024 16:46:58 +0900 Message-Id: <20240522074658.2420468-3-Sukrit.Bhatnagar@sony.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522074658.2420468-1-Sukrit.Bhatnagar@sony.com> References: <20240522074658.2420468-1-Sukrit.Bhatnagar@sony.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When a swapfile is created for hibernation purposes, we always need the starting physical block offset, which is usually determined using userspace commands such as filefrag. It would be good to have that value printed when we do swapon and get that value directly from dmesg. Signed-off-by: Sukrit Bhatnagar --- mm/swapfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index f6ca215fb92f..53c9187d5fbe 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3264,8 +3264,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) (swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT; enable_swap_info(p, prio, swap_map, cluster_info); - pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s\n", + pr_info("Adding %uk swap on %s. Priority:%d extents:%d start:%llu across:%lluk %s%s%s%s\n", K(p->pages), name->name, p->prio, nr_extents, + (unsigned long long)first_se(p)->start_block, K((unsigned long long)span), (p->flags & SWP_SOLIDSTATE) ? "SS" : "", (p->flags & SWP_DISCARDABLE) ? "D" : "",