From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 067AAC433FE for ; Tue, 22 Mar 2022 17:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239620AbiCVR0i (ORCPT ); Tue, 22 Mar 2022 13:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239618AbiCVR0e (ORCPT ); Tue, 22 Mar 2022 13:26:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4AA4246657 for ; Tue, 22 Mar 2022 10:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969906; 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=nPvfKTaEqxJ+Ae0wIaDYiuGLu21nzq7TNDCzPfa276A=; b=Ft6qpuBtm6bS8Q88hVkTin1/C4Y7/Brozk/bMZAyKY1t1mCNwbNWC6S25UVDbIqrqe0juD 06xMhyFI83n1LzbZmhxurTaausRcQDnhYxe1+J5TG3+psYlmjrbpSQw9xdNfMq0ji7QMUD 6/O8LRIRta9mq8nC7mUaFP/1A5q7j1c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-396-dMvdYKRwMIy3qG8JG2fyEQ-1; Tue, 22 Mar 2022 13:25:03 -0400 X-MC-Unique: dMvdYKRwMIy3qG8JG2fyEQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78CAF185A79C; Tue, 22 Mar 2022 17:25:02 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9A822166B2D; Tue, 22 Mar 2022 17:24:58 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky , stable@vger.kernel.org Subject: [PATCH 1/8] KVM: x86: avoid loading a vCPU after .vm_destroy was called Date: Tue, 22 Mar 2022 19:24:42 +0200 Message-Id: <20220322172449.235575-2-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This can cause various unexpected issues, since VM is partially destroyed at that point. For example when AVIC is enabled, this causes avic_vcpu_load to access physical id page entry which is already freed by .vm_destroy. Fixes: 8221c1370056 ("svm: Manage vcpu load/unload when enable AVIC") Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d3a9ce07a565..ba920e537ddf 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11759,20 +11759,15 @@ static void kvm_unload_vcpu_mmu(struct kvm_vcpu *= vcpu) vcpu_put(vcpu); } =20 -static void kvm_free_vcpus(struct kvm *kvm) +static void kvm_unload_vcpu_mmus(struct kvm *kvm) { unsigned long i; struct kvm_vcpu *vcpu; =20 - /* - * Unpin any mmu pages first. - */ kvm_for_each_vcpu(i, vcpu, kvm) { kvm_clear_async_pf_completion_queue(vcpu); kvm_unload_vcpu_mmu(vcpu); } - - kvm_destroy_vcpus(kvm); } =20 void kvm_arch_sync_events(struct kvm *kvm) @@ -11878,11 +11873,12 @@ void kvm_arch_destroy_vm(struct kvm *kvm) __x86_set_memory_region(kvm, TSS_PRIVATE_MEMSLOT, 0, 0); mutex_unlock(&kvm->slots_lock); } + kvm_unload_vcpu_mmus(kvm); static_call_cond(kvm_x86_vm_destroy)(kvm); kvm_free_msr_filter(srcu_dereference_check(kvm->arch.msr_filter, &kvm->sr= cu, 1)); kvm_pic_destroy(kvm); kvm_ioapic_destroy(kvm); - kvm_free_vcpus(kvm); + kvm_destroy_vcpus(kvm); kvfree(rcu_dereference_check(kvm->arch.apic_map, 1)); kfree(srcu_dereference_check(kvm->arch.pmu_event_filter, &kvm->srcu, 1)); kvm_mmu_uninit_vm(kvm); --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6715C433F5 for ; Tue, 22 Mar 2022 17:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239635AbiCVR0n (ORCPT ); Tue, 22 Mar 2022 13:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239632AbiCVR0l (ORCPT ); Tue, 22 Mar 2022 13:26:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1520C49692 for ; Tue, 22 Mar 2022 10:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969913; 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=U1H3Hqi1yPaMioKAaaHbxRBztSVtJHWS8z/3mEeiMtw=; b=QOyH8H6zq6n3ph4r3cVIHC8eSvaY8VdoO254R0RJVtjTjaSmo46hhASTrNTdxrhU9EvuWu uzoJrUH2enhr4FMkZVCFHBpk6Oq+auvbWjOQSHVpy3L9lnuKthlGaShYWOWz4xfR85fECG JlAm8dJ5/mgdH9ypZn+ZWAcginAh80k= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-yyXdqDiBPGiqmdQ8oGGrcQ-1; Tue, 22 Mar 2022 13:25:10 -0400 X-MC-Unique: yyXdqDiBPGiqmdQ8oGGrcQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34DFA3804077; Tue, 22 Mar 2022 17:25:09 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id D026C2166B2D; Tue, 22 Mar 2022 17:25:02 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 2/8] KVM: x86: SVM: use vmcb01 in avic_init_vmcb and init_vmcb Date: Tue, 22 Mar 2022 19:24:43 +0200 Message-Id: <20220322172449.235575-3-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 2 +- arch/x86/kvm/svm/svm.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index c5ef4715f3e0..b39fe614467a 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -167,7 +167,7 @@ int avic_vm_init(struct kvm *kvm) =20 void avic_init_vmcb(struct vcpu_svm *svm) { - struct vmcb *vmcb =3D svm->vmcb; + struct vmcb *vmcb =3D svm->vmcb01.ptr; struct kvm_svm *kvm_svm =3D to_kvm_svm(svm->vcpu.kvm); phys_addr_t bpa =3D __sme_set(page_to_phys(svm->avic_backing_page)); phys_addr_t lpa =3D __sme_set(page_to_phys(kvm_svm->avic_logical_id_table= _page)); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 6535adee3e9c..e9a5c1e80889 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -997,8 +997,9 @@ static inline void init_vmcb_after_set_cpuid(struct kvm= _vcpu *vcpu) static void init_vmcb(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); - struct vmcb_control_area *control =3D &svm->vmcb->control; - struct vmcb_save_area *save =3D &svm->vmcb->save; + struct vmcb *vmcb =3D svm->vmcb01.ptr; + struct vmcb_control_area *control =3D &vmcb->control; + struct vmcb_save_area *save =3D &vmcb->save; =20 svm_set_intercept(svm, INTERCEPT_CR0_READ); svm_set_intercept(svm, INTERCEPT_CR3_READ); @@ -1140,10 +1141,10 @@ static void init_vmcb(struct kvm_vcpu *vcpu) } } =20 - svm_hv_init_vmcb(svm->vmcb); + svm_hv_init_vmcb(vmcb); init_vmcb_after_set_cpuid(vcpu); =20 - vmcb_mark_all_dirty(svm->vmcb); + vmcb_mark_all_dirty(vmcb); =20 enable_gif(svm); } --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56EB8C433FE for ; Tue, 22 Mar 2022 17:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239652AbiCVR0u (ORCPT ); Tue, 22 Mar 2022 13:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239640AbiCVR0s (ORCPT ); Tue, 22 Mar 2022 13:26:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F9C249F05 for ; Tue, 22 Mar 2022 10:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969917; 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=rKDRAjIHXRB118gX9l+xARuxZXtMVqCCWlGMVq8Sub0=; b=Sg9VIY847UgvABaexNBgCl29KrUnLGuaX/Gj7m2V6VpIn4uqPsny8xdkG5kiLuz02LO84b zgNT9n7dIr3u/wcNjxretxfkd3n5deLB6p2ixQ+GgLBE8CjycfWK9D6s6hQ+Dvgyh2Ilk+ 5L+HaYyaHgiWgIAg3wCV7lq9iB2gcvs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-660-0uyVDhRYMgyNYl1VAFbJhA-1; Tue, 22 Mar 2022 13:25:13 -0400 X-MC-Unique: 0uyVDhRYMgyNYl1VAFbJhA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2734E82A682; Tue, 22 Mar 2022 17:25:13 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D4A62166B2D; Tue, 22 Mar 2022 17:25:09 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 3/8] kvm: x86: SVM: use vmcb* instead of svm->vmcb where it makes sense Date: Tue, 22 Mar 2022 19:24:44 +0200 Message-Id: <20220322172449.235575-4-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This makes the code a bit shorter and cleaner. No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/nested.c | 179 ++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 85 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index d736ec6514ca..1c381c6a7b51 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -36,40 +36,43 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu = *vcpu, struct x86_exception *fault) { struct vcpu_svm *svm =3D to_svm(vcpu); + struct vmcb *vmcb =3D svm->vmcb; =20 - if (svm->vmcb->control.exit_code !=3D SVM_EXIT_NPF) { + if (vmcb->control.exit_code !=3D SVM_EXIT_NPF) { /* * TODO: track the cause of the nested page fault, and * correctly fill in the high bits of exit_info_1. */ - svm->vmcb->control.exit_code =3D SVM_EXIT_NPF; - svm->vmcb->control.exit_code_hi =3D 0; - svm->vmcb->control.exit_info_1 =3D (1ULL << 32); - svm->vmcb->control.exit_info_2 =3D fault->address; + vmcb->control.exit_code =3D SVM_EXIT_NPF; + vmcb->control.exit_code_hi =3D 0; + vmcb->control.exit_info_1 =3D (1ULL << 32); + vmcb->control.exit_info_2 =3D fault->address; } =20 - svm->vmcb->control.exit_info_1 &=3D ~0xffffffffULL; - svm->vmcb->control.exit_info_1 |=3D fault->error_code; + vmcb->control.exit_info_1 &=3D ~0xffffffffULL; + vmcb->control.exit_info_1 |=3D fault->error_code; =20 nested_svm_vmexit(svm); } =20 static void svm_inject_page_fault_nested(struct kvm_vcpu *vcpu, struct x86= _exception *fault) { - struct vcpu_svm *svm =3D to_svm(vcpu); - WARN_ON(!is_guest_mode(vcpu)); + struct vcpu_svm *svm =3D to_svm(vcpu); + struct vmcb *vmcb =3D svm->vmcb; + + WARN_ON(!is_guest_mode(vcpu)); =20 if (vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_EXCEPTION_OFFSET + PF_VECTOR) && - !svm->nested.nested_run_pending) { - svm->vmcb->control.exit_code =3D SVM_EXIT_EXCP_BASE + PF_VE= CTOR; - svm->vmcb->control.exit_code_hi =3D 0; - svm->vmcb->control.exit_info_1 =3D fault->error_code; - svm->vmcb->control.exit_info_2 =3D fault->address; - nested_svm_vmexit(svm); - } else { - kvm_inject_page_fault(vcpu, fault); - } + !svm->nested.nested_run_pending) { + vmcb->control.exit_code =3D SVM_EXIT_EXCP_BASE + PF_VECTOR; + vmcb->control.exit_code_hi =3D 0; + vmcb->control.exit_info_1 =3D fault->error_code; + vmcb->control.exit_info_2 =3D fault->address; + nested_svm_vmexit(svm); + } else { + kvm_inject_page_fault(vcpu, fault); + } } =20 static u64 nested_svm_get_tdp_pdptr(struct kvm_vcpu *vcpu, int index) @@ -533,6 +536,7 @@ void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm) static void nested_vmcb02_prepare_save(struct vcpu_svm *svm, struct vmcb *= vmcb12) { bool new_vmcb12 =3D false; + struct vmcb *vmcb02 =3D svm->nested.vmcb02.ptr; =20 nested_vmcb02_compute_g_pat(svm); =20 @@ -544,18 +548,18 @@ static void nested_vmcb02_prepare_save(struct vcpu_sv= m *svm, struct vmcb *vmcb12 } =20 if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_SEG))) { - svm->vmcb->save.es =3D vmcb12->save.es; - svm->vmcb->save.cs =3D vmcb12->save.cs; - svm->vmcb->save.ss =3D vmcb12->save.ss; - svm->vmcb->save.ds =3D vmcb12->save.ds; - svm->vmcb->save.cpl =3D vmcb12->save.cpl; - vmcb_mark_dirty(svm->vmcb, VMCB_SEG); + vmcb02->save.es =3D vmcb12->save.es; + vmcb02->save.cs =3D vmcb12->save.cs; + vmcb02->save.ss =3D vmcb12->save.ss; + vmcb02->save.ds =3D vmcb12->save.ds; + vmcb02->save.cpl =3D vmcb12->save.cpl; + vmcb_mark_dirty(vmcb02, VMCB_SEG); } =20 if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_DT))) { - svm->vmcb->save.gdtr =3D vmcb12->save.gdtr; - svm->vmcb->save.idtr =3D vmcb12->save.idtr; - vmcb_mark_dirty(svm->vmcb, VMCB_DT); + vmcb02->save.gdtr =3D vmcb12->save.gdtr; + vmcb02->save.idtr =3D vmcb12->save.idtr; + vmcb_mark_dirty(vmcb02, VMCB_DT); } =20 kvm_set_rflags(&svm->vcpu, vmcb12->save.rflags | X86_EFLAGS_FIXED); @@ -572,15 +576,15 @@ static void nested_vmcb02_prepare_save(struct vcpu_sv= m *svm, struct vmcb *vmcb12 kvm_rip_write(&svm->vcpu, vmcb12->save.rip); =20 /* In case we don't even reach vcpu_run, the fields are not updated */ - svm->vmcb->save.rax =3D vmcb12->save.rax; - svm->vmcb->save.rsp =3D vmcb12->save.rsp; - svm->vmcb->save.rip =3D vmcb12->save.rip; + vmcb02->save.rax =3D vmcb12->save.rax; + vmcb02->save.rsp =3D vmcb12->save.rsp; + vmcb02->save.rip =3D vmcb12->save.rip; =20 /* These bits will be set properly on the first execution when new_vmc12 = is true */ if (unlikely(new_vmcb12 || vmcb_is_dirty(vmcb12, VMCB_DR))) { - svm->vmcb->save.dr7 =3D svm->nested.save.dr7 | DR7_FIXED_1; + vmcb02->save.dr7 =3D svm->nested.save.dr7 | DR7_FIXED_1; svm->vcpu.arch.dr6 =3D svm->nested.save.dr6 | DR6_ACTIVE_LOW; - vmcb_mark_dirty(svm->vmcb, VMCB_DR); + vmcb_mark_dirty(vmcb02, VMCB_DR); } } =20 @@ -592,6 +596,8 @@ static void nested_vmcb02_prepare_control(struct vcpu_s= vm *svm) const u32 int_ctl_vmcb12_bits =3D V_TPR_MASK | V_IRQ_INJECTION_BITS_MASK; =20 struct kvm_vcpu *vcpu =3D &svm->vcpu; + struct vmcb *vmcb01 =3D svm->vmcb01.ptr; + struct vmcb *vmcb02 =3D svm->nested.vmcb02.ptr; =20 /* * Filled at exit: exit_code, exit_code_hi, exit_info_1, exit_info_2, @@ -605,14 +611,14 @@ static void nested_vmcb02_prepare_control(struct vcpu= _svm *svm) WARN_ON(kvm_apicv_activated(svm->vcpu.kvm)); =20 /* Copied from vmcb01. msrpm_base can be overwritten later. */ - svm->vmcb->control.nested_ctl =3D svm->vmcb01.ptr->control.nested_ctl; - svm->vmcb->control.iopm_base_pa =3D svm->vmcb01.ptr->control.iopm_base_pa; - svm->vmcb->control.msrpm_base_pa =3D svm->vmcb01.ptr->control.msrpm_base_= pa; + vmcb02->control.nested_ctl =3D vmcb01->control.nested_ctl; + vmcb02->control.iopm_base_pa =3D vmcb01->control.iopm_base_pa; + vmcb02->control.msrpm_base_pa =3D vmcb01->control.msrpm_base_pa; =20 /* Done at vmrun: asid. */ =20 /* Also overwritten later if necessary. */ - svm->vmcb->control.tlb_ctl =3D TLB_CONTROL_DO_NOTHING; + vmcb02->control.tlb_ctl =3D TLB_CONTROL_DO_NOTHING; =20 /* nested_cr3. */ if (nested_npt_enabled(svm)) @@ -623,24 +629,24 @@ static void nested_vmcb02_prepare_control(struct vcpu= _svm *svm) svm->nested.ctl.tsc_offset, svm->tsc_ratio_msr); =20 - svm->vmcb->control.tsc_offset =3D vcpu->arch.tsc_offset; + vmcb02->control.tsc_offset =3D vcpu->arch.tsc_offset; =20 if (svm->tsc_ratio_msr !=3D kvm_default_tsc_scaling_ratio) { WARN_ON(!svm->tsc_scaling_enabled); nested_svm_update_tsc_ratio_msr(vcpu); } =20 - svm->vmcb->control.int_ctl =3D + vmcb02->control.int_ctl =3D (svm->nested.ctl.int_ctl & int_ctl_vmcb12_bits) | - (svm->vmcb01.ptr->control.int_ctl & int_ctl_vmcb01_bits); + (vmcb01->control.int_ctl & int_ctl_vmcb01_bits); =20 - svm->vmcb->control.int_vector =3D svm->nested.ctl.int_vector; - svm->vmcb->control.int_state =3D svm->nested.ctl.int_state; - svm->vmcb->control.event_inj =3D svm->nested.ctl.event_inj; - svm->vmcb->control.event_inj_err =3D svm->nested.ctl.event_inj_err; + vmcb02->control.int_vector =3D svm->nested.ctl.int_vector; + vmcb02->control.int_state =3D svm->nested.ctl.int_state; + vmcb02->control.event_inj =3D svm->nested.ctl.event_inj; + vmcb02->control.event_inj_err =3D svm->nested.ctl.event_inj_err; =20 if (!nested_vmcb_needs_vls_intercept(svm)) - svm->vmcb->control.virt_ext |=3D VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK; + vmcb02->control.virt_ext |=3D VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK; =20 nested_svm_transition_tlb_flush(vcpu); =20 @@ -719,6 +725,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) struct vmcb *vmcb12; struct kvm_host_map map; u64 vmcb12_gpa; + struct vmcb *vmcb01 =3D svm->vmcb01.ptr; =20 if (!svm->nested.hsave_msr) { kvm_inject_gp(vcpu, 0); @@ -762,14 +769,14 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) * Since vmcb01 is not in use, we can use it to store some of the L1 * state. */ - svm->vmcb01.ptr->save.efer =3D vcpu->arch.efer; - svm->vmcb01.ptr->save.cr0 =3D kvm_read_cr0(vcpu); - svm->vmcb01.ptr->save.cr4 =3D vcpu->arch.cr4; - svm->vmcb01.ptr->save.rflags =3D kvm_get_rflags(vcpu); - svm->vmcb01.ptr->save.rip =3D kvm_rip_read(vcpu); + vmcb01->save.efer =3D vcpu->arch.efer; + vmcb01->save.cr0 =3D kvm_read_cr0(vcpu); + vmcb01->save.cr4 =3D vcpu->arch.cr4; + vmcb01->save.rflags =3D kvm_get_rflags(vcpu); + vmcb01->save.rip =3D kvm_rip_read(vcpu); =20 if (!npt_enabled) - svm->vmcb01.ptr->save.cr3 =3D kvm_read_cr3(vcpu); + vmcb01->save.cr3 =3D kvm_read_cr3(vcpu); =20 svm->nested.nested_run_pending =3D 1; =20 @@ -835,8 +842,9 @@ void svm_copy_vmloadsave_state(struct vmcb *to_vmcb, st= ruct vmcb *from_vmcb) int nested_svm_vmexit(struct vcpu_svm *svm) { struct kvm_vcpu *vcpu =3D &svm->vcpu; + struct vmcb *vmcb01 =3D svm->vmcb01.ptr; + struct vmcb *vmcb02 =3D svm->nested.vmcb02.ptr; struct vmcb *vmcb12; - struct vmcb *vmcb =3D svm->vmcb; struct kvm_host_map map; int rc; =20 @@ -864,36 +872,36 @@ int nested_svm_vmexit(struct vcpu_svm *svm) =20 /* Give the current vmcb to the guest */ =20 - vmcb12->save.es =3D vmcb->save.es; - vmcb12->save.cs =3D vmcb->save.cs; - vmcb12->save.ss =3D vmcb->save.ss; - vmcb12->save.ds =3D vmcb->save.ds; - vmcb12->save.gdtr =3D vmcb->save.gdtr; - vmcb12->save.idtr =3D vmcb->save.idtr; + vmcb12->save.es =3D vmcb02->save.es; + vmcb12->save.cs =3D vmcb02->save.cs; + vmcb12->save.ss =3D vmcb02->save.ss; + vmcb12->save.ds =3D vmcb02->save.ds; + vmcb12->save.gdtr =3D vmcb02->save.gdtr; + vmcb12->save.idtr =3D vmcb02->save.idtr; vmcb12->save.efer =3D svm->vcpu.arch.efer; vmcb12->save.cr0 =3D kvm_read_cr0(vcpu); vmcb12->save.cr3 =3D kvm_read_cr3(vcpu); - vmcb12->save.cr2 =3D vmcb->save.cr2; + vmcb12->save.cr2 =3D vmcb02->save.cr2; vmcb12->save.cr4 =3D svm->vcpu.arch.cr4; vmcb12->save.rflags =3D kvm_get_rflags(vcpu); vmcb12->save.rip =3D kvm_rip_read(vcpu); vmcb12->save.rsp =3D kvm_rsp_read(vcpu); vmcb12->save.rax =3D kvm_rax_read(vcpu); - vmcb12->save.dr7 =3D vmcb->save.dr7; + vmcb12->save.dr7 =3D vmcb02->save.dr7; vmcb12->save.dr6 =3D svm->vcpu.arch.dr6; - vmcb12->save.cpl =3D vmcb->save.cpl; + vmcb12->save.cpl =3D vmcb02->save.cpl; =20 - vmcb12->control.int_state =3D vmcb->control.int_state; - vmcb12->control.exit_code =3D vmcb->control.exit_code; - vmcb12->control.exit_code_hi =3D vmcb->control.exit_code_hi; - vmcb12->control.exit_info_1 =3D vmcb->control.exit_info_1; - vmcb12->control.exit_info_2 =3D vmcb->control.exit_info_2; + vmcb12->control.int_state =3D vmcb02->control.int_state; + vmcb12->control.exit_code =3D vmcb02->control.exit_code; + vmcb12->control.exit_code_hi =3D vmcb02->control.exit_code_hi; + vmcb12->control.exit_info_1 =3D vmcb02->control.exit_info_1; + vmcb12->control.exit_info_2 =3D vmcb02->control.exit_info_2; =20 if (vmcb12->control.exit_code !=3D SVM_EXIT_ERR) nested_save_pending_event_to_vmcb12(svm, vmcb12); =20 if (svm->nrips_enabled) - vmcb12->control.next_rip =3D vmcb->control.next_rip; + vmcb12->control.next_rip =3D vmcb02->control.next_rip; =20 vmcb12->control.int_ctl =3D svm->nested.ctl.int_ctl; vmcb12->control.tlb_ctl =3D svm->nested.ctl.tlb_ctl; @@ -909,12 +917,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm) * no event can be injected in L1. */ svm_set_gif(svm, false); - svm->vmcb->control.exit_int_info =3D 0; + vmcb01->control.exit_int_info =3D 0; =20 svm->vcpu.arch.tsc_offset =3D svm->vcpu.arch.l1_tsc_offset; - if (svm->vmcb->control.tsc_offset !=3D svm->vcpu.arch.tsc_offset) { - svm->vmcb->control.tsc_offset =3D svm->vcpu.arch.tsc_offset; - vmcb_mark_dirty(svm->vmcb, VMCB_INTERCEPTS); + if (vmcb01->control.tsc_offset !=3D svm->vcpu.arch.tsc_offset) { + vmcb01->control.tsc_offset =3D svm->vcpu.arch.tsc_offset; + vmcb_mark_dirty(vmcb01, VMCB_INTERCEPTS); } =20 if (svm->tsc_ratio_msr !=3D kvm_default_tsc_scaling_ratio) { @@ -928,13 +936,13 @@ int nested_svm_vmexit(struct vcpu_svm *svm) /* * Restore processor state that had been saved in vmcb01 */ - kvm_set_rflags(vcpu, svm->vmcb->save.rflags); - svm_set_efer(vcpu, svm->vmcb->save.efer); - svm_set_cr0(vcpu, svm->vmcb->save.cr0 | X86_CR0_PE); - svm_set_cr4(vcpu, svm->vmcb->save.cr4); - kvm_rax_write(vcpu, svm->vmcb->save.rax); - kvm_rsp_write(vcpu, svm->vmcb->save.rsp); - kvm_rip_write(vcpu, svm->vmcb->save.rip); + kvm_set_rflags(vcpu, vmcb01->save.rflags); + svm_set_efer(vcpu, vmcb01->save.efer); + svm_set_cr0(vcpu, vmcb01->save.cr0 | X86_CR0_PE); + svm_set_cr4(vcpu, vmcb01->save.cr4); + kvm_rax_write(vcpu, vmcb01->save.rax); + kvm_rsp_write(vcpu, vmcb01->save.rsp); + kvm_rip_write(vcpu, vmcb01->save.rip); =20 svm->vcpu.arch.dr7 =3D DR7_FIXED_1; kvm_update_dr7(&svm->vcpu); @@ -952,7 +960,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) =20 nested_svm_uninit_mmu_context(vcpu); =20 - rc =3D nested_svm_load_cr3(vcpu, svm->vmcb->save.cr3, false, true); + rc =3D nested_svm_load_cr3(vcpu, vmcb01->save.cr3, false, true); if (rc) return 1; =20 @@ -970,7 +978,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) * right now so that it an be accounted for before we execute * L1's next instruction. */ - if (unlikely(svm->vmcb->save.rflags & X86_EFLAGS_TF)) + if (unlikely(vmcb01->save.rflags & X86_EFLAGS_TF)) kvm_queue_exception(&(svm->vcpu), DB_VECTOR); =20 return 0; @@ -1183,12 +1191,13 @@ static bool nested_exit_on_exception(struct vcpu_sv= m *svm) static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm) { unsigned int nr =3D svm->vcpu.arch.exception.nr; + struct vmcb *vmcb =3D svm->vmcb; =20 - svm->vmcb->control.exit_code =3D SVM_EXIT_EXCP_BASE + nr; - svm->vmcb->control.exit_code_hi =3D 0; + vmcb->control.exit_code =3D SVM_EXIT_EXCP_BASE + nr; + vmcb->control.exit_code_hi =3D 0; =20 if (svm->vcpu.arch.exception.has_error_code) - svm->vmcb->control.exit_info_1 =3D svm->vcpu.arch.exception.error_code; + vmcb->control.exit_info_1 =3D svm->vcpu.arch.exception.error_code; =20 /* * EXITINFO2 is undefined for all exception intercepts other @@ -1196,11 +1205,11 @@ static void nested_svm_inject_exception_vmexit(stru= ct vcpu_svm *svm) */ if (nr =3D=3D PF_VECTOR) { if (svm->vcpu.arch.exception.nested_apf) - svm->vmcb->control.exit_info_2 =3D svm->vcpu.arch.apf.nested_apf_token; + vmcb->control.exit_info_2 =3D svm->vcpu.arch.apf.nested_apf_token; else if (svm->vcpu.arch.exception.has_payload) - svm->vmcb->control.exit_info_2 =3D svm->vcpu.arch.exception.payload; + vmcb->control.exit_info_2 =3D svm->vcpu.arch.exception.payload; else - svm->vmcb->control.exit_info_2 =3D svm->vcpu.arch.cr2; + vmcb->control.exit_info_2 =3D svm->vcpu.arch.cr2; } else if (nr =3D=3D DB_VECTOR) { /* See inject_pending_event. */ kvm_deliver_exception_payload(&svm->vcpu); --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5310FC433EF for ; Tue, 22 Mar 2022 17:25:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239667AbiCVR0x (ORCPT ); Tue, 22 Mar 2022 13:26:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239647AbiCVR0t (ORCPT ); Tue, 22 Mar 2022 13:26:49 -0400 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 AEC3E49FBA for ; Tue, 22 Mar 2022 10:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969920; 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=0nD0f4ohe3Iz1X7Qm4QJaPpSnCIA0gc8Jw6mHd+dPZ0=; b=L66FLmnK7VcbMKbgUwB2w0ETdmMGxMSl2/50medriy+Zo7MZDwnAfAfjQ5fC9QuWH7ypBZ MZhpq7+IBAYtPwiDuznWBuurFFdWbjBCrIVtMnFq+k6KBPcpLdybm/ny3Tr56yvp0tQmdS hdsLt2PvYu+Vve6GN76WFEOg0JXYCaU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-_r9rqOeMPvOXIsL4g5ygKg-1; Tue, 22 Mar 2022 13:25:17 -0400 X-MC-Unique: _r9rqOeMPvOXIsL4g5ygKg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1C4B802803; Tue, 22 Mar 2022 17:25:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DDB92166B2D; Tue, 22 Mar 2022 17:25:13 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 4/8] KVM: x86: SVM: fix avic spec based definitions again Date: Tue, 22 Mar 2022 19:24:45 +0200 Message-Id: <20220322172449.235575-5-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Due to wrong rebase, commit 4a204f7895878 ("KVM: SVM: Allow AVIC support on system w/ physical APIC ID = > 255") moved avic spec #defines back to avic.c. Move them back, and while at it extend AVIC_DOORBELL_PHYSICAL_ID_MASK to 12 bits as well (it will be used in nested avic) Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/svm.h | 8 +++++--- arch/x86/kvm/svm/svm.h | 11 ----------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 7eb2df5417fb..ab572d8def2b 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -222,7 +222,7 @@ struct __attribute__ ((__packed__)) vmcb_control_area { =20 =20 /* AVIC */ -#define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFF) +#define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFFULL) #define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) =20 @@ -230,9 +230,11 @@ struct __attribute__ ((__packed__)) vmcb_control_area { #define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12) #define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62) #define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63) -#define AVIC_PHYSICAL_ID_TABLE_SIZE_MASK (0xFF) +#define AVIC_PHYSICAL_ID_TABLE_SIZE_MASK (0xFFULL) =20 -#define AVIC_DOORBELL_PHYSICAL_ID_MASK (0xFF) +#define AVIC_DOORBELL_PHYSICAL_ID_MASK GENMASK_ULL(11, 0) + +#define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL =20 #define AVIC_UNACCEL_ACCESS_WRITE_MASK 1 #define AVIC_UNACCEL_ACCESS_OFFSET_MASK 0xFF0 diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index d07a5b88ea96..468f149556dd 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -577,17 +577,6 @@ extern struct kvm_x86_nested_ops svm_nested_ops; =20 /* avic.c */ =20 -#define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFF) -#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 -#define AVIC_LOGICAL_ID_ENTRY_VALID_MASK (1 << 31) - -#define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK GENMASK_ULL(11, 0) -#define AVIC_PHYSICAL_ID_ENTRY_BACKING_PAGE_MASK (0xFFFFFFFFFFULL << 12) -#define AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK (1ULL << 62) -#define AVIC_PHYSICAL_ID_ENTRY_VALID_MASK (1ULL << 63) - -#define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL - int avic_ga_log_notifier(u32 ga_tag); void avic_vm_destroy(struct kvm *kvm); int avic_vm_init(struct kvm *kvm); --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97097C433FE for ; Tue, 22 Mar 2022 17:25:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239671AbiCVR1I (ORCPT ); Tue, 22 Mar 2022 13:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239658AbiCVR1A (ORCPT ); Tue, 22 Mar 2022 13:27:00 -0400 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 AD00A4A913 for ; Tue, 22 Mar 2022 10:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969924; 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=ljE1Q1pDWFeHEafcYaJmat1sJuOoQ7xxJXxrlZIWhVE=; b=WTxzQ5dV3A6y6Gxlw6lgSnm/baOWT/lRjWRAixhalTkWXjC79HR6lYjuUPeJ7saotFUrbi SKmhgwpwjtqdMBipQ3dI1nmsGJKBMxnQfvNqgkkN4HG3yzFdXxN25Uwg4YAW6yBImb69ll jG0MW7hJrsYaywHZ+OTRcqOSyjepano= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-5yc3rfuCN3GmkPs4NLhyDA-1; Tue, 22 Mar 2022 13:25:21 -0400 X-MC-Unique: 5yc3rfuCN3GmkPs4NLhyDA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A2FD1C05B0C; Tue, 22 Mar 2022 17:25:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3557C2166B2D; Tue, 22 Mar 2022 17:25:17 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 5/8] KVM: x86: SVM: move tsc ratio definitions to svm.h Date: Tue, 22 Mar 2022 19:24:46 +0200 Message-Id: <20220322172449.235575-6-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Another piece of SVM spec which should be in the header file Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/svm.h | 6 ++++++ arch/x86/kvm/svm/svm.c | 15 +++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index ab572d8def2b..f70a5108d464 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -221,6 +221,12 @@ struct __attribute__ ((__packed__)) vmcb_control_area { #define SVM_NESTED_CTL_SEV_ES_ENABLE BIT(2) =20 =20 +#define SVM_TSC_RATIO_RSVD 0xffffff0000000000ULL +#define SVM_TSC_RATIO_MIN 0x0000000000000001ULL +#define SVM_TSC_RATIO_MAX 0x000000ffffffffffULL +#define SVM_TSC_RATIO_DEFAULT 0x0100000000ULL + + /* AVIC */ #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFFULL) #define AVIC_LOGICAL_ID_ENTRY_VALID_BIT 31 diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index e9a5c1e80889..ea3f0b2605e5 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -72,10 +72,6 @@ MODULE_DEVICE_TABLE(x86cpu, svm_cpu_id); =20 #define DEBUGCTL_RESERVED_BITS (~(0x3fULL)) =20 -#define TSC_RATIO_RSVD 0xffffff0000000000ULL -#define TSC_RATIO_MIN 0x0000000000000001ULL -#define TSC_RATIO_MAX 0x000000ffffffffffULL - static bool erratum_383_found __read_mostly; =20 u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly; @@ -87,7 +83,6 @@ u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly; static uint64_t osvw_len =3D 4, osvw_status; =20 static DEFINE_PER_CPU(u64, current_tsc_ratio); -#define TSC_RATIO_DEFAULT 0x0100000000ULL =20 static const struct svm_direct_access_msrs { u32 index; /* Index of the MSR */ @@ -483,7 +478,7 @@ static void svm_hardware_disable(void) { /* Make sure we clean up behind us */ if (tsc_scaling) - wrmsrl(MSR_AMD64_TSC_RATIO, TSC_RATIO_DEFAULT); + wrmsrl(MSR_AMD64_TSC_RATIO, SVM_TSC_RATIO_DEFAULT); =20 cpu_svm_disable(); =20 @@ -529,8 +524,8 @@ static int svm_hardware_enable(void) * Set the default value, even if we don't use TSC scaling * to avoid having stale value in the msr */ - wrmsrl(MSR_AMD64_TSC_RATIO, TSC_RATIO_DEFAULT); - __this_cpu_write(current_tsc_ratio, TSC_RATIO_DEFAULT); + wrmsrl(MSR_AMD64_TSC_RATIO, SVM_TSC_RATIO_DEFAULT); + __this_cpu_write(current_tsc_ratio, SVM_TSC_RATIO_DEFAULT); } =20 =20 @@ -2729,7 +2724,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct = msr_data *msr) break; } =20 - if (data & TSC_RATIO_RSVD) + if (data & SVM_TSC_RATIO_RSVD) return 1; =20 svm->tsc_ratio_msr =3D data; @@ -4776,7 +4771,7 @@ static __init int svm_hardware_setup(void) } else { pr_info("TSC scaling supported\n"); kvm_has_tsc_control =3D true; - kvm_max_tsc_scaling_ratio =3D TSC_RATIO_MAX; + kvm_max_tsc_scaling_ratio =3D SVM_TSC_RATIO_MAX; kvm_tsc_scaling_ratio_frac_bits =3D 32; } } --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA1DFC433F5 for ; Tue, 22 Mar 2022 17:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239722AbiCVR1Y (ORCPT ); Tue, 22 Mar 2022 13:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239676AbiCVR1A (ORCPT ); Tue, 22 Mar 2022 13:27:00 -0400 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 C678A4AE2C for ; Tue, 22 Mar 2022 10:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969926; 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=K72g0jmc7uvvumj5L9vLgtlPQocFQSwJwXDuIV0lYDs=; b=A6VPfnEfm6zXxIMQSRRfjHkiVbwWwuu0+OgnO6zlPzOOhqw0/fl/GUvaGLaZpQDN1BTBXE cCoVjiPHmRmRxVwbHEJnzc57w6t41SXgVYeTCPYvHSSfpJmUdZfdHvqZI1uztTvDjhr/xw FVw9l3TESCF1oa6UAFg+zpMhbBsgNlQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-597-iRlNsCMLPmCsGb_tl-EdUA-1; Tue, 22 Mar 2022 13:25:25 -0400 X-MC-Unique: iRlNsCMLPmCsGb_tl-EdUA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41D9B82A682; Tue, 22 Mar 2022 17:25:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2ABF2166B2D; Tue, 22 Mar 2022 17:25:20 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 6/8] kvm: x86: SVM: remove unused defines Date: Tue, 22 Mar 2022 19:24:47 +0200 Message-Id: <20220322172449.235575-7-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove some unused #defines from svm.c Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ea3f0b2605e5..fb31ed01086c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -62,14 +62,6 @@ MODULE_DEVICE_TABLE(x86cpu, svm_cpu_id); #define SEG_TYPE_LDT 2 #define SEG_TYPE_BUSY_TSS16 3 =20 -#define SVM_FEATURE_LBRV (1 << 1) -#define SVM_FEATURE_SVML (1 << 2) -#define SVM_FEATURE_TSC_RATE (1 << 4) -#define SVM_FEATURE_VMCB_CLEAN (1 << 5) -#define SVM_FEATURE_FLUSH_ASID (1 << 6) -#define SVM_FEATURE_DECODE_ASSIST (1 << 7) -#define SVM_FEATURE_PAUSE_FILTER (1 << 10) - #define DEBUGCTL_RESERVED_BITS (~(0x3fULL)) =20 static bool erratum_383_found __read_mostly; --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3C64C433EF for ; Tue, 22 Mar 2022 17:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239707AbiCVR1O (ORCPT ); Tue, 22 Mar 2022 13:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239711AbiCVR1H (ORCPT ); Tue, 22 Mar 2022 13:27:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31CBD4C422 for ; Tue, 22 Mar 2022 10:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969933; 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=q8as9H1HZf7aEv/ALL6no45LqVp0BSMxnSHwKmtFgbg=; b=guMotcHcwiDePjyHakIC3ig3AZnyFnbu6p4QS31PY+8sE0ahe/HQ9klQ9xkC1A5u70WNCe KlKVL5YPEpWiV12FLShFzJbhAQvwcJ/R47MrfmuOmrAj6eI5Kmj7RbME/RlGWv5CVeVHM1 1VL4qk+n7rG3rlpmUn6GXdvg7KdjJAk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-544-_IGqjONjPyORBbMY1V1xUw-1; Tue, 22 Mar 2022 13:25:28 -0400 X-MC-Unique: _IGqjONjPyORBbMY1V1xUw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB4F3811E78; Tue, 22 Mar 2022 17:25:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 991382166B44; Tue, 22 Mar 2022 17:25:24 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 7/8] KVM: x86: SVM: fix tsc scaling when the host doesn't support it Date: Tue, 22 Mar 2022 19:24:48 +0200 Message-Id: <20220322172449.235575-8-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It was decided that when TSC scaling is not supported, the virtual MSR_AMD64_TSC_RATIO should still have the default '1.0' value. However in this case kvm_max_tsc_scaling_ratio is not set, which breaks various assumptions. Fix this by always calculating kvm_max_tsc_scaling_ratio regardless of host support. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 7 +++---- arch/x86/kvm/x86.c | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index fb31ed01086c..acf04cf4ed2a 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4763,10 +4763,10 @@ static __init int svm_hardware_setup(void) } else { pr_info("TSC scaling supported\n"); kvm_has_tsc_control =3D true; - kvm_max_tsc_scaling_ratio =3D SVM_TSC_RATIO_MAX; - kvm_tsc_scaling_ratio_frac_bits =3D 32; } } + kvm_max_tsc_scaling_ratio =3D SVM_TSC_RATIO_MAX; + kvm_tsc_scaling_ratio_frac_bits =3D 32; =20 tsc_aux_uret_slot =3D kvm_add_user_return_msr(MSR_TSC_AUX); =20 diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 84a7500cd80c..e3a311b9ba34 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7980,12 +7980,11 @@ static __init int hardware_setup(void) if (!enable_apicv) vmx_x86_ops.sync_pir_to_irr =3D NULL; =20 - if (cpu_has_vmx_tsc_scaling()) { + if (cpu_has_vmx_tsc_scaling()) kvm_has_tsc_control =3D true; - kvm_max_tsc_scaling_ratio =3D KVM_VMX_TSC_MULTIPLIER_MAX; - kvm_tsc_scaling_ratio_frac_bits =3D 48; - } =20 + kvm_max_tsc_scaling_ratio =3D KVM_VMX_TSC_MULTIPLIER_MAX; + kvm_tsc_scaling_ratio_frac_bits =3D 48; kvm_has_bus_lock_exit =3D cpu_has_vmx_bus_lock_detection(); =20 set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ba920e537ddf..9c27239f987f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11631,10 +11631,8 @@ int kvm_arch_hardware_setup(void *opaque) u64 max =3D min(0x7fffffffULL, __scale_tsc(kvm_max_tsc_scaling_ratio, tsc_khz)); kvm_max_guest_tsc_khz =3D max; - - kvm_default_tsc_scaling_ratio =3D 1ULL << kvm_tsc_scaling_ratio_frac_bit= s; } - + kvm_default_tsc_scaling_ratio =3D 1ULL << kvm_tsc_scaling_ratio_frac_bits; kvm_init_msr_list(); return 0; } --=20 2.26.3 From nobody Mon Jun 22 14:24:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E0F3C433EF for ; Tue, 22 Mar 2022 17:25:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239694AbiCVR1S (ORCPT ); Tue, 22 Mar 2022 13:27:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239726AbiCVR1H (ORCPT ); Tue, 22 Mar 2022 13:27:07 -0400 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 9AA564C7AE for ; Tue, 22 Mar 2022 10:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647969935; 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=7I7dqYMl5+doAoV5btm6XXybkDOAVnQ7eRTvquSjCLU=; b=L3wKpIwDPUPH1pMBbdohtDUPkza4oOs/2u8Q0PShtEZ5ywWmwwSymxKajMAdr+41OpKQVg vBlVLOnqD7ibKJLwbumaGDjYz8DDR+X3Se5w4XiPJ6Yl59F23tkhOgX97vYswecD5Wd81Z wqT6+Okc64DlJiy/joJwy7WAMmTKJc0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-77-g0aVRgOeOwC64VKOor939A-1; Tue, 22 Mar 2022 13:25:32 -0400 X-MC-Unique: g0aVRgOeOwC64VKOor939A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A248C811E76; Tue, 22 Mar 2022 17:25:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EB3D2166B2D; Tue, 22 Mar 2022 17:25:28 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , Paolo Bonzini , Wanpeng Li , Borislav Petkov , Joerg Roedel , Ingo Molnar , Suravee Suthikulpanit , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Thomas Gleixner , Maxim Levitsky Subject: [PATCH 8/8] KVM: x86: SVM: remove vgif_enabled() Date: Tue, 22 Mar 2022 19:24:49 +0200 Message-Id: <20220322172449.235575-9-mlevitsk@redhat.com> In-Reply-To: <20220322172449.235575-1-mlevitsk@redhat.com> References: <20220322172449.235575-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" KVM always uses vgif when allowed, thus there is no need to query current vmcb for it Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 12 ++++++------ arch/x86/kvm/svm/svm.h | 12 ++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index acf04cf4ed2a..70fc5897f5f2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -172,7 +172,7 @@ static int vls =3D true; module_param(vls, int, 0444); =20 /* enable/disable Virtual GIF */ -static int vgif =3D true; +int vgif =3D true; module_param(vgif, int, 0444); =20 /* enable/disable LBR virtualization */ @@ -2148,7 +2148,7 @@ void svm_set_gif(struct vcpu_svm *svm, bool value) * Likewise, clear the VINTR intercept, we will set it * again while processing KVM_REQ_EVENT if needed. */ - if (vgif_enabled(svm)) + if (vgif) svm_clr_intercept(svm, INTERCEPT_STGI); if (svm_is_intercept(svm, INTERCEPT_VINTR)) svm_clear_vintr(svm); @@ -2166,7 +2166,7 @@ void svm_set_gif(struct vcpu_svm *svm, bool value) * in use, we still rely on the VINTR intercept (rather than * STGI) to detect an open interrupt window. */ - if (!vgif_enabled(svm)) + if (!vgif) svm_clear_vintr(svm); } } @@ -3502,7 +3502,7 @@ static void svm_enable_irq_window(struct kvm_vcpu *vc= pu) * enabled, the STGI interception will not occur. Enable the irq * window under the assumption that the hardware will set the GIF. */ - if (vgif_enabled(svm) || gif_set(svm)) { + if (vgif || gif_set(svm)) { /* * IRQ window is not needed when AVIC is enabled, * unless we have pending ExtINT since it cannot be injected @@ -3522,7 +3522,7 @@ static void svm_enable_nmi_window(struct kvm_vcpu *vc= pu) return; /* IRET will cause a vm exit */ =20 if (!gif_set(svm)) { - if (vgif_enabled(svm)) + if (vgif) svm_set_intercept(svm, INTERCEPT_STGI); return; /* STGI will cause a vm exit */ } @@ -4329,7 +4329,7 @@ static void svm_enable_smi_window(struct kvm_vcpu *vc= pu) struct vcpu_svm *svm =3D to_svm(vcpu); =20 if (!gif_set(svm)) { - if (vgif_enabled(svm)) + if (vgif) svm_set_intercept(svm, INTERCEPT_STGI); /* STGI will cause a vm exit */ } else { diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 468f149556dd..6a10cb4817e8 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -33,6 +33,7 @@ #define MSRPM_OFFSETS 16 extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly; extern bool npt_enabled; +extern int vgif; extern bool intercept_smi; =20 /* @@ -453,14 +454,9 @@ static inline bool svm_is_intercept(struct vcpu_svm *s= vm, int bit) return vmcb_is_intercept(&svm->vmcb->control, bit); } =20 -static inline bool vgif_enabled(struct vcpu_svm *svm) -{ - return !!(svm->vmcb->control.int_ctl & V_GIF_ENABLE_MASK); -} - static inline void enable_gif(struct vcpu_svm *svm) { - if (vgif_enabled(svm)) + if (vgif) svm->vmcb->control.int_ctl |=3D V_GIF_MASK; else svm->vcpu.arch.hflags |=3D HF_GIF_MASK; @@ -468,7 +464,7 @@ static inline void enable_gif(struct vcpu_svm *svm) =20 static inline void disable_gif(struct vcpu_svm *svm) { - if (vgif_enabled(svm)) + if (vgif) svm->vmcb->control.int_ctl &=3D ~V_GIF_MASK; else svm->vcpu.arch.hflags &=3D ~HF_GIF_MASK; @@ -476,7 +472,7 @@ static inline void disable_gif(struct vcpu_svm *svm) =20 static inline bool gif_set(struct vcpu_svm *svm) { - if (vgif_enabled(svm)) + if (vgif) return !!(svm->vmcb->control.int_ctl & V_GIF_MASK); else return !!(svm->vcpu.arch.hflags & HF_GIF_MASK); --=20 2.26.3