From patchwork Thu Apr 11 16:36:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 2429641 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 068553FDC4 for ; Thu, 11 Apr 2013 16:38:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934008Ab3DKQiP (ORCPT ); Thu, 11 Apr 2013 12:38:15 -0400 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:64792 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756084Ab3DKQgr (ORCPT ); Thu, 11 Apr 2013 12:36:47 -0400 Received: from mudshark.cambridge.arm.com (mudshark.cambridge.arm.com [10.1.79.58]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id r3BGadki007861; Thu, 11 Apr 2013 17:36:39 +0100 (BST) Received: by mudshark.cambridge.arm.com (Postfix, from userid 1000) id 27026C2A93; Thu, 11 Apr 2013 17:36:27 +0100 (BST) From: Will Deacon To: kvm@vger.kernel.org Cc: penberg@kernel.org, sasha.levin@oracle.com, marc.zyngier@arm.com, Marc Zyngier , Will Deacon Subject: [PATCH 1/5] kvm tools: arm: don't crash when no compatible CPU is found Date: Thu, 11 Apr 2013 17:36:22 +0100 Message-Id: <1365698186-27355-2-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1365698186-27355-1-git-send-email-will.deacon@arm.com> References: <1365698186-27355-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Marc Zyngier If the kernel against which kvm tools was compiled supports more CPU types than kvm tools does, then we can hit a situation where we dereference an empty target slot. Just stepping over empty slots fixes the issue. Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon --- tools/kvm/arm/kvm-cpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c index 7a0eff45..2716690 100644 --- a/tools/kvm/arm/kvm-cpu.c +++ b/tools/kvm/arm/kvm-cpu.c @@ -56,6 +56,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) /* Find an appropriate target CPU type. */ for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) { + if (!kvm_arm_targets[i]) + continue; vcpu_init.target = kvm_arm_targets[i]->id; err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); if (!err)