qemu-e2k/include/hw/virtio
David Hildenbrand 910b25766b virtio-mem: Paravirtualized memory hot(un)plug
This is the very basic/initial version of virtio-mem. An introduction to
virtio-mem can be found in the Linux kernel driver [1]. While it can be
used in the current state for hotplug of a smaller amount of memory, it
will heavily benefit from resizeable memory regions in the future.

Each virtio-mem device manages a memory region (provided via a memory
backend). After requested by the hypervisor ("requested-size"), the
guest can try to plug/unplug blocks of memory within that region, in order
to reach the requested size. Initially, and after a reboot, all memory is
unplugged (except in special cases - reboot during postcopy).

The guest may only try to plug/unplug blocks of memory within the usable
region size. The usable region size is a little bigger than the
requested size, to give the device driver some flexibility. The usable
region size will only grow, except on reboots or when all memory is
requested to get unplugged. The guest can never plug more memory than
requested. Unplugged memory will get zapped/discarded, similar to in a
balloon device.

The block size is variable, however, it is always chosen in a way such that
THP splits are avoided (e.g., 2MB). The state of each block
(plugged/unplugged) is tracked in a bitmap.

As virtio-mem devices (e.g., virtio-mem-pci) will be memory devices, we now
expose "VirtioMEMDeviceInfo" via "query-memory-devices".

--------------------------------------------------------------------------

There are two important follow-up items that are in the works:
1. Resizeable memory regions: Use resizeable allocations/RAM blocks to
   grow/shrink along with the usable region size. This avoids creating
   initially very big VMAs, RAM blocks, and KVM slots.
2. Protection of unplugged memory: Make sure the gust cannot actually
   make use of unplugged memory.

Other follow-up items that are in the works:
1. Exclude unplugged memory during migration (via precopy notifier).
2. Handle remapping of memory.
3. Support for other architectures.

--------------------------------------------------------------------------

Example usage (virtio-mem-pci is introduced in follow-up patches):

Start QEMU with two virtio-mem devices (one per NUMA node):
 $ qemu-system-x86_64 -m 4G,maxmem=20G \
  -smp sockets=2,cores=2 \
  -numa node,nodeid=0,cpus=0-1 -numa node,nodeid=1,cpus=2-3 \
  [...]
  -object memory-backend-ram,id=mem0,size=8G \
  -device virtio-mem-pci,id=vm0,memdev=mem0,node=0,requested-size=0M \
  -object memory-backend-ram,id=mem1,size=8G \
  -device virtio-mem-pci,id=vm1,memdev=mem1,node=1,requested-size=1G

Query the configuration:
 (qemu) info memory-devices
 Memory device [virtio-mem]: "vm0"
   memaddr: 0x140000000
   node: 0
   requested-size: 0
   size: 0
   max-size: 8589934592
   block-size: 2097152
   memdev: /objects/mem0
 Memory device [virtio-mem]: "vm1"
   memaddr: 0x340000000
   node: 1
   requested-size: 1073741824
   size: 1073741824
   max-size: 8589934592
   block-size: 2097152
   memdev: /objects/mem1

Add some memory to node 0:
 (qemu) qom-set vm0 requested-size 500M

Remove some memory from node 1:
 (qemu) qom-set vm1 requested-size 200M

Query the configuration again:
 (qemu) info memory-devices
 Memory device [virtio-mem]: "vm0"
   memaddr: 0x140000000
   node: 0
   requested-size: 524288000
   size: 524288000
   max-size: 8589934592
   block-size: 2097152
   memdev: /objects/mem0
 Memory device [virtio-mem]: "vm1"
   memaddr: 0x340000000
   node: 1
   requested-size: 209715200
   size: 209715200
   max-size: 8589934592
   block-size: 2097152
   memdev: /objects/mem1

[1] https://lkml.kernel.org/r/20200311171422.10484-1-david@redhat.com

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20200626072248.78761-11-david@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2020-07-03 07:57:04 -04:00
..
vhost-backend.h vhost-user: add vhost_user_gpu_set_socket() 2019-05-29 06:29:07 +02:00
vhost-scsi-common.h Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
vhost-scsi.h Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
vhost-user-blk.h fix vhost_user_blk_watch crash 2020-03-29 09:52:13 -04:00
vhost-user-fs.h vhost-user-fs: convert to the new virtio_delete_queue function 2020-02-25 08:32:45 -05:00
vhost-user-scsi.h Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
vhost-user-vsock.h virtio: add vhost-user-vsock base device 2020-06-12 10:17:06 -04:00
vhost-user.h Add VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS 2020-06-12 10:17:06 -04:00
vhost-vsock-common.h vhost-vsock: add vhost-vsock-common abstraction 2020-06-12 10:17:06 -04:00
vhost-vsock.h vhost-vsock: add vhost-vsock-common abstraction 2020-06-12 10:17:06 -04:00
vhost.h Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
virtio-access.h include: Make headers more self-contained 2019-08-16 13:31:51 +02:00
virtio-balloon.h virtio-balloon: Provide an interface for free page reporting 2020-06-09 14:18:04 -04:00
virtio-blk.h virtio-blk: On restart, process queued requests in the proper context 2020-06-17 14:53:39 +02:00
virtio-bus.h Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
virtio-crypto.h Clean up ill-advised or unusual header guards 2019-05-13 08:58:55 +02:00
virtio-gpu-bswap.h include: Make headers more self-contained 2019-08-16 13:31:51 +02:00
virtio-gpu-pci.h hw/display: add vhost-user-vga & gpu-pci 2019-05-29 06:30:45 +02:00
virtio-gpu-pixman.h virtio-gpu: add a pixman helper header 2019-05-29 06:29:07 +02:00
virtio-gpu.h edid: flip the default to enabled 2019-06-13 09:34:50 +02:00
virtio-input.h Add vhost-user-input-pci 2019-05-10 14:52:47 +02:00
virtio-iommu.h misc: Replace zero-length arrays with flexible array member (automatic) 2020-03-16 22:07:42 +01:00
virtio-mem.h virtio-mem: Paravirtualized memory hot(un)plug 2020-07-03 07:57:04 -04:00
virtio-mmio.h hw/virtio: Factorize virtio-mmio headers 2019-10-22 09:38:42 +02:00
virtio-net.h virtio-net: reference implementation of hash report 2020-06-18 21:05:50 +08:00
virtio-pmem.h Include sysemu/hostmem.h less 2019-08-16 13:31:53 +02:00
virtio-rng.h virtio-rng: Keep the default backend out of VirtIORNGConf 2019-09-04 06:32:51 -04:00
virtio-scsi.h virtio: make seg_max virtqueue size dependent 2020-01-06 12:04:43 -05:00
virtio-serial.h Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
virtio.h virtio: don't enable notifications during polling 2020-01-05 07:03:03 -05:00