qemu-e2k/include/hw
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
..
acpi acpi: Some build_tpm2() code reshape 2020-06-24 17:18:28 -04:00
adc include: Make headers more self-contained 2019-08-16 13:31:51 +02:00
arm hw/arm/aspeed: QOM'ify AspeedMachineState 2020-06-26 14:30:28 +01:00
audio isa: Convert uses of isa_create() with Coccinelle 2020-06-15 22:05:28 +02:00
block virtio,acpi,pci: fixes, cleanups. 2020-06-25 16:52:42 +01:00
char hw/char: RX62N serial communication interface (SCI) 2020-06-22 18:37:12 +02:00
core cpu: convert queued work to a QSIMPLEQ 2020-06-16 14:49:05 +01:00
cpu Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
cris sysbus: Convert to sysbus_realize() etc. with Coccinelle 2020-06-15 22:05:28 +02:00
display qom/object: Move Object typedef to 'qemu/typedefs.h' 2020-06-10 12:09:36 -04:00
dma hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
firmware machine: Refactor smp-related call chains to pass MachineState 2019-07-05 17:07:36 -03:00
gpio nrf51: Fix last GPIO CNF address 2020-04-30 11:52:27 +01:00
hyperv hyperv: vmbus: Remove the 2nd IRQ 2020-06-26 09:39:40 -04:00
i2c hw/i2c/core: Add i2c_try_create_slave() and i2c_realize_and_unref() 2020-06-26 14:30:28 +01:00
i386 floppy: move cmos_get_fd_drive_type() from pc 2020-06-24 17:18:28 -04:00
ide hw/ide: Make IDEDMAOps handlers take a const IDEDMA pointer 2020-06-17 14:53:39 +02:00
input adb: add autopoll_blocked variable to block autopoll 2020-06-26 10:13:51 +01:00
intc hw/intc: RX62N interrupt controller (ICUa) 2020-06-22 18:37:12 +02:00
ipack Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
ipmi ipmi: Add support to customize OEM functions 2019-12-17 10:39:47 +11:00
isa isa: isa_create(), isa_try_create() are now unused, drop 2020-06-15 22:05:28 +02:00
kvm Supply missing header guards 2019-06-12 13:20:21 +02:00
lm32 Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
m68k m68k: Add NeXTcube machine 2019-09-07 08:31:51 +02:00
mem hw/acpi/nvdimm: add a helper to augment SRAT generation 2020-06-09 11:17:59 -04:00
mips Include hw/irq.h a lot less 2019-08-16 13:31:52 +02:00
misc hw/misc/pca9552: Model qdev output GPIOs 2020-06-26 14:30:28 +01:00
net net: cadence_gem: Add support for jumbo frames 2020-06-18 21:05:51 +08:00
nubus hw/m68k: add Nubus support 2019-10-28 19:06:47 +01:00
nvram fw_cfg: Migrate ACPI table mr sizes separately 2020-04-13 06:55:54 -04:00
pci pci: pci_create(), pci_create_multifunction() are now unused, drop 2020-06-15 22:05:28 +02:00
pci-bridge Supply missing header guards 2019-06-12 13:20:21 +02:00
pci-host hw/pci-host/q35: Remove unused includes 2020-03-09 15:59:31 +01:00
ppc spapr: Fix typos in comments and macro indentation 2020-06-26 09:22:30 +10:00
rdma {hmp, hw/pvrdma}: Expose device internals via monitor interface 2019-03-16 15:52:44 +02:00
riscv hw/riscv: sifive_u: Add a dummy DDR memory controller device 2020-06-19 08:25:27 -07:00
rtc rtc: add RTC_ISA_BASE 2020-05-04 10:25:02 -04:00
rx hw/rx: Add RX GDB simulator 2020-06-22 18:37:12 +02:00
s390x s390x/css: Refactor the css_queue_crw() routine 2020-06-18 12:13:54 +02:00
scsi qdev: Unrealize must not fail 2020-05-15 07:08:14 +02:00
sd sd: sdhci: Implement basic vendor specific register support 2020-06-16 10:32:29 +01:00
semihosting semihosting: add qemu_semihosting_console_inc for SYS_READC 2020-01-09 11:41:29 +00:00
sh4 hw/sh4: Extract timer definitions to 'hw/timer/tmu012.h' 2020-06-22 18:37:12 +02:00
southbridge hw/ide: Do ide_drive_get() within pci_ide_create_devs() 2020-03-17 12:22:36 -04:00
sparc Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
ssi ssi: ssi_create_slave_no_init() is now unused, drop 2020-06-15 22:05:28 +02:00
timer hw/timer: RX62N compare match timer (CMT) 2020-06-22 18:37:12 +02:00
tricore Include hw/irq.h a lot less 2019-08-16 13:31:52 +02:00
unicore32 hw/unicore32: restrict hw addr defines to source file 2017-12-18 17:07:02 +03:00
usb exec/cpu-common: Move MUSB specific typedefs to 'hw/usb/hcd-musb.h' 2020-06-12 11:20:15 -04:00
vfio vfio: Convert to ram_block_discard_disable() 2020-07-02 05:54:59 -04:00
virtio virtio-mem: Paravirtualized memory hot(un)plug 2020-07-03 07:57:04 -04:00
watchdog hw/watchdog: Implement full i.MX watchdog support 2020-05-21 20:00:18 +01:00
xen accel: Move Xen accelerator code under accel/xen/ 2020-06-10 12:09:56 -04:00
xtensa Include hw/irq.h a lot less 2019-08-16 13:31:52 +02:00
boards.h hw: add compat machines for 5.1 2020-05-06 10:12:16 -04:00
clock.h hw/core/clock-vmstate: define a vmstate entry for clock state 2020-04-30 15:35:40 +01:00
elf_ops.h hw/elf_ops: Do not ignore write failures when loading ELF 2020-06-10 12:10:23 -04:00
fw-path-provider.h Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
hotplug.h qom: make interface types abstract 2018-12-11 15:45:22 -02:00
hw.h Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
ide.h hw/ide: Move MAX_IDE_DEVS define to hw/ide/internal.h 2020-03-17 12:22:36 -04:00
irq.h Revert "irq: introduce qemu_irq_proxy()" 2019-11-05 23:33:12 +01:00
loader-fit.h Use #include "..." for our own headers, <...> for others 2018-02-09 05:05:11 +01:00
loader.h hw/core/loader: Let load_elf() populate a field with CPU-specific flags 2020-01-29 19:28:52 +01:00
nmi.h hw/nmi: Fix the NMI() macro, based on INTERFACE_CHECK() 2020-02-28 14:57:19 -05:00
or-irq.h hw/core/or-irq: Increase limit of or-lines to 48 2020-01-23 16:34:15 +00:00
pcmcia.h Include hw/qdev-properties.h less 2019-08-16 13:31:53 +02:00
platform-bus.h platform-bus-device: use device plug callback instead of machine_done notifier 2018-05-10 18:10:56 +01:00
ptimer.h ptimer: Remove old ptimer_init_with_bh() API 2019-11-11 13:44:16 +00:00
qdev-clock.h qdev-clock: introduce an init array to ease the device construction 2020-04-30 15:35:40 +01:00
qdev-core.h qdev: qdev_init_nofail() is now unused, drop 2020-06-15 22:06:04 +02:00
qdev-dma.h Supply missing header guards 2019-06-12 13:20:21 +02:00
qdev-properties.h qdev: Make qdev_prop_set_drive() match the other helpers 2020-06-23 16:07:07 +02:00
register.h hw/core/register: Add register_init_block8 helper. 2020-05-05 13:37:51 -07:00
registerfields.h hw/registerfields: Prefix local variables with underscore in macros 2020-05-27 11:23:07 -07:00
resettable.h hw/core: deprecate old reset functions and introduce new ones 2020-01-30 16:02:04 +00:00
stream.h hw/core: stream: Add an end-of-packet flag 2020-05-14 13:44:35 +02:00
sysbus.h sysbus: sysbus_init_child_obj() is now unused, drop 2020-06-15 22:06:04 +02:00
usb.h usb: usb_create() is now unused, drop 2020-06-15 22:05:28 +02:00
vmstate-if.h vmstate: add qom interface to get id 2020-01-06 18:41:32 +04:00