[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC XEN PATCH v4 38/41] tools/xl: add xl domain configuration for virtual NVDIMM devices
A new xl domain configuration vnvdimms = [ 'type=mfn, backend=START_PMEM_MFN, nr_pages=N', ... ] is added to specify the virtual NVDIMM devices backed by the specified host PMEM pages. As the kernel PMEM driver does not work in Dom0 now, we have to specify MFNs. Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx> --- Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- docs/man/xl.cfg.pod.5.in | 33 ++++++++++++++ tools/libxl/libxl.h | 5 ++ tools/libxl/libxl_nvdimm.c | 28 ++++++++++++ tools/libxl/libxl_types.idl | 15 ++++++ tools/xl/xl_parse.c | 108 ++++++++++++++++++++++++++++++++++++++++++++ tools/xl/xl_vmcontrol.c | 15 +++++- 6 files changed, 203 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in index 1f9538c445..1c0119cbcc 100644 --- a/docs/man/xl.cfg.pod.5.in +++ b/docs/man/xl.cfg.pod.5.in @@ -1268,6 +1268,39 @@ connectors=id0:1920x1080;id1:800x600;id2:640x480 =back +=item B<vnvdimms=[ 'VNVDIMM_SPEC', 'VNVDIMM_SPEC', ... ]> + +Specifies the virtual NVDIMM devices which are provided to the guest. + +Each B<VNVDIMM_SPEC> is a comma-separated list of C<KEY=VALUE> settings +from the following list: + +=over 4 + +=item B<type=TYPE> + +Specifies the type of host backend of the virtual NVDIMM device. Following +is a list of supported types: + +=over 4 + +=item B<mfn> + +backs the virtual NVDIMM device by a contiguous host PMEM region. + +=back + +=item B<backend=BACKEND> + +Specifies the host backend of the virtual NVDIMM device. If C<type=mfn>, +then B<BACKEND> specifies the start MFN of the host PMEM region. + +=item B<nr_pages=NUMBER> + +Specifies the number of pages of the host backend. + +=back + =item B<dm_restrict=BOOLEAN> Restrict the device model after startup, diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index c390bf227b..cb4fd84d48 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -2354,6 +2354,11 @@ int libxl_nvdimm_pmem_setup_data(libxl_ctx *ctx, unsigned long data_smfn, unsigned data_emfn, unsigned long mgmt_smfn, unsigned mgmt_emfn); +int libxl_vnvdimm_copy_config(libxl_ctx *ctx, + libxl_domain_config *dst, + const libxl_domain_config *src) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* misc */ /* Each of these sets or clears the flag according to whether the diff --git a/tools/libxl/libxl_nvdimm.c b/tools/libxl/libxl_nvdimm.c index 0d51036794..1863d76bbc 100644 --- a/tools/libxl/libxl_nvdimm.c +++ b/tools/libxl/libxl_nvdimm.c @@ -168,3 +168,31 @@ int libxl_nvdimm_pmem_setup_data(libxl_ctx *ctx, return errno ? ERROR_FAIL : 0; } + +int libxl_vnvdimm_copy_config(libxl_ctx *ctx, + libxl_domain_config *dst, + const libxl_domain_config *src) +{ + GC_INIT(ctx); + unsigned int nr = src->num_vnvdimms; + libxl_device_vnvdimm *vnvdimms; + int rc = 0; + + if (!nr) + goto out; + + vnvdimms = libxl__calloc(NOGC, nr, sizeof(*vnvdimms)); + if (!vnvdimms) { + rc = ERROR_NOMEM; + goto out; + } + + dst->num_vnvdimms = nr; + while (nr--) + libxl_device_vnvdimm_copy(ctx, &vnvdimms[nr], &src->vnvdimms[nr]); + dst->vnvdimms = vnvdimms; + + out: + GC_FREE; + return rc; +} diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 053b1c0b9a..30879d11db 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -247,6 +247,10 @@ libxl_vuart_type = Enumeration("vuart_type", [ (1, "sbsa_uart"), ]) +libxl_vnvdimm_backend_type = Enumeration("vnvdimm_backend_type", [ + (0, "mfn"), + ]) + # # Complex libxl types # @@ -813,6 +817,16 @@ libxl_device_vdispl = Struct("device_vdispl", [ ("connectors", Array(libxl_connector_param, "num_connectors")) ]) +libxl_device_vnvdimm = Struct("device_vnvdimm", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("nr_pages", uint64), + ("u", KeyedUnion(None, libxl_vnvdimm_backend_type, "backend_type", + [("mfn", uint64), + ])), +]) + libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info), ("b_info", libxl_domain_build_info), @@ -832,6 +846,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), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 0a43a4876e..0123fcf89e 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -851,6 +851,109 @@ out: return rc; } +static int parse_vnvdimm_config(libxl_device_vnvdimm *vnvdimm, char *token) +{ + char *oparg, *endptr; + unsigned long val; + + if (MATCH_OPTION("type", token, oparg)) { + if (libxl_vnvdimm_backend_type_from_string(oparg, + &vnvdimm->backend_type)) { + fprintf(stderr, + "ERROR: invalid vNVDIMM backend type '%s'\n", + oparg); + return 1; + } + } else if (MATCH_OPTION("nr_pages", token, oparg)) { + val = strtoul(oparg, &endptr, 0); + if (endptr == oparg || val == ULONG_MAX) + { + fprintf(stderr, + "ERROR: invalid number of vNVDIMM backend pages '%s'\n", + oparg); + return 1; + } + vnvdimm->nr_pages = val; + } else if (MATCH_OPTION("backend", token, oparg)) { + /* Skip: handled by parse_vnvdimms() */ + } else { + fprintf(stderr, "ERROR: unknown string '%s' in vnvdimm spec\n", token); + return 1; + } + + return 0; +} + +/* + * vnvdimms = [ 'type=<mfn>, backend=<base_mfn>, nr_pages=<N>', ... ] + */ +static void parse_vnvdimms(XLU_Config *config, libxl_domain_config *d_config) +{ + XLU_ConfigList *vnvdimms; + const char *buf; + int rc; + + rc = xlu_cfg_get_list(config, "vnvdimms", &vnvdimms, 0, 0); + if ( rc ) + return; + +#if !defined(__linux__) + fprintf(stderr, "ERROR: 'vnvdimms' is only supported on Linux\n"); + exit(-ERROR_FAIL); +#endif + + d_config->num_vnvdimms = 0; + d_config->vnvdimms = NULL; + + 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); + char *buf2 = strdup(buf), *backend = NULL, *p, *endptr; + unsigned long mfn; + + p = strtok(buf2, ","); + if (!p) + goto skip_nvdimm; + + do { + while (*p == ' ') + p++; + + rc = 0; + if (!MATCH_OPTION("backend", p, backend)) + rc = parse_vnvdimm_config(vnvdimm, p); + if (rc) + exit(-ERROR_FAIL); + } while ((p = strtok(NULL, ",")) != NULL); + + switch (vnvdimm->backend_type) + { + case LIBXL_VNVDIMM_BACKEND_TYPE_MFN: + mfn = strtoul(backend, &endptr, 0); + if (endptr == backend || mfn == ULONG_MAX) + { + fprintf(stderr, + "ERROR: invalid start MFN of host NVDIMM '%s'\n", + backend); + exit(-ERROR_FAIL); + } + vnvdimm->u.mfn = mfn; + + break; + } + + skip_nvdimm: + free(buf2); + } +} + +/* + * Reserved RAM space by qemu-xen for guest ACPI. + */ +#define QEMU_XEN_ACPI_BUILD_TABLE_MAX_SIZE 0x200000 + void parse_config_data(const char *config_source, const char *config_data, int config_len, @@ -2131,6 +2234,11 @@ skip_usbdev: exit(-ERROR_FAIL); } + /* parse 'vnvdimms' */ + parse_vnvdimms(config, d_config); + if (d_config->num_vnvdimms && !dm_acpi_size) + dm_acpi_size = QEMU_XEN_ACPI_BUILD_TABLE_MAX_SIZE; + b_info->u.hvm.dm_acpi_size = dm_acpi_size; } diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 89c2b25ded..1bdc173e04 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -381,12 +381,25 @@ static void reload_domain_config(uint32_t domid, if (rc) { LOG("failed to retrieve guest configuration (rc=%d). " "reusing old configuration", rc); - libxl_domain_config_dispose(&d_config_new); + goto error_out; } else { + rc = libxl_vnvdimm_copy_config(ctx, &d_config_new, d_config); + if (rc) { + LOG("failed to copy vnvdimm configuration (rc=%d). " + "reusing old configuration", rc); + libxl_domain_config_dispose(&d_config_new); + goto error_out; + } + libxl_domain_config_dispose(d_config); /* Steal allocations */ memcpy(d_config, &d_config_new, sizeof(libxl_domain_config)); } + + return; + + error_out: + libxl_domain_config_dispose(&d_config_new); } /* Can update r_domid if domain is destroyed */ -- 2.15.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |