Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4067349pxb; Tue, 17 Nov 2020 10:21:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJykP/yhlrcC+Q98GtyJMgvmY6imLHDTtIrKwqmhbNjBx3iSUweEaZyK3igyEtLG/DhMmshR X-Received: by 2002:aa7:c3c3:: with SMTP id l3mr22313194edr.118.1605637290228; Tue, 17 Nov 2020 10:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605637290; cv=none; d=google.com; s=arc-20160816; b=S0r+3a2nY1eOpPCEvPAapHScgeqF/TNv4+NXO2DlgpKluBiJmZk0z4PuQsxo9hhoXT QURk9sZMBYTCMcDr0nxjMRnTKg2/PHCQ19mL6ahtTih4HNe+pxLUkv31jgiA6Zzd/qHi Cmd0ZuHwGinzngPaHI14NrqmP0SInQWGLsbSwsGDj64oLEq13jIOTikSoT9MCWXjm0u+ vuzOFtPGgC6/FEEP/PJAdEceoqgXx1Aqw7P0Q13U0JLL0l/xxewvVsjU9ZokscO6tF6n xoTL8ljt8nAyAS22AHm3V7t0uhnDfT4AKGVn0Rg/18c5J3CKp5fan1Kw8YDm5/F/y5Po CizA== 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=IZC56EUbcZGLv67uWppNeQH9/JsQWBJOLy6w8MLjYOk=; b=ugDvz4EagGlp0uJqneia6bT5M2rEzC4F17WYo7itD0KibTNMF2/ZQGxo65OOoORfPu DL04t8Tz9gtthX+Egkzf19cupxZBoD2XgoKWNiu79ce3XhQbWY7Vs3NmAaWmJ7gaFT5n +5mUv+so1Hz72n9Na0B756HiGCESco3cE02WspCHgNiVtl0xyYi/ALx5vdevtOBXtu0I rJx2ozfwySKKsJKvwgUPIY/ghLmZGZqd3r8myM9c9GFW1/gnlQvknbJV7agEmX+8NnEG BSJVefeUzY2k8e9bjL/HhEnGzozlson+w/VvhnL1FKzJf4ncE5FEjyDA0X9DP/GpL50a 1MlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="vS+rvB1/"; 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 a21si3634589ejd.281.2020.11.17.10.21.06; Tue, 17 Nov 2020 10:21:30 -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="vS+rvB1/"; 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 S1730682AbgKQSQd (ORCPT + 99 others); Tue, 17 Nov 2020 13:16:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730673AbgKQSQb (ORCPT ); Tue, 17 Nov 2020 13:16:31 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3BC3C0613CF for ; Tue, 17 Nov 2020 10:16:29 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id y21so55592wma.6 for ; Tue, 17 Nov 2020 10:16:29 -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=IZC56EUbcZGLv67uWppNeQH9/JsQWBJOLy6w8MLjYOk=; b=vS+rvB1/6KGnGkdgssdAFqr2pdbbPpSdTO3v0TbihY/ScWy+IKWsAhYSb+9u1xIoQY iJ5ArdUb3OBFMAalNNv9B0qc726x3h1bvk8i+Bt1in0DvI/BetdAiJgv2iq6+11P85K3 POOkjSLXMrr5CvPC7Usq08l9ERlJLMKxBdTUq+O3qFMGt1wjdx9cjLeG1FpZm0WbcGgI gWEdRNRf4cc7JUlIQ8kW/6J7K8sBCpWEHsM8GS/TPC0z9RhMv2am4tyeUPp/P/FUsJ0h xuW1/Ugcc9nP8aKCuNn+d2qK3dxsz5m2Qxz8K4SfKxYCDJLLMPLQDJAyyK1BKwJgdl4V VQOQ== 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=IZC56EUbcZGLv67uWppNeQH9/JsQWBJOLy6w8MLjYOk=; b=czTDfzrvRFTXGUeHcYEX9S3A1Bn5OAMPDU7d8hOPaXvL3smLALelTNxBDZNRip4Ci6 nMAw2UlCTRc63DGNQGLcCFSyfOUpGSHP4dPuRCCEqDE5boBS/rbd1GFHJ4uEaduAXf/m 3GEwhsjIGq/5y6YpnYYaewf7hs4tVsbRfSpT8j7rlNgBS0IX5kHB3j9bYwGZjL2JWil9 GhSDAJdKQcpr7yEgKpY8A6fwqZiH0AxicVe0J+3oP8S1z1Eofcb51jy9nJ3jYLQAVw21 KBIF2FBh1PqkKarOA6HdkBjHnwIru+D+oXYubL+ujwmD74XI6zpreC0hKVEYdZGDKivy YnsQ== X-Gm-Message-State: AOAM530/NUMpWZKzORhFRhWYf8OXv0jirao8cYV56DWEJTa5zoMJM3j/ KaMJc1K9g5i0MXpcQ0Y6YK3yb1gYxoJ4 Sender: "qperret via sendgmr" X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) (user=qperret job=sendgmr) by 2002:a7b:cd10:: with SMTP id f16mr348760wmj.69.1605636988252; Tue, 17 Nov 2020 10:16:28 -0800 (PST) Date: Tue, 17 Nov 2020 18:15:44 +0000 In-Reply-To: <20201117181607.1761516-1-qperret@google.com> Message-Id: <20201117181607.1761516-5-qperret@google.com> Mime-Version: 1.0 References: <20201117181607.1761516-1-qperret@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH 04/27] KVM: arm64: Initialize kvm_nvhe_init_params early From: Quentin Perret To: Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand Cc: "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , open list , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , kernel-team@android.com, android-kvm@google.com, Quentin Perret 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-tables and stacks by the ones the hypervisor will create for itself. Signed-off-by: Quentin Perret --- arch/arm64/kvm/arm.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index d6d5211653b7..7335eb4fb0bd 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1355,24 +1355,20 @@ 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; - - /* Switch from the HYP stub to our own HYP init vector */ - __hyp_set_vectors(kvm_get_idmap_vector()); + struct kvm_nvhe_init_params *params = per_cpu_ptr_nvhe_sym(kvm_init_params, cpu); /* * 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. */ - params->tpidr_el2 = (unsigned long)this_cpu_ptr_nvhe_sym(__per_cpu_start) - + params->tpidr_el2 = (unsigned long)per_cpu_ptr_nvhe_sym(__per_cpu_start, cpu) - (unsigned long)kvm_ksym_ref(CHOOSE_NVHE_SYM(__per_cpu_start)); params->vector_hyp_va = kern_hyp_va((unsigned long)kvm_ksym_ref(__kvm_hyp_host_vector)); - 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->entry_hyp_va = kern_hyp_va((unsigned long)kvm_ksym_ref(__kvm_hyp_psci_cpu_entry)); params->pgd_pa = kvm_mmu_get_httbr(); @@ -1381,6 +1377,15 @@ static void cpu_init_hyp_mode(void) * be read while the MMU is off. */ __flush_dcache_area(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. @@ -1389,6 +1394,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); @@ -1742,6 +1748,12 @@ static int init_hyp_mode(void) init_cpu_logical_map(); init_psci_relay(); + /* + * Prepare the CPU initialization parameters + */ + for_each_possible_cpu(cpu) + cpu_prepare_hyp_mode(cpu); + return 0; out_err: -- 2.29.2.299.gdc1121823c-goog