loop: potential kernel hang waiting for kthread
PATCH 1/1 loop: potential kernel hang waiting for kthread
Hi Andrew! Folks!
just stumbled over the following issue with loop_set_fd() calling kernel_thread(loop_thread), ignoring the return value, even if it is an error, then doing wait_for_completion() on the device, which, in beforementioned error case, would wait forever (keeping a process stuck in 'D' state)
I can imagine at least three other solutions, but this one seemed quite organic to me, YMMV ...
best,
Herbert
---
drivers/block/loop.c +6 -1
@@ -747,6 +747,7 @@ static int loop_set_fd(struct loop_devicint lo_flags =0 ;int error;loff_t size; +pid_t pid;/* This is safe, since we have a reference from open(). */ __module_get (THIS_MODULE );
@@ -839,10 +840,14 @@ static int loop_set_fd(struct loop_devicset_blocksize (bdev, lo_blocksize); -kernel_thread (loop_thread, lo,CLONE_KERNEL ); + pid =kernel_thread (loop_thread, lo,CLONE_KERNEL ); +if (pid <0 ) + goto out_err;wait_for_completion (&lo->lo_done);return 0 ; + out_err: + error = (int )pid; out_putf:fput (file); out:
Quoted 11 lines · Herbert Poetzl
Hi Andrew! Folks!
just stumbled over the following issue with
loop_set_fd()callingkernel_thread(loop_thread), ignoring the return value, even if it is an error, then doingwait_for_completion()on the device, which, in beforementioned error case, would wait forever (keeping a process stuck in 'D' state)I can imagine at least three other solutions, but this one seemed quite organic to me, YMMV ...
Best thing would be to switch it to the kthread_ API.