From d5747cace73a9002f097a7da41253749c59fb36a Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:24:57 +0200 Subject: pc: create custom generic PC machine type it will be used for PC specific options/variables Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index fa9d99792a..aade1b23bb 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -12,9 +12,33 @@ #include "qemu/bitmap.h" #include "sysemu/sysemu.h" #include "hw/pci/pci.h" +#include "hw/boards.h" #define HPET_INTCAP "hpet-intcap" +struct PCMachineState { + /*< private >*/ + MachineState parent_obj; +}; + +struct PCMachineClass { + /*< private >*/ + MachineClass parent_class; +}; + +typedef struct PCMachineState PCMachineState; +typedef struct PCMachineClass PCMachineClass; + +#define TYPE_PC_MACHINE "generic-pc-machine" +#define PC_MACHINE(obj) \ + OBJECT_CHECK(PCMachineState, (obj), TYPE_PC_MACHINE) +#define PC_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(PCMachineClass, (obj), TYPE_PC_MACHINE) +#define PC_MACHINE_CLASS(klass) \ + OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE) + +void qemu_register_pc_machine(QEMUMachine *m); + /* PC-style peripherals (also used by other machines). */ typedef struct PcPciInfo { -- cgit v1.2.1 From 1f07048933d9c21acb40bce18af4f3ad6bae59b6 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Fri, 6 Jun 2014 17:54:29 +0200 Subject: add memdev backend infrastructure Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices. Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram(). Signed-off-by: Igor Mammedov Signed-off-by: Paolo Bonzini Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/hostmem.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/sysemu/hostmem.h (limited to 'include') diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h new file mode 100644 index 0000000000..4fc081eb17 --- /dev/null +++ b/include/sysemu/hostmem.h @@ -0,0 +1,60 @@ +/* + * QEMU Host Memory Backend + * + * Copyright (C) 2013-2014 Red Hat Inc + * + * Authors: + * Igor Mammedov + * + * 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 QEMU_RAM_H +#define QEMU_RAM_H + +#include "qom/object.h" +#include "qapi/error.h" +#include "exec/memory.h" +#include "qemu/option.h" + +#define TYPE_MEMORY_BACKEND "memory-backend" +#define MEMORY_BACKEND(obj) \ + OBJECT_CHECK(HostMemoryBackend, (obj), TYPE_MEMORY_BACKEND) +#define MEMORY_BACKEND_GET_CLASS(obj) \ + OBJECT_GET_CLASS(HostMemoryBackendClass, (obj), TYPE_MEMORY_BACKEND) +#define MEMORY_BACKEND_CLASS(klass) \ + OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND) + +typedef struct HostMemoryBackend HostMemoryBackend; +typedef struct HostMemoryBackendClass HostMemoryBackendClass; + +/** + * HostMemoryBackendClass: + * @parent_class: opaque parent class container + */ +struct HostMemoryBackendClass { + ObjectClass parent_class; +}; + +/** + * @HostMemoryBackend + * + * @parent: opaque parent object container + * @size: amount of memory backend provides + * @id: unique identification string in memdev namespace + * @mr: MemoryRegion representing host memory belonging to backend + */ +struct HostMemoryBackend { + /* private */ + Object parent; + + /* protected */ + uint64_t size; + + MemoryRegion mr; +}; + +MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend, + Error **errp); + +#endif -- cgit v1.2.1 From c270fb9eff1290e8a4a49040eba1305fec2ce0ec Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:02 +0200 Subject: vl.c: extend -m option to support options for memory hotplug Add following parameters: "slots" - total number of hotplug memory slots "maxmem" - maximum possible memory "slots" and "maxmem" should go in pair and "maxmem" should be greater than "mem" for memory hotplug to be enabled. Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin MST: fix build on 32 bit --- include/hw/boards.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/hw/boards.h b/include/hw/boards.h index 2d2e2bef19..184d2450ee 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -113,6 +113,8 @@ struct MachineState { char *firmware; ram_addr_t ram_size; + ram_addr_t maxram_size; + uint64_t ram_slots; const char *boot_order; char *kernel_filename; char *kernel_cmdline; -- cgit v1.2.1 From b74545481187945965cf9f4df70b71d2f6cded4a Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:03 +0200 Subject: qdev: hotplug for bus-less devices Add get_hotplug_handler() method to machine, and make bus-less device use it during hotplug as a means to discover a hotplug handler controller. The returned controller is used to perform hotplug actions. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/boards.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/hw/boards.h b/include/hw/boards.h index 184d2450ee..429ac43abc 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -61,6 +61,11 @@ extern MachineState *current_machine; /** * MachineClass: * @qemu_machine: #QEMUMachine + * @get_hotplug_handler: this function is called during bus-less + * device hotplug. If defined it returns pointer to an instance + * of HotplugHandler object, which handles hotplug operation + * for a given @dev. It may return NULL if @dev doesn't require + * any actions to be performed by hotplug handler. */ struct MachineClass { /*< private >*/ @@ -90,6 +95,9 @@ struct MachineClass { const char *default_boot_order; GlobalProperty *compat_props; const char *hw_version; + + HotplugHandler *(*get_hotplug_handler)(MachineState *machine, + DeviceState *dev); }; /** -- cgit v1.2.1 From 10b7e74bf2de8587a8f9e15f216b87be43d6a7cf Mon Sep 17 00:00:00 2001 From: Vasilis Liaskovitis Date: Mon, 2 Jun 2014 15:25:05 +0200 Subject: pc: implement pc-dimm device abstraction Each hotplug-able memory slot is a PCDIMMDevice. A hot-add operation for a memory device: - creates a new PCDIMMDevice and makes hotplug controller to map it into guest address space Hotplug operations are done through normal device_add commands. For migration case, all hotplugged memory devices on source should be specified on target's command line using '-device' option with properties set to the same values as on source. To simplify review, patch introduces only PCDIMMDevice QOM skeleton that will be extended by following patches to implement actual memory hotplug and related functions. Signed-off-by: Vasilis Liaskovitis Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/mem/pc-dimm.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 include/hw/mem/pc-dimm.h (limited to 'include') diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h new file mode 100644 index 0000000000..42118cb91d --- /dev/null +++ b/include/hw/mem/pc-dimm.h @@ -0,0 +1,73 @@ +/* + * PC DIMM device + * + * Copyright ProfitBricks GmbH 2012 + * Copyright (C) 2013-2014 Red Hat Inc + * + * Authors: + * Vasilis Liaskovitis + * Igor Mammedov + * + * 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 QEMU_PC_DIMM_H +#define QEMU_PC_DIMM_H + +#include "exec/memory.h" +#include "sysemu/hostmem.h" +#include "hw/qdev.h" + +#define DEFAULT_PC_DIMMSIZE (1024*1024*1024) + +#define TYPE_PC_DIMM "pc-dimm" +#define PC_DIMM(obj) \ + OBJECT_CHECK(PCDIMMDevice, (obj), TYPE_PC_DIMM) +#define PC_DIMM_CLASS(oc) \ + OBJECT_CLASS_CHECK(PCDIMMDeviceClass, (oc), TYPE_PC_DIMM) +#define PC_DIMM_GET_CLASS(obj) \ + OBJECT_GET_CLASS(PCDIMMDeviceClass, (obj), TYPE_PC_DIMM) + +#define PC_DIMM_ADDR_PROP "addr" +#define PC_DIMM_SLOT_PROP "slot" +#define PC_DIMM_NODE_PROP "node" +#define PC_DIMM_SIZE_PROP "size" +#define PC_DIMM_MEMDEV_PROP "memdev" + +#define PC_DIMM_UNASSIGNED_SLOT -1 + +/** + * PCDIMMDevice: + * @addr: starting guest physical address, where @PCDIMMDevice is mapped. + * Default value: 0, means that address is auto-allocated. + * @node: numa node to which @PCDIMMDevice is attached. + * @slot: slot number into which @PCDIMMDevice is plugged in. + * Default value: -1, means that slot is auto-allocated. + * @hostmem: host memory backend providing memory for @PCDIMMDevice + */ +typedef struct PCDIMMDevice { + /* private */ + DeviceState parent_obj; + + /* public */ + uint64_t addr; + uint32_t node; + int32_t slot; + HostMemoryBackend *hostmem; +} PCDIMMDevice; + +/** + * PCDIMMDeviceClass: + * @get_memory_region: returns #MemoryRegion associated with @dimm + */ +typedef struct PCDIMMDeviceClass { + /* private */ + DeviceClass parent_class; + + /* public */ + MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm); +} PCDIMMDeviceClass; + +#endif -- cgit v1.2.1 From eed2bacfd2519e45498b585a147f11b0fd01c3c7 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:06 +0200 Subject: memory: add memory_region_is_mapped() API which allows to check if MemoryRegion is already mapped. Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 549ae734e6..f4c8d4933e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -847,6 +847,14 @@ void memory_region_set_alias_offset(MemoryRegion *mr, */ bool memory_region_present(MemoryRegion *container, hwaddr addr); +/** + * memory_region_is_mapped: returns true if #MemoryRegion is mapped + * into any address space. + * + * @mr: a #MemoryRegion which should be checked if it's mapped + */ +bool memory_region_is_mapped(MemoryRegion *mr); + /** * memory_region_find: translate an address/size relative to a * MemoryRegion into a #MemoryRegionSection. -- cgit v1.2.1 From 619d11e4631000f20318dec90b87f314272bfa4a Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:08 +0200 Subject: pc: initialize memory hotplug address space initialize and map hotplug memory address space container into guest's RAM address space. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index aade1b23bb..48d4c5e9f0 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -16,9 +16,19 @@ #define HPET_INTCAP "hpet-intcap" +/** + * PCMachineState: + * @hotplug_memory_base: address in guest RAM address space where hotplug memory + * address space begins. + * @hotplug_memory: hotplug memory addess space container + */ struct PCMachineState { /*< private >*/ MachineState parent_obj; + + /* */ + ram_addr_t hotplug_memory_base; + MemoryRegion hotplug_memory; }; struct PCMachineClass { -- cgit v1.2.1 From a0cc8856e8722188583901665c7d9e5ddc752fc0 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:09 +0200 Subject: pc: exit QEMU if number of slots more than supported 256 ... which is imposed by current naming scheme of ACPI memory devices. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/acpi.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h index a9fae9d5c5..e93de6cab1 100644 --- a/include/hw/acpi/acpi.h +++ b/include/hw/acpi/acpi.h @@ -26,6 +26,12 @@ #include "exec/memory.h" #include "hw/irq.h" +/* + * current device naming scheme supports + * only upto 256 memory devices + */ +#define ACPI_MAX_RAM_SLOTS 256 + /* from linux include/acpi/actype.h */ /* Default ACPI register widths */ -- cgit v1.2.1 From de268e134c03612970d6f2c214df6287c9621cc8 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:10 +0200 Subject: pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS 'etc/reserved-memory-end' will allow QEMU to tell BIOS where PCI BARs mapping could safely start in high memory. Allowing BIOS to start mapping 64-bit PCI BARs at address where it wouldn't conflict with other mappings QEMU might place before it. That permits QEMU to reserve extra address space before 64-bit PCI hole for memory hotplug. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 48d4c5e9f0..501d9a0773 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -77,6 +77,7 @@ struct PcGuestInfo { uint64_t *node_cpu; FWCfgState *fw_cfg; bool has_acpi_build; + bool has_reserved_memory; }; /* parallel.c */ -- cgit v1.2.1 From 95bee274fd1d22dc6d35e52987f8b5d29fe754dd Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:12 +0200 Subject: pc: add memory hotplug handler to PC_MACHINE that will perform mapping of PC_DIMM device into guest's RAM address space Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 501d9a0773..c3ed8586df 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -31,9 +31,17 @@ struct PCMachineState { MemoryRegion hotplug_memory; }; +/** + * PCMachineClass: + * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler + */ struct PCMachineClass { /*< private >*/ MachineClass parent_class; + + /*< public >*/ + HotplugHandler *(*get_hotplug_handler)(MachineState *machine, + DeviceState *dev); }; typedef struct PCMachineState PCMachineState; -- cgit v1.2.1 From 0b3125711606374f04e279aebefcb7275480f040 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:13 +0200 Subject: pc-dimm: add busy address check and address auto-allocation - if 'addr' property is not specified on -device/device_add command, treat the default value as request for assigning PCDIMMDevice to the first free memory region. - if 'addr' is provided with -device/device_add command, attempt to use it or fail command if it's already occupied or falls inside of an existing PCDIMMDevice memory region. Note: GCompareFunc(a, b) used by g_slist_insert_sorted() returns 'gint', however it might be too small to fit difference between 2 addresses. So use 128bit to calculate the difference and normalize result to -1/0/1 return values. Signed-off-by: Igor Mammedov Signed-off-by: Tang Chen Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Tested-by: Andrey Korolyov MST: commit log tweaks --- include/hw/mem/pc-dimm.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 42118cb91d..5a3e7df13c 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -70,4 +70,8 @@ typedef struct PCDIMMDeviceClass { MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm); } PCDIMMDeviceClass; +uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, + uint64_t address_space_size, + uint64_t *hint, uint64_t size, + Error **errp); #endif -- cgit v1.2.1 From 0cd03d89b98154fcc03d9a8eeea70b9c50cb9457 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:14 +0200 Subject: pc-dimm: add busy slot check and slot auto-allocation - if slot property is not specified on -device/device_add command, treat default value as request for assigning PCDIMMDevice to the first free slot. - if slot is provided with -device/device_add command, attempt to use it or fail command if it's already occupied. Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/mem/pc-dimm.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 5a3e7df13c..0f4a6ba1e4 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -74,4 +74,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t size, Error **errp); + +int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); #endif -- cgit v1.2.1 From 7e629d1d8d09d9e9294def8bcac9c0f283e9b909 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:15 +0200 Subject: acpi: rename cpu_hotplug_defs.h to pc-hotplug.h to make it more generic, so it could be used for memory hotplug as well. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/cpu_hotplug.h | 2 +- include/hw/acpi/cpu_hotplug_defs.h | 32 -------------------------------- include/hw/acpi/pc-hotplug.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 include/hw/acpi/cpu_hotplug_defs.h create mode 100644 include/hw/acpi/pc-hotplug.h (limited to 'include') diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h index 4576400fd7..9e5d30c9df 100644 --- a/include/hw/acpi/cpu_hotplug.h +++ b/include/hw/acpi/cpu_hotplug.h @@ -13,7 +13,7 @@ #define ACPI_HOTPLUG_H #include "hw/acpi/acpi.h" -#include "hw/acpi/cpu_hotplug_defs.h" +#include "hw/acpi/pc-hotplug.h" typedef struct AcpiCpuHotplug { MemoryRegion io; diff --git a/include/hw/acpi/cpu_hotplug_defs.h b/include/hw/acpi/cpu_hotplug_defs.h deleted file mode 100644 index 9f33663511..0000000000 --- a/include/hw/acpi/cpu_hotplug_defs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * QEMU ACPI hotplug utilities shared defines - * - * Copyright (C) 2013 Red Hat Inc - * - * Authors: - * Igor Mammedov - * - * 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 ACPI_HOTPLUG_DEFS_H -#define ACPI_HOTPLUG_DEFS_H - -/* - * ONLY DEFINEs are permited in this file since it's shared - * between C and ASL code. - */ -#define ACPI_CPU_HOTPLUG_STATUS 4 - -/* Limit for CPU arch IDs for CPU hotplug. All hotpluggable CPUs should - * have CPUClass.get_arch_id() < ACPI_CPU_HOTPLUG_ID_LIMIT. - */ -#define ACPI_CPU_HOTPLUG_ID_LIMIT 256 - -/* 256 CPU IDs, 8 bits per entry: */ -#define ACPI_GPE_PROC_LEN 32 - -#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8 -#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00 - -#endif diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h new file mode 100644 index 0000000000..cee479de63 --- /dev/null +++ b/include/hw/acpi/pc-hotplug.h @@ -0,0 +1,32 @@ +/* + * QEMU ACPI hotplug utilities shared defines + * + * Copyright (C) 2014 Red Hat Inc + * + * Authors: + * Igor Mammedov + * + * 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 PC_HOTPLUG_H +#define PC_HOTPLUG_H + +/* + * ONLY DEFINEs are permited in this file since it's shared + * between C and ASL code. + */ +#define ACPI_CPU_HOTPLUG_STATUS 4 + +/* Limit for CPU arch IDs for CPU hotplug. All hotpluggable CPUs should + * have CPUClass.get_arch_id() < ACPI_CPU_HOTPLUG_ID_LIMIT. + */ +#define ACPI_CPU_HOTPLUG_ID_LIMIT 256 + +/* 256 CPU IDs, 8 bits per entry: */ +#define ACPI_GPE_PROC_LEN 32 + +#define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8 +#define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00 + +#endif -- cgit v1.2.1 From 3ef77acab21210b7d0853bf95798f8e0e748e500 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:16 +0200 Subject: acpi: memory hotplug ACPI hardware implementation - implements QEMU hardware part of memory hotplug protocol described at "docs/specs/acpi_mem_hotplug.txt" - handles only memory add notification event for now Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/memory_hotplug.h | 29 +++++++++++++++++++++++++++++ include/hw/acpi/pc-hotplug.h | 3 +++ 2 files changed, 32 insertions(+) create mode 100644 include/hw/acpi/memory_hotplug.h (limited to 'include') diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h new file mode 100644 index 0000000000..8f90f72fdb --- /dev/null +++ b/include/hw/acpi/memory_hotplug.h @@ -0,0 +1,29 @@ +#ifndef QEMU_HW_ACPI_MEMORY_HOTPLUG_H +#define QEMU_HW_ACPI_MEMORY_HOTPLUG_H + +#include "hw/qdev-core.h" +#include "hw/acpi/acpi.h" + +#define ACPI_MEMORY_HOTPLUG_STATUS 8 + +typedef struct MemStatus { + DeviceState *dimm; + bool is_enabled; + bool is_inserting; + uint32_t ost_event; + uint32_t ost_status; +} MemStatus; + +typedef struct MemHotplugState { + MemoryRegion io; + uint32_t selector; + uint32_t dev_count; + MemStatus *devs; +} MemHotplugState; + +void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner, + MemHotplugState *state); + +void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, + DeviceState *dev, Error **errp); +#endif diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h index cee479de63..01d38e2e7e 100644 --- a/include/hw/acpi/pc-hotplug.h +++ b/include/hw/acpi/pc-hotplug.h @@ -29,4 +29,7 @@ #define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8 #define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00 +#define ACPI_MEMORY_HOTPLUG_IO_LEN 24 +#define ACPI_MEMORY_HOTPLUG_BASE 0x0a00 + #endif -- cgit v1.2.1 From 34774320c3b05287a06775c31578bd1e2cb20b83 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:20 +0200 Subject: acpi:piix4: add memory hotplug handling Add memory hotplug initialization/handling to PIIX4_PM device and enable it by default for post 2.0 machine types Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin MST: resolve conflict in pc.h --- include/hw/acpi/memory_hotplug.h | 1 + include/hw/i386/pc.h | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h index 8f90f72fdb..912c53f3ea 100644 --- a/include/hw/acpi/memory_hotplug.h +++ b/include/hw/acpi/memory_hotplug.h @@ -15,6 +15,7 @@ typedef struct MemStatus { } MemStatus; typedef struct MemHotplugState { + bool is_enabled; /* true if memory hotplug is supported */ MemoryRegion io; uint32_t selector; uint32_t dev_count; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index c3ed8586df..f6d41729c5 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -310,11 +310,17 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); PC_Q35_COMPAT_1_5 #define PC_COMPAT_2_0 \ + {\ + .driver = "PIIX4_PM",\ + .property = "memory-hotplug-support",\ + .value = "off",\ + },\ {\ .driver = "apic",\ .property = "version",\ .value = stringify(0x11),\ - },{\ + },\ + {\ .driver = "nec-usb-xhci",\ .property = "superspeed-ports-first",\ .value = "off",\ -- cgit v1.2.1 From 1f8621842ebba95002f500935ac84e7dcf71a540 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:22 +0200 Subject: acpi:ich9: add memory hotplug handling Add memory hotplug initialization/handling to ICH9 LPC device and enable it by default for post 2.0 machine types Signed-off-by: Igor Mammedov Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/ich9.h | 4 ++++ include/hw/i386/pc.h | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h index 104f419852..1977f1b206 100644 --- a/include/hw/acpi/ich9.h +++ b/include/hw/acpi/ich9.h @@ -23,6 +23,7 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/acpi/memory_hotplug.h" typedef struct ICH9LPCPMRegs { /* @@ -46,6 +47,8 @@ typedef struct ICH9LPCPMRegs { AcpiCpuHotplug gpe_cpu; Notifier cpu_added_notifier; + + MemHotplugState acpi_memory_hotplug; } ICH9LPCPMRegs; void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, @@ -55,4 +58,5 @@ extern const VMStateDescription vmstate_ich9_pm; void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp); +void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp); #endif /* HW_ACPI_ICH9_H */ diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index f6d41729c5..1635aede0f 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -286,7 +286,12 @@ int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); #define PC_Q35_COMPAT_2_0 \ - PC_COMPAT_2_0 + PC_COMPAT_2_0, \ + {\ + .driver = "ICH9 LPC",\ + .property = "memory-hotplug-support",\ + .value = "off",\ + } #define PC_Q35_COMPAT_1_7 \ PC_COMPAT_1_7, \ -- cgit v1.2.1 From f816a62daa05ae3b973c76834be7f319b2d02f03 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:23 +0200 Subject: pc: migrate piix4 & ich9 MemHotplugState Adds an optional subsection that allows to migrate current state of acpi_memory_hotplug of ACPI PM device. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/memory_hotplug.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h index 912c53f3ea..458845933b 100644 --- a/include/hw/acpi/memory_hotplug.h +++ b/include/hw/acpi/memory_hotplug.h @@ -3,6 +3,7 @@ #include "hw/qdev-core.h" #include "hw/acpi/acpi.h" +#include "migration/vmstate.h" #define ACPI_MEMORY_HOTPLUG_STATUS 8 @@ -27,4 +28,10 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner, void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st, DeviceState *dev, Error **errp); + +extern const VMStateDescription vmstate_memory_hotplug; +#define VMSTATE_MEMORY_HOTPLUG(memhp, state) \ + VMSTATE_STRUCT(memhp, state, 1, \ + vmstate_memory_hotplug, MemHotplugState) + #endif -- cgit v1.2.1 From 781bbd6bec587606b1b98b78512f2bba64183b0c Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:24 +0200 Subject: pc: add acpi-device link to PCMachineState the link will used later to access device implementing ACPI functions instead of adhoc lookup in QOM tree. Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 1635aede0f..6050115042 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -21,6 +21,7 @@ * @hotplug_memory_base: address in guest RAM address space where hotplug memory * address space begins. * @hotplug_memory: hotplug memory addess space container + * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling */ struct PCMachineState { /*< private >*/ @@ -29,8 +30,12 @@ struct PCMachineState { /* */ ram_addr_t hotplug_memory_base; MemoryRegion hotplug_memory; + + HotplugHandler *acpi_dev; }; +#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" + /** * PCMachineClass: * @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler @@ -210,7 +215,8 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qemu_irq sci_irq, qemu_irq smi_irq, - int kvm_enabled, FWCfgState *fw_cfg); + int kvm_enabled, FWCfgState *fw_cfg, + DeviceState **piix4_pm); void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr); /* hpet.c */ -- cgit v1.2.1 From bef3492d1169a54c966cecd0e0b1dd25e9341582 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:26 +0200 Subject: pc: ACPI BIOS: implement memory hotplug interface - provides static SSDT object for memory hotplug that can handle upto 256 hotplugable memory slots - SSDT template for memory devices and runtime generator of them in SSDT table. Signed-off-by: Vasilis Liaskovitis Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/pc-hotplug.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include') diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h index 01d38e2e7e..bf5157d7c3 100644 --- a/include/hw/acpi/pc-hotplug.h +++ b/include/hw/acpi/pc-hotplug.h @@ -32,4 +32,25 @@ #define ACPI_MEMORY_HOTPLUG_IO_LEN 24 #define ACPI_MEMORY_HOTPLUG_BASE 0x0a00 +#define MEMORY_HOPTLUG_DEVICE MHPD +#define MEMORY_SLOTS_NUMBER MDNR +#define MEMORY_HOTPLUG_IO_REGION HPMR +#define MEMORY_SLOT_ADDR_LOW MRBL +#define MEMORY_SLOT_ADDR_HIGH MRBH +#define MEMORY_SLOT_SIZE_LOW MRLL +#define MEMORY_SLOT_SIZE_HIGH MRLH +#define MEMORY_SLOT_PROXIMITY MPX +#define MEMORY_SLOT_ENABLED MES +#define MEMORY_SLOT_INSERT_EVENT MINS +#define MEMORY_SLOT_SLECTOR MSEL +#define MEMORY_SLOT_OST_EVENT MOEV +#define MEMORY_SLOT_OST_STATUS MOSC +#define MEMORY_SLOT_LOCK MLCK +#define MEMORY_SLOT_STATUS_METHOD MRST +#define MEMORY_SLOT_CRS_METHOD MCRS +#define MEMORY_SLOT_OST_METHOD MOST +#define MEMORY_SLOT_PROXIMITY_METHOD MPXM +#define MEMORY_SLOT_NOTIFY_METHOD MTFY +#define MEMORY_SLOT_SCAN_METHOD MSCN + #endif -- cgit v1.2.1 From bf1e89395996c3a4c888faf297433482934ec007 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 2 Jun 2014 15:25:27 +0200 Subject: pc: add "hotplug-memory-region-size" property to PC_MACHINE ... it will be used by acpi-build code and by unit tests Signed-off-by: Igor Mammedov Acked-by: Peter Crosthwaite Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 6050115042..a2bf22c6a1 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -35,6 +35,7 @@ struct PCMachineState { }; #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" +#define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size" /** * PCMachineClass: -- cgit v1.2.1 From 292b1634d008d289d633ff5a8f2275288f607e56 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Sun, 8 Jun 2014 18:45:25 +0300 Subject: ich: get rid of spaces in type name Names with spaces in them are nasty, let's not go there. Signed-off-by: Michael S. Tsirkin --- include/hw/i386/ich9.h | 2 +- include/hw/i386/pc.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h index e19143555e..59ea25b49a 100644 --- a/include/hw/i386/ich9.h +++ b/include/hw/i386/ich9.h @@ -24,7 +24,7 @@ I2CBus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base); #define ICH9_CC_SIZE (16 * 1024) /* 16KB */ -#define TYPE_ICH9_LPC_DEVICE "ICH9 LPC" +#define TYPE_ICH9_LPC_DEVICE "ICH9-LPC" #define ICH9_LPC_DEVICE(obj) \ OBJECT_CHECK(ICH9LPCState, (obj), TYPE_ICH9_LPC_DEVICE) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index a2bf22c6a1..2e6ac04aea 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -295,7 +295,7 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); #define PC_Q35_COMPAT_2_0 \ PC_COMPAT_2_0, \ {\ - .driver = "ICH9 LPC",\ + .driver = "ICH9-LPC",\ .property = "memory-hotplug-support",\ .value = "off",\ } -- cgit v1.2.1 From 110f463062d65487fdd0daaaa0df53a2ea9d6619 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 20 May 2014 14:01:42 +0800 Subject: migration: export SELF_ANNOUNCE_ROUNDS Export it for other users. Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/migration/vmstate.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 7e45048355..6edce982b2 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -752,6 +752,8 @@ extern const VMStateInfo vmstate_info_bitmap; #define VMSTATE_END_OF_LIST() \ {} +#define SELF_ANNOUNCE_ROUNDS 5 + int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, -- cgit v1.2.1 From 508e1180d3e8371a902ba721d2c9e1ee04c33a15 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 20 May 2014 14:01:43 +0800 Subject: migration: introduce self_announce_delay() This patch introduces self_announce_delay() to calculate the delay for the next announce round. This could be used by other device e.g virtio-net who wants to do announcing by itself. Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/migration/vmstate.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 6edce982b2..799d2d0f03 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -780,4 +780,12 @@ void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev); void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev); void vmstate_register_ram_global(struct MemoryRegion *memory); +static inline +int64_t self_announce_delay(int round) +{ + assert(round < SELF_ANNOUNCE_ROUNDS && round > 0); + /* delay 50ms, 150ms, 250ms, ... */ + return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100; +} + #endif -- cgit v1.2.1 From f57fcf706342f8545d77a538c4319b752511f672 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 20 May 2014 14:01:44 +0800 Subject: virtio-net: announce self by guest It's hard to track all mac addresses and their configurations (e.g vlan or ipv6) in qemu. Without this information, it's impossible to build proper garp packet after migration. The only possible solution to this is let guest (who knows all configurations) to do this. So, this patch introduces a new readonly config status bit of virtio-net, VIRTIO_NET_S_ANNOUNCE which is used to notify guest to announce presence of its link through config update interrupt.When guest has done the announcement, it should ack the notification through VIRTIO_NET_CTRL_ANNOUNCE_ACK cmd. This feature is negotiated by a new feature bit VIRTIO_NET_F_ANNOUNCE (which has already been supported by Linux guest). During load, a counter of announcing rounds is set so that after the vm is running it can trigger rounds of config interrupts to notify the guest to build and send the correct garps. Cc: Liuyongan Cc: Amos Kong Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 5 +++++ include/hw/virtio/virtio-net.h | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 2e6ac04aea..a9529f418c 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -351,6 +351,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .driver = "pci-serial-4x",\ .property = "prog_if",\ .value = stringify(0),\ + },\ + {\ + .driver = "virtio-net-pci",\ + .property = "guest_announce",\ + .value = "off",\ } #define PC_COMPAT_1_7 \ diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 4b32440837..f7fccc08a4 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -49,12 +49,14 @@ #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ #define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ +#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce itself */ #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ +#define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ #define TX_TIMER_INTERVAL 150000 /* 150 us */ @@ -193,6 +195,8 @@ typedef struct VirtIONet { char *netclient_name; char *netclient_type; uint64_t curr_guest_offloads; + QEMUTimer *announce_timer; + int announce_counter; } VirtIONet; #define VIRTIO_NET_CTRL_MAC 1 @@ -212,6 +216,18 @@ typedef struct VirtIONet { #define VIRTIO_NET_CTRL_VLAN_ADD 0 #define VIRTIO_NET_CTRL_VLAN_DEL 1 +/* + * Control link announce acknowledgement + * + * VIRTIO_NET_S_ANNOUNCE bit in the status field requests link announcement from + * guest driver. The driver is notified by config space change interrupt. The + * command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that the driver has + * received the notification. It makes the device clear the bit + * VIRTIO_NET_S_ANNOUNCE in the status field. + */ +#define VIRTIO_NET_CTRL_ANNOUNCE 3 + #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 + /* * Control Multiqueue * @@ -251,6 +267,7 @@ struct virtio_net_ctrl_mq { DEFINE_PROP_BIT("guest_tso6", _state, _field, VIRTIO_NET_F_GUEST_TSO6, true), \ DEFINE_PROP_BIT("guest_ecn", _state, _field, VIRTIO_NET_F_GUEST_ECN, true), \ DEFINE_PROP_BIT("guest_ufo", _state, _field, VIRTIO_NET_F_GUEST_UFO, true), \ + DEFINE_PROP_BIT("guest_announce", _state, _field, VIRTIO_NET_F_GUEST_ANNOUNCE, true), \ DEFINE_PROP_BIT("host_tso4", _state, _field, VIRTIO_NET_F_HOST_TSO4, true), \ DEFINE_PROP_BIT("host_tso6", _state, _field, VIRTIO_NET_F_HOST_TSO6, true), \ DEFINE_PROP_BIT("host_ecn", _state, _field, VIRTIO_NET_F_HOST_ECN, true), \ -- cgit v1.2.1 From 69e03ae64ba01c4846425fb13e494bce3eedfa6b Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:03:35 +0300 Subject: Add kvm_eventfds_enabled function Add a function to check if the eventfd capability is present in KVM in the host kernel. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Acked-by: Paolo Bonzini --- include/sysemu/kvm.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index e79e92c50e..c4556ad59e 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -43,6 +43,7 @@ extern bool kvm_allowed; extern bool kvm_kernel_irqchip; extern bool kvm_async_interrupts_allowed; extern bool kvm_halt_in_kernel_allowed; +extern bool kvm_eventfds_allowed; extern bool kvm_irqfds_allowed; extern bool kvm_msi_via_irqfd_allowed; extern bool kvm_gsi_routing_allowed; @@ -82,6 +83,15 @@ extern bool kvm_readonly_mem_allowed; */ #define kvm_halt_in_kernel() (kvm_halt_in_kernel_allowed) +/** + * kvm_eventfds_enabled: + * + * Returns: true if we can use eventfds to receive notifications + * from a KVM CPU (ie the kernel supports eventds and we are running + * with a configuration where it is meaningful to use them). + */ +#define kvm_eventfds_enabled() (kvm_eventfds_allowed) + /** * kvm_irqfds_enabled: * @@ -128,6 +138,7 @@ extern bool kvm_readonly_mem_allowed; #define kvm_irqchip_in_kernel() (false) #define kvm_async_interrupts_enabled() (false) #define kvm_halt_in_kernel() (false) +#define kvm_eventfds_enabled() (false) #define kvm_irqfds_enabled() (false) #define kvm_msi_via_irqfd_enabled() (false) #define kvm_gsi_routing_allowed() (false) -- cgit v1.2.1 From 7b0bfdf52d694c9a3a96505aa42ce3f8d63acd35 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:03:48 +0300 Subject: Add chardev API qemu_chr_fe_read_all This function will attempt to read data from the chardev trying to fill the buffer up to the given length. Add tcp_chr_disconnect to reuse disconnection code where needed. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/char.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include') diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 7f5eeb38b0..5281123c9a 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -56,6 +56,8 @@ typedef void IOEventHandler(void *opaque, int event); struct CharDriverState { void (*init)(struct CharDriverState *s); int (*chr_write)(struct CharDriverState *s, const uint8_t *buf, int len); + int (*chr_sync_read)(struct CharDriverState *s, + const uint8_t *buf, int len); GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); void (*chr_update_read_handler)(struct CharDriverState *s); int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); @@ -188,6 +190,18 @@ int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len); */ int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len); +/** + * @qemu_chr_fe_read_all: + * + * Read data to a buffer from the back end. + * + * @buf the data buffer + * @len the number of bytes to read + * + * Returns: the number of bytes read + */ +int qemu_chr_fe_read_all(CharDriverState *s, uint8_t *buf, int len); + /** * @qemu_chr_fe_ioctl: * -- cgit v1.2.1 From d39aac7aac2abd78c483f8527c5aa9ae6156bd49 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:04:02 +0300 Subject: Add chardev API qemu_chr_fe_set_msgfds This will set an array of file descriptors to the internal structures. The next time a message is send the array will be send as ancillary data. This feature works on the UNIX domain socket backend only. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/char.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include') diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 5281123c9a..1aa080e00a 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -62,6 +62,7 @@ struct CharDriverState { void (*chr_update_read_handler)(struct CharDriverState *s); int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); int (*get_msgfd)(struct CharDriverState *s); + int (*set_msgfds)(struct CharDriverState *s, int *fds, int num); int (*chr_add_client)(struct CharDriverState *chr, int fd); IOEventHandler *chr_event; IOCanReadHandler *chr_can_read; @@ -228,6 +229,19 @@ int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg); */ int qemu_chr_fe_get_msgfd(CharDriverState *s); +/** + * @qemu_chr_fe_set_msgfds: + * + * For backends capable of fd passing, set an array of fds to be passed with + * the next send operation. + * A subsequent call to this function before calling a write function will + * result in overwriting the fd array with the new value without being send. + * Upon writing the message the fd array is freed. + * + * Returns: -1 if fd passing isn't supported. + */ +int qemu_chr_fe_set_msgfds(CharDriverState *s, int *fds, int num); + /** * @qemu_chr_fe_claim: * -- cgit v1.2.1 From c76bf6bb8fbbb233a7d3641e09229d23747d5ee3 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:04:15 +0300 Subject: Add chardev API qemu_chr_fe_get_msgfds This extends the existing qemu_chr_fe_get_msgfd by allowing to read a set of fds. The function for receiving the fds - unix_process_msgfd is extended to allocate the needed array size. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/char.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 1aa080e00a..930aaf1abe 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -61,7 +61,7 @@ struct CharDriverState { GSource *(*chr_add_watch)(struct CharDriverState *s, GIOCondition cond); void (*chr_update_read_handler)(struct CharDriverState *s); int (*chr_ioctl)(struct CharDriverState *s, int cmd, void *arg); - int (*get_msgfd)(struct CharDriverState *s); + int (*get_msgfds)(struct CharDriverState *s, int* fds, int num); int (*set_msgfds)(struct CharDriverState *s, int *fds, int num); int (*chr_add_client)(struct CharDriverState *chr, int fd); IOEventHandler *chr_event; @@ -229,6 +229,19 @@ int qemu_chr_fe_ioctl(CharDriverState *s, int cmd, void *arg); */ int qemu_chr_fe_get_msgfd(CharDriverState *s); +/** + * @qemu_chr_fe_get_msgfds: + * + * For backends capable of fd passing, return the number of file received + * descriptors and fills the fds array up to num elements + * + * Returns: -1 if fd passing isn't supported or there are no pending file + * descriptors. If file descriptors are returned, subsequent calls to + * this function will return -1 until a client sends a new set of file + * descriptors. + */ +int qemu_chr_fe_get_msgfds(CharDriverState *s, int *fds, int num); + /** * @qemu_chr_fe_set_msgfds: * -- cgit v1.2.1 From cdaa86a54b232572bba594bf87a7416e527e460c Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:04:28 +0300 Subject: Add G_IO_HUP handler for socket chardev This is used to detect that the remote end has disconnected. Just call tcp_char_disconnect on receiving this event. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/char.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 930aaf1abe..3b835f6fb3 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -83,6 +83,7 @@ struct CharDriverState { int avail_connections; int is_mux; guint fd_in_tag; + guint fd_hup_tag; QemuOpts *opts; QTAILQ_ENTRY(CharDriverState) next; }; -- cgit v1.2.1 From 2e6d46d77ed328d34a94688da8371bcbe243479b Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:04:42 +0300 Subject: vhost: add vhost_get_features and vhost_ack_features Generalize the features get/ack to be used for both vhost-net and vhost-scsi. In vhost-net add vhost_net_get_feature_bits to select the feature bit set depending on the NetClient kind. Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index de24746c7e..df1f2149cc 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -25,6 +25,7 @@ typedef unsigned long vhost_log_chunk_t; #define VHOST_LOG_PAGE 0x1000 #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t)) #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS) +#define VHOST_INVALID_FEATURE_BIT (0xff) struct vhost_memory; struct vhost_dev { @@ -68,4 +69,8 @@ bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n); */ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, bool mask); +unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, + unsigned features); +void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, + unsigned features); #endif -- cgit v1.2.1 From ed8b4afe5ff290ae119237e4fa2142e9f1832230 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:05:08 +0300 Subject: Refactor virtio-net to use generic get_vhost_net This decouples virtio-net from the TAP netdev backend and allows support for other backends to be implemented. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/net/vhost_net.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 2d936bb5f5..e2bd61c784 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -20,4 +20,5 @@ void vhost_net_ack_features(VHostNetState *net, unsigned features); bool vhost_net_virtqueue_pending(VHostNetState *net, int n); void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev, int idx, bool mask); +VHostNetState *get_vhost_net(NetClientState *nc); #endif -- cgit v1.2.1 From 81647a655fa4ff99fd5748363a174edd87a40950 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:05:22 +0300 Subject: vhost_net_init will use VhostNetOptions to get all its arguments vhost_dev_init will replace devfd and devpath with a single opaque argument. This is initialised with a file descriptor. When TAP is used (through vhost_net), open /dev/vhost-net and pass the fd as an opaque parameter in VhostNetOptions. The same applies to vhost-scsi - open /dev/vhost-scsi and pass the fd. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost.h | 2 +- include/net/vhost_net.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index df1f2149cc..8afc6f9f22 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -51,7 +51,7 @@ struct vhost_dev { hwaddr mem_changed_end_addr; }; -int vhost_dev_init(struct vhost_dev *hdev, int devfd, const char *devpath, +int vhost_dev_init(struct vhost_dev *hdev, void *opaque, bool force); void vhost_dev_cleanup(struct vhost_dev *hdev); bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index e2bd61c784..2067ee2298 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -6,7 +6,13 @@ struct vhost_net; typedef struct vhost_net VHostNetState; -VHostNetState *vhost_net_init(NetClientState *backend, int devfd, bool force); +typedef struct VhostNetOptions { + NetClientState *net_backend; + void *opaque; + bool force; +} VhostNetOptions; + +struct vhost_net *vhost_net_init(VhostNetOptions *options); bool vhost_net_query(VHostNetState *net, VirtIODevice *dev); int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues); -- cgit v1.2.1 From 24d1eb33eb2ccd995a845a4d4b793e2619a9e460 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:05:35 +0300 Subject: Add vhost_ops to vhost_dev struct and replace all relevant ioctls Decouple vhost from the Linux kernel by introducing vhost_ops. The intention is to provide different backends - a 'kernel' backend based on the ioctl interface, and an 'user' backend based on a UNIX domain socket and shared memory interface. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-backend.h | 27 +++++++++++++++++++++++++++ include/hw/virtio/vhost.h | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 include/hw/virtio/vhost-backend.h (limited to 'include') diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h new file mode 100644 index 0000000000..14e5878318 --- /dev/null +++ b/include/hw/virtio/vhost-backend.h @@ -0,0 +1,27 @@ +/* + * vhost-backend + * + * Copyright (c) 2013 Virtual Open Systems Sarl. + * + * 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 VHOST_BACKEND_H_ +#define VHOST_BACKEND_H_ + +struct vhost_dev; + +typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request, + void *arg); +typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); +typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); + +typedef struct VhostOps { + vhost_call vhost_call; + vhost_backend_init vhost_backend_init; + vhost_backend_cleanup vhost_backend_cleanup; +} VhostOps; + +#endif /* VHOST_BACKEND_H_ */ diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 8afc6f9f22..4714277f82 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -2,6 +2,7 @@ #define VHOST_H #include "hw/hw.h" +#include "hw/virtio/vhost-backend.h" #include "hw/virtio/virtio.h" #include "exec/memory.h" @@ -49,6 +50,7 @@ struct vhost_dev { bool memory_changed; hwaddr mem_changed_start_addr; hwaddr mem_changed_end_addr; + const VhostOps *vhost_ops; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque, -- cgit v1.2.1 From 1a1bfac9ee13d76a4b257431cc4193c8a42efa19 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:05:49 +0300 Subject: Add vhost-backend and VhostBackendType Use vhost_set_backend_type to initialise a proper vhost_ops structure. In vhost_net_init and vhost_net_start_one call conditionally TAP related initialisation depending on the vhost backend type. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/vhost-backend.h | 11 +++++++++++ include/hw/virtio/vhost.h | 4 ++-- include/net/vhost_net.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 14e5878318..d31768a1d4 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -11,6 +11,13 @@ #ifndef VHOST_BACKEND_H_ #define VHOST_BACKEND_H_ +typedef enum VhostBackendType { + VHOST_BACKEND_TYPE_NONE = 0, + VHOST_BACKEND_TYPE_KERNEL = 1, + VHOST_BACKEND_TYPE_USER = 2, + VHOST_BACKEND_TYPE_MAX = 3, +} VhostBackendType; + struct vhost_dev; typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request, @@ -19,9 +26,13 @@ typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque); typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev); typedef struct VhostOps { + VhostBackendType backend_type; vhost_call vhost_call; vhost_backend_init vhost_backend_init; vhost_backend_cleanup vhost_backend_cleanup; } VhostOps; +int vhost_set_backend_type(struct vhost_dev *dev, + VhostBackendType backend_type); + #endif /* VHOST_BACKEND_H_ */ diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 4714277f82..33028ec8c2 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -31,7 +31,6 @@ typedef unsigned long vhost_log_chunk_t; struct vhost_memory; struct vhost_dev { MemoryListener memory_listener; - int control; struct vhost_memory *mem; int n_mem_sections; MemoryRegionSection *mem_sections; @@ -51,10 +50,11 @@ struct vhost_dev { hwaddr mem_changed_start_addr; hwaddr mem_changed_end_addr; const VhostOps *vhost_ops; + void *opaque; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque, - bool force); + VhostBackendType backend_type, bool force); void vhost_dev_cleanup(struct vhost_dev *hdev); bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 2067ee2298..b1c18a3f3b 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -2,11 +2,13 @@ #define VHOST_NET_H #include "net/net.h" +#include "hw/virtio/vhost-backend.h" struct vhost_net; typedef struct vhost_net VHostNetState; typedef struct VhostNetOptions { + VhostBackendType backend_type; NetClientState *net_backend; void *opaque; bool force; -- cgit v1.2.1 From d314f586b3c5f8be243efb02c3944e327d4e11a7 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolaev Date: Tue, 27 May 2014 15:06:29 +0300 Subject: Add new vhost-user netdev backend Add a new QEMU netdev backend that is intended to invoke vhost_net with the vhost-user backend. It uses an Unix socket chardev to establish a communication with the 'slave' (client and server mode supported). At runtime the netdev will handle OPEN/CLOSE events from the chardev. Upon disconnection it will set link_down accordingly and notify virtio-net; the virtio-net interface will go down. Signed-off-by: Antonios Motakis Signed-off-by: Nikolay Nikolaev Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/net/vhost-user.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 include/net/vhost-user.h (limited to 'include') diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h new file mode 100644 index 0000000000..85109f63aa --- /dev/null +++ b/include/net/vhost-user.h @@ -0,0 +1,17 @@ +/* + * vhost-user.h + * + * Copyright (c) 2013 Virtual Open Systems Sarl. + * + * 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 VHOST_USER_H_ +#define VHOST_USER_H_ + +struct vhost_net; +struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc); + +#endif /* VHOST_USER_H_ */ -- cgit v1.2.1 From 96d0e26c238e8df5d659a9b89f323f2524ec0b74 Mon Sep 17 00:00:00 2001 From: Wanlong Gao Date: Wed, 14 May 2014 17:43:05 +0800 Subject: NUMA: move numa related code to new file numa.c Signed-off-by: Wanlong Gao Reviewed-by: Eduardo Habkost Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Signed-off-by: Blue Swirl Signed-off-by: Andre Przywara Signed-off-by: Michael S. Tsirkin Acked-by: Michael S. Tsirkin MST: comment tweaks --- include/exec/cpu-all.h | 2 -- include/exec/cpu-common.h | 2 ++ include/sysemu/cpus.h | 1 - include/sysemu/sysemu.h | 3 +++ 4 files changed, 5 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index e8363d7248..ed28f1ec63 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -297,8 +297,6 @@ CPUArchState *cpu_copy(CPUArchState *env); /* memory API */ -extern ram_addr_t ram_size; - /* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */ #define RAM_PREALLOC_MASK (1 << 0) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 89ec6404cf..e3ec4c8e0c 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -45,6 +45,8 @@ typedef uintptr_t ram_addr_t; # define RAM_ADDR_FMT "%" PRIxPTR #endif +extern ram_addr_t ram_size; + /* memory API */ typedef void CPUWriteMemoryFunc(void *opaque, hwaddr addr, uint32_t value); diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index 6502488a05..4f790810bf 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -23,7 +23,6 @@ extern int smp_threads; #define smp_threads 1 #endif -void set_numa_modes(void); void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg); #endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index ba5c7f8093..565c8f60c1 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -144,6 +144,9 @@ extern QEMUClockType rtc_clock; extern int nb_numa_nodes; extern uint64_t node_mem[MAX_NODES]; extern unsigned long *node_cpumask[MAX_NODES]; +void numa_add(const char *optarg); +void set_numa_nodes(void); +void set_numa_modes(void); #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { -- cgit v1.2.1 From 8c85901ed3cf2ede1ed5957e6e047d3719dceb4e Mon Sep 17 00:00:00 2001 From: Wanlong Gao Date: Wed, 14 May 2014 17:43:07 +0800 Subject: NUMA: Add numa_info structure to contain numa nodes info Add the numa_info structure to contain the numa nodes memory, VCPUs information and the future added numa nodes host memory policies. Reviewed-by: Eduardo Habkost Signed-off-by: Andre Przywara Signed-off-by: Wanlong Gao [Fix hw/ppc/spapr.c - Paolo] Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/sysemu.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 565c8f60c1..3a9308b60d 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -9,6 +9,7 @@ #include "qapi-types.h" #include "qemu/notify.h" #include "qemu/main-loop.h" +#include "qemu/bitmap.h" /* vl.c */ @@ -142,8 +143,11 @@ extern QEMUClockType rtc_clock; #define MAX_CPUMASK_BITS 255 extern int nb_numa_nodes; -extern uint64_t node_mem[MAX_NODES]; -extern unsigned long *node_cpumask[MAX_NODES]; +typedef struct node_info { + uint64_t node_mem; + DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); +} NodeInfo; +extern NodeInfo numa_info[MAX_NODES]; void numa_add(const char *optarg); void set_numa_nodes(void); void set_numa_modes(void); -- cgit v1.2.1 From 0042109a6ab629aebfb287ff7aee295f24fad40d Mon Sep 17 00:00:00 2001 From: Wanlong Gao Date: Wed, 14 May 2014 17:43:08 +0800 Subject: NUMA: convert -numa option to use OptsVisitor Signed-off-by: Wanlong Gao Signed-off-by: Igor Mammedov Tested-by: Eduardo Habkost Reviewed-by: Eduardo Habkost Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/sysemu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 3a9308b60d..4102be320f 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -148,9 +148,10 @@ typedef struct node_info { DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); } NodeInfo; extern NodeInfo numa_info[MAX_NODES]; -void numa_add(const char *optarg); void set_numa_nodes(void); void set_numa_modes(void); +extern QemuOptsList qemu_numa_opts; +int numa_init_func(QemuOpts *opts, void *opaque); #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { -- cgit v1.2.1 From 45e30bf3a98e313a22e7565497e50ddd2652eae7 Mon Sep 17 00:00:00 2001 From: Wanlong Gao Date: Wed, 14 May 2014 17:43:09 +0800 Subject: NUMA: expand MAX_NODES from 64 to 128 libnuma choosed 128 for MAX_NODES, so we follow libnuma here. Signed-off-by: Wanlong Gao Reviewed-by: Eduardo Habkost Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/sysemu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 4102be320f..423d49efc6 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -133,7 +133,7 @@ extern size_t boot_splash_filedata_size; extern uint8_t qemu_extra_params_fw[2]; extern QEMUClockType rtc_clock; -#define MAX_NODES 64 +#define MAX_NODES 128 /* The following shall be true for all CPUs: * cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS -- cgit v1.2.1 From dfabb8b91655f680eaa1aa05e9f226fbd596a70f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:15 +0800 Subject: numa: introduce memory_region_allocate_system_memory Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Signed-off-by: Michael S. Tsirkin Acked-by: Michael S. Tsirkin Reviewed-by: Eduardo Habkost Signed-off-by: Michael S. Tsirkin MST: resolve conflicts --- include/hw/boards.h | 6 +++++- include/sysemu/sysemu.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hw/boards.h b/include/hw/boards.h index 429ac43abc..605a970934 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -43,9 +43,13 @@ struct QEMUMachine { const char *hw_version; }; -#define TYPE_MACHINE_SUFFIX "-machine" +void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, + const char *name, + uint64_t ram_size); + int qemu_register_machine(QEMUMachine *m); +#define TYPE_MACHINE_SUFFIX "-machine" #define TYPE_MACHINE "machine" #undef MACHINE /* BSD defines it and QEMU does not use it */ #define MACHINE(obj) \ diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 423d49efc6..caf88dd870 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -10,6 +10,7 @@ #include "qemu/notify.h" #include "qemu/main-loop.h" #include "qemu/bitmap.h" +#include "qom/object.h" /* vl.c */ -- cgit v1.2.1 From e1c57ab86f3c4ea6532b51cfecf32770b45f5e7a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:18 +0800 Subject: memory: reorganize file-based allocation Split the internal interface in exec.c to a separate function, and push the check on mem_path up to memory_region_init_ram. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/cpu-all.h | 3 --- include/exec/ram_addr.h | 2 ++ include/sysemu/sysemu.h | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index ed28f1ec63..eaddea6194 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -325,9 +325,6 @@ typedef struct RAMList { } RAMList; extern RAMList ram_list; -extern const char *mem_path; -extern int mem_prealloc; - /* Flags stored in the low bits of the TLB virtual address. These are defined so that fast path ram access is all zeros. */ /* Zero if TLB entry is valid. */ diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index b94de02ea7..9b00638505 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -22,6 +22,8 @@ #ifndef CONFIG_USER_ONLY #include "hw/xen/xen.h" +ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, + const char *mem_path); ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr); ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index caf88dd870..c4e1bbd9fd 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -133,6 +133,8 @@ extern uint8_t *boot_splash_filedata; extern size_t boot_splash_filedata_size; extern uint8_t qemu_extra_params_fw[2]; extern QEMUClockType rtc_clock; +extern const char *mem_path; +extern int mem_prealloc; #define MAX_NODES 128 -- cgit v1.2.1 From 38183310be7af6af5ee60e7c9e9647133a7d11c3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:21 +0800 Subject: memory: move preallocation code out of exec.c So that backends can use it. Since we need the page size for efficiency, move code to compute it out of translate-all.c and into util/oslib-win32.c. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/qemu/osdep.h | 2 ++ include/sysemu/os-win32.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index ffb296692d..9c1a119703 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -251,4 +251,6 @@ void qemu_init_auxval(char **envp); void qemu_set_tty_echo(int fd, bool echo); +void os_mem_prealloc(int fd, char *area, size_t sz); + #endif diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index bf8523ada1..af3fbc47d8 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -89,6 +89,8 @@ static inline void os_setup_post(void) {} void os_set_line_buffering(void); static inline void os_set_proc_name(const char *dummy) {} +size_t getpagesize(void); + #if !defined(EPROTONOSUPPORT) # define EPROTONOSUPPORT EINVAL #endif -- cgit v1.2.1 From 7bd4f430a3a226c0016de00818a2a67fd58b2047 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:22 +0800 Subject: memory: move RAM_PREALLOC_MASK to exec.c, rename Prepare for adding more flags. The "_MASK" suffix is unique, kill it. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/cpu-all.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include') diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index eaddea6194..f91581fc65 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -297,9 +297,6 @@ CPUArchState *cpu_copy(CPUArchState *env); /* memory API */ -/* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */ -#define RAM_PREALLOC_MASK (1 << 0) - typedef struct RAMBlock { struct MemoryRegion *mr; uint8_t *host; -- cgit v1.2.1 From 7f8f9ef1dac25e76706ee0454bb6cfa097489170 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Wed, 14 May 2014 17:43:30 +0800 Subject: Introduce signed range. Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Tested-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin MST: split up patch --- include/qemu/range.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'include') diff --git a/include/qemu/range.h b/include/qemu/range.h index aae9720161..cfa021fd48 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -3,6 +3,7 @@ #include #include +#include "qemu/queue.h" /* * Operations on 64 bit address ranges. @@ -60,4 +61,75 @@ static inline int ranges_overlap(uint64_t first1, uint64_t len1, return !(last2 < first1 || last1 < first2); } +/* 0,1 can merge with 1,2 but don't overlap */ +static inline bool ranges_can_merge(Range *range1, Range *range2) +{ + return !(range1->end < range2->begin || range2->end < range1->begin); +} + +static inline int range_merge(Range *range1, Range *range2) +{ + if (ranges_can_merge(range1, range2)) { + if (range1->end < range2->end) { + range1->end = range2->end; + } + if (range1->begin > range2->begin) { + range1->begin = range2->begin; + } + return 0; + } + + return -1; +} + +static inline GList *g_list_insert_sorted_merged(GList *list, + gpointer data, + GCompareFunc func) +{ + GList *l, *next = NULL; + Range *r, *nextr; + + if (!list) { + list = g_list_insert_sorted(list, data, func); + return list; + } + + nextr = data; + l = list; + while (l && l != next && nextr) { + r = l->data; + if (ranges_can_merge(r, nextr)) { + range_merge(r, nextr); + l = g_list_remove_link(l, next); + next = g_list_next(l); + if (next) { + nextr = next->data; + } else { + nextr = NULL; + } + } else { + l = g_list_next(l); + } + } + + if (!l) { + list = g_list_insert_sorted(list, data, func); + } + + return list; +} + +static inline gint range_compare(gconstpointer a, gconstpointer b) +{ + Range *ra = (Range *)a, *rb = (Range *)b; + if (ra->begin == rb->begin && ra->end == rb->end) { + return 0; + } else if (range_get_last(ra->begin, ra->end) < + range_get_last(rb->begin, rb->end)) { + return -1; + } else { + return 1; + } +} + #endif -- cgit v1.2.1 From 1f21772db0b14049b1b4bfef1f039b40827c676f Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Wed, 14 May 2014 17:43:33 +0800 Subject: qom: introduce object_property_get_enum and object_property_get_uint16List Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/qom/object.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'include') diff --git a/include/qom/object.h b/include/qom/object.h index a641dcde10..b882ccc85f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -916,6 +916,34 @@ void object_property_set_int(Object *obj, int64_t value, int64_t object_property_get_int(Object *obj, const char *name, Error **errp); +/** + * object_property_get_enum: + * @obj: the object + * @name: the name of the property + * @strings: strings corresponding to enums + * @errp: returns an error if this function fails + * + * Returns: the value of the property, converted to an integer, or + * undefined if an error occurs (including when the property value is not + * an enum). + */ +int object_property_get_enum(Object *obj, const char *name, + const char *strings[], Error **errp); + +/** + * object_property_get_uint16List: + * @obj: the object + * @name: the name of the property + * @list: the returned int list + * @errp: returns an error if this function fails + * + * Returns: the value of the property, converted to integers, or + * undefined if an error occurs (including when the property value is not + * an list of integers). + */ +void object_property_get_uint16List(Object *obj, const char *name, + uint16List **list, Error **errp); + /** * object_property_set: * @obj: the object -- cgit v1.2.1 From 7febe36f9adbb34756a6a6765a36ea49b6e502ac Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:17 +0800 Subject: numa: add -numa node,memdev= option This option provides the infrastructure for binding guest NUMA nodes to host NUMA nodes. For example: -object memory-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0 \ -numa node,nodeid=0,cpus=0,memdev=ram-node0 \ -object memory-ram,size=1024M,policy=interleave,host-nodes=1-3,id=ram-node1 \ -numa node,nodeid=1,cpus=1,memdev=ram-node1 The option replaces "-numa node,mem=". Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Signed-off-by: Michael S. Tsirkin Acked-by: Michael S. Tsirkin MST: conflict resolution --- include/sysemu/sysemu.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index c4e1bbd9fd..277230db49 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -149,6 +149,7 @@ extern int nb_numa_nodes; typedef struct node_info { uint64_t node_mem; DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); + struct HostMemoryBackend *node_memdev; } NodeInfo; extern NodeInfo numa_info[MAX_NODES]; void set_numa_nodes(void); -- cgit v1.2.1 From 0b183fc871e61f4a586fdef2c0f880b6a856e444 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:19 +0800 Subject: memory: move mem_path handling to memory_region_allocate_system_memory Like the previous patch did in exec.c, split memory_region_init_ram and memory_region_init_ram_from_file, and push mem_path one step further up. Other RAM regions than system memory will now be backed by regular RAM. Also, boards that do not use memory_region_allocate_system_memory will not support -mem-path anymore. This can be changed before the patches are merged by migrating boards to use the function. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index f4c8d4933e..65ddb7a2a8 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -311,6 +311,24 @@ void memory_region_init_ram(MemoryRegion *mr, const char *name, uint64_t size); +#ifdef __linux__ +/** + * memory_region_init_ram_from_file: Initialize RAM memory region with a + * mmap-ed backend. + * + * @mr: the #MemoryRegion to be initialized. + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @path: the path in which to allocate the RAM. + */ +void memory_region_init_ram_from_file(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + const char *path); +#endif + /** * memory_region_init_ram_ptr: Initialize RAM memory region from a * user-provided pointer. Accesses into the -- cgit v1.2.1 From 7f56e740a68c9f4ccebf7ad7590e82fbb30ffc87 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 May 2014 17:43:20 +0800 Subject: memory: add error propagation to file-based RAM allocation Right now, -mem-path will fall back to RAM-based allocation in some cases. This should never happen with "-object memory-file", prepare the code by adding correct error propagation. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin MST: drop \n at end of error messages --- include/exec/memory.h | 5 ++++- include/exec/ram_addr.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 65ddb7a2a8..4c7bacf959 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -31,6 +31,7 @@ #include "qemu/queue.h" #include "qemu/int128.h" #include "qemu/notify.h" +#include "qapi/error.h" #define MAX_PHYS_ADDR_SPACE_BITS 62 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) @@ -321,12 +322,14 @@ void memory_region_init_ram(MemoryRegion *mr, * @name: the name of the region. * @size: size of the region. * @path: the path in which to allocate the RAM. + * @errp: pointer to Error*, to store an error if it happens. */ void memory_region_init_ram_from_file(MemoryRegion *mr, struct Object *owner, const char *name, uint64_t size, - const char *path); + const char *path, + Error **errp); #endif /** diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 9b00638505..deafcebac0 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -23,7 +23,7 @@ #include "hw/xen/xen.h" ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - const char *mem_path); + const char *mem_path, Error **errp); ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr); ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); -- cgit v1.2.1 From 9521d42b546f2f624d4dcd299e13a9ab37eb1d82 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 10 Jun 2014 19:15:17 +0800 Subject: pc: pass MachineState to pc_memory_init Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Reviewed-By: Igor Mammedov Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index a9529f418c..76d4c6e725 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -3,6 +3,7 @@ #include "qemu-common.h" #include "exec/memory.h" +#include "hw/boards.h" #include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "net/net.h" @@ -183,10 +184,8 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size, void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory, MemoryRegion *pci_address_space); -FWCfgState *pc_memory_init(MemoryRegion *system_memory, - const char *kernel_filename, - const char *kernel_cmdline, - const char *initrd_filename, +FWCfgState *pc_memory_init(MachineState *machine, + MemoryRegion *system_memory, ram_addr_t below_4g_mem_size, ram_addr_t above_4g_mem_size, MemoryRegion *rom_memory, -- cgit v1.2.1 From bd9262d95f9172a5f4897aeea341c219a6c6cf96 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Tue, 10 Jun 2014 19:15:19 +0800 Subject: hostmem: separate allocation from UserCreatable complete method This allows the superclass to set various policies on the memory region that the subclass creates. Drops hostmem-ram's complete method accordingly. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/hostmem.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index 4fc081eb17..923f6721d2 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -34,6 +34,8 @@ typedef struct HostMemoryBackendClass HostMemoryBackendClass; */ struct HostMemoryBackendClass { ObjectClass parent_class; + + void (*alloc)(HostMemoryBackend *backend, Error **errp); }; /** -- cgit v1.2.1 From 2925020d339d3b53fbb4fb82fbfb32b71f1b41ff Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Wed, 18 Jun 2014 21:48:19 +0300 Subject: osdep: add merge and dump flags will be used by follow up patch Signed-off-by: Michael S. Tsirkin --- include/qemu/osdep.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 9c1a119703..9438a4fb1a 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -133,6 +133,8 @@ void qemu_anon_ram_free(void *ptr, size_t size); #define QEMU_MADV_DONTNEED POSIX_MADV_DONTNEED #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID +#define QEMU_MADV_UNMERGEABLE QEMU_MADV_INVALID +#define QEMU_MADV_DODUMP QEMU_MADV_INVALID #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID @@ -142,6 +144,8 @@ void qemu_anon_ram_free(void *ptr, size_t size); #define QEMU_MADV_DONTNEED QEMU_MADV_INVALID #define QEMU_MADV_DONTFORK QEMU_MADV_INVALID #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID +#define QEMU_MADV_UNMERGEABLE QEMU_MADV_INVALID +#define QEMU_MADV_DODUMP QEMU_MADV_INVALID #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID -- cgit v1.2.1 From 605d0a945d020e3024aa7faf8a0e8b471371d8ff Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 10 Jun 2014 19:15:22 +0800 Subject: hostmem: add merge and dump properties Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/qemu/osdep.h | 10 ++++++++++ include/sysemu/hostmem.h | 1 + 2 files changed, 11 insertions(+) (limited to 'include') diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 9438a4fb1a..6d35c1bcba 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -116,6 +116,16 @@ void qemu_anon_ram_free(void *ptr, size_t size); #else #define QEMU_MADV_MERGEABLE QEMU_MADV_INVALID #endif +#ifdef MADV_UNMERGEABLE +#define QEMU_MADV_UNMERGEABLE MADV_UNMERGEABLE +#else +#define QEMU_MADV_UNMERGEABLE QEMU_MADV_INVALID +#endif +#ifdef MADV_DODUMP +#define QEMU_MADV_DODUMP MADV_DODUMP +#else +#define QEMU_MADV_DODUMP QEMU_MADV_INVALID +#endif #ifdef MADV_DONTDUMP #define QEMU_MADV_DONTDUMP MADV_DONTDUMP #else diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index 923f6721d2..ede5ec90c7 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -52,6 +52,7 @@ struct HostMemoryBackend { /* protected */ uint64_t size; + bool merge, dump; MemoryRegion mr; }; -- cgit v1.2.1 From a35ba7be4b696d4c7b47318fd2022e6c3eca0a63 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 10 Jun 2014 19:15:23 +0800 Subject: hostmem: allow preallocation of any memory region And allow preallocation of file-based memory even without -mem-prealloc. Some care is necessary because -mem-prealloc does not allow disabling preallocation for hostmem-file. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 10 ++++++++++ include/exec/ram_addr.h | 1 + include/sysemu/hostmem.h | 1 + 3 files changed, 12 insertions(+) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 4c7bacf959..1cf5981b2e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -533,6 +533,16 @@ bool memory_region_is_logging(MemoryRegion *mr); */ bool memory_region_is_rom(MemoryRegion *mr); +/** + * memory_region_get_fd: Get a file descriptor backing a RAM memory region. + * + * Returns a file descriptor backing a file-based RAM memory region, + * or -1 if the region is not a file-based RAM memory region. + * + * @mr: the RAM or alias memory region being queried. + */ +int memory_region_get_fd(MemoryRegion *mr); + /** * memory_region_get_ram_ptr: Get a pointer into a RAM memory region. * diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index deafcebac0..fcc7ef0180 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -27,6 +27,7 @@ ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr); ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); +int qemu_get_ram_fd(ram_addr_t addr); void *qemu_get_ram_ptr(ram_addr_t addr); void qemu_ram_free(ram_addr_t addr); void qemu_ram_free_from_ptr(ram_addr_t addr); diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index ede5ec90c7..4cae673c4b 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -53,6 +53,7 @@ struct HostMemoryBackend { /* protected */ uint64_t size; bool merge, dump; + bool prealloc, force_prealloc; MemoryRegion mr; }; -- cgit v1.2.1 From dbcb8981183592be129b2e624b7bcd4245e75fbc Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 10 Jun 2014 19:15:24 +0800 Subject: hostmem: add property to map memory with MAP_SHARED A new "share" property can be used with the "memory-file" backend to map memory with MAP_SHARED instead of MAP_PRIVATE. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/exec/memory.h b/include/exec/memory.h index 1cf5981b2e..3d778d70f0 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -321,6 +321,7 @@ void memory_region_init_ram(MemoryRegion *mr, * @owner: the object that tracks the region's reference count * @name: the name of the region. * @size: size of the region. + * @share: %true if memory must be mmaped with the MAP_SHARED flag * @path: the path in which to allocate the RAM. * @errp: pointer to Error*, to store an error if it happens. */ @@ -328,6 +329,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, struct Object *owner, const char *name, uint64_t size, + bool share, const char *path, Error **errp); #endif diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index fcc7ef0180..55ca67681f 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -23,7 +23,8 @@ #include "hw/xen/xen.h" ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - const char *mem_path, Error **errp); + bool share, const char *mem_path, + Error **errp); ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr); ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr); -- cgit v1.2.1 From 4cf1b76bf1e2cbb91b1123d47505a6586195800c Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Tue, 10 Jun 2014 19:15:25 +0800 Subject: hostmem: add properties for NUMA memory policy Signed-off-by: Hu Tao [Raise errors on setting properties if !CONFIG_NUMA. Add BUILD_BUG_ON checks. - Paolo] Signed-off-by: Paolo Bonzini Signed-off-by: Marcelo Tosatti Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/hostmem.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index 4cae673c4b..1ce439415d 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -12,10 +12,12 @@ #ifndef QEMU_RAM_H #define QEMU_RAM_H +#include "sysemu/sysemu.h" /* for MAX_NODES */ #include "qom/object.h" #include "qapi/error.h" #include "exec/memory.h" #include "qemu/option.h" +#include "qemu/bitmap.h" #define TYPE_MEMORY_BACKEND "memory-backend" #define MEMORY_BACKEND(obj) \ @@ -54,6 +56,8 @@ struct HostMemoryBackend { uint64_t size; bool merge, dump; bool prealloc, force_prealloc; + DECLARE_BITMAP(host_nodes, MAX_NODES + 1); + HostMemPolicy policy; MemoryRegion mr; }; -- cgit v1.2.1 From 6f2e27301d8cfea0a40dda7ec8a6dc1b9d0e228e Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 16 Jun 2014 19:12:25 +0200 Subject: qmp: add query-memory-devices command ... allowing to get state of present memory devices. Currently implemented only for PCDIMMDevice. Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/mem/pc-dimm.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 0f4a6ba1e4..761eeef801 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -76,4 +76,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, Error **errp); int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); + +int qmp_pc_dimm_device_list(Object *obj, void *opaque); #endif -- cgit v1.2.1 From 521b3673ac16ec7fa33b1ec2cdfe75ec708f073e Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 16 Jun 2014 19:12:26 +0200 Subject: acpi: introduce TYPE_ACPI_DEVICE_IF interface ... it will be used to abstract generic ACPI bits from device that implements ACPI interface. ACPIOSTInfo type is used for passing-through raw _OST event/status codes reported by guest OS to a management layer. It lets management tools interpret values as specified by ACPI spec if it is interested in it. QEMU doesn't encode these values as enum, since it doesn't need to handle them and it allows interface to scale well without any changes in QEMU while guest OS and management evolves in time. Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/acpi_dev_interface.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/hw/acpi/acpi_dev_interface.h (limited to 'include') diff --git a/include/hw/acpi/acpi_dev_interface.h b/include/hw/acpi/acpi_dev_interface.h new file mode 100644 index 0000000000..f245f8d236 --- /dev/null +++ b/include/hw/acpi/acpi_dev_interface.h @@ -0,0 +1,43 @@ +#ifndef ACPI_DEV_INTERFACE_H +#define ACPI_DEV_INTERFACE_H + +#include "qom/object.h" +#include "qapi-types.h" + +#define TYPE_ACPI_DEVICE_IF "acpi-device-interface" + +#define ACPI_DEVICE_IF_CLASS(klass) \ + OBJECT_CLASS_CHECK(AcpiDeviceIfClass, (klass), \ + TYPE_ACPI_DEVICE_IF) +#define ACPI_DEVICE_IF_GET_CLASS(obj) \ + OBJECT_GET_CLASS(AcpiDeviceIfClass, (obj), \ + TYPE_ACPI_DEVICE_IF) +#define ACPI_DEVICE_IF(obj) \ + INTERFACE_CHECK(AcpiDeviceIf, (obj), \ + TYPE_ACPI_DEVICE_IF) + + +typedef struct AcpiDeviceIf { + /* */ + Object Parent; +} AcpiDeviceIf; + +/** + * AcpiDeviceIfClass: + * + * ospm_status: returns status of ACPI device objects, reported + * via _OST method if device supports it. + * + * Interface is designed for providing unified interface + * to generic ACPI functionality that could be used without + * knowledge about internals of actual device that implements + * ACPI interface. + */ +typedef struct AcpiDeviceIfClass { + /* */ + InterfaceClass parent_class; + + /* */ + void (*ospm_status)(AcpiDeviceIf *adev, ACPIOSTInfoList ***list); +} AcpiDeviceIfClass; +#endif -- cgit v1.2.1 From 43f50410088847376c8b146e817a9042bd2a5f36 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 16 Jun 2014 19:12:27 +0200 Subject: acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices ... using TYPE_ACPI_DEVICE_IF interface. Which provides status reporting of ACPI declared memory devices Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/ich9.h | 3 +++ include/hw/acpi/memory_hotplug.h | 1 + 2 files changed, 4 insertions(+) (limited to 'include') diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h index 1977f1b206..7e42448ef9 100644 --- a/include/hw/acpi/ich9.h +++ b/include/hw/acpi/ich9.h @@ -24,6 +24,7 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/memory_hotplug.h" +#include "hw/acpi/acpi_dev_interface.h" typedef struct ICH9LPCPMRegs { /* @@ -59,4 +60,6 @@ extern const VMStateDescription vmstate_ich9_pm; void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp); void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp); + +void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list); #endif /* HW_ACPI_ICH9_H */ diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h index 458845933b..7bbf8a0064 100644 --- a/include/hw/acpi/memory_hotplug.h +++ b/include/hw/acpi/memory_hotplug.h @@ -34,4 +34,5 @@ extern const VMStateDescription vmstate_memory_hotplug; VMSTATE_STRUCT(memhp, state, 1, \ vmstate_memory_hotplug, MemHotplugState) +void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list); #endif -- cgit v1.2.1 From 02edd407f3f1a1c3aaf5247d131735cf71657d8b Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 16 Jun 2014 19:12:29 +0200 Subject: qmp: add ACPI_DEVICE_OST event handling emits event when ACPI OSPM evaluates _OST method of ACPI device. Signed-off-by: Igor Mammedov Reviewed-by: Eric Blake Acked-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/monitor/monitor.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 1c1f56f36b..97696ea693 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -51,6 +51,7 @@ typedef enum MonitorEvent { QEVENT_BLOCK_IMAGE_CORRUPTED, QEVENT_QUORUM_FAILURE, QEVENT_QUORUM_REPORT_BAD, + QEVENT_ACPI_OST, /* Add to 'monitor_event_names' array in monitor.c when * defining new events here */ -- cgit v1.2.1 From b4acfbcd95ac9a668e2f49dd9e1449ea81263752 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Tue, 17 Jun 2014 22:02:00 +0300 Subject: acpi: rephrase comment "only upto" is not proper English. Say "up to" and drop "only". Reported-by: Eric Blake Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/acpi.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h index e93de6cab1..1f678b4bf2 100644 --- a/include/hw/acpi/acpi.h +++ b/include/hw/acpi/acpi.h @@ -27,8 +27,7 @@ #include "hw/irq.h" /* - * current device naming scheme supports - * only upto 256 memory devices + * current device naming scheme supports up to 256 memory devices */ #define ACPI_MAX_RAM_SLOTS 256 -- cgit v1.2.1