From patchwork Fri Sep 28 13:39:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10619995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45551913 for ; Fri, 28 Sep 2018 13:55:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35B942B549 for ; Fri, 28 Sep 2018 13:55:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29C0C2B5A7; Fri, 28 Sep 2018 13:55:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B27822B549 for ; Fri, 28 Sep 2018 13:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NRcw/kHXDddMlFx9jumgrF4Lu8OBu2vTGAmQ3ZpqLTI=; b=lPpzYnAu/KSdpaTB2AtLGYDWjs lfbZWWlaBT+rVGeQxC4JarXVj/addardGd9uL8MIW82PEZceCjfiIVvEQXKvBeWG+wGzYpuDAI4UC su1b9129UY2MvIn0rDbna5+i1n1bIdhQIhc/bddaaX7EM2gRIGoIATGZUTmOVupg53t2cETgOberE AlqHn7QavhnXPI0ftzpE9PW+Xf+p57EyNuLLR89gpaTOHFGn5wsWrBix18XDw2oKU+nClB9lP4T4p 6uluwsXkX80eYYvDsNVjCybEhwr2nZmtKoEi/XdpwgvVHP9q1xc951CwNW/6xs8/x/moQgn+/g/OZ 4A1m/2qQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5tF8-0000qE-U4; Fri, 28 Sep 2018 13:55:42 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5t0t-0007ym-Qg for linux-arm-kernel@bombadil.infradead.org; Fri, 28 Sep 2018 13:40:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6FmEBkjdHqGIqbZGAwdtkgaMvmzVImq7/iROJIbF4ts=; b=w1DrOOG1McbEsTtuPug35zufi Rhdb6nMPnK7Oeh1ZNfW9BQdhzcJQHZ+BlnWnYNB4fSELYa45E23t3si769InIugOquDgw4xLbHtHI 7kXbNhlgslqpiFQRHK9r1nHqP+f5QFnL4LNCY7igAVm2oBqcWaawlCBLUvdFsc8/862xTZE7q1e8t bmmFB8kacMjGkgRjPqKf7KpqWL7mKg+2VtR9hjPXkNnsZb52j6fLV0ftmffXop02Z608OWi/YuWsU k/prk9PkPF0VXKgoYIayqZyGN1UqcTQIYwHVFsLeXY1wOnQuT65utJswPxQOsFqAW3lUMwUBWy9CU hHbn6wABw==; Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5t0r-00077c-4Y for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 13:40:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 07A89ED1; Fri, 28 Sep 2018 06:40:57 -0700 (PDT) Received: from e103592.Emea.Arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 503213F5B7; Fri, 28 Sep 2018 06:40:55 -0700 (PDT) From: Dave Martin To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH v2 21/23] KVM: arm64/sve: allow KVM_ARM_SVE_CONFIG_QUERY on vm fd Date: Fri, 28 Sep 2018 14:39:25 +0100 Message-Id: <1538141967-15375-22-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1538141967-15375-1-git-send-email-Dave.Martin@arm.com> References: <1538141967-15375-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180928_094057_274199_CF620CBB X-CRM114-Status: GOOD ( 18.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Okamoto Takayuki , Christoffer Dall , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , =?utf-8?q?Alex_Benn=C3=A9e?= , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since userspace may need to decide on the set of vector lengths for the guest before setting up a vm, it is onerous to require a vcpu fd to be available first. KVM_ARM_SVE_CONFIG_QUERY is not vcpu-dependent anyway, so this patch wires up KVM_ARM_SVE_CONFIG to be usable on a vm fd where appropriate. Subcommands that are vcpu-dependent (currently KVM_ARM_SVE_CONFIG_SET, KVM_ARM_SVE_CONFIG_GET) will return -EINVAL if invoked on a vm fd. Signed-off-by: Dave Martin --- arch/arm64/kvm/guest.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index f066b17..2313c22 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -574,6 +574,9 @@ static int kvm_vcpu_set_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls, unsigned int vq, max_vq; int ret; + if (!vcpu) + return -EINVAL; /* per-vcpu operation on vm fd */ + if (vcpu->arch.has_run_once || vcpu_has_sve(vcpu)) return -EBADFD; /* too late, or already configured */ @@ -659,6 +662,9 @@ static int kvm_vcpu_query_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls static int kvm_vcpu_get_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls, struct kvm_sve_vls __user *userp) { + if (!vcpu) + return -EINVAL; /* per-vcpu operation on vm fd */ + if (!vcpu_has_sve(vcpu)) return -EBADFD; /* not configured yet */ @@ -668,6 +674,7 @@ static int kvm_vcpu_get_sve_vls(struct kvm_vcpu *vcpu, struct kvm_sve_vls *vls, sve_vq_from_vl(vcpu->arch.sve_max_vl), userp); } +/* vcpu may be NULL if this is called via a vm fd */ static int kvm_vcpu_sve_config(struct kvm_vcpu *vcpu, struct kvm_sve_vls __user *userp) { @@ -717,7 +724,15 @@ int kvm_arm_arch_vcpu_ioctl(struct kvm_vcpu *vcpu, int kvm_arm_arch_vm_ioctl(struct kvm *kvm, unsigned int ioctl, unsigned long arg) { - return -EINVAL; + void __user *userp = (void __user *)arg; + + switch (ioctl) { + case KVM_ARM_SVE_CONFIG: + return kvm_vcpu_sve_config(NULL, userp); + + default: + return -EINVAL; + } } int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)