From patchwork Fri Jan 12 12:07:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160499 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 5323B602D8 for ; Fri, 12 Jan 2018 12:12:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35E1A289D2 for ; Fri, 12 Jan 2018 12:12:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A59F289D4; Fri, 12 Jan 2018 12:12:18 +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 92D4F289D2 for ; Fri, 12 Jan 2018 12:12:17 +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=rHH2yuZfayjwKQY0ixuYGQuRafabdWbDMfqXZnDc02A=; b=PC7cxu3+0kII77p+fzVgDttezF QpPp3GSulU3KvWIoKossFuV15SoJNijnPO/qLAQUSCD+TR+Rsfp42gY2WuYtG7F8u+GP6G8eDz+6D jSOdN/5aZfgL4YkbgcFMNm9mlMUoxVuzo1+dzNH/q2lNEcVLooApz6SvkSeixHb2O07MtmRok1rmb 2BiFwMtN+8O2NIPA5yT3lxrRtMy8NuwBeF8qJlEUXfplv+VXNI62BdfT1E9Qi3hConD7UFy4NZjum DD9mFY+134aXFremKbAodFZZ3dG8ug20zO0ni1P9WD/ksnNrTSckixciSiqBXo1eA/+5UXJa0ErwL UgEU6FQw==; 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 1eZyBy-0005oU-JP; Fri, 12 Jan 2018 12:12:14 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZy8S-0000c0-9Q for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:08:52 +0000 Received: by mail-wm0-x244.google.com with SMTP id i11so11332456wmf.4 for ; Fri, 12 Jan 2018 04:08:27 -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=868B016UA4oct7MtZ/aNKEuHupX0Q6kNXBDkekOT7Wk=; b=Q5OLnPI1mvgSJ/Fj2oVTLzwI1LyZCSDxMYa6sxGHkQ9OYkob84YPgJZUxLri2GCd0w AY9D/Uwo54H57m39sd1JsZ7OGnpo6D77+ucTq3p9tvlIQOvDecYE5u8shnMU82YjTKrW FZ0DWlkw4z9o4KxphF5+Hif85qar+Y+2kNgdQ= 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=868B016UA4oct7MtZ/aNKEuHupX0Q6kNXBDkekOT7Wk=; b=SS/huwJCkXPJy8IQkewTnFwmOB0IVMMQI2ew/EsnH7ICkfutod0pVk8QwSaw6tfj4w kGcza8ko3mOGz0yHUUsvm0bT9rzOiGfamzQ0COmiBX5ISRFmBVhxlz+rPfwuckMKM/U4 JxdS9zRzPB1zClDUiMB8+DPSbQFpgbDXT5mf9ehF6o+RmtyUu70SpX4GwQDOwi5Djl+H ZPiZly60vZGTRx0EkZsFpdPE1eD5SBDBik2ulJECJNXgF1K1mZXggeRzw+wG1AASWq1X 6bKhfeStTOJYSg8Vhx0RYhRfaRbvidow4bauO8/3oJvY3lEr5lHEG0bEcdOq6pBdfFUu UtmA== X-Gm-Message-State: AKGB3mKs83X8X3xGp4gzZo50t2IqkgUEAFaj81eRgHrD8R74X1wvviYy PhgUNtt9dtlaclR2iA8JPm9Lvw== X-Google-Smtp-Source: ACJfBosdz7e3LJWd9xdFSSVjTZX3ca1mNzZkBnbzNeBzyecoNM4nLGumW9kHLBrR+XcO2TANjO6Wyw== X-Received: by 10.80.201.75 with SMTP id p11mr35375288edh.199.1515758906208; Fri, 12 Jan 2018 04:08:26 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:25 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 23/41] KVM: arm64: Don't save the host ELR_EL2 and SPSR_EL2 on VHE systems Date: Fri, 12 Jan 2018 13:07:29 +0100 Message-Id: <20180112120747.27999-24-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_040836_721456_7A6AD516 X-CRM114-Status: UNSURE ( 9.95 ) X-CRM114-Notice: Please train this message. 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 On non-VHE systems we need to save the ELR_EL2 and SPSR_EL2 so that we can return to the host in EL1 in the same state and location where we issued a hypercall to EL2, but on VHE ELR_EL2 and SPSR_EL2 are not useful because we never enter a guest as a result of an exception entry that would be directly handled by KVM. The kernel entry code already saves ELR_EL1/SPSR_EL1 on exception entry, which is enough. Therefore, factor out these registers into separate save/restore functions, making it easy to exclude them from the VHE world-switch path later on. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp/sysreg-sr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/kvm/hyp/sysreg-sr.c b/arch/arm64/kvm/hyp/sysreg-sr.c index baa243a010b3..1f2d5e9343b0 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -71,6 +71,10 @@ static void __hyp_text __sysreg_save_el1_state(struct kvm_cpu_context *ctxt) ctxt->gp_regs.sp_el1 = read_sysreg(sp_el1); ctxt->gp_regs.elr_el1 = read_sysreg_el1(elr); ctxt->gp_regs.spsr[KVM_SPSR_EL1]= read_sysreg_el1(spsr); +} + +static void __hyp_text __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt) +{ ctxt->gp_regs.regs.pc = read_sysreg_el2(elr); ctxt->gp_regs.regs.pstate = read_sysreg_el2(spsr); } @@ -80,6 +84,7 @@ void __hyp_text __sysreg_save_state_nvhe(struct kvm_cpu_context *ctxt) __sysreg_save_el1_state(ctxt); __sysreg_save_common_state(ctxt); __sysreg_save_user_state(ctxt); + __sysreg_save_el2_return_state(ctxt); } void sysreg_save_host_state_vhe(struct kvm_cpu_context *ctxt) @@ -93,6 +98,7 @@ void sysreg_save_guest_state_vhe(struct kvm_cpu_context *ctxt) __sysreg_save_el1_state(ctxt); __sysreg_save_common_state(ctxt); __sysreg_save_user_state(ctxt); + __sysreg_save_el2_return_state(ctxt); } static void __hyp_text __sysreg_restore_common_state(struct kvm_cpu_context *ctxt) @@ -137,6 +143,11 @@ static void __hyp_text __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt) write_sysreg(ctxt->gp_regs.sp_el1, sp_el1); write_sysreg_el1(ctxt->gp_regs.elr_el1, elr); write_sysreg_el1(ctxt->gp_regs.spsr[KVM_SPSR_EL1],spsr); +} + +static void __hyp_text +__sysreg_restore_el2_return_state(struct kvm_cpu_context *ctxt) +{ write_sysreg_el2(ctxt->gp_regs.regs.pc, elr); write_sysreg_el2(ctxt->gp_regs.regs.pstate, spsr); } @@ -146,6 +157,7 @@ void __hyp_text __sysreg_restore_state_nvhe(struct kvm_cpu_context *ctxt) __sysreg_restore_el1_state(ctxt); __sysreg_restore_common_state(ctxt); __sysreg_restore_user_state(ctxt); + __sysreg_restore_el2_return_state(ctxt); } void sysreg_restore_host_state_vhe(struct kvm_cpu_context *ctxt) @@ -159,6 +171,7 @@ void sysreg_restore_guest_state_vhe(struct kvm_cpu_context *ctxt) __sysreg_restore_el1_state(ctxt); __sysreg_restore_common_state(ctxt); __sysreg_restore_user_state(ctxt); + __sysreg_restore_el2_return_state(ctxt); } static void __hyp_text __fpsimd32_save_state(struct kvm_cpu_context *ctxt)