From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E37123D6465 for ; Tue, 28 Jul 2026 15:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785250867; cv=none; b=B8NnkKucXVyNUXaMAGfvZbQLj4HmV84K/+wnhtJN1LZooDAta8q5zOa6ctffbXjwjBJaeC+o62Qq9pEz97gkDDBgtc91824bwWjwwrSB2pzzC4vDGY5cSOBNkNIg7P+nX7sMIL4IJUPwnV5frea6hzmm5/YVvxdj1c/+sSA9ZOo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785250867; c=relaxed/simple; bh=MWVaEdPwi/N4y+8uIbAvvKSawWcU8IB0yL2Pycw7drw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nG+42106yKKTlKuJyQMFEFzMMASr05SyYWR/xfnqKTSqlX+7Gh6c9tepULJjjQduWCuRFS2eOP/xWlxN/mg8gg1xcy8OlJ79DWEU7r1c6M/140hybM09Lfgzqm18vZLHAYhNEyrtTCirwmWznjxiOVI+6VzaaCjyS7D9I8irwq8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=EcMIJorp; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EcMIJorp" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-49553515a8bso49143575e9.1 for ; Tue, 28 Jul 2026 08:01:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1785250864; x=1785855664; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+OIGrkyqw2d+yA5TQnxK038Gqg7KBP2CiYzY7FjV1z8=; b=EcMIJorp90WqY/h0z2BWTK9b9TPwkHVllAthmifT9LPu/ZNL31avSRthiQLQDfgF94 U1yeyf7dUvN177sT1zSIPbAAesVc1nPapbkbIzcA34AOPqjEJh9Aa+nnZ6KKcnlMZzM/ KEIjBPwZ6bBF89l0xiuf0smtm7snEjXc9U71WWaqtDf03UUQ/Cbrf0bd344+M/yDWISd 5iP59DtIKcB3f1xwV7F4blJkKOZdFRSPKFyV4QWgeyd6pVMQx7fWfZG0Blf9gGYxnNdZ dHH01DyDaKVzrVn5f7xxLnoB+UJCAVqdmN4CjWxHh4WQMXXf3PPlk+pJztEzsVSleQTk me3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785250864; x=1785855664; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+OIGrkyqw2d+yA5TQnxK038Gqg7KBP2CiYzY7FjV1z8=; b=KOHuJClf2fotp8e5d75rBEzgU0mceWfE6BgVtzpK0uTrj+M3bhZtj5YLVBTjt8xhB7 PMFyb7RiwV/kkf4a6Hn+8SwU3dTjMunTFlu0I5qZVFWg6U1FwbhO5A0ch8nglR7qiS1r 1v8z71XXkpwiCr7BtYzBcNEwYvBT0gUm7QtzMJDMqONmnameRfyzjMMRM52PSGtYchak EuIhOHkndeesx++8l7/wVjeCWEX39g9PFq9lCih2gGBkbX86teA5DGgSlV7DAoPwRYow MEaAJUbr85FYq2oG6xDWbdj7DaNi4DQXwt7opfNhR6xdJIg9uFYx5TNvH5Q6o7/qgVCI aLrQ== X-Forwarded-Encrypted: i=1; AHgh+RptFfzE1Wu/OOGACNVdw79QKKIB8yG0tz0q5PPCsKNhMw7pDqzUPvddKwWQXsjJ5+kuAxVBubXTY486icI=@vger.kernel.org X-Gm-Message-State: AOJu0YwKox6hV/aHy3gv74SqNVWyoqrZ2ax2GrKVW2OyIohfxuzJ1UVl wRwC4Mv+UjkZxto0bqLVY09IbS87ooMFCKLjQPK+uPYsucpKys4rD51bUvq8T+VcF/4= X-Gm-Gg: AR+sD13b2jXgc5NKIvTihJvfcMnfzWla9nGGNDaP4CO6enzzl0DzO2SDJidB0t6SmMV Gsg65J8GCu15QiajzPdNQ0QxHgeWgSdCh+dbAUt6H1z1TxO/M6z/47m6vg+nE8OIPeWmNH4suXi tG/509eoZxIjPGRy6NeGJMJvywY98opaGWh9J/E6p03+JyFqlk4icOqCNkGjNEByfgTsU963Cfz kkKL4a868StJpeLDmM4TdZkMgFQhGz6bC/26V+ipgf4PxxThXzq6UUAswvz1oynvVL/WS9OXEOi JQbfYAKwBDEKSYz5OLtYaB9o+APjbKTT3T3zH8dcYJWdTsQ8J6uNGtZXZuSYz+M7vZ9kBDhEqj5 Vt3n0G45bepBTlzL0p0tfb+EY6b7pajh0ekALuPXqVpV2wLeAQTNc4XXyX3gpo6uQWTV9ZXWA0C mkv3rh62s= X-Received: by 2002:a05:600c:8b55:b0:496:c977:3b6d with SMTP id 5b1f17b1804b1-496c9775067mr16629755e9.12.1785250863749; Tue, 28 Jul 2026 08:01:03 -0700 (PDT) Received: from [192.168.1.3] ([37.18.141.193]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85c52fa9sm61036324f8f.20.2026.07.28.08.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 08:01:03 -0700 (PDT) From: James Clark Date: Tue, 28 Jul 2026 16:00:15 +0100 Subject: [PATCH v3 3/8] coresight: etm-perf: Flush workqueue before unloading module Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260728-james-cs-multiple-per-threads-v3-3-6aee7579f1dc@linaro.org> References: <20260728-james-cs-multiple-per-threads-v3-0-6aee7579f1dc@linaro.org> In-Reply-To: <20260728-james-cs-multiple-per-threads-v3-0-6aee7579f1dc@linaro.org> To: Suzuki K Poulose , Mike Leach , Leo Yan , Suyash Mahar , Yeoreum Yun Cc: Greg Kroah-Hartman , Qi Liu , Junhao He , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, James Clark , Jonathan Cameron , sashiko-bot X-Mailer: b4 0.14.0 The work queue is never flushed on module unload, so pending work items can run after coresight-config is cleaned up or the .text section is unloaded. The global workqueue also can't be flushed manually, so change it to a local workqueue and flush it on exit. The init function needs to be rearranged to fix a similar problem. The Perf PMU can be used as soon as registration succeeds, so move it as late as possible so that the only failure that can follow is coresight- config. Failing to register coresight-config means no flush dependency between coresight-config and the Perf PMU will exist, so it doesn't need to be done. Assisted-by: Codex:GPT-5.6-Sol Reported-by: sashiko-bot Fixes: 0bcbf2e30ff2 ("coresight: etm-perf: new PMU driver for ETM tracers") Signed-off-by: James Clark --- drivers/hwtracing/coresight/coresight-core.c | 28 ++++++++++++++---------- drivers/hwtracing/coresight/coresight-etm-perf.c | 22 +++++++++++++++---- drivers/hwtracing/coresight/coresight-etm-perf.h | 1 + 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c index f7b1308a759c..5e653b08a83d 100644 --- a/drivers/hwtracing/coresight/coresight-core.c +++ b/drivers/hwtracing/coresight/coresight-core.c @@ -2094,31 +2094,31 @@ static int __init coresight_init(void) if (ret) return ret; - ret = etm_perf_init(); - if (ret) - goto exit_bus_unregister; - /* Register function to be called for panic */ ret = atomic_notifier_chain_register(&panic_notifier_list, &coresight_notifier); if (ret) - goto exit_perf; + goto exit_bus_unregister; - /* initialise the coresight syscfg API */ - ret = cscfg_init(); + ret = coresight_pm_setup(); if (ret) goto exit_notifier; - ret = coresight_pm_setup(); + ret = etm_perf_init(); + if (ret) + goto exit_pm; + + /* initialise the coresight syscfg API */ + ret = cscfg_init(); if (!ret) return 0; - cscfg_exit(); + etm_perf_exit(); +exit_pm: + coresight_pm_cleanup(); exit_notifier: atomic_notifier_chain_unregister(&panic_notifier_list, &coresight_notifier); -exit_perf: - etm_perf_exit(); exit_bus_unregister: bus_unregister(&coresight_bustype); return ret; @@ -2127,6 +2127,12 @@ static int __init coresight_init(void) static void __exit coresight_exit(void) { coresight_pm_cleanup(); + /* + * Flush Perf workqueue before the rest of Coresight is torn down + * because work items touch coresight-config and also require the .text + * to remain loaded. + */ + etm_perf_flush_workqueue(); cscfg_exit(); atomic_notifier_chain_unregister(&panic_notifier_list, &coresight_notifier); diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 09b21a711a87..7fb5c3d18bd5 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -27,6 +27,7 @@ #include "coresight-trace-id.h" static struct pmu etm_pmu; +static struct workqueue_struct *etm_free_wq; static bool etm_perf_up; /* @@ -292,7 +293,7 @@ static void etm_free_aux(void *data) { struct etm_event_data *event_data = data; - schedule_work(&event_data->work); + queue_work(etm_free_wq, &event_data->work); } /* @@ -1034,6 +1035,10 @@ int __init etm_perf_init(void) { int ret; + etm_free_wq = alloc_workqueue("coresight_etm_free", WQ_UNBOUND, 0); + if (!etm_free_wq) + return -ENOMEM; + etm_pmu.capabilities = (PERF_PMU_CAP_EXCLUSIVE | PERF_PMU_CAP_ITRACE | PERF_PMU_CAP_AUX_PAUSE); @@ -1054,13 +1059,22 @@ int __init etm_perf_init(void) etm_pmu.module = THIS_MODULE; ret = perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1); - if (ret == 0) - etm_perf_up = true; + if (ret) { + destroy_workqueue(etm_free_wq); + return ret; + } - return ret; + etm_perf_up = true; + return 0; } void etm_perf_exit(void) { perf_pmu_unregister(&etm_pmu); + destroy_workqueue(etm_free_wq); +} + +void etm_perf_flush_workqueue(void) +{ + flush_workqueue(etm_free_wq); } diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h index 24d929428633..86e259cc1adf 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -116,5 +116,6 @@ int etm_perf_add_symlink_cscfg(struct device *dev, void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *config_desc); int __init etm_perf_init(void); void etm_perf_exit(void); +void etm_perf_flush_workqueue(void); #endif -- 2.34.1