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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14E34C433EF for ; Thu, 21 Oct 2021 14:34:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C761C6121F for ; Thu, 21 Oct 2021 14:34:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C761C6121F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=23IGMj03pPSGA32Kv02EJ3iam85hQfCwq6gELVR2ndg=; b=C8N16vpKEHHecHoHifTrLwVJsu 60ihVnZN8M6i4yXM25yg/tghme5R+RH8hFH+eOfTgXaq3/5S53SXTRJnJPriyrIrSa01OmCWgZhEQ nlhphr0yAxwAAhkYM0fasOy/T42FHDxh3sMgwiCUsVq9+DZ20X0Z6+0/BWxXc/enCt9U09ae1lOmS CK91OuTXD5I62vjAPrk/M6OF7zB+9iB8AX2GFG88N4n6x4huoaKtOq3wHlFKHotRsG/x0UmHtRxWT 5RNXzezK+FwcuKBAUkuDmvPKfg5oLSPPLJofU4UZB3f1fmgozrpCNGx94/fuibfzMwLzMDU9b4Orw rg1VeyNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdZ86-007r7j-OR; Thu, 21 Oct 2021 14:33:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdZ83-007r6B-De for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 14:33:13 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 90B06D6E; Thu, 21 Oct 2021 07:33:06 -0700 (PDT) Received: from [10.57.22.27] (unknown [10.57.22.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 524323F73D; Thu, 21 Oct 2021 07:33:04 -0700 (PDT) Subject: Re: [RFCv1 1/4] arm64: Use static key for tracing PID in CONTEXTIDR To: Leo Yan , Catalin Marinas , Will Deacon , Mark Rutland , Kees Cook , Ard Biesheuvel , Sami Tolvanen , Nicholas Piggin , James Morse , Marc Zyngier , Joey Gouly , Peter Collingbourne , Vincenzo Frascino , "Peter Zijlstra (Intel)" , Stephane Eranian , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20211021134530.206216-1-leo.yan@linaro.org> <20211021134530.206216-2-leo.yan@linaro.org> From: James Clark Message-ID: <53962765-53b9-dfdc-a5b2-a3133a924c12@arm.com> Date: Thu, 21 Oct 2021 15:33:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211021134530.206216-2-leo.yan@linaro.org> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_073311_616033_CC654ED3 X-CRM114-Status: GOOD ( 27.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 21/10/2021 14:45, Leo Yan wrote: > The kernel provides CONFIG_PID_IN_CONTEXTIDR for tracing PID into system > register CONTEXTIDR; we need to statically enable this configuration > when build kernel image to use this feature. > > On the other hand, hardware tracing modules (e.g. Arm CoreSight, SPE, > etc) rely on this feature to provide context info in their tracing data. > If kernel has not enabled configuration CONFIG_PID_IN_CONTEXTIDR, then > tracing modules have no chance to capture PID related info. > > This patch introduces static key for tracing PID in CONTEXTIDR, it > provides a possibility for device driver to dynamically enable and > disable tracing PID into CONTEXTIDR as needed. > > As the first step, the kernel increases the static key if > CONFIG_PID_IN_CONTEXTIDR is enabled when booting kernel, in this case > kernel will always trace PID into CONTEXTIDR at the runtime. This means > before and after applying this patch, the semantics for > CONFIG_PID_IN_CONTEXTIDR are consistent. > > Signed-off-by: Leo Yan > --- > arch/arm64/include/asm/mmu_context.h | 4 +++- > arch/arm64/kernel/process.c | 11 +++++++++++ > 2 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h > index f4ba93d4ffeb..e1f33616f83a 100644 > --- a/arch/arm64/include/asm/mmu_context.h > +++ b/arch/arm64/include/asm/mmu_context.h > @@ -26,9 +26,11 @@ > > extern bool rodata_full; > > +DECLARE_STATIC_KEY_FALSE(contextidr_in_use); > + > static inline void contextidr_thread_switch(struct task_struct *next) > { > - if (!IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR)) > + if (!static_branch_unlikely(&contextidr_in_use)) > return; > > write_sysreg(task_pid_nr(next), contextidr_el1); > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > index 40adb8cdbf5a..d744c0c7e4c4 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -61,6 +61,9 @@ unsigned long __stack_chk_guard __ro_after_init; > EXPORT_SYMBOL(__stack_chk_guard); > #endif > > +DEFINE_STATIC_KEY_FALSE(contextidr_in_use); > +EXPORT_SYMBOL_GPL(contextidr_in_use); > + > /* > * Function pointers to optional machine specific functions > */ > @@ -721,3 +724,11 @@ int arch_elf_adjust_prot(int prot, const struct arch_elf_state *state, > return prot; > } > #endif > + > +static int __init contextidr_init(void) > +{ > + if (IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR)) > + static_branch_inc(&contextidr_in_use); > + return 0; > +} > +early_initcall(contextidr_init); Hi Leo, Can you skip this early_initcall() part if you do something like this: DECLARE_STATIC_KEY_MAYBE(CONFIG_PID_IN_CONTEXTIDR, contextidr_in_use) It seems like there is a way to conditionally initialise it to true. James _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel