Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1026445rwb; Thu, 11 Aug 2022 14:27:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR47QeiEB73vOz+N9Lundw1NZMXRqbhGUEpj6cCh0PUfuOCEQcyL6Js+UE3SOlTqdMxh5HR1 X-Received: by 2002:a17:90a:a401:b0:1f2:19a0:2874 with SMTP id y1-20020a17090aa40100b001f219a02874mr10586432pjp.146.1660253255990; Thu, 11 Aug 2022 14:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660253255; cv=none; d=google.com; s=arc-20160816; b=dhh1xVejG8p1iRqcGKcFrf28zD9a6N928vjuZ7wla16auW6LBaHEcIOQcZq2SqKQ7u 8ZtW24mx2/pabtqOj06fWxL3V4Ya8Ta6XJ4hc5aMJ6fybDzmMzo5bzZiIxJg73s21HDt pFxkbKb+jozWlaQcwAvgFeLwCqGdTg3vXT3sZBAhCVXMHqOSLlAfvJfjFhcwSdtsUVAN w8Mq9mOGaFUyjbi7fyGRjYpHWLcD+ISsc2PmCxLZo5FUD3krYagS8m8EbR6kVpdhYYkq IpYpXvg9i1rLqV6Znkpxq+JCRxyDn0w8Kr7RfrkZbwqTgPCbz+BG0U/8JF62zPvKHbfK /Kow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K+7Clrf+ZaklLBV7mgCu2JZrobw4R6ISnHeNUw2I+2o=; b=OE5y3me5CXhOBEMnk2FOE35aV0Xrre/jXJqEzQL0RFHU6NQEyt4UPVNRXgZiLzGfuJ pdeqHmqtIZKthP3odkf6uQj5L09zqQdZIcDy7xX3bUubh5nurlrnVfwUGc9oLy16DQIY 0UuesJd3vKY3sgQ9SP2nUhVFZXX9I49TBiUUIa/GacoyN3m+esnrQAer0daDsRhDx3GO 2Q1zrajTsrRDKoXclPHGMG4jA/bPOwgrG/ynlNe7QVzfRGt2wTtgecP35f84uILc5YZM BUcg3XygQKjTPz8o4J9iH9xq3fNE/I8RcGx+zidrZgLxF7JPAyj3Jk7FIeRf36P0iBfH 6LfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Y/SPD3J7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a170902d88f00b0016efb38cf39si269616plz.141.2022.08.11.14.27.21; Thu, 11 Aug 2022 14:27:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Y/SPD3J7"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230422AbiHKVGm (ORCPT + 99 others); Thu, 11 Aug 2022 17:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236348AbiHKVGO (ORCPT ); Thu, 11 Aug 2022 17:06:14 -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 9E43273301 for ; Thu, 11 Aug 2022 14:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660251971; 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=K+7Clrf+ZaklLBV7mgCu2JZrobw4R6ISnHeNUw2I+2o=; b=Y/SPD3J74kl/JmHmeUanhAS0HCUuR+f9fym7Qn8oPZuC/H4yERCW7TQCMovq1OtpsjsFAt 5ZnUDP7cPMCNjmggydvYIyfl1BSADCtgMkxpum2Zt4u1qaOZ6QGlW0/AS59TwNnxTKOGL9 IQmUdlS2qHvBTc4qM7LukDx5VC8NuEM= 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-418-R3OsheUPPPSeAR4rpjP1_A-1; Thu, 11 Aug 2022 17:06:08 -0400 X-MC-Unique: R3OsheUPPPSeAR4rpjP1_A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D441B943202; Thu, 11 Aug 2022 21:06:07 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE2DB403343; Thu, 11 Aug 2022 21:06:07 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, mlevitsk@redhat.com, vkuznets@redhat.com Subject: [PATCH v2 8/9] KVM: x86: lapic does not have to process INIT if it is blocked Date: Thu, 11 Aug 2022 17:06:04 -0400 Message-Id: <20220811210605.402337-9-pbonzini@redhat.com> In-Reply-To: <20220811210605.402337-1-pbonzini@redhat.com> References: <20220811210605.402337-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Do not return true from kvm_apic_has_events, and consequently from kvm_vcpu_has_events, if the vCPU is not going to process an INIT. Signed-off-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/i8259.c | 2 +- arch/x86/kvm/lapic.h | 2 +- arch/x86/kvm/x86.c | 5 +++++ arch/x86/kvm/x86.h | 5 ----- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 293ff678fff5..1ce4ebc41118 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2042,6 +2042,7 @@ void __user *__x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size); bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu); bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu); +bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu); bool kvm_intr_is_single_vcpu(struct kvm *kvm, struct kvm_lapic_irq *irq, struct kvm_vcpu **dest_vcpu); diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index e1bb6218bb96..177555eea54e 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -29,9 +29,9 @@ #include #include #include -#include "irq.h" +#include -#include +#include "irq.h" #include "trace.h" #define pr_pic_unimpl(fmt, ...) \ diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 117a46df5cc1..12577ddccdfc 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -225,7 +225,7 @@ static inline bool kvm_vcpu_apicv_active(struct kvm_vcpu *vcpu) static inline bool kvm_apic_has_events(struct kvm_vcpu *vcpu) { - return lapic_in_kernel(vcpu) && vcpu->arch.apic->pending_events; + return lapic_in_kernel(vcpu) && vcpu->arch.apic->pending_events && !kvm_vcpu_latch_init(vcpu); } static inline bool kvm_lowest_prio_delivery(struct kvm_lapic_irq *irq) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0f9f24793b8a..5e9358ea112b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12529,6 +12529,11 @@ static inline bool kvm_guest_apic_has_interrupt(struct kvm_vcpu *vcpu) static_call(kvm_x86_guest_apic_has_interrupt)(vcpu)); } +bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu) +{ + return is_smm(vcpu) || static_call(kvm_x86_apic_init_signal_blocked)(vcpu); +} + static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) { if (!list_empty_careful(&vcpu->async_pf.done)) diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 1926d2cb8e79..c333e7cf933a 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -267,11 +267,6 @@ static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk) return !(kvm->arch.disabled_quirks & quirk); } -static inline bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu) -{ - return is_smm(vcpu) || static_call(kvm_x86_apic_init_signal_blocked)(vcpu); -} - void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip); u64 get_kvmclock_ns(struct kvm *kvm); -- 2.31.1