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: 10244889 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 ED4B960208 for ; Tue, 27 Feb 2018 11:36:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF40C28843 for ; Tue, 27 Feb 2018 11:36:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1DD828846; Tue, 27 Feb 2018 11:36:06 +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 4D0EA28843 for ; Tue, 27 Feb 2018 11:36:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753121AbeB0LgB (ORCPT ); Tue, 27 Feb 2018 06:36:01 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:37071 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753117AbeB0LfL (ORCPT ); Tue, 27 Feb 2018 06:35:11 -0500 Received: by mail-wm0-f68.google.com with SMTP id 139so9999094wmn.2 for ; Tue, 27 Feb 2018 03:35:10 -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=jtW5PUffBqnNmr8GfQTWM5Bui7Npr3aSH4AjWkc+tkM5eIqQafApFXRhUpo7F8s6fv TGEcFluQehp9is0bFj48J9hQKEDOgAEOCjFyG/K4wK3x4KGXAJ6ypdP0zYPTNKxj7ETG ak1gLFDfzKMISrxiWE18l/h2ca62RZPK+tsd2KlUeZVcuS9NdSLKknN0dXzGt4QHfHW6 Ah0W0t6FlwV29L8SpnaZzLx/dRyanCLW6RRHxvKicLJshABHvae6WR7mKkaooyzHWJth KcdPQ6PxU8hhpAuQl/h9pynmit9QGk6pWvqzHXRTmf5cTRzyamxJQKNO9JCuGTTvnwSb I1Hg== X-Gm-Message-State: APf1xPDK96KW3y0AHnYYlmfi6akE+9g6Bx6TTcx7Mh0IZPMn/5E+EsUu gArmJY8VSmCmzmXfTPZd65mflQ== 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 Cc: kvm@vger.kernel.org, Marc Zyngier , Andrew Jones , Shih-Wei Li , Dave Martin , Julien Grall , Tomasz Nowicki , Yury Norov 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> 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 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;