From nobody Tue Apr 28 03:55:57 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 4F5D0CCA473 for ; Mon, 6 Jun 2022 18:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231211AbiFFSIs (ORCPT ); Mon, 6 Jun 2022 14:08:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbiFFSIq (ORCPT ); Mon, 6 Jun 2022 14:08:46 -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 37D21703D1 for ; Mon, 6 Jun 2022 11:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538924; 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=SPSXt1XSzzkippZ/X9Z436U7ru2Jelf5JT0BkruxIf4=; b=XZFJkHK/R9IweCxubLW8jVvjeEJ+wLRtblD5F+CBjkMg3E0yyJQ89v/OxrB0SWGDWiQn5a V7tkNYXiTM3abWdP4c1c2+Jk99Bem+is1nyrFI1DhSMRSXUUnJqkSBwLwjkdBlvOMq/vlT yRh3RTaUC9M6IqTXVJ7o1nUGZxyT00A= 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-583-bv9FlcHRPKeBOZ_6uK9ObQ-1; Mon, 06 Jun 2022 14:08:39 -0400 X-MC-Unique: bv9FlcHRPKeBOZ_6uK9ObQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 56A19811E75; Mon, 6 Jun 2022 18:08:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id E30B11121314; Mon, 6 Jun 2022 18:08:34 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini Subject: [PATCH 1/7] KVM: x86: document AVIC/APICv inhibit reasons Date: Mon, 6 Jun 2022 21:08:23 +0300 Message-Id: <20220606180829.102503-2-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These days there are too many AVIC/APICv inhibit reasons, and it doesn't hurt to have some documentation for them. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 6cf5d77d78969..d7fb3ade44501 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1065,14 +1065,69 @@ struct kvm_x86_msr_filter { }; =20 enum kvm_apicv_inhibit { + + /********************************************************************/ + /* INHIBITs that are relevant to both Intel's APICv and AMD's AVIC. */ + /********************************************************************/ + + /* + * APIC acceleration is disabled by a module parameter + * and/or not supported in hardware. + */ APICV_INHIBIT_REASON_DISABLE, + + /* + * APIC acceleration is inhibited because AutoEOI feature is + * being used by a HyperV guest. + */ APICV_INHIBIT_REASON_HYPERV, + + /* + * APIC acceleration is inhibited because the userspace didn't yet + * enable the kernel/split irqchip. + */ + APICV_INHIBIT_REASON_ABSENT, + + /* APIC acceleration is inhibited because KVM_GUESTDBG_BLOCKIRQ + * (out of band, debug measure of blocking all interrupts on this vCPU) + * was enabled, to avoid AVIC/APICv bypassing it. + */ + APICV_INHIBIT_REASON_BLOCKIRQ, + + /******************************************************/ + /* INHIBITs that are relevant only to the AMD's AVIC. */ + /******************************************************/ + + /* + * AVIC is inhibited on a vCPU because it runs a nested guest. + * + * This is needed because unlike APICv, the peers of this vCPU + * cannot use the doorbell mechanism to signal interrupts via AVIC when + * a vCPU runs nested. + */ APICV_INHIBIT_REASON_NESTED, + + /* + * On SVM, the wait for the IRQ window is implemented with pending vIRQ, + * which cannot be injected when the AVIC is enabled, thus AVIC + * is inhibited while KVM waits for IRQ window. + */ APICV_INHIBIT_REASON_IRQWIN, + + /* + * PIT (i8254) 're-inject' mode, relies on EOI intercept, + * which AVIC doesn't support for edge triggered interrupts. + */ APICV_INHIBIT_REASON_PIT_REINJ, + + /* + * AVIC is inhibited because the guest has x2apic in its CPUID. + */ APICV_INHIBIT_REASON_X2APIC, - APICV_INHIBIT_REASON_BLOCKIRQ, - APICV_INHIBIT_REASON_ABSENT, + + /* + * AVIC is disabled because SEV doesn't support it. + */ APICV_INHIBIT_REASON_SEV, }; =20 --=20 2.26.3 From nobody Tue Apr 28 03:55:57 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 48AB4C433EF for ; Mon, 6 Jun 2022 18:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbiFFSIt (ORCPT ); Mon, 6 Jun 2022 14:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231192AbiFFSIr (ORCPT ); Mon, 6 Jun 2022 14:08:47 -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 BC989275CF for ; Mon, 6 Jun 2022 11:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538925; 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=9umq7ZLyfA//0JRA0NlxNtC/RFJORU4rQhFUvO9ESZk=; b=L+u8pxVvaHpi8yhyle7Lsy3ZepAFldOUBvnw1lgVre1x7/Sav96Ae4C1d7HYnB/fe72VAX NAzyhh5YaVKhzeQntQAbfMBxq12eUjntql6LlxgNmt4EHmQh6LtIt+vGJ/DcmNSIUjGM2B tU4LXWWhPeUEKhWxqoekI0OGrh2jQz8= 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-645-6bOGLsxEOoC4IVTutCC1Xw-1; Mon, 06 Jun 2022 14:08:42 -0400 X-MC-Unique: 6bOGLsxEOoC4IVTutCC1Xw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 23114858EED; Mon, 6 Jun 2022 18:08:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id B07C81121314; Mon, 6 Jun 2022 18:08:38 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini Subject: [PATCH 2/7] KVM: x86: inhibit APICv/AVIC when the guest and/or host changes either apic id or the apic base from their default values. Date: Mon, 6 Jun 2022 21:08:24 +0300 Message-Id: <20220606180829.102503-3-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Neither of these settings should be changed by the guest and it is a burden to support it in the acceleration code, so just inhibit this code instead. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 9 +++++++++ arch/x86/kvm/lapic.c | 27 +++++++++++++++++++++++---- arch/x86/kvm/svm/avic.c | 4 +++- arch/x86/kvm/vmx/vmx.c | 4 +++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index d7fb3ade44501..971db02e8ed86 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1094,6 +1094,15 @@ enum kvm_apicv_inhibit { */ APICV_INHIBIT_REASON_BLOCKIRQ, =20 + /* + * For simplicity, the APIC acceleration is inhibited + * first time either APIC ID or APIC base are changed by the guest + * from their reset values. + */ + APICV_INHIBIT_REASON_APIC_ID_MODIFIED, + APICV_INHIBIT_REASON_APIC_BASE_MODIFIED, + + /******************************************************/ /* INHIBITs that are relevant only to the AMD's AVIC. */ /******************************************************/ diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index e69b83708f050..a413a1d8df4c1 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2040,6 +2040,19 @@ static void apic_manage_nmi_watchdog(struct kvm_lapi= c *apic, u32 lvt0_val) } } =20 +static void kvm_lapic_xapic_id_updated(struct kvm_lapic *apic) +{ + struct kvm *kvm =3D apic->vcpu->kvm; + + if (KVM_BUG_ON(apic_x2apic_mode(apic), kvm)) + return; + + if (kvm_xapic_id(apic) =3D=3D apic->vcpu->vcpu_id) + return; + + kvm_set_apicv_inhibit(apic->vcpu->kvm, APICV_INHIBIT_REASON_APIC_ID_MODIF= IED); +} + static int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) { int ret =3D 0; @@ -2048,10 +2061,12 @@ static int kvm_lapic_reg_write(struct kvm_lapic *ap= ic, u32 reg, u32 val) =20 switch (reg) { case APIC_ID: /* Local APIC ID */ - if (!apic_x2apic_mode(apic)) + if (!apic_x2apic_mode(apic)) { kvm_apic_set_xapic_id(apic, val >> 24); - else + kvm_lapic_xapic_id_updated(apic); + } else { ret =3D 1; + } break; =20 case APIC_TASKPRI: @@ -2354,8 +2369,10 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 v= alue) MSR_IA32_APICBASE_BASE; =20 if ((value & MSR_IA32_APICBASE_ENABLE) && - apic->base_address !=3D APIC_DEFAULT_PHYS_BASE) - pr_warn_once("APIC base relocation is unsupported by KVM"); + apic->base_address !=3D APIC_DEFAULT_PHYS_BASE) { + kvm_set_apicv_inhibit(apic->vcpu->kvm, + APICV_INHIBIT_REASON_APIC_BASE_MODIFIED); + } } =20 void kvm_apic_update_apicv(struct kvm_vcpu *vcpu) @@ -2666,6 +2683,8 @@ static int kvm_apic_state_fixup(struct kvm_vcpu *vcpu, icr =3D __kvm_lapic_get_reg64(s->regs, APIC_ICR); __kvm_lapic_set_reg(s->regs, APIC_ICR2, icr >> 32); } + } else { + kvm_lapic_xapic_id_updated(vcpu->arch.apic); } =20 return 0; diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 54fe03714f8a6..8dffd67f60862 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -910,7 +910,9 @@ bool avic_check_apicv_inhibit_reasons(enum kvm_apicv_in= hibit reason) BIT(APICV_INHIBIT_REASON_PIT_REINJ) | BIT(APICV_INHIBIT_REASON_X2APIC) | BIT(APICV_INHIBIT_REASON_BLOCKIRQ) | - BIT(APICV_INHIBIT_REASON_SEV); + BIT(APICV_INHIBIT_REASON_SEV | + BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) | + BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED)); =20 return supported & BIT(reason); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index fd2e707faf2bf..48440f73c3352 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7860,7 +7860,9 @@ static bool vmx_check_apicv_inhibit_reasons(enum kvm_= apicv_inhibit reason) ulong supported =3D BIT(APICV_INHIBIT_REASON_DISABLE) | BIT(APICV_INHIBIT_REASON_ABSENT) | BIT(APICV_INHIBIT_REASON_HYPERV) | - BIT(APICV_INHIBIT_REASON_BLOCKIRQ); + BIT(APICV_INHIBIT_REASON_BLOCKIRQ) | + BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) | + BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED); =20 return supported & BIT(reason); } --=20 2.26.3 From nobody Tue Apr 28 03:55:57 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 4220AC433EF for ; Mon, 6 Jun 2022 18:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231338AbiFFSJE (ORCPT ); Mon, 6 Jun 2022 14:09:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbiFFSIz (ORCPT ); Mon, 6 Jun 2022 14:08:55 -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 81DE5168368 for ; Mon, 6 Jun 2022 11:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538929; 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=lJqqZQUOcRF2oy3vYgAuaBcdGGG+GwISZmjun1I/nOo=; b=axi7tartMROYNmsfTupJ299s2m22mC8hZANppjsDQ/SUdc1P3DEe8xXitkLySo+j2FAT25 aP5f3wCf0ZM7cetcHbWZQoT/kiXF8QvB+gLphjMfIVzIkutugLRpU94fMEY8+6qeBAMjfG Dro3Gvmb4JfjWyyydIGt1VKwjQBwdJw= 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-594-kfHbEYmWM_2mvX6QVoa8tQ-1; Mon, 06 Jun 2022 14:08:46 -0400 X-MC-Unique: kfHbEYmWM_2mvX6QVoa8tQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5B4E811E7A; Mon, 6 Jun 2022 18:08:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D4971121315; Mon, 6 Jun 2022 18:08:42 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini Subject: [PATCH 3/7] KVM: x86: SVM: remove avic's broken code that updated APIC ID Date: Mon, 6 Jun 2022 21:08:25 +0300 Message-Id: <20220606180829.102503-4-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" AVIC is now inhibited if the guest changes the apic id, and therefore this code is no longer needed. There are several ways this code was broken, including: 1. a vCPU was only allowed to change its apic id to an apic id of an existing vCPU. 2. After such change, the vCPU whose apic id entry was overwritten, could not correctly change its own apic id, because its own entry is already overwritten. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 8dffd67f60862..072e2c8cc66aa 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -508,35 +508,6 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcp= u) return ret; } =20 -static int avic_handle_apic_id_update(struct kvm_vcpu *vcpu) -{ - u64 *old, *new; - struct vcpu_svm *svm =3D to_svm(vcpu); - u32 id =3D kvm_xapic_id(vcpu->arch.apic); - - if (vcpu->vcpu_id =3D=3D id) - return 0; - - old =3D avic_get_physical_id_entry(vcpu, vcpu->vcpu_id); - new =3D avic_get_physical_id_entry(vcpu, id); - if (!new || !old) - return 1; - - /* We need to move physical_id_entry to new offset */ - *new =3D *old; - *old =3D 0ULL; - to_svm(vcpu)->avic_physical_id_cache =3D new; - - /* - * Also update the guest physical APIC ID in the logical - * APIC ID table entry if already setup the LDR. - */ - if (svm->ldr_reg) - avic_handle_ldr_update(vcpu); - - return 0; -} - static void avic_handle_dfr_update(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); @@ -555,10 +526,6 @@ static int avic_unaccel_trap_write(struct kvm_vcpu *vc= pu) AVIC_UNACCEL_ACCESS_OFFSET_MASK; =20 switch (offset) { - case APIC_ID: - if (avic_handle_apic_id_update(vcpu)) - return 0; - break; case APIC_LDR: if (avic_handle_ldr_update(vcpu)) return 0; @@ -650,8 +617,6 @@ int avic_init_vcpu(struct vcpu_svm *svm) =20 void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu) { - if (avic_handle_apic_id_update(vcpu) !=3D 0) - return; avic_handle_dfr_update(vcpu); avic_handle_ldr_update(vcpu); } --=20 2.26.3 From nobody Tue Apr 28 03:55:57 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 AF85FC433EF for ; Mon, 6 Jun 2022 18:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbiFFSJP (ORCPT ); Mon, 6 Jun 2022 14:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbiFFSI7 (ORCPT ); Mon, 6 Jun 2022 14:08:59 -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 DFB642FE71 for ; Mon, 6 Jun 2022 11:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5ouDcIYJZnuwxcggSN3JWhIbWktPsI+ueJ4oKyyKY60=; b=d+neJr2FP3uoKAsDWF0lGAPsrzHm99VahBg54sX01RG3gBrxytVRISC+a0ZOIrTVHPFs4L eN0rCzcugPIMW29iWdR9HUzJh8CbLUzcsKxc0PehrtTEG5YDjfq2LnY7rl72VJZLeWpKwS PtgmLohZMN/s7UM6HWZTNY/T0SB1tw8= 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-433-295CEvSJM7-w7nt7JRQBvg-1; Mon, 06 Jun 2022 14:08:50 -0400 X-MC-Unique: 295CEvSJM7-w7nt7JRQBvg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E56C81010368; Mon, 6 Jun 2022 18:08:49 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BDEA1121314; Mon, 6 Jun 2022 18:08:46 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini , stable@vger.kernel.org Subject: [PATCH 4/7] KVM: x86: SVM: fix avic_kick_target_vcpus_fast Date: Mon, 6 Jun 2022 21:08:26 +0300 Message-Id: <20220606180829.102503-5-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two issues in avic_kick_target_vcpus_fast 1. It is legal to issue an IPI request with APIC_DEST_NOSHORT and a physical destination of 0xFF (or 0xFFFFFFFF in case of x2apic), which must be treated as a broadcast destination. Fix this by explicitly checking for it. Also don=E2=80=99t use =E2=80=98index=E2=80=99 in this case as it gives = no new information. 2. It is legal to issue a logical IPI request to more than one target. Index field only provides index in physical id table of first such target and therefore can't be used before we are sure that only a single target was addressed. Instead, parse the ICRL/ICRH, double check that a unicast interrupt was requested, and use that info to figure out the physical id of the target vCPU. At that point there is no need to use the index field as well. In addition to fixing the above issues, also skip the call to kvm_apic_match_dest. It is possible to do this now, because now as long as AVIC is not inhibited, it is guaranteed that none of the vCPUs changed their apic id from its default value. This fixes boot of windows guest with AVIC enabled because it uses IPI with 0xFF destination and no destination shorthand. Fixes: 7223fd2d5338 ("KVM: SVM: Use target APIC ID to complete AVIC IRQs wh= en possible") Cc: stable@vger.kernel.org Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 105 ++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 36 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 072e2c8cc66aa..5d98ac575dedc 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -291,58 +291,91 @@ void avic_ring_doorbell(struct kvm_vcpu *vcpu) static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *= source, u32 icrl, u32 icrh, u32 index) { - u32 dest, apic_id; - struct kvm_vcpu *vcpu; + u32 l1_physical_id, dest; + struct kvm_vcpu *target_vcpu; int dest_mode =3D icrl & APIC_DEST_MASK; int shorthand =3D icrl & APIC_SHORT_MASK; struct kvm_svm *kvm_svm =3D to_kvm_svm(kvm); - u32 *avic_logical_id_table =3D page_address(kvm_svm->avic_logical_id_tabl= e_page); =20 if (shorthand !=3D APIC_DEST_NOSHORT) return -EINVAL; =20 - /* - * The AVIC incomplete IPI #vmexit info provides index into - * the physical APIC ID table, which can be used to derive - * guest physical APIC ID. - */ + if (apic_x2apic_mode(source)) + dest =3D icrh; + else + dest =3D GET_APIC_DEST_FIELD(icrh); + if (dest_mode =3D=3D APIC_DEST_PHYSICAL) { - apic_id =3D index; + /* broadcast destination, use slow path */ + if (apic_x2apic_mode(source) && dest =3D=3D X2APIC_BROADCAST) + return -EINVAL; + if (!apic_x2apic_mode(source) && dest =3D=3D APIC_BROADCAST) + return -EINVAL; + + l1_physical_id =3D dest; + + if (WARN_ON_ONCE(l1_physical_id !=3D index)) + return -EINVAL; + } else { - if (!apic_x2apic_mode(source)) { - /* For xAPIC logical mode, the index is for logical APIC table. */ - apic_id =3D avic_logical_id_table[index] & 0x1ff; + u32 bitmap, cluster; + int logid_index; + + if (apic_x2apic_mode(source)) { + /* 16 bit dest mask, 16 bit cluster id */ + bitmap =3D dest & 0xFFFF0000; + cluster =3D (dest >> 16) << 4; + } else if (kvm_lapic_get_reg(source, APIC_DFR) =3D=3D APIC_DFR_FLAT) { + /* 8 bit dest mask*/ + bitmap =3D dest; + cluster =3D 0; } else { - return -EINVAL; + /* 4 bit desk mask, 4 bit cluster id */ + bitmap =3D dest & 0xF; + cluster =3D (dest >> 4) << 2; } - } =20 - /* - * Assuming vcpu ID is the same as physical apic ID, - * and use it to retrieve the target vCPU. - */ - vcpu =3D kvm_get_vcpu_by_id(kvm, apic_id); - if (!vcpu) - return -EINVAL; + if (unlikely(!bitmap)) + /* guest bug: nobody to send the logical interrupt to */ + return 0; =20 - if (apic_x2apic_mode(vcpu->arch.apic)) - dest =3D icrh; - else - dest =3D GET_APIC_DEST_FIELD(icrh); + if (!is_power_of_2(bitmap)) + /* multiple logical destinations, use slow path */ + return -EINVAL; =20 - /* - * Try matching the destination APIC ID with the vCPU. - */ - if (kvm_apic_match_dest(vcpu, source, shorthand, dest, dest_mode)) { - vcpu->arch.apic->irr_pending =3D true; - svm_complete_interrupt_delivery(vcpu, - icrl & APIC_MODE_MASK, - icrl & APIC_INT_LEVELTRIG, - icrl & APIC_VECTOR_MASK); - return 0; + logid_index =3D cluster + __ffs(bitmap); + + if (apic_x2apic_mode(source)) { + l1_physical_id =3D logid_index; + } else { + u32 *avic_logical_id_table =3D + page_address(kvm_svm->avic_logical_id_table_page); + + u32 logid_entry =3D avic_logical_id_table[logid_index]; + + if (WARN_ON_ONCE(index !=3D logid_index)) + return -EINVAL; + + /* guest bug: non existing/reserved logical destination */ + if (unlikely(!(logid_entry & AVIC_LOGICAL_ID_ENTRY_VALID_MASK))) + return 0; + + l1_physical_id =3D logid_entry & + AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK; + } } =20 - return -EINVAL; + target_vcpu =3D kvm_get_vcpu_by_id(kvm, l1_physical_id); + if (unlikely(!target_vcpu)) + /* guest bug: non existing vCPU is a target of this IPI*/ + return 0; + + target_vcpu->arch.apic->irr_pending =3D true; + svm_complete_interrupt_delivery(target_vcpu, + icrl & APIC_MODE_MASK, + icrl & APIC_INT_LEVELTRIG, + icrl & APIC_VECTOR_MASK); + return 0; } =20 static void avic_kick_target_vcpus(struct kvm *kvm, struct kvm_lapic *sour= ce, --=20 2.26.3 From nobody Tue Apr 28 03:55:57 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 4F6BAC433EF for ; Mon, 6 Jun 2022 18:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbiFFSJT (ORCPT ); Mon, 6 Jun 2022 14:09:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbiFFSJB (ORCPT ); Mon, 6 Jun 2022 14:09:01 -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 2DDE57629C for ; Mon, 6 Jun 2022 11:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538940; 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=bA+N7Acl8NE8LWref9tanrAr4GkJgUhDrnzQeHMj1/E=; b=eXxks8J/I5bQD61qhSx6S0N/e1A9wECoPaKQIL7ioMsZF5gnkUnm4niGM0e6EySBxT8gX5 ievldU//epvrcsBn6JEHmWRdUb2klI9z9vLq+NFyRq63VA4vBPJ30TtBbtJhB5NOeBfyzl eDdoxVs4YCZCDQIl/tCWT8n8cZQrVHI= 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-249-dnIakPNVOlm3MpOjZ9kYLA-1; Mon, 06 Jun 2022 14:08:55 -0400 X-MC-Unique: dnIakPNVOlm3MpOjZ9kYLA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B24B929ABA3B; Mon, 6 Jun 2022 18:08:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B0551121315; Mon, 6 Jun 2022 18:08:50 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini Subject: [PATCH 5/7] KVM: x86: disable preemption while updating apicv inhibition Date: Mon, 6 Jun 2022 21:08:27 +0300 Message-Id: <20220606180829.102503-6-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently nothing prevents preemption in kvm_vcpu_update_apicv. On SVM, If the preemption happens after we update the vcpu->arch.apicv_active, the preemption itself will 'update' the inhibition since the AVIC will be first disabled on vCPU unload and then enabled, when the current task is loaded again. Then we will try to update it again, which will lead to a warning in __avic_vcpu_load, that the AVIC is already enabled. Fix this by disabling preemption in this code. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2db6f0373fa3f..9bbe6144d82ae 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9893,6 +9893,7 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) return; =20 down_read(&vcpu->kvm->arch.apicv_update_lock); + preempt_disable(); =20 activate =3D kvm_vcpu_apicv_activated(vcpu); =20 @@ -9913,6 +9914,7 @@ void kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) kvm_make_request(KVM_REQ_EVENT, vcpu); =20 out: + preempt_enable(); up_read(&vcpu->kvm->arch.apicv_update_lock); } EXPORT_SYMBOL_GPL(kvm_vcpu_update_apicv); --=20 2.26.3 From nobody Tue Apr 28 03:55:57 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 9BA88C433EF for ; Mon, 6 Jun 2022 18:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbiFFSJ0 (ORCPT ); Mon, 6 Jun 2022 14:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbiFFSJG (ORCPT ); Mon, 6 Jun 2022 14:09:06 -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 DE4D8BF105 for ; Mon, 6 Jun 2022 11:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538944; 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=JNRXKCMXNZiJcdlXlKMcIh/iU12ISsDJJO9JisSCbQU=; b=Z7K1qcVRasVkN8+I3Y2yo+Fg2hKDobvHqW6O6V1yJpY1JyNjzydJtMlQAPpoTwSIgWR4+6 776i4mb5BgZp8FABc0k7wOtjiJwcusfqqlCOLenhv07kKzVMmJe4UXbPZtrFgHG7nSHJmC BYlOsMvAkjOuoKAa3xxxqh1P4To2x6c= 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-53-vpSNwr0LNgaO7NBPnh9iUQ-1; Mon, 06 Jun 2022 14:08:58 -0400 X-MC-Unique: vpSNwr0LNgaO7NBPnh9iUQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 804DB185A79C; Mon, 6 Jun 2022 18:08:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17D611121314; Mon, 6 Jun 2022 18:08:53 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini Subject: [PATCH 6/7] KVM: x86: disable preemption around the call to kvm_arch_vcpu_{un|}blocking Date: Mon, 6 Jun 2022 21:08:28 +0300 Message-Id: <20220606180829.102503-7-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On SVM, if preemption happens right after the call to finish_rcuwait but before call to kvm_arch_vcpu_unblocking on SVM/AVIC, it itself will re-enable AVIC, and then we will try to re-enable it again in kvm_arch_vcpu_unblocking which will lead to a warning in __avic_vcpu_load. The same problem can happen if the vCPU is preempted right after the call to kvm_arch_vcpu_blocking but before the call to prepare_to_rcuwait and in this case, we will end up with AVIC enabled during sleep - Ooops. Signed-off-by: Maxim Levitsky --- virt/kvm/kvm_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5e511fcec80d7..642dba492c65d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3337,9 +3337,11 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) =20 vcpu->stat.generic.blocking =3D 1; =20 + preempt_disable(); kvm_arch_vcpu_blocking(vcpu); - prepare_to_rcuwait(wait); + preempt_enable(); + for (;;) { set_current_state(TASK_INTERRUPTIBLE); =20 @@ -3349,9 +3351,11 @@ bool kvm_vcpu_block(struct kvm_vcpu *vcpu) waited =3D true; schedule(); } - finish_rcuwait(wait); =20 + preempt_disable(); + finish_rcuwait(wait); kvm_arch_vcpu_unblocking(vcpu); + preempt_enable(); =20 vcpu->stat.generic.blocking =3D 0; =20 --=20 2.26.3 From nobody Tue Apr 28 03:55:57 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 8C84CC43334 for ; Mon, 6 Jun 2022 18:09:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbiFFSJ2 (ORCPT ); Mon, 6 Jun 2022 14:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbiFFSJK (ORCPT ); Mon, 6 Jun 2022 14:09:10 -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 9EF6D1E7158 for ; Mon, 6 Jun 2022 11:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538947; 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=OV9GEezBo0x4uuJVAwzC4RhABqDVq5710sPw72Fat3k=; b=QjaD7oehhT16H2mNYrOjSO3Q0O6QqFIjnpn1Pwf103W1szSihRz0STXUqi5LQCfKORNO7A q0pNRx6SLhP1AOMcDGN87AnSkbtQlkdMUDcZbyCFjFySvoGg1aemguIgiDkuidjWPScJuB En81aNiiPDJeRNRlxg6w4KKAs7+l2jc= 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-354-QrJ6fz12OiyNIvdRyhveDg-1; Mon, 06 Jun 2022 14:09:01 -0400 X-MC-Unique: QrJ6fz12OiyNIvdRyhveDg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4EEA21D33867; Mon, 6 Jun 2022 18:09:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAE371121314; Mon, 6 Jun 2022 18:08:57 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Wanpeng Li , Vitaly Kuznetsov , Sean Christopherson , Jim Mattson , "H. Peter Anvin" , Joerg Roedel , Dave Hansen , Ingo Molnar , Suravee Suthikulpanit , linux-kernel@vger.kernel.org, Maxim Levitsky , Thomas Gleixner , x86@kernel.org, Borislav Petkov , Paolo Bonzini Subject: [PATCH 7/7] KVM: x86: SVM: there is no need for preempt safe wrappers for avic_vcpu_load/put Date: Mon, 6 Jun 2022 21:08:29 +0300 Message-Id: <20220606180829.102503-8-mlevitsk@redhat.com> In-Reply-To: <20220606180829.102503-1-mlevitsk@redhat.com> References: <20220606180829.102503-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that these functions are always called with preemption disabled - remove them. No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 27 ++++----------------------- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/svm/svm.h | 4 ++-- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index 5d98ac575dedc..5542d8959e114 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -946,7 +946,7 @@ avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, = int cpu, bool r) return ret; } =20 -void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu) +void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { u64 entry; int h_physical_id =3D kvm_cpu_get_apicid(cpu); @@ -978,7 +978,7 @@ void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu) avic_update_iommu_vcpu_affinity(vcpu, h_physical_id, true); } =20 -void __avic_vcpu_put(struct kvm_vcpu *vcpu) +void avic_vcpu_put(struct kvm_vcpu *vcpu) { u64 entry; struct vcpu_svm *svm =3D to_svm(vcpu); @@ -997,25 +997,6 @@ void __avic_vcpu_put(struct kvm_vcpu *vcpu) WRITE_ONCE(*(svm->avic_physical_id_cache), entry); } =20 -static void avic_vcpu_load(struct kvm_vcpu *vcpu) -{ - int cpu =3D get_cpu(); - - WARN_ON(cpu !=3D vcpu->cpu); - - __avic_vcpu_load(vcpu, cpu); - - put_cpu(); -} - -static void avic_vcpu_put(struct kvm_vcpu *vcpu) -{ - preempt_disable(); - - __avic_vcpu_put(vcpu); - - preempt_enable(); -} =20 void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu) { @@ -1042,7 +1023,7 @@ void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vc= pu) vmcb_mark_dirty(vmcb, VMCB_AVIC); =20 if (activated) - avic_vcpu_load(vcpu); + avic_vcpu_load(vcpu, vcpu->cpu); else avic_vcpu_put(vcpu); =20 @@ -1075,5 +1056,5 @@ void avic_vcpu_unblocking(struct kvm_vcpu *vcpu) if (!kvm_vcpu_apicv_active(vcpu)) return; =20 - avic_vcpu_load(vcpu); + avic_vcpu_load(vcpu, vcpu->cpu); } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 4aea82f668fb1..b909769c73f03 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1439,13 +1439,13 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, in= t cpu) indirect_branch_prediction_barrier(); } if (kvm_vcpu_apicv_active(vcpu)) - __avic_vcpu_load(vcpu, cpu); + avic_vcpu_load(vcpu, cpu); } =20 static void svm_vcpu_put(struct kvm_vcpu *vcpu) { if (kvm_vcpu_apicv_active(vcpu)) - __avic_vcpu_put(vcpu); + avic_vcpu_put(vcpu); =20 svm_prepare_host_switch(vcpu); =20 diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index cd92f43437539..035020d073477 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -614,8 +614,8 @@ void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *= vmcb); int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu); int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu); int avic_init_vcpu(struct vcpu_svm *svm); -void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu); -void __avic_vcpu_put(struct kvm_vcpu *vcpu); +void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu); +void avic_vcpu_put(struct kvm_vcpu *vcpu); void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu); void avic_set_virtual_apic_mode(struct kvm_vcpu *vcpu); void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu); --=20 2.26.3