From nobody Sat Oct 4 16:20:47 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 02BD51FF5EC for ; Fri, 15 Aug 2025 00:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755217567; cv=none; b=E3hNRMiceboDMmlj9U9+MymWr0bEwMUx+vbIQZh+xPbPVXPU5yBa19WJ6P+hbg3kQvU0P4Aq2AeiWgn5pLpmjXWNj4Weh9rgwnEVCGIRKkF5sYLjrxaew5HRhA2nXtl3+4mPhaNKqCrc8Xgt+6Hn/unwbc+1IuV60fPpEkJLAKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755217567; c=relaxed/simple; bh=4HLcCjbausA3eoVQrOGl1gO2kwc168ccN7lc3Po/lf0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BplapEJ3U0izPzOg1mRCf+LoPsXPZiN7OeFOI28UrCstp72yf3qYdbi6avgcj7cjkTKaS9WWctXHv89vO1qeBMhT3dNB52kjE5Tq+kOEe8YRggFaoSdKbzcYrilg/hjDphMxhYVBcdiOcdhNei4OehkoDp75oqLPAUhuS1tEDNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=h4BO9ag9; arc=none smtp.client-ip=209.85.216.73 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="h4BO9ag9" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-32326e017eeso1544339a91.3 for ; Thu, 14 Aug 2025 17:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755217564; x=1755822364; 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=IMEGPXNdBJlGJ8bO8wbUcUjLikv8xvB0yfWaV9VU0Go=; b=h4BO9ag9sxLQ8qJ3HC9HZDSwXzBKDMB1nvsG5x/Eb/6RmV3kzyVYCTLgaQ6Y5dbFQy QYEPdh7MDtQgNVTP0mZBkVR8fylb34V3jWN9BHnyOQnhcoXRgM9Y20aRdScT5RUPzPjD jsIEnLvpv7DZqKalT6n/bn8m9LlGid3lZkdipxf0Jms6fw7LvZQleaDmqRgrrhDkbbLP dYY2O3nL+rtqgIWCJFOwwvbsQ6w+KEHzr18M55gWfU7OaFqIS9mtFXzDJcI0jYwxmhPZ u+J0rN3E8vHlOlpMRDu546TbNmkSYLHq69CPXmRufMiJ+/IToURY9K1swz7HHbOiaOHq jxfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755217564; x=1755822364; 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=IMEGPXNdBJlGJ8bO8wbUcUjLikv8xvB0yfWaV9VU0Go=; b=dcquDBo0BNYe6RbgdW/Ml1GiC1azRKUSH9gBZEV7x8h4xNKqpsQxsMVu/WKRxWpIfl zPizWEV+g48qg61zanDjg9ih5oArkvEUifd4uHEEN2lal/q4cCrC3HuhMBPDCIsWZpGY VRS6Dg5JoEDVl4eX2ebG/gwJXs/stf14Z1uo+qtBNItdcYqAi896lbRM8vxq5n17j+7/ IWyHsCnMrkjG1CqO0Mhdye6ryXLNn0JOtmmB+tC/t97bv4rjB2KGvzYmNbcwQEHtwn4S /zcsoulVcZmld7CVt3luQGgsgbeJPrFB2KZoUSlzi75Eaq2Z2ND3SzLmi7aG21/ZHco7 wmyg== X-Forwarded-Encrypted: i=1; AJvYcCXsq7NDd2XUFJ53sRwJpuraZ0Bd/lgurCopVRsHMn8pMkWZ0gaDxQGgdX8cvLNPtYJfqydeY9rfunbPzjM=@vger.kernel.org X-Gm-Message-State: AOJu0Yyp/CuqOqkmUiRWjtd92x35A5RlcxBRy0RN1c9uHCgWRxVocHIe HQZE2CxrCzWYe+ssVaI0Bfq6YHKhf9h45k7e+a1ESd9oiGIwt8cADJJFSHySqlWyjLetWJZ/5as zEabMyQ== X-Google-Smtp-Source: AGHT+IEa5l9DZtDfSQ2yyw8HyBbrhYk/nGXUVV1TCU+KUfQUicM7eFfRl07ZUYWp5hXfhJ/1H+E8hTPVXRA= X-Received: from pjv7.prod.google.com ([2002:a17:90b:5647:b0:321:a6cc:51c3]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:254a:b0:31f:335d:3424 with SMTP id 98e67ed59e1d1-3234215b4c2mr294304a91.27.1755217564473; Thu, 14 Aug 2025 17:26:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 14 Aug 2025 17:25:31 -0700 In-Reply-To: <20250815002540.2375664-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: <20250815002540.2375664-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.rc1.163.g2494970778-goog Message-ID: <20250815002540.2375664-12-seanjc@google.com> Subject: [PATCH 6.6.y 11/20] KVM: x86: Move handling of is_guest_mode() into fastpath exit handlers From: Sean Christopherson To: stable@vger.kernel.org, Greg Kroah-Hartman , Sasha Levin Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" [ Upstream commit bf1a49436ea37b98dd2f37c57608951d0e28eecc ] 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. Link: https://lore.kernel.org/r/20240110012705.506918-5-seanjc@google.com 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 5a230be224d1..f42c6ef7dc20 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4157,6 +4157,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); @@ -4315,9 +4318,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 631fdd4a575a..4c991d514015 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7258,6 +7258,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); @@ -7468,9 +7471,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.51.0.rc1.163.g2494970778-goog