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

[PATCH v3 6/6] xen: retrieve reserved pages on populate_physmap


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Wed, 27 Apr 2022 17:27:43 +0800
  • 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] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); 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=nqcTO4An0BbV9XfJHUHLhj5Zal3nPygOYB8CUZJHxi4=; b=jIRWwNoqH63Jm5Ju9lr39dEPu1WB4gYILPphBCrzKJXIvMDlVbv2K7rHjARfbMQs/hFp36hYxbBKZu25x/wWRGshnyb6y/4naQIdiVw6eZwpRb5Q/qo98d2MIKSkwLTKnIEeSyfwNMMa5s9UKvoSR1jGA9UonP7TEa/6SzhZj9myrvng+9yWDdsIUbH1HVPeEf5f8ewsaNrYxxav6Ub5U2lBUX76SN9QlCmGGyoyt2Lc1fgN1FYy49LsabucmL6zjAF47NbkzI3BG0N4id4RGYqWtMmjUkRNcAFvEoIkwm4xIGYHJkjsRj5Bdt9OrEGcRBP8F1Kg3/hVZ155Pw/CZw==
  • 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=nqcTO4An0BbV9XfJHUHLhj5Zal3nPygOYB8CUZJHxi4=; b=U1eEY0dqSIK+Ysny16f3TO96ijWbwrS1A/NYGj6Dp9jQNLQCr2LfiRVp2Dxob/3WtcjU/bZ67D+N708WyvxOcfC0zeVCXMjGTKbkUfhHIcD6EoQYfA35RgAFHMj+LVDVyPUo/oiNdEF8gD0Fibtd0fxopNXJmQQP20m/dB5b+W52mLsaqkKM4BLW+Jqyet1gzP9G9vQuRNy2hgysgFViDvfiTEkkESmHcHygWfBJ8tynGl4LLyPoQvmPuzzJZOni/LFAVWfIpHCdBvSRo3kApZM8cQ3CYZ/8K7nK2breLxKFjZjN1wE+oK3ESoweMU4Q0xY3Dtr1Xs5N/DrchT+CAQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=lx3muvo1NlYjIRnnCg1kt3OFOpKsUqq0PYoEogUasjlIPigg1ZmUPEWmGE8MPto+mhdGkXhvUEMqgN2DIsuUw3SITjghayxLbPY1iRZ615rwJoVHKZT0ECKEodfPDYpvPyqNBg+STctti5BCCHWS3OE2t+vMvWWt7Tprwt0RSjfFvD4xt871CdAdYpaNlWa/7UuvMcccvfSYnj7WXzNPocpdlQ+ki6PLkDgxLjz1kANfJpC+40TY8ma1mt7R/aLjd7E9/NzIh1KLSIT3qCKYYDVd1eCPs9olwbKrKRqNcDPbq413PVsT9RXJRbkJao8mEJmccJ62vmWgWVcogrYvuQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NHWeu1xM4N6IL9tfKciKbagCXC/TR8susY2uFAgeyrPFuoSt7c3VJ9FOu55myfqqrC3yd0FpMAX2uIOgIpc/lWh2Cszj5KyAd+gX5LylJUr59KeY0Qrx1kgpB0j13h9i1kOLCHUXZex7yuP5yWCMfFGx8RP7feakMJQ3gBHDSH9+DqywR9HAOODAv5VwPqc0PDx1xLwRI91+Yq8eo3EvXRs5DO9czhMWnWagEDUbpYiZ7L48ViH1IPeY4pXkfCU5oKvNeohT81SFx67G0dfsjzLeAmlEeiR7H8mbXHxhvFeuZmQBi6v2d9vGuxM9X+cFzwO/1ybJF1eAHXShsL6/fg==
  • Cc: <wei.chen@xxxxxxx>, <henry.wang@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, "George Dunlap" <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>
  • Delivery-date: Wed, 27 Apr 2022 09:29:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

When static domain populates memory through populate_physmap on runtime,
other than allocating from heap, it shall retrieve reserved pages from
resv_page_list to make sure that guest RAM is still restricted in statically
configured memory regions. And this commit introduces a new helper
acquire_reserved_page to make it work.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
v3 changes
- move #ifndef is_domain_using_staticmem to the common header file
- remove #ifdef CONFIG_STATIC_MEMORY-ary
- remove meaningless page_to_mfn(page) in error log
---
v2 changes:
- introduce acquire_reserved_page to retrieve reserved pages from
resv_page_list
- forbid non-zero-order requests in populate_physmap
- let is_domain_static return ((void)(d), false) on x86
---
 xen/common/memory.c      | 23 +++++++++++++++++++++++
 xen/common/page_alloc.c  | 38 ++++++++++++++++++++++++++++++++++++++
 xen/include/xen/domain.h |  4 ++++
 xen/include/xen/mm.h     |  3 +--
 4 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index 69b0cd1e50..6cee51f0e3 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -245,6 +245,29 @@ static void populate_physmap(struct memop_args *a)
 
                 mfn = _mfn(gpfn);
             }
+            else if ( is_domain_using_staticmem(d) )
+            {
+                /*
+                 * No easy way to guarantee the retreived pages are contiguous,
+                 * so forbid non-zero-order requests here.
+                 */
+                if ( a->extent_order != 0 )
+                {
+                    gdprintk(XENLOG_INFO,
+                             "Could not allocate non-zero-order pages for 
static %pd.\n.",
+                             d);
+                    goto out;
+                }
+
+                mfn = acquire_reserved_page(d, a->memflags);
+                if ( mfn_eq(mfn, INVALID_MFN) )
+                {
+                    gdprintk(XENLOG_INFO,
+                             "%pd: failed to retrieve a reserved page.\n.",
+                             d);
+                    goto out;
+                }
+            }
             else
             {
                 page = alloc_domheap_pages(d, a->extent_order, a->memflags);
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 1f3ad4bd28..78cc52986c 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -2769,12 +2769,50 @@ int __init acquire_domstatic_pages(struct domain *d, 
mfn_t smfn,
 
     return 0;
 }
+
+/*
+ * Acquire a page from reserved page list(resv_page_list), when populating
+ * memory for static domain on runtime.
+ */
+mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags)
+{
+    struct page_info *page;
+    mfn_t smfn;
+
+    /* Acquire a page from reserved page list(resv_page_list). */
+    page = page_list_remove_head(&d->resv_page_list);
+    if ( unlikely(!page) )
+    {
+        printk(XENLOG_ERR
+               "%pd: failed to acquire a reserved page from resv_page_list.\n",
+               d);
+        return INVALID_MFN;
+    }
+
+    smfn = page_to_mfn(page);
+
+    if ( acquire_domstatic_pages(d, smfn, 1, memflags) )
+        return INVALID_MFN;
+
+    return smfn;
+}
 #else
 void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
                           bool need_scrub)
 {
     ASSERT_UNREACHABLE();
 }
+
+int __init acquire_domstatic_pages(struct domain *d, mfn_t smfn,
+                                   unsigned int nr_mfns, unsigned int memflags)
+{
+    ASSERT_UNREACHABLE();
+}
+
+mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags)
+{
+    ASSERT_UNREACHABLE();
+}
 #endif
 
 /*
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index 35dc7143a4..c613afa57e 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -38,6 +38,10 @@ void arch_get_domain_info(const struct domain *d,
 #define CDF_staticmem            (1U << 2)
 #endif
 
+#ifndef is_domain_using_staticmem
+#define is_domain_using_staticmem(d) ((void)(d), false)
+#endif
+
 /*
  * Arch-specifics.
  */
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 9fd95deaec..32b0837fa0 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -88,10 +88,9 @@ bool scrub_free_pages(void);
 /* These functions are for static memory */
 void free_staticmem_pages(struct page_info *pg, unsigned long nr_mfns,
                           bool need_scrub);
-#ifdef CONFIG_STATIC_MEMORY
 int acquire_domstatic_pages(struct domain *d, mfn_t smfn, unsigned int nr_mfns,
                             unsigned int memflags);
-#endif
+mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags);
 
 /* Map machine page range in Xen virtual address space. */
 int map_pages_to_xen(
-- 
2.25.1




 


Rackspace

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