Skip to contentSkip to conversation

Emulating RDTSC

DISCUSSION Diwaker Gupta 2 participants 2 messages Oct 26, 2006 – Oct 27, 2006

lore
Share & tools
lore
#0 lore raw

Hi all,

Is it possible to modify Xen such that guests incur a fault when they try to execute RDTSC and control is then passed to the hypervisor which can then return whatever it wants to?

I'm starting with x86 PV guests, but using HVM guests is certainly an option if that hardware makes it easier to achieve this. I'm thinking that setting CR4.TSD in the guest control registers should be the first step? Any comments or suggestions much appreciated.

Thanks,
Diwaker

Signature · 1 line
Web/Blog/Gallery: http://floatingsun.net/blog
#1 lore raw

First, add emulation for rdtsc in xen/arch/x86/traps.c:emulate_privileged_op(). (Probably right next to the implementation of RDMSR makes the most sense.)

Then, set CR4.TSD in this manner:
set_in_cr4(X86_CR4_TSD);

Of course simply enabling TSD will cause all RDTSCs in all domains to be emulated, which may not be exactly what you want. You might consider adding a flag or something to the domain / vcpu struct and modifying the context switch code to set the TSD flag is set only for domains that you're interested in, and clear it otherwise.

Let me know if you have any trouble, and I'll see if I can extract a patch from some old code that I have that did this exact thing.

-George

Quoted 21 lines · Diwaker Gupta

Hi all,

Is it possible to modify Xen such that guests incur a fault when they try to execute RDTSC and control is then passed to the hypervisor which can then return whatever it wants to?

I'm starting with x86 PV guests, but using HVM guests is certainly an option if that hardware makes it easier to achieve this. I'm thinking that setting CR4.TSD in the guest control registers should be the first step? Any comments or suggestions much appreciated.

Thanks,
Diwaker
--
Web/Blog/Gallery: http://floatingsun.net/blog

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel