public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Mike Leach <mike.leach@arm.com>,
	James Clark <james.clark@linaro.org>,
	Yeoreum Yun <yeoreum.yun@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Will Deacon <will@kernel.org>, Yabin Cui <yabinc@google.com>,
	Keita Morisaki <keyz@google.com>,
	Yuanfang Zhang <quic_yuanfang@quicinc.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6 02/19] coresight: Set per-CPU source pointer
Date: Mon, 16 Mar 2026 19:30:37 +0000	[thread overview]
Message-ID: <20260316193037.GH8048@e132581.arm.com> (raw)
In-Reply-To: <4e36cf20-f3c0-4c3d-9bf4-da8228efaa15@arm.com>

On Mon, Mar 16, 2026 at 05:49:47PM +0000, Suzuki K Poulose wrote:
> On 16/03/2026 14:38, Leo Yan wrote:
> > On Fri, Mar 13, 2026 at 11:18:20AM +0000, Suzuki K Poulose wrote:
> > 
> > [...]
> > 
> > > >    static struct coresight_device *coresight_get_source(struct coresight_path *path)
> > > >    {
> > > >    	struct coresight_device *csdev;
> > > > @@ -1401,6 +1452,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
> > > >    	mutex_unlock(&coresight_mutex);
> > > > +	coresight_set_percpu_source(csdev);
> > > > +
> > > >    	if (cti_assoc_ops && cti_assoc_ops->add)
> > > >    		cti_assoc_ops->add(csdev);
> > > > @@ -1427,6 +1480,7 @@ void coresight_unregister(struct coresight_device *csdev)
> > > >    	if (cti_assoc_ops && cti_assoc_ops->remove)
> > > >    		cti_assoc_ops->remove(csdev);
> > > > +	coresight_clear_percpu_source(csdev);
> > > 
> > > Should these be done with the mutex lock held ?
> > 
> > If so, we will create a locking chain:
> > 
> >    coresight_mutex -> cpus_read_lock()
> > 
> > Afterwards in patch 18, it uses cpus_read_lock() to protect sysfs knobs,
> > a reversed locking chain will be established:
> > 
> >    cpus_read_lock() -> coresight_mutex
> > 
> > LOCKDEP will complain for possible deadlock.  This is why this patch
> > avoids to acquire mutex when set / clear per CPU sources.
> 
> The question is, what prevents two different CPUs trying to modify the
> "per_cpu_source" data structure when the CPU is not online.

I am struggling to establish a flow for this scenario.

Each CPU has a unique per-CPU source, and the pointer is only modified
during device probe or remove.  Both paths are protected by the device
lock (I confirmed that __device_attach() and
__device_release_driver() are protected by device_lock(dev)).
Therefore concurrent updates to the same source pointer should not
occur.

One possible corner case is the ETMv4 delayed probe (etm4_probe_cpu()).
Since the probe is deferred and coresight_register() is invoked when
a CPU is hotplugged, it could race with ETMv4 module unloading, i.e.
between etm4_probe_cpu() and etm4_remove_dev().

I discussed with James for another option before: we always access
per-cpu source pointer _locally_.  For example, we could set the pointer
in etm4_init_arch_data() and clear it in clear_etmdrvdata().  These
paths are protected by the CPU lock and in SMP call, thus
coresight_set_percpu_source() does not need acquire any lock.

The downside is that we set the per-cpu source pointer in ETM driver but
cannot use coresight_register/coresight_unregister as common place to
manage the pointer.

Thanks,
Leo


  reply	other threads:[~2026-03-16 19:30 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05 10:17 [PATCH v6 00/19] CoreSight: Refactor power management for CoreSight path Leo Yan
2026-03-05 10:17 ` [PATCH v6 01/19] coresight: sysfs: Validate CPU online status for per-CPU sources Leo Yan
2026-03-13 11:03   ` Suzuki K Poulose
2026-03-16 14:02     ` Leo Yan
2026-03-16 14:28       ` Suzuki K Poulose
2026-03-16 14:40         ` Leo Yan
2026-03-05 10:17 ` [PATCH v6 02/19] coresight: Set per-CPU source pointer Leo Yan
2026-03-13 11:18   ` Suzuki K Poulose
2026-03-16 14:38     ` Leo Yan
2026-03-16 17:49       ` Suzuki K Poulose
2026-03-16 19:30         ` Leo Yan [this message]
2026-03-13 11:22   ` Suzuki K Poulose
2026-03-16 17:41     ` Leo Yan
2026-03-05 10:17 ` [PATCH v6 03/19] coresight: Register CPU PM notifier in core layer Leo Yan
2026-03-05 10:17 ` [PATCH v6 04/19] coresight: etm4x: Hook CPU PM callbacks Leo Yan
2026-03-05 10:17 ` [PATCH v6 05/19] coresight: Add callback to determine if PM is needed Leo Yan
2026-03-13 11:26   ` Suzuki K Poulose
2026-03-17 11:22     ` Leo Yan
2026-03-05 10:17 ` [PATCH v6 06/19] coresight: etm4x: Remove redundant condition checks in save and restore Leo Yan
2026-03-05 10:17 ` [PATCH v6 07/19] coresight: syscfg: Use spinlock to protect active variables Leo Yan
2026-03-05 10:17 ` [PATCH v6 08/19] coresight: Introduce coresight_enable_source() helper Leo Yan
2026-03-13 11:31   ` Suzuki K Poulose
2026-03-05 10:17 ` [PATCH v6 09/19] coresight: Save active path for system tracers Leo Yan
2026-03-05 10:17 ` [PATCH v6 10/19] coresight: etm4x: Set active path on target CPU Leo Yan
2026-03-05 10:17 ` [PATCH v6 11/19] coresight: etm3x: " Leo Yan
2026-03-05 10:17 ` [PATCH v6 12/19] coresight: sysfs: Use source's path pointer for path control Leo Yan
2026-03-05 10:17 ` [PATCH v6 13/19] coresight: Add 'in_idle' argument to path Leo Yan
2026-03-13 14:37   ` Suzuki K Poulose
2026-03-05 10:17 ` [PATCH v6 14/19] coresight: Control path during CPU idle Leo Yan
2026-03-05 10:17 ` [PATCH v6 15/19] coresight: Add PM callbacks for sink device Leo Yan
2026-03-05 10:17 ` [PATCH v6 16/19] coresight: trbe: Save and restore state across CPU low power state Leo Yan
2026-03-05 10:17 ` [PATCH v6 17/19] coresight: sysfs: Increment refcount only for system tracers Leo Yan
2026-03-05 10:17 ` [PATCH v6 18/19] coresight: Take hotplug lock in enable_source_store() for Sysfs mode Leo Yan
2026-03-05 10:17 ` [PATCH v6 19/19] coresight: Move CPU hotplug callbacks to core layer Leo Yan
2026-03-06  9:53 ` [PATCH v6 00/19] CoreSight: Refactor power management for CoreSight path Yeoreum Yun
2026-03-16 16:08 ` James Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316193037.GH8048@e132581.arm.com \
    --to=leo.yan@arm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.clark@linaro.org \
    --cc=keyz@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=mike.leach@arm.com \
    --cc=quic_yuanfang@quicinc.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yabinc@google.com \
    --cc=yeoreum.yun@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox