All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v6 2/2] KVM: VMX: Cap VMX preemption timer to work around Intel erratum
Date: Wed, 29 Jul 2026 06:57:58 -0700	[thread overview]
Message-ID: <amoG5v6YWX5FcB-e@google.com> (raw)
In-Reply-To: <20260729135054.B5CAA1F000E9@smtp.kernel.org>

On Wed, Jul 29, 2026, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> > index 7d2cc36a04e51..67c8dc1eb2c4f 100644
> > --- a/arch/x86/kvm/vmx/vmx.c
> > +++ b/arch/x86/kvm/vmx/vmx.c
> 
> [ ... ]
> 
> > @@ -8305,6 +8306,33 @@ static inline int u64_shl_div_u64(u64 a, unsigned int shift,
> >  	return 0;
> >  }
> >  
> > +/*
> > + * 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_max_value(void)
> > +{
> > +	const u64 ARCHITECTURAL_MAX_VALUE = UINT_MAX;
> > +	u32 eax, ebx, ecx, edx;
> 
> [ ... ]
> 
> > +	if (WARN_ON_ONCE(!(((u64)ebx << 25) / eax)))
> > +		return ARCHITECTURAL_MAX_VALUE;
> > +
> > +	return (((u64)ebx << 25) / eax) - 1;
> 
> [Severity: High]
> If a CPU has a high TSC-to-crystal clock ratio (for example, EBX/EAX >= 128),
> could this calculation exceed UINT_MAX? Because the returned u64 is not clamped
> to ARCHITECTURAL_MAX_VALUE, preemption_timer_max_value could end up storing a
> value larger than 32 bits.

/facepalm

I completely misread this:

	return min_t(u64, 1ULL << 32, ((u64)ebx << 25) / eax);

as max_t.  I'll add it back... 

      reply	other threads:[~2026-07-29 13:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 13:42 [PATCH v6 0/2] KVM: VMX: Workaround VMX preemption timer erratum Sean Christopherson
2026-07-29 13:42 ` [PATCH v6 1/2] KVM: VMX: Bury all of the VMX preemption timer code under CONFIG_X86_64=y Sean Christopherson
2026-07-29 13:42 ` [PATCH v6 2/2] KVM: VMX: Cap VMX preemption timer to work around Intel erratum Sean Christopherson
2026-07-29 13:50   ` sashiko-bot
2026-07-29 13:57     ` Sean Christopherson [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=amoG5v6YWX5FcB-e@google.com \
    --to=seanjc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.