Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3953382rwi; Sat, 22 Oct 2022 02:48:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4aTCI6dIzLvRjz9trojNO5ieuvyyAUClZXE9jY1rUzKS9+GUQpyV8kP7hB2ixuwb1eLbi5 X-Received: by 2002:a63:586:0:b0:46e:bb33:1a0b with SMTP id 128-20020a630586000000b0046ebb331a0bmr6017263pgf.305.1666432131304; Sat, 22 Oct 2022 02:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666432131; cv=none; d=google.com; s=arc-20160816; b=Cui75aJcZB7ZEpfJ9b1HiNovUY90eAz1x2MEyJQLmHBXPYwBhdMvh/qM65UqT/chAw pBATZKtBGgA4ItexBJyPyZCbzBNtD/hVegh9sd86Tdzq9ASNoQ3EWGWHvCOy0O/drsRI NTd4ALP4tPXZo1v7a0phAYyY1CPr4r++vnR98aGB/5XDHWQMe9luuBV7wYpZ6KDsFwa7 F4qZbdZj5Q30KAL0c3FhR01WzD0yKtDG9Trsjr+ZxehmmHJKWIn4T4IJyWD5gFHUVa1z I5c1ezmxqUvP7PSPNBoZ70lYxqT36yDgYsLYugcI2MuPIHKK/qFmeLkuHK4b9Dokug84 Oerg== 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=Fs6eImEhcFufrEdwkiBtpTPZv7ieCzMy8PzWaOXFUzyL0If8/taOyNQZwA5ux58707 +26NiXeVJ5WdySrJ58wH96xcI+lPRC4CjeXrzHM756Dwthn7Cww8XVgW48Z0P/vwS7ez md217hUZucsQ5wf67iSitE+tHlVL9GCj3o9BD+hf8yckhadXWx//AKiRfuui8epbMV3E 9dGBPnp4l+9ovnE2ATkw6InmuZtx4NUwvuDLrdv6PHQg691zdK5zpGJ3nw9eNwOg7P8/ QYTkA+YvLn5MGzOnPviSAG3WoD1NjiFQN7mRETP+5OwCsHUq6CIjknJpRlT9PXLmNXra UrIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E4ag0xT2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a63c045000000b0043af57e5d16si25611970pgi.724.2022.10.22.02.48.12; Sat, 22 Oct 2022 02:48:51 -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=E4ag0xT2; 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 S231240AbiJVJVl (ORCPT + 99 others); Sat, 22 Oct 2022 05:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbiJVJVJ (ORCPT ); Sat, 22 Oct 2022 05:21:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D896B2CC9E; Sat, 22 Oct 2022 01:34:36 -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 9211060AED; Sat, 22 Oct 2022 07:37:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A032FC433C1; Sat, 22 Oct 2022 07:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424248; bh=I6MFGlUEj5EUaxpuOQQn/MHXXgwh2qEtqurcxmSeeuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4ag0xT2Muh0ZkTFPuB+Ju1pKy1rc4Q1s3wLTnVpJFVyCSXTkAFq2M94sg3w8xUJg 8jFwEz1oztcgDSaGcYAZKSsDNTIrUYucP9PvPP6WqVySFJ/wL0HSHLv/8s8v+tacXi Pb+4K7MIvCuVhVGgYzlW+OM/tUC69jOUxuK3VLcY= 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.19 076/717] mm/damon: validate if the pmd entry is present before accessing Date: Sat, 22 Oct 2022 09:19:15 +0200 Message-Id: <20221022072428.716219684@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 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 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;