On Thu, 2018-10-25 at 16:21 -0400, Theodore Y. Ts'o wrote: > We can guarantee it from someone who is looking at the code path. In > dio_set_defer_completion:
[snip] Right, it's indeed pretty obvious. I shouldn't have tried to reply before the kids went to bed, that made me cut some corners ;-) > The race found in the syzbot reproducer has multiple threads all > running DIO writes at the same time. So we have multiple threads > calling sb_init_dio_done_wq, but all but one will lose the race, and > then call destry_workqueue on the freshly created (but never used) > workqueue. Right. > We could replace the destroy_workqueue(wq) with a > "I_solemnly_swear_this_workqueue_has_never_been_used_please_destroy(wq)". :-) > Or, as Tejun suggested, "destroy_workqueue_skip_drain(wq)", but there is > no way for the workqueue code to know whether the caller was using the > interface correctly. So this basically becomes a philosophical > question about whether or not we trust the caller to be correct or > not. Right. Same with the lockdep annotation I suggested over in my other email, of course. I think that the set of APIs I wrote there ({drain,flush,destroy}_workqueue_nested()) might be more generally useful in other cases, not just this one, and I suspect that this code would basically be the only user of destroy_workqueue_skip_drain(). > I don't see an obvious way that we can test to make sure the workqueue > is never used without actually taking a performance. Am I correct > that we would need to take the wq->mutex before we can mess with the > wq->flags field? I don't really know, sorry. johannes