From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47D0AC43464 for ; Fri, 18 Sep 2020 09:24:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCF2421D43 for ; Fri, 18 Sep 2020 09:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600421050; bh=5BPFCutNa5VNQMibpDHHB+qvvOTgQcOE09RubxpF1GI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=ZdHHrzsjUtNIFrpRJx/a5npE4eblD06uk5dAwCNpr2KLGmHnVHKlmIiNcQaU9fki9 TOgjAxGCHK/5tyVW5HkvM2C8n7HnjyIHntOZdh3P0vAKR/snj+7vaXMjErLVveVdbZ 5xpSdDHD4MHNwOOsEEw9iPZbf9y99gfaW2+Fux1U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726576AbgIRJYJ (ORCPT ); Fri, 18 Sep 2020 05:24:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726316AbgIRJYH (ORCPT ); Fri, 18 Sep 2020 05:24:07 -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 238A120DD4; Fri, 18 Sep 2020 09:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600421046; bh=5BPFCutNa5VNQMibpDHHB+qvvOTgQcOE09RubxpF1GI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xU5lzR1Ga0PcfhABCdoUUHXJd6dN4fDFAU+RJC4XjY97A6xGaeDusE+AIxQe09UUe cjDXcplObHW/R0vJ/QWHVnEYHNiAmMG2eH98/7f5xG9jUnkaKa5fMSVYDlcCKKQY1K 3J3oarxI8eW8I9yOa/ZZSSr5YNbR3x/6bNNhLGVY= Date: Fri, 18 Sep 2020 10:24:01 +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 v3 06/11] kvm: arm64: Add helpers for accessing nVHE hyp per-cpu vars Message-ID: <20200918092400.GF30834@willie-the-truck> References: <20200916173439.32265-1-dbrazdil@google.com> <20200916173439.32265-7-dbrazdil@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200916173439.32265-7-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 Wed, Sep 16, 2020 at 06:34:34PM +0100, David Brazdil wrote: > Defining a per-CPU variable in hyp/nvhe will result in its name being > prefixed with __kvm_nvhe_. Add helpers for declaring these variables > in kernel proper and accessing them with this_cpu_ptr and per_cpu_ptr. > > Signed-off-by: David Brazdil > --- > arch/arm64/include/asm/kvm_asm.h | 25 +++++++++++++++++++++++-- > 1 file changed, 23 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index cf9456663289..abc03f386b40 100644 > --- a/arch/arm64/include/asm/kvm_asm.h > +++ b/arch/arm64/include/asm/kvm_asm.h > @@ -54,9 +54,21 @@ > DECLARE_KVM_VHE_SYM(sym); \ > DECLARE_KVM_NVHE_SYM(sym) > > +#define DECLARE_KVM_VHE_PER_CPU(type, sym) \ > + DECLARE_PER_CPU(type, sym) > +#define DECLARE_KVM_NVHE_PER_CPU(type, sym) \ > + DECLARE_PER_CPU(type, kvm_nvhe_sym(sym)) > + > +#define DECLARE_KVM_HYP_PER_CPU(type, sym) \ > + DECLARE_KVM_VHE_PER_CPU(type, sym); \ > + DECLARE_KVM_NVHE_PER_CPU(type, sym) > + > #define CHOOSE_VHE_SYM(sym) sym > #define CHOOSE_NVHE_SYM(sym) kvm_nvhe_sym(sym) > > +#define this_cpu_ptr_nvhe(sym) this_cpu_ptr(&kvm_nvhe_sym(sym)) > +#define per_cpu_ptr_nvhe(sym, cpu) per_cpu_ptr(&kvm_nvhe_sym(sym), cpu) nit: I'd probably stick a _sym suffix on these macros, to make it clear that they're just munging the symbol name rather than doing some completely different pcpu implementation. THat said, do you expect these to be used outside of the pcpu implementation? If not, I suggest some underscores as a prefix as well. > #ifndef __KVM_NVHE_HYPERVISOR__ > /* > * BIG FAT WARNINGS: > @@ -69,12 +81,21 @@ > * - Don't let the nVHE hypervisor have access to this, as it will > * pick the *wrong* symbol (yes, it runs at EL2...). > */ > -#define CHOOSE_HYP_SYM(sym) (is_kernel_in_hyp_mode() ? CHOOSE_VHE_SYM(sym) \ > +#define CHOOSE_HYP_SYM(sym) (is_kernel_in_hyp_mode() \ > + ? CHOOSE_VHE_SYM(sym) \ > : CHOOSE_NVHE_SYM(sym)) > +#define this_cpu_ptr_hyp(sym) (is_kernel_in_hyp_mode() \ > + ? this_cpu_ptr(&sym) \ > + : this_cpu_ptr_nvhe(sym)) > +#define per_cpu_ptr_hyp(sym, cpu) (is_kernel_in_hyp_mode() \ > + ? per_cpu_ptr(&sym, cpu) \ > + : per_cpu_ptr_nvhe(sym, cpu)) is_kernel_in_hyp_mode() reads a system register to determine the current exception level, so this doesn't seem like something we should be doing everytime here. Perhaps is_kernel_in_hyp_mode() should avoid read_sysreg() and instead use a non-volatile asm to allow the result to be cached by the compiler. Hmm. But I think that can be tackled as a future patch, so with the naming nits resolved: Acked-by: Will Deacon Will