From patchwork Mon Feb 18 19:52:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10818763 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 6D98A1390 for ; Mon, 18 Feb 2019 19:56:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 566362A03B for ; Mon, 18 Feb 2019 19:56:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 480852B7B2; Mon, 18 Feb 2019 19:56:57 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 B04E32A03B for ; Mon, 18 Feb 2019 19:56:56 +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=xteNDgrkPLYYoF4Hf/vnKOVxq95EKJjLF+CJ+j9AyEg=; b=JEzgYRQA+mpVfz35x4QkzJfvut e247CQEU9u81SJpUnF57GWxjNoAnzBmo7qnwbcJ1z3KRRpeyN6ytQ5i0kd3SkqoSvQra46TaP6T14 wLa/LEjC2GYMwe1TkbYpoood7xNm8IJaVzmi9GMPONLk/hMrPOwl5Ofqkfy4s6Bixttx2yZ0O87ur ywgz+4K3MoPrA2laRUcipRkCP3b5AilGDVfuROF+ei0p3htU1Bu5+/2PXOU+eN0y84HdF/g++2b+P R3AC6cuJXOiBXDrMHgYp0D5SWlpOI0k7g6gOITOcQw5O/QKRWANXkBuvqu9LlmnXrPRPWEHr1LAgK 4HmzBN/g==; 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 1gvp21-0008P5-6r; Mon, 18 Feb 2019 19:56:49 +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 1gvp00-0005Ck-Mx for linux-arm-kernel@bombadil.infradead.org; Mon, 18 Feb 2019 19:54:44 +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=qFmejAfScTZyZcZc5IW1S5jUQVxgh7WLALlBombMnb4=; b=LG75W+vSD22MMtAEtplPpykN/ zXBx/FcPWQwvfDKb5BsL9WTx/RpWkXZTyJw/C4DwWf7FAt3R+lGakSmu9yJOvJvxG59miKpgAR1NI 6taXNaNQM4QLkmbIpLoItkaFclP3WYMwB/3pF8soA5kMacfxAwuZJRIGuUl0NcVHYMjL3k3xiiaRI FTe0x2I6AsxpuCQBcH0dZNfP8/JBuTYZCNg+DX65YE6KXht+LGhoZ2RHmaewbyVMk83uKGgduzdf1 lmIKhxeVhBAjNsof64KY02yAMKCzZoiumbT/EsmH1OkuXu0RVB2EMot9M+3i0Ev8YJXTLMzaGn/zY OmLySNjfw==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gvozv-0003pZ-Fk for linux-arm-kernel@lists.infradead.org; Mon, 18 Feb 2019 19:54:42 +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 921A71C2B; Mon, 18 Feb 2019 11:54:14 -0800 (PST) Received: from e103592.cambridge.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 A3EB63FBA7; Mon, 18 Feb 2019 11:54:12 -0800 (PST) From: Dave Martin To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v5 21/26] KVM: arm/arm64: Add hook to finalize the vcpu configuration Date: Mon, 18 Feb 2019 19:52:34 +0000 Message-Id: <1550519559-15915-22-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1550519559-15915-1-git-send-email-Dave.Martin@arm.com> References: <1550519559-15915-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190218_145441_827989_DDACF79D X-CRM114-Status: GOOD ( 15.85 ) 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 , Zhang Lei , Julien Grall , =?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 Some aspects of vcpu configuration can't be completed inside KVM_VCPU_INIT, but still change API behaviour visible to userspace. Where such configuration choices affect the register list visible to userspace, we will need to track whether we have made a commitment to userspace regarding the list of vcpu registers. This patch adds a new hook kvm_arm_vcpu_finalize() to capture this commitment, along with a corresponding check kvm_arm_vcpu_finalized(). We commit to the register list when userspace reads it via KVM_GET_REG_LIST, or when the vcpu is fired up via KVM_RUN. kvm_arm_vcpu_finalize() is currently a no-op, but future patches will amend this to handle SVE on arm64. Signed-off-by: Dave Martin --- arch/arm/include/asm/kvm_host.h | 4 ++++ arch/arm64/include/asm/kvm_host.h | 4 ++++ virt/kvm/arm/arm.c | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index ca56537..ab7c76b 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -360,4 +360,8 @@ static inline int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type) return 0; } +/* Commit to the set of vcpu registers currently configured: */ +static inline int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu) { return 0; } +#define kvm_arm_vcpu_finalized(vcpu) true + #endif /* __ARM_KVM_HOST_H__ */ diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index d233855..015c2578 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -553,4 +553,8 @@ void kvm_arch_free_vm(struct kvm *kvm); int kvm_arm_setup_stage2(struct kvm *kvm, unsigned long type); +/* Commit to the set of vcpu registers currently configured: */ +static inline int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu) { return 0; } +#define kvm_arm_vcpu_finalized(vcpu) true + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 9e350fd3..12f9dc2 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -560,6 +560,10 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu) if (likely(vcpu->arch.has_run_once)) return 0; + ret = kvm_arm_vcpu_finalize(vcpu); + if (ret) + return ret; + vcpu->arch.has_run_once = true; if (likely(irqchip_in_kernel(kvm))) { @@ -1121,6 +1125,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp, if (unlikely(!kvm_vcpu_initialized(vcpu))) break; + r = kvm_arm_vcpu_finalize(vcpu); + if (r) + break; + r = -EFAULT; if (copy_from_user(®_list, user_list, sizeof(reg_list))) break;