Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp972585imm; Wed, 26 Sep 2018 09:34:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV62bDUMkwZyoAnj60tree4Zb/mSSpXehsWCiZGqIZRFPxhYwiSNyCX2VZHtiHSI5zR3P6jus X-Received: by 2002:a17:902:8681:: with SMTP id g1-v6mr6769236plo.302.1537979644189; Wed, 26 Sep 2018 09:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537979644; cv=none; d=google.com; s=arc-20160816; b=J8ePz9AOSD64mAPkUlTDQz43YiFRk27GUXvBouk+0IEi8UdhKsprs6AA/IMr5kW0Vc tKoRlT70bSW0CsD/1WemEpF5SUS/Jb44RJ7/5jwh/4+QfNOSWNYnS4dXQNdTVO+AmRZk 9menrDUZ50g4qH9tdo8o2jlPeK6E5oh4Tf1Pxt9ojV9BRLHS/YEMJkiYQlPMRgdURBBH JkHlCx4GfNBs9IHLr0A8+5d2MTj+4Lm60rRxMhBQX56CFgQtXNYrwpzOmlQyWfW/NVJ3 1/fT8EEsWUiB9Xx6vGa4opldK8OpBpryVDFWpR+MK9bL8Z2HWaUK63hIsUOxLJ/6S3P5 SJZg== 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=b0zFEKjr4YlErfS35KXTqWH4VKwnrfqAZos+NTZT55Lnaqy9Ly2qKedVorVsSVtG4m H5bnCIZQr9gscWzcxjODyDV/IF1Effu6eSnwb2X8miZTuG2EhGLBKUqxNIe9nW4lSADe kmCs4x3hv6z6GvAEYq2gF2k0kJb8qdfyAe9Gu7iENzS5SSlI5mK8VHIYazcyuDLdtcIP 8PjNBP/QyRtybLn/O+7+MDXU5GfkLPVcL0NdGZtyW9dfzaZNcbTB/LeWZaxtM+03YVPe ik2A1pevT4CQzEjE2JdROHwU5IOuI4VnpJp5NKMnv3P0ocEf8E80jrbZYrlGt0wffsYR 0M4Q== 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 a6-v6si5634773pgc.659.2018.09.26.09.33.48; Wed, 26 Sep 2018 09:34:04 -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 S1728676AbeIZWrV (ORCPT + 99 others); Wed, 26 Sep 2018 18:47:21 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:49948 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbeIZWrU (ORCPT ); Wed, 26 Sep 2018 18:47:20 -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 4457B15BF; Wed, 26 Sep 2018 09:33:35 -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 C58983F5B3; Wed, 26 Sep 2018 09:33:32 -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, suzuki.poulose@arm.com, will.deacon@arm.com, dave.martin@arm.com, peter.maydell@linaro.org, pbonzini@redhat.com, rkrcmar@redhat.com, julien.grall@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH v6 03/18] kvm: arm64: Add helper for loading the stage2 setting for a VM Date: Wed, 26 Sep 2018 17:32:39 +0100 Message-Id: <20180926163258.20218-4-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180926163258.20218-1-suzuki.poulose@arm.com> References: <20180926163258.20218-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