lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZJ8Pw3YMrYbwgcP2@linux.dev>
Date:   Fri, 30 Jun 2023 17:24:19 +0000
From:   Oliver Upton <oliver.upton@...ux.dev>
To:     Sean Christopherson <seanjc@...gle.com>
Cc:     Like Xu <like.xu.linux@...il.com>,
        Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] KVM: x86/tsc: Update guest tsc_offset again before vcpu
 first runs

On Fri, Jun 30, 2023 at 05:21:41PM +0000, Oliver Upton wrote:
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index c30364152fe6..43d40f058a41 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -2721,14 +2721,14 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 data)
> >  			 * kvm_clock stable after CPU hotplug
> >  			 */
> >  			synchronizing = true;
> > -		} else {
> > +		} else if (kvm_vcpu_has_run(vcpu)) {
> >  			u64 tsc_exp = kvm->arch.last_tsc_write +
> >  						nsec_to_cycles(vcpu, elapsed);
> >  			u64 tsc_hz = vcpu->arch.virtual_tsc_khz * 1000LL;
> >  			/*
> >  			 * Special case: TSC write with a small delta (1 second)
> > -			 * of virtual cycle time against real time is
> > -			 * interpreted as an attempt to synchronize the CPU.
> > +			 * of virtual cycle time against real time on a running
> > +			 * vCPU is interpreted as an attempt to synchronize.
> >  			 */
> >  			synchronizing = data < tsc_exp + tsc_hz &&
> >  					data + tsc_hz > tsc_exp;
> 
> This would break existing save/restore patterns for the TSC. QEMU relies
> on KVM synchronizing the TSCs when restoring a VM, since it cannot
> snapshot the TSC values of all the vCPUs in a single instant. It instead
> tries to save the TSCs at roughly the same time [*], which KVM detects
> on the target and gets everything back in sync. Can't wait to see when
> this heuristic actually breaks :)

Of course, forgot to actually include the link.

[*] https://gitlab.com/qemu-project/qemu/-/blob/408015a97dbe48a9dde8c0d2526c9312691952e7/target/i386/kvm/kvm.c#L249

-- 
Thanks,
Oliver

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ