Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4936338rdb; Fri, 15 Sep 2023 18:06:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDwE0qZX+a1teIxrQ7Q5TKEjeSz2O4naKL3pmwkB8G1ZRKZ9l4Hr+tlnaeCDaYOHc1aunw X-Received: by 2002:a17:902:76c5:b0:1c2:36a:52a5 with SMTP id j5-20020a17090276c500b001c2036a52a5mr2990430plt.57.1694826370478; Fri, 15 Sep 2023 18:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694826370; cv=none; d=google.com; s=arc-20160816; b=PzOPF8zYIrL4Q050N6JaSVurAGoYHHImnH6ZPnqwqEudcV5i4ICyWFcsPZL0bPNBww kmKq/WQbIeBjfhsKK6gHio2glR3+TiWitYPtY0ur3+puJve3aND5nDkKt0V/UMWaZriv FAkOJxBZeL/OhcT/VRNbBm2BS1COlJBqwafsfHZmEfVfM5I3mDV4ax6vyP2ayNW3skmi ss+SleorSdaCB/L/DIsPlyg8HSlR6snKO+g8G8w/t158MhWLgIvK4sUzu4r/USPdJAB4 L2vhigePJqFwaCGYkjF5JP/rbapouVTqZxu5LkqGluvcPKqLim2b4sep8YUP/NgkuyDM xmOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JnevztC5Xa5eXhjQG5gs4g0W7d3IJ4EIEPKbSlyaPoo=; fh=kl+S4GAUWD1kOeoqBopscteh2mu3DZslcHc01dOJ6TI=; b=pvCCLkOIoBgPMNfkl42vsT3PSobWR3KclSrqORa/ax2SFuLRp+Q9xqu8qLBRWXIS2d zphZeVaN53b0H6iO8SXxLmAHzeUQIcCRfA9ZUn5Ol0x3mp8DFADqTKwVy3PJd+Bs2mau AlGhnGPtZ3pTuXMkwbT1fl+s69NF2zIJOj0A0GY5PL42vEcPW33WS0sGSJI18xzENRab hI2mfQOX3vVb6yjyXzjO0ZZpSFFAy9U03Y+eM2lOVJItbmVkn7q0ZIJPhTB6W+rFSTXr nyS49rVyCUWvhoFbqPT2f+4QUvua7TD84pFc8uMGhByQOFuu3w0CyEUsARPAIk8dj7ID 8V1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=k4Yc0Oos; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m16-20020a170902db1000b001bf1d1d99f7si810351plx.567.2023.09.15.18.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 18:06:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=k4Yc0Oos; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E052F805093D; Fri, 15 Sep 2023 12:10:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236870AbjIOTJy (ORCPT + 99 others); Fri, 15 Sep 2023 15:09:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236872AbjIOSlN (ORCPT ); Fri, 15 Sep 2023 14:41:13 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC043AB3; Fri, 15 Sep 2023 11:40:17 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:10:26 -0700 (PDT) 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: -- 2.40.1