From nobody Tue Apr 7 06:48:13 2026 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 D29F3ECAAD4 for ; Tue, 30 Aug 2022 23:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232190AbiH3XTa (ORCPT ); Tue, 30 Aug 2022 19:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232024AbiH3XS0 (ORCPT ); Tue, 30 Aug 2022 19:18:26 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4F14A2DA0 for ; Tue, 30 Aug 2022 16:16:53 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 136-20020a63008e000000b0042d707c94fbso1788865pga.9 for ; Tue, 30 Aug 2022 16:16:53 -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; bh=6sbjG07/3BJg7OhuoSrfyiDHRM9Via7ZFsnDogcWimo=; b=O4mRBlL1GVybesZRph3jxADQGbSp7RAZAKEKxl/yQutqEWROG+vXriwhT4cwxSC98i KN8IqmYHuulMt/uOeEy03Jo3DUBNUrACt4nAnSUY5ePNdu4NFmoy5ave8wuphTBJDLAm Ivfv3D6Vx6fa14019uFWe9S4CrPjsH0dmtR9s9Qg/dOks9JKJUfXs8q0ep9abWf9kHIO UXeZ8EcHGJK0YT5gFa4JE3tnM+w+k471tss9JvmSJFeK1nkh670haRdum+PkEGCyGGDb kIYKV4iMAyv7N0ciA2AKYFPrhgXCoUAhpyCJlbu4VJIAIGzGHXAJQTb2zHignDCAXuNJ YgxA== 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; bh=6sbjG07/3BJg7OhuoSrfyiDHRM9Via7ZFsnDogcWimo=; b=HLNIGLtFe+H+LNJ7vfg52j/amEpiZdDhnIxBxinGY8/DE16nHAbH6LV0CEKP09G0Qg U9TgJFa56hfnkyt32nIY9Nt+1Jmn54yOJkGqXlOMVEXwIVY9lEgCt7ZJhX/lESQ5e+ym vOUjKeAoqon2OwCxCKFLU9ugLefUwb5z3EcxLQg173Z3e6Ye/U3l6m4sKAv7e3l0gkHJ FgxXV2CrAjsGqNjBIXBsaglVPlWS+bzOamoRot+Ub69L2l7RIGUhKwpO+qV8xRvFb+wy tK5M4gRiJ+/gyC4BCJ5El9dltp1Ku15Klf/gtsVvANfU28R20gra0hQdPWPs2Au+DA70 ru0g== X-Gm-Message-State: ACgBeo3yV+cKWY+Ok7cChunF1kvnw+v0x9FirJmgnZnHUig0ss2lq3BR pNGSPFmdAn6ow2OSxJPYcMgc9PDhwac= X-Google-Smtp-Source: AA6agR7SjO9JLbxN2xHQ6E0RBIlXXzvLyhqG5+N9qcoWAY4kD36SH0j14mV/yI2xP1mPSJid8n5KjtEfb1I= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:ac4:b0:535:c08:2da7 with SMTP id c4-20020a056a000ac400b005350c082da7mr23729757pfl.69.1661901407279; Tue, 30 Aug 2022 16:16:47 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Aug 2022 23:16:05 +0000 In-Reply-To: <20220830231614.3580124-1-seanjc@google.com> Mime-Version: 1.0 References: <20220830231614.3580124-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220830231614.3580124-19-seanjc@google.com> Subject: [PATCH v5 18/27] KVM: x86: Evaluate ability to inject SMI/NMI/IRQ after potential VM-Exit From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , Maxim Levitsky , Oliver Upton , Peter Shier Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Maxim Levitsky --- 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 534484318d52..57f10bfcb90d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9711,7 +9711,7 @@ static void kvm_inject_exception(struct kvm_vcpu *vcp= u) =20 static int inject_pending_event(struct kvm_vcpu *vcpu, bool *req_immediate= _exit) { - bool can_inject =3D !kvm_event_needs_reinjection(vcpu); + bool can_inject; int r; =20 /* @@ -9776,7 +9776,13 @@ static int inject_pending_event(struct kvm_vcpu *vcp= u, bool *req_immediate_exit) if (r < 0) goto out; =20 - /* 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 =3D !kvm_event_needs_reinjection(vcpu); + if (vcpu->arch.exception.pending) { /* * Fault-class exceptions, except #DBs, set RF=3D1 in the RFLAGS --=20 2.37.2.672.g94769d06f0-goog