2020-10-29 16:49:04

by Mathieu Poirier

[permalink] [raw]
Subject: [PATCH 0/2] coresight: Fixes for v5.10-rc2

Hi Greg,

Please consider those when collecting fixes for this cycle.

Thanks,
Mathieu

Mike Leach (1):
coresight: Fix uninitialised pointer bug in etm_setup_aux()

Suzuki K Poulose (1):
coresight: cti: Initialize dynamic sysfs attributes

drivers/hwtracing/coresight/coresight-cti-sysfs.c | 7 +++++++
drivers/hwtracing/coresight/coresight-etm-perf.c | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)

--
2.25.1


2020-10-29 16:49:14

by Mathieu Poirier

[permalink] [raw]
Subject: [PATCH 1/2] coresight: cti: Initialize dynamic sysfs attributes

From: Suzuki K Poulose <[email protected]>

With LOCKDEP enabled, CTI driver triggers the following splat due
to uninitialized lock class for dynamically allocated attribute
objects.

[ 5.372901] coresight etm0: CPU0: ETM v4.0 initialized
[ 5.376694] coresight etm1: CPU1: ETM v4.0 initialized
[ 5.380785] coresight etm2: CPU2: ETM v4.0 initialized
[ 5.385851] coresight etm3: CPU3: ETM v4.0 initialized
[ 5.389808] BUG: key ffff00000564a798 has not been registered!
[ 5.392456] ------------[ cut here ]------------
[ 5.398195] DEBUG_LOCKS_WARN_ON(1)
[ 5.398233] WARNING: CPU: 1 PID: 32 at kernel/locking/lockdep.c:4623 lockdep_init_map_waits+0x14c/0x260
[ 5.406149] Modules linked in:
[ 5.415411] CPU: 1 PID: 32 Comm: kworker/1:1 Not tainted 5.9.0-12034-gbbe85027ce80 #51
[ 5.418553] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT)
[ 5.426453] Workqueue: events amba_deferred_retry_func
[ 5.433299] pstate: 40000005 (nZcv daif -PAN -UAO -TCO BTYPE=--)
[ 5.438252] pc : lockdep_init_map_waits+0x14c/0x260
[ 5.444410] lr : lockdep_init_map_waits+0x14c/0x260
[ 5.449007] sp : ffff800012bbb720
...

[ 5.531561] Call trace:
[ 5.536847] lockdep_init_map_waits+0x14c/0x260
[ 5.539027] __kernfs_create_file+0xa8/0x1c8
[ 5.543539] sysfs_add_file_mode_ns+0xd0/0x208
[ 5.548054] internal_create_group+0x118/0x3c8
[ 5.552307] internal_create_groups+0x58/0xb8
[ 5.556733] sysfs_create_groups+0x2c/0x38
[ 5.561160] device_add+0x2d8/0x768
[ 5.565148] device_register+0x28/0x38
[ 5.568537] coresight_register+0xf8/0x320
[ 5.572358] cti_probe+0x1b0/0x3f0

...

Fix this by initializing the attributes when they are allocated.

Fixes: 3c5597e39812 ("coresight: cti: Add connection information to sysfs")
Reported-by: Leo Yan <[email protected]>
Tested-by: Leo Yan <[email protected]>
Cc: Mike Leach <[email protected]>
Cc: Mathieu Poirier <[email protected]>
Signed-off-by: Suzuki K Poulose <[email protected]>
Signed-off-by: Mathieu Poirier <[email protected]>
---
drivers/hwtracing/coresight/coresight-cti-sysfs.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-cti-sysfs.c b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
index 392757f3a019..7ff7e7780bbf 100644
--- a/drivers/hwtracing/coresight/coresight-cti-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
@@ -1065,6 +1065,13 @@ static int cti_create_con_sysfs_attr(struct device *dev,
}
eattr->var = con;
con->con_attrs[attr_idx] = &eattr->attr.attr;
+ /*
+ * Initialize the dynamically allocated attribute
+ * to avoid LOCKDEP splat. See include/linux/sysfs.h
+ * for more details.
+ */
+ sysfs_attr_init(con->con_attrs[attr_idx]);
+
return 0;
}

--
2.25.1

2020-10-29 16:50:51

by Mathieu Poirier

[permalink] [raw]
Subject: [PATCH 2/2] coresight: Fix uninitialised pointer bug in etm_setup_aux()

From: Mike Leach <[email protected]>

Commit [bb1860efc817] changed the sink handling code introducing an
uninitialised pointer bug. This results in the default sink selection
failing.

Prior to commit:

static void etm_setup_aux(...)

<snip>
struct coresight_device *sink;
<snip>

/* First get the selected sink from user space. */
if (event->attr.config2) {
id = (u32)event->attr.config2;
sink = coresight_get_sink_by_id(id);
} else {
sink = coresight_get_enabled_sink(true);
}
<ctd>

*sink always initialised - possibly to NULL which triggers the
automatic sink selection.

After commit:

static void etm_setup_aux(...)

<snip>
struct coresight_device *sink;
<snip>

/* First get the selected sink from user space. */
if (event->attr.config2) {
id = (u32)event->attr.config2;
sink = coresight_get_sink_by_id(id);
}
<ctd>

*sink pointer uninitialised when not providing a sink on the perf command
line. This breaks later checks to enable automatic sink selection.

Fixes: bb1860efc817 ("coresight: etm: perf: Sink selection using sysfs is deprecated")
Signed-off-by: Mike Leach <[email protected]>
Signed-off-by: Mathieu Poirier <[email protected]>
---
drivers/hwtracing/coresight/coresight-etm-perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index c2c9b127d074..bdc34ca449f7 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -210,7 +210,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
u32 id;
int cpu = event->cpu;
cpumask_t *mask;
- struct coresight_device *sink;
+ struct coresight_device *sink = NULL;
struct etm_event_data *event_data = NULL;

event_data = alloc_event_data(cpu);
--
2.25.1

2020-10-29 19:12:47

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 1/2] coresight: cti: Initialize dynamic sysfs attributes

On Thu, Oct 29, 2020 at 10:45:58AM -0600, Mathieu Poirier wrote:
> From: Suzuki K Poulose <[email protected]>
>
> With LOCKDEP enabled, CTI driver triggers the following splat due
> to uninitialized lock class for dynamically allocated attribute
> objects.
>
> [ 5.372901] coresight etm0: CPU0: ETM v4.0 initialized
> [ 5.376694] coresight etm1: CPU1: ETM v4.0 initialized
> [ 5.380785] coresight etm2: CPU2: ETM v4.0 initialized
> [ 5.385851] coresight etm3: CPU3: ETM v4.0 initialized
> [ 5.389808] BUG: key ffff00000564a798 has not been registered!
> [ 5.392456] ------------[ cut here ]------------
> [ 5.398195] DEBUG_LOCKS_WARN_ON(1)
> [ 5.398233] WARNING: CPU: 1 PID: 32 at kernel/locking/lockdep.c:4623 lockdep_init_map_waits+0x14c/0x260
> [ 5.406149] Modules linked in:
> [ 5.415411] CPU: 1 PID: 32 Comm: kworker/1:1 Not tainted 5.9.0-12034-gbbe85027ce80 #51
> [ 5.418553] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT)
> [ 5.426453] Workqueue: events amba_deferred_retry_func
> [ 5.433299] pstate: 40000005 (nZcv daif -PAN -UAO -TCO BTYPE=--)
> [ 5.438252] pc : lockdep_init_map_waits+0x14c/0x260
> [ 5.444410] lr : lockdep_init_map_waits+0x14c/0x260
> [ 5.449007] sp : ffff800012bbb720
> ...
>
> [ 5.531561] Call trace:
> [ 5.536847] lockdep_init_map_waits+0x14c/0x260
> [ 5.539027] __kernfs_create_file+0xa8/0x1c8
> [ 5.543539] sysfs_add_file_mode_ns+0xd0/0x208
> [ 5.548054] internal_create_group+0x118/0x3c8
> [ 5.552307] internal_create_groups+0x58/0xb8
> [ 5.556733] sysfs_create_groups+0x2c/0x38
> [ 5.561160] device_add+0x2d8/0x768
> [ 5.565148] device_register+0x28/0x38
> [ 5.568537] coresight_register+0xf8/0x320
> [ 5.572358] cti_probe+0x1b0/0x3f0
>
> ...
>
> Fix this by initializing the attributes when they are allocated.
>
> Fixes: 3c5597e39812 ("coresight: cti: Add connection information to sysfs")
> Reported-by: Leo Yan <[email protected]>
> Tested-by: Leo Yan <[email protected]>
> Cc: Mike Leach <[email protected]>
> Cc: Mathieu Poirier <[email protected]>
> Signed-off-by: Suzuki K Poulose <[email protected]>
> Signed-off-by: Mathieu Poirier <[email protected]>
> ---
> drivers/hwtracing/coresight/coresight-cti-sysfs.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/hwtracing/coresight/coresight-cti-sysfs.c b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> index 392757f3a019..7ff7e7780bbf 100644
> --- a/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> @@ -1065,6 +1065,13 @@ static int cti_create_con_sysfs_attr(struct device *dev,
> }
> eattr->var = con;
> con->con_attrs[attr_idx] = &eattr->attr.attr;
> + /*
> + * Initialize the dynamically allocated attribute
> + * to avoid LOCKDEP splat. See include/linux/sysfs.h
> + * for more details.
> + */
> + sysfs_attr_init(con->con_attrs[attr_idx]);
> +
> return 0;
> }

Should go to stable kernels too, as the patch this fixes is in 5.7.
I'll add the stable tag here, but feel free to do it yourself next time
:)

thanks,

greg k-h

2020-10-30 15:08:34

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH 1/2] coresight: cti: Initialize dynamic sysfs attributes

On Thu, Oct 29, 2020 at 08:10:11PM +0100, Greg KH wrote:
> On Thu, Oct 29, 2020 at 10:45:58AM -0600, Mathieu Poirier wrote:
> > From: Suzuki K Poulose <[email protected]>
> >
> > With LOCKDEP enabled, CTI driver triggers the following splat due
> > to uninitialized lock class for dynamically allocated attribute
> > objects.
> >
> > [ 5.372901] coresight etm0: CPU0: ETM v4.0 initialized
> > [ 5.376694] coresight etm1: CPU1: ETM v4.0 initialized
> > [ 5.380785] coresight etm2: CPU2: ETM v4.0 initialized
> > [ 5.385851] coresight etm3: CPU3: ETM v4.0 initialized
> > [ 5.389808] BUG: key ffff00000564a798 has not been registered!
> > [ 5.392456] ------------[ cut here ]------------
> > [ 5.398195] DEBUG_LOCKS_WARN_ON(1)
> > [ 5.398233] WARNING: CPU: 1 PID: 32 at kernel/locking/lockdep.c:4623 lockdep_init_map_waits+0x14c/0x260
> > [ 5.406149] Modules linked in:
> > [ 5.415411] CPU: 1 PID: 32 Comm: kworker/1:1 Not tainted 5.9.0-12034-gbbe85027ce80 #51
> > [ 5.418553] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT)
> > [ 5.426453] Workqueue: events amba_deferred_retry_func
> > [ 5.433299] pstate: 40000005 (nZcv daif -PAN -UAO -TCO BTYPE=--)
> > [ 5.438252] pc : lockdep_init_map_waits+0x14c/0x260
> > [ 5.444410] lr : lockdep_init_map_waits+0x14c/0x260
> > [ 5.449007] sp : ffff800012bbb720
> > ...
> >
> > [ 5.531561] Call trace:
> > [ 5.536847] lockdep_init_map_waits+0x14c/0x260
> > [ 5.539027] __kernfs_create_file+0xa8/0x1c8
> > [ 5.543539] sysfs_add_file_mode_ns+0xd0/0x208
> > [ 5.548054] internal_create_group+0x118/0x3c8
> > [ 5.552307] internal_create_groups+0x58/0xb8
> > [ 5.556733] sysfs_create_groups+0x2c/0x38
> > [ 5.561160] device_add+0x2d8/0x768
> > [ 5.565148] device_register+0x28/0x38
> > [ 5.568537] coresight_register+0xf8/0x320
> > [ 5.572358] cti_probe+0x1b0/0x3f0
> >
> > ...
> >
> > Fix this by initializing the attributes when they are allocated.
> >
> > Fixes: 3c5597e39812 ("coresight: cti: Add connection information to sysfs")
> > Reported-by: Leo Yan <[email protected]>
> > Tested-by: Leo Yan <[email protected]>
> > Cc: Mike Leach <[email protected]>
> > Cc: Mathieu Poirier <[email protected]>
> > Signed-off-by: Suzuki K Poulose <[email protected]>
> > Signed-off-by: Mathieu Poirier <[email protected]>
> > ---
> > drivers/hwtracing/coresight/coresight-cti-sysfs.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-cti-sysfs.c b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> > index 392757f3a019..7ff7e7780bbf 100644
> > --- a/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> > +++ b/drivers/hwtracing/coresight/coresight-cti-sysfs.c
> > @@ -1065,6 +1065,13 @@ static int cti_create_con_sysfs_attr(struct device *dev,
> > }
> > eattr->var = con;
> > con->con_attrs[attr_idx] = &eattr->attr.attr;
> > + /*
> > + * Initialize the dynamically allocated attribute
> > + * to avoid LOCKDEP splat. See include/linux/sysfs.h
> > + * for more details.
> > + */
> > + sysfs_attr_init(con->con_attrs[attr_idx]);
> > +
> > return 0;
> > }
>
> Should go to stable kernels too, as the patch this fixes is in 5.7.
> I'll add the stable tag here, but feel free to do it yourself next time
> :)

Oh - I (wrongly) assumed all patches with a "Fixes" tag were going to stable.

>
> thanks,
>
> greg k-h