From patchwork Mon Sep 11 04:38:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DEA86035D for ; Mon, 11 Sep 2017 04:42:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23BE527D0C for ; Mon, 11 Sep 2017 04:42:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18A6F28173; Mon, 11 Sep 2017 04:42:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A6DCC27D0C for ; Mon, 11 Sep 2017 04:42:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGW5-0003fs-Ct; Mon, 11 Sep 2017 04:40:13 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGW4-0003br-UA for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:40:13 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id 53/92-15060-CA316B95; Mon, 11 Sep 2017 04:40:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsXS1tYhortaeFu kwe1+RYslHxezODB6HN39mymAMYo1My8pvyKBNeNCa1TBf/WKhTvOsDUwfpftYuTiEBKYzigx Z/FFti5GTg4JAV6JI8tmsELYARJnTi9jhSjqZZS482gbO0iCTUBfYsXjg2BFIgLSEtc+X2YEs ZkF/jBK3PskC2ILC0RK9E6eClTPwcEioCqxdI4BSJhXwE7i4uRlLBDz5SV2tV0EG8MJFD/48h 0ziC0kYCux4PQC1gmMvAsYGVYxahSnFpWlFukameslFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQ mFesl5+duYgQGAwMQ7GBcvDbwEKMkB5OSKO+741sihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw qghtixQSLEpNT61Iy8wBhiVMWoKDR0mENwokzVtckJhbnJkOkTrFqMvRcfPuHyYhlrz8vFQpc V45kCIBkKKM0jy4EbAYucQoKyXMywh0lBBPQWpRbmYJqvwrRnEORiVh3giQKTyZeSVwm14BHc EEdATPpS0gR5QkIqSkGhjdWDP3sE5dNdv1Rf1Pe4vnm2dOO1Jr017gHnC595K5/pYsnfx554O PH3qsPU9Y7db3WC7vt34aX1frKYY42MyMD05b+uVsxpoJIvd+bmB5mpoj3NMtYdeZre0mJ9eb ZsuSdDyp53L5hRtZ9w82m2x8ujxCl+0z+z2Wk56Z/+udT2VclJ/h5ajEUpyRaKjFXFScCACQu 1+BjAIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!34 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52593 invoked from network); 11 Sep 2017 04:40:11 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:40:11 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:40:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078678" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:40:08 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:20 +0800 Message-Id: <20170911043820.14617-40-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com> References: <20170911043820.14617-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Wei Liu , Ian Jackson , Chao Peng , Dan Williams Subject: [Xen-devel] [RFC XEN PATCH v3 39/39] tools/libxl: build qemu options from xl vNVDIMM configs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP For xl configs vnvdimms = [ 'type=mfn,backend=$PMEM0_MFN,nr_pages=$N0', ... ] the following qemu options will be built -machine ,nvdimm -m ,slots=$NR_SLOTS,maxmem=$MEM_SIZE -object memory-backend-xen,id=mem1,host-addr=$PMEM0_ADDR,size=$PMEM0_SIZE -device nvdimm,id=xen_nvdimm1,memdev=mem1 ... in which, - NR_SLOTS is the number of entries in vnvdimms + 1, - MEM_SIZE is the total size of all RAM and NVDIMM devices, - PMEM0_ADDR = PMEM0_MFN * 4096, - PMEM0_SIZE = N0 * 4096, Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu --- tools/libxl/libxl_dm.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index e0e6a99e67..9bdb3cdb29 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -910,6 +910,58 @@ static char *qemu_disk_ide_drive_string(libxl__gc *gc, const char *target_path, return drive; } +#if defined(__linux__) + +static uint64_t libxl__build_dm_vnvdimm_args( + libxl__gc *gc, flexarray_t *dm_args, + struct libxl_device_vnvdimm *dev, int dev_no) +{ + uint64_t addr = 0, size = 0; + char *arg; + + switch (dev->backend_type) + { + case LIBXL_VNVDIMM_BACKEND_TYPE_MFN: + addr = dev->u.mfn << XC_PAGE_SHIFT; + size = dev->nr_pages << XC_PAGE_SHIFT; + break; + } + + if (!size) + return 0; + + flexarray_append(dm_args, "-object"); + arg = GCSPRINTF("memory-backend-xen,id=mem%d,host-addr=%"PRIu64",size=%"PRIu64, + dev_no + 1, addr, size); + flexarray_append(dm_args, arg); + + flexarray_append(dm_args, "-device"); + arg = GCSPRINTF("nvdimm,id=xen_nvdimm%d,memdev=mem%d", + dev_no + 1, dev_no + 1); + flexarray_append(dm_args, arg); + + return size; +} + +static uint64_t libxl__build_dm_vnvdimms_args( + libxl__gc *gc, flexarray_t *dm_args, + struct libxl_device_vnvdimm *vnvdimms, int num_vnvdimms) +{ + uint64_t total_size = 0, size; + unsigned int i; + + for (i = 0; i < num_vnvdimms; i++) { + size = libxl__build_dm_vnvdimm_args(gc, dm_args, &vnvdimms[i], i); + if (!size) + break; + total_size += size; + } + + return total_size; +} + +#endif /* __linux__ */ + static int libxl__build_device_model_args_new(libxl__gc *gc, const char *dm, int guest_domid, const libxl_domain_config *guest_config, @@ -923,13 +975,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, const libxl_device_nic *nics = guest_config->nics; const int num_disks = guest_config->num_disks; const int num_nics = guest_config->num_nics; +#if defined(__linux__) + const int num_vnvdimms = guest_config->num_vnvdimms; +#else + const int num_vnvdimms = 0; +#endif const libxl_vnc_info *vnc = libxl__dm_vnc(guest_config); const libxl_sdl_info *sdl = dm_sdl(guest_config); const char *keymap = dm_keymap(guest_config); char *machinearg; flexarray_t *dm_args, *dm_envs; int i, connection, devid, ret; - uint64_t ram_size; + uint64_t ram_size, ram_size_in_byte = 0, vnvdimms_size = 0; const char *path, *chardev; char *user = NULL; @@ -1451,6 +1508,9 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, } } + if (num_vnvdimms) + machinearg = libxl__sprintf(gc, "%s,nvdimm", machinearg); + flexarray_append(dm_args, machinearg); for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++) flexarray_append(dm_args, b_info->extra_hvm[i]); @@ -1460,8 +1520,25 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, } ram_size = libxl__sizekb_to_mb(b_info->max_memkb - b_info->video_memkb); + if (num_vnvdimms) { + ram_size_in_byte = ram_size << 20; + vnvdimms_size = libxl__build_dm_vnvdimms_args(gc, dm_args, + guest_config->vnvdimms, + num_vnvdimms); + if (ram_size_in_byte + vnvdimms_size < ram_size_in_byte) { + LOG(ERROR, + "total size of RAM (%"PRIu64") and NVDIMM (%"PRIu64") overflow", + ram_size_in_byte, vnvdimms_size); + return ERROR_INVAL; + } + } flexarray_append(dm_args, "-m"); - flexarray_append(dm_args, GCSPRINTF("%"PRId64, ram_size)); + flexarray_append(dm_args, + vnvdimms_size ? + GCSPRINTF("%"PRId64",slots=%d,maxmem=%"PRId64, + ram_size, num_vnvdimms + 1, + ROUNDUP(ram_size_in_byte, 12) + vnvdimms_size) : + GCSPRINTF("%"PRId64, ram_size)); if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { if (b_info->u.hvm.hdtype == LIBXL_HDTYPE_AHCI)