set td->io_ops to NULL before dlclose()
Hi Jens,
I'm top-posting here to catch your attention. If it wasn't clear, the patch I sent is generally applicable and not intended just for the original reporter, i.e., it's a candidate for integration.
Thanks,
Justin
Quoted 73 lines · Justin Eno (jeno)
Quoted 33 lines · James R
Quoted 33 lines · James R
If using ioengine=/path/to/ioengine to dynamically load an ioengine, there is a race between free_ioengine()'s
dlclose()and thetd->io_opsdereference inreap_threads().To resolve,
td->io_opsmust be set to NULL before callingdlclose()- this ensures the name check inreap_threads()does not try to reference memory no longer accessible due to the ioengine getting closed.Signed-off-by Jim Harris <[email protected]>---
ioengines.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)ioengines.c +2
-2@@ -170,10 +170,10 @@ void free_ioengine(struct thread_data *td) td->eo = NULL; } + td->io_ops = NULL; + if (td->io_ops_dlhandle) dlclose(td->io_ops_dlhandle); - - td->io_ops = NULL; }Quoted 8 lines
Quoted 4 lines
ioengines.c +0
-0void close_ioengine (struct thread_data *td)Signature · 1 line
2.12.2Please ignore. This only narrows the race window - it does not close it.
I also have a system that is prone to this segfault. Without some type of mutex,
td_iopscannot be dereferenced safely inreap_threads().This alternative patch works for me:
Signed-off-by Justin Eno <[email protected]>---
backend.c| 6 +-----1 file changed, 1 insertion(+), 5 deletions(-)backend.c +1
-5@@ -1929,11 +1929,7 @@ static void reap_threads(unsigned int *nr_running, uint64_t *t_rate, for_each_td(td, i) { int flags = 0; - /* - * ->io_ops is NULL for a thread that has closed its - * io engine - */ - if (td->io_ops && !strcmp(td->io_ops->name, "cpuio")) + if (!strcmp(td->o.ioengine, "cpuio")) cputhreads++;else
realthreads++;Signature · 3 lines
1.8.3.1 --
Quoted 5 lines · Justin Eno (jeno)
Hi Jens,
I'm top-posting here to catch your attention. If it wasn't clear, the patch I sent is generally applicable and not intended just for the original reporter, i.e., it's a candidate for integration.
Looks good to me, that should close the race. Applied, thanks.
Signature · 1 line
Jens Axboe