From patchwork Tue Feb 27 11:33:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10244911 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 0D1E66055B for ; Tue, 27 Feb 2018 11:37:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01289286D0 for ; Tue, 27 Feb 2018 11:37:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9CCF28883; Tue, 27 Feb 2018 11:37:34 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable 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 7335328859 for ; Tue, 27 Feb 2018 11:37:12 +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=yGae6VEY7KiGxd+t2Zld5vf+4Q2T53Tf7N5E0/t9iWA=; b=R5aHYBtzb0tLIkE1kJyju/A5ah CDGey66NPZmSyw5NRl+JllPjLUlt1M10atRe/kubQf8QwW4YikgC+OAViwc5yesh/PiP1a0lU8eiG 3Z/+p++JkgDFYeg61q0YqgbaM17fOoV/VZebR+T/mlnoWbZW7Ftlcl3+qJdhgbdS7vZMX5US3tKXw 6VTzGtnxln7OVWQFOpv6wzLU6sS28B4wnV9fgdfNJ8x4Krd7JeQVlb7y6uOsAwYvvyZxOxXjtI1RB Z5V0jKQv2tq2iAG2ISBJamJggEDY5eHbtvAUVdsMhtrE/gkuXaeLcq+72DkvkmwgVVI03vxajVEvR GQbi8GXA==; 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 1eqdZ9-0000Zo-3J; Tue, 27 Feb 2018 11:37:03 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdWv-0006Wk-JW for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:34:52 +0000 Received: by mail-wm0-x243.google.com with SMTP id 191so23154061wmm.4 for ; Tue, 27 Feb 2018 03:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nLj7rrbjeHD/2Z9FCOkebhUiHxayId1ouF87/6AYk0Q=; b=vk8Cx/QOCTgh9bN5Y8K2btVG6Xbl//tKFcvISD/r2LvA4eNeRx/DPtwSVJG+70VUB3 09ZtG3XGeGXbj7AGdkz3Aae0ex7bumMtgPv8vsM+HyXbHBOnDVSCRkV3rRpy/Ev9H9RZ mY0x5K5Lg5A/rHHdbDtI0CEpRNLH1e6zmxf4MBE8b4y5Q6upq4J+8UZUlMgYrXaBUQ0K ZKsTzIZM1FfeYzr1XOFqWepY305vayQf3uJ6jP+MFy60hjT3Qd/3K8TIMaQqdPgsvDoz Uzmri2izJ8/nV6ptjzk5ZCvtyaVe7XaTB5QKTIrMTmCP89OMeH3URqvamxWYvUcCiO9p yTjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=nLj7rrbjeHD/2Z9FCOkebhUiHxayId1ouF87/6AYk0Q=; b=aujWkozf5hC3lXJ/jddgz70IVwpq0l/pUBTg9620BoJEH8xXkVEW4+6Ecsn2ThuZ1h R0QWbpA2xKu27pkGVq77gWKz1nYpIQp7dYTPP6IEJvrxeRJ1KgD5DkoCWMNj0ubQdA6j w56p0oxrMjsCKMDoJN1wQnJJnF7bJ05mJNKiVJdJ1KQqsy5ceqkv8860kqH1WYcn5F6J YwuMWWX/MTSloLFHO3XgKh3K0ffjguk9C7UUXaV6p3k8EfBk7eg8K/SS0y7RCXnhjQix FuJp5kCq93A2/Pne4n0UKnbKnJFrG5ipvg+MiW3sq8mNT2mTjgJsFLcbei0nnFra/jEM sYSw== X-Gm-Message-State: APf1xPC8FKtcrA8Sfh/tk/hDTXlgUOsqx7fbdSxj4OmXRE4R9LHXx8AD 91k/RpfNG6+8sncwYVuAtGkFJQ== X-Google-Smtp-Source: AH8x224zQ3xJiyT/ttMhPYL12RUonV0PlVTzRJ92ECKoTZpdeTkGczm8g+axYC64Tmmuzvwqul9Row== X-Received: by 10.80.140.184 with SMTP id q53mr18336594edq.17.1519731282489; Tue, 27 Feb 2018 03:34:42 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id m1sm9176786ede.39.2018.02.27.03.34.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:34:41 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 07/40] KVM: arm/arm64: Add kvm_vcpu_load_sysregs and kvm_vcpu_put_sysregs Date: Tue, 27 Feb 2018 12:33:56 +0100 Message-Id: <20180227113429.637-8-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180227113429.637-1-cdall@kernel.org> References: <20180227113429.637-1-cdall@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_033445_908482_4A992D7A X-CRM114-Status: GOOD ( 14.03 ) 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: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Dave Martin , Shih-Wei Li 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 From: Christoffer Dall 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 --- 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 6137195ab815..c6a749568dd6 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -312,4 +312,7 @@ static inline bool kvm_arm_harden_branch_predictor(void) return false; } +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 b027a7f025d4..c30fc96992df 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -435,4 +435,7 @@ static inline bool kvm_arm_harden_branch_predictor(void) return cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR); } +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 43b7dd65e3e6..434f0fc9cfb3 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -190,6 +190,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 49d13510e9c2..2062d9357971 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -362,10 +362,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);