Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On Thu, 2012-11-22 at 11:56 +, Sethi Varun-B16395 wrote: -Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG(...) static int novmerge; static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int); static int __init
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On Fri, 2012-11-23 at 13:02 +1100, Alexey Kardashevskiy wrote: On 22/11/12 22:56, Sethi Varun-B16395 wrote: -Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On Mon, 2012-11-26 at 08:18 -0700, Alex Williamson wrote: On Fri, 2012-11-23 at 13:02 +1100, Alexey Kardashevskiy wrote: On 22/11/12 22:56, Sethi Varun-B16395 wrote: -Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On Mon, 2012-11-26 at 11:04 -0700, Alex Williamson wrote: Ok, I see tces are put on shutdown via tce_iommu_detach_group, so you're more concerned about the guest simply mapping over top of it's own mappings. Is that common? Is it common enough for every multi-page mapping to assume it will happen? I know this is a performance sensitive path for you and it seems like a map-only w/ fallback to unmap, remap would be better in the general case. On x86 we do exactly that, but we do the unmap, remap from userspace when we get an EBUSY. Thanks, Right, Linux as guest at least will never map over an existing mapping. It will always unmap first. IE. The only transition we do on H_PUT_TCE are 0 - valid and valid - 0. So it would be fine to simplify the code and keep the map over map as a slow fallback. I can't tell for other operating systems but we don't care about those at this point :-) Cheers, Ben. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On 27/11/12 05:04, Alex Williamson wrote: On Mon, 2012-11-26 at 08:18 -0700, Alex Williamson wrote: On Fri, 2012-11-23 at 13:02 +1100, Alexey Kardashevskiy wrote: On 22/11/12 22:56, Sethi Varun-B16395 wrote: -Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG(...) static int novmerge; static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int); static int __init
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On Tue, 2012-11-27 at 14:28 +1100, Alexey Kardashevskiy wrote: On 27/11/12 05:04, Alex Williamson wrote: On Mon, 2012-11-26 at 08:18 -0700, Alex Williamson wrote: On Fri, 2012-11-23 at 13:02 +1100, Alexey Kardashevskiy wrote: On 22/11/12 22:56, Sethi Varun-B16395 wrote: -Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci
RE: [PATCH] vfio powerpc: enabled and supported on powernv platform
-Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG(...) static int novmerge; static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int); static int __init setup_iommu(char *str) { if (!strcmp(str, novmerge)) novmerge = 1; else if (!strcmp(str, vmerge)) novmerge = 0
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On 22/11/12 22:56, Sethi Varun-B16395 wrote: -Original Message- From: linux-kernel-ow...@vger.kernel.org [mailto:linux-kernel- ow...@vger.kernel.org] On Behalf Of Alex Williamson Sent: Tuesday, November 20, 2012 11:50 PM To: Alexey Kardashevskiy Cc: Benjamin Herrenschmidt; Paul Mackerras; linuxppc- d...@lists.ozlabs.org; linux-ker...@vger.kernel.org; k...@vger.kernel.org; David Gibson Subject: Re: [PATCH] vfio powerpc: enabled and supported on powernv platform On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG(...) static int novmerge; static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int); static int __init setup_iommu(char *str) { if (!strcmp(str, novmerge)) novmerge = 1; else if (!strcmp(str, vmerge)) novmerge = 0; return 1; } @@ -844,15 +845,154 @@ void
Re: [PATCH] vfio powerpc: enabled and supported on powernv platform
On Tue, 2012-11-20 at 11:48 +1100, Alexey Kardashevskiy wrote: VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG(...) static int novmerge; static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int); static int __init setup_iommu(char *str) { if (!strcmp(str, novmerge)) novmerge = 1; else if (!strcmp(str, vmerge)) novmerge = 0; return 1; } @@ -844,15 +845,154 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl, } void iommu_free_coherent(struct iommu_table *tbl, size_t size, void *vaddr, dma_addr_t dma_handle) { if (tbl) { unsigned int nio_pages; size = PAGE_ALIGN(size); nio_pages = size IOMMU_PAGE_SHIFT; iommu_free(tbl, dma_handle, nio_pages); size =
[PATCH] vfio powerpc: enabled and supported on powernv platform
VFIO implements platform independent stuff such as a PCI driver, BAR access (via read/write on a file descriptor or direct mapping when possible) and IRQ signaling. The platform dependent part includes IOMMU initialization and handling. This patch initializes IOMMU groups based on the IOMMU configuration discovered during the PCI scan, only POWERNV platform is supported at the moment. Also the patch implements an VFIO-IOMMU driver which manages DMA mapping/unmapping requests coming from the client (now QEMU). It also returns a DMA window information to let the guest initialize the device tree for a guest OS properly. Although this driver has been tested only on POWERNV, it should work on any platform supporting TCE tables. To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config option. Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru --- arch/powerpc/include/asm/iommu.h |6 + arch/powerpc/kernel/iommu.c | 140 +++ arch/powerpc/platforms/powernv/pci.c | 135 +++ drivers/iommu/Kconfig|8 ++ drivers/vfio/Kconfig |6 + drivers/vfio/Makefile|1 + drivers/vfio/vfio_iommu_spapr_tce.c | 247 ++ include/linux/vfio.h | 20 +++ 8 files changed, 563 insertions(+) create mode 100644 drivers/vfio/vfio_iommu_spapr_tce.c diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h index cbfe678..5ba66cb 100644 --- a/arch/powerpc/include/asm/iommu.h +++ b/arch/powerpc/include/asm/iommu.h @@ -64,30 +64,33 @@ struct iommu_pool { } cacheline_aligned_in_smp; struct iommu_table { unsigned long it_busno; /* Bus number this table belongs to */ unsigned long it_size; /* Size of iommu table in entries */ unsigned long it_offset;/* Offset into global table */ unsigned long it_base; /* mapped address of tce table */ unsigned long it_index; /* which iommu table this is */ unsigned long it_type; /* type: PCI or Virtual Bus */ unsigned long it_blocksize; /* Entries in each block (cacheline) */ unsigned long poolsize; unsigned long nr_pools; struct iommu_pool large_pool; struct iommu_pool pools[IOMMU_NR_POOLS]; unsigned long *it_map; /* A simple allocation bitmap for now */ +#ifdef CONFIG_IOMMU_API + struct iommu_group *it_group; +#endif }; struct scatterlist; static inline void set_iommu_table_base(struct device *dev, void *base) { dev-archdata.dma_data.iommu_table_base = base; } static inline void *get_iommu_table_base(struct device *dev) { return dev-archdata.dma_data.iommu_table_base; } /* Frees table for an individual device node */ @@ -135,17 +138,20 @@ static inline void pci_iommu_init(void) { } extern void alloc_dart_table(void); #if defined(CONFIG_PPC64) defined(CONFIG_PM) static inline void iommu_save(void) { if (ppc_md.iommu_save) ppc_md.iommu_save(); } static inline void iommu_restore(void) { if (ppc_md.iommu_restore) ppc_md.iommu_restore(); } #endif +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry, uint64_t tce, + enum dma_data_direction direction, unsigned long pages); + #endif /* __KERNEL__ */ #endif /* _ASM_IOMMU_H */ diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c index ff5a6ce..94f614b 100644 --- a/arch/powerpc/kernel/iommu.c +++ b/arch/powerpc/kernel/iommu.c @@ -32,30 +32,31 @@ #include linux/dma-mapping.h #include linux/bitmap.h #include linux/iommu-helper.h #include linux/crash_dump.h #include linux/hash.h #include linux/fault-inject.h #include linux/pci.h #include asm/io.h #include asm/prom.h #include asm/iommu.h #include asm/pci-bridge.h #include asm/machdep.h #include asm/kdump.h #include asm/fadump.h #include asm/vio.h +#include asm/tce.h #define DBG(...) static int novmerge; static void __iommu_free(struct iommu_table *, dma_addr_t, unsigned int); static int __init setup_iommu(char *str) { if (!strcmp(str, novmerge)) novmerge = 1; else if (!strcmp(str, vmerge)) novmerge = 0; return 1; } @@ -844,15 +845,154 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl, } void iommu_free_coherent(struct iommu_table *tbl, size_t size, void *vaddr, dma_addr_t dma_handle) { if (tbl) { unsigned int nio_pages; size = PAGE_ALIGN(size); nio_pages = size IOMMU_PAGE_SHIFT; iommu_free(tbl, dma_handle, nio_pages); size = PAGE_ALIGN(size); free_pages((unsigned long)vaddr, get_order(size)); } } + +#ifdef CONFIG_IOMMU_API +/* + * SPAPR TCE API + */