From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Wilson Subject: Re: [PATCH v2] x86/viridian: Add Partition Reference Time enlightenment Date: Fri, 10 Oct 2014 18:36:30 +0200 Message-ID: <20141010163616.GA27670@u109add4315675089e695.ant.amazon.com> References: <1411986524-5201-1-git-send-email-paul.durrant@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1411986524-5201-1-git-send-email-paul.durrant@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Paul Durrant Cc: Keir Fraser , Ian Campbell , Stefano Stabellini , Christoph Egger , Ian Jackson , xen-devel@lists.xen.org, Jan Beulich , Anthony Liguori List-Id: xen-devel@lists.xenproject.org On Mon, Sep 29, 2014 at 11:28:44AM +0100, Paul Durrant wrote: > The presence of the partition reference time enlightenment persuades newer > versions of Windows to prefer the TSC as their primary time source. Hence, > if rdtsc is not being emulated and is invariant then many vmexits (for > alternative time sources such as the HPET or reference counter MSR) can > be avoided. > > The implementation is not yet complete as no attempt is made to prevent > emulation of rdtsc if the enlightenment is active and guest and host > TSC frequencies differ. To do that requires invasive changes in the core > x86 time code and hence a lot more testing. > > This patch avoids the issue by disabling the enlightenment if rdtsc is > being emulated, causing Windows to choose another time source. This is > safe, but may cause a big variation in performance of guests migrated > between hosts of differing TSC frequency. Thus the enlightenment is not > enabled in the default set, but may be enabled to improve guest performance > where such migrations are not a concern. > > See section 15.4 of the Microsoft Hypervisor Top Level Functional > Specification v4.0a for details. > > Signed-off-by: Paul Durrant > Cc: Keir Fraser > Cc: Jan Beulich > Cc: Ian Campbell > Cc: Ian Jackson > Cc: Stefano Stabellini > Cc: Christoph Egger [...] > + /* > + * The guest will calculate reference time according to the following > + * formula: > + * > + * ReferenceTime = ((RDTSC() * TscScale) >> 64) + TscOffset > + * > + * Windows uses a 100ns tick, so we need a scale which is cpu > + * ticks per 100ns shifted left by 64. > + */ > + p->TscScale = ((10000ul << 32) / d->arch.tsc_khz) << 32; > + > + do { > + p->TscSequence++; > + } while ( p->TscSequence == 0xFFFFFFFF || > + p->TscSequence == 0 ); /* Avoid both 'invalid' values */ Anthony Liguori and I were looking this over today and he pointed something out: couldn't a second vCPU of the guest write 0 or 0xffffffff in a tight loop to cause a hypervisor DoS? --msw > + unmap_domain_page(p); > + > + put_page_and_type(page); > +} > + [...]