diff mbox series

[4/8] xen/vmap: allow vm_init_type to be called during early_boot

Message ID 20200201003303.2363081-4-dwmw2@infradead.org (mailing list archive)
State New, archived
Headers show
Series Early cleanups and bug fixes in preparation for live update | expand

Commit Message

David Woodhouse Feb. 1, 2020, 12:32 a.m. UTC
From: Wei Liu <wei.liu2@citrix.com>

We want to move vm_init, which calls vm_init_type under the hood, to
early boot stage. Add a path to get page from boot allocator instead.

Add an emacs block to that file while I was there.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 xen/common/vmap.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Julien Grall Feb. 13, 2020, 10:36 a.m. UTC | #1
Hi David,

On 01/02/2020 01:32, David Woodhouse wrote:
> From: Wei Liu <wei.liu2@citrix.com>
> 
> We want to move vm_init, which calls vm_init_type under the hood, to
> early boot stage. Add a path to get page from boot allocator instead.
> 
> Add an emacs block to that file while I was there.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
> ---
>   xen/common/vmap.c | 22 +++++++++++++++++++---
>   1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/common/vmap.c b/xen/common/vmap.c
> index faebc1ddf1..37922f735b 100644
> --- a/xen/common/vmap.c
> +++ b/xen/common/vmap.c
> @@ -34,9 +34,15 @@ void __init vm_init_type(enum vmap_region type, void *start, void *end)
>   
>       for ( i = 0, va = (unsigned long)vm_bitmap(type); i < nr; ++i, va += PAGE_SIZE )
>       {
> -        struct page_info *pg = alloc_domheap_page(NULL, 0);
> -
> -        map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR);
> +        mfn_t mfn;
> +        int rc;
> +
> +        if ( system_state == SYS_STATE_early_boot )
> +            mfn = alloc_boot_pages(1, 1);
> +        else
> +            mfn = page_to_mfn(alloc_domheap_page(NULL, 0));

It looks like the function was doing a pretty bad job at checking the 
return values :(.

As you add a check for map_pages_to_xen(), would you mind to add another 
one for alloc_domheap_page()?

Other than that, the code looks good to me.

> +        rc = map_pages_to_xen(va, mfn, 1, PAGE_HYPERVISOR);
> +        BUG_ON(rc);
>           clear_page((void *)va);
>       }
>       bitmap_fill(vm_bitmap(type), vm_low[type]);
> @@ -330,3 +336,13 @@ void vfree(void *va)
>           free_domheap_page(pg);
>   }
>   #endif
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> 

Cheers,
Jan Beulich Feb. 21, 2020, 4:42 p.m. UTC | #2
On 01.02.2020 01:32, David Woodhouse wrote:
> From: Wei Liu <wei.liu2@citrix.com>
> 
> We want to move vm_init, which calls vm_init_type under the hood, to
> early boot stage. Add a path to get page from boot allocator instead.
> 
> Add an emacs block to that file while I was there.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
diff mbox series

Patch

diff --git a/xen/common/vmap.c b/xen/common/vmap.c
index faebc1ddf1..37922f735b 100644
--- a/xen/common/vmap.c
+++ b/xen/common/vmap.c
@@ -34,9 +34,15 @@  void __init vm_init_type(enum vmap_region type, void *start, void *end)
 
     for ( i = 0, va = (unsigned long)vm_bitmap(type); i < nr; ++i, va += PAGE_SIZE )
     {
-        struct page_info *pg = alloc_domheap_page(NULL, 0);
-
-        map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR);
+        mfn_t mfn;
+        int rc;
+
+        if ( system_state == SYS_STATE_early_boot )
+            mfn = alloc_boot_pages(1, 1);
+        else
+            mfn = page_to_mfn(alloc_domheap_page(NULL, 0));
+        rc = map_pages_to_xen(va, mfn, 1, PAGE_HYPERVISOR);
+        BUG_ON(rc);
         clear_page((void *)va);
     }
     bitmap_fill(vm_bitmap(type), vm_low[type]);
@@ -330,3 +336,13 @@  void vfree(void *va)
         free_domheap_page(pg);
 }
 #endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */