linux/drivers/virtio
Amit Shah e562966dba virtio: balloon: Add freeze, restore handlers to support S4
Handling balloon hibernate / restore is tricky.  If the balloon was
inflated before going into the hibernation state, upon resume, the host
will not have any memory of that.  Any pages that were passed on to the
host earlier would most likely be invalid, and the host will have to
re-balloon to the previous value to get in the pre-hibernate state.

So the only sane thing for the guest to do here is to discard all the
pages that were put in the balloon.  When to discard the pages is the
next question.

One solution is to deflate the balloon just before writing the image to
the disk (in the freeze() PM callback).  However, asking for pages from
the host just to discard them immediately after seems wasteful of
resources.  Hence, it makes sense to do this by just fudging our
counters soon after wakeup.  This means we don't deflate the balloon
before sleep, and also don't put unnecessary pressure on the host.

This also helps in the thaw case: if the freeze fails for whatever
reason, the balloon should continue to remain in the inflated state.
This was tested by issuing 'swapoff -a' and trying to go into the S4
state.  That fails, and the balloon stays inflated, as expected.  Both
the host and the guest are happy.

Finally, in the restore() callback, we empty the list of pages that were
previously given off to the host, add the appropriate number of pages to
the totalram_pages counter, reset the num_pages counter to 0, and
all is fine.

As a last step, delete the vqs on the freeze callback to prepare for
hibernation, and re-create them in the restore and thaw callbacks to
resume normal operation.

The kthread doesn't race with any operations here, since it's frozen
before the freeze() call and is thawed after the thaw() and restore()
callbacks, so we're safe with that.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2012-01-12 15:44:47 +10:30
..
Kconfig virtio: add HAS_IOMEM dependency to MMIO platform bus driver 2011-11-24 13:04:47 +10:30
Makefile virtio: Add platform bus driver for memory mapped virtio device 2011-11-02 11:41:01 +10:30
config.c Virtio interface 2007-10-23 15:49:54 +10:00
virtio.c virtio: Add module.h to drivers/virtio users. 2011-10-31 19:32:14 -04:00
virtio_balloon.c virtio: balloon: Add freeze, restore handlers to support S4 2012-01-12 15:44:47 +10:30
virtio_mmio.c virtio: harsher barriers for rpmsg. 2012-01-12 15:44:42 +10:30
virtio_pci.c virtio: pci: add PM notification handlers for restore, freeze, thaw, poweroff 2012-01-12 15:44:44 +10:30
virtio_ring.c virtio: add debugging if driver doesn't kick. 2012-01-12 15:44:43 +10:30