xen: fixup RAM memory region initialization
PATCH 1/1 xen: fixup RAM memory region initialization
Since bd457782b3b0 ("x86/pc: use memdev for RAM") Xen machine fails to start with:
qemu-system-i386: xen: failed to populate ram at 0
The reason is that xen_ram_alloc() which is called by memory_region_init_ram(), compares memory region with statically allocated 'global' ram_memory memory region that it uses for RAM, and does nothing in case it matches.
While it's possible feed machine->ram to xen_ram_alloc() in the same manner to keep that hack working, I'd prefer not to keep that circular dependency and try to untangle that.
However it doesn't look trivial to fix, so as temporary fixup opt out Xen machine from memdev based RAM allocation, and let xen_ram_alloc() do its trick for now.
---
PS:
- compile tested only
hw/i386/pc_piix.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/i386/pc_piix.c +4 -0
@@ -953,6 +953,10 @@ static void xenfv_machine_options(MachineClass *m) m->desc ="Xen Fully-virtualized PC" ; m->max_cpus =HVM_MAX_VCPUS ; m->default_machine_opts ="accel=xen" ; +/* +* opt out of system RAM being allocated by generic code +*/ + m->default_ram_id =NULL ; } DEFINE_PC_MACHINE(xenfv, "xenfv", pc_xen_hvm_init,
Signature · 1 line
2.18.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed build test on FreeBSD host. Please find the details below.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with # HEAD pointing to a commit that has the patches applied on top of "base"
# branch if qemu-system-x86_64 --help >/dev/null 2>&1; then QEMU=qemu-system-x86_64 elif /usr/libexec/qemu-kvm --help >/dev/null 2>&1; then QEMU=/usr/libexec/qemu-kvm else exit 1 fi make vm-build-freebsd J=21 QEMU=$QEMU exit 0 === TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/[email protected]/testing.FreeBSD/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Paolo,
could you take it along with Olaf's xenfv patch?
Quoted 41 lines · On Fri, 27 Mar 2020 06:48:28 -0400 Igor Mammedov <[email protected]> wrote:
Since
bd457782b3b0("x86/pc: use memdev for RAM") Xen machine fails to start with:
qemu-system-i386: xen: failed to populate ram at 0The reason is that
xen_ram_alloc()which is called bymemory_region_init_ram(), compares memory region with statically allocated 'global'ram_memorymemory region that it uses for RAM, and does nothing in case it matches.While it's possible feed
machine->ramtoxen_ram_alloc()in the same manner to keep that hack working, I'd prefer not to keep that circular dependency and try to untangle that.However it doesn't look trivial to fix, so as temporary fixup opt out Xen machine from memdev based RAM allocation, and let
xen_ram_alloc()do its trick for now.Reported-by Anthony PERARD <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
PS:
- compile tested onlyhw/i386/pc_piix.c | 4 ++++ 1 file changed, 4 insertions(+)hw/i386/pc_piix.c +4
-0@@ -953,6 +953,10 @@ static void xenfv_machine_options(MachineClass *m) m->desc ="Xen Fully-virtualized PC" ; m->max_cpus =HVM_MAX_VCPUS ; m->default_machine_opts ="accel=xen" ; +/* +* opt out of system RAM being allocated by generic code +*/ + m->default_ram_id =NULL ; } DEFINE_PC_MACHINE(xenfv, "xenfv", pc_xen_hvm_init,
Quoted 3 lines · Igor Mammedov
Paolo,
could you take it along with Olaf's xenfv patch?
Yes, thanks. Also your other patch.
Paolo
Quoted 13 lines · Igor Mammedov
Since
bd457782b3b0("x86/pc: use memdev for RAM") Xen machine fails to start with:
qemu-system-i386: xen: failed to populate ram at 0The reason is that
xen_ram_alloc()which is called bymemory_region_init_ram(), compares memory region with statically allocated 'global'ram_memorymemory region that it uses for RAM, and does nothing in case it matches.While it's possible feed
machine->ramtoxen_ram_alloc()in the same manner to keep that hack working, I'd prefer not to keep that circular dependency and try to untangle that.
Quoted 6 lines
However it doesn't look trivial to fix, so as temporary fixup opt out Xen machine from memdev based RAM allocation, and let
xen_ram_alloc()do its trick for now.Reported-by Anthony PERARD <[email protected]>Signed-off-by Igor Mammedov <[email protected]>
That should work on most configs. But we also sometime use the "pc" machine with accel=xen, to run without the "xen-platform" pci device, but that would be less common.
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 18 lines · On Mon, 30 Mar 2020 17:52:48 +0100 Anthony PERARD <[email protected]>…
Quoted 17 lines · Igor Mammedov
Since
bd457782b3b0("x86/pc: use memdev for RAM") Xen machine fails to start with:
qemu-system-i386: xen: failed to populate ram at 0The reason is that
xen_ram_alloc()which is called bymemory_region_init_ram(), compares memory region with statically allocated 'global'ram_memorymemory region that it uses for RAM, and does nothing in case it matches.While it's possible feed
machine->ramtoxen_ram_alloc()in the same manner to keep that hack working, I'd prefer not to keep that circular dependency and try to untangle that.However it doesn't look trivial to fix, so as temporary fixup opt out Xen machine from memdev based RAM allocation, and let
xen_ram_alloc()do its trick for now.
Quoted 8 lines
Quoted 2 lines
Reported-by Anthony PERARD <[email protected]>Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Anthony PERARD <[email protected]>That should work on most configs. But we also sometime use the "pc" machine with accel=xen, to run without the "xen-platform" pci device, but that would be less common.
does following work for you in case of pc machine?
hw/xen/xen-common.c +6 -0
@@ -151,6 +151,8 @@ static void xen_setup_post(MachineState *ms, AccelState *accel)static int xen_init (MachineState *ms) { +MachineClass *mc =MACHINE_GET_CLASS (ms); + xen_xc =xc_interface_open (0 ,0 ,0 );if (xen_xc ==NULL ) {xen_pv_printf (NULL ,0 ,"can't open xen interface\n" );
@@ -170,6 +172,10 @@ static int xen_init(MachineState *ms)return -1 ; }qemu_add_vm_change_state_handler (xen_change_state_handler,NULL ); +/* +* opt out of system RAM being allocated by generic code +*/ + m->default_ram_id =NULL ;return 0 ; }
Quoted 2 lines
Thanks,
Quoted 46 lines · Igor Mammedov
Quoted 18 lines · On Mon, 30 Mar 2020 17:52:48 +0100 Anthony PERARD <[email protected]>…
Quoted 17 lines · Igor Mammedov
Since
bd457782b3b0("x86/pc: use memdev for RAM") Xen machine fails to start with:
qemu-system-i386: xen: failed to populate ram at 0The reason is that
xen_ram_alloc()which is called bymemory_region_init_ram(), compares memory region with statically allocated 'global'ram_memorymemory region that it uses for RAM, and does nothing in case it matches.While it's possible feed
machine->ramtoxen_ram_alloc()in the same manner to keep that hack working, I'd prefer not to keep that circular dependency and try to untangle that.However it doesn't look trivial to fix, so as temporary fixup opt out Xen machine from memdev based RAM allocation, and let
xen_ram_alloc()do its trick for now.Quoted 8 lines
Quoted 2 lines
Reported-by Anthony PERARD <[email protected]>Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Anthony PERARD <[email protected]>That should work on most configs. But we also sometime use the "pc" machine with accel=xen, to run without the "xen-platform" pci device, but that would be less common.
does following work for you in case of pc machine?
hw/xen/xen-common.c +2
-0@@ -151,6 +151,8 @@ static void xen_setup_post(MachineState *ms, AccelState *accel)static int xen_init (MachineState *ms) { +MachineClass *mc =MACHINE_GET_CLASS (ms); + xen_xc =xc_interface_open (0 ,0 ,0 );if (xen_xc ==NULL ) {xen_pv_printf (NULL ,0 ,"can't open xen interface\n" );
hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 179
Quoted 8 lines
hw/xen/xen-common.c +4
-0@@ -170,6 +172,10 @@ static int xen_init(MachineState *ms)return -1 ; }qemu_add_vm_change_state_handler (xen_change_state_handler,NULL ); +/* +* opt out of system RAM being allocated by generic code +*/ + m->default_ram_id =NULL ;return 0 ;
After fixing the build issues, it does work, yes. I've tested both "xenfv" and "pc,accel=xen".
Build issue:
- I've added #include "hw/boards.h"
- and s/m->/mc->/
Thanks!
Signature · 1 line
Anthony PERARD
Quoted 50 lines · On Thu, 2 Apr 2020 14:25:30 +0100 Anthony PERARD <[email protected]>…
Quoted 49 lines · Igor Mammedov
Quoted 18 lines · On Mon, 30 Mar 2020 17:52:48 +0100 Anthony PERARD <[email protected]>…
Quoted 17 lines · Igor Mammedov
Since
bd457782b3b0("x86/pc: use memdev for RAM") Xen machine fails to start with:
qemu-system-i386: xen: failed to populate ram at 0The reason is that
xen_ram_alloc()which is called bymemory_region_init_ram(), compares memory region with statically allocated 'global'ram_memorymemory region that it uses for RAM, and does nothing in case it matches.While it's possible feed
machine->ramtoxen_ram_alloc()in the same manner to keep that hack working, I'd prefer not to keep that circular dependency and try to untangle that.However it doesn't look trivial to fix, so as temporary fixup opt out Xen machine from memdev based RAM allocation, and let
xen_ram_alloc()do its trick for now.Quoted 8 lines
Quoted 2 lines
Reported-by Anthony PERARD <[email protected]>Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Anthony PERARD <[email protected]>That should work on most configs. But we also sometime use the "pc" machine with accel=xen, to run without the "xen-platform" pci device, but that would be less common.
does following work for you in case of pc machine?
hw/xen/xen-common.c +2
-0@@ -151,6 +151,8 @@ static void xen_setup_post(MachineState *ms, AccelState *accel)static int xen_init (MachineState *ms) { +MachineClass *mc =MACHINE_GET_CLASS (ms); + xen_xc =xc_interface_open (0 ,0 ,0 );if (xen_xc ==NULL ) {xen_pv_printf (NULL ,0 ,"can't open xen interface\n" );@@ -170,6 +172,10 @@ static int xen_init(MachineState *ms)return -1 ; }qemu_add_vm_change_state_handler (xen_change_state_handler,NULL );
Quoted 8 lines
hw/xen/xen-common.c static int xen_init(MachineState *ms) · line 179
Quoted 5 lines
hw/xen/xen-common.c +4
-0+/* +* opt out of system RAM being allocated by generic code +*/ + m->default_ram_id =NULL ;return 0 ;After fixing the build issues, it does work, yes. I've tested both "xenfv" and "pc,accel=xen".
thanks, I'll post a formal patch
however it's all workarounds,
we need to fix ram allocation properly later on
so far I only have questions, hope you can help with clarifying them
1. why xen uses memory_region_init_ram() which does not allocate anything can it use plain memory_region_init() instead?
2. how main ram is allocated?
3. code has
/*
* Xen does not allocate the memory continuously, it keeps a
* hole of the size computed above or passed in.
*/
block_len = (1ULL << 32) + x86ms->above_4g_mem_size; which fixes up size ram memory region
can we allocate 1 memory region of ram_size and then alias lower and upper memory instead of that?
4. how RAM migration works in case of xen?
Quoted 4 lines
Build issue:
- I've added #include "hw/boards.h"
- and s/m->/mc->/
ccccccgndiej> gngfiehlivuil
Quoted 2 lines
Thanks!nbchihheikhjlnervve
Quoted 1 line · Igor Mammedov
1. why xen uses
memory_region_init_ram()which does not allocate anything
This seems to be due to history.
Quoted 1 line
can it use plain
memory_region_init()instead?
I can give it a try. And it doesn't work, I had to call qemu_ram_alloc() as well, to set ram_memory.ram_block.
On the other and, I think memory_region_init_ram_nomigrate() would be enough. QEMU didn't complain when I migrated the guest.
Quoted 1 line
2. how main ram is allocated?
It's done by the toolstack, libxl. It creates a new domain in the hypervisor, memory allocation is part of this, then QEMU is started, for emulation of some devices.
There is one thing that QEMU does in regards to memory, it's the call xc_domain_populate_physmap_exact() in xen_ram_alloc(). This is for when an emulated PCI device needs some memory, like for the VGA region.
Quoted 9 lines
3. code has
/* * Xen does not allocate the memory continuously, it keeps a * hole of the size computed above or passed in. */ block_len = (1ULL << 32) + x86ms->above_4g_mem_size;which fixes up size ram memory region
can we allocate 1 memory region ofram_sizeand then alias lower and upper memory instead of that?
I don't know, I don't think I know enough about how memory_region are used to be able to answer that.
Quoted 1 line
4. how RAM migration works in case of xen?
From QEMU, we only migrate devices states, we call the "xen-save-devices-state" QMP command. Memory migration is done by the toolstack. In QEMU, there is a bodge in xen_ram_alloc() to avoid having QEMU doing some "allocation" during migration.
I hope that help.
Cheers,
Signature · 1 line
Anthony PERARD
Quoted 5 lines · On Tue, 7 Apr 2020 12:36:34 +0100 Anthony PERARD <[email protected]>…
Quoted 1 line · Igor Mammedov
1. why xen uses
memory_region_init_ram()which does not allocate anythingThis seems to be due to history.
Quoted 7 lines
Quoted 1 line
can it use plain
memory_region_init()instead?I can give it a try. And it doesn't work, I had to call
qemu_ram_alloc()as well, to setram_memory.c.On the other and, I think
memory_region_init_ram_nomigrate()would be enough. QEMU didn't complain when I migrated the guest.
Why does it need ramblock fir main ram if it does not allocate nor migrate it using QEMU infrastructure?
Quoted 34 lines
Quoted 2 lines
2. how main ram is allocated?
It's done by the toolstack, libxl. It creates a new domain in the hypervisor, memory allocation is part of this, then QEMU is started, for emulation of some devices.
There is one thing that QEMU does in regards to memory, it's the call
xc_domain_populate_physmap_exact()inxen_ram_alloc(). This is for when an emulated PCI device needs some memory, like for the VGA region.Quoted 9 lines
3. code has
/* * Xen does not allocate the memory continuously, it keeps a * hole of the size computed above or passed in. */ block_len = (1ULL << 32) + x86ms->above_4g_mem_size;which fixes up size ram memory region
can we allocate 1 memory region ofram_sizeand then alias lower and upper memory instead of that?I don't know, I don't think I know enough about how
memory_regionare used to be able to answer that.Quoted 1 line
4. how RAM migration works in case of xen?
From QEMU, we only migrate devices states, we call the "xen-save-devices-state" QMP command. Memory migration is done by the toolstack. In QEMU, there is a bodge in
xen_ram_alloc()to avoid having QEMU doing some "allocation" during migration.I hope that help.
Cheers,