From mboxrd@z Thu Jan 1 00:00:00 1970 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 87306C25B08 for ; Thu, 18 Aug 2022 02:42:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FEEF8D0002; Wed, 17 Aug 2022 22:42:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ADCE8D0001; Wed, 17 Aug 2022 22:42:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09EE18D0002; Wed, 17 Aug 2022 22:42:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EE1B78D0001 for ; Wed, 17 Aug 2022 22:42:02 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BF29C160677 for ; Thu, 18 Aug 2022 02:42:02 +0000 (UTC) X-FDA: 79811163684.05.9BBC455 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf07.hostedemail.com (Postfix) with ESMTP id 0DE30401CC for ; Thu, 18 Aug 2022 02:42:01 +0000 (UTC) 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660790522; a=rsa-sha256; cv=none; b=f4pXjesTS15+VpiKiP87EtKFy3rMQ1iX3a/Att8yE/YGTfskDcuA9Weqr21ZccY0RIDoqg n9ZcYVlX1Ycr4+L0CeYGF2e8OwzBX1ZpbJqtkVB+CnrLRZzYdYYa0pXg8+A0WM4E8F6qR3 HGKlbDeH9mmNECOB79hcOfBVRoMlBiM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=YFhYP03x; spf=pass (imf07.hostedemail.com: domain of muchun.song@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660790522; h=from:from:sender: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:dkim-signature; bh=DdJ+Vr7hPHtj5OVHgPI42sVqcU6ySHTrxw+o43yK3qc=; b=Vj0c53ogRRW+AFZlaX5RxYMKry1jdSxLtF65GbBfzn79qN96EHygILlxD+222sbuCCzoVG wwfTz/4VONd70MorWqrLFep1RSct5DImdpGglDD70Sugbm+APo8l5QWmmpj6FfHFwpdHgA S4wEcMvleOIUKmxTz/DpP+VxlKDkE6Y= Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=YFhYP03x; spf=pass (imf07.hostedemail.com: domain of muchun.song@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: k6upx6gk4dsrpbapyyae44kxab9pxt6z X-Rspamd-Queue-Id: 0DE30401CC X-HE-Tag: 1660790521-197620 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: > 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