public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fsi: core: Lock scan mutex for master index removal
@ 2023-04-12 18:56 Eddie James
  2023-04-12 18:56 ` [PATCH 1/2] " Eddie James
  2023-04-12 18:56 ` [PATCH 2/2] fsi: core: Add trace events for scan and unregister Eddie James
  0 siblings, 2 replies; 6+ messages in thread
From: Eddie James @ 2023-04-12 18:56 UTC (permalink / raw)
  To: linux-fsi; +Cc: linux-kernel, joel, jk, alistair, Eddie James

If a master scan occurs while the master is being unregistered,
the devicecs may end up with incorrect and possibly duplicate names,
resulting in kernel warnings. Ensure the master index isn't changed
outside of the scan mutex.
In addition, add some trace events to debug any further issues in this
area.

Eddie James (2):
  fsi: core: Lock scan mutex for master index removal
  fsi: core: Add trace events for scan and unregister

 drivers/fsi/fsi-core.c     |  6 +++++-
 include/trace/events/fsi.h | 31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] fsi: core: Lock scan mutex for master index removal
  2023-04-12 18:56 [PATCH 0/2] fsi: core: Lock scan mutex for master index removal Eddie James
@ 2023-04-12 18:56 ` Eddie James
  2023-05-31  7:47   ` Joel Stanley
  2023-04-12 18:56 ` [PATCH 2/2] fsi: core: Add trace events for scan and unregister Eddie James
  1 sibling, 1 reply; 6+ messages in thread
From: Eddie James @ 2023-04-12 18:56 UTC (permalink / raw)
  To: linux-fsi; +Cc: linux-kernel, joel, jk, alistair, Eddie James

If a master scan occurs while the master is being unregistered,
the devicecs may end up with incorrect and possibly duplicate names,
resulting in kernel warnings. Ensure the master index isn't changed
outside of the scan mutex.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/fsi/fsi-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index fcbf0469ce3f..18d4d68482d7 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1354,12 +1354,12 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
 
 void fsi_master_unregister(struct fsi_master *master)
 {
+	mutex_lock(&master->scan_lock);
 	if (master->idx >= 0) {
 		ida_simple_remove(&master_ida, master->idx);
 		master->idx = -1;
 	}
 
-	mutex_lock(&master->scan_lock);
 	fsi_master_unscan(master);
 	mutex_unlock(&master->scan_lock);
 	device_unregister(&master->dev);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] fsi: core: Add trace events for scan and unregister
  2023-04-12 18:56 [PATCH 0/2] fsi: core: Lock scan mutex for master index removal Eddie James
  2023-04-12 18:56 ` [PATCH 1/2] " Eddie James
@ 2023-04-12 18:56 ` Eddie James
  2023-05-31  1:52   ` Joel Stanley
  1 sibling, 1 reply; 6+ messages in thread
From: Eddie James @ 2023-04-12 18:56 UTC (permalink / raw)
  To: linux-fsi; +Cc: linux-kernel, joel, jk, alistair, Eddie James

Add more trace events for the scanning and unregistration
functions for debug purposes.

Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
 drivers/fsi/fsi-core.c     |  4 ++++
 include/trace/events/fsi.h | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 18d4d68482d7..2dc119ab073c 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1220,6 +1220,7 @@ static int fsi_master_scan(struct fsi_master *master)
 {
 	int link, rc;
 
+	trace_fsi_master_scan(master, true);
 	for (link = 0; link < master->n_links; link++) {
 		rc = fsi_master_link_enable(master, link);
 		if (rc) {
@@ -1261,6 +1262,7 @@ static int fsi_master_remove_slave(struct device *dev, void *arg)
 
 static void fsi_master_unscan(struct fsi_master *master)
 {
+	trace_fsi_master_scan(master, false);
 	device_for_each_child(&master->dev, NULL, fsi_master_remove_slave);
 }
 
@@ -1355,6 +1357,8 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
 void fsi_master_unregister(struct fsi_master *master)
 {
 	mutex_lock(&master->scan_lock);
+	trace_fsi_master_unregister(master);
+
 	if (master->idx >= 0) {
 		ida_simple_remove(&master_ida, master->idx);
 		master->idx = -1;
diff --git a/include/trace/events/fsi.h b/include/trace/events/fsi.h
index c9a72e8432b8..5ff15126ad9d 100644
--- a/include/trace/events/fsi.h
+++ b/include/trace/events/fsi.h
@@ -122,6 +122,37 @@ TRACE_EVENT(fsi_master_break,
 	)
 );
 
+TRACE_EVENT(fsi_master_scan,
+	TP_PROTO(const struct fsi_master *master, bool scan),
+	TP_ARGS(master, scan),
+	TP_STRUCT__entry(
+		__field(int,	master_idx)
+		__field(int,	n_links)
+		__field(bool,	scan)
+	),
+	TP_fast_assign(
+		__entry->master_idx = master->idx;
+		__entry->n_links = master->n_links;
+		__entry->scan = scan;
+	),
+	TP_printk("fsi%d (%d links) %s", __entry->master_idx, __entry->n_links,
+		  __entry->scan ? "scan" : "unscan")
+);
+
+TRACE_EVENT(fsi_master_unregister,
+	TP_PROTO(const struct fsi_master *master),
+	TP_ARGS(master),
+	TP_STRUCT__entry(
+		__field(int,	master_idx)
+		__field(int,	n_links)
+	),
+	TP_fast_assign(
+		__entry->master_idx = master->idx;
+		__entry->n_links = master->n_links;
+	),
+	TP_printk("fsi%d (%d links)", __entry->master_idx, __entry->n_links)
+);
+
 TRACE_EVENT(fsi_slave_init,
 	TP_PROTO(const struct fsi_slave *slave),
 	TP_ARGS(slave),
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] fsi: core: Add trace events for scan and unregister
  2023-04-12 18:56 ` [PATCH 2/2] fsi: core: Add trace events for scan and unregister Eddie James
@ 2023-05-31  1:52   ` Joel Stanley
  0 siblings, 0 replies; 6+ messages in thread
From: Joel Stanley @ 2023-05-31  1:52 UTC (permalink / raw)
  To: Eddie James; +Cc: linux-fsi, linux-kernel, jk, alistair

On Wed, 12 Apr 2023 at 18:56, Eddie James <eajames@linux.ibm.com> wrote:
>
> Add more trace events for the scanning and unregistration
> functions for debug purposes.
>
> Signed-off-by: Eddie James <eajames@linux.ibm.com>

Reviewed-by: Joel Stanley <joel@jms.id.au>

> ---
>  drivers/fsi/fsi-core.c     |  4 ++++
>  include/trace/events/fsi.h | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+)
>
> diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
> index 18d4d68482d7..2dc119ab073c 100644
> --- a/drivers/fsi/fsi-core.c
> +++ b/drivers/fsi/fsi-core.c
> @@ -1220,6 +1220,7 @@ static int fsi_master_scan(struct fsi_master *master)
>  {
>         int link, rc;
>
> +       trace_fsi_master_scan(master, true);
>         for (link = 0; link < master->n_links; link++) {
>                 rc = fsi_master_link_enable(master, link);
>                 if (rc) {
> @@ -1261,6 +1262,7 @@ static int fsi_master_remove_slave(struct device *dev, void *arg)
>
>  static void fsi_master_unscan(struct fsi_master *master)
>  {
> +       trace_fsi_master_scan(master, false);
>         device_for_each_child(&master->dev, NULL, fsi_master_remove_slave);
>  }
>
> @@ -1355,6 +1357,8 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
>  void fsi_master_unregister(struct fsi_master *master)
>  {
>         mutex_lock(&master->scan_lock);
> +       trace_fsi_master_unregister(master);
> +
>         if (master->idx >= 0) {
>                 ida_simple_remove(&master_ida, master->idx);
>                 master->idx = -1;
> diff --git a/include/trace/events/fsi.h b/include/trace/events/fsi.h
> index c9a72e8432b8..5ff15126ad9d 100644
> --- a/include/trace/events/fsi.h
> +++ b/include/trace/events/fsi.h
> @@ -122,6 +122,37 @@ TRACE_EVENT(fsi_master_break,
>         )
>  );
>
> +TRACE_EVENT(fsi_master_scan,
> +       TP_PROTO(const struct fsi_master *master, bool scan),
> +       TP_ARGS(master, scan),
> +       TP_STRUCT__entry(
> +               __field(int,    master_idx)
> +               __field(int,    n_links)
> +               __field(bool,   scan)
> +       ),
> +       TP_fast_assign(
> +               __entry->master_idx = master->idx;
> +               __entry->n_links = master->n_links;
> +               __entry->scan = scan;
> +       ),
> +       TP_printk("fsi%d (%d links) %s", __entry->master_idx, __entry->n_links,
> +                 __entry->scan ? "scan" : "unscan")
> +);
> +
> +TRACE_EVENT(fsi_master_unregister,
> +       TP_PROTO(const struct fsi_master *master),
> +       TP_ARGS(master),
> +       TP_STRUCT__entry(
> +               __field(int,    master_idx)
> +               __field(int,    n_links)
> +       ),
> +       TP_fast_assign(
> +               __entry->master_idx = master->idx;
> +               __entry->n_links = master->n_links;
> +       ),
> +       TP_printk("fsi%d (%d links)", __entry->master_idx, __entry->n_links)
> +);
> +
>  TRACE_EVENT(fsi_slave_init,
>         TP_PROTO(const struct fsi_slave *slave),
>         TP_ARGS(slave),
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] fsi: core: Lock scan mutex for master index removal
  2023-04-12 18:56 ` [PATCH 1/2] " Eddie James
@ 2023-05-31  7:47   ` Joel Stanley
  2023-06-08 16:45     ` Eddie James
  0 siblings, 1 reply; 6+ messages in thread
From: Joel Stanley @ 2023-05-31  7:47 UTC (permalink / raw)
  To: Eddie James; +Cc: linux-fsi, linux-kernel, jk, alistair

On Wed, 12 Apr 2023 at 18:56, Eddie James <eajames@linux.ibm.com> wrote:
>
> If a master scan occurs while the master is being unregistered,
> the devicecs may end up with incorrect and possibly duplicate names,

typo: devices

> resulting in kernel warnings. Ensure the master index isn't changed
> outside of the scan mutex.
>
> Signed-off-by: Eddie James <eajames@linux.ibm.com>
> ---
>  drivers/fsi/fsi-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
> index fcbf0469ce3f..18d4d68482d7 100644
> --- a/drivers/fsi/fsi-core.c
> +++ b/drivers/fsi/fsi-core.c
> @@ -1354,12 +1354,12 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
>
>  void fsi_master_unregister(struct fsi_master *master)
>  {
> +       mutex_lock(&master->scan_lock);

The ida functions are supposed to not require locking, but protecting
against the test and changing of ->idx makes sense.

Do you want to add a Fixes: line?

>         if (master->idx >= 0) {
>                 ida_simple_remove(&master_ida, master->idx);

the ida_simple functions are depreciated, at some point we should
replace them with ida_alloc/ida_free.

>                 master->idx = -1;
>         }
>
> -       mutex_lock(&master->scan_lock);
>         fsi_master_unscan(master);
>         mutex_unlock(&master->scan_lock);
>         device_unregister(&master->dev);
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] fsi: core: Lock scan mutex for master index removal
  2023-05-31  7:47   ` Joel Stanley
@ 2023-06-08 16:45     ` Eddie James
  0 siblings, 0 replies; 6+ messages in thread
From: Eddie James @ 2023-06-08 16:45 UTC (permalink / raw)
  To: Joel Stanley; +Cc: linux-fsi, linux-kernel, jk, alistair


On 5/31/23 02:47, Joel Stanley wrote:
> On Wed, 12 Apr 2023 at 18:56, Eddie James <eajames@linux.ibm.com> wrote:
>> If a master scan occurs while the master is being unregistered,
>> the devicecs may end up with incorrect and possibly duplicate names,
> typo: devices


Thanks...



>
>> resulting in kernel warnings. Ensure the master index isn't changed
>> outside of the scan mutex.
>>
>> Signed-off-by: Eddie James <eajames@linux.ibm.com>
>> ---
>>   drivers/fsi/fsi-core.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
>> index fcbf0469ce3f..18d4d68482d7 100644
>> --- a/drivers/fsi/fsi-core.c
>> +++ b/drivers/fsi/fsi-core.c
>> @@ -1354,12 +1354,12 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
>>
>>   void fsi_master_unregister(struct fsi_master *master)
>>   {
>> +       mutex_lock(&master->scan_lock);
> The ida functions are supposed to not require locking, but protecting
> against the test and changing of ->idx makes sense.
>
> Do you want to add a Fixes: line?


Sure.


>
>>          if (master->idx >= 0) {
>>                  ida_simple_remove(&master_ida, master->idx);
> the ida_simple functions are depreciated, at some point we should
> replace them with ida_alloc/ida_free.


OK, I'll see if it makes sense to do that now.

Thanks!

Eddie


>
>>                  master->idx = -1;
>>          }
>>
>> -       mutex_lock(&master->scan_lock);
>>          fsi_master_unscan(master);
>>          mutex_unlock(&master->scan_lock);
>>          device_unregister(&master->dev);
>> --
>> 2.31.1
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-08 16:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-12 18:56 [PATCH 0/2] fsi: core: Lock scan mutex for master index removal Eddie James
2023-04-12 18:56 ` [PATCH 1/2] " Eddie James
2023-05-31  7:47   ` Joel Stanley
2023-06-08 16:45     ` Eddie James
2023-04-12 18:56 ` [PATCH 2/2] fsi: core: Add trace events for scan and unregister Eddie James
2023-05-31  1:52   ` Joel Stanley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox