From: James Morse <james.morse@arm.com>
To: KarimAllah Ahmed <karahmed@amazon.de>
Cc: Marc Zyngier <maz@kernel.org>,
linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] KVM: arm64: Use the correct timer for accessing CNT
Date: Tue, 17 Mar 2020 13:59:38 +0000 [thread overview]
Message-ID: <ac2933bf-452a-f27a-2d8a-8299c3044111@arm.com> (raw)
In-Reply-To: <1584351546-5018-1-git-send-email-karahmed@amazon.de>
Hi KarimAllah,
On 3/16/20 9:39 AM, KarimAllah Ahmed wrote:
> Use the physical timer object when reading the physical timer counter
> instead of using the virtual timer object. This is only visible when
> reading it from user-space as kvm_arm_timer_get_reg() is only executed on
> the get register patch from user-space.
Have you seen this go wrong?
I agree this looks like this was a typo introduced by:
84135d3d1 ("KVM: arm/arm64: consolidate arch timer trap handlers")
-----------------%<-----------------
case KVM_REG_ARM_PTIMER_CNT:
- return kvm_phys_timer_read();
+ return kvm_arm_timer_read(vcpu,
+ vcpu_vtimer(vcpu), TIMER_REG_CNT);
-----------------%<-----------------
This would be a problem when the guest reads the physical counter
directly, (which doesn't get trapped), and the VMM makes this API call
and gets a number in a totally different ball-park.
Can the VMM actually read these registers with this path?
kvm_arm_get_reg() gets to filter out the coproc registers that aren't in
the sys_reg[], it also uses is_timer_reg() to spot the timer/counter
registers, but is_timer_reg() only matches three of them:
| case KVM_REG_ARM_TIMER_CTL:
| case KVM_REG_ARM_TIMER_CNT:
| case KVM_REG_ARM_TIMER_CVAL:
KVM_REG_ARM_PTIMER_CNT is not one of them.
It looks like when the VMM tries to read this, it fails is_timer_reg(),
and matches in the sys_regs[] and is handled by access_arch_timer(),
which uses kvm_arm_timer_read_sysreg() -> kvm_arm_timer_read(),
bypassing this bug.
... this looks like a bug in dead code ...
Thanks!
James
> diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
> index 0d9438e..93bd59b 100644
> --- a/virt/kvm/arm/arch_timer.c
> +++ b/virt/kvm/arm/arch_timer.c
> @@ -788,7 +788,7 @@ u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid)
> vcpu_ptimer(vcpu), TIMER_REG_CTL);
> case KVM_REG_ARM_PTIMER_CNT:
> return kvm_arm_timer_read(vcpu,
> - vcpu_vtimer(vcpu), TIMER_REG_CNT);
> + vcpu_ptimer(vcpu), TIMER_REG_CNT);
> case KVM_REG_ARM_PTIMER_CVAL:
> return kvm_arm_timer_read(vcpu,
> vcpu_ptimer(vcpu), TIMER_REG_CVAL);
>
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
prev parent reply other threads:[~2020-03-17 13:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 9:39 [PATCH] KVM: arm64: Use the correct timer for accessing CNT KarimAllah Ahmed
2020-03-16 10:49 ` Zenghui Yu
2020-03-16 11:09 ` Marc Zyngier
2020-03-16 12:38 ` Zenghui Yu
2020-03-17 13:59 ` James Morse [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac2933bf-452a-f27a-2d8a-8299c3044111@arm.com \
--to=james.morse@arm.com \
--cc=karahmed@amazon.de \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).