From patchwork Fri Nov 17 06:22:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 10062365 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 34BBD6023A for ; Fri, 17 Nov 2017 06:27:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 275AD2A539 for ; Fri, 17 Nov 2017 06:27:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C4812A990; Fri, 17 Nov 2017 06:27:45 +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 7C8312A825 for ; Fri, 17 Nov 2017 06:27:44 +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 1eFa68-0001o9-DS; Fri, 17 Nov 2017 06:25:56 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa67-0001ln-8l for xen-devel@lists.xen.org; Fri, 17 Nov 2017 06:25:55 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id 2A/0F-28923-2F08E0A5; Fri, 17 Nov 2017 06:25:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42Jpa+uQ0P3YwBd lcGWrucWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmjFlyU2mgi9OFa/29DA3MC4x6mLk4hASmM4o 8XLOSvYuRk4OCQFeiSPLZrBC2AESD1uWg9lCAlUSdy49ZAOx2QSUJS5+7QWzRQSkJa59vswIM ohZ4DmzRMOE+UwgCWGBNIlf1y+D2SwCqhK/3mxjBLF5BZwlNq7sZYRYoCAx5eF7ZhCbEyi+/8 1BJohlThIH101jmsDIu4CRYRWjRnFqUVlqka6hqV5SUWZ6RkluYmaOrqGBqV5uanFxYnpqTmJ SsV5yfu4mRmBAMADBDsaG7Z6HGCU5mJREeXnM+aKE+JLyUyozEosz4otKc1KLDzHKcHAoSfAe qwfKCRalpqdWpGXmAEMTJi3BwaMkwpsIDE8h3uKCxNzizHSI1ClGe45jmy7/YeL40XEfSD6b+ bqBmWPa1dYmZiGWvPy8VClx3vsgUwVA2jJK8+CGwmLpEqOslDAvI9CZQjwFqUW5mSWo8q8YxT kYlYR5K0Gm8GTmlcDtfgV0FhPQWTY3uEHOKklESEk1MFY5c7MWvzBl32z7sdnrnJPxlxZf5h1 86k4345/dvXc6tPxa2o6VlhO8ja7dy9qxacfZLP3ZjyOu1VoI7GmS3i/zYt2pkI1+SnPPvDl8 rn1xxhuL3ZsCxB/aGWTJcufZWNmf2Z2Vcn7lFzeN+wtsF24Lf3Gx5IXD1Crx89nVlYZOYl2Zn 3ef3qjEUpyRaKjFXFScCACvmNRMoAIAAA== X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1510899922!87798367!11 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54617 invoked from network); 17 Nov 2017 06:25:53 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-11.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Nov 2017 06:25:53 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 22:25:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.44,407,1505804400"; d="scan'208"; a="1245165363" Received: from skl-4s-chao.sh.intel.com ([10.239.48.9]) by fmsmga002.fm.intel.com with ESMTP; 16 Nov 2017 22:25:50 -0800 From: Chao Gao To: xen-devel@lists.xen.org Date: Fri, 17 Nov 2017 14:22:32 +0800 Message-Id: <1510899755-40237-26-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510899755-40237-1-git-send-email-chao.gao@intel.com> References: <1510899755-40237-1-git-send-email-chao.gao@intel.com> Cc: Lan Tianyu , Kevin Tian , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Tim Deegan , Jan Beulich , Chao Gao , Ian Jackson , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v4 25/28] tools/libxl: Add an 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 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 --- v4: - Move VTD_BASE_ADDRESS's definition to libxl_arch.h v3: - allow an array of viommu rather 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_arch.h | 1 + tools/libxl/libxl_create.c | 47 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 12 +++++++++++ tools/xl/xl_parse.c | 50 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 136 insertions(+), 1 deletion(-) diff --git a/docs/man/xl.cfg.pod.5.in b/docs/man/xl.cfg.pod.5.in index b7b91d8..2a48cb8 100644 --- a/docs/man/xl.cfg.pod.5.in +++ b/docs/man/xl.cfg.pod.5.in @@ -1803,6 +1803,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_arch.h b/tools/libxl/libxl_arch.h index 784ec7f..9a74d96 100644 --- a/tools/libxl/libxl_arch.h +++ b/tools/libxl/libxl_arch.h @@ -81,6 +81,7 @@ int libxl__arch_extra_memory(libxl__gc *gc, #if defined(__i386__) || defined(__x86_64__) #define LAPIC_BASE_ADDRESS 0xfee00000 +#define VTD_BASE_ADDRESS 0xfed90000 int libxl__dom_load_acpi(libxl__gc *gc, const libxl_domain_build_info *b_info, diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index f15fb21..b486751 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -59,6 +59,50 @@ 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; + + 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)) { + LOG(ERROR, "Cannot create one virtual VTD without intremap"); + return ERROR_INVAL; + } + + switch (viommu->type) { + case 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) { + LOG(ERROR, "Multiple vIOMMUs support is under implementation"); + return ERROR_INVAL; + } + + /* Set default values to unexposed fields */ + viommu->base_addr = VTD_BASE_ADDRESS; + + /* Set desired capbilities */ + viommu->cap = VIOMMU_CAP_IRQ_REMAPPING; + + break; + + default: + return ERROR_INVAL; + } + } + + return 0; +} + int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info) { @@ -218,6 +262,9 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl__arch_domain_build_info_acpi_setdefault(b_info); libxl_defbool_setdefault(&b_info->dm_restrict, false); + 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) diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index a239324..b6869eb 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -457,6 +457,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), @@ -522,6 +533,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("nested_hvm", libxl_defbool), ("apic", libxl_defbool), ("dm_restrict", 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 9a692d5..aa2eeac 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -851,6 +851,38 @@ out: return rc; } +/* 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, @@ -860,7 +892,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, *vdispls; + *usbctrls, *usbdevs, *p9devs, *vdispls, *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; @@ -1199,6 +1231,22 @@ void parse_config_data(const char *config_source, xlu_cfg_get_defbool(config, "nestedhvm", &b_info->nested_hvm, 0); xlu_cfg_get_defbool(config, "apic", &b_info->apic, 0); + if (!xlu_cfg_get_list (config, "viommu", &iommus, 0, 0)) { + 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);