From patchwork Wed Jul 31 05:46:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13748079 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 F160DC3DA64 for ; Wed, 31 Jul 2024 05:46:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747B96B0085; Wed, 31 Jul 2024 01:46:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F7496B0088; Wed, 31 Jul 2024 01:46:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5735B6B0089; Wed, 31 Jul 2024 01:46:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3A18D6B0085 for ; Wed, 31 Jul 2024 01:46:43 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A4826160130 for ; Wed, 31 Jul 2024 05:46:42 +0000 (UTC) X-FDA: 82398963444.15.E230DC2 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf17.hostedemail.com (Postfix) with ESMTP id 027CF40010 for ; Wed, 31 Jul 2024 05:46:39 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=nsrn3xlZ; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722404746; 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=w2Q2qCZXQEBR41lpW2VH/vq7C6rQUymGzd3eTc4T0Kk=; b=5svhxySq5ZfuuXSLwH1HbvN4hVjx9BD5N9YTY9V8+sodwZlN/siz2erqAtRsGwtD+9BEc2 rCYmjbhsQYXjon4vW3PXzimJ+aslX1/dLGy968huhIf28N6DqV9oRhi/KiTKi5AX0KoY1z urLS7x5axzjyNwtQGxSIStBz5BiZC4A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722404746; a=rsa-sha256; cv=none; b=B2L20Ee4wUOvqsg4WYSxjfVcErzKOcm+5MinQfqKG8j05byqD3q7u+86BTLzx3gKJx24en StUN2xhDyAorzl9mlyTnv5RubFGbkEaQzOxapGgV7HuWYRS+DysdMQ8anQhB2P+bnUbKOi WcQXk6EuFT1Lh3FtxtTSQAjX2uC2wkg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=nsrn3xlZ; spf=pass (imf17.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1722404794; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=w2Q2qCZXQEBR41lpW2VH/vq7C6rQUymGzd3eTc4T0Kk=; b=nsrn3xlZ08Hbvpj9FjDKRXNOwLmrJofre+1a+JUI+Q0TDV7/wh74/HZ37G0ppS4HEJQApWaNMCoFiS2ny/TpSwnEs9pzqauIra8Wi9KkMJNKlfurHyNxSQcZ2+R4fd2caH2jLzNCj57IrxYhS9xETAk90GwXq8/GlCtTrG/YlWw= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0WBi1RC6_1722404792; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WBi1RC6_1722404792) by smtp.aliyun-inc.com; Wed, 31 Jul 2024 13:46:32 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ziy@nvidia.com, gshan@redhat.com, ioworker0@gmail.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: shmem: fix incorrect aligned index when checking conflicts Date: Wed, 31 Jul 2024 13:46:20 +0800 Message-Id: <07433b0f16a152bffb8cee34934a5c040e8e2ad6.1722404078.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <117121665254442c3c7f585248296495e5e2b45c.1722404078.git.baolin.wang@linux.alibaba.com> References: <117121665254442c3c7f585248296495e5e2b45c.1722404078.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 027CF40010 X-Stat-Signature: gtbjcrtubajxkrxaqmj6kmc3xsc1x8e3 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722404799-505108 X-HE-Meta: U2FsdGVkX1+QNHJDRVLXT5Yx3VLhopBURWaZjwyn/dmYIGe4AFhuordroJbk3PfGMCZdXovj+LIMzEh1uop2SzpIMrSotWTtFjFP4sLhfVd3exA0djdd5+r4YXzmxdFt/CAMkta69icqCua30MFTeV6FRBHcDT1qxR7ewVk/7eDZ5ZsEVofs+7G+TXlCaDlst51vfT/D/QB8HH6rrSRmhXIMT7eStaBroCAqWGs/3KLFd52++c6oKcKguJTCyKro/C1KUGNaV31u92WYDyjP8j56jUyfSfDQ8BX8piKSIboLXwXiG3TG3zfg/Z5ZRx8C8i5tzOXyUnD84WuJBlbx+8dkDHIzfBOxZeNxpPQLzk3NsBImhe0yZLbA3hzPmi65m+986dPv83n3uzPRgWbL/87aQGEjbL/D7TQDLVL6jBKN4ot1PUfHVP6eQzEUGpwvQmOiRxhbLku6fsDwW6s1p/7nIdtUkxNrsJRDtDH6JKnZ39Sp8/10n3mf0OgybHo+RsEwtOOs6KQklg69YG4+io9ixd4//ggTpByDCLYdjVmF9RdjDPIS950FTshZkGf0PnI68EONhGpcC7rNOBxQ59XqtHq85nOB21/CwrmJks8bG6UDLcj9KaLeaSvwDbAfjMmFUDBaALeE2jQ8FbjfJ+buYPrqxpaOhwlzhomyOuKizdwQYuzzMP2r7jb3zdSBG5v6wct5gHgsV/WrJrApVun073fe5+251wgkq5QdybNSXdyLOzJYRJb2Fa9jDqJt+3mPNqJc6pGCGZHCTudzrDLDq6QJgo5vcuXlWji8/Jw88u7YIcr1hjAp9x5bHfjKmxR+0/KPTGuORXjPys4biCSYL7lSl0G7JPSr66BT470GhUu9dtyFE4TC0ChZyJSM+2Bdy/pDHVs4r2f9ONbZS6hGeeK/OMgtjA/57CSOPCl/xEKWmNQTxGncbXKZYgddBZvb28yCDvmW+/MgD+F Zc1YPq8q +YTL8g3I+NXYj2xPbnoYJgQjTKwo3biHLXlfAufGx2e8I8j1PuupDdH+0nH98v+dmEziIORm3gI7ArztbuHSGYa5dfHCzqFeQCgo8q+DVlx4YOOERqouDY16LnjcfE4Q9hLEWjKUDI/0a8ngTfwcSMc+fuvy/xQwkjlxDXDVYO+AYjdw4KDL1xGbsOM45XxvR986dHvBw6C/WCwo= 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: In the shmem_suitable_orders() function, xa_find() is used to check for conflicts in the pagecache to select suitable huge orders. However, when checking each huge order in every loop, the aligned index is calculated from the previous iteration, which may cause suitable huge orders to be missed. We should use the original index each time in the loop to calculate a new aligned index for checking conflicts to avoid this issue. Fixes: e7a2ab7b3bb5 ("mm: shmem: add mTHP support for anonymous shmem") Signed-off-by: Baolin Wang Acked-by: David Hildenbrand --- mm/shmem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a4332a97558c..6e9836b1bd1d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1686,6 +1686,7 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault unsigned long orders) { struct vm_area_struct *vma = vmf->vma; + pgoff_t aligned_index; unsigned long pages; int order; @@ -1697,9 +1698,9 @@ static unsigned long shmem_suitable_orders(struct inode *inode, struct vm_fault order = highest_order(orders); while (orders) { pages = 1UL << order; - index = round_down(index, pages); - if (!xa_find(&mapping->i_pages, &index, - index + pages - 1, XA_PRESENT)) + aligned_index = round_down(index, pages); + if (!xa_find(&mapping->i_pages, &aligned_index, + aligned_index + pages - 1, XA_PRESENT)) break; order = next_order(&orders, order); }