Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp643815pxu; Thu, 26 Nov 2020 07:59:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1fHW42gyEnY8+fl1mwMSNaRJ/OHEI0BLoPcKu16QiDQcoTR8/O8Oh3jpzJWpIzrtfSC8g X-Received: by 2002:a05:6402:1b05:: with SMTP id by5mr1840500edb.237.1606406348599; Thu, 26 Nov 2020 07:59:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606406348; cv=none; d=google.com; s=arc-20160816; b=v+HCDeQuD9JBgDS/aWl/eJi8VLyWZVcQY7l23MLqu2IxcXRNC1Ceru9enZG9ud5o36 OKelDV6meXIuTv/Pch1TlA+pF4XMOiLrBcF50gGjCyI/GqJ+Uq9HUTKid5BcGGliTuVl RVVEwmb+E73JNot+giHqQcmj56/mmQIsBBvZZQXe9KVpFiQKB2C567XpV760NP8r7a6X RnKTqMRg36jQlFo1r/KRVTCsstYxBz+08NI4gxbfV/JqfApVih2AJ2TPoMtuYO3ZQu62 wbWYODwMd6duBUmPF/C+/vK0Qjx0leeeMlM1+cVBo4uskDO1ObnpRdAyb3hhkujbu0Z/ wKIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=abHZKvAnOIOh0cfJUm3aASRkjBMLNkdSVRPPeTy9mxo=; b=Smt9qbwUQLaoKpvgX8Jr61YV9UMXmjd4Wpp31uTwR3xjkxvW/pfoOQPc/QBy04a7rL qRv79jOoQFH1UEv5dsj/0wIGxDsK+ZW3PAFFz52BJPgtCvGKlZCWriw+0a3DuOgXDKNz +rrQMpQKWrYY9KKh8QONrtZUFGC8IoKZVRarOSZYndqdreumoWHSvastjjUuSxeR88rr dtBd2yOK4Q5gEZKYQzF1zHYI5YQQHIynI2xObFL3YnuNXgRnrBUUtJVbCVRH7m7jQvrf qkbyUzyppPA38lbc/whmB2lkXF9GxhRmnqHFC38O1TcwML5ccAJxj7EO4amakuwUIVmX jKtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jqLq4mvu; 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 ec3si3384566ejb.731.2020.11.26.07.58.40; Thu, 26 Nov 2020 07:59:08 -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=jqLq4mvu; 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 S2403896AbgKZPz1 (ORCPT + 99 others); Thu, 26 Nov 2020 10:55:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391464AbgKZPyy (ORCPT ); Thu, 26 Nov 2020 10:54:54 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5E8CC0613D4 for ; Thu, 26 Nov 2020 07:54:53 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id 64so2616935wra.11 for ; Thu, 26 Nov 2020 07:54:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=abHZKvAnOIOh0cfJUm3aASRkjBMLNkdSVRPPeTy9mxo=; b=jqLq4mvuFUHRNYTuDA8X4VqzR999IfDP4q84W39BYEKyBQxNgrPCGYrczkPYGhK3xu rAyOQQer3BhE9duh1aWdFCeG+6knjdw5TuROmYdg4HhznGrigbB06JqMnjAT7xfK+est C3hOyQ9Hz6DwLFMNdCGX7L+t1pUqK9ugYB0c9EsrTz5zLyPmstSDlVJslLskorCLfkLJ xnDwNLr1x8JteRXu7nG+IZYBSzTE8FzQbQlInhi+UOtUpSqxM/09so4wFxOqzOzG7W3k fMq1ulRSMT+FhtRSYbgZxKC8qiIf4rnRr+xoJ9PrqtwZUt/DvnRvDjiCJXDqxMKOdZfk IUcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=abHZKvAnOIOh0cfJUm3aASRkjBMLNkdSVRPPeTy9mxo=; b=W7TGF0EUHt+JFMZWmTfnAXN+h3UIp6KuLQd0HkLheOquTL92spT1YmA2NrptecYZdP Y10GL9EcMSF9eMuKADBd63AYDPSJIERFLaB/6xD+Fl/0HgLdCVtcwaNXAxY9ftEvpzDL XhBosogIc45Iw9dkL6A7ZzphW66ElYGOg0pBwy2kPOCoSNYGNOiI1vFs+VNNJZ8HXbso Tv+ZEezO5cDMYD8THtvOpqTrM4P5vmGoRhjOd6TVpDeZXnVwjFWyc7tpsUMFFN61T6Gt uanAuYi1/DVKMe4i8B7kQHPynh+LP+6hLwpQA5TCU4Vtp+N61MY7eP53+YtkBkVey/ZR lXsQ== X-Gm-Message-State: AOAM530LzHAJksiOxSQk6ZLbyiooUD+N2ZC5zEapXSRF0ff1qT1bBy3i i310bLu/RTr05Ub8tsvzJ6YE/A== X-Received: by 2002:adf:dc83:: with SMTP id r3mr4498991wrj.223.1606406092266; Thu, 26 Nov 2020 07:54:52 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:f008:704d:8d4b:9951]) by smtp.gmail.com with ESMTPSA id r13sm4193297wrm.25.2020.11.26.07.54.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Nov 2020 07:54:51 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: Jonathan Corbet , Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, David Brazdil Subject: [PATCH v3 12/23] kvm: arm64: Create nVHE copy of cpu_logical_map Date: Thu, 26 Nov 2020 15:54:10 +0000 Message-Id: <20201126155421.14901-13-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201126155421.14901-1-dbrazdil@google.com> References: <20201126155421.14901-1-dbrazdil@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When KVM starts validating host's PSCI requests, it will need to map MPIDR back to the CPU ID. To this end, copy cpu_logical_map into nVHE hyp memory when KVM is initialized. Only copy the information for CPUs that are online at the point of KVM initialization so that KVM rejects CPUs whose features were not checked against the finalized capabilities. Signed-off-by: David Brazdil --- arch/arm64/kvm/arm.c | 19 +++++++++++++++++++ arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index bb07f0401c68..bb3c541d3ddb 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -61,6 +61,8 @@ static bool vgic_present; static DEFINE_PER_CPU(unsigned char, kvm_arm_hardware_enabled); DEFINE_STATIC_KEY_FALSE(userspace_irqchip_in_use); +extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; @@ -1531,6 +1533,20 @@ static inline void hyp_cpu_pm_exit(void) } #endif +static void init_cpu_logical_map(void) +{ + unsigned int cpu; + + /* + * Copy the MPIDR <-> logical CPU ID mapping to hyp. + * Only copy the set of online CPUs whose features have been chacked + * against the finalized system capabilities. The hypervisor will not + * allow any other CPUs from the `possible` set to boot. + */ + for_each_online_cpu(cpu) + kvm_nvhe_sym(__cpu_logical_map)[cpu] = cpu_logical_map(cpu); +} + static int init_common_resources(void) { return kvm_set_ipa_limit(); @@ -1703,6 +1719,9 @@ static int init_hyp_mode(void) } } + if (is_protected_kvm_enabled()) + init_cpu_logical_map(); + return 0; out_err: diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c index c168d86f885a..ceb427aabb91 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c @@ -8,6 +8,22 @@ #include #include +/* + * nVHE copy of data structures tracking available CPU cores. + * Only entries for CPUs that were online at KVM init are populated. + * Other CPUs should not be allowed to boot because their features were + * not checked against the finalized system capabilities. + */ +u64 __ro_after_init __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; + +u64 cpu_logical_map(unsigned int cpu) +{ + if (cpu >= ARRAY_SIZE(__cpu_logical_map)) + hyp_panic(); + + return __cpu_logical_map[cpu]; +} + unsigned long __hyp_per_cpu_offset(unsigned int cpu) { unsigned long *cpu_base_array; -- 2.29.2.454.gaff20da3a2-goog