From patchwork Wed May 15 02:28:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13664546 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 69D121BC5C; Wed, 15 May 2024 02:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715740745; cv=none; b=eubk0Mq2PlLl89cFPjPyotr8KQPcuR75aIRJPyufPyKxbfdw4tfsDFacm1jtchZAkU8Z43HIZcnfD/w/aaHYC7EAAQmQEw5DmUFvmSS0Bycj7MkaNdp8ZOSrvvt3DnVMho9g0T/+AIFdi96GeiZua6myGWAKlYyXHgKAK+2IvSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715740745; c=relaxed/simple; bh=+1e1oNfgfqnwV71IA8G7FJFE9eAGlnj2iTdZeejW4mY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q43uI3WwEVv+kjbbtqSDoPJs76eI2N7BaDVYTBd3fjS9OJCx06rgRknQhfuTlSkYiyYRikz7JOaFYG67T7WtEVnYaSIEcqxjopxOUdzoBSzb66/Y+idsOaDXBVVEXl3i90X0b/c0ak3EZEJDgk2MM6JKyhOCUxMxOHkDl5nUTtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VfHV14W9Tz4f3lW1; Wed, 15 May 2024 10:38:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id C40EE1A08D4; Wed, 15 May 2024 10:38:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBXKBE8IERmRFzIMg--.49754S5; Wed, 15 May 2024 10:38:59 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH 1/3] iomap: pass blocksize to iomap_truncate_page() Date: Wed, 15 May 2024 10:28:27 +0800 Message-Id: <20240515022829.2455554-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240515022829.2455554-1-yi.zhang@huaweicloud.com> References: <20240515022829.2455554-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgBXKBE8IERmRFzIMg--.49754S5 X-Coremail-Antispam: 1UD129KBjvJXoWxuFyrKF15GFykZr4xWw1rJFb_yoW5Wr4rpF 1qkF45Gw4fXry09F1kWFyUZw1YyFn8Cr40kry8GrZxZr1vqr1IyFn2ka1jvF1jqr4xur4j qFZ8K3y8Xr15ArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUSYLPUUUUU = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi iomap_truncate_page() always assumes the block size of the truncating inode is i_blocksize(), this is not always true for some filesystems, e.g. XFS do extent size alignment for realtime inodes. Drop this assumption and pass the block size for zeroing into iomap_truncate_page(), allow filesystems to indicate the correct block size. Suggested-by: Dave Chinner Signed-off-by: Zhang Yi --- fs/iomap/buffered-io.c | 7 +++---- fs/xfs/xfs_iomap.c | 3 ++- include/linux/iomap.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 0926d216a5af..4cfe0a4b3325 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1445,11 +1445,10 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, EXPORT_SYMBOL_GPL(iomap_zero_range); int -iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops) +iomap_truncate_page(struct inode *inode, loff_t pos, loff_t blocksize, + bool *did_zero, const struct iomap_ops *ops) { - unsigned int blocksize = i_blocksize(inode); - unsigned int off = pos & (blocksize - 1); + unsigned int off = pos % blocksize; /* Block boundary? Nothing to do */ if (!off) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 2857ef1b0272..31ac07bb8425 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1467,10 +1467,11 @@ xfs_truncate_page( bool *did_zero) { struct inode *inode = VFS_I(ip); + unsigned int blocksize = i_blocksize(inode); if (IS_DAX(inode)) return dax_truncate_page(inode, pos, did_zero, &xfs_dax_write_iomap_ops); - return iomap_truncate_page(inode, pos, did_zero, + return iomap_truncate_page(inode, pos, blocksize, did_zero, &xfs_buffered_write_iomap_ops); } diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 6fc1c858013d..27d59e464502 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -273,8 +273,8 @@ int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, const struct iomap_ops *ops); int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, const struct iomap_ops *ops); -int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops); +int iomap_truncate_page(struct inode *inode, loff_t pos, loff_t blocksize, + bool *did_zero, const struct iomap_ops *ops); vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops); int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, From patchwork Wed May 15 02:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13664547 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 9F6A52BB0D; Wed, 15 May 2024 02:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715740745; cv=none; b=ZPXVRl3fAjCfLeyB8MFqzFId+tmR/k5rZ2WC116KjsCpTqlVNZ9/WZgnEB/rs0Xa+OTZS93rwBI/ZTnOX1EIxwclNVdytHlk/JVR2JvLoVZCVTK37a91nMjAQnEf5VrtL9SKQOXnF0dzdwjaGxBegoJXZ+FpoXmAr4vhD+P5eWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715740745; c=relaxed/simple; bh=XujiZ625YkMwUYco9phrrOmKK3leYBhdEU1A2DI+XqE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jFO2IgehBjxV8OPr/1qfRI/0WEndNfjghEg1aFLHelDB5YjK+jRfwrviG24++ppL730vVbgw0/5qE8nO6EXAQ9X4+L+SMYbkbRPIj5keY4+Adju77IivKVIShK+TNp+14FkaDkrBUXE9gmdvSkOt+kx/uO1h6dVgZrMUsE+EPcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VfHV21JXKz4f3lfn; Wed, 15 May 2024 10:38:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 51BCE1A0182; Wed, 15 May 2024 10:39:00 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBXKBE8IERmRFzIMg--.49754S6; Wed, 15 May 2024 10:39:00 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH 2/3] fsdax: pass blocksize to dax_truncate_page() Date: Wed, 15 May 2024 10:28:28 +0800 Message-Id: <20240515022829.2455554-3-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240515022829.2455554-1-yi.zhang@huaweicloud.com> References: <20240515022829.2455554-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgBXKBE8IERmRFzIMg--.49754S6 X-Coremail-Antispam: 1UD129KBjvJXoWxuFyrKF15GF1kGFWkAFWrKrg_yoW5CF4rpF 1DGa15G397X34j9F1kWF1UZw45t3WDCF409ryxAws3Zr92qr1IyF18KF1jkF4jqr48Z3yq qF98Kw47Gr1rAFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUAGYLUUUUU = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi dax_truncate_page() always assumes the block size of the truncating inode is i_blocksize(), this is not always true for some filesystems, e.g. XFS do extent size alignment for realtime inodes. Drop this assumption and pass the block size for zeroing into dax_truncate_page(), allow filesystems to indicate the correct block size. Suggested-by: Dave Chinner Signed-off-by: Zhang Yi --- fs/dax.c | 7 +++---- fs/ext2/inode.c | 4 ++-- fs/xfs/xfs_iomap.c | 2 +- include/linux/dax.h | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 423fc1607dfa..ae3133cc816c 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1403,11 +1403,10 @@ int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, } EXPORT_SYMBOL_GPL(dax_zero_range); -int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops) +int dax_truncate_page(struct inode *inode, loff_t pos, loff_t blocksize, + bool *did_zero, const struct iomap_ops *ops) { - unsigned int blocksize = i_blocksize(inode); - unsigned int off = pos & (blocksize - 1); + unsigned int off = pos % blocksize; /* Block boundary? Nothing to do */ if (!off) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index f3d570a9302b..fbbd479f3c4e 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -1278,8 +1278,8 @@ static int ext2_setsize(struct inode *inode, loff_t newsize) inode_dio_wait(inode); if (IS_DAX(inode)) - error = dax_truncate_page(inode, newsize, NULL, - &ext2_iomap_ops); + error = dax_truncate_page(inode, newsize, i_blocksize(inode), + NULL, &ext2_iomap_ops); else error = block_truncate_page(inode->i_mapping, newsize, ext2_get_block); diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 31ac07bb8425..4958cc3337bc 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1470,7 +1470,7 @@ xfs_truncate_page( unsigned int blocksize = i_blocksize(inode); if (IS_DAX(inode)) - return dax_truncate_page(inode, pos, did_zero, + return dax_truncate_page(inode, pos, blocksize, did_zero, &xfs_dax_write_iomap_ops); return iomap_truncate_page(inode, pos, blocksize, did_zero, &xfs_buffered_write_iomap_ops); diff --git a/include/linux/dax.h b/include/linux/dax.h index 9d3e3327af4c..861fac466c76 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -210,8 +210,8 @@ int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, const struct iomap_ops *ops); int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, const struct iomap_ops *ops); -int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops); +int dax_truncate_page(struct inode *inode, loff_t pos, loff_t blocksize, + bool *did_zero, const struct iomap_ops *ops); #if IS_ENABLED(CONFIG_DAX) int dax_read_lock(void); From patchwork Wed May 15 02:28:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13664549 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 B2B6B2C69B; Wed, 15 May 2024 02:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715740746; cv=none; b=t6RUq4j09f17QSDd2HOQnv6UaSFOLBnd42wSUTAIlVRmLZKnJYivKhWgEmJYLCtul1IMqtJAgI7L8aRubi0xOh1r7MpdrOU7IJBl8iLDLSQ5vhdZyCFerGAMf1vqtZrl2Pi42wSIUiCArT6TFyQtKLAfblcGR6vP2R2K4xgOLgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715740746; c=relaxed/simple; bh=xuIlfY/3HVCtD8t5rWUv44jPGANtnz30uK1KfBywpWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ggYy1zNQs8YTtMF8ruK0s0i5iXymkpJ7xSYLvKs2IJD4aUc2iyFtZdnNU4PJ7cbtOfIK692P4NLaAZw20APN+WiEZw8zM426GDnrQjVHzAq2qAX4+3FFGoCmpHyXqEnOWd9srRjjDM3HQHOqy8EdC1u58VcIqOl3bgB0vAGRV9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VfHV72Cpjz4f3jjk; Wed, 15 May 2024 10:38:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D10301A0D99; Wed, 15 May 2024 10:39:00 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBXKBE8IERmRFzIMg--.49754S7; Wed, 15 May 2024 10:39:00 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH 3/3] xfs: correct the zeroing truncate range Date: Wed, 15 May 2024 10:28:29 +0800 Message-Id: <20240515022829.2455554-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240515022829.2455554-1-yi.zhang@huaweicloud.com> References: <20240515022829.2455554-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgBXKBE8IERmRFzIMg--.49754S7 X-Coremail-Antispam: 1UD129KBjvJXoWxGrW7uF4UAw1DCr4fGFW8Xrb_yoWrGry5pr s7K3Z8CrsrK347ZF1kXF1jvw1Fy3WrAF409ryfGrn7Za4DXr1Iyrn2gF4rKa1Utr4DXw4Y qFs5tayUuas5AaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8Jw CI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUFfHUDUUU U X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi When truncating a realtime file unaligned to a shorter size, xfs_setattr_size() only flush the EOF page before zeroing out, and xfs_truncate_page() also only zeros the EOF block. This could expose stale data since 943bc0882ceb ("iomap: don't increase i_size if it's not a write operation"). If the sb_rextsize is bigger than one block, and we have a realtime inode that contains a long enough written extent. If we unaligned truncate into the middle of this extent, xfs_itruncate_extents() could split the extent and align the it's tail to sb_rextsize, there maybe have more than one blocks more between the end of the file. Since xfs_truncate_page() only zeros the trailing portion of the i_blocksize() value, so it may leftover some blocks contains stale data that could be exposed if we append write it over a long enough distance later. xfs_truncate_page() should flush, zeros out the entire rtextsize range, and make sure the entire zeroed range have been flushed to disk before updating the inode size. Fixes: 943bc0882ceb ("iomap: don't increase i_size if it's not a write operation") Reported-by: Chandan Babu R Link: https://lore.kernel.org/linux-xfs/0b92a215-9d9b-3788-4504-a520778953c2@huaweicloud.com Signed-off-by: Zhang Yi --- fs/xfs/xfs_iomap.c | 35 +++++++++++++++++++++++++++++++---- fs/xfs/xfs_iops.c | 10 ---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 4958cc3337bc..fc379450fe74 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1466,12 +1466,39 @@ xfs_truncate_page( loff_t pos, bool *did_zero) { + struct xfs_mount *mp = ip->i_mount; struct inode *inode = VFS_I(ip); unsigned int blocksize = i_blocksize(inode); + int error; + + if (XFS_IS_REALTIME_INODE(ip)) + blocksize = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize); + + /* + * iomap won't detect a dirty page over an unwritten block (or a + * cow block over a hole) and subsequently skips zeroing the + * newly post-EOF portion of the page. Flush the new EOF to + * convert the block before the pagecache truncate. + */ + error = filemap_write_and_wait_range(inode->i_mapping, pos, + roundup_64(pos, blocksize)); + if (error) + return error; if (IS_DAX(inode)) - return dax_truncate_page(inode, pos, blocksize, did_zero, - &xfs_dax_write_iomap_ops); - return iomap_truncate_page(inode, pos, blocksize, did_zero, - &xfs_buffered_write_iomap_ops); + error = dax_truncate_page(inode, pos, blocksize, did_zero, + &xfs_dax_write_iomap_ops); + else + error = iomap_truncate_page(inode, pos, blocksize, did_zero, + &xfs_buffered_write_iomap_ops); + if (error) + return error; + + /* + * Write back path won't write dirty blocks post EOF folio, + * flush the entire zeroed range before updating the inode + * size. + */ + return filemap_write_and_wait_range(inode->i_mapping, pos, + roundup_64(pos, blocksize)); } diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 66f8c47642e8..baeeddf4a6bb 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -845,16 +845,6 @@ xfs_setattr_size( error = xfs_zero_range(ip, oldsize, newsize - oldsize, &did_zeroing); } else { - /* - * iomap won't detect a dirty page over an unwritten block (or a - * cow block over a hole) and subsequently skips zeroing the - * newly post-EOF portion of the page. Flush the new EOF to - * convert the block before the pagecache truncate. - */ - error = filemap_write_and_wait_range(inode->i_mapping, newsize, - newsize); - if (error) - return error; error = xfs_truncate_page(ip, newsize, &did_zeroing); }