From patchwork Thu May 12 17:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12847964 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 1C86FC433EF for ; Thu, 12 May 2022 17:45:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A04F66B0074; Thu, 12 May 2022 13:45:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B3B66B0075; Thu, 12 May 2022 13:45:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87B5F6B0078; Thu, 12 May 2022 13:45:55 -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 7A8706B0074 for ; Thu, 12 May 2022 13:45:55 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 520C6321D3 for ; Thu, 12 May 2022 17:45:55 +0000 (UTC) X-FDA: 79457819070.09.D7364C0 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf17.hostedemail.com (Postfix) with ESMTP id 33F8E400B5 for ; Thu, 12 May 2022 17:45:35 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id p8so5450927pfh.8 for ; Thu, 12 May 2022 10:45:54 -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:mime-version :content-transfer-encoding; bh=OSHOn8AD50fQNdDvnnCPyCnTAz1Ztb2Lto+TID48AdM=; b=bGCK0VIVkh5sODitLTjTvH48DFLUzYQ67s0FaQhbO15ZF+zJ9eltLkCOZ8q15ufcKJ HfYoHJFeirejxeuRQ994CbeuvwPKtp3j2aCwamWEL+0DuxhuQcK3Gh6W3ol6MMMVZunN AxjzSBs6bLQuKGx1mKNRr9YSkRp0mokj3oDREUNb2AGp8FMsigsyHas7DXPc8xAm+UCs l14sciRRQb9W8b8YCxKZAYRUGf29LlwhEkZYyL2iYzK/NPNjhsJ07NrpXqFPlqCHqMUC HZN2j91L3W5ksxkhfpBs2be9nqrnfxsW6ii9VtwFPQEdL2r2WPp/DOlx8AM5VlUp+cl9 J8tQ== 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:mime-version :content-transfer-encoding; bh=OSHOn8AD50fQNdDvnnCPyCnTAz1Ztb2Lto+TID48AdM=; b=FGcin4fbH1MdkAEnmQTaKOLUPs6YUL2T0kDf55Zl3sgO6RZ8sLHzGpQ9FtRKTQpsh3 uUnfl9GQGAhQGLXcnTo0lSUcEOw05NQTpeXX4t6iiPOYJvifHC74i51Xr+XrCeoyQQdH KvKpTWJGn1lktcwNHXRnoXke4j28wZbUm4NoidPYh6JB3wDXUQl+i6n2Ig2//EJEJ9DR aKge4k03XZqwL3yF2Rsg/Is36OOBxVEHPTn4iakwF0WzuNuyFnrefvUqiTqY04JUuCbs UMYBt8LS6lEKQ3LGwFUsnHFxiGB1aTAH1VD8hojrAVEaQ2vxK5TTGRX+s5LQT00INdeD YQaA== X-Gm-Message-State: AOAM530mZhoujkqugjkI8xY0JAz8O1EUtTxwMzjr1uzoHO2Kq8M+7ejY OTL7bgvuVbC9IJvh4AAoddc= X-Google-Smtp-Source: ABdhPJzZ2pkh84Xs7giiuJYzryaLE1Sfm/N6dNt+o5E4Yg/OPMusEnPCaFMHncjfA5rlxn7atwNzaA== X-Received: by 2002:a65:5acd:0:b0:399:24bc:bbfd with SMTP id d13-20020a655acd000000b0039924bcbbfdmr604051pgt.323.1652377553663; Thu, 12 May 2022 10:45:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 10:45:52 -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 1/2] mm: rmap: use the correct parameter name for DEFINE_PAGE_VMA_WALK Date: Thu, 12 May 2022 10:45:50 -0700 Message-Id: <20220512174551.81279-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 33F8E400B5 X-Stat-Signature: 87nm3d7y85366n3sw5bbgen3m77kxkys X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bGCK0VIV; spf=pass (imf17.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1652377535-121106 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: The parameter used by DEFINE_PAGE_VMA_WALK is _page not page, fix the parameter name. It didn't cause any build error, it is probably because the only caller is write_protect_page() from ksm.c, which pass in page. Fixes: 2aff7a4755be ("mm: Convert page_vma_mapped_walk to work on PFNs") Signed-off-by: Yang Shi Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Muchun Song --- include/linux/rmap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index cbe279a6f0de..d4f1c0bdd084 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -320,8 +320,8 @@ struct page_vma_mapped_walk { #define DEFINE_PAGE_VMA_WALK(name, _page, _vma, _address, _flags) \ struct page_vma_mapped_walk name = { \ .pfn = page_to_pfn(_page), \ - .nr_pages = compound_nr(page), \ - .pgoff = page_to_pgoff(page), \ + .nr_pages = compound_nr(_page), \ + .pgoff = page_to_pgoff(_page), \ .vma = _vma, \ .address = _address, \ .flags = _flags, \ 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);