From patchwork Thu Oct 21 13:45:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12575129 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 7A87AC433F5 for ; Thu, 21 Oct 2021 13:47:33 +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 41AF0610A1 for ; Thu, 21 Oct 2021 13:47:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 41AF0610A1 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:References:In-Reply-To: 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: List-Owner; bh=aGDgMe2IJgpxxe4d1Z629XLFvvgBZbhoB6SzGtpWrJk=; b=Mh6IxDkfNW7JsQ Mz3Pzfpf9RzSNTMXLEOmSO8sFDRLjOfc0pavLZBp7EVhshvU9JAElJ8GCpN1CBNn5MTdOr6xdncFo IU8ThBdDSRZYKWlFCl0hvb/hb/E3aTlWFaZRwaQgYX3eSsuT4w6cu/uQ1mz0R9upxQvYlO/a+P5BQ FRv5rc+MvUhYlaugOOWUYRvCFqlVDy/OPDq9mep3S3xdh6aZpWiiQqtnKhq/UgQz/OoD1YpjsNRfA R633vX06y4rFOHHuXSIzJm3VUtmETNy8RVU1kaoonT8Xinl6Q/e5IClq6luqbG4lLstpdjXv1QXIY R1rNDi3nWMtCaiLuoxVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYON-007gbD-1A; Thu, 21 Oct 2021 13:45:59 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOA-007gW8-7m for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 13:45:47 +0000 Received: by mail-pj1-x102d.google.com with SMTP id u6-20020a17090a3fc600b001a00250584aso3165028pjm.4 for ; Thu, 21 Oct 2021 06:45:45 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=QDxUA5M+5Tc9pgMaEnmtMzJohvZssOB/8meny4PzmyY=; b=FIUQGFZ7VcUHQw/Lbr3XDxLdHWunjI79HlNGqEknHtJaH3F/YRy6LUuGzshoBeXDYr MZlbyyYmOFBMUpa6fAEa+ahnfh1ILUpy0O2mHlcbfdbBLpbQZjDU85f0ecq/OVTqNFpo 18auKJ2PqREqW0jRZ0e9PU0KxPS4QbGaLpDy60P5CZmPgMgI1h3zVgkzB24Yr4EXITPW ngdail0s4XsavPsVm2VlUP3T2DModYPjhY7eKoXJzRQF8Owjo/EOl2dqmyLm+cDUvCwd UjHACR1cuXhbezr2fIn87GzGepfNOhcb5Iw3rxpTvAJDxB65AIgLhK7HiWIFcwtslPLI VuNg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=QDxUA5M+5Tc9pgMaEnmtMzJohvZssOB/8meny4PzmyY=; b=ysn/0NtUXWzDvDkkjk0W5aatGwpFMbeAEpkGY1+qZZDzfQlh5ZgH1dRg2hGrhqi99q 4wBZXETL7R4ewJQXwKo6rfY55VxOKMxst97kWdW5Uf6tmrLhx32QN60P9QfX0RGU9e/s Yz/crwZ2YhVh+nJ8qajzZQz8RlgBu98J+XL5aX8BOsHQDU3ZuH0TkK8gnQblturd3ZEn TxCPPc2Zb9/2mWwLzprzMVljJ9Ku1sdWUbeYvyKdra3d/qE85WlrAHx6TcrP3gFGbcrl UE6G+FM+sw3UH42wFDfqafdWyDBbg7ZJH+4BpWHtO/wx4JIlaDfUj7KLqNKHrDi6xoG/ lXbg== X-Gm-Message-State: AOAM530C5+CuJVvwCIN3kXyVgr0t0idKl0fC+D9OBL6imtEhZULYgJ+Z YVGUuJqT0Am1EniRm176ldkqFA== X-Google-Smtp-Source: ABdhPJyRF8CtK/W4CjNGZjAYfQW6WxJaeE1/vureHfym+WBfENBF4Q2Cej51bPyc1R3TWXC/9XwKhQ== X-Received: by 2002:a17:902:7001:b0:13d:d5b7:d06e with SMTP id y1-20020a170902700100b0013dd5b7d06emr5272202plk.61.1634823945071; Thu, 21 Oct 2021 06:45:45 -0700 (PDT) Received: from localhost ([103.127.241.129]) by smtp.gmail.com with ESMTPSA id b19sm5480396pgs.33.2021.10.21.06.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 06:45:44 -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 1/4] arm64: Use static key for tracing PID in CONTEXTIDR Date: Thu, 21 Oct 2021 21:45:27 +0800 Message-Id: <20211021134530.206216-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021134530.206216-1-leo.yan@linaro.org> References: <20211021134530.206216-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_064546_310591_9FDF419F X-CRM114-Status: GOOD ( 16.69 ) 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 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 Reviewed-by: Kees Cook --- 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); From patchwork Thu Oct 21 13:45:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12575131 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 0AB7CC433EF for ; Thu, 21 Oct 2021 13:47:40 +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 BF4A560F59 for ; Thu, 21 Oct 2021 13:47:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BF4A560F59 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:References:In-Reply-To: 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: List-Owner; bh=LwAU3e81Tdm7JwNPlUG7s5v0aemH255wQovxugGPnAM=; b=4MeTZoBN0wsH0z gAYIWzU6a8oGUsLwsEotfYFevCRhvodmwMHNUIfCQkyOTHOUuVi1S82p04O5nnJ3WqjOsni2JlLp4 dWPuuTcFXOi5OJcBkR7HI7Y/pqszf+Vriir92vJZgHKMt2+rp/3eqfn8D8A2dTdHsYRvagI1fxyM7 cCl80ErgnycIolYdItzfOOw5FfqZYFUonrp4gYFbcPAUMpXVub/5/s4it0aOs5c0OMidqyd9wDyTT IQSbzxqM1nPORQgviG5h7XoVSP2QWMF/xTSD4suScEWT61K5hwGconwg4XV7dBy9X920yLAbPgsKy itxQHOk6VHLDgNbUG5sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOZ-007geZ-5t; Thu, 21 Oct 2021 13:46:11 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOC-007gXW-Ky for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 13:45:50 +0000 Received: by mail-pl1-x630.google.com with SMTP id i5so445171pla.5 for ; Thu, 21 Oct 2021 06:45:48 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=C4YhQIiG/VVRYQyoXQKHZiWpfOu0OLjbGvCY/d59nFU=; b=HlmJX7TRx4UG0ncPN6Qe3EXnk2ZF9DqLFJphH7uq5N7ZIMVDkvlFe3OwfVkzv+jOUX nEDYcNKn4FiMGpSyH9MwVHOjHjmj/xJwjp42QY85oyBxzOp3Lfi+oyWc4CCwbsr/h1VR ZZ5f7OSp4EysK8w2Ca20O+4hNrZOXf2w4wqak+Z1N/vLht/egXfxz5WzI9ZalH/lUvC+ nTVD9dOb5T+i2eO4DGb3yPVbHOT2JcUv4xEZ/LSjuG+2BUNPjSk4+GZK6l+QMLfHUw7D agQLiL+7qyQzFutls43OjUocmcdw64gKS0AWCnKD47K7Pp7YDIOW73Lxd6Kl0f+KTK+C UJ/A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=C4YhQIiG/VVRYQyoXQKHZiWpfOu0OLjbGvCY/d59nFU=; b=qDZZkyt12IW2umw+JvyWtp3Qn7HSG12ohjW37M1w/CyLFd7ovm026BeCEjI950DZ+l 9JzzhQLbmckx9bJVhzZ6emOneE1tzFWOEJIlrguGGUvnMAJ+jU/vSlwtROp9jOalN6MB ekH7qS9vigCdHUfcF+q4Zb937biGCmQDF/aAmYVc1+vfdRMbtG307OV0hf1bNb8ZrMmy ZovmIybdNZLhDS8SauW1fmDtrkmRUUxWlJDOPjUlboDJ+0EW6OkVPHsKyKyRpKf3HNdi stSYtOyA3qrViMbt9aSR0XGeX/wMcXluC6UEowdI5mX9dTxS7Xvv3LzJRT5sVG5k9Lv+ +aKw== X-Gm-Message-State: AOAM532pMM3x2gHHF7qaN5nBKhjK413zpAmK7dhUc0mJeAqCYCZhhDiX C7jnnP/gx1vUxW812aYLE6Ok8w== X-Google-Smtp-Source: ABdhPJwvwIGLuEN95nh+Hdt3OX1LVT7d/V/k3x5/tuTpUkDCBpOM1BJzR/hzpYqZkA7GOoyte5YkgA== X-Received: by 2002:a17:902:b213:b0:13e:cd44:b4b5 with SMTP id t19-20020a170902b21300b0013ecd44b4b5mr5250651plr.18.1634823948002; Thu, 21 Oct 2021 06:45:48 -0700 (PDT) Received: from localhost ([103.127.241.129]) by smtp.gmail.com with ESMTPSA id g16sm1370633pfv.192.2021.10.21.06.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 06:45:47 -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 2/4] arm64: entry: Always apply workaround for contextidr_el1 Date: Thu, 21 Oct 2021 21:45:28 +0800 Message-Id: <20211021134530.206216-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021134530.206216-1-leo.yan@linaro.org> References: <20211021134530.206216-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_064548_751173_659CE77E X-CRM114-Status: GOOD ( 12.55 ) 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 After introducing static key as the switch for tracing PID into contextidr_el1, the kernel can dynamically turn on the static key to use PID tracing to contextidr_el1. This means even the config CONFIG_PID_IN_CONTEXTIDR is not selected, the kernel still can use contextidr_el1. When erratum 84571 is detected, the workaround should be always applied on contextidr_el1, particularly if the static key is enabled dynamically. This patch would introduce minor overload by one extra instruction for accessing system register contextidr_el1 and it only impacts platform which erratum 84571. So it's expected to not cause any significant regression. Signed-off-by: Leo Yan --- arch/arm64/kernel/entry.S | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index bc6d5a970a13..c41a4cfff527 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -356,12 +356,8 @@ alternative_else_nop_endif #ifdef CONFIG_ARM64_ERRATUM_845719 alternative_if ARM64_WORKAROUND_845719 -#ifdef CONFIG_PID_IN_CONTEXTIDR mrs x29, contextidr_el1 msr contextidr_el1, x29 -#else - msr contextidr_el1, xzr -#endif alternative_else_nop_endif #endif 3: From patchwork Thu Oct 21 13:45:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12575137 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 0E200C433F5 for ; Thu, 21 Oct 2021 13:48:14 +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 C7783610A1 for ; Thu, 21 Oct 2021 13:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C7783610A1 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:References:In-Reply-To: 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: List-Owner; bh=/yHstv8ERk8JXKYcEEeJ7w730PMpP6z1vNVSmagGyJw=; b=zvuFsqpB0dT3Mq GbKSsrOiev7GU2+qCBdr04kcWc4CQbqFgxiHHfRVlIIlZpYTgqNKblwylRpFYAw1fH1P9ZULGzjn2 g8jNBHDJqwzPIBzTPnVtYqNWiXScbvrVMXgf2YMEAxuG05Bwo2uxJdcailNwcOug5Pt2/AVXQMFl6 lBElXtDu7j1DW2MOBg0HAVg9RHy+dWJVV3xP5xxbt5RTMHuIX5fvI+LqV9L9feZ3dH+u6GPIL9kAh AvYqlicU5HrKRpfjsRAWVgpe9NZc5lGTz0A/Z+215EU+TmCZb8bqsvQD+tDrA4htDwnCjPfVOwwPN 7eXpJduQmDXsRiyRG+BQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOn-007gkB-Cv; Thu, 21 Oct 2021 13:46:25 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOH-007gZE-2v for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 13:45:54 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d5so722398pfu.1 for ; Thu, 21 Oct 2021 06:45:52 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=koUrUpf8/lWFSVycc73OYER9/wNi0PLyGr7jK5BVrkE=; b=VjYlFYBFcBY4Xf9hmTEBkgkmnvg8mfNqcDq3fEUxO5+UegVAxYVvGBBJircBFhWdoe MUyXt116AIC80z9y4TuxxMXXx+dh3gDh3EIJOTPTSx/bPec2VyGePhDz9RvuX/qBV+3s 7G+1Xf/zPB3OXGgfAc+1j+rgDWbRtcDmTRmzzgW9lpIpt+DPemN9l+jLluJUoJDVig6X DUIL4TbY3lSiinMS43t7gW5dMkcj9LL/OS3+4dEJxar6iJr3EpGIO0INmN019BtEgdzD 0pYZyrcaSTOmiipMDJRFH58htob4krdZ8wd2GvDlN1+/PkUEl7KVtnQKWd9Z1mN22ea3 gqHQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=koUrUpf8/lWFSVycc73OYER9/wNi0PLyGr7jK5BVrkE=; b=Weegda30kqGqq68rJ4qBJWUQWCa/1y/icxR0bTEkryxw6LEGt2k6LhakvzI1YeFWnK 1p5tFIUPYOpUxs11ua48KMU+8q1cdJiTWitM9CfS3NYARW8gbOSQnBVjFBzq16fSMFF5 1bOOuEvZEroP4yDmdeCzwhbN6YtrBBDt6PV3uCCVCrVoiNk5o4IYAphR5BUSqgXuUl88 yQWGlzeHHJOOJegPOtFsQPSZSM372Vh2bM5ycrP7TjuUIO3JBtnmGImwivyTZ5doTMaP CRhZ5CU+LR/liQk6sDiJDZwLMEqdQdjPN0V/NyDLzz9IhWAFubPdvstx735cvbd356/p LDaQ== X-Gm-Message-State: AOAM532Ee5hC9uzBIwY79s8NqSZuLXWVz6pqDdizaMyE8GW29UDjcZ7g uktUz0jbYLrvtSdfxISq8XFBVw== X-Google-Smtp-Source: ABdhPJwvgZgAy8cV8JcLrX7e83ZSIgNJ+0e7SgDaeSbYMx5rKqLga2ogThAEQvXS3l2rwnBM8gwfzA== X-Received: by 2002:a62:6d86:0:b0:448:152d:83a4 with SMTP id i128-20020a626d86000000b00448152d83a4mr5805089pfc.38.1634823951886; Thu, 21 Oct 2021 06:45:51 -0700 (PDT) Received: from localhost ([103.127.241.129]) by smtp.gmail.com with ESMTPSA id e12sm6021827pfl.67.2021.10.21.06.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 06:45:51 -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 3/4] arm64: Introduce functions for controlling PID tracing Date: Thu, 21 Oct 2021 21:45:29 +0800 Message-Id: <20211021134530.206216-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021134530.206216-1-leo.yan@linaro.org> References: <20211021134530.206216-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_064553_189441_BA5FB073 X-CRM114-Status: GOOD ( 11.36 ) 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 Introduce two functions contextidr_enable() and contextidr_disable(), which can be used by kernel modules to turn on or off PID tracing in contextidr register. Signed-off-by: Leo Yan --- arch/arm64/include/asm/mmu_context.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index e1f33616f83a..0c1669db19a1 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -37,6 +37,16 @@ static inline void contextidr_thread_switch(struct task_struct *next) isb(); } +static inline void contextidr_enable(void) +{ + static_branch_inc(&contextidr_in_use); +} + +static inline void contextidr_disable(void) +{ + static_branch_dec(&contextidr_in_use); +} + /* * Set TTBR0 to reserved_pg_dir. No translations will be possible via TTBR0. */ From patchwork Thu Oct 21 13:45:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12575139 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 D707DC433F5 for ; Thu, 21 Oct 2021 13:48:22 +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 9DF78610A1 for ; Thu, 21 Oct 2021 13:48:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9DF78610A1 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:References:In-Reply-To: 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: List-Owner; bh=LLF8FeWa6JEIvGo8eCW/Z42lTRu3cuFhK+DvAf0PKjs=; b=X8bkVyiNGdO1O4 bm+tfdInK22tdEQvZ6nMD6PzcNmiC+FqfrAXuU/iDDHtgZg0Js70ldH+tLs5A0xDlVMu1RU5UnkgZ gkmR3n5aJ6l3L5W7Mfs2AqN0RWB8nUT5AejSQzBbnZeJvkcA4tG2qXIEv0k14EgLCxzV18yxXzik5 aylUH4v/1YnZyJd5sc2TY/DesSfqwr7ewr4+6ha3PtcCihc9c5IyR8PgbVwhRzOvWzybiNEM9Tq79 in7bjEhW/KWjGfzY58BqzjpmuH+rMrnBr32kTno16IWvfspO3XAee6xsgGDp7ZGh1DWWyxbtWyAnG yNW85UADfwoEExQm4rJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYP4-007gsC-Pg; Thu, 21 Oct 2021 13:46:43 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdYOK-007gaW-K7 for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 13:45:58 +0000 Received: by mail-pl1-x636.google.com with SMTP id f21so459722plb.3 for ; Thu, 21 Oct 2021 06:45:55 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=scJONSeVpOmV2CJVVcM76etm+auyzPBKzEOe3qDiuJI=; b=yf6zl7BSnChL++bbuckoCVvgC4TomTcXaTcWHOM7j0198dxACJIobVYzGwkvRXnN3n mqJVzfJqusMXuLXyDtKvPr/XvUrl5Pfpg9BnM7nqw4IJd3PQXg05RRWqhKMKGuM/SZWt uivpxxT/SmJiYAstIA/v92JAjTbftIZsHNxXhexEW2mfTq1gxFh0/jfx1FlVRTV7Yzgq 3qbI/IkLOddEEFfoLXae4vqmpQ4CiHi/ni8xvdz5WP9rTZ0ljZ2gqJpFBtRsUn/srKBO xJMDHK2QIY3I87+iQ+C/gaM4WiQhy0ewC1EyK9NlsLUuKF7Br00oJbFgiYtJaZVzTbCf 638w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=scJONSeVpOmV2CJVVcM76etm+auyzPBKzEOe3qDiuJI=; b=GNGnPd0Bs0UD0l0lONrnh0K8v5XAc25XPjKa/OuQBQ6tTU6yek4O+c30U+BkxUxbKf aq3wdJtMhEH6KS253/zDQ3CwyXg2l6Ghy6IqfKpLOcsfDRxhYMlSl6psDSwSUpwD2E7h Er4DVn/klG+r6BmIvgkUzTzxx1LemMV817hQh3eLraZAnxiDs4YF6NajtAEBzga3S30v hepoSDd4ULOBXdOTalTijFlcB9cOn2YyIX+EZGXJy1ONu4sPy/+kZANF2VKQweLUxb0h o1LtHaZa2uTnffHGV6nra+AeDilKXAeXWLmzaFl1ahIFnQaUSP8am+EPYFibgtRJkCbJ nRfw== X-Gm-Message-State: AOAM5308ye8I+6L0S0v9OxfUcp7xOVTBShsRxWot1g2SkWlUBnonotMN EJ0RKRyH1bEawcNQiVKdZLl7gg== X-Google-Smtp-Source: ABdhPJzGxXaDeuxo28QlnFOxhVT5SttuPRnaGNdYo/lbZThTyRUA0LHbeq/ZIhYriJdjajjwI9uYhg== X-Received: by 2002:a17:90b:4a8d:: with SMTP id lp13mr6861919pjb.240.1634823955404; Thu, 21 Oct 2021 06:45:55 -0700 (PDT) Received: from localhost ([103.127.241.129]) by smtp.gmail.com with ESMTPSA id n14sm5383076pgd.68.2021.10.21.06.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 06:45:54 -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 4/4] perf: arm_spe: Dynamically switch PID tracing to contextidr Date: Thu, 21 Oct 2021 21:45:30 +0800 Message-Id: <20211021134530.206216-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021134530.206216-1-leo.yan@linaro.org> References: <20211021134530.206216-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_064556_716939_6E6D4C7B X-CRM114-Status: GOOD ( 15.36 ) 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 Now Arm64 provides API for enabling and disable PID tracing, Arm SPE driver invokes these functions to dynamically enable it during profiling when the program runs in root PID name space, and disable PID tracing when the perf event is stopped. Device drivers should not depend on CONFIG_PID_IN_CONTEXTIDR for PID tracing, so this patch uses the consistent condition for setting bit EL1_CX for PMSCR. Signed-off-by: Leo Yan --- drivers/perf/arm_spe_pmu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index d44bcc29d99c..935343cdcb39 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -272,7 +273,7 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event) if (!attr->exclude_kernel) reg |= BIT(SYS_PMSCR_EL1_E1SPE_SHIFT); - if (IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR) && perfmon_capable()) + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) reg |= BIT(SYS_PMSCR_EL1_CX_SHIFT); return reg; @@ -731,6 +732,13 @@ static void arm_spe_pmu_start(struct perf_event *event, int flags) if (hwc->state) return; + /* + * Enable tracing PID to contextidr if profiling program runs in + * root PID namespace. + */ + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) + contextidr_enable(); + reg = arm_spe_event_to_pmsfcr(event); write_sysreg_s(reg, SYS_PMSFCR_EL1); @@ -792,6 +800,9 @@ static void arm_spe_pmu_stop(struct perf_event *event, int flags) } hwc->state |= PERF_HES_STOPPED; + + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) + contextidr_disable(); } static int arm_spe_pmu_add(struct perf_event *event, int flags)