Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3136565pxb; Mon, 9 Nov 2020 03:41:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/aZ6UkBfKAF82+dhRRRriMMm14LPhXN2bvbEUE6NxibKGms1GwkeY5cLUSL+drVTrgdeD X-Received: by 2002:a17:906:3092:: with SMTP id 18mr14440729ejv.43.1604922108506; Mon, 09 Nov 2020 03:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604922108; cv=none; d=google.com; s=arc-20160816; b=G7vY0x8mdEoE4fhezDJMYnb0YjjQfnf28y+tPJ1zPHAR4qfRt/hCB8YSQk9x+i/6ZL 6pEHmGd7uJbaL+xFRO/rsJumBMzDrmow7n4KruGsIH22nD9k0cb7EziPp8pRKOcOiYr+ xhJU5sBQZ5MN6DWSzzo7ZnMOH+3FMkrv03QspoY0kDdfzRWUCG3ZKX3ENvpUl1PqK29/ C0nfnxzfN57rrI1rVTv5oxtt27aEjYrmT8Mm2QEUachOAvpoKTI3g73PNa2oFBdiebZ6 Og2J8jZsb31BtezY7QI6lO7LXfcQtQHpXexLCa94mYEIXvdJTOx8wFHDwzYsN+lBBf9K q6Mw== 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=E1NKlSXbosotz7yE3k2vTKr2ydlvsygMA7t9DehWpvE=; b=xHNIGXgZHC49hU5HV///jbn4Ar77HmMpEBK+M9LqM2JxZy8TBY5t/80vi2PP534df4 OhKhxN7Tt3iiw9jwiL/JILIgKpHjnmAznSoKJ0zSm7xmg6b2rs4VGP1U/BeaXBqgILfB TZC8qm6QaYYjJzqkU1CClOf8JGf3cTORDF55OUEuUK4GkBVhHowTKzzh3uLkELme0uPC eqZWZU7L+9RRX8qBkREM5yOIcrGn+VYKqLE1m9oJQJS7XtSaJMFF2F2FOyOd3kP1PPZX l8jt3FgmHGr3X2aqy6Jqc+xfjMQdel6t8Q64QMvs6gUBkpUhr/dmDbkscaMEF6v68Th4 Q3tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=l5mFBYX1; 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 q10si7976259eji.684.2020.11.09.03.41.25; Mon, 09 Nov 2020 03:41:48 -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=l5mFBYX1; 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 S1729830AbgKILhD (ORCPT + 99 others); Mon, 9 Nov 2020 06:37:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729530AbgKILc4 (ORCPT ); Mon, 9 Nov 2020 06:32:56 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8F4C0613D3 for ; Mon, 9 Nov 2020 03:32:55 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id s8so1210625wrw.10 for ; Mon, 09 Nov 2020 03:32:55 -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=E1NKlSXbosotz7yE3k2vTKr2ydlvsygMA7t9DehWpvE=; b=l5mFBYX18Rn7YX+QOaWfw6pSERAucDkfSD0fLjY2La9KEXAkogCnx0MlXxkUnnQruE hcRz3mFUUHEK7BkHrKmHKS7z4K9kzSMySOyP7FbGc3/T8JrugpkNZIt/AJ44AdxcV/y9 7EGITSkupXBoishh0kGdsfNPWgvqpzGLGKMdOBFcz0OhhjZ9kNWpadYeoPxbZ90OQ0rG QoZLm++zKXNxDhFNzhQ4FEt5gWvnAlfXkA27lW91g6b2Ie32EmXFrFBg/m4ggOxY1441 ypg58scvklmkltXN9bpd2eLzNMuaLpFOQc9Qw8AdB4l22lVMqsm9gnPrsu3lwPJtpD7k bfQw== 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=E1NKlSXbosotz7yE3k2vTKr2ydlvsygMA7t9DehWpvE=; b=sbZsWdovy0mpJFsfvnr/ad1/DaHPQ7CCbTiop+6dqSqa/XQHvDRsX0gf6TsYelxWIm Gs2/ySCXOMFPjNDrYs5IaS9/SCgKi/gnLIhBw/bpDexn7tDEVFROZb7kJyFOBC16LyA1 mByzYxC19mNwCe5G69pfdHwaNwTIjkPx6pk8H8FhZTI0qKirEs04x3gzMUjyztxjrD24 5W5kw2Y4qABUgtujpbMiJO+KW+O0zDjqys3pkPtoVy93A0Dx84Q1dV8rxqNQl4d4GkqR jciEYb5cLtu0ctOgrQGpTvZammtIkweRudhUR3gUcL3BG6RgGzjGDP2vtoc8FicB/LIp mPpA== X-Gm-Message-State: AOAM532wH466Z8CLljXO6+Dd2T0Rdd8sFoKsKDOgYXdxa/S2S6Gcjx0M TdWvVXkkSNENd3Z7V8526BXuyw== X-Received: by 2002:adf:e287:: with SMTP id v7mr17824035wri.252.1604921574345; Mon, 09 Nov 2020 03:32:54 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id f23sm12132699wmb.43.2020.11.09.03.32.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:32:53 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , 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, David Brazdil Subject: [PATCH v1 07/24] kvm: arm64: Create nVHE copy of cpu_logical_map Date: Mon, 9 Nov 2020 11:32:16 +0000 Message-Id: <20201109113233.9012-8-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-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 | 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 }; + +u64 cpu_logical_map(int cpu) +{ + 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; -- 2.29.2.222.g5d2a92d10f8-goog