Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1843779iog; Tue, 14 Jun 2022 14:51:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t5vEN3QYXt1R3olQdOHGSB9f1vPt4PWE/q25wiSvGT/8LsX77UJC40+j17BgAbIhYmxYp9 X-Received: by 2002:a05:6402:5c9:b0:420:aac6:257b with SMTP id n9-20020a05640205c900b00420aac6257bmr8745528edx.128.1655243479620; Tue, 14 Jun 2022 14:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655243479; cv=none; d=google.com; s=arc-20160816; b=tLjEXX14HTIypF7YNjt677intzgE6hgfHkYYKPlG5TllAUZP764LGhhOIHm2/0PivT lw7nzMPYCWDiuY3P0O8E+RHVCd1IHItYwtMeBpFNTu1+W7OO0JmMwiYsIRK0IrmWPjYP e64sUOgzWTHPm6/2+v6dKjteuN8LgkU/1IblhlYtYonGtmeGGiKcCXeJuoOq5waEzSlt JIvY1kDLIu3d4OiFYKPCKmG8d+wo/TZshV7Tbovc1GVe2EvZQNOzuYLCyi2UV1XuMRK0 cFQQudid7aWr/CD2kLapSWnXr/ndpQC3fNDqxER8u2ZZR2e6Kc9flhCtNCO7vFfASIly l+Lg== 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:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=/TuCx+mMC/wWO+wCOMNM3bKKbwcesvJBIffjbKO56Bw=; b=hvrs89LTA6jJMQGpbO0G8ikbQCEUjz/I5Aph5bYCl78uLs4J2OrXYg+9HxWSMt2u7C 9gKoBRBuBD+PPgiopc+5g03Jn32RHXHR6CjiT8NLHQf2J1VmzgPe81kLy4C3DNVLe9Ma 4qsseHq9PJBCvlWQ06GCLj+qngeE5s93QTZ1PKxlYi/KdMhiWahh1Ar63lqxfiwWbasm lBjJzCLseTwJQ8PpbcPo7iS+WABrS1mV46fnsC3YQk+qOoYNLJ4oEcNSlzdtGL5wwgTz Nzr3EvZNWmmqBxPe1k64rWIABVzaRvADlmCldwf7LoL4JKOO0MKMy2TSmtFw7y5GiCta IXgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EXnkADu6; 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 k26-20020aa7c05a000000b0043139d41054si12038888edo.381.2022.06.14.14.50.51; Tue, 14 Jun 2022 14:51:19 -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=EXnkADu6; 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 S1357829AbiFNUse (ORCPT + 99 others); Tue, 14 Jun 2022 16:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345122AbiFNUr5 (ORCPT ); Tue, 14 Jun 2022 16:47:57 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3D96245B4 for ; Tue, 14 Jun 2022 13:47:53 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id z186-20020a6233c3000000b00510a6bc2864so4249534pfz.10 for ; Tue, 14 Jun 2022 13:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=/TuCx+mMC/wWO+wCOMNM3bKKbwcesvJBIffjbKO56Bw=; b=EXnkADu6RTXV+ib1jbxWSMLKVki7PKLtpXvmbrKGr1wxeZWUrsr61IsHWiwHEf0pfg qQZ3wjYx3pdYZQgdg3r+72YXMx7RcUwoMH3KcXd6ehSu5fKAu8tA8PfYyqlRowpbk0gg cWQ6geMtAhCjmdrTsw1XkaTXddSWFsOhm7BBj0Q6afoWf9dfCVGVrn9bUYCljrZLbMZt 0QzEhPK0g13S4RBTn3zN1PoijTNol+n0QJmJKuE/qhvi41OZ7AUZuaj6TQZF8ggwlGPO 6hOIufOCh/p2Vzffj9QPxCzA+r2W5rLEb63J7eMK39NUsXaL+PQJsIdItwEyz/zg04mN BF1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=/TuCx+mMC/wWO+wCOMNM3bKKbwcesvJBIffjbKO56Bw=; b=6K/iNQXSLMF1pUkyfHUU5aMmOz4V1GqSaUsBVg8+h7plnG8Du9c5LJGt0QAIEEhVRe neq4sehKZxseymEkGQG3ViQKd5J9yhhlHulfNUfF6JWW6biRo+owtekzfVURdS7O34ub hPT0xoqKRBBryjNyra/949oWM7qM8Yk4q7KZUf57uZi4gRuKy3m132DM6BVpaIMT5biz jxJ1vpicYN5Yp4oN4//C+49JAsYEE+PpOriXb4c3vJZ+w/S7xUQFpuznQlsYel2gUukw T2jrXwixW7cH1zMyJ5Z/MESMkNSHydFz++TEIt0hHSliIMDhCLJUYvsNsIkbFySjoLGb M9Kg== X-Gm-Message-State: AOAM531wWuSiDqaPvaFXztYt6zKG3VN6SUQFZBcFpJEQJmeiDLUV1q7L OcqZO7TGWxH+VC4vvcvA6EiBYY6ANwk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:aa7:9f84:0:b0:51b:b64d:fc69 with SMTP id z4-20020aa79f84000000b0051bb64dfc69mr6543168pfr.7.1655239672654; Tue, 14 Jun 2022 13:47:52 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:47:18 +0000 In-Reply-To: <20220614204730.3359543-1-seanjc@google.com> Message-Id: <20220614204730.3359543-10-seanjc@google.com> Mime-Version: 1.0 References: <20220614204730.3359543-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 09/21] KVM: nVMX: Unconditionally clear mtf_pending on nested VM-Exit From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Upton , Peter Shier 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,T_SCC_BODY_TEXT_LINE,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 Clear mtf_pending on nested VM-Exit instead of handling the clear on a case-by-case basis in vmx_check_nested_events(). The pending MTF should rever survive nested VM-Exit, as it is a property of KVM's run of the current L2, i.e. should never affect the next L2 run by L1. In practice, this is likely a nop as getting to L1 with nested_run_pending is impossible, and KVM doesn't correctly handle morphing a pending exception that occurs on a prior injected exception (need for re-injected exception being the other case where MTF isn't cleared). However, KVM will hopefully soon correctly deal with a pending exception on top of an injected exception. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index d080bfca16ef..7b644513c82b 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3909,16 +3909,8 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) unsigned long exit_qual; bool block_nested_events = vmx->nested.nested_run_pending || kvm_event_needs_reinjection(vcpu); - bool mtf_pending = vmx->nested.mtf_pending; struct kvm_lapic *apic = vcpu->arch.apic; - /* - * Clear the MTF state. If a higher priority VM-exit is delivered first, - * this state is discarded. - */ - if (!block_nested_events) - vmx->nested.mtf_pending = false; - if (lapic_in_kernel(vcpu) && test_bit(KVM_APIC_INIT, &apic->pending_events)) { if (block_nested_events) @@ -3927,6 +3919,9 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) clear_bit(KVM_APIC_INIT, &apic->pending_events); if (vcpu->arch.mp_state != KVM_MP_STATE_INIT_RECEIVED) nested_vmx_vmexit(vcpu, EXIT_REASON_INIT_SIGNAL, 0, 0); + + /* MTF is discarded if the vCPU is in WFS. */ + vmx->nested.mtf_pending = false; return 0; } @@ -3964,7 +3959,7 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu) return 0; } - if (mtf_pending) { + if (vmx->nested.mtf_pending) { if (block_nested_events) return -EBUSY; nested_vmx_update_pending_dbg(vcpu); @@ -4562,6 +4557,9 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason, struct vcpu_vmx *vmx = to_vmx(vcpu); struct vmcs12 *vmcs12 = get_vmcs12(vcpu); + /* Pending MTF traps are discarded on VM-Exit. */ + vmx->nested.mtf_pending = false; + /* trying to cancel vmlaunch/vmresume is a bug */ WARN_ON_ONCE(vmx->nested.nested_run_pending); -- 2.36.1.476.g0c4daa206d-goog