From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795025177; b=gJXDHjZog36jSpTb/S0vtZgmHS7nJ4W/shreO1dpoSOBMPmMAGQr8ncMkJn/vUb6iHOt gnL3IkQvkonqJyw/gyrZSlb8OKwuZmd4JfYD+JB6i40hcId/uYYLPYnkC9nWVQ06V2Ern jz9rWaUiBUTOuRwhMLkT8Hj5aCTxl4bEWCkv+bhu7kyvcMA12egu265wAO3iAdhEfDlNj 8VQRa0P32qIbKGbh3HDXzttny37HYBS2emGm0rGSqcz+89xdmX0NBHE59Xs61P/cpuOZh 6m/dyFgE2ObLgk+4poqDtp6/q+Awh8IQ2Hy9M8D5Qu9MWcULyZTS28Aq7BcQ2GjsSxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795025177; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=E6sbPyA96KVlZh0NRhW8xu9f+sN+1r61FDp/FEBp9bI=; b=gh/fq4IKFl0yF3iXqRuVWTG7XCL3xKE8teGdWvzfpLqCJ8DnAHNmi225UGe9EHalT4X0 MEGGKpfiBAD973buXPoMp81QN/+fY/bIJwe/CVgMkgLye+vm+W4g3hTI1wRmv/BYBPsaH zXyQGplVaCCbtoK8M+qUU7uW5f6dkV7Ki1PzaGQZsqYgEEytCSsv/PshnMR8FqGtPrrzX gkeidmCP06JWwZgG6P381S+vYSsqmAashnKQwPtBPBhDCELi60MJYluNrYdfwE5jx9sxJ 9I5LI1bEHeUO0xRQAJmI7HqxO8MQhzXzk6odNOiJYfAG9jALZVoxPzvlAoZou0MJKuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lOgVYzVf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFD8A60A2621; Wed, 18 Nov 2026 18:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lOgVYzVf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BF341F000C6; Wed, 18 Nov 2026 18:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795025177; bh=E6sbPyA96KVlZh0NRhW8xu9f+sN+1r61FDp/FEBp9bI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lOgVYzVfTp+OA8WfKtg9ZxxPBzvJP2YnGs0uNT8GVsc/Ri3qU85wJYolZpOWS+e5U ZIadAIAqUOesmYWMLfSKDHTWzg0djwmpHCzPhw5qG5qvzBfmYJro7OFZnN5aiKy0j6 L1i4XjRz7LiJrPxuu41kQJqKT5DC4a7QmzxchmMY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mike Leach , James Clark , Yeoreum Yun , Jie Gan , Leo Yan , Suzuki K Poulose , Sasha Levin Subject: [PATCH 6.18 0988/2151] coresight: Take hotplug lock in enable_source_store() for Sysfs mode Date: Wed, 18 Nov 2026 15:45:23 +0100 Message-ID: <20261118150158.461477376@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Leo Yan [ Upstream commit 2c7f786928c4319ee9c68207a28529e5226b9266 ] The hotplug lock is acquired and released in etm{3|4}_disable_sysfs(), which are low-level functions. This prevents us from a new solution for hotplug. Firstly, hotplug callbacks cannot invoke etm{3|4}_disable_sysfs() to disable the source; otherwise, a deadlock issue occurs. The reason is that, in the hotplug flow, the kernel acquires the hotplug lock before calling callbacks. Subsequently, if coresight_disable_source() is invoked and it calls etm{3|4}_disable_sysfs(), the hotplug lock will be acquired twice, leading to a double lock issue. Secondly, when hotplugging a CPU on or off, if we want to manipulate all components on a path attached to the CPU, we need to maintain atomicity for the entire path. Otherwise, a race condition may occur with users setting the same path via the Sysfs knobs, ultimately causing mess states in CoreSight components. This patch moves the hotplug locking from etm{3|4}_disable_sysfs() into enable_source_store(). As a result, when users control the Sysfs knobs, the whole flow is protected by hotplug locking, ensuring it is mutual exclusive with hotplug callbacks. Note, the paired function etm{3|4}_enable_sysfs() does not use hotplug locking, which is why this patch does not modify it. Reviewed-by: Mike Leach Tested-by: James Clark Reviewed-by: Yeoreum Yun Reviewed-by: James Clark Tested-by: Jie Gan Signed-off-by: Leo Yan Signed-off-by: Suzuki K Poulose Link: https://lore.kernel.org/r/20260515-arm_coresight_path_power_management_improvement-v14-6-f88c4a3ecfe9@arm.com Stable-dep-of: 950cca5352b0 ("coresight: etm3x: fix inconsistencies with sysfs configuration") Signed-off-by: Sasha Levin --- drivers/hwtracing/coresight/coresight-etm3x-core.c | 8 -------- drivers/hwtracing/coresight/coresight-etm4x-core.c | 9 --------- drivers/hwtracing/coresight/coresight-sysfs.c | 7 +++++++ 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c index 0c011b7041696..e71a6fb36fabf 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c @@ -622,13 +622,6 @@ static void etm_disable_sysfs(struct coresight_device *csdev) { struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); - /* - * Taking hotplug lock here protects from clocks getting disabled - * with tracing being left on (crash scenario) if user disable occurs - * after cpu online mask indicates the cpu is offline but before the - * DYING hotplug callback is serviced by the ETM driver. - */ - cpus_read_lock(); spin_lock(&drvdata->spinlock); /* @@ -639,7 +632,6 @@ static void etm_disable_sysfs(struct coresight_device *csdev) drvdata, 1); spin_unlock(&drvdata->spinlock); - cpus_read_unlock(); /* * we only release trace IDs when resetting sysfs. diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index be05ef41fd734..37a244e68eb52 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -1117,13 +1117,6 @@ static void etm4_disable_sysfs(struct coresight_device *csdev) { struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); - /* - * Taking hotplug lock here protects from clocks getting disabled - * with tracing being left on (crash scenario) if user disable occurs - * after cpu online mask indicates the cpu is offline but before the - * DYING hotplug callback is serviced by the ETM driver. - */ - cpus_read_lock(); raw_spin_lock(&drvdata->spinlock); /* @@ -1137,8 +1130,6 @@ static void etm4_disable_sysfs(struct coresight_device *csdev) cscfg_csdev_disable_active_config(csdev); - cpus_read_unlock(); - /* * we only release trace IDs when resetting sysfs. * This permits sysfs users to read the trace ID after the trace diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c index 958c0fe8837d5..a307852a72026 100644 --- a/drivers/hwtracing/coresight/coresight-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-sysfs.c @@ -362,6 +362,13 @@ static ssize_t enable_source_store(struct device *dev, if (ret) return ret; + /* + * CoreSight hotplug callbacks in core layer control a activated path + * from its source to sink. Taking hotplug lock here protects a race + * condition with hotplug callbacks. + */ + guard(cpus_read_lock)(); + if (val) { ret = coresight_enable_sysfs(csdev); if (ret) -- 2.53.0