From: Lan Tianyu <tianyu.lan@intel.com>
To: xen-devel@lists.xen.org
Cc: Lan Tianyu <tianyu.lan@intel.com>,
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@intel.com
Subject: [PATCH V3 2/29] VIOMMU: Add vIOMMU helper functions to create, destroy vIOMMU instance
Date: Thu, 21 Sep 2017 23:01:43 -0400 [thread overview]
Message-ID: <1506049330-11196-3-git-send-email-tianyu.lan@intel.com> (raw)
In-Reply-To: <1506049330-11196-1-git-send-email-tianyu.lan@intel.com>
This patch is to introduce an abstract layer for arch vIOMMU implementation
to deal with requests from dom0. Arch vIOMMU code needs to provide callback
to do create and destroy operation.
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
docs/misc/xen-command-line.markdown | 7 ++
xen/arch/x86/Kconfig | 1 +
xen/common/Kconfig | 3 +
xen/common/Makefile | 1 +
xen/common/domain.c | 4 +
xen/common/viommu.c | 144 ++++++++++++++++++++++++++++++++++++
xen/include/xen/sched.h | 8 ++
xen/include/xen/viommu.h | 63 ++++++++++++++++
8 files changed, 231 insertions(+)
create mode 100644 xen/common/viommu.c
create mode 100644 xen/include/xen/viommu.h
diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown
index 9797c8d..dfd1db5 100644
--- a/docs/misc/xen-command-line.markdown
+++ b/docs/misc/xen-command-line.markdown
@@ -1825,3 +1825,10 @@ mode.
> Default: `true`
Permit use of the `xsave/xrstor` instructions.
+
+### viommu
+> `= <boolean>`
+
+> Default: `false`
+
+Permit use of viommu interface to create and destroy viommu device model.
diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 30c2769..1f1de96 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -23,6 +23,7 @@ config X86
select HAS_PDX
select NUMA
select VGA
+ select VIOMMU
config ARCH_DEFCONFIG
string
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index dc8e876..2ad2c8d 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -49,6 +49,9 @@ config HAS_CHECKPOLICY
string
option env="XEN_HAS_CHECKPOLICY"
+config VIOMMU
+ bool
+
config KEXEC
bool "kexec support"
default y
diff --git a/xen/common/Makefile b/xen/common/Makefile
index 39e2614..da32f71 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -56,6 +56,7 @@ obj-y += time.o
obj-y += timer.o
obj-y += trace.o
obj-y += version.o
+obj-$(CONFIG_VIOMMU) += viommu.o
obj-y += virtual_region.o
obj-y += vm_event.o
obj-y += vmap.o
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 5aebcf2..cdb1c9d 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -814,6 +814,10 @@ static void complete_domain_destroy(struct rcu_head *head)
sched_destroy_domain(d);
+#ifdef CONFIG_VIOMMU
+ viommu_destroy_domain(d);
+#endif
+
/* Free page used by xen oprofile buffer. */
#ifdef CONFIG_XENOPROF
free_xenoprof_pages(d);
diff --git a/xen/common/viommu.c b/xen/common/viommu.c
new file mode 100644
index 0000000..64d91e6
--- /dev/null
+++ b/xen/common/viommu.c
@@ -0,0 +1,144 @@
+/*
+ * common/viommu.c
+ *
+ * Copyright (c) 2017 Intel Corporation
+ * Author: Lan Tianyu <tianyu.lan@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/sched.h>
+#include <xen/spinlock.h>
+#include <xen/types.h>
+#include <xen/viommu.h>
+
+bool __read_mostly opt_viommu;
+boolean_param("viommu", opt_viommu);
+
+static DEFINE_SPINLOCK(type_list_lock);
+static LIST_HEAD(type_list);
+
+struct viommu_type {
+ uint64_t type;
+ struct viommu_ops *ops;
+ struct list_head node;
+};
+
+int viommu_destroy_domain(struct domain *d)
+{
+ int ret;
+
+ if ( !d->viommu )
+ return -EINVAL;
+
+ ret = d->viommu->ops->destroy(d->viommu);
+ if ( ret < 0 )
+ return ret;
+
+ xfree(d->viommu);
+ d->viommu = NULL;
+ return 0;
+}
+
+static struct viommu_type *viommu_get_type(uint64_t type)
+{
+ struct viommu_type *viommu_type = NULL;
+
+ spin_lock(&type_list_lock);
+ list_for_each_entry( viommu_type, &type_list, node )
+ {
+ if ( viommu_type->type == type )
+ {
+ spin_unlock(&type_list_lock);
+ return viommu_type;
+ }
+ }
+ spin_unlock(&type_list_lock);
+
+ return NULL;
+}
+
+int viommu_register_type(uint64_t type, struct viommu_ops *ops)
+{
+ struct viommu_type *viommu_type = NULL;
+
+ if ( !viommu_enabled() )
+ return -ENODEV;
+
+ if ( viommu_get_type(type) )
+ return -EEXIST;
+
+ viommu_type = xzalloc(struct viommu_type);
+ if ( !viommu_type )
+ return -ENOMEM;
+
+ viommu_type->type = type;
+ viommu_type->ops = ops;
+
+ spin_lock(&type_list_lock);
+ list_add_tail(&viommu_type->node, &type_list);
+ spin_unlock(&type_list_lock);
+
+ return 0;
+}
+
+static int viommu_create(struct domain *d, uint64_t type,
+ uint64_t base_address, uint64_t caps,
+ uint32_t *viommu_id)
+{
+ struct viommu *viommu;
+ struct viommu_type *viommu_type = NULL;
+ int rc;
+
+ /* Only support one vIOMMU per domain. */
+ if ( d->viommu )
+ return -E2BIG;
+
+ viommu_type = viommu_get_type(type);
+ if ( !viommu_type )
+ return -EINVAL;
+
+ if ( !viommu_type->ops || !viommu_type->ops->create )
+ return -EINVAL;
+
+ viommu = xzalloc(struct viommu);
+ if ( !viommu )
+ return -ENOMEM;
+
+ viommu->base_address = base_address;
+ viommu->caps = caps;
+ viommu->ops = viommu_type->ops;
+
+ rc = viommu->ops->create(d, viommu);
+ if ( rc < 0 )
+ {
+ xfree(viommu);
+ return rc;
+ }
+
+ d->viommu = viommu;
+
+ /* Only support one vIOMMU per domain. */
+ *viommu_id = 0;
+ return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 5b8f8c6..750f235 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -33,6 +33,10 @@
DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_compat_t);
#endif
+#ifdef CONFIG_VIOMMU
+#include <xen/viommu.h>
+#endif
+
/*
* Stats
*
@@ -479,6 +483,10 @@ struct domain
rwlock_t vnuma_rwlock;
struct vnuma_info *vnuma;
+#ifdef CONFIG_VIOMMU
+ struct viommu *viommu;
+#endif
+
/* Common monitor options */
struct {
unsigned int guest_request_enabled : 1;
diff --git a/xen/include/xen/viommu.h b/xen/include/xen/viommu.h
new file mode 100644
index 0000000..636a2a3
--- /dev/null
+++ b/xen/include/xen/viommu.h
@@ -0,0 +1,63 @@
+/*
+ * include/xen/viommu.h
+ *
+ * Copyright (c) 2017, Intel Corporation
+ * Author: Lan Tianyu <tianyu.lan@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef __XEN_VIOMMU_H__
+#define __XEN_VIOMMU_H__
+
+struct viommu;
+
+struct viommu_ops {
+ int (*create)(struct domain *d, struct viommu *viommu);
+ int (*destroy)(struct viommu *viommu);
+};
+
+struct viommu {
+ uint64_t base_address;
+ uint64_t caps;
+ const struct viommu_ops *ops;
+ void *priv;
+};
+
+#ifdef CONFIG_VIOMMU
+extern bool opt_viommu;
+static inline bool viommu_enabled(void)
+{
+ return opt_viommu;
+}
+
+int viommu_register_type(uint64_t type, struct viommu_ops *ops);
+int viommu_destroy_domain(struct domain *d);
+#else
+static inline int viommu_register_type(uint64_t type, struct viommu_ops *ops)
+{
+ return -EINVAL;
+}
+#endif
+
+#endif /* __XEN_VIOMMU_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-09-22 3:01 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 3:01 [PATCH V3 00/29] Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 1/29] Xen/doc: Add Xen virtual IOMMU doc Lan Tianyu
2017-10-18 13:26 ` Roger Pau Monné
2017-10-19 2:26 ` Lan Tianyu
2017-10-19 8:49 ` Roger Pau Monné
2017-10-19 11:28 ` Jan Beulich
2017-10-24 7:16 ` Lan Tianyu
2017-09-22 3:01 ` Lan Tianyu [this message]
2017-10-18 14:05 ` [PATCH V3 2/29] VIOMMU: Add vIOMMU helper functions to create, destroy vIOMMU instance Roger Pau Monné
2017-10-19 6:31 ` Lan Tianyu
2017-10-19 8:47 ` Roger Pau Monné
2017-10-25 1:43 ` Lan Tianyu
2017-10-30 1:41 ` Lan Tianyu
2017-10-30 9:54 ` Roger Pau Monné
2017-10-30 1:51 ` Lan Tianyu
2017-11-06 8:19 ` Jan Beulich
2017-09-22 3:01 ` [PATCH V3 3/29] DOMCTL: Introduce new DOMCTL commands for vIOMMU support Lan Tianyu
2017-10-18 14:18 ` Roger Pau Monné
2017-10-19 6:41 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 4/29] tools/libacpi: Add DMA remapping reporting (DMAR) ACPI table structures Lan Tianyu
2017-10-18 14:36 ` Roger Pau Monné
2017-10-19 6:46 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 5/29] tools/libacpi: Add new fields in acpi_config for DMAR table Lan Tianyu
2017-10-18 15:12 ` Roger Pau Monné
2017-10-19 8:09 ` Lan Tianyu
2017-10-19 8:40 ` Roger Pau Monné
2017-10-25 6:06 ` Lan Tianyu
2017-10-19 11:31 ` Jan Beulich
2017-09-22 3:01 ` [PATCH V3 6/29] tools/libxl: Add a user configurable parameter to control vIOMMU attributes Lan Tianyu
2017-10-19 9:49 ` Roger Pau Monné
2017-10-20 1:36 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 7/29] tools/libxl: build DMAR table for a guest with one virtual VTD Lan Tianyu
2017-10-19 10:00 ` Roger Pau Monné
2017-10-20 1:44 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 8/29] tools/libxl: create vIOMMU during domain construction Lan Tianyu
2017-10-19 10:13 ` Roger Pau Monné
2017-10-26 12:05 ` Wei Liu
2017-10-27 1:58 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 9/29] tools/libxc: Add viommu operations in libxc Lan Tianyu
2017-10-19 10:17 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 10/29] vtd: add and align register definitions Lan Tianyu
2017-10-19 10:21 ` Roger Pau Monné
2017-10-20 1:47 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 11/29] x86/hvm: Introduce a emulated VTD for HVM Lan Tianyu
2017-10-19 11:20 ` Roger Pau Monné
2017-10-20 2:46 ` Chao Gao
2017-10-20 6:56 ` Jan Beulich
2017-10-20 6:12 ` Chao Gao
2017-10-20 8:37 ` Lan Tianyu
2017-09-22 3:01 ` [PATCH V3 12/29] x86/vvtd: Add MMIO handler for VVTD Lan Tianyu
2017-10-19 11:34 ` Roger Pau Monné
2017-10-20 2:58 ` Chao Gao
2017-10-20 9:51 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 13/29] x86/vvtd: Set Interrupt Remapping Table Pointer through GCMD Lan Tianyu
2017-10-19 11:56 ` Roger Pau Monné
2017-10-20 4:08 ` Chao Gao
2017-10-20 6:57 ` Jan Beulich
2017-09-22 3:01 ` [PATCH V3 14/29] x86/vvtd: Enable Interrupt Remapping " Lan Tianyu
2017-10-19 13:42 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 15/29] x86/vvtd: Process interrupt remapping request Lan Tianyu
2017-10-19 14:26 ` Roger Pau Monné
2017-10-20 5:16 ` Chao Gao
2017-10-20 10:01 ` Roger Pau Monné
2017-10-23 6:44 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 16/29] x86/vvtd: decode interrupt attribute from IRTE Lan Tianyu
2017-10-19 14:39 ` Roger Pau Monné
2017-10-20 5:22 ` Chao Gao
2017-09-22 3:01 ` [PATCH V3 17/29] x86/vvtd: add a helper function to decide the interrupt format Lan Tianyu
2017-10-19 14:43 ` Roger Pau Monné
2017-09-22 3:01 ` [PATCH V3 18/29] VIOMMU: Add irq request callback to deal with irq remapping Lan Tianyu
2017-10-19 15:00 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 19/29] x86/vioapic: Hook interrupt delivery of vIOAPIC Lan Tianyu
2017-10-19 15:37 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 20/29] VIOMMU: Add get irq info callback to convert irq remapping request Lan Tianyu
2017-10-19 15:42 ` Roger Pau Monné
2017-10-25 7:30 ` Lan Tianyu
2017-10-25 7:43 ` Roger Pau Monné
2017-10-25 7:38 ` Lan Tianyu
2017-09-22 3:02 ` [PATCH V3 21/29] VIOMMU: Introduce callback of checking irq remapping mode Lan Tianyu
2017-10-19 15:43 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 22/29] x86/vioapic: extend vioapic_get_vector() to support remapping format RTE Lan Tianyu
2017-10-19 15:49 ` Roger Pau Monné
2017-10-19 15:56 ` Jan Beulich
2017-10-20 1:04 ` Chao Gao
2017-09-22 3:02 ` [PATCH V3 23/29] passthrough: move some fields of hvm_gmsi_info to a sub-structure Lan Tianyu
2017-09-22 3:02 ` [PATCH V3 24/29] tools/libxc: Add a new interface to bind remapping format msi with pirq Lan Tianyu
2017-10-19 16:03 ` Roger Pau Monné
2017-10-20 5:39 ` Chao Gao
2017-09-22 3:02 ` [PATCH V3 25/29] x86/vmsi: Hook delivering remapping format msi to guest Lan Tianyu
2017-10-19 16:07 ` Roger Pau Monné
2017-10-20 6:48 ` Jan Beulich
2017-09-22 3:02 ` [PATCH V3 26/29] x86/vvtd: Handle interrupt translation faults Lan Tianyu
2017-10-19 16:31 ` Roger Pau Monné
2017-10-20 5:54 ` Chao Gao
2017-10-20 10:08 ` Roger Pau Monné
2017-10-20 14:20 ` Jan Beulich
2017-09-22 3:02 ` [PATCH V3 27/29] x86/vvtd: Enable Queued Invalidation through GCMD Lan Tianyu
2017-10-20 10:30 ` Roger Pau Monné
2017-09-22 3:02 ` [PATCH V3 28/29] x86/vvtd: Add queued invalidation (QI) support Lan Tianyu
2017-10-20 11:20 ` Roger Pau Monné
2017-10-23 7:50 ` Chao Gao
2017-10-23 8:57 ` Roger Pau Monné
2017-10-23 8:52 ` Chao Gao
2017-10-23 23:26 ` Tian, Kevin
2017-09-22 3:02 ` [PATCH V3 29/29] x86/vvtd: save and restore emulated VT-d Lan Tianyu
2017-10-20 11:25 ` Roger Pau Monné
2017-10-20 11:36 ` [PATCH V3 00/29] Roger Pau Monné
2017-10-23 1:23 ` 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=1506049330-11196-3-git-send-email-tianyu.lan@intel.com \
--to=tianyu.lan@intel.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=chao.gao@intel.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).