Skip to contentSkip to conversation

Add vNVDIMM support to HVM domains

RFC PATCH Superseded Haozhong Zhang 4 participants 32 messages Mar 20, 2017 – Apr 11, 2017

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add vNVDIMM support to HVM domains

This is v2 RFC patch series to add vNVDIMM support to HVM domains.
v1 can be found at https://lists.xenproject.org/archives/html/xen-devel/2016-10/msg00424.html.

No label and no _DSM except function 0 "query implemented functions" is supported by this version, but they will be added by future patches.

The corresponding Qemu patch series is sent in another thread "[RFC QEMU PATCH v2 00/10] Implement vNVDIMM for Xen HVM guest".

All patch series can be found at
Xen: https://github.com/hzzhan9/xen.git nvdimm-rfc-v2
Qemu: https://github.com/hzzhan9/qemu.git xen-nvdimm-rfc-v2

Changes in v2
==============

- One of the primary changes in v2 is dropping the linux kernel patches, which were used to reserve on host pmem for placing its frametable and M2P table. In v2, we add a management tool xen-ndctl which is used in Dom0 to notify Xen hypervisor of which storage can be used to manage the host pmem.

For example,
1. xen-ndctl setup 0x240000 0x380000 0x380000 0x3c0000
tells Xen hypervisor to use host pmem pages at MFN 0x380000 ~ 0x3c0000 to manage host pmem pages at MFN 0x240000 ~ 0x380000. I.e. the former is used to place the frame table and M2P table of both ranges of pmem pages.

2. xen-ndctl setup 0x240000 0x380000
tells Xen hypervisor to use the regular RAM to manage the host pmem pages at MFN 0x240000 ~ 0x380000. I.e the regular RMA is used to place the frame table and M2P table.

- Another primary change in v2 is dropping the support to map files on the host pmem to HVM domains as virtual NVDIMMs, as I cannot find a stable to fix the fiemap of host files. Instead, we can rely on the ability added in Linux kernel v4.9 that enables creating multiple pmem namespaces on a single nvdimm interleave set.

- Other changes are logged in each patch separately.

How to Test
==============

0. This patch series can be tested either on the real hardware with NVDIMM, or in the nested virtualization environment on KVM. The latter requires QEMU 2.9 or newer with, for example, following commands and options,

     # dd if=/dev/zero of=nvm-8G.img bs=1G count=8
     # rmmod kvm-intel; modprobe kvm-intel nested=1
     # qemu-system-x86_64 -enable-kvm -smp 4 -cpu host,+vmx \
                          -hda DISK_IMG_OF_XEN \
                          -machine pc,nvdimm \
                          -m 8G,slots=4,maxmem=128G \
                          -object memory-backend-file,id=mem1,mem-path=nvm-8G,size=8G \
                          -device nvdimm,id=nv1,memdev=mem1,label-size=2M \
                          ...
   Above will create a nested virtualization environment with a 8G
   pmem mode NVDIMM device (whose last 2MB is used as the label
   storage area).

1. Check out Xen and QEMU from above repositories and branches. Build and install Xen with qemu-xen replaced by above QEMU.

2. Build and install Linux kernel 4.9 or later as Dom0 kernel with the following configs selected:
CONFIG_ACPI_NFIT
CONFIG_LIBNVDIMM
CONFIG_BLK_DEV_PMEM
CONFIG_NVDIMM_PFN
CONFIG_FS_DAX

3. Check out ndctl from https://github.com/pmem/ndctl.git. Build and install ndctl in Dom0.

4. Boot to Xen Dom0.

5. Create pmem namespaces on the host pmem region.

     # ndctl disable-region region0
     # ndctl zero-labels nmem0                        // clear existing labels
     # ndctl init-labels nmem0                        // initialize the label area
     # ndctl enable-region region0     
     # ndctl create-namespace -r region0 -s 4G -m raw // create one 4G pmem namespace
     # ndctl create-namespace -r region0 -s 1G -m raw // create one 1G pmem namespace
     # ndctl list --namespaces
     [
       {
           "dev":"namespace0.0",
           "mode":"raw",
           "size":4294967296,
           "uuid":"bbfbedbd-3ada-4f55-9484-01f2722c651b",
           "blockdev":"pmem0"
       },
       {
           "dev":"namespace0.1",
           "mode":"raw",
           "size":1073741824,
           "uuid":"dd4d3949-6887-417b-b819-89a7854fcdbd",
           "blockdev":"pmem0.1"
       }
     ]

6. Ask Xen hypervisor to use namespace0.1 to manage namespace0.0.

     # grep namespace /proc/iomem
         240000000-33fffffff : namespace0.0
         340000000-37fffffff : namespace0.1
     # xen-ndctl setup 0x240000 0x340000 0x340000 0x380000

7. Start a HVM domain with "vnvdimms=[ '/dev/pmem0' ]" in its xl config.

If ndctl is installed in HVM domain, "ndctl list" should be able to list a 4G pmem namespace, e.g.

   {
     "dev":"namespace0.0",
     "mode":"raw",
     "size":4294967296,
     "blockdev":"pmem0"

}

Haozhong Zhang (15):
xen/common: add Kconfig item for pmem support
xen: probe pmem regions via ACPI NFIT
xen/x86: allow customizing locations of extended frametable & M2P xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem xen/x86: add XENMEM_populate_pmemmap to map host pmem pages to HVM domain
tools: reserve guest memory for ACPI from device model tools/libacpi: expose the minimum alignment used by mem_ops.alloc tools/libacpi: add callback acpi_ctxt.p2v to get a pointer from physical address tools/libacpi: add callbacks to access XenStore
tools/libacpi: add a simple AML builder
tools/libacpi: load ACPI built by the device model
tools/libxl: build qemu options from xl vNVDIMM configs tools/libxl: add support to map host pmem device to guests tools/libxl: initiate pmem mapping via qmp callback
tools/misc: add xen-ndctl

 .gitignore                              |   1 +
 docs/man/xl.cfg.pod.5.in                |   6 +
 tools/firmware/hvmloader/Makefile       |   3 +-
 tools/firmware/hvmloader/util.c         |  75 ++++++
 tools/firmware/hvmloader/util.h         |  10 +
 tools/firmware/hvmloader/xenbus.c       |  44 +++-
 tools/flask/policy/modules/dom0.te      |   2 +-
 tools/flask/policy/modules/xen.if       |   2 +-
 tools/libacpi/acpi2_0.h                 |   2 +
 tools/libacpi/aml_build.c               | 326 +++++++++++++++++++++++
 tools/libacpi/aml_build.h               | 116 +++++++++
 tools/libacpi/build.c                   | 311 ++++++++++++++++++++++
 tools/libacpi/libacpi.h                 |  21 ++
 tools/libxc/include/xc_dom.h            |   1 +
 tools/libxc/include/xenctrl.h           |  36 +++
 tools/libxc/xc_dom_x86.c                |   7 +
 tools/libxc/xc_domain.c                 |  15 ++
 tools/libxc/xc_misc.c                   |  17 ++
 tools/libxl/Makefile                    |   7 +-
 tools/libxl/libxl_create.c              |   4 +-
 tools/libxl/libxl_dm.c                  | 109 +++++++-
 tools/libxl/libxl_dom.c                 |  22 ++
 tools/libxl/libxl_nvdimm.c              | 182 +++++++++++++
 tools/libxl/libxl_nvdimm.h              |  42 +++
 tools/libxl/libxl_qmp.c                 | 116 ++++++++-
 tools/libxl/libxl_types.idl             |   8 +
 tools/libxl/libxl_x86_acpi.c            |  41 +++
 tools/misc/Makefile                     |   4 +
 tools/misc/xen-ndctl.c                  | 227 ++++++++++++++++
 tools/xl/xl_parse.c                     |  16 ++
 xen/arch/x86/acpi/boot.c                |   4 +
 xen/arch/x86/domain.c                   |   7 +
 xen/arch/x86/sysctl.c                   |  22 ++
 xen/arch/x86/x86_64/mm.c                | 191 ++++++++++++--
 xen/common/Kconfig                      |   9 +
 xen/common/Makefile                     |   1 +
 xen/common/compat/memory.c              |   1 +
 xen/common/domain.c                     |   3 +
 xen/common/memory.c                     |  43 +++
 xen/common/pmem.c                       | 448 ++++++++++++++++++++++++++++++++
 xen/drivers/acpi/Makefile               |   2 +
 xen/drivers/acpi/nfit.c                 | 116 +++++++++
 xen/include/acpi/actbl.h                |   1 +
 xen/include/acpi/actbl1.h               |  42 +++
 xen/include/public/hvm/hvm_xs_strings.h |  11 +
 xen/include/public/memory.h             |  14 +-
 xen/include/public/sysctl.h             |  29 ++-
 xen/include/xen/acpi.h                  |   4 +
 xen/include/xen/pmem.h                  |  66 +++++
 xen/include/xen/sched.h                 |   3 +
 xen/include/xsm/dummy.h                 |  11 +
 xen/include/xsm/xsm.h                   |  12 +
 xen/xsm/dummy.c                         |   4 +
 xen/xsm/flask/hooks.c                   |  17 ++
 xen/xsm/flask/policy/access_vectors     |   4 +
 55 files changed, 2795 insertions(+), 43 deletions(-)
 create mode 100644 tools/libacpi/aml_build.c
 create mode 100644 tools/libacpi/aml_build.h
 create mode 100644 tools/libxl/libxl_nvdimm.c
 create mode 100644 tools/libxl/libxl_nvdimm.h
 create mode 100644 tools/misc/xen-ndctl.c
 create mode 100644 xen/common/pmem.c
 create mode 100644 xen/drivers/acpi/nfit.c
 create mode 100644 xen/include/xen/pmem.h
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

RFC PATCH v2 1/15 xen/common: add Kconfig item for pmem support

Add CONFIG_PMEM to enable NVDIMM persistent memory support. By default, it's N.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/common/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
xen/common/Kconfig +9 -0
index f2ecbc43d6..f58a47d3a7 100644
@@ -237,4 +237,13 @@ config FAST_SYMBOL_LOOKUP
 	  The only user of this is Live patching.
 
 	  If unsure, say Y.
+
+config PMEM
+	bool "Pmem support"
+	default n
+	---help---
+	  Enable support for the persistent memory mode NVDIMM.
+
+	  If unsure, say N.
+
 endmenu
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

RFC PATCH v2 2/15 xen: probe pmem regions via ACPI NFIT

In reply to Haozhong Zhang

Probe the address ranges of pmem regions via ACPI NFIT and report them to Xen hypervisor.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/acpi/boot.c  |   4 ++
 xen/common/Makefile       |   1 +
 xen/common/pmem.c         | 106 ++++++++++++++++++++++++++++++++++++++++++
 xen/drivers/acpi/Makefile |   2 +
 xen/drivers/acpi/nfit.c   | 116 ++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/acpi/actbl.h  |   1 +
 xen/include/acpi/actbl1.h |  42 +++++++++++++++++
 xen/include/xen/acpi.h    |   4 ++
 xen/include/xen/pmem.h    |  28 +++++++++++
 9 files changed, 304 insertions(+)
 create mode 100644 xen/common/pmem.c
 create mode 100644 xen/drivers/acpi/nfit.c
 create mode 100644 xen/include/xen/pmem.h
xen/arch/x86/acpi/boot.c +4 -0
index 33c9133812..83d73868d6 100644
@@ -754,5 +754,9 @@ int __init acpi_boot_init(void)
 
 	acpi_table_parse(ACPI_SIG_BGRT, acpi_invalidate_bgrt);
 
+#ifdef CONFIG_PMEM
+	acpi_nfit_init();
+#endif
+
 	return 0;
 }
xen/common/Makefile +1 -0
index 0fed30bcc6..16c273b6d4 100644
@@ -29,6 +29,7 @@ obj-y += notifier.o
 obj-y += page_alloc.o
 obj-$(CONFIG_HAS_PDX) += pdx.o
 obj-$(CONFIG_PERF_COUNTERS) += perfc.o
+obj-$(CONFIG_PMEM) += pmem.o
 obj-y += preempt.o
 obj-y += random.o
 obj-y += rangeset.o
xen/common/pmem.c new file +106 -0

106 lines not on this page · raw message

xen/drivers/acpi/Makefile +2 -0
index 444b11d583..cef9d90222 100644
@@ -9,3 +9,5 @@ obj-$(CONFIG_HAS_CPUFREQ) += pmstat.o
 
 obj-$(CONFIG_X86) += hwregs.o
 obj-$(CONFIG_X86) += reboot.o
+
+obj-$(CONFIG_PMEM) += nfit.o
xen/drivers/acpi/nfit.c new file +116 -0

116 lines not on this page · raw message

xen/include/acpi/actbl.h +1 -0
index 3079176992..6e113b0873 100644
@@ -71,6 +71,7 @@
 #define ACPI_SIG_XSDT           "XSDT"	/* Extended  System Description Table */
 #define ACPI_SIG_SSDT           "SSDT"	/* Secondary System Description Table */
 #define ACPI_RSDP_NAME          "RSDP"	/* Short name for RSDP, not signature */
+#define ACPI_SIG_NFIT           "NFIT"	/* NVDIMM Firmware Interface Table */
 
 /*
  * All tables and structures must be byte-packed to match the ACPI
xen/include/acpi/actbl1.h +42 -0

48 lines not on this page · raw message

xen/include/xen/acpi.h +4 -0
index 30ec0eec5f..8edb9a275e 100644
@@ -180,4 +180,8 @@ void acpi_reboot(void);
 void acpi_dmar_zap(void);
 void acpi_dmar_reinstate(void);
 
+#ifdef CONFIG_PMEM
+void acpi_nfit_init(void);
+#endif /* CONFIG_PMEM */
+
 #endif /*_LINUX_ACPI_H*/
xen/include/xen/pmem.h new file +28 -0
new file mode 100644
index 0000000000..1144e86f98
@@ -0,0 +1,28 @@
+/*
+ * xen/include/xen/pmem.h
+ *
+ * Copyright (C) 2017, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms and conditions of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __XEN_PMEM_H__
+#define __XEN_PMEM_H__
+#ifdef CONFIG_PMEM
+
+#include <xen/types.h>
+
+int pmem_register(unsigned long smfn, unsigned long emfn);
+
+#endif /* CONFIG_PMEM */
+#endif /* __XEN_PMEM_H__ */
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

RFC PATCH v2 3/15 xen/x86: allow customizing locations of extended frametable & M2P

In reply to Haozhong Zhang

Xen is not aware which portions of pmem can be used to store its frametable and M2P table. Instead, it will rely on users or system admins in Dom0 to specify the location. For the regular RAM, no functional change is introduced.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes in v2:
* Merge v1 patch 1 (for frametable) and v1 patch 2 (for M2P).
* Add const to some parameters.
* Explain new parameters of extend_frame_table() and setup_m2p_table().

---
 xen/arch/x86/x86_64/mm.c | 80 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 19 deletions(-)
xen/arch/x86/x86_64/mm.c +61 -19
index 34f3250fd7..0f1ceacc6a 100644
@@ -111,15 +111,27 @@ int hotadd_mem_valid(unsigned long pfn, struct mem_hotadd_info *info)
     return (pfn < info->epfn && pfn >= info->spfn);
 }
 
+/*
+ * Allocate pages in the PFN range from info->spfn to info->epfn. The
+ * first free page is indicated by info->cur. The allocation unit is
+ * (1 << PAGETABLE_ORDER) pages.
+ *
+ * On success, return PFN of the first allocated page. Otherwise, return
+ * mfn_x(INVALID_MFN).
+ */
+typedef unsigned long (*mfns_alloc_fn_t)(struct mem_hotadd_info *info);
+
 static unsigned long alloc_hotadd_mfn(struct mem_hotadd_info *info)
 {
-    unsigned mfn;
+    unsigned long mfn;
 
-    ASSERT((info->cur + ( 1UL << PAGETABLE_ORDER) < info->epfn) &&
-            info->cur >= info->spfn);
+    if ( (info->cur + (1UL << PAGETABLE_ORDER) >= info->epfn) ||
+         info->cur < info->spfn )
+        return mfn_x(INVALID_MFN);
 
     mfn = info->cur;
     info->cur += (1UL << PAGETABLE_ORDER);
+
     return mfn;
 }
 
@@ -313,11 +325,13 @@ void destroy_m2p_mapping(struct mem_hotadd_info *info)
 }
 
 /*
- * Allocate and map the compatibility mode machine-to-phys table.
- * spfn/epfn: the pfn ranges to be setup
- * free_s/free_e: the pfn ranges that is free still
+ * Allocate and map the compatibility mode machine-to-phys table for
+ * pages info->spfn ~ info->epfn. M2P is placed in pages allocated
+ * by alloc_fn from the range alloc_info->cur ~ alloc_info->epfn.
  */
-static int setup_compat_m2p_table(struct mem_hotadd_info *info)
+static int setup_compat_m2p_table(const struct mem_hotadd_info *info,
+                                  mfns_alloc_fn_t alloc_fn,
+                                  struct mem_hotadd_info *alloc_info)
 {
     unsigned long i, va, smap, emap, rwva, epfn = info->epfn, mfn;
     unsigned int n;
@@ -371,7 +385,12 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info)
         if ( n == CNT )
             continue;
 
-        mfn = alloc_hotadd_mfn(info);
+        mfn = alloc_fn(alloc_info);
+        if ( mfn == mfn_x(INVALID_MFN) )
+        {
+            err = -ENOMEM;
+            break;
+        }
         err = map_pages_to_xen(rwva, mfn, 1UL << PAGETABLE_ORDER,
                                PAGE_HYPERVISOR);
         if ( err )
@@ -389,9 +408,14 @@ 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
+ * The L3 for RO/RWRW MPT and the L2 for compatible MPT should be setup already.
+ *
+ * M2P is placed in pages allocated by alloc_fn from the range
+ * alloc_info->cur ~ alloc_info->epfn.
  */
-static int setup_m2p_table(struct mem_hotadd_info *info)
+static int setup_m2p_table(const struct mem_hotadd_info *info,
+                           mfns_alloc_fn_t alloc_fn,
+                           struct mem_hotadd_info *alloc_info)
 {
     unsigned long i, va, smap, emap;
     unsigned int n;
@@ -440,7 +464,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_fn(alloc_info);
+
+            if ( mfn == mfn_x(INVALID_MFN) )
+            {
+                ret = -ENOMEM;
+                goto error;
+            }
 
             ret = map_pages_to_xen(
                         RDWR_MPT_VIRT_START + i * sizeof(unsigned long),
@@ -485,7 +515,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_fn, alloc_info);
 error:
     return ret;
 }
@@ -769,7 +799,8 @@ void cleanup_frame_table(struct mem_hotadd_info *info)
 }
 
 static int setup_frametable_chunk(void *start, void *end,
-                                  struct mem_hotadd_info *info)
+                                  mfns_alloc_fn_t alloc_fn,
+                                  struct mem_hotadd_info *alloc_info)
 {
     unsigned long s = (unsigned long)start;
     unsigned long e = (unsigned long)end;
@@ -781,7 +812,9 @@ static int setup_frametable_chunk(void *start, void *end,
 
     for ( ; s < e; s += (1UL << L2_PAGETABLE_SHIFT))
     {
-        mfn = alloc_hotadd_mfn(info);
+        mfn = alloc_fn(alloc_info);
+        if ( mfn == mfn_x(INVALID_MFN) )
+            return -ENOMEM;
         err = map_pages_to_xen(s, mfn, 1UL << PAGETABLE_ORDER,
                                PAGE_HYPERVISOR);
         if ( err )
@@ -792,7 +825,14 @@ static int setup_frametable_chunk(void *start, void *end,
     return 0;
 }
 
-static int extend_frame_table(struct mem_hotadd_info *info)
+/*
+ * Create and map the frame table for page ranges info->spfn ~
+ * info->epfn. The frame table is placed in pages allocated by
+ * alloc_fn from page range alloc_info->cur ~ alloc_info->epfn.
+ */
+static int extend_frame_table(const struct mem_hotadd_info *info,
+                              mfns_alloc_fn_t alloc_fn,
+                              struct mem_hotadd_info *alloc_info)
 {
     unsigned long cidx, nidx, eidx, spfn, epfn;
 
@@ -818,9 +858,9 @@ static int extend_frame_table(struct mem_hotadd_info *info)
         nidx = find_next_bit(pdx_group_valid, eidx, cidx);
         if ( nidx >= eidx )
             nidx = eidx;
-        err = setup_frametable_chunk(pdx_to_page(cidx * PDX_GROUP_COUNT ),
+        err = setup_frametable_chunk(pdx_to_page(cidx * PDX_GROUP_COUNT),
                                      pdx_to_page(nidx * PDX_GROUP_COUNT),
-                                     info);
+                                     alloc_fn, alloc_info);
         if ( err )
             return err;
 
@@ -1422,7 +1462,8 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
     info.epfn = epfn;
     info.cur = spfn;
 
-    ret = extend_frame_table(&info);
+    /* Place the frame table at the beginning of hotplugged memory. */
+    ret = extend_frame_table(&info, alloc_hotadd_mfn, &info);
     if (ret)
         goto destroy_frametable;
 
@@ -1435,7 +1476,8 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
     total_pages += epfn - spfn;
 
     set_pdx_range(spfn, epfn);
-    ret = setup_m2p_table(&info);
+    /* Place M2P in the hotplugged memory after the frame table. */
+    ret = setup_m2p_table(&info, alloc_hotadd_mfn, &info);
 
     if ( ret )
         goto destroy_m2p;
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

RFC PATCH v2 4/15 xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem

In reply to Haozhong Zhang

Xen hypervisor is not aware which portions of pmem can be used to store the frame table and M2P table of pmem. Instead, it provides users or admins in Dom0 with a sysctl XEN_SYSCTL_nvdimm_pmem_setup to specify the location.

XEN_SYSCTL_nvdimm_pmem_setup receives four arguments: data_smfn, data_emfn, mgmt_smfn and mgmt_emfn.
- data_smfn and data_emfn specify the start and end MFN of a host pmem region that can be used by guest.
- If neither mgmt_smfn nor mgmt_emfn is INVALID_MFN, the host pmem pages from mgmt_smfn to mgmt_emfn will be used to store the frametable and M2P table of the pmem region data_smfn ~ data_emfn and itself. data_smfn ~ data_emfn and mgmt_smfn ~ mgmt_emfn should not overlap with each other.
- If either mgmt_smfn or mgmt_emfn is INVALID_MFN, Xen hypervisor will store the frametable and M2P table of the pmem region data_smfn ~ data_emfn in the regular RAM.

XEN_SYSCTL_nvdimm_pmem_setup currently only works on x86, and returns -ENOSYS on other architectures.

---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes in v2:
* Convert XENPF_pmem_add in v1 to XEN_SYSCTL_nvdimm_pmem_setup in v2. v2 patch series relies on users/admins in Dom0 instead of Dom0 driver to indicate the location to store the frametable and M2P of pmem.
* Separate the architecture-independent and -depend code to pmem_setup and pmem_arch_setup. Currently, only pmem_arch_setup on x86 is implemented, while it returns -ENOSYS on other architectures.
* Add XSM check for XEN_SYSCTL_nvdimm_pmem_setup.

---
 tools/flask/policy/modules/dom0.te  |   2 +-
 tools/libxc/include/xenctrl.h       |  19 ++++
 tools/libxc/xc_misc.c               |  17 ++++
 tools/misc/xen-ndctl.c              |   0
 xen/arch/x86/sysctl.c               |  22 ++++
 xen/arch/x86/x86_64/mm.c            | 111 ++++++++++++++++++++
 xen/common/pmem.c                   | 197 ++++++++++++++++++++++++++++++++++++
 xen/include/public/sysctl.h         |  29 +++++-
 xen/include/xen/pmem.h              |  14 +++
 xen/xsm/flask/hooks.c               |   4 +
 xen/xsm/flask/policy/access_vectors |   2 +
 11 files changed, 415 insertions(+), 2 deletions(-)
 create mode 100644 tools/misc/xen-ndctl.c
tools/flask/policy/modules/dom0.te +1 -1
index d0a4d91ac0..d31c514550 100644
@@ -16,7 +16,7 @@ allow dom0_t xen_t:xen {
 allow dom0_t xen_t:xen2 {
 	resource_op psr_cmt_op psr_cat_op pmu_ctrl get_symbol
 	get_cpu_levelling_caps get_cpu_featureset livepatch_op
-	gcov_op
+	gcov_op nvdimm_op
 };
 
 # Allow dom0 to use all XENVER_ subops that have checks.
tools/libxc/include/xenctrl.h +19 -0
index a48981abea..d4e3002c9e 100644
@@ -2534,6 +2534,25 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout);
 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid,
                          xen_pfn_t start_pfn, xen_pfn_t nr_pfns);
 
+/*
+ * Query Xen hypervisor to prepare for mapping host pmem pages.
+ *
+ * Parameters:
+ *  xch:       xc interface handler
+ *  smfn:      the start MFN of the host pmem pages to be mapped
+ *  emfn:      the end MFN of the host pmem pages to be mapped
+ *  mgmt_smfn: If not INVALID_MFN, the start MFN of host pmem pages for managing
+ *             above pmem pages
+ *  mgmt_emfn: If not INVALID_MFN, the end MFN of host pmem pages for managing
+ *             above pmem pages
+ *
+ * Return:
+ *  0 on success; non-zero error code on failures.
+ */
+int xc_nvdimm_pmem_setup(xc_interface *xch,
+                         unsigned long smfn, unsigned long emfn,
+                         unsigned long mgmt_smfn, unsigned long mgmt_emfn);
+
 /* Compat shims */
 #include "xenctrl_compat.h"
 
tools/libxc/xc_misc.c +17 -0
index 88084fde30..0384f45b8e 100644
@@ -817,6 +817,23 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout)
     return _xc_livepatch_action(xch, name, LIVEPATCH_ACTION_REPLACE, timeout);
 }
 
+int xc_nvdimm_pmem_setup(xc_interface *xch,
+                         unsigned long smfn, unsigned long emfn,
+                         unsigned long mgmt_smfn, unsigned long mgmt_emfn)
+{
+    DECLARE_SYSCTL;
+
+    sysctl.cmd = XEN_SYSCTL_nvdimm_op;
+    sysctl.u.nvdimm.cmd = XEN_SYSCTL_nvdimm_pmem_setup;
+    sysctl.u.nvdimm.pad = 0;
+    sysctl.u.nvdimm.u.setup.smfn = smfn;
+    sysctl.u.nvdimm.u.setup.emfn = emfn;
+    sysctl.u.nvdimm.u.setup.mgmt_smfn = mgmt_smfn;
+    sysctl.u.nvdimm.u.setup.mgmt_emfn = mgmt_emfn;
+
+    return do_sysctl(xch, &sysctl);
+}
+
 /*
  * Local variables:
  * mode: C
tools/misc/xen-ndctl.c new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/x86/sysctl.c +22 -0
index 2f7056e816..62f2980840 100644
@@ -19,6 +19,7 @@
 #include <xen/trace.h>
 #include <xen/console.h>
 #include <xen/iocap.h>
+#include <xen/pmem.h>
 #include <asm/irq.h>
 #include <asm/hvm/hvm.h>
 #include <asm/hvm/support.h>
@@ -250,6 +251,27 @@ long arch_do_sysctl(
         break;
     }
 
+#ifdef CONFIG_PMEM
+    case XEN_SYSCTL_nvdimm_op:
+    {
+        xen_sysctl_nvdimm_pmem_setup_t *setup;
+
+        switch ( sysctl->u.nvdimm.cmd )
+        {
+        case XEN_SYSCTL_nvdimm_pmem_setup:
+            setup = &sysctl->u.nvdimm.u.setup;
+            ret = pmem_setup(setup->smfn, setup->emfn,
+                             setup->mgmt_smfn, setup->mgmt_emfn);
+            break;
+
+        default:
+            ret = -ENOSYS;
+        }
+
+        break;
+    }
+#endif /* CONFIG_PMEM */
+
     default:
         ret = -ENOSYS;
         break;
xen/arch/x86/x86_64/mm.c +111 -0

123 lines not on this page · raw message

xen/common/pmem.c +197 -0

222 lines not on this page · raw message

xen/include/public/sysctl.h +28 -1
index 00f5e77d91..27831a5e4f 100644
@@ -36,7 +36,7 @@
 #include "physdev.h"
 #include "tmem.h"
 
-#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000F
+#define XEN_SYSCTL_INTERFACE_VERSION 0x00000010
 
 /*
  * Read console content from Xen buffer ring.
@@ -1088,6 +1088,31 @@ struct xen_sysctl_livepatch_op {
 typedef struct xen_sysctl_livepatch_op xen_sysctl_livepatch_op_t;
 DEFINE_XEN_GUEST_HANDLE(xen_sysctl_livepatch_op_t);
 
+#define XEN_SYSCTL_nvdimm_pmem_setup 0
+struct xen_sysctl_nvdimm_pmem_setup {
+    /* IN variables */
+    uint64_t smfn;      /* start MFN of the pmem region                  */
+    uint64_t emfn;      /* end MFN of the pmem region                    */
+    uint64_t mgmt_smfn; /* If not INVALID_MFN, start MFN of another pmem */
+                        /* region that will be used to manage above pmem */
+                        /* region.                                       */
+    uint64_t mgmt_emfn; /* If not INVALID_MFN, end MFN of another pmem   */
+                        /* region that will be used to manage above pmem */
+                        /* region. */
+};
+typedef struct xen_sysctl_nvdimm_pmem_setup xen_sysctl_nvdimm_pmem_setup_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_pmem_setup_t);
+
+struct xen_sysctl_nvdimm_op {
+    uint32_t cmd; /* IN: XEN_SYSCTL_NVDIMM_*. */
+    uint32_t pad; /* IN: Always zero. */
+    union {
+        xen_sysctl_nvdimm_pmem_setup_t setup;
+    } u;
+};
+typedef struct xen_sysctl_nvdimm_op xen_sysctl_nvdimm_op_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_op_t);
+
 struct xen_sysctl {
     uint32_t cmd;
 #define XEN_SYSCTL_readconsole                    1
@@ -1116,6 +1141,7 @@ struct xen_sysctl {
 #define XEN_SYSCTL_get_cpu_levelling_caps        25
 #define XEN_SYSCTL_get_cpu_featureset            26
 #define XEN_SYSCTL_livepatch_op                  27
+#define XEN_SYSCTL_nvdimm_op                     28
     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
     union {
         struct xen_sysctl_readconsole       readconsole;
@@ -1144,6 +1170,7 @@ struct xen_sysctl {
         struct xen_sysctl_cpu_levelling_caps cpu_levelling_caps;
         struct xen_sysctl_cpu_featureset    cpu_featureset;
         struct xen_sysctl_livepatch_op      livepatch;
+        struct xen_sysctl_nvdimm_op         nvdimm;
         uint8_t                             pad[128];
     } u;
 };
xen/include/xen/pmem.h +14 -0
index 1144e86f98..95c8207ff6 100644
@@ -23,6 +23,20 @@
 #include <xen/types.h>
 
 int pmem_register(unsigned long smfn, unsigned long emfn);
+int pmem_setup(unsigned long data_spfn, unsigned long data_emfn,
+               unsigned long mgmt_smfn, unsigned long mgmt_emfn);
+
+#ifdef CONFIG_X86
+int pmem_arch_setup(unsigned long data_smfn, unsigned long data_emfn,
+                    unsigned long mgmt_smfn, unsigned long mgmt_emfn);
+#else /* !CONFIG_X86 */
+static inline int
+pmem_arch_setup(unsigned long data_smfn, unsigned long data_emfn,
+                unsigned mgmt_smfn, unsigned long mgmt_emfn)
+{
+    return -ENOSYS;
+}
+#endif /* CONFIG_X86 */
 
 #endif /* CONFIG_PMEM */
 #endif /* __XEN_PMEM_H__ */
xen/xsm/flask/hooks.c +4 -0
index 4baed39890..e3c77bbe3f 100644
@@ -826,6 +826,10 @@ static int flask_sysctl(int cmd)
         return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2,
                                     XEN2__GCOV_OP, NULL);
 
+    case XEN_SYSCTL_nvdimm_op:
+        return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2,
+                                    XEN2__NVDIMM_OP, NULL);
+
     default:
         return avc_unknown_permission("sysctl", cmd);
     }
xen/xsm/flask/policy/access_vectors +2 -0
index 1f7eb35fc8..a8ddd7ca84 100644
@@ -101,6 +101,8 @@ class xen2
     livepatch_op
 # XEN_SYSCTL_gcov_op
     gcov_op
+# XEN_SYSCTL_nvdimm_op
+    nvdimm_op
 }
 
 # Classes domain and domain2 consist of operations that a domain performs on
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

RFC PATCH v2 5/15 xen/x86: add XENMEM_populate_pmem_map to map host pmem pages to HVM domain

In reply to Haozhong Zhang

XENMEM_populate_pmemmap is used by toolstack to map the specified host pmem pages to the specified guest physical address. Only pmem pages that have been setup via XEN_SYSCTL_nvdimm_pmem_setup can be mapped via XENMEM_populate_pmem_map. Because XEN_SYSCTL_nvdimm_pmem_setup only works on x86, XENMEM_populate_pmem_map is made to work only on x86 as well and return -ENOSYS on other architectures.

---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

Changes in v2:
* Rename *_pmemmap to *_pmem_map.
* Add XSM check fo XENMEM_populate_pmem_map.
* Add compat code for XENMEM_populate_pmem_map.
* Add stub for pmem_populate() on non-x86 architectures.
* Add check to avoid populate pmem pages to dom0.
* Merge v1 patch 5 "xen/x86: release pmem pages at domain destroy".

---
 tools/flask/policy/modules/xen.if   |   2 +-
 tools/libxc/include/xenctrl.h       |  17 ++++
 tools/libxc/xc_domain.c             |  15 ++++
 xen/arch/x86/domain.c               |   7 ++
 xen/common/compat/memory.c          |   1 +
 xen/common/domain.c                 |   3 +
 xen/common/memory.c                 |  43 ++++++++++
 xen/common/pmem.c                   | 151 +++++++++++++++++++++++++++++++++++-
 xen/include/public/memory.h         |  14 +++-
 xen/include/xen/pmem.h              |  24 ++++++
 xen/include/xen/sched.h             |   3 +
 xen/include/xsm/dummy.h             |  11 +++
 xen/include/xsm/xsm.h               |  12 +++
 xen/xsm/dummy.c                     |   4 +
 xen/xsm/flask/hooks.c               |  13 ++++
 xen/xsm/flask/policy/access_vectors |   2 +
 16 files changed, 317 insertions(+), 5 deletions(-)
tools/flask/policy/modules/xen.if +1 -1
index ed0df4f010..bc4176c089 100644
@@ -55,7 +55,7 @@ define(`create_domain_common', `
 			psr_cmt_op psr_cat_op soft_reset };
 	allow $1 $2:security check_context;
 	allow $1 $2:shadow enable;
-	allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };
+	allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp populate_pmem_map };
 	allow $1 $2:grant setup;
 	allow $1 $2:hvm { cacheattr getparam hvmctl sethvmc
 			setparam nested altp2mhvm altp2mhvm_op dm };
tools/libxc/include/xenctrl.h +17 -0
index d4e3002c9e..f8a9581506 100644
@@ -2553,6 +2553,23 @@ int xc_nvdimm_pmem_setup(xc_interface *xch,
                          unsigned long smfn, unsigned long emfn,
                          unsigned long mgmt_smfn, unsigned long mgmt_emfn);
 
+/*
+ * Map host pmem pages to a domain.
+ *
+ * Parameters:
+ *  xch:     xc interface handler
+ *  domid:   the target domain id
+ *  mfn:     start MFN of the host pmem pages to be mapped
+ *  nr_mfns: the number of host pmem pages to be mapped
+ *  gfn:     start GFN of the target guest physical pages
+ *
+ * Return:
+ *  0 on success; non-zero error code for failures.
+ */
+int xc_domain_populate_pmemmap(xc_interface *xch, uint32_t domid,
+                               unsigned long mfn, unsigned long gfn,
+                               unsigned long nr_mfns);
+
 /* Compat shims */
 #include "xenctrl_compat.h"
 
tools/libxc/xc_domain.c +15 -0
index d862e537d9..9ccdda086d 100644
@@ -2291,6 +2291,21 @@ int xc_domain_soft_reset(xc_interface *xch,
     domctl.domain = (domid_t)domid;
     return do_domctl(xch, &domctl);
 }
+
+int xc_domain_populate_pmemmap(xc_interface *xch, uint32_t domid,
+                               unsigned long mfn, unsigned long gfn,
+                               unsigned long nr_mfns)
+{
+    struct xen_pmem_map args = {
+        .domid   = domid,
+        .mfn     = mfn,
+        .gfn     = gfn,
+        .nr_mfns = nr_mfns,
+    };
+
+    return do_memory_op(xch, XENMEM_populate_pmem_map, &args, sizeof(args));
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/domain.c +7 -0
index 479aee641f..2333603f3e 100644
@@ -36,6 +36,7 @@
 #include <xen/wait.h>
 #include <xen/guest_access.h>
 #include <xen/livepatch.h>
+#include <xen/pmem.h>
 #include <public/sysctl.h>
 #include <public/hvm/hvm_vcpu.h>
 #include <asm/regs.h>
@@ -2352,6 +2353,12 @@ int domain_relinquish_resources(struct domain *d)
         if ( ret )
             return ret;
 
+#ifdef CONFIG_PMEM
+        ret = pmem_teardown(d);
+        if ( ret )
+            return ret;
+#endif /* CONFIG_PMEM */
+
         /* Tear down paging-assistance stuff. */
         ret = paging_teardown(d);
         if ( ret )
xen/common/compat/memory.c +1 -0
index a37a948331..19382f6dfc 100644
@@ -523,6 +523,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
         case XENMEM_add_to_physmap:
         case XENMEM_remove_from_physmap:
         case XENMEM_access_op:
+        case XENMEM_populate_pmem_map:
             break;
 
         case XENMEM_get_vnumainfo:
xen/common/domain.c +3 -0
index 4492c9c3d5..f8b4bd9c29 100644
@@ -287,6 +287,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
     INIT_PAGE_LIST_HEAD(&d->page_list);
     INIT_PAGE_LIST_HEAD(&d->xenpage_list);
 
+    spin_lock_init_prof(d, pmem_lock);
+    INIT_PAGE_LIST_HEAD(&d->pmem_page_list);
+
     spin_lock_init(&d->node_affinity_lock);
     d->node_affinity = NODE_MASK_ALL;
     d->auto_node_affinity = 1;
xen/common/memory.c +43 -0

55 lines not on this page · raw message

xen/common/pmem.c +148 -3

181 lines not on this page · raw message

xen/include/public/memory.h +13 -1
index 6eee0c8a16..fa636b313a 100644
@@ -648,7 +648,19 @@ struct xen_vnuma_topology_info {
 typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t;
 DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t);
 
-/* Next available subop number is 28 */
+#define XENMEM_populate_pmem_map 28
+
+struct xen_pmem_map {
+    /* IN */
+    domid_t domid;
+    unsigned long mfn;
+    unsigned long gfn;
+    unsigned int nr_mfns;
+};
+typedef struct xen_pmem_map xen_pmem_map_t;
+DEFINE_XEN_GUEST_HANDLE(xen_pmem_map_t);
+
+/* Next available subop number is 29 */
 
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
 
xen/include/xen/pmem.h +24 -0
index 95c8207ff6..cbc621048b 100644
@@ -26,9 +26,23 @@ int pmem_register(unsigned long smfn, unsigned long emfn);
 int pmem_setup(unsigned long data_spfn, unsigned long data_emfn,
                unsigned long mgmt_smfn, unsigned long mgmt_emfn);
 
+struct xen_pmem_map_args {
+    struct domain *domain;
+
+    unsigned long mfn;     /* start MFN of pmems page to be mapped */
+    unsigned long gfn;     /* start GFN of target domain */
+    unsigned long nr_mfns; /* number of pmem pages to be mapped */
+
+    /* For preemption ... */
+    unsigned long nr_done; /* number of pmem pages processed so far */
+    int preempted;         /* Is the operation preempted? */
+};
+
 #ifdef CONFIG_X86
 int pmem_arch_setup(unsigned long data_smfn, unsigned long data_emfn,
                     unsigned long mgmt_smfn, unsigned long mgmt_emfn);
+int pmem_populate(struct xen_pmem_map_args *args);
+int pmem_teardown(struct domain *d);
 #else /* !CONFIG_X86 */
 static inline int
 pmem_arch_setup(unsigned long data_smfn, unsigned long data_emfn,
@@ -36,6 +50,16 @@ pmem_arch_setup(unsigned long data_smfn, unsigned long data_emfn,
 {
     return -ENOSYS;
 }
+
+static inline int pmem_populate(struct xen_pmem_map_args *args)
+{
+    return -ENOSYS;
+}
+
+static inline int pmem_teardown(struct domain *d)
+{
+    return -ENOSYS;
+}
 #endif /* CONFIG_X86 */
 
 #endif /* CONFIG_PMEM */
xen/include/xen/sched.h +3 -0
index 0929c0b910..39057243d6 100644
@@ -336,6 +336,9 @@ struct domain
     atomic_t         shr_pages;       /* number of shared pages             */
     atomic_t         paged_pages;     /* number of paged-out pages          */
 
+    spinlock_t       pmem_lock;       /* protect all following pmem_ fields */
+    struct page_list_head pmem_page_list; /* linked list of pmem pages      */
+
     /* Scheduling. */
     void            *sched_priv;    /* scheduler-specific data */
     struct cpupool  *cpupool;
xen/include/xsm/dummy.h +11 -0
index 4b27ae72de..aea0b9376f 100644
@@ -728,3 +728,14 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)
         return xsm_default_action(XSM_PRIV, current->domain, NULL);
     }
 }
+
+#ifdef CONFIG_PMEM
+
+static XSM_INLINE int xsm_populate_pmem_map(XSM_DEFAULT_ARG
+                                            struct domain *d1, struct domain *d2)
+{
+    XSM_ASSERT_ACTION(XSM_TARGET);
+    return xsm_default_action(action, d1, d2);
+}
+
+#endif /* CONFIG_PMEM */
xen/include/xsm/xsm.h +12 -0
index 2cf7ac10db..8f62b21739 100644
@@ -182,6 +182,10 @@ struct xsm_operations {
     int (*dm_op) (struct domain *d);
 #endif
     int (*xen_version) (uint32_t cmd);
+
+#ifdef CONFIG_PMEM
+    int (*populate_pmem_map) (struct domain *d1, struct domain *d2);
+#endif /* CONFIG_PMEM */
 };
 
 #ifdef CONFIG_XSM
@@ -705,6 +709,14 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op)
     return xsm_ops->xen_version(op);
 }
 
+#ifdef CONFIG_PMEM
+static inline int xsm_populate_pmem_map(xsm_default_t def,
+                                        struct domain *d1, struct domain *d2)
+{
+    return xsm_ops->populate_pmem_map(d1, d2);
+}
+#endif /* CONFIG_PMEM */
+
 #endif /* XSM_NO_WRAPPERS */
 
 #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +4 -0
index 3cb5492dd3..dde68ecf59 100644
@@ -159,4 +159,8 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, dm_op);
 #endif
     set_to_dummy_if_null(ops, xen_version);
+
+#ifdef CONFIG_PMEM
+    set_to_dummy_if_null(ops, populate_pmem_map);
+#endif
 }
xen/xsm/flask/hooks.c +13 -0
index e3c77bbe3f..582ddf81d3 100644
@@ -1659,6 +1659,15 @@ static int flask_xen_version (uint32_t op)
     }
 }
 
+#ifdef CONFIG_PMEM
+
+static int flask_populate_pmem_map(struct domain *d1, struct domain *d2)
+{
+    return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__POPULATE_PMEM_MAP);
+}
+
+#endif /* CONFIG_PMEM */
+
 long do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 int compat_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 
@@ -1794,6 +1803,10 @@ static struct xsm_operations flask_ops = {
     .dm_op = flask_dm_op,
 #endif
     .xen_version = flask_xen_version,
+
+#ifdef CONFIG_PMEM
+    .populate_pmem_map = flask_populate_pmem_map,
+#endif /* CONFIG_PMEM */
 };
 
 void __init flask_init(const void *policy_buffer, size_t policy_size)
xen/xsm/flask/policy/access_vectors +2 -0
index a8ddd7ca84..44cbd66f4d 100644
@@ -385,6 +385,8 @@ class mmu
 # Allow a privileged domain to install a map of a page it does not own.  Used
 # for stub domain device models with the PV framebuffer.
     target_hack
+# XENMEM_populate_pmem_map
+    populate_pmem_map
 }
 
 # control of the paging_domctl split by subop
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

RFC PATCH v2 6/15 tools: reserve guest memory for ACPI from device model

In reply to Haozhong Zhang

Some virtual devices (e.g. NVDIMM) require complex ACPI tables and definition blocks (in AML), which a device model (e.g. QEMU) has already been able to construct. Instead of introducing the similar implementation to Xen, we would like to reuse the device model to provide those ACPI stuffs.

This commit reserves an area in the guest memory for the device model to pass its ACPI tables and definition blocks to guest, which will be loaded by hvmloader. The base guest physical address and the size of the reserved area are passed to the device model via XenStore keys hvmloader/dm-acpi/{address, length}.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxc/include/xc_dom.h            |  1 +
 tools/libxc/xc_dom_x86.c                |  7 +++++++
 tools/libxl/libxl_dom.c                 | 22 ++++++++++++++++++++++
 xen/include/public/hvm/hvm_xs_strings.h | 11 +++++++++++
 4 files changed, 41 insertions(+)
tools/libxc/include/xc_dom.h +1 -0
index 608cbc2ad6..19d65cda1e 100644
@@ -98,6 +98,7 @@ struct xc_dom_image {
     xen_pfn_t xenstore_pfn;
     xen_pfn_t shared_info_pfn;
     xen_pfn_t bootstack_pfn;
+    xen_pfn_t dm_acpi_pfn;
     xen_pfn_t pfn_alloc_end;
     xen_vaddr_t virt_alloc_end;
     xen_vaddr_t bsd_symtab_start;
tools/libxc/xc_dom_x86.c +7 -0
index 6495e7fc30..917fb51abf 100644
@@ -674,6 +674,13 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom)
                          ioreq_server_pfn(0));
         xc_hvm_param_set(xch, domid, HVM_PARAM_NR_IOREQ_SERVER_PAGES,
                          NR_IOREQ_SERVER_PAGES);
+
+        dom->dm_acpi_pfn = xc_dom_alloc_page(dom, "DM ACPI");
+        if ( dom->dm_acpi_pfn == INVALID_PFN )
+        {
+            DOMPRINTF("Could not allocate page for device model ACPI.");
+            goto error_out;
+        }
     }
 
     rc = xc_dom_alloc_segment(dom, &dom->start_info_seg,
tools/libxl/libxl_dom.c +22 -0
index d519c8d440..5f621466d5 100644
@@ -865,6 +865,28 @@ static int hvm_build_set_xs_values(libxl__gc *gc,
             goto err;
     }
 
+    if (dom->dm_acpi_pfn) {
+        uint64_t guest_addr_out = dom->dm_acpi_pfn * XC_DOM_PAGE_SIZE(dom);
+
+        if (guest_addr_out >= 0x100000000ULL) {
+            LOG(ERROR,
+                "Guest address of DM ACPI is 0x%"PRIx64", but expected below 4G",
+                guest_addr_out);
+            goto err;
+        }
+
+        path = GCSPRINTF("/local/domain/%d/"HVM_XS_DM_ACPI_ADDRESS, domid);
+        ret = libxl__xs_printf(gc, XBT_NULL, path, "0x%"PRIx64, guest_addr_out);
+        if (ret)
+            goto err;
+
+        path = GCSPRINTF("/local/domain/%d/"HVM_XS_DM_ACPI_LENGTH, domid);
+        ret = libxl__xs_printf(gc, XBT_NULL, path, "0x%"PRIx64,
+                               (uint64_t)XC_DOM_PAGE_SIZE(dom));
+        if (ret)
+            goto err;
+    }
+
     return 0;
 
 err:
xen/include/public/hvm/hvm_xs_strings.h +11 -0
index 146b0b0582..f9b82dbbc0 100644
@@ -79,4 +79,15 @@
  */
 #define HVM_XS_OEM_STRINGS             "bios-strings/oem-%d"
 
+/* Follows are XenStore keys for DM ACPI (ACPI built by device model,
+ * e.g. QEMU).
+ *
+ * A reserved area of guest physical memory is used to pass DM
+ * ACPI. Values of following two keys specify the base physical
+ * address and length (in bytes) of the reserved area.
+ */
+#define HVM_XS_DM_ACPI_ROOT            "hvmloader/dm-acpi"
+#define HVM_XS_DM_ACPI_ADDRESS         HVM_XS_DM_ACPI_ROOT"/address"
+#define HVM_XS_DM_ACPI_LENGTH          HVM_XS_DM_ACPI_ROOT"/length"
+
 #endif /* __XEN_PUBLIC_HVM_HVM_XS_STRINGS_H__ */
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#7 lore raw

RFC PATCH v2 7/15 tools/libacpi: expose the minimum alignment used by mem_ops.alloc

In reply to Haozhong Zhang

The AML builder added later requires this information to implement a memory allocator that can allocate contiguous memory across multiple calls to mem_ops.alloc().

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

Changes in v2:
* Only expose the minimal alignment.
* Rename min_alloc_align to min_alloc_byte_align to clarify the unit.

---
 tools/firmware/hvmloader/util.c | 2 ++
 tools/libacpi/libacpi.h         | 2 ++
 tools/libxl/libxl_x86_acpi.c    | 2 ++
 3 files changed, 6 insertions(+)
tools/firmware/hvmloader/util.c +2 -0
index 03cfb795d3..d289361317 100644
@@ -971,6 +971,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     ctxt.mem_ops.free = acpi_mem_free;
     ctxt.mem_ops.v2p = acpi_v2p;
 
+    ctxt.min_alloc_byte_align = 16;
+
     acpi_build_tables(&ctxt, config);
 
     hvm_param_set(HVM_PARAM_VM_GENERATION_ID_ADDR, config->vm_gid_addr);
tools/libacpi/libacpi.h +2 -0
index 67bd67fa0a..2049a1b032 100644
@@ -51,6 +51,8 @@ struct acpi_ctxt {
         void (*free)(struct acpi_ctxt *ctxt, void *v, uint32_t size);
         unsigned long (*v2p)(struct acpi_ctxt *ctxt, void *v);
     } mem_ops;
+
+    uint32_t min_alloc_byte_align; /* minimum alignment used by mem_ops.alloc */
 };
 
 struct acpi_config {
tools/libxl/libxl_x86_acpi.c +2 -0
index c0a6e321ec..f242450166 100644
@@ -183,6 +183,8 @@ int libxl__dom_load_acpi(libxl__gc *gc,
     libxl_ctxt.c.mem_ops.v2p = virt_to_phys;
     libxl_ctxt.c.mem_ops.free = acpi_mem_free;
 
+    libxl_ctxt.c.min_alloc_byte_align = 16;
+
     rc = init_acpi_config(gc, dom, b_info, &config);
     if (rc) {
         LOG(ERROR, "init_acpi_config failed (rc=%d)", rc);
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#8 lore raw

RFC PATCH v2 8/15 tools/libacpi: add callback acpi_ctxt.p2v to get a pointer from physical address

In reply to Haozhong Zhang

The address of ACPI blobs passed from device model is provided via XenStore as the physical address. libacpi needs this callback to access them.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/firmware/hvmloader/util.c |  6 ++++++
 tools/firmware/hvmloader/util.h |  1 +
 tools/libacpi/libacpi.h         |  1 +
 tools/libxl/libxl_x86_acpi.c    | 10 ++++++++++
 4 files changed, 18 insertions(+)
tools/firmware/hvmloader/util.c +6 -0
index d289361317..b2372a75be 100644
@@ -871,6 +871,11 @@ static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
     return virt_to_phys(v);
 }
 
+static void *acpi_p2v(struct acpi_ctxt *ctxt, unsigned long p)
+{
+    return phys_to_virt(p);
+}
+
 static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
                             uint32_t size, uint32_t align)
 {
@@ -970,6 +975,7 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     ctxt.mem_ops.alloc = acpi_mem_alloc;
     ctxt.mem_ops.free = acpi_mem_free;
     ctxt.mem_ops.v2p = acpi_v2p;
+    ctxt.mem_ops.p2v = acpi_p2v;
 
     ctxt.min_alloc_byte_align = 16;
 
tools/firmware/hvmloader/util.h +1 -0
index 6062f0b8cf..6a50dae1eb 100644
@@ -200,6 +200,7 @@ xen_pfn_t mem_hole_alloc(uint32_t nr_mfns);
 /* Allocate memory in a reserved region below 4GB. */
 void *mem_alloc(uint32_t size, uint32_t align);
 #define virt_to_phys(v) ((unsigned long)(v))
+#define phys_to_virt(p) ((void *)(p))
 
 /* Allocate memory in a scratch region */
 void *scratch_alloc(uint32_t size, uint32_t align);
tools/libacpi/libacpi.h +1 -0
index 2049a1b032..48acf9583c 100644
@@ -50,6 +50,7 @@ struct acpi_ctxt {
         void *(*alloc)(struct acpi_ctxt *ctxt, uint32_t size, uint32_t align);
         void (*free)(struct acpi_ctxt *ctxt, void *v, uint32_t size);
         unsigned long (*v2p)(struct acpi_ctxt *ctxt, void *v);
+        void *(*p2v)(struct acpi_ctxt *ctxt, unsigned long p);
     } mem_ops;
 
     uint32_t min_alloc_byte_align; /* minimum alignment used by mem_ops.alloc */
tools/libxl/libxl_x86_acpi.c +10 -0
index f242450166..2622e03ce6 100644
@@ -52,6 +52,15 @@ static unsigned long virt_to_phys(struct acpi_ctxt *ctxt, void *v)
             libxl_ctxt->alloc_base_paddr);
 }
 
+static void *phys_to_virt(struct acpi_ctxt *ctxt, unsigned long p)
+{
+    struct libxl_acpi_ctxt *libxl_ctxt =
+        CONTAINER_OF(ctxt, struct libxl_acpi_ctxt, c);
+
+    return (void *)((p - libxl_ctxt->alloc_base_paddr) +
+                    libxl_ctxt->alloc_base_vaddr);
+}
+
 static void *mem_alloc(struct acpi_ctxt *ctxt,
                        uint32_t size, uint32_t align)
 {
@@ -181,6 +190,7 @@ int libxl__dom_load_acpi(libxl__gc *gc,
 
     libxl_ctxt.c.mem_ops.alloc = mem_alloc;
     libxl_ctxt.c.mem_ops.v2p = virt_to_phys;
+    libxl_ctxt.c.mem_ops.p2v = phys_to_virt;
     libxl_ctxt.c.mem_ops.free = acpi_mem_free;
 
     libxl_ctxt.c.min_alloc_byte_align = 16;
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#9 lore raw

RFC PATCH v2 9/15 tools/libacpi: add callbacks to access XenStore

In reply to Haozhong Zhang

libacpi needs to access information placed in XenStore in order to load ACPI built by the device model.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

Changes in v2:
* Extract the common part of the existing xenstore_read() and the new xenstore_directory() in xenbus.c.

---
 tools/firmware/hvmloader/util.c   | 52 +++++++++++++++++++++++++++++++++++++++
 tools/firmware/hvmloader/util.h   |  9 +++++++
 tools/firmware/hvmloader/xenbus.c | 44 +++++++++++++++++++++++----------
 tools/libacpi/libacpi.h           | 10 ++++++++
 tools/libxl/libxl_x86_acpi.c      | 29 ++++++++++++++++++++++
 5 files changed, 131 insertions(+), 13 deletions(-)
tools/firmware/hvmloader/util.c +52 -0
index b2372a75be..ec0de711c2 100644
@@ -893,6 +893,53 @@ static uint8_t acpi_lapic_id(unsigned cpu)
     return LAPIC_ID(cpu);
 }
 
+static const char *acpi_xs_read(struct acpi_ctxt *ctxt, const char *path)
+{
+    return xenstore_read(path, NULL);
+}
+
+static int acpi_xs_write(struct acpi_ctxt *ctxt,
+                         const char *path, const char *value)
+{
+    return xenstore_write(path, value);
+}
+
+static unsigned int count_strings(const char *strings, unsigned int len)
+{
+    const char *p;
+    unsigned int n;
+
+    for ( p = strings, n = 0; p < strings + len; p++ )
+        if ( *p == '\0' )
+            n++;
+
+    return n;
+}
+
+static char **acpi_xs_directory(struct acpi_ctxt *ctxt,
+                                const char *path, unsigned int *num)
+{
+    const char *strings;
+    char *s, *p, **ret;
+    unsigned int len, n;
+
+    strings = xenstore_directory(path, &len, NULL);
+    if ( !strings )
+        return NULL;
+
+    n = count_strings(strings, len);
+    ret = ctxt->mem_ops.alloc(ctxt, n * sizeof(p) + len, 0);
+    if ( !ret )
+        return NULL;
+    memcpy(&ret[n], strings, len);
+
+    s = (char *)&ret[n];
+    for ( p = s, *num = 0; p < s + len; p += strlen(p) + 1 )
+        ret[(*num)++] = p;
+
+    return ret;
+}
+
 void hvmloader_acpi_build_tables(struct acpi_config *config,
                                  unsigned int physical)
 {
@@ -979,6 +1026,11 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
 
     ctxt.min_alloc_byte_align = 16;
 
+    ctxt.xs_ops.read = acpi_xs_read;
+    ctxt.xs_ops.write = acpi_xs_write;
+    ctxt.xs_ops.directory = acpi_xs_directory;
+    ctxt.xs_opaque = NULL;
+
     acpi_build_tables(&ctxt, config);
 
     hvm_param_set(HVM_PARAM_VM_GENERATION_ID_ADDR, config->vm_gid_addr);
tools/firmware/hvmloader/util.h +9 -0
index 6a50dae1eb..ac10a7106a 100644
@@ -225,6 +225,15 @@ const char *xenstore_read(const char *path, const char *default_resp);
  */
 int xenstore_write(const char *path, const char *value);
 
+/* Read a xenstore directory. Return NULL, or a nul-terminated string
+ * which contains all names of directory entries. Names are separated
+ * by '\0'. The returned string is in a static buffer, so only valid
+ * until the next xenstore/xenbus operation.  If @default_resp is
+ * specified, it is returned in preference to a NULL or empty string
+ * received from xenstore.
+ */
+const char *xenstore_directory(const char *path, uint32_t *len,
+                               const char *default_resp);
 
 /* Get a HVM param.
  */
tools/firmware/hvmloader/xenbus.c +31 -13

61 lines not on this page · raw message

tools/libacpi/libacpi.h +10 -0
index 48acf9583c..645e091f68 100644
@@ -54,6 +54,16 @@ struct acpi_ctxt {
     } mem_ops;
 
     uint32_t min_alloc_byte_align; /* minimum alignment used by mem_ops.alloc */
+
+    struct acpi_xs_ops {
+        const char *(*read)(struct acpi_ctxt *ctxt, const char *path);
+        int (*write)(struct acpi_ctxt *ctxt,
+                     const char *path, const char *value);
+        char **(*directory)(struct acpi_ctxt *ctxt,
+                            const char *path, unsigned int *num);
+    } xs_ops;
+
+    void *xs_opaque;
 };
 
 struct acpi_config {
tools/libxl/libxl_x86_acpi.c +29 -0
index 2622e03ce6..591a4f44fa 100644
@@ -93,6 +93,25 @@ static void acpi_mem_free(struct acpi_ctxt *ctxt,
 {
 }
 
+static const char *acpi_xs_read(struct acpi_ctxt *ctxt, const char *path)
+{
+    return libxl__xs_read((libxl__gc *)ctxt->xs_opaque, XBT_NULL, path);
+}
+
+static int acpi_xs_write(struct acpi_ctxt *ctxt,
+                         const char *path, const char *value)
+{
+    return libxl__xs_write_checked((libxl__gc *)ctxt->xs_opaque, XBT_NULL,
+                                   path, value);
+}
+
+static char **acpi_xs_directory(struct acpi_ctxt *ctxt,
+                                const char *path, unsigned int *num)
+{
+    return libxl__xs_directory((libxl__gc *)ctxt->xs_opaque, XBT_NULL,
+                               path, num);
+}
+
 static uint8_t acpi_lapic_id(unsigned cpu)
 {
     return cpu * 2;
@@ -195,6 +214,16 @@ int libxl__dom_load_acpi(libxl__gc *gc,
 
     libxl_ctxt.c.min_alloc_byte_align = 16;
 
+    libxl_ctxt.c.xs_ops.read = acpi_xs_read;
+    libxl_ctxt.c.xs_ops.write = acpi_xs_write;
+    libxl_ctxt.c.xs_ops.directory = acpi_xs_directory;
+    libxl_ctxt.c.xs_opaque = gc;
+
+    libxl_ctxt.c.xs_ops.read = acpi_xs_read;
+    libxl_ctxt.c.xs_ops.write = acpi_xs_write;
+    libxl_ctxt.c.xs_ops.directory = acpi_xs_directory;
+    libxl_ctxt.c.xs_opaque = gc;
+
     rc = init_acpi_config(gc, dom, b_info, &config);
     if (rc) {
         LOG(ERROR, "init_acpi_config failed (rc=%d)", rc);
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#10 lore raw

RFC PATCH v2 10/15 tools/libacpi: add a simple AML builder

In reply to Haozhong Zhang

It is used by libacpi to generate SSDTs from ACPI namespace devices built by the device model.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: [email protected]

Changes in v2:
* Add code comment for what is built by each function.
* Change the license to LGPL.

---
 tools/firmware/hvmloader/Makefile |   3 +-
 tools/libacpi/aml_build.c         | 326 ++++++++++++++++++++++++++++++++++++++
 tools/libacpi/aml_build.h         | 116 ++++++++++++++
 tools/libxl/Makefile              |   3 +-
 4 files changed, 446 insertions(+), 2 deletions(-)
 create mode 100644 tools/libacpi/aml_build.c
 create mode 100644 tools/libacpi/aml_build.h
tools/firmware/hvmloader/Makefile +2 -1
index 80d7b448a5..abbdaaeb40 100644
@@ -76,11 +76,12 @@ smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\""
 
 ACPI_PATH = ../../libacpi
 DSDT_FILES = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c
-ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o
+ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o aml_build.o
 $(ACPI_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\"
 CFLAGS += -I$(ACPI_PATH)
 vpath build.c $(ACPI_PATH)
 vpath static_tables.c $(ACPI_PATH)
+vpath aml_build.c $(ACPI_PATH)
 OBJS += $(ACPI_OBJS)
 
 hvmloader: $(OBJS)
tools/libacpi/aml_build.c new file +326 -0

326 lines not on this page · raw message

tools/libacpi/aml_build.h new file +116 -0

116 lines not on this page · raw message

tools/libxl/Makefile +2 -1
index f00d9ef355..a3e5e9909f 100644
@@ -77,11 +77,12 @@ endif
 
 ACPI_PATH  = $(XEN_ROOT)/tools/libacpi
 DSDT_FILES-$(CONFIG_X86) = dsdt_pvh.c
-ACPI_OBJS  = $(patsubst %.c,%.o,$(DSDT_FILES-y)) build.o static_tables.o
+ACPI_OBJS  = $(patsubst %.c,%.o,$(DSDT_FILES-y)) build.o static_tables.o aml_build.o
 $(DSDT_FILES-y): acpi
 $(ACPI_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/libxl_x86_acpi.h\"
 vpath build.c $(ACPI_PATH)/
 vpath static_tables.c $(ACPI_PATH)/
+vpath aml_build.c $(ACPI_PATH)/
 LIBXL_OBJS-$(CONFIG_X86) += $(ACPI_OBJS)
 
 .PHONY: acpi
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#11 lore raw

RFC PATCH v2 11/15 tools/libacpi: load ACPI built by the device model

In reply to Haozhong Zhang

ACPI tables built by the device model, whose signatures do not conflict with tables built by Xen (except SSDT), are loaded after ACPI tables built by Xen.

ACPI namespace devices built by the device model, whose names do not conflict with devices built by Xen, are assembled and placed in SSDTs after ACPI tables built by Xen.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

Changes in v2:
* Add dm_acpi_{signature, devname}_blacklist_register() to let each acpi construct function register tables and namespace devices that should not be loaded from DM ACPI.

---
 tools/firmware/hvmloader/util.c |  15 ++
 tools/libacpi/acpi2_0.h         |   2 +
 tools/libacpi/build.c           | 311 ++++++++++++++++++++++++++++++++++++++++
 tools/libacpi/libacpi.h         |   8 ++
 4 files changed, 336 insertions(+)
tools/firmware/hvmloader/util.c +15 -0
index ec0de711c2..295b748829 100644
@@ -1000,6 +1000,21 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,
     if ( !strncmp(xenstore_read("platform/acpi_s4", "1"), "1", 1)  )
         config->table_flags |= ACPI_HAS_SSDT_S4;
 
+    s = xenstore_read(HVM_XS_DM_ACPI_ADDRESS, NULL);
+    if ( s )
+    {
+        config->dm.addr = strtoll(s, NULL, 0);
+
+        s = xenstore_read(HVM_XS_DM_ACPI_LENGTH, NULL);
+        if ( s )
+        {
+            config->dm.length = strtoll(s, NULL, 0);
+            config->table_flags |= ACPI_HAS_DM;
+        }
+        else
+            config->dm.addr = 0;
+    }
+
     config->table_flags |= (ACPI_HAS_TCPA | ACPI_HAS_IOAPIC |
                             ACPI_HAS_WAET | ACPI_HAS_PMTIMER |
                             ACPI_HAS_BUTTONS | ACPI_HAS_VGA |
tools/libacpi/acpi2_0.h +2 -0
index 2619ba32db..365825e6bc 100644
@@ -435,6 +435,7 @@ struct acpi_20_slit {
 #define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')
 #define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')
 #define ACPI_2_0_SLIT_SIGNATURE ASCII32('S','L','I','T')
+#define ACPI_2_0_SSDT_SIGNATURE ASCII32('S','S','D','T')
 
 /*
  * Table revision numbers.
@@ -449,6 +450,7 @@ struct acpi_20_slit {
 #define ACPI_1_0_FADT_REVISION 0x01
 #define ACPI_2_0_SRAT_REVISION 0x01
 #define ACPI_2_0_SLIT_REVISION 0x01
+#define ACPI_2_0_SSDT_REVISION 0x02
 
 #pragma pack ()
 
tools/libacpi/build.c +311 -0

418 lines not on this page · raw message

tools/libacpi/libacpi.h +8 -0
index 645e091f68..b41113ff3f 100644
@@ -20,6 +20,8 @@
 #ifndef __LIBACPI_H__
 #define __LIBACPI_H__
 
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
 #define ACPI_HAS_COM1        (1<<0)
 #define ACPI_HAS_COM2        (1<<1)
 #define ACPI_HAS_LPT1        (1<<2)
@@ -35,6 +37,7 @@
 #define ACPI_HAS_VGA         (1<<12)
 #define ACPI_HAS_8042        (1<<13)
 #define ACPI_HAS_CMOS_RTC    (1<<14)
+#define ACPI_HAS_DM          (1<<15)
 
 struct xen_vmemrange;
 struct acpi_numa {
@@ -87,6 +90,11 @@ struct acpi_config {
         uint32_t length;
     } pt;
 
+    struct {
+        uint32_t addr;
+        uint32_t length;
+    } dm;
+
     struct acpi_numa numa;
     const struct hvm_info_table *hvminfo;
 
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

RFC PATCH v2 12/15 tools/libxl: build qemu options from xl vNVDIMM configs

In reply to Haozhong Zhang

For xl configs
vnvdimms = [ '/path/to/pmem0', '/path/to/pmem1', ... ]

the following qemu options are built
-machine <existing options>,nvdimm
-m <existing options>,slots=$NR_SLOTS,maxmem=$MEM_SIZE
-object memory-backend-xen,id=mem1,size=$PMEM0_SIZE,mem-path=/path/to/pmem0 -device nvdimm,id=nvdimm1,memdev=mem1
-object memory-backend-xen,id=mem2,size=$PMEM1_SIZE,mem-path=/path/to/pmem1 -device nvdimm,id=nvdimm2,memdev=mem2
...
where
- NR_SLOTS is the number of entries in vnvdimms + 1,
- MEM_SIZE is the total size of all RAM and NVDIMM devices,
- PMEM#_SIZE is the size of the host pmem device/file '/path/to/pmem#'.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

The qemu option "-object memory-backend-xen" is added by the QEMU patch "hostmem: add a host memory backend for Xen". Other qemu options have been implemented since QEMU 2.6.0.

Changes in v2:
* Update the manpage of xl.cfg for the new option "vnvdimms".

---
 docs/man/xl.cfg.pod.5.in    |   6 +++
 tools/libxl/libxl_dm.c      | 109 +++++++++++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_types.idl |   8 ++++
 tools/xl/xl_parse.c         |  16 +++++++
 4 files changed, 137 insertions(+), 2 deletions(-)
docs/man/xl.cfg.pod.5.in +6 -0
index 505c11137f..53296595ff 100644
@@ -1064,6 +1064,12 @@ FIFO-based event channel ABI support up to 131,071 event channels.
 Other guests are limited to 4095 (64-bit x86 and ARM) or 1023 (32-bit
 x86).
 
+=item B<vnvdimms=[ 'PATH0', 'PATH1', ... ]>
+
+Specify the virtual NVDIMM devices which are provided to the guest.
+B<PATH0>, B<PATH1>, ... specify the host NVDIMM pmem devices which are used
+as the backend storage of each virtual NVDIMM device.
+
 =back
 
 =head2 Paravirtualised (PV) Guest Specific Options
tools/libxl/libxl_dm.c +107 -2

146 lines not on this page · raw message

tools/libxl/libxl_types.idl +8 -0
index a612d1f4ff..e1a3fd9279 100644
@@ -704,6 +704,13 @@ libxl_device_channel = Struct("device_channel", [
            ])),
 ])
 
+libxl_device_vnvdimm = Struct("device_vnvdimm", [
+    ("backend_domid",   libxl_domid),
+    ("backend_domname", string),
+    ("devid",           libxl_devid),
+    ("file",            string),
+])
+
 libxl_domain_config = Struct("domain_config", [
     ("c_info", libxl_domain_create_info),
     ("b_info", libxl_domain_build_info),
@@ -721,6 +728,7 @@ libxl_domain_config = Struct("domain_config", [
     ("channels", Array(libxl_device_channel, "num_channels")),
     ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")),
     ("usbdevs", Array(libxl_device_usbdev, "num_usbdevs")),
+    ("vnvdimms", Array(libxl_device_vnvdimm, "num_vnvdimms")),
 
     ("on_poweroff", libxl_action_on_shutdown),
     ("on_reboot", libxl_action_on_shutdown),
tools/xl/xl_parse.c +16 -0
index 1ef0c272a8..2cf8c9756b 100644
@@ -718,6 +718,7 @@ void parse_config_data(const char *config_source,
     XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms,
                    *usbctrls, *usbdevs;
     XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs;
+    XLU_ConfigList *vnvdimms;
     int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 0;
@@ -1902,6 +1903,21 @@ skip_usbdev:
         }
      }
 
+    if (!xlu_cfg_get_list (config, "vnvdimms", &vnvdimms, 0, 0)) {
+#if defined(__linux__)
+        while ((buf = xlu_cfg_get_listitem(vnvdimms,
+                                           d_config->num_vnvdimms)) != NULL) {
+            libxl_device_vnvdimm *vnvdimm =
+                ARRAY_EXTEND_INIT(d_config->vnvdimms, d_config->num_vnvdimms,
+                                  libxl_device_vnvdimm_init);
+            vnvdimm->file = strdup(buf);
+        }
+#else
+        fprintf(stderr, "ERROR: vnvdimms is only supported on Linux\n");
+        exit(-ERROR_FAIL);
+#endif /* __linux__ */
+    }
+
     xlu_cfg_destroy(config);
 }
 
Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#13 lore raw

RFC PATCH v2 13/15 tools/libxl: add support to map host pmem device to guests

In reply to Haozhong Zhang

We can map host pmem devices or files on pmem devices to guests. This patch adds support to map pmem devices. The implementation relies on the Linux pmem driver (CONFIG_ACPI_NFIT, CONFIG_LIBNVDIMM, CONFIG_BLK_DEV_PMEM), so it functions only when libxl is compiled for Linux right now.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxl/Makefile       |   4 +
 tools/libxl/libxl_nvdimm.c | 182 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_nvdimm.h |  42 +++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 tools/libxl/libxl_nvdimm.c
 create mode 100644 tools/libxl/libxl_nvdimm.h
tools/libxl/Makefile +4 -0
index a3e5e9909f..6bfc78972f 100644
@@ -115,6 +115,10 @@ endif
 endif
 endif
 
+ifeq ($(CONFIG_Linux), y)
+LIBXL_OBJS-y += libxl_nvdimm.o
+endif
+
 ifeq ($(FLEX),)
 %.c %.h:: %.l
 	$(warning Flex is needed to rebuild some libxl parsers and \
tools/libxl/libxl_nvdimm.c new file +182 -0

182 lines not on this page · raw message

tools/libxl/libxl_nvdimm.h new file +42 -0

42 lines not on this page · raw message

Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#14 lore raw

RFC PATCH v2 14/15 tools/libxl: initiate pmem mapping via qmp callback

In reply to Haozhong Zhang

Get the backend device, the guest SPA and the size of each vNVDIMM device via QMP commands "query-memory-device devtype=nvdimm" and "qom-get", and pass them to libxl to map each backend device to guest.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

Changes in v2:
* Fail the domain creation if QMP initialization for NVDIMM fails. Other failures in QMP initialization do not fail the domain creation as before.

---
 tools/libxl/libxl_create.c |   4 +-
 tools/libxl/libxl_qmp.c    | 116 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 117 insertions(+), 3 deletions(-)
tools/libxl/libxl_create.c +3 -1
index e741b9a39a..b8c867d0fa 100644
@@ -1510,7 +1510,9 @@ static void domcreate_devmodel_started(libxl__egc *egc,
     if (dcs->sdss.dm.guest_domid) {
         if (d_config->b_info.device_model_version
             == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
-            libxl__qmp_initializations(gc, domid, d_config);
+            ret = libxl__qmp_initializations(gc, domid, d_config);
+            if (ret == ERROR_BADFAIL)
+                goto error_out;
         }
     }
 
tools/libxl/libxl_qmp.c +114 -2

145 lines not on this page · raw message

Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#15 lore raw

RFC PATCH v2 15/15 tools/misc: add xen-ndctl

In reply to Haozhong Zhang

xen-ndctl is a tool for users in Dom0 to setup the host pmem with Xen hypervisor. It's used to specify the storage, which is either the regular RAM or a pmem range, to manage the specified pmem.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 .gitignore             |   1 +
 tools/misc/Makefile    |   4 +
 tools/misc/xen-ndctl.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 232 insertions(+)
.gitignore +1 -0
index 4567de7a59..1af7cda8bd 100644
@@ -206,6 +206,7 @@ tools/misc/xen-hvmctx
 tools/misc/xenlockprof
 tools/misc/lowmemd
 tools/misc/xencov
+tools/misc/xen-ndctl
 tools/pkg-config/*
 tools/qemu-xen-build
 tools/xentrace/xenalyze
tools/misc/Makefile +4 -0
index 8152f7bfb5..86d89f1577 100644
@@ -31,6 +31,7 @@ INSTALL_SBIN                   += xenperf
 INSTALL_SBIN                   += xenpm
 INSTALL_SBIN                   += xenwatchdogd
 INSTALL_SBIN                   += xen-livepatch
+INSTALL_SBIN                   += xen-ndctl
 INSTALL_SBIN += $(INSTALL_SBIN-y)
 
 # Everything to be installed in a private bin/
@@ -108,4 +109,7 @@ xen-lowmemd: xen-lowmemd.o
 xencov: xencov.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
+xen-ndctl: xen-ndctl.o
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+
 -include $(DEPS)
tools/misc/xen-ndctl.c +227 -0

227 lines not on this page · raw message

Signature · 7 lines
2.12.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#16 lore raw

Re: [RFC XEN PATCH v2 15/15] tools/misc: add xen-ndctl

Quoted 9 lines · Haozhong Zhang

xen-ndctl is a tool for users in Dom0 to setup the host pmem with Xen hypervisor. It's used to specify the storage, which is either the regular RAM or a pmem range, to manage the specified pmem.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
---

I would be open to moving this tooling into upstream ndctl [1]. Especially since you're reusing the same name it would be confusing to have 2 ndctl tools.

[1]: https://github.com/pmem/ndctl

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [RFC XEN PATCH v2 15/15] tools/misc: add xen-ndctl

Quoted 12 lines · Dan Williams
Quoted 9 lines · Haozhong Zhang

xen-ndctl is a tool for users in Dom0 to setup the host pmem with Xen hypervisor. It's used to specify the storage, which is either the regular RAM or a pmem range, to manage the specified pmem.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
---

Quoted 5 lines

I would be open to moving this tooling into upstream ndctl [1]. Especially since you're reusing the same name it would be confusing to have 2 ndctl tools.

[1]: https://github.com/pmem/ndctl

Then it could leverage existing code in ndctl (e.g. getting parameters from a device name rather than using address in my current implementation).

I'm not sure about Xen's policy whether a tool should be included in Xen or can be left in 3rd party program. Let's wait for Xen maintainers' reply.

Thanks,
Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw

Re: [RFC XEN PATCH v2 15/15] tools/misc: add xen-ndctl

Quoted 17 lines · Haozhong Zhang
Quoted 16 lines · Dan Williams
Quoted 9 lines · Haozhong Zhang

xen-ndctl is a tool for users in Dom0 to setup the host pmem with Xen hypervisor. It's used to specify the storage, which is either the regular RAM or a pmem range, to manage the specified pmem.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
---

I would be open to moving this tooling into upstream ndctl [1]. Especially since you're reusing the same name it would be confusing to have 2 ndctl tools.

Quoted 7 lines
Quoted 1 line

[1]: https://github.com/pmem/ndctl

Then it could leverage existing code in ndctl (e.g. getting parameters from a device name rather than using address in my current implementation).

I'm not sure about Xen's policy whether a tool should be included in Xen or can be left in 3rd party program. Let's wait for Xen maintainers' reply.

No problems. For example QEMU has it (it has an configure to detect the headers and then uses xc_XYZ calls). Also kexec-tools does it as well.

The big thing that you have to keep in mind is to make the hypercall as future proof as possible - so you don't have #ifdef all over the code.

Quoted 3 lines

Thanks,
Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#19 lore raw
In reply to Haozhong Zhang
Quoted 34 lines · Haozhong Zhang

This is v2 RFC patch series to add vNVDIMM support to HVM domains.
v1 can be found at https://lists.xenproject.org/archives/html/xen-devel/2016-10/msg00424.html.

No label and no _DSM except function 0 "query implemented functions" is supported by this version, but they will be added by future patches.

The corresponding Qemu patch series is sent in another thread "[RFC QEMU PATCH v2 00/10] Implement vNVDIMM for Xen HVM guest".

All patch series can be found at
Xen: https://github.com/hzzhan9/xen.git nvdimm-rfc-v2
Qemu: https://github.com/hzzhan9/qemu.git xen-nvdimm-rfc-v2

Changes in v2
==============

- One of the primary changes in v2 is dropping the linux kernel patches, which were used to reserve on host pmem for placing its frametable and M2P table. In v2, we add a management tool xen-ndctl which is used in Dom0 to notify Xen hypervisor of which storage can be used to manage the host pmem.

For example,
1. xen-ndctl setup 0x240000 0x380000 0x380000 0x3c0000
tells Xen hypervisor to use host pmem pages at MFN 0x380000 ~ 0x3c0000 to manage host pmem pages at MFN 0x240000 ~ 0x380000. I.e. the former is used to place the frame table and M2P table of both ranges of pmem pages.

2. xen-ndctl setup 0x240000 0x380000
tells Xen hypervisor to use the regular RAM to manage the host pmem pages at MFN 0x240000 ~ 0x380000. I.e the regular RMA is used to place the frame table and M2P table.

Quoted 5 lines

- Another primary change in v2 is dropping the support to map files on the host pmem to HVM domains as virtual NVDIMMs, as I cannot find a stable to fix the fiemap of host files. Instead, we can rely on the ability added in Linux kernel v4.9 that enables creating multiple pmem namespaces on a single nvdimm interleave set.

This restriction is unfortunate, and it seems to limit the future architecture of the pmem driver. We may not always be able to guarantee a contiguous physical address range to Xen for a given namespace and may want to concatenate disjoint physical address ranges into a logically contiguous namespace.

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#20 lore raw
Quoted 42 lines · Dan Williams
Quoted 34 lines · Haozhong Zhang

This is v2 RFC patch series to add vNVDIMM support to HVM domains.
v1 can be found at https://lists.xenproject.org/archives/html/xen-devel/2016-10/msg00424.html.

No label and no _DSM except function 0 "query implemented functions" is supported by this version, but they will be added by future patches.

The corresponding Qemu patch series is sent in another thread "[RFC QEMU PATCH v2 00/10] Implement vNVDIMM for Xen HVM guest".

All patch series can be found at
Xen: https://github.com/hzzhan9/xen.git nvdimm-rfc-v2
Qemu: https://github.com/hzzhan9/qemu.git xen-nvdimm-rfc-v2

Changes in v2
==============

- One of the primary changes in v2 is dropping the linux kernel patches, which were used to reserve on host pmem for placing its frametable and M2P table. In v2, we add a management tool xen-ndctl which is used in Dom0 to notify Xen hypervisor of which storage can be used to manage the host pmem.

For example,
1. xen-ndctl setup 0x240000 0x380000 0x380000 0x3c0000
tells Xen hypervisor to use host pmem pages at MFN 0x380000 ~ 0x3c0000 to manage host pmem pages at MFN 0x240000 ~ 0x380000. I.e. the former is used to place the frame table and M2P table of both ranges of pmem pages.

2. xen-ndctl setup 0x240000 0x380000
tells Xen hypervisor to use the regular RAM to manage the host pmem pages at MFN 0x240000 ~ 0x380000. I.e the regular RMA is used to place the frame table and M2P table.

Quoted 5 lines

- Another primary change in v2 is dropping the support to map files on the host pmem to HVM domains as virtual NVDIMMs, as I cannot find a stable to fix the fiemap of host files. Instead, we can rely on the ability added in Linux kernel v4.9 that enables creating multiple pmem namespaces on a single nvdimm interleave set.

Quoted 6 lines

This restriction is unfortunate, and it seems to limit the future architecture of the pmem driver. We may not always be able to guarantee a contiguous physical address range to Xen for a given namespace and may want to concatenate disjoint physical address ranges into a logically contiguous namespace.

The hypervisor code that actual maps host pmem address to guest does not require the host address be contiguous. We can modify the toolstack code that get the address range from a namespace to support passing multiple address ranges to Xen hypervisor

Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Haozhong

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#21 lore raw
Quoted 58 lines · Haozhong Zhang
Quoted 42 lines · Dan Williams
Quoted 34 lines · Haozhong Zhang

This is v2 RFC patch series to add vNVDIMM support to HVM domains.
v1 can be found at https://lists.xenproject.org/archives/html/xen-devel/2016-10/msg00424.html.

No label and no _DSM except function 0 "query implemented functions" is supported by this version, but they will be added by future patches.

The corresponding Qemu patch series is sent in another thread "[RFC QEMU PATCH v2 00/10] Implement vNVDIMM for Xen HVM guest".

All patch series can be found at
Xen: https://github.com/hzzhan9/xen.git nvdimm-rfc-v2
Qemu: https://github.com/hzzhan9/qemu.git xen-nvdimm-rfc-v2

Changes in v2
==============

- One of the primary changes in v2 is dropping the linux kernel patches, which were used to reserve on host pmem for placing its frametable and M2P table. In v2, we add a management tool xen-ndctl which is used in Dom0 to notify Xen hypervisor of which storage can be used to manage the host pmem.

For example,
1. xen-ndctl setup 0x240000 0x380000 0x380000 0x3c0000
tells Xen hypervisor to use host pmem pages at MFN 0x380000 ~ 0x3c0000 to manage host pmem pages at MFN 0x240000 ~ 0x380000. I.e. the former is used to place the frame table and M2P table of both ranges of pmem pages.

2. xen-ndctl setup 0x240000 0x380000
tells Xen hypervisor to use the regular RAM to manage the host pmem pages at MFN 0x240000 ~ 0x380000. I.e the regular RMA is used to place the frame table and M2P table.

Quoted 5 lines

- Another primary change in v2 is dropping the support to map files on the host pmem to HVM domains as virtual NVDIMMs, as I cannot find a stable to fix the fiemap of host files. Instead, we can rely on the ability added in Linux kernel v4.9 that enables creating multiple pmem namespaces on a single nvdimm interleave set.

Quoted 6 lines

This restriction is unfortunate, and it seems to limit the future architecture of the pmem driver. We may not always be able to guarantee a contiguous physical address range to Xen for a given namespace and may want to concatenate disjoint physical address ranges into a logically contiguous namespace.

The hypervisor code that actual maps host pmem address to guest does not require the host address be contiguous. We can modify the toolstack code that get the address range from a namespace to support passing multiple address ranges to Xen hypervisor

Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

Quoted 10 lines

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Thanks, but what I don't understand is why this M2P lookup is needed? Does Xen establish this metadata for PCI mmio ranges as well? What Xen memory management operations does this enable? Sorry if these are basic Xen questions, I'm just looking to see if we can make the mapping support more dynamic. For example, what if we wanted to change the MFN to guest PFN relationship after every fault?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#22 lore raw

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

Quoted 4 lines

memory management operations does this enable? Sorry if these are basic Xen questions, I'm just looking to see if we can make the mapping support more dynamic. For example, what if we wanted to change the MFN to guest PFN relationship after every fault?

As in swap it out? (Like a hard drive swaps out faulty sectors?). That is certainly done. We also have tools (xen-hptool) that can mark certain pages as broken/etc and inject the MCEs in the guest to reflect that. But all of that is driven by hypercalls

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#23 lore raw
Quoted 17 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Quoted 7 lines

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

So, I'm confused again. This patchset / enabling requires both M2P and contiguous PMEM ranges. If the PMEM is contiguous it seems you don't need M2P and can just reuse the MMIO enabling, or am I missing something?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#24 lore raw
Quoted 22 lines · Dan Williams
Quoted 21 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

Quoted 8 lines
Quoted 3 lines

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

So, I'm confused again. This patchset / enabling requires both M2P and contiguous PMEM ranges. If the PMEM is contiguous it seems you don't need M2P and can just reuse the MMIO enabling, or am I missing something?

I think I am confusing you.

The patchset (specifically 04/15] xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem ) adds a hypercall to tell Xen where on the NVDIMM it can put
the M2P array and as well the frametables ('struct page').

There is no range support. The reason is that if break up
an NVDIMM in various chunks (and then put a filesystem on top of it) - and then figure out which of the SPAs belong to the file - and then "expose" that file to a guest as NVDIMM - it's SPAs won't
be contingous. Hence the hypervisor would need to break down the 'ranges' structure down in either a bitmap or an M2P
and also store it. This can get quite tricky so you may
as well just start with an M2P and 'struct page'.

The placement of those datastructures is "
v2 patch
series relies on users/admins in Dom0 instead of Dom0 driver to indicate the location to store the frametable and M2P of pmem.
"

Hope this helps?

Quoted 5 lines

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#25 lore raw
Quoted 38 lines · Konrad Rzeszutek Wilk
Quoted 22 lines · Dan Williams
Quoted 21 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

Quoted 8 lines
Quoted 3 lines

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

So, I'm confused again. This patchset / enabling requires both M2P and contiguous PMEM ranges. If the PMEM is contiguous it seems you don't need M2P and can just reuse the MMIO enabling, or am I missing something?

I think I am confusing you.

The patchset (specifically 04/15] xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem ) adds a hypercall to tell Xen where on the NVDIMM it can put
the M2P array and as well the frametables ('struct page').

Quoted 8 lines

There is no range support. The reason is that if break up
an NVDIMM in various chunks (and then put a filesystem on top of it) - and then figure out which of the SPAs belong to the file - and then "expose" that file to a guest as NVDIMM - it's SPAs won't
be contingous. Hence the hypervisor would need to break down the 'ranges' structure down in either a bitmap or an M2P
and also store it. This can get quite tricky so you may
as well just start with an M2P and 'struct page'.

Ok... but the problem then becomes that the filesystem is free to change the file-offset to SPA mapping any time it wants. So the M2P support is broken if it expects static relationships.

Quoted 7 lines

The placement of those datastructures is "
v2 patch
series relies on users/admins in Dom0 instead of Dom0 driver to indicate the location to store the frametable and M2P of pmem.
"

Hope this helps?

It does, but it still seems we're stuck between either 1/ not needing M2P if we can pass a whole pmem-namespace through to the guest or 2/ M2P being broken by non-static file-offset to physical address mappings.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#26 lore raw
Quoted 49 lines · Dan Williams
Quoted 38 lines · Konrad Rzeszutek Wilk
Quoted 22 lines · Dan Williams
Quoted 21 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

Quoted 8 lines
Quoted 3 lines

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

So, I'm confused again. This patchset / enabling requires both M2P and contiguous PMEM ranges. If the PMEM is contiguous it seems you don't need M2P and can just reuse the MMIO enabling, or am I missing something?

I think I am confusing you.

The patchset (specifically 04/15] xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem ) adds a hypercall to tell Xen where on the NVDIMM it can put
the M2P array and as well the frametables ('struct page').

Quoted 8 lines

There is no range support. The reason is that if break up
an NVDIMM in various chunks (and then put a filesystem on top of it) - and then figure out which of the SPAs belong to the file - and then "expose" that file to a guest as NVDIMM - it's SPAs won't
be contingous. Hence the hypervisor would need to break down the 'ranges' structure down in either a bitmap or an M2P
and also store it. This can get quite tricky so you may
as well just start with an M2P and 'struct page'.

Quoted 3 lines

Ok... but the problem then becomes that the filesystem is free to change the file-offset to SPA mapping any time it wants. So the M2P support is broken if it expects static relationships.

Can't you flock an file and that will freeze it? Or mlock it since one is rather mmap-ing it?

Quoted 7 lines
Quoted 7 lines

The placement of those datastructures is "
v2 patch
series relies on users/admins in Dom0 instead of Dom0 driver to indicate the location to store the frametable and M2P of pmem.
"

Quoted 6 lines
Quoted 1 line

Hope this helps?

It does, but it still seems we're stuck between either 1/ not needing M2P if we can pass a whole pmem-namespace through to the guest or 2/ M2P being broken by non-static file-offset to physical address mappings.

Aye. So how can 2/ be fixed? I am assuming you would have the same issue with KVM - if the file is 'moving' underneath (and the file-offset to SPA has changed) won't that affect the EPT and other page entries?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#27 lore raw
Quoted 50 lines · Konrad Rzeszutek Wilk
Quoted 49 lines · Dan Williams
Quoted 46 lines · Konrad Rzeszutek Wilk
Quoted 22 lines · Dan Williams
Quoted 21 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

Quoted 8 lines
Quoted 3 lines

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

So, I'm confused again. This patchset / enabling requires both M2P and contiguous PMEM ranges. If the PMEM is contiguous it seems you don't need M2P and can just reuse the MMIO enabling, or am I missing something?

I think I am confusing you.

The patchset (specifically 04/15] xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem ) adds a hypercall to tell Xen where on the NVDIMM it can put
the M2P array and as well the frametables ('struct page').

There is no range support. The reason is that if break up
an NVDIMM in various chunks (and then put a filesystem on top of it) - and then figure out which of the SPAs belong to the file - and then "expose" that file to a guest as NVDIMM - it's SPAs won't
be contingous. Hence the hypervisor would need to break down the 'ranges' structure down in either a bitmap or an M2P
and also store it. This can get quite tricky so you may
as well just start with an M2P and 'struct page'.

Quoted 6 lines
Quoted 3 lines

Ok... but the problem then becomes that the filesystem is free to change the file-offset to SPA mapping any time it wants. So the M2P support is broken if it expects static relationships.

Can't you flock an file and that will freeze it? Or mlock it since one is rather mmap-ing it?

Unfortunately no. This dovetails with the discussion we have been having with filesystem folks about the need to call msync() after every write. Whenever the filesystem sees a write fault it is free to move blocks around in the file, think allocation or copy-on-write operations like reflink. The filesystem depends on the application calling msync/fsync before it makes the writes from those faults durable against crash / powerloss. Also, actions like online defrag can change these offset to physical address relationships without any involvement from the application. There's currently no mechanism to lock out this behavior because the filesystem assumes that it can just invalidate mappings to make the application re-fault.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

The placement of those datastructures is "
v2 patch
series relies on users/admins in Dom0 instead of Dom0 driver to indicate the location to store the frametable and M2P of pmem.
"

Hope this helps?

Quoted 8 lines
Quoted 4 lines

It does, but it still seems we're stuck between either 1/ not needing M2P if we can pass a whole pmem-namespace through to the guest or 2/ M2P being broken by non-static file-offset to physical address mappings.

Aye. So how can 2/ be fixed? I am assuming you would have the same issue with KVM - if the file is 'moving' underneath (and the file-offset to SPA has changed) won't that affect the EPT and other page entries?

I don't think KVM has the same issue, but honestly I don't have the full mental model of how KVM supports mmap. I've at least been able to run a guest where the "pmem" is just dynamic page cache on the host side so the physical memory mapping is changing all the time due to swap. KVM does not have this third-party M2P mapping table to keep up to date so I assume it is just handled by the standard mmap support for establishing a guest physical address range and the standard mapping-invalidate + remap mechanism just works.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#28 lore raw
Quoted 89 lines · Dan Williams
Quoted 50 lines · Konrad Rzeszutek Wilk
Quoted 49 lines · Dan Williams
Quoted 46 lines · Konrad Rzeszutek Wilk
Quoted 22 lines · Dan Williams
Quoted 21 lines · Konrad Rzeszutek Wilk

..snip..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

Is there a resource I can read more about why the hypervisor needs to have this M2P mapping for nvdimm support?

M2P is basically an array of frame numbers. It's indexed by the host page frame number, or the machine frame number (MFN) in Xen's definition. The n'th entry records the guest page frame number that is mapped to MFN n. M2P is one of the core data structures used in Xen memory management, and is used to convert MFN to guest PFN. A read-only version of M2P is also exposed as part of ABI to guest. In the previous design discussion, we decided to put the management of NVDIMM in the existing Xen memory management as much as possible, so we need to build M2P for NVDIMM as well.

Quoted 1 line

Thanks, but what I don't understand is why this M2P lookup is needed?

Xen uses it to construct the EPT page tables for the guests.

Quoted 1 line

Does Xen establish this metadata for PCI mmio ranges as well? What Xen

Quoted 8 lines
Quoted 3 lines

It doesn't have that (M2P) for PCI MMIO ranges. For those it has an ranges construct (since those are usually contingous and given in ranges to a guest).

So, I'm confused again. This patchset / enabling requires both M2P and contiguous PMEM ranges. If the PMEM is contiguous it seems you don't need M2P and can just reuse the MMIO enabling, or am I missing something?

I think I am confusing you.

The patchset (specifically 04/15] xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem ) adds a hypercall to tell Xen where on the NVDIMM it can put
the M2P array and as well the frametables ('struct page').

There is no range support. The reason is that if break up
an NVDIMM in various chunks (and then put a filesystem on top of it) - and then figure out which of the SPAs belong to the file - and then "expose" that file to a guest as NVDIMM - it's SPAs won't
be contingous. Hence the hypervisor would need to break down the 'ranges' structure down in either a bitmap or an M2P
and also store it. This can get quite tricky so you may
as well just start with an M2P and 'struct page'.

Quoted 6 lines
Quoted 3 lines

Ok... but the problem then becomes that the filesystem is free to change the file-offset to SPA mapping any time it wants. So the M2P support is broken if it expects static relationships.

Can't you flock an file and that will freeze it? Or mlock it since one is rather mmap-ing it?

Unfortunately no. This dovetails with the discussion we have been having with filesystem folks about the need to call msync() after every write. Whenever the filesystem sees a write fault it is free to move blocks around in the file, think allocation or copy-on-write operations like reflink. The filesystem depends on the application calling msync/fsync before it makes the writes from those faults durable against crash / powerloss. Also, actions like online defrag can change these offset to physical address relationships without any involvement from the application. There's currently no mechanism to lock out this behavior because the filesystem assumes that it can just invalidate mappings to make the application re-fault.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

The placement of those datastructures is "
v2 patch
series relies on users/admins in Dom0 instead of Dom0 driver to indicate the location to store the frametable and M2P of pmem.
"

Hope this helps?

Quoted 8 lines
Quoted 4 lines

It does, but it still seems we're stuck between either 1/ not needing M2P if we can pass a whole pmem-namespace through to the guest or 2/ M2P being broken by non-static file-offset to physical address mappings.

Aye. So how can 2/ be fixed? I am assuming you would have the same issue with KVM - if the file is 'moving' underneath (and the file-offset to SPA has changed) won't that affect the EPT and other page entries?

Quoted 8 lines

I don't think KVM has the same issue, but honestly I don't have the full mental model of how KVM supports mmap. I've at least been able to run a guest where the "pmem" is just dynamic page cache on the host side so the physical memory mapping is changing all the time due to swap. KVM does not have this third-party M2P mapping table to keep up to date so I assume it is just handled by the standard mmap support for establishing a guest physical address range and the standard mapping-invalidate + remap mechanism just works.

Could it be possible to have an Xen driver that would listen on these notifications and percolate those changes this driver. Then this driver would make the appropiate hypercalls to update the M2P ?

That would solve the 2/ I think?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#29 lore raw
Quoted 9 lines
Quoted 8 lines

I don't think KVM has the same issue, but honestly I don't have the full mental model of how KVM supports mmap. I've at least been able to run a guest where the "pmem" is just dynamic page cache on the host side so the physical memory mapping is changing all the time due to swap. KVM does not have this third-party M2P mapping table to keep up to date so I assume it is just handled by the standard mmap support for establishing a guest physical address range and the standard mapping-invalidate + remap mechanism just works.

Quoted 5 lines

Could it be possible to have an Xen driver that would listen on these notifications and percolate those changes this driver. Then this driver would make the appropiate hypercalls to update the M2P ?

That would solve the 2/ I think?

I think that could work. That sounds like userfaultfd support for DAX which is something I want to take a look at in the next couple kernel cycles for other reasons like live migration of guest-VMs with DAX mappings.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#30 lore raw
Quoted 13 lines · Dan Williams
Quoted 13 lines
Quoted 8 lines

I don't think KVM has the same issue, but honestly I don't have the full mental model of how KVM supports mmap. I've at least been able to run a guest where the "pmem" is just dynamic page cache on the host side so the physical memory mapping is changing all the time due to swap. KVM does not have this third-party M2P mapping table to keep up to date so I assume it is just handled by the standard mmap support for establishing a guest physical address range and the standard mapping-invalidate + remap mechanism just works.

Could it be possible to have an Xen driver that would listen on these notifications and percolate those changes this driver. Then this driver would make the appropiate hypercalls to update the M2P ?

Quoted 6 lines
Quoted 1 line

That would solve the 2/ I think?

I think that could work. That sounds like userfaultfd support for DAX which is something I want to take a look at in the next couple kernel cycles for other reasons like live migration of guest-VMs with DAX mappings.

I would need to educate myself a bit more about this.
But I just realized we lost Haozhong on this thread. Adding him back in, perhaps he has more experience with that.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#31 lore raw
In reply to Haozhong Zhang
Quoted 6 lines · Haozhong Zhang

This is v2 RFC patch series to add vNVDIMM support to HVM domains.
v1 can be found at https://lists.xenproject.org/archives/html/xen-devel/2016-10/msg00424.html.

No label and no _DSM except function 0 "query implemented functions" is supported by this version, but they will be added by future patches.

Quoted 7 lines

The corresponding Qemu patch series is sent in another thread "[RFC QEMU PATCH v2 00/10] Implement vNVDIMM for Xen HVM guest".

All patch series can be found at
Xen: https://github.com/hzzhan9/xen.git nvdimm-rfc-v2
Qemu: https://github.com/hzzhan9/qemu.git xen-nvdimm-rfc-v2

Hey!

Thank you for posting this. A quick question.

Quoted 16 lines

Changes in v2
==============

- One of the primary changes in v2 is dropping the linux kernel patches, which were used to reserve on host pmem for placing its frametable and M2P table. In v2, we add a management tool xen-ndctl which is used in Dom0 to notify Xen hypervisor of which storage can be used to manage the host pmem.

For example,
1. xen-ndctl setup 0x240000 0x380000 0x380000 0x3c0000
tells Xen hypervisor to use host pmem pages at MFN 0x380000 ~ 0x3c0000 to manage host pmem pages at MFN 0x240000 ~ 0x380000. I.e. the former is used to place the frame table and M2P table of both ranges of pmem pages.

Quoted 4 lines

2. xen-ndctl setup 0x240000 0x380000
tells Xen hypervisor to use the regular RAM to manage the host pmem pages at MFN 0x240000 ~ 0x380000. I.e the regular RMA is used to place the frame table and M2P table.

How were you thinking to 'glue' this to the libvirt (xl) way of setting up NVDIMM? Could you explain (even in broad ways) how that would be done? I see the 'vnvdimms' but somehow would have thought the libxl would parse the /proc/iomem (or perhaps call ndctl to obtain this ?)

Quoted 6 lines

- Another primary change in v2 is dropping the support to map files on the host pmem to HVM domains as virtual NVDIMMs, as I cannot find a stable to fix the fiemap of host files. Instead, we can rely on the ability added in Linux kernel v4.9 that enables creating multiple pmem namespaces on a single nvdimm interleave set.

Could you expand on this a bit please? This is a quite important feature and I thought the mix of mlock + fiemap would have solved this?

Quoted 4 lines

- Other changes are logged in each patch separately.

How to Test

Thank you for the detailed way this is explained!

Quoted 4 lines

==============

0. This patch series can be tested either on the real hardware with NVDIMM, or in the nested virtualization environment on KVM. The

Real hardware, eh? Nice!

Quoted 147 lines
   latter requires QEMU 2.9 or newer with, for example, following
   commands and options,
     # dd if=/dev/zero of=nvm-8G.img bs=1G count=8
     # rmmod kvm-intel; modprobe kvm-intel nested=1
     # qemu-system-x86_64 -enable-kvm -smp 4 -cpu host,+vmx \
                          -hda DISK_IMG_OF_XEN \
                          -machine pc,nvdimm \
                          -m 8G,slots=4,maxmem=128G \
                          -object memory-backend-file,id=mem1,mem-path=nvm-8G,size=8G \
                          -device nvdimm,id=nv1,memdev=mem1,label-size=2M \
                          ...
   Above will create a nested virtualization environment with a 8G
   pmem mode NVDIMM device (whose last 2MB is used as the label
   storage area).

1. Check out Xen and QEMU from above repositories and branches. Build and install Xen with qemu-xen replaced by above QEMU.

2. Build and install Linux kernel 4.9 or later as Dom0 kernel with the following configs selected:
CONFIG_ACPI_NFIT
CONFIG_LIBNVDIMM
CONFIG_BLK_DEV_PMEM
CONFIG_NVDIMM_PFN
CONFIG_FS_DAX

3. Check out ndctl from https://github.com/pmem/ndctl.git. Build and install ndctl in Dom0.

4. Boot to Xen Dom0.

5. Create pmem namespaces on the host pmem region.

     # ndctl disable-region region0
     # ndctl zero-labels nmem0                        // clear existing labels
     # ndctl init-labels nmem0                        // initialize the label area
     # ndctl enable-region region0     
     # ndctl create-namespace -r region0 -s 4G -m raw // create one 4G pmem namespace
     # ndctl create-namespace -r region0 -s 1G -m raw // create one 1G pmem namespace
     # ndctl list --namespaces
     [
       {
           "dev":"namespace0.0",
           "mode":"raw",
           "size":4294967296,
           "uuid":"bbfbedbd-3ada-4f55-9484-01f2722c651b",
           "blockdev":"pmem0"
       },
       {
           "dev":"namespace0.1",
           "mode":"raw",
           "size":1073741824,
           "uuid":"dd4d3949-6887-417b-b819-89a7854fcdbd",
           "blockdev":"pmem0.1"
       }
     ]

6. Ask Xen hypervisor to use namespace0.1 to manage namespace0.0.

     # grep namespace /proc/iomem
         240000000-33fffffff : namespace0.0
         340000000-37fffffff : namespace0.1
     # xen-ndctl setup 0x240000 0x340000 0x340000 0x380000

7. Start a HVM domain with "vnvdimms=[ '/dev/pmem0' ]" in its xl config.

   If ndctl is installed in HVM domain, "ndctl list" should be able to
   list a 4G pmem namespace, e.g.
   {
     "dev":"namespace0.0",
     "mode":"raw",
     "size":4294967296,
     "blockdev":"pmem0"
   }

Haozhong Zhang (15):
xen/common: add Kconfig item for pmem support
xen: probe pmem regions via ACPI NFIT
xen/x86: allow customizing locations of extended frametable & M2P xen/x86: add XEN_SYSCTL_nvdimm_pmem_setup to setup host pmem xen/x86: add XENMEM_populate_pmemmap to map host pmem pages to HVM domain
tools: reserve guest memory for ACPI from device model tools/libacpi: expose the minimum alignment used by mem_ops.alloc tools/libacpi: add callback acpi_ctxt.p2v to get a pointer from physical address tools/libacpi: add callbacks to access XenStore
tools/libacpi: add a simple AML builder
tools/libacpi: load ACPI built by the device model
tools/libxl: build qemu options from xl vNVDIMM configs tools/libxl: add support to map host pmem device to guests tools/libxl: initiate pmem mapping via qmp callback
tools/misc: add xen-ndctl

 .gitignore                              |   1 +
 docs/man/xl.cfg.pod.5.in                |   6 +
 tools/firmware/hvmloader/Makefile       |   3 +-
 tools/firmware/hvmloader/util.c         |  75 ++++++
 tools/firmware/hvmloader/util.h         |  10 +
 tools/firmware/hvmloader/xenbus.c       |  44 +++-
 tools/flask/policy/modules/dom0.te      |   2 +-
 tools/flask/policy/modules/xen.if       |   2 +-
 tools/libacpi/acpi2_0.h                 |   2 +
 tools/libacpi/aml_build.c               | 326 +++++++++++++++++++++++
 tools/libacpi/aml_build.h               | 116 +++++++++
 tools/libacpi/build.c                   | 311 ++++++++++++++++++++++
 tools/libacpi/libacpi.h                 |  21 ++
 tools/libxc/include/xc_dom.h            |   1 +
 tools/libxc/include/xenctrl.h           |  36 +++
 tools/libxc/xc_dom_x86.c                |   7 +
 tools/libxc/xc_domain.c                 |  15 ++
 tools/libxc/xc_misc.c                   |  17 ++
 tools/libxl/Makefile                    |   7 +-
 tools/libxl/libxl_create.c              |   4 +-
 tools/libxl/libxl_dm.c                  | 109 +++++++-
 tools/libxl/libxl_dom.c                 |  22 ++
 tools/libxl/libxl_nvdimm.c              | 182 +++++++++++++
 tools/libxl/libxl_nvdimm.h              |  42 +++
 tools/libxl/libxl_qmp.c                 | 116 ++++++++-
 tools/libxl/libxl_types.idl             |   8 +
 tools/libxl/libxl_x86_acpi.c            |  41 +++
 tools/misc/Makefile                     |   4 +
 tools/misc/xen-ndctl.c                  | 227 ++++++++++++++++
 tools/xl/xl_parse.c                     |  16 ++
 xen/arch/x86/acpi/boot.c                |   4 +
 xen/arch/x86/domain.c                   |   7 +
 xen/arch/x86/sysctl.c                   |  22 ++
 xen/arch/x86/x86_64/mm.c                | 191 ++++++++++++--
 xen/common/Kconfig                      |   9 +
 xen/common/Makefile                     |   1 +
 xen/common/compat/memory.c              |   1 +
 xen/common/domain.c                     |   3 +
 xen/common/memory.c                     |  43 +++
 xen/common/pmem.c                       | 448 ++++++++++++++++++++++++++++++++
 xen/drivers/acpi/Makefile               |   2 +
 xen/drivers/acpi/nfit.c                 | 116 +++++++++
 xen/include/acpi/actbl.h                |   1 +
 xen/include/acpi/actbl1.h               |  42 +++
 xen/include/public/hvm/hvm_xs_strings.h |  11 +
 xen/include/public/memory.h             |  14 +-
 xen/include/public/sysctl.h             |  29 ++-
 xen/include/xen/acpi.h                  |   4 +
 xen/include/xen/pmem.h                  |  66 +++++
 xen/include/xen/sched.h                 |   3 +
 xen/include/xsm/dummy.h                 |  11 +
 xen/include/xsm/xsm.h                   |  12 +
 xen/xsm/dummy.c                         |   4 +
 xen/xsm/flask/hooks.c                   |  17 ++
 xen/xsm/flask/policy/access_vectors     |   4 +
 55 files changed, 2795 insertions(+), 43 deletions(-)
Quoted 12 lines
 create mode 100644 tools/libacpi/aml_build.c
 create mode 100644 tools/libacpi/aml_build.h
 create mode 100644 tools/libxl/libxl_nvdimm.c
 create mode 100644 tools/libxl/libxl_nvdimm.h
 create mode 100644 tools/misc/xen-ndctl.c
 create mode 100644 xen/common/pmem.c
 create mode 100644 xen/drivers/acpi/nfit.c
 create mode 100644 xen/include/xen/pmem.h
Signature · 1 line
2.12.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel