From patchwork Wed Oct 19 08:22:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp204208wrs; Wed, 19 Oct 2022 01:45:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ElTBTdildl9+hEWo1jfzoM/jvr40os1jO5/Vk7NpihHOHO9T3M5qJL37kZMpk5uq+ya+G X-Received: by 2002:a63:8149:0:b0:461:f9f7:f64a with SMTP id t70-20020a638149000000b00461f9f7f64amr6273020pgd.338.1666169127185; Wed, 19 Oct 2022 01:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169127; cv=none; d=google.com; s=arc-20160816; b=mVhaR0UVNcD7uSf6OJ90/q4NLo7DBwEgtsoE6uqNAvlsLb4mfLM5Q+Bdw3FEG8g2Pq 399Bj5ugHv8hGjziUASDnho0cubWmlWeni+S7OricgoeM5LmfRFh4nFYIbypMaT431/G WdWTwlaHHbReuvEzmzrouZrto9q3DMRO92xQhq4Nb5ebW/yLl5E4ji1So7kZayIs7aqq xWQbC/AZJJEdwP38QYo4sczCRJ7L138gxh1V0CAkfBp55s38udo4e44YMzoEhAAfVJyo hy/EdSuAEGCs31iyUiMnldAtjkuLSzmXB5Zo7wlfpOoxN1EtSzcU+XWthBpKkwSgQuXV pLdg== 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=RGwaLVJROyG+xukoRwaAjzO2VtOKfTbFcHqQ254I78Y=; b=SB0JEIebzdBek0ao9ROb0FHnE7BZuK0SwEUI2xuaNOJDL4o2Ja2Kt0jMA+6bfBe4ZW E1vNLU1l3sckmtRz7XL46znqPuYdKpii0YzzFGw3neZenVHglKX3pDkh8/TRU+JaoIBo SXKZ5ZpCUD0UF/BfR1rpJSI3PPQCv4EZez7L8C4feq/OAmdnkeTFdCk4PW/QvJPat3ey gcPeZF3eZoc5aPQ0q1U8zsR8xRFyJUM+q6Bwm58lZU2tgtGCT80aLHJcDhPfy3OLX4PU c5y+MtU17sjOAADW+oc2WDpQQrGXNMCqzcsxxE3oUcIP68kbyF0vxLk+tR8IjYbaYNkq ZAAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ns9Yfy95; 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 e14-20020a170902ef4e00b001825b1375ebsi17055634plx.544.2022.10.19.01.45.13; Wed, 19 Oct 2022 01:45:27 -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=ns9Yfy95; 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 S231294AbiJSIox (ORCPT + 99 others); Wed, 19 Oct 2022 04:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231329AbiJSIn7 (ORCPT ); Wed, 19 Oct 2022 04:43:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2134F7FFA8; Wed, 19 Oct 2022 01:41:41 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3B548617F2; Wed, 19 Oct 2022 08:41:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BEEAC433D7; Wed, 19 Oct 2022 08:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168876; bh=I6MFGlUEj5EUaxpuOQQn/MHXXgwh2qEtqurcxmSeeuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ns9Yfy95osqnpTJttDjdi8pzcy12KIxreYWwK/VmvpYVejM82T/5gALnjiEAUlxM/ GN8BNdMLMCJmiCz+zUogL9MNBz/2JwomZ+4Uj++d5FseuVSG5ISazFihs03XF0zr4f QflzDPXWlaUIx4woFdRX7HRI1gOXbEkvD0ZMC8ZE= 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 6.0 084/862] mm/damon: validate if the pmd entry is present before accessing Date: Wed, 19 Oct 2022 10:22:51 +0200 Message-Id: <20221019083253.646689056@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747104958522701485?= X-GMAIL-MSGID: =?utf-8?q?1747104958522701485?= 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 @@ -304,6 +304,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); @@ -431,6 +436,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;