Re: [PATCH v2 1/1] powerpc/kvm: Save Timebase Offset to fix sched_clock() while running guest code.

From: Michael Ellerman
Date: Fri Feb 05 2021 - 21:57:51 EST


Nicholas Piggin <npiggin@xxxxxxxxx> writes:
> Excerpts from Leonardo Bras's message of February 5, 2021 4:06 pm:
>> Before guest entry, TBU40 register is changed to reflect guest timebase.
>> After exitting guest, the register is reverted to it's original value.
>>
>> If one tries to get the timestamp from host between those changes, it
>> will present an incorrect value.
>>
>> An example would be trying to add a tracepoint in
>> kvmppc_guest_entry_inject_int(), which depending on last tracepoint
>> acquired could actually cause the host to crash.
>>
>> Save the Timebase Offset to PACA and use it on sched_clock() to always
>> get the correct timestamp.
>
> Ouch. Not sure how reasonable it is to half switch into guest registers
> and expect to call into the wider kernel, fixing things up as we go.

Yeah it's not.

We need to disable tracing on those routines that are called in that
half-exited state.

cheers