From patchwork Thu Oct 12 10:41:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10001653 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 96B8560325 for ; Thu, 12 Oct 2017 10:53:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8775028D6C for ; Thu, 12 Oct 2017 10:53:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AFA128D6E; Thu, 12 Oct 2017 10:53:08 +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 1B83428D6C for ; Thu, 12 Oct 2017 10:53:08 +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=qLZ1foD35MwrIcgbk08L8oFIlEzfX5Yb3pHlO5M0R3A=; b=p/nG5Ho+Euy9rI529FT5Ql81c5 PKuQAfiM29gXMWtTdv2GpvTrIDJA5E0pHb+0eFSEOkwawVmHHZj8bjfbSeF9spIfO045Rw+wg8viL /gwnyZw7JWqCMbxyRJRxFD1PL4fJFfIFLZoKWjWEDDP/1SMGw4wKOXt8TvlTQnW+L2LljPRWEOLvQ VxzvjEtsa7V91Y5QFUplDOqh8Bp9+RcyYf6B/iKCWjcV1AwdBBhfJpCSf1/E3kARg0qRj4LPfBGqB FkfRW/Hk1EcFr0Ha+IGFNsiEpEU/QUNxpoAdZNL33ji9mhabXRwtMHVV2dJTrhiAYSPdcSJuIaMhp MqqnNQTA==; 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 1e2b6b-0002OH-Dd; Thu, 12 Oct 2017 10:52:45 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2ay1-0000V8-9c for linux-arm-kernel@bombadil.infradead.org; Thu, 12 Oct 2017 10:43:53 +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=8NF1WCx7jLzGFzlF9tq6c8S+jceRMSLazcI4L2No4p8=; b=CkIiYrC0QD1PDLssU02nIbqkw IWLlXzWO7DFa8G2zq+uXBb6FeLXwBl41s1SyXwezPHl9Z4u7O3vP1u3jx5+y+ngj//Qk1dQABMYN5 76rN7x+V+4ldnwmnUuoOQAS+ujd79UuKUkmmpE11F9qCJna6g0K3vVKZmPLgK+JIsKtm5XTnDCHkW kgfRfLu1xkOCfqKK73sE2FYY8+60+1OWjcTd0RtfMXvJHwt1+RmGlrvfyiO2IlvpCAxZ7/9eHm4nJ IZ+L0sihEDV+VOgTTEnSIx47/rc9hRkutdTaNjcuS+JS5c46mqnMaiCGKmILEeLO8tyftgK9vwUjj /Q5+i2aiA==; Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2awi-0005Jc-0e for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 10:42:33 +0000 Received: by mail-wm0-x22d.google.com with SMTP id i124so12075979wmf.3 for ; Thu, 12 Oct 2017 03:42:11 -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=8NF1WCx7jLzGFzlF9tq6c8S+jceRMSLazcI4L2No4p8=; b=JMDJi445z/KkhxPKvblv/Gt9DGDRAqPdbuIk7iimsQCVW/Zi8Q/1dxyzag9z0A5Kmr slROxUijr6K5eQzykRyWMxmxHCHf/mZJBeHcpqVLyLi5za9IcyqAgc3DznAqcrBcNxKT XqgYkSvE8/XxCnhWnlrfoF8YYCzIopwX/VAqM= 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=8NF1WCx7jLzGFzlF9tq6c8S+jceRMSLazcI4L2No4p8=; b=g1eQjH0zt6Tq7hrMAXu3ql7Kd1bllRi72FzOosbGRMNHGWnvyajNSDNSVdUObih/Z9 tzTWAvI+wb6VcTwvCW8ffhJcYaxWGRUBIDIQg/P+qm2NdUGWs1M5hgkUHqxOzODoPciq gmaW9uOVSgk4D+FXMCVwxpbGdg5rqGf+We3roR3/WIe85mogWDGEcgAgLJGIvZq69q0x g9ykLkqYlzva9Ps6B17xQ4cDVjnhC4zDCLmGZp1cs9vTx/FwEVHK40KBZmgM/KQ7UK2r OHuLG3AOfGBtMtUrC8K+BrCT9x3p62yjse59iynywbaJnMT38iwZuHIpLdwSwEHjNq5K TqWw== X-Gm-Message-State: AMCzsaW4bBmF8ur4er9go30+nllaYL4Yben5WtNWxzYTzOQJu1LIxjbS m0fY23IF0cwHNMCy8CgdILMB1A== X-Google-Smtp-Source: AOwi7QCJZXBUXOcCe+jlioz1kFs8k1TyCWpEI/C+HABXOp0rXwTEuexkcYAYo/3VWksqhdOxJD9XIA== X-Received: by 10.80.144.243 with SMTP id d48mr2368105eda.161.1507804930776; Thu, 12 Oct 2017 03:42:10 -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.42.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 03:42:10 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 21/37] KVM: arm64: Don't save the host ELR_EL2 and SPSR_EL2 on VHE systems Date: Thu, 12 Oct 2017 12:41:25 +0200 Message-Id: <20171012104141.26902-22-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_114232_065755_E4C80586 X-CRM114-Status: GOOD ( 12.22 ) 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 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 these registers don't contain anything important on VHE, because all of the host runs in EL2. Therefore, exclude them when saving/restoring the host state. 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 f5c1b44..354ca02 100644 --- a/arch/arm64/kvm/hyp/sysreg-sr.c +++ b/arch/arm64/kvm/hyp/sysreg-sr.c @@ -66,6 +66,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); } @@ -75,6 +79,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) @@ -88,6 +93,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) @@ -127,6 +133,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); } @@ -136,6 +147,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) @@ -149,6 +161,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)