From patchwork Fri Mar 1 16:44:41 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: 13578748 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 0EBBBC5475B for ; Fri, 1 Mar 2024 16:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90823940009; Fri, 1 Mar 2024 11:45:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88DDF940007; Fri, 1 Mar 2024 11:45:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E1DF940009; Fri, 1 Mar 2024 11:45:27 -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 59D52940007 for ; Fri, 1 Mar 2024 11:45:27 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 30A9C120502 for ; Fri, 1 Mar 2024 16:45:27 +0000 (UTC) X-FDA: 81849045894.07.4B56F7F Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf18.hostedemail.com (Postfix) with ESMTP id 7260A1C0013 for ; Fri, 1 Mar 2024 16:45:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=Rf4VH7so; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf18.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=1709311525; 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=CoSlfuEyGkiaGErrLwm5tBbxdIgWjqVT8F2G+alxKAU=; b=tYsmH4uRNhjNUrMsMHcWujK80cxCUUwqFKjGErj3wiPxthr/BDiv1paRzNAW5u+CaAhQF5 zMyQS/543zS335Uege/tbcaIUDGGwq1HbB9mYr/83hWI8KbXJ/sNeA9k5DSSoCcI2A51rD 0toQ8qi31wxY6SxahCC+esWuSJBdB68= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=Rf4VH7so; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf18.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=1709311525; a=rsa-sha256; cv=none; b=QtF1Zw1jFh4MnFmvVsNMeqanUEdOyLTSOYPB2WnLSrcX0GPbS/KfuE+4kuLYw+86g7EmXk 4DPTPZKVxm5PqT+CGnrcH9Jf+nm+HwbusG5JF3QrPdpskq8Oz69k39OuHUJFiMxTcOrs6K tNyYVuXgo1duNZgEw5SN303ZyHx6K7Q= 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 4TmYqQ3Hk7z9tCB; Fri, 1 Mar 2024 17:45:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311522; 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=CoSlfuEyGkiaGErrLwm5tBbxdIgWjqVT8F2G+alxKAU=; b=Rf4VH7soZ/cgnAGRXcTEcKIV/sG+KQuBxSpjF53mjWkAVL6sw+HKmLZew6ousle6MJeTUR IHe7T5isExiLl34phOmLhBwfhIZEFdlgboAhxkyuZgZuf5NaxXrr27uqubaNFYdGVJD9SI L4yen1nde0OHzhSgMHHVPvrT5AK0WDQ6MA9eXSGNzhILjZ1fr5/v8PTxoP/MEiJ5ivl7kA d9Q+olVPgC8eTnAA4azyQ/pNJveDrQS69Ks+aTtNNlTHuVnAlQxPKoYb6QV6h/XK+zmD07 PfFk8VJkOPsqMYrsi/y++OTMIKetmkWOleeP43XvHi+QSCDr2GUPbuDuaMwb8g== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 10/13] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Fri, 1 Mar 2024 17:44:41 +0100 Message-ID: <20240301164444.3799288-11-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7260A1C0013 X-Stat-Signature: wdyhij5uc6dthrfrqfjwmsd4a5g1htrq X-Rspam-User: X-HE-Tag: 1709311525-114209 X-HE-Meta: U2FsdGVkX19nFM0lugBYCsJnua6WiI+sG5e3RGmyqhbpBpFmo9MsmbfN9lgZT2PoYoA0yHH7dfIPScNjeZzqS6PT2WAiBTM1qpWuR1j8FIE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UzI48NsXSmDFNoGtIr9qHs0a6LTjuBEsbasrB4M10uA2gxLPX8A7Uz2iLIPNi6EUG2hLuMte0jpboFndLIU2P1cpdZPg3nZE/tNGSYwIbxEUnSF/YJrxVo4xayoxeoTfw6aLm+fYBw6bAlakPRT8VmdIjdR6bfZe+XukaAUKh25K50I+R/UIGt4S5upwMjQ8DAykSfoWZ5O4zQvbwkCcLadH0I88zNYnhtCJpytiowSwLiL/wYbREjXe+YMgAz5oI6Y3DQhsDf25kw/T+L0xLHAOrG/qq10OEnsUlCf3hMXkjLw2yBus= 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: 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); }