Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jim Mattson" <jmattson@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: VMX: Cap VMX preemption timer to work around Intel errata
Date: Mon, 20 Jul 2026 21:36:31 +0000	[thread overview]
Message-ID: <20260720213632.0F3271F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720205230.1457146-1-jmattson@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch introduces a 64-bit division using the `/` operator which will cause a link-time error (`undefined reference to __udivdi3`) on 32-bit x86 builds.
--

--- Patch [1]: [PATCH] KVM: VMX: Cap VMX preemption timer to work around Intel errata ---
commit 366ce3421414ba11b41c6d60e48e81bd155756a9
Author: Jim Mattson <jmattson@google.com>

KVM: VMX: Cap VMX preemption timer to work around Intel errata

Due to a widespread Intel erratum (e.g. EMR158), programming the
VMX-preemption timer with certain large values may cause the timer to expire
earlier than expected. This patch calculates a limit based on CPUID 15H and
returns -ERANGE in vmx_set_hv_timer() if the shifted delta_tsc reaches or
exceeds this preemption timer limit.

Link: https://lore.kernel.org/all/Zn9X0yFxZi_Mrlnt@google.com/

> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 6b96f7aea20bd..9c540a50922a9 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c

[ ... ]

> @@ -8489,6 +8490,26 @@ static void __init vmx_setup_me_spte_mask(void)
>  	kvm_mmu_set_me_spte_mask(0, me_mask);
>  }
>  
> +/*
> + * Workaround for a widespread Intel erratum (e.g. EMR158) where the
> + * VMX-preemption timer may expire earlier than expected when programmed
> + * with large values. The workaround is to cap the timer value to strictly
> + * less than 2^25 * CPUID.15H:EBX / CPUID.15H:EAX.
> + */
> +static __init u64 calc_preemption_timer_limit(void)
> +{
> +	u32 eax, ebx, ecx, edx;
> +
> +	if (cpuid_eax(0) < 0x15)
> +		return 1ULL << 32;
> +
> +	cpuid(0x15, &eax, &ebx, &ecx, &edx);
> +	if (!eax || !ebx)
> +		return 1ULL << 32;
> +
> +	return min_t(u64, 1ULL << 32, ((u64)ebx << 25) / eax);
                                                         ^^^^^

[Severity: High]
Will this 64-bit division using the / operator cause a link-time error on
32-bit x86 builds?

Since the Linux kernel does not export the __udivdi3 compiler intrinsic on
32-bit x86, compiling with CONFIG_KVM_INTEL enabled on a 32-bit configuration
might result in an undefined reference error during the build.

Should this use div_u64() from include/linux/math64.h to perform the 64-bit
by 32-bit division instead?

> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720205230.1457146-1-jmattson@google.com?part=1

      reply	other threads:[~2026-07-20 21:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 20:52 [PATCH] KVM: VMX: Cap VMX preemption timer to work around Intel errata Jim Mattson
2026-07-20 21:36 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260720213632.0F3271F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox