powerpc/powenv/ioda: Allow huge DMA window at 4GB
Subsystems (4)
cover powerpc/powenv/ioda: Allow huge DMA window at 4GB
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).
For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1a6ed68d6468b Linus Torvalds "Merge tag 'drm-next-2019-11-27' of git://anongit.freedesktop.org/drm/drm".
Please comment. Thanks.
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GB
arch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Signature · 1 line
2.17.1
RFC PATCH 1/4 powerpc/powernv/ioda: Rework for huge DMA window at 4GB
This moves code to make the next patches look simpler. In particular:
1. Separate locals declaration as we will be allocating a smaller DMA window if a TVE1_4GB option (allows a huge DMA windows at 4GB) is enabled;
2. Pass the bypass offset directly to pnv_pci_ioda2_create_table() as it is the only information needed from @pe;
3. Use PAGE_SHIFT for it_map allocation estimate and @tceshift for the IOMMU page size; this makes the distinction clear and allows easy switching between different IOMMU page size.
These changes should not cause behavioral change.
---
I really need 1), 2) makes the code less dependent on the PE struct member value (==easier to follow), 3) is to enable 2MB quickly for the default DMA window for debugging/performance testing.
--- arch/powerpc/platforms/powernv/pci-ioda.c | 38 ++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda.c +20 -18
@@ -2349,15 +2349,10 @@ static void pnv_pci_ioda2_set_bypass(struct pnv_ioda_pe *pe, bool enable) pe->tce_bypass_enabled = enable; } -static long pnv_pci_ioda2_create_table (struct iommu_table_group *table_group, -int num,__u32 page_shift,__u64 window_size,__u32 levels, +static long pnv_pci_ioda2_create_table (int nid,int num,__u64 bus_offset, +__u32 page_shift,__u64 window_size,__u32 levels,bool alloc_userspace_copy,struct iommu_table **ptbl) { - struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe, - table_group); -int nid = pe->phb->hose->node; -__u64 bus_offset = num ? - pe->table_group.tce64_start : table_group->tce32_start;long ret;struct iommu_table *tbl;
@@ -2384,21 +2379,23 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe) {struct iommu_table *tbl =NULL ;long rc; -unsigned long res_start, res_end; +u64 max_memory, maxblock, window_size; +const unsigned int tceshift =PAGE_SHIFT ; +unsigned long res_start, res_end, tces_order, tcelevel_order, levels;/* * crashkernel= specifies the kdump kernel's maximum memory at * some offset and there is no guaranteed the result is a power * of 2, which will cause errors later. */ -const u64 max_memory =__rounddown_pow_of_two (memory_hotplug_max ()); + max_memory =__rounddown_pow_of_two (memory_hotplug_max ());/* * In memory constrained environments, e.g. kdump kernel, the * DMA window can be larger than available memory, which will * cause errors later. */ -const u64 maxblock =1UL << (PAGE_SHIFT +MAX_ORDER -1 ); + maxblock =1UL << (PAGE_SHIFT +MAX_ORDER -1 );/* * We create the default window as big as we can. The constraint is
@@ -2408,11 +2405,11 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)* to support crippled devices (i.e. not fully 64bit DMAble) only. */ /* iommu_table::it_map uses 1 bit per IOMMU page, hence 8 */ -const u64 window_size =min ((maxblock *8 ) <<PAGE_SHIFT , max_memory); + window_size =min ((maxblock *8 ) << tceshift, max_memory);/* Each TCE level cannot exceed maxblock so go multilevel if needed */ -unsigned long tces_order =ilog2 (window_size >>PAGE_SHIFT ); -unsigned long tcelevel_order =ilog2 (maxblock >>3 ); -unsigned int levels = tces_order / tcelevel_order; + tces_order =ilog2 (window_size >> tceshift); + tcelevel_order =ilog2 (maxblock >>3 ); + levels = tces_order / tcelevel_order;if (tces_order % tcelevel_order) levels +=1 ;
@@ -2422,8 +2419,8 @@ static long pnv_pci_ioda2_setup_default_config(struct pnv_ioda_pe *pe)*/ levels = max_t(unsigned int, levels, POWERNV_IOMMU_DEFAULT_LEVELS); - rc =pnv_pci_ioda2_create_table (&pe->table_group,0 ,PAGE_SHIFT , - window_size, levels, false, &tbl); + rc =pnv_pci_ioda2_create_table (pe->phb->hose->node, +0 ,0 , tceshift, window_size, levels, false, &tbl);if (rc) {pe_err (pe,"Failed to create 32-bit TCE table, err %ld" , rc);
@@ -2525,8 +2522,13 @@ static long pnv_pci_ioda2_create_table_userspace( int num, __u32 page_shift, __u64 window_size, __u32 levels, struct iommu_table **ptbl) { - long ret = pnv_pci_ioda2_create_table(table_group, - num, page_shift, window_size, levels, true, ptbl); + struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe, + table_group); +__u64 bus_offset = num ? + pe->table_group.tce64_start : table_group->tce32_start; +long ret =pnv_pci_ioda2_create_table (pe->phb->hose->node, + num, bus_offset, page_shift, window_size, levels, true, + ptbl);if (!ret) (*ptbl)->it_allocated_size = pnv_pci_ioda2_get_table_size(
Signature · 1 line
2.17.1
RFC PATCH 2/4 powerpc/powernv/ioda: Allow smaller TCE table levels
In reply to Alexey KardashevskiyNow the minimum allocation size for a TCE table level is PAGE_SIZE (64k) as this is the minimum for alloc_pages(). The limit was set in POWER8 where we did not have sparse RAM so we did not need sparse TCE tables. On POWER9 we have gaps in the phys address space for which using multi level TCE tables makes sense. The problem with that is that 64K per level is too much for 2 levels and 1GB pages as it exceeds the hardware limit of 55bits so we need smaller levels.
This drops the minimum level size to 4K.
For a machine with 2 CPUs, top RAM address 0x4000.0000.0000 (each node gets 32TiB) and 1GiB IOMMU pages:
Before the patch: 512KiB or 8 pages.
After the patch: 3 pages: one level1 + 2xlevel2 tables, each can map up to 64k>>3<<30 = 8TiB of physical space.
--- arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda-tce.c +2 -2
@@ -37,7 +37,7 @@ static __be64 *pnv_alloc_tce_level(int nid, unsigned int shift)__be64 *addr; tce_mem =alloc_pages_node (nid,GFP_ATOMIC | __GFP_NOWARN, - shift -PAGE_SHIFT ); + shift >PAGE_SHIFT ? shift -PAGE_SHIFT :0 );if (!tce_mem) {pr_err ("Failed to allocate a TCE memory, level shift=%d\n" , shift);
@@ -282,7 +282,7 @@ long pnv_pci_ioda2_table_alloc_pages(int nid, __u64 bus_offset,/* Adjust direct table size from window_size and levels */ entries_shift = (entries_shift + levels -1 ) / levels; level_shift = entries_shift +3 ; - level_shift = max_t(unsigned int, level_shift, PAGE_SHIFT); + level_shift = max_t(unsigned int, level_shift, 12); /* 4K is minimum */if ((level_shift -3 ) * levels + page_shift >=55 )return -EINVAL ;
Signature · 1 line
2.17.1
RFC PATCH 3/4 powerpc/powernv/phb4: Add 4GB IOMMU bypass mode
In reply to Alexey KardashevskiyIODA2 systems (POWER8/9) allow DMA windows at 2 fixed locations - 0 and 0x800.0000.0000.0000==1<<59, stored in TVT as TVE0/1. PHB4 on POWER9 has an additional PHB mode to allow mapping both windows at 0 and selecting one based on IOBA address - accesses below 4GB go via TVE0 and above 4GB - via TVE1.
This adds a new value for the "iommu" kernel parameter - "iommu_bypass". When enabled this programs PHB to enable the TVE1_4GB mode and uses TVE1 to map the entire host RAM using the largest available IOMMU pages
- 1GB for PHB and 256MB for NPU-PHB effectively.
This creates huge DMA windows at 4GB for VFIO; new iommu_table::it_dmaoff flag tells the VFIO IOMMU driver about the bus offset it should be using. Since the actual second table still covers the first 4GB of the bus space iommu_table::it_offset is set to 0. The next patch will explicitly advertise new offset to the userspace.
When TVE1_4GB enabled, this creates a small (2GB typically) 32 bit window as there is no need to cover as much of lower DMA space - the 4GB+ window does it better anyway.
This keeps the existing behavior by default as the TVE1_4GB flag is set per PHB by device assignment is done on PE basis and managing both modes dynamically might get nasty.
This relies on skiboot supporting the new OPAL_PHB_SET_OPTION OPAL call.
--- arch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda.c | 191 +++++++++++++++++---- 6 files changed, 175 insertions(+), 33 deletions(-)
arch/powerpc/include/asm/iommu.h +1 -0
@@ -97,6 +97,7 @@ struct iommu_table {unsigned long it_level_size;unsigned long it_allocated_size;unsigned long it_offset;/* Offset into global table */ +unsigned long it_dmaoff;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 */
arch/powerpc/include/asm/opal-api.h +10 -1
@@ -211,7 +211,12 @@#define OPAL_MPIPL_UPDATE 173#define OPAL_MPIPL_REGISTER_TAG 174#define OPAL_MPIPL_QUERY_TAG 175 -#define OPAL_LAST 175 +#define OPAL_SECVAR_GET 176 +#define OPAL_SECVAR_GET_NEXT 177 +#define OPAL_SECVAR_ENQUEUE_UPDATE 178 +#define OPAL_PHB_SET_OPTION 179 +#define OPAL_PHB_GET_OPTION 180 +#define OPAL_LAST 180#define QUIESCE_HOLD 1/* Spin all calls at entry */ #define QUIESCE_REJECT 2/* Fail all calls with OPAL_BUSY */
@@ -434,6 +439,10 @@ enum OpalSlotLedState { OPAL_SLOT_LED_STATE_ON = 1 /* LED is ON */ }; +enum OpalPhbOption { +OPAL_PCI_PHB_FLAG_TVE1_4GB =0x1 , +}; +/* * Address cycle types for LPC accesses. These also correspond * to the content of the first cell of the "reg" property for
arch/powerpc/include/asm/opal.h +2 -0
@@ -142,6 +142,8 @@ int64_t opal_pci_map_pe_dma_window(uint64_t phb_id, uint16_t pe_number, uint16_tint64_t opal_pci_map_pe_dma_window_real (uint64_t phb_id,uint16_t pe_number,uint16_t dma_window_number,uint64_t pci_start_addr,uint64_t pci_mem_size); +int64_t opal_phb_set_option (uint64_t phb_id,uint64_t opt,uint64_t setting); +int64_t opal_phb_get_option (uint64_t phb_id,uint64_t opt,uint64_t *setting);int64_t opal_pci_reset (uint64_t id,uint8_t reset_scope,uint8_t assert_state); int64_t opal_pci_get_hub_diag_data(uint64_t hub_id, void *diag_buffer,
arch/powerpc/platforms/powernv/pci.h +1 -0
@@ -100,6 +100,7 @@ struct pnv_phb {int has_dbgfs;struct dentry *dbgfs;#endif +struct iommu_table *bypass_tbl;/* PNV_IOMMU_TCE_BYPASS only */ unsigned int msi_base;unsigned int msi32_support;
arch/powerpc/platforms/powernv/opal-call.c +2 -0
@@ -290,3 +290,5 @@ OPAL_CALL(opal_nx_coproc_init, OPAL_NX_COPROC_INIT);OPAL_CALL (opal_mpipl_update,OPAL_MPIPL_UPDATE );OPAL_CALL (opal_mpipl_register_tag,OPAL_MPIPL_REGISTER_TAG );OPAL_CALL (opal_mpipl_query_tag,OPAL_MPIPL_QUERY_TAG ); +OPAL_CALL (opal_phb_set_option,OPAL_PHB_SET_OPTION ); +OPAL_CALL (opal_phb_get_option,OPAL_PHB_GET_OPTION );
arch/powerpc/platforms/powernv/pci-ioda.c +159 -32
257 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 4/4 vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GB
In reply to Alexey KardashevskiySo far the only option for a big 64big DMA window was a window located at 0x800.0000.0000.0000 (1<<59) which creates problems for devices supporting smaller DMA masks.
This exploits a POWER9 PHB option to allow the second DMA window to map at 0 and advertises it with a 4GB offset to avoid overlap with the default 32bit window.
---
This is an additional option and not inside vfio_iommu_spapr_tce_ddw_info as the new option gets a new flag and one would expect a new member in vfio_iommu_spapr_tce_info per a flag but can squash it into vfio_iommu_spapr_tce_ddw_info, should I?
--- include/uapi/linux/vfio.h | 2 ++ drivers/vfio/vfio_iommu_spapr_tce.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
include/uapi/linux/vfio.h +2 -0
@@ -831,9 +831,11 @@ struct vfio_iommu_spapr_tce_info {__u32 argsz;__u32 flags;#define VFIO_IOMMU_SPAPR_INFO_DDW (1 << 0)/* DDW supported */ +#define VFIO_IOMMU_SPAPR_INFO_DDW_START (1 << 1)/* DDW offset */ __u32 dma32_window_start;/* 32 bit window start (bytes) */ __u32 dma32_window_size;/* 32 bit window size (bytes) */ struct vfio_iommu_spapr_tce_ddw_info ddw; +__u64 dma64_window_start; };#define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
drivers/vfio/vfio_iommu_spapr_tce.c +8 -2
@@ -691,7 +691,7 @@ static long tce_iommu_create_window(struct tce_container *container, container->tables[num] = tbl;/* Return start address assigned by platform in create_table() */ - *start_addr = tbl->it_offset << tbl->it_page_shift; + *start_addr = tbl->it_dmaoff << tbl->it_page_shift;return 0 ;
@@ -842,7 +842,13 @@ static long tce_iommu_ioctl(void *iommu_data, info.ddw.levels = table_group->max_levels; } - ddwsz = offsetofend(struct vfio_iommu_spapr_tce_info, ddw); + ddwsz = offsetofend(struct vfio_iommu_spapr_tce_info, + dma64_window_start); + +if (info.argsz >= ddwsz) { + info.flags |=VFIO_IOMMU_SPAPR_INFO_DDW_START ; + info.dma64_window_start = table_group->tce64_start; + }if (info.argsz >= ddwsz) minsz = ddwsz;
Signature · 1 line
2.17.1
Quoted 7 lines · AEDT Alexey Kardashevskiy
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and
Would it be possible to just enable this by default if the platform supports it? Are there any downsides? Adding it as an option seems like it would make things harder to support and reduces the amount of testing/use it would get.
Quoted 11 lines
supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1
a6ed68d6468bLinus Torvalds "Merge tag 'drm-next-2019-11-27' ofgit://
anongit.freedesktop.org/drm/drm".
Are you sure? I am getting the following rejected hunk trying to apply the first patch in the series:
powerpc/platforms/powernv/pci-ioda.c +0 -0
@@ -2349,15 +2349,10 @@ static void pnv_pci_ioda2_set_bypass(struct
pnv_ioda_pe *pe, bool enable)
pe->tce_bypass_enabled = enable;
}
-static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group,
- int num, __u32 page_shift, __u64 window_size, __u32 levels,
+static long pnv_pci_ioda2_create_table(int nid, int num, __u64 bus_offset,
+ __u32 page_shift, __u64 window_size, __u32 levels,
bool alloc_userspace_copy, struct iommu_table **ptbl)
{
- struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe,
- table_group);
- int nid = pe->phb->hose->node;
- __u64 bus_offset = num ?
- pe->table_group.tce64_start : table_group->tce32_start;
long ret;
struct iommu_table *tbl;- Alistair
Quoted 22 lines
Please comment. Thanks.
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GBarch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Quoted 11 lines · Alistair Popple
Quoted 7 lines · AEDT Alexey Kardashevskiy
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and
Would it be possible to just enable this by default if the platform supports it? Are there any downsides?
It changes the second DMA window location which is now assumed by QEMU to be at 0x800.0000.0000.0000 and I do not see an easy way to work around this.
For example, we start QEMU without VFIO but with emulated XHCI which will ask for DDW, we (QEMU) have to pick a window location but then we have to stick to it and if a user later hotplugs an VFIO-PCI, that physical IOMMU has to support the previously selected DMA window address; otherwise hotplug is going to fail.
The question is how to tell QEMU about this new offset and what we do about migration from P8 (which let's say did have a VFIO device which we unplug before the migration) to P9 with a prospect of hotplugging an VFIO device but this time with this GTE4GB bit set.
Quoted 2 lines
Adding it as an option seems like it would make
things harder to support and reduces the amount of testing/use it would get.
Yeah, this why this is an RFC...
Quoted 6 lines
Quoted 6 lines
supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).
Quoted 8 lines
Quoted 5 lines
For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1
a6ed68d6468bLinus Torvalds "Merge tag 'drm-next-2019-11-27' ofgit://anongit.freedesktop.org/drm/drm".
Are you sure?
Almost. It should have been HEAD^^^^^..HEAD instead of HEAD^^^^..HEAD :)
I've posted 00/4 to the thread now, sorry about that. Thanks,
Quoted 52 lines
I am getting the following rejected hunk trying to apply the first patch in the series:
powerpc/platforms/powernv/pci-ioda.c +2
-8@@ -2349,15 +2349,10 @@ static void pnv_pci_ioda2_set_bypass(struct pnv_ioda_pe *pe, bool enable) pe->tce_bypass_enabled = enable; } -static long pnv_pci_ioda2_create_table (struct iommu_table_group *table_group, -int num,__u32 page_shift,__u64 window_size,__u32 levels, +static long pnv_pci_ioda2_create_table (int nid,int num,__u64 bus_offset, +__u32 page_shift,__u64 window_size,__u32 levels,bool alloc_userspace_copy,struct iommu_table **ptbl) { - struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe, - table_group); -int nid = pe->phb->hose->node; -__u64 bus_offset = num ? - pe->table_group.tce64_start : table_group->tce32_start;long ret;struct iommu_table *tbl; - AlistairQuoted 23 lines
Please comment. Thanks.
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GBarch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Signature · 1 line
Alexey
cover powerpc/powernv/ioda: Move TCE bypass base to PE
In reply to Alexey KardashevskiyWe are about to allow another location for the second DMA window and we will need to advertise it outside of the powernv platform code.
This moves bypass base address to iommu_table_group so drivers such as VFIO SPAPR TCE can see it.
--- arch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/platforms/powernv/pci.h | 1 - arch/powerpc/platforms/powernv/npu-dma.c | 1 + arch/powerpc/platforms/powernv/pci-ioda.c | 18 +++++++++--------- 4 files changed, 11 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/iommu.h +1 -0
@@ -194,6 +194,7 @@ struct iommu_table_group {__u64 pgsizes;/* Bitmap of supported page sizes */ __u32 max_dynamic_windows_supported;__u32 max_levels; +__u64 tce64_start;struct iommu_group *group;struct iommu_table *tables[IOMMU_TABLE_GROUP_MAX_TABLES ];
arch/powerpc/platforms/powernv/pci.h +0 -1
@@ -67,7 +67,6 @@ struct pnv_ioda_pe {/* 64-bit TCE bypass region */ bool tce_bypass_enabled; -uint64_t tce_bypass_base;/* MSIs. MVE index is identical for for 32 and 64 bit MSI * and -1 if not supported. (It's actually identical to the
arch/powerpc/platforms/powernv/npu-dma.c +1 -0
@@ -469,6 +469,7 @@ struct iommu_table_group *pnv_try_setup_npu_table_group(struct pnv_ioda_pe *pe) table_group->tce32_start = pe->table_group.tce32_start; table_group->tce32_size = pe->table_group.tce32_size; table_group->max_levels = pe->table_group.max_levels; + table_group->tce64_start = pe->table_group.tce64_start;if (!table_group->pgsizes) table_group->pgsizes = pe->table_group.pgsizes;
arch/powerpc/platforms/powernv/pci-ioda.c +9 -9
@@ -1747,7 +1747,7 @@ static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb *phb, struct pci_dev *pdev pe = &phb->ioda.pe_array[pdn->pe_number];WARN_ON (get_dma_ops (&pdev->dev) != &dma_iommu_ops); - pdev->dev.archdata.dma_offset = pe->tce_bypass_base; + pdev->dev.archdata.dma_offset = pe->table_group.tce64_start;set_iommu_table_base (&pdev->dev, pe->table_group.tables[0 ]);/* * Note: iommu_add_device() will fail here as
@@ -1839,7 +1839,8 @@ static bool pnv_pci_ioda_iommu_bypass_supported(struct pci_dev *pdev, pe = &phb->ioda.pe_array[pdn->pe_number];if (pe->tce_bypass_enabled) { -u64 top = pe->tce_bypass_base +memblock_end_of_DRAM () -1 ; +u64 top = pe->table_group.tce64_start + +memblock_end_of_DRAM () -1 ;if (dma_mask >= top)return true; }
@@ -1873,7 +1874,7 @@ static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)list_for_each_entry (dev, &bus->devices, bus_list) {set_iommu_table_base (&dev->dev, pe->table_group.tables[0 ]); - dev->dev.archdata.dma_offset = pe->tce_bypass_base; + dev->dev.archdata.dma_offset = pe->table_group.tce64_start;if ((pe->flags &PNV_IODA_PE_BUS_ALL ) && dev->subordinate)pnv_ioda_setup_bus_dma (pe, dev->subordinate);
@@ -2333,13 +2334,13 @@ static void pnv_pci_ioda2_set_bypass(struct pnv_ioda_pe *pe, bool enable) rc =opal_pci_map_pe_dma_window_real (pe->phb->opal_id, pe->pe_number, window_id, - pe->tce_bypass_base, + pe->table_group.tce64_start, top); }else { rc =opal_pci_map_pe_dma_window_real (pe->phb->opal_id, pe->pe_number, window_id, - pe->tce_bypass_base, + pe->table_group.tce64_start,0 ); }if (rc)
@@ -2355,7 +2356,8 @@ static long pnv_pci_ioda2_create_table(struct iommu_table_group *table_group, struct pnv_ioda_pe *pe = container_of(table_group, struct pnv_ioda_pe, table_group);int nid = pe->phb->hose->node; -__u64 bus_offset = num ? pe->tce_bypass_base : table_group->tce32_start; +__u64 bus_offset = num ? + pe->table_group.tce64_start : table_group->tce32_start;long ret;struct iommu_table *tbl;
@@ -2705,9 +2707,6 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,if (!pnv_pci_ioda_pe_dma_weight (pe))return ; -/* TVE #1 is selected by PCI address bit 59 */ - pe->tce_bypass_base =1ull <<59 ; -/* The PE will reserve all possible 32-bits space */ pe_info (pe,"Setting up 32-bit TCE table at 0..%08x\n" , phb->ioda.m32_pci_base);
@@ -2715,6 +2714,7 @@ static void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb,/* Setup linux iommu table */ pe->table_group.tce32_start =0 ; pe->table_group.tce32_size = phb->ioda.m32_pci_base; + pe->table_group.tce64_start =1UL <<59 ; pe->table_group.max_dynamic_windows_supported =IOMMU_TABLE_GROUP_MAX_TABLES ; pe->table_group.max_levels =POWERNV_IOMMU_MAX_LEVELS ;
Signature · 1 line
2.17.1
Quoted 13 lines · Alexey Kardashevskiy
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).
Quoted 7 lines
For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1
a6ed68d6468bLinus Torvalds "Merge tag 'drm-next-2019-11-27' ofgit://anongit.freedesktop.org/drm/drm".Please comment. Thanks.
David, Alistair, ping? Thanks,
Quoted 20 lines
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GBarch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Signature · 1 line
Alexey
Anyone, ping?
Quoted 51 lines · Alexey Kardashevskiy
Quoted 13 lines · Alexey Kardashevskiy
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).Quoted 7 lines
For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1
a6ed68d6468bLinus Torvalds "Merge tag 'drm-next-2019-11-27' ofgit://anongit.freedesktop.org/drm/drm".Please comment. Thanks.
David, Alistair, ping? Thanks,
Quoted 20 lines
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GBarch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Signature · 1 line
Alexey
Quoted 1 line · Alexey Kardashevskiy
Anyone, ping?
Sorry, I've totally lost track of this one. I think you'll need to repost.
Quoted 55 lines · Alexey Kardashevskiy
Quoted 51 lines · Alexey Kardashevskiy
Quoted 13 lines
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).Quoted 7 lines
For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1
a6ed68d6468bLinus Torvalds "Merge tag 'drm-next-2019-11-27' ofgit://anongit.freedesktop.org/drm/drm".Please comment. Thanks.
David, Alistair, ping? Thanks,
Quoted 20 lines
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GBarch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 5 lines · David Gibson
Quoted 1 line · Alexey Kardashevskiy
Anyone, ping?
Sorry, I've totally lost track of this one. I think you'll need to repost.
It has not changed and still applies, and the question is more about how we proceed with this feature that the patches themselves. Or it is just not in your mailbox anymore so you cannot reply? :)
Quoted 58 lines
Quoted 57 lines · Alexey Kardashevskiy
Quoted 51 lines · Alexey Kardashevskiy
Quoted 13 lines
Here is an attempt to support bigger DMA space for devices supporting DMA masks less than 59 bits (GPUs come into mind first). POWER9 PHBs have an option to map 2 windows at 0 and select a windows based on DMA address being below or above 4GB.
This adds the "iommu=iommu_bypass" kernel parameter and supports VFIO+pseries machine - current this requires telling upstream+unmodified QEMU about this via
-global spapr-pci-host-bridge.dma64_win_addr=0x100000000 or per-phb property. 4/4 advertises the new option but there is no automation around it in QEMU (should it be?).Quoted 7 lines
For now it is either 1<<59 or 4GB mode; dynamic switching is not supported (could be via sysfs).
This is based on sha1
a6ed68d6468bLinus Torvalds "Merge tag 'drm-next-2019-11-27' ofgit://anongit.freedesktop.org/drm/drm".Please comment. Thanks.
David, Alistair, ping? Thanks,
Quoted 20 lines
Alexey Kardashevskiy (4):
powerpc/powernv/ioda: Rework for huge DMA window at 4GB powerpc/powernv/ioda: Allow smaller TCE table levels powerpc/powernv/phb4: Add 4GB IOMMU bypass mode vfio/spapr_tce: Advertise and allow a huge DMA windows at 4GBarch/powerpc/include/asm/iommu.h | 1 + arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 2 + arch/powerpc/platforms/powernv/pci.h | 1 + include/uapi/linux/vfio.h | 2 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/pci-ioda-tce.c | 4 +- arch/powerpc/platforms/powernv/pci-ioda.c | 219 ++++++++++++++---- drivers/vfio/vfio_iommu_spapr_tce.c | 10 +- 9 files changed, 202 insertions(+), 50 deletions(-)
Signature · 1 line
Alexey