The attached test reliably reproduces the deadlock without these patches.
This may not be the preferred way to avoid this deadlock, and I may be missing some context as to why the code is structured like it is...
[deadlock-test.diff](/uploads/91898ab89d5eca8fb18709112a0f751c/deadlock-test.diff)