Add max-ram-below-4g (was Add pci_hole_min_size machine option)
v6 cover Add max-ram-below-4g (was Add pci_hole_min_size machine option)
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: Pass is_default to xen_hvm_init
hw/i386/pc.c | 45 ++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 73 +++++++++++++++++++++++++++++++++------------------- hw/i386/pc_q35.c | 72 ++++++++++++++++++++++++++++++++------------------- include/hw/i386/pc.h | 4 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 +++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 46 +++++++++++++++++++-------------- 8 files changed, 177 insertions(+), 73 deletions(-)
Signature · 1 line
1.8.4
PATCH v6 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.
---
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 v6 2/3 pc & q35: Add new machine opt max-ram-below-4g
In reply to Don SlutzThis is a pc & q35 only machine opt.
Remove gigabyte_align (now handled by .default_machine_opts). Add warning about BIOS.
One use is to allow for more ram in a 32bit guest for example:
-machine pc,max-ram-below-4g=3.75G
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.
---
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 | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 46 ++++++++++++++++++++++++++++++++-------------- hw/i386/pc_q35.c | 45 +++++++++++++++++++++++++++++++-------------- include/hw/i386/pc.h | 3 +++ vl.c | 4 ++++ 5 files changed, 114 insertions(+), 28 deletions(-)
hw/i386/pc.c +44 -0
@@ -1647,11 +1647,55 @@ 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 >0 && 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) {object_property_add (obj,PC_MACHINE_MEMHP_REGION_SIZE ,"int" , pc_machine_get_hotplug_memory_region_size,NULL ,NULL ,NULL ,NULL ); +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 +32 -14
106 lines not on this page · raw message
hw/i386/pc_q35.c +31 -14
99 lines not on this page · raw message
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
PATCH v6 3/3 xen-hvm: Pass is_default to xen_hvm_init
In reply to Don SlutzThis is the xen part of "pc & q35: Add new machine opt max-ram-below-4g"
This is done by adding a counter to know how many times pc_machine_set_max_ram_below_4g() is called. Therefore xen can know if a non-default setting is requested.
---
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.
hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 2 ++ hw/i386/pc_q35.c | 2 ++ include/hw/i386/pc.h | 1 + include/hw/xen/xen.h | 2 +- xen-hvm-stub.c | 2 +- xen-hvm.c | 36 ++++++++++++++++++++---------------- 7 files changed, 28 insertions(+), 18 deletions(-)
hw/i386/pc.c +1 -0
@@ -1685,6 +1685,7 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v, } pcms->max_ram_below_4g = value; + pcms->max_ram_below_4g_changed++; }static void pc_machine_initfn (Object *obj)
hw/i386/pc_piix.c +2 -0
@@ -129,7 +129,9 @@ static void pc_init1(MachineState *machine, below_4g_mem_size = machine->ram_size; } +assert (pc_machine->max_ram_below_4g_changed >0 );if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, + pc_machine->max_ram_below_4g_changed ==1 , &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 );
hw/i386/pc_q35.c +2 -0
@@ -118,7 +118,9 @@ static void pc_q35_init(MachineState *machine) below_4g_mem_size = machine->ram_size; } +assert (pc_machine->max_ram_below_4g_changed >0 );if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, + pc_machine->max_ram_below_4g_changed ==1 , &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 );
include/hw/i386/pc.h +1 -0
@@ -35,6 +35,7 @@ struct PCMachineState {HotplugHandler *acpi_dev;uint64_t max_ram_below_4g; +uint32_t max_ram_below_4g_changed; };#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
include/hw/xen/xen.h +1 -1
@@ -41,7 +41,7 @@ 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); +bool is_default,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 +1 -1
@@ -52,7 +52,7 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) }int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -MemoryRegion **ram_memory) +bool is_default,MemoryRegion **ram_memory) {return 0 ; }
xen-hvm.c +20 -16
@@ -156,31 +156,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ static void xen_ram_init (ram_addr_t *below_4g_mem_size, -ram_addr_t *above_4g_mem_size, +ram_addr_t *above_4g_mem_size,bool is_default,ram_addr_t ram_size,MemoryRegion **ram_memory_p) {MemoryRegion *sysmem =get_system_memory ();ram_addr_t block_len; - 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 +if (is_default) { +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 ; + }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 +=HVM_BELOW_4G_MMIO_LENGTH ; + 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); -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 ; - }else { - *above_4g_mem_size =0 ; - *below_4g_mem_size = ram_size; - } -memory_region_init_alias (&ram_640k,NULL ,"xen.ram.640k" , &ram_memory,0 ,0xa0000 );memory_region_add_subregion (sysmem,0 , &ram_640k);
@@ -962,7 +965,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data) }int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -MemoryRegion **ram_memory) +bool is_default,MemoryRegion **ram_memory) {int i, rc;unsigned long ioreq_pfn;
@@ -1040,7 +1043,8 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,/* Init RAM management */ xen_map_cache_init (xen_phys_offset_to_gaddr, state); -xen_ram_init (below_4g_mem_size, above_4g_mem_size, ram_size, ram_memory); +xen_ram_init (below_4g_mem_size, above_4g_mem_size, is_default, ram_size, + ram_memory);qemu_add_vm_change_state_handler (xen_hvm_change_state_handler, state);
Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH v6 3/3] xen-hvm: Pass is_default to xen_hvm_init
Quoted 6 lines · Don Slutz
This is the xen part of "pc & q35: Add new machine opt max-ram-below-4g"
This is done by adding a counter to know how many times
pc_machine_set_max_ram_below_4g()is called. Therefore xen can know if a non-default setting is requested.
Quoted 6 lines
Signed-off-by Don Slutz <[email protected]>---
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.
If you are special casing the default you might set it to 0 just as well.
Sorry about not being clear, but what me and others were saying is that we prefer an API should that there's no need for special-casing user-specified values.
This approach isn't any better, it's just moving hacks around.
Of the two use-cases that you supplied, increasing RAM below 4g and decreasing RAM below 4g, which do you really care about?
If you really want a way to limit low RAM to 2g, then how about this: set max_ram_below_4g_changed to 4g, and apply the current limits *on top*.
So if user sets limit to 3.99 one still gets 3.5 or whatever. But if you set it to 2G then you get 2G.
Quoted 166 lines
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.hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 2 ++ hw/i386/pc_q35.c | 2 ++ include/hw/i386/pc.h | 1 + include/hw/xen/xen.h | 2 +- xen-hvm-stub.c | 2 +- xen-hvm.c | 36 ++++++++++++++++++++---------------- 7 files changed, 28 insertions(+), 18 deletions(-)hw/i386/pc.c +1
-0@@ -1685,6 +1685,7 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, Visitor *v, } pcms->max_ram_below_4g = value; + pcms->max_ram_below_4g_changed++; }static void pc_machine_initfn (Object *obj)hw/i386/pc_piix.c +2
-0@@ -129,7 +129,9 @@ static void pc_init1(MachineState *machine, below_4g_mem_size = machine->ram_size; } +assert (pc_machine->max_ram_below_4g_changed >0 );if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, + pc_machine->max_ram_below_4g_changed ==1 , &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 );hw/i386/pc_q35.c +2
-0@@ -118,7 +118,9 @@ static void pc_q35_init(MachineState *machine) below_4g_mem_size = machine->ram_size; } +assert (pc_machine->max_ram_below_4g_changed >0 );if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, + pc_machine->max_ram_below_4g_changed ==1 , &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 );include/hw/i386/pc.h +1
-0@@ -35,6 +35,7 @@ struct PCMachineState {HotplugHandler *acpi_dev;uint64_t max_ram_below_4g; +uint32_t max_ram_below_4g_changed; };#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"include/hw/xen/xen.h +1
-1@@ -41,7 +41,7 @@ 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); +bool is_default,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 +1
-1@@ -52,7 +52,7 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length) }int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -MemoryRegion **ram_memory) +bool is_default,MemoryRegion **ram_memory) {return 0 ; }xen-hvm.c +20
-16@@ -156,31 +156,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ static void xen_ram_init (ram_addr_t *below_4g_mem_size, -ram_addr_t *above_4g_mem_size, +ram_addr_t *above_4g_mem_size,bool is_default,ram_addr_t ram_size,MemoryRegion **ram_memory_p) {MemoryRegion *sysmem =get_system_memory ();ram_addr_t block_len; - 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 +if (is_default) { +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 ; + }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 +=HVM_BELOW_4G_MMIO_LENGTH ; + 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); -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 ; - }else { - *above_4g_mem_size =0 ; - *below_4g_mem_size = ram_size; - } -memory_region_init_alias (&ram_640k,NULL ,"xen.ram.640k" , &ram_memory,0 ,0xa0000 );memory_region_add_subregion (sysmem,0 , &ram_640k);@@ -962,7 +965,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data) }int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -MemoryRegion **ram_memory) +bool is_default,MemoryRegion **ram_memory) {int i, rc;unsigned long ioreq_pfn;@@ -1040,7 +1043,8 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,/* Init RAM management */ xen_map_cache_init (xen_phys_offset_to_gaddr, state); -xen_ram_init (below_4g_mem_size, above_4g_mem_size, ram_size, ram_memory); +xen_ram_init (below_4g_mem_size, above_4g_mem_size, is_default, ram_size, + ram_memory);qemu_add_vm_change_state_handler (xen_hvm_change_state_handler, state);Signature · 1 line
1.8.4
Quoted 8 lines · Don Slutz
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.
Quoted 8 lines
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.
I don't think it's OK.
The beauty of Gerd's hack is that it does the right thing for 32 bit guests without any need for tweaks. I.e. most users get good performance.
By comparison this setting seems easier to get wrong than right.
And we definitely don't want to push people to use 2.0 compat setting unless they need bug for bug compatible hardware.
Generally, I'm still confused about this feature.
It seems to be about helping 32 bit non PAE guests, is that right? But if that's the case why use >4G memory?
Quoted 109 lines
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: Passis_defaulttoxen_hvm_inithw/i386/pc.c | 45 ++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 73 +++++++++++++++++++++++++++++++++------------------- hw/i386/pc_q35.c | 72 ++++++++++++++++++++++++++++++++------------------- include/hw/i386/pc.h | 4 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 +++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 46 +++++++++++++++++++-------------- 8 files changed, 177 insertions(+), 73 deletions(-)Signature · 1 line
1.8.4
Quoted 19 lines · Michael S. Tsirkin
Quoted 8 lines · Don Slutz
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.Quoted 8 lines
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.I don't think it's OK.
Quoted 8 lines
The beauty of Gerd's hack is that it does the right thing for 32 bit guests without any need for tweaks. I.e. most users get good performance.
By comparison this setting seems easier to get wrong than right.
And we definitely don't want to push people to use 2.0 compat setting unless they need bug for bug compatible hardware.
Ok. Will switch back on a v7.
Quoted 2 lines
Generally, I'm still confused about this feature.
It seems to be about helping 32 bit non PAE guests, is that right?
No. That is just part of it.
Quoted 2 lines
But if that's the case why use >4G memory?
I know of a use case where the guest code (custom OS) wants 1G below 4G and 3G above 4G. And 1G below and 7G above. They want a big MMIO space for many PCI cards but also still gigabyte aligned.
It seems to me to be better to add the machine option (that is more flexible) then 4 new pc machine types that have this memory layout.
-Don Slutz
Quoted 109 lines
Quoted 109 lines
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: Passis_defaulttoxen_hvm_inithw/i386/pc.c | 45 ++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 73 +++++++++++++++++++++++++++++++++------------------- hw/i386/pc_q35.c | 72 ++++++++++++++++++++++++++++++++------------------- include/hw/i386/pc.h | 4 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 +++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 46 +++++++++++++++++++-------------- 8 files changed, 177 insertions(+), 73 deletions(-)Signature · 1 line
1.8.4
Quoted 34 lines · Don Slutz
Quoted 19 lines · Michael S. Tsirkin
Quoted 8 lines · Don Slutz
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.Quoted 8 lines
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.I don't think it's OK.
Quoted 8 lines
The beauty of Gerd's hack is that it does the right thing for 32 bit guests without any need for tweaks. I.e. most users get good performance.
By comparison this setting seems easier to get wrong than right.
And we definitely don't want to push people to use 2.0 compat setting unless they need bug for bug compatible hardware.
Ok. Will switch back on a v7.
Quoted 2 lines
Generally, I'm still confused about this feature.
It seems to be about helping 32 bit non PAE guests, is that right?
Quoted 8 lines
No. That is just part of it.
Quoted 2 lines
But if that's the case why use >4G memory?
I know of a use case where the guest code (custom OS) wants 1G below 4G and 3G above 4G. And 1G below and 7G above. They want a big MMIO space for many PCI cards but also still gigabyte aligned.
Why not use 64 bit BARs on cards?
Many cards we emulate don't support them but
that's historical: before 57271d63c4d93352406704d540453c43a4a241a7 we didn't emulate 64 bit addresses correctly (and that was because before b35ba30f8fa235c779d876ee299b80a2d501d204 it was too expensive).
Quoted 5 lines
It seems to me to be better to add the machine option (that is more flexible) then 4 new pc machine types that have this memory layout.
-Don Slutz
Assuming we want this (motivation for which I didn't yet get completely), I think the right thing to do would not be to let user specify the layout exactly, instead
let user specify a limit on low memory.
Use that together with other limits we calculate. Default would be 4g -> no limit.
Quoted 108 lines
Quoted 108 lines
Quoted 108 lines
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: Passis_defaulttoxen_hvm_inithw/i386/pc.c | 45 ++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 73 +++++++++++++++++++++++++++++++++------------------- hw/i386/pc_q35.c | 72 ++++++++++++++++++++++++++++++++------------------- include/hw/i386/pc.h | 4 +++ include/hw/xen/xen.h | 3 ++- vl.c | 4 +++ xen-hvm-stub.c | 3 ++- xen-hvm.c | 46 +++++++++++++++++++-------------- 8 files changed, 177 insertions(+), 73 deletions(-)Signature · 1 line
1.8.4