Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4908529ioa; Wed, 27 Apr 2022 14:05:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykSrRg5vmJgykVGSCXoKOh1b+u/+iOpvRLOKEbQG5FNO9DnjkaQaC+XLlQ2dE7WcmUSffW X-Received: by 2002:a17:907:6ea4:b0:6f3:c09a:e97f with SMTP id sh36-20020a1709076ea400b006f3c09ae97fmr6090141ejc.18.1651093530197; Wed, 27 Apr 2022 14:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651093530; cv=none; d=google.com; s=arc-20160816; b=XRv9RZIMBn5Gvtia/49NMdVsxboMgJsHC1+vtd18fJks2q7RNVofQu1nNjTE0pdRF4 hp08gg6TvUSWcuokFO0o44o808lZGJf8Zjt/1NzLM0RY8fp3BbJF+UoW29R4A2pHRj58 rADoBclRb+gBXqTsIsEmIUtVkW7WiZpkG57/ifQy1pZoiBOfOU2E4T/QNrjO8ovBovY0 ZvFRnlFJcc8dUItxN/Cr54g1uel0arOUXyqjUY5Zphr9/eyWYw6DgWN5TilB0nLmF/f6 +ThX4vo0t8VvSaxAwzlPcK+l1CyHuqCHnpuxau+7E//JwOOoHZGpFr04/i7/puTN0cBP 5nlg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=gFMPjJE+QXYf1X/XGRpB326TaYnBoulTgNBrURc+les=; b=DjL4cZKZncVNi0wYUEG4DZdbW27OzrIzMQsoONvGRQUKYU34VQ4rxkxg8R33g6bZuR kGPtl+UJwUmrVNAx1ORlHvJeFZvIrj84rEwhm5MigmoyaDavXr41M9DH4EywOUgTdQe0 k0jUmnXFQN+NJ36nQbszOrJ90JCkfu/HNEK03wMl2EPOUL1rDesyggwnWF0flcr+IGFT hY+F1bHckoyxEreBExx1CLXD1Hgnesna/x227nxixApmRifxQ0eMNYnvoadHNeeZREfk SAzDPcna40fctSWknIAVGMPu6WsT3nNcDaIB4sVIpXyORYBDNbG+0BJHCQQ/Euf/gt0y oJdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TgDHGE8B; 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 7-20020a170906208700b006df76385ee7si2048476ejq.903.2022.04.27.14.05.05; Wed, 27 Apr 2022 14:05:30 -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=TgDHGE8B; 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 S229769AbiD0UoV (ORCPT + 99 others); Wed, 27 Apr 2022 16:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbiD0UoN (ORCPT ); Wed, 27 Apr 2022 16:44:13 -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 79786273B for ; Wed, 27 Apr 2022 13:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651092060; 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=gFMPjJE+QXYf1X/XGRpB326TaYnBoulTgNBrURc+les=; b=TgDHGE8BAvvJd18m/qT6QBOc1sOhsUvFOckY8BQ1cVkfyQepU0hhtlLo0eSsy56Vi1+pu2 Z1ZCSxT12LgpoJb2Hzc/jGLMI14jVOmhvRCMBiOrHPAMRUF8CNFkTTpat4JmGdBL3SO9hM ho5kA3dODb0FflM675OnRD3hSi2X9Fk= 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-621-mWbQvKmbN8GaGizkGLS-GA-1; Wed, 27 Apr 2022 16:40:57 -0400 X-MC-Unique: mWbQvKmbN8GaGizkGLS-GA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0C409381D8A1; Wed, 27 Apr 2022 20:40:56 +0000 (UTC) Received: from starship (unknown [10.40.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8939400E436; Wed, 27 Apr 2022 20:40:54 +0000 (UTC) Message-ID: Subject: Re: [PATCH 1/3] KVM: x86: make vendor code check for all nested events From: Maxim Levitsky To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, stable@vger.kernel.org Date: Wed, 27 Apr 2022 23:40:53 +0300 In-Reply-To: <20220427173758.517087-2-pbonzini@redhat.com> References: <20220427173758.517087-1-pbonzini@redhat.com> <20220427173758.517087-2-pbonzini@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2022-04-27 at 13:37 -0400, Paolo Bonzini wrote: > Right now, the VMX preemption timer is special cased via the > hv_timer_pending, but the purpose of the callback can be easily > extended to observing any event that can occur only in non-root > mode. Interrupts, NMIs etc. are already handled properly by > the *_interrupt_allowed callbacks, so what is missing is only > MTF. Check it in the newly-renamed callback, so that > kvm_vcpu_running's call to kvm_check_nested_events > becomes redundant. > > Cc: stable@vger.kernel.org > Reported-by: Maxim Levitsky > Signed-off-by: Paolo Bonzini > --- > arch/x86/include/asm/kvm_host.h | 2 +- > arch/x86/kvm/vmx/nested.c | 7 ++++++- > arch/x86/kvm/x86.c | 8 ++++---- > 3 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 4ff36610af6a..e2e4f60159e9 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1504,7 +1504,7 @@ struct kvm_x86_ops { > struct kvm_x86_nested_ops { > void (*leave_nested)(struct kvm_vcpu *vcpu); > int (*check_events)(struct kvm_vcpu *vcpu); > - bool (*hv_timer_pending)(struct kvm_vcpu *vcpu); > + bool (*has_events)(struct kvm_vcpu *vcpu); > void (*triple_fault)(struct kvm_vcpu *vcpu); > int (*get_state)(struct kvm_vcpu *vcpu, > struct kvm_nested_state __user *user_kvm_nested_state, > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > index 856c87563883..54672025c3a1 100644 > --- a/arch/x86/kvm/vmx/nested.c > +++ b/arch/x86/kvm/vmx/nested.c > @@ -3857,6 +3857,11 @@ static bool nested_vmx_preemption_timer_pending(struct kvm_vcpu *vcpu) > to_vmx(vcpu)->nested.preemption_timer_expired; > } > > +static bool vmx_has_nested_events(struct kvm_vcpu *vcpu) > +{ Typo: needs struct vcpu_vmx *vmx = to_vmx(vcpu); > + return nested_vmx_preemption_timer_pending(vcpu) || vmx->nested.mtf_pending; > +} > + > static int vmx_check_nested_events(struct kvm_vcpu *vcpu) > { > struct vcpu_vmx *vmx = to_vmx(vcpu); > @@ -6809,7 +6814,7 @@ __init int nested_vmx_hardware_setup(int (*exit_handlers[])(struct kvm_vcpu *)) > struct kvm_x86_nested_ops vmx_nested_ops = { > .leave_nested = vmx_leave_nested, > .check_events = vmx_check_nested_events, > - .hv_timer_pending = nested_vmx_preemption_timer_pending, > + .has_events = vmx_has_nested_events, > .triple_fault = nested_vmx_triple_fault, > .get_state = vmx_get_nested_state, > .set_state = vmx_set_nested_state, > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index a6ab19afc638..0e73607b02bd 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -9471,8 +9471,8 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit) > } > > if (is_guest_mode(vcpu) && > - kvm_x86_ops.nested_ops->hv_timer_pending && > - kvm_x86_ops.nested_ops->hv_timer_pending(vcpu)) > + kvm_x86_ops.nested_ops->has_events && > + kvm_x86_ops.nested_ops->has_events(vcpu)) > *req_immediate_exit = true; > > WARN_ON(vcpu->arch.exception.pending); > @@ -12183,8 +12183,8 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) > return true; > > if (is_guest_mode(vcpu) && > - kvm_x86_ops.nested_ops->hv_timer_pending && > - kvm_x86_ops.nested_ops->hv_timer_pending(vcpu)) > + kvm_x86_ops.nested_ops->has_events && > + kvm_x86_ops.nested_ops->has_events(vcpu)) Nitpick: Won't it make sense to use conditional static call here instead? > return true; > > return false; Besides nitpicks, Reviewed-by: Maxim Levitsky Wasn't able to test on my intel laptop, I am getting out of sudden in qemu: 'cpuid_data is full, no space for cpuid(eax:0x8000001d,ecx:0x3e)' I will investigate tomorrow. Best regards, Maxim Levitsky