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

RE: [PATCH v7 7/9] xen/arm: unpopulate memory when domain is static


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Mon, 27 Jun 2022 10:03:14 +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=EMFCQLaap/xgdts+uNUPkcoHzsu6uULHjfoESVJScLo=; b=A/VwiT+6GgbaCt8w71y4AXoHaN0buZBLui+OAQphr1FmPgngAQML7Tq1CWB0TCGjoaK2lsEn9lFJpOQDOn72rFQXU9kDL+4LjdzyGOSVJ2vkmKQf41SYHUOR+ipsiKiSfop6aXlwey/meGlLFAsWt5avVVy+SHV7T7UxDwEqqkiZR3u0lH7sXqqjLnxc9wD7G8S+2D0KSe8F/ESJs3wscnfUKS7VupLvkWDf0enmj/FcxNxPKymORN+xMocymJc+w22GSrSVmuVTZM8dR81GM+ekgZNEcBuYOZRxaLumarILGaubd2FUWKPbNEA09+F1nf0uLEy6wR3TBV9AmeDPbA==
  • 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=EMFCQLaap/xgdts+uNUPkcoHzsu6uULHjfoESVJScLo=; b=MfSIWNOkA/Z95IeYBf8cgV+P2oDsCD+PxZSVrKDCxlP42mMY3bsBvDFyk1xl2yde27Zx/FOcP/eAUH7RvrTEFYrRMJ3pvM2ZlQQiAfg9I+/Dmt/xCbFjK9WKkS4bBfBIZQRuGplxBmezD2U7V212jytGzigsEQprLvpfUvRaGLY4U+aYS3DddhoZzHNm/Yt6AtmZwCNxmzNS8AFCp09JYtDfAFMN85iTq3qep/ZQdKuXfOV0u5G8zFaq09YKhJUycSWtrD2SfdBuBokkqBW5/jh4VxL5P5mLXqlA7IZNc+E6USH6vnboeP+2xOCEKaesDDZ5QkIOgx+70G5ApKf3ZQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=XEhR42riBUexEutGUilceK7kL8yI1U3qOBbbVEhgoQqeC1YNQXwORez0GOyuxfv01/5An3eu8JpPr6sxcehi28/B22iRyps8wZ+pacVXU+S0objIudl+1N3HaWIVtVUxuIt6OsEJyEcsKiJ9rU5dHvrp06V2vBtQUwmP354LhrAMqvKH4fvyCE3ydV9cE/LaGwtXZjL5YTNveG4uKPD+7vXA0OhuMVfUMVHpAIDLNag50QcIDSaQClyUv5urmMMIpSehOrO8VZd+qHFvvp2M/zDu/Wp/Re2rTerGiJr5X4UEYqoIrMgm1ne8v4kl66HHdMp3gB1HFh3BZY52npgOmg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XZEBIqxpd3UXRIu15tn7rlGEwf1Q/9P+9U/0XrOtl1dBc6uvZjgwjfMoNWFcVSpEZ+sh7U2ajdHhn6Q5axyhECsapLqwXGPPLKX2kM5S9SoQ97lXKEybFw+KrYZmRvHWuRMKIWYrPIsRWmqw8ovxEBwN0ygLp7sUPQiJwQ21pvS1oIOqldJySsOX84HTrsnWAe4w7QRziqGDMjg4nMF/lS6poh3Shb6sF5f6ZC4KOQugxXsWmrD5SLChrRO9pP4iac0FsCFgCIjtpc5JF89iBeTgbfJdwOU78IWD4hwMChg9WaUCCEXUsz0UN3SHUFUdQBZFpW5UgR+vqobbYuqMSA==
  • 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>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 27 Jun 2022 10:03:33 +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: AQHYhE/FRuoXPvvK9EWAAAtCUPIrtq1bKxqAgAfcEEA=
  • Thread-topic: [PATCH v7 7/9] xen/arm: unpopulate memory when domain is static

Hi jan

> -----Original Message-----
> From: Jan Beulich <jbeulich@xxxxxxxx>
> Sent: Wednesday, June 22, 2022 5:24 PM
> To: Penny Zheng <Penny.Zheng@xxxxxxx>
> Cc: Wei Chen <Wei.Chen@xxxxxxx>; Andrew Cooper
> <andrew.cooper3@xxxxxxxxxx>; George Dunlap <george.dunlap@xxxxxxxxxx>;
> Julien Grall <julien@xxxxxxx>; Stefano Stabellini <sstabellini@xxxxxxxxxx>;
> Wei Liu <wl@xxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx
> Subject: Re: [PATCH v7 7/9] xen/arm: unpopulate memory when domain is
> static
> 
> On 20.06.2022 04:44, Penny Zheng wrote:
> > --- a/xen/common/page_alloc.c
> > +++ b/xen/common/page_alloc.c
> > @@ -2498,6 +2498,10 @@ void free_domheap_pages(struct page_info *pg,
> unsigned int order)
> >          }
> >
> >          free_heap_pages(pg, order, scrub);
> > +
> > +        /* Add page on the resv_page_list *after* it has been freed. */
> > +        if ( unlikely(pg->count_info & PGC_static) )
> > +            put_static_pages(d, pg, order);
> 
> Unless I'm overlooking something the list addition done there / ...
> 
> > --- a/xen/include/xen/mm.h
> > +++ b/xen/include/xen/mm.h
> > @@ -90,6 +90,15 @@ void free_staticmem_pages(struct page_info *pg,
> unsigned long nr_mfns,
> >                            bool need_scrub);  int
> > acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int
> nr_mfns,
> >                              unsigned int memflags);
> > +#ifdef CONFIG_STATIC_MEMORY
> > +#define put_static_pages(d, page, order) ({                 \
> > +    unsigned int i;                                         \
> > +    for ( i = 0; i < (1 << (order)); i++ )                  \
> > +        page_list_add_tail((pg) + i, &(d)->resv_page_list); \
> > +})
> 
> ... here isn't guarded by any lock. Feels like we've been there before.
> It's not really clear to me why the freeing of staticmem pages needs to be
> split like this - if it wasn't split, the list addition would "naturally" 
> occur with
> the lock held, I think.

Reminded by you and Julien, I need to add a lock for 
operations(free/allocation) on
resv_page_list, I'll guard the put_static_pages with d->page_alloc_lock. And 
bring
back the lock in acquire_reserved_page.

put_static_pages, that is, adding pages to the reserved list, is only for 
freeing static
pages on runtime. In static page initialization stage, I also use 
free_statimem_pages,
and in which stage, I think the domain has not been constructed at all. So I 
prefer
the freeing of staticmem pages is split into two parts: free_staticmem_pages and
put_static_pages 

> 
> Furthermore careful with the local variable name used here. Consider what
> would happen with an invocation of
> 
>     put_static_pages(d, page, i);
> 
> To common approach is to suffix an underscore to the variable name.
> Such names are not supposed to be used outside of macros definitions, and
> hence there's then no potential for such a conflict.
> 

Understood!! I will change "unsigned int i" to "unsigned int _i";

> Finally I think you mean (1u << (order)) to be on the safe side against UB if
> order could ever reach 31. Then again - is "order" as a parameter needed
> here in the first place? Wasn't it that staticmem operations are limited to
> order-0 regions?

Yes, right now, the actual usage is limited to order-0, how about I add 
assertion here
and remove order parameter:

        /* Add page on the resv_page_list *after* it has been freed. */
        if ( unlikely(pg->count_info & PGC_static) )
        {
            ASSERT(!order);
            put_static_pages(d, pg);
        }

> Jan

 


Rackspace

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