[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH linux-next 2/2] x86/xen/time: cleanup xen_tsc_safe_clocksource


  • To: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
  • From: Krister Johansen <kjlx@xxxxxxxxxxxxxxxxxx>
  • Date: Tue, 21 Feb 2023 09:21:53 -0800
  • Arc-authentication-results: i=1; rspamd-5db48964c-h5x86; auth=pass smtp.auth=dreamhost smtp.mailfrom=kjlx@xxxxxxxxxxxxxxxxxx
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1677000117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ik/BxQVPULpYrwYc2hSx19d57QjiK1F7eWzQZ1uWOVk=; b=J4derqVFJoMoBMS/cOvGnTn+1pWG8PtkakqynpvlrMNI7DP8XPx22NbRhksWdA7Mz3US7t RXP1weVwGeCUrjhYnx584vnfuZwbuI1WsY2jnCQp+E96FLqX0uKvtwV6KxWp7txe6DQCNh jhWH6jBRFA1ufHME3j7WAlNeJwjsMKKtx9vbQZaxa1tOoefKz/Py6a+Gftljo2ey8tz5G/ cSaVj/Pk5tU3wv80JVQijOrpiVbRZH6Er2VYnz1whEkFt3J6/VxKd9+oE5ej35izV93H5p vqgH2cWE3dHQmVVScySMf+WQlnxLiYNF5sKFGL0NPvGCRtaHtPWniXQE2ce6zQ==
  • Arc-seal: i=1; s=arc-2022; d=mailchannels.net; t=1677000117; a=rsa-sha256; cv=none; b=6LNeswM14LG7SEv4EJuJzbcPK9yxw2FjS8mK39q4oSvkJ2Ya6yHlBhgnhiIgCiLH19sJNA eTjJuazBcEjhOsWnk26Tx9G6G4u8CMzEIEoFEA39ZE4VjpGzMW/79VPlMudOUS+RORJZPG nfTdqXSxbDroc+Nb77kTOvSHdrQ23j7YVlL/BIH/JPkZqjgm057e/Dbi8UG+vmgEmmtf5p c0ACxiueVbw7MoR0QiyquLmdtsNka8w7LJBOQxIPIV+OWAm3ZUyrSQnzi02M9VCsI/Q31T T9SxvFwIIemm5or70jo+EGo45tUUcfyb5+iomzqtcs/aR75BghGtGsDEffVtyg==
  • Cc: Krister Johansen <kjlx@xxxxxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Juergen Gross <jgross@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, x86@xxxxxxxxxx, "H. Peter Anvin" <hpa@xxxxxxxxx>, Marcelo Tosatti <mtosatti@xxxxxxxxxx>, Anthony Liguori <aliguori@xxxxxxxxxx>, David Reaver <me@xxxxxxxxxxxxxxx>, Brendan Gregg <brendan@xxxxxxxxx>
  • Delivery-date: Tue, 21 Feb 2023 17:22:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Feb 21, 2023 at 10:14:54AM +0100, Thomas Gleixner wrote:
> On Mon, Feb 20 2023 at 21:51, Krister Johansen wrote:
> > On Mon, Feb 20, 2023 at 08:14:40PM -0800, Krister Johansen wrote:
> >> > static bool __init xen_tsc_safe_clocksource(void)
> >> > {
> >> >  u32 eax, ebx. ecx, edx;
> >> >  
> >> >  /* Leaf 4, sub-leaf 0 (0x40000x03) */
> >> >  cpuid_count(xen_cpuid_base() + 3, 0, &eax, &ebx, &ecx, &edx);
> >> > 
> >> >  return ebx == XEN_CPUID_TSC_MODE_NEVER_EMULATE;
> >> > }
> >> 
> >> I'm all for simplifying.  I'm happy to clean up that return to be more
> >> idiomatic.  I was under the impression, perhaps mistaken, though, that
> >> the X86_FEATURE_CONSTANT_TSC, X86_FEATURE_NONSTOP_TSC, and
> >> check_tsc_unstable() checks were actually serving a purpose: to ensure
> >> that we don't rely on the tsc in environments where it's being emulated
> >> and the OS would be better served by using a PV clock.  Specifically,
> >> kvmclock_init() makes a very similar set of checks that I also thought
> >> were load-bearing.
> >
> > Bah, what I meant to say was emulated, unstable, or otherwise unsuitable
> > for use as a clocksource.  IOW, even if TSC_MODE_NEVER_EMULATE is
> > set, it's possible that a user is attempting a migration from a cpu
> > that's not invariant, and we'd still want to check for that case and
> > fall back to a PV clocksource, correct?
> 
> Sure. But a life migration from a NEVER_EMULATE to a non-invariant host
> is a patently bad idea and has nothing to do with the __init function,
> which is gone at that point already.
> 
> What I wanted to say:
> 
> static bool __init xen_tsc_safe_clocksource(void)
> {
>         ......        
> 
>       /* Leaf 4, sub-leaf 0 (0x40000x03) */
>       cpuid_count(xen_cpuid_base() + 3, 0, &eax, &ebx, &ecx, &edx);
> 
>       return ebx == XEN_CPUID_TSC_MODE_NEVER_EMULATE;
> }

Thanks, I'm happy to make it look like ^ that.  I should have thought to
do this myself. :/

I'll send out a v2 making this correction.

> I didn't have the full context and was just looking at the condition.
> Now I checked the full context and I think that except for the
> 
>       if (check_tsc_unstable())
> 
> check everything else can go away unless you do not trust the hypervisor
> that it only sets the NEVER_EMULATE bit when CONSTANT and NONSTOP are
> set as well. But yeah, you might prefer to be paranoid. It's virt after
> all.

Unless there are objections, I think I'd prefer to err on the side of
paranoia here.  Sorry for the confusion.

-K



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.