Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4080253pxb; Tue, 10 Nov 2020 07:30:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPfDtRpEERg+2qS1sHwqUdiy6awZ4rjp/FnY3eGSVANWxcg08BBz3rxEkx+iunoq0/Mgyp X-Received: by 2002:a17:906:6b86:: with SMTP id l6mr20305458ejr.524.1605022212346; Tue, 10 Nov 2020 07:30:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605022212; cv=none; d=google.com; s=arc-20160816; b=g8NPjyMk+qrxswq9JgDBj4YHFzi11RLLkEfmlDtClW1jmhblHfQ1WkWH5Ny3rMKlPB XP9MumCYhQeLEgEuaLstF94ya/rHJLgQG2ghQNvQl5BwR1k49gHd4xaoozoh9uiXmxpE YoveOEFGYP26qpYNgzaMKgDtYWRrBWLehJds8XJFhTYjTt0lvJeCVCpnwo9zjit/pWIJ lFZ0QRJgiuoBAp/IRh8BNy+dcbAq6sJl/SBx4OfC+70vmudE4UJsRt2mb5H5eRE8GbGy r2cDLFaSH7zUhe/3RIidE3rWs0c5lQbBaJKNqcgJ1Y7O1eMYiwXPMjAyiD9oa8mEOec9 Xq4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=zUEfktMlLLxiLeikIIBTLumbI9Myg57btqeCbRGyXm0=; b=uOMvwtBemK35Dujc5WVX5s1sL5/j2T+EYpylqwVqhCNq1PSDuBw0nioVOqJzrPROCg M6Q9AzfmzGJ2TCKd/xDqldcvKF3RQoVnESaTyuVwXeCaqdLfjM6cz7axauBefSPNh8X8 E1DFtD8yN3srG6iFhxH4b+wGiSKqyl98tIZ3GznOkRfq7Ze9Yowe5sx/dqdPf9p5XfBk QbgiVNhLgFrVcqUPUXHjs2IoIbBBvvGH8KyQuJ/PHPBG5I6tRX2XyYggGMQMYCPmrRX6 pwIN+N62whsDgrQWFP/PO4DY9CLdh8A5c6mQrEoqhSFOYZryISkU5Q7u9Ryqf2jnWhBw zpgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xfNstsPM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si10174436edn.504.2020.11.10.07.29.39; Tue, 10 Nov 2020 07:30:12 -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=@kernel.org header.s=default header.b=xfNstsPM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732593AbgKJPY6 (ORCPT + 99 others); Tue, 10 Nov 2020 10:24:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:32848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732232AbgKJPYz (ORCPT ); Tue, 10 Nov 2020 10:24:55 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ABD57207D3; Tue, 10 Nov 2020 15:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605021894; bh=6grBIe9Ab1qZ3+EKmKO+hoC/BEgkpYoULIb3EV2t5yo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=xfNstsPMqn3ECov8nxjyJrLJ1+DSpZyC0Ss8RG/e28rt4BLSM8F0v7CrR9L+ZA0/S RSUEjAK3adrJk6vUBiDTu6vDp24Jz1wWPISq73w6uzLvPeMvrBW1AaQTEgfm7tBt24 dVU5iImG7WCRm7bkND2kFaKfCAF6YXP3QSVDTu2w= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kcVVs-009UKZ-Jg; Tue, 10 Nov 2020 15:24:52 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 10 Nov 2020 15:24:52 +0000 From: Marc Zyngier To: David Brazdil Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Quentin Perret , Andrew Scull , Andrew Walbran , kernel-team@android.com Subject: Re: [PATCH v1 07/24] kvm: arm64: Create nVHE copy of cpu_logical_map In-Reply-To: <20201109113233.9012-8-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> <20201109113233.9012-8-dbrazdil@google.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: dbrazdil@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, dennis@kernel.org, tj@kernel.org, cl@linux.com, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, qperret@google.com, ascull@google.com, qwandor@google.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-11-09 11:32, David Brazdil wrote: > 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 | 17 +++++++++++++++++ > arch/arm64/kvm/hyp/nvhe/percpu.c | 16 ++++++++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 9ba9db2aa7f8..b85b4294b72d 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -1481,6 +1481,21 @@ static inline void hyp_cpu_pm_exit(void) > } > #endif > > +static void init_cpu_logical_map(void) > +{ > + extern u64 kvm_nvhe_sym(__cpu_logical_map)[NR_CPUS]; > + 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) > + CHOOSE_NVHE_SYM(__cpu_logical_map)[cpu] = cpu_logical_map(cpu); > +} > + > static int init_common_resources(void) > { > return kvm_set_ipa_limit(); > @@ -1659,6 +1674,8 @@ static int init_hyp_mode(void) > } > } > > + init_cpu_logical_map(); > + > return 0; > > out_err: > diff --git a/arch/arm64/kvm/hyp/nvhe/percpu.c > b/arch/arm64/kvm/hyp/nvhe/percpu.c > index 5fd0c5696907..d0b9dbc2df45 100644 > --- a/arch/arm64/kvm/hyp/nvhe/percpu.c > +++ b/arch/arm64/kvm/hyp/nvhe/percpu.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 }; I'm not sure what __ro_after_init means once we get S2 isolation. > + > +u64 cpu_logical_map(int cpu) nit: is there any reason why "cpu" cannot be unsigned? The thought of a negative CPU number makes me shiver... > +{ > + if (cpu < 0 || 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; Overall, this patch would make more sense closer it its use case (in patch 19). I also don't understand why this lives in percpu.c... Thanks, M. -- Jazz is not dead. It just smells funny...