From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] kvm: apic: set APIC base as part of kvm_apic_put
Date: Thu, 22 Sep 2016 16:09:27 +0100 [thread overview]
Message-ID: <20160922150927.GF2085@work-vm> (raw)
In-Reply-To: <1474556571-21200-3-git-send-email-pbonzini@redhat.com>
* Paolo Bonzini (pbonzini@redhat.com) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> The parsing of KVM_SET_LAPIC's input depends on the current value of the
> APIC base MSR---which indeed is stored in APICCommonState---but for historical
> reasons APIC base is set through KVM_SET_SREGS together with cr8 (which is
> really just the APIC TPR) and the actual "special CPU registers".
>
> APIC base must now be set before the actual LAPIC registers, so do that
> in kvm_apic_put. It will be set again to the same value with KVM_SET_SREGS,
> but that's not a big issue.
>
> This only happens since Linux 4.8, which checks for x2apic mode in
> KVM_SET_LAPIC. However it's really a QEMU bug; until the recent
> commit 78d6a05 ("x86/lapic: Load LAPIC state at post_load", 2016-09-13)
> QEMU was indeed setting APIC base (via KVM_SET_SREGS) before the other
> LAPIC registers.
I think you've posted the wrong version here; it's not the version I tested
and it's got two problems:
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> hw/i386/kvm/apic.c | 2 ++
> target-i386/kvm.c | 9 +++++++++
> target-i386/kvm_i386.h | 2 ++
> 3 files changed, 13 insertions(+)
>
> diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
> index feb0002..f57fed1 100644
> --- a/hw/i386/kvm/apic.c
> +++ b/hw/i386/kvm/apic.c
> @@ -15,6 +15,7 @@
> #include "hw/i386/apic_internal.h"
> #include "hw/pci/msi.h"
> #include "sysemu/kvm.h"
> +#include "target-i386/kvm_i386.h"
>
> static inline void kvm_apic_set_reg(struct kvm_lapic_state *kapic,
> int reg_id, uint32_t val)
> @@ -130,6 +131,7 @@ static void kvm_apic_put(void *data)
> struct kvm_lapic_state kapic;
> int ret;
>
> + kvm_put_apicbase(s->cpu, s->apicbase);
> kvm_put_apic_state(s, &kapic);
>
> ret = kvm_vcpu_ioctl(CPU(s->cpu), KVM_SET_LAPIC, &kapic);
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 38609fd..59242e4 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -1542,6 +1542,15 @@ static int kvm_put_one_msr(X86CPU *cpu, int index, uint64_t value)
> return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, cpu->kvm_msr_buf);
> }
>
> +void kvm_put_apicbase(X86CPU *cpu, uint64_t value)
> +{
> + CPUX86State *env = &cpu->env;
> + int ret;
> +
> + ret = kvm_put_one_msr(cpu, MSR_IA32_TSCDEADLINE, value);
That's not the MSR you wanted.
Dave
> + assert(ret == 1);
> +}
> +
> static int kvm_put_tscdeadline_msr(X86CPU *cpu)
> {
> CPUX86State *env = &cpu->env;
> diff --git a/target-i386/kvm_i386.h b/target-i386/kvm_i386.h
> index 42b00af..36407e0 100644
> --- a/target-i386/kvm_i386.h
> +++ b/target-i386/kvm_i386.h
> @@ -41,4 +41,6 @@ int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector,
> int kvm_device_msix_assign(KVMState *s, uint32_t dev_id);
> int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id);
>
> +void kvm_put_apicbase(X86CPU *cpu, uint64_t value);
> +
> #endif
> --
> 2.7.4
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2016-09-22 15:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 15:02 [Qemu-devel] [PATCH 0/2] kvm: fix incorrect LAPIC reset after reboot in x2apic mode Paolo Bonzini
2016-09-22 15:02 ` [Qemu-devel] [PATCH 1/2] target-i386: introduce kvm_put_one_msr Paolo Bonzini
2016-09-22 15:10 ` Dr. David Alan Gilbert
2016-09-22 15:02 ` [Qemu-devel] [PATCH 2/2] kvm: apic: set APIC base as part of kvm_apic_put Paolo Bonzini
2016-09-22 15:09 ` Dr. David Alan Gilbert [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-09-22 15:25 [Qemu-devel] [PATCH v2 0/2] kvm: fix incorrect LAPIC reset after reboot in x2apic mode Paolo Bonzini
2016-09-22 15:25 ` [Qemu-devel] [PATCH 2/2] kvm: apic: set APIC base as part of kvm_apic_put Paolo Bonzini
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=20160922150927.GF2085@work-vm \
--to=dgilbert@redhat.com \
--cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.