From patchwork Wed Nov 13 09:47:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13895563 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 59397E7716D for ; Thu, 5 Dec 2024 15:26:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C9926B00DD; Thu, 5 Dec 2024 10:19:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1E016B00A9; Thu, 5 Dec 2024 10:19:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 530FB6B00C2; Thu, 5 Dec 2024 10:19:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CE19D6B00C6 for ; Wed, 13 Nov 2024 04:47:36 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6DA7A140984 for ; Wed, 13 Nov 2024 09:47:36 +0000 (UTC) X-FDA: 82780593252.22.3E4E22A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id 30FED140007 for ; Wed, 13 Nov 2024 09:47:06 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Gu2MfyO+; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine); spf=none (imf23.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731491167; h=from:from:sender: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=EeFsYhvb/Fdit2R4hCFUp0b7VKyDdbX2dUmYXd00mGc=; b=VvSrDIx/7igiYfbTVcZ38RVJoSVEGRSPLqL1p/5dYOTTevloYYY7mkdcwhN54M+X/LVXFx SJII9BVM5agrCCCpMdw7B+vX55PAKLu5Gon9u8H0HsDwMm/oTd2YKuoNA/IwvrO9IG4hkr EGstKtr/AZbJV8S5Z8y/4PK8ZXzafWA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Gu2MfyO+; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine); spf=none (imf23.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731491167; a=rsa-sha256; cv=none; b=0VgwoKqULUjxSrkkmMsESO+q5RvjCV8+4odT/i/eKP5zlXNTb1faQY3QYb6TXidvC5y7uk fSywmGsiMDuXuPIvqcgcRjYB/7urX9NsVVdsp+3xdzyU3Vi3A1QlHt2397cj3zsg9bD7vH Ae2AXsAGihbcV5Hy0e143mk7qXX5AAQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=EeFsYhvb/Fdit2R4hCFUp0b7VKyDdbX2dUmYXd00mGc=; b=Gu2MfyO+KOMeF2SXnrD9P/+Yok ZDkackaAAZcM922Q2kci3CL8PuXVDU3ipL5W/i0JARN0Ecf4AMl+R9WYIZ4MjG6rBTVsRiX2s23jf Y1SGKls98aedAJVN5zJ9MrapGIkNeCebbvf00Jc772ox6gByfWwqFTITY4Ol/QR08T4fH18Dpz4X9 xMSuviowVOdca3AC9xrghQxbXYXHK+HOc/fBo+zng9q/nKrY9zyh0E/Vs1XrHK+p4z0yxx9Z7ClTP P6umpagaAJMQvQ7chWp66JmdoBso0jnn0hL2GBNLLFILfTKQ0UK0jD+5ZjDQZOzqPD00xXj/1t9TZ h6oYqmxg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tB9yD-00000006Hd6-0Cj0; Wed, 13 Nov 2024 09:47:29 +0000 From: Luis Chamberlain To: willy@infradead.org, hch@lst.de, hare@suse.de, david@fromorbit.com, djwong@kernel.org Cc: john.g.garry@oracle.com, ritesh.list@gmail.com, kbusch@kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com, kernel@pankajraghav.com, mcgrof@kernel.org Subject: [RFC 3/8] fs/buffer: restart block_read_full_folio() to avoid array overflow Date: Wed, 13 Nov 2024 01:47:22 -0800 Message-ID: <20241113094727.1497722-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241113094727.1497722-1-mcgrof@kernel.org> References: <20241113094727.1497722-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 30FED140007 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Stat-Signature: td8zdx3obk75aonf316zdokgsdmaa7wx X-Rspam: Yes X-HE-Tag: 1731491226-510022 X-HE-Meta: U2FsdGVkX1+if4f5iP5n79ULFSlIW4M3GscwPybENI7gaEJyXBpfGiXyRasCMa4FuuCRGC5/a7c63AmwmVPN5CYYaSBLRTpxm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ByuSxPmxorZ+aZb2eadzMW32RXrrwN9J8DSS3XBZXSFhdbQKOb71VcN3RCpoT5lS9KToeql8k/Sj5BLdCoi5ztvN5l5BUfyEfuSyp0aCLtGRRi4LC6q7c6J6slkfsfQFPo/ZvMdkR3/vz/z02WuLKha9ucsdigw9nG0nPfhIKQOG++TjB8YReuJxsfwWOp6+62PxMcrEpNLU32W+hgkZ6yU7C0p2337swNYIp8y9JyqJT3Oc22EFz7499YT/raxNhm7MbUhFr3t41Tl/OEQx6j/q2h9SeGtEevNNH7WBs+vzHi26Jw/N+TtTUniv6VMb+izaBTBOPDQ8g3iHkDkW4hW1XW/0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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: Hannes Reinecke block_read_full_folio() uses an on-stack array to hold any buffer_heads which should be updated. The array is sized for the number of buffer_heads per PAGE_SIZE, which of course will overflow for large folios. So instead of increasing the size of the array (and thereby incurring a possible stack overflow for really large folios) stop the iteration when the array is filled up, submit these buffer_heads, and restart the iteration with the remaining buffer_heads. Signed-off-by: Hannes Reinecke --- fs/buffer.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 1fc9a50def0b..818c9c5840fe 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2366,7 +2366,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) { struct inode *inode = folio->mapping->host; sector_t iblock, lblock; - struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; + struct buffer_head *bh, *head, *restart_bh = NULL, *arr[MAX_BUF_PER_PAGE]; size_t blocksize; int nr, i; int fully_mapped = 1; @@ -2385,6 +2385,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) iblock = div_u64(folio_pos(folio), blocksize); lblock = div_u64(limit + blocksize - 1, blocksize); bh = head; +restart: nr = 0; i = 0; @@ -2417,7 +2418,12 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) continue; } arr[nr++] = bh; - } while (i++, iblock++, (bh = bh->b_this_page) != head); + } while (i++, iblock++, (bh = bh->b_this_page) != head && nr < MAX_BUF_PER_PAGE); + + if (nr == MAX_BUF_PER_PAGE && bh != head) + restart_bh = bh; + else + restart_bh = NULL; if (fully_mapped) folio_set_mappedtodisk(folio); @@ -2450,6 +2456,15 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) else submit_bh(REQ_OP_READ, bh); } + + /* + * Found more buffers than 'arr' could hold, + * restart to submit the remaining ones. + */ + if (restart_bh) { + bh = restart_bh; + goto restart; + } return 0; } EXPORT_SYMBOL(block_read_full_folio);