From patchwork Mon Oct 24 11:26:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10081 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp625022wru; Mon, 24 Oct 2022 12:53:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Rco5EA6GVN7VCahpRmntzNRGFnVxpPU3iZqyq1D8WosIl/SqhpxsBQ1csl6zlWTWERAR5 X-Received: by 2002:a63:5950:0:b0:459:35df:3014 with SMTP id j16-20020a635950000000b0045935df3014mr29204025pgm.325.1666641194993; Mon, 24 Oct 2022 12:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666641194; cv=none; d=google.com; s=arc-20160816; b=hs9iysV9HF9h1y+zfqJJLzcgTkdlbJMImZZAclvwofdp/xbyt7NtlinD/qleCBeb2Z dXd4bvIYbpf3+LGCpF7XcksRyfnbAkMy9IwDFGKUqp4n0KoVoWnDNUJbUL0d/gl1k5Fp 1BMbBkQDnWrOkvz4R/zVl+pAJdRQ4CpUNCuRlPaef7J9HW5jsqPf1ZFASXQGj4BCGpA/ kqrV3j9o1jQUa+4l8XaKcF5g6WUfaYQ6tiOiomDx6UJS+mDTYXnj7Xjqohzkx6aXc51v 9c+lFkM+cXHK24qGAlWuj+fTWk2vkSIBN4gyAVdrKYO7PRmA8jiSXbTmG6k8c52Fp5ue nF6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bq/7P5pw1OowaHSDaFUqmchatpG9OjvzSKhEpNFd3Lw=; b=CB3AXji9M7+2Bc0vb/leydJ+zSvfYPbsjz+wbq4g7txuavrJBw27akTcrJp1IqF+PF NLzQU6fx7cnuHVryFNdIESEjXRbOleI4MhUJNzQxeoZ8WJEf2SpqxpHr6PeokqhBFMQS X3t/e1pjNYapVEDL0yNYfhbd4DjJpdCens48jsuQQObyUYJN/XWFhNfC+jTw6S8ZYfvX MaX5YX0N3PDqUeRGDtA1LOCNWedyjzdUdiLogyaQHNDN7NEhkP4OZvxnMa5FZUhyTwin r28jAOU437nGtzRoAouWYMsgR93aLIl8wG8BXl14QqpzEJW1SHGEyjXyZI2k4D2P9Fk3 stqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K5rcD71h; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a056a00179500b00536ee478380si759499pfg.7.2022.10.24.12.52.59; Mon, 24 Oct 2022 12:53:14 -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=@linuxfoundation.org header.s=korg header.b=K5rcD71h; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233546AbiJXTwT (ORCPT + 99 others); Mon, 24 Oct 2022 15:52:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233543AbiJXTvq (ORCPT ); Mon, 24 Oct 2022 15:51:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD5381B7AB; Mon, 24 Oct 2022 11:17:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 44E19B81147; Mon, 24 Oct 2022 12:35:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A125DC433C1; Mon, 24 Oct 2022 12:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614931; bh=eG772EymcZ2/cocaXc0a5fNVtPwx5zmLGY63ykM1Z74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5rcD71hxY3wZhxt78nnD5E1vt8iGgikFTHOaJUGRsn2r3NILwcmgjkZ+AEkD0+cz qOyJGoh5di4mnmhqoBOa+Xnrv+iRWig9Kmp84qu1wTKduSLlxVZfLSGyTsjvY5arhM Zxp1A245tC8RqSC3bUMrFwN0HUJVVXrOKrKLBe6c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Baolin Wang , SeongJae Park , Muchun Song , Mike Kravetz , Andrew Morton Subject: [PATCH 5.15 057/530] mm/damon: validate if the pmd entry is present before accessing Date: Mon, 24 Oct 2022 13:26:41 +0200 Message-Id: <20221024113047.621856529@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747599957452511697?= X-GMAIL-MSGID: =?utf-8?q?1747599957452511697?= From: Baolin Wang commit c8b9aff419303e4d4219b5ff64b1c7e062dee48e upstream. 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. This means that pmd_pfn() can not get the correct pfn number for a 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()), making the access statistics incorrect. This means that the DAMON may make incorrect decision according to the incorrect statistics, for example, DAMON may can not reclaim cold page in time due to this cold page was regarded as accessed mistakenly if DAMOS_PAGEOUT operation is specified. 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, which maintains consistency with non-present pte level entries. So add pmd entry present validation to fix the above issues. Link: https://lkml.kernel.org/r/58b1d1f5fbda7db49ca886d9ef6783e3dcbbbc98.1660805030.git.baolin.wang@linux.alibaba.com Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces") Signed-off-by: Baolin Wang Reviewed-by: SeongJae Park Reviewed-by: Muchun Song Cc: Mike Kravetz Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/damon/vaddr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -456,6 +456,11 @@ static int damon_mkold_pmd_entry(pmd_t * 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); @@ -530,6 +535,11 @@ static int damon_young_pmd_entry(pmd_t * #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;