Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp958881pxb; Wed, 3 Mar 2021 22:32:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXc0MqcEewXBNxWT1r/bYi0VfgqS/tP8PQ2tPJ3bohxzSMl1YQhLiQaP28E0Xa3yDDySHC X-Received: by 2002:a17:906:3395:: with SMTP id v21mr2590183eja.322.1614839564943; Wed, 03 Mar 2021 22:32:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839564; cv=none; d=google.com; s=arc-20160816; b=PF+FhVLOU2IzYlWon5EQmmZBOrDVn89aJpdBwu6ZNO3cUqCJnn6JIacNsYQCiy4C+g TY5VhhQHqJfSYLgkQTsVspq3taU2xunLZkrK/yBLKC7mQkHSXejaq+njl5CGziMyak4D P8iRry7jk0lFVNpzxsgIHI8daDzDU0qL8fsDx+272HFuFT9g6F0JG29K9M2Iesfe4wMI 7P4DDhDKSBJf+VnlNODrAMrEO9S5VsyhPmNoyKtzUi6AZ2t134SlZJEcoTudq19DE8Zg yrHR0CWcW0X3jwWfOYCC4Flgh//I928aaQ3U/n3zT/6sRWFQdshTwgSRDZS1OvGGgbWq 3NaQ== 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:sender:dkim-signature; bh=CR8slcHJty71kvDCKzriIjKyavoYKi9QlRsnw//QRog=; b=dOWyj8rsIiBQ4dgTLKjkYysyOq6NNc8sLA8KyOOAGw/iENDv55zUYkAHN8+XEElFB7 Rhsrdxgw1JERHpGIl7z33ZOsAEbOZiztuGCUvOZmwMGUN++qxiQrqZdEg3E0Wf0sFVIv bK4Wf7qr9OEmXwBAsTRR77rvPnfnGhScDmOdpnwDh+f0PzL1siS1BdeLpb7qtzMt8WNv sidQt9hRhfbMvHgtDdiUQeEhwN8jS98nqFonUpiuMWGCoFgMRdnfGIHIrLPx7K3GJ4tt DcRwncOcSCKUoLPuZsO18fsDSYsOHHJa7GaG5/IulvZWiXJDxORoM44D5n3//DJicx8P RE0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gpNav6in; 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 i10si16507493ejd.572.2021.03.03.22.32.22; Wed, 03 Mar 2021 22:32:44 -0800 (PST) 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=gpNav6in; 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 S1352087AbhCBSKj (ORCPT + 99 others); Tue, 2 Mar 2021 13:10:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347474AbhCBP2W (ORCPT ); Tue, 2 Mar 2021 10:28:22 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194ACC061A86 for ; Tue, 2 Mar 2021 07:00:16 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id v184so17004545qkd.22 for ; Tue, 02 Mar 2021 07:00:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=CR8slcHJty71kvDCKzriIjKyavoYKi9QlRsnw//QRog=; b=gpNav6inPzEt9MzUtLCd/NJ9zfZ25Hl8Fy5hqYea9JqzZVivwRYLifUQyzoD2FEiid b2UuiFbsnXWY11BMcHhgQD/oBacoTL5GwDVp1MD/kfNwKNgY0OPtv6voubsIXVzeC+Cd pxHVjVfb/gt1Iz0gyThf70TSrfBa0KpCM7TCt8YoMCZi9AS+YeEr7kzDGNyId75/Xuy9 w2bcoc2cCIaav3tj/U86Nn1iVbzQJDABbjCM/IrZ4bFnt8fv0giaK0P3VD70fYTu+WQV t51XY5o2hrnMbZCiHBAZ5QMj4a60W+acb1k2xSjBvdTOvSbbHdKHP5Gwp0rSJ+CD561U dTqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CR8slcHJty71kvDCKzriIjKyavoYKi9QlRsnw//QRog=; b=ULu2SsTdVkOcesfMLy8TDKzwak0FOoo0PhKWHnMgPPGEr868QZQpq4QefD69oUgnWs 79y6yERidy7KiPUYliwp2e624XwT4DofklSKQLbUXzfG8aHE27QmQ+cHqs57dhMBa1kr yDS9yduONtoy4oUyvAowaRRHBd2vsWhLD3mplw3bqEcHmRhRwceuVXqYcYsA12DQWqOS 2dJ55ylEc8H3+jt/CTVbZw5mzMXQfkTAendSmGtjo2sGVMl8sDi7LDBgftPO4NcEUS7v zaWLUqrO+Noj3XDg9SU2AfhGACcgI4O2TwPOrDCVuTQo2DHQuiH30b3ks5DAiLJbXotv dCUg== X-Gm-Message-State: AOAM533R32h7uaeRKYr+fVhfKB1Yedbc1Olmu8qU7gWusKgUiPGveqla GizeezrApw4JUf+IXEUZNjdvgY53Tg8I Sender: "qperret via sendgmr" X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a05:6214:52:: with SMTP id c18mr3713024qvr.54.1614697215183; Tue, 02 Mar 2021 07:00:15 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:34 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-5-qperret@google.com> Mime-Version: 1.0 References: <20210302150002.3685113-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 04/32] KVM: arm64: Initialize kvm_nvhe_init_params early 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, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, qperret@google.com, robh+dt@kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the initialization of kvm_nvhe_init_params in a dedicated function that is run early, and only once during KVM init, rather than every time the KVM vectors are set and reset. This also opens the opportunity for the hypervisor to change the init structs during boot, hence simplifying the replacement of host-provided page-table by the one the hypervisor will create for itself. Signed-off-by: Quentin Perret --- arch/arm64/kvm/arm.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index fc4c95dd2d26..2d1e7ef69c04 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1383,22 +1383,18 @@ static int kvm_init_vector_slots(void) return 0; } -static void cpu_init_hyp_mode(void) +static void cpu_prepare_hyp_mode(int cpu) { - struct kvm_nvhe_init_params *params = this_cpu_ptr_nvhe_sym(kvm_init_params); - struct arm_smccc_res res; + struct kvm_nvhe_init_params *params = per_cpu_ptr_nvhe_sym(kvm_init_params, cpu); unsigned long tcr; - /* Switch from the HYP stub to our own HYP init vector */ - __hyp_set_vectors(kvm_get_idmap_vector()); - /* * Calculate the raw per-cpu offset without a translation from the * kernel's mapping to the linear mapping, and store it in tpidr_el2 * so that we can use adr_l to access per-cpu variables in EL2. * Also drop the KASAN tag which gets in the way... */ - params->tpidr_el2 = (unsigned long)kasan_reset_tag(this_cpu_ptr_nvhe_sym(__per_cpu_start)) - + params->tpidr_el2 = (unsigned long)kasan_reset_tag(per_cpu_ptr_nvhe_sym(__per_cpu_start, cpu)) - (unsigned long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start)); params->mair_el2 = read_sysreg(mair_el1); @@ -1422,7 +1418,7 @@ static void cpu_init_hyp_mode(void) tcr |= (idmap_t0sz & GENMASK(TCR_TxSZ_WIDTH - 1, 0)) << TCR_T0SZ_OFFSET; params->tcr_el2 = tcr; - params->stack_hyp_va = kern_hyp_va(__this_cpu_read(kvm_arm_hyp_stack_page) + PAGE_SIZE); + params->stack_hyp_va = kern_hyp_va(per_cpu(kvm_arm_hyp_stack_page, cpu) + PAGE_SIZE); params->pgd_pa = kvm_mmu_get_httbr(); /* @@ -1430,6 +1426,15 @@ static void cpu_init_hyp_mode(void) * be read while the MMU is off. */ kvm_flush_dcache_to_poc(params, sizeof(*params)); +} + +static void cpu_init_hyp_mode(void) +{ + struct kvm_nvhe_init_params *params; + struct arm_smccc_res res; + + /* Switch from the HYP stub to our own HYP init vector */ + __hyp_set_vectors(kvm_get_idmap_vector()); /* * Call initialization code, and switch to the full blown HYP code. @@ -1438,6 +1443,7 @@ static void cpu_init_hyp_mode(void) * cpus_have_const_cap() wrapper. */ BUG_ON(!system_capabilities_finalized()); + params = this_cpu_ptr_nvhe_sym(kvm_init_params); arm_smccc_1_1_hvc(KVM_HOST_SMCCC_FUNC(__kvm_hyp_init), virt_to_phys(params), &res); WARN_ON(res.a0 != SMCCC_RET_SUCCESS); @@ -1785,19 +1791,19 @@ static int init_hyp_mode(void) } } - /* - * Map Hyp percpu pages - */ for_each_possible_cpu(cpu) { char *percpu_begin = (char *)kvm_arm_hyp_percpu_base[cpu]; char *percpu_end = percpu_begin + nvhe_percpu_size(); + /* Map Hyp percpu pages */ err = create_hyp_mappings(percpu_begin, percpu_end, PAGE_HYP); - if (err) { kvm_err("Cannot map hyp percpu region\n"); goto out_err; } + + /* Prepare the CPU initialization parameters */ + cpu_prepare_hyp_mode(cpu); } if (is_protected_kvm_enabled()) { -- 2.30.1.766.gb4fecdf3b7-goog