From: Yeoreum Yun <yeoreum.yun@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Yeoreum Yun <yeoreum.yun@arm.com>,
linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH v13 04/14] coresight: etm4x: fix inconsistencies with sysfs configuration
Date: Sat, 3 Oct 2026 03:30:21 +0100 [thread overview]
Message-ID: <asBovdmuZRDF5r8c@e129823.arm.com> (raw)
In-Reply-To: <20261003013347.0E07E1F00899@smtp.kernel.org>
On Sat, Oct 03, 2026 at 01:33:46AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] coresight: etm4x: data race in etm4_disable_sysfs() due to missing spinlock
> - [Medium] coresight: etm4x: resource leak when disabling sysfs tracing on an offline CPU
> --
>
> commit 431ca53aed38063c4c77184079a32f5fbbb5b69b
> Author: Yeoreum Yun <yeoreum.yun@arm.com>
>
> coresight: etm4x: fix inconsistencies with sysfs configuration
>
> This commit separates the configuration into curr_config and config to prevent
> inconsistencies when modifying via sysfs during an active perf session. It
> also removes the lock/unlock from the sysfs enable/disable path and
> startup/dying_cpu, except when accessing config fields.
>
> > diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > @@ -1090,8 +1097,9 @@ static void etm4_disable_sysfs_smp_call(void *info)
> >
> > etm4_disable_hw(drvdata);
> >
> > + cscfg_csdev_disable_active_config(drvdata->csdev);
> > +
> > drvdata->csdev->path = NULL;
> > - coresight_set_mode(drvdata->csdev, CS_MODE_DISABLED);
> > }
>
> [ ... ]
>
> > @@ -1144,9 +1153,19 @@ static void etm4_disable_sysfs(struct coresight_device *csdev)
> > smp_call_function_single(drvdata->cpu, etm4_disable_sysfs_smp_call,
> > drvdata, 1);
>
> [Severity: Medium]
> If smp_call_function_single() fails (for instance, if the target CPU is
> offline), it will return -ENXIO and bypass the callback entirely.
> Since cscfg_csdev_disable_active_config() was moved into the SMP callback
> etm4_disable_sysfs_smp_call(), does this mean we could permanently leak the
> active configuration when the CPU is offline? This could leave the module
> reference count (active_cnt) leaked and active_cscfg_ctxt dangling.
This is totally wrong. since sysfs seesion is disabled before *offline*
by coresight_dying_cpu().
> >
> > - raw_spin_unlock(&drvdata->spinlock);
> > + /*
> > + * Userspace may read ss_status and cntr_val through sysfs after
> > + * the sysfs-session has been disabled.
> > + */
> > + for (i = 0; i < drvdata->nr_ss_cmp; i++)
> > + config->ss_status[i] = curr_config->ss_status[i];
> >
> > - cscfg_csdev_disable_active_config(csdev);
> > + for (i = 0; i < drvdata->nr_cntr; i++)
> > + config->cntr_val[i] = curr_config->cntr_val[i];
> > +
> > + config->seq_state = curr_config->seq_state;
>
> [Severity: Medium]
> Is it safe to copy curr_config to config here without holding the
> drvdata->spinlock?
>
> Sysfs writers (like reset_store()) and readers (like cntr_val_show()) do
> not check if the device is currently in CS_MODE_SYSFS; they rely solely on
> the spinlock for synchronization.
>
> Could this create a data race where concurrent sysfs operations are
> overwritten by this lockless loop, corrupting the sysfs-exposed state?
It's okay since the ss_status's purpose is to clear the PENDING and
STATUS bit otherwise, RES and RO field.
>
> > +
> > + coresight_set_mode(drvdata->csdev, CS_MODE_DISABLED);
> >
> > /*
> > * we only release trace IDs when resetting sysfs.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261002-separate_etm_cfg_v2-v13-0-fe429d8d96fb@arm.com?part=4
--
Sincerely,
Yeoreum Yun
next prev parent reply other threads:[~2026-10-03 2:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 19:03 [PATCH v13 00/14] fix several inconsistencies with sysfs configuration in etmX Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 01/14] coresight: etm4x: read-back TRCSEQSTR at disabling and prohibit modifying seq_state while enabling Yeoreum Yun
2026-10-03 1:33 ` sashiko-bot
2026-10-03 1:47 ` Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 02/14] coresight: etm4x: prohibit modifying cntr_val while session is enabled Yeoreum Yun
2026-10-03 1:33 ` sashiko-bot
2026-10-03 1:50 ` Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 03/14] coresight: etm3x: prohibit modifying cntr_val and reset " Yeoreum Yun
2026-10-03 1:33 ` sashiko-bot
2026-10-03 2:02 ` Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 04/14] coresight: etm4x: fix inconsistencies with sysfs configuration Yeoreum Yun
2026-10-03 1:33 ` sashiko-bot
2026-10-03 2:30 ` Yeoreum Yun [this message]
2026-10-02 19:03 ` [PATCH v13 05/14] coresight: etm3x: " Yeoreum Yun
2026-10-03 1:33 ` sashiko-bot
2026-10-03 2:47 ` Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 06/14] coresight: etm3x: remove redundant cpu online check on etm_enable_sysfs() Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 07/14] coresight: etm4x: introduce struct etm4_caps Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 08/14] coresight: etm4x: exclude ss_status from drvdata->config Yeoreum Yun
2026-10-03 1:33 ` sashiko-bot
2026-10-03 2:38 ` Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 09/14] coresight: etm4x: remove s_ex_level from config Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 10/14] coresight: etm4x: rename local config as curr_config referring drvdata->curr_config Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 11/14] coresight: etm4x: rename drvdata->config to sysfs_config Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 12/14] coresight: etm3x: introduce struct etm_caps Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 13/14] coresight: etm3x: rename local config as curr_config referring drvdata->curr_config Yeoreum Yun
2026-10-02 19:03 ` [PATCH v13 14/14] coresight: etm3x: rename drvdata->config to sysfs_config Yeoreum Yun
2026-10-03 2:49 ` [PATCH v13 00/14] fix several inconsistencies with sysfs configuration in etmX Yeoreum Yun
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=asBovdmuZRDF5r8c@e129823.arm.com \
--to=yeoreum.yun@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.