Re: [tip:perfcounters/core] perf_counter: x86: Fix call-chain support to use NMI-safe methods

Ingo Molnar
2009-06-16T10:51:17Z

* Avi Kivity <avi@redhat.com> wrote:

> On 06/16/2009 11:36 AM, Ingo Molnar wrote:
>>
>>>> I can try to find out internally what Intel's position on writing
>>>> %cr2 is, but it'll take a while; however, KVM should be able to
>>>> tell you if any random OS uses %cr2 writes (as should a static
>>>> disassembly of their kernel.)
>>>>
>>> Linux is one such OS. When acting as a hypervisor it writes cr2
>>> to present its guests with their expected environment (any
>>> hypervisor that uses virtualization extensions will of course need
>>> to do this).
>>>
>>
>> Ah, it does save/restore it in svm_vcpu_run. VMX can do this via its
>> context structure (without explicit CR manipulations in host space),
>> right?
>>
>
> It's the other way around. svm switches the guest cr2 in hardware
> (through svm->vmcb->save.cr2). The code you're referring to saves
> and restores the host cr2, which is completely unnecessary. I'm
> currently in the middle of dropping it :)

Heh :)

> vmx has no hardware support for switching cr2, so vmx_vcpu_run()
> switches it using mov cr2. Given that it's pretty expensive, I've
> switched it to write-if-changed, which dropped 70 cycles from the
> vmexit latency.

Yep, see my numbers elsewhere in this thread - the cost of a cr2
write is ~84 cycles on Nehalem.

Ingo