qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Gleb Natapov <gleb@redhat.com>, kvm <kvm@vger.kernel.org>,
	qemu-devel <qemu-devel@nongnu.org>,
	Alexander Graf <agraf@suse.de>, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] Re: [RFC][PATCH] KVM: Introduce modification context for cpu_synchronize_state
Date: Wed, 27 Jan 2010 18:53:34 -0200	[thread overview]
Message-ID: <20100127205334.GA19934@amt.cnet> (raw)
In-Reply-To: <4B605390.9020709@siemens.com>

On Wed, Jan 27, 2010 at 03:54:08PM +0100, Jan Kiszka wrote:
> This patch originates in the mp_state writeback issue: During runtime
> and even on reset, we must not write the previously saved VCPU state
> back into the kernel in an uncontrolled fashion. E.g mp_state should
> only written on reset or on VCPU setup. Certain clocks (e.g. the TSC)
> may only be written on setup or after vmload.
> 
> By introducing additional information about the context of the planned
> vcpu state manipulation, we can simply skip sensitive states like
> mp_state when updating the in-kernel state. The planned modifications
> are defined when calling cpu_synchronize_state. They accumulate, ie.
> once a full writeback was requested, it will stick until it was
> performed.
> 
> This patch already fixes existing writeback issues in upstream KVM by
> only selectively writing MSR_IA32_TSC, MSR_KVM_SYSTEM_TIME,
> MSR_KVM_WALL_CLOCK, the mp_state and the vcpu_events.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
> 
> This patch is intentionally written against uq/master. As upstream is
> less convoluted (yet :) ), it may help understanding the basic idea. An
> add-on patch for qemu-kvm that both cleans up the current code and also
> moves kvm_get/set_lapic into kvm_arch_get/put_registers (hmm, maybe also
> renaming that services...) will follow soon if no one sees fundamental
> problems of this approach.
> 
>  exec.c                |    4 ++--
>  gdbstub.c             |   10 +++++-----
>  hw/apic.c             |    2 +-
>  hw/ppc_newworld.c     |    2 +-
>  hw/ppc_oldworld.c     |    2 +-
>  hw/s390-virtio.c      |    2 +-
>  kvm-all.c             |   31 +++++++++++++++++++------------
>  kvm.h                 |   13 +++++++++----
>  monitor.c             |    4 ++--
>  target-i386/helper.c  |    2 +-
>  target-i386/kvm.c     |   31 +++++++++++++++++++------------
>  target-i386/machine.c |    4 ++--
>  target-ppc/kvm.c      |    2 +-
>  target-ppc/machine.c  |    4 ++--
>  target-s390x/kvm.c    |   17 ++++++++++++-----
>  15 files changed, 78 insertions(+), 52 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index f8350c9..8595cd9 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -57,7 +57,8 @@ struct KVMState
>      KVMSlot slots[32];
>      int fd;
>      int vmfd;
> -    int regs_modified;
> +    int synchronized;
> +    int pending_modifications;
>      int coalesced_mmio;
>  #ifdef KVM_CAP_COALESCED_MMIO
>      struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;

Should be per-vcpu.

> @@ -155,10 +156,12 @@ static void kvm_reset_vcpu(void *opaque)
>      CPUState *env = opaque;
>  
>      kvm_arch_reset_vcpu(env);
> -    if (kvm_arch_put_registers(env)) {
> +    if (kvm_arch_put_registers(env, env->kvm_state->pending_modifications
> +                                    | CPU_MODIFY_RESET)) {
>          fprintf(stderr, "Fatal: kvm vcpu reset failed\n");
>          abort();
>      }
> +    env->kvm_state->pending_modifications = CPU_MODIFY_NONE;

Can't the writeback here happen at exec_cpu?

> @@ -946,9 +953,9 @@ static void kvm_invoke_set_guest_debug(void *data)
>      struct kvm_set_guest_debug_data *dbg_data = data;
>      CPUState *env = dbg_data->env;
>  
> -    if (env->kvm_state->regs_modified) {
> -        kvm_arch_put_registers(env);
> -        env->kvm_state->regs_modified = 0;
> +    if (env->kvm_state->pending_modifications) {
> +        kvm_arch_put_registers(env, env->kvm_state->pending_modifications);
> +        env->kvm_state->pending_modifications = CPU_MODIFY_NONE;
>      }

Why's synchronous writeback needed here?

Otherwise seems fine.

  reply	other threads:[~2010-01-27 20:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27 14:54 [Qemu-devel] [RFC][PATCH] KVM: Introduce modification context for cpu_synchronize_state Jan Kiszka
2010-01-27 20:53 ` Marcelo Tosatti [this message]
2010-01-28  8:52   ` [Qemu-devel] " Jan Kiszka
2010-01-29 14:50 ` [Qemu-devel] " Anthony Liguori
2010-01-29 15:25   ` Jan Kiszka
2010-01-29 15:44     ` Anthony Liguori

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=20100127205334.GA19934@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.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).