From patchwork Wed Mar 30 14:57:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 8697641 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 24CE2C0553 for ; Wed, 30 Mar 2016 15:02:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 733AC20389 for ; Wed, 30 Mar 2016 15:02:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 05E2E2038A for ; Wed, 30 Mar 2016 15:02:18 +0000 (UTC) Received: from localhost ([::1]:54615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alHdR-0003iB-DF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Mar 2016 11:02:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alHZL-0004kE-QL for qemu-devel@nongnu.org; Wed, 30 Mar 2016 10:58:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alHZH-00052w-CT for qemu-devel@nongnu.org; Wed, 30 Mar 2016 10:58:03 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:56293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alHZH-00050z-52 for qemu-devel@nongnu.org; Wed, 30 Mar 2016 10:57:59 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1alHZE-0001D0-Vz for qemu-devel@nongnu.org; Wed, 30 Mar 2016 15:57:57 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Wed, 30 Mar 2016 15:57:47 +0100 Message-Id: <1459349869-25448-16-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459349869-25448-1-git-send-email-peter.maydell@linaro.org> References: <1459349869-25448-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 15/17] arm: enhance kvm_arm_create_scratch_host_vcpu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Xu Support passing NULL for the first parameter (with the same effect as passing an empty array) and for the third parameter (meaning that we should not attempt to init the vcpu). Signed-off-by: Peter Xu Acked-by: Sergey Fedorov Message-id: 1458788142-17509-3-git-send-email-peterx@redhat.com [PMM: tweaked commit message, comment] Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target-arm/kvm.c | 14 +++++++++++++- target-arm/kvm_arm.h | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 969ab0b..3671032 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -62,13 +62,18 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, goto err; } + if (!init) { + /* Caller doesn't want the VCPU to be initialized, so skip it */ + goto finish; + } + ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, init); if (ret >= 0) { ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, init); if (ret < 0) { goto err; } - } else { + } else if (cpus_to_try) { /* Old kernel which doesn't know about the * PREFERRED_TARGET ioctl: we know it will only support * creating one kind of guest CPU which is its preferred @@ -85,8 +90,15 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, if (ret < 0) { goto err; } + } else { + /* Treat a NULL cpus_to_try argument the same as an empty + * list, which means we will fail the call since this must + * be an old kernel which doesn't support PREFERRED_TARGET. + */ + goto err; } +finish: fdarray[0] = kvmfd; fdarray[1] = vmfd; fdarray[2] = cpufd; diff --git a/target-arm/kvm_arm.h b/target-arm/kvm_arm.h index 07f0c72..345233c 100644 --- a/target-arm/kvm_arm.h +++ b/target-arm/kvm_arm.h @@ -124,9 +124,12 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu); * kvm_arm_create_scratch_host_vcpu: * @cpus_to_try: array of QEMU_KVM_ARM_TARGET_* values (terminated with * QEMU_KVM_ARM_TARGET_NONE) to try as fallback if the kernel does not - * know the PREFERRED_TARGET ioctl + * know the PREFERRED_TARGET ioctl. Passing NULL is the same as passing + * an empty array. * @fdarray: filled in with kvmfd, vmfd, cpufd file descriptors in that order - * @init: filled in with the necessary values for creating a host vcpu + * @init: filled in with the necessary values for creating a host + * vcpu. If NULL is provided, will not init the vCPU (though the cpufd + * will still be set up). * * Create a scratch vcpu in its own VM of the type preferred by the host * kernel (as would be used for '-cpu host'), for purposes of probing it