From patchwork Thu Dec 7 17:05:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10100219 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 024AB6056F for ; Thu, 7 Dec 2017 17:08:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF39A284B5 for ; Thu, 7 Dec 2017 17:08:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3E15284CE; Thu, 7 Dec 2017 17:08:28 +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=ham 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 6AD40284DE for ; Thu, 7 Dec 2017 17:08:28 +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=zlsc3StiFkkXOnOXvDj7LPAPKOgcoul8IxgY7M/9TAI=; b=FYhISoXD4N8+COA5UM3P8KHBvY RRxXYc9uAKkdlilMltrze7sYMrvS1phXyF5ZHXZTlhSoXouypQfLbNelKu/2qy6t3K4fEeDOqF0qy NKsriXj2KBj1AUMSVCeL8UZA3SEcpWJ6Je7PKN/6sa5qVmP6IoPQQgirXT9l53zTjZj8uiSCezofl I8c4xcPZIgrtTX2MbaQf0p9CFMi8X1EG63sKcubuHfuqTRld73JrbC64xR1MP0R/QnvmsLw8DBrmi bHgctHpMPnQUh2tlYLWHg3LOqNXyAErkljUG9cjhh+02DLQeG4QAj4ovdig/YiPK6xAN3aJGIaJCq 04IYgWAA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMzet-0004MG-BJ; Thu, 07 Dec 2017 17:08:27 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMzdb-0002md-RU for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 17:07:10 +0000 Received: by mail-wm0-x242.google.com with SMTP id 9so14259747wme.4 for ; Thu, 07 Dec 2017 09:06:49 -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=lRmG1T3dezYzSPe1XMo1Ey++xsHZi3qNOlnrdli6Nak=; b=XqLJHCWkUFi1mjgsnSZY1Yg7MY4FhzjRPvj1LEsgATSYquGdlET02r3V0XN9czIQz/ 4OEzFdBeOLyUvXrg7AAEdsGZrGcXi+oultq+zF8HJi4PrEy4Wy5iNwzhQo0j0Qe3tjCx b65JBkOics+oOiPeg3+VvKznpfcC/94/GVBZU= 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=lRmG1T3dezYzSPe1XMo1Ey++xsHZi3qNOlnrdli6Nak=; b=c8mm+iqaz/ndFq7E4CzWPlp+n7Y4rODyfr1t8UDyRaotQDZGwzNYNWJgfhGWV8we6u OWZT3HaBLZ9COh3I7DZ5xp8vAecTr1cUmrivZD5hzvWp2PBtSwopRPaITbv8/A+E1/Or DwJMJmquBB2q5a1nuuxGvz3Gp0fwkwb5bhETRO4zWrneMQStU24yUVgB/TktwFFuZfRO ujjIhcRAEtp5IhSvfdA2zJDP+9+8G2Y5JFM8crHkH2ZeE9v575tDMz8oULeeuVPoO6Qw oH1e292QcArGdWlnT6S19TptJkaMTPcQMn7rmbvDK0dtCUdImlJzTKQDcNa8TT8t8UMr wJmw== X-Gm-Message-State: AJaThX5zBYHdTV72Uq1k8hZwd68MUkl4wcsN7JmvBwrHw5IDjc6IZMf+ Pem3CoA1pdwy35cKHFUF3CTW8w== X-Google-Smtp-Source: AGs4zMZLlDsEtM7GaqKj70GWsozss67yV2tAEyd76fcRMRuHq3FyYiu0f12rfr40nLshJHl/5s+H1w== X-Received: by 10.80.207.193 with SMTP id i1mr31615375edk.55.1512666408169; Thu, 07 Dec 2017 09:06:48 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id a16sm2868270edd.19.2017.12.07.09.06.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 09:06:45 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 05/36] KVM: arm/arm64: Add kvm_vcpu_load_sysregs and kvm_vcpu_put_sysregs Date: Thu, 7 Dec 2017 18:05:59 +0100 Message-Id: <20171207170630.592-6-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207170630.592-1-christoffer.dall@linaro.org> References: <20171207170630.592-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171207_090708_082461_F69FBDCD X-CRM114-Status: GOOD ( 12.45 ) 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 Signed-off-by: Christoffer Dall Acked-by: Marc Zyngier --- Notes: Changes since v1: - Reworded comments as suggested by Drew 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 b92d2bcb3c08..8fce576199e0 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -298,4 +298,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 d85c1e6ec53f..20fab9194794 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -410,4 +410,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 e5a5cf0d17fe..3e10343374a1 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -357,10 +357,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);