Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4643700rwb; Tue, 20 Sep 2022 17:46:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Zr3GAEiz0jUa/TJNCKTo5SPiihE2ExeTrTfyhAi7BgijXrbS8WDriKa4zWEwOp5+4ozKH X-Received: by 2002:a17:907:d91:b0:770:86d3:36e4 with SMTP id go17-20020a1709070d9100b0077086d336e4mr18099643ejc.687.1663721183645; Tue, 20 Sep 2022 17:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663721183; cv=none; d=google.com; s=arc-20160816; b=HFxbyle2auMu9hOofQ1Dh0xJDhEBb9rRwDB30489kbzBY/U+9LCP7XthqBnMIpvqwn TXExgezbieqxU1e5YlZUWaFE/sGjNhzORlPF2e3jyEp+iT3kIaksuhHWUlNBFliINhlS Psdr3/7WTC5dqyggPRzNy/RpV1OUniKCIJyQOCJfLE0M7MIFkCc61RJ+9DcMLJpRQ3DV wWY2BlMQ9Pg2RmMZuqV0oQNJq0JWBn6K7ARctGjHsw/Pz7YOb+A/mKkFStApcgMiBF0S umcWKIeK007oVNx1DZZAeva3fRB354RN2aCgbYLE8zYS2012vcaN9FOzwlqnp+HFZdL2 2M6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=v7YHpsXihO1IGC0K/PKlA8GEkrI37lPnwhd36LF7pVk=; b=oX6d7kU2GAkBEsH283MqXUtbHJWkSSQ11K5TjX2k4ay2iTL+JaZuvZxg9OIMWD6qjz gdERSSAigiEQqNww8va1cjS2L6Vo+IrLI4V9c9jR9iUu3e9pDd25HeP3nJdbgPkMbUkw vj6yfRTgFQfUXLPEd2Pty8A6RtQQgRihDVjZXai5OqI1J7zgP7nwBtbeXD1WRmJeuoq0 KRS9Fs6YCIymZfa9ksJ2EcPga+DtpomIHDcG24m41+C4TQdjBEROdMODUiaINUw01XG7 F/8dry7so63WTYJUO0Fw6zA4QkYfVBK3inCkRq+zZ4mPwY3xgP47x3fC/9B/I4RVTioq DMjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=T4Pq1vwh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx2-20020a05640222a200b0045251875154si962577edb.531.2022.09.20.17.45.58; Tue, 20 Sep 2022 17:46:23 -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=@google.com header.s=20210112 header.b=T4Pq1vwh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbiIUAc5 (ORCPT + 99 others); Tue, 20 Sep 2022 20:32:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbiIUAcw (ORCPT ); Tue, 20 Sep 2022 20:32:52 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0E53760F1 for ; Tue, 20 Sep 2022 17:32:49 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id g15-20020a17090a708f00b00203a68c9acaso2047643pjk.8 for ; Tue, 20 Sep 2022 17:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date; bh=v7YHpsXihO1IGC0K/PKlA8GEkrI37lPnwhd36LF7pVk=; b=T4Pq1vwhu58JKk9S6MS0EL1IJhE9KPvx6f3kP5213oRycLCnCPGalTsox3aAjnkBY+ bvrARzyrfMnXa376luKHrUSUC3r41vDBz/363U0/GCT1m+sgrmqVasY3fcU9OUU8ZnQr fGLzK1tbOFeQ4wKJzJP+i1caYDQsEDEbwf5IEBhf8mxzB0P/PeEP0jzwrUt5tUlgn1vs khV0dI6DS92WUbMb+SK3UCu6WG61MT61dVs3It8NhZZ7b/6/vq2QNm9LhdsajCmXKYhu RM5VBfvag1jIjc/ktzcq5owOd+kKUM+xzeu/Nh4l3/G9+HsymuEMfqdrfo6zFFuJfavG EM4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date; bh=v7YHpsXihO1IGC0K/PKlA8GEkrI37lPnwhd36LF7pVk=; b=6JgYD2QZrkFLSZbys4LsLqhG5jVVLeGLVJzhpWOaWMyFNraheYlu+3Lk3d8FEgPpLj TdIas5eM8OBYsrdlbuXQqhUMmLxpZMQ/IFIu7XRolvpnBv717vIZNrO5AlSiAZQ3O78y gap6JzOrOID8sa90ABPJ7FDz45ZFR8JTk8j6BpS5GHLfebgWPU5ptkz7jI5wkPPZwZek Aibe2CTXDp5qsiBnkXOwYouZje5pZcdpG05qavsVFvXCKOHCzLiFay3qibKWxvQPlvKr iLr0v5Ht0gwW0hF2RTW7K5e50fFShcqlN14uz878nm3m0HIs0oXJ/R/qi7iaceSa2zvW k9IA== X-Gm-Message-State: ACrzQf1IOAp926E75FW3pRVxEOZnpcopNMT7rm30WP/MdzhiU+8UOAI/ aFVWCmVQxs2VbzEX/kdwooQ14ZRr1+g= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:f644:b0:172:b074:d1f5 with SMTP id m4-20020a170902f64400b00172b074d1f5mr2177656plg.29.1663720369344; Tue, 20 Sep 2022 17:32:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 21 Sep 2022 00:31:50 +0000 In-Reply-To: <20220921003201.1441511-1-seanjc@google.com> Mime-Version: 1.0 References: <20220921003201.1441511-1-seanjc@google.com> X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog Message-ID: <20220921003201.1441511-2-seanjc@google.com> Subject: [PATCH v4 01/12] KVM: x86: make vendor code check for all nested events From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Maxim Levitsky Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 From: Paolo Bonzini Interrupts, NMIs etc. sent while in guest mode are already handled properly by the *_interrupt_allowed callbacks, but other events can cause a vCPU to be runnable that are specific to guest mode. In the case of VMX there are two, the preemption timer and the monitor trap. The VMX preemption timer is already special cased via the hv_timer_pending callback, but the purpose of the callback can be easily extended to MTF or in fact any other event that can occur only in guest mode. Rename the callback and add an MTF check; kvm_arch_vcpu_runnable() now can return true if an MTF is pending, without relying on kvm_vcpu_running()'s call to kvm_check_nested_events(). Until that call is removed, however, the patch introduces no functional change. Reviewed-by: Maxim Levitsky Signed-off-by: Paolo Bonzini Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/vmx/nested.c | 8 +++++++- arch/x86/kvm/x86.c | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index ee940c4c0f64..c03590d1c5e1 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1649,7 +1649,7 @@ struct kvm_x86_nested_ops { bool (*is_exception_vmexit)(struct kvm_vcpu *vcpu, u8 vector, u32 error_code); 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 4da0558943ce..85318d803f4f 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3929,6 +3929,12 @@ 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) || + to_vmx(vcpu)->nested.mtf_pending; +} + /* * Per the Intel SDM's table "Priority Among Concurrent Events", with minor * edits to fill in missing examples, e.g. #DB due to split-lock accesses, @@ -6971,7 +6977,7 @@ struct kvm_x86_nested_ops vmx_nested_ops = { .leave_nested = vmx_leave_nested, .is_exception_vmexit = nested_vmx_is_exception_vmexit, .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 5b8328cb6c14..e1a25e46dbf7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9966,8 +9966,8 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu, } 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(kvm_is_exception_pending(vcpu)); @@ -12792,8 +12792,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; if (kvm_xen_has_pending_events(vcpu)) -- 2.37.3.968.ga6b4b080e4-goog