Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5500892rwb; Wed, 17 Aug 2022 19:50:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ovSQ4oJPPchZcn3eFhzTpXpdrS431MrHL3M3MOS0PgJg73B1fUm+I04ZMSAFEiTy3F/ph X-Received: by 2002:a05:6402:550c:b0:443:7d15:d57f with SMTP id fi12-20020a056402550c00b004437d15d57fmr650379edb.147.1660791018234; Wed, 17 Aug 2022 19:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660791018; cv=none; d=google.com; s=arc-20160816; b=ugnXllUIunospRnAO/Gxsh6nb1bLKqvo/0+ZLuJIDk4gcfKWIvWcAma6OLh60g8LE7 pupwsYEmX/Yy6E1ADsI6hdwjdPjhf73XWuoqWaVfuDMHx9FmoyezwC8W/bBaeDQRJisC 0aWcKpnulSI3HU62t4JPfvUPQbWCX3AsNSopaVTXROay2ozqvVhSEHtxHD/Hpsv4vVMd fpx0KP69q2SQNqwsg4LohHNc057kPmeOq7CzFpddL+GVgV3LlNLPf+9urQKmYtgZ8opK 7LgwcCGn2Jy7v2uOWUgvoWVfkpdy7kPrmkS8nG/bEt/hfYQk0X56Vbuae5fDpHOJbWl0 a+nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=DdJ+Vr7hPHtj5OVHgPI42sVqcU6ySHTrxw+o43yK3qc=; b=UKDggqNws2oryXvb2F6cygpvC8QftL8wzqBWSUTAS+XWPU8oyQSc52Ke8AKw0ayYtN ic+OIXY6Al3Bs9COxeuFDX8nXvMKuIA4kpotdrDfv3qyenJYQvD/A8QZBnIWb46+Gr1C iZrriNi6EWjenNO4JvMDaM0jO7O99Z8vEznREXgtyAL8lM8abxZRiHLTWnZN/WisChrZ aL6C2JpQxezl6O4A6o1ELd1lzeP4jqOAjVvsccbx2R6wPzj9C3ZxrV2szbBWuNZdgHZa IoW657NJP5dflZJXEEoqOnLdt3PIU/IZ73IICYmxL4gRcLhD/XjBWJr+HsgjKUTOiKgx kQBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=YFhYP03x; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e17-20020a056402191100b0043a72c8b750si365662edz.114.2022.08.17.19.49.53; Wed, 17 Aug 2022 19:50:18 -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; dkim=pass header.i=@linux.dev header.s=key1 header.b=YFhYP03x; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242809AbiHRCmE (ORCPT + 99 others); Wed, 17 Aug 2022 22:42:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240598AbiHRCmD (ORCPT ); Wed, 17 Aug 2022 22:42:03 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5E769C218 for ; Wed, 17 Aug 2022 19:42:01 -0700 (PDT) Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1660790520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DdJ+Vr7hPHtj5OVHgPI42sVqcU6ySHTrxw+o43yK3qc=; b=YFhYP03xMRd4qrEdF/hwyTE3DQlMeh266DP4j6S83vMgNmMNSDkLC8FgjkrjJ/4rTIc+ct p+pnfdvAoTQBhMXdCorPGUtgec/BO/47bmASu/JjzPVrVcUnfm4vfCF3Q3SUjAip8CR5uO GlafXazSUxdrbLS34UvualWhN/WOAl0= MIME-Version: 1.0 Subject: Re: [PATCH] mm/damon: Validate if the pmd entry is present before accessing X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <2838b6737bc259cf575ff11fd1c4b7fdb340fa73.1660717122.git.baolin.wang@linux.alibaba.com> Date: Thu, 18 Aug 2022 10:41:10 +0800 Cc: sj@kernel.org, Andrew Morton , damon@lists.linux.dev, Linux MM , linux-kernel@vger.kernel.org, Mike Kravetz Content-Transfer-Encoding: quoted-printable Message-Id: <5173E308-2403-4667-9162-865CF7F11838@linux.dev> References: <2838b6737bc259cf575ff11fd1c4b7fdb340fa73.1660717122.git.baolin.wang@linux.alibaba.com> To: Baolin Wang X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 > On Aug 17, 2022, at 14:21, Baolin Wang = wrote: >=20 > 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. >=20 > Signed-off-by: Baolin Wang > --- > mm/damon/vaddr.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) >=20 > 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, >=20 > if (pmd_huge(*pmd)) { > ptl =3D pmd_lock(walk->mm, pmd); > + if (!pmd_present(*pmd)) { Unluckily, we should use pte_present here. See commit c9d398fa23788. We = can use huge_ptep_get() to get a hugetlb pte, so it=E2=80=99s better to put the = check after pmd_huge. Cc Mike to make sure I am not missing something. Muchun, Thanks. > + 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 =3D pmd_lock(walk->mm, pmd); > + if (!pmd_present(*pmd)) { > + spin_unlock(ptl); > + return 0; > + } > + > if (!pmd_huge(*pmd)) { > spin_unlock(ptl); > goto regular_page; > --=20 > 1.8.3.1 >=20 >=20