All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lan Tianyu <tianyu.lan@intel.com>
To: xen-devel@lists.xen.org
Cc: Lan Tianyu <tianyu.lan@intel.com>,
	kevin.tian@intel.com, wei.liu2@citrix.com,
	ian.jackson@eu.citrix.com, jbeulich@suse.com, chao.gao@intel.com
Subject: [RFC PATCH 8/23] Tools/libacpi: Add a user configurable parameter to control vIOMMU attributes
Date: Fri, 17 Mar 2017 19:27:08 +0800	[thread overview]
Message-ID: <1489750043-17260-9-git-send-email-tianyu.lan@intel.com> (raw)
In-Reply-To: <1489750043-17260-1-git-send-email-tianyu.lan@intel.com>

From: Chao Gao <chao.gao@intel.com>

a field, viommu_info, is added to struct libxl_domain_build_info. Several
attributes can be specified by guest configuration file for the DMAR table
building and dummy vIOMMU creation.

In domain creation process, a new logic is added to build ACPI DMAR table in
tool stack according VM configuration and to pass though it to hvmloader via
xenstore ACPI PT channel. If there are ACPI tables needed to pass through, we
joint the tables.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 tools/libacpi/build.c       |  5 +++
 tools/libacpi/libacpi.h     |  1 +
 tools/libxl/libxl_dom.c     | 85 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_types.idl |  8 +++++
 tools/xl/xl_parse.c         | 54 ++++++++++++++++++++++++++++
 5 files changed, 153 insertions(+)

diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c
index 89a3c6c..080413e 100644
--- a/tools/libacpi/build.c
+++ b/tools/libacpi/build.c
@@ -550,6 +550,11 @@ static int new_vm_gid(struct acpi_ctxt *ctxt,
     return 1;
 }
 
+uint32_t acpi_get_table_size(struct acpi_header * header)
+{
+    return header ? header->length : 0;
+}
+
 int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config)
 {
     struct acpi_info *acpi_info;
diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h
index ee08c45..0882729 100644
--- a/tools/libacpi/libacpi.h
+++ b/tools/libacpi/libacpi.h
@@ -108,6 +108,7 @@ struct acpi_config {
 #define DMAR_X2APIC_OPT_OUT 0x2
 struct acpi_dmar *construct_dmar(struct acpi_ctxt *ctxt,
                                  const struct acpi_config *config);
+uint32_t acpi_get_table_size(struct acpi_header * header);
 int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config);
 
 #endif /* __LIBACPI_H__ */
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index d519c8d..99132d0 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -19,6 +19,7 @@
 
 #include "libxl_internal.h"
 #include "libxl_arch.h"
+#include "libacpi/libacpi.h"
 
 #include <xc_dom.h>
 #include <xen/hvm/hvm_info_table.h>
@@ -908,6 +909,43 @@ out:
     return rc;
 }
 
+static unsigned long acpi_v2p(struct acpi_ctxt *ctxt, void *v)
+{
+    return (unsigned long)v;
+}
+
+static void *acpi_mem_alloc(struct acpi_ctxt *ctxt,
+                            uint32_t size, uint32_t align)
+{
+    return aligned_alloc(align, size);
+}
+
+static void acpi_mem_free(struct acpi_ctxt *ctxt,
+                          void *v, uint32_t size)
+{
+    /* ACPI builder currently doesn't free memory so this is just a stub */
+}
+
+static int libxl__acpi_build_dmar(libxl__gc *gc,
+                                  struct acpi_config *config,
+                                  void **data_r, int *datalen_r)
+{
+    struct acpi_ctxt ctxt;
+    void *table;
+
+    ctxt.mem_ops.alloc = acpi_mem_alloc;
+    ctxt.mem_ops.free = acpi_mem_free;
+    ctxt.mem_ops.v2p = acpi_v2p;
+
+    table = construct_dmar(&ctxt, config);
+    if ( !table )
+        return ERROR_FAIL;
+
+    *data_r = table;
+    *datalen_r = acpi_get_table_size((struct acpi_header *)table);
+    return 0;
+}
+
 static int libxl__domain_firmware(libxl__gc *gc,
                                   libxl_domain_build_info *info,
                                   struct xc_dom_image *dom)
@@ -1028,6 +1066,53 @@ static int libxl__domain_firmware(libxl__gc *gc,
         }
     }
 
+    /* build DMAR table according guest configuration and joint it with other
+     * apci tables specified by acpi_modules */
+    if (!libxl_defbool_is_default(info->u.hvm.viommu.intremap) &&
+        info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
+        struct acpi_config config;
+
+        memset(&config, 0, sizeof(config));
+        if (libxl_defbool_val(info->u.hvm.viommu.intremap)) {
+            config.table_flags |= ACPI_HAS_DMAR;
+            config.dmar_flag = DMAR_INTR_REMAP;
+            if (!libxl_defbool_is_default(info->u.hvm.viommu.x2apic_opt_out)
+                && libxl_defbool_val(info->u.hvm.viommu.x2apic_opt_out))
+                config.dmar_flag |= DMAR_X2APIC_OPT_OUT;
+
+            config.viommu_base_addr = info->u.hvm.viommu.base_addr;
+            data = NULL;
+            e = libxl__acpi_build_dmar(gc, &config, &data, &datalen);
+            if (e) {
+                LOGE(ERROR, "failed to build DMAR table");
+                rc = ERROR_FAIL;
+                goto out;
+            }
+
+            libxl__ptr_add(gc, data);
+            if (datalen) {
+                if (!dom->acpi_modules[0].data) {
+                    dom->acpi_modules[0].data = data;
+                    dom->acpi_modules[0].length = (uint32_t)datalen;
+                } else {
+                    /* joint tables */
+                    void *newdata;
+                    newdata = malloc(datalen + dom->acpi_modules[0].length);
+                    if (!newdata) {
+                        LOGE(ERROR, "failed to joint DMAR table to acpi modules");
+                        rc = ERROR_FAIL;
+                        goto out;
+                    }
+                    memcpy(newdata, dom->acpi_modules[0].data,
+                           dom->acpi_modules[0].length);
+                    memcpy(newdata + dom->acpi_modules[0].length, data, datalen);
+                    dom->acpi_modules[0].data = newdata;
+                    dom->acpi_modules[0].length += (uint32_t)datalen;
+                }
+            }
+        }
+    }
+
     return 0;
 out:
     assert(rc != 0);
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index a612d1f..912582a 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -440,6 +440,13 @@ libxl_rdm_reserve = Struct("rdm_reserve", [
     ("policy",      libxl_rdm_reserve_policy),
     ])
 
+libxl_viommu_info = Struct("viommu_info", [
+    ("intremap",        libxl_defbool),
+    ("x2apic_opt_out",  libxl_defbool),
+    ("cap",             uint64),
+    ("base_addr",       uint64),
+    ])
+
 libxl_domain_build_info = Struct("domain_build_info",[
     ("max_vcpus",       integer),
     ("avail_vcpus",     libxl_bitmap),
@@ -550,6 +557,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                        ("serial_list",      libxl_string_list),
                                        ("rdm", libxl_rdm_reserve),
                                        ("rdm_mem_boundary_memkb", MemKB),
+                                       ("viommu",           libxl_viommu_info),
                                        ])),
                  ("pv", Struct(None, [("kernel", string),
                                       ("slack_memkb", MemKB),
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index 1ef0c27..9349367 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <xen/hvm/e820.h>
+#include <xen/viommu.h>
 
 #include <libxl.h>
 #include <libxl_utils.h>
@@ -29,6 +30,8 @@
 
 extern void set_default_nic_values(libxl_device_nic *nic);
 
+#define VIOMMU_BASE_ADDR 0xfed90000
+
 #define ARRAY_EXTEND_INIT__CORE(array,count,initfn,more)                \
     ({                                                                  \
         typeof((count)) array_extend_old_count = (count);               \
@@ -707,6 +710,25 @@ 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 token does not match one of the keys
+ * or parsed values are not correct. Successful parse returns 0 */
+static int parse_viommu_config(libxl_viommu_info *viommu, char *token)
+{
+    char *oparg;
+
+    if (MATCH_OPTION("intremap", token, oparg)) {
+        libxl_defbool_set(&viommu->intremap, !!strtoul(oparg, NULL, 0));
+    } else if (MATCH_OPTION("x2apic_opt_out", token, oparg)) {
+        libxl_defbool_set(&viommu->x2apic_opt_out, !!strtoul(oparg, NULL, 0));
+    } else {
+        fprintf(stderr, "Unknown string `%s' in viommu spec\n", token);
+        return 1;
+    }
+
+    return 0;
+}
+
 void parse_config_data(const char *config_source,
                        const char *config_data,
                        int config_len,
@@ -1084,6 +1106,38 @@ void parse_config_data(const char *config_source,
 
         if (!xlu_cfg_get_long (config, "rdm_mem_boundary", &l, 0))
             b_info->u.hvm.rdm_mem_boundary_memkb = l * 1024;
+
+        if (!xlu_cfg_get_string(config, "viommu_info", &buf, 0)) {
+            libxl_viommu_info viommu;
+            char *p, *str2;
+
+            str2 = strdup(buf);
+            if (!str2) {
+                fprintf(stderr, "ERROR: strdup failed\n");
+                exit (1);
+            }
+            p = strtok(str2, ",");
+            if (!p) {
+                fprintf(stderr, "ERROR: invalid viommu_info format\n");
+                exit (1);
+            }
+            do {
+                if (*p == ' ')
+                    p++;
+                if (parse_viommu_config(&viommu, p)) {
+                    fprintf(stderr, "ERROR: invalid viommu settting\n");
+                    exit (1);
+                }
+            } while ((p=strtok(NULL, ",")) != NULL);
+            free(str2);
+            b_info->u.hvm.viommu.intremap = viommu.intremap;
+            b_info->u.hvm.viommu.x2apic_opt_out = viommu.x2apic_opt_out;
+            if ( libxl_defbool_val(b_info->u.hvm.viommu.intremap) )
+            {
+                b_info->u.hvm.viommu.cap = VIOMMU_CAP_IRQ_REMAPPING;
+                b_info->u.hvm.viommu.base_addr = VIOMMU_BASE_ADDR;
+            }
+        }
         break;
     case LIBXL_DOMAIN_TYPE_PV:
     {
-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-03-17 11:27 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-17 11:27 [RFC PATCH 00/23] xen/vIOMMU: Add vIOMMU support with irq remapping fucntion on Intel platform Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 1/23] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities Lan Tianyu
2017-03-21 19:56   ` Julien Grall
2017-03-22  8:36     ` Tian, Kevin
2017-03-22 12:41       ` Lan, Tianyu
2017-03-22  8:45     ` Lan Tianyu
2017-03-22 11:40       ` Julien Grall
2017-03-22 13:32         ` Lan, Tianyu
2017-03-17 11:27 ` [RFC PATCH 2/23] DMOP: Introduce new DMOP commands for vIOMMU support Lan Tianyu
2017-04-17 14:36   ` Konrad Rzeszutek Wilk
2017-04-18  7:24     ` Lan Tianyu
2017-04-18 13:32       ` Konrad Rzeszutek Wilk
2017-03-17 11:27 ` [RFC PATCH 3/23] VIOMMU: Add irq request callback to deal with irq remapping Lan Tianyu
2017-04-17 14:39   ` Konrad Rzeszutek Wilk
2017-04-18  8:18     ` Lan Tianyu
2017-04-18 13:36       ` Konrad Rzeszutek Wilk
2017-03-17 11:27 ` [RFC PATCH 4/23] VIOMMU: Add get irq info callback to convert irq remapping request Lan Tianyu
2017-04-17 14:39   ` Konrad Rzeszutek Wilk
2017-03-17 11:27 ` [RFC PATCH 5/23] Tools/libxc: Add viommu operations in libxc Lan Tianyu
2017-03-28 16:24   ` Wei Liu
2017-03-29  0:40     ` Chao Gao
2017-03-29  9:08       ` Paul Durrant
2017-03-30 19:57         ` Chao Gao
2017-04-14 15:38           ` Lan, Tianyu
2017-04-17 11:08             ` Wei Liu
2017-04-17 12:01               ` Lan Tianyu
2017-05-11 12:35                 ` Wei Liu
2017-05-11 12:31                   ` Lan Tianyu
2017-04-18  9:08             ` Paul Durrant
2017-04-18  9:59               ` Lan Tianyu
2017-04-18 14:15                 ` Paul Durrant
2017-04-19 12:21                   ` Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 6/23] Tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table structures Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 7/23] Tools/libacpi: Add new fields in acpi_config to build DMAR table Lan Tianyu
2017-03-17 11:27 ` Lan Tianyu [this message]
2017-03-17 11:27 ` [RFC PATCH 9/23] Tools/libxl: Inform device model to create a guest with a vIOMMU device Lan Tianyu
2017-03-28 16:24   ` Wei Liu
2017-03-17 11:27 ` [RFC PATCH 10/23] x86/hvm: Introduce a emulated VTD for HVM Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 11/23] X86/vvtd: Add MMIO handler for VVTD Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 12/23] X86/vvtd: Set Interrupt Remapping Table Pointer through GCMD Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 13/23] X86/vvtd: Process interrupt remapping request Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 14/23] X86/vvtd: decode interrupt attribute from IRTE Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 15/23] X86/vioapic: Hook interrupt delivery of vIOAPIC Lan Tianyu
2017-04-17 14:43   ` Konrad Rzeszutek Wilk
2017-04-18  8:34     ` Lan Tianyu
2017-04-18 13:37       ` Konrad Rzeszutek Wilk
2017-03-17 11:27 ` [RFC PATCH 16/23] X86/vvtd: Enable Queued Invalidation through GCMD Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 17/23] X86/vvtd: Enable Interrupt Remapping " Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 18/23] x86/vpt: Get interrupt vector through a vioapic interface Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 19/23] passthrough: move some fields of hvm_gmsi_info to a sub-structure Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 20/23] Tools/libxc: Add a new interface to bind msi-ir with pirq Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 21/23] X86/vmsi: Hook guest MSI injection Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 22/23] X86/vvtd: Handle interrupt translation faults Lan Tianyu
2017-03-17 11:27 ` [RFC PATCH 23/23] X86/vvtd: Add queued invalidation (QI) support Lan Tianyu
2017-03-20 14:23 ` [RFC PATCH 00/23] xen/vIOMMU: Add vIOMMU support with irq remapping fucntion on Intel platform Roger Pau Monné
2017-03-21  2:28   ` Lan Tianyu
2017-03-21  5:29     ` Lan Tianyu
2017-03-29  8:00       ` Roger Pau Monné
2017-03-29  3:52         ` Chao Gao
2017-04-17 14:41   ` Konrad Rzeszutek Wilk
2017-04-18  8:19     ` Lan Tianyu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489750043-17260-9-git-send-email-tianyu.lan@intel.com \
    --to=tianyu.lan@intel.com \
    --cc=chao.gao@intel.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=kevin.tian@intel.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.