migration: Wait on preempt channel in preempt thread
authorPeter Xu <peterx@redhat.com>
Tue, 14 Mar 2023 20:54:29 +0000 (16:54 -0400)
committerJuan Quintela <quintela@redhat.com>
Thu, 16 Mar 2023 15:07:07 +0000 (16:07 +0100)
commita5d35dc7e06896a33216610cc86527258735b0e3
tree1d899221551709fdd19fa405f55921f779ab41b9
parent9636e513255362c4a329e3e5fb2c97dab3c5ce47
migration: Wait on preempt channel in preempt thread

QEMU main thread will wait until dest preempt channel established during
processing the LISTEN command (within the whole postcopy PACKAGED data), by
waiting on the semaphore postcopy_qemufile_dst_done.

That's racy, because it's possible that the dest QEMU main thread hasn't
yet accept()ed the new connection when processing the LISTEN event.  The
sem_wait() will yield the main thread without being able to run anything
else including the accept() of the new socket, which can cause deadlock
within the main thread.

To avoid the race, move the "wait channel" from main thread to the preempt
thread right at the start.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: 5655aab079 ("migration: Postpone postcopy preempt channel to be after main")
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
migration/postcopy-ram.c