From patchwork Tue Feb 27 11:34:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10245029 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 272F160362 for ; Tue, 27 Feb 2018 12:11:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1324A2889E for ; Tue, 27 Feb 2018 12:11:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 070552889D; Tue, 27 Feb 2018 12:11:13 +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 8887728898 for ; Tue, 27 Feb 2018 12:11: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=GLjoKvhs7huAb2a+wsFtMQ+k/VZTzLbbPLFlgJUu9Ec=; b=q/g2qz01RAqc4JNaYj58ZLdIvX cMRfdSxQSSnhbQHhsq2ioaWExWDGe5Uq73590OaK3IGul8kQWTkmFg2dwWrEtXy5LS9RTW3z4wMoZ turMXHsMfY6n1Fh+FWVsluhGM5vIA8PVb2LEy5KxGQTA8kYK/4soPin0yKXg3CoNCtRCs7RrYorcA Eh+xDclw7sSPweBItet9Q3gJjQmYU/reXNkrtVo9kTS2d+SnaoPgSvQu6/cBhkOPLISRBNMQDPGXl vm9din09jGYlx/5gmEclUbfRMSzgvaCrfgncxjD1W6g7WKLLaxtwCd1Ke4PiLb+PNR4L8AMe8pYeS Qkm1j2OQ==; 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 1eqe61-0006HI-Fe; Tue, 27 Feb 2018 12:11:01 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqe1P-000228-7V for linux-arm-kernel@bombadil.infradead.org; Tue, 27 Feb 2018 12:06:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=T69jXtsxMEOwpLXf1WvJVnStXHMsH/t/wf3wb8rGA5k=; b=XrRHGJPAWjVit1vTlLMJAj8sN V0D5CutDmopGqqW1PUC06N8x5JoGun0fyY/5oGyLqfI9JjhdORcG6WuUYD3ixRV629P9/tKTFRp7s q9dO2YjzeFN3do4Sq5yTyoTLf2lRTyMns2AvoOkEcWXH3qe9KWb5cZJId+MEuU31IfoPlvnNrkIul yKU2g+RJnP/gXWoCVrov56T9FDM581CkQfpt5Wt28f65SXcwSCFIJykn+trrKHB7xQMWK1OIi5eql 3/5ytp5PutWwKDisyuvNnG5SfIp+QaVsAt42HmkfDac+05Lu9rM6WQYk4qGIGioH/U3YAHYCSfUZe 55BFtwtFQ==; Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdXP-000733-Ff for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:35:17 +0000 Received: by mail-wm0-x244.google.com with SMTP id z81so23373499wmb.4 for ; Tue, 27 Feb 2018 03:35:04 -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=T69jXtsxMEOwpLXf1WvJVnStXHMsH/t/wf3wb8rGA5k=; b=PO9QAVRbZmR9dSW80IweVTsUZxCKWwBTQSS6/ycgdYebrHZD/M8Vd4z7ScBHYWI6MV QGxMfcvpai3GJ44kAN7LX6URZQjFZvOS0RdmJKsl7HGmZ8weM44grZcbventFTJFOLcq qoCX9Rf1+xM5SteDaJsatv6Ufhh+VGoRqNWMJ9T4DlwKDgpT1ifOPt4h/Tl2eWsxAsAN oWe/ZB5LjN01qqY/Y4f/eBx7jYmsW+HpRZx2Jo/2jxs1oAvZwthkOu8PGsSs1G+l89PN dfBw6aCCts5rCU+9GBRC38rz696jcrI50XfPjblttslG3Zi+FJRyGybLwxRt9JJ1VvFq qSEg== 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=T69jXtsxMEOwpLXf1WvJVnStXHMsH/t/wf3wb8rGA5k=; b=IwN5uXkSGyMD4i1Ly03QgmH6oMXDmXxSxPtsb2DUfjH+TtjDBOohK5da4NzCYz4kMS jjVST9kgjDL19U4SD3Hi6dS7uKcfgSukLqPvK/l+VXVsyj1g17ESfTVf2K91OmJE8LWt tNbzDHbMnKKBNUyhfqDO5pCB2Hh3WvGu/5LX8+VvG6/ie25gdaa7np5/LztYKKnI9b0J /X0vQtEhv3es7OvjOpUyrwrkBMIeFFzm1vMRaGagT4+wUsIGVv/gLkGg5xpOGuNTMTMn ncu9OB9b/GBa7em48+6RgNbG+hIKg4SaJTc+fnsA5wiMWG7WD9he54dvkBHzaWqoGNi0 rgYA== X-Gm-Message-State: APf1xPClhr33SPr6hWF1VWSzminD5Gp0T+oi4yDEcOHHo544rpYBZI/j eqCZ45Ulyx39Wr1NBT2No69jVw== X-Google-Smtp-Source: AG47ELvw47YtTKqEOCNNH3xJdVtDVV9MLstkv5j7Qbf2eeLwwc96pR/K75qLTK+5sSm8idQXy4w+Eg== X-Received: by 10.80.191.4 with SMTP id f4mr9514582edk.224.1519731303135; Tue, 27 Feb 2018 03:35:03 -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.35.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:35:02 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 22/40] KVM: arm64: Don't save the host ELR_EL2 and SPSR_EL2 on VHE systems Date: Tue, 27 Feb 2018 12:34:11 +0100 Message-Id: <20180227113429.637-23-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_113515_517856_250921E0 X-CRM114-Status: GOOD ( 14.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: 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 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 Reviewed-by: Andrew Jones 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 d35b3aa680ab..906606dc4e2c 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); @@ -83,6 +87,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) @@ -96,6 +101,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) @@ -140,6 +146,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); @@ -152,6 +163,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) @@ -165,6 +177,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); } void __hyp_text __sysreg32_save_state(struct kvm_vcpu *vcpu)