fsi: core: Lock scan mutex for master index removal
Eddie James
maintainercover fsi: core: Lock scan mutex for master index removal
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(-)
Signature · 1 line
2.31.1
Eddie James
maintainerPATCH 1/2 fsi: core: Lock scan mutex for master index removal
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.
--- drivers/fsi/fsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fsi/fsi-core.c +1 -1
@@ -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);
Signature · 1 line
2.31.1
Eddie James
maintainerPATCH 2/2 fsi: core: Add trace events for scan and unregister
In reply to Eddie JamesAdd more trace events for the scanning and unregistration functions for debug purposes.
--- drivers/fsi/fsi-core.c | 4 ++++ include/trace/events/fsi.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
drivers/fsi/fsi-core.c +4 -0
@@ -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 ;
include/trace/events/fsi.h +31 -0
@@ -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),
Signature · 1 line
2.31.1
Re: [PATCH 2/2] fsi: core: Add trace events for scan and unregister
Quoted 5 lines · Eddie James
Add more trace events for the scanning and unregistration functions for debug purposes.
Signed-off-by Eddie James <[email protected]>
Quoted 79 lines
--- drivers/fsi/fsi-core.c | 4 ++++ include/trace/events/fsi.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)drivers/fsi/fsi-core.c +4
-0@@ -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 ;include/trace/events/fsi.h +31
-1@@ -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
Quoted 3 lines · Eddie James
If a master scan occurs while the master is being unregistered, the devicecs may end up with incorrect and possibly duplicate names,
typo: devices
Quoted 13 lines
resulting in kernel warnings. Ensure the master index isn't changed outside of the scan mutex.
Signed-off-by Eddie James <[email protected]>--- drivers/fsi/fsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/fsi/fsi-core.c +0
-0
drivers/fsi/fsi-core.c EXPORT_SYMBOL_GPL(fsi_master_register); · line 1357
Quoted 4 lines
drivers/fsi/fsi-core.c +1
-0@@ -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?
drivers/fsi/fsi-core.c EXPORT_SYMBOL_GPL(fsi_master_register); · line 1359
Quoted 2 lines
drivers/fsi/fsi-core.c +0
-0if (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.
Quoted 10 lines
drivers/fsi/fsi-core.c +0
-2master->idx =-1 ; } -mutex_lock (&master->scan_lock);fsi_master_unscan (master);mutex_unlock (&master->scan_lock);device_unregister (&master->dev); --2.31.1
Eddie James
maintainerQuoted 4 lines · Joel Stanley
Quoted 2 lines · Eddie James
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...
Quoted 15 lines
Quoted 15 lines
resulting in kernel warnings. Ensure the master index isn't changed outside of the scan mutex.
Signed-off-by Eddie James <[email protected]>--- drivers/fsi/fsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/fsi/fsi-core.c +0
-0@@ -1354,12 +1354,12 @@ EXPORT_SYMBOL_GPL(fsi_master_register);
Quoted 7 lines
drivers/fsi/fsi-core.c EXPORT_SYMBOL_GPL(fsi_master_register); · line 1357
Quoted 3 lines
drivers/fsi/fsi-core.c +1
-0void 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.
Quoted 5 lines
drivers/fsi/fsi-core.c EXPORT_SYMBOL_GPL(fsi_master_register); · line 1359
Quoted 3 lines
drivers/fsi/fsi-core.c +0
-0if (master->idx >=0 ) {ida_simple_remove (&master_ida, master->idx);the
ida_simplefunctions 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
Quoted 11 lines
Quoted 11 lines
drivers/fsi/fsi-core.c +0
-2master->idx =-1 ; } -mutex_lock (&master->scan_lock);fsi_master_unscan (master);mutex_unlock (&master->scan_lock);device_unregister (&master->dev); --2.31.1