From nobody Tue Jun 23 17:20:52 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 B617CC433FE for ; Tue, 1 Mar 2022 13:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235175AbiCAN4c (ORCPT ); Tue, 1 Mar 2022 08:56:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235167AbiCAN43 (ORCPT ); Tue, 1 Mar 2022 08:56:29 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8A549F6F0 for ; Tue, 1 Mar 2022 05:55:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646142946; 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=OiMjjIHHeTM/gQ1C4O+yjUIrBcfp/Osrq5pxcQPrA3c=; b=AAcQ2G2G/iZrs/YZapnCuxjenxp55uA/TV+ZIZB6d93da9B3GirELjAfy6G9bdR4U2pQPv lq3t5mGX5zEuUgaWlbh3Nj2o4IJ7faxeAriUQb+eVcyIwaWpt8gHvbp6cKzUrGtpINK/uB 8f1RoGmLMrm+WEsifiHN81S9YKwiLgA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-njn-BBIVOmy3rjb8sccEhA-1; Tue, 01 Mar 2022 08:55:44 -0500 X-MC-Unique: njn-BBIVOmy3rjb8sccEhA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F5BA180473E; Tue, 1 Mar 2022 13:55:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E1811057FD2; Tue, 1 Mar 2022 13:55:38 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini , Joerg Roedel , Sean Christopherson , Thomas Gleixner , Dave Hansen , Wanpeng Li , Borislav Petkov , x86@kernel.org, Maxim Levitsky Subject: [PATCH 1/4] KVM: x86: mark synthetic SMM vmexit as SVM_EXIT_SW Date: Tue, 1 Mar 2022 15:55:23 +0200 Message-Id: <20220301135526.136554-2-mlevitsk@redhat.com> In-Reply-To: <20220301135526.136554-1-mlevitsk@redhat.com> References: <20220301135526.136554-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use a dummy unused vmexit reason to mark the 'VM exit' that is happening when kvm exits to handle SMM, which is not a real VM exit. This makes it a bit easier to read the KVM trace, and avoids other potential problems. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 7038c76fa8410..c08fd7f4f3414 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4218,7 +4218,7 @@ static int svm_enter_smm(struct kvm_vcpu *vcpu, char = *smstate) svm->vmcb->save.rsp =3D vcpu->arch.regs[VCPU_REGS_RSP]; svm->vmcb->save.rip =3D vcpu->arch.regs[VCPU_REGS_RIP]; =20 - ret =3D nested_svm_vmexit(svm); + ret =3D nested_svm_simple_vmexit(svm, SVM_EXIT_SW); if (ret) return ret; =20 --=20 2.26.3 From nobody Tue Jun 23 17:20:52 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 30F5EC433F5 for ; Tue, 1 Mar 2022 13:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235187AbiCAN4i (ORCPT ); Tue, 1 Mar 2022 08:56:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235176AbiCAN4c (ORCPT ); Tue, 1 Mar 2022 08:56:32 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 893589F6E1 for ; Tue, 1 Mar 2022 05:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646142949; 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=gSFeH1i77V/KkgawIUDjeRhR+3rBrHanlQxBcU1qMVM=; b=G5VMHrxqUDkIcxGLJZVuuccQI8SWMf0P9PnEa72SbAu+okvQ1nUqY2mFKOh/mxjRB5vKvx W0Q+QOiRjpUdCqGuAd1IURN2zAeS5QxAqwqlybMcmbraGRCKnAy8qOENUbYQgniuZChuQZ wQfOdFQ4ZAR4//dy3qvq7QpGQo/RmVo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-JLkAO0TqMSyP51vTULynBA-1; Tue, 01 Mar 2022 08:55:48 -0500 X-MC-Unique: JLkAO0TqMSyP51vTULynBA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39B8C800422; Tue, 1 Mar 2022 13:55:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98BF41057F7C; Tue, 1 Mar 2022 13:55:42 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini , Joerg Roedel , Sean Christopherson , Thomas Gleixner , Dave Hansen , Wanpeng Li , Borislav Petkov , x86@kernel.org, Maxim Levitsky Subject: [PATCH 2/4] KVM: x86: SVM: disable preemption in avic_refresh_apicv_exec_ctrl Date: Tue, 1 Mar 2022 15:55:24 +0200 Message-Id: <20220301135526.136554-3-mlevitsk@redhat.com> In-Reply-To: <20220301135526.136554-1-mlevitsk@redhat.com> References: <20220301135526.136554-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" avic_refresh_apicv_exec_ctrl is called from vcpu_enter_guest, without preemption disabled, however avic_vcpu_load, and avic_vcpu_put expect preemption to be disabled. This issue was found by lockdep. Signed-off-by: Maxim Levitsky Reported-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index aea0b13773fd3..e23159f3a62ba 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -640,12 +640,16 @@ void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vc= pu) } vmcb_mark_dirty(vmcb, VMCB_AVIC); =20 + preempt_disable(); + if (activated) avic_vcpu_load(vcpu, vcpu->cpu); else avic_vcpu_put(vcpu); =20 avic_set_pi_irte_mode(vcpu, activated); + + preempt_enable(); } =20 static void svm_ir_list_del(struct vcpu_svm *svm, struct amd_iommu_pi_data= *pi) --=20 2.26.3 From nobody Tue Jun 23 17:20:52 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 5AA3EC433F5 for ; Tue, 1 Mar 2022 13:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235203AbiCAN4p (ORCPT ); Tue, 1 Mar 2022 08:56:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235176AbiCAN4j (ORCPT ); Tue, 1 Mar 2022 08:56:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 365B2A0BCD for ; Tue, 1 Mar 2022 05:55:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646142957; 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=hAnHrd9CZ7T+EE9+uK5MAxGO2eqTA/lCT0zOhWpk6rE=; b=hoYi0TqEvF7Eg4ik9rlVYY8V4DjDMtKat2Aan/ahC/YlaIwaOdZthG1Zo2HNe+WbOU9Kkh E34heWi9vIoxaswIdIjOmQCnpeOjvcoQvbJx1dO+dRpuiyLIhrOknOVOMwphFAjcXvCWaH VeZvsDIQeN51L0JY3HaPsXtYBfsr0Sg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-mKxe7MxTO_6LRICKCVt10A-1; Tue, 01 Mar 2022 08:55:52 -0500 X-MC-Unique: mKxe7MxTO_6LRICKCVt10A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45D351091DA1; Tue, 1 Mar 2022 13:55:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id A42CB1057FDB; Tue, 1 Mar 2022 13:55:46 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini , Joerg Roedel , Sean Christopherson , Thomas Gleixner , Dave Hansen , Wanpeng Li , Borislav Petkov , x86@kernel.org, Maxim Levitsky Subject: [PATCH 3/4] KVM: x86: SVM: use vmcb01 in avic_init_vmcb Date: Tue, 1 Mar 2022 15:55:25 +0200 Message-Id: <20220301135526.136554-4-mlevitsk@redhat.com> In-Reply-To: <20220301135526.136554-1-mlevitsk@redhat.com> References: <20220301135526.136554-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Out of precation use vmcb01 when enabling host AVIC. No functional change intended. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index e23159f3a62ba..9656e192c646b 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)); --=20 2.26.3 From nobody Tue Jun 23 17:20:52 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 CD5DAC433EF for ; Tue, 1 Mar 2022 13:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235199AbiCAN4t (ORCPT ); Tue, 1 Mar 2022 08:56:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235198AbiCAN4n (ORCPT ); Tue, 1 Mar 2022 08:56:43 -0500 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 54918A0BDC for ; Tue, 1 Mar 2022 05:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646142960; 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=tI3lcF3SMMWiuDSlZvS+v6w9gqEgscSUK6B6ANT7DHI=; b=AN48ADfmUwmD38rlLYVsOIsypW05H746SYMCoSeI7hxwvYphWyL4UIPbStN4B3UAzsJ8Av BIhDu42FzJR5ESjCsiYdfhhO7cH4cM1GYzT0ZMZfN2F1VEdLFW3J+U5W/G2OjOtG0KB9Bx dnNXfS0lNU+xc78OyJSZmZL2N8wHJqo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-OW6ztaohN_q3XJ6UXAc1BQ-1; Tue, 01 Mar 2022 08:55:57 -0500 X-MC-Unique: OW6ztaohN_q3XJ6UXAc1BQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55B9C180A08B; Tue, 1 Mar 2022 13:55:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF7461057FD1; Tue, 1 Mar 2022 13:55:50 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Jim Mattson , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Vitaly Kuznetsov , Paolo Bonzini , Joerg Roedel , Sean Christopherson , Thomas Gleixner , Dave Hansen , Wanpeng Li , Borislav Petkov , x86@kernel.org, Maxim Levitsky Subject: [PATCH 4/4] KVM: x86: lapic: don't allow to set non default apic id when not using x2apic api Date: Tue, 1 Mar 2022 15:55:26 +0200 Message-Id: <20220301135526.136554-5-mlevitsk@redhat.com> In-Reply-To: <20220301135526.136554-1-mlevitsk@redhat.com> References: <20220301135526.136554-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix a loop hole in setting the apic state that didn't check if apic id =3D=3D vcpu_id when x2apic is enabled but userspace is using a older variant of the ioctl which didn't had 32 bit apic ids. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/lapic.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 80a2020c4db40..8d35f56c64020 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2618,15 +2618,14 @@ static int kvm_apic_state_fixup(struct kvm_vcpu *vc= pu, u32 *ldr =3D (u32 *)(s->regs + APIC_LDR); u64 icr; =20 - if (vcpu->kvm->arch.x2apic_format) { - if (*id !=3D vcpu->vcpu_id) - return -EINVAL; - } else { - if (set) - *id >>=3D 24; - else - *id <<=3D 24; - } + if (!vcpu->kvm->arch.x2apic_format && set) + *id >>=3D 24; + + if (*id !=3D vcpu->vcpu_id) + return -EINVAL; + + if (!vcpu->kvm->arch.x2apic_format && !set) + *id <<=3D 24; =20 /* * In x2APIC mode, the LDR is fixed and based on the id. And --=20 2.26.3