From patchwork Mon May 5 09:00:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PranavkumarSawargaonkar X-Patchwork-Id: 29620 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6D5002055D for ; Mon, 5 May 2014 09:02:03 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id bj1sf8111231pad.3 for ; Mon, 05 May 2014 02:02:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=bI1ttVfRJKf16fhi4xaV4geQEVOe3yroias5E4z665s=; b=mX64o7XMC6GdfamzOpbEMpGke3kyMcbhZ5uKiwUj+z1THZ8z+ebE4ZeBp2NQTZpx+C aHH2c2RmnCqYR9CyuShtsySv+5ZKn5kVlkZIM8RCaMTSWPntWji0//4ffUhi8K4jJcF8 AcjOGcx9cgDRE7BOACg3/LyKX+54MnWODpHzAOdDNuZxtRzMOlCt2qsY19EkXeAwev7A AoCKk1LUViECwSObe7r0sIf759GIRdLDLSI1EU2vP+feADQtRJjjUx74tgGcH/bH+F5k oXHSdZiE/ba9jskN2aklleZ1YUEjjaaSHk0ZjJOJ3+0pjhlXH2pvS0jWBXXDCuY8QjDt SLhQ== X-Gm-Message-State: ALoCoQlxg9Yqhep7KvSo3zjCRFW+36cXvw8rmfv+161dnf9AaPPmE9wO1lW/HJfoSDYyr0smpVgT X-Received: by 10.66.232.229 with SMTP id tr5mr18807349pac.16.1399280522408; Mon, 05 May 2014 02:02:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.231 with SMTP id q94ls2330694qga.28.gmail; Mon, 05 May 2014 02:02:02 -0700 (PDT) X-Received: by 10.220.167.2 with SMTP id o2mr27359846vcy.8.1399280522264; Mon, 05 May 2014 02:02:02 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id jb7si1407745vec.197.2014.05.05.02.02.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 02:02:02 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id oz11so653387veb.17 for ; Mon, 05 May 2014 02:02:02 -0700 (PDT) X-Received: by 10.220.10.2 with SMTP id n2mr1676353vcn.26.1399280522186; Mon, 05 May 2014 02:02:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp124126vcb; Mon, 5 May 2014 02:02:01 -0700 (PDT) X-Received: by 10.140.40.81 with SMTP id w75mr2202299qgw.112.1399280521755; Mon, 05 May 2014 02:02:01 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e7si3065736qai.157.2014.05.05.02.02.01 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 05 May 2014 02:02:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:56108 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhEmf-0001wC-EM for patch@linaro.org; Mon, 05 May 2014 05:02:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhEmB-0001eH-MH for qemu-devel@nongnu.org; Mon, 05 May 2014 05:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhEm5-0008Ug-Pp for qemu-devel@nongnu.org; Mon, 05 May 2014 05:01:31 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:59325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhEm5-0008UP-8t for qemu-devel@nongnu.org; Mon, 05 May 2014 05:01:25 -0400 Received: by mail-pa0-f53.google.com with SMTP id kp14so4468485pab.26 for ; Mon, 05 May 2014 02:01:24 -0700 (PDT) X-Received: by 10.66.192.73 with SMTP id he9mr27059166pac.88.1399280484405; Mon, 05 May 2014 02:01:24 -0700 (PDT) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id qx11sm66590807pab.35.2014.05.05.02.01.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 02:01:22 -0700 (PDT) From: Pranavkumar Sawargaonkar To: qemu-devel@nongnu.org Date: Mon, 5 May 2014 14:30:45 +0530 Message-Id: <1399280445-25345-1-git-send-email-pranavkumar@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.53 Cc: peter.maydell@linaro.org, Anup Patel , patches@apm.com, robherring2@gmail.com, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, Pranavkumar Sawargaonkar Subject: [Qemu-devel] [RFC PATCH V4 5/6] target-arm: Common kvm_arm_vcpu_init() for KVM ARM and KVM ARM64 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pranavkumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Introduce a common kvm_arm_vcpu_init() for doing KVM_ARM_VCPU_INIT ioctl in KVM ARM and KVM ARM64. This also helps us factor-out few common code lines from kvm_arch_init_vcpu() for KVM ARM/ARM64. Signed-off-by: Pranavkumar Sawargaonkar Signed-off-by: Anup Patel --- target-arm/kvm.c | 23 +++++++++++++++++++++++ target-arm/kvm32.c | 18 +++--------------- target-arm/kvm64.c | 22 ++++++++-------------- target-arm/kvm_arm.h | 14 ++++++++++++++ 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 39202d7..55bc3a3 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -27,6 +27,29 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO }; +int kvm_arm_vcpu_init(CPUState *cs, uint32_t feature0_extra) +{ + ARMCPU *cpu = ARM_CPU(cs); + struct kvm_vcpu_init init; + + if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) { + fprintf(stderr, "KVM is not supported for this guest CPU type\n"); + return -EINVAL; + } + + init.target = cpu->kvm_target; + memset(init.features, 0, sizeof(init.features)); + if (cpu->start_powered_off) { + init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF; + } + if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) { + init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; + } + init.features[0] |= feature0_extra; + + return kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init); +} + bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, int *fdarray, struct kvm_vcpu_init *init) diff --git a/target-arm/kvm32.c b/target-arm/kvm32.c index cd9ac03..0034248 100644 --- a/target-arm/kvm32.c +++ b/target-arm/kvm32.c @@ -166,7 +166,6 @@ static int compare_u64(const void *a, const void *b) int kvm_arch_init_vcpu(CPUState *cs) { - struct kvm_vcpu_init init; int i, ret, arraylen; uint64_t v; struct kvm_one_reg r; @@ -174,23 +173,12 @@ int kvm_arch_init_vcpu(CPUState *cs) struct kvm_reg_list *rlp; ARMCPU *cpu = ARM_CPU(cs); - if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) { - fprintf(stderr, "KVM is not supported for this guest CPU type\n"); - return -EINVAL; - } - - init.target = cpu->kvm_target; - memset(init.features, 0, sizeof(init.features)); - if (cpu->start_powered_off) { - init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF; - } - if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) { - init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; - } - ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init); + /* Do KVM_ARM_VCPU_INIT ioctl */ + ret = kvm_arm_vcpu_init(cs, 0x0); if (ret) { return ret; } + /* Query the kernel to make sure it supports 32 VFP * registers: QEMU's "cortex-a15" CPU is always a * VFP-D32 core. The simplest way to do this is just diff --git a/target-arm/kvm64.c b/target-arm/kvm64.c index bc6cd74..f7cc3ef 100644 --- a/target-arm/kvm64.c +++ b/target-arm/kvm64.c @@ -77,29 +77,23 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUClass *ahcc) int kvm_arch_init_vcpu(CPUState *cs) { - ARMCPU *cpu = ARM_CPU(cs); - struct kvm_vcpu_init init; int ret; + ARMCPU *cpu = ARM_CPU(cs); - if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE || - !arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { - fprintf(stderr, "KVM is not supported for this guest CPU type\n"); + if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + fprintf(stderr, "KVM only support Aarch64 CPU type\n"); return -EINVAL; } - init.target = cpu->kvm_target; - memset(init.features, 0, sizeof(init.features)); - if (cpu->start_powered_off) { - init.features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF; - } - if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) { - init.features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; + /* Do KVM_ARM_VCPU_INIT ioctl */ + ret = kvm_arm_vcpu_init(cs, 0x0); + if (ret) { + return ret; } - ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init); /* TODO : support for save/restore/reset of system regs via tuple list */ - return ret; + return 0; } #define AARCH64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ diff --git a/target-arm/kvm_arm.h b/target-arm/kvm_arm.h index 137c567..1889ba1 100644 --- a/target-arm/kvm_arm.h +++ b/target-arm/kvm_arm.h @@ -15,6 +15,20 @@ #include "exec/memory.h" /** + * kvm_arm_vcpu_init: + * @cs: CPUState + * @feature0_extra: additional features + * + * KVM ARM and KVM ARM64 need to use KVM_ARM_VCPU_INIT ioctl for + * init/re-init/reset the VCPU with given feature flags. + * This is a common function for doing KVM_ARM_VCPU_INIT ioctl + * independent of KVM ARM or KVM ARM64. + * + * Returns: 0 if success else < 0 error code + */ +int kvm_arm_vcpu_init(CPUState *cs, uint32_t feature0_extra); + +/** * kvm_arm_register_device: * @mr: memory region for this device * @devid: the KVM device ID