[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH v6 2/9] xen: do not free reserved memory into heap


  • To: Julien Grall <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Thu, 9 Jun 2022 05:54:37 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lV76d8EifUYxX2ogEEWUwF2kTd7ZXe4L5KM7qJxoibw=; b=I3BxS2AqVGutKY+r8T/Ln/Z7BAEJE1K1KwdpYpeopI9bGEzeVB+BRfJPF9Zr+cN0Lfog4T4EKyerh0YSUfULM4aZ6ivM250VSATnk3zMGZ8gFltOOGmgOZQL8q5ybSU8hSM0Av2lDfYKwduHj/gVoQaKCJ2gkUF/TX2kljEAdW02a2VjnEnC2PHg59gdS6fdP4ivv+Z8x941b+TNtBoSOqAPy+WpoV6hiRMoh+gNUVGMOWZ1tcHfIxW32BlbARMLV60vDDH/Qpd5pKS/gsy0/glLLpcZOPLWK6MINM6ZW5bAqbutKYp/xdeNRxUSkmCUya7a6i/Cs+xjcxMK1MDP0w==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lV76d8EifUYxX2ogEEWUwF2kTd7ZXe4L5KM7qJxoibw=; b=jOS7ZorqVuEAh6Z9App1mNSvdULOQYhXrh8U/enIk2rtBIhnzbJotjfHJCumJ/PQ7VyfYNjLC++GbKM7AdT6enkSPGlJmpkzYGlzGCmTSkZu+vzXTpsuTovnaJyEXSGuslq7Pa2q1fyluZScQImqQQ92Uoo2puPCFkQd83SxDfpdZoRZbl3wlbkH3sldtaokt17Yb2Af+zcj7b3N2yiixh6+Zhoq1lFZHENwMqgpVr+Uygbk5mrOhgsFxrQgb9Ab0pe73IWrt+qc3vPobM4Yu2U6+sqLYSMC6aqkDtrO4tSQOUF5J2loRmCEttunfmz5xAdTaoyEWF6HblUYZp4RPQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=SY5TqLtmwUvYWigfWcadzuF6AUCyWTM+luL3WVGkHmNQyrzfHl7PQc1B7paRjhc1cxvgPYiUbQqyUzX3XSeyZ8ODHBdJoXGybtgboLH1b0DTFJOwQGjdLkyUC3uTSfsDCoNZhXQvLrvKlY5kbFRBwmbOeTc7iQvdVY3+4nuclR6ByYceTE78UjQTf1xYLwP9RrsaYrKGQIq6043UApua5I+icBZFTCcW2UhlDEU1nD9RVe81GjxjvtL8+Zn0/fUbqumcDgFpaOye9q4WEmXtdylEMlgOPe75jTkiVohXgiagmhwp7Vf9lOB8MhDZ4adoJY6hPAjFC1eCCUKy+3sJeQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZQVDpeEG0RZq3jLqqJxDohcWuR/vOvvEH2AzhHRuvstW+WgpQ3m0HI0L9SqWtbhroFGTIcnZS6MX4kvm+9QdyxkKv9tCNrXaf6WCtkqRtBwQbzzeh67MoftUGMUZZ7ObtpQ9xBJqusbqFg005CZfiDmu+G2zIC7Q8TZOZ8x93KXkpGcPJLN0wMKKtHnMQhVkwg8iGEhxdyX36ID9rglFXNelzbQ49m7+9CyDhU8RHoi3uZFPJNlg6gftgaKo6RpypW4txewd1FKV/lKJvH5zrny6vcx6Gn0HSsn30C/YS5la0Rtpp/778VIkSHUsOWf7CgpOsKnuGxwz73rx41rf8g==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Wei Chen <Wei.Chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 09 Jun 2022 05:55:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYekCLapi6TfhNLECKo4lt4smsBq1DqSgAgALDbhA=
  • Thread-topic: [PATCH v6 2/9] xen: do not free reserved memory into heap


> -----Original Message-----
> From: Julien Grall <julien@xxxxxxx>
> Sent: Tuesday, June 7, 2022 5:13 PM
> To: Penny Zheng <Penny.Zheng@xxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Wei Chen <Wei.Chen@xxxxxxx>; Stefano Stabellini
> <sstabellini@xxxxxxxxxx>; Bertrand Marquis <Bertrand.Marquis@xxxxxxx>;
> Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>; Andrew Cooper
> <andrew.cooper3@xxxxxxxxxx>; George Dunlap <george.dunlap@xxxxxxxxxx>;
> Jan Beulich <jbeulich@xxxxxxxx>; Wei Liu <wl@xxxxxxx>
> Subject: Re: [PATCH v6 2/9] xen: do not free reserved memory into heap
> 
> Hi Penny,
> 

Hi Julien

> On 07/06/2022 08:30, Penny Zheng wrote:
> > Pages used as guest RAM for static domain, shall be reserved to this
> > domain only.
> > So in case reserved pages being used for other purpose, users shall
> > not free them back to heap, even when last ref gets dropped.
> >
> > free_staticmem_pages will be called by free_heap_pages in runtime for
> > static domain freeing memory resource, so let's drop the __init flag.
> >
> > Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
> > ---
> > v6 changes:
> > - adapt to PGC_static
> > - remove #ifdef aroud function declaration
> > ---
> > v5 changes:
> > - In order to avoid stub functions, we #define PGC_staticmem to
> > non-zero only when CONFIG_STATIC_MEMORY
> > - use "unlikely()" around pg->count_info & PGC_staticmem
> > - remove pointless "if", since mark_page_free() is going to set
> > count_info to PGC_state_free and by consequence clear PGC_staticmem
> > - move #define PGC_staticmem 0 to mm.h
> > ---
> > v4 changes:
> > - no changes
> > ---
> > v3 changes:
> > - fix possible racy issue in free_staticmem_pages()
> > - introduce a stub free_staticmem_pages() for the
> > !CONFIG_STATIC_MEMORY case
> > - move the change to free_heap_pages() to cover other potential call
> > sites
> > - fix the indentation
> > ---
> > v2 changes:
> > - new commit
> > ---
> >   xen/arch/arm/include/asm/mm.h |  4 +++-
> >   xen/common/page_alloc.c       | 12 +++++++++---
> >   xen/include/xen/mm.h          |  2 --
> >   3 files changed, 12 insertions(+), 6 deletions(-)
> >
> > diff --git a/xen/arch/arm/include/asm/mm.h
> > b/xen/arch/arm/include/asm/mm.h index fbff11c468..7442893e77 100644
> > --- a/xen/arch/arm/include/asm/mm.h
> > +++ b/xen/arch/arm/include/asm/mm.h
> > @@ -108,9 +108,11 @@ struct page_info
> >     /* Page is Xen heap? */
> >   #define _PGC_xen_heap     PG_shift(2)
> >   #define PGC_xen_heap      PG_mask(1, 2)
> > -  /* Page is static memory */
> 
> NITpicking: You added this comment in patch #1 and now removing the space.
> Any reason to drop the space?
> 
> > +#ifdef CONFIG_STATIC_MEMORY
> 
> I think this change ought to be explained in the commit message. AFAIU, this 
> is
> necessary to allow the compiler to remove code and avoid linking issues. Is
> that correct?
> 
> > +/* Page is static memory */
> >   #define _PGC_static    PG_shift(3)
> >   #define PGC_static     PG_mask(1, 3)
> > +#endif
> >   /* ... */
> >   /* Page is broken? */
> >   #define _PGC_broken       PG_shift(7)
> > diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index
> > 9e5c757847..6876869fa6 100644
> > --- a/xen/common/page_alloc.c
> > +++ b/xen/common/page_alloc.c
> > @@ -1443,6 +1443,13 @@ static void free_heap_pages(
> >
> >       ASSERT(order <= MAX_ORDER);
> >
> > +    if ( unlikely(pg->count_info & PGC_static) )
> > +    {
> > +        /* Pages of static memory shall not go back to the heap. */
> > +        free_staticmem_pages(pg, 1UL << order, need_scrub);
> I can't remember whether I asked this before (I couldn't find a thread).
> 
> free_staticmem_pages() doesn't seem to be protected by any lock. So how do
> you prevent the concurrent access to the page info with the acquire part?

True, last time you suggested that rsv_page_list needs to be protected with a
spinlock (mostly like d->page_alloc_lock). I haven't thought it thoroughly, 
sorry
about that.
So for freeing part, I shall get the lock at arch_free_heap_page(), where we 
insert
the page to the rsv_page_list, and release the lock at the end of the 
free_staticmem_page.
And for acquiring part, I've already put the lock around 
page = page_list_remove_head(&d->resv_page_list);

> Cheers,
> 
> --
> Julien Grall

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.