From patchwork Mon Jul 12 06:02:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 475892 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 7497AC07E9B for ; Mon, 12 Jul 2021 06:58:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E6FC611C2 for ; Mon, 12 Jul 2021 06:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242519AbhGLHBe (ORCPT ); Mon, 12 Jul 2021 03:01:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:35674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242900AbhGLHAy (ORCPT ); Mon, 12 Jul 2021 03:00:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CFA1C613C3; Mon, 12 Jul 2021 06:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626073086; bh=YH8FbVC9ZzzQ95sCWHs8HCUBibhQ/gYCxwml8BfXn8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hjvVmiW2htpdbma9VL+JCjTjQDUreU65kRT4PgaHcPi2Rx1GpaL4ry+2cbUcOX889 ytA+W0r+hUpd/Wh4e1rBTDT8vn6JK1Da6QS0iZMNkbtlW4B21cs/E4M8PPoKtX9Bxd Y8Srofw5ot1jtFea8K3XGFYahxhrPpgMyagqqx0I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shinichiro Kawasaki , Chao Yu , Jaegeuk Kim Subject: [PATCH 5.12 079/700] f2fs: Prevent swap file in LFS mode Date: Mon, 12 Jul 2021 08:02:42 +0200 Message-Id: <20210712060935.852615013@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Shin'ichiro Kawasaki commit d927ccfccb009ede24448d69c08b12e7c8a6979b upstream. The kernel writes to swap files on f2fs directly without the assistance of the filesystem. This direct write by kernel can be non-sequential even when the f2fs is in LFS mode. Such non-sequential write conflicts with the LFS semantics. Especially when f2fs is set up on zoned block devices, the non-sequential write causes unaligned write command errors. To avoid the non-sequential writes to swap files, prevent swap file activation when the filesystem is in LFS mode. Fixes: 4969c06a0d83 ("f2fs: support swap file w/ DIO") Signed-off-by: Shin'ichiro Kawasaki Cc: stable@vger.kernel.org # v5.10+ Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/data.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3971,6 +3971,12 @@ static int f2fs_swap_activate(struct swa if (f2fs_readonly(F2FS_I_SB(inode)->sb)) return -EROFS; + if (f2fs_lfs_mode(F2FS_I_SB(inode))) { + f2fs_err(F2FS_I_SB(inode), + "Swapfile not supported in LFS mode"); + return -EINVAL; + } + ret = f2fs_convert_inline_inode(inode); if (ret) return ret;