Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3018785rwb; Mon, 15 Aug 2022 16:15:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4RLGTg0owSLuid2assm3dtbtl+AkOXhZ88ei4JiZJaYeVOgFS56ReT5oTLO6CHXS9CmnT4 X-Received: by 2002:a17:907:1c18:b0:731:a6c:8a with SMTP id nc24-20020a1709071c1800b007310a6c008amr11818680ejc.459.1660605337861; Mon, 15 Aug 2022 16:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605337; cv=none; d=google.com; s=arc-20160816; b=e+5GtQ8qqX1o+QyW2FmUWozIBGxaG6GPuNkHGNNZH64KQDaBUKkDiPuTLESTw9KWR5 Ewt4SmXMXqLCc+86YfZdZ/CA1VX+lBytuQWGMP+p8Hri5+K1V5vC3q6s+iVDNpTw7CUi iiGHnaXUQrj3/RZ7eSKhO0JZOr5KaUMDYza2WeMXolxjgsruJVftyZ8jAvBBH1gf6pjt DVORSYtKozYl0e2H4kNQlEGXMaBybTA+HguE4Yut/brZLlKLjHa3pq/N3whqMe73C4dO L0Wx4JV88cRXi2paTlSDhf+SyeTzH9WLkBOeVJADCKbVzD4bLxYcY54/TarvLZbTEYLl ZDJA== 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=Ywxh6wn1Uil1F2IV4u4dqPrG6TCuQ3SXyeZ3JQRUZT4=; b=YWvSpcWyOJ7ykAZAeCs84ZqCc4n/j+38P1SgZ+4rDfVzmYzoQP2PhcxtqzWDEmnopI XXfqamJNdzAvqpR/SDdYtGmiufPCb+lH3eDi56kUmrzLpgeeRDN95RPlwrgO4lNdfLLL QalBkC1L5gNUKk0gcmpnf0Oq0XP9UMlXx1bJCbkIxwaA9j0TS28ihScdXAcI4Kn4JKrG KMup1CTVmVQTejgn9b8aVdJbX2UgXDVa+fBvkcx7coIEWWSbOQ/vpRTVl1nw5hEEFOZD ZySaD95xiCgdJIm/E603WToug42f3Le7iAobNC0mDbTmcKe3yQlg0a7Z6f6fdH+MXMZn mYhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zbI4BhQN; 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 n8-20020a05640205c800b0043ac721c313si10078604edx.550.2022.08.15.16.15.11; Mon, 15 Aug 2022 16:15:37 -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=zbI4BhQN; 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 S1349892AbiHOVs5 (ORCPT + 99 others); Mon, 15 Aug 2022 17:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349746AbiHOVq0 (ORCPT ); Mon, 15 Aug 2022 17:46:26 -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 C76F9C9EBF; Mon, 15 Aug 2022 12:30:12 -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 6ABA5B810C6; Mon, 15 Aug 2022 19:30:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B736CC433D6; Mon, 15 Aug 2022 19:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591810; bh=1aEBkEVldE0y9BjO7ITmcEY/CmdEXYwxIU4S5/DA+5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zbI4BhQNmNNLKOO7VUqdFLfqdIGd2IvSAu+sNi8CpFlKOdjrgcFfJQv1LSD7DeNsG MPDKCs3KuPj5mYg7UI6X87lcs7CV9jUhHx2QGq5tWSpBTe7huVDU562DyffVCBefWp OBIW0F2tNU8HwDH9TC3vkCswavTlNsO1hnoXrQgA= 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.18 0684/1095] KVM: Dont set Accessed/Dirty bits for ZERO_PAGE Date: Mon, 15 Aug 2022 20:01:23 +0200 Message-Id: <20220815180457.671221396@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 6c8295e76548..843396ed4ad3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2852,16 +2852,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