Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4465745rwb; Tue, 16 Aug 2022 23:44:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5m8bQAwIYoiXp5twIDHezwMYyM6ekeq5aU1TN+Tbl6v2e+2DF0mc4t4Qhtf/MrQ/k+6Q2w X-Received: by 2002:a63:5fd0:0:b0:41b:d317:7122 with SMTP id t199-20020a635fd0000000b0041bd3177122mr9780544pgb.61.1660718696107; Tue, 16 Aug 2022 23:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660718696; cv=none; d=google.com; s=arc-20160816; b=xDhqP6kTpfd2mLEXvdt04hO3aXFsNPdk20OA4PrKtdLNZkvslXD/UlNtk/KoqG9JFX 1ahzGwOFKuvqt7gPjaKVHyb3Vbk8T8X0cEJYOyLsJrww9WbLhlmYspSrj7ujpsYvf4J4 i0hf//RBJ+Y5ez5KXLFtx0BxJ/44pLmntmzm/Euq30ytBwvBV1MGdiaS8jcdcTcg76hl HjwJHoiJVpQ/lgH0Y93rfah215d8pZLdsSjaEh0TXGHbNkubSHnuHdF4xX99YZhPWE6t GxViwSm+g2vSPsc/uzjclLCKIChPJbM1KVCewomSRdcW46YoZMNSm2IeYiGHRgPixPZh +M9w== 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=TgyE7dM01AeSLRQ4eNBvbibwIgCmhrhgs16AOfLJTJY=; b=ptVzqrIUuzY9yF9oH8Qs20IED6rJFygfMzgXPmuSVLzM4uXIruFDBgyHiuUQN0v2An m85werrooKgpifviFPL+pujcG1Y128VBOvobzXPF0YdtzWw9or2vOeFk1hxxbuoaLYrt rtHzHKvtHyvRWwCNnwGIZq9IMRqUz27F0llo9tFSRTX4YtenoabHc+XWBRgEpnAftF3w 8rdnSRZnUpP6JfsulkRoK0msLFJmDS5TlOByTiyd5Wt4voT1U/u/sU3ujZavF8S0suTO frzRd52HN8U/dUKAUSNc9pOkx3crVd/CLf06L3V/S5Vp8tU62oARzAQjdIvYeLtJnAhw XqQw== 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 il11-20020a17090b164b00b001f4fc60c4dcsi1313141pjb.6.2022.08.16.23.44.45; Tue, 16 Aug 2022 23:44:56 -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 S238930AbiHQGVp (ORCPT + 99 others); Wed, 17 Aug 2022 02:21:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238924AbiHQGVj (ORCPT ); Wed, 17 Aug 2022 02:21:39 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76F206FA31 for ; Tue, 16 Aug 2022 23:21:25 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;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=6;SR=0;TI=SMTPD_---0VMUBGX4_1660717281; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VMUBGX4_1660717281) by smtp.aliyun-inc.com; Wed, 17 Aug 2022 14:21:22 +0800 From: Baolin Wang To: sj@kernel.org, akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon: Validate if the pmd entry is present before accessing Date: Wed, 17 Aug 2022 14:21:12 +0800 Message-Id: <2838b6737bc259cf575ff11fd1c4b7fdb340fa73.1660717122.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,RCVD_IN_DNSWL_NONE,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. Thus we should validate if it is present before making the pmd entry old or getting young state, otherwise we can not get the correct corresponding page. Signed-off-by: Baolin Wang --- 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