From patchwork Fri Nov 17 06:22:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 10062359 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 18C1F6023A for ; Fri, 17 Nov 2017 06:27:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085EE2A539 for ; Fri, 17 Nov 2017 06:27:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F164C2A997; Fri, 17 Nov 2017 06:27:42 +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 7A2092A539 for ; Fri, 17 Nov 2017 06:27:42 +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 1eFa6A-0001sS-R9; Fri, 17 Nov 2017 06:25:58 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eFa6A-0001qv-9k for xen-devel@lists.xen.org; Fri, 17 Nov 2017 06:25:58 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id C5/CF-25868-5F08E0A5; Fri, 17 Nov 2017 06:25:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42Jpa+uQ0P3SwBd l0PzEwmLJx8UsDoweR3f/ZgpgjGLNzEvKr0hgzVi4+ypbwXfjikn9Fg2Mv9S6GLk4hASmM0o8 uX6RsYuRk0NCgFfiyLIZrBB2gMSx6+uZQGwhgSqJaT//sYPYbALKEhe/9rKB2CIC0hLXPl9mB BnELPCcWeL/7gawQcICERLPHv0Ha2ARUJV4dW0HmM0r4Cyx4egMJogFChJTHr5nBrE5geL73x yEWuYkcXDdNKYJjLwLGBlWMWoUpxaVpRbpGprqJRVlpmeU5CZm5ugaGpjq5aYWFyemp+YkJhX rJefnbmIEhgMDEOxgbNjueYhRkoNJSZSXx5wvSogvKT+lMiOxOCO+qDQntfgQowwHh5IE77F6 oJxgUWp6akVaZg4wMGHSEhw8SiK8icDgFOItLkjMLc5Mh0idYjTmeDbzdQMzx7SrrU3MQix5+ XmpUuK890EmCYCUZpTmwQ2CRcwlRlkpYV5GoNOEeApSi3IzS1DlXzGKczAqCfNWgkzhycwrgd v3CugUJqBTbG5wg5xSkoiQkmpgZP61kCWLuZCv4XXU9kyZPRcPnn7ZfN1AUStMY3OMl/KCC+v VHWec3uaqVJ4pv7/0XVt4/cYc+bJHQSYNF3RS96pENEmxlO7cU9u0KSj2gyKDXtfU1WHsizlK 1geecF/80Fs2e15v1IOL/Ctm/g02+qrqZVqsY3x4o9LphspGx3mfFqVczVJRYinOSDTUYi4qT gQAy76EEpMCAAA= X-Env-Sender: chao.gao@intel.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1510899922!87798367!12 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 54769 invoked from network); 17 Nov 2017 06:25:56 -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:56 -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:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.44,407,1505804400"; d="scan'208"; a="1245165371" Received: from skl-4s-chao.sh.intel.com ([10.239.48.9]) by fmsmga002.fm.intel.com with ESMTP; 16 Nov 2017 22:25:53 -0800 From: Chao Gao To: xen-devel@lists.xen.org Date: Fri, 17 Nov 2017 14:22:33 +0800 Message-Id: <1510899755-40237-27-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 26/28] tools/libxl: build DMAR table for a guest with one virtual VTD 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 new logic is added to init_acpi_config(). The logic initializes some fields introduced for DMAR table. For PVH guest, the DMAR table is built as other tables. But for HVM guest, only the DMAR table is built in toolstack and pass through it to guest via existing mechanism. Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- v4: - build DMAR table for PVH guest. - remove LIBXL_DEVICE_MODEL_VERSION_NONE v3: - build dmar and initialize related acpi_modules struct in libxl_x86_acpi.c, keeping in accordance with pvh. --- tools/libacpi/build.c | 12 ++++++ tools/libacpi/libacpi.h | 1 + tools/libxl/libxl_x86.c | 4 +- tools/libxl/libxl_x86_acpi.c | 98 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 111 insertions(+), 4 deletions(-) diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c index bd759da..df0a67c 100644 --- a/tools/libacpi/build.c +++ b/tools/libacpi/build.c @@ -517,6 +517,18 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, printf("Failed to build SLIT, skipping...\n"); } + /* DMAR */ + if ( config->table_flags & ACPI_HAS_DMAR ) + { + struct acpi_dmar *dmar = construct_dmar(ctxt, config); + + if ( dmar ) + table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, dmar); + else + printf("Failed to build DMAR, skipping...\n"); + } + + /* Load any additional tables passed through. */ nr_tables += construct_passthrough_tables(ctxt, table_ptrs, nr_tables, config); diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h index c09afdc..bdeeccc 100644 --- a/tools/libacpi/libacpi.h +++ b/tools/libacpi/libacpi.h @@ -36,6 +36,7 @@ #define ACPI_HAS_8042 (1<<13) #define ACPI_HAS_CMOS_RTC (1<<14) #define ACPI_HAS_SSDT_LAPTOP_SLATE (1<<15) +#define ACPI_HAS_DMAR (1<<16) struct xen_vmemrange; struct acpi_numa { diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index 5f91fe4..cb2f494 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -383,7 +383,9 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc, { int rc = 0; - if (info->type == LIBXL_DOMAIN_TYPE_PVH) { + + if (info->type == LIBXL_DOMAIN_TYPE_HVM + || info->type == LIBXL_DOMAIN_TYPE_PVH) { rc = libxl__dom_load_acpi(gc, info, dom); if (rc != 0) LOGE(ERROR, "libxl_dom_load_acpi failed"); diff --git a/tools/libxl/libxl_x86_acpi.c b/tools/libxl/libxl_x86_acpi.c index 9a7c904..bbe9219 100644 --- a/tools/libxl/libxl_x86_acpi.c +++ b/tools/libxl/libxl_x86_acpi.c @@ -16,6 +16,7 @@ #include "libxl_arch.h" #include #include +#include "libacpi/acpi2_0.h" #include "libacpi/libacpi.h" #include @@ -100,6 +101,25 @@ static int init_acpi_config(libxl__gc *gc, struct hvm_info_table *hvminfo; int i, r, rc; + if ((b_info->num_viommus == 1) && + (b_info->viommu[0].type == LIBXL_VIOMMU_TYPE_INTEL_VTD)) { + if (libxl_defbool_val(b_info->viommu[0].intremap)) + config->iommu_intremap_supported = true; + config->iommu_base_addr = b_info->viommu[0].base_addr; + + /* IOAPIC id and PSEUDO BDF */ + config->ioapic_id = 1; + config->ioapic_bus = 0xff; + config->ioapic_devfn = 0x0; + + config->host_addr_width = 39; + config->table_flags |= ACPI_HAS_DMAR; + } + + if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { + return 0; + } + config->dsdt_anycpu = config->dsdt_15cpu = dsdt_pvh; config->dsdt_anycpu_len = config->dsdt_15cpu_len = dsdt_pvh_len; @@ -161,9 +181,9 @@ out: return rc; } -int libxl__dom_load_acpi(libxl__gc *gc, - const libxl_domain_build_info *b_info, - struct xc_dom_image *dom) +static int libxl__dom_load_acpi_pvh(libxl__gc *gc, + const libxl_domain_build_info *b_info, + struct xc_dom_image *dom) { struct acpi_config config = {0}; struct libxl_acpi_ctxt libxl_ctxt; @@ -235,6 +255,78 @@ out: return rc; } +static void *acpi_memalign(struct acpi_ctxt *ctxt, uint32_t size, + uint32_t align) +{ + int ret; + void *ptr; + + ret = posix_memalign(&ptr, align, size); + if (ret != 0 || !ptr) + return NULL; + + return ptr; +} + +/* + * For hvm, we don't need build acpi in libxl. Instead, it's built in hvmloader. + * But if one hvm has virtual VTD(s), we build DMAR table for it and joint this + * table with existing content in acpi_modules in order to employ HVM + * firmware pass-through mechanism to pass-through DMAR table. + */ +static int libxl__dom_load_acpi_hvm(libxl__gc *gc, + const libxl_domain_build_info *b_info, + struct xc_dom_image *dom) +{ + struct acpi_config config = { 0 }; + struct acpi_ctxt ctxt; + struct acpi_dmar *dmar; + uint32_t len; + + ctxt.mem_ops.alloc = acpi_memalign; + ctxt.mem_ops.v2p = virt_to_phys; + ctxt.mem_ops.free = acpi_mem_free; + + init_acpi_config(gc, dom, b_info, &config); + dmar = construct_dmar(&ctxt, &config); + if ( !dmar ) + return ERROR_NOMEM; + len = dmar->header.length; + + if (len) { + libxl__ptr_add(gc, dmar); + if (!dom->acpi_modules[0].data) { + dom->acpi_modules[0].data = (void *)dmar; + dom->acpi_modules[0].length = len; + } else { + /* joint tables */ + void *newdata; + + newdata = libxl__malloc(gc, len + dom->acpi_modules[0].length); + memcpy(newdata, dom->acpi_modules[0].data, + dom->acpi_modules[0].length); + memcpy(newdata + dom->acpi_modules[0].length, dmar, len); + + free(dom->acpi_modules[0].data); + dom->acpi_modules[0].data = newdata; + dom->acpi_modules[0].length += len; + } + } + return 0; +} + +int libxl__dom_load_acpi(libxl__gc *gc, + const libxl_domain_build_info *b_info, + struct xc_dom_image *dom) +{ + + if (b_info->type == LIBXL_DOMAIN_TYPE_PVH) + return libxl__dom_load_acpi_pvh(gc, b_info, dom); + else if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) + return libxl__dom_load_acpi_hvm(gc, b_info, dom); + + return -EINVAL; +} /* * Local variables: * mode: C