From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH RFC v2 1/4] Introduce kvm_vcpu_is_bsp() function. Date: Tue, 26 May 2009 09:12:07 +0300 Message-ID: <20090526061207.GK3948@redhat.com> References: <1243266636-16914-1-git-send-email-gleb@redhat.com> <1243266636-16914-2-git-send-email-gleb@redhat.com> <20090525204622.GA7890@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from mx2.redhat.com ([66.187.237.31]:36573 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753361AbZEZGMH (ORCPT ); Tue, 26 May 2009 02:12:07 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4Q6C9Kv027258 for ; Tue, 26 May 2009 02:12:09 -0400 Content-Disposition: inline In-Reply-To: <20090525204622.GA7890@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, May 25, 2009 at 05:46:22PM -0300, Marcelo Tosatti wrote: > On Mon, May 25, 2009 at 06:50:33PM +0300, Gleb Natapov wrote: > > Use it instead of open code "vcpu_id zero is BSP" assumption. > > > > Signed-off-by: Gleb Natapov > > --- > > arch/ia64/kvm/kvm-ia64.c | 2 +- > > arch/ia64/kvm/vcpu.c | 2 +- > > arch/x86/kvm/i8254.c | 4 ++-- > > arch/x86/kvm/i8259.c | 6 +++--- > > arch/x86/kvm/lapic.c | 7 ++++--- > > arch/x86/kvm/svm.c | 4 ++-- > > arch/x86/kvm/vmx.c | 6 +++--- > > arch/x86/kvm/x86.c | 4 ++-- > > include/linux/kvm_host.h | 5 +++++ > > virt/kvm/ioapic.c | 4 +++- > > virt/kvm/kvm_main.c | 2 ++ > > 11 files changed, 28 insertions(+), 18 deletions(-) > > > > #endif > > diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c > > index 1eddae9..a8a8252 100644 > > --- a/virt/kvm/ioapic.c > > +++ b/virt/kvm/ioapic.c > > @@ -165,7 +165,9 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) > > /* Always delivery PIT interrupt to vcpu 0 */ > > if (irq == 0) { > > irqe.dest_mode = 0; /* Physical mode. */ > > - irqe.dest_id = ioapic->kvm->vcpus[0]->vcpu_id; > > + /* need to read apic_id from apic regiest since > > + * it can be rewritten */ > > + irqe.dest_id = ioapic->kvm->bsp_vcpu->vcpu_id; > > } > > Won't this oops if userspace creates only vcpu 3 and attempts to deliver > to IRQ0 ? (not directly related to the patchset though). I doesn't oops since if BSP is not created this code is not reached (nothing runs eventually). But see below. > > Also you said "The code still assumes that boot cpu is created first." > Where is that? > Oops. It should be like this, but this patch series has a bug. In kvm_vm_ioctl_create_vcpu: if (id == 0) kvm->bsp_vcpu = vcpu; should be: if (!kvm->bsp_vcpu) kvm->bsp_vcpu = vcpu; I really don't want to make acpi_id zero to be special. > Otherwise, neat! > > > #endif > > return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe); > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > index de042cb..5a55fe0 100644 > > --- a/virt/kvm/kvm_main.c > > +++ b/virt/kvm/kvm_main.c > > @@ -1737,6 +1737,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n) > > goto vcpu_destroy; > > } > > kvm->vcpus[n] = vcpu; > > + if (n == 0) > > + kvm->bsp_vcpu = vcpu; > > mutex_unlock(&kvm->lock); > > > > /* Now it's all set up, let userspace reach it */ > > -- > > 1.6.2.1 > > > > -- > > To unsubscribe from this list: send the line "unsubscribe kvm" in > > the body of a message to majordomo@vger.kernel.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Gleb.