From patchwork Thu Oct 12 10:41:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10001631 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 5B16C60325 for ; Thu, 12 Oct 2017 10:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5351028C7E for ; Thu, 12 Oct 2017 10:49:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4813B28C90; Thu, 12 Oct 2017 10:49:50 +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 99CEA28C7E for ; Thu, 12 Oct 2017 10:49:49 +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=pJ8aTLQsoyMflSUU6/1N5sFmVW5DYHz22xcHfmeZqs8=; b=DxUv0MmtDqGW5qdh9VucODMPJe a6NTzCRLo+Lp8D3H0DItepSV+k4KC8E/qFi5YS4uqDW3yIqt61HadLeg7Nch4SG0HgNsTE2DDd70x r+oJ76+NpHfqR/c4sULtv1g/ANxLaLUTAUg5fRvSvz0kGRU7ly6COkv/N7rEN1paFCOL6YYUJ3o3e l/JkZVlGG5n0UNrkPK4lUqcR5Uk2jq6vxR8bR4HCya/LL4PoyVFhWn1Ss0VN6o+zvK/JnWRpmRbv0 +c5DAzpH7tZc2o2DP5VBEUP1Z1wQMa9GlF8uIpMS2onH4QpeihiX3EYMOzWXPtno+Hc84T+0g7+hq UhDhFwLw==; 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 1e2b3O-0006XL-Vg; Thu, 12 Oct 2017 10:49:26 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2awP-0007V1-H2 for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 10:42:23 +0000 Received: by mail-wm0-x236.google.com with SMTP id m72so11976931wmc.1 for ; Thu, 12 Oct 2017 03:41:53 -0700 (PDT) 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=QKKFTuVo6RwXt3lnkgGHD32x8k/S7k0odvYRxGG7yHw=; b=VS1geAkXZSEgmJj5uopxfupBLGiOVN/4l5NZSODsVleA3DX5JZsCTA9V7kfIH3Mslf N9Zibihzyp+u/0On2yhHulfhrOMYVfJT2xAOwKR/MAgzAQ5MePNexlFYbcP1oF+E0JL1 4q/1TIlGle2a9aV3iEYrirwj9oTyr+EcDLlAw= 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=QKKFTuVo6RwXt3lnkgGHD32x8k/S7k0odvYRxGG7yHw=; b=IsJt/Ngl+F1bNEyUqKlGJgvq30elrDugL8JE8yOf4pEp1T0uhGfu+BoxXqQYmHew36 hxNxFnNjDdDIJLsR1I2/OtDPzCiQBZowiLiqzOYiyy3OLJKOnO3mxT4iyXea4FrWa3zj O4HAXSv2nB/1JGSAMDjc0u8RwJeV2bXLNiPbUBIx6DwgDQ7OHnpyXvXt766Vm/tR3VSL TM9Bp/s6McLnAqBSKFB9SEkcjOlHoeHXyfhkK44Jp8xdLiYt4G+fWj47dU+nvoYmhXYL vJE6qCWK75iD3OvYgErn6rOsB8PjPKOAKTTdYn7UpnO6b4oWNsQ1izqtEueHbJBruPnN fd6g== X-Gm-Message-State: AMCzsaUewAC4BFeo9EnMnn+18oFK+sKP+K1RAntv1yWOsvolIbU38hzr b1PUTpk3XJINzW15tZzmrc9gIg== X-Google-Smtp-Source: AOwi7QBeeKuHoLM774Yb1BsUY/4PColanZF9aFWUVOHV7Sd6c8syPELvvrPMMWkQXbj77ROpATJ/8Q== X-Received: by 10.80.226.8 with SMTP id n8mr2428437edl.177.1507804911688; Thu, 12 Oct 2017 03:41:51 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id g49sm4798603edc.31.2017.10.12.03.41.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 03:41:50 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 07/37] KVM: arm/arm64: Add kvm_vcpu_load_sysregs and kvm_vcpu_put_sysregs Date: Thu, 12 Oct 2017 12:41:11 +0200 Message-Id: <20171012104141.26902-8-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171012104141.26902-1-christoffer.dall@linaro.org> References: <20171012104141.26902-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171012_034213_994935_5FB95DF2 X-CRM114-Status: GOOD ( 12.61 ) 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 , 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 buch of save/restore logic for VHE kernels to the load and put functions, we need some infrastructure to do this. Signed-off-by: Christoffer Dall Reviewed-by: Andrew Jones --- arch/arm/include/asm/kvm_host.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/kvm/hyp/sysreg-sr.c | 27 +++++++++++++++++++++++++++ virt/kvm/arm/arm.c | 2 ++ 4 files changed, 35 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 1100170..13f8165 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -290,4 +290,7 @@ int kvm_arm_vcpu_arch_get_attr(struct kvm_vcpu *vcpu, int kvm_arm_vcpu_arch_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr); +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 27305e7..7d3bfa7 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -383,4 +383,7 @@ static inline void __cpu_init_stage2(void) "PARange is %d bits, unsupported configuration!", parange); } +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 c54cc2a..b7438c8 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -183,3 +183,30 @@ void __hyp_text __sysreg32_restore_state(struct kvm_vcpu *vcpu) if (vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY) write_sysreg(sysreg[DBGVCR32_EL2], dbgvcr32_el2); } + +/** + * kvm_vcpu_load_sysregs - Load guest system register to physical CPU + * + * @vcpu: The VCPU pointer + * + * If the kernel runs in EL2 then load the system register state for the VCPU + * for EL1 onto the physical CPU so that we can go back and foward between the + * VM and the hypervisor without switching all this state around. + */ +void kvm_vcpu_load_sysregs(struct kvm_vcpu *vcpu) +{ +} + +/** + * kvm_vcpu_put_sysregs - Restore host system register state to physical CPU + * + * @vcpu: The VCPU pointer + * + * If the kernel runs in EL2 and the physical register state belongs to the + * VCPU, then restore the system register state for the host for EL1 onto the + * physical CPU so that we can run userspace and other threads on this + * physical CPU. + */ +void kvm_vcpu_put_sysregs(struct kvm_vcpu *vcpu) +{ +} diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index d495453..cf121b2 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -358,6 +358,7 @@ 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) @@ -365,6 +366,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) if (vcpu->ioctl != KVM_RUN) return; + kvm_vcpu_put_sysregs(vcpu); kvm_timer_vcpu_put(vcpu); kvm_vgic_put(vcpu);