Add max-ram-below-4g (was Add pci_hole_min_size machine option)
v2 cover Add max-ram-below-4g (was Add pci_hole_min_size machine option)
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 (4):
xen-all: Fix xen_hvm_init() to adjust pc memory layout.
GlobalProperty: Display warning about unused -global pc & q35: Add new object pc-memory-layout.
xen-all: Pass max_ram_below_4g to xen_hvm_init.
hw/core/qdev-properties-system.c | 1 + hw/core/qdev-properties.c | 15 ++++++++++++ hw/i386/pc.c | 42 ++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 52 +++++++++++++++++++++++++++------------- hw/i386/pc_q35.c | 50 ++++++++++++++++++++++++++------------ include/hw/i386/pc.h | 2 ++ include/hw/qdev-core.h | 1 + include/hw/qdev-properties.h | 1 + include/hw/xen/xen.h | 3 ++- vl.c | 2 ++ xen-all.c | 47 ++++++++++++++++++++---------------- xen-stub.c | 3 ++- 12 files changed, 166 insertions(+), 53 deletions(-)
Signature · 1 line
1.8.4
PATCH v2 1/4 xen-all: 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.
--- hw/i386/pc_piix.c | 31 ++++++++++++++++--------------- hw/i386/pc_q35.c | 29 +++++++++++++++-------------- include/hw/xen/xen.h | 3 ++- xen-all.c | 24 ++++++++++++++---------- xen-stub.c | 3 ++- 5 files changed, 49 insertions(+), 41 deletions(-)
hw/i386/pc_piix.c +16 -15
@@ -96,21 +96,6 @@ static void pc_init1(QEMUMachineInitArgs *args,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 (args->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
@@ -127,6 +112,22 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->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 (args->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
@@ -83,20 +83,6 @@ static void pc_q35_init(QEMUMachineInitArgs *args)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 (args->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).
@@ -115,6 +101,21 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->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 (args->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
@@ -38,10 +38,11 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);qemu_irq *xen_interrupt_controller_init (void );int xen_init (QEMUMachine *machine); -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-all.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); } }
@@ -1066,7 +1069,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;
@@ -1144,7 +1148,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);
xen-stub.c +2 -1
@@ -64,7 +64,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 ; }
Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH v2 1/4] xen-all: Fix xen_hvm_init() to adjust pc memory layout.
Quoted 3 lines · Don Slutz
This is just
below_4g_mem_sizeandabove_4g_mem_sizewhich is used later in QEMU.Signed-off-by Don Slutz <[email protected]>
Quoted 206 lines
hw/i386/pc_piix.c | 31 ++++++++++++++++--------------- hw/i386/pc_q35.c | 29 +++++++++++++++-------------- include/hw/xen/xen.h | 3 ++- xen-all.c | 24 ++++++++++++++---------- xen-stub.c | 3 ++- 5 files changed, 49 insertions(+), 41 deletions(-)hw/i386/pc_piix.c +16
-15@@ -96,21 +96,6 @@ static void pc_init1(QEMUMachineInitArgs *args,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 (args->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 @@ -127,6 +112,22 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->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 (args->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@@ -83,20 +83,6 @@ static void pc_q35_init(QEMUMachineInitArgs *args)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 (args->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). @@ -115,6 +101,21 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->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 (args->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@@ -38,10 +38,11 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);qemu_irq *xen_interrupt_controller_init (void );int xen_init (QEMUMachine *machine); -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-all.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); } }@@ -1066,7 +1069,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;@@ -1144,7 +1148,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);xen-stub.c +2
-1@@ -64,7 +64,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 ; }Signature · 1 line
1.8.4
PATCH v2 2/4 GlobalProperty: Display warning about unused -global
In reply to Don SlutzThis can help a user understand why -global was ignored.
For example: with "-vga cirrus"; "-global vga.vgamem_mb=16" is just ignored when "-global cirrus-vga.vgamem_mb=16" is not.
This is currently clear when the wrong property is provided:
out/x86_64-softmmu/qemu-system-x86_64 -global cirrus-vga.vram_size_mb=16 -monitor pty -vga cirrus char device redirected to /dev/pts/20 (label compat_monitor0)
qemu-system-x86_64: Property '.vram_size_mb' not found
Aborted (core dumped)
vs
out/x86_64-softmmu/qemu-system-x86_64 -global vga.vram_size_mb=16 -monitor pty -vga cirrus char device redirected to /dev/pts/20 (label compat_monitor0)
VNC server running on `::1:5900'
^Cqemu: terminating on signal 2
--- hw/core/qdev-properties-system.c | 1 + hw/core/qdev-properties.c | 15 +++++++++++++++ include/hw/qdev-core.h | 1 + include/hw/qdev-properties.h | 1 + vl.c | 2 ++ 5 files changed, 20 insertions(+)
hw/core/qdev-properties-system.c +1 -0
@@ -390,6 +390,7 @@ static int qdev_add_one_global(QemuOpts *opts, void *opaque) g->driver =qemu_opt_get (opts,"driver" ); g->property =qemu_opt_get (opts,"property" ); g->value =qemu_opt_get (opts,"value" ); + g->not_used = true;qdev_prop_register_global (g);return 0 ; }
hw/core/qdev-properties.c +15 -0
@@ -939,6 +939,20 @@ void qdev_prop_register_global_list(GlobalProperty *props) } } +void qdev_prop_check_global (void ) +{ +GlobalProperty *prop; + + QTAILQ_FOREACH(prop, &global_props, next) { +if (!prop->not_used) { +continue ; + } +fprintf (stderr,"Warning: \"-global %s.%s=%s\" not used\n" , + prop->driver, prop->property, prop->value); + + } +} +void qdev_prop_set_globals_for_type (DeviceState *dev,const char *typename,Error **errp) {
@@ -950,6 +964,7 @@ void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,if (strcmp (typename, prop->driver) !=0 ) {continue ; } + prop->not_used = false;object_property_parse (OBJECT (dev), prop->value, prop->property, &err);if (err !=NULL ) {error_propagate (errp, err);
include/hw/qdev-core.h +1 -0
@@ -229,6 +229,7 @@ typedef struct GlobalProperty {const char *driver;const char *property;const char *value; +bool not_used;QTAILQ_ENTRY (GlobalProperty) next; } GlobalProperty;
include/hw/qdev-properties.h +1 -0
@@ -177,6 +177,7 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);void qdev_prop_register_global (GlobalProperty *prop);void qdev_prop_register_global_list (GlobalProperty *props); +void qdev_prop_check_global (void );void qdev_prop_set_globals (DeviceState *dev,Error **errp);void qdev_prop_set_globals_for_type (DeviceState *dev,const char *typename,Error **errp);
vl.c +2 -0
@@ -4411,6 +4411,8 @@ int main(int argc, char **argv, char **envp) } } +qdev_prop_check_global (); +if (incoming) {Error *local_err =NULL ;qemu_start_incoming_migration (incoming, &local_err);
Signature · 1 line
1.8.4
PATCH v2 3/4 pc & q35: Add new object pc-memory-layout.
In reply to Don SlutzThis new object has the property max-ram-below-4g.
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 adding "-global pc-memory-layout.max-ram-below-4g=2G" to the command line will limit the amount of ram that is below 4G to 2G.
--- hw/i386/pc.c | 42 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 23 +++++++++++++++++++++-- hw/i386/pc_q35.c | 23 +++++++++++++++++++++-- include/hw/i386/pc.h | 2 ++ 4 files changed, 86 insertions(+), 4 deletions(-)
hw/i386/pc.c +42 -0
@@ -1413,3 +1413,45 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) gsi_state->ioapic_irq[i] =qdev_get_gpio_in (dev, i); } } + +/* pc-memory-layout stuff */ + +typedef struct PcMemoryLayoutState PcMemoryLayoutState ; + +/** +* @PcMemoryLayoutState: +*/ +struct PcMemoryLayoutState { +/*< private >*/ +Object parent_obj; +/*< public >*/ + +uint64_t max_ram_below_4g; +}; + +static Property pc_memory_layout_props[] = { +DEFINE_PROP_SIZE ("max-ram-below-4g" , PcMemoryLayoutState, + max_ram_below_4g,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pc_memory_layout_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->props = pc_memory_layout_props; +} + +static const TypeInfo pc_memory_layout_info = { + .name =TYPE_PC_MEMORY_LAYOUT , + .parent =TYPE_DEVICE , + .instance_size =sizeof (PcMemoryLayoutState), + .class_init = pc_memory_layout_class_init, +}; + +static void pc_memory_layout_register_types (void ) +{ +type_register_static (&pc_memory_layout_info); +} + +type_init (pc_memory_layout_register_types)
hw/i386/pc_piix.c +21 -2
@@ -95,6 +95,23 @@ static void pc_init1(QEMUMachineInitArgs *args,DeviceState *icc_bridge;FWCfgState *fw_cfg =NULL ;PcGuestInfo *guest_info; +Object *pc_memory_layout; +uint64_t max_ram_below_4g; +ram_addr_t lowmem =0xe0000000 ; + + pc_memory_layout =object_new (TYPE_PC_MEMORY_LAYOUT ); + max_ram_below_4g =object_property_get_int (pc_memory_layout, +"max-ram-below-4g" , +NULL ); +if (max_ram_below_4g) { +if (max_ram_below_4g > (1ULL <<32 )) { +fprintf (stderr, +"%s: max_ram_below_4g=%lld too big adjusted to %lld\n" , + __func__, (long long )max_ram_below_4g,1ULL <<32 ); + max_ram_below_4g =1ULL <<32 ; + } + lowmem = max_ram_below_4g; + }/* 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.
@@ -103,8 +120,10 @@ static void pc_init1(QEMUMachineInitArgs *args,* For old machine types, use whatever split we used historically to avoid * breaking migration. */ -if (args->ram_size >=0xe0000000 ) { -ram_addr_t lowmem = gigabyte_align ?0xc0000000 :0xe0000000 ; +if (args->ram_size >= lowmem) { +if (!max_ram_below_4g && gigabyte_align) { + lowmem =0xc0000000 ; + } above_4g_mem_size = args->ram_size - lowmem; below_4g_mem_size = lowmem; }else {
hw/i386/pc_q35.c +21 -2
@@ -82,6 +82,23 @@ static void pc_q35_init(QEMUMachineInitArgs *args)PCIDevice *ahci;DeviceState *icc_bridge;PcGuestInfo *guest_info; +Object *pc_memory_layout; +uint64_t max_ram_below_4g; +ram_addr_t lowmem =0xb0000000 ; + + pc_memory_layout =object_new (TYPE_PC_MEMORY_LAYOUT ); + max_ram_below_4g =object_property_get_int (pc_memory_layout, +"max-ram-below-4g" , +NULL ); +if (max_ram_below_4g) { +if (max_ram_below_4g > (1ULL <<32 )) { +fprintf (stderr, +"%s: max_ram_below_4g=%lld too big adjusted to %lld\n" , + __func__, (long long )max_ram_below_4g,1ULL <<32 ); + max_ram_below_4g =1ULL <<32 ; + } + lowmem = max_ram_below_4g; + }/* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory * and 256 Mbytes for PCI Express Enhanced Configuration Access Mapping
@@ -92,8 +109,10 @@ static void pc_q35_init(QEMUMachineInitArgs *args)* For old machine types, use whatever split we used historically to avoid * breaking migration. */ -if (args->ram_size >=0xb0000000 ) { -ram_addr_t lowmem = gigabyte_align ?0x80000000 :0xb0000000 ; +if (args->ram_size >= lowmem) { +if (!max_ram_below_4g && gigabyte_align) { + lowmem =0x80000000 ; + } above_4g_mem_size = args->ram_size - lowmem; below_4g_mem_size = lowmem; }else {
include/hw/i386/pc.h +2 -0
@@ -163,6 +163,8 @@ void cpu_smm_register(cpu_set_smm_t callback, void *arg);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name); +#define TYPE_PC_MEMORY_LAYOUT "pc-memory-layout" +/* acpi_piix.c */ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
Signature · 1 line
1.8.4
PATCH v2 4/4 xen-all: Pass max_ram_below_4g to xen_hvm_init.
In reply to Don SlutzThis is the xen part of "pc & q35: Add new object pc-memory-layout."
--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)
hw/i386/pc_piix.c +2 -2
@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } -if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) !=0 ) { +if (xen_enabled () &&xen_hvm_init (max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 ); }
hw/i386/pc_q35.c +2 -2
@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } -if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) !=0 ) { +if (xen_enabled () &&xen_hvm_init (max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 ); }
include/hw/xen/xen.h +2 -2
@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init (ram_addr_t max_ram_below_4g,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-all.c +22 -19
69 lines not on this page · raw message
xen-stub.c +2 -2
@@ -64,8 +64,8 @@ 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) +int xen_hvm_init (ram_addr_t max_ram_below_4g,ram_addr_t *below_4g_mem_size, +ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {return 0 ; }
Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH v2 4/4] xen-all: Pass max_ram_below_4g to xen_hvm_init.
Quoted 79 lines · Don Slutz
This is the xen part of "pc & q35: Add new object pc-memory-layout."
Signed-off-by Don Slutz <[email protected]>--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)hw/i386/pc_piix.c +2
-2@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } -if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) !=0 ) { +if (xen_enabled () &&xen_hvm_init (max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 ); }hw/i386/pc_q35.c +2
-2@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } -if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) !=0 ) { +if (xen_enabled () &&xen_hvm_init (max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 ); }include/hw/xen/xen.h +2
-2@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init (ram_addr_t max_ram_below_4g,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-all.c +3
-7@@ -155,32 +155,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init (ram_addr_t *below_4g_mem_size, +static void xen_ram_init (ram_addr_t ram_size,ram_addr_t max_ram_below_4g, +ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -ram_addr_t ram_size,MemoryRegion **ram_memory_p) +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 -*/
xen-all.c qemu_irq *xen_interrupt_controller_init(void) · line 174
Quoted 10 lines
xen-all.c +9
-1- block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +if (!max_ram_below_4g) { +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; + } + }
Instead of treating max_ram_below_4g as a special case, couldn't initialize it to HVM_BELOW_4G_RAM_END?
We could consider HVM_BELOW_4G_RAM_END as the upper bound of max_ram_below_4g.
I would just change the code to:
if (ram_size >= max_ram_below_4g) {
above_4g_mem_size = ram_size - max_ram_below_4g;
below_4g_mem_size = max_ram_below_4g;
} else {
below_4g_mem_size = ram_size;
}Quoted 61 lines
xen-all.c +10
-11+if (!*above_4g_mem_size) { + block_len = ram_size; + }else { +/* Xen does not allocate the memory continuously, and keep a hole of +* 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); -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);@@ -1069,8 +1071,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 (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -MemoryRegion **ram_memory) +int xen_hvm_init (ram_addr_t max_ram_below_4g,ram_addr_t *below_4g_mem_size, +ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {int i, rc;unsigned long ioreq_pfn;@@ -1148,7 +1150,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 (ram_size, max_ram_below_4g, below_4g_mem_size, + above_4g_mem_size, ram_memory);qemu_add_vm_change_state_handler (xen_hvm_change_state_handler, state);xen-stub.c +2
-2@@ -64,8 +64,8 @@ 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) +int xen_hvm_init (ram_addr_t max_ram_below_4g,ram_addr_t *below_4g_mem_size, +ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {return 0 ; }Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH v2 4/4] xen-all: Pass max_ram_below_4g to xen_hvm_init.
Quoted 84 lines · Stefano Stabellini
Quoted 83 lines · Don Slutz
This is the xen part of "pc & q35: Add new object pc-memory-layout."
Signed-off-by Don Slutz<[email protected]>--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)hw/i386/pc_piix.c +2
-2@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } -if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) !=0 ) { +if (xen_enabled () &&xen_hvm_init (max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 ); }hw/i386/pc_q35.c +2
-2@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } -if (xen_enabled () &&xen_hvm_init (&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) !=0 ) { +if (xen_enabled () &&xen_hvm_init (max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0 ) {fprintf (stderr,"xen hardware virtual machine initialisation failed\n" );exit (1 ); }include/hw/xen/xen.h +2
-2@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init (ram_addr_t max_ram_below_4g,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-all.c +6
-8@@ -155,32 +155,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init (ram_addr_t *below_4g_mem_size, +static void xen_ram_init (ram_addr_t ram_size,ram_addr_t max_ram_below_4g, +ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -ram_addr_t ram_size,MemoryRegion **ram_memory_p) +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 -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +if (!max_ram_below_4g) { +if (ram_size >=HVM_BELOW_4G_RAM_END ) { + *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ;
Quoted 8 lines
xen-all.c qemu_irq *xen_interrupt_controller_init(void) · line 174
Quoted 6 lines
xen-all.c +6
-0+ *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; + }else { + *above_4g_mem_size =0 ; + *below_4g_mem_size = ram_size; + } + }Instead of treating
max_ram_below_4gas a special case, couldn't initialize it toHVM_BELOW_4G_RAM_END?
Since max_ram_below_4g is used and initialize in normal QEMU code where HVM_BELOW_4G_RAM_END is not defined, I do not see how to do this outside of this routine without adding a new routine for this.
Quoted 2 lines
We could consider
HVM_BELOW_4G_RAM_ENDas the upper bound ofmax_ram_below_4g.
Yes. Currently the only limit on max_ram_below_4g is 4G. I am on the fence on this. I think there are valid values > HVM_BELOW_4G_RAM_END, but not clear they need to be supported.
Quoted 9 lines
I would just change the code to:
if (ram_size >= max_ram_below_4g) { above_4g_mem_size = ram_size - max_ram_below_4g; below_4g_mem_size = max_ram_below_4g; } else { below_4g_mem_size = ram_size; }
This is the code that is in patch #3 in the normal QEMU path but using the variable lowmem so that xen can know if max_ram_below_4g was set to non-zero. The issue that I am looking at handling here is the case of an older xen (does not know about max_ram_below_4g) and the newer QEMU, where xen expects QEMUs memory layout to change to HVM_BELOW_4G_RAM_END.
Because of this (QEMU is doing the right thing if max_ram_below_4g is non-zero) is why I coded it as only when max_ram_below_4g is zero, the xen default is not the same as QEMU.
-Don Slutz
Quoted 61 lines
Quoted 61 lines
xen-all.c +10
-11+if (!*above_4g_mem_size) { + block_len = ram_size; + }else { +/* Xen does not allocate the memory continuously, and keep a hole of +* 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); -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);@@ -1069,8 +1071,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 (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size, -MemoryRegion **ram_memory) +int xen_hvm_init (ram_addr_t max_ram_below_4g,ram_addr_t *below_4g_mem_size, +ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {int i, rc;unsigned long ioreq_pfn;@@ -1148,7 +1150,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 (ram_size, max_ram_below_4g, below_4g_mem_size, + above_4g_mem_size, ram_memory);qemu_add_vm_change_state_handler (xen_hvm_change_state_handler, state);xen-stub.c +2
-2@@ -64,8 +64,8 @@ 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) +int xen_hvm_init (ram_addr_t max_ram_below_4g,ram_addr_t *below_4g_mem_size, +ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {return 0 ; }Signature · 1 line
1.8.4
Re: [Qemu-devel] [PATCH v2 4/4] xen-all: Pass max_ram_below_4g to xen_hvm_init.
Quoted 102 lines · Don Slutz
Quoted 92 lines · Stefano Stabellini
Quoted 91 lines · Don Slutz
This is the xen part of "pc & q35: Add new object pc-memory-layout."
Signed-off-by Don Slutz<[email protected]>--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)hw/i386/pc_piix.c +2
-1@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisationfailed\n"); exit(1); }hw/i386/pc_q35.c +2
-1@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisationfailed\n"); exit(1); }include/hw/xen/xen.h +2
-2@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init(ram_addr_t max_ram_below_4g, 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-all.c +3
-3@@ -155,32 +155,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init(ram_addr_t *below_4g_mem_size, +static void xen_ram_init (ram_addr_t ram_size,ram_addr_t max_ram_below_4g, +ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, -ram_addr_t ram_size,MemoryRegion **ram_memory_p) + 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
xen-all.c +3
-3-* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +if (!max_ram_below_4g) { +if (ram_size >=HVM_BELOW_4G_RAM_END ) { + *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ;Quoted 8 lines
xen-all.c qemu_irq *xen_interrupt_controller_init(void) · line 174
Quoted 6 lines
xen-all.c +6
-0+ *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; + }else { + *above_4g_mem_size =0 ; + *below_4g_mem_size = ram_size; + } + }Instead of treating
max_ram_below_4gas a special case, couldn't initialize it toHVM_BELOW_4G_RAM_END?
Quoted 3 lines
Since
max_ram_below_4gis used and initialize in normal QEMU code whereHVM_BELOW_4G_RAM_ENDis not defined, I do not see how to do this outside of this routine without adding a new routine for this.
You can simply do this at the beginning of xen_ram_init:
max_ram_below_4g = max_ram_below_4g ? max_ram_below_4g : HVM_BELOW_4G_RAM_END;
my comment was about code readability, I didn't mean change any functionalities.
Re: [Qemu-devel] [PATCH v2 4/4] xen-all: Pass max_ram_below_4g to xen_hvm_init.
Quoted 106 lines · Stefano Stabellini
Quoted 101 lines · Don Slutz
Quoted 92 lines · Stefano Stabellini
Quoted 91 lines · Don Slutz
This is the xen part of "pc & q35: Add new object pc-memory-layout."
Signed-off-by Don Slutz<[email protected]>--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)hw/i386/pc_piix.c +2
-1@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisationfailed\n"); exit(1); }hw/i386/pc_q35.c +2
-1@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisationfailed\n"); exit(1); }include/hw/xen/xen.h +2
-2@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init(ram_addr_t max_ram_below_4g, 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-all.c +3
-3@@ -155,32 +155,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init(ram_addr_t *below_4g_mem_size, +static void xen_ram_init (ram_addr_t ram_size,ram_addr_t max_ram_below_4g, +ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, -ram_addr_t ram_size,MemoryRegion **ram_memory_p) + 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
xen-all.c +3
-3-* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +if (!max_ram_below_4g) { +if (ram_size >=HVM_BELOW_4G_RAM_END ) { + *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ;Quoted 8 lines
xen-all.c qemu_irq *xen_interrupt_controller_init(void) · line 174
Quoted 6 lines
xen-all.c +6
-0+ *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; + }else { + *above_4g_mem_size =0 ; + *below_4g_mem_size = ram_size; + } + }Instead of treating
max_ram_below_4gas a special case, couldn't initialize it toHVM_BELOW_4G_RAM_END?Quoted 3 lines
Since
max_ram_below_4gis used and initialize in normal QEMU code whereHVM_BELOW_4G_RAM_ENDis not defined, I do not see how to do this outside of this routine without adding a new routine for this.
Quoted 6 lines
You can simply do this at the beginning of
xen_ram_init:
max_ram_below_4g=max_ram_below_4g?max_ram_below_4g:HVM_BELOW_4G_RAM_END;my comment was about code readability, I didn't mean change any functionalities.
So the partial code delta:
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
- */
- block_len += HVM_BELOW_4G_MMIO_LENGTH;
- } - 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;
+ max_ram_below_4g = max_ram_below_4g ? max_ram_below_4g : HVM_BELOW_4G_RAM_END;
+ if (ram_size >= max_ram_below_4g) {
+ *above_4g_mem_size = ram_size - max_ram_below_4g;
+ *below_4g_mem_size = max_ram_below_4g;
} 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, and keep a hole of
+ * 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);
Which does redo the calculation of above and below when max_ram_below_4g is set, is better for code readability.
I am happy to send a v2 with this, just do not want to send too many versions.
-Don Slutz
Re: [Qemu-devel] [PATCH v2 4/4] xen-all: Pass max_ram_below_4g to xen_hvm_init.
Quoted 152 lines · Don Slutz
Quoted 105 lines · Stefano Stabellini
Quoted 101 lines · Don Slutz
Quoted 92 lines · Stefano Stabellini
Quoted 91 lines · Don Slutz
This is the xen part of "pc & q35: Add new object pc-memory-layout."
Signed-off-by Don Slutz<[email protected]>--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)hw/i386/pc_piix.c +2
-1@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisationfailed\n"); exit(1); }hw/i386/pc_q35.c +2
-1@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machine initialisationfailed\n"); exit(1); }include/hw/xen/xen.h +2
-2@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init(ram_addr_t max_ram_below_4g, 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-all.c +3
-3@@ -155,32 +155,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init(ram_addr_t *below_4g_mem_size, +static void xen_ram_init (ram_addr_t ram_size,ram_addr_t max_ram_below_4g, +ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, -ram_addr_t ram_size,MemoryRegion **ram_memory_p) + 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
xen-all.c +3
-3-* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +if (!max_ram_below_4g) { +if (ram_size >=HVM_BELOW_4G_RAM_END ) { + *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ;Quoted 8 lines
xen-all.c qemu_irq *xen_interrupt_controller_init(void) · line 174
Quoted 6 lines
xen-all.c +6
-0+ *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; + }else { + *above_4g_mem_size =0 ; + *below_4g_mem_size = ram_size; + } + }Instead of treating
max_ram_below_4gas a special case, couldn't initialize it toHVM_BELOW_4G_RAM_END?Quoted 3 lines
Since
max_ram_below_4gis used and initialize in normal QEMU code whereHVM_BELOW_4G_RAM_ENDis not defined, I do not see how to do this outside of this routine without adding a new routine for this.Quoted 6 lines
You can simply do this at the beginning of
xen_ram_init:
max_ram_below_4g=max_ram_below_4g?max_ram_below_4g:HVM_BELOW_4G_RAM_END;my comment was about code readability, I didn't mean change any functionalities.
So the partial code delta:
MemoryRegion *sysmem = get_system_memory(); ram_addr_t block_len;(quoted diff) +14
-14- 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; - } - 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; + max_ram_below_4g = max_ram_below_4g ? max_ram_below_4g : HVM_BELOW_4G_RAM_END; + if (ram_size >= max_ram_below_4g) { + *above_4g_mem_size = ram_size - max_ram_below_4g; + *below_4g_mem_size = max_ram_below_4g; } 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, and keep a hole of + * 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);
Quoted 5 lines
Which does redo the calculation of above and below when
max_ram_below_4gis set, is better for code readability.I am happy to send a v2 with this, just do not want to send too many versions.
That would be v3. :(
Quoted 4 lines
-Don Slutz
Re: [Qemu-devel] [PATCH v2 4/4] xen-all: Pass max_ram_below_4g to xen_hvm_init.
Quoted 163 lines · Don Slutz
Quoted 162 lines · Don Slutz
Quoted 111 lines · Stefano Stabellini
Quoted 107 lines · Don Slutz
Quoted 98 lines · Stefano Stabellini
Quoted 97 lines · Don Slutz
This is the xen part of "pc & q35: Add new object pc-memory-layout."
Signed-off-by Don Slutz<[email protected]>--- hw/i386/pc_piix.c | 4 ++-- hw/i386/pc_q35.c | 4 ++-- include/hw/xen/xen.h | 4 ++-- xen-all.c | 41 ++++++++++++++++++++++------------------- xen-stub.c | 4 ++-- 5 files changed, 30 insertions(+), 27 deletions(-)hw/i386/pc_piix.c +2
-1@@ -131,8 +131,8 @@ static void pc_init1(QEMUMachineInitArgs *args, below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) != 0) { fprintf(stderr, "xen hardware virtual machineinitialisation
failed\n"); exit(1); }hw/i386/pc_q35.c +2
-1@@ -120,8 +120,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) below_4g_mem_size = args->ram_size; } - if (xen_enabled() && xen_hvm_init(&below_4g_mem_size, &above_4g_mem_size, - &ram_memory) != 0) { + if (xen_enabled() && xen_hvm_init(max_ram_below_4g, &below_4g_mem_size, + &above_4g_mem_size, &ram_memory) !=0) {
fprintf(stderr, "xen hardware virtual machine
initialisationfailed\n"); exit(1); }include/hw/xen/xen.h +2
-2@@ -41,8 +41,8 @@ int xen_init(QEMUMachine *machine);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); +int xen_hvm_init(ram_addr_t max_ram_below_4g, 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-all.c +3
-3@@ -155,32 +155,34 @@ qemu_irq *xen_interrupt_controller_init(void)/* Memory Ops */ -static void xen_ram_init(ram_addr_t *below_4g_mem_size, +static void xen_ram_init (ram_addr_t ram_size,ram_addr_t max_ram_below_4g, +ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, -ram_addr_t ram_size,MemoryRegion **ram_memory_p) + 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
atxen-all.c +3
-3-* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH -*/ - block_len +=HVM_BELOW_4G_MMIO_LENGTH ; +if (!max_ram_below_4g) { +if (ram_size >=HVM_BELOW_4G_RAM_END ) { + *above_4g_mem_size = ram_size -HVM_BELOW_4G_RAM_END ;Quoted 8 lines
xen-all.c qemu_irq *xen_interrupt_controller_init(void) · line 174
Quoted 6 lines
xen-all.c +6
-0+ *below_4g_mem_size =HVM_BELOW_4G_RAM_END ; + }else { + *above_4g_mem_size =0 ; + *below_4g_mem_size = ram_size; + } + }Instead of treating
max_ram_below_4gas a special case, couldn't initialize it toHVM_BELOW_4G_RAM_END?Quoted 3 lines
Since
max_ram_below_4gis used and initialize in normal QEMU code whereHVM_BELOW_4G_RAM_ENDis not defined, I do not see how to do this outside of this routine without adding a new routine for this.Quoted 7 lines
You can simply do this at the beginning of
xen_ram_init:
max_ram_below_4g=max_ram_below_4g?max_ram_below_4g:HVM_BELOW_4G_RAM_END;my comment was about code readability, I didn't mean change any functionalities.
So the partial code delta:
MemoryRegion *sysmem = get_system_memory(); ram_addr_t block_len;xen-all.c +0
-3- block_len = ram_size; -if (ram_size >=HVM_BELOW_4G_RAM_END ) { -/* Xen does not allocate the memory continuously, and keep a hole at
(quoted diff) +1
-11- * HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH - */ - block_len += HVM_BELOW_4G_MMIO_LENGTH; - } - 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; + max_ram_below_4g = max_ram_below_4g ? max_ram_below_4g :
HVM_BELOW_4G_RAM_END;(quoted diff) +7
-0+ if (ram_size >= max_ram_below_4g) { + *above_4g_mem_size = ram_size - max_ram_below_4g; + *below_4g_mem_size = max_ram_below_4g; } 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, and keep a holeof
(quoted diff) +6
-0+ * 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);
Quoted 8 lines
Quoted 6 lines
Which does redo the calculation of above and below when
max_ram_below_4gis set, is better for code readability.I am happy to send a v2 with this, just do not want to send too many versions.
That would be v3. :(
That would be OK for me. You still need to get an ack for patch #2 and #3 from Michael and Paolo.