Add max-ram-below-4g (was Add pci_hole_min_size machine option)
v7 cover Add max-ram-below-4g (was Add pci_hole_min_size machine option)
Changes v6 to v7:
Drop most of v5 to v6 changes.
Michael S. Tsirkin:
#2 "pc & q35: Add new machine opt max-ram-below-4g":
default: max-ram-below-4g=4g
pc & q35:
calculate lowmem
lowmem = MIN(lowmem, max-ram-below-4g) calculate above_4g_mem_size and below_4g_mem_size
#3 "xen-hvm: Handle machine opt max-ram-below-4g":
Rename from "xen-hvm: Pass is_default to xen_hvm_init" Drop is_default.
Use object_property_get_int() to get max-ram-below-4g. Do min(xen limit, user limit).
Changes v5 to v6:
rebased on git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git pci
Changed default handling. Most pc machines are now set to 3.5G (0xe0000000) and q35 are set to 2.75G (0xb0000000). The special value of 0 is used to flag the complex gigabyte_align memory layout selection.
I did change the default for pc-i440fx-2.1 to 3G and pc-q35-2.1 to 2G instead of the complex gigabyte_align. This looks ok to me because the statement by Gerd Hoffmann is about more ram for 32 bit (+non-PAE) guests can now have more then the defualt by specifing the new option like "max-ram-below-4g=3.75G" or "max-ram-below-4g=3.9375G". Or if that is too complex to understand just select pc-i440fx-2.0 or pc-q35-2.0 to get what they use to get.
Michael S. Tsirkin, Igor Mammedov, Marcel Apfelbaum:
#2 "pc & q35: Add new machine opt max-ram-below-4g":
Added setting of .default_machine_opts to include max-ram-below-4g
for all pc types.
Removed gigabyte_align.
Added warning on small value.
"less then" to "less than"
#3 "xen-hvm: Pass is_default to xen_hvm_init":
Changed to work with the changes in #2:
Added max_ram_below_4g_changed in order to know if it is a default value or a user specified one.
Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
"make check" will abort on default not set for any of the pc or q35 machine types.
Dropped "Acked-by: Stefano Stabellin" do to bigger change.
Changes v4 to v5:
Re-work based on:
https://github.com/imammedo/qemu/commits/memory-hotplug-v11
And so it now depends on this patch set.
Stefano Stabellini:
#3 "xen-hvm: Pass is_default to xen_hvm_init"
Acked-by
Minor change of pmc to pcms.
Changes v3 to v4:
Split out #2 "GlobalProperty: Display warning about unused -global" rebase on e00fcfe (origin/master)
rename xen-all to xen-hvm
Adjust #1 "xen-hvm: Fix xen_hvm_init() to adjust pc memory layout"
Switch Acked-by & Signed-off-by
rebase on master
Rework #3 "xen-hvm: Pass is_default to xen_hvm_init":
To pass is_default instead of max_ram_below_4g.
Also did not add "Acked-by: Stefano Stabellini" since code changed a lot.
Andreas Färber:
all: Remove dot at end of subject
#3 "xen-hvm: Pass is_default to xen_hvm_init"
Adjust comment formatting.
Andreas Färber, Paolo Bonzini, Marcel Apfelbaum:
rework to use "opts per machine"
Drop old #3, new #2.
Changes v2 to v3:
Stefano Stabellini:
Acked-by #1 "xen-all: Fix xen_hvm_init() to adjust pc memory" Adjust for code readability #4 "xen-all: Pass max_ram_below_4g to xen_hvm_init."
Set max_ram_below_4g always and use it to calculate above_4g_mem_size, below_4g_mem_size.
Changes v1 to v2:
Michael S. Tsirkin:
Rename option.
Only add it to machine types that support it.
Split into 4 parts.
1/4 -- xen-all: Fix xen_hvm_init() to adjust pc memory layout
This looks to be a possible bug that has yet to be found. below_4g_mem_size and above_4g_mem_size are stored in PcGuestInfo (pc_guest_info_init) which are currently not "correct". This and 4/4 change the same lines.
2/4 -- GlobalProperty: Display warning about unused -global
My testing showed that setting a global property on an object that is not used is not reported at all. This is added to help when the new global is set but not used. The negative not_used was picked so that all static objects are assumed to be used even when they are not.
3/4 -- pc & q35: Add new object pc-memory-layout
The objects that it might make sense to add this property to all get created too late. So add a new object just to hold this property. Name it so that it is expected that only pc (and q35) machine types support it.
4/4 -- xen-all: Pass max_ram_below_4g to xen_hvm_init
Seprate the xen only part of the change. Currectly based on patch 1/4
Don Slutz (3):
xen-hvm: Fix xen_hvm_init() to adjust pc memory layout pc & q35: Add new machine opt max-ram-below-4g
xen-hvm: Handle machine opt max-ram-below-4g
hw/i386/pc.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 53 ++++++++++++++++++++++++++++++++++++---------------- hw/i386/pc_q35.c | 51 +++++++++++++++++++++++++++++++++++--------------- include/hw/i386/pc.h | 3 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 ++++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 53 +++++++++++++++++++++++++++++++++------------------- 8 files changed, 165 insertions(+), 52 deletions(-)
Signature · 1 line
1.8.4
PATCH v7 1/3 xen-hvm: Fix xen_hvm_init() to adjust pc memory layout
This is just below_4g_mem_size and above_4g_mem_size which is used later in QEMU.
---
v7:
No change
v6:
No change
v5:
No change
v4:
Switch Acked-by & Signed-off-by
rebase on master
v3:
Add Acked-by: Stefano Stabellini
v2:
No change
hw/i386/pc_piix.c | 31 ++++++++++++++++--------------- hw/i386/pc_q35.c | 29 +++++++++++++++-------------- include/hw/xen/xen.h | 3 ++- xen-hvm-stub.c | 3 ++- xen-hvm.c | 24 ++++++++++++++---------- 5 files changed, 49 insertions(+), 41 deletions(-)
hw/i386/pc_piix.c +16 -15
@@ -99,21 +99,6 @@ static void pc_init1(MachineState *machine,FWCfgState *fw_cfg =NULL ;PcGuestInfo *guest_info; -if (xen_enabled () &&xen_hvm_init (&ram_memory) !=0 ) { -fprintf (stderr,"xen hardware virtual machine initialisation failed\n" ); -exit (1 ); - } - - icc_bridge =qdev_create (NULL ,TYPE_ICC_BRIDGE ); -object_property_add_child (qdev_get_machine (),"icc-bridge" , -OBJECT (icc_bridge),NULL ); - -pc_cpus_init (machine->cpu_model, icc_bridge); - -if (kvm_enabled () && kvmclock_enabled) { -kvmclock_create (); - } -/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory). * If it doesn't, we need to split it in chunks below and above 4G. * In any case, try to make sure that guest addresses aligned at
@@ -130,6 +115,22 @@ static void pc_init1(MachineState *machine, below_4g_mem_size = machine->ram_size; } +if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, + &ram_memory) !=0 ) { +fprintf (stderr,"xen hardware virtual machine initialisation failed\n" ); +exit (1 ); + } + + icc_bridge =qdev_create (NULL ,TYPE_ICC_BRIDGE ); +object_property_add_child (qdev_get_machine (),"icc-bridge" , +OBJECT (icc_bridge),NULL ); + +pc_cpus_init (machine->cpu_model, icc_bridge); + +if (kvm_enabled () && kvmclock_enabled) { +kvmclock_create (); + } +if (pci_enabled) { pci_memory =g_new (MemoryRegion,1 );memory_region_init (pci_memory,NULL ,"pci" ,UINT64_MAX );
hw/i386/pc_q35.c +15 -14
@@ -86,20 +86,6 @@ static void pc_q35_init(MachineState *machine)DeviceState *icc_bridge;PcGuestInfo *guest_info; -if (xen_enabled () &&xen_hvm_init (&ram_memory) !=0 ) { -fprintf (stderr,"xen hardware virtual machine initialisation failed\n" ); -exit (1 ); - } - - icc_bridge =qdev_create (NULL ,TYPE_ICC_BRIDGE ); -object_property_add_child (qdev_get_machine (),"icc-bridge" , -OBJECT (icc_bridge),NULL ); - -pc_cpus_init (machine->cpu_model, icc_bridge); -pc_acpi_init ("q35-acpi-dsdt.aml" ); - -kvmclock_create (); -/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping * also known as MMCFG).
@@ -118,6 +104,21 @@ static void pc_q35_init(MachineState *machine) below_4g_mem_size = machine->ram_size; } +if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, + &ram_memory) !=0 ) { +fprintf (stderr,"xen hardware virtual machine initialisation failed\n" ); +exit (1 ); + } + + icc_bridge =qdev_create (NULL ,TYPE_ICC_BRIDGE ); +object_property_add_child (qdev_get_machine (),"icc-bridge" , +OBJECT (icc_bridge),NULL ); + +pc_cpus_init (machine->cpu_model, icc_bridge); +pc_acpi_init ("q35-acpi-dsdt.aml" ); + +kvmclock_create (); +/* pci enabled */ if (pci_enabled) { pci_memory =g_new (MemoryRegion,1 );
include/hw/xen/xen.h +2 -1
@@ -37,10 +37,11 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);qemu_irq *xen_interrupt_controller_init (void );int xen_init (MachineClass *mc); -int xen_hvm_init (MemoryRegion **ram_memory);void xenstore_store_pv_console_info (int i,struct CharDriverState *chr);#if defined(NEED_CPU_H ) && !defined(CONFIG_USER_ONLY ) +int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, +MemoryRegion **ram_memory);void xen_ram_alloc (ram_addr_t ram_addr,ram_addr_t size,struct MemoryRegion *mr);void xen_modified_memory (ram_addr_t start,ram_addr_t length);
xen-hvm-stub.c +2 -1
@@ -51,7 +51,8 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) { } -int xen_hvm_init (MemoryRegion **ram_memory) +int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, +MemoryRegion **ram_memory) {return 0 ; }
xen-hvm.c +14 -10
@@ -155,10 +155,11 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init (ram_addr_t ram_size,MemoryRegion **ram_memory_p) +static void xen_ram_init (ram_addr_t *below_4g_mem_size, +ram_addr_t *above_4g_mem_size, +ram_addr_t ram_size,MemoryRegion **ram_memory_p) {MemoryRegion *sysmem =get_system_memory (); -ram_addr_t below_4g_mem_size, above_4g_mem_size =0 ;ram_addr_t block_len; block_len = ram_size;
@@ -173,10 +174,11 @@ static void xen_ram_init(ram_addr_t ram_size, MemoryRegion **ram_memory_p)vmstate_register_ram_global (&ram_memory);if (ram_size >=HVM_BELOW_4G_RAM_END ) { - above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ; - below_4g_mem_size =HVM_BELOW_4G_RAM_END ; + *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ; + *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; }else { - below_4g_mem_size = ram_size; + *above_4g_mem_size =0 ; + *below_4g_mem_size = ram_size; } memory_region_init_alias(&ram_640k, NULL, "xen.ram.640k",
@@ -189,12 +191,13 @@ static void xen_ram_init(ram_addr_t ram_size, MemoryRegion **ram_memory_p)* the Options ROM, so it is registered here as RAM. */ memory_region_init_alias (&ram_lo,NULL ,"xen.ram.lo" , - &ram_memory,0xc0000 , below_4g_mem_size -0xc0000 ); + &ram_memory,0xc0000 , + *below_4g_mem_size -0xc0000 );memory_region_add_subregion (sysmem,0xc0000 , &ram_lo); -if (above_4g_mem_size >0 ) { +if (*above_4g_mem_size >0 ) {memory_region_init_alias (&ram_hi,NULL ,"xen.ram.hi" , &ram_memory,0x100000000ULL , - above_4g_mem_size); + *above_4g_mem_size);memory_region_add_subregion (sysmem,0x100000000ULL , &ram_hi); } }
@@ -958,7 +961,8 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,0 ); } -int xen_hvm_init (MemoryRegion **ram_memory) +int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, +MemoryRegion **ram_memory) {int i, rc;unsigned long ioreq_pfn;
@@ -1036,7 +1040,7 @@ int xen_hvm_init(MemoryRegion **ram_memory)/* Init RAM management */ xen_map_cache_init (xen_phys_offset_to_gaddr, state); -xen_ram_init (ram_size, ram_memory); +xen_ram_init (below_4g_mem_size, above_4g_mem_size, ram_size, ram_memory);qemu_add_vm_change_state_handler (xen_hvm_change_state_handler, state);
Signature · 1 line
1.8.4
PATCH v7 2/3 pc & q35: Add new machine opt max-ram-below-4g
In reply to Don SlutzThis is a pc & q35 only machine opt.
If you add enough PCI devices then all mmio for them will not fit below 4G which may not be the layout the user wanted. This allows you to increase the below 4G address space that PCI devices can use (aka decrease ram below 4G) and therefore in more cases not have any mmio that is above 4G.
For example using "-machine pc,max-ram-below-4g=2G" on the command line will limit the amount of ram that is below 4G to 2G.
Note: this machine option cannot be used to increase the amount of ram below 4G.
---
v7:
Drop most of v5 to v6 changes.
default: max-ram-below-4g=4g
pc & q35:
calculate lowmem
lowmem = MIN(lowmem, max-ram-below-4g)
calculate above_4g_mem_size and below_4g_mem_size
v6:
Added setting of .default_machine_opts to include max-ram-below-4g
for all pc types.
Removed gigabyte_align
Added warning on small value.
"less then" to "less than"
v5:
Re-work based on:
https://github.com/imammedo/qemu/commits/memory-hotplug-v11
hw/i386/pc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 22 +++++++++++++++++++++- hw/i386/pc_q35.c | 22 +++++++++++++++++++++- include/hw/i386/pc.h | 3 +++ vl.c | 4 ++++ 5 files changed, 96 insertions(+), 2 deletions(-)
hw/i386/pc.c +47 -0
@@ -1647,11 +1647,58 @@ pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque,visit_type_int (v, &value, name, errp); } +static void pc_machine_get_max_ram_below_4g (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); +uint64_t value = pcms->max_ram_below_4g; + +visit_type_size (v, &value, name, errp); +} + +static void pc_machine_set_max_ram_below_4g (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); +Error *error =NULL ; +uint64_t value; + +visit_type_size (v, &value, name, &error); +if (error) { +error_propagate (errp, error); +return ; + } +if (value > (1ULL <<32 )) { +error_set (&error,ERROR_CLASS_GENERIC_ERROR , +"Machine option 'max-ram-below-4g=%" PRIu64 +"' expects size less than or equal to 4G" , value); +error_propagate (errp, error); +return ; + } + +if (value < (1ULL <<20 )) { +error_report ("Warning: small max_ram_below_4g(%" PRIu64 +") less than 1M. BIOS may not work.." , + value); + } + + pcms->max_ram_below_4g = value; +} +static void pc_machine_initfn (Object *obj) { +PCMachineState *pcms =PC_MACHINE (obj); +object_property_add (obj,PC_MACHINE_MEMHP_REGION_SIZE ,"int" , pc_machine_get_hotplug_memory_region_size,NULL ,NULL ,NULL ,NULL ); + pcms->max_ram_below_4g =1UL <<32 ;/* 4G */ +object_property_add (obj,PC_MACHINE_MAX_RAM_BELOW_4G ,"size" , + pc_machine_get_max_ram_below_4g, + pc_machine_set_max_ram_below_4g, +NULL ,NULL ,NULL ); }static void pc_machine_class_init (ObjectClass *oc,void *data)
hw/i386/pc_piix.c +21 -1
@@ -48,6 +48,7 @@#include "exec/address-spaces.h" #include "hw/acpi/acpi.h" #include "cpu.h" +#include "qemu/error-report.h" #ifdef CONFIG_XEN # include <xen/hvm/hvm_info_table.h> #endif
@@ -98,6 +99,7 @@ static void pc_init1(MachineState *machine,DeviceState *icc_bridge;FWCfgState *fw_cfg =NULL ;PcGuestInfo *guest_info; +ram_addr_t lowmem;/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory). * If it doesn't, we need to split it in chunks below and above 4G.
@@ -107,7 +109,25 @@ static void pc_init1(MachineState *machine,* breaking migration. */ if (machine->ram_size >=0xe0000000 ) { -ram_addr_t lowmem = gigabyte_align ?0xc0000000 :0xe0000000 ; + lowmem = gigabyte_align ?0xc0000000 :0xe0000000 ; + }else { + lowmem =0xe0000000 ; + } + +/* Handle the machine opt max-ram-below-4g. It is basicly doing +* min(qemu limit, user limit). +*/ +if (lowmem > pc_machine->max_ram_below_4g) { + lowmem = pc_machine->max_ram_below_4g; +if (machine->ram_size - lowmem > lowmem && + lowmem & ((1ULL <<30 ) -1 )) { +error_report ("Warning: Large machine and max_ram_below_4g(%" PRIu64 +") not a multiple of 1G; possible bad performance." , + pc_machine->max_ram_below_4g); + } + } + +if (machine->ram_size >= lowmem) { above_4g_mem_size = machine->ram_size - lowmem; below_4g_mem_size = lowmem; }else {
hw/i386/pc_q35.c +21 -1
@@ -44,6 +44,7 @@#include "hw/ide/ahci.h" #include "hw/usb.h" #include "hw/cpu/icc_bus.h" +#include "qemu/error-report.h" /* ICH9 AHCI has 6 ports */ #define MAX_SATA_PORTS 6
@@ -85,6 +86,7 @@ static void pc_q35_init(MachineState *machine)PCIDevice *ahci;DeviceState *icc_bridge;PcGuestInfo *guest_info; +ram_addr_t lowmem;/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
@@ -96,7 +98,25 @@ static void pc_q35_init(MachineState *machine)* breaking migration. */ if (machine->ram_size >=0xb0000000 ) { -ram_addr_t lowmem = gigabyte_align ?0x80000000 :0xb0000000 ; + lowmem = gigabyte_align ?0x80000000 :0xb0000000 ; + }else { + lowmem =0xb0000000 ; + } + +/* Handle the machine opt max-ram-below-4g. It is basicly doing +* min(qemu limit, user limit). +*/ +if (lowmem > pc_machine->max_ram_below_4g) { + lowmem = pc_machine->max_ram_below_4g; +if (machine->ram_size - lowmem > lowmem && + lowmem & ((1ULL <<30 ) -1 )) { +error_report ("Warning: Large machine and max_ram_below_4g(%" PRIu64 +") not a multiple of 1G; possible bad performance." , + pc_machine->max_ram_below_4g); + } + } + +if (machine->ram_size >= lowmem) { above_4g_mem_size = machine->ram_size - lowmem; below_4g_mem_size = lowmem; }else {
include/hw/i386/pc.h +3 -0
@@ -33,10 +33,13 @@ struct PCMachineState {MemoryRegion hotplug_memory;HotplugHandler *acpi_dev; + +uint64_t max_ram_below_4g; };#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"#define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size" +#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"/** * PCMachineClass:
vl.c +4 -0
@@ -381,6 +381,10 @@ static QemuOptsList qemu_machine_opts = { .name = "kvm-type", .type = QEMU_OPT_STRING, .help = "Specifies the KVM virtualization mode (HV, PR)", + },{ + .name = PC_MACHINE_MAX_RAM_BELOW_4G, + .type = QEMU_OPT_SIZE, + .help = "maximum ram below the 4G boundary (32bit boundary)", }, {/* End of list */ } },
Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g
Quoted 89 lines · Don Slutz
This is a pc & q35 only machine opt.
If you add enough PCI devices then all mmio for them will not fit below 4G which may not be the layout the user wanted. This allows you to increase the below 4G address space that PCI devices can use (aka decrease ram below 4G) and therefore in more cases not have any mmio that is above 4G.
For example using "-machine pc,max-ram-below-4g=2G" on the command line will limit the amount of ram that is below 4G to 2G.
Note: this machine option cannot be used to increase the amount of ram below 4G.
Signed-off-by Don Slutz <[email protected]>---
v7:
Drop most of v5 to v6 changes.
default: max-ram-below-4g=4g
pc & q35:
calculate lowmem
lowmem =MIN(lowmem, max-ram-below-4g)
calculateabove_4g_mem_sizeandbelow_4g_mem_size
v6:
Added setting of .default_machine_opts to include max-ram-below-4g
for all pc types.
Removedgigabyte_align
Added warning on small value.
"less then" to "less than"v5:
Re-work based on:https://github.com/imammedo/qemu/commits/memory-hotplug-v11
hw/i386/pc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 22 +++++++++++++++++++++- hw/i386/pc_q35.c | 22 +++++++++++++++++++++- include/hw/i386/pc.h | 3 +++ vl.c | 4 ++++ 5 files changed, 96 insertions(+), 2 deletions(-)hw/i386/pc.c +38
-0@@ -1647,11 +1647,58 @@ pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque,visit_type_int (v, &value, name, errp); } +static void pc_machine_get_max_ram_below_4g (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); +uint64_t value = pcms->max_ram_below_4g; + +visit_type_size (v, &value, name, errp); +} + +static void pc_machine_set_max_ram_below_4g (Object *obj,Visitor *v, +void *opaque,const char *name, +Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); +Error *error =NULL ; +uint64_t value; + +visit_type_size (v, &value, name, &error); +if (error) { +error_propagate (errp, error); +return ; + } +if (value > (1ULL <<32 )) { +error_set (&error,ERROR_CLASS_GENERIC_ERROR , +"Machine option 'max-ram-below-4g=%" PRIu64 +"' expects size less than or equal to 4G" , value); +error_propagate (errp, error); +return ; + } + +if (value < (1ULL <<20 )) { +error_report ("Warning: small max_ram_below_4g(%" PRIu64 +") less than 1M. BIOS may not work.." , + value); + } + + pcms->max_ram_below_4g = value;
hw/i386/pc.c pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque, · line 1697
Quoted 10 lines
hw/i386/pc.c +5
-0+} +static void pc_machine_initfn (Object *obj) { +PCMachineState *pcms =PC_MACHINE (obj); +object_property_add (obj,PC_MACHINE_MEMHP_REGION_SIZE ,"int" , pc_machine_get_hotplug_memory_region_size,NULL ,NULL ,NULL ,NULL ); + pcms->max_ram_below_4g =1UL <<32 ;/* 4G */
This is a bug: should be 1ULL. Fixed it up locally.
Quoted 136 lines
hw/i386/pc.c +4
-0+object_property_add (obj,PC_MACHINE_MAX_RAM_BELOW_4G ,"size" , + pc_machine_get_max_ram_below_4g, + pc_machine_set_max_ram_below_4g, +NULL ,NULL ,NULL ); }static void pc_machine_class_init (ObjectClass *oc,void *data)hw/i386/pc_piix.c +21
-1@@ -48,6 +48,7 @@#include "exec/address-spaces.h" #include "hw/acpi/acpi.h" #include "cpu.h" +#include "qemu/error-report.h" #ifdef CONFIG_XEN # include <xen/hvm/hvm_info_table.h> #endif @@ -98,6 +99,7 @@ static void pc_init1(MachineState *machine,DeviceState *icc_bridge;FWCfgState *fw_cfg =NULL ;PcGuestInfo *guest_info; +ram_addr_t lowmem;/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory). * If it doesn't, we need to split it in chunks below and above 4G. @@ -107,7 +109,25 @@ static void pc_init1(MachineState *machine,* breaking migration. */ if (machine->ram_size >=0xe0000000 ) { -ram_addr_t lowmem = gigabyte_align ?0xc0000000 :0xe0000000 ; + lowmem = gigabyte_align ?0xc0000000 :0xe0000000 ; + }else { + lowmem =0xe0000000 ; + } + +/* Handle the machine opt max-ram-below-4g. It is basicly doing +* min(qemu limit, user limit). +*/ +if (lowmem > pc_machine->max_ram_below_4g) { + lowmem = pc_machine->max_ram_below_4g; +if (machine->ram_size - lowmem > lowmem && + lowmem & ((1ULL <<30 ) -1 )) { +error_report ("Warning: Large machine and max_ram_below_4g(%" PRIu64 +") not a multiple of 1G; possible bad performance." , + pc_machine->max_ram_below_4g); + } + } + +if (machine->ram_size >= lowmem) { above_4g_mem_size = machine->ram_size - lowmem; below_4g_mem_size = lowmem; }else {hw/i386/pc_q35.c +21
-1@@ -44,6 +44,7 @@#include "hw/ide/ahci.h" #include "hw/usb.h" #include "hw/cpu/icc_bus.h" +#include "qemu/error-report.h" /* ICH9 AHCI has 6 ports */ #define MAX_SATA_PORTS 6@@ -85,6 +86,7 @@ static void pc_q35_init(MachineState *machine)PCIDevice *ahci;DeviceState *icc_bridge;PcGuestInfo *guest_info; +ram_addr_t lowmem;/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping @@ -96,7 +98,25 @@ static void pc_q35_init(MachineState *machine)* breaking migration. */ if (machine->ram_size >=0xb0000000 ) { -ram_addr_t lowmem = gigabyte_align ?0x80000000 :0xb0000000 ; + lowmem = gigabyte_align ?0x80000000 :0xb0000000 ; + }else { + lowmem =0xb0000000 ; + } + +/* Handle the machine opt max-ram-below-4g. It is basicly doing +* min(qemu limit, user limit). +*/ +if (lowmem > pc_machine->max_ram_below_4g) { + lowmem = pc_machine->max_ram_below_4g; +if (machine->ram_size - lowmem > lowmem && + lowmem & ((1ULL <<30 ) -1 )) { +error_report ("Warning: Large machine and max_ram_below_4g(%" PRIu64 +") not a multiple of 1G; possible bad performance." , + pc_machine->max_ram_below_4g); + } + } + +if (machine->ram_size >= lowmem) { above_4g_mem_size = machine->ram_size - lowmem; below_4g_mem_size = lowmem; }else {include/hw/i386/pc.h +3
-0@@ -33,10 +33,13 @@ struct PCMachineState {MemoryRegion hotplug_memory;HotplugHandler *acpi_dev; + +uint64_t max_ram_below_4g; };#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"#define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size" +#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"/** * PCMachineClass: vl.c +4
-0@@ -381,6 +381,10 @@ static QemuOptsList qemu_machine_opts = { .name = "kvm-type", .type = QEMU_OPT_STRING, .help = "Specifies the KVM virtualization mode (HV, PR)", + },{ + .name = PC_MACHINE_MAX_RAM_BELOW_4G, + .type = QEMU_OPT_SIZE, + .help = "maximum ram below the 4G boundary (32bit boundary)", }, {/* End of list */ } },Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH 2.1 v7 2/3] pc & q35: Add new machine opt max-ram-below-4g
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Don Slutz
This is a pc & q35 only machine opt.
...
Quoted 10 lines
hw/i386/pc.c pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, void *opaque, · line 1697
Quoted 9 lines
static void pc_machine_initfn(Object *obj) {hw/i386/pc.c +3
-0+PCMachineState *pcms =PC_MACHINE (obj); +object_property_add (obj,PC_MACHINE_MEMHP_REGION_SIZE ,"int" , pc_machine_get_hotplug_memory_region_size,NULL ,NULL ,NULL ,NULL ); + pcms->max_ram_below_4g =1UL <<32 ;/* 4G */ This is a bug: should be 1ULL. Fixed it up locally.
Yes. Thanks for fixing it. My 64bit system's gcc:
dcs-xen-54:~/qemu>gcc --version
gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
Copyright (C) 2012 Free Software Foundation, Inc.
Gets this wrong generating 32bit code :(
-Don Slutz
Quoted 5 lines
Quoted 5 lines
hw/i386/pc.c +4
-0+object_property_add (obj,PC_MACHINE_MAX_RAM_BELOW_4G ,"size" , + pc_machine_get_max_ram_below_4g, + pc_machine_set_max_ram_below_4g, +NULL ,NULL ,NULL ); }
PATCH v7 3/3 xen-hvm: Handle machine opt max-ram-below-4g
In reply to Don SlutzThis is the xen part of "pc & q35: Add new machine opt max-ram-below-4g"
Note: this machine option cannot be used to increase the amount of ram below 4G.
---
v7:
Rename from "xen-hvm: Pass is_default to xen_hvm_init"
Drop is_default.
Use object_property_get_int() to get max-ram-below-4g.
Do min(xen limit, user limit).
v6:
Changed to work with the changes in #2:
Added max_ram_below_4g_changed in order to know if it is a default value or a user specified one.
Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
"make check" will abort on default not set for any of the pc or q35 machine types.
Dropped "Acked-by: Stefano Stabellin" do to bigger change.
xen-hvm.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
xen-hvm.c +23 -12
@@ -161,25 +161,36 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size, {MemoryRegion *sysmem =get_system_memory ();ram_addr_t block_len; +uint64_t user_lowmem =object_property_get_int (qdev_get_machine (), +PC_MACHINE_MAX_RAM_BELOW_4G , + &error_abort); - block_len = ram_size; -if (ram_size >=HVM_BELOW_4G_RAM_END ) { -/* Xen does not allocate the memory continuously, and keep a hole at -* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +/* Handle the machine opt max-ram-below-4g. It is basicly doing +* min(xen limit, user limit). +*/ +if (HVM_BELOW_4G_RAM_END <= user_lowmem) { + user_lowmem =HVM_BELOW_4G_RAM_END ; } -memory_region_init_ram (&ram_memory,NULL ,"xen.ram" , block_len); - *ram_memory_p = &ram_memory; -vmstate_register_ram_global (&ram_memory); -if (ram_size >=HVM_BELOW_4G_RAM_END ) { - *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ; - *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; +if (ram_size >= user_lowmem) { + *above_4g_mem_size = ram_size - user_lowmem; + *below_4g_mem_size = user_lowmem; }else { *above_4g_mem_size =0 ; *below_4g_mem_size = ram_size; } +if (!*above_4g_mem_size) { + block_len = ram_size; + }else { +/* +* Xen does not allocate the memory continuously, it keeps a +* hole of the size computed above or passed in. +*/ + block_len = (1ULL <<32 ) + *above_4g_mem_size; + } +memory_region_init_ram (&ram_memory,NULL ,"xen.ram" , block_len); + *ram_memory_p = &ram_memory; +vmstate_register_ram_global (&ram_memory);memory_region_init_alias (&ram_640k,NULL ,"xen.ram.640k" , &ram_memory,0 ,0xa0000 );
Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH 2.1 v7 3/3] xen-hvm: Handle machine opt max-ram-below-4g
Quoted 6 lines · Don Slutz
This is the xen part of "pc & q35: Add new machine opt max-ram-below-4g"
Note: this machine option cannot be used to increase the amount of ram below 4G.
Signed-off-by Don Slutz <[email protected]>
It is still good for me.
Quoted 73 lines
v7:
Rename from "xen-hvm: Passis_defaulttoxen_hvm_init"
Dropis_default.
Useobject_property_get_int()to get max-ram-below-4g.
Domin(xen limit, user limit).
v6:
Changed to work with the changes in #2:
Addedmax_ram_below_4g_changedin order to know if it is a default value or a user specified one.
Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
"make check" will abort on default not set for any of the pc or q35 machine types.
Dropped "Acked-by: Stefano Stabellin" do to bigger change.xen-hvm.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)xen-hvm.c +23
-12@@ -161,25 +161,36 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size, {MemoryRegion *sysmem =get_system_memory ();ram_addr_t block_len; +uint64_t user_lowmem =object_property_get_int (qdev_get_machine (), +PC_MACHINE_MAX_RAM_BELOW_4G , + &error_abort); - block_len = ram_size; -if (ram_size >=HVM_BELOW_4G_RAM_END ) { -/* Xen does not allocate the memory continuously, and keep a hole at -* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +/* Handle the machine opt max-ram-below-4g. It is basicly doing +* min(xen limit, user limit). +*/ +if (HVM_BELOW_4G_RAM_END <= user_lowmem) { + user_lowmem =HVM_BELOW_4G_RAM_END ; } -memory_region_init_ram (&ram_memory,NULL ,"xen.ram" , block_len); - *ram_memory_p = &ram_memory; -vmstate_register_ram_global (&ram_memory); -if (ram_size >=HVM_BELOW_4G_RAM_END ) { - *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ; - *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; +if (ram_size >= user_lowmem) { + *above_4g_mem_size = ram_size - user_lowmem; + *below_4g_mem_size = user_lowmem; }else { *above_4g_mem_size =0 ; *below_4g_mem_size = ram_size; } +if (!*above_4g_mem_size) { + block_len = ram_size; + }else { +/* +* Xen does not allocate the memory continuously, it keeps a +* hole of the size computed above or passed in. +*/ + block_len = (1ULL <<32 ) + *above_4g_mem_size; + } +memory_region_init_ram (&ram_memory,NULL ,"xen.ram" , block_len); + *ram_memory_p = &ram_memory; +vmstate_register_ram_global (&ram_memory);memory_region_init_alias (&ram_640k,NULL ,"xen.ram.640k" , &ram_memory,0 ,0xa0000 );Signature · 1 line
1.8.4
Michael S. Tsirkin
AppliedQuoted 11 lines · Don Slutz
Changes v6 to v7:
Drop most of v5 to v6 changes.Michael S. Tsirkin:
#2 "pc & q35: Add new machine opt max-ram-below-4g":
default: max-ram-below-4g=4g
pc & q35:
calculate lowmem
lowmem =MIN(lowmem, max-ram-below-4g)calculateabove_4g_mem_sizeandbelow_4g_mem_size
Quoted 6 lines
#3 "xen-hvm: Handle machine opt max-ram-below-4g":
Rename from "xen-hvm: Passis_defaulttoxen_hvm_init" Dropis_default.
Useobject_property_get_int()to get max-ram-below-4g. Domin(xen limit, user limit).
Applied, thanks!
Quoted 126 lines
Changes v5 to v6:
rebased ongit://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gitpciChanged default handling. Most pc machines are now set to 3.5G (
0xe0000000) and q35 are set to 2.75G (0xb0000000). The special value of 0 is used to flag the complexgigabyte_alignmemory layout selection.I did change the default for pc-i440fx-2.1 to 3G and pc-q35-2.1 to 2G instead of the complex
gigabyte_align. This looks ok to me because the statement by Gerd Hoffmann is about more ram for 32 bit (+non-PAE) guests can now have more then the defualt by specifing the new option like "max-ram-below-4g=3.75G" or "max-ram-below-4g=3.9375G". Or if that is too complex to understand just select pc-i440fx-2.0 or pc-q35-2.0 to get what they use to get.Michael S. Tsirkin, Igor Mammedov, Marcel Apfelbaum:
#2 "pc & q35: Add new machine opt max-ram-below-4g":
Added setting of .default_machine_opts to include max-ram-below-4g
for all pc types.
Removedgigabyte_align.
Added warning on small value.
"less then" to "less than"#3 "xen-hvm: Pass
is_defaulttoxen_hvm_init":
Changed to work with the changes in #2:
Addedmax_ram_below_4g_changedin order to know if it is a default value or a user specified one.
Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
"make check" will abort on default not set for any of the pc or q35 machine types.
Dropped "Acked-by: Stefano Stabellin" do to bigger change.Changes v4 to v5:
Re-work based on:https://github.com/imammedo/qemu/commits/memory-hotplug-v11
And so it now depends on this patch set.
Stefano Stabellini:
#3 "xen-hvm: Passis_defaulttoxen_hvm_init"
Acked-by
Minor change of pmc to pcms.Changes v3 to v4:
Split out #2 "GlobalProperty: Display warning about unused -global" rebase on e00fcfe (origin/master)
rename xen-all to xen-hvmAdjust #1 "xen-hvm: Fix
xen_hvm_init()to adjust pc memory layout"
Switch Acked-by & Signed-off-by
rebase on masterRework #3 "xen-hvm: Pass
is_defaulttoxen_hvm_init":
To passis_defaultinstead ofmax_ram_below_4g.
Also did not add "Acked-by: Stefano Stabellini" since code changed a lot.Andreas Färber:
all: Remove dot at end of subject
#3 "xen-hvm: Passis_defaulttoxen_hvm_init"
Adjust comment formatting.Andreas Färber, Paolo Bonzini, Marcel Apfelbaum:
rework to use "opts per machine"
Drop old #3, new #2.Changes v2 to v3:
Stefano Stabellini:
Acked-by #1 "xen-all: Fixxen_hvm_init()to adjust pc memory" Adjust for code readability #4 "xen-all: Passmax_ram_below_4gtoxen_hvm_init."
Setmax_ram_below_4galways and use it to calculateabove_4g_mem_size,below_4g_mem_size.Changes v1 to v2:
Michael S. Tsirkin:
Rename option.
Only add it to machine types that support it.
Split into 4 parts.1/4 -- xen-all: Fix
xen_hvm_init()to adjust pc memory layoutThis looks to be a possible bug that has yet to be found.
below_4g_mem_sizeandabove_4g_mem_sizeare stored in PcGuestInfo (pc_guest_info_init) which are currently not "correct". This and 4/4 change the same lines.2/4 -- GlobalProperty: Display warning about unused -global
My testing showed that setting a global property on an object that is not used is not reported at all. This is added to help when the new global is set but not used. The negative
not_usedwas picked so that all static objects are assumed to be used even when they are not.3/4 -- pc & q35: Add new object pc-memory-layout
The objects that it might make sense to add this property to all get created too late. So add a new object just to hold this property. Name it so that it is expected that only pc (and q35) machine types support it.
4/4 -- xen-all: Pass
max_ram_below_4gtoxen_hvm_initSeprate the xen only part of the change. Currectly based on patch 1/4
Don Slutz (3):
xen-hvm: Fixxen_hvm_init()to adjust pc memory layout pc & q35: Add new machine opt max-ram-below-4g
xen-hvm: Handle machine opt max-ram-below-4ghw/i386/pc.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 53 ++++++++++++++++++++++++++++++++++++---------------- hw/i386/pc_q35.c | 51 +++++++++++++++++++++++++++++++++++--------------- include/hw/i386/pc.h | 3 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 ++++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 53 +++++++++++++++++++++++++++++++++------------------- 8 files changed, 165 insertions(+), 52 deletions(-)Signature · 1 line
1.8.4
Quoted 20 lines · Michael S. Tsirkin
Quoted 11 lines · Don Slutz
Changes v6 to v7:
Drop most of v5 to v6 changes.Michael S. Tsirkin:
#2 "pc & q35: Add new machine opt max-ram-below-4g":
default: max-ram-below-4g=4g
pc & q35:
calculate lowmem
lowmem =MIN(lowmem, max-ram-below-4g)calculateabove_4g_mem_sizeandbelow_4g_mem_sizeQuoted 6 lines
#3 "xen-hvm: Handle machine opt max-ram-below-4g":
Rename from "xen-hvm: Passis_defaulttoxen_hvm_init" Dropis_default.
Useobject_property_get_int()to get max-ram-below-4g. Domin(xen limit, user limit).
Quoted 1 line
Applied, thanks!
Thanks, Michael.
Quoted 127 lines
Quoted 126 lines
Changes v5 to v6:
rebased ongit://git.kernel.org/pub/scm/virt/kvm/mst/qemu.gitpciChanged default handling. Most pc machines are now set to 3.5G (
0xe0000000) and q35 are set to 2.75G (0xb0000000). The special value of 0 is used to flag the complexgigabyte_alignmemory layout selection.I did change the default for pc-i440fx-2.1 to 3G and pc-q35-2.1 to 2G instead of the complex
gigabyte_align. This looks ok to me because the statement by Gerd Hoffmann is about more ram for 32 bit (+non-PAE) guests can now have more then the defualt by specifing the new option like "max-ram-below-4g=3.75G" or "max-ram-below-4g=3.9375G". Or if that is too complex to understand just select pc-i440fx-2.0 or pc-q35-2.0 to get what they use to get.Michael S. Tsirkin, Igor Mammedov, Marcel Apfelbaum:
#2 "pc & q35: Add new machine opt max-ram-below-4g":
Added setting of .default_machine_opts to include max-ram-below-4g
for all pc types.
Removedgigabyte_align.
Added warning on small value.
"less then" to "less than"#3 "xen-hvm: Pass
is_defaulttoxen_hvm_init":
Changed to work with the changes in #2:
Addedmax_ram_below_4g_changedin order to know if it is a default value or a user specified one.
Added "assert(pc_machine->max_ram_below_4g_changed > 0)" so that
"make check" will abort on default not set for any of the pc or q35 machine types.
Dropped "Acked-by: Stefano Stabellin" do to bigger change.Changes v4 to v5:
Re-work based on:https://github.com/imammedo/qemu/commits/memory-hotplug-v11
And so it now depends on this patch set.
Stefano Stabellini:
#3 "xen-hvm: Passis_defaulttoxen_hvm_init"
Acked-by
Minor change of pmc to pcms.Changes v3 to v4:
Split out #2 "GlobalProperty: Display warning about unused -global" rebase on e00fcfe (origin/master)
rename xen-all to xen-hvmAdjust #1 "xen-hvm: Fix
xen_hvm_init()to adjust pc memory layout"
Switch Acked-by & Signed-off-by
rebase on masterRework #3 "xen-hvm: Pass
is_defaulttoxen_hvm_init":
To passis_defaultinstead ofmax_ram_below_4g.
Also did not add "Acked-by: Stefano Stabellini" since code changed a lot.Andreas Färber:
all: Remove dot at end of subject
#3 "xen-hvm: Passis_defaulttoxen_hvm_init"
Adjust comment formatting.Andreas Färber, Paolo Bonzini, Marcel Apfelbaum:
rework to use "opts per machine"
Drop old #3, new #2.Changes v2 to v3:
Stefano Stabellini:
Acked-by #1 "xen-all: Fixxen_hvm_init()to adjust pc memory" Adjust for code readability #4 "xen-all: Passmax_ram_below_4gtoxen_hvm_init."
Setmax_ram_below_4galways and use it to calculateabove_4g_mem_size,below_4g_mem_size.Changes v1 to v2:
Michael S. Tsirkin:
Rename option.
Only add it to machine types that support it.
Split into 4 parts.1/4 -- xen-all: Fix
xen_hvm_init()to adjust pc memory layoutThis looks to be a possible bug that has yet to be found.
below_4g_mem_sizeandabove_4g_mem_sizeare stored in PcGuestInfo (pc_guest_info_init) which are currently not "correct". This and 4/4 change the same lines.2/4 -- GlobalProperty: Display warning about unused -global
My testing showed that setting a global property on an object that is not used is not reported at all. This is added to help when the new global is set but not used. The negative
not_usedwas picked so that all static objects are assumed to be used even when they are not.3/4 -- pc & q35: Add new object pc-memory-layout
The objects that it might make sense to add this property to all get created too late. So add a new object just to hold this property. Name it so that it is expected that only pc (and q35) machine types support it.
4/4 -- xen-all: Pass
max_ram_below_4gtoxen_hvm_initSeprate the xen only part of the change. Currectly based on patch 1/4
Don Slutz (3):
xen-hvm: Fixxen_hvm_init()to adjust pc memory layout pc & q35: Add new machine opt max-ram-below-4g
xen-hvm: Handle machine opt max-ram-below-4ghw/i386/pc.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 53 ++++++++++++++++++++++++++++++++++++---------------- hw/i386/pc_q35.c | 51 +++++++++++++++++++++++++++++++++++--------------- include/hw/i386/pc.h | 3 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 ++++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 53 +++++++++++++++++++++++++++++++++------------------- 8 files changed, 165 insertions(+), 52 deletions(-)Signature · 1 line
1.8.4