From patchwork Thu Feb 15 21:03:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10223589 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 E698A60467 for ; Thu, 15 Feb 2018 21:05:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6B5D29512 for ; Thu, 15 Feb 2018 21:05:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB9F429529; Thu, 15 Feb 2018 21:05:21 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 7206D29512 for ; Thu, 15 Feb 2018 21:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167355AbeBOVFT (ORCPT ); Thu, 15 Feb 2018 16:05:19 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35036 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1167350AbeBOVEa (ORCPT ); Thu, 15 Feb 2018 16:04:30 -0500 Received: by mail-wm0-f67.google.com with SMTP id x21so3349661wmh.0 for ; Thu, 15 Feb 2018 13:04:29 -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=2jluDA2VjIEjThpU40ufg3aSTTS9qeVVtLexcKOR3SI=; b=eoJxRXS3SUoVczJxFxUwe1HLGMUUtWICq1G0qYsIuveM9A7QJZNRjj6jAbGuWSB/Ac mXDOwyMisAQSWUPFME30J7ZQbGP0c0x0XDWG1rBBxKCU/3acDcqzukxeIEdYEozEpU/p Z80nYH7d8+LXZ7etIMy5fDsw4kZWKeZYvMpFU= 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=2jluDA2VjIEjThpU40ufg3aSTTS9qeVVtLexcKOR3SI=; b=X8SXVFejURU9leGy7CTvZsM9EOf4/vYwQ72SFk8R2exmiRpOIAFKXp+JvxVMknOIQ9 rEw4avlPFbwUSd0UIT/ujfyt8psUAyq1EuHlEqBYSp9v9l4x/OhMjyyhuFVx5rEYmM2f iAoq2ZGCPLGyTvRRxYxfM+0gEyfF6uM4JzSRTrWAeJIViHoURVCagn3YqYRMAvsW1/YR NGzNRg4X8QG/ELuN2gutZjfiRjn3S3eV+XYvirQrG5SWqZpuKyhedhMJPNZBduQUphwj L3ZhKXPlk4oosKRsIIP09ute7Mjj1jOK4A/gribxmYt1uIVVbjhMfoK1lbvHLVRq6sND U2Tg== X-Gm-Message-State: APf1xPAfkT0HS9qKz0K5gcZEm9AxLxK76+ecnEHU9Avbnb9TgkssD9uU fZMstz6IMaIAL/7ji7tehoIemw== X-Google-Smtp-Source: AH8x226Nc0IKXjJEqUALHrH8NFIQWjNtCq4LJdpV3KtW4bQPzNkSq6nZcOB68yBmiXN8nGbn5nn6cQ== X-Received: by 10.80.149.140 with SMTP id w12mr4971798eda.229.1518728669267; Thu, 15 Feb 2018 13:04:29 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id p55sm8220030edc.15.2018.02.15.13.04.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Feb 2018 13:04:28 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Christoffer Dall , Marc Zyngier , Andrew Jones , Shih-Wei Li , Dave Martin , Julien Grall , Tomasz Nowicki , Yury Norov Subject: [PATCH v4 27/40] KVM: arm64: Prepare to handle deferred save/restore of ELR_EL1 Date: Thu, 15 Feb 2018 22:03:19 +0100 Message-Id: <20180215210332.8648-28-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180215210332.8648-1-christoffer.dall@linaro.org> References: <20180215210332.8648-1-christoffer.dall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier Reviewed-by: Andrew Jones --- 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 47c2406755fa..9cb13b23c7a1 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 8dda1edae727..cc13b6f5ad11 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;