diff mbox

[4/5] xen: Fix the memory registration to reflect of what is done by Xen.

Message ID 1310740376-13323-5-git-send-email-anthony.perard@citrix.com
State New
Headers show

Commit Message

Anthony PERARD July 15, 2011, 2:32 p.m. UTC
A Xen guest memory is allocated by libxc. But this memory is not
allocated continuously, instead, it leaves the VGA IO memory space not
allocated, same for the MMIO space (at HVM_BELOW_4G_MMIO_START of size
HVM_BELOW_4G_MMIO_LENGTH).

So to reflect that, we do not register the physical memory for this two
holes. But we still keep only one RAMBlock for the all RAM as it is more
easier than have two separate blocks (1 above 4G). Also this prevent QEMU
from use the MMIO space for a ROM.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 xen-all.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

Comments

Paolo Bonzini July 15, 2011, 2:55 p.m. UTC | #1
On 07/15/2011 04:32 PM, Anthony PERARD wrote:
> A Xen guest memory is allocated by libxc. But this memory is not
> allocated continuously, instead, it leaves the VGA IO memory space not
> allocated, same for the MMIO space (at HVM_BELOW_4G_MMIO_START of size
> HVM_BELOW_4G_MMIO_LENGTH).
>
> So to reflect that, we do not register the physical memory for this two
> holes. But we still keep only one RAMBlock for the all RAM as it is more
> easier than have two separate blocks (1 above 4G). Also this prevent QEMU
> from use the MMIO space for a ROM.
>
> Signed-off-by: Anthony PERARD<anthony.perard@citrix.com>
> ---
>   xen-all.c |   21 ++++++++++++++-------
>   1 files changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/xen-all.c b/xen-all.c
> index 2c0a62d..76d5c5c 100644
> --- a/xen-all.c
> +++ b/xen-all.c
> @@ -144,6 +144,12 @@ static void xen_ram_init(ram_addr_t ram_size)
>       new_block->host = NULL;
>       new_block->offset = 0;
>       new_block->length = 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
> +         */
> +        new_block->length += HVM_BELOW_4G_MMIO_LENGTH;
> +    }
>
>       QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
>
> @@ -152,20 +158,21 @@ static void xen_ram_init(ram_addr_t ram_size)
>       memset(ram_list.phys_dirty + (new_block->offset>>  TARGET_PAGE_BITS),
>              0xff, new_block->length>>  TARGET_PAGE_BITS);
>
> -    if (ram_size>= 0xe0000000 ) {
> -        above_4g_mem_size = ram_size - 0xe0000000;
> -        below_4g_mem_size = 0xe0000000;
> +    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 {
>           below_4g_mem_size = ram_size;
>       }
>
> -    cpu_register_physical_memory(0, below_4g_mem_size, new_block->offset);
> -#if TARGET_PHYS_ADDR_BITS>  32
> +    cpu_register_physical_memory(0, 0xa0000, 0);
> +    /* Skip of the VGA IO memory space */
> +    cpu_register_physical_memory(0xc0000, below_4g_mem_size - 0xc0000,
> +                                 0xc0000);
>       if (above_4g_mem_size>  0) {
>           cpu_register_physical_memory(0x100000000ULL, above_4g_mem_size,
> -                                     new_block->offset + below_4g_mem_size);
> +                                     0x100000000ULL);
>       }
> -#endif
>   }
>
>   void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo
Stefano Stabellini July 15, 2011, 5:05 p.m. UTC | #2
On Fri, 15 Jul 2011, Anthony PERARD wrote:
> A Xen guest memory is allocated by libxc. But this memory is not
> allocated continuously, instead, it leaves the VGA IO memory space not
> allocated, same for the MMIO space (at HVM_BELOW_4G_MMIO_START of size
> HVM_BELOW_4G_MMIO_LENGTH).
> 
> So to reflect that, we do not register the physical memory for this two
> holes. But we still keep only one RAMBlock for the all RAM as it is more
> easier than have two separate blocks (1 above 4G). Also this prevent QEMU
> from use the MMIO space for a ROM.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  xen-all.c |   21 ++++++++++++++-------
>  1 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/xen-all.c b/xen-all.c
> index 2c0a62d..76d5c5c 100644
> --- a/xen-all.c
> +++ b/xen-all.c
> @@ -144,6 +144,12 @@ static void xen_ram_init(ram_addr_t ram_size)
>      new_block->host = NULL;
>      new_block->offset = 0;
>      new_block->length = 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
> +         */
> +        new_block->length += HVM_BELOW_4G_MMIO_LENGTH;
> +    }
>  
>      QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
>  
> @@ -152,20 +158,21 @@ static void xen_ram_init(ram_addr_t ram_size)
>      memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
>             0xff, new_block->length >> TARGET_PAGE_BITS);
>  
> -    if (ram_size >= 0xe0000000 ) {
> -        above_4g_mem_size = ram_size - 0xe0000000;
> -        below_4g_mem_size = 0xe0000000;
> +    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 {
>          below_4g_mem_size = ram_size;
>      }
>  
> -    cpu_register_physical_memory(0, below_4g_mem_size, new_block->offset);
> -#if TARGET_PHYS_ADDR_BITS > 32
> +    cpu_register_physical_memory(0, 0xa0000, 0);
> +    /* Skip of the VGA IO memory space */
> +    cpu_register_physical_memory(0xc0000, below_4g_mem_size - 0xc0000,
> +                                 0xc0000);
 
Shouldn't we avoid registering any memory for the whole video ram area?
I mean:
    
0xa0000 - 0x100000
Anthony PERARD July 15, 2011, 5:51 p.m. UTC | #3
On Fri, Jul 15, 2011 at 18:05, Stefano Stabellini
<stefano.stabellini@eu.citrix.com> wrote:
> Shouldn't we avoid registering any memory for the whole video ram area?
> I mean:
>
> 0xa0000 - 0x100000

No, because SeaBIOS load the Options ROM (VGA Bios, PXE) to the area
between 0xc0000 and 0x100000, and this go through QEMU.

The area between 0xa0000 and 0xc0000 is registred later by the
cirrus_vga bits, as IO.
Stefano Stabellini July 18, 2011, 11:14 a.m. UTC | #4
On Fri, 15 Jul 2011, Anthony PERARD wrote:
> On Fri, Jul 15, 2011 at 18:05, Stefano Stabellini
> <stefano.stabellini@eu.citrix.com> wrote:
> > Shouldn't we avoid registering any memory for the whole video ram area?
> > I mean:
> >
> > 0xa0000 - 0x100000
> 
> No, because SeaBIOS load the Options ROM (VGA Bios, PXE) to the area
> between 0xc0000 and 0x100000, and this go through QEMU.
> 
> The area between 0xa0000 and 0xc0000 is registred later by the
> cirrus_vga bits, as IO.

OK. Can you please expand your comment in the code with the same
explanation?
Anthony PERARD July 18, 2011, 3:29 p.m. UTC | #5
On Mon, Jul 18, 2011 at 12:14, Stefano Stabellini
<stefano.stabellini@eu.citrix.com> wrote:
> On Fri, 15 Jul 2011, Anthony PERARD wrote:
>> On Fri, Jul 15, 2011 at 18:05, Stefano Stabellini
>> <stefano.stabellini@eu.citrix.com> wrote:
>> > Shouldn't we avoid registering any memory for the whole video ram area?
>> > I mean:
>> >
>> > 0xa0000 - 0x100000
>>
>> No, because SeaBIOS load the Options ROM (VGA Bios, PXE) to the area
>> between 0xc0000 and 0x100000, and this go through QEMU.
>>
>> The area between 0xa0000 and 0xc0000 is registred later by the
>> cirrus_vga bits, as IO.
>
> OK. Can you please expand your comment in the code with the same
> explanation?

Yes, I will do that.
Stefano Stabellini July 18, 2011, 4:14 p.m. UTC | #6
On Fri, 15 Jul 2011, Anthony PERARD wrote:
> A Xen guest memory is allocated by libxc. But this memory is not
> allocated continuously, instead, it leaves the VGA IO memory space not
> allocated, same for the MMIO space (at HVM_BELOW_4G_MMIO_START of size
> HVM_BELOW_4G_MMIO_LENGTH).

I realized now that you started using HVM_BELOW_4G_MMIO_START and
HVM_BELOW_4G_MMIO_LENGTH without including xen/hvm/e820.h.
It fails to compile on the latest xen-unstable.
diff mbox

Patch

diff --git a/xen-all.c b/xen-all.c
index 2c0a62d..76d5c5c 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -144,6 +144,12 @@  static void xen_ram_init(ram_addr_t ram_size)
     new_block->host = NULL;
     new_block->offset = 0;
     new_block->length = 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
+         */
+        new_block->length += HVM_BELOW_4G_MMIO_LENGTH;
+    }
 
     QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
 
@@ -152,20 +158,21 @@  static void xen_ram_init(ram_addr_t ram_size)
     memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
            0xff, new_block->length >> TARGET_PAGE_BITS);
 
-    if (ram_size >= 0xe0000000 ) {
-        above_4g_mem_size = ram_size - 0xe0000000;
-        below_4g_mem_size = 0xe0000000;
+    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 {
         below_4g_mem_size = ram_size;
     }
 
-    cpu_register_physical_memory(0, below_4g_mem_size, new_block->offset);
-#if TARGET_PHYS_ADDR_BITS > 32
+    cpu_register_physical_memory(0, 0xa0000, 0);
+    /* Skip of the VGA IO memory space */
+    cpu_register_physical_memory(0xc0000, below_4g_mem_size - 0xc0000,
+                                 0xc0000);
     if (above_4g_mem_size > 0) {
         cpu_register_physical_memory(0x100000000ULL, above_4g_mem_size,
-                                     new_block->offset + below_4g_mem_size);
+                                     0x100000000ULL);
     }
-#endif
 }
 
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size)