Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3814104imm; Mon, 17 Sep 2018 03:46:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY0HF+Wc3ztZlCGjv2bJCjJ4Y+ixKjfWzuW3KGJ907MkOcUwEU0kUbUP6lflaY1AWF/5i2F X-Received: by 2002:a63:f657:: with SMTP id u23-v6mr20802521pgj.258.1537181166994; Mon, 17 Sep 2018 03:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537181166; cv=none; d=google.com; s=arc-20160816; b=J6S0LVoqDWJdlGGB6T4S/gOCgv8FG9nWvlUQIchxOQs2rDpVyZI+KKt9kJZJ4aY5bB qVJKyycCtZezaFD5LtNesn0tAOcy4lbqolANBXUfYi3akds2sjl9tXOIHrLo3HbsxU+w jUYEYuD3KeUTl+/O0qGHVJ5F2RSwI0Voxew7p8EgZYQ9qgEwfRWhHOYn10E+56pPk5no Jww4fvXi1IPv/1rlH0zCqm4tJk2OnTuFmxNSVxbn/O8tb0Ta+HR80xiA0ty5iTMallRU xFywSJSmVza8cnKELzp2uyh/JIk5kROmYIM9+ycGgSGN1FP1H0ePJupw27gvJKQIOevn c4LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Uz+cB9iUgexJFCyyvg+I/IhXzrel7jhp+KWVwvu5sM4=; b=aJrZSE9xkRzwWE4hbd2EQsWWHRd6RNEoM/CVJbQFmYdB2iy9IRNHsoO7vcZZFf5Uq6 FTaGEeeJJMWR2cyKErr6tf9F+a94uKpD2KHox6OLnQTm77QAzfW0V2jjz7CQkY3nADJd 4echM74nLM+XY3Q0AnAbJ7n27bKnap1691LRptaeQ9aB7hwpyOrxjLcKNWGST8puzgM0 u0Y/62RcRpdgLRIYeTUeZxXmd8kZdDEGDPqJaMfzNJE6w/5Wpjh885ff2WGowwBcKy23 dVbbyndcivHhu/1iVcuRDr28x17iv7/LKyvaN99JtomBS5AhnW2n//Xpvp1lso4CSSri IDbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5-v6si15671830plt.342.2018.09.17.03.45.51; Mon, 17 Sep 2018 03:46:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728160AbeIQQJT (ORCPT + 99 others); Mon, 17 Sep 2018 12:09:19 -0400 Received: from foss.arm.com ([217.140.101.70]:56444 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728115AbeIQQJS (ORCPT ); Mon, 17 Sep 2018 12:09:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1323F15BE; Mon, 17 Sep 2018 03:42:31 -0700 (PDT) Received: from en101.Emea.Arm.com (en101.emea.arm.com [10.4.13.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8BEC43F5BD; Mon, 17 Sep 2018 03:42:28 -0700 (PDT) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, marc.zyngier@arm.com, cdall@kernel.org, eric.auger@redhat.com, pbonzini@redhat.com, rkrcmar@redhat.com, will.deacon@arm.com, catalin.marinas@arm.com, james.morse@arm.com, dave.martin@arm.com, julien.grall@arm.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com Subject: [PATCH v5 03/18] kvm: arm64: Add helper for loading the stage2 setting for a VM Date: Mon, 17 Sep 2018 11:41:25 +0100 Message-Id: <20180917104144.19188-4-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917104144.19188-1-suzuki.poulose@arm.com> References: <20180917104144.19188-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We load the stage2 context of a guest for different operations, including running the guest and tlb maintenance on behalf of the guest. As of now only the vttbr is private to the guest, but this is about to change with IPA per VM. Add a helper to load the stage2 configuration for a VM, which could do the right thing with the future changes. Cc: Christoffer Dall Cc: Marc Zyngier Reviewed-by: Eric Auger Signed-off-by: Suzuki K Poulose --- Changes since v2: - New patch --- arch/arm64/include/asm/kvm_hyp.h | 9 +++++++++ arch/arm64/kvm/hyp/switch.c | 2 +- arch/arm64/kvm/hyp/tlb.c | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_hyp.h b/arch/arm64/include/asm/kvm_hyp.h index 384c34397619..d1bd1e0f14d7 100644 --- a/arch/arm64/include/asm/kvm_hyp.h +++ b/arch/arm64/include/asm/kvm_hyp.h @@ -155,5 +155,14 @@ void deactivate_traps_vhe_put(void); u64 __guest_enter(struct kvm_vcpu *vcpu, struct kvm_cpu_context *host_ctxt); void __noreturn __hyp_do_panic(unsigned long, ...); +/* + * Must be called from hyp code running at EL2 with an updated VTTBR + * and interrupts disabled. + */ +static __always_inline void __hyp_text __load_guest_stage2(struct kvm *kvm) +{ + write_sysreg(kvm->arch.vttbr, vttbr_el2); +} + #endif /* __ARM64_KVM_HYP_H__ */ diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index ca46153d7915..9d5ce1a3039a 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -198,7 +198,7 @@ void deactivate_traps_vhe_put(void) static void __hyp_text __activate_vm(struct kvm *kvm) { - write_sysreg(kvm->arch.vttbr, vttbr_el2); + __load_guest_stage2(kvm); } static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c index 131c7772703c..4dbd9c69a96d 100644 --- a/arch/arm64/kvm/hyp/tlb.c +++ b/arch/arm64/kvm/hyp/tlb.c @@ -30,7 +30,7 @@ static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm) * bits. Changing E2H is impossible (goodbye TTBR1_EL2), so * let's flip TGE before executing the TLB operation. */ - write_sysreg(kvm->arch.vttbr, vttbr_el2); + __load_guest_stage2(kvm); val = read_sysreg(hcr_el2); val &= ~HCR_TGE; write_sysreg(val, hcr_el2); @@ -39,7 +39,7 @@ static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm) static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm) { - write_sysreg(kvm->arch.vttbr, vttbr_el2); + __load_guest_stage2(kvm); isb(); } -- 2.19.0