From patchwork Fri Jan 12 12:07:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160481 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 38123602D8 for ; Fri, 12 Jan 2018 12:09:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AC5328876 for ; Fri, 12 Jan 2018 12:09:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EEDD28518; Fri, 12 Jan 2018 12:09: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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 86EF728518 for ; Fri, 12 Jan 2018 12:09: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=iKysuf2rKKQeQJVAACck5NZ5sYUGeezHXfWXMkcPlc4=; b=cFMwPvrXDlJhlawWRtcCgsBLU0 OIQFOG93DP1QgpLp88iWYEm0seDAHIsnwMLR2RAfswb4tePaZWLcVKfWYYuiqXoEo94rEWSl3YOom GPGLl0UiIrmvYlO5biJhiW6ABCrYFjaZ2NksdxFdiWMVVo2uHAtQo3Snu5qLI0shjepNJRUQSolLq RT3+x+miKT1yXFSyF1AbKnjuJXMtWwhetn98ZzBh/+88ryEQ3irNH/qL6VSbJi4k7fZYCteoJAm5f Xp6aQbYPnKr7yPZea9EKdJvkgy26qokQ/Hbi+iTy9sJdMxSUerOPuXbzF9rJYTXT4olimZSTfhCA0 ht83fZmQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZy9h-0002GR-Bq; Fri, 12 Jan 2018 12:09:53 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZy80-0008Su-J3 for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:08:21 +0000 Received: by mail-wm0-x242.google.com with SMTP id g1so11609925wmg.2 for ; Fri, 12 Jan 2018 04:08:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WWARp+CGSJKBMM0KsTg3J3Qk58u+pTqHd09M0YCpHUk=; b=Vi5xQtTsoTGAVpBG0tMIj9v/t1pf1kuWN/ZfYRHQBp2M7y0VUxX6WyuvI2HkcpZjGk QmhFtG6BwVYvHeb0tsdHF6Oxl3EoAKur3jTg3rCJGRFRrTra4crI71KjmdO3HckdpJ09 S/pbNEBgdhHwfOKYz3Ltl7TdkTTcqN6X22ocs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WWARp+CGSJKBMM0KsTg3J3Qk58u+pTqHd09M0YCpHUk=; b=Txt1VApGxVdkaKIlqvEpOdT61WLHNs7cwVJRvxHLL5KDPgxOQR5LU7tmtCtUoerhP7 AcTY5QYQ+nBU29+VOIIVfPo7IlmlzkrE0KIdo5JJgNVgWaEEA+tyKIDAFqRJbqaFlydj kr7tAW/2Av3YXyVwt3840oIoof9yDbfolDE4nHKwGUjqf8sLshmz/SqhZn+f9rKtecvG 3gEfdW9siPlFQbOMQXFG+teW+jBzq5GOe6fo0OS7RQytwuxdzPj9Fpc9h3J0jJpWJ7lT fga/YAStaFwtLcu47Re6Pqj4bEbvMUn7tkM/K0ee/xlGPOc7/vPC+uji2DmjT1W7JlXy VmWg== X-Gm-Message-State: AKwxytcoC/QU5eYJ5uW/G783dKaDy2HYCiRdBoC+nzZ0qY+SH+OGDHfm QqnSv56nkT4JolciFnIbse1Ngg== X-Google-Smtp-Source: ACJfBovtkk0naxhnpFQff05UGWAvBYAKQ6lxz8sQZTU1+B4iHnpJrRT3pGlC61IOjtoUof2taqRV9w== X-Received: by 10.80.153.194 with SMTP id n2mr17146133edb.303.1515758881898; Fri, 12 Jan 2018 04:08:01 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f16sm13489705edj.65.2018.01.12.04.08.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:00 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 07/41] KVM: arm/arm64: Add kvm_vcpu_load_sysregs and kvm_vcpu_put_sysregs Date: Fri, 12 Jan 2018 13:07:13 +0100 Message-Id: <20180112120747.27999-8-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180112120747.27999-1-christoffer.dall@linaro.org> References: <20180112120747.27999-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180112_040808_823773_38E83EF4 X-CRM114-Status: GOOD ( 12.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: Marc Zyngier , Andrew Jones , Christoffer Dall , Shih-Wei Li , kvm@vger.kernel.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 As we are about to move a bunch of save/restore logic for VHE kernels to the load and put functions, we need some infrastructure to do this. Reviewed-by: Andrew Jones Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm/include/asm/kvm_host.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/hyp/sysreg-sr.c | 30 ++++++++++++++++++++++++++++++ virt/kvm/arm/arm.c | 2 ++ 4 files changed, 38 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 7f96b3541939..793b3bc5a56c 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -300,4 +300,7 @@ int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu, /* All host FP/SIMD state is restored on guest exit, so nothing to save: */ static inline void kvm_fpsimd_flush_cpu_state(void) {} +static inline void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) {} +static inline void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) {} + #endif /* __ARM_KVM_HOST_H__ */ diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 59150c75f9a5..0e9e7291a7e6 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -412,4 +412,7 @@ static inline void kvm_fpsimd_flush_cpu_state(void) sve_flush_cpu_state(); } +void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu); +void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu); + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index e19d89cabf2a..cbbcd6f410a8 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -184,6 +184,36 @@ void __hyp_text __sysreg32_restore_state(struct kvm_vcpu *vcpu) write_sysreg(sysreg[DBGVCR32_EL2], dbgvcr32_el2); } +/** + * kvm_vcpu_load_sysregs - Load guest system registers to the physical CPU + * + * @vcpu: The VCPU pointer + * + * Load system registers that do not affect the host's execution, for + * example EL1 system registers on a VHE system where the host kernel + * runs at EL2. This function is called from KVM's vcpu_load() function + * and loading system register state early avoids having to load them on + * every entry to the VM. + */ +void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) +{ +} + +/** + * kvm_vcpu_put_sysregs - Restore host system registers to the physical CPU + * + * @vcpu: The VCPU pointer + * + * Save guest system registers that do not affect the host's execution, for + * example EL1 system registers on a VHE system where the host kernel + * runs at EL2. This function is called from KVM's vcpu_put() function + * and deferring saving system register state until we're no longer running the + * VCPU avoids having to save them on every exit from the VM. + */ +void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) +{ +} + void __hyp_text __kvm_set_tpidr_el2(u64 tpidr_el2) { asm("msr tpidr_el2, %0": : "r" (tpidr_el2)); diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 46c125f1da56..5b1487bd91e8 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -361,10 +361,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) kvm_arm_set_running_vcpu(vcpu); kvm_vgic_load(vcpu); kvm_timer_vcpu_load(vcpu); + kvm_vcpu_load_sysregs(vcpu); } void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { + kvm_vcpu_put_sysregs(vcpu); kvm_timer_vcpu_put(vcpu); kvm_vgic_put(vcpu);