Re: [PATCH 14/16] nvme-rdma: Ensure dma support when using p2pdma

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Ensure the dma operations support p2pdma before using the RDMA device for P2PDMA. This allows switching the RDMA driver from pci_p2pdma_map_sg() to dma_map_sg_p2pdma(). Tentatively, this looks right, but it really should be combined with a following

Re: [PATCH 13/16] nvme-pci: Convert to using dma_map_sg_p2pdma for p2pdma pages

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Convert to using dma_map_sg_p2pdma() for PCI p2pdma pages. This should be equivalent but allows for heterogeneous scatterlists with both P2PDMA and regular pages. However, P2PDMA support will be slightly more restricted (only dma-direct and dma-iommu

Re: [PATCH 12/16] nvme-pci: Check DMA ops when indicating support for PCI P2PDMA

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Introduce a supports_pci_p2pdma() operation in nvme_ctrl_ops to replace the fixed NVME_F_PCI_P2PDMA flag such that the dma_map_ops flags can be checked for PCI P2PDMA support. Signed-off-by: Logan Gunthorpe --- drivers/nvme/host/core.c | 3 ++-

Re: [PATCH 11/16] iommu/dma: Support PCI P2PDMA pages in dma-iommu map_sg

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: When a PCI P2PDMA page is seen, set the IOVA length of the segment to zero so that it is not mapped into the IOVA. Then, in finalise_sg(), apply the appropriate bus address to the segment. The IOVA is not created if the scatterlist only consists of

Re: [PATCH 08/16] PCI/P2PDMA: Introduce helpers for dma_map_sg implementations

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Add pci_p2pdma_map_segment() as a helper for simple dma_map_sg() implementations. It takes an scatterlist segment that must point to a pci_p2pdma struct page and will map it if the mapping requires a bus address. The return value indicates whether the

Re: [PATCH 10/16] dma-mapping: Add flags to dma_map_ops to indicate PCI P2PDMA support

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Add a flags member to the dma_map_ops structure with one flag to indicate support for PCI P2PDMA. Also, add a helper to check if a device supports PCI P2PDMA. Signed-off-by: Logan Gunthorpe --- include/linux/dma-map-ops.h | 3 +++

Re: [PATCH 09/16] dma-direct: Support PCI P2PDMA pages in dma-direct map_sg

2021-05-02 Thread John Hubbard
On 5/2/21 4:28 PM, John Hubbard wrote: On 4/8/21 10:01 AM, Logan Gunthorpe wrote: ... @@ -387,19 +388,37 @@ void dma_direct_unmap_sg(struct device *dev, struct scatterlist *sgl, This routine now deserves a little bit of commenting, now that it is doing less obvious things. How about

Re: [PATCH 09/16] dma-direct: Support PCI P2PDMA pages in dma-direct map_sg

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Add PCI P2PDMA support for dma_direct_map_sg() so that it can map PCI P2PDMA pages directly without a hack in the callers. This allows for heterogeneous SGLs that contain both P2PDMA and regular pages. SGL segments that contain PCI bus addresses are

Re: [PATCH 08/16] PCI/P2PDMA: Introduce helpers for dma_map_sg implementations

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Add pci_p2pdma_map_segment() as a helper for simple dma_map_sg() implementations. It takes an scatterlist segment that must point to a pci_p2pdma struct page and will map it if the mapping requires a bus address. The return value indicates whether the

Re: [PATCH 07/16] PCI/P2PDMA: Make pci_p2pdma_map_type() non-static

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: pci_p2pdma_map_type() will be needed by the dma-iommu map_sg implementation because it will need to determine the mapping type ahead of actually doing the mapping to create the actual iommu mapping. Signed-off-by: Logan Gunthorpe ---

Re: [PATCH 06/16] lib/scatterlist: Add flag for indicating P2PDMA segments in an SGL

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Make use of the third free LSB in scatterlist's page_link on 64bit systems. The extra bit will be used by dma_[un]map_sg_p2pdma() to determine when a given SGL segments dma_address points to a PCI bus address. dma_unmap_sg_p2pdma() will need to perform

Re: [PATCH 05/16] dma-mapping: Introduce dma_map_sg_p2pdma()

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: dma_map_sg() either returns a positive number indicating the number of entries mapped or zero indicating that resources were not available to create the mapping. When zero is returned, it is always safe to retry the mapping later once resources have

Re: [PATCH 04/16] PCI/P2PDMA: Refactor pci_p2pdma_map_type() to take pagmap and device

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: All callers of pci_p2pdma_map_type() have a struct dev_pgmap and a struct device (of the client doing the DMA transfer). Thus move the conversion to struct pci_devs for the provider and client into this function. Actually, this is the wrong direction

Re: [PATCH 03/16] PCI/P2PDMA: Attempt to set map_type if it has not been set

2021-05-02 Thread John Hubbard
On 4/8/21 10:01 AM, Logan Gunthorpe wrote: Attempt to find the mapping type for P2PDMA pages on the first DMA map attempt if it has not been done ahead of time. Previously, the mapping type was expected to be calculated ahead of time, but if pages are to come from userspace then there's no way

[PATCH 4/4] iommu/amd: Do not use flush-queue when NpCache is on

2021-05-02 Thread Nadav Amit
From: Nadav Amit Do not use flush-queue on virtualized environments, where the NpCache capability of the IOMMU is set. This is required to reduce virtualization overheads. This change follows a similar change to Intel's VT-d and a detailed explanation as for the rationale is described in commit

[PATCH 3/4] iommu/amd: Selective flush on unmap

2021-05-02 Thread Nadav Amit
From: Nadav Amit Recent patch attempted to enable selective page flushes on AMD IOMMU but neglected to adapt amd_iommu_iotlb_sync() to use the selective flushes. Adapt amd_iommu_iotlb_sync() to use selective flushes and change amd_iommu_unmap() to collect the flushes. As a defensive measure, to

[PATCH 3/4] iommu/amd: Do not sync on page size changes

2021-05-02 Thread Nadav Amit
From: Nadav Amit Some IOMMU architectures perform invalidations regardless of the page size. In such architectures there is no need to sync when the page size changes or to regard pgsize when making interim flush in iommu_iotlb_gather_add_page(). Add a "ignore_gather_pgsize" property for each

[PATCH 2/4] iommu/amd: Selective flush on unmap

2021-05-02 Thread Nadav Amit
From: Nadav Amit Recent patch attempted to enable selective page flushes on AMD IOMMU but neglected to adapt amd_iommu_iotlb_sync() to use the selective flushes. Adapt amd_iommu_iotlb_sync() to use selective flushes and change amd_iommu_unmap() to collect the flushes. As a defensive measure, to

[PATCH 2/4] iommu/amd: Do not sync on page size changes

2021-05-02 Thread Nadav Amit
From: Nadav Amit Some IOMMU architectures perform invalidations regardless of the page size. In such architectures there is no need to sync when the page size changes. In such architecture, there is no need to regard pgsize when making interim flush in iommu_iotlb_gather_add_page(). Add a

[PATCH 1/4] iommu/amd: Fix wrong parentheses on page-specific invalidations

2021-05-02 Thread Nadav Amit
From: Nadav Amit The logic to determine the mask of page-specific invalidations was tested in userspace. As the code was copied into the kernel, the parentheses were mistakenly set in the wrong place, resulting in the wrong mask. Fix it. Cc: Joerg Roedel Cc: Will Deacon Cc: Jiajun Cao Cc:

[PATCH 0/4] iommu/amd: Enable page-selective flushes

2021-05-02 Thread Nadav Amit
From: Nadav Amit The previous patch, commit 268aa4548277 ("iommu/amd: Page-specific invalidations for more than one page") was supposed to enable page-selective IOTLB flushes on AMD. The patch had an embaressing bug, and I apologize for it. Analysis as for why this bug did not result in