From patchwork Wed Dec 7 07:19:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Evans X-Patchwork-Id: 129909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0D41A1007D7 for ; Wed, 7 Dec 2011 18:19:00 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752270Ab1LGHS6 (ORCPT ); Wed, 7 Dec 2011 02:18:58 -0500 Received: from ozlabs.org ([203.10.76.45]:56231 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751799Ab1LGHS5 (ORCPT ); Wed, 7 Dec 2011 02:18:57 -0500 Received: from [10.61.2.183] (ibmaus65.lnk.telstra.net [165.228.126.9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id D0FB11007D5; Wed, 7 Dec 2011 18:18:52 +1100 (EST) Message-ID: <4EDF138E.6040703@ozlabs.org> Date: Wed, 07 Dec 2011 18:19:42 +1100 From: Matt Evans User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 MIME-Version: 1.0 To: Sasha Levin CC: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, Alexander Graf Subject: Re: [PATCH 07/28] kvm tools: Move 'kvm__recommended_cpus' to arch-specific code References: <4EDD8E73.8040505@ozlabs.org> <1323159616.3882.7.camel@lappy> <4EDF04F4.40805@ozlabs.org> <1323239695.8489.25.camel@lappy> In-Reply-To: <1323239695.8489.25.camel@lappy> Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org On 07/12/11 17:34, Sasha Levin wrote: > On Wed, 2011-12-07 at 17:17 +1100, Matt Evans wrote: >> On 06/12/11 19:20, Sasha Levin wrote: >>> Why is it getting moved out of generic code? >>> >>> This is used to determine the maximum amount of vcpus supported by the >>> host for a single guest, and as far as I know KVM_CAP_NR_VCPUS and >>> KVM_CAP_MAX_VCPUS are not arch specific. >> >> I checked api.txt and you're right, it isn't arch-specific. I assumed it was, >> because PPC KVM doesn't support it ;-) I've dropped this patch and in its place >> implemented the api.txt suggestion of "if KVM_CAP_NR_VCPUS fails, use 4" instead >> of die(); you'll see that when I repost. >> >> This will have the effect of PPC being limited to 4 CPUs until the kernel >> supports that CAP. (I'll see about this part too.) > > I went to look at which limitation PPC places on amount of vcpus in > guest, and saw this in kvmppc_core_vcpu_create() in the book3s code: > > vcpu = kvmppc_core_vcpu_create(kvm, id); > vcpu->arch.wqp = &vcpu->wq; > if (!IS_ERR(vcpu)) > kvmppc_create_vcpu_debugfs(vcpu, id); > > This is wrong, right? The VCPU is dereferenced before actually checking > that it's not an error. Yeah, that's b0rk. Alex, a patch below. :) Cheers, Matt Signed-off-by: Matt Evans --- Subject: [PATCH] KVM: PPC: Fix vcpu_create dereference before validity check. Signed-off-by: Matt Evans --- arch/powerpc/kvm/powerpc.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 084d1c5..7c7220c 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -285,9 +285,10 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) { struct kvm_vcpu *vcpu; vcpu = kvmppc_core_vcpu_create(kvm, id); - vcpu->arch.wqp = &vcpu->wq; - if (!IS_ERR(vcpu)) + if (!IS_ERR(vcpu)) { + vcpu->arch.wqp = &vcpu->wq; kvmppc_create_vcpu_debugfs(vcpu, id); + } return vcpu; }