From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64769C433F5 for ; Fri, 11 Mar 2022 03:29:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346153AbiCKDai (ORCPT ); Thu, 10 Mar 2022 22:30:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346067AbiCKD3w (ORCPT ); Thu, 10 Mar 2022 22:29:52 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E907FF47CB for ; Thu, 10 Mar 2022 19:28:33 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id c14-20020a17090a674e00b001bf1c750f9bso7059918pjm.9 for ; Thu, 10 Mar 2022 19:28:33 -0800 (PST) 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=GjFGC3zkLsAKJ8vvrLjGXYpYaWOgGo2yckKlLK/AIVY=; b=KQO3w+xmpoTyRvXAzcDfzPqPSx3WjGUr9L3gTJqQHiDJ2yTrH27YOKscDQl3Bp5Ua3 JfqPIci9q5Jz4WO1A/G7lKuGKCZy7o4nCNEH/GgMX4qgdeli7FwIJjONYLTXwvxHizcN ozj8xFK5uiv1S8Bxp5Q7v9KiTJL0C6gmswS3YDE6EO4srnr7tfn3oEo4fSfRoseyDUPa nYhSc4QJzLV3W0edaaRrTPITCokuqgad2WWpUjLMM05Y7Eo0ViwaEzaYdn5qjPsJf2PM nHFQ4o/2Gnq/9A+Zylc7yuArpklMIbfeTAmAoMdwT6rHfpUMp50gbBjzoaytKI6TAL+F Jx4g== 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=GjFGC3zkLsAKJ8vvrLjGXYpYaWOgGo2yckKlLK/AIVY=; b=xGxnfSqFp2kvF5ald77856UqqdzxihfFiP7mv7NkTRX+X7MuCyumn8RsA0qweXweXY 2tNHBDr4urg+Pp9ZfL26e9cBoXC55Qn6CWc4V27xjfeAQMqyw3T2NNcYjCHqVsthutxM VA7Kl9UOt76dWRCO6F+1dySU3ijIJLakK73v1MnUbU6C5XEynl0RsMvXcc10QMWzDiWw 9w8iEJ6J+nU1gQqbIKj+BfOYWsTJ3ZAFHBKPeTLeHW4OVea57NPfVRAQxCB0AJrYyGy2 ZL1Va+gsYBv/e00Wanwo5xYhhDrWqcGspoYkLPR4IZty0+PvxbLFw4LUxCXucYzNK9zQ whRw== X-Gm-Message-State: AOAM533tKr18jLTOrLg2zNVvXi1kwH0JkhVtS6laKlbeCePBuj1Ads+v +iSL4x1Ec1MaQDWl17kXDJedrhJK4TI= X-Google-Smtp-Source: ABdhPJzHDnuZl/O/d0//LQZL3QjijqGxvFKvqsDfvyxeDIx3v/bkVReGqtS28e14C/BWbLfRKeuJ3m7CVLg= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:4d81:b0:1bf:8ce4:4f51 with SMTP id oj1-20020a17090b4d8100b001bf8ce44f51mr404251pjb.0.1646969313078; Thu, 10 Mar 2022 19:28:33 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 11 Mar 2022 03:27:57 +0000 In-Reply-To: <20220311032801.3467418-1-seanjc@google.com> Message-Id: <20220311032801.3467418-18-seanjc@google.com> Mime-Version: 1.0 References: <20220311032801.3467418-1-seanjc@google.com> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH 17/21] KVM: x86: Evaluate ability to inject SMI/NMI/IRQ after potential 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Determine whether or not new events can be injected after checking nested events. If a VM-Exit occurred during nested event handling, any previous event that needed re-injection is gone from's KVM perspective; the event is captured in the vmc*12 VM-Exit information, but doesn't exist in terms of what needs to be done for entry to L1. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c1cd2166fe22..327a935712fb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9310,7 +9310,7 @@ static void kvm_inject_exception(struct kvm_vcpu *vcpu) static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit) { - bool can_inject = !kvm_event_needs_reinjection(vcpu); + bool can_inject; int r; /* @@ -9375,7 +9375,13 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate_exit) if (r < 0) goto out; - /* try to inject new event if pending */ + /* + * New events, other than exceptions, cannot be injected if KVM needs + * to re-inject a previous event. See above comments on re-injecting + * for why pending exceptions get priority. + */ + can_inject = !kvm_event_needs_reinjection(vcpu); + if (vcpu->arch.exception.pending) { trace_kvm_inj_exception(vcpu->arch.exception.vector, vcpu->arch.exception.has_error_code, -- 2.35.1.723.g4982287a31-goog