From patchwork Fri Sep 15 18:38:37 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: 13387473 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 F1E88EED61A for ; Fri, 15 Sep 2023 18:39:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD6E76B03C4; Fri, 15 Sep 2023 14:39:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 951926B03C5; Fri, 15 Sep 2023 14:39:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A4766B03C6; Fri, 15 Sep 2023 14:39:30 -0400 (EDT) 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 5A4546B03C4 for ; Fri, 15 Sep 2023 14:39:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 38440A0669 for ; Fri, 15 Sep 2023 18:39:30 +0000 (UTC) X-FDA: 81239694900.03.54AAB84 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf07.hostedemail.com (Postfix) with ESMTP id 7FA8440023 for ; Fri, 15 Sep 2023 18:39:28 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=k4Yc0Oos; dmarc=none; spf=pass (imf07.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 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=1694803168; 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=JnevztC5Xa5eXhjQG5gs4g0W7d3IJ4EIEPKbSlyaPoo=; b=2nkSUU9EKrR9wvUBTwZPpxROO/KzTf33TlkFOk605MM1mNu3jAe5BiqrBsohW6cnAg9Brj m5hTGAkhxEqtlv8+sX/kOYgG1jf+L4wTYfWfeF2w/G08h7PAm/JVq8jMZzrFwiDprBvQD3 1w3+G2B87d/IpABpxNkazqqSutecbuI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=k4Yc0Oos; dmarc=none; spf=pass (imf07.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694803168; a=rsa-sha256; cv=none; b=abNmT7zo4UJkgAEBpemTp9LT5uUHR1119nh+ZX2Erp+jAPykihYgI8MLrqFoSzokaBaGcl JE9fJSNWg1u1EIG4/EXFMGxqAeAkOT9+aMD0QxHIiGxcFEQvle73OpdYCdluiSJt3NJ68c k1O9kL0kcYhBXeZ1b0s2MHl2fWlVWes= 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-102.mailbox.org (Postfix) with ESMTPS id 4RnNJY3FJzz9scf; Fri, 15 Sep 2023 20:39:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803165; 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=JnevztC5Xa5eXhjQG5gs4g0W7d3IJ4EIEPKbSlyaPoo=; b=k4Yc0OosuSwPR3GTilJO7yik1UFI1e6xzGKpUTNNry/gNO9lqC1Hn++uqllS/hFhBaUp6j 6BBBUZpa/0JEi+Ai24ps3Zh96w+C5hA/SBom+sueFZylFoXiFJ3xBsGSVR7Kx39XhlqT2H YOlLsSed4aroEit7x8wYZ8RvZOJZ+pga6uAq12op8NlVwJZFuRyGjiIOX/IasnXvy7of8E Bw4C9te4wO/7VvuvE2h4jtQPMc4DTeaiNz65EMObnRF4FhfyLBhafL3EofkDiD+TjE1xXb nF23dD6KEojM6yEaCJImMCaCLpilwthMJTX0vmP0FilI3KujhBBnBd4Doz0C6w== 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 12/23] filemap: align index to mapping_min_order in filemap_fault() Date: Fri, 15 Sep 2023 20:38:37 +0200 Message-Id: <20230915183848.1018717-13-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-Queue-Id: 7FA8440023 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 9n1udxsskyp1tw6d3xt5hd1hmeoa6a9j X-HE-Tag: 1694803168-901167 X-HE-Meta: U2FsdGVkX19eykoiOwN9aw/QlDp5LTQG58izWYb7S6jH8bm/WAdz7zjo7C0G6AI2MtgYEt6J1Qz7RiSC+QH8R1S0kdT1MIy3Gr4S9Ig9aUOrGxcwMFEbGOdhUUvCXZczBNtLNlLkeWMPOfNrPaEssr/uf5NIijwhvhpb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inENeJt64waa6C++hG/SP2xNoF1CKtGMfPfKTQiLo2sbFmaGBegZwydqLJ8fiYd1KVhxT4MKWoFg9rR4he2B4Hd290sijJjwXa49QNNRsBk= 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: Pankaj Raghav ALign the indices to mapping_min_order number of pages in filemap_fault(). Signed-off-by: Pankaj Raghav --- mm/filemap.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 3853df90f9cf..f97099de80b3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3288,13 +3288,17 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file *fpin = NULL; struct address_space *mapping = file->f_mapping; + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1UL << min_order; struct inode *inode = mapping->host; - pgoff_t max_idx, index = vmf->pgoff; + pgoff_t max_idx, index = round_down(vmf->pgoff, nrpages); struct folio *folio; vm_fault_t ret = 0; bool mapping_locked = false; max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); + max_idx = round_up(max_idx, nrpages); + if (unlikely(index >= max_idx)) return VM_FAULT_SIGBUS; @@ -3386,13 +3390,17 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * We must recheck i_size under page lock. */ max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); + max_idx = round_up(max_idx, nrpages); + if (unlikely(index >= max_idx)) { folio_unlock(folio); folio_put(folio); return VM_FAULT_SIGBUS; } - vmf->page = folio_file_page(folio, index); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); + + vmf->page = folio_file_page(folio, vmf->pgoff); return ret | VM_FAULT_LOCKED; page_not_uptodate: