From patchwork Fri Sep 15 18:38:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13387471 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 35818EED61E for ; Fri, 15 Sep 2023 18:39:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 928A56B03C1; Fri, 15 Sep 2023 14:39:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D74D6B03C2; Fri, 15 Sep 2023 14:39:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 778E56B03C3; Fri, 15 Sep 2023 14:39:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 581AF6B03C1 for ; Fri, 15 Sep 2023 14:39:25 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2CF231CAACA for ; Fri, 15 Sep 2023 18:39:25 +0000 (UTC) X-FDA: 81239694690.17.DB2B4BD Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 70090180025 for ; Fri, 15 Sep 2023 18:39:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=zv1eBTD7; spf=pass (imf16.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694803163; a=rsa-sha256; cv=none; b=my7UhQQJTPqQaTXpCgsFrgqqgchScSQJBgPVIQsbDHtn8WqXa15KpV0k2nJJHKQE170bF5 9SdIfcp0HsQUHwq0/Wh3EIx2RXNOaf848I71YKAXM84V78l3XUh1WRoOaroV8SmFr+CfE/ hxFrm1JRUS2j0agj8iYIdST2IYkZIJ0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=zv1eBTD7; spf=pass (imf16.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 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=1694803163; 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=SzrHPPmJTKjWfDrn3YXBgU9n1TNPo/kiGOZujmxfC3o=; b=6aCJQq+j2OOerDU8oobw898PfEi8asERsvEDthSa1f3qm1pTvx8X0e6p07sI1HkcZdW//r 8NshLmyq9KZwztde7Bk41CWDPOPmi1SNiWMW6phgJV1vkGfgEgnnmdi5J5uYGUww70vs5j OucaUEcTRYrLq0tvM0wLGio3P9U2drM= Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4RnNJS3W0Xz9sbL; Fri, 15 Sep 2023 20:39:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803160; 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=SzrHPPmJTKjWfDrn3YXBgU9n1TNPo/kiGOZujmxfC3o=; b=zv1eBTD7DSyKB/ZHl4zr3fiwfusUpLKbzkWEafjVoKUx2xfMK7rklsQPPIp19HKeoo3l8c FWeg/koAWMOCS5X6e/FiZsa8S/OteBDH7E1VOVQjIAhxRZxG2855TiW8pZ388XhUkviYq2 bUYv3/X5vM3Wi4vWfiFfR93e4/3fPoNylQkICflCDoirfo2ziNslgUpmYPd0h1VRhy/zgi U9QpS/GtWY71h/CXkrwsXNlNbS9TdIZ8rep7TVuhIWNrq3bhlA9o+chV8bjGafiMcWHOQs lIMWb0XukJXAYtVaua7Mngo8ueNlG8zrZT38tUYnIZNdtKRF4sPJFkbVEB/wNA== From: Pankaj Raghav To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: p.raghav@samsung.com, david@fromorbit.com, da.gomez@samsung.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, djwong@kernel.org, linux-mm@kvack.org, chandan.babu@oracle.com, mcgrof@kernel.org, gost.dev@samsung.com Subject: [RFC 10/23] filemap: align the index to mapping_min_order in filemap_get_pages() Date: Fri, 15 Sep 2023 20:38:35 +0200 Message-Id: <20230915183848.1018717-11-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 70090180025 X-Stat-Signature: peymcnmkxj3swsdx7w4japtja5m5kb3j X-Rspam-User: X-HE-Tag: 1694803163-419005 X-HE-Meta: U2FsdGVkX19TQFtsrBLhsdmj2HBT+B31wbidNKcKugHzaVvI7q3o4tcS3CGYuhCbHHX6t7TSJGuOTgj5RFQslxloStFHpfeuSsQ9OMb88p8bhogvXuV6jLZFfaOqlD6NKKBbOvnr+4+rTT/6jf5lsCeY49TzjW6M9y14WqCm6bZAuxSa8k+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jl4r3c+zUNt53O3eWNy6IA1eJ7UAiuNkJnY5XSSA4PyvV22oN69xFxz/cTvPk1truUxpyc7BM+Prm104BUAWdGYEiMSbsN6GnYmTkxK9gGyzaeDqsf5Eg4dnv6cOKQD0= 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: From: Luis Chamberlain Align the index to the mapping_min_order number of pages in filemap_get_pages(). Signed-off-by: Luis Chamberlain --- generic/451 triggers a crash in this path for bs = 16k. mm/filemap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index e4d46f79e95d..8a4bbddcf575 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2558,14 +2558,17 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, { struct file *filp = iocb->ki_filp; struct address_space *mapping = filp->f_mapping; + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1UL << min_order; struct file_ra_state *ra = &filp->f_ra; - pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; + pgoff_t index = round_down(iocb->ki_pos >> PAGE_SHIFT, nrpages); pgoff_t last_index; struct folio *folio; int err = 0; /* "last_index" is the index of the page beyond the end of the read */ last_index = DIV_ROUND_UP(iocb->ki_pos + count, PAGE_SIZE); + last_index = round_up(last_index, nrpages); retry: if (fatal_signal_pending(current)) return -EINTR; @@ -2581,8 +2584,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_folio(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, fbatch); + err = filemap_create_folio(filp, mapping, index, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err;