Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4785899ioa; Wed, 27 Apr 2022 11:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPaX6EyXkPlcq27tUaIXTaHqpzljTQCm7yOiD19JR69z7w6SKi0gIa2AqbXG4a2Tja/ozR X-Received: by 2002:a05:6638:2411:b0:32a:cd11:d04d with SMTP id z17-20020a056638241100b0032acd11d04dmr9546761jat.70.1651082690412; Wed, 27 Apr 2022 11:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651082690; cv=none; d=google.com; s=arc-20160816; b=ez86i+5vC4B1BtAPKkiJQUvIyWr5c3aCKpNhE+aVgHqFFDxTyYJZ9dwMPXXhHgAdSm rQEDc3Qvj99xOGMcSoRjcU+pzwEL6SMq3XSD74fibXtr8M4P983H+QxkpzBN79yrVhWU abm5xudRE4le5XGcO8Nf3uedi6RS6sZZMyq9r2Q8KuZylWQbr0OGlbh/QW4xty/m5JlY cDLn7mAB/wrZghv5K4Ltn7VUAFdANYEfjuzAbvN2J/rl9kgg2Q6beMnFqs6IAWvDUCjd D69mwCfqPr/uA8+MWdOOjWCpyq69HtTRnL9A+eQO/dgAVdTzcuQun56V5/WP//enQO0k g4WA== 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=FCEYz9iiBoLYp3MC39QvQcLFQE/JiMBJg4nT2bv7piQ=; b=s7WYujEbRhxiVt1PNTCCcb6O8fH2Zr9unWvVhQR8MOywWqVvsQxLIuC/FDMXbYGrLJ m1pfk8SEQhL5fA7eSXQ2WnXrVGX72DrlBWxonY6KcC5qDeeQ5ntxVktP74/78fb43DwR DlxeJJfgnZ3EnbEx8dktz2acuBESZNXAzMPcvzZFdptnYOjClnWL6NZwywV9rXxtHswG u5A9RXwf9/MgT4/mm84w3WAKIFQbqrbj6mCj61KQAsaAnEROapuC1jiKWBf1XIjf/1ha os1+0RMMdGWOU8Cut4+dsoVh48YN5DqaGzTcYBEREOIAo5W+PuVWvVJZ7Zjczhv33sSY wrVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NFdJsML1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a7-20020a92c547000000b002c8687c8f9dsi1316232ilj.48.2022.04.27.11.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 11:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NFdJsML1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EC41E5A16D; Wed, 27 Apr 2022 10:38:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244216AbiD0RlW (ORCPT + 99 others); Wed, 27 Apr 2022 13:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230371AbiD0RlO (ORCPT ); Wed, 27 Apr 2022 13:41: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 0D07042483 for ; Wed, 27 Apr 2022 10:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651081081; 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=FCEYz9iiBoLYp3MC39QvQcLFQE/JiMBJg4nT2bv7piQ=; b=NFdJsML1PmJL7WEcL3cTUeBWaFbUJGAemaa9/Fzv9VENnccz5RvaNAzBPJyTyEQiXCVFT5 VNZwS42RkyOgQipjJLYqhpJzrCeTN7QQOLJwNfkEzbB0YkGgQNZ0TjLasAoFK7mDRh9gsv VbBlcNP3jNbllCpGFuQV7npDkrqXoqM= 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-442-SPR1-pTnOS-M4R1bFzKV9Q-1; Wed, 27 Apr 2022 13:37:59 -0400 X-MC-Unique: SPR1-pTnOS-M4R1bFzKV9Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E1AD101AA46; Wed, 27 Apr 2022 17:37:59 +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 163A5407DEC3; Wed, 27 Apr 2022 17:37:59 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: mlevitsk@redhat.com, seanjc@google.com, stable@vger.kernel.org Subject: [PATCH 1/3] KVM: x86: make vendor code check for all nested events Date: Wed, 27 Apr 2022 13:37:56 -0400 Message-Id: <20220427173758.517087-2-pbonzini@redhat.com> In-Reply-To: <20220427173758.517087-1-pbonzini@redhat.com> References: <20220427173758.517087-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_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 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) +{ + 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)) return true; return false; -- 2.31.1