From: Gleb Natapov <gleb@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
Glauber Costa <glommer@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Alexander Graf <agraf@suse.de>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] Re: [PATCH 15/21] qemu-kvm: Clean up mpstate synchronization
Date: Tue, 2 Feb 2010 14:37:10 +0200 [thread overview]
Message-ID: <20100202123710.GD739@redhat.com> (raw)
In-Reply-To: <4B681B36.3010300@siemens.com>
On Tue, Feb 02, 2010 at 01:31:50PM +0100, Jan Kiszka wrote:
> Gleb Natapov wrote:
> > On Tue, Feb 02, 2010 at 09:19:01AM +0100, Jan Kiszka wrote:
> >> Push mpstate reading/writing into kvm_arch_load/save_regs and, on x86,
> >> properly synchronize with halted in the accessor functions.
> >>
> >> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> >> ---
> >> hw/apic.c | 7 ----
> >> qemu-kvm-ia64.c | 4 ++-
> >> qemu-kvm-x86.c | 88 +++++++++++++++++++++++++++---------------------
> >> qemu-kvm.c | 30 -----------------
> >> qemu-kvm.h | 15 --------
> >> target-i386/machine.c | 6 ---
> >> target-ia64/machine.c | 3 ++
> >> 7 files changed, 55 insertions(+), 98 deletions(-)
> >>
> >> diff --git a/hw/apic.c b/hw/apic.c
> >> index 3e03e10..092c61e 100644
> >> --- a/hw/apic.c
> >> +++ b/hw/apic.c
> >> @@ -507,13 +507,6 @@ void apic_init_reset(CPUState *env)
> >> s->wait_for_sipi = 1;
> >>
> >> env->halted = !(s->apicbase & MSR_IA32_APICBASE_BSP);
> >> -#ifdef KVM_CAP_MP_STATE
> >> - if (kvm_enabled() && kvm_irqchip_in_kernel()) {
> >> - env->mp_state
> >> - = env->halted ? KVM_MP_STATE_UNINITIALIZED : KVM_MP_STATE_RUNNABLE;
> >> - kvm_load_mpstate(env);
> >> - }
> >> -#endif
> >> }
> >>
> >> static void apic_startup(APICState *s, int vector_num)
> >> diff --git a/qemu-kvm-ia64.c b/qemu-kvm-ia64.c
> >> index fc8110e..39bcbeb 100644
> >> --- a/qemu-kvm-ia64.c
> >> +++ b/qemu-kvm-ia64.c
> >> @@ -124,7 +124,9 @@ void kvm_arch_cpu_reset(CPUState *env)
> >> {
> >> if (kvm_irqchip_in_kernel(kvm_context)) {
> >> #ifdef KVM_CAP_MP_STATE
> >> - kvm_reset_mpstate(env->kvm_cpu_state.vcpu_ctx);
> >> + struct kvm_mp_state mp_state = {.mp_state = KVM_MP_STATE_UNINITIALIZED
> >> + };
> >> + kvm_set_mpstate(env, &mp_state);
> >> #endif
> >> } else {
> >> env->interrupt_request &= ~CPU_INTERRUPT_HARD;
> >> diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
> >> index 63cd095..6b5895f 100644
> >> --- a/qemu-kvm-x86.c
> >> +++ b/qemu-kvm-x86.c
> >> @@ -754,6 +754,48 @@ static int get_msr_entry(struct kvm_msr_entry *entry, CPUState *env)
> >> return 0;
> >> }
> >>
> >> +static void kvm_arch_save_mpstate(CPUState *env)
> >> +{
> >> +#ifdef KVM_CAP_MP_STATE
> >> + int r;
> >> + struct kvm_mp_state mp_state;
> >> +
> >> + r = kvm_get_mpstate(env, &mp_state);
> >> + if (r < 0) {
> >> + env->mp_state = -1;
> >> + } else {
> >> + env->mp_state = mp_state.mp_state;
> >> + if (kvm_irqchip_in_kernel()) {
> >> + env->halted = (env->mp_state == KVM_MP_STATE_HALTED);
> >> + }
> >> + }
> >> +#else
> >> + env->mp_state = -1;
> >> +#endif
> >> +}
> >> +
> >> +static void kvm_arch_load_mpstate(CPUState *env)
> >> +{
> >> +#ifdef KVM_CAP_MP_STATE
> >> + struct kvm_mp_state mp_state;
> >> +
> >> + /*
> >> + * -1 indicates that the host did not support GET_MP_STATE ioctl,
> >> + * so don't touch it.
> >> + */
> >> + if (env->mp_state != -1) {
> >> + if (kvm_irqchip_in_kernel()) {
> >> + env->mp_state = env->halted ? KVM_MP_STATE_UNINITIALIZED :
> >> + KVM_MP_STATE_RUNNABLE;
> > When irqchip is in kernel env->halted doesn't contain any relevant
> > information, so this is incorrect. Actually env->halted is updated only
> > to show correct cpu state during "info cpus".
>
> OK, copied from apic_init_reset, see above. So that hunk was probably at
> least useless, and now it's harmfull. Will drop this and only sync from
> mp_state -> halted.
>
It was not useless in apic_init_reset it was a shortcut for:
env->mp_state = !(s->apicbase & MSR_IA32_APICBASE_BSP) ? KVM_MP_STATE_UNINITIALIZED : KVM_MP_STATE_RUNNABLE;
On reset BSP VCPU should set env->mp_state to KVM_MP_STATE_RUNNABLE and
all others to KVM_MP_STATE_UNINITIALIZED.
--
Gleb.
next prev parent reply other threads:[~2010-02-02 12:37 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-02 8:18 [Qemu-devel] [PATCH 00/21] qemu-kvm: Hook cleanups and extended use of upstream code Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 01/21] qemu-kvm: Drop vmport changes Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 02/21] KVM: Make vmport KVM-compatible Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 03/21] qemu-kvm: Clean up register access API Jan Kiszka
2010-02-02 11:06 ` [Qemu-devel] " Gleb Natapov
2010-02-02 11:18 ` Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 04/21] KVM: x86: Fix up misreported CPU features Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 05/21] qemu-kvm: Use upstream kvm_enabled and cpu_synchronize_state Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 06/21] qemu-kvm: Use upstream kvm_setup_guest_memory Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 07/21] qemu-kvm: Use some more upstream prototypes Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 08/21] qemu-kvm: Use upstream kvm_arch_get_supported_cpuid Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 09/21] qemu-kvm: Use upstream kvm_pit_in_kernel Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 10/21] KVM: Move and rename regs_modified Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 11/21] KVM: Rework of guest debug state writing Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 12/21] qemu-kvm: Use upstream kvm_vcpu_dirty Jan Kiszka
2010-02-02 8:18 ` [Qemu-devel] [PATCH 13/21] qemu-kvm: Use upstream guest debug code Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 14/21] qemu-kvm: Rework VCPU state writeback API Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 15/21] qemu-kvm: Clean up mpstate synchronization Jan Kiszka
2010-02-02 12:23 ` [Qemu-devel] " Gleb Natapov
2010-02-02 12:31 ` Jan Kiszka
2010-02-02 12:37 ` Gleb Natapov [this message]
2010-02-02 12:40 ` Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 16/21] KVM: x86: Restrict writeback of VCPU state Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 17/21] qemu-kvm: Use VCPU event state for reset and vmsave/load Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 18/21] qemu-kvm: Cleanup/fix TSC and PV clock writeback Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 19/21] qemu-kvm: Clean up KVM's APIC hooks Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 20/21] qemu-kvm: Move kvm_set_boot_cpu_id Jan Kiszka
2010-02-02 14:11 ` [Qemu-devel] " Gleb Natapov
2010-02-02 14:20 ` Jan Kiszka
2010-02-02 14:28 ` Gleb Natapov
2010-02-02 14:33 ` Jan Kiszka
2010-02-02 8:19 ` [Qemu-devel] [PATCH 21/21] qemu-kvm: Bring qemu_init_vcpu back home Jan Kiszka
2010-02-02 10:52 ` [Qemu-devel] Re: [PATCH 00/21] qemu-kvm: Hook cleanups and extended use of upstream code Alexander Graf
2010-02-02 11:19 ` Jan Kiszka
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=20100202123710.GD739@redhat.com \
--to=gleb@redhat.com \
--cc=agraf@suse.de \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=glommer@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--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).