Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3978816pxk; Tue, 29 Sep 2020 10:52:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLWKr9qQPzRZxGMgTm+ov6ZhjsyY32wHz4WY9sXPZLfSYYCxKaUsLpQsyt+Yk9YYiFYhI8 X-Received: by 2002:a17:906:2e14:: with SMTP id n20mr5230405eji.214.1601401965654; Tue, 29 Sep 2020 10:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601401965; cv=none; d=google.com; s=arc-20160816; b=HhaWD47tABZkTJTZPr8GY5fCNZrv1oCyaAVgxHlUG/MBozyNa+enb/JYmm3SqY1V94 D4Ix5yO/j2zACyaFUInhARHaMleE/wL53zjdT3tB5wRtrtiRCnLbuppLJjdiP/4KI4zE JYrsK+6wVzYvUft4Mi91S7LYOjsP4NC0BdjQxTp5ypTlZwgmfVUVI2KipWsEA1d0UcB1 0cjPk30icfeeV02uHB5JA7guT37pHjAxr7RhITfq1AS7ha+3+P14OT1M1D+YcUa/aedY uK/JePe+dybT7Z1Z+yUKZW3tCmR8R5/u6Z7u9XlRvYL2AwfHfYIa+XThl9+YWts2i/dB 7C0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=P7diGSdqZBW88D9WYODpTn6ftDAxdbDl0fc3DjyxqEQ=; b=r2vsw8qHFcpWxSabSPKpcfT+sEx4P6a7wH3ecWp1iGHyZNy4bGe/+DyelM9d7/YuJP e4zAiXYfiucXkj5kse5O8yt1azraN7jWVvvxiCUofXBQObC3ADSh7wMp+IJKh8u0Em39 HRXRr5auG4oYXpMrTYEK+ZcBZxBNp1gzTmY4J5i6Te25mugVlpSj+23mgnk04ztWUMKM ixq2FVvX8Geexf8rg/+ioLMPenB/f9HiRznoKTzkVaSdjpFpef8Y1j0A958qurMHfzmJ EK3TXiznioFNMjz8ynqXwWY3luHCuckywPApUQna1A5ZYVKCSplKezpGP6StxJ0fwVoN ZwfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v3iYD7Op; 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 di23si3391364edb.451.2020.09.29.10.52.21; Tue, 29 Sep 2020 10:52:45 -0700 (PDT) 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=v3iYD7Op; 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 S1729209AbgI2RuT (ORCPT + 99 others); Tue, 29 Sep 2020 13:50:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:51908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728565AbgI2RuT (ORCPT ); Tue, 29 Sep 2020 13:50:19 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 58725208B8; Tue, 29 Sep 2020 17:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601401818; bh=uBLV+tu6o+mROcgLnwH2kdhzX8zXFfZBmHNyNsTufv8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=v3iYD7OpFw8zFjcLyDlK28tE1YugikhyVROqyNQNQXGTtRvbJ5nMFGBGZU4jhQpyD QrT9/eGRyiE+wLiMK5xmIbrszrN+BrjVfcIQuG9GTaJx0xdTgZQhPYNgzze8QWXdy5 S/tgJ5YYrn1TGsSGZEyBNR3kTP/ZyWfI6gf2nYzc= Date: Tue, 29 Sep 2020 18:50:13 +0100 From: Will Deacon To: David Brazdil Cc: kvmarm@lists.cs.columbia.edu, Catalin Marinas , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Dennis Zhou , Tejun Heo , Christoph Lameter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v4 09/10] kvm: arm64: Set up hyp percpu data for nVHE Message-ID: <20200929175012.GH14317@willie-the-truck> References: <20200922204910.7265-1-dbrazdil@google.com> <20200922204910.7265-10-dbrazdil@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922204910.7265-10-dbrazdil@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 09:49:09PM +0100, David Brazdil wrote: > Add hyp percpu section to linker script and rename the corresponding ELF > sections of hyp/nvhe object files. This moves all nVHE-specific percpu > variables to the new hyp percpu section. > > Allocate sufficient amount of memory for all percpu hyp regions at global KVM > init time and create corresponding hyp mappings. > > The base addresses of hyp percpu regions are kept in a dynamically allocated > array in the kernel. > > Add NULL checks in PMU event-reset code as it may run before KVM memory is > initialized. > > Signed-off-by: David Brazdil > --- > arch/arm64/include/asm/kvm_asm.h | 19 +++++++++-- > arch/arm64/kernel/vmlinux.lds.S | 8 +++++ > arch/arm64/kvm/arm.c | 55 +++++++++++++++++++++++++++++-- > arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 6 ++++ > arch/arm64/kvm/pmu.c | 5 ++- > 5 files changed, 87 insertions(+), 6 deletions(-) Acked-by: Will Deacon But one comment for Marc below... > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index 911d91787fa0..863f669d4dc8 100644 > --- a/arch/arm64/include/asm/kvm_asm.h > +++ b/arch/arm64/include/asm/kvm_asm.h > @@ -66,8 +66,19 @@ > #define CHOOSE_VHE_SYM(sym) sym > #define CHOOSE_NVHE_SYM(sym) kvm_nvhe_sym(sym) > > -#define this_cpu_ptr_nvhe_sym(sym) this_cpu_ptr(&kvm_nvhe_sym(sym)) > -#define per_cpu_ptr_nvhe_sym(sym, cpu) per_cpu_ptr(&kvm_nvhe_sym(sym), cpu) > +/* > + * Compute pointer to a symbol defined in nVHE percpu region. > + * Returns NULL if percpu memory has not been allocated yet. > + */ > +#define this_cpu_ptr_nvhe_sym(sym) per_cpu_ptr_nvhe_sym(sym, smp_processor_id()) > +#define per_cpu_ptr_nvhe_sym(sym, cpu) \ > + ({ \ > + unsigned long base, off; \ > + base = kvm_arm_hyp_percpu_base[cpu]; \ > + off = (unsigned long)&CHOOSE_NVHE_SYM(sym) - \ > + (unsigned long)&CHOOSE_NVHE_SYM(__per_cpu_start); \ > + base ? (typeof(CHOOSE_NVHE_SYM(sym))*)(base + off) : NULL; \ > + }) > > #ifndef __KVM_NVHE_HYPERVISOR__ > /* > @@ -117,6 +128,10 @@ DECLARE_KVM_HYP_SYM(__kvm_hyp_vector); > #define __kvm_hyp_init CHOOSE_NVHE_SYM(__kvm_hyp_init) > #define __kvm_hyp_vector CHOOSE_HYP_SYM(__kvm_hyp_vector) > > +extern unsigned long kvm_arm_hyp_percpu_base[NR_CPUS]; > +DECLARE_KVM_NVHE_SYM(__per_cpu_start); > +DECLARE_KVM_NVHE_SYM(__per_cpu_end); > + > #ifdef CONFIG_KVM_INDIRECT_VECTORS > extern atomic_t arm64_el2_vector_last_slot; > DECLARE_KVM_HYP_SYM(__bp_harden_hyp_vecs); The changes in this file will collide quite badly with Andrew's "handler" branch which you've already queued, so you'll probably want to chat with Andrew and David when you get to resolve that. In particular, I think it would be good if the this_cpu_ptr_nvhe_sym() macro only ends up in the EL1 block, since I don't think that its use of smp_processor_id() is safe at EL2. That's not a problem as it stands, as its only used by the host. Will