From patchwork Thu Dec 7 17:06:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10100283 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 5D7AD60360 for ; Thu, 7 Dec 2017 17:12:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42B17284CE for ; Thu, 7 Dec 2017 17:12:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37CBC28502; Thu, 7 Dec 2017 17:12:59 +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 BEA3E284CE for ; Thu, 7 Dec 2017 17:12:58 +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=E7JMS8v90SOtD7qqKyEoDkLInDWU6nCPPcQo4CAILCw=; b=Ny0ckZ1KnLEgDNzg20ZtqXU77i S8WbjoNQscSSblJImEM88TKsvw8JJp/Apbjac7ua5nleHwL2pA8YGWq+i4KHDgh9QMn1gBhXgObT7 MMzCAX4HUnZYNVyLHEdt2RVSGk2ZqtSCcZHjSissGBE4fkxfr+FpwVuEBOY/yV9IIFhicob+6uQ4R AAe5Nqio356Eb1vX8il8xtEPoTiPoZklge0/WeDrOykj1CQZCDrBTW0MptGVqbu45aF9r2MBM+IOJ 77GjrDW6MyN/blWwgBH2SsJYU/5Nqd12cZ3FrQwY3TfcKQancR9KGwHDVE6/HtiloMcNkLX6VJjUe EvqBKgmg==; 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 1eMzjF-0000yx-Vq; Thu, 07 Dec 2017 17:12:57 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMze0-0003Ab-RX for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 17:08:01 +0000 Received: by mail-wm0-x242.google.com with SMTP id b76so14242252wmg.1 for ; Thu, 07 Dec 2017 09:07:14 -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=2S/u1TK4okIakrG6tLz0pfNqE1CQvldKy9CEsjsgMVs=; b=KkYZzEGBptus++LnknBc8R8bYt0/Jrjkeixe7f9/yPB+DfxwL6QJFV11VVf94Pg/h6 yayA8CDCRy4Br4qGur6g3AdnOUyUus2vPV8smS0i/LQ+lcNlHxPqW/QwzjRW4YwujP9T +IoZdGBvRxbr2Y4SrHQf8FEPRCArkeozpR4Hg= 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=2S/u1TK4okIakrG6tLz0pfNqE1CQvldKy9CEsjsgMVs=; b=UyDkIAnIqF5CV6BmW1q0VatMsIYJYbpn0XpwLjtI8HS6JQ6DOkZ+GDIRuqq32y128G FeF/N6RSoMdygw16x4jejad8k72GHmNG5C1WZBfCWejo1kfZQjAcJ3OkP9LqdcQm/J3M eosZOykMlyHVmTIx5x86F2krEYeg8IY7XunhVwaIX9joODmQ5U49ZEYnGiMjNaVcth+b aj76AfbRVc2V/710un0BbpIrqiLDzDfmFj5ihfP7A1AsNaAlLy9YVbnzJ2600vXj1Qi9 /Ja6veTc4IpDjfrU/Sr990N4WGX7lb/D3TLZcztAmgFgKRqfBTvuOpmGxvZCYIjEbscv seIA== X-Gm-Message-State: AJaThX5ymkZasgVKVG39AwjkRip6TI+k7b2p8fyshliGwkXP3e3HQ5c+ Tb+PvXMue/StSteJ39OPFJyhOg== X-Google-Smtp-Source: AGs4zMbEea2AQimwY27qtakV0RLUDXtja9bfHAyBW9N03IJh9UkjXiyVWVfH/uB6Rk/hz0OrZUhQQQ== X-Received: by 10.80.225.3 with SMTP id h3mr46983218edl.128.1512666432817; Thu, 07 Dec 2017 09:07:12 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id a16sm2868270edd.19.2017.12.07.09.07.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 09:07:11 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 20/36] KVM: arm64: Don't save the host ELR_EL2 and SPSR_EL2 on VHE systems Date: Thu, 7 Dec 2017 18:06:14 +0100 Message-Id: <20171207170630.592-21-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207170630.592-1-christoffer.dall@linaro.org> References: <20171207170630.592-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171207_090733_928286_F5D8779B X-CRM114-Status: GOOD ( 10.34 ) 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 these registers don't contain anything important on VHE, because all of the host runs in EL2. Therefore, factor out these registers into separate save/restore functions, making it easy to exclude them from the VHE world-switch path later on. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- 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 a12112494f75..479de0f0dd07 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)