Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1861937rwb; Fri, 19 Aug 2022 10:36:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Ztq3yoGIYUoNckc1Hp1VPmxs1cPBih6kfocm7X2+YVPtwCmi/k5rFCL0e+gD4qqgiRzVn X-Received: by 2002:a17:902:d403:b0:172:9f0a:e591 with SMTP id b3-20020a170902d40300b001729f0ae591mr8416581ple.109.1660930606133; Fri, 19 Aug 2022 10:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930606; cv=none; d=google.com; s=arc-20160816; b=SFXtmH+vwDyGV3bKkAmi0H+XYlDL4CsEi8y4UFsP/cNXtPKbkLEX1kUmdGdFIAxXIg /8tVfF090MDIsiAXu6ROtD6NRiI+9Q4tZIiKNxCaG8MFvzkbWH2zCOk35hMR2txEc54C JoA9zq0QVRYUgqg5UGIT/Xfd7xOuQr7Si856St2U6c6UHWIUkUHi7KIG8qOSGNVpwA73 qzHFTCACu/LBwHe1CHyXZOVmh6B+YoWUr1tTn3kFpnWuBE5v4uxG1degzlQ2UDgBC0eq IJoYtrggKc5xHQJl3hwbmawPhXWkY9EWWwEUNmcp9S2rd9zanbgnqgpi1Ormd8w3FGLS r2fg== 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=D/tEnN15+reLhh2FifefeFIblasCq4yvKW7fWrJyAlk=; b=FExB1UUFs0E1u4fhGgiQZHjQL+vayAk7q3UT7cWXYSn+32pOtbhU7wOZGLjsGi+Fo3 S5YsX8Mxl8vfTNoT8u1RYWYdshJYkk2tF5ZrifX0f8tjA9WZHVk3tLtJU0sCcK87P6SB fCPH0yI3JyHTJ7v+qmyIXGsPN5TAWtpcSFdEG/xwN3KDOLIdjnMZo76VvLXVupXV1tom Si2QH6f5dmoUosZvaL3dD3tLjZzOwtqvKZjwPjFiUtWJSzj7mTR6ScCD2FtQm/qB2QGF JwXByFujgjJ0XMJQaPNvR8asgTD8z4Pslum8auhW2nYVe6EVB7dav6dh6Fkb/e51d9+R LEtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ikH5z9re; 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 t20-20020a17090aba9400b001f0761ae6besi6829096pjr.91.2022.08.19.10.36.35; Fri, 19 Aug 2022 10:36:46 -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=ikH5z9re; 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 S1352310AbiHSQV7 (ORCPT + 99 others); Fri, 19 Aug 2022 12:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352508AbiHSQQ4 (ORCPT ); Fri, 19 Aug 2022 12:16:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE861175D1; Fri, 19 Aug 2022 09:00:06 -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 95EC2B8281C; Fri, 19 Aug 2022 16:00:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4AEAC433C1; Fri, 19 Aug 2022 16:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924803; bh=xRccUg+RYk2HYXcKqv40Tc20yTxns1wD23CNpPqj9F8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ikH5z9ren+u89aZB6p/LHNepsWlAWV0OpPHPE+8W252VujA0i+QRRWMtJ1sSRQcyB m2Jfwn8Pd6HmR9SEHf8fVG/9hUxR8uyOHJszM441orAIJX+1Gx6dgalLfJkIyxTI70 kgWeSG7JCIZonGN8JG3Ocg44x+SGKbEQvhwsQLH4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 288/545] KVM: Dont set Accessed/Dirty bits for ZERO_PAGE Date: Fri, 19 Aug 2022 17:40:58 +0200 Message-Id: <20220819153842.220152009@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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.1 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,T_SCC_BODY_TEXT_LINE 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: Sean Christopherson [ Upstream commit a1040b0d42acf69bb4f6dbdc54c2dcd78eea1de5 ] Don't set Accessed/Dirty bits for a struct page with PG_reserved set, i.e. don't set A/D bits for the ZERO_PAGE. The ZERO_PAGE (or pages depending on the architecture) should obviously never be written, and similarly there's no point in marking it accessed as the page will never be swapped out or reclaimed. The comment in page-flags.h is quite clear that PG_reserved pages should be managed only by their owner, and strictly following that mandate also simplifies KVM's logic. Fixes: 7df003c85218 ("KVM: fix overflow of zero page refcount with ksm running") Signed-off-by: Sean Christopherson Message-Id: <20220429010416.2788472-4-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- virt/kvm/kvm_main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c5dbac10c372..421b0ff72b46 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2339,16 +2339,28 @@ void kvm_release_pfn_dirty(kvm_pfn_t pfn) } EXPORT_SYMBOL_GPL(kvm_release_pfn_dirty); +static bool kvm_is_ad_tracked_pfn(kvm_pfn_t pfn) +{ + if (!pfn_valid(pfn)) + return false; + + /* + * Per page-flags.h, pages tagged PG_reserved "should in general not be + * touched (e.g. set dirty) except by its owner". + */ + return !PageReserved(pfn_to_page(pfn)); +} + void kvm_set_pfn_dirty(kvm_pfn_t pfn) { - if (!kvm_is_reserved_pfn(pfn) && !kvm_is_zone_device_pfn(pfn)) + if (kvm_is_ad_tracked_pfn(pfn)) SetPageDirty(pfn_to_page(pfn)); } EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty); void kvm_set_pfn_accessed(kvm_pfn_t pfn) { - if (!kvm_is_reserved_pfn(pfn) && !kvm_is_zone_device_pfn(pfn)) + if (kvm_is_ad_tracked_pfn(pfn)) mark_page_accessed(pfn_to_page(pfn)); } EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed); -- 2.35.1