From patchwork Fri Sep 22 03:01:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9965595 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 81EDB6057C for ; Fri, 22 Sep 2017 09:12:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C5F928517 for ; Fri, 22 Sep 2017 09:12:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 714D92891D; Fri, 22 Sep 2017 09:12:23 +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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, 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 CADA028517 for ; Fri, 22 Sep 2017 09:12:22 +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 1dvJy7-0003NC-NJ; Fri, 22 Sep 2017 09:09:55 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvJy6-0003MM-Ez for xen-devel@lists.xen.org; Fri, 22 Sep 2017 09:09:54 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 3D/8F-03283-163D4C95; Fri, 22 Sep 2017 09:09:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42I5YG5SrJt4+Ui kwcP5zBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bXe1NYC3a5VKyd/YG9gbHfuIuRi0NIYDqj xOGTu5m7GDk5JAR4JY4sm8HaxcgBZPtLPJwiDlHTwSix/EkLO0gNm4C6xInFExlBbBEBaYlrn y8zghQxC2xmkpi7ZhYLSLOwQIrE13UOIDUsAqoSu3+tAevlFXCRONz9FmqXgsSUh+/BbE4BV4 lffduZQGwhoJrWpfuZJjDyLmBkWMWoUZxaVJZapGtopJdUlJmeUZKbmJmja2hgppebWlycmJ6 ak5hUrJecn7uJERgODECwg/HyxoBDjJIcTEqivO/PH4kU4kvKT6nMSCzOiC8qzUktPsQow8Gh JMHrdwkoJ1iUmp5akZaZAwxMmLQEB4+SCK8aSJq3uCAxtzgzHSJ1itGY49imy3+YODpu3v3DJ MSSl5+XKiXOqwdSKgBSmlGaBzcIFjGXGGWlhHkZgU4T4ilILcrNLEGVf8UozsGoJMxrADKFJz OvBG7fK6BTmIBOKV8NdkpJIkJKqoGRv6rGY5nJdq1p119lG85XyPlu5PeA54OPf8RJfgVbm4f /Fr5q7Wx8f69E+csdNvb1Yg9t5hivT9I12TDza+3fa87OwcdtLN+/4H5gXqnq+YV1lfXdoO3+ 4RbvN3+KmFHZsffP2imPrULeKpUW8Fj9tnvaIPHqvp3/5cfTP0yMX6E+4+krjamOSizFGYmGW sxFxYkARxjQYpMCAAA= X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1506071390!65146022!1 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=1.3 required=7.0 tests=BODY_RANDOM_LONG, DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 56021 invoked from network); 22 Sep 2017 09:09:52 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Sep 2017 09:09:52 -0000 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Sep 2017 02:09:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,427,1500966000"; d="scan'208";a="154791723" Received: from sky-ws.sh.intel.com (HELO localhost) ([10.239.48.141]) by fmsmga006.fm.intel.com with ESMTP; 22 Sep 2017 02:09:48 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 23:01:47 -0400 Message-Id: <1506049330-11196-7-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> References: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , kevin.tian@intel.com, sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com, roger.pau@citrix.com, Chao Gao Subject: [Xen-devel] [PATCH V3 6/29] tools/libxl: Add a user configurable parameter to control vIOMMU attributes 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 From: Chao Gao A field, viommu_info, is added to struct libxl_domain_build_info. Several attributes can be specified by guest config file for virtual IOMMU. These attributes are used for DMAR construction and vIOMMU creation. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v3: - allow an array of viommu other than only one viommu to present to guest. During domain building, an error would be raised for multiple viommus case since we haven't implemented this yet. - provide a libxl__viommu_set_default() for viommu --- docs/man/xl.cfg.pod.5.in | 27 +++++++++++++++++++++++ tools/libxl/libxl_create.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 12 +++++++++++ tools/xl/xl_parse.c | 52 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 142 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in index 79cb2ea..9cd7dd7 100644 --- a/docs/man/xl.cfg.pod.5.in +++ b/docs/man/xl.cfg.pod.5.in @@ -1547,6 +1547,33 @@ L =back +=item B + +Specifies the vIOMMUs which are to be provided to the guest. + +B has the form C where: + +=over 4 + +=item B + +Possible Bs are: + +=over 4 + +=item B + +Currently there is only one valid type: + +(x86 only) "intel_vtd" means providing a emulated Intel VT-d to the guest. + +=item B + +Specifies whether the vIOMMU should support interrupt remapping +and default 'true'. + +=back + =head3 Guest Virtual Time Controls =over 4 diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 9123585..decd7a8 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -27,6 +27,8 @@ #include +#define VIOMMU_VTD_BASE_ADDR 0xfed90000ULL + int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info) { @@ -59,6 +61,47 @@ void libxl__rdm_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info) LIBXL_RDM_MEM_BOUNDARY_MEMKB_DEFAULT; } +static int libxl__viommu_set_default(libxl__gc *gc, + libxl_domain_build_info *b_info) +{ + int i; + + if (!b_info->num_viommus) + return 0; + + for (i = 0; i < b_info->num_viommus; i++) { + libxl_viommu_info *viommu = &b_info->viommu[i]; + + if (libxl_defbool_is_default(viommu->intremap)) + libxl_defbool_set(&viommu->intremap, true); + + if (!libxl_defbool_val(viommu->intremap)) { + LOGE(ERROR, "Cannot create one virtual VTD without intremap"); + return ERROR_INVAL; + } + + if (viommu->type == LIBXL_VIOMMU_TYPE_INTEL_VTD) { + /* + * If there are multiple vIOMMUs, we need arrange all vIOMMUs to + * avoid overlap. Put a check here in case we get here for multiple + * vIOMMUs case. + */ + if (b_info->num_viommus > 1) { + LOGE(ERROR, "Multiple vIOMMUs support is under implementation"); + return ERROR_INVAL; + } + + /* Set default values to unexposed fields */ + viommu->base_addr = VIOMMU_VTD_BASE_ADDR; + + /* Set desired capbilities */ + viommu->cap = VIOMMU_CAP_IRQ_REMAPPING; + } + } + + return 0; +} + int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info) { @@ -214,6 +257,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl__arch_domain_build_info_acpi_setdefault(b_info); + if (libxl__viommu_set_default(gc, b_info)) + return ERROR_FAIL; + switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT) @@ -890,6 +936,12 @@ static void initiate_domain_create(libxl__egc *egc, goto error_out; } + if (d_config->b_info.num_viommus > 1) { + ret = ERROR_INVAL; + LOGD(ERROR, domid, "Cannot support multiple vIOMMUs"); + goto error_out; + } + ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info); if (ret) { LOGD(ERROR, domid, "Unable to set domain create info defaults"); diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 173d70a..286c960 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -450,6 +450,17 @@ libxl_altp2m_mode = Enumeration("altp2m_mode", [ (3, "limited"), ], init_val = "LIBXL_ALTP2M_MODE_DISABLED") +libxl_viommu_type = Enumeration("viommu_type", [ + (1, "intel_vtd"), + ]) + +libxl_viommu_info = Struct("viommu_info", [ + ("type", libxl_viommu_type), + ("intremap", libxl_defbool), + ("cap", uint64), + ("base_addr", uint64), + ]) + libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap), @@ -506,6 +517,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # 65000 which is reserved by the toolstack. ("device_tree", string), ("acpi", libxl_defbool), + ("viommu", Array(libxl_viommu_info, "num_viommus")), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 02ddd2e..34f8128 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -804,6 +804,38 @@ int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token) return 0; } +/* Parses viommu data and adds info into viommu + * Returns 1 if the input doesn't form a valid viommu + * or parsed values are not correct. Successful parse returns 0 */ +static int parse_viommu_config(libxl_viommu_info *viommu, const char *info) +{ + char *ptr, *oparg, *saveptr = NULL, *buf = xstrdup(info); + + ptr = strtok_r(buf, ",", &saveptr); + if (MATCH_OPTION("type", ptr, oparg)) { + if (!strcmp(oparg, "intel_vtd")) { + viommu->type = LIBXL_VIOMMU_TYPE_INTEL_VTD; + } else { + fprintf(stderr, "Invalid viommu type: %s\n", oparg); + return 1; + } + } else { + fprintf(stderr, "viommu type should be set first: %s\n", oparg); + return 1; + } + + for (ptr = strtok_r(NULL, ",", &saveptr); ptr; + ptr = strtok_r(NULL, ",", &saveptr)) { + if (MATCH_OPTION("intremap", ptr, oparg)) { + libxl_defbool_set(&viommu->intremap, !!strtoul(oparg, NULL, 0)); + } else { + fprintf(stderr, "Unknown string `%s' in viommu spec\n", ptr); + return 1; + } + } + return 0; +} + void parse_config_data(const char *config_source, const char *config_data, int config_len, @@ -813,7 +845,7 @@ void parse_config_data(const char *config_source, long l, vcpus = 0; XLU_Config *config; XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, - *usbctrls, *usbdevs, *p9devs; + *usbctrls, *usbdevs, *p9devs, *iommus; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, *mca_caps; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_caps; @@ -1037,6 +1069,24 @@ void parse_config_data(const char *config_source, xlu_cfg_get_defbool(config, "driver_domain", &c_info->driver_domain, 0); xlu_cfg_get_defbool(config, "acpi", &b_info->acpi, 0); + if (!xlu_cfg_get_list (config, "viommu", &iommus, 0, 0)) { + b_info->num_viommus = 0; + b_info->viommu = NULL; + while ((buf = xlu_cfg_get_listitem (iommus, b_info->num_viommus)) + != NULL) { + libxl_viommu_info *viommu; + + viommu = ARRAY_EXTEND_INIT_NODEVID(b_info->viommu, + b_info->num_viommus, + libxl_viommu_info_init); + + if (parse_viommu_config(viommu, buf)) { + fprintf(stderr, "ERROR: invalid viommu setting\n"); + exit (1); + } + } + } + switch(b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: kernel_basename = libxl_basename(b_info->kernel);