From nobody Fri Dec 26 05:27:49 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14EA6DDB7 for ; Wed, 10 Jan 2024 01:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ccVJjRaF" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5f874219ff9so31475557b3.0 for ; Tue, 09 Jan 2024 17:27:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704850036; x=1705454836; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=KWtjxcr+sKa83fwm9XKbhXp8mShZD+B5e+jlbLU3DeA=; b=ccVJjRaFTBIbpymyx7OVq27nXMk8/0OJ2Sc6lwat/YpE4VDQtqKqQNaMmjGUlLLtPd 1PU4P48OjsFL6QKX0/Kk1dGySee7Chk8FEyhTgYqntcD2GVhwFcpRfX8ua50kXAr3qzx +jn6LTGqBK1iQplCi3HGbYUPG9WAqt4+NkdjYQMnLoo5NIy4UWqs5W/wTaaCgSJ/eOkp bWLu/u0uTRMjshv5FA06ryIZt4OAIVJGkK8he7BsFV+t4UH71q2igLimZ/90Xuvigd6S lo5xr8JnsNr0gUYTjUprK8MaN8dHMkCdv5J73R8na4J1lr6vf0X3URclJKUTn9LwFrPU MzSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704850036; x=1705454836; 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:message-id :reply-to; bh=KWtjxcr+sKa83fwm9XKbhXp8mShZD+B5e+jlbLU3DeA=; b=WtCXZhbO5CuqYXN+ZZrcKqTHQ83YBVIUaLI2SLsxNqOeroTQjw3/g0rWVSi/lEnGvj MYZ1DEeWg8z3ujd/e2zpWV5J1OF3qUPEQnWn1k1T+jFCuScZ7pbkC+Uw7c5alocab2Wb 9tFRKIWMbH0jRoJ3poEYBkYdOwII+cP9B6s6ByIRsHBjjvloxVVK637m1mXvTi86WG6P B6K7saFn7uAepxCaD2iV4sgHTEDW3eBwVLKCTD+1HeBjlpJjpgESdF+atQdXqH7X9oCU YocgJ5CjiWsT7lvvv/VwRecgSoZaOn/3bnCFkfjrahcSNdyhxao/0n1hrfJxbyhfbWzG YrLA== X-Gm-Message-State: AOJu0Yym86O768pVlz5m18Ica4kgTTsF/PkdkJzLSGDaQ9q/PIGUSaB+ HQfWKvAkAyACHZq5O8KaJ+TH0HpxM7/pJwMuhA== X-Google-Smtp-Source: AGHT+IFcAWQuBc3tZqBZxZIOMH1LF2jE9lNRYGm7n/qlagDrLr0lHXn2P3l8tjHdwxamBYe1l5cex6xTw4k= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:f00d:0:b0:5f0:92a1:18b2 with SMTP id p13-20020a81f00d000000b005f092a118b2mr577842ywm.2.1704850036153; Tue, 09 Jan 2024 17:27:16 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 9 Jan 2024 17:27:03 -0800 In-Reply-To: <20240110012705.506918-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240110012705.506918-1-seanjc@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240110012705.506918-5-seanjc@google.com> Subject: [PATCH 4/6] KVM: x86: Move handling of is_guest_mode() into fastpath exit handlers From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Maxim Levitsky Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let the fastpath code decide which exits can/can't be handled in the fastpath when L2 is active, e.g. when KVM generates a VMX preemption timer exit to forcefully regain control, there is no "work" to be done and so such exits can be handled in the fastpath regardless of whether L1 or L2 is active. Moving the is_guest_mode() check into the fastpath code also makes it easier to see that L2 isn't allowed to use the fastpath in most cases, e.g. it's not immediately obvious why handle_fastpath_preemption_timer() is called from the fastpath and the normal path. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 6 +++--- arch/x86/kvm/vmx/vmx.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f5f3301d2a01..c32576c951ce 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4092,6 +4092,9 @@ static int svm_vcpu_pre_run(struct kvm_vcpu *vcpu) =20 static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu) { + if (is_guest_mode(vcpu)) + return EXIT_FASTPATH_NONE; + if (to_svm(vcpu)->vmcb->control.exit_code =3D=3D SVM_EXIT_MSR && to_svm(vcpu)->vmcb->control.exit_info_1) return handle_fastpath_set_msr_irqoff(vcpu); @@ -4238,9 +4241,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_= vcpu *vcpu, =20 svm_complete_interrupts(vcpu); =20 - if (is_guest_mode(vcpu)) - return EXIT_FASTPATH_NONE; - return svm_exit_handlers_fastpath(vcpu); } =20 diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index c4a10d46d7a8..a602c5b52c64 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7217,6 +7217,9 @@ void noinstr vmx_spec_ctrl_restore_host(struct vcpu_v= mx *vmx, =20 static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu) { + if (is_guest_mode(vcpu)) + return EXIT_FASTPATH_NONE; + switch (to_vmx(vcpu)->exit_reason.basic) { case EXIT_REASON_MSR_WRITE: return handle_fastpath_set_msr_irqoff(vcpu); @@ -7428,9 +7431,6 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu,= bool force_immediate_exit) vmx_recover_nmi_blocking(vmx); vmx_complete_interrupts(vmx); =20 - if (is_guest_mode(vcpu)) - return EXIT_FASTPATH_NONE; - return vmx_exit_handlers_fastpath(vcpu); } =20 --=20 2.43.0.472.g3155946c3a-goog