From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Chao Peng <chao.p.peng@linux.intel.com>,
Dan Williams <dan.j.williams@intel.com>
Subject: [RFC XEN PATCH v4 14/41] x86_64/mm: allow customized location of extended frametable and M2P table
Date: Thu, 7 Dec 2017 18:10:03 +0800 [thread overview]
Message-ID: <20171207101030.22364-15-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20171207101030.22364-1-haozhong.zhang@intel.com>
As the existing data in PMEM region is persistent, Xen hypervisor has
no knowledge of which part is free to be used for the frame table and
M2P table of that PMEM region. Instead, we will allow users or system
admins to specify the location of those frame table and M2P table.
The location is not necessarily at the beginning of the PMEM region,
which is different from the case of hotplugged RAM.
This commit adds the support for a customized page allocation
function, which is used to allocate the memory for the frame table and
M2P table. No page free function is added, and we require that all
allocated pages can be reclaimed or has no effect out of
memory_add_common(), if memory_add_common() fails.
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
xen/arch/x86/x86_64/mm.c | 83 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 69 insertions(+), 14 deletions(-)
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 90341267d9..36dcb3f1cb 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -106,13 +106,44 @@ struct mem_hotadd_info
unsigned long cur;
};
+struct mem_hotadd_alloc
+{
+ /*
+ * Allocate 2^PAGETABLE_ORDER pages.
+ *
+ * No free function is added right now, so we require that all
+ * allocated pages can be reclaimed easily or has no effect out of
+ * memory_add_common(), if memory_add_common() fails.
+ *
+ * For example, alloc_hotadd_mfn(), which is used in RAM hotplug,
+ * allocates pages from the hotplugged RAM. If memory_add_common()
+ * fails, the hotplugged RAM will not be available to Xen, so
+ * pages allocated by alloc_hotadd_mfns() will never be used and
+ * have no effect.
+ *
+ * Parameters:
+ * opaque: arguments of the allocator (depending on the implementation)
+ *
+ * Return:
+ * On success, return MFN of the first page.
+ * Otherwise, return mfn_x(INVALID_MFN).
+ */
+ unsigned long (*alloc_mfns)(void *opaque);
+
+ /*
+ * Additional arguments passed to @alloc_mfns().
+ */
+ void *opaque;
+};
+
static int hotadd_mem_valid(unsigned long pfn, struct mem_hotadd_info *info)
{
return (pfn < info->epfn && pfn >= info->spfn);
}
-static unsigned long alloc_hotadd_mfn(struct mem_hotadd_info *info)
+static unsigned long alloc_hotadd_mfn(void *opaque)
{
+ struct mem_hotadd_info *info = opaque;
unsigned mfn;
ASSERT((info->cur + ( 1UL << PAGETABLE_ORDER) < info->epfn) &&
@@ -315,7 +346,8 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info)
* spfn/epfn: the pfn ranges to be setup
* free_s/free_e: the pfn ranges that is free still
*/
-static int setup_compat_m2p_table(struct mem_hotadd_info *info)
+static int setup_compat_m2p_table(struct mem_hotadd_info *info,
+ struct mem_hotadd_alloc *alloc)
{
unsigned long i, va, smap, emap, rwva, epfn = info->epfn, mfn;
unsigned int n;
@@ -369,7 +401,13 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info)
if ( n == CNT )
continue;
- mfn = alloc_hotadd_mfn(info);
+ mfn = alloc->alloc_mfns(alloc->opaque);
+ if ( mfn == mfn_x(INVALID_MFN) )
+ {
+ err = -ENOMEM;
+ break;
+ }
+
err = map_pages_to_xen(rwva, mfn, 1UL << PAGETABLE_ORDER,
PAGE_HYPERVISOR);
if ( err )
@@ -389,7 +427,8 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info)
* Allocate and map the machine-to-phys table.
* The L3 for RO/RWRW MPT and the L2 for compatible MPT should be setup already
*/
-static int setup_m2p_table(struct mem_hotadd_info *info)
+static int setup_m2p_table(struct mem_hotadd_info *info,
+ struct mem_hotadd_alloc *alloc)
{
unsigned long i, va, smap, emap;
unsigned int n;
@@ -438,7 +477,13 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
break;
if ( n < CNT )
{
- unsigned long mfn = alloc_hotadd_mfn(info);
+ unsigned long mfn = alloc->alloc_mfns(alloc->opaque);
+
+ if ( mfn == mfn_x(INVALID_MFN) )
+ {
+ ret = -ENOMEM;
+ goto error;
+ }
ret = map_pages_to_xen(
RDWR_MPT_VIRT_START + i * sizeof(unsigned long),
@@ -483,7 +528,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
#undef CNT
#undef MFN
- ret = setup_compat_m2p_table(info);
+ ret = setup_compat_m2p_table(info, alloc);
error:
return ret;
}
@@ -762,7 +807,7 @@ static void cleanup_frame_table(unsigned long spfn, unsigned long epfn)
}
static int setup_frametable_chunk(void *start, void *end,
- struct mem_hotadd_info *info)
+ struct mem_hotadd_alloc *alloc)
{
unsigned long s = (unsigned long)start;
unsigned long e = (unsigned long)end;
@@ -774,7 +819,13 @@ static int setup_frametable_chunk(void *start, void *end,
for ( cur = s; cur < e; cur += (1UL << L2_PAGETABLE_SHIFT) )
{
- mfn = alloc_hotadd_mfn(info);
+ mfn = alloc->alloc_mfns(alloc->opaque);
+ if ( mfn == mfn_x(INVALID_MFN) )
+ {
+ err = -ENOMEM;
+ break;
+ }
+
err = map_pages_to_xen(cur, mfn, 1UL << PAGETABLE_ORDER,
PAGE_HYPERVISOR);
if ( err )
@@ -789,7 +840,8 @@ static int setup_frametable_chunk(void *start, void *end,
return err;
}
-static int extend_frame_table(struct mem_hotadd_info *info)
+static int extend_frame_table(struct mem_hotadd_info *info,
+ struct mem_hotadd_alloc *alloc)
{
unsigned long cidx, nidx, eidx, spfn, epfn;
int err = 0;
@@ -816,7 +868,7 @@ static int extend_frame_table(struct mem_hotadd_info *info)
nidx = eidx;
err = setup_frametable_chunk(pdx_to_page(cidx * PDX_GROUP_COUNT ),
pdx_to_page(nidx * PDX_GROUP_COUNT),
- info);
+ alloc);
if ( err )
break;
@@ -1338,7 +1390,8 @@ static int mem_hotadd_check(unsigned long spfn, unsigned long epfn)
}
static int memory_add_common(struct mem_hotadd_info *info,
- unsigned int pxm, bool direct_map)
+ unsigned int pxm, bool direct_map,
+ struct mem_hotadd_alloc *alloc)
{
unsigned long spfn = info->spfn, epfn = info->epfn;
int ret;
@@ -1402,7 +1455,7 @@ static int memory_add_common(struct mem_hotadd_info *info,
NODE_DATA(node)->node_spanned_pages = epfn - node_start_pfn(node);
}
- ret = extend_frame_table(info);
+ ret = extend_frame_table(info, alloc);
if ( ret )
goto restore_node_status;
@@ -1415,7 +1468,7 @@ static int memory_add_common(struct mem_hotadd_info *info,
total_pages += epfn - spfn;
set_pdx_range(spfn, epfn);
- ret = setup_m2p_table(info);
+ ret = setup_m2p_table(info, alloc);
if ( ret )
goto destroy_m2p;
@@ -1465,11 +1518,13 @@ destroy_directmap:
int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
{
struct mem_hotadd_info info = { .spfn = spfn, .epfn = epfn, .cur = spfn };
+ struct mem_hotadd_alloc alloc =
+ { .alloc_mfns = alloc_hotadd_mfn, .opaque = &info };
int ret;
dprintk(XENLOG_INFO, "memory_add %lx ~ %lx with pxm %x\n", spfn, epfn, pxm);
- ret = memory_add_common(&info, pxm, true);
+ ret = memory_add_common(&info, pxm, true, &alloc);
if ( !ret )
{
/* We can't revert any more */
--
2.15.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2017-12-07 10:10 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 10:09 [RFC XEN PATCH v4 00/41] Add vNVDIMM support to HVM domains Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 01/41] x86_64/mm: fix the PDX group check in mem_hotadd_check() Haozhong Zhang
2018-01-04 6:12 ` Chao Peng
2018-05-07 15:59 ` Jan Beulich
2017-12-07 10:09 ` [RFC XEN PATCH v4 02/41] x86_64/mm: avoid cleaning the unmapped frame table Haozhong Zhang
2018-01-04 6:20 ` Chao Peng
2017-12-07 10:09 ` [RFC XEN PATCH v4 03/41] hvmloader/util: do not compare characters after '\0' in strncmp Haozhong Zhang
2018-01-04 6:23 ` Chao Peng
2017-12-07 10:09 ` [RFC XEN PATCH v4 04/41] xen/common: add Kconfig item for pmem support Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 05/41] x86/mm: exclude PMEM regions from initial frametable Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 06/41] acpi: probe valid PMEM regions via NFIT Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 07/41] xen/pmem: register valid PMEM regions to Xen hypervisor Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 08/41] xen/pmem: hide NFIT and deny access to PMEM from Dom0 Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 09/41] xen/pmem: add framework for hypercall XEN_SYSCTL_nvdimm_op Haozhong Zhang
2017-12-07 10:09 ` [RFC XEN PATCH v4 10/41] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_get_rgions_nr Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 11/41] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_get_regions Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 12/41] tools/xl: add xl command 'pmem-list' Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 13/41] x86_64/mm: refactor memory_add() Haozhong Zhang
2017-12-07 10:10 ` Haozhong Zhang [this message]
2017-12-07 10:10 ` [RFC XEN PATCH v4 15/41] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_setup to setup management PMEM region Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 16/41] tools/xl: accept all bases in parse_ulong() Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 17/41] tools/xl: expose parse_ulong() Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 18/41] tools/xl: add xl command 'pmem-setup' Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 19/41] xen/pmem: support PMEM_REGION_TYPE_MGMT for XEN_SYSCTL_nvdimm_pmem_get_regions_nr Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 20/41] xen/pmem: support PMEM_REGION_TYPE_MGMT for XEN_SYSCTL_nvdimm_pmem_get_regions Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 21/41] tools/xl: add option '--mgmt | -m' to xl command pmem-list Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 22/41] xen/pmem: support setup PMEM region for guest data usage Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 23/41] tools/xl: add option '--data | -d' to xl command pmem-setup Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 24/41] xen/pmem: support PMEM_REGION_TYPE_DATA for XEN_SYSCTL_nvdimm_pmem_get_regions_nr Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 25/41] xen/pmem: support PMEM_REGION_TYPE_DATA for XEN_SYSCTL_nvdimm_pmem_get_regions Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 26/41] tools/xl: add option '--data | -d' to xl command pmem-list Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 27/41] xen/pmem: add function to map PMEM pages to HVM domain Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 28/41] xen/pmem: release PMEM pages on HVM domain destruction Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 29/41] xen: add hypercall XENMEM_populate_pmem_map Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 30/41] tools: reserve extra guest memory for ACPI from device model Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 31/41] tools/libacpi: add callback to translate GPA to GVA Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 32/41] tools/libacpi: build a DM ACPI signature blacklist Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 33/41] tools/libacpi, hvmloader: detect QEMU fw_cfg interface Haozhong Zhang
2018-02-27 17:37 ` Anthony PERARD
2018-02-28 9:17 ` Haozhong Zhang
2018-03-02 11:26 ` Anthony PERARD
2018-03-05 7:55 ` Haozhong Zhang
2018-02-27 18:03 ` Anthony PERARD
2018-02-28 8:18 ` Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 34/41] tools/libacpi: probe QEMU ACPI ROMs via " Haozhong Zhang
2018-02-27 17:56 ` Anthony PERARD
2018-02-28 9:28 ` Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 35/41] tools/libacpi: add a QEMU BIOSLinkLoader executor Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 36/41] tools/libacpi: add function to get the data of QEMU RSDP Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 37/41] tools/libacpi: load QEMU ACPI Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 38/41] tools/xl: add xl domain configuration for virtual NVDIMM devices Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 39/41] tools/libxl: allow aborting domain creation on fatal QMP init errors Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 40/41] tools/libxl: initiate PMEM mapping via QMP callback Haozhong Zhang
2017-12-07 10:10 ` [RFC XEN PATCH v4 41/41] tools/libxl: build qemu options from xl vNVDIMM configs Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 00/10] Implement vNVDIMM for Xen HVM guest Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 01/10] xen-hvm: remove a trailing space Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 02/10] xen-hvm: create the hotplug memory region on Xen Haozhong Zhang
2018-02-27 16:37 ` Anthony PERARD
2018-02-28 7:47 ` Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 03/10] hostmem-xen: add a host memory backend for Xen Haozhong Zhang
2018-02-27 16:41 ` Anthony PERARD
2018-02-28 7:56 ` Haozhong Zhang
[not found] ` <20180228075654.gv22h2zd73peuyxm@hz-desktop>
2018-03-02 11:50 ` Anthony PERARD
2018-03-05 7:53 ` [Qemu-devel] " Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 04/10] nvdimm: do not intiailize nvdimm->label_data if label size is zero Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 05/10] xen-hvm: initialize fw_cfg interface Haozhong Zhang
2018-02-27 16:46 ` Anthony PERARD
2018-02-28 8:16 ` Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 06/10] hw/acpi-build, xen-hvm: introduce a Xen-specific ACPI builder Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 07/10] xen-hvm: add functions to copy data from/to HVM memory Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 08/10] nvdimm acpi: add functions to access DSM memory on Xen Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 09/10] nvdimm acpi: add compatibility for 64-bit integer in ACPI 2.0 and later Haozhong Zhang
2017-12-07 10:18 ` [RFC QEMU PATCH v4 10/10] xen-hvm: enable building NFIT and SSDT of vNVDIMM for HVM domains Haozhong Zhang
2018-02-27 17:22 ` [RFC QEMU PATCH v4 00/10] Implement vNVDIMM for Xen HVM guest Anthony PERARD
2018-02-28 9:36 ` Haozhong Zhang
[not found] ` <20180228093659.xpq2amq2zjuw2mdr@hz-desktop>
2018-03-02 12:03 ` Anthony PERARD
2018-03-06 4:16 ` Haozhong Zhang
2018-03-06 11:38 ` Anthony PERARD
2018-02-09 12:33 ` [RFC XEN PATCH v4 00/41] Add vNVDIMM support to HVM domains Roger Pau Monné
2018-02-12 1:25 ` Haozhong Zhang
2018-02-12 10:05 ` Roger Pau Monné
2018-02-13 10:06 ` Jan Beulich
2018-02-13 10:29 ` Roger Pau Monné
2018-02-13 11:05 ` Jan Beulich
2018-02-13 11:13 ` Roger Pau Monné
2018-02-13 13:40 ` Jan Beulich
2018-02-13 15:39 ` Roger Pau Monné
2018-02-15 6:59 ` Haozhong Zhang
2018-02-15 6:44 ` Haozhong Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171207101030.22364-15-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=chao.p.peng@linux.intel.com \
--cc=dan.j.williams@intel.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).