From patchwork Thu Oct 21 13:45:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12575127 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 5632AC433EF for ; Thu, 21 Oct 2021 13:47:03 +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 291BB61212 for ; Thu, 21 Oct 2021 13:47:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 291BB61212 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=iFfC8t+2znC59Lexlj0tfqDidxYKo6QacFyvYRZBLN8=; b=Qx2TeSv+n7j1cg c5XKWxAPh75xBlLneqOZKGjjWMXVEybBR7p713aNcEjxCWBeHFH87atpF2Tc30GK38Um7xmhNk+NM ct3z4YVk6BV5vYv9Xv+wTJcBzhcRol9UXsE9at3jTV7cf3GczwMdQ5TRJ0TN4MHnskNqt8LTNgmy7 RK9urqfksuHdJVbGgub1LPgtLlJbkzWUqjtA8WiK5uvNDTfWn8Sa7LQjPEw1SyKvHwD8me8z09b5a MorcCIDnf6+LoxzvFy/sbBZg75SEOZ5zfTyNxpa5M27W24UTS3rjKbalSyO9bfazVqkPbPhbKS6C2 jFCf9I3G0OcbexNogrVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOB-007gWL-8S; Thu, 21 Oct 2021 13:45:47 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYO7-007gV5-R6 for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 13:45:45 +0000 Received: by mail-pj1-x102c.google.com with SMTP id kk10so558951pjb.1 for ; Thu, 21 Oct 2021 06:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XtPHFQm3Gx9OKSk223OIG1zPCPHU2yhr3Gzd+GkMp4Y=; b=iSq35zcccVlkAf+ROcAmanV9praZzQYoXHbQI0udTe/yEEjuqBnhBUWzbiuWK+WFG2 AB0hdkyMhW+/V5OksQCLkgo3zLzfxTgXLceJiGavfPrTbKDQLDL1Fie93QRDdrCTmsmA 5RkmV79E67tcPiFtxa+OP3zK3G5mPFz9BlzmOGdO6U9M+TaPQrPwV2pKbbD3q35hOnIc tWbTxu9PZDkBE3rUFqhDVQ2Lqg7nppqpWCQr2zRFtwVCwR9AakxBNBvAgi5rjpruZisI sIyTR2gIhlP6gwuXgWO0h8t8V50pJw2NhK3Rm3RBnGg1SN3KbrTlJokgnsVGL8RyWZ5d YtWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XtPHFQm3Gx9OKSk223OIG1zPCPHU2yhr3Gzd+GkMp4Y=; b=D4OdjgbrUXWp9RDOsHW/v6uJmN9Vek+dHgW2t1cQZX3usWAzy2kMikuSb2HffgifuH dr1osFNi4l1D1ypcJqQBBd+Gc2fuFNaClcY2T97YNBjvnEFYii5sbFaVZ1igIucqs9oS XkJ8z5TdDFq+q0Ibn32eB5q7buDcoLuM/n/pufDV6w71V9Qk3zXw0UXtduGSPYaCvaDn f3xEAZn7lnRcR/ZQbkx3gI8TgBu2qZc2mXj2NlgrhgAkYzXwg70Jl9wSwBjk36Y3tVqF 1MV1x+2SRq5ui7QxGHNCeOYPwaMVUAf6JYc+2qb8pYb9Gwtwuan29KJSPVFwZFmBxlnY Zzbg== X-Gm-Message-State: AOAM53187DeZV5ojstwFy1dPgvbUMyTPhlgB6On3L3KBkObHzQ6JtQmG 6koFikG0Nb+Md4d7Ph9a8aP/nw== X-Google-Smtp-Source: ABdhPJzdrQHCy1u8xHpxg/F/zz71e4fBRbDCwoKYJ9sgYMHLjpXNIm0R8UxBXVL8KTeFkQ2j0hAj2w== X-Received: by 2002:a17:90a:fca:: with SMTP id 68mr1148819pjz.77.1634823941410; Thu, 21 Oct 2021 06:45:41 -0700 (PDT) Received: from localhost ([103.127.241.129]) by smtp.gmail.com with ESMTPSA id z24sm6373840pfr.141.2021.10.21.06.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 06:45:40 -0700 (PDT) From: Leo Yan To: 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 , James Clark , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [RFCv1 0/4] arm64: Use static key for PID in CONTEXTIDR Date: Thu, 21 Oct 2021 21:45:26 +0800 Message-Id: <20211021134530.206216-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_064543_965317_37E92923 X-CRM114-Status: GOOD ( 19.20 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Kernel provides configuration PID_IN_CONTEXTIDR so we can save PID into system register contextidr_el{1|2}. This means developer must build kernel with this config, otherwise, the feature is disabled and cannot be used by hardware tracing modules (Like Arm CoreSight, SPE, etc) on the fly. Suggested by Stephane Eranian, this patch series introduces static key for PID in CONTEXTIDR. If the config PID_IN_CONTEXTIDR is selected when build kernel, then the static key will be set as true and kernel will always trace PID into CONTEXTIDR, so we can keep the same semantics for PID_IN_CONTEXTIDR before and after applying this patch series. If the config PID_IN_CONTEXTIDR is not selected, the kernel modules still can invoke the pair functions contextidr_enable() and contextidr_disable() to dynamically enable and disable PID tracing in the profiling flow. As result, Arm SPE is the first consumer to use static key. When I review Arm CoreSight driver, I found it misses to check root PID namespace for its register setting. So it would use a dedicate patch series to firstly correct namespace checking and then apply static key for PID tracing. For this reason, this patch set doesn't contain Arm CoreSight related enhancement. We also need to provide arm32 variant to use static key for PID in CONTEXTIDR. I'd like to send out this patch series firstly for comment, in case this approach is not accepted by maintainer. If we can conclude this is the right thing to do, I will supplement arm32 support in next spin. This patch set has been verified on Hisilicon D06 board with Arm SPE driver. I tested the performance for using static key, the result doesn't show regression. In the testing, I used the command 'perf bench sched messaging -t -g 20 -l 1000' to measure the scheduling latency for 4 different modes: 'dis': Disable kernel configuration PID_IN_CONTEXTIDR. 'enb': Enable kernel configuration PID_IN_CONTEXTIDR. 'true': Set static key to 'TRUE' 'false': Set static key to 'FALSE' (so don't store PID into CONTEXTIDR) The testing iterates for 5 loops for every configuration, and get the run time (in seconds): dis enb true false ---+--------+--------+--------+------- #1 26.568 | 26.786 | 26.056 | 26.197 #2 26.442 | 26.457 | 26.458 | 26.846 #3 26.719 | 26.701 | 27.119 | 26.281 #4 26.448 | 27.595 | 26.953 | 27.043 #5 27.017 | 27.263 | 26.638 | 26.933 ---+--------+--------+--------+------- avg. 26.638 | 26.960 | 26.644 | 26.66 ---+--------+--------+--------+------- delta pct. | 1.21% | 0.02% | 0.08% Leo Yan (4): arm64: Use static key for tracing PID in CONTEXTIDR arm64: entry: Always apply workaround for contextidr_el1 arm64: Introduce functions for controlling PID tracing perf: arm_spe: Dynamically switch PID tracing to contextidr arch/arm64/include/asm/mmu_context.h | 14 +++++++++++++- arch/arm64/kernel/entry.S | 4 ---- arch/arm64/kernel/process.c | 11 +++++++++++ drivers/perf/arm_spe_pmu.c | 13 ++++++++++++- 4 files changed, 36 insertions(+), 6 deletions(-)