From patchwork Thu May 12 17:45:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12847965 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 A197FC433F5 for ; Thu, 12 May 2022 17:45:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28A936B0075; Thu, 12 May 2022 13:45:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23A496B0078; Thu, 12 May 2022 13:45:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08D066B007B; Thu, 12 May 2022 13:45:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EED996B0075 for ; Thu, 12 May 2022 13:45:56 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BED95994 for ; Thu, 12 May 2022 17:45:56 +0000 (UTC) X-FDA: 79457819112.14.AA3A4C2 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf07.hostedemail.com (Postfix) with ESMTP id 9A268400AC for ; Thu, 12 May 2022 17:45:49 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id c14so5477735pfn.2 for ; Thu, 12 May 2022 10:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MKSf812TTE05BrANtImubNsPtr0MvP/NAKhjTot4IJA=; b=T4klzcOxo/2MGKJlZI20mz46CAW/dJSi8WpnD+JfxxXVw2Sm2479kH38VRnPx71CMV CbtFS6KSZ13DX7jsgSAVeCts3SAsIPlfPU3hIjWKllG3bpSrTLr2lsAsjO8uMTGlm2wk 1ZZZFjDxCGeLr4dimsllA/e8y3AoDx9zxFGS84Hj7M9j6TNHfetyNVfpZVC3dGsc9EtT Fb8kD8irhbZBbuJKx7Y2pwA9Z6xEDRA4jdtGEvcQnnhaOQ8JjDxXBcFk1dO76iOhYk1o XDHyC/GJpI6PbXOi3/jwogaI96tQF7ZA/o2cuxToERseGQIxosM7Mf2VsVipk6ZuLCPV IOCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MKSf812TTE05BrANtImubNsPtr0MvP/NAKhjTot4IJA=; b=5enaq68ZNfk9dYzvm3CfYJT9KJ6bhEFyI3oUkoY+KSac3p67+gm13laJG04odaLjgB 2unNFrmoz5R2tjD2EfCy6M7kW4zEEpsgvvlgT5Inmw9JbnpXQdL7dBP6sRDCMNtCohCl e/GtdcBObc7ynhlJwEIA9KG0iDZIO7mx3X/LESxNEish+8ePFOD8gINqWF7LC6t23gFo HW3N0Nq5+t43KGbXUbV+QGHeTF8qRvGDUMGczJ/WxkBCRlehog6i6T5AveJx2vBgFXg5 MTeM9geaXNXjOHGHOg6Mrj4FOPWdK2zidpoK/g3H7nIy8IHFIHap1mid+zMRAXYZyM1J FTjQ== X-Gm-Message-State: AOAM531fSIwC1Bi0INZ8keAgu3h+afyGSN1BArWntyi1CL0NQOpNw0k3 kOxO9z1cYVWZZ8TJarmdDf8= X-Google-Smtp-Source: ABdhPJyaxS+JpibF6XGuB3QzwL/WbWlsDrwN5hk4B2HsNo04GTLu6GafE4I8Hu+zLZoU6aKdMDT3bw== X-Received: by 2002:a63:5746:0:b0:3c2:363b:a88d with SMTP id h6-20020a635746000000b003c2363ba88dmr605892pgm.17.1652377555198; Thu, 12 May 2022 10:45:55 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id f123-20020a62db81000000b00512d84548c7sm121950pfg.53.2022.05.12.10.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 10:45:54 -0700 (PDT) From: Yang Shi To: willy@infradead.org, songmuchun@bytedance.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm: pvmw: check possible huge PMD map by transhuge_vma_suitable() Date: Thu, 12 May 2022 10:45:51 -0700 Message-Id: <20220512174551.81279-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220512174551.81279-1-shy828301@gmail.com> References: <20220512174551.81279-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: g9iefhr9hyreu8sn6adtd5qxknyigdxf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9A268400AC X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=T4klzcOx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1652377549-897446 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: IIUC PVMW checks if the vma is possibly huge PMD mapped by transparent_hugepage_active() and "pvmw->nr_pages >= HPAGE_PMD_NR". Actually pvmw->nr_pages is returned by compound_nr() or folio_nr_pages(), so the page should be THP as long as "pvmw->nr_pages >= HPAGE_PMD_NR". And it is guaranteed THP is allocated for valid VMA in the first place. But it may be not PMD mapped if the VMA is file VMA and it is not properly aligned. The transhuge_vma_suitable() is used to do such check, so replace transparent_hugepage_active() to it, which is too heavy and overkilling. Fixes: 2aff7a4755be ("mm: Convert page_vma_mapped_walk to work on PFNs") Signed-off-by: Yang Shi Reported-by: kernel test robot --- mm/page_vma_mapped.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index c10f839fc410..2634565be175 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -237,13 +237,14 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) spin_unlock(pvmw->ptl); pvmw->ptl = NULL; } else if (!pmd_present(pmde)) { + unsigned long haddr = pvmw->address & HPAGE_PMD_MASK; /* * If PVMW_SYNC, take and drop THP pmd lock so that we * cannot return prematurely, while zap_huge_pmd() has * cleared *pmd but not decremented compound_mapcount(). */ if ((pvmw->flags & PVMW_SYNC) && - transparent_hugepage_active(vma) && + transhuge_vma_suitable(vma, haddr) && (pvmw->nr_pages >= HPAGE_PMD_NR)) { spinlock_t *ptl = pmd_lock(mm, pvmw->pmd);