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

[Xen-devel] [PATCH 13/15] xen: tools: add new 'epc' parameter support



In order to be able to configure domain's EPC size when it is created, a new
'epc' parameter is added to XL configuration file. Like memory it indicates
EPC size in MB. A new 'libxl_sgx_buildinfo', which contains EPC base and size,
is also added to libxl_domain_buind_info. EPC base and size are also added to
'xc_dom_image' in order to add EPC to e820 table. EPC base is calculated
internally.

Signed-off-by: Kai Huang <kai.huang@xxxxxxxxxxxxxxx>
---
 tools/libxc/include/xc_dom.h |  4 ++++
 tools/libxl/libxl_create.c   |  9 +++++++++
 tools/libxl/libxl_dom.c      | 30 ++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_types.idl  |  6 ++++++
 tools/libxl/libxl_x86.c      | 12 ++++++++++++
 tools/xl/xl_parse.c          |  5 +++++
 7 files changed, 68 insertions(+)

diff --git a/tools/libxc/include/xc_dom.h b/tools/libxc/include/xc_dom.h
index ce47058c41..be10af7002 100644
--- a/tools/libxc/include/xc_dom.h
+++ b/tools/libxc/include/xc_dom.h
@@ -203,6 +203,10 @@ struct xc_dom_image {
     xen_paddr_t lowmem_end;
     xen_paddr_t highmem_end;
     xen_pfn_t vga_hole_size;
+#if defined(__i386__) || defined(__x86_64__)
+    xen_paddr_t epc_base;
+    xen_paddr_t epc_size;
+#endif
 
     /* If unset disables the setup of the IOREQ pages. */
     bool device_model;
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index bffbc456c1..8710e53ffd 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -59,6 +59,13 @@ void libxl__rdm_setdefault(libxl__gc *gc, 
libxl_domain_build_info *b_info)
                             LIBXL_RDM_MEM_BOUNDARY_MEMKB_DEFAULT;
 }
 
+void libxl__sgx_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info)
+{
+    if (b_info->u.hvm.sgx.epckb == LIBXL_MEMKB_DEFAULT)
+        b_info->u.hvm.sgx.epckb = 0;
+    b_info->u.hvm.sgx.epcbase = 0;
+}
+
 int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info)
 {
@@ -372,6 +379,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         libxl_defbool_setdefault(&b_info->u.hvm.gfx_passthru, false);
 
         libxl__rdm_setdefault(gc, b_info);
+
+        libxl__sgx_setdefault(gc, b_info);
         break;
     case LIBXL_DOMAIN_TYPE_PV:
         libxl_defbool_setdefault(&b_info->u.pv.e820_host, false);
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 5d914a59ee..6d1d51d35d 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -1124,6 +1124,36 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
         highmem_end = (1ull << 32) + (lowmem_end - mmio_start);
         lowmem_end = mmio_start;
     }
+#if defined(__i386__) || defined(__x86_64__)
+    if (info->u.hvm.sgx.epckb) {
+        /*
+         * FIXME:
+         *
+         * Currently EPC base is put at highmem_end + 8G, which should be
+         * safe in most cases.
+         *
+         * I am not quite sure which is the best way to calcualte EPC base.
+         * IMO we can either:
+         * 1) put EPC between lowmem_end to mmio_start, but this brings
+         * additional logic to handle, ex, lowmem_end may become too small
+         * if EPC is large (shall we limit domain's EPC size?), and hvmloader
+         * will try to enlarge MMIO space until lowmem_end, or even relocate
+         * lowmem -- all those make things complicated, so probably put EPC
+         * in hole between lowmem_end to mmio_start is not good.
+         * 2) put EPC after highmem_end, but hvmloader may also relocate MMIO
+         * resource to the place after highmem_end. Maybe the ideal way is to
+         * put EPC right after highmem_end, and change hvmloader to detect
+         * EPC, and put high MMIO resource after EPC. I've done this but I
+         * found a strange bug that EPT mapping of EPC will be (at least part
+         * of the mappings) will be removed by whom I still cannot find.
+         * Currently EPC base is put at highmem_end + 8G, and hvmloader code
+         * is not changed to handle EPC, but this should be safe for most 
cases.
+         */
+        info->u.hvm.sgx.epcbase = highmem_end + (2ULL << 32);
+    }
+    dom->epc_size = (info->u.hvm.sgx.epckb << 10);
+    dom->epc_base = info->u.hvm.sgx.epcbase;
+#endif
     dom->lowmem_end = lowmem_end;
     dom->highmem_end = highmem_end;
     dom->mmio_start = mmio_start;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index afe6652847..9a1d309dac 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1252,6 +1252,8 @@ _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, 
libxl_device_vkb *vkb);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
                                    libxl_domain_build_info *b_info);
+_hidden void libxl__sgx_setdefault(libxl__gc *gc,
+                                   libxl_domain_build_info *b_info);
 _hidden int libxl__device_p9_setdefault(libxl__gc *gc,
                                         libxl_device_p9 *p9);
 
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 22044259f3..9723c1fa46 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -450,6 +450,11 @@ libxl_altp2m_mode = Enumeration("altp2m_mode", [
     (3, "limited"),
     ], init_val = "LIBXL_ALTP2M_MODE_DISABLED")
 
+libxl_sgx_buildinfo = Struct("sgx_buildinfo", [
+    ("epcbase", uint64), # EPC base address
+    ("epckb", MemKB), # EPC size in KB
+    ], dir=DIR_IN)
+
 libxl_domain_build_info = Struct("domain_build_info",[
     ("max_vcpus",       integer),
     ("avail_vcpus",     libxl_bitmap),
@@ -564,6 +569,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                        ("serial_list",      libxl_string_list),
                                        ("rdm", libxl_rdm_reserve),
                                        ("rdm_mem_boundary_memkb", MemKB),
+                                       ("sgx", libxl_sgx_buildinfo),
                                        ])),
                  ("pv", Struct(None, [("kernel", string),
                                       ("slack_memkb", MemKB),
diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index 455f6f0bed..35b0ff1ba3 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -530,6 +530,9 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc,
         if (dom->acpi_modules[i].length)
             e820_entries++;
 
+    if ( dom->epc_base && dom->epc_size )
+        e820_entries++;
+
     if (e820_entries >= E820MAX) {
         LOGD(ERROR, domid, "Ooops! Too many entries in the memory map!");
         rc = ERROR_INVAL;
@@ -570,6 +573,15 @@ int libxl__arch_domain_construct_memmap(libxl__gc *gc,
         e820[nr].addr = ((uint64_t)1 << 32);
         e820[nr].size = highmem_size;
         e820[nr].type = E820_RAM;
+        nr++;
+    }
+
+    /* EPC */
+    if (dom->epc_base && dom->epc_size) {
+        e820[nr].addr = dom->epc_base;
+        e820[nr].size = dom->epc_size;
+        e820[nr].type = E820_RESERVED;
+        nr++;
     }
 
     if (xc_domain_set_memory_map(CTX->xch, domid, e820, e820_entries) != 0) {
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index 856a304b30..4a9be64f78 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -1182,6 +1182,11 @@ void parse_config_data(const char *config_source,
 
         if (!xlu_cfg_get_long (config, "rdm_mem_boundary", &l, 0))
             b_info->u.hvm.rdm_mem_boundary_memkb = l * 1024;
+
+        if (!xlu_cfg_get_long (config, "epc", &l, 0)) {
+            /* Get EPC size. EPC base is calculated by toolstack later. */
+            b_info->u.hvm.sgx.epckb = l * 1024;
+        }
         break;
     case LIBXL_DOMAIN_TYPE_PV:
     {
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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