From nobody Fri Dec 26 05:27:51 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 4B47F46AD for ; Wed, 10 Jan 2024 01:27:11 +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="s54wu1cp" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-28d4ec3bf5bso2374503a91.1 for ; Tue, 09 Jan 2024 17:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704850031; x=1705454831; 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=uDSz3XZTGTdHd1XB0ese2a/q6yXzymb/AuDVpe3xIZo=; b=s54wu1cplNOmeztAv3PiqSXXjaJhFWU2OATKw9nQPrE3+0VGE9buzjDfBEGaAzTKzM 13VWBYZoIvqyoqqe5yYLk71I4LJpTwYFVDbezEyYoEXPev/obiugqYwWl7MKhawmPGqe 8BztRfX5OSuN+NaxvFdHRA4HIoi0dHrfW7DFhlb34ZB9IHqxxLpYijqeqxy1E0lbV1ns 46+IH+JlJrtb7uaydSL0Lya2MXak9sU/ep1kA83pO+H7d8nfNBIrC0Xvb+adue4qV+u/ rCacMQhq/UkVSFkt7gHJk6Daa519JHgxlhIWNBQjfID4xzzEp39KC/rB52vUI38zyd2Y 4WFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704850031; x=1705454831; 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=uDSz3XZTGTdHd1XB0ese2a/q6yXzymb/AuDVpe3xIZo=; b=AesbxitMJJMfblii10ASeZScoxqp1F0y7RVG7vF46ipzUZW9PAI//mlvEkv1YILsfB gfph+kQko60C8GjWGiuwkxKgJq2xUNYpZNA+WTZ51KiZQZpI82VNl/XyqTWjvcAEHN8L sejiIrLg1V8d8+W7KjNAkzYbqzpevxRb/3ZfR9LGxNp8afzyZ8zhHncU/LyR0ULO09HV bLke4FD0npt3XjsBW8CZmJp+hHMiAUnPsu0xghUxwquSD0rkbV40RCvGdJWT3ZveQBZ2 pACoHoj84DXgfcpdQ8LBg1KToT3YyRtQjdWkl6WrkJCdj8PhpNxQSP+diypPgm6wY3Xx TO2Q== X-Gm-Message-State: AOJu0YwRfb3OrEMdY6um8kMdR66b7S+RjVqeAsaoGfKiZYT827UjQIBW HotMGjdEt4C0Dt3DwJxIHduVYbPzcpiEEnZ9SQ== X-Google-Smtp-Source: AGHT+IHMQGToTfzq5Il+OqaDv8F05pv4rv24DTaau8gLjNp+L0rsgUPbs8aaWg1c7lL/5TPqwD3CR/t9qqQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:2382:b0:28d:adc5:ce08 with SMTP id mr2-20020a17090b238200b0028dadc5ce08mr19940pjb.2.1704850031487; Tue, 09 Jan 2024 17:27:11 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 9 Jan 2024 17:27:01 -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-3-seanjc@google.com> Subject: [PATCH 2/6] KVM: VMX: Re-enter guest in fastpath for "spurious" preemption timer exits 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" Re-enter the guest in the fast path if VMX preeemption timer VM-Exit was "spurious", i.e. if KVM "soft disabled" the timer by writing -1u and by some miracle the timer expired before any other VM-Exit occurred. This is just an intermediate step to cleaning up the preemption timer handling, optimizing these types of spurious VM-Exits is not interesting as they are extremely rare/infrequent. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 51d0f3985463..4caad881d9a0 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5995,8 +5995,15 @@ static fastpath_t handle_fastpath_preemption_timer(s= truct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx =3D to_vmx(vcpu); =20 - if (!vmx->req_immediate_exit && - !unlikely(vmx->loaded_vmcs->hv_timer_soft_disabled)) { + /* + * In the *extremely* unlikely scenario that this is a spurious VM-Exit + * due to the timer expiring while it was "soft" disabled, just eat the + * exit and re-enter the guest. + */ + if (unlikely(vmx->loaded_vmcs->hv_timer_soft_disabled)) + return EXIT_FASTPATH_REENTER_GUEST; + + if (!vmx->req_immediate_exit) { kvm_lapic_expired_hv_timer(vcpu); return EXIT_FASTPATH_REENTER_GUEST; } --=20 2.43.0.472.g3155946c3a-goog