Re: [PATCH 2/2] KVM: arm64: timers: Adjust CVAL of a ptimer across guest entry and exits

From: Marc Zyngier
Date: Mon Aug 28 2023 - 06:17:57 EST


On Thu, 24 Aug 2023 07:37:42 +0100,
Ganapatrao Kulkarni <gankulkarni@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> >> Now, to the actual patch: I think the way you offset CVAL isn't
> >> great. You should never have to change it on entry, and you should
> >> instead read the correct value from memory. Then, save/restore of CVAL
> >> must be amended to always apply the offset. Can you give the hack
> >> below a go on your HW?
>
> I tried this and seems not working, this is due to timer save/restore
> are not called for some of the kvm_exit and entry paths(lighter
> switches).

Can you point me to such paths? Are you referring to the ECV handling
of the physical timer registers?

>
> I tried changing this patch like, Removed cval adjust from the
> kvm_entry and still cval is adjusted on kvm_exit and in
> timer_restore_state function, reduced cval by offset.
>
> Please let me know, if this is not you intended to try?
> If possible, please share the steps or pseudo code.

What I want to get to is that:

- on entry (TGE having been flipped to 0), the guest's CVAL is always
reload from memory, because that's the absolute reference. We should
never load anything else on the CPU.

- on exit (TGE having been flipped to 1), the guest's CVAL is stored
as the one true value to memory, and the CPU's view is offset by the
offset.

- the high-level save/restore helpers apply the offsets back and forth
as if CNTPOFF didn't exist (because that's exactly the case if
TGE=1).

Now, I'm pretty sure I'm still missing something, but the above is
roughly the scheme I'm trying to follow?

Thanks,

M.

--
Without deviation from the norm, progress is not possible.