Commit c6725ee
committed
vsock: Enable live migrations (snapshot-restore)
The [virtio
spec](https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.html#x1-4950001)
mandates that when restoring from a snapshot (such as when the VM was
migrated to a different host) the device must send a TRANSPORT RESET
event via the event virtqueue to the driver. The driver in turn, upon
receiving the event, must drop all existing connections while keeping
all listeners and read the CID again from the device configuration
space and update the listeners with the (potentially different) CID.
On the device side care must be taken to ensure no new connections are
established until that transport reset event is handled otherwise the
guest will silently drop them and the peer may not know about it. Given
that the driver must read the CID from the configuration space during
normal boot and after doing a reset that's the best signal for the
device to "activate" and start processing packets from the host and
sibling VMs. Feature negotiation also happens during both normal boot
and restore, but in the case of restore it happens before the transport
reset and therefore can't be used as reliable signal to "activate" the
device.
The device doesn't need to save/load any state for this. When loading a
snapshot the device simply notes that it must send a TRANSPORT RESET
event to the driver as soon as possible, which it then does when it
receives a kick on the event vring. Independently of whether the device
is started to restore a previous VM state or brand new (the device
actually doesn't know until it `set_device_state_fd` is called), the
device always starts in "inactive" state, meaning it will drop any
packets coming from any source. As mentioned before the device
"activates" once the driver has read the configuration space.
Unlike other VMMs, QEMU takes ownership of the event vring and handles
sending of the TRANSPORT RESET event itself. This change attempts to handle
both approaches by sending the TRANSPORT RESET event if the vring is
kicked, but doesn't treat it as precondition to activate the device,
instead choosing to activate unconditionally once the driver reads the
configuration space.
There is a race in this implementation, that occurs when the snapshot
was taken before the guest driver read the configuration and then it
reads immediately upon restore, before the transport reset event was
handled. While this could be mitigated by waiting for the reset event to
be sent AND the config to be read AFTER the event was sent, QEMU's
decision to take over the event queue makes that approach unviable.
Hopefully, it will be very unlikely a snapshot will be taken before the
driver is fully initialized as that would be of very little value in
practice.
Signed-off-by: Jorge E. Moreira <jemoreira@google.com>1 parent 62a6cf7 commit c6725ee
File tree
5 files changed
+189
-42
lines changed- vhost-device-vsock
- src
5 files changed
+189
-42
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
132 | 144 | | |
133 | 145 | | |
134 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
353 | 360 | | |
354 | 361 | | |
355 | 362 | | |
| |||
525 | 532 | | |
526 | 533 | | |
527 | 534 | | |
| 535 | + | |
528 | 536 | | |
529 | 537 | | |
530 | 538 | | |
| |||
698 | 706 | | |
699 | 707 | | |
700 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
701 | 723 | | |
702 | 724 | | |
703 | 725 | | |
704 | 726 | | |
705 | 727 | | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
706 | 731 | | |
707 | 732 | | |
708 | 733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | | - | |
28 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
29 | 39 | | |
30 | 40 | | |
31 | 41 | | |
| |||
72 | 82 | | |
73 | 83 | | |
74 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
75 | 88 | | |
76 | | - | |
| 89 | + | |
77 | 90 | | |
78 | 91 | | |
79 | 92 | | |
| |||
141 | 154 | | |
142 | 155 | | |
143 | 156 | | |
| 157 | + | |
| 158 | + | |
144 | 159 | | |
145 | 160 | | |
146 | 161 | | |
| |||
261 | 276 | | |
262 | 277 | | |
263 | 278 | | |
| 279 | + | |
264 | 280 | | |
265 | 281 | | |
266 | 282 | | |
| |||
286 | 302 | | |
287 | 303 | | |
288 | 304 | | |
| 305 | + | |
289 | 306 | | |
290 | 307 | | |
291 | 308 | | |
| |||
310 | 327 | | |
311 | 328 | | |
312 | 329 | | |
313 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
314 | 333 | | |
315 | 334 | | |
316 | 335 | | |
| |||
335 | 354 | | |
336 | 355 | | |
337 | 356 | | |
| 357 | + | |
338 | 358 | | |
339 | 359 | | |
340 | 360 | | |
| |||
349 | 369 | | |
350 | 370 | | |
351 | 371 | | |
352 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
353 | 377 | | |
354 | 378 | | |
355 | 379 | | |
| |||
389 | 413 | | |
390 | 414 | | |
391 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
392 | 425 | | |
393 | 426 | | |
394 | 427 | | |
| |||
401 | 434 | | |
402 | 435 | | |
403 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
404 | 454 | | |
405 | 455 | | |
406 | 456 | | |
| |||
436 | 486 | | |
437 | 487 | | |
438 | 488 | | |
| 489 | + | |
439 | 490 | | |
440 | 491 | | |
441 | 492 | | |
442 | 493 | | |
443 | 494 | | |
| 495 | + | |
| 496 | + | |
444 | 497 | | |
445 | 498 | | |
446 | 499 | | |
447 | 500 | | |
448 | 501 | | |
449 | | - | |
| 502 | + | |
450 | 503 | | |
451 | 504 | | |
452 | 505 | | |
| |||
569 | 622 | | |
570 | 623 | | |
571 | 624 | | |
| 625 | + | |
572 | 626 | | |
573 | 627 | | |
574 | 628 | | |
| |||
0 commit comments