From patchwork Mon Feb 26 09:49:33 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: 13571768 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 98FECC48BF6 for ; Mon, 26 Feb 2024 09:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E7FE940024; Mon, 26 Feb 2024 04:50:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 195E0940014; Mon, 26 Feb 2024 04:50:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00EA3940024; Mon, 26 Feb 2024 04:50:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E3008940014 for ; Mon, 26 Feb 2024 04:50:30 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BDA39C07DD for ; Mon, 26 Feb 2024 09:50:30 +0000 (UTC) X-FDA: 81833485020.01.EBB8EC4 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf17.hostedemail.com (Postfix) with ESMTP id 2F5AB40018 for ; Mon, 26 Feb 2024 09:50:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ftPcgErq; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708941029; 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=EsD2C5aTpyQ9F59C7+oMuBPC+zkPm5tXDu06owfCznipcZIrwVHg87O6o2YtyP2JEBNFTF frqxIdsCPZc+G16bzbZQ5gAVAr7Wo/JXI4Sotuq6zCSNiIFoqVh+XvrsDfpXlgHaTuRBtF uWk6SQNpGWsSYh18+8JGK1KQTIidjnY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708941029; a=rsa-sha256; cv=none; b=2+bJuloBaR8s+7LHJUE6V6r7VRommuTy2Y/m+9sxqaoVUEi/0aJYXlUBM+eTIU3mRAmH0N dZuOfd9Wv2MGHuHKsYsVqUItDjEbOlIGwXgT8+WWW6cAJ9EdG9aehQOfWbKOnypw0ynZ5J /2uBwD2dT/0nEzTg2wzYbS2Ynitsk0k= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ftPcgErq; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4TjwpV0ZL1z9ssH; Mon, 26 Feb 2024 10:50:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1708941026; 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=ftPcgErqnPBTbun/dhyU0NKfoVEkMjjZg0CZNyhDa1KTOioigQfA3tSxToEOkKPQT/5uVW CEY6E5/8D+UDJP+TbD41sLzkafb7BBOKarhRvsqEpaL3/dvCB7+HuFndTFm+FosZeS0VQl h4YFFeZ/Y+oZy/EKgfiAs1/xt1ctY/D6Fjyj/FcCTutVY6I2tpKMSKZ5oAox1iVPEfEzBX WpNNRQKPXKgxbceDl4iniriCVCxFMh9t7y74jc8ICR+vUH/CIUoQtd3pG5pxH9Qm8gddRV m/HS4ri7tPBppNTTqo7BDAzkBzabfNdsNicJ8dOItqWJP3LIMduq7kYp7b2sPQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, mcgrof@kernel.org, ziy@nvidia.com, hare@suse.de, djwong@kernel.org, gost.dev@samsung.com, linux-mm@kvack.org, willy@infradead.org, Pankaj Raghav Subject: [PATCH 10/13] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Mon, 26 Feb 2024 10:49:33 +0100 Message-ID: <20240226094936.2677493-11-kernel@pankajraghav.com> In-Reply-To: <20240226094936.2677493-1-kernel@pankajraghav.com> References: <20240226094936.2677493-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2F5AB40018 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hwxgyb88etqd7sgb9kyrunj6cegup73a X-HE-Tag: 1708941028-548276 X-HE-Meta: U2FsdGVkX19Pq1f9v8KrCfsVjO2vuSijAuTVIQAj5PDCyl4nBMOJmY0Ln5SgqOlO1o7XYW0r1SdCej9O0gDhB60MQXuHckCD0wcGUBNI5bbeZD+Jczh/b4QMZC+oM3JjS5r7voyqDBB1LcIyHB4u3PXn6kaoIGlkjCrvqLl3H411Ziw8fkbm0Pk0wfsLR7Cybxd5I1ebx+dqFJV1cCzW9BpniDELS/nk5/D6TzOB7zeramk7vDRw8ONS18k3/RiTQwuDmAcDvw9aEAdyEnhbHjYTThLUftY8DhC9v6gof8HgqFOEXncEweRpkYqT1SxhFuaezkRuaCKL9fnbHllKQO6oeW+o3oK57uyntBABGKxYRTx0zgIYfrNQCgNd8gN8go3d50WENfX18Jg6ceetJk54GvTG+TjZ1nZT91ioeZC3si18DN07gvGMyrem6R9xS+rGIiTEs1MzQIDT0Hn+RJ7t0rWzjtB6jRaM5yz0XhwrAW+anJnbfO9t3XWAit33sY2ZwVp6OVEP5sQxpVuhgdpX2W8NLf+MDyVXsM72JqtG7KShIYWr8HRVZYrvLBCLX+bBEzCtQFgs1+jdRPtcVtn14UGyxAqWBFfvqTQqyimwA/E6uATER8Cq5F6JEHrjJh2dXd6sNQIa/EhAtx0KFQRix1XsSalQ200kKpz/4tHlJUKW+xUjXPi96mBIFHXXhKG+5yq8fWqVKi3W6PQl4WoSTqoHyRxs8P56osRmilkwvIAhbnW8vwZreRxEz8MQ5WCQAlEvIjhOTAsxdKJGl8EEOeIz2ovqgEcpIbmWyfB3PmpBFTXTyr4L3n4tgO5tGG4UYVeREjBMGMoNUrr2aeR8+WMMftT8wRyy9oEy2qGAnRphOMKF6qZc/Kd/D4+nPeePKouAvr/SYOimgZoJ4cT0/b+kdibhAyOUhLEBxnOT7eRI+4Zs4eUhRgXgwlMgYaHnUKhtrzADyibVFbl wQfJCXWx NXSJCvXYPFBSz8zLIdPZt4VCwhDeLdCPAnf5/7b3Ul1X37jne2wqYBPgxKurn6gABc+hGcZqnCKxKjETAEOyKfc0etJ7NYVfvPgSpcACaPUmJdbg= 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); }