ACPI memory hotplug
v2 cover ACPI memory hotplug
This is v2 of the ACPI memory hotplug prototype for x86_64 target.
Changes v1->v2
- memory map is automatically calculated for hotplug dimms. Dimms are added from top-of-memory skipping the pci hole at [PCI_HOLE_START, 4G).
- Renamed from "-memslot" to "-dimm". Commands changed to "dimm_add", "dimm_del".
- Seabios ejection array reduced to a byte. Use extraction macros for dimm ssdt.
- additional SRAT paravirt info does not break previous SRAT fw_cfg layout.
- Documentation of new acpi_piix4 registers and paravirt data.
- add ACPI _OST support for _OST enabled guests. This allows qemu to receive notification for success / failure of memory hot-add and hot-remove operations. Guest needs to support _OST (https://lkml.org/lkml/2012/6/25/321)
- add monitor info command to report total guest memory (initial + hot-added)
- add command line options and monitor commands for batch dimm creation/population
Overview:
Dimm devices are modeled with a new qemu command line
"-dimm id=name,size=sz,node=pxm,populated=on|off"
As already mentioned, the starting physical address for all dimms is calculated automatically from top of memory, skipping the pci hole at [PCI_HOLE_START, 4G). Node is defining numa proximity for this dimm. When not defined it defaults to zero.
"-dimm id=dimm0,size=512M,node=0,populated=off"
will define a 512M memory slot belonging to numa node 0.
Dimms are added or removed with a new hmp command "dimm_add/dimm_del":
Hot-add syntax: "dimm_add id"
Hot-remove syntax: "dimm_del id"
Issues:
- Live migration works as long as populated field is changed to "on" for hotplugged dimms at the destination qemu command line (patch 12/21 lifts this requirement). The DimmState structure does not yet define a VMStateDescription, but i assume this is the preferred way to pass state for migration.
- Dimms are abstracted as qdevices attached to the main system bus. However, memory hotplugging has its own side channel ignoring main_system_bus's hotplug incapability. A cleaner integration is still needed, probably attaching memory devices as children-links of an acpi-capable device (in the pc case acpi_piix4) instead of the system bus (TBD). Then device_add/device_del instead of new commands can hopefully be used.
Comments/review welcome.
series is based on uq/master for qemu-kvm, and master for seabios. Can be found also at:
http://github.com/vliaskov/qemu-kvm/commits/memhp-v2
http://github.com/vliaskov/seabios/commits/memhp-v2
Vasilis Liaskovitis (14):
dimm: Implement memory device abstraction
acpi_piix4: Implement memory device hotplug registers
pc: calculate dimm physical addresses and adjust memory map
pc: Add dimm paravirt SRAT info
Implement "-dimm" command line option
Implement dimm_add and dimm_del commands for hmp and qmp fix live-migration when "populated=on" is missing Implement memory hotplug notification lists
acpi_piix4: _OST dimm support
acpi_piix4: Update dimm state on VM reboot
acpi_piix4: Update dimm bitmap state on hot-remove fail Implement "info memtotal" and "query-memtotal" Implement -dimms, -dimmspop command line options Implement mem_increase, mem_decrease hmp/qmp commands
arch_init.c | 23 ++- docs/specs/acpi_hotplug.txt | 46 +++++ docs/specs/fwcfg.txt | 28 +++ hmp-commands.hx | 67 +++++++ hmp.c | 24 +++ hmp.h | 2 + hw/Makefile.objs | 2 +- hw/acpi_piix4.c | 131 ++++++++++++- hw/dimm.c | 449 +++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 72 +++++++ hw/pc.c | 94 +++++++++- hw/pc.h | 6 + hw/pc_piix.c | 18 ++- monitor.c | 35 ++++ monitor.h | 5 + qapi-schema.json | 38 ++++ qemu-config.c | 70 +++++++ qemu-options.hx | 15 ++ qmp-commands.hx | 137 +++++++++++++ sysemu.h | 1 + vl.c | 122 ++++++++++++- 21 files changed, 1368 insertions(+), 17 deletions(-) create mode 100644 docs/specs/acpi_hotplug.txt create mode 100644 docs/specs/fwcfg.txt create mode 100644 hw/dimm.c create mode 100644 hw/dimm.h
Vasilis Liaskovitis (7):
Add ACPI_EXTRACT_DEVICE* macros
Add SSDT memory device support
acpi-dsdt: Implement functions for memory hotplug.
acpi: generate hotplug memory devices.
pciinit: Fix pcimem_start value
acpi_dsdt: Support _OST dimm method
acpi_dsdt: Revert internal dimm state on _OST failure
Makefile | 2 +- src/acpi-dsdt.dsl | 120 ++++++++++++++++++++++++++++++++++++- src/acpi.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++-- src/pciinit.c | 2 +- src/ssdt-mem.dsl | 69 +++++++++++++++++++++ tools/acpi_extract.py | 28 +++++++++ 6 files changed, 369 insertions(+), 10 deletions(-) create mode 100644 src/ssdt-mem.dsl
RFC PATCH v2 1/21 Add ACPI_EXTRACT_DEVICE* macros
This allows to extract the beginning, end and name of a Device object.
--- tools/acpi_extract.py | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-)
tools/acpi_extract.py +28 -0
@@ -195,6 +195,28 @@ def aml_package_start(offset): offset += 1 return offset + aml_pkglen_bytes(offset) + 1 +def aml_device_start(offset): + #0x5B 0x82 DeviceOp PkgLength NameString ProcID + if ((aml[offset] != 0x5B) or (aml[offset + 1] != 0x82)): + die( "Name offset 0x%x: expected 0x5B 0x83 actual 0x%x 0x%x" % + (offset, aml[offset], aml[offset + 1])); + return offset + +def aml_device_string(offset): + #0x5B 0x82 DeviceOp PkgLength NameString ProcID + start = aml_device_start(offset) + offset += 2 + pkglenbytes = aml_pkglen_bytes(offset) + offset += pkglenbytes + return offset + +def aml_device_end(offset): + start = aml_device_start(offset) + offset += 2 + pkglenbytes = aml_pkglen_bytes(offset) + pkglen = aml_pkglen(offset) + return offset + pkglen + lineno = 0 for line in fileinput.input(): # Strip trailing newline
@@ -279,6 +301,12 @@ for i in range(len(asl)): offset = aml_processor_end(offset) elif (directive == "ACPI_EXTRACT_PKG_START"): offset = aml_package_start(offset) + elif (directive == "ACPI_EXTRACT_DEVICE_START"): + offset = aml_device_start(offset) + elif (directive == "ACPI_EXTRACT_DEVICE_STRING"): + offset = aml_device_string(offset) + elif (directive == "ACPI_EXTRACT_DEVICE_END"): + offset = aml_device_end(offset) else: die("Unsupported directive %s" % directive)
Signature · 1 line
1.7.9
RFC PATCH v2 2/21 Add SSDT memory device support
In reply to Vasilis LiaskovitisDefine SSDT hotplug-able memory devices in _SB namespace. The dynamically generated SSDT includes per memory device hotplug methods. These methods just call methods defined in the DSDT. Also dynamically generate a MTFY method and a MEON array of the online/available memory devices. ACPI extraction macros are used to place the AML code in variables later used by src/acpi. The design is taken from SSDT cpu generation.
--- Makefile | 2 +- src/ssdt-mem.dsl | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletions(-) create mode 100644 src/ssdt-mem.dsl
Makefile +1 -1
@@ -228,7 +228,7 @@ $(OUT)%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.p $(Q)$(PYTHON) ./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off $(Q)cat $(OUT)$*.off > $@ -$(OUT)ccode32flat.o: $(OUT)acpi-dsdt.hex $(OUT)ssdt-proc.hex $(OUT)ssdt-pcihp.hex +$(OUT)ccode32flat.o: $(OUT)acpi-dsdt.hex $(OUT)ssdt-proc.hex $(OUT)ssdt-pcihp.hex $(OUT)ssdt-mem.hex ################ Kconfig rules
src/ssdt-mem.dsl new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.7.9
RFC PATCH v2 3/21 acpi-dsdt: Implement functions for memory hotplug
In reply to Vasilis LiaskovitisExtend the DSDT to include methods for handling memory hot-add and hot-remove notifications and memory device status requests. These functions are called from the memory device SSDT methods.
--- src/acpi-dsdt.dsl | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 68 insertions(+), 2 deletions(-)
src/acpi-dsdt.dsl +68 -2
@@ -737,6 +737,71 @@ DefinitionBlock ( } Return(One) } + /* Objects filled in by run-time generated SSDT */ + External(MTFY, MethodObj) + External(MEON, PkgObj) + + Method (CMST, 1, NotSerialized) { + // _STA method - return ON status of memdevice + // Local0 = MEON flag for this cpu + Store(DerefOf(Index(MEON, Arg0)), Local0) + If (Local0) { Return(0xF) } Else { Return(0x0) } + } + + /* Memory hotplug notify array */ + OperationRegion(MEST, SystemIO, 0xaf80, 32) + Field (MEST, ByteAcc, NoLock, Preserve) + { + MES, 256 + } + + /* Memory eject byte */ + OperationRegion(MEMJ, SystemIO, 0xafa0, 1) + Field (MEMJ, ByteAcc, NoLock, Preserve) + { + MPE, 8 + } + + Method(MESC, 0) { + // Local5 = active memdevice bitmap + Store (MES, Local5) + // Local2 = last read byte from bitmap + Store (Zero, Local2) + // Local0 = memory device iterator + Store (Zero, Local0) + While (LLess(Local0, SizeOf(MEON))) { + // Local1 = MEON flag for this memory device + Store(DerefOf(Index(MEON, Local0)), Local1) + If (And(Local0, 0x07)) { + // Shift down previously read bitmap byte + ShiftRight(Local2, 1, Local2) + } Else { + // Read next byte from memdevice bitmap + Store(DerefOf(Index(Local5, ShiftRight(Local0, 3))), Local2) + } + // Local3 = active state for this memory device + Store(And(Local2, 1), Local3) + + If (LNotEqual(Local1, Local3)) { + // State change - update MEON with new state + Store(Local3, Index(MEON, Local0)) + // Do MEM notify + If (LEqual(Local3, 1)) { + MTFY(Local0, 1) + } Else { + MTFY(Local0, 3) + } + } + Increment(Local0) + } + Return(One) + } + + Method (MPEJ, 2, NotSerialized) { + // _EJ0 method - eject callback + Store(Arg0, MPE) + Sleep(200) + } }
@@ -759,8 +824,9 @@ DefinitionBlock ( // CPU hotplug event Return(\_SB.PRSC()) } - Method(_L03) { - Return(0x01) + Method(_E03) { + // Memory hotplug event + Return(\_SB.MESC()) } Method(_L04) { Return(0x01)
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 03/21][SeaBIOS] acpi-dsdt: Implement functions for memory hotplug
At 07/11/2012 06:31 PM, Vasilis Liaskovitis Wrote:
Quoted 53 lines
Extend the DSDT to include methods for handling memory hot-add and hot-remove notifications and memory device status requests. These functions are called from the memory device SSDT methods.
Signed-off-by Vasilis Liaskovitis <[email protected]>--- src/acpi-dsdt.dsl | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 68 insertions(+), 2 deletions(-)src/acpi-dsdt.dsl +36
-0@@ -737,6 +737,71 @@ DefinitionBlock ( } Return(One) } + /* Objects filled in by run-time generated SSDT */ + External(MTFY, MethodObj) + External(MEON, PkgObj) + + Method (CMST, 1, NotSerialized) { + // _STA method - return ON status of memdevice + // Local0 = MEON flag for this cpu + Store(DerefOf(Index(MEON, Arg0)), Local0) + If (Local0) { Return(0xF) } Else { Return(0x0) } + } + + /* Memory hotplug notify array */ + OperationRegion(MEST, SystemIO, 0xaf80, 32) + Field (MEST, ByteAcc, NoLock, Preserve) + { + MES, 256 + } + + /* Memory eject byte */ + OperationRegion(MEMJ, SystemIO, 0xafa0, 1) + Field (MEMJ, ByteAcc, NoLock, Preserve) + { + MPE, 8 + } + + Method(MESC, 0) { + // Local5 = active memdevice bitmap + Store (MES, Local5) + // Local2 = last read byte from bitmap + Store (Zero, Local2) + // Local0 = memory device iterator + Store (Zero, Local0) + While (LLess(Local0, SizeOf(MEON))) { + // Local1 = MEON flag for this memory device + Store(DerefOf(Index(MEON, Local0)), Local1) + If (And(Local0, 0x07)) {
src/acpi-dsdt.dsl DefinitionBlock ( · line 785
Quoted 10 lines
src/acpi-dsdt.dsl +10
-0+ // Shift down previously read bitmap byte + ShiftRight(Local2, 1, Local2) + } Else { + // Read next byte from memdevice bitmap + Store(DerefOf(Index(Local5, ShiftRight(Local0, 3))), Local2) + } + // Local3 = active state for this memory device + Store(And(Local2, 1), Local3) + + If (LNotEqual(Local1, Local3)) {
There are two ways to hot remove a memory device:
1. dimm_del
2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
In the 2nd case, we cannot hotplug this memory device again, because both Local1 and Local3 are 1.
So, I think MEON flag for this meory device should be set to 0 in method _EJ0 or implement method _PS3 for memory device.
Thanks
Wen Congyang
Quoted 34 lines
src/acpi-dsdt.dsl +22
-2+ // State change - update MEON with new state + Store(Local3, Index(MEON, Local0)) + // Do MEM notify + If (LEqual(Local3, 1)) { + MTFY(Local0, 1) + } Else { + MTFY(Local0, 3) + } + } + Increment(Local0) + } + Return(One) + } + + Method (MPEJ, 2, NotSerialized) { + // _EJ0 method - eject callback + Store(Arg0, MPE) + Sleep(200) + } }@@ -759,8 +824,9 @@ DefinitionBlock ( // CPU hotplug event Return(\_SB.PRSC()) } - Method(_L03) { - Return(0x01) + Method(_E03) { + // Memory hotplug event + Return(\_SB.MESC()) } Method(_L04) { Return(0x01)
Re: [RFC PATCH v2 03/21][SeaBIOS] acpi-dsdt: Implement functions for memory hotplug
Quoted 26 lines · Wen Congyang
Quoted 11 lines
src/acpi-dsdt.dsl +11
-0+ Method(MESC, 0) { + // Local5 = active memdevice bitmap + Store (MES, Local5) + // Local2 = last read byte from bitmap + Store (Zero, Local2) + // Local0 = memory device iterator + Store (Zero, Local0) + While (LLess(Local0, SizeOf(MEON))) { + // Local1 = MEON flag for this memory device + Store(DerefOf(Index(MEON, Local0)), Local1) + If (And(Local0, 0x07)) {src/acpi-dsdt.dsl DefinitionBlock ( · line 785
Quoted 10 lines
src/acpi-dsdt.dsl +10
-0+ // Shift down previously read bitmap byte + ShiftRight(Local2, 1, Local2) + } Else { + // Read next byte from memdevice bitmap + Store(DerefOf(Index(Local5, ShiftRight(Local0, 3))), Local2) + } + // Local3 = active state for this memory device + Store(And(Local2, 1), Local3) + + If (LNotEqual(Local1, Local3)) {There are two ways to hot remove a memory device:
1.dimm_del
2. echo 1 >/sys/bus/acpi/devices/PNP0C80:XX/eject
Quoted 5 lines
In the 2nd case, we cannot hotplug this memory device again, because both Local1 and Local3 are 1.
So, I think MEON flag for this meory device should be set to 0 in method
_EJ0or implement method_PS3for memory device.
good catch. Both internal seabios state (MEON) and the machine qemu bitmap (mems_sts in hw/acpi_piix4.c) have to be updated when the ejection comes from OSPM action. I will implement a _PS3 method that updates the MEON flag and also signals qemu to change the mems_sts bitmap.
thanks,
- Vasilis
RFC PATCH v2 4/21 acpi: generate hotplug memory devices
In reply to Vasilis LiaskovitisThe memory device generation is guided by qemu paravirt info. Seabios first uses the info to setup SRAT entries for the hotplug-able memory slots. Afterwards, build_memssdt uses the created SRAT entries to generate appropriate memory device objects. One memory device (and corresponding SRAT entry) is generated for each hotplug-able qemu memslot. Currently no SSDT memory device is created for initial system memory.
We only support up to 255 DIMMs for now (PackageOp used for the MEON array can only describe an array of at most 255 elements. VarPackageOp would be needed to support more than 255 devices)
v1->v2:
Seabios reads mems_sts from qemu to build e820_map
SSDT size and some offsets are calculated with extraction macros.
--- src/acpi.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 152 insertions(+), 6 deletions(-)
src/acpi.c +152 -6
@@ -510,6 +510,127 @@ build_ssdt(void)return ssdt; } +#include "ssdt-mem.hex" + +/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */ +#define MEM_BASE 0xaf80 +#define SD_MEM (ssdm_mem_aml + *ssdt_mem_start) +#define SD_MEMSIZEOF (*ssdt_mem_end - *ssdt_mem_start) +#define SD_OFFSET_MEMHEX (*ssdt_mem_name - *ssdt_mem_start + 2) +#define SD_OFFSET_MEMID (*ssdt_mem_id - *ssdt_mem_start) +#define SD_OFFSET_PXMID 31 +#define SD_OFFSET_MEMSTART 55 +#define SD_OFFSET_MEMEND 63 +#define SD_OFFSET_MEMSIZE 79 + +u64 nb_hp_memslots =0 ; +struct srat_memory_affinity *mem; + +static void build_memdev (u8 *ssdt_ptr,int i,u64 mem_base,u64 mem_len,u8 node) +{ +memcpy (ssdt_ptr,SD_MEM ,SD_MEMSIZEOF ); + ssdt_ptr[SD_OFFSET_MEMHEX ] =getHex (i >>4 ); + ssdt_ptr[SD_OFFSET_MEMHEX +1 ] =getHex (i); + ssdt_ptr[SD_OFFSET_MEMID ] = i; + ssdt_ptr[SD_OFFSET_PXMID ] = node; + *(u64 *)(ssdt_ptr +SD_OFFSET_MEMSTART ) = mem_base; + *(u64 *)(ssdt_ptr +SD_OFFSET_MEMEND ) = mem_base + mem_len; + *(u64 *)(ssdt_ptr +SD_OFFSET_MEMSIZE ) = mem_len; +} + +static void * +build_memssdt (void ) +{ +u64 mem_base; +u64 mem_len; +u8 node; +int i; +struct srat_memory_affinity *entry = mem; +u64 nb_memdevs = nb_hp_memslots; +u8 memslot_status, enabled; + +int length = ((1 +3 +4 ) + + (nb_memdevs *SD_MEMSIZEOF ) + + (1 +2 +5 +(12 *nb_memdevs)) + + (6 +2 +1 +(1 *nb_memdevs))); +u8 *ssdt =malloc_high (sizeof (struct acpi_table_header ) + length); +if (! ssdt) { +warn_noalloc (); +return NULL ; + } +u8 *ssdt_ptr = ssdt +sizeof (struct acpi_table_header ); + +// build Scope(_SB_) header + *(ssdt_ptr++) =0x10 ;// ScopeOp + ssdt_ptr =encodeLen (ssdt_ptr, length-1 ,3 ); + *(ssdt_ptr++) ='_' ; + *(ssdt_ptr++) ='S' ; + *(ssdt_ptr++) ='B' ; + *(ssdt_ptr++) ='_' ; + +for (i =0 ; i < nb_memdevs; i++) { + mem_base = (((u64)(entry->base_addr_high) <<32 )| entry->base_addr_low); + mem_len = (((u64)(entry->length_high) <<32 )| entry->length_low); + node = entry->proximity[0 ]; +build_memdev (ssdt_ptr, i, mem_base, mem_len, node); + ssdt_ptr +=SD_MEMSIZEOF ; + entry++; + } + +// build "Method(MTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CM00, Arg1)} ...}" + *(ssdt_ptr++) =0x14 ;// MethodOp + ssdt_ptr =encodeLen (ssdt_ptr,2 +5 +(12 *nb_memdevs),2 ); + *(ssdt_ptr++) ='M' ; + *(ssdt_ptr++) ='T' ; + *(ssdt_ptr++) ='F' ; + *(ssdt_ptr++) ='Y' ; + *(ssdt_ptr++) =0x02 ; +for (i=0 ; i<nb_memdevs; i++) { + *(ssdt_ptr++) =0xA0 ;// IfOp + ssdt_ptr =encodeLen (ssdt_ptr,11 ,1 ); + *(ssdt_ptr++) =0x93 ;// LEqualOp + *(ssdt_ptr++) =0x68 ;// Arg0Op + *(ssdt_ptr++) =0x0A ;// BytePrefix + *(ssdt_ptr++) = i; + *(ssdt_ptr++) =0x86 ;// NotifyOp + *(ssdt_ptr++) ='M' ; + *(ssdt_ptr++) ='P' ; + *(ssdt_ptr++) =getHex (i >>4 ); + *(ssdt_ptr++) =getHex (i); + *(ssdt_ptr++) =0x69 ;// Arg1Op + } + +// build "Name(MEON, Package() { One, One, ..., Zero, Zero, ... })" + *(ssdt_ptr++) =0x08 ;// NameOp + *(ssdt_ptr++) ='M' ; + *(ssdt_ptr++) ='E' ; + *(ssdt_ptr++) ='O' ; + *(ssdt_ptr++) ='N' ; + *(ssdt_ptr++) =0x12 ;// PackageOp + ssdt_ptr =encodeLen (ssdt_ptr,2 +1 +(1 *nb_memdevs),2 ); + *(ssdt_ptr++) = nb_memdevs; + + entry = mem; + memslot_status =0 ; + +for (i =0 ; i < nb_memdevs; i++) { + enabled =0 ; +if (i %8 ==0 ) + memslot_status =inb (MEM_BASE + i/8 ); + enabled = memslot_status &1 ; + mem_base = (((u64)(entry->base_addr_high) <<32 )| entry->base_addr_low); + mem_len = (((u64)(entry->length_high) <<32 )| entry->length_low); + *(ssdt_ptr++) = enabled ?0x01 :0x00 ; +if (enabled) +add_e820 (mem_base, mem_len,E820_RAM ); + memslot_status = memslot_status >>1 ; + entry++; + } +build_header ((void *)ssdt,SSDT_SIGNATURE , ssdt_ptr - ssdt,1 ); + +return ssdt; +} +#include "ssdt-pcihp.hex" #define PCI_RMV_BASE 0xae0c
@@ -618,9 +739,6 @@ build_srat(void) {int nb_numa_nodes =qemu_cfg_get_numa_nodes (); -if (nb_numa_nodes ==0 ) -return NULL ; -u64 *numadata =malloc_tmphigh (sizeof (u64) * (MaxCountCPUs + nb_numa_nodes));if (!numadata) {warn_noalloc ();
@@ -629,10 +747,11 @@ build_srat(void)qemu_cfg_get_numa_data (numadata, MaxCountCPUs + nb_numa_nodes); +qemu_cfg_get_numa_data (&nb_hp_memslots,1 );struct system_resource_affinity_table *srat;int srat_size =sizeof (*srat) +sizeof (struct srat_processor_affinity ) * MaxCountCPUs + -sizeof (struct srat_memory_affinity ) * (nb_numa_nodes +2 ); +sizeof (struct srat_memory_affinity ) * (nb_numa_nodes + nb_hp_memslots +2 ); srat =malloc_high (srat_size);if (!srat) {
@@ -667,7 +786,7 @@ build_srat(void)* from 640k-1M and possibly another one from 3.5G-4G. */ struct srat_memory_affinity *numamem = (void *)core; -int slots =0 ; +int slots =0 , node;u64 mem_len, mem_base, next_base =0 ;acpi_build_srat_memory (numamem,0 ,640 *1024 ,0 ,1 );
@@ -694,10 +813,36 @@ build_srat(void) next_base += (1ULL <<32 ) - RamSize; }acpi_build_srat_memory (numamem, mem_base, mem_len, i-1 ,1 ); + numamem++; slots++; + + } + mem = (void *)numamem; + +if (nb_hp_memslots) { +u64 *hpmemdata =malloc_tmphigh (sizeof (u64) * (3 * nb_hp_memslots)); +if (!hpmemdata) { +warn_noalloc (); +free (hpmemdata); +free (numadata); +return NULL ; + } + +qemu_cfg_get_numa_data (hpmemdata,3 * nb_hp_memslots); + +for (i =1 ; i < nb_hp_memslots +1 ; ++i) { + mem_base = *hpmemdata++; + mem_len = *hpmemdata++; + node = *hpmemdata++; +acpi_build_srat_memory (numamem, mem_base, mem_len, node,1 ); + numamem++; + slots++; + } +free (hpmemdata); } -for (; slots < nb_numa_nodes +2 ; slots++) { + +for (; slots < nb_numa_nodes + nb_hp_memslots +2 ; slots++) {acpi_build_srat_memory (numamem,0 ,0 ,0 ,0 ); numamem++; }
@@ -748,6 +893,7 @@ acpi_bios_init(void)ACPI_INIT_TABLE (build_madt ());ACPI_INIT_TABLE (build_hpet ());ACPI_INIT_TABLE (build_srat ()); +ACPI_INIT_TABLE (build_memssdt ());ACPI_INIT_TABLE (build_pcihp ());u16 i, external_tables =qemu_cfg_acpi_additional_tables ();
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 04/21][SeaBIOS] acpi: generate hotplug memory devices
At 07/11/2012 06:31 PM, Vasilis Liaskovitis Wrote:
Quoted 131 lines
The memory device generation is guided by qemu paravirt info. Seabios first uses the info to setup SRAT entries for the hotplug-able memory slots. Afterwards,
build_memssdtuses the created SRAT entries to generate appropriate memory device objects. One memory device (and corresponding SRAT entry) is generated for each hotplug-able qemu memslot. Currently no SSDT memory device is created for initial system memory.We only support up to 255 DIMMs for now (PackageOp used for the MEON array can only describe an array of at most 255 elements. VarPackageOp would be needed to support more than 255 devices)
v1->v2:
Seabios readsmems_stsfrom qemu to builde820_map
SSDT size and some offsets are calculated with extraction macros.Signed-off-by Vasilis Liaskovitis <[email protected]>--- src/acpi.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 152 insertions(+), 6 deletions(-)src/acpi.c +103
-0@@ -510,6 +510,127 @@ build_ssdt(void)return ssdt; } +#include "ssdt-mem.hex" + +/* 0x5B 0x82 DeviceOp PkgLength NameString DimmID */ +#define MEM_BASE 0xaf80 +#define SD_MEM (ssdm_mem_aml + *ssdt_mem_start) +#define SD_MEMSIZEOF (*ssdt_mem_end - *ssdt_mem_start) +#define SD_OFFSET_MEMHEX (*ssdt_mem_name - *ssdt_mem_start + 2) +#define SD_OFFSET_MEMID (*ssdt_mem_id - *ssdt_mem_start) +#define SD_OFFSET_PXMID 31 +#define SD_OFFSET_MEMSTART 55 +#define SD_OFFSET_MEMEND 63 +#define SD_OFFSET_MEMSIZE 79 + +u64 nb_hp_memslots =0 ; +struct srat_memory_affinity *mem; + +static void build_memdev (u8 *ssdt_ptr,int i,u64 mem_base,u64 mem_len,u8 node) +{ +memcpy (ssdt_ptr,SD_MEM ,SD_MEMSIZEOF ); + ssdt_ptr[SD_OFFSET_MEMHEX ] =getHex (i >>4 ); + ssdt_ptr[SD_OFFSET_MEMHEX +1 ] =getHex (i); + ssdt_ptr[SD_OFFSET_MEMID ] = i; + ssdt_ptr[SD_OFFSET_PXMID ] = node; + *(u64 *)(ssdt_ptr +SD_OFFSET_MEMSTART ) = mem_base; + *(u64 *)(ssdt_ptr +SD_OFFSET_MEMEND ) = mem_base + mem_len; + *(u64 *)(ssdt_ptr +SD_OFFSET_MEMSIZE ) = mem_len; +} + +static void * +build_memssdt (void ) +{ +u64 mem_base; +u64 mem_len; +u8 node; +int i; +struct srat_memory_affinity *entry = mem; +u64 nb_memdevs = nb_hp_memslots; +u8 memslot_status, enabled; + +int length = ((1 +3 +4 ) + + (nb_memdevs *SD_MEMSIZEOF ) + + (1 +2 +5 +(12 *nb_memdevs)) + + (6 +2 +1 +(1 *nb_memdevs))); +u8 *ssdt =malloc_high (sizeof (struct acpi_table_header ) + length); +if (! ssdt) { +warn_noalloc (); +return NULL ; + } +u8 *ssdt_ptr = ssdt +sizeof (struct acpi_table_header ); + +// build Scope(_SB_) header + *(ssdt_ptr++) =0x10 ;// ScopeOp + ssdt_ptr =encodeLen (ssdt_ptr, length-1 ,3 ); + *(ssdt_ptr++) ='_' ; + *(ssdt_ptr++) ='S' ; + *(ssdt_ptr++) ='B' ; + *(ssdt_ptr++) ='_' ; + +for (i =0 ; i < nb_memdevs; i++) { + mem_base = (((u64)(entry->base_addr_high) <<32 )| entry->base_addr_low); + mem_len = (((u64)(entry->length_high) <<32 )| entry->length_low); + node = entry->proximity[0 ]; +build_memdev (ssdt_ptr, i, mem_base, mem_len, node); + ssdt_ptr +=SD_MEMSIZEOF ; + entry++; + } + +// build "Method(MTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CM00, Arg1)} ...}" + *(ssdt_ptr++) =0x14 ;// MethodOp + ssdt_ptr =encodeLen (ssdt_ptr,2 +5 +(12 *nb_memdevs),2 ); + *(ssdt_ptr++) ='M' ; + *(ssdt_ptr++) ='T' ; + *(ssdt_ptr++) ='F' ; + *(ssdt_ptr++) ='Y' ; + *(ssdt_ptr++) =0x02 ; +for (i=0 ; i<nb_memdevs; i++) { + *(ssdt_ptr++) =0xA0 ;// IfOp + ssdt_ptr =encodeLen (ssdt_ptr,11 ,1 ); + *(ssdt_ptr++) =0x93 ;// LEqualOp + *(ssdt_ptr++) =0x68 ;// Arg0Op + *(ssdt_ptr++) =0x0A ;// BytePrefix + *(ssdt_ptr++) = i; + *(ssdt_ptr++) =0x86 ;// NotifyOp + *(ssdt_ptr++) ='M' ; + *(ssdt_ptr++) ='P' ; + *(ssdt_ptr++) =getHex (i >>4 ); + *(ssdt_ptr++) =getHex (i); + *(ssdt_ptr++) =0x69 ;// Arg1Op + } + +// build "Name(MEON, Package() { One, One, ..., Zero, Zero, ... })" + *(ssdt_ptr++) =0x08 ;// NameOp + *(ssdt_ptr++) ='M' ; + *(ssdt_ptr++) ='E' ; + *(ssdt_ptr++) ='O' ; + *(ssdt_ptr++) ='N' ; + *(ssdt_ptr++) =0x12 ;// PackageOp + ssdt_ptr =encodeLen (ssdt_ptr,2 +1 +(1 *nb_memdevs),2 ); + *(ssdt_ptr++) = nb_memdevs; + + entry = mem; + memslot_status =0 ; +
src/acpi.c build_ssdt(void) · line 625
Quoted 10 lines
src/acpi.c +10
-0+for (i =0 ; i < nb_memdevs; i++) { + enabled =0 ; +if (i %8 ==0 ) + memslot_status =inb (MEM_BASE + i/8 ); + enabled = memslot_status &1 ; + mem_base = (((u64)(entry->base_addr_high) <<32 )| entry->base_addr_low); + mem_len = (((u64)(entry->length_high) <<32 )| entry->length_low); + *(ssdt_ptr++) = enabled ?0x01 :0x00 ; +if (enabled) +add_e820 (mem_base, mem_len,E820_RAM );
add_e820() is declared in memmap.h. You should include this header file, otherwise, seabios cannot be built.
Thanks
Wen Congyang
Quoted 89 lines
src/acpi.c +39
-6+ memslot_status = memslot_status >>1 ; + entry++; + } +build_header ((void *)ssdt,SSDT_SIGNATURE , ssdt_ptr - ssdt,1 ); + +return ssdt; +} +#include "ssdt-pcihp.hex" #define PCI_RMV_BASE 0xae0c@@ -618,9 +739,6 @@ build_srat(void) {int nb_numa_nodes =qemu_cfg_get_numa_nodes (); -if (nb_numa_nodes ==0 ) -return NULL ; -u64 *numadata =malloc_tmphigh (sizeof (u64) * (MaxCountCPUs + nb_numa_nodes));if (!numadata) {warn_noalloc ();@@ -629,10 +747,11 @@ build_srat(void)qemu_cfg_get_numa_data (numadata, MaxCountCPUs + nb_numa_nodes); +qemu_cfg_get_numa_data (&nb_hp_memslots,1 );struct system_resource_affinity_table *srat;int srat_size =sizeof (*srat) +sizeof (struct srat_processor_affinity ) * MaxCountCPUs + -sizeof (struct srat_memory_affinity ) * (nb_numa_nodes +2 ); +sizeof (struct srat_memory_affinity ) * (nb_numa_nodes + nb_hp_memslots +2 ); srat =malloc_high (srat_size);if (!srat) {@@ -667,7 +786,7 @@ build_srat(void)* from 640k-1M and possibly another one from 3.5G-4G. */ struct srat_memory_affinity *numamem = (void *)core; -int slots =0 ; +int slots =0 , node;u64 mem_len, mem_base, next_base =0 ;acpi_build_srat_memory (numamem,0 ,640 *1024 ,0 ,1 );@@ -694,10 +813,36 @@ build_srat(void) next_base += (1ULL <<32 ) - RamSize; }acpi_build_srat_memory (numamem, mem_base, mem_len, i-1 ,1 ); + numamem++; slots++; + + } + mem = (void *)numamem; + +if (nb_hp_memslots) { +u64 *hpmemdata =malloc_tmphigh (sizeof (u64) * (3 * nb_hp_memslots)); +if (!hpmemdata) { +warn_noalloc (); +free (hpmemdata); +free (numadata); +return NULL ; + } + +qemu_cfg_get_numa_data (hpmemdata,3 * nb_hp_memslots); + +for (i =1 ; i < nb_hp_memslots +1 ; ++i) { + mem_base = *hpmemdata++; + mem_len = *hpmemdata++; + node = *hpmemdata++; +acpi_build_srat_memory (numamem, mem_base, mem_len, node,1 ); + numamem++; + slots++; + } +free (hpmemdata); } -for (; slots < nb_numa_nodes +2 ; slots++) { + +for (; slots < nb_numa_nodes + nb_hp_memslots +2 ; slots++) {acpi_build_srat_memory (numamem,0 ,0 ,0 ,0 ); numamem++; }@@ -748,6 +893,7 @@ acpi_bios_init(void)ACPI_INIT_TABLE (build_madt ());ACPI_INIT_TABLE (build_hpet ());ACPI_INIT_TABLE (build_srat ()); +ACPI_INIT_TABLE (build_memssdt ());ACPI_INIT_TABLE (build_pcihp ());u16 i, external_tables =qemu_cfg_acpi_additional_tables ();
Re: [RFC PATCH v2 04/21][SeaBIOS] acpi: generate hotplug memory devices
Hi,
Quoted 5 lines · Wen Congyang
src/acpi.c build_ssdt(void) · line 625
Quoted 2 lines
src/acpi.c +2
-0+if (enabled) +add_e820 (mem_base, mem_len,E820_RAM );
add_e820()is declared inmemmap.h. You should include this header file, otherwise, seabios cannot be built.
thanks. you had the same comment on v1 but I forgot to address it. I will update.
- Vasilis
Quoted 94 lines
Thanks
Wen CongyangQuoted 89 lines
src/acpi.c +39
-6+ memslot_status = memslot_status >>1 ; + entry++; + } +build_header ((void *)ssdt,SSDT_SIGNATURE , ssdt_ptr - ssdt,1 ); + +return ssdt; +} +#include "ssdt-pcihp.hex" #define PCI_RMV_BASE 0xae0c@@ -618,9 +739,6 @@ build_srat(void) {int nb_numa_nodes =qemu_cfg_get_numa_nodes (); -if (nb_numa_nodes ==0 ) -return NULL ; -u64 *numadata =malloc_tmphigh (sizeof (u64) * (MaxCountCPUs + nb_numa_nodes));if (!numadata) {warn_noalloc ();@@ -629,10 +747,11 @@ build_srat(void)qemu_cfg_get_numa_data (numadata, MaxCountCPUs + nb_numa_nodes); +qemu_cfg_get_numa_data (&nb_hp_memslots,1 );struct system_resource_affinity_table *srat;int srat_size =sizeof (*srat) +sizeof (struct srat_processor_affinity ) * MaxCountCPUs + -sizeof (struct srat_memory_affinity ) * (nb_numa_nodes +2 ); +sizeof (struct srat_memory_affinity ) * (nb_numa_nodes + nb_hp_memslots +2 ); srat =malloc_high (srat_size);if (!srat) {@@ -667,7 +786,7 @@ build_srat(void)* from 640k-1M and possibly another one from 3.5G-4G. */ struct srat_memory_affinity *numamem = (void *)core; -int slots =0 ; +int slots =0 , node;u64 mem_len, mem_base, next_base =0 ;acpi_build_srat_memory (numamem,0 ,640 *1024 ,0 ,1 );@@ -694,10 +813,36 @@ build_srat(void) next_base += (1ULL <<32 ) - RamSize; }acpi_build_srat_memory (numamem, mem_base, mem_len, i-1 ,1 ); + numamem++; slots++; + + } + mem = (void *)numamem; + +if (nb_hp_memslots) { +u64 *hpmemdata =malloc_tmphigh (sizeof (u64) * (3 * nb_hp_memslots)); +if (!hpmemdata) { +warn_noalloc (); +free (hpmemdata); +free (numadata); +return NULL ; + } + +qemu_cfg_get_numa_data (hpmemdata,3 * nb_hp_memslots); + +for (i =1 ; i < nb_hp_memslots +1 ; ++i) { + mem_base = *hpmemdata++; + mem_len = *hpmemdata++; + node = *hpmemdata++; +acpi_build_srat_memory (numamem, mem_base, mem_len, node,1 ); + numamem++; + slots++; + } +free (hpmemdata); } -for (; slots < nb_numa_nodes +2 ; slots++) { + +for (; slots < nb_numa_nodes + nb_hp_memslots +2 ; slots++) {acpi_build_srat_memory (numamem,0 ,0 ,0 ,0 ); numamem++; }@@ -748,6 +893,7 @@ acpi_bios_init(void)ACPI_INIT_TABLE (build_madt ());ACPI_INIT_TABLE (build_hpet ());ACPI_INIT_TABLE (build_srat ()); +ACPI_INIT_TABLE (build_memssdt ());ACPI_INIT_TABLE (build_pcihp ());u16 i, external_tables =qemu_cfg_acpi_additional_tables ();
RFC PATCH v2 5/21 pciinit: Fix pcimem_start value
In reply to Vasilis LiaskovitisIn order to hotplug memory between RamSize and BUILD_PCIMEM_START, the pci window needs to start at BUILD_PCIMEM_START (0xe0000000). Otherwise, the guest cannot online new dimms at those ranges due to pci_root window conflicts. (workaround for linux guest is booting with pci=nocrs)
--- src/pciinit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
src/pciinit.c +1 -1
@@ -592,7 +592,7 @@ static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r)static void pci_bios_map_devices (struct pci_bus *busses) { - pcimem_start = RamSize; + pcimem_start =BUILD_PCIMEM_START ;if (pci_bios_init_root_regions (busses)) {struct pci_region r64_mem, r64_pref;
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 05/21][SeaBIOS] pciinit: Fix pcimem_start value
src/pciinit.c static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r) · line 595
Quoted 9 lines · Vasilis Liaskovitis
In order to hotplug memory between RamSize and
BUILD_PCIMEM_START, the pci window needs to start atBUILD_PCIMEM_START(0xe0000000). Otherwise, the guest cannot online new dimms at those ranges due topci_rootwindow conflicts. (workaround for linux guest is booting with pci=nocrs)static void
pci_bios_map_devices(struct pci_bus *busses){src/pciinit.c +1
-1- pcimem_start = RamSize; + pcimem_start =BUILD_PCIMEM_START ;
It isn't that simple. For the 32bit pci window it will work, but will leaves address space unused instead of assigning it to the 32bit pci window. For the 64bit pci window it will not work.
You have to walk the dimms and figure what the highest used address is, for both below-4g and above-4g. Then fill two variable with it and make the pci init code use that instead of RamSize and RamSizeOver4G.
cheers,
Gerd
Re: [RFC PATCH v2 05/21][SeaBIOS] pciinit: Fix pcimem_start value
Hi,
Quoted 11 lines · Gerd Hoffmann
src/pciinit.c static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r) · line 595
Quoted 9 lines · Vasilis Liaskovitis
In order to hotplug memory between RamSize and
BUILD_PCIMEM_START, the pci window needs to start atBUILD_PCIMEM_START(0xe0000000). Otherwise, the guest cannot online new dimms at those ranges due topci_rootwindow conflicts. (workaround for linux guest is booting with pci=nocrs)static void
pci_bios_map_devices(struct pci_bus *busses){src/pciinit.c +1
-1- pcimem_start = RamSize; + pcimem_start =BUILD_PCIMEM_START ;
Quoted 7 lines
It isn't that simple. For the 32bit pci window it will work, but will leaves address space unused instead of assigning it to the 32bit pci window. For the 64bit pci window it will not work.
You have to walk the dimms and figure what the highest used address is, for both below-4g and above-4g. Then fill two variable with it and make the pci init code use that instead of RamSize and RamSizeOver4G.
I see. I already have these values values computed in qemu-kvm, so I can pass them in a paravirt struct, or infer them from the dimm/srat paravirt info that I already pass to seabios.
If i understand correctly, we would like the pcimem windows to use the maximum possible address space (constrained by the exact dimms/ranges which are defined) instead of leaving unused space.
thanks,
- Vasilis
Re: [RFC PATCH v2 05/21][SeaBIOS] pciinit: Fix pcimem_start value
Quoted 18 lines · Vasilis Liaskovitis
Hi,
Quoted 15 lines · Gerd Hoffmann
src/pciinit.c static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r) · line 595
Quoted 9 lines · Vasilis Liaskovitis
In order to hotplug memory between RamSize and
BUILD_PCIMEM_START, the pci window needs to start atBUILD_PCIMEM_START(0xe0000000). Otherwise, the guest cannot online new dimms at those ranges due topci_rootwindow conflicts. (workaround for linux guest is booting with pci=nocrs)static void
pci_bios_map_devices(struct pci_bus *busses){src/pciinit.c +1
-1- pcimem_start = RamSize; + pcimem_start =BUILD_PCIMEM_START ;It isn't that simple. For the 32bit pci window it will work, but will leaves address space unused instead of assigning it to the 32bit pci window. For the 64bit pci window it will not work.
Quoted 7 lines
Quoted 3 lines
You have to walk the dimms and figure what the highest used address is, for both below-4g and above-4g. Then fill two variable with it and make the pci init code use that instead of RamSize and RamSizeOver4G.
I see. I already have these values values computed in qemu-kvm, so I can pass them in a paravirt struct, or infer them from the dimm/srat paravirt info that I already pass to seabios.
I'd suggest to infer from the dimm info, to limit the amout of information which needs to be passed from qemu to seabios.
Quoted 3 lines
If i understand correctly, we would like the pcimem windows to use the maximum possible address space (constrained by the exact dimms/ranges which are defined) instead of leaving unused space.
Yes, for the 32bit pci window.
The 64bit pci window is mapped above all memory, and it must likewise consider defined+unfilled dimms so the start address doesn't collide with memory hot-plugged above 4G later on.
cheers,
Gerd
Re: [RFC PATCH v2 05/21][SeaBIOS] pciinit: Fix pcimem_start value
Quoted 23 lines · Gerd Hoffmann
Quoted 22 lines · Vasilis Liaskovitis
Hi,
Quoted 18 lines · Gerd Hoffmann
src/pciinit.c static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r) · line 595
Quoted 9 lines · Vasilis Liaskovitis
In order to hotplug memory between RamSize and
BUILD_PCIMEM_START, the pci window needs to start atBUILD_PCIMEM_START(0xe0000000). Otherwise, the guest cannot online new dimms at those ranges due topci_rootwindow conflicts. (workaround for linux guest is booting with pci=nocrs)static void
pci_bios_map_devices(struct pci_bus *busses){src/pciinit.c +1
-1- pcimem_start = RamSize; + pcimem_start =BUILD_PCIMEM_START ;It isn't that simple. For the 32bit pci window it will work, but will leaves address space unused instead of assigning it to the 32bit pci window. For the 64bit pci window it will not work.
You have to walk the dimms and figure what the highest used address is, for both below-4g and above-4g. Then fill two variable with it and make the pci init code use that instead of RamSize and RamSizeOver4G.
Quoted 6 lines
Quoted 3 lines
I see. I already have these values values computed in qemu-kvm, so I can pass them in a paravirt struct, or infer them from the dimm/srat paravirt info that I already pass to seabios.
I'd suggest to infer from the dimm info, to limit the amout of information which needs to be passed from qemu to seabios.
ok.Currently dimm info is processed in bios_init_tables(), which is called after pci_setup(). I 'll see if i can do the processing earlier.
Quoted 10 lines
Quoted 4 lines
If i understand correctly, we would like the pcimem windows to use the maximum possible address space (constrained by the exact dimms/ranges which are defined) instead of leaving unused space.
Yes, for the 32bit pci window.
The 64bit pci window is mapped above all memory, and it must likewise consider defined+unfilled dimms so the start address doesn't collide with memory hot-plugged above 4G later on.
yes, understood.
thanks,
- Vasilis
RFC PATCH v2 6/21 dimm: Implement memory device abstraction
In reply to Vasilis LiaskovitisEach hotplug-able memory slot is a SysBusDevice. A hot-add operation for a particular dimm creates a new MemoryRegion of the given physical address offset, size and node proximity, and attaches it to main system memory as a sub_region. A hot-remove operation detaches and frees the MemoryRegion from system memory.
This prototype still lacks proper qdev integration: a separate hotplug side-channel is used and main system bus hotplug capability is ignored.
--- hw/Makefile.objs | 2 +- hw/dimm.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 58 +++++++++++++ 3 files changed, 293 insertions(+), 1 deletions(-) create mode 100644 hw/dimm.c create mode 100644 hw/dimm.h
hw/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o hw-obj-$(CONFIG_PCSPK) += pcspk.o hw-obj-$(CONFIG_PCKBD) += pckbd.o hw-obj-$(CONFIG_FDC) += fdc.o -hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o +hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o dimm.o hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_I82374) += i82374.o
hw/dimm.c new file +234 -0
234 lines not on this page · raw message
hw/dimm.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 06/21] dimm: Implement memory device abstraction
Quoted 56 lines · Vasilis Liaskovitis
Each hotplug-able memory slot is a SysBusDevice. A hot-add operation for a particular dimm creates a new MemoryRegion of the given physical address offset, size and node proximity, and attaches it to main system memory as a
sub_region. A hot-remove operation detaches and frees the MemoryRegion from system memory.This prototype still lacks proper qdev integration: a separate hotplug side-channel is used and main system bus hotplug capability is ignored.
Signed-off-by Vasilis Liaskovitis <[email protected]>--- hw/Makefile.objs | 2 +- hw/dimm.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 58 +++++++++++++ 3 files changed, 293 insertions(+), 1 deletions(-) create mode 100644 hw/dimm.c create mode 100644 hw/dimm.hhw/Makefile.objs +1
-1@@ -26,7 +26,7 @@ hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o hw-obj-$(CONFIG_PCSPK) += pcspk.o hw-obj-$(CONFIG_PCKBD) += pckbd.o hw-obj-$(CONFIG_FDC) += fdc.o -hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o +hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o dimm.o hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_I82374) += i82374.ohw/dimm.c new file +18
-0@@ -0,0 +1,234 @@ +/* +* Dimm device for Memory Hotplug +* +* Copyright ProfitBricks GmbH 2012 +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ +
hw/dimm.c line 28
Quoted 10 lines
hw/dimm.c new file +10
-0+#include "trace.h" +#include "qdev.h" +#include "dimm.h" +#include <time.h> +#include "../exec-memory.h" +#include "qmp-commands.h" + +static DeviceState *dimm_hotplug_qdev; +static dimm_hotplug_fn dimm_hotplug; +static QTAILQ_HEAD(Dimmlist, DimmState) dimmlist;
Using global state does not look right. It should always be possible to pass around structures to avoid it.
hw/dimm.c line 34
Quoted 6 lines
hw/dimm.c new file +6
-0+ +static Property dimm_properties[] = { +DEFINE_PROP_END_OF_LIST () +}; + +void dimm_populate (DimmState *s)
All functions are global and exported but there does not seem to be users. Please make all static which you can.
Quoted 46 lines
hw/dimm.c new file +46
-0+{ +DeviceState *dev= (DeviceState *)s; +MemoryRegion *new =NULL ; + + new =g_malloc (sizeof (MemoryRegion)); +memory_region_init_ram (new, dev->id, s->size); +vmstate_register_ram_global (new); +memory_region_add_subregion (get_system_memory (), s->start, new); + s->mr = new; + s->populated = true; +} + + +void dimm_depopulate (DimmState *s) +{ +assert (s); +if (s->populated) { +vmstate_unregister_ram (s->mr,NULL ); +memory_region_del_subregion (get_system_memory (), s->mr); +memory_region_destroy (s->mr); + s->populated = false; + s->mr =NULL ; + } +} + +DimmState *dimm_create (char *id,uint64_t size,uint64_t node,uint32_t + dimm_idx,bool populated) +{ +DeviceState *dev; +DimmState *mdev; + + dev =sysbus_create_simple ("dimm" ,-1 ,NULL ); + dev->id = id; + + mdev =DIMM (dev); + mdev->idx = dimm_idx; + mdev->start =0 ; + mdev->size = size; + mdev->node = node; + mdev->populated = populated; +QTAILQ_INSERT_TAIL (&dimmlist, mdev, nextdimm); +return mdev; +} + +void dimm_register_hotplug (dimm_hotplug_fn hotplug,DeviceState *qdev) +{
hw/dimm.c line 90
Quoted 10 lines
hw/dimm.c new file +10
-0+ dimm_hotplug_qdev = qdev; + dimm_hotplug = hotplug; +dimm_scan_populated (); +} + +void dimm_activate (DimmState *slot) +{ +dimm_populate (slot); +if (dimm_hotplug) +dimm_hotplug (dimm_hotplug_qdev, (SysBusDevice *)slot,1 );
Why the cast?
Also braces, please check your patches with checkpatch.pl.
hw/dimm.c line 99
Quoted 9 lines
hw/dimm.c new file +9
-0+} + +void dimm_deactivate (DimmState *slot) +{ +if (dimm_hotplug) +dimm_hotplug (dimm_hotplug_qdev, (SysBusDevice *)slot,0 ); +} + +DimmState *dimm_find_from_name (char *id)
const char *id?
Quoted 12 lines
hw/dimm.c new file +12
-0+{ +Error *err =NULL ; +DeviceState *qdev; +const char *type; + qdev =qdev_find_recursive (sysbus_get_default (), id); +if (qdev) { + type =object_property_get_str (OBJECT (qdev),"type" , &err); +if (!type) { +return NULL ; + } +if (!strcmp (type,"dimm" )) { +return DIMM (qdev);
hw/dimm.c line 121
Quoted 10 lines
hw/dimm.c new file +10
-0+ } + } +return NULL ; +} + +int dimm_do (Monitor *mon,const QDict *qdict,bool add) +{ +DimmState *slot =NULL ; + +char *id = (char *)qdict_get_try_str (qdict,"id" );
Why this cast?
Quoted 119 lines
hw/dimm.c new file +113
-0+if (!id) { +fprintf (stderr,"ERROR %s invalid id\n" ,__FUNCTION__); +return 1 ; + } + + slot =dimm_find_from_name (id); + +if (!slot) { +fprintf (stderr,"%s no slot %s found\n" , __FUNCTION__, id); +return 1 ; + } + +if (add) { +if (slot->populated) { +fprintf (stderr,"ERROR %s slot %s already populated\n" , + __FUNCTION__, id); +return 1 ; + } +dimm_activate (slot); + } +else { +if (!slot->populated) { +fprintf (stderr,"ERROR %s slot %s is not populated\n" , + __FUNCTION__, id); +return 1 ; + } +dimm_deactivate (slot); + } + +return 0 ; +} + +DimmState *dimm_find_from_idx (uint32_t idx) +{ +DimmState *slot; + + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (slot->idx == idx) { +return slot; + } + } +return NULL ; +} + +/* used to calculate physical address offsets for all dimms */ +void dimm_calc_offsets (dimm_calcoffset_fn calcfn) +{ +DimmState *slot; + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (!slot->start) + slot->start =calcfn (slot->size); + } +} + +/* used to populate and activate dimms at boot time */ +void dimm_scan_populated (void ) +{ +DimmState *slot; + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (slot->populated && !slot->mr) { +dimm_activate (slot); + } + } +} + +void dimm_notify (uint32_t idx,uint32_t event) +{ +DimmState *s; + s =dimm_find_from_idx (idx); +assert (s !=NULL ); + +switch (event) { +case DIMM_REMOVE_SUCCESS : +dimm_depopulate (s); +break ; +default : +break ; + } +} + +static int dimm_init (SysBusDevice *s) +{ +DimmState *slot; + slot =DIMM (s); + slot->mr =NULL ; + slot->populated = false; +return 0 ; +} + +static void dimm_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sc =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = dimm_properties; + sc->init = dimm_init; + dimm_hotplug =NULL ; +QTAILQ_INIT (&dimmlist); +} + +static TypeInfo dimm_info = { + .name ="dimm" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (DimmState), + .class_init = dimm_class_init, +}; + +static void dimm_register_types (void ) +{ +type_register_static (&dimm_info); +} + +type_init (dimm_register_types)hw/dimm.h new file +0
-0
hw/dimm.h line 2
Quoted 2 lines
hw/dimm.h new file +2
-0@@ -0,0 +1,58 @@ +#ifndef QEMU_DIMM_H +#define QEMU_DIMM_H
Should be HW_DIMM_H.
Quoted 60 lines
hw/dimm.h new file +56
-1+ +#include "qemu-common.h" +#include "memory.h" +#include "sysbus.h" +#include "qapi-types.h" +#include "qemu-queue.h" +#include "cpus.h" +#define MAX_DIMMS 255 +#define DIMM_BITMAP_BYTES (MAX_DIMMS + 7) / 8 +#define DEFAULT_DIMMSIZE 1024*1024*1024 + +typedef enum { +DIMM_REMOVE_SUCCESS =0 , +DIMM_REMOVE_FAIL =1 , +DIMM_ADD_SUCCESS =2 , +DIMM_ADD_FAIL =3 +}dimm_hp_result_code ; + +#define TYPE_DIMM "dimm" +#define DIMM (obj) \ + OBJECT_CHECK(DimmState, (obj), TYPE_DIMM) +#define DIMM_CLASS (klass) \ + OBJECT_CLASS_CHECK(DimmClass, (obj), TYPE_DIMM) +#define DIMM_GET_CLASS (obj) \ + OBJECT_GET_CLASS(DimmClass, (obj), TYPE_DIMM) + +typedef struct DimmState { +SysBusDevice busdev; +uint32_t idx;/* index in memory hotplug register/bitmap */ +ram_addr_t start;/* starting physical address */ +ram_addr_t size; +uint32_t node;/* numa node proximity */ +MemoryRegion *mr;/* MemoryRegion for this slot. !NULL only if populated */ +bool populated;/* 1 means device has been hotplugged. Default is 0. */ +QTAILQ_ENTRY (DimmState) nextdimm; +}DimmState ; + +typedef int (*dimm_hotplug_fn )(DeviceState *qdev,SysBusDevice *dev,int add); +typedef target_phys_addr_t (*dimm_calcoffset_fn )(uint64_t size); + +DimmState *dimm_create (char *id,uint64_t size,uint64_t node,uint32_t + dimm_idx,bool populated); +void dimm_populate (DimmState *s); +void dimm_depopulate (DimmState *s); +int dimm_do (Monitor *mon,const QDict *qdict,bool add); +DimmState *dimm_find_from_idx (uint32_t idx); +DimmState *dimm_find_from_name (char *id); +void dimm_register_hotplug (dimm_hotplug_fn hotplug,DeviceState *qdev); +void dimm_calc_offsets (dimm_calcoffset_fn calcfn); +void dimm_activate (DimmState *slot); +void dimm_deactivate (DimmState *slot); +void dimm_scan_populated (void ); +void dimm_notify (uint32_t idx,uint32_t event); + + +#endif --1.7.9
Re: [RFC PATCH v2 06/21] dimm: Implement memory device abstraction
Hi,
Quoted 63 lines · Blue Swirl
Quoted 61 lines · Vasilis Liaskovitis
Each hotplug-able memory slot is a SysBusDevice. A hot-add operation for a particular dimm creates a new MemoryRegion of the given physical address offset, size and node proximity, and attaches it to main system memory as a
sub_region. A hot-remove operation detaches and frees the MemoryRegion from system memory.This prototype still lacks proper qdev integration: a separate hotplug side-channel is used and main system bus hotplug capability is ignored.
Signed-off-by Vasilis Liaskovitis <[email protected]>--- hw/Makefile.objs | 2 +- hw/dimm.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 58 +++++++++++++ 3 files changed, 293 insertions(+), 1 deletions(-) create mode 100644 hw/dimm.c create mode 100644 hw/dimm.hhw/Makefile.objs +1
-1@@ -26,7 +26,7 @@ hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o hw-obj-$(CONFIG_PCSPK) += pcspk.o hw-obj-$(CONFIG_PCKBD) += pckbd.o hw-obj-$(CONFIG_FDC) += fdc.o -hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o +hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o dimm.o hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_I82374) += i82374.ohw/dimm.c new file +23
-0@@ -0,0 +1,234 @@ +/* +* Dimm device for Memory Hotplug +* +* Copyright ProfitBricks GmbH 2012 +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include "trace.h" +#include "qdev.h" +#include "dimm.h" +#include <time.h> +#include "../exec-memory.h"
Quoted 8 lines
hw/dimm.c line 28
Quoted 5 lines
hw/dimm.c new file +5
-0+#include "qmp-commands.h" + +static DeviceState *dimm_hotplug_qdev; +static dimm_hotplug_fn dimm_hotplug; +static QTAILQ_HEAD(Dimmlist, DimmState) dimmlist;Using global state does not look right. It should always be possible to pass around structures to avoid it.
ok, I 'll try to remove the global state.
Quoted 10 lines
hw/dimm.c line 34
Quoted 7 lines
hw/dimm.c new file +6
-0+ +static Property dimm_properties[] = { +DEFINE_PROP_END_OF_LIST () +}; + +void dimm_populate (DimmState *s)All functions are global and exported but there does not seem to be users. Please make all static which you can.
will do
Quoted 51 lines
Quoted 51 lines
hw/dimm.c new file +50
-0+{ +DeviceState *dev= (DeviceState *)s; +MemoryRegion *new =NULL ; + + new =g_malloc (sizeof (MemoryRegion)); +memory_region_init_ram (new, dev->id, s->size); +vmstate_register_ram_global (new); +memory_region_add_subregion (get_system_memory (), s->start, new); + s->mr = new; + s->populated = true; +} + + +void dimm_depopulate (DimmState *s) +{ +assert (s); +if (s->populated) { +vmstate_unregister_ram (s->mr,NULL ); +memory_region_del_subregion (get_system_memory (), s->mr); +memory_region_destroy (s->mr); + s->populated = false; + s->mr =NULL ; + } +} + +DimmState *dimm_create (char *id,uint64_t size,uint64_t node,uint32_t + dimm_idx,bool populated) +{ +DeviceState *dev; +DimmState *mdev; + + dev =sysbus_create_simple ("dimm" ,-1 ,NULL ); + dev->id = id; + + mdev =DIMM (dev); + mdev->idx = dimm_idx; + mdev->start =0 ; + mdev->size = size; + mdev->node = node; + mdev->populated = populated; +QTAILQ_INSERT_TAIL (&dimmlist, mdev, nextdimm); +return mdev; +} + +void dimm_register_hotplug (dimm_hotplug_fn hotplug,DeviceState *qdev) +{ + dimm_hotplug_qdev = qdev; + dimm_hotplug = hotplug; +dimm_scan_populated (); +}
Quoted 8 lines
hw/dimm.c line 90
Quoted 6 lines
hw/dimm.c new file +6
-0+ +void dimm_activate (DimmState *slot) +{ +dimm_populate (slot); +if (dimm_hotplug) +dimm_hotplug (dimm_hotplug_qdev, (SysBusDevice *)slot,1 );Why the cast?
dimm_hotplug accepts SysBusDevice, not DimmState, though that can be changed.
Quoted 3 lines
Also braces, please check your patches with checkpatch.pl.
ok, I 'll do checks with checkpatch.pl.
Quoted 11 lines
hw/dimm.c line 99
Quoted 9 lines
hw/dimm.c new file +9
-0+} + +void dimm_deactivate (DimmState *slot) +{ +if (dimm_hotplug) +dimm_hotplug (dimm_hotplug_qdev, (SysBusDevice *)slot,0 ); +} + +DimmState *dimm_find_from_name (char *id)const char *id?
ok
Quoted 17 lines
Quoted 17 lines
hw/dimm.c new file +16
-0+{ +Error *err =NULL ; +DeviceState *qdev; +const char *type; + qdev =qdev_find_recursive (sysbus_get_default (), id); +if (qdev) { + type =object_property_get_str (OBJECT (qdev),"type" , &err); +if (!type) { +return NULL ; + } +if (!strcmp (type,"dimm" )) { +return DIMM (qdev); + } + } +return NULL ; +}
Quoted 8 lines
hw/dimm.c line 121
Quoted 6 lines
hw/dimm.c new file +6
-0+ +int dimm_do (Monitor *mon,const QDict *qdict,bool add) +{ +DimmState *slot =NULL ; + +char *id = (char *)qdict_get_try_str (qdict,"id" );Why this cast?
unneeded, because id should be declared as const char*. will fix.
Quoted 116 lines
Quoted 116 lines
hw/dimm.c new file +113
-0+if (!id) { +fprintf (stderr,"ERROR %s invalid id\n" ,__FUNCTION__); +return 1 ; + } + + slot =dimm_find_from_name (id); + +if (!slot) { +fprintf (stderr,"%s no slot %s found\n" , __FUNCTION__, id); +return 1 ; + } + +if (add) { +if (slot->populated) { +fprintf (stderr,"ERROR %s slot %s already populated\n" , + __FUNCTION__, id); +return 1 ; + } +dimm_activate (slot); + } +else { +if (!slot->populated) { +fprintf (stderr,"ERROR %s slot %s is not populated\n" , + __FUNCTION__, id); +return 1 ; + } +dimm_deactivate (slot); + } + +return 0 ; +} + +DimmState *dimm_find_from_idx (uint32_t idx) +{ +DimmState *slot; + + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (slot->idx == idx) { +return slot; + } + } +return NULL ; +} + +/* used to calculate physical address offsets for all dimms */ +void dimm_calc_offsets (dimm_calcoffset_fn calcfn) +{ +DimmState *slot; + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (!slot->start) + slot->start =calcfn (slot->size); + } +} + +/* used to populate and activate dimms at boot time */ +void dimm_scan_populated (void ) +{ +DimmState *slot; + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (slot->populated && !slot->mr) { +dimm_activate (slot); + } + } +} + +void dimm_notify (uint32_t idx,uint32_t event) +{ +DimmState *s; + s =dimm_find_from_idx (idx); +assert (s !=NULL ); + +switch (event) { +case DIMM_REMOVE_SUCCESS : +dimm_depopulate (s); +break ; +default : +break ; + } +} + +static int dimm_init (SysBusDevice *s) +{ +DimmState *slot; + slot =DIMM (s); + slot->mr =NULL ; + slot->populated = false; +return 0 ; +} + +static void dimm_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sc =SYS_BUS_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = dimm_properties; + sc->init = dimm_init; + dimm_hotplug =NULL ; +QTAILQ_INIT (&dimmlist); +} + +static TypeInfo dimm_info = { + .name ="dimm" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (DimmState), + .class_init = dimm_class_init, +}; + +static void dimm_register_types (void ) +{ +type_register_static (&dimm_info); +} + +type_init (dimm_register_types)hw/dimm.h new file +0
-0
Quoted 8 lines
hw/dimm.h line 2
Quoted 6 lines
index 0000000..643f319
hw/dimm.h new file +2
-0@@ -0,0 +1,58 @@ +#ifndef QEMU_DIMM_H +#define QEMU_DIMM_H Should be
HW_DIMM_H.
ok.
Quoted 61 lines
Quoted 61 lines
hw/dimm.h new file +56
-1+ +#include "qemu-common.h" +#include "memory.h" +#include "sysbus.h" +#include "qapi-types.h" +#include "qemu-queue.h" +#include "cpus.h" +#define MAX_DIMMS 255 +#define DIMM_BITMAP_BYTES (MAX_DIMMS + 7) / 8 +#define DEFAULT_DIMMSIZE 1024*1024*1024 + +typedef enum { +DIMM_REMOVE_SUCCESS =0 , +DIMM_REMOVE_FAIL =1 , +DIMM_ADD_SUCCESS =2 , +DIMM_ADD_FAIL =3 +}dimm_hp_result_code ; + +#define TYPE_DIMM "dimm" +#define DIMM (obj) \ + OBJECT_CHECK(DimmState, (obj), TYPE_DIMM) +#define DIMM_CLASS (klass) \ + OBJECT_CLASS_CHECK(DimmClass, (obj), TYPE_DIMM) +#define DIMM_GET_CLASS (obj) \ + OBJECT_GET_CLASS(DimmClass, (obj), TYPE_DIMM) + +typedef struct DimmState { +SysBusDevice busdev; +uint32_t idx;/* index in memory hotplug register/bitmap */ +ram_addr_t start;/* starting physical address */ +ram_addr_t size; +uint32_t node;/* numa node proximity */ +MemoryRegion *mr;/* MemoryRegion for this slot. !NULL only if populated */ +bool populated;/* 1 means device has been hotplugged. Default is 0. */ +QTAILQ_ENTRY (DimmState) nextdimm; +}DimmState ; + +typedef int (*dimm_hotplug_fn )(DeviceState *qdev,SysBusDevice *dev,int add); +typedef target_phys_addr_t (*dimm_calcoffset_fn )(uint64_t size); + +DimmState *dimm_create (char *id,uint64_t size,uint64_t node,uint32_t + dimm_idx,bool populated); +void dimm_populate (DimmState *s); +void dimm_depopulate (DimmState *s); +int dimm_do (Monitor *mon,const QDict *qdict,bool add); +DimmState *dimm_find_from_idx (uint32_t idx); +DimmState *dimm_find_from_name (char *id); +void dimm_register_hotplug (dimm_hotplug_fn hotplug,DeviceState *qdev); +void dimm_calc_offsets (dimm_calcoffset_fn calcfn); +void dimm_activate (DimmState *slot); +void dimm_deactivate (DimmState *slot); +void dimm_scan_populated (void ); +void dimm_notify (uint32_t idx,uint32_t event); + + +#endif --1.7.9
RFC PATCH v2 7/21 acpi_piix4: Implement memory device hotplug registers
In reply to Vasilis LiaskovitisA 32-byte register is used to present up to 256 hotplug-able memory devices to BIOS and OSPM. Hot-add and hot-remove functions trigger an ACPI hotplug event through these. Only reads are allowed from these registers.
An ACPI hot-remove event but needs to wait for OSPM to eject the device. We use a single-byte register to know when OSPM has called the _EJ function for a particular dimm. A write to this byte will depopulate the respective dimm. Only writes are allowed to this byte.
v1->v2:mems_sts address moved from 0xaf20 to 0xaf80 (to accomodate more space for cpu-hotplugging in the future)._EJ array is reduced to a single byte.
Add documentation in docs/specs/acpi_hotplug.txt
--- docs/specs/acpi_hotplug.txt | 22 +++++++++++++ hw/acpi_piix4.c | 73 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 docs/specs/acpi_hotplug.txt
docs/specs/acpi_hotplug.txt new file +22 -0
@@ -0,0 +1,22 @@ +QEMU<->ACPI BIOS hotplug interface +-------------------------------------- +This document describes the interface between QEMU and the ACPI BIOS for non-PCI +space. For the PCI interface please look at docs/specs/acpi_pci_hotplug.txt + +QEMU<->ACPI BIOS memory hotplug interface +-------------------------------------- + +Memory Dimm status array (IO port 0xaf80-0xaf9f, 1-byte access): +--------------------------------------------------------------- +Dimm hot-plug notification pending. One bit per slot. + +Read by ACPI BIOS GPE.3 handler to notify OS of memory hot-add or hot-remove +events. Read-only. + +Memory Dimm ejection success notification (IO port 0xafa0, 1-byte access): +--------------------------------------------------------------- +Dimm hot-remove _EJ0 notification. Byte value indicates Dimm slot that was +ejected. + +Written by ACPI memory device _EJ0 method to notify qemu of successfull +hot-removal. Write-only.
hw/acpi_piix4.c +69 -4
134 lines not on this page · raw message
Signature · 1 line
1.7.9
RFC PATCH v2 8/21 pc: calculate dimm physical addresses and adjust memory map
In reply to Vasilis LiaskovitisDimm physical address offsets are calculated automatically and memory map is adjusted accordingly. If a DIMM can fit before the PCI_HOLE_START (currently 0xe0000000), it will be added normally, otherwise its physical address will be above 4GB.
--- hw/pc.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/pc.h | 6 ++++++ hw/pc_piix.c | 18 ++++++++++++------ vl.c | 1 + 4 files changed, 60 insertions(+), 6 deletions(-)
hw/pc.c +41 -0
@@ -48,6 +48,7 @@#include "memory.h" #include "exec-memory.h" #include "arch_init.h" +#include "dimm.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS
@@ -89,6 +90,9 @@ struct e820_table {static struct e820_table e820_table;struct hpet_fw_config hpet_cfg = {.count =UINT8_MAX }; +ram_addr_t below_4g_hp_mem_size =0 ; +ram_addr_t above_4g_hp_mem_size =0 ; +extern target_phys_addr_t ram_hp_offset;void gsi_handler (void *opaque,int n,int level) {GSIState *s = opaque;
@@ -1182,3 +1186,40 @@ void pc_pci_device_init(PCIBus *pci_bus)pci_create_simple (pci_bus,-1 ,"lsi53c895a" ); } } + + +/* Function to configure memory offsets of hotpluggable dimms */ + +target_phys_addr_t pc_set_hp_memory_offset (uint64_t size) +{ +target_phys_addr_t ret; + +/* on first call, initialize ram_hp_offset */ +if (!ram_hp_offset) { +if (ram_size >=PCI_HOLE_START ) { + ram_hp_offset =0x100000000LL + (ram_size -PCI_HOLE_START ); + }else { + ram_hp_offset = ram_size; + } + } + +if (ram_hp_offset >=0x100000000LL ) { + ret = ram_hp_offset; + above_4g_hp_mem_size += size; + ram_hp_offset += size; + } +/* if dimm fits before pci hole, append it normally */ +else if (ram_hp_offset + size <=PCI_HOLE_START ) { + ret = ram_hp_offset; + below_4g_hp_mem_size += size; + ram_hp_offset += size; + } +/* otherwise place it above 4GB */ +else { + ret =0x100000000LL ; + above_4g_hp_mem_size += size; + ram_hp_offset =0x100000000LL + size; + } + +return ret; +}
hw/pc.h +6 -0
@@ -10,6 +10,7 @@#include "memory.h" #include "ioapic.h" +#define PCI_HOLE_START 0xe0000000/* PC-style peripherals (also used by other machines). */ /* serial.c */
@@ -218,6 +219,11 @@ static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd)/* pc_sysfw.c */ void pc_system_firmware_init (MemoryRegion *rom_memory); +/* memory hotplug */ +target_phys_addr_t pc_set_hp_memory_offset (uint64_t size); +extern ram_addr_t below_4g_hp_mem_size; +extern ram_addr_t above_4g_hp_mem_size; +/* e820 types */ #define E820_RAM 1#define E820_RESERVED 2
hw/pc_piix.c +12 -6
@@ -43,6 +43,7 @@#include "xen.h" #include "memory.h" #include "exec-memory.h" +#include "dimm.h" #ifdef CONFIG_XEN # include <xen/hvm/hvm_info_table.h> #endif
@@ -155,9 +156,9 @@ static void pc_init1(MemoryRegion *system_memory,kvmclock_create (); } -if (ram_size >=0xe0000000 ) { - above_4g_mem_size = ram_size -0xe0000000 ; - below_4g_mem_size =0xe0000000 ; +if (ram_size >=PCI_HOLE_START ) { + above_4g_mem_size = ram_size -PCI_HOLE_START ; + below_4g_mem_size =PCI_HOLE_START ; }else { above_4g_mem_size =0 ; below_4g_mem_size = ram_size;
@@ -172,6 +173,9 @@ static void pc_init1(MemoryRegion *system_memory, rom_memory = system_memory; } +/* adjust memory map for hotplug dimms */ +dimm_calc_offsets (pc_set_hp_memory_offset); +/* allocate ram and load rom/bios */ if (!xen_enabled ()) { fw_cfg = pc_memory_init(system_memory,
@@ -192,9 +196,11 @@ static void pc_init1(MemoryRegion *system_memory,if (pci_enabled) { pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi, system_memory, system_io, ram_size, - below_4g_mem_size, - 0x100000000ULL - below_4g_mem_size, - 0x100000000ULL + above_4g_mem_size, + below_4g_mem_size + below_4g_hp_mem_size, + 0x100000000ULL - below_4g_mem_size + - below_4g_hp_mem_size, + 0x100000000ULL + above_4g_mem_size + + above_4g_hp_mem_size, (sizeof(target_phys_addr_t) == 4 ? 0 : ((uint64_t)1 << 62)),
vl.c +1 -0
@@ -176,6 +176,7 @@ DisplayType display_type = DT_DEFAULT;int display_remote =0 ;const char * keyboard_layout =NULL ;ram_addr_t ram_size; +ram_addr_t ram_hp_offset;const char *mem_path =NULL ;#ifdef MAP_POPULATE int mem_prealloc =0 ;/* force preallocation of physical target memory */
Signature · 1 line
1.7.9
RFC PATCH v2 9/21 pc: Add dimm paravirt SRAT info
In reply to Vasilis LiaskovitisThe numa_fw_cfg paravirt interface is extended to include SRAT information for all hotplug-able dimms. There are 3 words for each hotplug-able memory slot, denoting start address, size and node proximity. The new info is appended after existing numa info, so that the fw_cfg layout does not break. This information is used by Seabios to build hotplug memory device objects at runtime. nb_numa_nodes is set to 1 by default (not 0), so that we always pass srat info to SeaBIOS.
v1->v2:
Dimm SRAT info (#dimms) is appended at end of existing numa fw_cfg in order not to break existing layout
Documentation of the new fwcfg layout is included in docs/specs/fwcfg.txt
--- docs/specs/fwcfg.txt | 28 ++++++++++++++++++++++++++ hw/pc.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- vl.c | 2 +- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 docs/specs/fwcfg.txt
docs/specs/fwcfg.txt new file +28 -0
@@ -0,0 +1,28 @@ +QEMU<->BIOS Paravirt Documentation +-------------------------------------- + +This document describes paravirt data structures passed from QEMU to BIOS. + +fw_cfg SRAT paravirt info +-------------------- +The SRAT info passed from QEMU to BIOS has the following layout: + +----------------------------------------------------------------------------------------------- +#nodes | cpu0_pxm | cpu1_pxm | ... | cpulast_pxm | node0_mem | node1_mem | ... | nodelast_mem + +----------------------------------------------------------------------------------------------- +#dimms | dimm0_start | dimm0_sz | dimm0_pxm | ... | dimmlast_start | dimmlast_sz | dimmlast_pxm + +Entry 0 contains the number of numa nodes (nb_numa_nodes). + +Entries 1..max_cpus: The next max_cpus entries describe node proximity for each +one of the vCPUs in the system. + +Entries max_cpus+1..max_cpus+nb_numa_nodes+1: The next nb_numa_nodes entries +describe the memory size for each one of the NUMA nodes in the system. + +Entry max_cpus+nb_numa_nodes+1 contains the number of memory dimms (nb_hp_dimms) + +The last 3 * nb_hp_dimms entries are organized in triplets: Each triplet contains +the physical address offset, size (in bytes), and node proximity for the +respective dimm.
hw/pc.c +51 -2
82 lines not on this page · raw message
vl.c +1 -1
@@ -2335,7 +2335,7 @@ int main(int argc, char **argv, char **envp) node_cpumask[i] =0 ; } - nb_numa_nodes =0 ; + nb_numa_nodes =1 ; nb_nics =0 ; autostart=1 ;
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 09/21] pc: Add dimm paravirt SRAT info
Quoted 45 lines · Vasilis Liaskovitis
The
numa_fw_cfgparavirt interface is extended to include SRAT information for all hotplug-able dimms. There are 3 words for each hotplug-able memory slot, denoting start address, size and node proximity. The new info is appended after existing numa info, so that thefw_cfglayout does not break. This information is used by Seabios to build hotplug memory device objects at runtime.nb_numa_nodesis set to 1 by default (not 0), so that we always pass srat info to SeaBIOS.
v1->v2:
Dimm SRAT info (#dimms) is appended at end of existing numafw_cfgin order not to break existing layout
Documentation of the new fwcfg layout is included indocs/specs/fwcfg.txtSigned-off-by Vasilis Liaskovitis <[email protected]>--- docs/specs/fwcfg.txt | 28 ++++++++++++++++++++++++++ hw/pc.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- vl.c | 2 +- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 docs/specs/fwcfg.txtdocs/specs/fwcfg.txt new file +18
-0@@ -0,0 +1,28 @@ +QEMU<->BIOS Paravirt Documentation +-------------------------------------- + +This document describes paravirt data structures passed from QEMU to BIOS. + +fw_cfg SRAT paravirt info +-------------------- +The SRAT info passed from QEMU to BIOS has the following layout: + +----------------------------------------------------------------------------------------------- +#nodes | cpu0_pxm | cpu1_pxm | ... | cpulast_pxm | node0_mem | node1_mem | ... | nodelast_mem + +----------------------------------------------------------------------------------------------- +#dimms | dimm0_start | dimm0_sz | dimm0_pxm | ... | dimmlast_start | dimmlast_sz | dimmlast_pxm + +Entry 0 contains the number of numa nodes (nb_numa_nodes). + +Entries 1..max_cpus: The next max_cpus entries describe node proximity for each
docs/specs/fwcfg.txt line 28
Quoted 10 lines
docs/specs/fwcfg.txt new file +10
-0+one of the vCPUs in the system. + +Entries max_cpus+1..max_cpus+nb_numa_nodes+1: The next nb_numa_nodes entries +describe the memory size for each one of the NUMA nodes in the system. + +Entry max_cpus+nb_numa_nodes+1 contains the number of memory dimms (nb_hp_dimms) + +The last 3 * nb_hp_dimms entries are organized in triplets: Each triplet contains +the physical address offset, size (in bytes), and node proximity for the +respective dimm.
The size and endianness are not specified, you are using LE 64 bit values for each item.
Quoted 33 lines
hw/pc.c +6
-1@@ -598,12 +598,15 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)return index; } +static void setup_hp_dimms (uint64_t *fw_cfg_slots); +static void *bochs_bios_init (void ) {void *fw_cfg;uint8_t *smbios_table;size_t smbios_len;uint64_t *numa_fw_cfg; +uint64_t *hp_dimms_fw_cfg;int i, j;register_ioport_write (0x400 ,1 ,2 , bochs_bios_write,NULL );@@ -638,8 +641,10 @@ static void *bochs_bios_init(void)/* allocate memory for the NUMA channel: one (64bit) word for the number * of nodes, one word for each VCPU->node and one word for each node to * hold the amount of memory. +* Finally one word for the number of hotplug memory slots and three words +* for each hotplug memory slot (start address, size and node proximity). */ - numa_fw_cfg =g_malloc0 ((1 + max_cpus + nb_numa_nodes) *8 ); + numa_fw_cfg =g_malloc0 ((2 + max_cpus + nb_numa_nodes +3 * nb_hp_dimms) *8 ); numa_fw_cfg[0 ] =cpu_to_le64 (nb_numa_nodes);for (i =0 ; i < max_cpus; i++) {for (j =0 ; j < nb_numa_nodes; j++) {
hw/pc.c static void *bochs_bios_init(void) · line 665
Quoted 9 lines
hw/pc.c +6
-0@@ -652,8 +657,15 @@ static void *bochs_bios_init(void)for (i =0 ; i < nb_numa_nodes; i++) { numa_fw_cfg[max_cpus +1 + i] =cpu_to_le64 (node_mem[i]); } + + numa_fw_cfg[1 + max_cpus + nb_numa_nodes] =cpu_to_le64 (nb_hp_dimms); + + hp_dimms_fw_cfg = numa_fw_cfg +2 + max_cpus + nb_numa_nodes; +if (nb_hp_dimms) +setup_hp_dimms (hp_dimms_fw_cfg);
Braces.
Quoted 65 lines
hw/pc.c +39
-1+fw_cfg_add_bytes (fw_cfg,FW_CFG_NUMA , (uint8_t *)numa_fw_cfg, - (1 + max_cpus + nb_numa_nodes) *8 ); + (2 + max_cpus + nb_numa_nodes +3 * nb_hp_dimms) *8 );return fw_cfg; }@@ -1223,3 +1235,40 @@ target_phys_addr_t pc_set_hp_memory_offset(uint64_t size)return ret; } + +static void setup_hp_dimms (uint64_t *fw_cfg_slots) +{ +int i =0 ; +Error *err =NULL ; +DeviceState *dev; +DimmState *slot; +const char *type; +BusChild *kid; +BusState *bus =sysbus_get_default (); + + QTAILQ_FOREACH(kid, &bus->children, sibling) { + dev = kid->child; + type =object_property_get_str (OBJECT (dev),"type" , &err); +if (err) { +error_free (err); +fprintf (stderr,"error getting device type\n" ); +exit (1 ); + } + +if (!strcmp (type,"dimm" )) { +if (!dev->id) { +fprintf (stderr,"error getting dimm device id\n" ); +exit (1 ); + } + slot =DIMM (dev); +/* determine starting physical address for this memory slot */ +assert (slot->start); + fw_cfg_slots[3 * slot->idx] =cpu_to_le64 (slot->start); + fw_cfg_slots[3 * slot->idx +1 ] =cpu_to_le64 (slot->size); + fw_cfg_slots[3 * slot->idx +2 ] =cpu_to_le64 (slot->node); + i++; + } + } +assert (i == nb_hp_dimms); +} +vl.c +1
-2@@ -2335,7 +2335,7 @@ int main(int argc, char **argv, char **envp) node_cpumask[i] =0 ; } - nb_numa_nodes =0 ; + nb_numa_nodes =1 ; nb_nics =0 ; autostart=1 ; --1.7.9
Re: [Qemu-devel] [RFC PATCH v2 09/21] pc: Add dimm paravirt SRAT info
Quoted 52 lines · Blue Swirl
Quoted 50 lines · Vasilis Liaskovitis
The
numa_fw_cfgparavirt interface is extended to include SRAT information for all hotplug-able dimms. There are 3 words for each hotplug-able memory slot, denoting start address, size and node proximity. The new info is appended after existing numa info, so that thefw_cfglayout does not break. This information is used by Seabios to build hotplug memory device objects at runtime.nb_numa_nodesis set to 1 by default (not 0), so that we always pass srat info to SeaBIOS.
v1->v2:
Dimm SRAT info (#dimms) is appended at end of existing numafw_cfgin order not to break existing layout
Documentation of the new fwcfg layout is included indocs/specs/fwcfg.txtSigned-off-by Vasilis Liaskovitis <[email protected]>--- docs/specs/fwcfg.txt | 28 ++++++++++++++++++++++++++ hw/pc.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- vl.c | 2 +- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 docs/specs/fwcfg.txtdocs/specs/fwcfg.txt new file +23
-0@@ -0,0 +1,28 @@ +QEMU<->BIOS Paravirt Documentation +-------------------------------------- + +This document describes paravirt data structures passed from QEMU to BIOS. + +fw_cfg SRAT paravirt info +-------------------- +The SRAT info passed from QEMU to BIOS has the following layout: + +----------------------------------------------------------------------------------------------- +#nodes | cpu0_pxm | cpu1_pxm | ... | cpulast_pxm | node0_mem | node1_mem | ... | nodelast_mem + +----------------------------------------------------------------------------------------------- +#dimms | dimm0_start | dimm0_sz | dimm0_pxm | ... | dimmlast_start | dimmlast_sz | dimmlast_pxm + +Entry 0 contains the number of numa nodes (nb_numa_nodes). + +Entries 1..max_cpus: The next max_cpus entries describe node proximity for each +one of the vCPUs in the system. + +Entries max_cpus+1..max_cpus+nb_numa_nodes+1: The next nb_numa_nodes entries +describe the memory size for each one of the NUMA nodes in the system. +
Quoted 8 lines
docs/specs/fwcfg.txt line 28
Quoted 5 lines
docs/specs/fwcfg.txt new file +5
-0+Entry max_cpus+nb_numa_nodes+1 contains the number of memory dimms (nb_hp_dimms) + +The last 3 * nb_hp_dimms entries are organized in triplets: Each triplet contains +the physical address offset, size (in bytes), and node proximity for the +respective dimm.The size and endianness are not specified, you are using LE 64 bit values for each item.
thanks, I 'll update.
Quoted 111 lines
Quoted 34 lines
hw/pc.c +6
-1@@ -598,12 +598,15 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)return index; } +static void setup_hp_dimms (uint64_t *fw_cfg_slots); +static void *bochs_bios_init (void ) {void *fw_cfg;uint8_t *smbios_table;size_t smbios_len;uint64_t *numa_fw_cfg; +uint64_t *hp_dimms_fw_cfg;int i, j;register_ioport_write (0x400 ,1 ,2 , bochs_bios_write,NULL );@@ -638,8 +641,10 @@ static void *bochs_bios_init(void)/* allocate memory for the NUMA channel: one (64bit) word for the number * of nodes, one word for each VCPU->node and one word for each node to * hold the amount of memory. +* Finally one word for the number of hotplug memory slots and three words +* for each hotplug memory slot (start address, size and node proximity). */ - numa_fw_cfg =g_malloc0 ((1 + max_cpus + nb_numa_nodes) *8 ); + numa_fw_cfg =g_malloc0 ((2 + max_cpus + nb_numa_nodes +3 * nb_hp_dimms) *8 ); numa_fw_cfg[0 ] =cpu_to_le64 (nb_numa_nodes);for (i =0 ; i < max_cpus; i++) {for (j =0 ; j < nb_numa_nodes; j++) {hw/pc.c static void *bochs_bios_init(void) · line 665
Quoted 9 lines
hw/pc.c +6
-0@@ -652,8 +657,15 @@ static void *bochs_bios_init(void)for (i =0 ; i < nb_numa_nodes; i++) { numa_fw_cfg[max_cpus +1 + i] =cpu_to_le64 (node_mem[i]); } + + numa_fw_cfg[1 + max_cpus + nb_numa_nodes] =cpu_to_le64 (nb_hp_dimms); + + hp_dimms_fw_cfg = numa_fw_cfg +2 + max_cpus + nb_numa_nodes; +if (nb_hp_dimms) +setup_hp_dimms (hp_dimms_fw_cfg);Braces.
Quoted 65 lines
hw/pc.c +39
-1+fw_cfg_add_bytes (fw_cfg,FW_CFG_NUMA , (uint8_t *)numa_fw_cfg, - (1 + max_cpus + nb_numa_nodes) *8 ); + (2 + max_cpus + nb_numa_nodes +3 * nb_hp_dimms) *8 );return fw_cfg; }@@ -1223,3 +1235,40 @@ target_phys_addr_t pc_set_hp_memory_offset(uint64_t size)return ret; } + +static void setup_hp_dimms (uint64_t *fw_cfg_slots) +{ +int i =0 ; +Error *err =NULL ; +DeviceState *dev; +DimmState *slot; +const char *type; +BusChild *kid; +BusState *bus =sysbus_get_default (); + + QTAILQ_FOREACH(kid, &bus->children, sibling) { + dev = kid->child; + type =object_property_get_str (OBJECT (dev),"type" , &err); +if (err) { +error_free (err); +fprintf (stderr,"error getting device type\n" ); +exit (1 ); + } + +if (!strcmp (type,"dimm" )) { +if (!dev->id) { +fprintf (stderr,"error getting dimm device id\n" ); +exit (1 ); + } + slot =DIMM (dev); +/* determine starting physical address for this memory slot */ +assert (slot->start); + fw_cfg_slots[3 * slot->idx] =cpu_to_le64 (slot->start); + fw_cfg_slots[3 * slot->idx +1 ] =cpu_to_le64 (slot->size); + fw_cfg_slots[3 * slot->idx +2 ] =cpu_to_le64 (slot->node); + i++; + } + } +assert (i == nb_hp_dimms); +} +vl.c +1
-2@@ -2335,7 +2335,7 @@ int main(int argc, char **argv, char **envp) node_cpumask[i] =0 ; } - nb_numa_nodes =0 ; + nb_numa_nodes =1 ; nb_nics =0 ; autostart=1 ; --1.7.9
RFC PATCH v2 10/21 Implement "-dimm" command line option
In reply to Vasilis LiaskovitisSyntax: "-dimm id=name,size=sz,node=pxm,populated=on|off"
The starting physical address for all dimms is calculated automatically from top of memory, skipping the pci hole at [PCI_HOLE_START, 4G). "populated=on" means the dimm is populated at machine startup. Default is off. "node" is defining numa proximity for this dimm. Default is node zero.
Example:
"-dimm id=dimm0,size=512M,node=0,populated=off" will define a 512M memory slot belonging to numa node 0.
--- qemu-config.c | 25 +++++++++++++++++++++++++ qemu-options.hx | 5 +++++ sysemu.h | 1 + vl.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 0 deletions(-)
qemu-config.c +25 -0
@@ -626,6 +626,30 @@ QemuOptsList qemu_boot_opts = { }, }; +static QemuOptsList qemu_dimm_opts = { + .name ="dimm" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_dimm_opts.head), + .desc = { + { + .name ="id" , + .type =QEMU_OPT_STRING , + .help ="id of this dimm device" , + },{ + .name ="size" , + .type =QEMU_OPT_SIZE , + .help ="memory size for this dimm" , + },{ + .name ="populated" , + .type =QEMU_OPT_BOOL , + .help ="populated for this dimm" , + },{ + .name ="node" , + .type =QEMU_OPT_NUMBER , + .help ="NUMA node number (i.e. proximity) for this dimm" , + }, + {/* end of list */ } + }, +};static QemuOptsList *vm_config_groups[32 ] = { &qemu_drive_opts, &qemu_chardev_opts,
@@ -641,6 +665,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_machine_opts, &qemu_boot_opts, &qemu_iscsi_opts, + &qemu_dimm_opts, NULL, };
qemu-options.hx +5 -0
@@ -2747,3 +2747,8 @@ HXCOMM This is the last statement. Insert new options before this line! STEXI @end table ETEXI + +DEF("dimm", HAS_ARG, QEMU_OPTION_dimm, + "-dimm id=dimmid,size=sz,node=nd,populated=on|off\n" + "specify memory dimm device with name dimmid, size sz on node nd", + QEMU_ARCH_ALL)
sysemu.h +1 -0
@@ -136,6 +136,7 @@ extern QEMUClock *rtc_clock;extern int nb_numa_nodes;extern uint64_t node_mem[MAX_NODES ];extern uint64_t node_cpumask[MAX_NODES ]; +extern int nb_hp_dimms;#define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom {
vl.c +35 -0
@@ -120,6 +120,7 @@ int main(int argc, char **argv)#include "hw/xen.h" #include "hw/qdev.h" #include "hw/loader.h" +#include "hw/dimm.h" #include "bt-host.h" #include "net.h" #include "net/slirp.h"
@@ -242,6 +243,7 @@ QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_orderint nb_numa_nodes;uint64_t node_mem[MAX_NODES ];uint64_t node_cpumask[MAX_NODES ]; +int nb_hp_dimms;uint8_t qemu_uuid[16 ];
@@ -518,6 +520,23 @@ static void configure_rtc_date_offset(const char *startdate, int legacy) rtc_date_offset =time (NULL ) - rtc_start_date; } } +static void configure_dimm (QemuOpts *opts) +{ +const char *id; +uint64_t size, node; +bool populated; +if (nb_hp_dimms ==MAX_DIMMS ) { +fprintf (stderr,"qemu: maximum number of DIMMs (%d) exceeded\n" , +MAX_DIMMS ); +exit (1 ); + } + id =qemu_opts_id (opts); + size =qemu_opt_get_size (opts,"size" ,DEFAULT_DIMMSIZE ); + populated =qemu_opt_get_bool (opts,"populated" ,0 ); + node =qemu_opt_get_number (opts,"node" ,0 ); +dimm_create ((char *)id, size, node, nb_hp_dimms, populated); + nb_hp_dimms++; +}static void configure_rtc (QemuOpts *opts) {
@@ -2273,6 +2292,8 @@ int main(int argc, char **argv, char **envp)DisplayChangeListener *dcl;int cyls, heads, secs, translation;QemuOpts *hda_opts =NULL , *opts, *machine_opts; +QemuOpts *dimm_opts[MAX_DIMMS ]; +int nb_dimm_opts =0 ;QemuOptsList *olist;int optind;const char *optarg;
@@ -3200,6 +3221,18 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_qtest_log: qtest_log = optarg;break ; +case QEMU_OPTION_dimm: +if (nb_dimm_opts ==MAX_DIMMS ) { +fprintf (stderr,"qemu: maximum number of DIMMs (%d) exceeded\n" , +MAX_DIMMS ); + } + dimm_opts[nb_dimm_opts] = +qemu_opts_parse (qemu_find_opts ("dimm" ), optarg,0 ); +if (!dimm_opts[nb_dimm_opts]) { +exit (1 ); + } + nb_dimm_opts++; +break ;default :os_parse_cmd_args (popt->index, optarg); }
@@ -3517,6 +3550,8 @@ int main(int argc, char **argv, char **envp) }qemu_add_globals (); +for (i =0 ; i < nb_dimm_opts; i++) +configure_dimm (dimm_opts[i]);qdev_machine_init (); machine->init(ram_size, boot_devices,
Signature · 1 line
1.7.9
RFC PATCH v2 11/21 Implement dimm_add and dimm_del hmp/qmp commands
In reply to Vasilis LiaskovitisHot-add hmp syntax: dimm_add dimmid
Hot-remove hmp syntax: dimm_del dimmid
Respective qmp commands are "dimm-add", "dimm-del".
--- hmp-commands.hx | 32 ++++++++++++++++++++++++++++++++ monitor.c | 11 +++++++++++ monitor.h | 3 +++ qmp-commands.hx | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 0 deletions(-)
hmp-commands.hx +32 -0
@@ -618,6 +618,38 @@ Add device. ETEXI { + .name = "dimm_del", + .args_type = "id:s", + .params = "id", + .help = "hot-remove memory (dimm device)", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_dimm_del, + }, + +STEXI +@item dimm_del @var{config} +@findex dimm_del + +Hot-remove dimm. +ETEXI + + { + .name = "dimm_add", + .args_type = "id:s", + .params = "id", + .help = "hot-add memory (dimm device)", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_dimm_add, + }, + +STEXI +@item dimm_add @var{config} +@findex dimm_add + +Hot-add dimm. +ETEXI + + { .name = "device_del", .args_type = "id:s", .params = "device",
monitor.c +11 -0
@@ -67,6 +67,7 @@#include "qmp-commands.h" #include "hmp.h" #include "qemu-thread.h" +#include "hw/dimm.h" /* for pic/irq_info */ #if defined(TARGET_SPARC )
@@ -4813,3 +4814,13 @@ int monitor_read_block_device_key(Monitor *mon, const char *device,return monitor_read_bdrv_key_start (mon, bs, completion_cb, opaque); } + +int do_dimm_add (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +return dimm_do (mon, qdict, true); +} + +int do_dimm_del (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +return dimm_do (mon, qdict, false); +}
monitor.h +3 -0
@@ -86,4 +86,7 @@ int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret);int qmp_qom_get (Monitor *mon,const QDict *qdict,QObject **ret); +int do_dimm_add (Monitor *mon,const QDict *qdict,QObject **ret_data); +int do_dimm_del (Monitor *mon,const QDict *qdict,QObject **ret_data); +#endif /* !MONITOR_H */
qmp-commands.hx +39 -0
@@ -2209,3 +2209,42 @@ EQMP .args_type = "implements:s?,abstract:b?", .mhandler.cmd_new = qmp_marshal_input_qom_list_types, }, + { + .name = "dimm-add", + .args_type = "id:s", + .mhandler.cmd_new = do_dimm_add, + }, +SQMP +dimm-add +------------- + +Hot-add memory DIMM + +Will hotplug memory DIMMs with given id. + +Example: + +-> { "execute": "dimm-add", "arguments": { "id": "dimm0" } } +<- { "return": {} } + +EQMP + + { + .name = "dimm-del", + .args_type = "id:s", + .mhandler.cmd_new = do_dimm_del, + }, +SQMP +dimm-del +------------- + +Hot-remove memory DIMM + +Will hot-unplug memory DIMMs with given id. + +Example: + +-> { "execute": "dimm-del", "arguments": { "id": "dimm0" } } +<- { "return": {} } + +EQMP
Signature · 1 line
1.7.9
RFC PATCH v2 12/21 fix live-migration when "populated=on" is missing
In reply to Vasilis LiaskovitisLive migration works after memory hot-add events, as long as the qemu command line "-dimm" arguments are changed on the destination host to specify "populated=on" for the dimms that have been hot-added.
If a command-line change has not occured, the destination host does not yet have the corresponding ramblock in its ram_list. Activate the memslot on the destination during ram_load.
Perhaps several fields of the DimmState struct should be part of a VMStateDescription to handle migration in a cleaner way.
--- arch_init.c | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-)
arch_init.c +20 -3
@@ -43,6 +43,7 @@#include "hw/smbios.h" #include "exec-memory.h" #include "hw/pcspk.h" +#include "hw/dimm.h" #ifdef TARGET_SPARC int graphic_width =1024 ;
@@ -452,9 +453,25 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) }if (!block) { -fprintf (stderr,"Unknown ramblock \"%s\", cannot " -"accept migration\n" , id); -return -EINVAL ; +/* this can happen if a dimm was hot-added at source host */ +DimmState *slot =dimm_find_from_name (id); +if (slot) { +dimm_activate (slot); +/* rescan ram_list, verify ramblock is there now */ + QLIST_FOREACH(block, &ram_list.blocks, next) { +if (!strncmp (id, block->idstr,sizeof (id))) { +if (block->length != length) +return -EINVAL ; +break ; + } + } +assert (block); + } +else { +fprintf (stderr,"Unknown ramblock \"%s\", cannot " +"accept migration\n" , id); +return -EINVAL ; + } } total_ram_bytes -= length;
Signature · 1 line
1.7.9
RFC PATCH v2 13/21 Implement memory hotplug notification lists
In reply to Vasilis LiaskovitisGuest can respond to ACPI hotplug events e.g. with _EJ or _OST method. This patch implements a tail queue to store guest notifications for memory hot-add and hot-remove requests.
Guest responses for memory hotplug command on a per-dimm basis can be detected with the new hmp command "info memhp" or the new qmp command "query-memhp" Examples:
(qemu) dimm_add dimm0
(qemu) info memhp
Dimm: dimm0 hot-add success
or
Dimm: dimm0 hot-add failure
(qemu) dimm_del dimm0
(qemu) info memhp
Dimm: dimm0 hot-remove success
or
Dimm: dimm0 hot-remove failure
Results are removed from the queue once read.
This patch only queues _EJ events that signal hot-remove success. For _OST event queuing, which cover the hot-remove failure and hot-add success/failure cases, the next 2 patches are also needed.
These notification items should probably be part of migration state (not yet implemented)
--- hmp-commands.hx | 2 + hmp.c | 17 ++++++++++++++++ hmp.h | 1 + hw/dimm.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 6 +++++ monitor.c | 7 ++++++ qapi-schema.json | 26 +++++++++++++++++++++++++ qmp-commands.hx | 38 +++++++++++++++++++++++++++++++++++++ 8 files changed, 152 insertions(+), 0 deletions(-)
hmp-commands.hx +2 -0
@@ -1459,6 +1459,8 @@ show device tree show qdev device model list @item info roms show roms +@item info memhp +show memhp @end table ETEXI
hmp.c +17 -0
@@ -1000,3 +1000,20 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)qmp_netdev_del (id, &err);hmp_handle_error (mon, &err); } + +void hmp_info_memhp (Monitor *mon) +{ +MemHpInfoList *info; +MemHpInfoList *item; +MemHpInfo *dimm; + + info =qmp_query_memhp (NULL ); +for (item = info; item; item = item->next) { + dimm = item->value; +monitor_printf (mon,"Dimm: %s %s %s\n" , dimm->Dimm, + dimm->request, dimm->result); + dimm->Dimm =NULL ; + } + +qapi_free_MemHpInfoList (info); +}
hmp.h +1 -0
@@ -64,5 +64,6 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);void hmp_dump_guest_memory (Monitor *mon,const QDict *qdict);void hmp_netdev_add (Monitor *mon,const QDict *qdict);void hmp_netdev_del (Monitor *mon,const QDict *qdict); +void hmp_info_memhp (Monitor *mon);#endif
hw/dimm.c +55 -0
83 lines not on this page · raw message
hw/dimm.h +6 -0
@@ -37,6 +37,12 @@ typedef struct DimmState {QTAILQ_ENTRY (DimmState) nextdimm; } DimmState; +struct dimm_hp_result { +DimmState *s; +dimm_hp_result_code ret; +QTAILQ_ENTRY (dimm_hp_result) next; +}; +typedef int (*dimm_hotplug_fn )(DeviceState *qdev,SysBusDevice *dev,int add);typedef target_phys_addr_t (*dimm_calcoffset_fn )(uint64_t size);
monitor.c +7 -0
@@ -2732,6 +2732,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.info = do_trace_print_events, }, { + .name = "memhp", + .args_type = "", + .params = "", + .help = "show memory hotplug status", + .mhandler.info = hmp_info_memhp, + }, + { .name = NULL, }, };
qapi-schema.json +26 -0
@@ -1862,3 +1862,29 @@ # Since: 0.14.0 ## { 'command': 'netdev_del', 'data': {'id': 'str'} } + +## +# @MemHpInfo: +# +# Information about status of a memory hotplug command +# +# @Dimm: the Dimm associated with the result +# +# @result: the result of the hotplug command +# +# Since: 1.1.3 +# +## +{ 'type': 'MemHpInfo', + 'data': {'Dimm': 'str', 'request': 'str', 'result': 'str'} } + +## +# @query-memhp: +# +# Returns a list of information about pending hotplug commands +# +# Returns: a list of @MemhpInfo +# +# Since: 1.1.3 +## +{ 'command': 'query-memhp', 'returns': ['MemHpInfo'] }
qmp-commands.hx +38 -0
@@ -2248,3 +2248,41 @@ Example: <- { "return": {} } EQMP + + { + .name = "query-memhp", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_memhp + }, +SQMP +query-memhp +---------- + +Show memory hotplug command notifications. + +Return a json-array. Each DIMM that has a pending notification is represented +by a json-object, which contains: + +- "Dimm": Dimm name (json-str) +- "request": type of hot request: hot-add or hot-remove (json-str) +- "result": result of the hotplug request for this Dimm success or failure (json-str) + +Example: + +-> { "execute": "query-memhp" } +<- { + "return":[ + { + "result": "failure", + "request": "hot-remove", + "Dimm": "dimm10" + }, + { + "result": "success", + "request": "hot-add", + "Dimm": "dimm3" + } + ] + } + +EQMP
Signature · 1 line
1.7.9
Re: [Qemu-devel] [RFC PATCH v2 13/21] Implement memory hotplug notification lists
Quoted 15 lines · Vasilis Liaskovitis
Guest can respond to ACPI hotplug events e.g. with
_EJor_OSTmethod. This patch implements a tail queue to store guest notifications for memory hot-add and hot-remove requests.Guest responses for memory hotplug command on a per-dimm basis can be detected with the new hmp command "info memhp" or the new qmp command "query-memhp" Examples:
+++
b/qapi-schema.jsonqapi-schema.json +1
-0@@ -1862,3 +1862,29 @@ # Since: 0.14.0 ## { 'command': 'netdev_del', 'data': {'id': 'str'} } +
qapi-schema.json line 1875
Quoted 10 lines
qapi-schema.json +10
-0+## +# @MemHpInfo: +# +# Information about status of a memory hotplug command +# +# @Dimm: the Dimm associated with the result +# +# @result: the result of the hotplug command +# +# Since: 1.1.3
Should probably be 1.2, not 1.1.3.
qapi-schema.json line 1879
Quoted 4 lines
qapi-schema.json +4
-0+# +## +{ 'type': 'MemHpInfo', + 'data': {'Dimm': 'str', 'request': 'str', 'result': 'str'} }
Why the upper case? Wouldn't 'dimm' be more consistent?
qapi-schema.json line 1882
Quoted 3 lines
qapi-schema.json +3
-0+ +## +# @query-memhp:
Why are we abbreviating? It might be better to name the QMP command query-memory-hotplug
qapi-schema.json line 1888
Quoted 6 lines
qapi-schema.json +6
-0+# +# Returns a list of information about pending hotplug commands +# +# Returns: a list of @MemhpInfo +# +# Since: 1.1.3
Likewise for 1.2.
qmp-commands.hx Example: · line 2268
Quoted 4 lines
qmp-commands.hx +4
-0+ +- "Dimm": Dimm name (json-str) +- "request": type of hot request: hot-add or hot-remove (json-str) +- "result": result of the hotplug request for this Dimm success or failure (json-str)
This may need tweaks (such as s/Dimm/dimm/) based on resolution of above comments.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH v2 13/21] Implement memory hotplug notification lists
Hi,
Quoted 20 lines · Eric Blake
Quoted 19 lines · Vasilis Liaskovitis
Guest can respond to ACPI hotplug events e.g. with
_EJor_OSTmethod. This patch implements a tail queue to store guest notifications for memory hot-add and hot-remove requests.Guest responses for memory hotplug command on a per-dimm basis can be detected with the new hmp command "info memhp" or the new qmp command "query-memhp" Examples:
+++
b/qapi-schema.jsonqapi-schema.json +5
-0@@ -1862,3 +1862,29 @@ # Since: 0.14.0 ## { 'command': 'netdev_del', 'data': {'id': 'str'} } + +## +# @MemHpInfo: +# +# Information about status of a memory hotplug command
Quoted 9 lines
qapi-schema.json line 1875
Quoted 6 lines
qapi-schema.json +6
-0+# +# @Dimm: the Dimm associated with the result +# +# @result: the result of the hotplug command +# +# Since: 1.1.3Should probably be 1.2, not 1.1.3.
right
Quoted 7 lines
qapi-schema.json line 1879
Quoted 4 lines
qapi-schema.json +4
-0+# +## +{ 'type': 'MemHpInfo', + 'data': {'Dimm': 'str', 'request': 'str', 'result': 'str'} }Why the upper case? Wouldn't 'dimm' be more consistent?
I will change to "dimm"
Quoted 7 lines
qapi-schema.json line 1882
Quoted 3 lines
qapi-schema.json +3
-0+ +## +# @query-memhp:Why are we abbreviating? It might be better to name the QMP command query-memory-hotplug
agreed, memhp is a bit cryptic. I will change to your suggestion
Quoted 8 lines
qapi-schema.json line 1888
Quoted 6 lines
qapi-schema.json +6
-0+# +# Returns a list of information about pending hotplug commands +# +# Returns: a list of @MemhpInfo +# +# Since: 1.1.3Likewise for 1.2.
right
Quoted 8 lines
qmp-commands.hx Example: · line 2268
Quoted 5 lines
qmp-commands.hx +4
-0+ +- "Dimm": Dimm name (json-str) +- "request": type of hot request: hot-add or hot-remove (json-str) +- "result": result of the hotplug request for this Dimm success or failure (json-str)This may need tweaks (such as s/Dimm/dimm/) based on resolution of above comments.
ok, it will be "dimm"
thanks,
- Vasilis
RFC PATCH v2 14/21 acpi_dsdt: Support _OST dimm method
In reply to Vasilis LiaskovitisAdd support for _OST method. _OST method will write into the correct I/O byte to signal success / failure of hot-add or hot-remove to qemu.
--- src/acpi-dsdt.dsl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/ssdt-mem.dsl | 4 ++++ 2 files changed, 50 insertions(+), 0 deletions(-)
src/acpi-dsdt.dsl +46 -0
@@ -762,6 +762,28 @@ DefinitionBlock ( MPE, 8 } + + /* Memory hot-remove notify failure byte */ + OperationRegion(MEEF, SystemIO, 0xafa1, 1) + Field (MEEF, ByteAcc, NoLock, Preserve) + { + MEF, 8 + } + + /* Memory hot-add notify success byte */ + OperationRegion(MPIS, SystemIO, 0xafa2, 1) + Field (MPIS, ByteAcc, NoLock, Preserve) + { + MIS, 8 + } + + /* Memory hot-add notify failure byte */ + OperationRegion(MPIF, SystemIO, 0xafa3, 1) + Field (MPIF, ByteAcc, NoLock, Preserve) + { + MIF, 8 + } + Method(MESC, 0) { // Local5 = active memdevice bitmap Store (MES, Local5)
@@ -802,6 +824,30 @@ DefinitionBlock ( Store(Arg0, MPE) Sleep(200) } + Method (MOST, 3, Serialized) { + // _OST method - OS status indication + Switch (And(Arg0, 0xFF)) { + Case(0x3) + { + Switch(And(Arg1, 0xFF)) { + Case(0x1) { + Store(Arg2, MEF) + } + } + } + Case(0x1) + { + Switch(And(Arg1, 0xFF)) { + Case(0x0) { + Store(Arg2, MIS) + } + Case(0x1) { + Store(Arg2, MIF) + } + } + } + } + } }
src/ssdt-mem.dsl +4 -0
@@ -38,6 +38,7 @@ DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1) External(CMST, MethodObj) External(MPEJ, MethodObj) + External(MOST, MethodObj) Name(_CRS, ResourceTemplate() { QwordMemory(
@@ -60,6 +61,9 @@ DefinitionBlock ("ssdt-mem.aml", "SSDT", 0x02, "BXPC", "CSSDT", 0x1) Method (_EJ0, 1, NotSerialized) { MPEJ(ID, Arg0) } + Method (_OST, 3) { + MOST(Arg0, Arg1, ID) + } } }
Signature · 1 line
1.7.9
RFC PATCH v2 15/21 acpi_piix4: _OST dimm support
In reply to Vasilis LiaskovitisThis allows qemu to receive notifications from the guest OS on success or failure of a memory hotplug request. The guest OS needs to implement the _OST functionality for this to work (linux-next: http://lkml.org/lkml/2012/6/25/321)
Also add new _OST registers in docs/specs/acpi_hotplug.txt
--- docs/specs/acpi_hotplug.txt | 24 ++++++++++++++++++++++++ hw/acpi_piix4.c | 15 +++++++++++++++ hw/dimm.c | 18 ++++++++++++++++++ hw/dimm.h | 1 + 4 files changed, 58 insertions(+), 0 deletions(-)
docs/specs/acpi_hotplug.txt +24 -0
@@ -20,3 +20,27 @@ ejected. Written by ACPI memory device _EJ0 method to notify qemu of successfull hot-removal. Write-only. + +Memory Dimm ejection failure notification (IO port 0xafa1, 1-byte access): +--------------------------------------------------------------- +Dimm hot-remove _OST failure notification. Byte value indicates Dimm slot for +which ejection failed. + +Written by ACPI memory device _OST method to notify qemu of failed +hot-removal. Write-only. + +Memory Dimm insertion success notification (IO port 0xafa2, 1-byte access): +--------------------------------------------------------------- +Dimm hot-add _OST success notification. Byte value indicates Dimm slot for which +insertion succeeded. + +Written by ACPI memory device _OST method to notify qemu of failed +hot-add. Write-only. + +Memory Dimm insertion failure notification (IO port 0xafa3, 1-byte access): +--------------------------------------------------------------- +Dimm hot-add _OST failure notification. Byte value indicates Dimm slot for which +insertion failed. + +Written by ACPI memory device _OST method to notify qemu of failed +hot-add. Write-only.
hw/acpi_piix4.c +15 -0
@@ -49,6 +49,9 @@#define PCI_RMV_BASE 0xae0c#define MEM_BASE 0xaf80#define MEM_EJ_BASE 0xafa0 +#define MEM_OST_REMOVE_FAIL 0xafa1 +#define MEM_OST_ADD_SUCCESS 0xafa2 +#define MEM_OST_ADD_FAIL 0xafa3#define PIIX4_MEM_HOTPLUG_STATUS 8#define PIIX4_PCI_HOTPLUG_STATUS 2
@@ -531,6 +534,15 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)case MEM_EJ_BASE :dimm_notify (val,DIMM_REMOVE_SUCCESS );break ; +case MEM_OST_REMOVE_FAIL : +dimm_notify (val,DIMM_REMOVE_FAIL ); +break ; +case MEM_OST_ADD_SUCCESS : +dimm_notify (val,DIMM_ADD_SUCCESS ); +break ; +case MEM_OST_ADD_FAIL : +dimm_notify (val,DIMM_ADD_FAIL ); +break ;default :acpi_gpe_ioport_writeb (&s->ar, addr, val); }
@@ -604,6 +616,9 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)register_ioport_read (MEM_BASE ,DIMM_BITMAP_BYTES ,1 , gpe_readb, s);register_ioport_write (MEM_EJ_BASE ,1 ,1 , gpe_writeb, s); +register_ioport_write (MEM_OST_REMOVE_FAIL ,1 ,1 , gpe_writeb, s); +register_ioport_write (MEM_OST_ADD_SUCCESS ,1 ,1 , gpe_writeb, s); +register_ioport_write (MEM_OST_ADD_FAIL ,1 ,1 , gpe_writeb, s);for (i =0 ; i <DIMM_BITMAP_BYTES ; i++) { s->gperegs.mems_sts[i] =0 ;
hw/dimm.c +18 -0
@@ -89,12 +89,14 @@ void dimm_activate(DimmState *slot)dimm_populate (slot);if (dimm_hotplug)dimm_hotplug (dimm_hotplug_qdev, (SysBusDevice *)slot,1 ); + slot->pending = true; }void dimm_deactivate (DimmState *slot) {if (dimm_hotplug)dimm_hotplug (dimm_hotplug_qdev, (SysBusDevice *)slot,0 ); + slot->pending = true; }DimmState *dimm_find_from_name (char *id)
@@ -138,6 +140,10 @@ int dimm_do(Monitor *mon, const QDict *qdict, bool add) __FUNCTION__, id);return 1 ; } +if (slot->pending) { +fprintf (stderr,"warning: %s slot %s hot-operation pending\n" , + __FUNCTION__, id); + }dimm_activate (slot); }else {
@@ -146,6 +152,10 @@ int dimm_do(Monitor *mon, const QDict *qdict, bool add) __FUNCTION__, id);return 1 ; } +if (slot->pending) { +fprintf (stderr,"warning: %s slot %s hot-operation pending\n" , + __FUNCTION__, id); + }dimm_deactivate (slot); }
@@ -198,6 +208,13 @@ void dimm_notify(uint32_t idx, uint32_t event)case DIMM_REMOVE_SUCCESS :dimm_depopulate (s);QTAILQ_INSERT_TAIL (&dimm_hp_result_queue, result, next); + s->pending = false; +break ; +case DIMM_REMOVE_FAIL : +case DIMM_ADD_SUCCESS : +case DIMM_ADD_FAIL : +QTAILQ_INSERT_TAIL (&dimm_hp_result_queue, result, next); + s->pending = false;break ;default :g_free (result);
@@ -259,6 +276,7 @@ static int dimm_init(SysBusDevice *s) slot =DIMM (s); slot->mr =NULL ; slot->populated = false; + slot->pending = false;return 0 ; }
hw/dimm.h +1 -0
@@ -35,6 +35,7 @@ typedef struct DimmState {MemoryRegion *mr;/* MemoryRegion for this slot. !NULL only if populated */ bool populated;/* 1 means device has been hotplugged. Default is 0. */ QTAILQ_ENTRY (DimmState) nextdimm; +bool pending;/* true means a hot operation is pending for this dimm */ } DimmState;struct dimm_hp_result {
Signature · 1 line
1.7.9
RFC PATCH v2 16/21 acpi_piix4: Update dimm state on VM reboot
In reply to Vasilis Liaskovitisin case of hot-remove or hot-add failure, the dimm bitmaps in qemu and Seabios are inconsistent with the true state of the DIMM devices. The "populated" field of the DimmState reflects the true state of the device. This inconsistency means that a failed operation cannot be retried.
Ths patch updates the bit array to the true state of the dimms on VM reboot. This allows retry of failed hot-add or hot-remove operations after a reboot.
Retrying a failed hot operation is not yet possible before reboot (the following patch removes this limitation for guests with _OST acpi support)
--- hw/acpi_piix4.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-)
hw/acpi_piix4.c +25 -0
@@ -91,6 +91,7 @@ typedef struct PIIX4PMState { } PIIX4PMState;static void piix4_acpi_system_hot_add_init (PCIBus *bus,PIIX4PMState *s); +static void piix4_dimm_state_sync (PIIX4PMState *s);#define ACPI_ENABLE 0xf1#define ACPI_DISABLE 0xf0
@@ -369,6 +370,7 @@ static void piix4_reset(void *opaque)/* Mark SMM as already inited (until KVM supports SMM). */ pci_conf[0x5B ] =0x02 ; } +piix4_dimm_state_sync (s);piix4_update_hotplug (s); }
@@ -671,6 +673,29 @@ static int piix4_dimm_hotplug(DeviceState *qdev, SysBusDevice *dev, intreturn 0 ; } +void piix4_dimm_state_sync (PIIX4PMState *s) +{ +struct gpe_regs *g = &s->gperegs; +DimmState *slot =NULL ; +uint32_t i, temp =1 ; + +for (i =0 ; i <MAX_DIMMS ; i++) { + slot =dimm_find_from_idx (i); +if (!slot) +break ; +if (i %8 ==0 ) { + temp =1 ; + g->mems_sts[i /8 ] =0 ; + } +else + temp = temp <<1 ; +if (slot->populated) { + g->mems_sts[i /8 ] |= temp; + } + slot->pending = false; + } +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {
Signature · 1 line
1.7.9
RFC PATCH v2 17/21 acpi_dsdt: Revert internal dimm state on _OST failure
In reply to Vasilis LiaskovitisThis reverts bitmap state in the case of a failed hot operation, in order to allow retry of failed hot operations
--- src/acpi-dsdt.dsl | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
src/acpi-dsdt.dsl +4 -0
@@ -832,6 +832,8 @@ DefinitionBlock ( Switch(And(Arg1, 0xFF)) { Case(0x1) { Store(Arg2, MEF) + // Revert MEON flag for this memory device to one + Store(One, Index(MEON, Arg2)) } } }
@@ -843,6 +845,8 @@ DefinitionBlock ( } Case(0x1) { Store(Arg2, MIF) + // Revert MEON flag for this memory device to zero + Store(Zero, Index(MEON, Arg2)) } } }
Signature · 1 line
1.7.9
RFC PATCH v2 18/21 acpi_piix4: Update dimm bitmap state on hot-remove fail
In reply to Vasilis LiaskovitisThis allows failed hot operations to be retried at anytime. This only works for guests that use _OST notification. Other guests cannot retry failed hot operations on same devices until after reboot.
--- hw/acpi_piix4.c | 20 +++++++++++++++++++- hw/dimm.c | 16 +++++++++++++++- hw/dimm.h | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-)
hw/acpi_piix4.c +19 -1
@@ -599,6 +599,7 @@ static uint32_t pcirmv_read(void *opaque, uint32_t addr)static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state);static int piix4_dimm_hotplug (DeviceState *qdev,SysBusDevice *dev,int add); +static int piix4_dimm_revert (DeviceState *qdev,SysBusDevice *dev,int add);static void piix4_acpi_system_hot_add_init (PCIBus *bus,PIIX4PMState *s) {
@@ -627,7 +628,7 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s) }pci_bus_hotplug (bus, piix4_device_hotplug, &s->dev.qdev); -dimm_register_hotplug (piix4_dimm_hotplug, &s->dev.qdev); +dimm_register_hotplug (piix4_dimm_hotplug, piix4_dimm_revert, &s->dev.qdev); }static void enable_device (PIIX4PMState *s,int slot)
@@ -696,6 +697,23 @@ void piix4_dimm_state_sync(PIIX4PMState *s) } } +static int piix4_dimm_revert (DeviceState *qdev,SysBusDevice *dev,int add) +{ +PCIDevice *pci_dev =DO_UPCAST (PCIDevice, qdev, qdev); +PIIX4PMState *s =DO_UPCAST (PIIX4PMState, dev, pci_dev); +struct gpe_regs *g = &s->gperegs; +DimmState *slot =DIMM (dev); +int idx = slot->idx; + +if (add) { + g->mems_sts[idx/8 ] &= ~(1 << (idx%8 )); + } +else { + g->mems_sts[idx/8 ] |= (1 << (idx%8 )); + } +return 0 ; +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {
hw/dimm.c +15 -1
@@ -25,6 +25,7 @@static DeviceState *dimm_hotplug_qdev;static dimm_hotplug_fn dimm_hotplug; +static dimm_hotplug_fn dimm_revert; static QTAILQ_HEAD(Dimmlist, DimmState) dimmlist; static QTAILQ_HEAD(dimm_hp_result_head, dimm_hp_result) dimm_hp_result_queue;
@@ -77,10 +78,12 @@ DimmState *dimm_create(char *id, uint64_t size, uint64_t node, uint32_treturn mdev; } -void dimm_register_hotplug (dimm_hotplug_fn hotplug,DeviceState *qdev) +void dimm_register_hotplug (dimm_hotplug_fn hotplug,dimm_hotplug_fn revert, +DeviceState *qdev) { dimm_hotplug_qdev = qdev; dimm_hotplug = hotplug; + dimm_revert = revert;dimm_scan_populated (); }
@@ -211,10 +214,20 @@ void dimm_notify(uint32_t idx, uint32_t event) s->pending = false;break ;case DIMM_REMOVE_FAIL : +QTAILQ_INSERT_TAIL (&dimm_hp_result_queue, result, next); + s->pending = false; +if (dimm_revert) +dimm_revert (dimm_hotplug_qdev, (SysBusDevice *)s,0 ); +break ;case DIMM_ADD_SUCCESS : +QTAILQ_INSERT_TAIL (&dimm_hp_result_queue, result, next); + s->pending = false; +break ;case DIMM_ADD_FAIL :QTAILQ_INSERT_TAIL (&dimm_hp_result_queue, result, next); s->pending = false; +if (dimm_revert) +dimm_revert (dimm_hotplug_qdev, (SysBusDevice *)s,1 );break ;default :g_free (result);
@@ -288,6 +301,7 @@ static void dimm_class_init(ObjectClass *klass, void *data) dc->props = dimm_properties; sc->init = dimm_init; dimm_hotplug =NULL ; + dimm_revert =NULL ;QTAILQ_INIT (&dimmlist);QTAILQ_INIT (&dimm_hp_result_queue); }
hw/dimm.h +1 -1
@@ -54,7 +54,7 @@ void dimm_depopulate(DimmState *s);int dimm_do (Monitor *mon,const QDict *qdict,bool add);DimmState *dimm_find_from_idx (uint32_t idx);DimmState *dimm_find_from_name (char *id); -void dimm_register_hotplug (dimm_hotplug_fn hotplug,DeviceState *qdev); +void dimm_register_hotplug (dimm_hotplug_fn hotplug,dimm_hotplug_fn revert,DeviceState *qdev);void dimm_calc_offsets (dimm_calcoffset_fn calcfn);void dimm_activate (DimmState *slot);void dimm_deactivate (DimmState *slot);
Signature · 1 line
1.7.9
RFC PATCH v2 19/21 Implement "info memtotal" and "query-memtotal"
In reply to Vasilis LiaskovitisReturns total memory of guest in bytes, including hotplugged memory.
--- hmp-commands.hx | 2 ++ hmp.c | 7 +++++++ hmp.h | 1 + hw/dimm.c | 15 +++++++++++++++ monitor.c | 7 +++++++ qapi-schema.json | 12 ++++++++++++ qmp-commands.hx | 20 ++++++++++++++++++++ 7 files changed, 64 insertions(+), 0 deletions(-)
hmp-commands.hx +2 -0
@@ -1461,6 +1461,8 @@ show qdev device model list show roms @item info memhp show memhp +@item info memtotal +show memtotal @end table ETEXI
hmp.c +7 -0
@@ -1017,3 +1017,10 @@ void hmp_info_memhp(Monitor *mon)qapi_free_MemHpInfoList (info); } + +void hmp_info_memtotal (Monitor *mon) +{ +uint64_t ram_total; + ram_total = (uint64_t )qmp_query_memtotal (NULL ); +monitor_printf (mon,"MemTotal: %lu \n" , ram_total); +}
hmp.h +1 -0
@@ -65,5 +65,6 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);void hmp_netdev_add (Monitor *mon,const QDict *qdict);void hmp_netdev_del (Monitor *mon,const QDict *qdict);void hmp_info_memhp (Monitor *mon); +void hmp_info_memtotal (Monitor *mon);#endif
hw/dimm.c +15 -0
@@ -28,6 +28,7 @@ static dimm_hotplug_fn dimm_hotplug;static dimm_hotplug_fn dimm_revert; static QTAILQ_HEAD(Dimmlist, DimmState) dimmlist; static QTAILQ_HEAD(dimm_hp_result_head, dimm_hp_result) dimm_hp_result_queue; +extern ram_addr_t ram_size;static Property dimm_properties[] = {DEFINE_PROP_END_OF_LIST ()
@@ -292,6 +293,20 @@ MemHpInfoList *qmp_query_memhp(Error **errp)return head; } + +int64_t qmp_query_memtotal (Error **errp) +{ +DimmState *slot; +uint64_t info = ram_size; + + QTAILQ_FOREACH(slot, &dimmlist, nextdimm) { +if (slot->populated) { + info += slot->size; + } + } +return (int64_t )info; +} +static int dimm_init (SysBusDevice *s) {DimmState *slot;
monitor.c +7 -0
@@ -2739,6 +2739,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.info = hmp_info_memhp, }, { + .name = "memtotal", + .args_type = "", + .params = "", + .help = "show total memory size", + .mhandler.info = hmp_info_memtotal, + }, + { .name = NULL, }, };
qapi-schema.json +12 -0
@@ -1888,3 +1888,15 @@ # Since: 1.1.3 ## { 'command': 'query-memhp', 'returns': ['MemHpInfo'] } + +## +# @query-memtotal: +# +# Returns total memory in bytes, including hotplugged dimms +# +# Returns: a l +# +# Since: 1.2 +## +{ 'command': 'query-memtotal', 'returns': 'int' } +
qmp-commands.hx +20 -0
@@ -2286,3 +2286,23 @@ Example: } EQMP + + { + .name = "query-memtotal", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_memtotal + }, +SQMP +query-memtotal +---------- + +Return total memory in bytes, including hotplugged dimms + +Example: + +-> { "execute": "query-memtotal" } +<- { + "return": 1073741824 + } + +EQMP
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 19/21] Implement "info memtotal" and "query-memtotal"
Quoted 3 lines · Vasilis Liaskovitis
Returns total memory of guest in bytes, including hotplugged memory.
Signed-off-by Vasilis Liaskovitis <[email protected]>
Should this instead be merged with query-balloon output, so that we have a single command that shows all aspects of memory usage (both balloon and hotplug at once)?
qapi-schema.json line 1893
Quoted 7 lines
qapi-schema.json +3
-0@@ -1888,3 +1888,15 @@ # Since: 1.1.3 ## { 'command': 'query-memhp', 'returns': ['MemHpInfo'] } + +## +# @query-memtotal:
A more generic name might be 'query-memory', especially if we merge balloon and hotplug information into one command.
qapi-schema.json line 1897
Quoted 4 lines
qapi-schema.json +4
-0+# +# Returns total memory in bytes, including hotplugged dimms +# +# Returns: a l
truncated
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH v2 19/21] Implement "info memtotal" and "query-memtotal"
Hi,
Quoted 10 lines · Eric Blake
Quoted 3 lines · Vasilis Liaskovitis
Returns total memory of guest in bytes, including hotplugged memory.
Signed-off-by Vasilis Liaskovitis <[email protected]>Should this instead be merged with query-balloon output, so that we have a single command that shows all aspects of memory usage (both balloon and hotplug at once)?
Quoted 10 lines
qapi-schema.json line 1893
Quoted 7 lines
qapi-schema.json +3
-0@@ -1888,3 +1888,15 @@ # Since: 1.1.3 ## { 'command': 'query-memhp', 'returns': ['MemHpInfo'] } + +## +# @query-memtotal:A more generic name might be 'query-memory', especially if we merge balloon and hotplug information into one command.
"query-memory" sounds reasonable to me.
"query-balloon" should also be updated to show the correct memory. Do you foresee any issues with merging them? the "query-memory" command should work independently of the balloon driver.
Quoted 6 lines
qapi-schema.json line 1897
Quoted 4 lines
qapi-schema.json +4
-0+# +# Returns total memory in bytes, including hotplugged dimms +# +# Returns: a ltruncated
sorry about that.
thanks,
- Vasilis
Quoted 7 lines
Signature · 3 lines
-- Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
RFC PATCH v2 20/21 Implement -dimms, -dimmspop command line options
In reply to Vasilis LiaskovitisImplement batch dimm creation command line options. These could be useful for not bloating the command line with a large number of dimms.
syntax: -dimms pfx=poolid,size=sz,num=n
Will create numdimms dimms with ids poolid0, ..., poolidn-1. Each dimm has a size of sz.
Implement -dimmpop option to populate dimms at bootup
syntax: -dimmpop pfx=poolid,num=n
This will populate n dimms with ids poolid0, ..., poolidn-1.
(live-migration could break here without patch 12/21: -dimmspop needs to be reworked to support populating of individual dimms with same prefix, and not only a range of dimms starting from 0)
--- hw/dimm.c | 9 ++++++ hw/dimm.h | 2 +- qemu-config.c | 45 ++++++++++++++++++++++++++++ qemu-options.hx | 10 ++++++ vl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 150 insertions(+), 2 deletions(-)
hw/dimm.c +9 -0
@@ -187,6 +187,15 @@ void dimm_calc_offsets(dimm_calcoffset_fn calcfn) } } +int dimm_set_populated (DimmState *s) +{ +if (s) { + s->populated = true; +return 0 ; + } +else return -1 ; +} +/* used to populate and activate dimms at boot time */ void dimm_scan_populated (void ) {
hw/dimm.h +1 -1
@@ -60,6 +60,6 @@ void dimm_activate(DimmState *slot);void dimm_deactivate (DimmState *slot);void dimm_scan_populated (void );void dimm_notify (uint32_t idx,uint32_t event); - +int dimm_set_populated (DimmState *s);#endif
qemu-config.c +45 -0
57 lines not on this page · raw message
qemu-options.hx +10 -0
@@ -2752,3 +2752,13 @@ DEF("dimm", HAS_ARG, QEMU_OPTION_dimm, "-dimm id=dimmid,size=sz,node=nd,populated=on|off\n" "specify memory dimm device with name dimmid, size sz on node nd", QEMU_ARCH_ALL) + +DEF("dimms", HAS_ARG, QEMU_OPTION_dimms, + "-dimms pfx=id,size=sz,node=nd\n" + "specify pool of num memory dimm devices of size sz each on node nd", + QEMU_ARCH_ALL) + +DEF("dimmspop", HAS_ARG, QEMU_OPTION_dimmspop, + "-dimmspop pfx=id,num=n\n" + "populate n dimms of pool id (dimms with ids id0,...,idn-1) at system startup", + QEMU_ARCH_ALL)
vl.c +85 -1
110 lines not on this page · raw message
Signature · 1 line
1.7.9
Re: [RFC PATCH v2 20/21] Implement -dimms, -dimmspop command line options
Quoted 2 lines · Vasilis Liaskovitis
Implement batch dimm creation command line options. These could be useful for not bloating the command line with a large number of dimms.
IMO this is unneeded. With a management tool there is no problem generating a long command line; from the command line -dimm will be a rarely used option.
Quoted 13 lines
syntax: -dimms pfx=poolid,size=sz,num=n
Will create numdimms dimms with ids poolid0, ..., poolidn-1. Each dimm has a size of sz.Implement -dimmpop option to populate dimms at bootup
syntax: -dimmpop pfx=poolid,num=n
This will populate n dimms with ids poolid0, ..., poolidn-1.(live-migration could break here without patch 12/21: -dimmspop needs to be reworked to support populating of individual dimms with same prefix, and not only a range of dimms starting from 0)
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [RFC PATCH v2 20/21] Implement -dimms, -dimmspop command line options
Hi,
Quoted 7 lines · Avi Kivity
Quoted 2 lines · Vasilis Liaskovitis
Implement batch dimm creation command line options. These could be useful for not bloating the command line with a large number of dimms.
IMO this is unneeded. With a management tool there is no problem generating a long command line; from the command line -dimm will be a rarely used option.
ok, I thought so. I guess this patch and the next are unwanted, unless there is a strong opinion for using them coming from others.
thanks,
- Vasilis
RFC PATCH v2 21/21 Implement mem_increase, mem_decrease hmp/qmp commands
In reply to Vasilis LiaskovitisThis implements batch monitor operations for hot-add and hot-remove. These are probably better suited for a higher-level management layer, but are useful for testing. Let me know if there is interest for such commands upstream.
syntax: mem_increase poolid num
will hotplug num dimms from pool poolid. This starts from lowest unpopulated physical memory (dimm) and trying to cover any existing physical holes.
syntax: mem_decrease poolid num
will hot-unplug num dimms from pool poolid, This starts from highest populated physical memory (dimm).
Respective qmp commands are "mem-increase", "mem-decrease".
--- hmp-commands.hx | 31 ++++++++++++++++ hw/dimm.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 7 ++++ monitor.c | 10 +++++ monitor.h | 2 + qmp-commands.hx | 40 +++++++++++++++++++++ 6 files changed, 194 insertions(+), 0 deletions(-)
hmp-commands.hx +31 -0
@@ -648,6 +648,37 @@ STEXI Hot-add dimm. ETEXI + { + .name = "mem_increase", + .args_type = "pfx:s,num:s", + .params = "pfx num", + .help = "hot-plug num dimms of memory pool pfx", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_dimm_add_range, + }, + +STEXI +@item mem_increase @var{config} +@findex mem_increase + +Hotplug dimms. +ETEXI + + { + .name = "mem_decrease", + .args_type = "pfx:s,num:s", + .params = "pfx num", + .help = "hot-unplug num dimms of memory pool pfx", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_dimm_del_range, + }, + +STEXI +@item mem_decrease @var{config} +@findex mem_decrease + +Hot-unplug dimms. +ETEXI { .name = "device_del",
hw/dimm.c +104 -0
110 lines not on this page · raw message
hw/dimm.h +7 -0
@@ -11,6 +11,11 @@#define DIMM_BITMAP_BYTES (MAX_DIMMS + 7) / 8#define DEFAULT_DIMMSIZE 1024*1024*1024 +enum { +DIMM_MIN_UNPOPULATED =0 , +DIMM_MAX_POPULATED =1 +}; + typedef enum { DIMM_REMOVE_SUCCESS = 0, DIMM_REMOVE_FAIL = 1,
@@ -61,5 +66,7 @@ void dimm_deactivate(DimmState *slot);void dimm_scan_populated (void );void dimm_notify (uint32_t idx,uint32_t event);int dimm_set_populated (DimmState *s); +DimmState *dimm_find_next (char *pfx,uint32_t mode); +int dimm_do_range (Monitor *mon,const QDict *qdict,bool add);#endif
monitor.c +10 -0
@@ -4838,3 +4838,13 @@ int do_dimm_del(Monitor *mon, const QDict *qdict, QObject **ret_data) {return dimm_do (mon, qdict, false); } + +int do_dimm_add_range (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +return dimm_do_range (mon, qdict, true); +} + +int do_dimm_del_range (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +return dimm_do_range (mon, qdict, false); +}
monitor.h +2 -0
@@ -88,5 +88,7 @@ int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret);int do_dimm_add (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_dimm_del (Monitor *mon,const QDict *qdict,QObject **ret_data); +int do_dimm_add_range (Monitor *mon,const QDict *qdict,QObject **ret_data); +int do_dimm_del_range (Monitor *mon,const QDict *qdict,QObject **ret_data);#endif /* !MONITOR_H */
qmp-commands.hx +40 -0
@@ -2306,3 +2306,43 @@ Example: } EQMP + + { + .name = "mem-increase", + .args_type = "pfx:s,num:s", + .mhandler.cmd_new = do_dimm_add_range, + }, +SQMP +mem-increase +------------- + +Hotplug memory DIMMs from memory pool + +Will hotplug num memory DIMMs from pool with name pfx. + +Example: + +-> { "execute": "mem-increase", "arguments": { "pfx" : "pool", "num": "10" } } +<- { "return": {} } + +EQMP + + { + .name = "mem-decrease", + .args_type = "pfx:s,num:s", + .mhandler.cmd_new = do_dimm_del_range, + }, +SQMP +mem-decrease +------------- + +Hot-unplug memory DIMMs from memory pool + +Will hot-unplug num memory DIMMs from pool with name pfx. + +Example: + +-> { "execute": "mem-decrease", "arguments": { "pfx" : "pool", "num": "10" } } +<- { "return": {} } + +EQMP
Signature · 1 line
1.7.9
Quoted 1 line · Vasilis Liaskovitis
This is v2 of the ACPI memory hotplug prototype for
x86_64target.
I think the concept of DIMMs (what about SIMMs? SODIMMs? I liked memslot) would be useful for most targets, but hotplugging may be limited to x86 only. It would be nice to keep these two separate or as loosely coupled as possible.
Quoted 115 lines
Changes
v1->v2- memory map is automatically calculated for hotplug dimms. Dimms are added from top-of-memory skipping the pci hole at [
PCI_HOLE_START, 4G).
- Renamed from "-memslot" to "-dimm". Commands changed to "dimm_add", "dimm_del".
- Seabios ejection array reduced to a byte. Use extraction macros for dimm ssdt.
- additional SRAT paravirt info does not break previous SRATfw_cfglayout.
- Documentation of newacpi_piix4registers and paravirt data.
- add ACPI_OSTsupport for_OSTenabled guests. This allows qemu to receive notification for success / failure of memory hot-add and hot-remove operations. Guest needs to support_OST(https://lkml.org/lkml/2012/6/25/321)
- add monitor info command to report total guest memory (initial + hot-added)
- add command line options and monitor commands for batch dimm creation/populationOverview:
Dimm devices are modeled with a new qemu command line
"-dimm id=name,size=sz,node=pxm,populated=on|off"
As already mentioned, the starting physical address for all dimms is calculated automatically from top of memory, skipping the pci hole at [
PCI_HOLE_START, 4G). Node is defining numa proximity for this dimm. When not defined it defaults to zero.
"-dimm id=dimm0,size=512M,node=0,populated=off"
will define a 512M memory slot belonging to numa node 0.Dimms are added or removed with a new hmp command "dimm_add/dimm_del":
Hot-add syntax: "dimm_addid"
Hot-remove syntax: "dimm_delid"Issues:
- Live migration works as long as populated field is changed to "on" for hotplugged dimms at the destination qemu command line (patch 12/21 lifts this requirement). The DimmState structure does not yet define a VMStateDescription, but i assume this is the preferred way to pass state for migration.
- Dimms are abstracted as qdevices attached to the main system bus. However, memory hotplugging has its own side channel ignoring main_system_bus's hotplug incapability. A cleaner integration is still needed, probably attaching memory devices as children-links of an acpi-capable device (in the pc case
acpi_piix4) instead of the system bus (TBD). Then device_add/device_del instead of new commands can hopefully be used.Comments/review welcome.
series is based on uq/master for qemu-kvm, and master for seabios. Can be found also at:
http://github.com/vliaskov/qemu-kvm/commits/memhp-v2
http://github.com/vliaskov/seabios/commits/memhp-v2Vasilis Liaskovitis (14):
dimm: Implement memory device abstraction
acpi_piix4: Implement memory device hotplug registers
pc: calculate dimm physical addresses and adjust memory map
pc: Add dimm paravirt SRAT info
Implement "-dimm" command line option
Implementdimm_addanddimm_delcommands for hmp and qmp fix live-migration when "populated=on" is missing Implement memory hotplug notification lists
acpi_piix4:_OSTdimm support
acpi_piix4: Update dimm state on VM reboot
acpi_piix4: Update dimm bitmap state on hot-remove fail Implement "info memtotal" and "query-memtotal" Implement -dimms, -dimmspop command line options Implementmem_increase,mem_decreasehmp/qmp commandsarch_init.c | 23 ++- docs/specs/acpi_hotplug.txt | 46 +++++ docs/specs/fwcfg.txt | 28 +++ hmp-commands.hx | 67 +++++++ hmp.c | 24 +++ hmp.h | 2 + hw/Makefile.objs | 2 +- hw/acpi_piix4.c | 131 ++++++++++++- hw/dimm.c | 449 +++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 72 +++++++ hw/pc.c | 94 +++++++++- hw/pc.h | 6 + hw/pc_piix.c | 18 ++- monitor.c | 35 ++++ monitor.h | 5 + qapi-schema.json | 38 ++++ qemu-config.c | 70 +++++++ qemu-options.hx | 15 ++ qmp-commands.hx | 137 +++++++++++++ sysemu.h | 1 + vl.c | 122 ++++++++++++- 21 files changed, 1368 insertions(+), 17 deletions(-) create mode 100644 docs/specs/acpi_hotplug.txt create mode 100644 docs/specs/fwcfg.txt create mode 100644 hw/dimm.c create mode 100644 hw/dimm.hVasilis Liaskovitis (7):
Add ACPI_EXTRACT_DEVICE* macros
Add SSDT memory device support
acpi-dsdt: Implement functions for memory hotplug.
acpi: generate hotplug memory devices.
pciinit: Fixpcimem_startvalue
acpi_dsdt: Support_OSTdimm method
acpi_dsdt: Revert internal dimm state on_OSTfailureMakefile | 2 +- src/acpi-dsdt.dsl | 120 ++++++++++++++++++++++++++++++++++++- src/acpi.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++-- src/pciinit.c | 2 +- src/ssdt-mem.dsl | 69 +++++++++++++++++++++ tools/acpi_extract.py | 28 +++++++++ 6 files changed, 369 insertions(+), 10 deletions(-) create mode 100644 src/ssdt-mem.dsl
Quoted 8 lines · Blue Swirl
Quoted 1 line · Vasilis Liaskovitis
This is v2 of the ACPI memory hotplug prototype for
x86_64target.I think the concept of DIMMs (what about SIMMs? SODIMMs? I liked memslot) would be useful for most targets, but hotplugging may be limited to x86 only. It would be nice to keep these two separate or as loosely coupled as possible.
agreed.
what specific usecases besides hotplugging are you thinking about? Also are there non-acpi hotplug platforms?
I am trying to keep generic dimm manipulation functions (e.g. population / depopulation and searching) in hw/dimm[.ch]. Currently the x86-acpi_piix4 "backend" registers a callback for hot-add / hot-remove. In theory other hotplug backends can hook in.
btw I don't mind using "-memslot" (I think someone during v1 mentioned -dimm), we just need some consensus on the naming.
Quoted 116 lines
Quoted 116 lines
Changes
v1->v2- memory map is automatically calculated for hotplug dimms. Dimms are added from top-of-memory skipping the pci hole at [
PCI_HOLE_START, 4G).
- Renamed from "-memslot" to "-dimm". Commands changed to "dimm_add", "dimm_del".
- Seabios ejection array reduced to a byte. Use extraction macros for dimm ssdt.
- additional SRAT paravirt info does not break previous SRATfw_cfglayout.
- Documentation of newacpi_piix4registers and paravirt data.
- add ACPI_OSTsupport for_OSTenabled guests. This allows qemu to receive notification for success / failure of memory hot-add and hot-remove operations. Guest needs to support_OST(https://lkml.org/lkml/2012/6/25/321)
- add monitor info command to report total guest memory (initial + hot-added)
- add command line options and monitor commands for batch dimm creation/populationOverview:
Dimm devices are modeled with a new qemu command line
"-dimm id=name,size=sz,node=pxm,populated=on|off"
As already mentioned, the starting physical address for all dimms is calculated automatically from top of memory, skipping the pci hole at [
PCI_HOLE_START, 4G). Node is defining numa proximity for this dimm. When not defined it defaults to zero.
"-dimm id=dimm0,size=512M,node=0,populated=off"
will define a 512M memory slot belonging to numa node 0.Dimms are added or removed with a new hmp command "dimm_add/dimm_del":
Hot-add syntax: "dimm_addid"
Hot-remove syntax: "dimm_delid"Issues:
- Live migration works as long as populated field is changed to "on" for hotplugged dimms at the destination qemu command line (patch 12/21 lifts this requirement). The DimmState structure does not yet define a VMStateDescription, but i assume this is the preferred way to pass state for migration.
- Dimms are abstracted as qdevices attached to the main system bus. However, memory hotplugging has its own side channel ignoring main_system_bus's hotplug incapability. A cleaner integration is still needed, probably attaching memory devices as children-links of an acpi-capable device (in the pc case
acpi_piix4) instead of the system bus (TBD). Then device_add/device_del instead of new commands can hopefully be used.Comments/review welcome.
series is based on uq/master for qemu-kvm, and master for seabios. Can be found also at:
http://github.com/vliaskov/qemu-kvm/commits/memhp-v2
http://github.com/vliaskov/seabios/commits/memhp-v2Vasilis Liaskovitis (14):
dimm: Implement memory device abstraction
acpi_piix4: Implement memory device hotplug registers
pc: calculate dimm physical addresses and adjust memory map
pc: Add dimm paravirt SRAT info
Implement "-dimm" command line option
Implementdimm_addanddimm_delcommands for hmp and qmp fix live-migration when "populated=on" is missing Implement memory hotplug notification lists
acpi_piix4:_OSTdimm support
acpi_piix4: Update dimm state on VM reboot
acpi_piix4: Update dimm bitmap state on hot-remove fail Implement "info memtotal" and "query-memtotal" Implement -dimms, -dimmspop command line options Implementmem_increase,mem_decreasehmp/qmp commandsarch_init.c | 23 ++- docs/specs/acpi_hotplug.txt | 46 +++++ docs/specs/fwcfg.txt | 28 +++ hmp-commands.hx | 67 +++++++ hmp.c | 24 +++ hmp.h | 2 + hw/Makefile.objs | 2 +- hw/acpi_piix4.c | 131 ++++++++++++- hw/dimm.c | 449 +++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 72 +++++++ hw/pc.c | 94 +++++++++- hw/pc.h | 6 + hw/pc_piix.c | 18 ++- monitor.c | 35 ++++ monitor.h | 5 + qapi-schema.json | 38 ++++ qemu-config.c | 70 +++++++ qemu-options.hx | 15 ++ qmp-commands.hx | 137 +++++++++++++ sysemu.h | 1 + vl.c | 122 ++++++++++++- 21 files changed, 1368 insertions(+), 17 deletions(-) create mode 100644 docs/specs/acpi_hotplug.txt create mode 100644 docs/specs/fwcfg.txt create mode 100644 hw/dimm.c create mode 100644 hw/dimm.hVasilis Liaskovitis (7):
Add ACPI_EXTRACT_DEVICE* macros
Add SSDT memory device support
acpi-dsdt: Implement functions for memory hotplug.
acpi: generate hotplug memory devices.
pciinit: Fixpcimem_startvalue
acpi_dsdt: Support_OSTdimm method
acpi_dsdt: Revert internal dimm state on_OSTfailureMakefile | 2 +- src/acpi-dsdt.dsl | 120 ++++++++++++++++++++++++++++++++++++- src/acpi.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++-- src/pciinit.c | 2 +- src/ssdt-mem.dsl | 69 +++++++++++++++++++++ tools/acpi_extract.py | 28 +++++++++ 6 files changed, 369 insertions(+), 10 deletions(-) create mode 100644 src/ssdt-mem.dsl
Quoted 5 lines · Vasilis Liaskovitis
Quoted 4 lines · Blue Swirl
Quoted 1 line · Vasilis Liaskovitis
This is v2 of the ACPI memory hotplug prototype for
x86_64target.
Quoted 7 lines
Quoted 4 lines
I think the concept of DIMMs (what about SIMMs? SODIMMs? I liked memslot) would be useful for most targets, but hotplugging may be limited to x86 only. It would be nice to keep these two separate or as loosely coupled as possible.
agreed.
what specific usecases besides hotplugging are you thinking about?
Most real boards have some kind of RAM module slots. Now this is implemented with -m option, but a generic memory slot model would be more accurate. Also the memory layout needs to be communicated to BIOS somehow unless we want to spend cycles for BIOS memory probes. The NUMA fw_cfg memory description should be usable for most cases even for embedded UP machines.
Quoted 1 line
Also are there non-acpi hotplug platforms?
Some enterprise-class Sparc and PPC machines support memory hotplug.
Quoted 125 lines
I am trying to keep generic dimm manipulation functions (e.g. population / depopulation and searching) in hw/dimm[.ch]. Currently the x86-acpi_piix4 "backend" registers a callback for hot-add / hot-remove. In theory other hotplug backends can hook in.
btw I don't mind using "-memslot" (I think someone during v1 mentioned -dimm), we just need some consensus on the naming.
Quoted 116 lines
Quoted 116 lines
Changes
v1->v2- memory map is automatically calculated for hotplug dimms. Dimms are added from top-of-memory skipping the pci hole at [
PCI_HOLE_START, 4G).
- Renamed from "-memslot" to "-dimm". Commands changed to "dimm_add", "dimm_del".
- Seabios ejection array reduced to a byte. Use extraction macros for dimm ssdt.
- additional SRAT paravirt info does not break previous SRATfw_cfglayout.
- Documentation of newacpi_piix4registers and paravirt data.
- add ACPI_OSTsupport for_OSTenabled guests. This allows qemu to receive notification for success / failure of memory hot-add and hot-remove operations. Guest needs to support_OST(https://lkml.org/lkml/2012/6/25/321)
- add monitor info command to report total guest memory (initial + hot-added)
- add command line options and monitor commands for batch dimm creation/populationOverview:
Dimm devices are modeled with a new qemu command line
"-dimm id=name,size=sz,node=pxm,populated=on|off"
As already mentioned, the starting physical address for all dimms is calculated automatically from top of memory, skipping the pci hole at [
PCI_HOLE_START, 4G). Node is defining numa proximity for this dimm. When not defined it defaults to zero.
"-dimm id=dimm0,size=512M,node=0,populated=off"
will define a 512M memory slot belonging to numa node 0.Dimms are added or removed with a new hmp command "dimm_add/dimm_del":
Hot-add syntax: "dimm_addid"
Hot-remove syntax: "dimm_delid"Issues:
- Live migration works as long as populated field is changed to "on" for hotplugged dimms at the destination qemu command line (patch 12/21 lifts this requirement). The DimmState structure does not yet define a VMStateDescription, but i assume this is the preferred way to pass state for migration.
- Dimms are abstracted as qdevices attached to the main system bus. However, memory hotplugging has its own side channel ignoring main_system_bus's hotplug incapability. A cleaner integration is still needed, probably attaching memory devices as children-links of an acpi-capable device (in the pc case
acpi_piix4) instead of the system bus (TBD). Then device_add/device_del instead of new commands can hopefully be used.Comments/review welcome.
series is based on uq/master for qemu-kvm, and master for seabios. Can be found also at:
http://github.com/vliaskov/qemu-kvm/commits/memhp-v2
http://github.com/vliaskov/seabios/commits/memhp-v2Vasilis Liaskovitis (14):
dimm: Implement memory device abstraction
acpi_piix4: Implement memory device hotplug registers
pc: calculate dimm physical addresses and adjust memory map
pc: Add dimm paravirt SRAT info
Implement "-dimm" command line option
Implementdimm_addanddimm_delcommands for hmp and qmp fix live-migration when "populated=on" is missing Implement memory hotplug notification lists
acpi_piix4:_OSTdimm support
acpi_piix4: Update dimm state on VM reboot
acpi_piix4: Update dimm bitmap state on hot-remove fail Implement "info memtotal" and "query-memtotal" Implement -dimms, -dimmspop command line options Implementmem_increase,mem_decreasehmp/qmp commandsarch_init.c | 23 ++- docs/specs/acpi_hotplug.txt | 46 +++++ docs/specs/fwcfg.txt | 28 +++ hmp-commands.hx | 67 +++++++ hmp.c | 24 +++ hmp.h | 2 + hw/Makefile.objs | 2 +- hw/acpi_piix4.c | 131 ++++++++++++- hw/dimm.c | 449 +++++++++++++++++++++++++++++++++++++++++++ hw/dimm.h | 72 +++++++ hw/pc.c | 94 +++++++++- hw/pc.h | 6 + hw/pc_piix.c | 18 ++- monitor.c | 35 ++++ monitor.h | 5 + qapi-schema.json | 38 ++++ qemu-config.c | 70 +++++++ qemu-options.hx | 15 ++ qmp-commands.hx | 137 +++++++++++++ sysemu.h | 1 + vl.c | 122 ++++++++++++- 21 files changed, 1368 insertions(+), 17 deletions(-) create mode 100644 docs/specs/acpi_hotplug.txt create mode 100644 docs/specs/fwcfg.txt create mode 100644 hw/dimm.c create mode 100644 hw/dimm.hVasilis Liaskovitis (7):
Add ACPI_EXTRACT_DEVICE* macros
Add SSDT memory device support
acpi-dsdt: Implement functions for memory hotplug.
acpi: generate hotplug memory devices.
pciinit: Fixpcimem_startvalue
acpi_dsdt: Support_OSTdimm method
acpi_dsdt: Revert internal dimm state on_OSTfailureMakefile | 2 +- src/acpi-dsdt.dsl | 120 ++++++++++++++++++++++++++++++++++++- src/acpi.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++-- src/pciinit.c | 2 +- src/ssdt-mem.dsl | 69 +++++++++++++++++++++ tools/acpi_extract.py | 28 +++++++++ 6 files changed, 369 insertions(+), 10 deletions(-) create mode 100644 src/ssdt-mem.dsl