From patchwork Tue Feb 27 11:34:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10245069 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 5593660211 for ; Tue, 27 Feb 2018 12:45:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4573D288A0 for ; Tue, 27 Feb 2018 12:45:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39C40288AE; Tue, 27 Feb 2018 12:45:29 +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 C848C288A0 for ; Tue, 27 Feb 2018 12:45:28 +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=VCZWj0cXhU/QSPsrivU+gyOThS6EEpGJ1wQ4MSLWFtU=; b=iYFinrMtXBMH5yZFFbBVXeWJbp dilcxyTC3YJ020fIaqbp9gEy/sREqpsadzxCY47XE4hWdFrUQqX+cHNOFl7fkFL9lPQcrQX1TxaN3 BVGyKtDCfFy0r1MAyKlzvmfJuMUb4fUjyKQJmv1t8S4QJvBZSBSQDR6hgW6/7k94P161a4I2NBJ5B nLjljjac3NWox6+/rW1MhEIHQZA7OX/Da4Gs9mMSu28Uu/Tb23zuxgzECM/FOYe6LywlR/fBXJaUs nVhQWK9/pkf+3fknurDki5i+Bq/3kmMPz5Kz3Bl5Cm42OTVTJX1ZmRH4d3R1BIOCpn/vHNq2PRzY+ YNQwgaPw==; 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 1eqedG-0007Hg-K7; Tue, 27 Feb 2018 12:45:22 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqeZo-0004jB-AR for linux-arm-kernel@bombadil.infradead.org; Tue, 27 Feb 2018 12:41:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=dEuOk/yOhtaqehiAH0y/kyL/xyEJ5AOO0a4MdtSM5To=; b=sIv/QH/Vhnc3Ncrj69he+UVMt hFvhXJtTkl77BMkm7dW7Xt446eYEkddslXrj/0U91+m2Wo0pfmsxtLoiP7Dbcr3JESQ4y+BFvbmUg gAFoY7Xp/qXXI6BBgnFfb2CgV4iNLqd2Z5v5jhcx0rWYJ4pReVVaIOx5+4XKO4ik9hmBRnS5pv5lt oux/IfLcjs88sA98O6y+Kmd4o+iN4PpK0IaH64MJnK0IzMMD+3M8y7CK9/HIoDjLtgVbTgw7vefYU 8UH8FIklGmM9cHrwA74usBqXBTbgcl6cK1iOCPuFEf7rqedZuTqMycD6cQGUXgSUqiHQu+InR7ms8 dYuP/b+Hw==; Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqdXY-0006K8-HY for linux-arm-kernel@lists.infradead.org; Tue, 27 Feb 2018 11:35:26 +0000 Received: by mail-wm0-x242.google.com with SMTP id z81so23374291wmb.4 for ; Tue, 27 Feb 2018 03:35:12 -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=dEuOk/yOhtaqehiAH0y/kyL/xyEJ5AOO0a4MdtSM5To=; b=Y5fy8IZTPiBo32HeGiorVW51BY9huzOUNGE3ZUs/UKTwk45esekQCQXRLuJyM761Fa iIhRYIweZ5nf7iuNGwSFy8ijsYcIsIJglvipVLjWNSFXeB+ztvVt/N4JgMgM5i3HURmZ joj0ieq+VhVZ4uwMdx+0LLAvzTCPkfW4diRhehQ0qzF8qUqeauxb6lfSkAINKxJAlRzl ycjFv8oKR5R+sPKPoMnVSxrerqInia0F+1wK6A/Fm69FDwqLLG5nJoNZ+REC3qhD7ZFD wuvB9WiPx3JaCWChuX8ee8Ej9r70SYfayo+Luf1zHytPOjryRluYW1WTHH+uLkN/n8ec qssA== 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=dEuOk/yOhtaqehiAH0y/kyL/xyEJ5AOO0a4MdtSM5To=; b=ENnX8DSjXsQd2vRzykUaGlsr+gtpbRudPqqEw18rtYfg2oD4M5fxHc3z0/kM4y/xyJ pHkzoH9AR1Fw0YffOjUpReCYAKzul5R3Fyh2fXPgeuAs6RR19ZlAz4tcLJl2V6t/fi5s nn9BzNdw+sNUA4X8GcDzeMPbPqIDerFLbF6/yH0Uk2xqjULmjmaUzIKEpOzSDo/Wl4m7 4Tl1lR+J2KtPTFCd8yn0V3lSwpypvMqjtpwh6KVg/Hc8tL7pFWZVfM/6tiQb5Ci6dRiZ v3B1jZgCNmcJqMv2sus2cwFQtwcpIY/WB8KfjGgwPgRtbiMFelVr0+rFPVWXsKevG5Hv 9Ldg== X-Gm-Message-State: APf1xPBxlKp0fYjJ4+27TrJ1+fWRnifUaTqh3cqaONWRLpuy6z3y+puy IfYnN28E3rxBlyMVYh/kMHeTsQ== X-Google-Smtp-Source: AG47ELuDULbfp0/DeAe5FdGnkQ8TiKknvhwC4U92rtbdZZT0gbZxsc+IyRQKXg5NjezcZEkwZC6o5Q== X-Received: by 10.80.221.74 with SMTP id u10mr14629502edk.198.1519731310228; Tue, 27 Feb 2018 03:35:10 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Feb 2018 03:35:09 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 27/40] KVM: arm64: Prepare to handle deferred save/restore of ELR_EL1 Date: Tue, 27 Feb 2018 12:34:16 +0100 Message-Id: <20180227113429.637-28-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_063524_614250_46691F03 X-CRM114-Status: GOOD ( 15.89 ) 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 ELR_EL1 is not used by a VHE host kernel and can be deferred, but we need to rework the accesses to this register to access the latest value depending on whether or not guest system registers are loaded on the CPU or only reside in memory. Reviewed-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall --- Notes: Changes since v2: - New patch (deferred register handling has been reworked) arch/arm64/include/asm/kvm_emulate.h | 18 +++++++++++++++++- arch/arm64/kvm/inject_fault.c | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index f32640132e26..6ed18ce0d638 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -90,11 +90,27 @@ static inline unsigned long *vcpu_pc(const struct kvm_vcpu *vcpu) return (unsigned long *)&vcpu_gp_regs(vcpu)->regs.pc; } -static inline unsigned long *vcpu_elr_el1(const struct kvm_vcpu *vcpu) +static inline unsigned long *__vcpu_elr_el1(const struct kvm_vcpu *vcpu) { return (unsigned long *)&vcpu_gp_regs(vcpu)->elr_el1; } +static inline unsigned long vcpu_read_elr_el1(const struct kvm_vcpu *vcpu) +{ + if (vcpu->arch.sysregs_loaded_on_cpu) + return read_sysreg_el1(elr); + else + return *__vcpu_elr_el1(vcpu); +} + +static inline void vcpu_write_elr_el1(const struct kvm_vcpu *vcpu, unsigned long v) +{ + if (vcpu->arch.sysregs_loaded_on_cpu) + write_sysreg_el1(v, elr); + else + *__vcpu_elr_el1(vcpu) = v; +} + static inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu) { return (unsigned long *)&vcpu_gp_regs(vcpu)->regs.pstate; diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c index 7f8d2a4e420f..d8e71659ba7e 100644 --- a/arch/arm64/kvm/inject_fault.c +++ b/arch/arm64/kvm/inject_fault.c @@ -67,7 +67,7 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr bool is_aarch32 = vcpu_mode_is_32bit(vcpu); u32 esr = 0; - *vcpu_elr_el1(vcpu) = *vcpu_pc(vcpu); + vcpu_write_elr_el1(vcpu, *vcpu_pc(vcpu)); *vcpu_pc(vcpu) = get_except_vector(vcpu, except_type_sync); *vcpu_cpsr(vcpu) = PSTATE_FAULT_BITS_64; @@ -102,7 +102,7 @@ static void inject_undef64(struct kvm_vcpu *vcpu) unsigned long cpsr = *vcpu_cpsr(vcpu); u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT); - *vcpu_elr_el1(vcpu) = *vcpu_pc(vcpu); + vcpu_write_elr_el1(vcpu, *vcpu_pc(vcpu)); *vcpu_pc(vcpu) = get_except_vector(vcpu, except_type_sync); *vcpu_cpsr(vcpu) = PSTATE_FAULT_BITS_64;