kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Glauber Costa <glommer@redhat.com>
Cc: kvm@vger.kernel.org, avi@redhat.com, zamsden@redhat.com
Subject: Re: [PATCH 2/2] turn off kvmclock when resetting cpu
Date: Fri, 7 May 2010 17:44:29 -0300	[thread overview]
Message-ID: <20100507204429.GA13212@amt.cnet> (raw)
In-Reply-To: <1272998128-30384-3-git-send-email-glommer@redhat.com>

On Tue, May 04, 2010 at 02:35:28PM -0400, Glauber Costa wrote:
> Currently, in the linux kernel, we reset kvmclock if we are rebooting
> into a crash kernel through kexec. The rationale, is that a new kernel
> won't follow the same memory addresses, and the memory where kvmclock is
> located in the first kernel, will be something else in the second one.
> 
> We don't do it in normal reboots, because the second kernel ends up
> registering kvmclock again, which has the effect of turning off the
> first instance.
> 
> This is, however, totally wrong. This assumes we're booting into
> a kernel that also has kvmclock enabled. If by some reason we reboot
> into something that doesn't do kvmclock including but not limited to:
>  * rebooting into an older kernel without kvmclock support,
>  * rebooting with no-kvmclock,
>  * rebootint into another O.S,
> 
> we'll simply have the hypervisor writing into a random memory position
> into the guest. Neat, uh?
> 
> Moreover, I believe the fix belongs in qemu, since it is the entity
> more prepared to detect all kinds of reboots (by means of a cpu_reset),
> not to mention the presence of misbehaving guests, that can forget
> to turn kvmclock off.
> 
> This patch fixes the issue for me.
> 
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
>  qemu-kvm-x86.c |   19 +++++++++++++++++++
>  1 files changed, 19 insertions(+), 0 deletions(-)
> 
> diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
> index 439c31a..4b94e04 100644
> --- a/qemu-kvm-x86.c
> +++ b/qemu-kvm-x86.c
> @@ -1417,8 +1417,27 @@ void kvm_arch_push_nmi(void *opaque)
>  }
>  #endif /* KVM_CAP_USER_NMI */
>  
> +static int kvm_turn_off_clock(CPUState *env)
> +{
> +    struct {
> +        struct kvm_msrs info;
> +        struct kvm_msr_entry entries[100];
> +    } msr_data;
> +
> +    struct kvm_msr_entry *msrs = msr_data.entries;
> +    int n = 0;
> +
> +    kvm_msr_entry_set(&msrs[n++], MSR_KVM_SYSTEM_TIME, 0);
> +    kvm_msr_entry_set(&msrs[n++], MSR_KVM_WALL_CLOCK, 0);
> +    msr_data.info.nmsrs = n;
> +
> +    return kvm_vcpu_ioctl(env, KVM_SET_MSRS, &msr_data);
> +}
> +
> +
>  void kvm_arch_cpu_reset(CPUState *env)
>  {
> +    kvm_turn_off_clock(env);

Better to zero env->system_time_msr and wall_clock_msr here, and modify
kvm_arch_load_regs to write those MSRs on KVM_PUT_RESET_STATE (to be
conformant with the new writeback scheme).


  parent reply	other threads:[~2010-05-07 20:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04 18:35 [PATCH 0/2] fix kvmclock bug - memory corruption Glauber Costa
2010-05-04 18:35 ` [PATCH 1/2] replace set_msr_entry with kvm_msr_entry Glauber Costa
2010-05-04 18:35   ` [PATCH 2/2] turn off kvmclock when resetting cpu Glauber Costa
2010-05-05  7:26     ` Avi Kivity
2010-05-05 15:24       ` Glauber Costa
2010-05-05 15:34         ` Avi Kivity
2010-05-05 18:21           ` Glauber Costa
2010-05-07 20:44     ` Marcelo Tosatti [this message]
2010-05-05  8:42   ` [PATCH 1/2] replace set_msr_entry with kvm_msr_entry Avi Kivity
2010-05-04 20:21 ` [PATCH 0/2] fix kvmclock bug - memory corruption Zachary Amsden

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=20100507204429.GA13212@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=glommer@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=zamsden@redhat.com \
    /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).