Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3357220pxf; Mon, 15 Mar 2021 07:54:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7cEtoLg2KljcmXaCzKo97X6Zhq9tkGM5u561NEJ2oIHKW81rVcD+/jWM/mrhaQtAhttd2 X-Received: by 2002:a17:906:74c4:: with SMTP id z4mr3497401ejl.512.1615820048174; Mon, 15 Mar 2021 07:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615820048; cv=none; d=google.com; s=arc-20160816; b=oB/ylZsutKPdzhB5tN6qn13fBRv+J7xJUm4FPHPtW3XnpRNzHewSRBiNmkGtQWNpfi crsj6cVEtYz1pJCLkpbXIUuE26ZpkgSHjVPPnREwRlesmVHuKnl6SVnCQxNIEDhh6KmX uPEWkdN9/LcR/jjjzhfOLYhx6l5WSJBbKkVCHBVP90NIa5dbtXw8vmH+v9oNGCIoznMs eolaQvhXqAFCxotzMHkUode33zci0bHJDbt2FsSDUwyVDkD+//7DBRrm7Cuub5ApalRA UDbemFboat+4SjtunN0I6b3vYOYO8mNWGGpPk+hYRZVCtcU3wMrc999eZLS94czVu+TH 0gMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=D5e14wSMElm4lGDiCma+usUQSFdAZDSfAZdDxnBgLrs=; b=gL8lUUygwq9elQGNoWQF5gEnx5nJmm9zFqcPeZ7YZhjC8zDh2z7yUrvj5ehdr48G1l DIOtMY5QiV8RXxsOpEKIgr9VvcGB+/p9dLPh59GLeo+Kc/FH5st2c2ZkEU9cxtutLP9c fFfNgrdGxVEGUMlYFBHVBXMkPfOOB9GHP2wZA/5hQ9pPeCIfYirbo4kKCVAXoTKa2X0Y ZGRbOuXFQ6RNBX+ebLvob5y9PIMq7i3uM+U2PjSuYuqYsJfvt0a/Qxp8zMJ+88jJKvAy EURE9jM38cvj1JjRLmxZvaN0PVeFCJbpw8ebZk25/2H/033OXTMO7YVlqJTsCS6R5yOY ZWIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="d/vLmiLX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si10887803ejr.38.2021.03.15.07.53.44; Mon, 15 Mar 2021 07:54:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="d/vLmiLX"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239327AbhCOOvt (ORCPT + 99 others); Mon, 15 Mar 2021 10:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236529AbhCOOgs (ORCPT ); Mon, 15 Mar 2021 10:36:48 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C269EC0613E2 for ; Mon, 15 Mar 2021 07:36:24 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id u1so38370096ybu.14 for ; Mon, 15 Mar 2021 07:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=D5e14wSMElm4lGDiCma+usUQSFdAZDSfAZdDxnBgLrs=; b=d/vLmiLXof7x+7eiY7dtBIRlpcuQAYNjMCzBArdjw6PTVPDNRZkLnQrZMHHwO3XSic E6HUFEK20C1ZdwapwkMcvI+hxjWzPOeiuvyI2KAZVBMNkLN13yXnyTnUf8Qvpd/Y8u1g POEkGA1Pwk10qTv4Yn/WbUt90Thrpl8BoV5h6zPAe5DNA7dKpzj2EbjQeW9osZVuvuGl pHvdF5hW6aCJ9TgkgSQ6NGe/x6DWWE8t7oU6+7TnaMB3xxfiqegU9SDsXrr7taZD/3S/ YduDj83szdsIdokuWVDAcR3xGQptQ0N1DNM6/lGPNQq3ChiQdyM3x5d7hv6TKDf0lDAB dDOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=D5e14wSMElm4lGDiCma+usUQSFdAZDSfAZdDxnBgLrs=; b=lp6ajf+PlsLQHnliougj0DuvanXNgEXKWxV/1oB1ZL+tS+Z3WINgmi/DinOJCHyZ4E JNB09qiAzg6NJ3hCzpQkDKlwcDiXnPpARa6CS4JR+Jtm1Z3yeBvecrkIwsWeRw7jNqpw qLng4s3sB4x8USS01W2MrsTcct1xY4RHkkMv8LLR19aHE+tmEzwa4RUzXkxFBpilUiP5 vSGET/HOLwTV8Hj7Kd+QRQ8H7o3G6m2ukL3kTmyCM+mEvmh0jB8H3pEOoMm7//0+QufS 2shH/eq7sN7gc5xP4eKa09UFxT/ef9zUjbjJw+5TBmSKyQ9xCDoHQk5vNvmKnnxaD9xA qSQQ== X-Gm-Message-State: AOAM531NDmvqJ6mO7c0IgdkfSoOSDrz8Olmb25JbeGS4JilwnLQeGtko ssAkzy+AjHARCSfoftMAUWEuco1CxvqN X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a25:cc4b:: with SMTP id l72mr36451374ybf.455.1615818983972; Mon, 15 Mar 2021 07:36:23 -0700 (PDT) Date: Mon, 15 Mar 2021 14:35:21 +0000 In-Reply-To: <20210315143536.214621-1-qperret@google.com> Message-Id: <20210315143536.214621-22-qperret@google.com> Mime-Version: 1.0 References: <20210315143536.214621-1-qperret@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v5 21/36] KVM: arm64: Set host stage 2 using kvm_nvhe_init_params From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com, qperret@google.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the registers relevant to host stage 2 enablement to kvm_nvhe_init_params to prepare the ground for enabling it in later patches. Acked-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_asm.h | 3 +++ arch/arm64/kernel/asm-offsets.c | 3 +++ arch/arm64/kvm/arm.c | 5 +++++ arch/arm64/kvm/hyp/nvhe/hyp-init.S | 14 +++++++++----- arch/arm64/kvm/hyp/nvhe/switch.c | 5 +---- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index db20a9477870..6dce860f8bca 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -158,6 +158,9 @@ struct kvm_nvhe_init_params { unsigned long tpidr_el2; unsigned long stack_hyp_va; phys_addr_t pgd_pa; + unsigned long hcr_el2; + unsigned long vttbr; + unsigned long vtcr; }; /* Translate a kernel address @ptr into its equivalent linear mapping */ diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index a36e2fc330d4..8930b42f6418 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -120,6 +120,9 @@ int main(void) DEFINE(NVHE_INIT_TPIDR_EL2, offsetof(struct kvm_nvhe_init_params, tpidr_el2)); DEFINE(NVHE_INIT_STACK_HYP_VA, offsetof(struct kvm_nvhe_init_params, stack_hyp_va)); DEFINE(NVHE_INIT_PGD_PA, offsetof(struct kvm_nvhe_init_params, pgd_pa)); + DEFINE(NVHE_INIT_HCR_EL2, offsetof(struct kvm_nvhe_init_params, hcr_el2)); + DEFINE(NVHE_INIT_VTTBR, offsetof(struct kvm_nvhe_init_params, vttbr)); + DEFINE(NVHE_INIT_VTCR, offsetof(struct kvm_nvhe_init_params, vtcr)); #endif #ifdef CONFIG_CPU_PM DEFINE(CPU_CTX_SP, offsetof(struct cpu_suspend_ctx, sp)); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 7d62211109d9..d474eec606a3 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1413,6 +1413,11 @@ static void cpu_prepare_hyp_mode(int cpu) params->stack_hyp_va = kern_hyp_va(per_cpu(kvm_arm_hyp_stack_page, cpu) + PAGE_SIZE); params->pgd_pa = kvm_mmu_get_httbr(); + if (is_protected_kvm_enabled()) + params->hcr_el2 = HCR_HOST_NVHE_PROTECTED_FLAGS; + else + params->hcr_el2 = HCR_HOST_NVHE_FLAGS; + params->vttbr = params->vtcr = 0; /* * Flush the init params from the data cache because the struct will diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index a2b8b6a84cbd..a50ad9e9fc05 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -83,11 +83,6 @@ SYM_CODE_END(__kvm_hyp_init) * x0: struct kvm_nvhe_init_params PA */ SYM_CODE_START_LOCAL(___kvm_hyp_init) -alternative_if ARM64_KVM_PROTECTED_MODE - mov_q x1, HCR_HOST_NVHE_PROTECTED_FLAGS - msr hcr_el2, x1 -alternative_else_nop_endif - ldr x1, [x0, #NVHE_INIT_TPIDR_EL2] msr tpidr_el2, x1 @@ -97,6 +92,15 @@ alternative_else_nop_endif ldr x1, [x0, #NVHE_INIT_MAIR_EL2] msr mair_el2, x1 + ldr x1, [x0, #NVHE_INIT_HCR_EL2] + msr hcr_el2, x1 + + ldr x1, [x0, #NVHE_INIT_VTTBR] + msr vttbr_el2, x1 + + ldr x1, [x0, #NVHE_INIT_VTCR] + msr vtcr_el2, x1 + ldr x1, [x0, #NVHE_INIT_PGD_PA] phys_to_ttbr x2, x1 alternative_if ARM64_HAS_CNP diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c index f3d0e9eca56c..979a76cdf9fb 100644 --- a/arch/arm64/kvm/hyp/nvhe/switch.c +++ b/arch/arm64/kvm/hyp/nvhe/switch.c @@ -97,10 +97,7 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu) mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT; write_sysreg(mdcr_el2, mdcr_el2); - if (is_protected_kvm_enabled()) - write_sysreg(HCR_HOST_NVHE_PROTECTED_FLAGS, hcr_el2); - else - write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2); + write_sysreg(this_cpu_ptr(&kvm_init_params)->hcr_el2, hcr_el2); write_sysreg(CPTR_EL2_DEFAULT, cptr_el2); write_sysreg(__kvm_hyp_host_vector, vbar_el2); } -- 2.31.0.rc2.261.g7f71774620-goog