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: 10223693 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 D7AA3602CB for ; Thu, 15 Feb 2018 21:27:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3B0027D4A for ; Thu, 15 Feb 2018 21:27:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4C5B27F3E; Thu, 15 Feb 2018 21:27:36 +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 3701B27D4A for ; Thu, 15 Feb 2018 21:27:36 +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=wGq1QqkmS0bRVCwVgG/sGMN63Mx4b9tuKCy8bI+CMxI=; b=FXHS8+C0C110fAXLQnaxzxS4zG 8AibQeKYXIPhdgjLZzwwZyZwZT3KG3ZyWYHaNCO9pAf2DvvENn2xqJZLCH43aUq6/XSeUsZsDZ4Al 8OkQNgDyFGHf7LhCyzJ58VyP7zc8eSgagduiP1wq6TwAErnytzidgjF/OYUeIMJJ6kg6i2Scsxgwu 9VbbzuU9XCqFRnWMnipVI3Css1Fc/Xt1NTbHA7Die3pgZlnOgYE9WpHJSI0WiJ3m/eOfh+Asp4/vc 5eTGKjfrQJzzO4ZXgTZAsEI1QzJMGh5v6E2TbXzKr2rgtU5V8bX0p54n9UHW5LYgfY/d7shwg0WSG rWtgk0Fg==; 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 1emR3q-0003mV-89; Thu, 15 Feb 2018 21:27:22 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1emQht-0000Pn-0Y for linux-arm-kernel@lists.infradead.org; Thu, 15 Feb 2018 21:05:38 +0000 Received: by mail-wm0-x243.google.com with SMTP id f3so3348762wmc.1 for ; Thu, 15 Feb 2018 13:04:30 -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=h1ornTP/Jx9knEz8D8wPtIjOWhE9HJ16PqvJG570f4D+KEtdWo6WIFLB0kuUACbxT+ byeRvyAUt36OgFl3xenvhtAlkBnzuqMbLMjoDe9/285Za28rX4VuOIn3/o1GawP32YIa 9jy6a3XdW6cyN5a6PgLXgfyfRlTNmpPynX8o8cjkqS4ezfuqfYu97u5KPzPiZnQ+g0X3 rXbrCzqqNJj6rbtv8tCG1DkOjMCd4RjggqSA3fHi+ttdqTnNUZYcC6iDJAApABeXIs5Z WxolSctdv8yDv6N1IMAXVn9DkhkFGUta3a5OSOsKxqhZPPXcDUKBO3DtvKCFLJrtudxe 8pRA== X-Gm-Message-State: APf1xPCoNUHLPuBz95vcNny4ZMCHFDbcD3MT0eLWs3qP5Hs4G2Z7eSeG bCmZzQ1ve3y86eZDGQf40oIkzA== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180215_130441_186933_72580962 X-CRM114-Status: GOOD ( 14.43 ) 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 , Christoffer Dall , 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 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;