diff mbox series

[v1,4/5] xen/arm: retrieve reserved pages on populate_physmap

Message ID 20220330093617.3870589-5-Penny.Zheng@arm.com (mailing list archive)
State Superseded
Headers show
Series populate/unpopulate memory when domain on static | expand

Commit Message

Penny Zheng March 30, 2022, 9:36 a.m. UTC
When domain on static allocation populates memory through populate_physmap,
other than allocating from heap, it shall allocate from resv_page_list to
make sure that all guest RAM are still restricted in statically configured
regions.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
---
 xen/common/memory.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Jan Beulich March 30, 2022, 9:58 a.m. UTC | #1
On 30.03.2022 11:36, Penny Zheng wrote:
> --- a/xen/common/memory.c
> +++ b/xen/common/memory.c
> @@ -249,6 +249,26 @@ static void populate_physmap(struct memop_args *a)
>  
>                  mfn = _mfn(gpfn);
>              }
> +#ifdef CONFIG_STATIC_MEMORY
> +            else if ( is_domain_on_static_allocation(d) )
> +            {
> +                for ( j = 0; j < (1U << a->extent_order); j++ )
> +                {
> +                    page = page_list_remove_head(&d->resv_page_list);

How do you guarantee the pages are contiguous, as required by a non-zero
a->extent_order? Did you perhaps mean to forbid non-zero-order requests
in this configuration?

> +                    if ( unlikely(!page) )
> +                    {
> +                        gdprintk(XENLOG_INFO,
> +                                 "Could not allocate guest page number %lx\n",
> +                                 gfn_x(_gfn(gpfn)));
> +                        goto out;

And earlier allocated pages are simply lost / leaked?

Jan
Penny Zheng March 31, 2022, 6:53 a.m. UTC | #2
Hi Jan

> -----Original Message-----
> From: Jan Beulich <jbeulich@suse.com>
> Sent: Wednesday, March 30, 2022 5:59 PM
> To: Penny Zheng <Penny.Zheng@arm.com>
> Cc: Wei Chen <Wei.Chen@arm.com>; Henry Wang <Henry.Wang@arm.com>;
> Andrew Cooper <andrew.cooper3@citrix.com>; George Dunlap
> <george.dunlap@citrix.com>; Julien Grall <julien@xen.org>; Stefano Stabellini
> <sstabellini@kernel.org>; Wei Liu <wl@xen.org>; xen-
> devel@lists.xenproject.org
> Subject: Re: [PATCH v1 4/5] xen/arm: retrieve reserved pages on
> populate_physmap
> 
> On 30.03.2022 11:36, Penny Zheng wrote:
> > --- a/xen/common/memory.c
> > +++ b/xen/common/memory.c
> > @@ -249,6 +249,26 @@ static void populate_physmap(struct memop_args
> *a)
> >
> >                  mfn = _mfn(gpfn);
> >              }
> > +#ifdef CONFIG_STATIC_MEMORY
> > +            else if ( is_domain_on_static_allocation(d) )
> > +            {
> > +                for ( j = 0; j < (1U << a->extent_order); j++ )
> > +                {
> > +                    page = page_list_remove_head(&d->resv_page_list);
> 
> How do you guarantee the pages are contiguous, as required by a non-zero
> a->extent_order? Did you perhaps mean to forbid non-zero-order requests
> in this configuration?,

True, true, thanks for pointing that out.
I would not intend to add complex algorithm here to find contiguous pages of requested
order, forbidding non-zero-order with error message shall be added here.

> 
> > +                    if ( unlikely(!page) )
> > +                    {
> > +                        gdprintk(XENLOG_INFO,
> > +                                 "Could not allocate guest page number %lx\n",
> > +                                 gfn_x(_gfn(gpfn)));
> > +                        goto out;
> 
> And earlier allocated pages are simply lost / leaked?
> 

That was unconsidered, thanks for pointing that out.
Since now we are forbidding non-zero-order requests, earlier allocated pages shall
not need to be considered.
 
> Jan
diff mbox series

Patch

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 2afc3c6f10..2122ceeba7 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -249,6 +249,26 @@  static void populate_physmap(struct memop_args *a)
 
                 mfn = _mfn(gpfn);
             }
+#ifdef CONFIG_STATIC_MEMORY
+            else if ( is_domain_on_static_allocation(d) )
+            {
+                for ( j = 0; j < (1U << a->extent_order); j++ )
+                {
+                    page = page_list_remove_head(&d->resv_page_list);
+                    if ( unlikely(!page) )
+                    {
+                        gdprintk(XENLOG_INFO,
+                                 "Could not allocate guest page number %lx\n",
+                                 gfn_x(_gfn(gpfn)));
+                        goto out;
+                    }
+                    d->resv_pages--;
+
+                    if ( j == 0 )
+                        mfn = page_to_mfn(page);
+                }
+            }
+#endif
             else
             {
                 page = alloc_domheap_pages(d, a->extent_order, a->memflags);