Factor VT-d KVM functions into a generic API
Subsystems (6)
PATCH 5/9 VT-d: add domain init and destroy functions for IOMMU API
In reply to Joerg Roedel--- drivers/pci/intel-iommu.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-)
drivers/pci/intel-iommu.c +24 -0
@@ -35,6 +35,7 @@#include <linux/mempool.h> #include <linux/timer.h> #include <linux/iova.h> +#include <linux/iommu.h> #include <linux/intel-iommu.h> #include <asm/cacheflush.h> #include <asm/iommu.h>
@@ -2436,3 +2437,26 @@ u64 intel_iommu_iova_to_pfn(struct dmar_domain *domain, u64 iova)return pfn >>VTD_PAGE_SHIFT ; }EXPORT_SYMBOL_GPL (intel_iommu_iova_to_pfn); + +static int intel_iommu_domain_init (struct iommu_domain *domain, +struct device *dev) +{ +struct dmar_domain *dmar_domain; +struct pci_dev *pdev =to_pci_dev (dev); + +if (!pdev) +return -EINVAL ; + + dmar_domain =intel_iommu_domain_alloc (pdev); + domain->priv = dmar_domain; + +return 0 ; +} + +static void intel_iommu_domain_destroy (struct iommu_domain *domain) +{ +struct dmar_domain *dmar_domain = domain->priv; + +intel_iommu_domain_exit (dmar_domain); + domain->priv =NULL ; +}
Signature · 1 line
1.5.6.4
PATCH 1/9 KVM: rename vtd.c to iommu.c
In reply to Joerg RoedelImpace: file renamed
The code in the vtd.c file can be reused for other IOMMUs as well. So rename it to make it clear that it handle more than VT-d.
--- arch/ia64/kvm/Makefile | 2 +- arch/x86/kvm/Makefile | 2 +- virt/kvm/iommu.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/vtd.c | 191 ------------------------------------------------ 4 files changed, 193 insertions(+), 193 deletions(-) create mode 100644 virt/kvm/iommu.c delete mode 100644 virt/kvm/vtd.c
arch/ia64/kvm/Makefile +1 -1
@@ -52,7 +52,7 @@ common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o ioapic.o \ coalesced_mmio.o irq_comm.o) ifeq ($(CONFIG_DMAR),y) -common-objs += $(addprefix ../../../virt/kvm/, vtd.o) +common-objs += $(addprefix ../../../virt/kvm/, iommu.o) endif kvm-objs := $(common-objs) kvm-ia64.o kvm_fw.o
arch/x86/kvm/Makefile +1 -1
@@ -8,7 +8,7 @@ ifeq ($(CONFIG_KVM_TRACE),y) common-objs += $(addprefix ../../../virt/kvm/, kvm_trace.o) endif ifeq ($(CONFIG_DMAR),y) -common-objs += $(addprefix ../../../virt/kvm/, vtd.o) +common-objs += $(addprefix ../../../virt/kvm/, iommu.o) endif EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm
virt/kvm/iommu.c new file +191 -0
191 lines not on this page · raw message
virt/kvm/vtd.c deleted +0 -191
191 lines not on this page · raw message
Signature · 1 line
1.5.6.4
PATCH 6/9 VT-d: add device attach and detach functions for IOMMU API
In reply to Joerg Roedel--- drivers/pci/intel-iommu.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-)
drivers/pci/intel-iommu.c +32 -0
@@ -2460,3 +2460,35 @@ static void intel_iommu_domain_destroy(struct iommu_domain *domain)intel_iommu_domain_exit (dmar_domain); domain->priv =NULL ; } + +static int intel_iommu_attach_device (struct iommu_domain *domain, +struct device *dev) +{ +struct dmar_domain *dmar_domain; +struct pci_dev *pdev; + + dmar_domain = domain->priv; + pdev =to_pci_dev (dev); + +if (!pdev) +return -EINVAL ; + +intel_iommu_context_mapping (dmar_domain, pdev); + +return 0 ; +} + +static void intel_iommu_detach_device (struct iommu_domain *domain, +struct device *dev) +{ +struct dmar_domain *dmar_domain; +struct pci_dev *pdev; + + dmar_domain = domain->priv; + pdev =to_pci_dev (dev); + +if (!pdev) +return ; + +intel_iommu_detach_dev (dmar_domain, pdev->bus->number, pdev->devfn); +}
Signature · 1 line
1.5.6.4
PATCH 8/9 VT-d: register functions for the IOMMU API
In reply to Joerg Roedel--- drivers/pci/intel-iommu.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/pci/intel-iommu.c +13 -0
@@ -57,6 +57,7 @@static void flush_unmaps_timeout (unsigned long data); +static struct iommu_ops intel_iommu_ops;DEFINE_TIMER (unmap_timer, flush_unmaps_timeout,0 ,0 );
@@ -2326,6 +2327,9 @@ int __init intel_iommu_init(void)init_timer (&unmap_timer); force_iommu =1 ; dma_ops = &intel_dma_ops; + +register_iommu (&intel_iommu_ops); +return 0 ; }
@@ -2514,3 +2518,12 @@ static phys_addr_t intel_iova_to_phys(struct iommu_domain *domain,return (pfn <<PAGE_SHIFT ) & offset; } + +static struct iommu_ops intel_iommu_ops = { + .domain_init = intel_iommu_domain_init, + .domain_destroy = intel_iommu_domain_destroy, + .attach_dev = intel_iommu_attach_device, + .detach_dev = intel_iommu_detach_device, + .map = intel_iommu_map, + .iova_to_phys = intel_iova_to_phys, +};
Signature · 1 line
1.5.6.4
PATCH 2/9 introcude linux/iommu.h for an iommu api
In reply to Joerg RoedelThis patch introduces the API to abstract the exported VT-d functions for KVM into a generic API. This way the AMD IOMMU implementation can plug into this API later.
--- include/linux/iommu.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 100 insertions(+), 0 deletions(-) create mode 100644 include/linux/iommu.h
include/linux/iommu.h new file +100 -0
@@ -0,0 +1,100 @@ +/* +* Copyright (C) 2007-2008 Advanced Micro Devices, Inc. +* Author: Joerg Roedel <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that 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, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __LINUX_IOMMU_H +#define __LINUX_IOMMU_H + +struct device ; + +struct iommu_domain { +void *priv; +}; + +struct iommu_ops { +int (*domain_init)(struct iommu_domain *domain,struct device *dev); +void (*domain_destroy)(struct iommu_domain *domain); +int (*attach_dev)(struct iommu_domain *domain,struct device *dev); +void (*detach_dev)(struct iommu_domain *domain,struct device *dev); +int (*map)(struct iommu_domain *domain,dma_addr_t iova, +phys_addr_t paddr,size_t size,int prot); +phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, +dma_addr_t iova); +}; + +#ifdef CONFIG_IOMMU_API + +extern void register_iommu (struct iommu_ops *ops); +extern bool iommu_found (void ); +extern struct iommu_domain *iommu_domain_alloc (struct device *dev); +extern void iommu_domain_free (struct iommu_domain *domain); +extern int iommu_attach_device (struct iommu_domain *domain, +struct device *dev); +extern void iommu_detach_device (struct iommu_domain *domain, +struct device *dev); +extern int iommu_map_address (struct iommu_domain *domain,dma_addr_t iova, +phys_addr_t paddr,size_t size,int prot); +extern phys_addr_t iommu_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova); + +#else /* CONFIG_IOMMU_API */ + +static inline void register_iommu (struct iommu_ops *ops) +{ +} + +static inline bool iommu_found (void ) +{ +return false; +} + +static inline struct iommu_domain *iommu_domain_alloc (struct device *dev) +{ +return NULL ; +} + +static inline void iommu_domain_free (struct iommu_domain *domain) +{ +} + +static inline int iommu_attach_device (struct iommu_domain *domain, +struct device *dev) +{ +return -ENODEV ; +} + +static inline void iommu_detach_device (struct iommu_domain *domain, +struct device *dev) +{ +} + +static inline int iommu_map_address (struct iommu_domain *domain, +dma_addr_t iova,phys_addr_t paddr, +size_t size,int prot) +{ +return -ENODEV ; +} + +static inline phys_addr_t iommu_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova) +{ +return 0 ; +} + +#endif /* CONFIG_IOMMU_API */ + +#endif /* __LINUX_IOMMU_H */
Signature · 1 line
1.5.6.4
PATCH 4/9 select IOMMU_API when DMAR and/or AMD_IOMMU is selected
In reply to Joerg RoedelThese two IOMMUs can implement the current version of this API. So select the API if one or both of these IOMMU drivers is selected.
--- arch/ia64/Kconfig | 3 +++ arch/x86/Kconfig | 3 +++ drivers/base/Makefile | 1 + 3 files changed, 7 insertions(+), 0 deletions(-)
arch/ia64/Kconfig +3 -0
@@ -687,3 +687,6 @@ config IRQ_PER_CPU config IOMMU_HELPER def_bool (IA64_HP_ZX1 || IA64_HP_ZX1_SWIOTLB || IA64_GENERIC || SWIOTLB) + +config IOMMU_API + def_bool (DMAR)
arch/x86/Kconfig +3 -0
@@ -580,6 +580,9 @@ config SWIOTLB config IOMMU_HELPER def_bool (CALGARY_IOMMU || GART_IOMMU || SWIOTLB || AMD_IOMMU) +config IOMMU_API + def_bool (AMD_IOMMU || DMAR) + config MAXSMP bool "Configure Maximum number of SMP Processors and NUMA Nodes" depends on X86_64 && SMP && BROKEN
drivers/base/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o obj-$(CONFIG_NUMA) += node.o obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o obj-$(CONFIG_SMP) += topology.o +obj-$(CONFIG_IOMMU_API) += iommu.o ifeq ($(CONFIG_SYSFS),y) obj-$(CONFIG_MODULES) += module.o endif
Signature · 1 line
1.5.6.4
cover Factor VT-d KVM functions into a generic API
Hi,
this patch series makes the current KVM device passthrough code generic enough so that other IOMMU implementation can also plug into this code. It works by factoring the functions Vt-d code exports to KVM into a generic interface which allows different backends.
This a basic implementation of a generic interface. It can and should be improved later to support more types of hardware IOMMUs then VT-d and AMD IOMMU.
Since I have no VT-d hardware available these patches are only compile tested for now.
Please review, comment and test these patches.
Thanks,
Joerg
diffstat:
arch/ia64/Kconfig | 3 + arch/ia64/kvm/Makefile | 2 +- arch/x86/Kconfig | 3 + arch/x86/include/asm/kvm_host.h | 3 +- arch/x86/kvm/Makefile | 2 +- drivers/base/Makefile | 1 + drivers/base/iommu.c | 94 +++++++++++++++++++ drivers/pci/intel-iommu.c | 91 ++++++++++++++++++ include/linux/iommu.h | 100 ++++++++++++++++++++ virt/kvm/iommu.c | 193 +++++++++++++++++++++++++++++++++++++++ virt/kvm/vtd.c | 191 --------------------------------------
PATCH 3/9 add frontend implementation for the IOMMU API
--- drivers/base/iommu.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 drivers/base/iommu.c
drivers/base/iommu.c new file +94 -0
@@ -0,0 +1,94 @@ +/* +* Copyright (C) 2007-2008 Advanced Micro Devices, Inc. +* Author: Joerg Roedel <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +* +* This program is distributed in the hope that 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, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/bug.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/iommu.h> + +static struct iommu_ops *iommu_ops; + +void register_iommu (struct iommu_ops *ops) +{ +if (iommu_ops) +BUG (); + + iommu_ops = ops; +} + +bool iommu_found () +{ +return iommu_ops !=NULL ; +} +EXPORT_SYMBOL_GPL (iommu_found); + +struct iommu_domain *iommu_domain_alloc (struct device *dev) +{ +struct iommu_domain *domain; +int ret; + + domain =kmalloc (sizeof (*domain),GFP_KERNEL ); +if (!domain) +return NULL ; + + ret = iommu_ops->domain_init (domain, dev); +if (ret) + goto out_free; + +return domain; + +out_free: +kfree (domain); + +return NULL ; +} +EXPORT_SYMBOL_GPL (iommu_domain_alloc); + +void iommu_domain_free (struct iommu_domain *domain) +{ + iommu_ops->domain_destroy (domain); +kfree (domain); +} +EXPORT_SYMBOL_GPL (iommu_domain_free); + +int iommu_attach_device (struct iommu_domain *domain,struct device *dev) +{ +return iommu_ops->attach_dev (domain, dev); +} +EXPORT_SYMBOL_GPL (iommu_attach_device); + +void iommu_detach_device (struct iommu_domain *domain,struct device *dev) +{ + iommu_ops->detach_dev (domain, dev); +} +EXPORT_SYMBOL_GPL (iommu_detach_device); + +int iommu_map_address (struct iommu_domain *domain, +dma_addr_t iova,phys_addr_t paddr, +size_t size,int prot) +{ +return iommu_ops->map (domain, iova, paddr, size, prot); +} +EXPORT_SYMBOL_GPL (iommu_map_address); + +phys_addr_t iommu_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova) +{ +return iommu_ops->iova_to_phys (domain, iova); +} +EXPORT_SYMBOL_GPL (iommu_iova_to_phys);
Signature · 1 line
1.5.6.4
PATCH 7/9 VT-d: add domain map and iova_to_phys functions for IOMMU API
In reply to Joerg Roedel--- drivers/pci/intel-iommu.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
drivers/pci/intel-iommu.c +22 -0
@@ -2492,3 +2492,25 @@ static void intel_iommu_detach_device(struct iommu_domain *domain,intel_iommu_detach_dev (dmar_domain, pdev->bus->number, pdev->devfn); } + +static int intel_iommu_map (struct iommu_domain *domain,dma_addr_t iova, +phys_addr_t paddr,size_t size,int prot) +{ +struct dmar_domain *dmar_domain = domain->priv; + +return intel_iommu_page_mapping (dmar_domain, iova, paddr, size, prot); +} + +static phys_addr_t intel_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova) +{ +struct dmar_domain *dmar_domain = domain->priv; +u64 pfn; +u64 offset = iova & ~PAGE_MASK ; + + pfn =intel_iommu_iova_to_pfn (dmar_domain, iova); +if (!pfn) +return pfn; + +return (pfn <<PAGE_SHIFT ) & offset; +}
Signature · 1 line
1.5.6.4
PATCH 9/9 KVM: change KVM iommu.c to use IOMMU API
In reply to Joerg Roedel--- arch/x86/include/asm/kvm_host.h | 3 +- virt/kvm/iommu.c | 66 ++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 33 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -1
@@ -14,6 +14,7 @@#include <linux/types.h> #include <linux/mm.h> #include <linux/mmu_notifier.h> +#include <linux/iommu.h> #include <linux/kvm.h> #include <linux/kvm_para.h>
@@ -356,7 +357,7 @@ struct kvm_arch{*/ struct list_head active_mmu_pages;struct list_head assigned_dev_head; -struct dmar_domain *intel_iommu_domain; +struct iommu_domain *iommu_domain;struct kvm_pic *vpic;struct kvm_ioapic *vioapic;struct kvm_pit *vpit;
virt/kvm/iommu.c +34 -32
152 lines not on this page · raw message
Signature · 1 line
1.5.6.4
Quoted 7 lines · Joerg Roedel
Hi,
this patch series makes the current KVM device passthrough code generic enough so that other IOMMU implementation can also plug into this code. It works by factoring the functions Vt-d code exports to KVM into a generic interface which allows different backends.
Quoted 8 lines
This a basic implementation of a generic interface. It can and should be improved later to support more types of hardware IOMMUs then VT-d and AMD IOMMU.
Since I have no VT-d hardware available these patches are only compile tested for now.
Please review, comment and test these patches.
For testing, the patches can be pulled against avi/master from
git://git.kernel.org/pub/scm/linux/kernel/git/joro/linux-2.6-iommu.git iommu-api
Quoted 24 lines
Thanks,
Joerg
diffstat:
arch/ia64/Kconfig | 3 + arch/ia64/kvm/Makefile | 2 +- arch/x86/Kconfig | 3 + arch/x86/include/asm/kvm_host.h | 3 +- arch/x86/kvm/Makefile | 2 +- drivers/base/Makefile | 1 + drivers/base/iommu.c | 94 +++++++++++++++++++ drivers/pci/intel-iommu.c | 91 ++++++++++++++++++ include/linux/iommu.h | 100 ++++++++++++++++++++ virt/kvm/iommu.c | 193 +++++++++++++++++++++++++++++++++++++++ virt/kvm/vtd.c | 191 --------------------------------------_______________________________________________
osrc-patches mailing list
[email protected]
https://ddcwww.amd.com/mailman/listinfo/osrc-patches
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 1/9] KVM: rename vtd.c to iommu.c
In reply to Joerg RoedelQuoted 3 lines · Joerg Roedel
Impace: file renamed
"impact"?
Quoted 10 lines
The code in the
vtd.cfile can be reused for other IOMMUs as well. So rename it to make it clear that it handle more than VT-d.Signed-off-by Joerg Roedel <[email protected]>--- arch/ia64/kvm/Makefile | 2 +- arch/x86/kvm/Makefile | 2 +- virt/kvm/iommu.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/vtd.c | 191 ------------------------------------------------
Use the git -M switch, which show renames as renames instead of removes+adds.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 1/9] KVM: rename vtd.c to iommu.c
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Joerg Roedel
Impace: file renamed
"impact"?
Yeah, patches for x86 should have such a line in the description. I just added it here too because of the many x86-patches I did in the last time. Depending on the way this will be merged I can remove the line from the description.
Quoted 12 lines
Quoted 11 lines
The code in the
vtd.cfile can be reused for other IOMMUs as well. So rename it to make it clear that it handle more than VT-d.Signed-off-by Joerg Roedel <[email protected]>---
arch/ia64/kvm/Makefile | 2 +- arch/x86/kvm/Makefile | 2 +- virt/kvm/iommu.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/vtd.c | 191 ------------------------------------------------
Quoted 1 line
Use the git -M switch, which show renames as renames instead of removes+adds.
Ok, will do this in the next post
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRE: [PATCH 2/9] introcude linux/iommu.h for an iommu api
In reply to Joerg RoedelQuoted 36 lines · Joerg Roedel
This patch introduces the API to abstract the exported VT-d functions for KVM into a generic API. This way the AMD IOMMU implementation can plug into this API later.
Signed-off-by Joerg Roedel <[email protected]>--- include/linux/iommu.h | 100+++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 100 insertions(+), 0 deletions(-) create mode 100644
include/linux/iommu.hinclude/linux/iommu.h new file +5
-0@@ -0,0 +1,100 @@ +/* +* Copyright (C) 2007-2008 Advanced Micro Devices, Inc. +* Author: Joerg Roedel <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */include/linux/iommu.h new file +2
-0+ +#ifndef __LINUX_IOMMU_H
include/linux/iommu.h line 29
Quoted 10 lines
include/linux/iommu.h new file +10
-0+#define __LINUX_IOMMU_H + +struct device ; + +struct iommu_domain { +void *priv; +}; + +struct iommu_ops { +int (*domain_init)(struct iommu_domain *domain,struct device *dev);
needn't parameter dev, use attach_dev to assign dev to domain.
include/linux/iommu.h line 34
Quoted 5 lines
include/linux/iommu.h new file +5
-0+void (*domain_destroy)(struct iommu_domain *domain); +int (*attach_dev)(struct iommu_domain *domain,struct device *dev); +void (*detach_dev)(struct iommu_domain *domain,struct device *dev); +int (*map)(struct iommu_domain *domain,dma_addr_t iova, +phys_addr_t paddr,size_t size,int prot);
It maps/unmaps pages for iommu in kvm, so I think it's better change to
int (*map_pages)(struct iommu_domain *domain, unsigned long gfn, unsigned long pfn, unsigned long npages, int prot); and also add unmap op: int (*unmap_pages)(struct iommu_domain *domain, unsigned long gfn, unsigned long npages);
Quoted 15 lines
include/linux/iommu.h new file +15
-0+phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, +dma_addr_t iova); +}; + +#ifdef CONFIG_IOMMU_API + +extern void register_iommu (struct iommu_ops *ops); +extern bool iommu_found (void ); +extern struct iommu_domain *iommu_domain_alloc (struct device *dev); +extern void iommu_domain_free (struct iommu_domain *domain); +extern int iommu_attach_device (struct iommu_domain *domain, +struct device *dev); +extern void iommu_detach_device (struct iommu_domain *domain, +struct device *dev); +extern int iommu_map_address(struct iommu_domain *domain, dma_addr_t
Quoted 1 line
iova, +
phys_addr_tpaddr,size_tsize, int prot);
similarly:
extern int iommu_map_pages(struct iommu_domain *domain, unsigned long gfn, unsigned long pfn,
unsigned long npages, int prot);
extern int iommu_unmap_pages(struct iommu_domain *domain, unsigned long gfn, unsigned long npages);
Regards,
Weidong
RE: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to Joerg RoedelQuoted 63 lines · Joerg Roedel
Signed-off-by Joerg Roedel <[email protected]>--- drivers/base/iommu.c | 94++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) create mode 100644
drivers/base/iommu.cdrivers/base/iommu.c new file +5
-0@@ -0,0 +1,94 @@ +/* +* Copyright (C) 2007-2008 Advanced Micro Devices, Inc. +* Author: Joerg Roedel <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */drivers/base/iommu.c new file +33
-0+ +#include <linux/bug.h> +#include <linux/types.h> +#include <linux/errno.h> +#include <linux/iommu.h> + +static struct iommu_ops *iommu_ops; + +void register_iommu (struct iommu_ops *ops) +{ +if (iommu_ops) +BUG (); + + iommu_ops = ops; +} + +bool iommu_found () +{ +return iommu_ops !=NULL ; +} +EXPORT_SYMBOL_GPL (iommu_found); + +struct iommu_domain *iommu_domain_alloc (struct device *dev) +{ +struct iommu_domain *domain; +int ret; + + domain =kmalloc (sizeof (*domain),GFP_KERNEL ); +if (!domain) +return NULL ; + + ret = iommu_ops->domain_init (domain, dev); +if (ret)
drivers/base/iommu.c line 60
Quoted 10 lines
drivers/base/iommu.c new file +10
-0+ goto out_free; + +return domain; + +out_free: +kfree (domain); + +return NULL ; +} +EXPORT_SYMBOL_GPL (iommu_domain_alloc);
remove the parameter dev.
Quoted 17 lines
drivers/base/iommu.c new file +9
-0+ +void iommu_domain_free (struct iommu_domain *domain) +{ + iommu_ops->domain_destroy (domain); +kfree (domain); +} +EXPORT_SYMBOL_GPL (iommu_domain_free); + +int iommu_attach_device(struct iommu_domain *domain, struct device*dev) +{
drivers/base/iommu.c new file +5
-0+return iommu_ops->attach_dev (domain, dev); +} +EXPORT_SYMBOL_GPL (iommu_attach_device); + +void iommu_detach_device(struct iommu_domain *domain, struct device*dev) +{
drivers/base/iommu.c new file +1
-0+ iommu_ops->detach_dev (domain, dev);
drivers/base/iommu.c line 87
Quoted 10 lines
drivers/base/iommu.c new file +10
-0+} +EXPORT_SYMBOL_GPL (iommu_detach_device); + +int iommu_map_address (struct iommu_domain *domain, +dma_addr_t iova,phys_addr_t paddr, +size_t size,int prot) +{ +return iommu_ops->map (domain, iova, paddr, size, prot); +} +EXPORT_SYMBOL_GPL (iommu_map_address);
change to:
int iommu_map_pages(struct iommu_domain *domain, unsigned long gfn,
unsigned long pfn, unsigned long npages, int prot)
{
return iommu_ops->map(domain, gfn, pfn, npages, prot);
}EXPORT_SYMBOL_GPL(iommu_map_pages);
int iommu_unmap_pages(struct iommu_domain *domain, unsigned long gfn, unsigned long npages)
{
return iommu_ops->map(domain, gfn, npages);
}EXPORT_SYMBOL_GPL(iommu_unmap_pages);
Regards,
Weidong
Quoted 7 lines
drivers/base/iommu.c new file +7
-0+ +phys_addr_t iommu_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova) +{ +return iommu_ops->iova_to_phys (domain, iova); +} +EXPORT_SYMBOL_GPL (iommu_iova_to_phys);
RE: [PATCH 8/9] VT-d: register functions for the IOMMU API
In reply to Joerg RoedelQuoted 29 lines · Joerg Roedel
Signed-off-by Joerg Roedel <[email protected]>--- drivers/pci/intel-iommu.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)drivers/pci/intel-iommu.c +4
-0@@ -57,6 +57,7 @@static void flush_unmaps_timeout (unsigned long data); +static struct iommu_ops intel_iommu_ops;DEFINE_TIMER (unmap_timer, flush_unmaps_timeout,0 ,0 );@@ -2326,6 +2327,9 @@ int __init intel_iommu_init(void)init_timer (&unmap_timer); force_iommu =1 ; dma_ops = &intel_dma_ops; + +register_iommu (&intel_iommu_ops); +return 0 ; }@@ -2514,3 +2518,12 @@ static phys_addr_t intel_iova_to_phys(struct iommu_domain *domain,
drivers/pci/intel-iommu.c static phys_addr_t intel_iova_to_phys(struct · line 2527
Quoted 10 lines
drivers/pci/intel-iommu.c +7
-0return (pfn <<PAGE_SHIFT ) & offset; } + +static struct iommu_ops intel_iommu_ops = { + .domain_init = intel_iommu_domain_init, + .domain_destroy = intel_iommu_domain_destroy, + .attach_dev = intel_iommu_attach_device, + .detach_dev = intel_iommu_detach_device, + .map = intel_iommu_map,
change to:
.map_pages = intel_iommu_map_pages,
.unmap_pages = intel_iommu_unmap_pages,
drivers/pci/intel-iommu.c static phys_addr_t intel_iova_to_phys(struct iommu_domain *domain, · line 2529
Quoted 2 lines
drivers/pci/intel-iommu.c +2
-0+ .iova_to_phys = intel_iova_to_phys, +};
should remove old kvm VT-d API declarations in include/linux/intel-iommu.h, and don't export them. In fact, should remove old kvm VT-d APIs, and move their code to corresponding new APIs. I can help you to do this if need.
Regards,
Weidong
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to Joerg Roedeldrivers/base/iommu.c
Quoted 11 lines · On Thu, 27 Nov 2008 16:40:48 +0100 Joerg Roedel <[email protected]> wrote:
Signed-off-by Joerg Roedel <[email protected]>--- drivers/base/iommu.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 drivers/base/iommu.cdrivers/base/iommu.c new file +0
-0
Hmm, why is this at drivers/base/? Anyone except for kvm could use this? If so, under virt/ is more appropriate?
The majority of the names (include/linux/iommu.h, iommu.c, iommu_ops, etc) looks too generic? We already have lots of similar things (e.g. arch/{x86,ia64}/asm/iommu.h, several archs' iommu.c, etc). Such names are expected to be used by all the IOMMUs.
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 9 lines · FUJITA Tomonori
Quoted 6 lines · On Thu, 27 Nov 2008 16:40:48 +0100 Joerg Roedel <[email protected]> wrote:
Signed-off-by Joerg Roedel <[email protected]>--- drivers/base/iommu.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 drivers/base/iommu.c
Quoted 8 lines
drivers/base/iommu.c
Quoted 5 lines
drivers/base/iommu.c new file +0
-0Hmm, why is this at
drivers/base/? Anyone except for kvm could use this? If so, undervirt/is more appropriate?
I don't see a reason why this should be KVM specific. KVM is the only user for now. But it can be used for i.e. UIO too. Or in drivers to speed up devices which have bad performance when they do scather gather IO.
Quoted 4 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.
The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Joerg
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 1/9] KVM: rename vtd.c to iommu.c
In reply to Joerg RoedelQuoted 8 lines · Joerg Roedel
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel
Impace: file renamed
Quoted 9 lines
Quoted 2 lines
"impact"?
Yeah, patches for x86 should have such a line in the description. I just added it here too because of the many x86-patches I did in the last time. Depending on the way this will be merged I can remove the line from the description.
I meant, you have a typo. Sorry for not being explicit.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to Joerg RoedelQuoted 19 lines · On Fri, 28 Nov 2008 12:31:29 +0100 Joerg Roedel <[email protected]> wrote:
Quoted 9 lines · FUJITA Tomonori
Quoted 6 lines · On Thu, 27 Nov 2008 16:40:48 +0100 Joerg Roedel <[email protected]> wrote:
Signed-off-by Joerg Roedel <[email protected]>--- drivers/base/iommu.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 drivers/base/iommu.cQuoted 8 lines
drivers/base/iommu.c
Quoted 5 lines
drivers/base/iommu.c new file +0
-0Hmm, why is this at
drivers/base/? Anyone except for kvm could use this? If so, undervirt/is more appropriate?
Quoted 4 lines
I don't see a reason why this should be KVM specific. KVM is the only user for now. But it can be used for i.e. UIO too. Or in drivers to speed up devices which have bad performance when they do scather gather IO.
If there are some except for kvm that could use this, it should be fine, I guess.
Can you add such information (e.g. who could use this) to the patch description? It should be in the git log if the patch is merged.
Quoted 9 lines
Quoted 4 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Can you be more specific? What IOMMU could use this? For example, how GART can use this? I think that people expect the name 'struct iommu_ops' to be an abstract for all the IOMMUs (or the majority at least). If this works like that, the name is a good choice, I think.
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 27 lines · FUJITA Tomonori
Quoted 19 lines · On Fri, 28 Nov 2008 12:31:29 +0100 Joerg Roedel <[email protected]> wrote:
Quoted 9 lines · FUJITA Tomonori
Quoted 6 lines · On Thu, 27 Nov 2008 16:40:48 +0100 Joerg Roedel <[email protected]> wrote:
Signed-off-by Joerg Roedel <[email protected]>--- drivers/base/iommu.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 drivers/base/iommu.cQuoted 8 lines
drivers/base/iommu.c
Quoted 5 lines
drivers/base/iommu.c new file +0
-0Hmm, why is this at
drivers/base/? Anyone except for kvm could use this? If so, undervirt/is more appropriate?Quoted 4 lines
I don't see a reason why this should be KVM specific. KVM is the only user for now. But it can be used for i.e. UIO too. Or in drivers to speed up devices which have bad performance when they do scather gather IO.
Quoted 5 lines
If there are some except for kvm that could use this, it should be fine, I guess.
Can you add such information (e.g. who could use this) to the patch description? It should be in the git log if the patch is merged.
Ok, I will add it.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Quoted 4 lines
Can you be more specific? What IOMMU could use this? For example, how GART can use this? I think that people expect the name 'struct
iommu_ops' to be an abstract for all the IOMMUs (or the majority at least). If this works like that, the name is a good choice, I think.
GART can't use exactly this. But with some extensions we can make it useful for GART and GART-like IOMMUs too. For example we can emulate domains in GART by partitioning the GART aperture space.
Joerg
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 18 lines · Joerg Roedel
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Quoted 5 lines
Can you be more specific? What IOMMU could use this? For example, how GART can use this? I think that people expect the name 'struct
iommu_ops' to be an abstract for all the IOMMUs (or the majority at least). If this works like that, the name is a good choice, I think.
Quoted 3 lines
GART can't use exactly this. But with some extensions we can make it useful for GART and GART-like IOMMUs too. For example we can emulate domains in GART by partitioning the GART aperture space.
That would only work with a pvdma API, since GART doesn't support multiple address spaces, and you don't get the isolation properties of a real IOMMU, so... why would you want to do that?
Cheers,
Muli
Signature · 5 lines
The First Workshop on I/O Virtualization (WIOV '08)
Dec 2008, San Diego, CA, http://www.usenix.org/wiov08/
<->
SYSTOR 2009---The Israeli Experimental Systems Conference
http://www.haifa.il.ibm.com/conferences/systor2009/Re: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 20 lines · Muli Ben-Yehuda
Quoted 18 lines · Joerg Roedel
Quoted 17 lines
Quoted 11 lines
Quoted 5 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Can you be more specific? What IOMMU could use this? For example, how GART can use this? I think that people expect the name 'struct
iommu_ops' to be an abstract for all the IOMMUs (or the majority at least). If this works like that, the name is a good choice, I think.
Quoted 7 lines
Quoted 3 lines
GART can't use exactly this. But with some extensions we can make it useful for GART and GART-like IOMMUs too. For example we can emulate domains in GART by partitioning the GART aperture space.
That would only work with a pvdma API, since GART doesn't support multiple address spaces, and you don't get the isolation properties of a real IOMMU, so... why would you want to do that?
Yes, this can not be used for not-pv device passthrough. But I think it can speed up the pvdma case. Beside that I can be used for UIO and devices which perform bad with sg.
Joerg
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to Muli Ben-YehudaQuoted 20 lines · On Mon, 1 Dec 2008 15:02:09 +0200 Muli Ben-Yehuda <[email protected]> wrote:
Quoted 18 lines · Joerg Roedel
Quoted 17 lines
Quoted 11 lines
Quoted 5 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Can you be more specific? What IOMMU could use this? For example, how GART can use this? I think that people expect the name 'struct
iommu_ops' to be an abstract for all the IOMMUs (or the majority at least). If this works like that, the name is a good choice, I think.
Quoted 7 lines
Quoted 3 lines
GART can't use exactly this. But with some extensions we can make it useful for GART and GART-like IOMMUs too. For example we can emulate domains in GART by partitioning the GART aperture space.
That would only work with a pvdma API, since GART doesn't support multiple address spaces, and you don't get the isolation properties of a real IOMMU, so... why would you want to do that?
If this works for only IOMMUs that support kinda domain concept, then I think that a name like iommu_domain_ops is more appropriate.
Joerg Roedel
maintainerRe: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 27 lines · FUJITA Tomonori
Quoted 24 lines · On Mon, 1 Dec 2008 15:02:09 +0200 Muli Ben-Yehuda <[email protected]> wrote:
Quoted 21 lines · Joerg Roedel
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
The majority of the names (
include/linux/iommu.h,iommu.c,iommu_ops, etc) looks too generic? We already have lots of similar things (e.g.arch/{x86,ia64}/asm/iommu.h, several archs'iommu.c, etc). Such names are expected to be used by all the IOMMUs.The API is already useful for more than KVM. I also plan to extend it to support more types of IOMMUs than VT-d and AMD IOMMU in the future. But these changes are more intrusive than this patchset and need more discussion. I prefer to do small steps into this direction.
Quoted 5 lines
Can you be more specific? What IOMMU could use this? For example, how GART can use this? I think that people expect the name 'struct
iommu_ops' to be an abstract for all the IOMMUs (or the majority at least). If this works like that, the name is a good choice, I think.GART can't use exactly this. But with some extensions we can make it useful for GART and GART-like IOMMUs too. For example we can emulate domains in GART by partitioning the GART aperture space.
Quoted 6 lines
Quoted 3 lines
That would only work with a pvdma API, since GART doesn't support multiple address spaces, and you don't get the isolation properties of a real IOMMU, so... why would you want to do that?
If this works for only IOMMUs that support kinda domain concept, then I think that a name like
iommu_domain_opsis more appropriate.
Hmm, is there any hardware IOMMU with which we can't emulate domains by partitioning the IO address space? This concept works for GART and Calgary.
Joerg
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 5 lines · Joerg Roedel
Hmm, is there any hardware IOMMU with which we can't emulate domains by partitioning the IO address space? This concept works for GART and Calgary.
Is partitioning secure? Domain X's user could program its hardware to dma to domain Y's addresses, zapping away Domain Y's user's memory.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 9 lines · Avi Kivity
Quoted 5 lines · Joerg Roedel
Hmm, is there any hardware IOMMU with which we can't emulate domains by partitioning the IO address space? This concept works for GART and Calgary.
Is partitioning secure? Domain X's user could program its hardware to dma to domain Y's addresses, zapping away Domain Y's user's memory.
No its not secure. But this problem exists with pv-dma without iommu too.
Joerg
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to Avi KivityQuoted 9 lines · On Mon, 01 Dec 2008 16:33:11 +0200 Avi Kivity <[email protected]> wrote:
Quoted 5 lines · Joerg Roedel
Hmm, is there any hardware IOMMU with which we can't emulate domains by partitioning the IO address space? This concept works for GART and Calgary.
Is partitioning secure? Domain X's user could program its hardware to dma to domain Y's addresses, zapping away Domain Y's user's memory.
It can't be secure. So what's the point to emulate the domain partitioning in many traditional hardware IOMMUs that doesn't support it.
The emulated domain support with the DMA mapping debugging feature might be useful to debug drivers but it doesn't mean that we need to add the emulated domain support to every hardware IOMMU. If you add it to swiotlb, everyone can enjoy the debugging.
Re: [PATCH 3/9] add frontend implementation for the IOMMU API
Quoted 10 lines · FUJITA Tomonori
Quoted 7 lines · On Mon, 01 Dec 2008 16:33:11 +0200 Avi Kivity <[email protected]> wrote:
Quoted 5 lines · Joerg Roedel
Hmm, is there any hardware IOMMU with which we can't emulate domains by partitioning the IO address space? This concept works for GART and Calgary.
Quoted 6 lines
Quoted 2 lines
Is partitioning secure? Domain X's user could program its hardware to dma to domain Y's addresses, zapping away Domain Y's user's memory.
It can't be secure. So what's the point to emulate the domain partitioning in many traditional hardware IOMMUs that doesn't support it.
Its a generic way to make non-contiguous host memory io-contiguous. I already pointed out some potential users for this.
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to FUJITA TomonoriQuoted 10 lines · FUJITA Tomonori
Quoted 7 lines · On Mon, 01 Dec 2008 16:33:11 +0200 Avi Kivity <[email protected]> wrote:
Quoted 5 lines · Joerg Roedel
Hmm, is there any hardware IOMMU with which we can't emulate domains by partitioning the IO address space? This concept works for GART and Calgary.
Quoted 6 lines
Quoted 2 lines
Is partitioning secure? Domain X's user could program its hardware to dma to domain Y's addresses, zapping away Domain Y's user's memory.
It can't be secure. So what's the point to emulate the domain partitioning in many traditional hardware IOMMUs that doesn't support it.
Btw, if you use the k8-agp driver the GART space is already partitioned today. So this concept is not entirely new.
Joerg
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoyRe: [PATCH 3/9] add frontend implementation for the IOMMU API
In reply to Han, WeidongQuoted 16 lines · Weidong
Quoted 15 lines · Joerg Roedel
drivers/base/iommu.c new file +15
-0+struct iommu_domain *iommu_domain_alloc (struct device *dev) +{ +struct iommu_domain *domain; +int ret; + + domain =kmalloc (sizeof (*domain),GFP_KERNEL ); +if (!domain) +return NULL ; + + ret = iommu_ops->domain_init (domain, dev); +if (ret) + goto out_free; + +return domain; +
Quoted 8 lines
drivers/base/iommu.c line 60
Quoted 6 lines
drivers/base/iommu.c new file +6
-0+out_free: +kfree (domain); + +return NULL ; +} +EXPORT_SYMBOL_GPL (iommu_domain_alloc);remove the parameter dev.
[x] Done.
Quoted 34 lines
Quoted 17 lines
drivers/base/iommu.c new file +9
-0+ +void iommu_domain_free (struct iommu_domain *domain) +{ + iommu_ops->domain_destroy (domain); +kfree (domain); +} +EXPORT_SYMBOL_GPL (iommu_domain_free); + +int iommu_attach_device(struct iommu_domain *domain, struct device*dev) +{
drivers/base/iommu.c new file +5
-0+return iommu_ops->attach_dev (domain, dev); +} +EXPORT_SYMBOL_GPL (iommu_attach_device); + +void iommu_detach_device(struct iommu_domain *domain, struct device*dev) +{
drivers/base/iommu.c new file +1
-0+ iommu_ops->detach_dev (domain, dev);drivers/base/iommu.c line 87
Quoted 10 lines
drivers/base/iommu.c new file +10
-0+} +EXPORT_SYMBOL_GPL (iommu_detach_device); + +int iommu_map_address (struct iommu_domain *domain, +dma_addr_t iova,phys_addr_t paddr, +size_t size,int prot) +{ +return iommu_ops->map (domain, iova, paddr, size, prot); +} +EXPORT_SYMBOL_GPL (iommu_map_address);change to:
int iommu_map_pages(structiommu_domain*domain, unsigned long gfn,
unsigned long pfn, unsigned long npages, int prot){ return iommu_ops->map(domain, gfn, pfn, npages, prot); }
Quoted 7 lines
EXPORT_SYMBOL_GPL(iommu_map_pages);int
iommu_unmap_pages(struct iommu_domain *domain, unsigned long gfn, unsigned long npages){ return iommu_ops->map(domain, gfn, npages); }
EXPORT_SYMBOL_GPL(iommu_unmap_pages);
Ok, I added the unmap function. But I think this API should work with addresses instead of page numbers. This way the IO page size is transparent for the user.
Signature · 6 lines
| AMD Saxony Limited Liability Company & Co. KG
Operating | Wilschdorfer Landstr. 101, 01109 Dresden, Germany
System | Register Court Dresden: HRA 4896
Research | General Partner authorized to represent:
Center | AMD Saxony LLC (Wilmington, Delaware, US)
| General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy