From patchwork Tue Feb 13 09:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B38EC4829F for ; Tue, 13 Feb 2024 09:38:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17C7C8D0009; Tue, 13 Feb 2024 04:38:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 108188D0001; Tue, 13 Feb 2024 04:38:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC2CA8D0009; Tue, 13 Feb 2024 04:38:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D44B78D0001 for ; Tue, 13 Feb 2024 04:38:00 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AEE0080892 for ; Tue, 13 Feb 2024 09:38:00 +0000 (UTC) X-FDA: 81786279120.17.281D60F Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf03.hostedemail.com (Postfix) with ESMTP id 070E420016 for ; Tue, 13 Feb 2024 09:37:58 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=BmByWoGm; dmarc=none; spf=pass (imf03.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817079; a=rsa-sha256; cv=none; b=Y3OSjDAf1V1c3YOtOdED+Di3BVgMy5SegH57dFwzjtAUNct85yk1Df7FV152WzDCW5s3Kq t1G7kgG8m0qHgZr+Zd/TtdKDozt6ckrDZJsM9F9iZpchAcKbXQTKxn9mw1eMRBQpamWYxk ac0n/EFDTNyEJldNG2XhIv6QHUGEX9I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=BmByWoGm; dmarc=none; spf=pass (imf03.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817079; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TZW5dJ0nv7fo+LI90ijtR+d2/ZkIfNS9bRkcnAAFJTI=; b=irefFZkpI5vl8Uelyp0ThTGwwsuEfo1yvdWRL++sTC244kkvxhkRRWx4qmJlZFtNedIqqt r7awbu8oSHxtEKv3g8vUcangvvbYo8d9/1tGYGAcRXSQSBwP/Bz7lRhZUqX7cJVD9AvU9I G90DOrEYsfwCYTSBgstCUpO6jMU7fS0= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TYx8347SMz9stR; Tue, 13 Feb 2024 10:37:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TZW5dJ0nv7fo+LI90ijtR+d2/ZkIfNS9bRkcnAAFJTI=; b=BmByWoGmvp+kEWIRd+4bCnx1c2aolG8l1MFYl3diqfPl1tqcl9YnuViapkcDsVIqIxJBzY QXT/YcPpK9B3nuaFEVuFdW5R6AlwojOALukyjqK/Yy3Te36bjXCR40bUAM+uoMezT5lgKn NC+RH4zuH3m2XBI4ZPaWaxWn/2hQpPmmrP0HjKHmzPORWmz+z4fAA3h98UmbZDvBT2S2Vk isdlWNDiTRE+qpjyeeVHFzn5lQttGKmWNJ2UkMcSSryAvZdDhvlh337EwDRWCUh4cfyLwr x0EH5x4x/v33DNXaAiV4YYn1JWJnST4sjQeqW1JYK0nqjGowTU6abq3eQaKg2g== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 10/14] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Tue, 13 Feb 2024 10:37:09 +0100 Message-ID: <20240213093713.1753368-11-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 070E420016 X-Stat-Signature: c8rybhry4xw8atabxh5e6mduk675rmf5 X-HE-Tag: 1707817078-38223 X-HE-Meta: U2FsdGVkX1/x3oMNtkz9cHqi1L4AT8SlFFF6dCuThNIJBtITy2fcAH+9HbaClXgdyNXAPSXWDBSXk3EH5bGV8AmsUmJ/AF9igeK8pY3Qhw7+pYXlmI43AO+jnXXRefjc6yg92DfEz3zppcAELvPbiB9KD9yi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uwzjVdDZ8PGWpiQo8qLeNvfuc9dUZalWjr9LzcXOZ2IEr4tROvg+UIGfTtRyyCpxJsrh+QbXdUU1qZg3YoJaNOSvKPZCMSiJQAmXxzSRSAUqY193P6pwc+fYgQSiRqMovuf 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: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav iomap_dio_zero() will pad a fs block with zeroes if the direct IO size < fs block size. iomap_dio_zero() has an implicit assumption that fs block size < page_size. This is true for most filesystems at the moment. If the block size > page size, this will send the contents of the page next to zero page(as len > PAGE_SIZE) to the underlying block device, causing FS corruption. iomap is a generic infrastructure and it should not make any assumptions about the fs block size and the page size of the system. Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Darrick J. Wong --- fs/iomap/direct-io.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..04f6c5548136 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -239,14 +239,23 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, struct page *page = ZERO_PAGE(0); struct bio *bio; - bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); + WARN_ON_ONCE(len > (BIO_MAX_VECS * PAGE_SIZE)); + + bio = iomap_dio_alloc_bio(iter, dio, BIO_MAX_VECS, + REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); + bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - __bio_add_page(bio, page, len, 0); + while (len) { + unsigned int io_len = min_t(unsigned int, len, PAGE_SIZE); + + __bio_add_page(bio, page, io_len, 0); + len -= io_len; + } iomap_dio_submit_bio(iter, dio, bio, pos); }