* [PATCH 1/1] KVM: arm/arm64: arch_timer: Fix TimerValue TVAL calculation in KVM
@ 2019-03-29 20:12 Wei Huang
2019-03-30 9:56 ` Marc Zyngier
0 siblings, 1 reply; 2+ messages in thread
From: Wei Huang @ 2019-03-29 20:12 UTC (permalink / raw)
To: linux-kernel
Cc: kvmarm, linux-arm-kernel, andre.przywara, christoffer.dall,
marc.zyngier, james.morse, julien.thierry, suzuki.poulose, wei
Recently the generic timer test of kvm-unit-tests failed to complete
(stalled) when a physical timer is being used. This issue is caused
by incorrect update of CNT_CVAL when TimerValue is being accessed,
introduced by 'Commit 84135d3d18da ("KVM: arm/arm64: consolidate arch
timer trap handlers")'. According to Arm ARM, the read/write behavior
of accesses to TimeValue registers is expected to be:
* READ: TimerValue = (CompareValue – (Counter - Offset)
* WRITE: CompareValue = ((Counter - Offset) + Sign(TimerValue)
This patch fixes the TVAL read/write code path according to the
specification.
Signed-off-by: Wei Huang <wei@redhat.com>
---
virt/kvm/arm/arch_timer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 3417f2dbc366..d43308dc3617 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -812,7 +812,7 @@ static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu,
switch (treg) {
case TIMER_REG_TVAL:
- val = kvm_phys_timer_read() - timer->cntvoff - timer->cnt_cval;
+ val = timer->cnt_cval - kvm_phys_timer_read() + timer->cntvoff;
break;
case TIMER_REG_CTL:
@@ -858,7 +858,7 @@ static void kvm_arm_timer_write(struct kvm_vcpu *vcpu,
{
switch (treg) {
case TIMER_REG_TVAL:
- timer->cnt_cval = val - kvm_phys_timer_read() - timer->cntvoff;
+ timer->cnt_cval = kvm_phys_timer_read() - timer->cntvoff + val;
break;
case TIMER_REG_CTL:
--
2.14.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] KVM: arm/arm64: arch_timer: Fix TimerValue TVAL calculation in KVM
2019-03-29 20:12 [PATCH 1/1] KVM: arm/arm64: arch_timer: Fix TimerValue TVAL calculation in KVM Wei Huang
@ 2019-03-30 9:56 ` Marc Zyngier
0 siblings, 0 replies; 2+ messages in thread
From: Marc Zyngier @ 2019-03-30 9:56 UTC (permalink / raw)
To: Wei Huang
Cc: linux-kernel, kvmarm, linux-arm-kernel, andre.przywara,
christoffer.dall, james.morse, julien.thierry, suzuki.poulose
On Fri, 29 Mar 2019 20:12:53 +0000,
Wei Huang <wei@redhat.com> wrote:
>
> Recently the generic timer test of kvm-unit-tests failed to complete
> (stalled) when a physical timer is being used. This issue is caused
> by incorrect update of CNT_CVAL when TimerValue is being accessed,
> introduced by 'Commit 84135d3d18da ("KVM: arm/arm64: consolidate arch
> timer trap handlers")'. According to Arm ARM, the read/write behavior
> of accesses to TimeValue registers is expected to be:
>
> * READ: TimerValue = (CompareValue – (Counter - Offset)
> * WRITE: CompareValue = ((Counter - Offset) + Sign(TimerValue)
>
> This patch fixes the TVAL read/write code path according to the
> specification.
>
> Signed-off-by: Wei Huang <wei@redhat.com>
Huh... Nice catch. I guess I only ran this with a VHE host, where this
code path is unused.
Thanks,
M.
--
Jazz is not dead, it just smell funny.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-03-30 9:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 20:12 [PATCH 1/1] KVM: arm/arm64: arch_timer: Fix TimerValue TVAL calculation in KVM Wei Huang
2019-03-30 9:56 ` Marc Zyngier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).