From: Christoffer Dall <christoffer.dall@linaro.org>
To: Marc Zyngier <marc.zyngier@arm.com>
Cc: kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [RFC PATCH] KVM: arm/arm64: Don't let userspace update CNTVOFF once guest is running
Date: Thu, 25 Jun 2015 10:04:57 +0200 [thread overview]
Message-ID: <20150625080457.GD28244@cbox> (raw)
In-Reply-To: <1435157697-28579-1-git-send-email-marc.zyngier@arm.com>
On Wed, Jun 24, 2015 at 03:54:57PM +0100, Marc Zyngier wrote:
> Userspace is allowed to set the guest's view of CNTVCT, which turns
> into setting CNTVOFF for the whole VM. One thing userspace is not supposed
> to do is to update that register while the guest is running. Time will
> either move forward (best case) or backward (really bad idea). Either way,
> this shouldn't happen.
>
> This patch prevents userspace from touching CNTVOFF as soon as a vcpu
> has been started. This ensures that time will keep monotonically increase.
>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>
> QEMU seems to trigger this at boot time, and I have no idea why it does so.
> It would be good to find out, hence the RFC tag.
Is this at kernel boot time you see this, or at system startup time?
IIRC, QEMU creates a throw-away VM with the default CPU target time,
reads out all the system registers to get the KVM reset values of those,
then creates the real VM, and feeds back in all the system register
reset values, as a method for QEMU and KVM to be in sync about the reset
state of the machine. If we do this, and include CNTVCT, then that
would probably trigger this, but the VCPU really shouldn't have been run
at that time...
We should prevent userspace from fiddling with this register post VCPU
start regardless, but yes, it would be good to find out why this is
happening in the first place.
How did you notice this and does it manifest itself in some user-visible
ugliness?
Thanks,
-Christoffer
>
> virt/kvm/arm/arch_timer.c | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
> index 98c95f2..660f348 100644
> --- a/virt/kvm/arm/arch_timer.c
> +++ b/virt/kvm/arm/arch_timer.c
> @@ -220,9 +220,26 @@ int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value)
> case KVM_REG_ARM_TIMER_CTL:
> timer->cntv_ctl = value;
> break;
> - case KVM_REG_ARM_TIMER_CNT:
> - vcpu->kvm->arch.timer.cntvoff = kvm_phys_timer_read() - value;
> + case KVM_REG_ARM_TIMER_CNT: {
> + struct kvm_vcpu *tmp;
> + int i;
> + u64 cntvoff = kvm_phys_timer_read() - value;
> +
> + /*
> + * If any of the vcpus has started, don't update
> + * CNTVOFF. Userspace is severely brain damaged.
> + */
> + kvm_for_each_vcpu(i, tmp, vcpu->kvm) {
> + if (tmp->arch.has_run_once) {
> + kvm_debug("Won't set CNTVOFF to %llx (%llx)\n",
> + cntvoff,
> + vcpu->kvm->arch.timer.cntvoff);
> + return -1;
> + }
> + }
> + vcpu->kvm->arch.timer.cntvoff = cntvoff;
> break;
> + }
> case KVM_REG_ARM_TIMER_CVAL:
> timer->cntv_cval = value;
> break;
> --
> 2.1.4
>
next prev parent reply other threads:[~2015-06-25 8:04 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-24 14:54 [RFC PATCH] KVM: arm/arm64: Don't let userspace update CNTVOFF once guest is running Marc Zyngier
2015-06-25 8:04 ` Christoffer Dall [this message]
2015-06-25 8:48 ` Marc Zyngier
2015-06-25 8:59 ` Claudio Fontana
2015-06-25 9:10 ` Peter Maydell
2015-06-25 9:25 ` Claudio Fontana
2015-06-26 4:49 ` Jan Kiszka
2015-06-29 17:20 ` Claudio Fontana
2015-06-29 17:37 ` Peter Maydell
2015-07-08 15:56 ` Marc Zyngier
2015-07-08 16:06 ` Peter Maydell
2015-07-08 16:37 ` Marc Zyngier
2015-07-08 19:13 ` Peter Maydell
2015-07-09 10:22 ` Christoffer Dall
2015-07-09 10:38 ` Peter Maydell
2015-07-09 12:05 ` Christoffer Dall
2015-07-09 12:07 ` Peter Maydell
2015-07-09 12:24 ` Christoffer Dall
2015-07-09 14:17 ` Christoffer Dall
2015-07-09 14:26 ` Peter Maydell
2015-07-09 16:06 ` Christoffer Dall
2015-07-09 10:40 ` Jan Kiszka
2015-07-09 12:08 ` Christoffer Dall
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=20150625080457.GD28244@cbox \
--to=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marc.zyngier@arm.com \
--cc=peter.maydell@linaro.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).