From: Marcelo Tosatti <mtosatti@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: avi@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH RFC 3/3] Break dependency between vcpu index in vcpus array and vcpu's apic id.
Date: Thu, 21 May 2009 15:21:45 -0300 [thread overview]
Message-ID: <20090521182145.GA11828@amt.cnet> (raw)
In-Reply-To: <1242910606-29286-4-git-send-email-gleb@redhat.com>
On Thu, May 21, 2009 at 03:56:46PM +0300, Gleb Natapov wrote:
> Move decision on how to store vcpus into arch code. X86 finds first free
> slot in vcpus array and uses id that userspace pass as vcpu's apic id.
> Other arches keep using it as array index for now.
>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> ---
> arch/ia64/kvm/kvm-ia64.c | 25 ++++++++++++++++++---
> arch/powerpc/kvm/booke.c | 20 ++++++++++++++++-
> arch/powerpc/kvm/powerpc.c | 7 +++++-
> arch/s390/kvm/kvm-s390.c | 24 ++++++++++++++++++--
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/lapic.c | 4 +-
> arch/x86/kvm/x86.c | 45 ++++++++++++++++++++++++++++++++++++++-
> include/linux/kvm_host.h | 7 +++++-
> virt/kvm/kvm_main.c | 27 +---------------------
> 9 files changed, 122 insertions(+), 38 deletions(-)
>
> diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
> index 8a5911c..575765c 100644
> --- a/arch/ia64/kvm/kvm-ia64.c
> +++ b/arch/ia64/kvm/kvm-ia64.c
> @@ -1200,7 +1200,7 @@ out:
>
> #define PALE_RESET_ENTRY 0x80000000ffffffb0UL
>
> -int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
> +int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu, u32 id)
> {
> struct kvm_vcpu *v;
> int r;
> @@ -1212,6 +1212,8 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
> union context *p_ctx = &vcpu->arch.guest;
> struct kvm_vcpu *vmm_vcpu = to_guest(vcpu->kvm, vcpu);
>
> + vcpu->vcpu_id = id;
> +
> /*Init vcpu context for first run.*/
> if (IS_ERR(vmm_vcpu))
> return PTR_ERR(vmm_vcpu);
> @@ -1321,8 +1323,7 @@ fail:
> return r;
> }
>
> -struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
> - unsigned int id)
> +struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
> {
> struct kvm_vcpu *vcpu;
> unsigned long vm_base = kvm->arch.vm_base;
> @@ -1332,6 +1333,9 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
> BUG_ON(sizeof(struct kvm_vcpu) > VCPU_STRUCT_SIZE/2);
>
> r = -EINVAL;
> + if (!valid_vcpu_idx(id))
> + goto fail;
> +
> if (id >= KVM_MAX_VCPUS) {
> printk(KERN_ERR"kvm: Can't configure vcpus > %ld",
> KVM_MAX_VCPUS);
> @@ -1365,6 +1369,19 @@ fail:
>
> int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> {
> + struct kvm *kvm = vcpu->kvm;
> +
> + mutex_lock(&kvm->lock);
> + if (kvm->vcpus[vcpu->vcpu_id]) {
> + mutex_unlock(&kvm->lock);
> + kvm_arch_vcpu_destroy(vcpu);
> + return -EEXIST;
> + }
> + /* first one created is BSP */
> + if (!kvm->bsp_vcpu)
> + kvm->bsp_vcpu = vcpu;
> + kvm->vcpus[vcpu->vcpu_id] = vcpu;
> + mutex_unlock(&kvm->lock);
Why don't make a convention that vcpu_id 0 is the BSP, by default,
instead of the first vcpu created? This way if userspace creates vcpu 3
first, there are no problems.
That brings the question, why is the apic_id passed as the argument to
vcpu_create? It seems that the argument to vcpu_create should be the
kVM's internal vcpu_id, and the apic_id should come from somewhere else,
apic_mmio_write maybe?
AFAICS there is no linkage between apic_id and BSP (MP SPEC says BSP
is determined by hardware and BIOS), but in KVM's BIOS case the BSP is
conventioned to be vcpu with vcpu_id == 0, no?
Another thing, it would be better if the linking of the vcpu in the
array could be in arch independent code as it is today?
next prev parent reply other threads:[~2009-05-21 18:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-21 12:56 [PATCH RFC 0/3] decouple vcpu index from apic id Gleb Natapov
2009-05-21 12:56 ` [PATCH RFC 1/3] Introduce kvm_vcpu_is_bsp() function Gleb Natapov
2009-05-21 12:56 ` [PATCH RFC 2/3] Use pointer to vcpu instead of vcpu_id in timer code Gleb Natapov
2009-05-21 12:56 ` [PATCH RFC 3/3] Break dependency between vcpu index in vcpus array and vcpu's apic id Gleb Natapov
2009-05-21 18:21 ` Marcelo Tosatti [this message]
2009-05-21 20:06 ` Gleb Natapov
2009-05-21 20:29 ` Marcelo Tosatti
2009-05-22 11:41 ` Gleb Natapov
2009-05-28 3:47 ` Marcelo Tosatti
2009-05-28 5:11 ` Gleb Natapov
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=20090521182145.GA11828@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.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.