From patchwork Thu Sep 5 14:46:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 2854150 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B4819C0AB5 for ; Thu, 5 Sep 2013 14:47:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86A5920459 for ; Thu, 5 Sep 2013 14:47:47 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 285A220453 for ; Thu, 5 Sep 2013 14:47:46 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VHaqC-0000qz-BX; Thu, 05 Sep 2013 14:47:24 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VHaq5-0003nX-85; Thu, 05 Sep 2013 14:47:17 +0000 Received: from mail-pb0-f41.google.com ([209.85.160.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VHaq0-0003mE-9G for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2013 14:47:13 +0000 Received: by mail-pb0-f41.google.com with SMTP id rp2so1879095pbb.28 for ; Thu, 05 Sep 2013 07:46:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ydx2+eGtklr1jz9/mWw1koFA2Ohq8C770Xgixv7d0qo=; b=JgTl0ek1eDb9LbcwyT6PufI5Ybrh9kp+MfEUiNcG7mHq8IohaR7s5UH4+551vKbFis fbd/uwB0ucrQ9GXPGK+kHghYScEXfHg7s9SzlEWr4QrYZpqlJNWvdMDqWf1EbkjgLuuy bgAYhBpzv2nRvQkTMlO6nwoEcbjHTfAIyAB29WMgVX4Av356yCWesDHBQFDqeHL/+Ooi UZwa93MtoWFoP6DKigo8wqpiyghymb+LQMPkVi/RAxlv/RG3B93nPympOZ7MU5Azeci7 NY89mDVHD16/Fm6OPNrv8Y5D4/xxs3y+UL53E0z0Vypi2xN+TO6NZFm+35Z8ForvK7ye BYfQ== X-Gm-Message-State: ALoCoQn533SEXhW6QkrhPVZKXhMtu2fdFDO/r1krZGDLPADoBUBfnmlw9WpMu8kjv7GGUSn82e1O X-Received: by 10.68.254.5 with SMTP id ae5mr9822943pbd.40.1378392409447; Thu, 05 Sep 2013 07:46:49 -0700 (PDT) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id xs1sm38485325pac.7.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Sep 2013 07:46:48 -0700 (PDT) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 1/3] ARM: KVM: Implement target CPU=Host Date: Thu, 5 Sep 2013 20:16:00 +0530 Message-Id: <1378392362-6773-2-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1378392362-6773-1-git-send-email-anup.patel@linaro.org> References: <1378392362-6773-1-git-send-email-anup.patel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130905_104712_440538_D0942818 X-CRM114-Status: GOOD ( 14.68 ) X-Spam-Score: -2.6 (--) Cc: linaro-kernel@lists.linaro.org, Anup Patel , patches@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, christoffer.dall@linaro.org, pranavkumar@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 This patch implements KVM_ARM_TARGET_HOST for KVM ARM. If user space provides KVM_ARM_TARGET_HOST as target type in KVM_ARM_VCPU_INIT ioctl then we find out appropriate target type based on underlying host and return that to user space via struct kvm_vcpu_init. Signed-off-by: Anup Patel Signed-off-by: Pranavkumar Sawargaonkar Acked-by: Claudio Fontana --- arch/arm/include/asm/kvm_host.h | 2 +- arch/arm/include/uapi/asm/kvm.h | 1 + arch/arm/kvm/arm.c | 9 ++++++++- arch/arm/kvm/guest.c | 11 +++++++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 7d22517..3bb6c2b 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -153,7 +153,7 @@ struct kvm_vcpu_stat { struct kvm_vcpu_init; int kvm_vcpu_set_target(struct kvm_vcpu *vcpu, - const struct kvm_vcpu_init *init); + struct kvm_vcpu_init *init); unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu); int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); struct kvm_one_reg; diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index c1ee007..644012e 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -63,6 +63,7 @@ struct kvm_regs { /* Supported Processor Types */ #define KVM_ARM_TARGET_CORTEX_A15 0 +#define KVM_ARM_TARGET_HOST 0x0FFFFFFF #define KVM_ARM_NUM_TARGETS 1 /* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */ diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 741f66a..d8e494e 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -698,6 +698,7 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level, long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { + int err; struct kvm_vcpu *vcpu = filp->private_data; void __user *argp = (void __user *)arg; @@ -708,8 +709,14 @@ long kvm_arch_vcpu_ioctl(struct file *filp, if (copy_from_user(&init, argp, sizeof(init))) return -EFAULT; - return kvm_vcpu_set_target(vcpu, &init); + err = kvm_vcpu_set_target(vcpu, &init); + if (err) + return err; + + if (copy_to_user(argp, &init, sizeof(init))) + return -EFAULT; + return 0; } case KVM_SET_ONE_REG: case KVM_GET_ONE_REG: { diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c index 152d036..050df63 100644 --- a/arch/arm/kvm/guest.c +++ b/arch/arm/kvm/guest.c @@ -198,12 +198,19 @@ int __attribute_const__ kvm_target_cpu(void) } int kvm_vcpu_set_target(struct kvm_vcpu *vcpu, - const struct kvm_vcpu_init *init) + struct kvm_vcpu_init *init) { unsigned int i; + int phys_target = kvm_target_cpu(); + + if (phys_target < 0) { + return phys_target; + } /* We can only do a cortex A15 for now. */ - if (init->target != kvm_target_cpu()) + if (init->target == KVM_ARM_TARGET_HOST) + init->target = phys_target; + else if (init->target != phys_target) return -EINVAL; vcpu->arch.target = init->target;