Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2106283pxb; Wed, 9 Feb 2022 10:59:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwp/85VzXIyTboqQ1cSenx7dphSNXxXJUre+WWT4VLtYsZzdwLCZhp1uSYBD7NYy/R9rP5 X-Received: by 2002:a63:6a82:: with SMTP id f124mr2990278pgc.64.1644433150502; Wed, 09 Feb 2022 10:59:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644433150; cv=none; d=google.com; s=arc-20160816; b=TFIq5wUsoTCy8WPKQ5obY2wIK8FF/e0mr4SIyQwXhNtvEgEZFlzb1aHElkJRGxguud KLPyBL6M6+7QxpdcClzzpky30nVREbZCCh1JPlAn496Uo6lRAr66mbA/bnbgG+uLk32r jXTH02bBSUxF7fzS5R7Gh7Ec66SCZb9eW1u8jcwTf8EDcqLMSlnBXSSk6iJKXgUL4voR DBBkC9P3YEfRYCcMP2CM7V3XoN4UBT8jG8iNIVQE5iMyNGNpLYFP1I8F4kXHKtt81MfA VEh/IDwSOOI+gSeTOHhHSSDPDt+4R9d0iR3aPPwvr9qqPdmso7jAz4TiKzBKDogZbNjh 8znQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8TYNwAs02vm4CDNx1aPCczbwgm5BVw9EzNs2ZbO9w3I=; b=Az/C/xkjKUjtxOFNcGhKHHEvlgX1lmWRbVZn3DjeAisa4s9hdd8cWix+zqJgreDFOC 4mHz5ezOk7xjXGexuh/76hIVOKq0Qdj3b9sht6Sin4ldxLwwJOiAzET08cmtDrjZnObl sirCeRhK9rSI9xTgERmU3Hey0KV16AJ8pYXjZ7YzCL1lUhOBFVF+P8lYdn8Av6aNpv0v AI/lFXmalSLKFJUUP6CDgHjWoWV+fxAN1UXYBOcyP5xv45hLTrgf+MJqvZzIK4thk3fx 3e07rpM0ARR6EdL9nbH6e6OjsdM8c5+9FvebQo/9r9YFTNrM+JCGMDXt6e0obKTS3aj6 zW4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UrrGe7PF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si15944400plp.111.2022.02.09.10.58.58; Wed, 09 Feb 2022 10:59:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UrrGe7PF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237706AbiBIRA5 (ORCPT + 99 others); Wed, 9 Feb 2022 12:00:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237684AbiBIRAw (ORCPT ); Wed, 9 Feb 2022 12:00:52 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02A1EC05CB87 for ; Wed, 9 Feb 2022 09:00:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644426055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8TYNwAs02vm4CDNx1aPCczbwgm5BVw9EzNs2ZbO9w3I=; b=UrrGe7PFHEmI5PJR8GRocA1aGE/rF9a8jof+53L177wZABJvXK3WpoY0d0FQ5TIHcIjOsm SQZ2PTcXkpuXYDx6EVkaT88ld8wAwZ91TVpPN3RKvFzbPtAIXV99wbsOaYScpcQ+d5TtUw Ahz1GzI0EQfaLq7dnOEOAH0v86/glZE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-155-QukTdJvoOv-PPolitsLQWQ-1; Wed, 09 Feb 2022 12:00:51 -0500 X-MC-Unique: QukTdJvoOv-PPolitsLQWQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 802E48145E0; Wed, 9 Feb 2022 17:00:50 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03CF37CD66; Wed, 9 Feb 2022 17:00:49 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vkuznets@redhat.com, mlevitsk@redhat.com, dmatlack@google.com, seanjc@google.com Subject: [PATCH 04/12] KVM: MMU: WARN if PAE roots linger after kvm_mmu_unload Date: Wed, 9 Feb 2022 12:00:12 -0500 Message-Id: <20220209170020.1775368-5-pbonzini@redhat.com> In-Reply-To: <20220209170020.1775368-1-pbonzini@redhat.com> References: <20220209170020.1775368-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index e0c0f0bc2e8b..7b5765ced928 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5065,12 +5065,21 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu) return r; } +static void __kvm_mmu_unload(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu) +{ + int i; + kvm_mmu_free_roots(vcpu, mmu, KVM_MMU_ROOTS_ALL); + WARN_ON(VALID_PAGE(mmu->root_hpa)); + if (mmu->pae_root) { + for (i = 0; i < 4; ++i) + WARN_ON(IS_VALID_PAE_ROOT(mmu->pae_root[i])); + } +} + void kvm_mmu_unload(struct kvm_vcpu *vcpu) { - kvm_mmu_free_roots(vcpu, &vcpu->arch.root_mmu, KVM_MMU_ROOTS_ALL); - WARN_ON(VALID_PAGE(vcpu->arch.root_mmu.root_hpa)); - kvm_mmu_free_roots(vcpu, &vcpu->arch.guest_mmu, KVM_MMU_ROOTS_ALL); - WARN_ON(VALID_PAGE(vcpu->arch.guest_mmu.root_hpa)); + __kvm_mmu_unload(vcpu, &vcpu->arch.root_mmu); + __kvm_mmu_unload(vcpu, &vcpu->arch.guest_mmu); } static bool need_remote_flush(u64 old, u64 new) -- 2.31.1