Hyper-V Dynamic Memory Protocol driver (hv-balloon 🎈️)
v6 cover Hyper-V Dynamic Memory Protocol driver (hv-balloon 🎈️)
From: "Maciej S. Szmigiero" <[email protected]>
This is a continuation of the v5 of the patch series located here:
https://lore.kernel.org/qemu-devel/[email protected]/
Changes from v5:
* Incorporate David's rework of the driver on top of his virtio-mem-memslots patches (specifically, commit 6769107d1a4f), making use of a memory region container created upfront to avoid calling memory_device{,_pre}_plug() functions from the driver and introducing a driver-specific MemoryDeviceInfo sub-type.
* Include two additional David's memory-device patches necessary for the aforementioned conversion in this patch set.
* Use multiple memslots to cover the hot-add memory backend in order to reduce metadata size for the not-yet-hot-added part of the memory backend.
* Add David's "Co-developed-by:" to patches where he contributed some changes.
* Use OBJECT_DEFINE_TYPE_WITH_INTERFACES() and OBJECT_DECLARE_SIMPLE_TYPE() macros instead of open-coding the equivalent functionality.
* Drop no longer necessary patch adding g_autoptr() cleanup function for the Error type.
David Hildenbrand (2):
memory-device: Support empty memory devices
memory-device: Drop size alignment check
Maciej S. Szmigiero (4):
Add Hyper-V Dynamic Memory Protocol definitions
qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
qapi: Add HV_BALLOON_STATUS_REPORT event
Add a Hyper-V Dynamic Memory Protocol driver (hv-balloon)
Kconfig.host | 3 + hw/core/machine-hmp-cmds.c | 15 + hw/hyperv/Kconfig | 5 + hw/hyperv/hv-balloon.c | 2246 ++++++++++++++++++++++++++++++ hw/hyperv/meson.build | 1 + hw/hyperv/trace-events | 18 + hw/i386/pc.c | 22 + hw/mem/memory-device.c | 45 +- include/hw/hyperv/dynmem-proto.h | 423 ++++++ include/hw/hyperv/hv-balloon.h | 18 + include/hw/mem/memory-device.h | 7 +- meson.build | 28 +- meson_options.txt | 2 + qapi/machine.json | 64 +- scripts/meson-buildoptions.sh | 3 + 15 files changed, 2888 insertions(+), 12 deletions(-) create mode 100644 hw/hyperv/hv-balloon.c create mode 100644 include/hw/hyperv/dynmem-proto.h create mode 100644 include/hw/hyperv/hv-balloon.h
PATCH v6 1/6 memory-device: Support empty memory devices
From: David Hildenbrand <[email protected]>
Let's support empty memory devices -- memory devices that don't have a memory device region in the current configuration. hv-balloon with an optional memdev is the primary use case.
--- hw/mem/memory-device.c | 39 ++++++++++++++++++++++++++++++++-- include/hw/mem/memory-device.h | 7 +++++- 2 files changed, 43 insertions(+), 3 deletions(-)
hw/mem/memory-device.c +37 -2
@@ -45,6 +45,22 @@*/ #define MEMORY_DEVICES_MEMSLOT_SOFT_LIMIT 256 +static bool memory_device_is_empty (const MemoryDeviceState *md) +{ +const MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (md); +Error *local_err =NULL ; +MemoryRegion *mr; + +/* dropping const here is fine as we don't touch the memory region */ + mr = mdc->get_memory_region ((MemoryDeviceState *)md, &local_err); +if (local_err) { +/* Not empty, we'll report errors later when ontaining the MR again. */ +error_free (local_err); +return false; + } +return !mr; +} +static gint memory_device_addr_sort (gconstpointer a,gconstpointer b) {const MemoryDeviceState *md_a =MEMORY_DEVICE (a);
@@ -321,6 +337,10 @@ static uint64_t memory_device_get_free_addr(MachineState *ms,uint64_t next_addr;Range tmp; +if (memory_device_is_empty (md)) { +continue ; + } +range_init_nofail (&tmp, mdc->get_addr (md),memory_device_get_region_size (md, &error_abort));
@@ -364,6 +384,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void)const MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (item->data);MemoryDeviceInfo *info =g_new0 (MemoryDeviceInfo,1 ); +/* Let's query infotmation even for empty memory devices. */ mdc->fill_device_info (md, info);QAPI_LIST_APPEND (tail, info);
@@ -383,7 +404,7 @@ static int memory_device_plugged_size(Object *obj, void *opaque)const MemoryDeviceState *md =MEMORY_DEVICE (obj);const MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (obj); -if (dev->realized) { +if (dev->realized && !memory_device_is_empty (md)) { *size += mdc->get_plugged_size (md, &error_abort); } }
@@ -409,6 +430,11 @@ void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,uint64_t addr, align =0 ;MemoryRegion *mr; +/* We support empty memory devices even without device memory. */ +if (memory_device_is_empty (md)) { +return ; + } +if (!ms->device_memory) {error_setg (errp,"the configuration is not prepared for memory devices" " (e.g., for memory hotplug), consider specifying the"
@@ -452,9 +478,14 @@ out:void memory_device_plug (MemoryDeviceState *md,MachineState *ms) {const MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (md); -const uint64_t addr = mdc->get_addr (md); +uint64_t addr;MemoryRegion *mr; +if (memory_device_is_empty (md)) { +return ; + } + addr = mdc->get_addr (md); +/* * We expect that a previous call to memory_device_pre_plug() succeeded, so * it can't fail at this point.
@@ -475,6 +506,10 @@ void memory_device_unplug(MemoryDeviceState *md, MachineState *ms)const MemoryDeviceClass *mdc =MEMORY_DEVICE_GET_CLASS (md);MemoryRegion *mr; +if (memory_device_is_empty (md)) { +return ; + } +/* * We expect that a previous call to memory_device_pre_plug() succeeded, so * it can't fail at this point.
include/hw/mem/memory-device.h +6 -1
@@ -38,6 +38,10 @@ typedef struct MemoryDeviceState MemoryDeviceState;* address in guest physical memory can either be specified explicitly * or get assigned automatically. * +* Some memory device might not own a memory region in certain device +* configurations. Such devices can logically get (un)plugged, however, +* empty memory devices are mostly ignored by the memory device code. +* * Conceptually, memory devices only span one memory region. If multiple * successive memory regions are used, a covering memory region has to * be provided. Scattered memory regions are not supported for single
@@ -91,7 +95,8 @@ struct MemoryDeviceClass {uint64_t (*get_plugged_size)(const MemoryDeviceState *md,Error **errp);/* -* Return the memory region of the memory device. +* Return the memory region of the memory device. If the device is +* completely empty, returns NULL without an error. * * Called when (un)plugging the memory device, to (un)map the * memory region in guest physical memory, but also to detect the
PATCH v6 2/6 memory-device: Drop size alignment check
In reply to Maciej S. SzmigieroFrom: David Hildenbrand <[email protected]>
There is no strong requirement that the size has to be multiples of the requested alignment, let's drop it. This is a preparation for hv-baloon.
--- hw/mem/memory-device.c | 6 ------ 1 file changed, 6 deletions(-)
hw/mem/memory-device.c +0 -6
@@ -308,12 +308,6 @@ static uint64_t memory_device_get_free_addr(MachineState *ms,return 0 ; } -if (!QEMU_IS_ALIGNED (size, align)) { -error_setg (errp,"backend memory size must be multiple of 0x%" - PRIx64, align); -return 0 ; - } -if (hint) {if (range_init (&new, *hint, size) || !range_contains_range (&as, &new)) { error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" PRIx64
PATCH v6 3/6 Add Hyper-V Dynamic Memory Protocol definitions
In reply to Maciej S. SzmigieroFrom: "Maciej S. Szmigiero" <[email protected]>
This commit adds Hyper-V Dynamic Memory Protocol definitions, taken from hv_balloon Linux kernel driver, adapted to the QEMU coding style and definitions.
--- include/hw/hyperv/dynmem-proto.h | 423 +++++++++++++++++++++++++++++++ 1 file changed, 423 insertions(+) create mode 100644 include/hw/hyperv/dynmem-proto.h
include/hw/hyperv/dynmem-proto.h new file +423 -0
@@ -0,0 +1,423 @@ +#ifndef HW_HYPERV_DYNMEM_PROTO_H +#define HW_HYPERV_DYNMEM_PROTO_H + +/* +* Hyper-V Dynamic Memory Protocol definitions +* +* Copyright (C) 2020-2023 Oracle and/or its affiliates. +* +* Based on drivers/hv/hv_balloon.c from Linux kernel: +* Copyright (c) 2012, Microsoft Corporation. +* +* Author: K. Y. Srinivasan <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. +* See the COPYING file in the top-level directory. +*/ + +/* +* Protocol versions. The low word is the minor version, the high word the major +* version. +* +* History: +* Initial version 1.0 +* Changed to 0.1 on 2009/03/25 +* Changes to 0.2 on 2009/05/14 +* Changes to 0.3 on 2009/12/03 +* Changed to 1.0 on 2011/04/05 +* Changed to 2.0 on 2019/12/10 +*/ + +#define DYNMEM_MAKE_VERSION (Major, Minor) ((uint32_t)(((Major) << 16) | (Minor))) +#define DYNMEM_MAJOR_VERSION (Version) ((uint32_t)(Version) >> 16) +#define DYNMEM_MINOR_VERSION (Version) ((uint32_t)(Version) & 0xff) + +enum { +DYNMEM_PROTOCOL_VERSION_1 =DYNMEM_MAKE_VERSION (0 ,3 ), +DYNMEM_PROTOCOL_VERSION_2 =DYNMEM_MAKE_VERSION (1 ,0 ), +DYNMEM_PROTOCOL_VERSION_3 =DYNMEM_MAKE_VERSION (2 ,0 ), + +DYNMEM_PROTOCOL_VERSION_WIN7 =DYNMEM_PROTOCOL_VERSION_1 , +DYNMEM_PROTOCOL_VERSION_WIN8 =DYNMEM_PROTOCOL_VERSION_2 , +DYNMEM_PROTOCOL_VERSION_WIN10 =DYNMEM_PROTOCOL_VERSION_3 , + +DYNMEM_PROTOCOL_VERSION_CURRENT =DYNMEM_PROTOCOL_VERSION_WIN10 +}; + + + +/* +* Message Types +*/ + +enum dm_message_type { +/* +* Version 0.3 +*/ +DM_ERROR =0 , +DM_VERSION_REQUEST =1 , +DM_VERSION_RESPONSE =2 , +DM_CAPABILITIES_REPORT =3 , +DM_CAPABILITIES_RESPONSE =4 , +DM_STATUS_REPORT =5 , +DM_BALLOON_REQUEST =6 , +DM_BALLOON_RESPONSE =7 , +DM_UNBALLOON_REQUEST =8 , +DM_UNBALLOON_RESPONSE =9 , +DM_MEM_HOT_ADD_REQUEST =10 , +DM_MEM_HOT_ADD_RESPONSE =11 , +DM_VERSION_03_MAX =11 , +/* +* Version 1.0. +*/ +DM_INFO_MESSAGE =12 , +DM_VERSION_1_MAX =12 , + +/* +* Version 2.0 +*/ +DM_MEM_HOT_REMOVE_REQUEST =13 , +DM_MEM_HOT_REMOVE_RESPONSE =14 +}; + + +/* +* Structures defining the dynamic memory management +* protocol. +*/ + +union dm_version { +struct { +uint16_t minor_version; +uint16_t major_version; + }; +uint32_t version; +}QEMU_PACKED ; + + +union dm_caps { +struct { +uint64_t balloon:1 ; +uint64_t hot_add:1 ; +/* +* To support guests that may have alignment +* limitations on hot-add, the guest can specify +* its alignment requirements; a value of n +* represents an alignment of 2^n in mega bytes. +*/ +uint64_t hot_add_alignment:4 ; +uint64_t hot_remove:1 ; +uint64_t reservedz:57 ; + } cap_bits; +uint64_t caps; +}QEMU_PACKED ; + +union dm_mem_page_range { +struct { +/* +* The PFN number of the first page in the range. +* 40 bits is the architectural limit of a PFN +* number for AMD64. +*/ +uint64_t start_page:40 ; +/* +* The number of pages in the range. +*/ +uint64_t page_cnt:24 ; + } finfo; +uint64_t page_range; +}QEMU_PACKED ; + + + +/* +* The header for all dynamic memory messages: +* +* type: Type of the message. +* size: Size of the message in bytes; including the header. +* trans_id: The guest is responsible for manufacturing this ID. +*/ + +struct dm_header { +uint16_t type; +uint16_t size; +uint32_t trans_id; +}QEMU_PACKED ; + +/* +* A generic message format for dynamic memory. +* Specific message formats are defined later in the file. +*/ + +struct dm_message { +struct dm_header hdr; +uint8_t data[];/* enclosed message */ +}QEMU_PACKED ; + + +/* +* Specific message types supporting the dynamic memory protocol. +*/ + +/* +* Version negotiation message. Sent from the guest to the host. +* The guest is free to try different versions until the host +* accepts the version. +* +* dm_version: The protocol version requested. +* is_last_attempt: If TRUE, this is the last version guest will request. +* reservedz: Reserved field, set to zero. +*/ + +struct dm_version_request { +struct dm_header hdr; +union dm_version version; +uint32_t is_last_attempt:1 ; +uint32_t reservedz:31 ; +}QEMU_PACKED ; + +/* +* Version response message; Host to Guest and indicates +* if the host has accepted the version sent by the guest. +* +* is_accepted: If TRUE, host has accepted the version and the guest +* should proceed to the next stage of the protocol. FALSE indicates that +* guest should re-try with a different version. +* +* reservedz: Reserved field, set to zero. +*/ + +struct dm_version_response { +struct dm_header hdr; +uint64_t is_accepted:1 ; +uint64_t reservedz:63 ; +}QEMU_PACKED ; + +/* +* Message reporting capabilities. This is sent from the guest to the +* host. +*/ + +struct dm_capabilities { +struct dm_header hdr; +union dm_caps caps; +uint64_t min_page_cnt; +uint64_t max_page_number; +}QEMU_PACKED ; + +/* +* Response to the capabilities message. This is sent from the host to the +* guest. This message notifies if the host has accepted the guest's +* capabilities. If the host has not accepted, the guest must shutdown +* the service. +* +* is_accepted: Indicates if the host has accepted guest's capabilities. +* reservedz: Must be 0. +*/ + +struct dm_capabilities_resp_msg { +struct dm_header hdr; +uint64_t is_accepted:1 ; +uint64_t hot_remove:1 ; +uint64_t suppress_pressure_reports:1 ; +uint64_t reservedz:61 ; +}QEMU_PACKED ; + +/* +* This message is used to report memory pressure from the guest. +* This message is not part of any transaction and there is no +* response to this message. +* +* num_avail: Available memory in pages. +* num_committed: Committed memory in pages. +* page_file_size: The accumulated size of all page files +* in the system in pages. +* zero_free: The nunber of zero and free pages. +* page_file_writes: The writes to the page file in pages. +* io_diff: An indicator of file cache efficiency or page file activity, +* calculated as File Cache Page Fault Count - Page Read Count. +* This value is in pages. +* +* Some of these metrics are Windows specific and fortunately +* the algorithm on the host side that computes the guest memory +* pressure only uses num_committed value. +*/ + +struct dm_status { +struct dm_header hdr; +uint64_t num_avail; +uint64_t num_committed; +uint64_t page_file_size; +uint64_t zero_free; +uint32_t page_file_writes; +uint32_t io_diff; +}QEMU_PACKED ; + + +/* +* Message to ask the guest to allocate memory - balloon up message. +* This message is sent from the host to the guest. The guest may not be +* able to allocate as much memory as requested. +* +* num_pages: number of pages to allocate. +*/ + +struct dm_balloon { +struct dm_header hdr; +uint32_t num_pages; +uint32_t reservedz; +}QEMU_PACKED ; + + +/* +* Balloon response message; this message is sent from the guest +* to the host in response to the balloon message. +* +* reservedz: Reserved; must be set to zero. +* more_pages: If FALSE, this is the last message of the transaction. +* if TRUE there will atleast one more message from the guest. +* +* range_count: The number of ranges in the range array. +* +* range_array: An array of page ranges returned to the host. +* +*/ + +struct dm_balloon_response { +struct dm_header hdr; +uint32_t reservedz; +uint32_t more_pages:1 ; +uint32_t range_count:31 ; +union dm_mem_page_range range_array[]; +}QEMU_PACKED ; + +/* +* Un-balloon message; this message is sent from the host +* to the guest to give guest more memory. +* +* more_pages: If FALSE, this is the last message of the transaction. +* if TRUE there will atleast one more message from the guest. +* +* reservedz: Reserved; must be set to zero. +* +* range_count: The number of ranges in the range array. +* +* range_array: An array of page ranges returned to the host. +* +*/ + +struct dm_unballoon_request { +struct dm_header hdr; +uint32_t more_pages:1 ; +uint32_t reservedz:31 ; +uint32_t range_count; +union dm_mem_page_range range_array[]; +}QEMU_PACKED ; + +/* +* Un-balloon response message; this message is sent from the guest +* to the host in response to an unballoon request. +* +*/ + +struct dm_unballoon_response { +struct dm_header hdr; +}QEMU_PACKED ; + + +/* +* Hot add request message. Message sent from the host to the guest. +* +* mem_range: Memory range to hot add. +* +*/ + +struct dm_hot_add { +struct dm_header hdr; +union dm_mem_page_range range; +}QEMU_PACKED ; + +/* +* Hot add response message. +* This message is sent by the guest to report the status of a hot add request. +* If page_count is less than the requested page count, then the host should +* assume all further hot add requests will fail, since this indicates that +* the guest has hit an upper physical memory barrier. +* +* Hot adds may also fail due to low resources; in this case, the guest must +* not complete this message until the hot add can succeed, and the host must +* not send a new hot add request until the response is sent. +* If VSC fails to hot add memory DYNMEM_NUMBER_OF_UNSUCCESSFUL_HOTADD_ATTEMPTS +* times it fails the request. +* +* +* page_count: number of pages that were successfully hot added. +* +* result: result of the operation 1: success, 0: failure. +* +*/ + +struct dm_hot_add_response { +struct dm_header hdr; +uint32_t page_count; +uint32_t result; +}QEMU_PACKED ; + +struct dm_hot_remove { +struct dm_header hdr; +uint32_t virtual_node; +uint32_t page_count; +uint32_t qos_flags; +uint32_t reservedZ; +}QEMU_PACKED ; + +struct dm_hot_remove_response { +struct dm_header hdr; +uint32_t result; +uint32_t range_count; +uint64_t more_pages:1 ; +uint64_t reservedz:63 ; +union dm_mem_page_range range_array[]; +}QEMU_PACKED ; + +#define DM_REMOVE_QOS_LARGE (1 << 0) +#define DM_REMOVE_QOS_LOCAL (1 << 1) +#define DM_REMOVE_QOS_MASK (0x3) + +/* +* Types of information sent from host to the guest. +*/ + +enum dm_info_type { +INFO_TYPE_MAX_PAGE_CNT =0 , +MAX_INFO_TYPE +}; + + +/* +* Header for the information message. +*/ + +struct dm_info_header { +enum dm_info_type type; +uint32_t data_size; +uint8_t data[]; +}QEMU_PACKED ; + +/* +* This message is sent from the host to the guest to pass +* some relevant information (win8 addition). +* +* reserved: no used. +* info_size: size of the information blob. +* info: information blob. +*/ + +struct dm_info_msg { +struct dm_header hdr; +uint32_t reserved; +uint32_t info_size; +uint8_t info[]; +}; + +#endif
PATCH v6 4/6 qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
In reply to Maciej S. SzmigieroFrom: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver to report its provided memory state information.
--- hw/core/machine-hmp-cmds.c | 15 +++++++++++++++ qapi/machine.json | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)
hw/core/machine-hmp-cmds.c +15 -0
@@ -247,6 +247,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)MemoryDeviceInfo *value;PCDIMMDeviceInfo *di;SgxEPCDeviceInfo *se; +HvBalloonDeviceInfo *hi;for (info = info_list; info; info = info->next) { value = info->value;
@@ -304,6 +305,20 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ; +case MEMORY_DEVICE_INFO_KIND_HV_BALLOON : + hi = value->u.hv_balloon.data; +monitor_printf (mon,"Memory device [%s]: \"%s\"\n" , +MemoryDeviceInfoKind_str (value->type), + hi->id ? hi->id :"" ); +if (hi->has_memaddr) { +monitor_printf (mon," memaddr: 0x%" PRIx64"\n" , + hi->memaddr); + } +monitor_printf (mon," max-size: %" PRIu64"\n" , hi->max_size); +if (hi->memdev) { +monitor_printf (mon," memdev: %s\n" , hi->memdev); + } +break ;default :g_assert_not_reached (); }
qapi/machine.json +37 -2
@@ -1265,6 +1265,29 @@ } } +## +# @HvBalloonDeviceInfo: +# +# hv-balloon provided memory state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @max-size: the maximum size of memory that the device can provide +# +# @memdev: memory backend linked with device +# +# Since: TBD +## +{ 'struct': 'HvBalloonDeviceInfo', + 'data': { '*id': 'str', + '*memaddr': 'size', + 'max-size': 'size', + '*memdev': 'str' + } +} + ## # @MemoryDeviceInfoKind: #
@@ -1276,10 +1299,13 @@ # # @sgx-epc: since 6.2. # +# @hv-balloon: since TBD. +# # Since: 2.1 ## { 'enum': 'MemoryDeviceInfoKind', - 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc' ] } + 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc', + 'hv-balloon' ] } ## # @PCDIMMDeviceInfoWrapper:
@@ -1313,6 +1339,14 @@ { 'struct': 'SgxEPCDeviceInfoWrapper', 'data': { 'data': 'SgxEPCDeviceInfo' } } +## +# @HvBalloonDeviceInfoWrapper: +# +# Since: TBD +## +{ 'struct': 'HvBalloonDeviceInfoWrapper', + 'data': { 'data': 'HvBalloonDeviceInfo' } } + ## # @MemoryDeviceInfo: #
@@ -1327,7 +1361,8 @@ 'nvdimm': 'PCDIMMDeviceInfoWrapper', 'virtio-pmem': 'VirtioPMEMDeviceInfoWrapper', 'virtio-mem': 'VirtioMEMDeviceInfoWrapper', - 'sgx-epc': 'SgxEPCDeviceInfoWrapper' + 'sgx-epc': 'SgxEPCDeviceInfoWrapper', + 'hv-balloon': 'HvBalloonDeviceInfoWrapper' } }
Re: [PATCH v6 4/6] qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
Quoted 25 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver to report its provided memory state information.
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by Maciej S. Szmigiero <[email protected]>--- hw/core/machine-hmp-cmds.c | 15 +++++++++++++++ qapi/machine.json | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)hw/core/machine-hmp-cmds.c +1
-0@@ -247,6 +247,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)MemoryDeviceInfo *value;PCDIMMDeviceInfo *di;SgxEPCDeviceInfo *se; +HvBalloonDeviceInfo *hi;for (info = info_list; info; info = info->next) { value = info->value;
hw/core/machine-hmp-cmds.c void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) · line 308
Quoted 4 lines
hw/core/machine-hmp-cmds.c +1
-0@@ -304,6 +305,20 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ; +case MEMORY_DEVICE_INFO_KIND_HV_BALLOON :
This is the only occurence of MEMORY_DEVICE_INFO_KIND_HV_BALLOON at the end of the series. Where are MemoryDeviceInfo with this union tag created?
Quoted 16 lines
hw/core/machine-hmp-cmds.c +13
-0+ hi = value->u.hv_balloon.data; +monitor_printf (mon,"Memory device [%s]: \"%s\"\n" , +MemoryDeviceInfoKind_str (value->type), + hi->id ? hi->id :"" ); +if (hi->has_memaddr) { +monitor_printf (mon," memaddr: 0x%" PRIx64"\n" , + hi->memaddr); + } +monitor_printf (mon," max-size: %" PRIu64"\n" , hi->max_size); +if (hi->memdev) { +monitor_printf (mon," memdev: %s\n" , hi->memdev); + } +break ;default :g_assert_not_reached (); }
[...]
Re: [PATCH v6 4/6] qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver to report its provided memory state information.
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by Maciej S. Szmigiero <[email protected]>--- hw/core/machine-hmp-cmds.c | 15 +++++++++++++++ qapi/machine.json | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)hw/core/machine-hmp-cmds.c +1
-0@@ -247,6 +247,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)MemoryDeviceInfo *value;PCDIMMDeviceInfo *di;SgxEPCDeviceInfo *se; +HvBalloonDeviceInfo *hi;
Quoted 12 lines
hw/core/machine-hmp-cmds.c void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) · line 308
Quoted 7 lines
hw/core/machine-hmp-cmds.c +1
-0for (info = info_list; info; info = info->next) { value = info->value;@@ -304,6 +305,20 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ; +case MEMORY_DEVICE_INFO_KIND_HV_BALLOON :This is the only occurence of
MEMORY_DEVICE_INFO_KIND_HV_BALLOONat the end of the series. Where are MemoryDeviceInfo with this union tag created?
From patch 6:
+static void hv_balloon_md_fill_device_info(const MemoryDeviceState *md,
+ MemoryDeviceInfo *info)
+{
+ HvBalloonDeviceInfo *hi = g_new0(HvBalloonDeviceInfo, 1); + const HvBalloon *balloon = HV_BALLOON(md); + DeviceState *dev = DEVICE(md);
+
+ if (dev->id) {
+ hi->id = g_strdup(dev->id);
+ }
+
+ if (balloon->hostmem) {
+ hi->memdev = object_get_canonical_path(OBJECT(balloon->hostmem)); + hi->memaddr = balloon->addr; + hi->has_memaddr = true; + hi->max_size = memory_region_size(balloon->mr); + /* TODO: expose current provided size or something else? */
+ } else {
+ hi->max_size = 0;
+ }
+
+ info->u.hv_balloon.data = hi;
+ info->type = MEMORY_DEVICE_INFO_KIND_HV_BALLOON;
^ here.
Thanks,
Maciej
Re: [PATCH v6 4/6] qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
Quoted 36 lines · Maciej S. Szmigiero
Quoted 26 lines · Markus Armbruster
Quoted 24 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver to report its provided memory state information.
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by Maciej S. Szmigiero <[email protected]>--- hw/core/machine-hmp-cmds.c | 15 +++++++++++++++ qapi/machine.json | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)hw/core/machine-hmp-cmds.c +1
-0@@ -247,6 +247,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)MemoryDeviceInfo *value;PCDIMMDeviceInfo *di;SgxEPCDeviceInfo *se; +HvBalloonDeviceInfo *hi;for (info = info_list; info; info = info->next) { value = info->value;@@ -304,6 +305,20 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)Quoted 8 lines
hw/core/machine-hmp-cmds.c void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) · line 308
Quoted 4 lines
hw/core/machine-hmp-cmds.c +1
-0monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ; +case MEMORY_DEVICE_INFO_KIND_HV_BALLOON :This is the only occurence of
MEMORY_DEVICE_INFO_KIND_HV_BALLOONat the end of the series. Where are MemoryDeviceInfo with this union tag created?
Quoted 1 line
From patch 6:
[...]
I messed around with git, and managed to confuse myself. Thanks for your help!
Re: [PATCH v6 4/6] qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
In reply to Maciej S. SzmigieroQuoted 57 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver to report its provided memory state information.
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by Maciej S. Szmigiero <[email protected]>--- hw/core/machine-hmp-cmds.c | 15 +++++++++++++++ qapi/machine.json | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)hw/core/machine-hmp-cmds.c +15
-0@@ -247,6 +247,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)MemoryDeviceInfo *value;PCDIMMDeviceInfo *di;SgxEPCDeviceInfo *se; +HvBalloonDeviceInfo *hi;for (info = info_list; info; info = info->next) { value = info->value;@@ -304,6 +305,20 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ; +case MEMORY_DEVICE_INFO_KIND_HV_BALLOON : + hi = value->u.hv_balloon.data; +monitor_printf (mon,"Memory device [%s]: \"%s\"\n" , +MemoryDeviceInfoKind_str (value->type), + hi->id ? hi->id :"" ); +if (hi->has_memaddr) { +monitor_printf (mon," memaddr: 0x%" PRIx64"\n" , + hi->memaddr); + } +monitor_printf (mon," max-size: %" PRIu64"\n" , hi->max_size); +if (hi->memdev) { +monitor_printf (mon," memdev: %s\n" , hi->memdev); + } +break ;default :g_assert_not_reached (); }qapi/machine.json +4
-0@@ -1265,6 +1265,29 @@ } } +## +# @HvBalloonDeviceInfo: +# +# hv-balloon provided memory state information
qapi/machine.json line 1281
Quoted 10 lines
qapi/machine.json +10
-0+# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @max-size: the maximum size of memory that the device can provide +# +# @memdev: memory backend linked with device +# +# Since: TBD
I understand why you put in TBD here (aiming for a moving target is a hassle), but patches not marked RFC should have no known issues that should be fixed before merging them.
Quoted 43 lines
qapi/machine.json +21
-1+## +{ 'struct': 'HvBalloonDeviceInfo', + 'data': { '*id': 'str', + '*memaddr': 'size', + 'max-size': 'size', + '*memdev': 'str' + } +} + ## # @MemoryDeviceInfoKind: #@@ -1276,10 +1299,13 @@ # # @sgx-epc: since 6.2. # +# @hv-balloon: since TBD. +# # Since: 2.1 ## { 'enum': 'MemoryDeviceInfoKind', - 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc' ] } + 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc', + 'hv-balloon' ] } ## # @PCDIMMDeviceInfoWrapper:@@ -1313,6 +1339,14 @@ { 'struct': 'SgxEPCDeviceInfoWrapper', 'data': { 'data': 'SgxEPCDeviceInfo' } } +## +# @HvBalloonDeviceInfoWrapper: +# +# Since: TBD +## +{ 'struct': 'HvBalloonDeviceInfoWrapper', + 'data': { 'data': 'HvBalloonDeviceInfo' } } + ## # @MemoryDeviceInfo: #
qapi/machine.json line 1368
Quoted 9 lines
qapi/machine.json +2
-1@@ -1327,7 +1361,8 @@ 'nvdimm': 'PCDIMMDeviceInfoWrapper', 'virtio-pmem': 'VirtioPMEMDeviceInfoWrapper', 'virtio-mem': 'VirtioMEMDeviceInfoWrapper', - 'sgx-epc': 'SgxEPCDeviceInfoWrapper' + 'sgx-epc': 'SgxEPCDeviceInfoWrapper', + 'hv-balloon': 'HvBalloonDeviceInfoWrapper' } }
The organization of the series feels a bit awkward.
In this patch, you define QAPI types and add a bit of code reading them, but the code creating them is left for later.
In the next patch, you define a QMP event, but the code sending it is left for later.
In the final, huge patch, you fill in the blanks.
Adding definitions before their uses can be the least awkward solution. But then the commit messages should point out that uses come later. Describing these future uses briefly may be necessary to help the reader understand the patch on its own.
Perhaps you can restructure the series instead.
Re: [PATCH v6 4/6] qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
Quoted 65 lines · Markus Armbruster
Quoted 63 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver to report its provided memory state information.
Co-developed-by David Hildenbrand <[email protected]>Signed-off-by Maciej S. Szmigiero <[email protected]>--- hw/core/machine-hmp-cmds.c | 15 +++++++++++++++ qapi/machine.json | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-)hw/core/machine-hmp-cmds.c +15
-0@@ -247,6 +247,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)MemoryDeviceInfo *value;PCDIMMDeviceInfo *di;SgxEPCDeviceInfo *se; +HvBalloonDeviceInfo *hi;for (info = info_list; info; info = info->next) { value = info->value;@@ -304,6 +305,20 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)monitor_printf (mon," node: %" PRId64"\n" , se->node);monitor_printf (mon," memdev: %s\n" , se->memdev);break ; +case MEMORY_DEVICE_INFO_KIND_HV_BALLOON : + hi = value->u.hv_balloon.data; +monitor_printf (mon,"Memory device [%s]: \"%s\"\n" , +MemoryDeviceInfoKind_str (value->type), + hi->id ? hi->id :"" ); +if (hi->has_memaddr) { +monitor_printf (mon," memaddr: 0x%" PRIx64"\n" , + hi->memaddr); + } +monitor_printf (mon," max-size: %" PRIu64"\n" , hi->max_size); +if (hi->memdev) { +monitor_printf (mon," memdev: %s\n" , hi->memdev); + } +break ;default :g_assert_not_reached (); }qapi/machine.json +10
-0@@ -1265,6 +1265,29 @@ } } +## +# @HvBalloonDeviceInfo: +# +# hv-balloon provided memory state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @max-size: the maximum size of memory that the device can provide
Quoted 8 lines
qapi/machine.json line 1281
Quoted 4 lines
qapi/machine.json +4
-0+# +# @memdev: memory backend linked with device +# +# Since: TBDI understand why you put in TBD here (aiming for a moving target is a hassle), but patches not marked RFC should have no known issues that should be fixed before merging them.
Will change TBD to 8.2 then.
Quoted 61 lines
Quoted 43 lines
qapi/machine.json +21
-1+## +{ 'struct': 'HvBalloonDeviceInfo', + 'data': { '*id': 'str', + '*memaddr': 'size', + 'max-size': 'size', + '*memdev': 'str' + } +} + ## # @MemoryDeviceInfoKind: #@@ -1276,10 +1299,13 @@ # # @sgx-epc: since 6.2. # +# @hv-balloon: since TBD. +# # Since: 2.1 ## { 'enum': 'MemoryDeviceInfoKind', - 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc' ] } + 'data': [ 'dimm', 'nvdimm', 'virtio-pmem', 'virtio-mem', 'sgx-epc', + 'hv-balloon' ] } ## # @PCDIMMDeviceInfoWrapper:@@ -1313,6 +1339,14 @@ { 'struct': 'SgxEPCDeviceInfoWrapper', 'data': { 'data': 'SgxEPCDeviceInfo' } } +## +# @HvBalloonDeviceInfoWrapper: +# +# Since: TBD +## +{ 'struct': 'HvBalloonDeviceInfoWrapper', + 'data': { 'data': 'HvBalloonDeviceInfo' } } + ## # @MemoryDeviceInfo: #qapi/machine.json line 1368
Quoted 9 lines
qapi/machine.json +2
-1@@ -1327,7 +1361,8 @@ 'nvdimm': 'PCDIMMDeviceInfoWrapper', 'virtio-pmem': 'VirtioPMEMDeviceInfoWrapper', 'virtio-mem': 'VirtioMEMDeviceInfoWrapper', - 'sgx-epc': 'SgxEPCDeviceInfoWrapper' + 'sgx-epc': 'SgxEPCDeviceInfoWrapper', + 'hv-balloon': 'HvBalloonDeviceInfoWrapper' } }The organization of the series feels a bit awkward.
In this patch, you define QAPI types and add a bit of code reading them, but the code creating them is left for later.
In the next patch, you define a QMP event, but the code sending it is left for later.
Quoted 8 lines
In the final, huge patch, you fill in the blanks.
Adding definitions before their uses can be the least awkward solution. But then the commit messages should point out that uses come later. Describing these future uses briefly may be necessary to help the reader understand the patch on its own.
Perhaps you can restructure the series instead.
Will make use of your suggestion in the other e-mail to refactor it like this:
Quoted 5 lines
0. The driver with QMP stuff omitted / stubbed out
1. Enable query-memory-devices
2. Add
HV_BALLOON_STATUS_REPORTevent
Thanks,
Maciej
PATCH v6 5/6 qapi: Add HV_BALLOON_STATUS_REPORT event
In reply to Maciej S. SzmigieroFrom: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver for (optional) guest memory status reports.
--- qapi/machine.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
qapi/machine.json +25 -0
@@ -1113,6 +1113,31 @@ { 'event': 'BALLOON_CHANGE', 'data': { 'actual': 'int' } } +## +# @HV_BALLOON_STATUS_REPORT: +# +# Emitted when the hv-balloon driver receives a "STATUS" message from +# the guest. +# +# @commited: the amount of memory in use inside the guest plus the amount +# of the memory unusable inside the guest (ballooned out, +# offline, etc.) +# +# @available: the amount of the memory inside the guest available for new +# allocations ("free") +# +# Since: TBD +# +# Example: +# +# <- { "event": "HV_BALLOON_STATUS_REPORT", +# "data": { "commited": 816640000, "available": 3333054464 }, +# "timestamp": { "seconds": 1600295492, "microseconds": 661044 } } +# +## +{ 'event': 'HV_BALLOON_STATUS_REPORT', + 'data': { 'commited': 'size', 'available': 'size' } } + ## # @MemoryInfo: #
Re: [PATCH v6 5/6] qapi: Add HV_BALLOON_STATUS_REPORT event
Quoted 3 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver for (optional) guest memory status reports.
Inhowfar optional? What enables / triggers it?
Use case for the event?
Could a status event make sense for other balloon drivers as well?
Quoted 10 lines
Signed-off-by Maciej S. Szmigiero <[email protected]>--- qapi/machine.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)qapi/machine.json +0
-0
qapi/machine.json line 1120
Quoted 8 lines
qapi/machine.json +5
-0@@ -1113,6 +1113,31 @@ { 'event': 'BALLOON_CHANGE', 'data': { 'actual': 'int' } } +## +# @HV_BALLOON_STATUS_REPORT: +# +# Emitted when the hv-balloon driver receives a "STATUS" message from +# the guest.
Aha, the event is triggered by the guest. It must therefore be rate-limited, just like BALLOON_CHANGE. To do that, add it to monitor_qapi_event_conf[] in monitor/monitor.c, and document it as noted below.
qapi/machine.json line 1127
Quoted 7 lines
qapi/machine.json +7
-0+# +# @commited: the amount of memory in use inside the guest plus the amount +# of the memory unusable inside the guest (ballooned out, +# offline, etc.) +# +# @available: the amount of the memory inside the guest available for new +# allocations ("free")
Spelling: committed. Remember to update the example, too.
Please format like
# @committed: the amount of memory in use inside the guest plus the
# amount of the memory unusable inside the guest (ballooned out,
# offline, etc.)
#
# @available: the amount of the memory inside the guest available for
# new allocations ("free")
to blend in with recent commit a937b6aa739 (qapi: Reformat doc comments to conform to current conventions).
qapi/machine.json line 1128
Quoted 1 line
qapi/machine.json +1
-0+#
To document rate-limiting, add:
# Note: this event is rate-limited.
#
Quoted 5 lines
qapi/machine.json +5
-0+# Since: TBD +# +# Example: +# +# <- { "event": "HV_BALLOON_STATUS_REPORT",
qapi/machine.json line 1143
Quoted 10 lines
qapi/machine.json +7
-0+# "data": { "commited": 816640000, "available": 3333054464 }, +# "timestamp": { "seconds": 1600295492, "microseconds": 661044 } } +# +## +{ 'event': 'HV_BALLOON_STATUS_REPORT', + 'data': { 'commited': 'size', 'available': 'size' } } + ## # @MemoryInfo: #
An event is commonly paired with a query command, so that QMP clients can resynchronize state after missing events, e.g. when reconnecting after a client restart.
query-balloon isn't such a query: it returns less than the event.
If a paired query doesn't make sense, explain why.
Re: [PATCH v6 5/6] qapi: Add HV_BALLOON_STATUS_REPORT event
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
Used by the hv-balloon driver for (optional) guest memory status reports.
Inhowfar optional? What enables / triggers it?
They are enabled by "status-report=on" device property, hence they don't need to be enabled if unwanted.
As you have written below, each status report is generated by the guest sending a DM_STATUS_REPORT message (which guests do periodically).
Quoted 2 lines
Use case for the event?
To monitor memory state in the guest, for example for some QEMU auto-ballooning controller.
Quoted 1 line
Could a status event make sense for other balloon drivers as well?
virtio-balloon has some guest memory stats support, too, but with important differences, because in virtio-balloon:
1) Stats retrieval is driven by the QEMU process (essentially polling the guest),
2) There's no notification mechanism for QEMU controller to know that new stats have arrived from the guest,
3) The list of available individual stats is not constant, rather it's an array of (TAG, VALUE) pairs.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Maciej S. Szmigiero <[email protected]>--- qapi/machine.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)qapi/machine.json +0
-0@@ -1113,6 +1113,31 @@ { 'event': 'BALLOON_CHANGE', 'data': { 'actual': 'int' } }
Quoted 10 lines
qapi/machine.json line 1120
Quoted 5 lines
qapi/machine.json +5
-0+## +# @HV_BALLOON_STATUS_REPORT: +# +# Emitted when the hv-balloon driver receives a "STATUS" message from +# the guest.Aha, the event is triggered by the guest. It must therefore be rate-limited, just like
BALLOON_CHANGE. To do that, add it to monitor_qapi_event_conf[] inmonitor/monitor.c, and document it as noted below.
Ack.
Quoted 9 lines
qapi/machine.json line 1127
Quoted 7 lines
qapi/machine.json +7
-0+# +# @commited: the amount of memory in use inside the guest plus the amount +# of the memory unusable inside the guest (ballooned out, +# offline, etc.) +# +# @available: the amount of the memory inside the guest available for new +# allocations ("free")Spelling: committed. Remember to update the example, too.
Ack.
Quoted 11 lines
Please format like
# @committed: the amount of memory in use inside the guest plus the
# amount of the memory unusable inside the guest (ballooned out,
# offline, etc.)
#
# @available: the amount of the memory inside the guest available for
# new allocations ("free")to blend in with recent commit
a937b6aa739(qapi: Reformat doc comments to conform to current conventions).
Ack.
Quoted 6 lines
qapi/machine.json line 1128
Quoted 1 line
qapi/machine.json +1
-0+#To document rate-limiting, add:
# Note: this event is rate-limited.
#
Ack.
Quoted 20 lines
Quoted 5 lines
qapi/machine.json +5
-0+# Since: TBD +# +# Example: +# +# <- { "event": "HV_BALLOON_STATUS_REPORT",qapi/machine.json line 1143
Quoted 10 lines
qapi/machine.json +7
-0+# "data": { "commited": 816640000, "available": 3333054464 }, +# "timestamp": { "seconds": 1600295492, "microseconds": 661044 } } +# +## +{ 'event': 'HV_BALLOON_STATUS_REPORT', + 'data': { 'commited': 'size', 'available': 'size' } } + ## # @MemoryInfo: #An event is commonly paired with a query command, so that QMP clients can resynchronize state after missing events, e.g. when reconnecting after a client restart.
Quoted 4 lines
query-balloon isn't such a query: it returns less than the event.
If a paired query doesn't make sense, explain why.
Will add a query command that returns the last STATUS event data.
Thanks,
Maciej
PATCH v6 6/6 Add a Hyper-V Dynamic Memory Protocol driver (hv-balloon)
In reply to Maciej S. SzmigieroFrom: "Maciej S. Szmigiero" <[email protected]>
This driver is like virtio-balloon on steroids: it allows both changing the guest memory allocation via ballooning and inserting pieces of extra RAM into it on demand from a provided memory backend.
One of advantages of these over ACPI-based PC DIMM hotplug is that such memory can be hotplugged in much smaller granularity because the ACPI DIMM slot limit does not apply.
In order to enable hot-adding additional memory a new memory backend needs to be created and provided to the driver via the "memdev" parameter. This can be achieved by, for example, adding
"-object memory-backend-ram,id=mem1,size=32G" to the QEMU command line and then instantiating the driver with "memdev=mem1" parameter.
The device will try to use multiple memslots to cover the memory backend in order to reduce the size of metadata for the not-yet-hot-added part of the memory backend.
In contrast with ACPI DIMM hotplug where one can only request to unplug a whole DIMM stick this driver allows removing memory from guest in single page (4k) units via ballooning.
The actual resizing is done via ballooning interface (for example, via the "balloon" HMP command)
This includes resizing the guest past its boot size - that is, hot-adding additional memory in granularity limited only by the guest alignment requirements.
After a VM reboot the guest is back to its original (boot) size.
In the future, the guest boot memory size might be changed on reboot instead, taking into account the effective size that VM had before that reboot (much like Hyper-V does).
For performance reasons, the guest-released memory is tracked in a few range trees, as a series of (start, count) ranges.
Each time a new page range is inserted into such tree its neighbors are checked as candidates for possible merging with it.
Besides performance reasons, the Dynamic Memory protocol itself uses page ranges as the data structure in its messages, so relevant pages need to be merged into such ranges anyway.
One has to be careful when tracking the guest-released pages, since the guest can maliciously report returning pages outside its current address space, which later clash with the address range of newly added memory. Similarly, the guest can report freeing the same page twice.
The above design results in much better ballooning performance than when using virtio-balloon with the same guest: 230 GB / minute with this driver versus 70 GB / minute with virtio-balloon.
During a ballooning operation most of time is spent waiting for the guest to come up with newly freed page ranges, processing the received ranges on the host side (in QEMU and KVM) is nearly instantaneous.
The unballoon operation is also pretty much instantaneous:
thanks to the merging of the ballooned out page ranges 200 GB of memory can be returned to the guest in about 1 second.
With virtio-balloon this operation takes about 2.5 minutes.
These tests were done against a Windows Server 2019 guest running on a Xeon E5-2699, after dirtying the whole memory inside guest before each balloon operation.
Using a range tree instead of a bitmap to track the removed memory also means that the solution scales well with the guest size: even a 1 TB range takes just a few bytes of such metadata.
Since the required GTree operations aren't present in every Glib version a check for them was added to the meson build script, together with new "--enable-hv-balloon" and "--disable-hv-balloon" configure arguments. If these GTree operations are missing in the system's Glib version this driver will be skipped during QEMU build.
An optional "status-report=on" device parameter requests memory status events from the guest (typically sent every second), which allow the host to learn both the guest memory available and the guest memory in use counts.
They are emitted externally as "HV_BALLOON_STATUS_REPORT" QMP events.
The driver is named hv-balloon since the Linux kernel client driver for the Dynamic Memory Protocol is named as such and to follow the naming pattern established by the virtio-balloon driver.
The whole protocol runs over Hyper-V VMBus.
The driver was tested against Windows Server 2012 R2, Windows Server 2016 and Windows Server 2019 guests and obeys the guest alignment requirements reported to the host via DM_CAPABILITIES_REPORT message.
--- Kconfig.host | 3 + hw/hyperv/Kconfig | 5 + hw/hyperv/hv-balloon.c | 2246 ++++++++++++++++++++++++++++++++ hw/hyperv/meson.build | 1 + hw/hyperv/trace-events | 18 + hw/i386/pc.c | 22 + include/hw/hyperv/hv-balloon.h | 18 + meson.build | 28 +- meson_options.txt | 2 + scripts/meson-buildoptions.sh | 3 + 10 files changed, 2345 insertions(+), 1 deletion(-) create mode 100644 hw/hyperv/hv-balloon.c create mode 100644 include/hw/hyperv/hv-balloon.h
Kconfig.host +3 -0
@@ -46,3 +46,6 @@ config FUZZ config VFIO_USER_SERVER_ALLOWED bool imply VFIO_USER_SERVER + +config HV_BALLOON_POSSIBLE + bool
hw/hyperv/Kconfig +5 -0
@@ -16,3 +16,8 @@ config SYNDBG bool default y depends on VMBUS + +config HV_BALLOON + bool + default y + depends on HV_BALLOON_POSSIBLE && VMBUS
hw/hyperv/hv-balloon.c new file +2246 -0
2,246 lines not on this page · raw message
hw/hyperv/meson.build +1 -0
@@ -2,3 +2,4 @@ specific_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c')) specific_ss.add(when: 'CONFIG_HYPERV_TESTDEV', if_true: files('hyperv_testdev.c')) specific_ss.add(when: 'CONFIG_VMBUS', if_true: files('vmbus.c')) specific_ss.add(when: 'CONFIG_SYNDBG', if_true: files('syndbg.c')) +specific_ss.add(when: 'CONFIG_HV_BALLOON', if_true: files('hv-balloon.c'))
hw/hyperv/trace-events +18 -0
@@ -16,3 +16,21 @@ vmbus_gpadl_torndown(uint32_t gpadl_id) "gpadl #%d" vmbus_open_channel(uint32_t chan_id, uint32_t gpadl_id, uint32_t target_vp) "channel #%d gpadl #%d target vp %d" vmbus_channel_open(uint32_t chan_id, uint32_t status) "channel #%d status %d" vmbus_close_channel(uint32_t chan_id) "channel #%d" + +# hv-balloon +hv_balloon_state_change(const char *tostr) "-> %s" +hv_balloon_incoming_version(uint16_t major, uint16_t minor) "incoming proto version %u.%u" +hv_balloon_incoming_caps(uint32_t caps) "incoming caps 0x%x" +hv_balloon_outgoing_unballoon(uint32_t trans_id, uint64_t count, uint64_t start, uint64_t rempages) "posting unballoon %"PRIu32" for %"PRIu64" @ 0x%"PRIx64", remaining %"PRIu64 +hv_balloon_incoming_unballoon(uint32_t trans_id) "incoming unballoon response %"PRIu32 +hv_balloon_outgoing_hot_add(uint32_t trans_id, uint64_t count, uint64_t start) "posting hot add %"PRIu32" for %"PRIu64" @ 0x%"PRIx64 +hv_balloon_incoming_hot_add(uint32_t trans_id, uint32_t result, uint32_t count) "incoming hot add response %"PRIu32", result %"PRIu32", count %"PRIu32 +hv_balloon_outgoing_balloon(uint32_t trans_id, uint64_t count, uint64_t rempages) "posting balloon %"PRIu32" for %"PRIu64", remaining %"PRIu64 +hv_balloon_incoming_balloon(uint32_t trans_id, uint32_t range_count, uint32_t more_pages) "incoming balloon response %"PRIu32", ranges %"PRIu32", more %"PRIu32 +hv_balloon_our_range_add(uint64_t count, uint64_t start) "adding our range %"PRIu64" @ 0x%"PRIx64 +hv_balloon_remove_response(uint64_t count, uint64_t start, unsigned int both) "processing remove response range %"PRIu64" @ 0x%"PRIx64", both %u" +hv_balloon_remove_response_hole(uint64_t counthole, uint64_t starthole, uint64_t countrange, uint64_t startrange, uint64_t starthpr, unsigned int both) "response range hole %"PRIu64" @ 0x%"PRIx64" from range %"PRIu64" @ 0x%"PRIx64", before our start 0x%"PRIx64", both %u" +hv_balloon_remove_response_common(uint64_t countcommon, uint64_t startcommon, uint64_t countrange, uint64_t startrange, uint64_t counthpr, uint64_t starthpr, uint64_t removed, unsigned int both) "response common range %"PRIu64" @ 0x%"PRIx64" from range %"PRIu64" @ 0x%"PRIx64" with our %"PRIu64" @ 0x%"PRIx64", removed %"PRIu64", both %u" +hv_balloon_remove_response_remainder(uint64_t count, uint64_t start, unsigned int both) "remove response remaining range %"PRIu64" @ 0x%"PRIx64", both %u" +hv_balloon_map_slot(unsigned int idx, unsigned int total_slots, uint64_t offset) "mapping memslot %u / %u @ 0x%"PRIx64 +hv_balloon_unmap_slot(unsigned int idx, unsigned int total_slots, uint64_t offset) "unmapping memslot %u / %u @ 0x%"PRIx64
hw/i386/pc.c +22 -0
@@ -28,6 +28,7 @@#include "hw/i386/pc.h" #include "hw/char/serial.h" #include "hw/char/parallel.h" +#include "hw/hyperv/hv-balloon.h" #include "hw/i386/topology.h" #include "hw/i386/fw_cfg.h" #include "hw/i386/vmport.h"
@@ -93,6 +94,7 @@#include "hw/i386/kvm/xen_evtchn.h" #include "hw/i386/kvm/xen_gnttab.h" #include "hw/i386/kvm/xen_xenstore.h" +#include "hw/mem/memory-device.h" #include "sysemu/replay.h" #include "target/i386/cpu.h" #include "e820_memory_layout.h"
@@ -1491,6 +1493,21 @@ static void pc_memory_unplug(HotplugHandler *hotplug_dev,error_propagate (errp, local_err); } +static void pc_hv_balloon_pre_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +/* The vmbus handler has no hotplug handler; we should never end up here. */ +g_assert (!dev->hotplugged); +memory_device_pre_plug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev),NULL , + errp); +} + +static void pc_hv_balloon_plug (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +memory_device_plug (MEMORY_DEVICE (dev),MACHINE (hotplug_dev)); +} +static void pc_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -1521,6 +1538,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,return ; } pcms->iommu = dev; + }else if (object_dynamic_cast (OBJECT (dev),TYPE_HV_BALLOON )) { +pc_hv_balloon_pre_plug (hotplug_dev, dev, errp); } }
@@ -1533,6 +1552,8 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev,x86_cpu_plug (hotplug_dev, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_MD_PCI )) {virtio_md_pci_plug (VIRTIO_MD_PCI (dev),MACHINE (hotplug_dev), errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_HV_BALLOON )) { +pc_hv_balloon_plug (hotplug_dev, dev, errp); } }
@@ -1574,6 +1595,7 @@ static HotplugHandler *pc_get_hotplug_handler(MachineState *machine, object_dynamic_cast(OBJECT(dev), TYPE_CPU) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI) || object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_HV_BALLOON) || object_dynamic_cast(OBJECT(dev), TYPE_X86_IOMMU_DEVICE)) {return HOTPLUG_HANDLER (machine); }
include/hw/hyperv/hv-balloon.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* QEMU Hyper-V Dynamic Memory Protocol driver +* +* Copyright (C) 2020-2023 Oracle and/or its affiliates. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_HV_BALLOON_H +#define HW_HV_BALLOON_H + +#include "qom/object.h" + +#define TYPE_HV_BALLOON "hv-balloon" +OBJECT_DECLARE_SIMPLE_TYPE(HvBalloon, HV_BALLOON) + +#endif
meson.build +27 -1
@@ -1340,6 +1340,30 @@ if not get_option('glusterfs').auto() or have_block endif endif +hv_balloon = false +if get_option('hv_balloon').allowed() and have_system + if cc.links(''' + #include <string.h> + #include <gmodule.h> + int main(void) { + GTree *tree; + + tree = g_tree_new((GCompareFunc)strcmp); + (void)g_tree_node_first(tree); + g_tree_destroy(tree); + return 0; + } + ''', dependencies: glib) + hv_balloon = true + else + if get_option('hv_balloon').enabled() + error('could not enable hv-balloon, update your glib') + else + warning('could not find glib support for hv-balloon, disabling') + endif + endif +endif + libssh = not_found if not get_option('libssh').auto() or have_block libssh = dependency('libssh', version: '>=0.8.7',
@@ -2844,7 +2868,8 @@ host_kconfig = \ ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ (have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \ (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) + \ - (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) + (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=y'] : []) + \ + (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=y'] : []) ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ]
@@ -4299,6 +4324,7 @@ if targetos == 'windows' endif summary_info += {'seccomp support': seccomp} summary_info += {'GlusterFS support': glusterfs} +summary_info += {'hv-balloon support': hv_balloon} summary_info += {'TPM support': have_tpm} summary_info += {'libssh support': libssh} summary_info += {'lzo support': lzo}
meson_options.txt +2 -0
@@ -142,6 +142,8 @@ option('gio', type : 'feature', value : 'auto', description: 'use libgio for D-Bus support') option('glusterfs', type : 'feature', value : 'auto', description: 'Glusterfs block device driver') +option('hv_balloon', type : 'feature', value : 'auto', + description: 'hv-balloon driver (requires Glib 2.68+ GTree API)') option('libdw', type : 'feature', value : 'auto', description: 'debuginfo support') option('libiscsi', type : 'feature', value : 'auto',
scripts/meson-buildoptions.sh +3 -0
@@ -111,6 +111,7 @@ meson_options_help() { printf "%s\n" ' guest-agent Build QEMU Guest Agent' printf "%s\n" ' guest-agent-msi Build MSI package for the QEMU Guest Agent' printf "%s\n" ' hax HAX acceleration support' + printf "%s\n" ' hv-balloon hv-balloon driver (requires Glib 2.68+ GTree API)' printf "%s\n" ' hvf HVF acceleration support' printf "%s\n" ' iconv Font glyph conversion support' printf "%s\n" ' jack JACK sound support'
@@ -316,6 +317,8 @@ _meson_option_parse() { --disable-hax) printf "%s" -Dhax=disabled ;; --enable-hexagon-idef-parser) printf "%s" -Dhexagon_idef_parser=true ;; --disable-hexagon-idef-parser) printf "%s" -Dhexagon_idef_parser=false ;; + --enable-hv-balloon) printf "%s" -Dhv_balloon=enabled ;; + --disable-hv-balloon) printf "%s" -Dhv_balloon=disabled ;; --enable-hvf) printf "%s" -Dhvf=enabled ;; --disable-hvf) printf "%s" -Dhvf=disabled ;; --iasl=*) quote_sh "-Diasl=$2" ;;
Doesn't apply to master. Care to rebase?
Quoted 2 lines · Markus Armbruster
Doesn't apply to master. Care to rebase?
The series is now based on David's virtio-mem-memslots patches (specifically, commit 6769107d1a4f from [1]) since it depends on support for exposing device memory via multiple memslots provided by that series.
I'm sorry if that wasn't clear from the cover letter.
Thanks,
Maciej
[1]: https://github.com/davidhildenbrand/qemu/tree/virtio-mem-memslots
Quoted 10 lines · Maciej S. Szmigiero
Quoted 2 lines · Markus Armbruster
Doesn't apply to master. Care to rebase?
The series is now based on David's virtio-mem-memslots patches (specifically, commit
6769107d1a4ffrom [1]) since it depends on support for exposing device memory via multiple memslots provided by that series.I'm sorry if that wasn't clear from the cover letter.
Aha! I just fetched David's branch, applied your patches on top, and rebased to current master.
I recommend to list dependencies like
Based-on: <message-id>
so Patchew applies them.
Quoted 4 lines
Thanks,
Maciej[1]: https://github.com/davidhildenbrand/qemu/tree/virtio-mem-memslots
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Maciej S. Szmigiero
Quoted 2 lines · Markus Armbruster
Doesn't apply to master. Care to rebase?
The series is now based on David's virtio-mem-memslots patches (specifically, commit
6769107d1a4ffrom [1]) since it depends on support for exposing device memory via multiple memslots provided by that series.I'm sorry if that wasn't clear from the cover letter.
Quoted 8 lines
Aha! I just fetched David's branch, applied your patches on top, and rebased to current master.
I recommend to list dependencies like
Based-on: <message-id>
so Patchew applies them.
Didn't know that notation, thanks for point this out. Will use it in the future version(s).
Quoted 3 lines
Quoted 2 lines
[1]: https://github.com/davidhildenbrand/qemu/tree/virtio-mem-memslots
Thanks,
Maciej
Quoted 5 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
This is a continuation of the v5 of the patch series located here:
https://lore.kernel.org/qemu-devel/[email protected]/
We're now in QEMU soft-freeze, which means the memslot series might take a bit to land. I'm going to follow-up on that soonish.
Quoted 27 lines
Changes from v5:
* Incorporate David's rework of the driver on top of his virtio-mem-memslots patches (specifically, commit6769107d1a4f), making use of a memory region container created upfront to avoid calling memory_device{,_pre}_plug() functions from the driver and introducing a driver-specific MemoryDeviceInfo sub-type.* Include two additional David's memory-device patches necessary for the aforementioned conversion in this patch set.
* Use multiple memslots to cover the hot-add memory backend in order to reduce metadata size for the not-yet-hot-added part of the memory backend.
* Add David's "Co-developed-by:" to patches where he contributed some changes.
* Use
OBJECT_DEFINE_TYPE_WITH_INTERFACES()andOBJECT_DECLARE_SIMPLE_TYPE()macros instead of open-coding the equivalent functionality.* Drop no longer necessary patch adding
g_autoptr()cleanup function for the Error type.David Hildenbrand (2):
memory-device: Support empty memory devices
memory-device: Drop size alignment check
Quoted 5 lines
Maciej S. Szmigiero (4):
Add Hyper-V Dynamic Memory Protocol definitions
qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
qapi: AddHV_BALLOON_STATUS_REPORTevent
Add a Hyper-V Dynamic Memory Protocol driver (hv-balloon)
That is still a gigantic patch. Is there any way to split that into reasonable chunks? For example, move the whole hotplug/memslot part into a dedicated patch?
See below on splitting off the PC changes.
Quoted 16 lines
Kconfig.host | 3 + hw/core/machine-hmp-cmds.c | 15 + hw/hyperv/Kconfig | 5 + hw/hyperv/hv-balloon.c | 2246 ++++++++++++++++++++++++++++++ hw/hyperv/meson.build | 1 + hw/hyperv/trace-events | 18 + hw/i386/pc.c | 22 + hw/mem/memory-device.c | 45 +- include/hw/hyperv/dynmem-proto.h | 423 ++++++ include/hw/hyperv/hv-balloon.h | 18 + include/hw/mem/memory-device.h | 7 +- meson.build | 28 +- meson_options.txt | 2 + qapi/machine.json | 64 +- scripts/meson-buildoptions.sh | 3 +
It's probably best to separate the actual device implementation from wiring up the machine. That is, have a HV_BALLOON_SUPPORTED kconfig (like VIRTIO_MEM_SUPPORTED), and activate that in a single commit for
PC, where you also modify hw/i386/pc.c.
That commit would be called something like "pc: Support hv-balloon".
Signature · 3 lines
Cheers, David / dhildenb
Quoted 53 lines · David Hildenbrand
Quoted 4 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]> This is a continuation of the v5 of the patch series located here:
https://lore.kernel.org/qemu-devel/[email protected]/We're now in QEMU soft-freeze, which means the memslot series might take a bit to land. I'm going to follow-up on that soonish.
Quoted 15 lines
Changes from v5:
* Incorporate David's rework of the driver on top of his virtio-mem-memslots patches (specifically, commit6769107d1a4f), making use of a memory region container created upfront to avoid calling memory_device{,_pre}_plug() functions from the driver and introducing a driver-specific MemoryDeviceInfo sub-type.
* Include two additional David's memory-device patches necessary for the aforementioned conversion in this patch set.
* Use multiple memslots to cover the hot-add memory backend in order to reduce metadata size for the not-yet-hot-added part of the memory backend.
* Add David's "Co-developed-by:" to patches where he contributed some changes.
* UseOBJECT_DEFINE_TYPE_WITH_INTERFACES()andOBJECT_DECLARE_SIMPLE_TYPE()macros instead of open-coding the equivalent functionality.
* Drop no longer necessary patch addingg_autoptr()cleanup function for the Error type.Quoted 8 lines
David Hildenbrand (2):
memory-device: Support empty memory devices
memory-device: Drop size alignment check
Maciej S. Szmigiero (4):
Add Hyper-V Dynamic Memory Protocol definitions
qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
qapi: AddHV_BALLOON_STATUS_REPORTevent
Add a Hyper-V Dynamic Memory Protocol driver (hv-balloon)That is still a gigantic patch. Is there any way to split that into reasonable chunks? For example, move the whole hotplug/memslot part into a dedicated patch?
See below on splitting off the PC changes.
Quoted 7 lines
Kconfig.host | 3 + hw/core/machine-hmp-cmds.c | 15 + hw/hyperv/Kconfig | 5 + hw/hyperv/hv-balloon.c | 2246 ++++++++++++++++++++++++++++++ hw/hyperv/meson.build | 1 + hw/hyperv/trace-events | 18 + hw/i386/pc.c | 22 +Quoted 8 lines
hw/mem/memory-device.c | 45 +- include/hw/hyperv/dynmem-proto.h | 423 ++++++ include/hw/hyperv/hv-balloon.h | 18 + include/hw/mem/memory-device.h | 7 +- meson.build | 28 +- meson_options.txt | 2 + qapi/machine.json | 64 +- scripts/meson-buildoptions.sh | 3 +
Quoted 5 lines
It's probably best to separate the actual device implementation from wiring up the machine. That is, have a
HV_BALLOON_SUPPORTEDkconfig (likeVIRTIO_MEM_SUPPORTED), and activate that in a single commit for
PC, where you also modifyhw/i386/pc.c.That commit would be called something like "pc: Support hv-balloon".
Furthermore, try to factor out stuff related to QMP:
0. The driver with QMP stuff omitted / stubbed out
1. Enable query-memory-devices
2. Add HV_BALLOON_STATUS_REPORT event
Quoted 8 lines · David Hildenbrand
Quoted 5 lines · Maciej S. Szmigiero
From: "Maciej S. Szmigiero" <[email protected]>
This is a continuation of the v5 of the patch series located here:
https://lore.kernel.org/qemu-devel/[email protected]/We're now in QEMU soft-freeze, which means the memslot series might take a bit to land. I'm going to follow-up on that soonish.
Ack, [1] even says that we're in a hard-freeze already.
Quoted 27 lines
Quoted 27 lines
Changes from v5:
* Incorporate David's rework of the driver on top of his virtio-mem-memslots patches (specifically, commit6769107d1a4f), making use of a memory region container created upfront to avoid calling memory_device{,_pre}_plug() functions from the driver and introducing a driver-specific MemoryDeviceInfo sub-type.* Include two additional David's memory-device patches necessary for the aforementioned conversion in this patch set.
* Use multiple memslots to cover the hot-add memory backend in order to reduce metadata size for the not-yet-hot-added part of the memory backend.
* Add David's "Co-developed-by:" to patches where he contributed some changes.
* Use
OBJECT_DEFINE_TYPE_WITH_INTERFACES()andOBJECT_DECLARE_SIMPLE_TYPE()macros instead of open-coding the equivalent functionality.* Drop no longer necessary patch adding
g_autoptr()cleanup function for the Error type.David Hildenbrand (2):
memory-device: Support empty memory devices
memory-device: Drop size alignment check
Quoted 8 lines
Quoted 5 lines
Maciej S. Szmigiero (4):
Add Hyper-V Dynamic Memory Protocol definitions
qapi: Add HvBalloonDeviceInfo sub-type to MemoryDeviceInfo
qapi: AddHV_BALLOON_STATUS_REPORTevent
Add a Hyper-V Dynamic Memory Protocol driver (hv-balloon)That is still a gigantic patch. Is there any way to split that into reasonable chunks? For example, move the whole hotplug/memslot part into a dedicated patch?
Will move hot-add support from the initial driver patch to a separate one.
Quoted 19 lines
See below on splitting off the PC changes.
Quoted 16 lines
Kconfig.host| 3 + hw/core/machine-hmp-cmds.c | 15 + hw/hyperv/Kconfig | 5 + hw/hyperv/hv-balloon.c | 2246 ++++++++++++++++++++++++++++++ hw/hyperv/meson.build | 1 + hw/hyperv/trace-events | 18 +
hw/i386/pc.c | 22 + hw/mem/memory-device.c | 45 +-include/hw/hyperv/dynmem-proto.h| 423 ++++++ include/hw/hyperv/hv-balloon.h | 18 + include/hw/mem/memory-device.h | 7 +-
meson.build | 28 +- meson_options.txt | 2 + qapi/machine.json | 64 +- scripts/meson-buildoptions.sh | 3 +
Quoted 5 lines
It's probably best to separate the actual device implementation from wiring up the machine. That is, have a
HV_BALLOON_SUPPORTEDkconfig (likeVIRTIO_MEM_SUPPORTED), and activate that in a single commit for
PC, where you also modifyhw/i386/pc.c.That commit would be called something like "pc: Support hv-balloon".
If I remove the driver from Kconfig in the initial patch then AFAIK this initial patch will add a dead driver file that it is not possible to build yet, right?
Or is there some configure-time override for lack of specific Kconfig option?
Thanks,
Maciej
Quoted 5 lines
Quoted 1 line
That commit would be called something like "pc: Support hv-balloon".
If I remove the driver from
Kconfigin the initial patch then AFAIK this initial patch will add a dead driver file that it is not possible to build yet, right?
Yes, that's also what we did for virtio-mem:
(bottom to top)
0ed48fd32e pc: Support for virtio-mem-pci16647a8224 numa: Handle virtio-mem in NUMA stats 2e70874b16 hmp: Handle virtio-mem when printing memory device info 751c7bdd04 MAINTAINERS: Add myself as virtio-mem maintainer 0b9a2443a4 virtio-pci: Proxy for virtio-mem910b25766b virtio-mem: Paravirtualized memory hot(un)plug
And virtio-pmem:
(bottom to top)
a0a49813f7 pc: Support for virtio-pmem-pcicae02c3480 numa: Handle virtio-pmem in NUMA stats d766b22bbd hmp: Handle virtio-pmem when printing memory device infos adf0748a49 virtio-pci: Proxy for virtio-pmem9f583bdd47 virtio-pmem: sync linux headers5f503cd9f3 virtio-pmem: add virtio device
As you're adding all in a single series, that's perfectly fine.
Signature · 3 lines
Cheers, David / dhildenb