Re: [PATCH] swiotlb: allocate memory in a cache-friendly way

2021-09-16 Thread Chao Gao
On Thu, Sep 16, 2021 at 11:49:39AM -0400, Konrad Rzeszutek Wilk wrote: >On Wed, Sep 01, 2021 at 12:21:35PM +0800, Chao Gao wrote: >> Currently, swiotlb uses a global index to indicate the starting point >> of next search. The index increases from 0 to the number of slots - 1 >> and then wraps aroun

[PATCH v3 17/20] block: set FOLL_PCI_P2PDMA in bio_map_user_iov()

2021-09-16 Thread Logan Gunthorpe
When a bio's queue supports PCI P2PDMA, set FOLL_PCI_P2PDMA for iov_iter_get_pages_flags(). This allows PCI P2PDMA pages to be passed from userspace and enables the NVMe passthru requests to use P2PDMA pages. Signed-off-by: Logan Gunthorpe --- block/blk-map.c | 7 ++- 1 file changed, 6 inser

[PATCH v3 20/20] nvme-pci: allow mmaping the CMB in userspace

2021-09-16 Thread Logan Gunthorpe
Allow userspace to obtain CMB memory by mmaping the controller's char device. The mmap call allocates and returns a hunk of CMB memory, (the offset is ignored) so userspace does not have control over the address within the CMB. A VMA allocated in this way will only be usable by drivers that set FO

[PATCH v3 18/20] mm: use custom page_free for P2PDMA pages

2021-09-16 Thread Logan Gunthorpe
When P2PDMA pages are passed to userspace, they will need to be reference counted properly and returned to their genalloc after their reference count returns to 1. This is accomplished with the existing DEV_PAGEMAP_OPS and the .page_free() operation. Change CONFIG_P2PDMA to select CONFIG_DEV_PAGEM

[PATCH v3 08/20] iommu/dma: support PCI P2PDMA pages in dma-iommu map_sg

2021-09-16 Thread Logan Gunthorpe
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 P2PDMA pages. A P2PDMA page may have three possib

[PATCH v3 19/20] PCI/P2PDMA: introduce pci_mmap_p2pmem()

2021-09-16 Thread Logan Gunthorpe
Introduce pci_mmap_p2pmem() which is a helper to allocate and mmap a hunk of p2pmem into userspace. Pages are allocated from the genalloc in bulk and their reference count incremented. They are returned to the genalloc when the page is put. The VMA does not take a reference to the pages when they

[PATCH v3 09/20] nvme-pci: check DMA ops when indicating support for PCI P2PDMA

2021-09-16 Thread Logan Gunthorpe
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 ++- drivers/nvme/host/nvme.h | 2 +- drivers/nvme/hos

[PATCH v3 12/20] RDMA/rw: use dma_map_sgtable()

2021-09-16 Thread Logan Gunthorpe
dma_map_sg() now supports the use of P2PDMA pages so pci_p2pdma_map_sg() is no longer necessary and may be dropped. Switch to the dma_map_sgtable() interface which will allow for better error reporting if the P2PDMA pages are unsupported. The change to sgtable also appears to fix a couple subtle

[PATCH v3 06/20] dma-direct: support PCI P2PDMA pages in dma-direct map_sg

2021-09-16 Thread Logan Gunthorpe
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. A P2PDMA page may have three possible outcomes when being mapped: 1) If the data path between

[PATCH v3 05/20] dma-mapping: allow EREMOTEIO return code for P2PDMA transfers

2021-09-16 Thread Logan Gunthorpe
Add EREMOTEIO error return to dma_map_sgtable() which will be used by .map_sg() implementations that detect P2PDMA pages that the underlying DMA device cannot access. Signed-off-by: Logan Gunthorpe --- kernel/dma/mapping.c | 16 +--- 1 file changed, 9 insertions(+), 7 deletions(-) d

[PATCH v3 10/20] nvme-pci: convert to using dma_map_sgtable()

2021-09-16 Thread Logan Gunthorpe
The dma_map operations now support P2PDMA pages directly. So remove the calls to pci_p2pdma_[un]map_sg_attrs() and replace them with calls to dma_map_sgtable(). dma_map_sgtable() returns more complete error codes than dma_map_sg() and allows differentiating EREMOTEIO errors in case an unsupported

[PATCH v3 00/20] Userspace P2PDMA with O_DIRECT NVMe devices

2021-09-16 Thread Logan Gunthorpe
Hi, This patchset continues my work to add userspace P2PDMA access using O_DIRECT NVMe devices. My last posting[1] just included the first 13 patches in this series, but the early P2PDMA cleanup and map_sg error changes from that series have been merged into v5.15-rc1. To address concerns that tha

[PATCH v3 07/20] dma-mapping: add flags to dma_map_ops to indicate PCI P2PDMA support

2021-09-16 Thread Logan Gunthorpe
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 | 10 ++ include/linux/dma-mapping.h | 5 + kernel/dma/mappi

[PATCH v3 11/20] RDMA/core: introduce ib_dma_pci_p2p_dma_supported()

2021-09-16 Thread Logan Gunthorpe
Introduce the helper function ib_dma_pci_p2p_dma_supported() to check if a given ib_device can be used in P2PDMA transfers. This ensures the ib_device is not using virt_dma and also that the underlying dma_device supports P2PDMA. Use the new helper in nvme-rdma to replace the existing check for ib

[PATCH v3 16/20] block: set FOLL_PCI_P2PDMA in __bio_iov_iter_get_pages()

2021-09-16 Thread Logan Gunthorpe
When a bio's queue supports PCI P2PDMA, set FOLL_PCI_P2PDMA for iov_iter_get_pages_flags(). This allows PCI P2PDMA pages to be passed from userspace and enables the O_DIRECT path in iomap based filesystems and direct to block devices. Signed-off-by: Logan Gunthorpe --- block/bio.c | 8 +++-

[PATCH v3 02/20] PCI/P2PDMA: attempt to set map_type if it has not been set

2021-09-16 Thread Logan Gunthorpe
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 to ensure the path was checked ahead of time.

[PATCH v3 14/20] mm: introduce FOLL_PCI_P2PDMA to gate getting PCI P2PDMA pages

2021-09-16 Thread Logan Gunthorpe
Callers that expect PCI P2PDMA pages can now set FOLL_PCI_P2PDMA to allow obtaining P2PDMA pages. If a caller does not set this flag and tries to map P2PDMA pages it will fail. This is implemented by adding a flag and a check to get_dev_pagemap(). Signed-off-by: Logan Gunthorpe --- drivers/dax/

[PATCH v3 04/20] PCI/P2PDMA: introduce helpers for dma_map_sg implementations

2021-09-16 Thread Logan Gunthorpe
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 mapping required a bus address or whether the

[PATCH v3 15/20] iov_iter: introduce iov_iter_get_pages_[alloc_]flags()

2021-09-16 Thread Logan Gunthorpe
Add iov_iter_get_pages_flags() and iov_iter_get_pages_alloc_flags() which take a flags argument that is passed to get_user_pages_fast(). This is so that FOLL_PCI_P2PDMA can be passed when appropriate. Signed-off-by: Logan Gunthorpe --- include/linux/uio.h | 21 + lib/iov_ite

[PATCH v3 01/20] lib/scatterlist: add flag for indicating P2PDMA segments in an SGL

2021-09-16 Thread Logan Gunthorpe
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 different cleanup when a segment is marked as

[PATCH v3 03/20] PCI/P2PDMA: make pci_p2pdma_map_type() non-static

2021-09-16 Thread Logan Gunthorpe
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 --- drivers/pci/p2pdma.c | 24 +- includ

[PATCH v3 13/20] PCI/P2PDMA: remove pci_p2pdma_[un]map_sg()

2021-09-16 Thread Logan Gunthorpe
This interface is superseded by support in dma_map_sg() which now supports heterogeneous scatterlists. There are no longer any users, so remove it. Signed-off-by: Logan Gunthorpe --- drivers/pci/p2pdma.c | 65 -- include/linux/pci-p2pdma.h | 27 -

Re: [PATCH v3 0/8] Implement generic cc_platform_has() helper function

2021-09-16 Thread Kuppuswamy, Sathyanarayanan
On 9/16/21 8:02 AM, Borislav Petkov wrote: On Wed, Sep 15, 2021 at 10:26:06AM -0700, Kuppuswamy, Sathyanarayanan wrote: I have a Intel variant patch (please check following patch). But it includes TDX changes as well. Shall I move TDX changes to different patch and just create a separate patc

Re: [RFC][PATCH v2 00/13] iommu/arm-smmu-v3: Add NVIDIA implementation

2021-09-16 Thread Nicolin Chen via iommu
Hi Kevin, On Thu, Sep 02, 2021 at 10:27:06PM +, Tian, Kevin wrote: > > Indeed, this looks like a flavour of the accelerated invalidation > > stuff we've talked about already. > > > > I would see it probably exposed as some HW specific IOCTL on the iommu > > fd to get access to the accelerated

Re: [PATCH] swiotlb: allocate memory in a cache-friendly way

2021-09-16 Thread Konrad Rzeszutek Wilk
On Wed, Sep 01, 2021 at 12:21:35PM +0800, Chao Gao wrote: > Currently, swiotlb uses a global index to indicate the starting point > of next search. The index increases from 0 to the number of slots - 1 > and then wraps around. It is straightforward but not cache-friendly > because the "oldest" slot

[PATCH v2 4/8] iommu/arm-smmu: Attach to host1x context device bus

2021-09-16 Thread Mikko Perttunen via iommu
Set itself as the IOMMU for the host1x context device bus, containing "dummy" devices used for Host1x context isolation. Signed-off-by: Mikko Perttunen --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 13 + 1 file changed, 13 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu

[PATCH v2 2/8] gpu: host1x: Add context device management code

2021-09-16 Thread Mikko Perttunen via iommu
Add code to register context devices from device tree, allocate them out and manage their refcounts. Signed-off-by: Mikko Perttunen --- v2: * Directly set DMA mask instead of inheriting from Host1x. * Use iommu-map instead of custom DT property. --- drivers/gpu/host1x/Makefile | 1 + drivers/

[PATCH v2 3/8] gpu: host1x: Program context stream ID on submission

2021-09-16 Thread Mikko Perttunen via iommu
Add code to do stream ID switching at the beginning of a job. The stream ID is switched to the stream ID specified by the context passed in the job structure. Before switching the stream ID, an OP_DONE wait is done on the channel's engine to ensure that there is no residual ongoing work that might

[PATCH v2 6/8] drm/tegra: falcon: Set DMACTX field on DMA transactions

2021-09-16 Thread Mikko Perttunen via iommu
The DMACTX field determines which context, as specified in the TRANSCFG register, is used. While during boot it doesn't matter which is used, later on it matters and this value is reused by the firmware. Signed-off-by: Mikko Perttunen --- drivers/gpu/drm/tegra/falcon.c | 8 drivers/gpu/

[PATCH v2 7/8] drm/tegra: vic: Implement get_streamid_offset

2021-09-16 Thread Mikko Perttunen via iommu
Implement the get_streamid_offset required for supporting context isolation. Since old firmware cannot support context isolation without hacks that we don't want to implement, check the firmware binary to see if context isolation should be enabled. Signed-off-by: Mikko Perttunen --- drivers/gpu/

[PATCH v2 5/8] arm64: tegra: Add Host1x context stream IDs on Tegra186+

2021-09-16 Thread Mikko Perttunen via iommu
Add Host1x context stream IDs on systems that support Host1x context isolation. Host1x and attached engines can use these stream IDs to allow isolation between memory used by different processes. The specified stream IDs must match those configured by the hypervisor, if one is present. Signed-off

[PATCH v2 8/8] drm/tegra: Support context isolation

2021-09-16 Thread Mikko Perttunen via iommu
For engines that support context isolation, allocate a context when opening a channel, and set up stream ID offset and context fields when submitting a job. Signed-off-by: Mikko Perttunen --- drivers/gpu/drm/tegra/drm.h| 2 ++ drivers/gpu/drm/tegra/submit.c | 13 + drivers/gpu/d

Re: [PATCH v3 0/8] Implement generic cc_platform_has() helper function

2021-09-16 Thread Borislav Petkov
On Wed, Sep 15, 2021 at 10:26:06AM -0700, Kuppuswamy, Sathyanarayanan wrote: > I have a Intel variant patch (please check following patch). But it includes > TDX changes as well. Shall I move TDX changes to different patch and just > create a separate patch for adding intel_cc_platform_has()? Yes,

[PATCH v2 1/8] gpu: host1x: Add context bus

2021-09-16 Thread Mikko Perttunen via iommu
The context bus is a "dummy" bus that contains struct devices that correspond to IOMMU contexts assigned through Host1x to processes. Even when host1x itself is built as a module, the bus is registered in built-in code so that the built-in ARM SMMU driver is able to reference it. Signed-off-by: M

[PATCH v2 0/8] Host1x context isolation support

2021-09-16 Thread Mikko Perttunen via iommu
Hi all, *** New in v2: Added support for Tegra194 Use standard iommu-map property instead of custom mechanism *** this series adds support for Host1x 'context isolation'. Since when programming engines through Host1x, userspace can program in any addresses it wants, we need some way to isolate t

Re: [PATCH V5 12/12] net: netvsc: Add Isolation VM support for netvsc driver

2021-09-16 Thread Tianyu Lan
On 9/16/2021 12:21 AM, Michael Kelley wrote: I think you are proposing this approach to allocating memory for the send and receive buffers so that you can avoid having two virtual mappings for the memory, per comments from Christop Hellwig. But overall, the approach seems a bit complex and I won

Re: [PATCH V5 12/12] net: netvsc: Add Isolation VM support for netvsc driver

2021-09-16 Thread Tianyu Lan
On 9/16/2021 12:46 AM, Haiyang Zhang wrote: + memset(vmap_pages, 0, + sizeof(*vmap_pages) * vmap_page_index); + vmap_page_index = 0; + + for (j = 0; j < i; j++) +

Re: [PATCH v3 4/8] powerpc/pseries/svm: Add a powerpc version of cc_platform_has()

2021-09-16 Thread Michael Ellerman
Christoph Hellwig writes: > On Wed, Sep 15, 2021 at 07:18:34PM +0200, Christophe Leroy wrote: >> Could you please provide more explicit explanation why inlining such an >> helper is considered as bad practice and messy ? > > Because now we get architectures to all subly differ. Look at the mess >

Re: [PATCH v7 2/9] ACPI/IORT: Add support for RMR node parsing

2021-09-16 Thread Jon Nettleton
On Thu, Sep 16, 2021 at 10:26 AM Shameerali Kolothum Thodi wrote: > > > > > -Original Message- > > From: Jon Nettleton [mailto:j...@solid-run.com] > > Sent: 16 September 2021 08:52 > > To: Shameerali Kolothum Thodi > > Cc: Robin Murphy ; Lorenzo Pieralisi > > ; Laurentiu Tudor ; > > linux

Re: [PATCH V5 09/12] x86/Swiotlb: Add Swiotlb bounce buffer remap function for HV IVM

2021-09-16 Thread Tianyu Lan
On 9/15/2021 11:42 PM, Michael Kelley wrote: @@ -196,13 +199,34 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start, mem->slots[i].orig_addr = INVALID_PHYS_ADDR; mem->slots[i].alloc_size = 0; } + + if (set_memory_decrypte

Re: [PATCH V5 07/12] Drivers: hv: vmbus: Add SNP support for VMbus channel initiate message

2021-09-16 Thread Tianyu Lan
On 9/15/2021 11:41 PM, Michael Kelley wrote: diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 42f3d9d123a1..560cba916d1d 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -240,6 +240,8 @@ struct vmbus_connection { * is child->parent notific

Re: [PATCH] swiotlb: set IO TLB segment size via cmdline

2021-09-16 Thread Roman Skakun
Hi Stefano, > Also, Option 1 listed in the webpage seems to be a lot better. Any > reason you can't do that? Because that option both solves the problem > and increases performance. Yes, Option 1 is probably more efficient. But I use another platform under Xen without DMA adjustment functionality

RE: [PATCH v7 2/9] ACPI/IORT: Add support for RMR node parsing

2021-09-16 Thread Shameerali Kolothum Thodi
> -Original Message- > From: Jon Nettleton [mailto:j...@solid-run.com] > Sent: 16 September 2021 08:52 > To: Shameerali Kolothum Thodi > Cc: Robin Murphy ; Lorenzo Pieralisi > ; Laurentiu Tudor ; > linux-arm-kernel ; ACPI Devel Maling > List ; Linux IOMMU > ; Joerg Roedel ; Will > Deaco

Re: [PATCH v7 2/9] ACPI/IORT: Add support for RMR node parsing

2021-09-16 Thread Jon Nettleton
On Thu, Sep 16, 2021 at 9:26 AM Shameerali Kolothum Thodi wrote: > > > > > -Original Message- > > From: Jon Nettleton [mailto:j...@solid-run.com] > > Sent: 06 September 2021 20:51 > > To: Robin Murphy > > Cc: Lorenzo Pieralisi ; Shameerali Kolothum Thodi > > ; Laurentiu Tudor > > ; linux-

Re: [PATCH v3 4/8] powerpc/pseries/svm: Add a powerpc version of cc_platform_has()

2021-09-16 Thread Christoph Hellwig
On Wed, Sep 15, 2021 at 07:18:34PM +0200, Christophe Leroy wrote: > Could you please provide more explicit explanation why inlining such an > helper is considered as bad practice and messy ? Because now we get architectures to all subly differ. Look at the mess for ioremap and the ioremap* varian

RE: [PATCH v7 2/9] ACPI/IORT: Add support for RMR node parsing

2021-09-16 Thread Shameerali Kolothum Thodi
> -Original Message- > From: Jon Nettleton [mailto:j...@solid-run.com] > Sent: 06 September 2021 20:51 > To: Robin Murphy > Cc: Lorenzo Pieralisi ; Shameerali Kolothum Thodi > ; Laurentiu Tudor > ; linux-arm-kernel > ; ACPI Devel Maling List > ; Linux IOMMU > ; Linuxarm ; > Joerg Roedel