On 6/12/23 04:15, Martin Wilck wrote:
I guess the race that Bart was hinting at is hard to trigger.
Are you sure about this? I think this scenario can be triggered by writing into the sysfs attribute that changes the SCSI device state while a scsi_target_block() call is in progress. See also store_state_field().
I would like to remark that the fact that we need to hold the SCSI state_mutex while calling blk_mq_quiesce_queue_nowait() looks like a layering issue to me. Not sure if, and how, this could be avoided, though.
I do not agree that this is a layering issue. Is holding a mutex around a call of a function in a lower layer ever a layering issue?
What matters is to be very careful with locks while invoking callback functions. See also slide 7 in Ousterhout's presentation "Why Threads Are A Bad Idea (for most purposes)" from 1996 (https://web.stanford.edu/~ouster/cgi-bin/papers/threads.pdf).
Bart.