PCI/P2PDMA: Support transactions that hit the host bridge
Subsystems (5)
Logan Gunthorpe
maintainerv2 cover PCI/P2PDMA: Support transactions that hit the host bridge
Here's v2 of the patchset. It doesn't sound like there's anything terribly controversial here so this version is mostly just some cleanup changes for clarity.
Changes in v2:
* Rebase on v5.3-rc2 (No changes)
* Re-introduce the private pagemap structure and move the p2p-specific elements out of the commond dev_pagemap (per Christoph)
* Use flags instead of bool in the whitelist (per Jason)
* Only store the mapping type in the xarray (instead of the distance with flags) such that a function can return the mapping method with a switch statement to decide how to map. (per Christoph)
* Drop find_parent_pci_dev() on the fast path and rely on the fact that the struct device passed to the mapping functions *must* be a PCI device and convert it directly. (per suggestions from Christoph and Jason)
* Collected Christian's Reviewed-by's
--
As discussed on the list previously, in order to fully support the whitelist Christian added with the IOMMU, we must ensure that we map any buffer going through the IOMMU with an aprropriate dma_map call. This patchset accomplishes this by cleaning up the output of upstream_bridge_distance() to better indicate the mapping requirements, caching these requirements in an xarray, then looking them up at map time and applying the appropriate mapping method.
After this patchset, it's possible to use the NVMe-of P2P support to transfer between devices without a switch on the whitelisted root complexes. A couple Intel device I have tested this on have also been added to the white list.
Most of the changes are contained within the p2pdma.c, but there are a few minor touches to other subsystems, mostly to add support to call an unmap function.
The final patch in this series demonstrates a possible pci_p2pdma_map_resource() function that I expect Christian will need but does not have any users at this time so I don't intend for it to be considered for merging.
This patchset is based on 5.3-rc2 and a git branch is available here:
https://github.com/sbates130272/linux-p2pmem/ p2pdma_rc_map_v2
--
Logan Gunthorpe (14):
PCI/P2PDMA: Introduce private pagemap structure PCI/P2PDMA: Add the provider's pci_dev to the pci_p2pdma_pagemap
struct
PCI/P2PDMA: Add constants for not-supported result
upstream_bridge_distance()
PCI/P2PDMA: Factor out __upstream_bridge_distance() PCI/P2PDMA: Apply host bridge white list for ACS PCI/P2PDMA: Factor out host_bridge_whitelist()
PCI/P2PDMA: Add whitelist support for Intel Host Bridges PCI/P2PDMA: Add attrs argument to pci_p2pdma_map_sg() PCI/P2PDMA: Introduce pci_p2pdma_unmap_sg()
PCI/P2PDMA: Factor out __pci_p2pdma_map_sg()
PCI/P2PDMA: Store mapping method in an xarray
PCI/P2PDMA: dma_map P2PDMA map requests that traverse the host bridge PCI/P2PDMA: No longer require no-mmu for host bridge whitelist PCI/P2PDMA: Update documentation for pci_p2pdma_distance_many()
drivers/infiniband/core/rw.c | 6 +- drivers/nvme/host/pci.c | 10 +- drivers/pci/p2pdma.c | 361 +++++++++++++++++++++++++---------- include/linux/memremap.h | 1 - include/linux/pci-p2pdma.h | 28 ++- 5 files changed, 296 insertions(+), 110 deletions(-)
--
2.20.1
Logan Gunthorpe
maintainerPATCH v2 1/14 PCI/P2PDMA: Introduce private pagemap structure
Move the PCI bus offset from the generic dev_pagemap structure to a specific pci_p2pdma_pagemap structure.
This structure will grow in subsequent patches.
--- drivers/pci/p2pdma.c | 26 ++++++++++++++++++++------ include/linux/memremap.h | 1 - 2 files changed, 20 insertions(+), 7 deletions(-)
drivers/pci/p2pdma.c +20 -6
@@ -25,6 +25,16 @@ struct pci_p2pdma {bool p2pmem_published; }; +struct pci_p2pdma_pagemap { +struct dev_pagemap pgmap; +u64 bus_offset; +}; + +static struct pci_p2pdma_pagemap *to_p2p_pgmap (struct dev_pagemap *pgmap) +{ + return container_of(pgmap, struct pci_p2pdma_pagemap, pgmap); +} +static ssize_t size_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -135,6 +145,7 @@ static int pci_p2pdma_setup(struct pci_dev *pdev)int pci_p2pdma_add_resource (struct pci_dev *pdev,int bar,size_t size,u64 offset) { +struct pci_p2pdma_pagemap *p2p_pgmap;struct dev_pagemap *pgmap;void *addr;int error;
@@ -157,14 +168,17 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,return error; } - pgmap =devm_kzalloc (&pdev->dev,sizeof (*pgmap),GFP_KERNEL ); -if (!pgmap) + p2p_pgmap =devm_kzalloc (&pdev->dev,sizeof (*p2p_pgmap),GFP_KERNEL ); +if (!p2p_pgmap)return -ENOMEM ; + + pgmap = &p2p_pgmap->pgmap; pgmap->res.start =pci_resource_start (pdev, bar) + offset; pgmap->res.end = pgmap->res.start + size -1 ; pgmap->res.flags =pci_resource_flags (pdev, bar); pgmap->type =MEMORY_DEVICE_PCI_P2PDMA ; - pgmap->pci_p2pdma_bus_offset =pci_bus_address (pdev, bar) - + + p2p_pgmap->bus_offset =pci_bus_address (pdev, bar) -pci_resource_start (pdev, bar); addr =devm_memremap_pages (&pdev->dev, pgmap);
@@ -720,7 +734,7 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_publish);int pci_p2pdma_map_sg (struct device *dev,struct scatterlist *sg,int nents,enum dma_data_direction dir) { -struct dev_pagemap *pgmap; +struct pci_p2pdma_pagemap *p2p_pgmap;struct scatterlist *s;phys_addr_t paddr;int i;
@@ -736,10 +750,10 @@ int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg, int nents,return 0 ;for_each_sg (sg, s, nents, i) { - pgmap =sg_page (s)->pgmap; + p2p_pgmap =to_p2p_pgmap (sg_page (s)->pgmap); paddr =sg_phys (s); - s->dma_address = paddr - pgmap->pci_p2pdma_bus_offset; + s->dma_address = paddr - p2p_pgmap->bus_offset;sg_dma_len (s) = s->length; }
include/linux/memremap.h +0 -1
@@ -112,7 +112,6 @@ struct dev_pagemap {struct device *dev;enum memory_type type;unsigned int flags; -u64 pci_p2pdma_bus_offset;const struct dev_pagemap_ops *ops; };
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 2/14 PCI/P2PDMA: Add the provider's pci_dev to the pci_p2pdma_pagemap struct
In reply to Logan GunthorpeThe provider will be needed to figure out how to properly map a device.
--- drivers/pci/p2pdma.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/p2pdma.c +2 -0
@@ -27,6 +27,7 @@ struct pci_p2pdma {struct pci_p2pdma_pagemap {struct dev_pagemap pgmap; +struct pci_dev *provider;u64 bus_offset; };
@@ -178,6 +179,7 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size, pgmap->res.flags =pci_resource_flags (pdev, bar); pgmap->type =MEMORY_DEVICE_PCI_P2PDMA ; + p2p_pgmap->provider = pdev; p2p_pgmap->bus_offset =pci_bus_address (pdev, bar) -pci_resource_start (pdev, bar);
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 3/14 PCI/P2PDMA: Add constants for not-supported result upstream_bridge_distance()
In reply to Logan GunthorpeAdd constant flags to indicate two devices are not supported or whether the data path goes through the host bridge instead of using the negative values -1 and -2.
This helps annotate the code better, but the main reason is so we can use the information to store the required mapping method in an xarray.
--- drivers/pci/p2pdma.c | 52 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-)
drivers/pci/p2pdma.c +31 -21
@@ -289,6 +289,20 @@ static bool root_complex_whitelist(struct pci_dev *dev)return false; } +enum { +/* +* These arbitrary offset are or'd onto the upstream distance +* calculation for the following conditions: +*/ + +/* The data path includes the host-bridge */ +P2PDMA_THRU_HOST_BRIDGE =0x02000000 , +/* The data path is forced through the host-bridge due to ACS */ +P2PDMA_ACS_FORCES_UPSTREAM =0x04000000 , +/* The data path is not supported by P2PDMA */ +P2PDMA_NOT_SUPPORTED =0x08000000 , +}; +/* * Find the distance through the nearest common upstream bridge between * two PCI devices.
@@ -313,22 +327,17 @@ static bool root_complex_whitelist(struct pci_dev *dev)* port of the switch, to the common upstream port, back up to the second * downstream port and then to Device B. * -* Any two devices that don't have a common upstream bridge will return -1. -* In this way devices on separate PCIe root ports will be rejected, which -* is what we want for peer-to-peer seeing each PCIe root port defines a -* separate hierarchy domain and there's no way to determine whether the root -* complex supports forwarding between them. +* Any two devices that cannot communicate using p2pdma will return the distance +* with the flag P2PDMA_NOT_SUPPORTED. * -* In the case where two devices are connected to different PCIe switches, -* this function will still return a positive distance as long as both -* switches eventually have a common upstream bridge. Note this covers -* the case of using multiple PCIe switches to achieve a desired level of -* fan-out from a root port. The exact distance will be a function of the -* number of switches between Device A and Device B. +* Any two devices that have a data path that goes through the host bridge +* will consult a whitelist. If the host bridges are on the whitelist, +* then the distance will be returned with the flag P2PDMA_THRU_HOST_BRIDGE set. +* If either bridge is not on the whitelist, the flag P2PDMA_NOT_SUPPORTED will +* be set. * * If a bridge which has any ACS redirection bits set is in the path -* then this functions will return -2. This is so we reject any -* cases where the TLPs are forwarded up into the root complex. +* then this functions will flag the result with P2PDMA_ACS_FORCES_UPSTREAM. * In this case, a list of all infringing bridge addresses will be * populated in acs_list (assuming it's non-null) for printk purposes. */
@@ -375,9 +384,9 @@ static int upstream_bridge_distance(struct pci_dev *provider,*/ if (root_complex_whitelist (provider) &&root_complex_whitelist (client)) -return 0x1000 + dist_a + dist_b; +return (dist_a + dist_b) |P2PDMA_THRU_HOST_BRIDGE ; -return -1 ; +return (dist_a + dist_b) |P2PDMA_NOT_SUPPORTED ; check_b_path_acs: bb = b;
@@ -395,7 +404,7 @@ static int upstream_bridge_distance(struct pci_dev *provider, }if (acs_cnt) -return -2 ; +return P2PDMA_NOT_SUPPORTED |P2PDMA_ACS_FORCES_UPSTREAM ;return dist_a + dist_b; }
@@ -411,16 +420,17 @@ static int upstream_bridge_distance_warn(struct pci_dev *provider,return -ENOMEM ; ret =upstream_bridge_distance (provider, client, &acs_list); -if (ret ==-2 ) { -pci_warn (client,"cannot be used for peer-to-peer DMA as ACS redirect is set between the client and provider (%s)\n" , +if (ret &P2PDMA_ACS_FORCES_UPSTREAM ) { +pci_warn (client,"ACS redirect is set between the client and provider (%s)\n" ,pci_name (provider));/* Drop final semicolon */ acs_list.buffer[acs_list.len-1 ] =0 ;pci_warn (client,"to disable ACS redirect for this path, add the kernel parameter: pci=disable_acs_redir=%s\n" , acs_list.buffer); + } - }else if (ret <0 ) { -pci_warn (client,"cannot be used for peer-to-peer DMA as the client and provider (%s) do not share an upstream bridge\n" , +if (ret &P2PDMA_NOT_SUPPORTED ) { +pci_warn (client,"cannot be used for peer-to-peer DMA as the client and provider (%s) do not share an upstream bridge or whitelisted host bridge\n" ,pci_name (provider)); }
@@ -484,7 +494,7 @@ int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,pci_dev_put (pci_client); -if (ret <0 ) +if (ret &P2PDMA_NOT_SUPPORTED ) not_supported = true;if (not_supported && !verbose)
Signature · 1 line
2.20.1
Christoph Hellwig
maintainerRe: [PATCH v2 03/14] PCI/P2PDMA: Add constants for not-supported result upstream_bridge_distance()
Quoted 10 lines · Logan Gunthorpe
Add constant flags to indicate two devices are not supported or whether the data path goes through the host bridge instead of using the negative values -1 and -2.
This helps annotate the code better, but the main reason is so we can use the information to store the required mapping method in an xarray.
Signed-off-by Logan Gunthorpe <logang at deltatee.com>Reviewed-by Christian K?nig <christian.koenig at amd.com>
Is there really no way to keep the distance separate from the type of the connection as I requested? I think that would avoid a lot of confusion down the road.
Logan Gunthorpe
maintainerRe: [PATCH v2 03/14] PCI/P2PDMA: Add constants for not-supported result upstream_bridge_distance()
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Logan Gunthorpe
Add constant flags to indicate two devices are not supported or whether the data path goes through the host bridge instead of using the negative values -1 and -2.
This helps annotate the code better, but the main reason is so we can use the information to store the required mapping method in an xarray.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Logan Gunthorpe <logang at deltatee.com>Reviewed-by Christian K?nig <christian.koenig at amd.com>Is there really no way to keep the distance separate from the type of the connection as I requested? I think that would avoid a lot of confusion down the road.
Well I separated it in the xarray and the interface. It only stores the type of mapping, not the distance and uses pci_p2pdma_map_type() to retrieve it.
We only calculate it at the same time as we calculate the distance. This is necessary because, to calculate the type, we have to walk the tree and check the ACS bits. If we separated it, we'd have to walk the tree twice in a very similar way just to determine both the distance and the mapping type.
I'll apply your other feedback to a v3 next week.
Logan
Christoph Hellwig
maintainerRe: [PATCH v2 03/14] PCI/P2PDMA: Add constants for not-supported result upstream_bridge_distance()
Quoted 5 lines · Logan Gunthorpe
We only calculate it at the same time as we calculate the distance. This is necessary because, to calculate the type, we have to walk the tree and check the ACS bits. If we separated it, we'd have to walk the tree twice in a very similar way just to determine both the distance and the mapping type.
Calculating it together makes perfect sense. What I find odd is the overloading of a single return value. Why not return the map type as the return value, and the distance as a by reference argument to keep them properly separated?
Logan Gunthorpe
maintainerRe: [PATCH v2 03/14] PCI/P2PDMA: Add constants for not-supported result upstream_bridge_distance()
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Logan Gunthorpe
We only calculate it at the same time as we calculate the distance. This is necessary because, to calculate the type, we have to walk the tree and check the ACS bits. If we separated it, we'd have to walk the tree twice in a very similar way just to determine both the distance and the mapping type.
Calculating it together makes perfect sense. What I find odd is the overloading of a single return value. Why not return the map type as the return value, and the distance as a by reference argument to keep them properly separated?
Ok, understood. I'll make that change and send some incremental patches to Bjorn tomorrow.
Logan
Logan Gunthorpe
maintainerPATCH v2 4/14 PCI/P2PDMA: Factor out __upstream_bridge_distance()
In reply to Logan GunthorpeThis is a prep patch to create a second level helper. There are no functional changes.
The root complex whitelist code will be moved into this function in a subsequent patch.
--- drivers/pci/p2pdma.c | 89 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 41 deletions(-)
drivers/pci/p2pdma.c +48 -41
@@ -303,47 +303,9 @@ enum { P2PDMA_NOT_SUPPORTED = 0x08000000, }; -/* -* Find the distance through the nearest common upstream bridge between -* two PCI devices. -* -* If the two devices are the same device then 0 will be returned. -* -* If there are two virtual functions of the same device behind the same -* bridge port then 2 will be returned (one step down to the PCIe switch, -* then one step back to the same device). -* -* In the case where two devices are connected to the same PCIe switch, the -* value 4 will be returned. This corresponds to the following PCI tree: -* -* -+ Root Port -* \+ Switch Upstream Port -* +-+ Switch Downstream Port -* + \- Device A -* \-+ Switch Downstream Port -* \- Device B -* -* The distance is 4 because we traverse from Device A through the downstream -* port of the switch, to the common upstream port, back up to the second -* downstream port and then to Device B. -* -* Any two devices that cannot communicate using p2pdma will return the distance -* with the flag P2PDMA_NOT_SUPPORTED. -* -* Any two devices that have a data path that goes through the host bridge -* will consult a whitelist. If the host bridges are on the whitelist, -* then the distance will be returned with the flag P2PDMA_THRU_HOST_BRIDGE set. -* If either bridge is not on the whitelist, the flag P2PDMA_NOT_SUPPORTED will -* be set. -* -* If a bridge which has any ACS redirection bits set is in the path -* then this functions will flag the result with P2PDMA_ACS_FORCES_UPSTREAM. -* In this case, a list of all infringing bridge addresses will be -* populated in acs_list (assuming it's non-null) for printk purposes. -*/ -static int upstream_bridge_distance (struct pci_dev *provider, -struct pci_dev *client, -struct seq_buf *acs_list) +static int __upstream_bridge_distance (struct pci_dev *provider, +struct pci_dev *client, +struct seq_buf *acs_list) {struct pci_dev *a = provider, *b = client, *bb;int dist_a =0 ;
@@ -409,6 +371,51 @@ static int upstream_bridge_distance(struct pci_dev *provider,return dist_a + dist_b; } +/* +* Find the distance through the nearest common upstream bridge between +* two PCI devices. +* +* If the two devices are the same device then 0 will be returned. +* +* If there are two virtual functions of the same device behind the same +* bridge port then 2 will be returned (one step down to the PCIe switch, +* then one step back to the same device). +* +* In the case where two devices are connected to the same PCIe switch, the +* value 4 will be returned. This corresponds to the following PCI tree: +* +* -+ Root Port +* \+ Switch Upstream Port +* +-+ Switch Downstream Port +* + \- Device A +* \-+ Switch Downstream Port +* \- Device B +* +* The distance is 4 because we traverse from Device A through the downstream +* port of the switch, to the common upstream port, back up to the second +* downstream port and then to Device B. +* +* Any two devices that cannot communicate using p2pdma will return the distance +* with the flag P2PDMA_NOT_SUPPORTED. +* +* Any two devices that have a data path that goes through the host bridge +* will consult a whitelist. If the host bridges are on the whitelist, +* then the distance will be returned with the flag P2PDMA_THRU_HOST_BRIDGE set. +* If either bridge is not on the whitelist, the flag P2PDMA_NOT_SUPPORTED will +* be set. +* +* If a bridge which has any ACS redirection bits set is in the path +* then this functions will flag the result with P2PDMA_ACS_FORCES_UPSTREAM. +* In this case, a list of all infringing bridge addresses will be +* populated in acs_list (assuming it's non-null) for printk purposes. +*/ +static int upstream_bridge_distance (struct pci_dev *provider, +struct pci_dev *client, +struct seq_buf *acs_list) +{ +return __upstream_bridge_distance (provider, client, acs_list); +} +static int upstream_bridge_distance_warn (struct pci_dev *provider,struct pci_dev *client) {
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 5/14 PCI/P2PDMA: Apply host bridge white list for ACS
In reply to Logan GunthorpeWhen a P2PDMA transfer is rejected due to ACS being set, we can also check the white list and allow the transactions.
Do this by pushing the whitelist check into theupstream_bridge_distance() function.
--- drivers/pci/p2pdma.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/pci/p2pdma.c +14 -11
@@ -340,15 +340,7 @@ static int __upstream_bridge_distance(struct pci_dev *provider, dist_a++; } -/* -* Allow the connection if both devices are on a whitelisted root -* complex, but add an arbitrary large value to the distance. -*/ -if (root_complex_whitelist (provider) && -root_complex_whitelist (client)) -return (dist_a + dist_b) |P2PDMA_THRU_HOST_BRIDGE ; - -return (dist_a + dist_b) |P2PDMA_NOT_SUPPORTED ; +return (dist_a + dist_b) |P2PDMA_THRU_HOST_BRIDGE ; check_b_path_acs: bb = b;
@@ -366,7 +358,8 @@ static int __upstream_bridge_distance(struct pci_dev *provider, }if (acs_cnt) -return P2PDMA_NOT_SUPPORTED |P2PDMA_ACS_FORCES_UPSTREAM ; +return (dist_a + dist_b) |P2PDMA_ACS_FORCES_UPSTREAM | +P2PDMA_THRU_HOST_BRIDGE ;return dist_a + dist_b; }
@@ -413,7 +406,17 @@ static int upstream_bridge_distance(struct pci_dev *provider,struct pci_dev *client, struct seq_buf *acs_list) { - return __upstream_bridge_distance(provider, client, acs_list); + int dist; + + dist =__upstream_bridge_distance (provider, client, acs_list); + +if (!(dist &P2PDMA_THRU_HOST_BRIDGE )) +return dist; + +if (root_complex_whitelist (provider) &&root_complex_whitelist (client)) +return dist; + +return dist |P2PDMA_NOT_SUPPORTED ; } static int upstream_bridge_distance_warn(struct pci_dev *provider,
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 6/14 PCI/P2PDMA: Factor out host_bridge_whitelist()
In reply to Logan GunthorpePush both PCI devices into the whitelist checking function seeing some hardware will require us ensuring they are on the same host bridge.
At the same time we rename root_complex_whitelist() to host_bridge_whitelist() to match the terminology used in the code.
--- drivers/pci/p2pdma.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/pci/p2pdma.c +20 -10
@@ -262,19 +262,11 @@ static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)seq_buf_printf (buf,"%s;" ,pci_name (pdev)); } -/* -* If we can't find a common upstream bridge take a look at the root -* complex and compare it to a whitelist of known good hardware. -*/ -static bool root_complex_whitelist (struct pci_dev *dev) +static bool __host_bridge_whitelist (struct pci_host_bridge *host) { -struct pci_host_bridge *host =pci_find_host_bridge (dev->bus);struct pci_dev *root =pci_get_slot (host->bus,PCI_DEVFN (0 ,0 ));unsigned short vendor, device; -if (iommu_present (dev->dev.bus)) -return false; -if (!root)return false;
@@ -289,6 +281,24 @@ static bool root_complex_whitelist(struct pci_dev *dev)return false; } +/* +* If we can't find a common upstream bridge take a look at the root +* complex and compare it to a whitelist of known good hardware. +*/ +static bool host_bridge_whitelist (struct pci_dev *a,struct pci_dev *b) +{ +struct pci_host_bridge *host_a =pci_find_host_bridge (a->bus); +struct pci_host_bridge *host_b =pci_find_host_bridge (b->bus); + +if (iommu_present (a->dev.bus) ||iommu_present (b->dev.bus)) +return false; + +if (__host_bridge_whitelist (host_a) &&__host_bridge_whitelist (host_b)) +return true; + +return false; +} +enum {/* * These arbitrary offset are or'd onto the upstream distance
@@ -413,7 +423,7 @@ static int upstream_bridge_distance(struct pci_dev *provider,if (!(dist &P2PDMA_THRU_HOST_BRIDGE ))return dist; -if (root_complex_whitelist (provider) &&root_complex_whitelist (client)) +if (host_bridge_whitelist (provider, client))return dist;return dist |P2PDMA_NOT_SUPPORTED ;
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 7/14 PCI/P2PDMA: Add whitelist support for Intel Host Bridges
In reply to Logan GunthorpeIntel devices do not have good support for P2P requests that span different host bridges as the transactions will cross the QPI/UPI bus and this does not perform well.
Therefore, enable support for these devices only if the host bridges match.
Adds the Intel device's that have been tested to work. There are likely many others out there that will need to be tested and added.
--- drivers/pci/p2pdma.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-)
drivers/pci/p2pdma.c +34 -4
@@ -262,9 +262,30 @@ static void seq_buf_print_bus_devfn(struct seq_buf *buf, struct pci_dev *pdev)seq_buf_printf (buf,"%s;" ,pci_name (pdev)); } -static bool __host_bridge_whitelist (struct pci_host_bridge *host) +static const struct pci_p2pdma_whitelist_entry { +unsigned short vendor; +unsigned short device; +enum { +REQ_SAME_HOST_BRIDGE =1 <<0 , + } flags; +} pci_p2pdma_whitelist[] = { +/* AMD ZEN */ + {PCI_VENDOR_ID_AMD ,0x1450 ,0 }, + +/* Intel Xeon E5/Core i7 */ + {PCI_VENDOR_ID_INTEL ,0x3c00 ,REQ_SAME_HOST_BRIDGE }, + {PCI_VENDOR_ID_INTEL ,0x3c01 ,REQ_SAME_HOST_BRIDGE }, +/* Intel Xeon E7 v3/Xeon E5 v3/Core i7 */ + {PCI_VENDOR_ID_INTEL ,0x2f00 ,REQ_SAME_HOST_BRIDGE }, + {PCI_VENDOR_ID_INTEL ,0x2f01 ,REQ_SAME_HOST_BRIDGE }, + {} +}; + +static bool __host_bridge_whitelist (struct pci_host_bridge *host, +bool same_host_bridge) {struct pci_dev *root =pci_get_slot (host->bus,PCI_DEVFN (0 ,0 )); +const struct pci_p2pdma_whitelist_entry *entry;unsigned short vendor, device;if (!root)
@@ -274,9 +295,14 @@ static bool __host_bridge_whitelist(struct pci_host_bridge *host) device = root->device;pci_dev_put (root); -/* AMD ZEN host bridges can do peer to peer */ -if (vendor ==PCI_VENDOR_ID_AMD && device ==0x1450 ) +for (entry = pci_p2pdma_whitelist; entry->vendor; entry++) { +if (vendor != entry->vendor || device != entry->device) +continue ; +if (entry->flags &REQ_SAME_HOST_BRIDGE && !same_host_bridge) +return false; +return true; + }return false; }
@@ -293,7 +319,11 @@ static bool host_bridge_whitelist(struct pci_dev *a, struct pci_dev *b)if (iommu_present (a->dev.bus) ||iommu_present (b->dev.bus))return false; -if (__host_bridge_whitelist (host_a) &&__host_bridge_whitelist (host_b)) +if (host_a == host_b) +return __host_bridge_whitelist (host_a, true); + +if (__host_bridge_whitelist (host_a, false) && +__host_bridge_whitelist (host_b, false))return true;return false;
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 8/14 PCI/P2PDMA: Add attrs argument to pci_p2pdma_map_sg()
In reply to Logan GunthorpeThis is to match the dma_map_sg() API which this function will have to call in an future patch.
Adds a pci_p2pdma_map_sg_attrs() function and helper to call it with no attributes just like the dma_map_sg() function.
--- drivers/nvme/host/pci.c | 4 ++-- drivers/pci/p2pdma.c | 7 ++++--- include/linux/pci-p2pdma.h | 15 +++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-)
drivers/nvme/host/pci.c +2 -2
@@ -832,8 +832,8 @@ static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req, goto out;if (is_pci_p2pdma_page (sg_page (iod->sg))) - nr_mapped =pci_p2pdma_map_sg (dev->dev, iod->sg, iod->nents, -rq_dma_dir (req)); + nr_mapped =pci_p2pdma_map_sg_attrs (dev->dev, iod->sg, + iod->nents,rq_dma_dir (req),DMA_ATTR_NO_WARN );else nr_mapped =dma_map_sg_attrs (dev->dev, iod->sg, iod->nents,rq_dma_dir (req),DMA_ATTR_NO_WARN );
drivers/pci/p2pdma.c +4 -3
@@ -788,13 +788,14 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_publish);* @sg: scatter list to map * @nents: elements in the scatterlist * @dir: DMA direction +* @attrs: dma attributes passed to dma_map_sg() (if called) * * Scatterlists mapped with this function should not be unmapped in any way. * * Returns the number of SG entries mapped or 0 on error. */ -int pci_p2pdma_map_sg (struct device *dev,struct scatterlist *sg,int nents, -enum dma_data_direction dir) +int pci_p2pdma_map_sg_attrs (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs) {struct pci_p2pdma_pagemap *p2p_pgmap;struct scatterlist *s;
@@ -821,7 +822,7 @@ int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg, int nents,return nents; } -EXPORT_SYMBOL_GPL (pci_p2pdma_map_sg); +EXPORT_SYMBOL_GPL (pci_p2pdma_map_sg_attrs);/** * pci_p2pdma_enable_store - parse a configfs/sysfs attribute store
include/linux/pci-p2pdma.h +11 -4
@@ -30,8 +30,8 @@ struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev, unsigned int *nents, u32 length);void pci_p2pmem_free_sgl (struct pci_dev *pdev,struct scatterlist *sgl);void pci_p2pmem_publish (struct pci_dev *pdev,bool publish); -int pci_p2pdma_map_sg (struct device *dev,struct scatterlist *sg,int nents, -enum dma_data_direction dir); +int pci_p2pdma_map_sg_attrs (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs);int pci_p2pdma_enable_store (const char *page,struct pci_dev **p2p_dev,bool *use_p2pdma); ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
@@ -81,8 +81,9 @@ static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,static inline void pci_p2pmem_publish (struct pci_dev *pdev,bool publish) { } -static inline int pci_p2pdma_map_sg (struct device *dev, -struct scatterlist *sg,int nents,enum dma_data_direction dir) +static inline int pci_p2pdma_map_sg_attrs (struct device *dev, +struct scatterlist *sg,int nents,enum dma_data_direction dir, +unsigned long attrs) {return 0 ; }
@@ -111,4 +112,10 @@ static inline struct pci_dev *pci_p2pmem_find(struct device *client) return pci_p2pmem_find_many(&client, 1); } +static inline int pci_p2pdma_map_sg (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir) +{ +return pci_p2pdma_map_sg_attrs (dev, sg, nents, dir,0 ); +} +#endif /* _LINUX_PCI_P2P_H */
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 9/14 PCI/P2PDMA: Introduce pci_p2pdma_unmap_sg()
In reply to Logan GunthorpeAdd pci_p2pdma_unmap_sg() to the two places that call pci_p2pdma_map_sg().
This is a prep patch to introduce correct mappings for p2pdma transactions that go through the root complex.
--- drivers/infiniband/core/rw.c | 6 ++++-- drivers/nvme/host/pci.c | 6 ++++-- drivers/pci/p2pdma.c | 18 +++++++++++++++++- include/linux/pci-p2pdma.h | 13 +++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-)
drivers/infiniband/core/rw.c +4 -2
@@ -583,8 +583,10 @@ void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,break ; } -/* P2PDMA contexts do not need to be unmapped */ -if (!is_pci_p2pdma_page (sg_page (sg))) +if (is_pci_p2pdma_page (sg_page (sg))) +pci_p2pdma_unmap_sg (qp->pd->device->dma_device, sg, + sg_cnt, dir); +else ib_dma_unmap_sg (qp->pd->device, sg, sg_cnt, dir); }EXPORT_SYMBOL (rdma_rw_ctx_destroy);
drivers/nvme/host/pci.c +4 -2
@@ -547,8 +547,10 @@ static void nvme_unmap_data(struct nvme_dev *dev, struct request *req)WARN_ON_ONCE (!iod->nents); -/* P2PDMA requests do not need to be unmapped */ -if (!is_pci_p2pdma_page (sg_page (iod->sg))) +if (is_pci_p2pdma_page (sg_page (iod->sg))) +pci_p2pdma_unmap_sg (dev->dev, iod->sg, iod->nents, +rq_dma_dir (req)); +else dma_unmap_sg (dev->dev, iod->sg, iod->nents,rq_dma_dir (req));
drivers/pci/p2pdma.c +17 -1
@@ -790,7 +790,8 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_publish);* @dir: DMA direction * @attrs: dma attributes passed to dma_map_sg() (if called) * -* Scatterlists mapped with this function should not be unmapped in any way. +* Scatterlists mapped with this function should be unmapped using +* pci_p2pdma_unmap_sg_attrs(). * * Returns the number of SG entries mapped or 0 on error. */
@@ -824,6 +825,21 @@ int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg, }EXPORT_SYMBOL_GPL (pci_p2pdma_map_sg_attrs); +/** +* pci_p2pdma_unmap_sg - unmap a PCI peer-to-peer scatterlist that was +* mapped with pci_p2pdma_map_sg() +* @dev: device doing the DMA request +* @sg: scatter list to map +* @nents: number of elements returned by pci_p2pdma_map_sg() +* @dir: DMA direction +* @attrs: dma attributes passed to dma_unmap_sg() (if called) +*/ +void pci_p2pdma_unmap_sg_attrs (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs) +{ +} +EXPORT_SYMBOL_GPL (pci_p2pdma_unmap_sg_attrs); +/** * pci_p2pdma_enable_store - parse a configfs/sysfs attribute store * to enable p2pdma
include/linux/pci-p2pdma.h +13 -0
@@ -32,6 +32,8 @@ void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);void pci_p2pmem_publish (struct pci_dev *pdev,bool publish);int pci_p2pdma_map_sg_attrs (struct device *dev,struct scatterlist *sg,int nents,enum dma_data_direction dir,unsigned long attrs); +void pci_p2pdma_unmap_sg_attrs (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs);int pci_p2pdma_enable_store (const char *page,struct pci_dev **p2p_dev,bool *use_p2pdma); ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
@@ -87,6 +89,11 @@ static inline int pci_p2pdma_map_sg_attrs(struct device *dev, {return 0 ; } +static inline void pci_p2pdma_unmap_sg_attrs (struct device *dev, +struct scatterlist *sg,int nents,enum dma_data_direction dir, +unsigned long attrs) +{ +}static inline int pci_p2pdma_enable_store (const char *page,struct pci_dev **p2p_dev,bool *use_p2pdma) {
@@ -118,4 +125,10 @@ static inline int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg, return pci_p2pdma_map_sg_attrs(dev, sg, nents, dir, 0); } +static inline void pci_p2pdma_unmap_sg (struct device *dev, +struct scatterlist *sg,int nents,enum dma_data_direction dir) +{ +pci_p2pdma_unmap_sg_attrs (dev, sg, nents, dir,0 ); +} +#endif /* _LINUX_PCI_P2P_H */
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 10/14 PCI/P2PDMA: Factor out __pci_p2pdma_map_sg()
In reply to Logan GunthorpeFactor out the bus only mapping into it's own static function. No functional changes. The original pci_p2pdma_map_sg_attrs() will be used to decide whether this is an appropriate way to map.
--- drivers/pci/p2pdma.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-)
drivers/pci/p2pdma.c +24 -17
@@ -782,23 +782,9 @@ void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) }EXPORT_SYMBOL_GPL (pci_p2pmem_publish); -/** -* pci_p2pdma_map_sg - map a PCI peer-to-peer scatterlist for DMA -* @dev: device doing the DMA request -* @sg: scatter list to map -* @nents: elements in the scatterlist -* @dir: DMA direction -* @attrs: dma attributes passed to dma_map_sg() (if called) -* -* Scatterlists mapped with this function should be unmapped using -* pci_p2pdma_unmap_sg_attrs(). -* -* Returns the number of SG entries mapped or 0 on error. -*/ -int pci_p2pdma_map_sg_attrs (struct device *dev,struct scatterlist *sg, -int nents,enum dma_data_direction dir,unsigned long attrs) +static int __pci_p2pdma_map_sg (struct pci_p2pdma_pagemap *p2p_pgmap, +struct device *dev,struct scatterlist *sg,int nents) { -struct pci_p2pdma_pagemap *p2p_pgmap;struct scatterlist *s;phys_addr_t paddr;int i;
@@ -814,7 +800,6 @@ int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg,return 0 ;for_each_sg (sg, s, nents, i) { - p2p_pgmap =to_p2p_pgmap (sg_page (s)->pgmap); paddr =sg_phys (s); s->dma_address = paddr - p2p_pgmap->bus_offset;
@@ -823,6 +808,28 @@ int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg,return nents; } + +/** +* pci_p2pdma_map_sg - map a PCI peer-to-peer scatterlist for DMA +* @dev: device doing the DMA request +* @sg: scatter list to map +* @nents: elements in the scatterlist +* @dir: DMA direction +* @attrs: dma attributes passed to dma_map_sg() (if called) +* +* Scatterlists mapped with this function should be unmapped using +* pci_p2pdma_unmap_sg_attrs(). +* +* Returns the number of SG entries mapped or 0 on error. +*/ +int pci_p2pdma_map_sg_attrs (struct device *dev,struct scatterlist *sg, +int nents,enum dma_data_direction dir,unsigned long attrs) +{ +struct pci_p2pdma_pagemap *p2p_pgmap = +to_p2p_pgmap (sg_page (sg)->pgmap); + +return __pci_p2pdma_map_sg (p2p_pgmap, dev, sg, nents); +}EXPORT_SYMBOL_GPL (pci_p2pdma_map_sg_attrs);/**
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 11/14 PCI/P2PDMA: Store mapping method in an xarray
In reply to Logan GunthorpeWhen upstream_bridge_distance() is called store the method required to map the DMA transfers in an xarray so that it can be looked up efficiently on the hot path in pci_p2pdma_map_sg().
--- drivers/pci/p2pdma.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-)
drivers/pci/p2pdma.c +35 -5
@@ -19,10 +19,19 @@#include <linux/random.h> #include <linux/seq_buf.h> #include <linux/iommu.h> +#include <linux/xarray.h> + +enum pci_p2pdma_map_type { +PCI_P2PDMA_MAP_UNKNOWN =0 , +PCI_P2PDMA_MAP_NOT_SUPPORTED , +PCI_P2PDMA_MAP_BUS_ADDR , +PCI_P2PDMA_MAP_THRU_IOMMU , +};struct pci_p2pdma {struct gen_pool *pool;bool p2pmem_published; +struct xarray map_types; };struct pci_p2pdma_pagemap {
@@ -98,6 +107,7 @@ static void pci_p2pdma_release(void *data)gen_pool_destroy (p2pdma->pool);sysfs_remove_group (&pdev->dev.kobj, &p2pmem_group); +xa_destroy (&p2pdma->map_types); }static int pci_p2pdma_setup (struct pci_dev *pdev)
@@ -109,6 +119,8 @@ static int pci_p2pdma_setup(struct pci_dev *pdev)if (!p2p)return -ENOMEM ; +xa_init (&p2p->map_types); + p2p->pool =gen_pool_create (PAGE_SHIFT ,dev_to_node (&pdev->dev));if (!p2p->pool) goto out;
@@ -404,6 +416,12 @@ static int __upstream_bridge_distance(struct pci_dev *provider,return dist_a + dist_b; } +static int map_types_idx (struct pci_dev *client) +{ +return (pci_domain_nr (client->bus) <<16 ) | + (client->bus->number <<8 ) | client->devfn; +} +/* * Find the distance through the nearest common upstream bridge between * two PCI devices.
@@ -446,17 +464,29 @@ static int upstream_bridge_distance(struct pci_dev *provider,struct pci_dev *client, struct seq_buf *acs_list) { + enum pci_p2pdma_map_type map_type;int dist; dist =__upstream_bridge_distance (provider, client, acs_list); -if (!(dist &P2PDMA_THRU_HOST_BRIDGE )) -return dist; +if (!(dist &P2PDMA_THRU_HOST_BRIDGE )) { + map_type =PCI_P2PDMA_MAP_BUS_ADDR ; + goto store_map_type_and_return; + } + +if (host_bridge_whitelist (provider, client)) { + map_type =PCI_P2PDMA_MAP_THRU_IOMMU ; + }else { + dist |=P2PDMA_NOT_SUPPORTED ; + map_type =PCI_P2PDMA_MAP_NOT_SUPPORTED ; + } -if (host_bridge_whitelist (provider, client)) -return dist; +store_map_type_and_return: +if (provider->p2pdma) +xa_store (&provider->p2pdma->map_types,map_types_idx (client), +xa_mk_value (map_type),GFP_KERNEL ); -return dist |P2PDMA_NOT_SUPPORTED ; +return dist; } static int upstream_bridge_distance_warn(struct pci_dev *provider,
Signature · 1 line
2.20.1
Christoph Hellwig
maintainerRe: [PATCH v2 11/14] PCI/P2PDMA: Store mapping method in an xarray
Quoted 15 lines · Logan Gunthorpe
When
upstream_bridge_distance()is called store the method required to map the DMA transfers in an xarray so that it can be looked up efficiently on the hot path inpci_p2pdma_map_sg().Signed-off-by Logan Gunthorpe <logang at deltatee.com>--- drivers/pci/p2pdma.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-)drivers/pci/p2pdma.c +0
-0@@ -19,10 +19,19 @@#include <linux/random.h>
drivers/pci/p2pdma.c line 29
Quoted 10 lines
drivers/pci/p2pdma.c +8
-0#include <linux/seq_buf.h> #include <linux/iommu.h> +#include <linux/xarray.h> + +enum pci_p2pdma_map_type { +PCI_P2PDMA_MAP_UNKNOWN =0 , +PCI_P2PDMA_MAP_NOT_SUPPORTED , +PCI_P2PDMA_MAP_BUS_ADDR , +PCI_P2PDMA_MAP_THRU_IOMMU , +};
So here we add a new enum for the map type, but for the internal code the previousloading of the distance is kept, which seems a little strange.
drivers/pci/p2pdma.c static int upstream_bridge_distance(struct pci_dev *provider, · line 484
Quoted 13 lines
drivers/pci/p2pdma.c +12
-0+if (!(dist &P2PDMA_THRU_HOST_BRIDGE )) { + map_type =PCI_P2PDMA_MAP_BUS_ADDR ; + goto store_map_type_and_return; + } + +if (host_bridge_whitelist (provider, client)) { + map_type =PCI_P2PDMA_MAP_THRU_IOMMU ; + }else { + dist |=P2PDMA_NOT_SUPPORTED ; + map_type =PCI_P2PDMA_MAP_NOT_SUPPORTED ; + } +store_map_type_and_return:
Why not:
if (dist & P2PDMA_THRU_HOST_BRIDGE) {
if (host_bridge_whitelist(provider, client)) {
map_type = PCI_P2PDMA_MAP_THRU_IOMMU;
} else {
dist |= P2PDMA_NOT_SUPPORTED;
map_type = PCI_P2PDMA_MAP_NOT_SUPPORTED;
}
}Logan Gunthorpe
maintainerPATCH v2 12/14 PCI/P2PDMA: dma_map P2PDMA map requests that traverse the host bridge
In reply to Logan GunthorpeAny requests that traverse the host bridge will need to be mapped into the IOMMU, so call dma_map_sg() inside pci_p2pdma_map_sg() when appropriate.
Similarly, call dma_unmap_sg() inside pci_p2pdma_unmap_sg().
--- drivers/pci/p2pdma.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/pci/p2pdma.c +39 -1
@@ -812,6 +812,16 @@ void pci_p2pmem_publish(struct pci_dev *pdev, bool publish) }EXPORT_SYMBOL_GPL (pci_p2pmem_publish); +static enum pci_p2pdma_map_type pci_p2pdma_map_type (struct pci_dev *provider, +struct pci_dev *client) +{ +if (!provider->p2pdma) +return PCI_P2PDMA_MAP_NOT_SUPPORTED ; + +return xa_to_value (xa_load (&provider->p2pdma->map_types, +map_types_idx (client))); +} +static int __pci_p2pdma_map_sg (struct pci_p2pdma_pagemap *p2p_pgmap,struct device *dev,struct scatterlist *sg,int nents) {
@@ -857,8 +867,22 @@ int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg, {struct pci_p2pdma_pagemap *p2p_pgmap =to_p2p_pgmap (sg_page (sg)->pgmap); +struct pci_dev *client; -return __pci_p2pdma_map_sg (p2p_pgmap, dev, sg, nents); +if (WARN_ON_ONCE (!dev_is_pci (dev))) +return 0 ; + + client =to_pci_dev (dev); + +switch (pci_p2pdma_map_type (p2p_pgmap->provider, client)) { +case PCI_P2PDMA_MAP_THRU_IOMMU : +return dma_map_sg_attrs (dev, sg, nents, dir, attrs); +case PCI_P2PDMA_MAP_BUS_ADDR : +return __pci_p2pdma_map_sg (p2p_pgmap, dev, sg, nents); +default : +WARN_ON_ONCE (1 ); +return 0 ; + } }EXPORT_SYMBOL_GPL (pci_p2pdma_map_sg_attrs);
@@ -874,6 +898,20 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_map_sg_attrs);void pci_p2pdma_unmap_sg_attrs (struct device *dev,struct scatterlist *sg,int nents,enum dma_data_direction dir,unsigned long attrs) { +struct pci_p2pdma_pagemap *p2p_pgmap = +to_p2p_pgmap (sg_page (sg)->pgmap); +enum pci_p2pdma_map_type map_type; +struct pci_dev *client; + +if (WARN_ON_ONCE (!dev_is_pci (dev))) +return ; + + client =to_pci_dev (dev); + + map_type =pci_p2pdma_map_type (p2p_pgmap->provider, client); + +if (map_type ==PCI_P2PDMA_MAP_THRU_IOMMU ) +dma_unmap_sg_attrs (dev, sg, nents, dir, attrs); }EXPORT_SYMBOL_GPL (pci_p2pdma_unmap_sg_attrs);
Signature · 1 line
2.20.1
Logan Gunthorpe
maintainerPATCH v2 13/14 PCI/P2PDMA: No longer require no-mmu for host bridge whitelist
In reply to Logan GunthorpeNow that we map the requests correctly we can remove the iommu_present() restriction.
--- drivers/pci/p2pdma.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/pci/p2pdma.c +0 -4
@@ -18,7 +18,6 @@#include <linux/percpu-refcount.h> #include <linux/random.h> #include <linux/seq_buf.h> -#include <linux/iommu.h> #include <linux/xarray.h> enum pci_p2pdma_map_type {
@@ -328,9 +327,6 @@ static bool host_bridge_whitelist(struct pci_dev *a, struct pci_dev *b)struct pci_host_bridge *host_a =pci_find_host_bridge (a->bus);struct pci_host_bridge *host_b =pci_find_host_bridge (b->bus); -if (iommu_present (a->dev.bus) ||iommu_present (b->dev.bus)) -return false; -if (host_a == host_b)return __host_bridge_whitelist (host_a, true);
Signature · 1 line
2.20.1
Christoph Hellwig
maintainerRe: [PATCH v2 13/14] PCI/P2PDMA: No longer require no-mmu for host bridge whitelist
no-mmu sounds stange, as we use that for linux ports without paging hardware. I think an "io" got lost somewhere..
Re: [PATCH v2 13/14] PCI/P2PDMA: No longer require no-mmu for host bridge whitelist
Quoted 2 lines · Christoph Hellwig
no-mmu sounds stange, as we use that for linux ports without paging hardware. I think an "io" got lost somewhere..
I had already changed the subject to
PCI/P2PDMA: Allow IOMMU for host bridge whitelist
but certainly open to better suggestions.
Christoph Hellwig
maintainerRe: [PATCH v2 13/14] PCI/P2PDMA: No longer require no-mmu for host bridge whitelist
Quoted 9 lines · Bjorn Helgaas
Quoted 2 lines · Christoph Hellwig
no-mmu sounds stange, as we use that for linux ports without paging hardware. I think an "io" got lost somewhere..
I had already changed the subject to
PCI/P2PDMA: Allow IOMMU for host bridge whitelist
but certainly open to better suggestions.
Maybe:
PCI/P2PDMA: Allow P2P transfers behind IOMMUs
?
Logan Gunthorpe
maintainerPATCH v2 14/14 PCI/P2PDMA: Update documentation for pci_p2pdma_distance_many()
In reply to Logan GunthorpeThe comment describing pci_p2pdma_distance_many() still referred to the devices being behind the same root port. This no longer applies so reword the documentation.
--- drivers/pci/p2pdma.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/pci/p2pdma.c +7 -8
@@ -523,15 +523,14 @@ static int upstream_bridge_distance_warn(struct pci_dev *provider,* @num_clients: number of clients in the array * @verbose: if true, print warnings for devices when we return -1 * -* Returns -1 if any of the clients are not compatible (behind the same -* root port as the provider), otherwise returns a positive number where -* a lower number is the preferable choice. (If there's one client -* that's the same as the provider it will return 0, which is best choice). +* Returns -1 if any of the clients are not compatible, otherwise returns a +* positive number where a lower number is the preferable choice. (If there's +* one client that's the same as the provider it will return 0, which is best +* choice). * -* For now, "compatible" means the provider and the clients are all behind -* the same PCI root port. This cuts out cases that may work but is safest -* for the user. Future work can expand this to white-list root complexes that -* can safely forward between each ports. +* "compatible" means the provider and the clients are either all behind +* the same PCI root port or the host bridge connected to each of the devices +* are is listed in the 'pci_p2pdma_whitelist'. */ int pci_p2pdma_distance_many (struct pci_dev *provider,struct device **clients,int num_clients,bool verbose)
Signature · 1 line
2.20.1
Quoted 32 lines · Logan Gunthorpe
Here's v2 of the patchset. It doesn't sound like there's anything terribly controversial here so this version is mostly just some cleanup changes for clarity.
Changes in v2:
* Rebase on v5.3-rc2 (No changes)
* Re-introduce the private pagemap structure and move the p2p-specific elements out of the commonddev_pagemap(per Christoph)
* Use flags instead of bool in the whitelist (per Jason)
* Only store the mapping type in the xarray (instead of the distance with flags) such that a function can return the mapping method with a switch statement to decide how to map. (per Christoph)
* Dropfind_parent_pci_dev()on the fast path and rely on the fact that the struct device passed to the mapping functions *must* be a PCI device and convert it directly. (per suggestions from Christoph and Jason)
* Collected Christian's Reviewed-by's
--As discussed on the list previously, in order to fully support the whitelist Christian added with the IOMMU, we must ensure that we map any buffer going through the IOMMU with an aprropriate
dma_mapcall. This patchset accomplishes this by cleaning up the output ofupstream_bridge_distance()to better indicate the mapping requirements, caching these requirements in an xarray, then looking them up at map time and applying the appropriate mapping method.After this patchset, it's possible to use the NVMe-of P2P support to transfer between devices without a switch on the whitelisted root complexes. A couple Intel device I have tested this on have also been added to the white list.
Quoted 8 lines
Most of the changes are contained within the
p2pdma.c, but there are a few minor touches to other subsystems, mostly to add support to call an unmap function.The final patch in this series demonstrates a possible
pci_p2pdma_map_resource()function that I expect Christian will need but does not have any users at this time so I don't intend for it to be considered for merging.
I don't see pci_p2pdma_map_resource() in any of these patches.
I tentatively applied these to pci/p2pdma with minor typographical updates (below), but I'll update the branch if necessary.
Quoted 24 lines
This patchset is based on 5.3-rc2 and a git branch is available here:
https://github.com/sbates130272/linux-p2pmem/
p2pdma_rc_map_v2--
Logan Gunthorpe (14):
PCI/P2PDMA: Introduce private pagemap structure PCI/P2PDMA: Add the provider'spci_devto thepci_p2pdma_pagemap
struct
PCI/P2PDMA: Add constants for not-supported result
upstream_bridge_distance()
PCI/P2PDMA: Factor out__upstream_bridge_distance()PCI/P2PDMA: Apply host bridge white list for ACS PCI/P2PDMA: Factor outhost_bridge_whitelist()
PCI/P2PDMA: Add whitelist support for Intel Host Bridges PCI/P2PDMA: Add attrs argument topci_p2pdma_map_sg()PCI/P2PDMA: Introducepci_p2pdma_unmap_sg()
PCI/P2PDMA: Factor out__pci_p2pdma_map_sg()
PCI/P2PDMA: Store mapping method in an xarray
PCI/P2PDMA:dma_mapP2PDMA map requests that traverse the host bridge PCI/P2PDMA: No longer require no-mmu for host bridge whitelist PCI/P2PDMA: Update documentation forpci_p2pdma_distance_many()
Quoted 6 lines
drivers/infiniband/core/rw.c | 6 +- drivers/nvme/host/pci.c | 10 +- drivers/pci/p2pdma.c | 361 +++++++++++++++++++++++++---------- include/linux/memremap.h | 1 - include/linux/pci-p2pdma.h | 28 ++- 5 files changed, 296 insertions(+), 110 deletions(-)
drivers/pci/p2pdma.c +8 -8
@@ -442,17 +442,17 @@ static int map_types_idx(struct pci_dev *client)* port of the switch, to the common upstream port, back up to the second * downstream port and then to Device B. * -* Any two devices that cannot communicate using p2pdma will return the distance -* with the flag P2PDMA_NOT_SUPPORTED. +* Any two devices that cannot communicate using p2pdma will return the +* distance with the flag P2PDMA_NOT_SUPPORTED. * * Any two devices that have a data path that goes through the host bridge * will consult a whitelist. If the host bridges are on the whitelist, -* then the distance will be returned with the flag P2PDMA_THRU_HOST_BRIDGE set. +* the distance will be returned with the flag P2PDMA_THRU_HOST_BRIDGE set. * If either bridge is not on the whitelist, the flag P2PDMA_NOT_SUPPORTED will * be set. * * If a bridge which has any ACS redirection bits set is in the path -* then this functions will flag the result with P2PDMA_ACS_FORCES_UPSTREAM. +* this function will flag the result with P2PDMA_ACS_FORCES_UPSTREAM. * In this case, a list of all infringing bridge addresses will be * populated in acs_list (assuming it's non-null) for printk purposes. */
@@ -529,8 +529,8 @@ static int upstream_bridge_distance_warn(struct pci_dev *provider,* choice). * * "compatible" means the provider and the clients are either all behind -* the same PCI root port or the host bridge connected to each of the devices -* are is listed in the 'pci_p2pdma_whitelist'. +* the same PCI root port or the host bridges connected to each of the devices +* are listed in the 'pci_p2pdma_whitelist'. */ int pci_p2pdma_distance_many (struct pci_dev *provider,struct device **clients,int num_clients,bool verbose)
@@ -850,7 +850,7 @@ static int __pci_p2pdma_map_sg(struct pci_p2pdma_pagemap *p2p_pgmap,* @sg: scatter list to map * @nents: elements in the scatterlist * @dir: DMA direction -* @attrs: dma attributes passed to dma_map_sg() (if called) +* @attrs: DMA attributes passed to dma_map_sg() (if called) * * Scatterlists mapped with this function should be unmapped using * pci_p2pdma_unmap_sg_attrs().
@@ -888,7 +888,7 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_map_sg_attrs);* @sg: scatter list to map * @nents: number of elements returned by pci_p2pdma_map_sg() * @dir: DMA direction -* @attrs: dma attributes passed to dma_unmap_sg() (if called) +* @attrs: DMA attributes passed to dma_unmap_sg() (if called) */ void pci_p2pdma_unmap_sg_attrs (struct device *dev,struct scatterlist *sg,int nents,enum dma_data_direction dir,unsigned long attrs)
Logan Gunthorpe
maintainerQuoted 37 lines · Bjorn Helgaas
Quoted 36 lines · Logan Gunthorpe
Here's v2 of the patchset. It doesn't sound like there's anything terribly controversial here so this version is mostly just some cleanup changes for clarity.
Changes in v2:
* Rebase on v5.3-rc2 (No changes)
* Re-introduce the private pagemap structure and move the p2p-specific elements out of the commonddev_pagemap(per Christoph)
* Use flags instead of bool in the whitelist (per Jason)
* Only store the mapping type in the xarray (instead of the distance with flags) such that a function can return the mapping method with a switch statement to decide how to map. (per Christoph)
* Dropfind_parent_pci_dev()on the fast path and rely on the fact that the struct device passed to the mapping functions *must* be a PCI device and convert it directly. (per suggestions from Christoph and Jason)
* Collected Christian's Reviewed-by's
--As discussed on the list previously, in order to fully support the whitelist Christian added with the IOMMU, we must ensure that we map any buffer going through the IOMMU with an aprropriate
dma_mapcall. This patchset accomplishes this by cleaning up the output ofupstream_bridge_distance()to better indicate the mapping requirements, caching these requirements in an xarray, then looking them up at map time and applying the appropriate mapping method.After this patchset, it's possible to use the NVMe-of P2P support to transfer between devices without a switch on the whitelisted root complexes. A couple Intel device I have tested this on have also been added to the white list.
Most of the changes are contained within the
p2pdma.c, but there are a few minor touches to other subsystems, mostly to add support to call an unmap function.
Quoted 6 lines
Quoted 4 lines
The final patch in this series demonstrates a possible
pci_p2pdma_map_resource()function that I expect Christian will need but does not have any users at this time so I don't intend for it to be considered for merging.I don't see
pci_p2pdma_map_resource()in any of these patches.
Oh, sorry, I removed that in v2 seeing there was some confusion over it. I guess I forgot to remove the reference in the cover letter.
Quoted 2 lines
I tentatively applied these to pci/p2pdma with minor typographical updates (below), but I'll update the branch if necessary.
Great, thanks! The typographical changes look good.
I already have one very minor change queued up for these. Should I just send you a small patch against your branch for you to squash?
Logan
Quoted 9 lines · Logan Gunthorpe
Quoted 2 lines · Bjorn Helgaas
I tentatively applied these to pci/p2pdma with minor typographical updates (below), but I'll update the branch if necessary.
Great, thanks! The typographical changes look good.
I already have one very minor change queued up for these. Should I just send you a small patch against your branch for you to squash?
Yes, an incremental patch against my branch would be nice.
Bjorn