Skip to contentSkip to conversation

dom0 pvops and rearranging memory layout

DISCUSSION Juergen Gross 5 participants 9 messages Jan 23, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi,

while testing new patches to support dom0 with more than 512 GB I stumbled over an issue which - I think - is present in pvops for some time now.

On boot the kernel rearranges the memory layout to match the host E820 map. This is done to be able to access all I/O areas with identity mapped pfns (pfn == mfn). So basically some memory pages change their pfns while the mfns stay the same.

There is no check done whether the moved memory areas are actually in use (e.g. via memblock_is_reserved()). This can lead to cases where memory in use is put to an area which is made available for new memory allocations soon afterwards. Memory in question could be the initrd, the p2m map presented to dom0 by the hypervisor, or (hopefully in theory only) even the kernel itself or it's initial page tables built by the hypervisor.

In my test I had a p2m map of nearly 2GB size and the area between 2GB and 4GB had no RAM. So parts of the p2m map and the complete initrd where subject to be remapped which led to an early PANIC.

I'll try to add some special handling for the initrd and the p2m map. In case someone has a better idea: please tell me.

Juergen

#1 lore raw
Quoted 19 lines · Juergen Gross

Hi,

while testing new patches to support dom0 with more than 512 GB I stumbled over an issue which - I think - is present in pvops for some time now.

On boot the kernel rearranges the memory layout to match the host E820 map. This is done to be able to access all I/O areas with identity mapped pfns (pfn == mfn). So basically some memory pages change their pfns while the mfns stay the same.

There is no check done whether the moved memory areas are actually in use (e.g. via memblock_is_reserved()). This can lead to cases where memory in use is put to an area which is made available for new memory allocations soon afterwards. Memory in question could be the initrd, the p2m map presented to dom0 by the hypervisor, or (hopefully in theory only) even the kernel itself or it's initial page tables built by the hypervisor.

Quoted 7 lines

In my test I had a p2m map of nearly 2GB size and the area between 2GB and 4GB had no RAM. So parts of the p2m map and the complete initrd where subject to be remapped which led to an early PANIC.

I'll try to add some special handling for the initrd and the p2m map. In case someone has a better idea: please tell me.

The relocation is done based only on the e820 is it not?

I wonder whether it might be reasonable to extend contruct_dom0/libelf to avoid constructing a p2m where pfns of built data (kernel, initrd, p2m and initial pagetables) aliased with host io regions.

~Andrew

#2 lore raw
Quoted 24 lines · Andrew Cooper
Quoted 23 lines · Juergen Gross

Hi,

while testing new patches to support dom0 with more than 512 GB I stumbled over an issue which - I think - is present in pvops for some time now.

On boot the kernel rearranges the memory layout to match the host E820 map. This is done to be able to access all I/O areas with identity mapped pfns (pfn == mfn). So basically some memory pages change their pfns while the mfns stay the same.

There is no check done whether the moved memory areas are actually in use (e.g. via memblock_is_reserved()). This can lead to cases where memory in use is put to an area which is made available for new memory allocations soon afterwards. Memory in question could be the initrd, the p2m map presented to dom0 by the hypervisor, or (hopefully in theory only) even the kernel itself or it's initial page tables built by the hypervisor.

In my test I had a p2m map of nearly 2GB size and the area between 2GB and 4GB had no RAM. So parts of the p2m map and the complete initrd where subject to be remapped which led to an early PANIC.

Quoted 5 lines
Quoted 3 lines

I'll try to add some special handling for the initrd and the p2m map. In case someone has a better idea: please tell me.

The relocation is done based only on the e820 is it not?

Yes.

Quoted 3 lines

I wonder whether it might be reasonable to extend contruct_dom0/libelf to avoid constructing a p2m where pfns of built data (kernel, initrd, p2m and initial pagetables) aliased with host io regions.

That was my first idea, too. OTOH this would require a rather new hypervisor with this functionality to be able to run a pvops dom0 on such a machine.

Ans can we be sure that an existing non-pvops dom0 (or even an old pvops one) can work with such a change?

Juergen

#7 lore raw
In reply to Juergen Gross
Quoted 19 lines · Juergen Gross

Hi,

while testing new patches to support dom0 with more than 512 GB I stumbled over an issue which - I think - is present in pvops for some time now.

On boot the kernel rearranges the memory layout to match the host E820 map. This is done to be able to access all I/O areas with identity mapped pfns (pfn == mfn). So basically some memory pages change their pfns while the mfns stay the same.

There is no check done whether the moved memory areas are actually in use (e.g. via memblock_is_reserved()). This can lead to cases where memory in use is put to an area which is made available for new memory allocations soon afterwards. Memory in question could be the initrd, the p2m map presented to dom0 by the hypervisor, or (hopefully in theory only) even the kernel itself or it's initial page tables built by the hypervisor.

Quoted 6 lines

In my test I had a p2m map of nearly 2GB size and the area between 2GB and 4GB had no RAM. So parts of the p2m map and the complete initrd where subject to be remapped which led to an early PANIC.

I'll try to add some special handling for the initrd and the p2m map. In case someone has a better idea: please tell me.

I would suggest:

Pass 1: relocate p2m and page tables to "safe" areas. Pass 2: relocate frames from holes/reserved regions.

I don't think we want to change the hypervisor to workaround this.

David

#3 lore raw
In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 12:35, <[email protected]> wrote:

I wonder whether it might be reasonable to extend contruct_dom0/libelf to avoid constructing a p2m where pfns of built data (kernel, initrd, p2m and initial pagetables) aliased with host io regions.

For one, the problem goes away to 99.999% if using the advanced capabilities of relocating the P2M and not mapping the initrd at all.

And then, such a change could easily end up being incompatible with older kernels, which may (and do) build on the initial memory map being a single chunk.

Jan

#5 lore raw
In reply to a message not in the archive
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 12:35, <[email protected]> wrote:

I wonder whether it might be reasonable to extend contruct_dom0/libelf to avoid constructing a p2m where pfns of built data (kernel, initrd, p2m and initial pagetables) aliased with host io regions.

For one, the problem goes away to 99.999% if using the advanced capabilities of relocating the P2M and not mapping the initrd at all.

No, it does not. I'm doing both and the systems dies at once.

Even relocating the P2M to another virtual address and not mapping the initrd won't help if the related PFNs are relocated and, even worse, are made available for new memory allocations.

Quoted 3 lines

And then, such a change could easily end up being incompatible with older kernels, which may (and do) build on the initial memory map being a single chunk.

Yes, I fear so, too.

Juergen

#6 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 13:08, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 12:35, <[email protected]> wrote:

I wonder whether it might be reasonable to extend contruct_dom0/libelf to avoid constructing a p2m where pfns of built data (kernel, initrd, p2m and initial pagetables) aliased with host io regions.

Quoted 8 lines
Quoted 2 lines

For one, the problem goes away to 99.999% if using the advanced capabilities of relocating the P2M and not mapping the initrd at all.

No, it does not. I'm doing both and the systems dies at once.

Even relocating the P2M to another virtual address and not mapping the initrd won't help if the related PFNs are relocated and, even worse, are made available for new memory allocations.

Oh, right, the placement in VA space doesn't matter here.

Jan

#8 lore raw
In reply to Juergen Gross
Quoted 19 lines · Juergen Gross

Hi,

while testing new patches to support dom0 with more than 512 GB I stumbled over an issue which - I think - is present in pvops for some time now.

On boot the kernel rearranges the memory layout to match the host E820 map. This is done to be able to access all I/O areas with identity mapped pfns (pfn == mfn). So basically some memory pages change their pfns while the mfns stay the same.

There is no check done whether the moved memory areas are actually in use (e.g. via memblock_is_reserved()). This can lead to cases where memory in use is put to an area which is made available for new memory allocations soon afterwards. Memory in question could be the initrd, the p2m map presented to dom0 by the hypervisor, or (hopefully in theory only) even the kernel itself or it's initial page tables built by the hypervisor.

Quoted 1 line

In my test I had a p2m map of nearly 2GB size and the area between

Oh my. That is huge. Could you compress it? This would require of course a new type of P2M - where would mark which MFNs are contingous.

And then during booting you could read over and find these special ones and when creating the new P2M do the right uncompression?

Quoted 8 lines

2GB and 4GB had no RAM. So parts of the p2m map and the complete initrd where subject to be remapped which led to an early PANIC.

I'll try to add some special handling for the initrd and the p2m map. In case someone has a better idea: please tell me.

Juergen

#9 lore raw
Quoted 20 lines · Konrad Rzeszutek Wilk
Quoted 19 lines · Juergen Gross

Hi,

while testing new patches to support dom0 with more than 512 GB I stumbled over an issue which - I think - is present in pvops for some time now.

On boot the kernel rearranges the memory layout to match the host E820 map. This is done to be able to access all I/O areas with identity mapped pfns (pfn == mfn). So basically some memory pages change their pfns while the mfns stay the same.

There is no check done whether the moved memory areas are actually in use (e.g. via memblock_is_reserved()). This can lead to cases where memory in use is put to an area which is made available for new memory allocations soon afterwards. Memory in question could be the initrd, the p2m map presented to dom0 by the hypervisor, or (hopefully in theory only) even the kernel itself or it's initial page tables built by the hypervisor.

Quoted 7 lines
Quoted 1 line

In my test I had a p2m map of nearly 2GB size and the area between

Oh my. That is huge. Could you compress it? This would require of course a new type of P2M - where would mark which MFNs are contingous.

And then during booting you could read over and find these special ones and when creating the new P2M do the right uncompression?

I don't think that's the correct solution. It would require a new hypervisor as well and we still wouldn't have a guarantee it will work.

That's "only" for 1TB of memory. I think we want to support much more.

And even if the p2m is okay, a huge initrd will still blow us up.

Juergen

Quoted 10 lines
Quoted 9 lines

2GB and 4GB had no RAM. So parts of the p2m map and the complete initrd where subject to be remapped which led to an early PANIC.

I'll try to add some special handling for the initrd and the p2m map. In case someone has a better idea: please tell me.

Juergen