From patchwork Thu Jun 21 14:57:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10480037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AB058602CB for ; Thu, 21 Jun 2018 15:21:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 983EB28FDB for ; Thu, 21 Jun 2018 15:21:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C8822902D; Thu, 21 Jun 2018 15:21:11 +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 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 157B928FDB for ; Thu, 21 Jun 2018 15:21:11 +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=8tzpJYRD6yZZ/SvOswyuZVMZ8xP0QRa1skaKZghw1mo=; b=JINkSxLzhGK3XYLKCS+eP7ph2c dFj6gL+TsK7icYhHkCDRu4Ihacj19/2KHkMnfT0LOp30HEvIJSGoQjpWXhzigPcmsQ/lZ1fID4Wfp VZBVBxak3t34izhHTJNXeF76uMKklQ5ZWTTcfXSY8jxjwKPyd/+o9i2z9/1pmx1YQW5m+GZpRhrQO pfNarEb2lvN5Zp/b5X7vda9z1NOSGp+XH6qwWnY4n+6UWg/aoQ/PPurQINePwdI/zDAqsLo3mnodS 3OGpQO3CPnkM3fHaNcYwo7rXxdYi+3m668MKvl6LQVfeAEkDV8+a2P3eYoKP/4w6BatR8Nr3iTn+v RGUkyG7A==; 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 1fW1OM-0002cx-Q9; Thu, 21 Jun 2018 15:20:58 +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 1fW1NR-0000uR-JY for linux-arm-kernel@bombadil.infradead.org; Thu, 21 Jun 2018 15:20:01 +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=ltlXds4C7hSA462duvDEpueEodS/5A+etwh9xYlQpbk=; b=gvCaVjE0iecmjfVB7yKbMRAuQ CgpFZ65CLIJYdJuxlkMqpKL0eyZl45oXPciijRfmLHE1706LfWsDnpPeSAbmD2onFDNLAQ97GzfQL c/4fo2lbx30SieKEKRXG0o6RmiUiEV0DqRbbSHjE7SSr6SbqKyYF+TGFjSMHy/bPuY1IxPxkI+PoC YYlOxw/cFOPXq5FL5vc+LIDC3BaT+va4ykqJS1RdghKWYw74DDtaRkKb5iTHBYG6JM1Gyo4gvYUxs 9j5tk0UVAOWOPDCJLRxktd0YKQErP6FeA7wSmeOP74qj9ZAhtnwo2vp3iLvoG7bk5PTEovZkSqY+W hjwy0YP2Q==; Received: from foss.arm.com ([217.140.101.70]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fW132-0007k8-7e for linux-arm-kernel@lists.infradead.org; Thu, 21 Jun 2018 14:59:01 +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 A61CB15BF; Thu, 21 Jun 2018 07:58:42 -0700 (PDT) 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 0AA9A3F246; Thu, 21 Jun 2018 07:58:40 -0700 (PDT) From: Dave Martin To: kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH 05/16] KVM: arm: Add arch init/uninit hooks Date: Thu, 21 Jun 2018 15:57:29 +0100 Message-Id: <1529593060-542-6-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1529593060-542-1-git-send-email-Dave.Martin@arm.com> References: <1529593060-542-1-git-send-email-Dave.Martin@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180621_105856_414302_98B15F0D X-CRM114-Status: GOOD ( 16.34 ) 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=20Benn=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 In preparation for adding support for SVE in guests on arm64, hooks for allocating and freeing additional per-vcpu memory are needed. kvm_arch_vcpu_setup() could be used for allocation, but this function is not clearly balanced by un "unsetup" function, making it unclear where memory allocated in this function should be freed. To keep things simple, this patch defines backend hooks kvm_arm_arch_vcpu_{,un}unint(), and plumbs them in appropriately. The exusting kvm_arch_vcpu_init() function now calls kvm_arm_arch_vcpu_init(), while an explicit kvm_arch_vcpu_uninit() is added which current does nothing except to call kvm_arm_arch_vcpu_uninit(). The backend functions are currently defined to do nothing. No functional change. 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 | 13 ++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 1f1fe410..9b902b8 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -284,10 +284,12 @@ struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr); static inline bool kvm_arch_check_sve_has_vhe(void) { return true; } static inline void kvm_arch_hardware_unsetup(void) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} -static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} +static inline int kvm_arm_arch_vcpu_init(struct kvm_vcpu *vcpu) { return 0; } +static inline void kvm_arm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} + static inline void kvm_arm_init_debug(void) {} static inline void kvm_arm_setup_debug(struct kvm_vcpu *vcpu) {} static inline void kvm_arm_clear_debug(struct kvm_vcpu *vcpu) {} diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 92d6e88..9671ddd 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -425,10 +425,12 @@ static inline bool kvm_arch_check_sve_has_vhe(void) static inline void kvm_arch_hardware_unsetup(void) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} -static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} +static inline int kvm_arm_arch_vcpu_init(struct kvm_vcpu *vcpu) { return 0; } +static inline void kvm_arm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {} + void kvm_arm_init_debug(void); void kvm_arm_setup_debug(struct kvm_vcpu *vcpu); void kvm_arm_clear_debug(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 04e554c..66f15cc 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -345,6 +345,8 @@ void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) { + int ret; + /* Force users to call KVM_ARM_VCPU_INIT */ vcpu->arch.target = -1; bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES); @@ -354,7 +356,16 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) kvm_arm_reset_debug_ptr(vcpu); - return kvm_vgic_vcpu_init(vcpu); + ret = kvm_vgic_vcpu_init(vcpu); + if (ret) + return ret; + + return kvm_arm_arch_vcpu_init(vcpu); +} + +void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) +{ + kvm_arm_arch_vcpu_uninit(vcpu); } void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)