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: 10244887 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 22A9D6055B for ; Tue, 27 Feb 2018 11:36:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 158FC28843 for ; Tue, 27 Feb 2018 11:36:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 056E228849; Tue, 27 Feb 2018 11:36:04 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FB8028845 for ; Tue, 27 Feb 2018 11:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753136AbeB0LgC (ORCPT ); Tue, 27 Feb 2018 06:36:02 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:55764 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752988AbeB0LfE (ORCPT ); Tue, 27 Feb 2018 06:35:04 -0500 Received: by mail-wm0-f67.google.com with SMTP id q83so23501371wme.5 for ; Tue, 27 Feb 2018 03:35:03 -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=mLi5lQThsp7C4LNxO8e3PSUczlb7iRR23el1bBUtbpk5aX6R2+Ug2Q5fwc5GcFsVLi t/tVtEfiwwep3wsIEdnhcwoCWmsL1L+16kx6QMTlogGJ+oxjCk8++1412FHT4uENChrG IfdgkyhqLHgipt7cBJ/Tx1t5jX949JfV9NOfLPKXZwqKXk0mD4Nj3gDz3cy1ZxvtjKQC 7mohlr8krZ3nSuWGo0DJmjpLTpZhdmsuLjG09JET+xzUSC0FdepjH/16z4zbre77DwvR bjNK3UfHMVoXSf8HPLecKyvzMFAXeuL+ya+oOJUVF4F70snzT4stWANgMCGg53LXAufe cuTA== X-Gm-Message-State: APf1xPDKYZEcrSAX+OcfggVav1HnbpVvaV0VoPpDBBIBvt4XMEjuNGms GLeMdXEr0alC1184Y+co6cUqAw== 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 Cc: kvm@vger.kernel.org, Marc Zyngier , Andrew Jones , Shih-Wei Li , Dave Martin , Julien Grall , Tomasz Nowicki , Yury Norov 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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)