Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp142759rwb; Thu, 18 Aug 2022 00:50:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR4pYlTw1UbL2DaEqV7lbSzRrzJPaOWJxSWjy9bAXum5xUYmnbBTcDb6uR4q3xwiz4FS/c8Y X-Received: by 2002:a17:903:30c9:b0:172:aba2:532c with SMTP id s9-20020a17090330c900b00172aba2532cmr1598683plc.118.1660809046143; Thu, 18 Aug 2022 00:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660809046; cv=none; d=google.com; s=arc-20160816; b=hl4fiOHpm6rYotx+zArYW4vt0BMXupilc1XFydw1DGy9n/fVGDZefoDe8tnZi6uPAM Yy8x+xFZ3ck6s6dO5xnxgQBeALoqy3KmBkmJNUBZXC//A/bHh7cm9dhjZLlm8MAZjp/+ UPGYHgSJkQ7bAj287mGwDtKCGYW89nfMAt1FwZBCyQcwE2CLK3DqGFTIXS9FmfHQ1PZ0 G/NULEEs/a7xNm8eF9Mp3OG4Ru+D4FGt9j9igh9JsF/cGwykPGs2FWZ9y1XrJKZx89Xu qhPG4repQPrMR+fsnReQtEn5iwAq5ytYYr7wC2uDYdVVQ5kGAXnLuhGj+3dJrym+PRXU zM0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=WOV+y7G+Fg4w65jWTwKj0UdeeEwFKqSPXznC4p/vWKQ=; b=TEg8BtfGiCUAyIKmmYb/HUSxYIZMsolR5iRWFu4Jsn/ElqrLQ6SalNLMq6GEE4Ic+/ R7y+xey/0tzRV3vV7r2eZa5wODZfuR5UNjso8uGIiK7V+8H5eyqxTjA6TDoI4hNSaAhB wz0XEZo5TCNoswwKnOgoPaEKKT69ptlFxDPGQPkeeWPeveQqMUmVLg2JiPZNYdPlwX6U 7XivdBfo4wqOE9OfJDxPrQ7T1xgduGy9iOJkOpH0YU1u0R3qbGF1DG9ZBUAaIV0QxkIn 9/XNWCX7VriH6Izly+C+mB5tGfQ8mfGndLAqiHFaw6llMvYTiZ6EBeje+O8kz7Ntk+w4 WRgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn11-20020a17090b38cb00b001f2cf977479si4055643pjb.116.2022.08.18.00.50.34; Thu, 18 Aug 2022 00:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243744AbiHRHiE (ORCPT + 99 others); Thu, 18 Aug 2022 03:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243591AbiHRHiB (ORCPT ); Thu, 18 Aug 2022 03:38:01 -0400 Received: from out199-14.us.a.mail.aliyun.com (out199-14.us.a.mail.aliyun.com [47.90.199.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA62AB43A for ; Thu, 18 Aug 2022 00:37:59 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VMZnOij_1660808275; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VMZnOij_1660808275) by smtp.aliyun-inc.com; Thu, 18 Aug 2022 15:37:56 +0800 From: Baolin Wang To: sj@kernel.org, akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, muchun.song@linux.dev, mike.kravetz@oracle.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] mm/damon: validate if the pmd entry is present before accessing Date: Thu, 18 Aug 2022 15:37:43 +0800 Message-Id: <58b1d1f5fbda7db49ca886d9ef6783e3dcbbbc98.1660805030.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pmd_huge() is used to validate if the pmd entry is mapped by a huge page, also including the case of non-present (migration or hwpoisoned) pmd entry on arm64 or x86 architectures. That means the pmd_pfn() can not get the correct pfn number for the non-present pmd entry, which will cause damon_get_page() to get an incorrect page struct (also may be NULL by pfn_to_online_page()) to make the access statistics incorrect. Moreover it does not make sense that we still waste time to get the page of the non-present entry, just treat it as not-accessed and skip it, that keeps consistent with non-present pte level entry. Thus adding a pmd entry present validation to fix above issues. Signed-off-by: Baolin Wang Reviewed-by: SeongJae Park --- Changes from v1: - Update the commit message to make it more clear. - Add reviewed tag from SeongJae. --- mm/damon/vaddr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 3c7b9d6..1d16c6c 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -304,6 +304,11 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr, if (pmd_huge(*pmd)) { ptl = pmd_lock(walk->mm, pmd); + if (!pmd_present(*pmd)) { + spin_unlock(ptl); + return 0; + } + if (pmd_huge(*pmd)) { damon_pmdp_mkold(pmd, walk->mm, addr); spin_unlock(ptl); @@ -431,6 +436,11 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr, #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (pmd_huge(*pmd)) { ptl = pmd_lock(walk->mm, pmd); + if (!pmd_present(*pmd)) { + spin_unlock(ptl); + return 0; + } + if (!pmd_huge(*pmd)) { spin_unlock(ptl); goto regular_page; -- 1.8.3.1