Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1091123pxu; Wed, 2 Dec 2020 10:46:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9IOTvx3bJaUTrzAl5/+DMv4Hl7XLXoZHn7ArKoIH48GAyMujS39t4z+QE5OHS0g7dmiTH X-Received: by 2002:a05:6402:c9b:: with SMTP id cm27mr1333711edb.294.1606934785458; Wed, 02 Dec 2020 10:46:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606934785; cv=none; d=google.com; s=arc-20160816; b=zEbQIYDV7j0E1tPv78EJlmA80VOHLWCAEKXywKnxQneQNmV4hszok5jXQB6ZJLz3MJ xfIsWxFl1oYqvgQs5MLxYGGJaoc+4rraMSOjfzODqzS8aLDCtub10L2QofrfP3nJF/hw ob18F1lWpfNNU2ib03dfoUiOV/NUHibHVFLcB5lJwxDbGt3IzAzZIVYTGx1hSZc7vJe5 l8jtzlvRtVDwC9hXMG4SfeLAHSNmTix8DS4tUMOr11krfxS5NL1zXYkhG+Am5II6e2Oe Dan1rVPBoWQ/MH9lQ6hmUax0WF7DWPjnt1HuT2gaWUnPwdTaEjaDVG6MEgNNJ8k8okXv X6mw== 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=acdB9myIWDy4DJFolYzOe4SZxoOSmlBPTOQxNwh7fkY=; b=UbipaNuSY6I4mJbhxHF4x2BDv5cmZgGr9Ke2bI1vp1CS0i+3zug1OfplEHdwSQT0Nc Wsn8AmnMUuSqW2FkdBiQyPvGCPuS+9mtNTBkChJWOl1CJRdqPvJ16ZSkacQqVq8x7Dox A5NcNLAdN33NcrNjyJ8lNcLYUTPEJ3tObUK4FyegJNHkmTd3b3+w3RkZB801je/koYRe ZNm/v58kID9hRsQEdh2e0lT5xCqra6p6PS2UPBsR1jwP5zV/Myr8Wgf11AjJaHXkHd16 4tBIMyXJHPrne27tnjg4e8rSMHD6yzsibbun1Ka9jRUSOlbK+EU4sZJPk6MErqHlHc9z 13fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FSAcmlxF; 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 j26si468061eds.457.2020.12.02.10.46.02; Wed, 02 Dec 2020 10:46:25 -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=FSAcmlxF; 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 S2389584AbgLBSne (ORCPT + 99 others); Wed, 2 Dec 2020 13:43:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389577AbgLBSnc (ORCPT ); Wed, 2 Dec 2020 13:43:32 -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 CE51CC08E863 for ; Wed, 2 Dec 2020 10:41:57 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id t4so5091579wrr.12 for ; Wed, 02 Dec 2020 10:41:57 -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=acdB9myIWDy4DJFolYzOe4SZxoOSmlBPTOQxNwh7fkY=; b=FSAcmlxFDzuSUOeF5TGkNCgmVQmWPU2u0IKkkvgG9Ot1WbCofrNuJYCBmgE3OAlNr+ m9Ifb05xO6DRGHvirgILi6saMn/UeeokDDYPbeJbT2J5yM5PY1lXarCs5wZXyPnBKWG6 Qb8ilNqTHFiZXKqSaGDxVKb5sblwFv6YMXqYCJaVzMPqJi4n6knBKqcOu+bSLQy+ieAT xFvIh6NMyrZ5lQMaz5O69R1f60gvYLNVcYiRszXQ9cdUbJ9oIN5m6JKUy0nWYZ9L4381 3vsc4Yt0IHyOp8an6PNdtYWs78pR1CUJmWEcVQRyw/zVl5H1KkfqmPs8qdGhZvTEWMxh qqXA== 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=acdB9myIWDy4DJFolYzOe4SZxoOSmlBPTOQxNwh7fkY=; b=XqJgi5Ja5GJSC3gn4WBJ4KPSdIB1Dbs38aflMJBUmEOUwN5uf5CidM7pRyVRVDyqdk qwPbNp4gK7xlfSQSl9hiWLlHydM1NbLkJ8AGhk3VVv5Sxj/kFCKdbjsP6MR0mDi7xvYi i21RNfKuBaKyeaQCn+3P1KQxbPd3Zui0AWZIxfiVyQXTiZReO15ZiglhIsJhjizf3DwJ dpDPyHYMQRAhusyRd1iFobH5Qdb7X5tH25OTlVbFDXPWCEUTMGM+rYTBRYQc7wcJrHpp GQS/X9cmkAZ7arV2j6swR2zy91YsQcbeHI99XNTARib96bh6WcFTwCfOJxZPzWQo8xud IlFg== X-Gm-Message-State: AOAM531eoT+WjbDM0Yw4XzkSCov03y/rIYJgqTvFKt2+EmubS8amQG2M ljbYMRq+6lFZdhVj+gjBmGIZtA== X-Received: by 2002:a5d:4892:: with SMTP id g18mr4992479wrq.365.1606934516331; Wed, 02 Dec 2020 10:41:56 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:5ddd:b7c5:e3c9:e87a]) by smtp.gmail.com with ESMTPSA id n9sm2918860wmd.4.2020.12.02.10.41.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2020 10:41:55 -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 v4 13/26] kvm: arm64: Support per_cpu_ptr in nVHE hyp code Date: Wed, 2 Dec 2020 18:41:09 +0000 Message-Id: <20201202184122.26046-14-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201202184122.26046-1-dbrazdil@google.com> References: <20201202184122.26046-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 compiling with __KVM_NVHE_HYPERVISOR__, redefine per_cpu_offset() to __hyp_per_cpu_offset() which looks up the base of the nVHE per-CPU region of the given cpu and computes its offset from the .hyp.data..percpu section. This enables use of per_cpu_ptr() helpers in nVHE hyp code. Until now only this_cpu_ptr() was supported by setting TPIDR_EL2. Signed-off-by: David Brazdil --- arch/arm64/include/asm/percpu.h | 6 ++++++ arch/arm64/kernel/image-vars.h | 3 +++ arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++- arch/arm64/kvm/hyp/nvhe/hyp-smp.c | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kvm/hyp/nvhe/hyp-smp.c diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h index 1599e17379d8..8f1661603b78 100644 --- a/arch/arm64/include/asm/percpu.h +++ b/arch/arm64/include/asm/percpu.h @@ -239,6 +239,12 @@ PERCPU_RET_OP(add, add, ldadd) #define this_cpu_cmpxchg_8(pcp, o, n) \ _pcp_protect_return(cmpxchg_relaxed, pcp, o, n) +#ifdef __KVM_NVHE_HYPERVISOR__ +extern unsigned long __hyp_per_cpu_offset(unsigned int cpu); +#define __per_cpu_offset +#define per_cpu_offset(cpu) __hyp_per_cpu_offset((cpu)) +#endif + #include /* Redefine macros for nVHE hyp under DEBUG_PREEMPT to avoid its dependencies. */ diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index 08e69faedf6c..39289d75118d 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -99,6 +99,9 @@ KVM_NVHE_ALIAS(gic_nonsecure_priorities); KVM_NVHE_ALIAS(__start___kvm_ex_table); KVM_NVHE_ALIAS(__stop___kvm_ex_table); +/* Array containing bases of nVHE per-CPU memory regions. */ +KVM_NVHE_ALIAS(kvm_arm_hyp_percpu_base); + #endif /* CONFIG_KVM */ #endif /* __ARM64_KERNEL_IMAGE_VARS_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile index 77b8c4e06f2f..cf11f8182756 100644 --- a/arch/arm64/kvm/hyp/nvhe/Makefile +++ b/arch/arm64/kvm/hyp/nvhe/Makefile @@ -6,7 +6,8 @@ asflags-y := -D__KVM_NVHE_HYPERVISOR__ ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o +obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \ + hyp-main.o hyp-smp.o obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \ ../fpsimd.o ../hyp-entry.o ../exception.o diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-smp.c b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c new file mode 100644 index 000000000000..7b0363b4857f --- /dev/null +++ b/arch/arm64/kvm/hyp/nvhe/hyp-smp.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2020 - Google LLC + * Author: David Brazdil + */ + +#include +#include +#include + +unsigned long __hyp_per_cpu_offset(unsigned int cpu) +{ + unsigned long *cpu_base_array; + unsigned long this_cpu_base; + unsigned long elf_base; + + if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)) + hyp_panic(); + + cpu_base_array = (unsigned long *)hyp_symbol_addr(kvm_arm_hyp_percpu_base); + this_cpu_base = kern_hyp_va(cpu_base_array[cpu]); + elf_base = (unsigned long)hyp_symbol_addr(__per_cpu_start); + return this_cpu_base - elf_base; +} -- 2.29.2.454.gaff20da3a2-goog