Re: [PATCH v6 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-28 Thread Jason Gunthorpe
On Tue, Oct 27, 2020 at 05:32:26PM +, Xiong, Jianxin wrote: > > On Mon, Oct 26, 2020 at 09:26:37AM -0300, Jason Gunthorpe wrote: > > > On Sat, Oct 24, 2020 at 08:48:07AM +0100, Christoph Hellwig wrote: > > > > On Fri, Oct 23, 2020 at 03:20:05PM -

Re: [PATCH v6 4/4] RDMA/mlx5: Support dma-buf based userspace memory region

2020-10-28 Thread Jason Gunthorpe
On Fri, Oct 23, 2020 at 09:40:01AM -0700, Jianxin Xiong wrote: > diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c > index b261797..3bc412b 100644 > +++ b/drivers/infiniband/hw/mlx5/mr.c > @@ -1,5 +1,6 @@ > /* > * Copyright (c) 2013-2015, Mellanox Technologies. All

Re: [PATCH v6 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-28 Thread Jason Gunthorpe
On Fri, Oct 23, 2020 at 09:39:58AM -0700, Jianxin Xiong wrote: > +/* > + * Generate a new dma sg list from a sub range of an existing dma sg list. > + * Both the input and output have their entries page aligned. > + */ > +static int ib_umem_dmabuf_sgt_slice(struct sg_table *sgt, u64 offset, > +

Re: [PATCH v6 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-26 Thread Jason Gunthorpe
On Sat, Oct 24, 2020 at 08:48:07AM +0100, Christoph Hellwig wrote: > On Fri, Oct 23, 2020 at 03:20:05PM -0300, Jason Gunthorpe wrote: > > The problem is we have RDMA drivers that assume SGL's have a valid > > struct page, and these hacky/wrong P2P sgls that DMABUF creates canno

Re: [PATCH v6 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-24 Thread Jason Gunthorpe
On Fri, Oct 23, 2020 at 06:49:11PM +0200, Daniel Vetter wrote: > > +struct ib_umem *ib_umem_dmabuf_get(struct ib_device *device, > > + unsigned long offset, size_t size, > > + int fd, int access, > > + const

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-23 Thread Jason Gunthorpe
On Thu, Oct 22, 2020 at 09:00:44AM +0200, Daniel Vetter wrote: > On Thu, Oct 22, 2020 at 1:20 AM Jason Gunthorpe wrote: > > > > On Wed, Oct 21, 2020 at 09:24:08PM +0200, Daniel Vetter wrote: > > > On Wed, Oct 21, 2020 at 6:37 PM Jason Gunthorpe wrote: > > > >

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 09:24:08PM +0200, Daniel Vetter wrote: > On Wed, Oct 21, 2020 at 6:37 PM Jason Gunthorpe wrote: > > > > On Wed, Oct 21, 2020 at 05:54:54PM +0200, Daniel Vetter wrote: > > > > > The trouble is that io_remap_pfn adjust vma->pgoff, so we'd nee

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 04:42:11PM +0200, Daniel Vetter wrote: > Uh yes. In drivers/gpu this isn't a problem because we only install > ptes from the vm_ops->fault handler. So no races. And I don't think > you can fix this otherwise through holding locks: mmap_sem we can't > hold because before

Re: [PATCH v3 00/16] follow_pfn and other iomap races

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 10:56:39AM +0200, Daniel Vetter wrote: > Hi all, > > Round 3 of my patch series to clamp down a bunch of races and gaps > around follow_pfn and other access to iomem mmaps. Previous version: > > v1: >

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
to idle io memory ranges") > Signed-off-by: Daniel Vetter > Cc: Jason Gunthorpe > Cc: Kees Cook > Cc: Dan Williams > Cc: Andrew Morton > Cc: John Hubbard > Cc: Jérôme Glisse > Cc: Jan Kara > Cc: Dan Williams > Cc: linux...@kvack.org > Cc: linux-arm-ker..

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 05:54:54PM +0200, Daniel Vetter wrote: > The trouble is that io_remap_pfn adjust vma->pgoff, so we'd need to > split that. So ideally ->mmap would never set up any ptes. /dev/mem makes pgoff == pfn so it doesn't get changed by remap. pgoff doesn't get touched for

Re: [RFC] treewide: cleanup unreachable breaks

2020-10-20 Thread Jason Gunthorpe
On Mon, Oct 19, 2020 at 12:42:15PM -0700, Nick Desaulniers wrote: > On Sat, Oct 17, 2020 at 10:43 PM Greg KH wrote: > > > > On Sat, Oct 17, 2020 at 09:09:28AM -0700, t...@redhat.com wrote: > > > From: Tom Rix > > > > > > This is a upcoming change to clean up a new warning treewide. > > > I am

Re: [PATCH 1/2] mm: mmap: fix fput in error path v2

2020-10-17 Thread Jason Gunthorpe
on the wrong file. > > Revert the workaround and proper fix this in mmap_region. > > v2: drop the extra if in dma_buf_mmap as well > > Signed-off-by: Christian König > Reviewed-by: Jason Gunthorpe > --- > drivers/dma-buf/dma-buf.c | 20 +++-

Re: [PATCH v5 3/5] RDMA/uverbs: Add uverbs command for dma-buf based MR registration

2020-10-17 Thread Jason Gunthorpe
On Thu, Oct 15, 2020 at 03:02:55PM -0700, Jianxin Xiong wrote: > Implement a new uverbs ioctl method for memory registration with file > descriptor as an extra parameter. > > Signed-off-by: Jianxin Xiong > Reviewed-by: Sean Hefty > Acked-by: Michael J. Ruhl > Acked-by: Christian Koenig >

Re: [PATCH v5 1/5] RDMA/umem: Support importing dma-buf as user memory region

2020-10-17 Thread Jason Gunthorpe
On Sat, Oct 17, 2020 at 12:57:21AM +, Xiong, Jianxin wrote: > > From: Jason Gunthorpe > > Sent: Friday, October 16, 2020 5:28 PM > > To: Xiong, Jianxin > > Cc: linux-r...@vger.kernel.org; dri-devel@lists.freedesktop.org; Doug > > Ledford ; Leon Romanovsky

Re: [PATCH 2/2] mm: introduce vma_set_file function v4

2020-10-17 Thread Jason Gunthorpe
c| 3 +-- > drivers/staging/android/ashmem.c | 6 +++--- > include/linux/mm.h | 2 ++ > mm/mmap.c | 12 > 10 files changed, 26 insertions(+), 19 deletions(-) Reviewed-by: Jason Gunthorpe Jason _

Re: [PATCH v5 1/5] RDMA/umem: Support importing dma-buf as user memory region

2020-10-17 Thread Jason Gunthorpe
On Thu, Oct 15, 2020 at 03:02:45PM -0700, Jianxin Xiong wrote: > +static void ib_umem_dmabuf_invalidate_cb(struct dma_buf_attachment *attach) > +{ > + struct ib_umem_dmabuf *umem_dmabuf = attach->importer_priv; > + > + dma_resv_assert_held(umem_dmabuf->attach->dmabuf->resv); > + > +

Re: [PATCH v5 4/5] RDMA/mlx5: Support dma-buf based userspace memory region

2020-10-17 Thread Jason Gunthorpe
On Fri, Oct 16, 2020 at 06:40:01AM +, Xiong, Jianxin wrote: > > > + if (!mr) > > > + return -EINVAL; > > > + > > > + return mlx5_ib_update_xlt(mr, 0, mr->npages, PAGE_SHIFT, flags); } > > > + > > > +static struct ib_umem_dmabuf_ops mlx5_ib_umem_dmabuf_ops = { > > > + .init =

Re: [PATCH v5 1/5] RDMA/umem: Support importing dma-buf as user memory region

2020-10-17 Thread Jason Gunthorpe
On Thu, Oct 15, 2020 at 03:02:45PM -0700, Jianxin Xiong wrote: > +struct ib_umem *ib_umem_dmabuf_get(struct ib_device *device, > +unsigned long addr, size_t size, > +int dmabuf_fd, int access, > +const

Re: [PATCH v5 4/5] RDMA/mlx5: Support dma-buf based userspace memory region

2020-10-17 Thread Jason Gunthorpe
On Thu, Oct 15, 2020 at 03:02:58PM -0700, Jianxin Xiong wrote: > Implement the new driver method 'reg_user_mr_dmabuf'. Utilize the core > functions to import dma-buf based memory region and update the mappings. > > Add code to handle dma-buf related page fault. > > Signed-off-by: Jianxin Xiong

Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework

2020-10-15 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 11:28:54AM -0700, Dan Williams wrote: > On Fri, Oct 9, 2020 at 7:32 AM Jason Gunthorpe wrote: > > > > On Fri, Oct 09, 2020 at 04:24:45PM +0200, Daniel Vetter wrote: > > > On Fri, Oct 9, 2020 at 2:31 PM Jason Gunthorpe wrote: > > > > &

Re: [PATCH 1/6] mm: mmap: fix fput in error path

2020-10-10 Thread Jason Gunthorpe
ma, > return -EINVAL; > > /* readjust the vma */ > - get_file(dmabuf->file); > - oldfile = vma->vm_file; > - vma->vm_file = dmabuf->file; > - vma->vm_pgoff = pgoff; > + if (vma->vm_file) > + fput(vma->vm_fil

Re: [PATCH 1/4] mm: introduce vma_set_file function v2

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 09:39:00AM +0200, Daniel Vetter wrote: > I just noticed this here in the patch because everyone else does not do > this. But looking at the mmap_region() code in mmap.c we seem to indeed > have this problem for the error path: > > unmap_and_free_vma: > vma->vm_file =

Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 04:24:45PM +0200, Daniel Vetter wrote: > On Fri, Oct 9, 2020 at 2:31 PM Jason Gunthorpe wrote: > > > > On Fri, Oct 09, 2020 at 09:59:31AM +0200, Daniel Vetter wrote: > > > > > +struct address_space *iomem_get_mapping(void) > > > +{ &g

Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 02:37:23PM +0200, Mauro Carvalho Chehab wrote: > I'm not a mm/ expert, but, from what I understood from Daniel's patch > description is that this is unsafe *only if* __GFP_MOVABLE is used. No, it is unconditionally unsafe. The CMA movable mappings are specific VMAs that

Re: [PATCH 2/6] mm: introduce vma_set_file function v3

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 05:03:38PM +0200, Christian König wrote: > +/* > + * Change backing file, only valid to use during initial VMA setup. > + */ > +void vma_set_file(struct vm_area_struct *vma, struct file *file) > +{ > + if (file) > + get_file(file); > + > +

Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 12:34:21PM +0200, Mauro Carvalho Chehab wrote: > Hi, > > Em Fri, 9 Oct 2020 09:59:26 +0200 > Daniel Vetter escreveu: > > > Way back it was a reasonable assumptions that iomem mappings never > > change the pfn range they point at. But this has changed: > > > > - gpu

Re: [PATCH v2 14/17] resource: Move devmem revoke code to resource framework

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 09:59:31AM +0200, Daniel Vetter wrote: > +struct address_space *iomem_get_mapping(void) > +{ > + return iomem_inode->i_mapping; This should pair an acquire with the release below > + /* > + * Publish /dev/mem initialized. > + * Pairs with

Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 07:52:05PM +0200, Daniel Vetter wrote: > > > If this is the case, the proper fix seems to have a GFP_NOT_MOVABLE > > > flag that it would be denying the core mm code to set __GFP_MOVABLE. > > > > We can't tell from the VMA these kinds of details.. > > > > It has to go the

Re: [PATCH 1/6] mm: mmap: fix fput in error path

2020-10-10 Thread Jason Gunthorpe
On Fri, Oct 09, 2020 at 03:04:20PM -0700, Andrew Morton wrote: > On Fri, 9 Oct 2020 17:03:37 +0200 "Christian König" > wrote: > > > Patch "495c10cc1c0c CHROMIUM: dma-buf: restore args..." > > adds a workaround for a bug in mmap_region. > > > > As the comment states ->mmap() callback can

Re: [PATCH 10/13] PCI: revoke mappings like devmem

2020-10-09 Thread Jason Gunthorpe
On Thu, Oct 08, 2020 at 12:49:54AM -0700, Dan Williams wrote: > > This is what got me thinking maybe this needs to be a bit bigger > > generic infrastructure - eg enter this scheme from fops mmap and > > everything else is in mm/user_iomem.c > > It still requires every file that can map physical

Re: [PATCH 13/13] vfio/type1: Mark follow_pfn as unsafe

2020-10-08 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 08:14:06PM +0200, Daniel Vetter wrote: > Hm, but wouldn't need that the semi-nasty vma_open trick to make sure > that vma doesn't untimely disappear? Or is the idea to look up the > underlying vfio object, and refcount that directly? Ah, the patches Alex was working on

Re: [PATCH 10/13] PCI: revoke mappings like devmem

2020-10-08 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 12:33:06PM -0700, Dan Williams wrote: > On Wed, Oct 7, 2020 at 11:11 AM Daniel Vetter wrote: > > > > Since 3234ac664a87 ("/dev/mem: Revoke mappings when a driver claims > > the region") /dev/kmem zaps ptes when the kernel requests exclusive > > acccess to an iomem region.

Re: [PATCH 07/13] mm: close race in generic_access_phys

2020-10-08 Thread Jason Gunthorpe
for moving the > memory from iomem to system memory, as the old comment seemed to > suggest. > > References: 28b2ee20c7cb ("access_process_vm device memory infrastructure") > Cc: Jason Gunthorpe > Cc: Dan Williams > Cc: Kees Cook > Cc: Rik van Riel > Cc: Benja

Re: [PATCH 05/13] mm/frame-vector: Use FOLL_LONGTERM

2020-10-08 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 07:12:24PM +0200, Daniel Vetter wrote: > On Wed, Oct 7, 2020 at 6:53 PM Jason Gunthorpe wrote: > > > > On Wed, Oct 07, 2020 at 06:44:18PM +0200, Daniel Vetter wrote: > > > > > > - /* > > > - * While get_vaddr_fr

Re: [PATCH 13/13] vfio/type1: Mark follow_pfn as unsafe

2020-10-08 Thread Jason Gunthorpe
afe. This means that with > CONFIG_STRICT_FOLLOW_PFN, these will be rejected. > > Real fix is to wire up an mmu_notifier ... somehow. Probably means any > invalidate is a fatal fault for this vfio device, but then this > shouldn't ever happen if userspace is reasonable. > > Signe

Re: [PATCH 07/13] mm: close race in generic_access_phys

2020-10-08 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 08:01:42PM +0200, Daniel Vetter wrote: > I think it'd fix the bug, until someone wires ->access up for > drivers/gpu, or the next subsystem. This is also just for ptrace, so > we really don't care when we stall the vm badly and other silly > things. So I figured the

Re: [PATCH 05/13] mm/frame-vector: Use FOLL_LONGTERM

2020-10-08 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 06:44:18PM +0200, Daniel Vetter wrote: > > - /* > - * While get_vaddr_frames() could be used for transient (kernel > - * controlled lifetime) pinning of memory pages all current > - * users establish long term (userspace controlled lifetime) > - *

Re: [PATCH 11/13] mm: add unsafe_follow_pfn

2020-10-08 Thread Jason Gunthorpe
s will then > roll out to all appropriate places. > > Signed-off-by: Daniel Vetter > Cc: Jason Gunthorpe > Cc: Kees Cook > Cc: Dan Williams > Cc: Andrew Morton > Cc: John Hubbard > Cc: Jérôme Glisse > Cc: Jan Kara > Cc: Dan Williams > Cc: linu

Re: [PATCH 11/13] mm: add unsafe_follow_pfn

2020-10-08 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 08:10:34PM +0200, Daniel Vetter wrote: > On Wed, Oct 7, 2020 at 7:36 PM Jason Gunthorpe wrote: > > > > On Wed, Oct 07, 2020 at 06:44:24PM +0200, Daniel Vetter wrote: > > > Way back it was a reasonable assumptions that iomem mappings never &g

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 03:34:01PM +0200, Tomasz Figa wrote: > I think the userptr zero-copy hack should be able to go away indeed, > given that we now have CMA that allows having carveouts backed by > struct pages and having the memory represented as DMA-buf normally. This also needs to figure

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 02:58:33PM +0200, Daniel Vetter wrote: > On Wed, Oct 7, 2020 at 2:48 PM Tomasz Figa wrote: > > > > On Wed, Oct 7, 2020 at 2:44 PM Jason Gunthorpe wrote: > > > > > > On Wed, Oct 07, 2020 at 02:33:56PM +0200, Marek Szyprowski wrote: &g

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 04:11:59PM +0200, Tomasz Figa wrote: > We also need to bring back the vma_open() that somehow disappeared > around 4.2, as Marek found. No Jason ___ dri-devel mailing list dri-devel@lists.freedesktop.org

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 03:06:17PM +0200, Tomasz Figa wrote: > Note that vb2_vmalloc is only used for in-kernel CPU usage, e.g. the > contents being copied by the driver between vb2 buffers and some > hardware FIFO or other dedicated buffers. The memory does not go to > any hardware DMA. That is

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Wed, Oct 07, 2020 at 02:33:56PM +0200, Marek Szyprowski wrote: > Well, it was in vb2_get_vma() function, but now I see that it has been > lost in fb639eb39154 and 6690c8c78c74 some time ago... There is no guarentee that holding a get on the file says anthing about the VMA. This needed to

Re: [RFC PATCH v3 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-07 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 08:17:05PM +0200, Daniel Vetter wrote: > So on the gpu we pipeline this all. So step 4 doesn't happen on the > cpu, but instead we queue up a bunch of command buffers so that the > gpu writes these pagetables (and the flushes tlbs and then does the > actual stuff userspace

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Mon, Oct 05, 2020 at 08:36:00PM -0700, Andrew Morton wrote: > On Mon, 5 Oct 2020 14:47:47 -0300 Jason Gunthorpe wrote: > > > Andrew please let me know if you need a resend > > Andrew is rather confused. > > Can we please identify the minimal patch(es) which are need

Re: [RFC PATCH v3 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-07 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 11:22:14AM +0200, Daniel Vetter wrote: > > For reinstanting the pages you need: > > - dma_resv_lock, this prevents anyone else from issuing new moves or > anything like that > - dma_resv_get_excl + dma_fence_wait to wait for any pending moves to > finish. gpus

Re: linux-next: build failure after merge of the hmm tree

2020-10-07 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 08:35:08PM +1100, Stephen Rothwell wrote: > Hi all, > > After merging the hmm tree, today's linux-next build (arm > multi_v7_defconfig) failed like this: > > > Caused by commit > > 07da1223ec93 ("lib/scatterlist: Add support in dynamic allocation of SG > table from

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-07 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 08:23:23AM +0200, Daniel Vetter wrote: > On Tue, Oct 6, 2020 at 1:41 AM Jason Gunthorpe wrote: > > > > On Tue, Oct 06, 2020 at 12:43:31AM +0200, Daniel Vetter wrote: > > > > > > iow I think I can outright delete the frame vector stuff.

Re: [RFC PATCH v3 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-07 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 07:24:30PM +0200, Daniel Vetter wrote: > On Tue, Oct 6, 2020 at 6:34 PM Daniel Vetter wrote: > > > > On Tue, Oct 06, 2020 at 12:49:56PM -0300, Jason Gunthorpe wrote: > > > On Tue, Oct 06, 2020 at 11:22:14AM +0200, Daniel Vetter wrote: > >

Re: [PATCH rdma-next v5 0/4] Dynamicaly allocate SG table from the pages

2020-10-07 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 12:41:22PM +0200, Daniel Vetter wrote: > On Mon, Oct 05, 2020 at 08:56:50PM -0300, Jason Gunthorpe wrote: > > On Sun, Oct 04, 2020 at 06:43:36PM +0300, Leon Romanovsky wrote: > > > This series extends __sg_alloc_table_from_pages to allow chaining

Re: [RFC PATCH v3 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-06 Thread Jason Gunthorpe
On Sun, Oct 04, 2020 at 12:12:28PM -0700, Jianxin Xiong wrote: > Dma-buf is a standard cross-driver buffer sharing mechanism that can be > used to support peer-to-peer access from RDMA devices. > > Device memory exported via dma-buf is associated with a file descriptor. > This is passed to the

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
On Mon, Oct 05, 2020 at 02:38:54PM -0300, Jason Gunthorpe wrote: > When get_vaddr_frames() does its hacky follow_pfn() loop it should never > be allowed to extract a struct page from a normal VMA. This could allow a > serious use-after-free problem on any kernel memory. > > Restri

Re: [RFC PATCH v3 1/4] RDMA/umem: Support importing dma-buf as user memory region

2020-10-06 Thread Jason Gunthorpe
On Mon, Oct 05, 2020 at 04:18:11PM +, Xiong, Jianxin wrote: > > The implementation in mlx5 will be much more understandable, it would just > > do dma_buf_dynamic_attach() and program the XLT exactly > > the same as a normal umem. > > > > The move_notify() simply zap's the XLT and triggers a

Re: [PATCH rdma-next v5 0/4] Dynamicaly allocate SG table from the pages

2020-10-06 Thread Jason Gunthorpe
On Sun, Oct 04, 2020 at 06:43:36PM +0300, Leon Romanovsky wrote: > This series extends __sg_alloc_table_from_pages to allow chaining of > new pages to already initialized SG table. > > This allows for the drivers to utilize the optimization of merging contiguous > pages without a need to pre

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
On Sun, Oct 04, 2020 at 01:20:31PM +0200, Daniel Vetter wrote: > Yeah I think that works. I tried understanding gup.c code a bit more, > and it looks like FOLL_LONGTERM only works for the pup_fast variant > right now? All others seem to have this comment that it's somehow > incompatible with

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
On Mon, Oct 05, 2020 at 07:53:08PM +0200, Jan Kara wrote: > On Mon 05-10-20 14:38:54, Jason Gunthorpe wrote: > > When get_vaddr_frames() does its hacky follow_pfn() loop it should never > > be allowed to extract a struct page from a normal VMA. This could allow a > > serious u

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
-free problem to only IO memory, which while still serious, is an improvement. Cc: sta...@vger.kernel.org Fixes: 8025e5ddf9c1 ("[media] mm: Provide new get_vaddr_frames() helper") Signed-off-by: Jason Gunthorpe --- mm/frame_vector.c | 4 1 file changed, 4 insertions(+) diff

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
On Sun, Oct 04, 2020 at 06:09:29PM +0200, Daniel Vetter wrote: > On Sun, Oct 4, 2020 at 2:51 PM Jason Gunthorpe wrote: > > > > On Sat, Oct 03, 2020 at 11:40:22AM +0200, Daniel Vetter wrote: > > > > > > That leaves the only interes

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
On Tue, Oct 06, 2020 at 12:43:31AM +0200, Daniel Vetter wrote: > > iow I think I can outright delete the frame vector stuff. > > Ok this doesn't work, because dma_mmap always uses a remap_pfn_range, > which is a VM_IO | VM_PFNMAP vma and so even if it's cma backed and > not a carveout, we can't

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-06 Thread Jason Gunthorpe
On Mon, Oct 05, 2020 at 08:16:33PM +0200, Daniel Vetter wrote: > > kvm is some similar hack added for P2P DMA, see commit > > add6a0cd1c5ba51b201e1361b05a5df817083618. It might be protected by > > notifiers.. > > Yeah my thinking is that kvm (and I think also vfio, also seems to > have mmu

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-05 Thread Jason Gunthorpe
On Sat, Oct 03, 2020 at 03:52:32PM -0700, John Hubbard wrote: > On 10/3/20 2:45 AM, Daniel Vetter wrote: > > On Sat, Oct 3, 2020 at 12:39 AM John Hubbard wrote: > > > > > > On 10/2/20 10:53 AM, Daniel Vetter wrote: > > > > For $reasons I've stumbled over this code and I'm not sure the change > >

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-05 Thread Jason Gunthorpe
On Sat, Oct 03, 2020 at 11:40:22AM +0200, Daniel Vetter wrote: > > That leaves the only interesting places as vb2_dc_get_userptr() and > > vb2_vmalloc_get_userptr() which both completely fail to follow the > > REQUIRED behavior in the function's comment about checking PTEs. It > > just DMA maps

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-03 Thread Jason Gunthorpe
On Fri, Oct 02, 2020 at 08:16:48PM +0200, Daniel Vetter wrote: > On Fri, Oct 2, 2020 at 8:06 PM Jason Gunthorpe wrote: > > On Fri, Oct 02, 2020 at 07:53:03PM +0200, Daniel Vetter wrote: > > > For $reasons I've stumbled over this code and I'm not sure the change > > &g

Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM

2020-10-03 Thread Jason Gunthorpe
On Fri, Oct 02, 2020 at 07:53:03PM +0200, Daniel Vetter wrote: > For $reasons I've stumbled over this code and I'm not sure the change > to the new gup functions in 55a650c35fea ("mm/gup: frame_vector: > convert get_user_pages() --> pin_user_pages()") was entirely correct. > > This here is used

Re: [PATCH rdma-next v4 1/4] lib/scatterlist: Add support in dynamic allocation of SG table from pages

2020-10-03 Thread Jason Gunthorpe
On Sun, Sep 27, 2020 at 09:46:44AM +0300, Leon Romanovsky wrote: > +struct scatterlist *__sg_alloc_table_from_pages(struct sg_table *sgt, > + struct page **pages, unsigned int n_pages, unsigned int offset, > + unsigned long size, unsigned int max_segment, > +

Re: [PATCH rdma-next v4 1/4] lib/scatterlist: Add support in dynamic allocation of SG table from pages

2020-10-03 Thread Jason Gunthorpe
On Fri, Oct 02, 2020 at 07:11:33PM +0300, Maor Gottlieb wrote: > > On 10/2/2020 6:02 PM, Jason Gunthorpe wrote: > > On Sun, Sep 27, 2020 at 09:46:44AM +0300, Leon Romanovsky wrote: > > > +struct scatterlist *__sg_alloc_table_from_pages(struct sg_table *sgt, > > >

Re: [PATCH rdma-next v4 4/4] RDMA/umem: Move to allocate SG table from pages

2020-10-01 Thread Jason Gunthorpe
On Wed, Sep 30, 2020 at 02:53:58PM +0300, Maor Gottlieb wrote: > > On 9/30/2020 2:45 PM, Jason Gunthorpe wrote: > > On Wed, Sep 30, 2020 at 12:53:21PM +0300, Leon Romanovsky wrote: > > > On Tue, Sep 29, 2020 at 04:59:29PM -0300, Jason Gunthorpe wrote: > > > > O

Re: [PATCH rdma-next v4 4/4] RDMA/umem: Move to allocate SG table from pages

2020-10-01 Thread Jason Gunthorpe
On Wed, Sep 30, 2020 at 12:53:21PM +0300, Leon Romanovsky wrote: > On Tue, Sep 29, 2020 at 04:59:29PM -0300, Jason Gunthorpe wrote: > > On Sun, Sep 27, 2020 at 09:46:47AM +0300, Leon Romanovsky wrote: > > > @@ -296,11 +223,17 @@ static struct ib_umem *__ib_umem_get(struct >

Re: [PATCH rdma-next v4 4/4] RDMA/umem: Move to allocate SG table from pages

2020-10-01 Thread Jason Gunthorpe
On Wed, Sep 30, 2020 at 06:05:15PM +0300, Maor Gottlieb wrote: > This is right only for the last iteration. E.g. in the first iteration in > case that there are more pages (left_pages), then we allocate > SG_MAX_SINGLE_ALLOC.  We don't know how many pages from the second iteration > will be

Re: [PATCH rdma-next v4 4/4] RDMA/umem: Move to allocate SG table from pages

2020-09-30 Thread Jason Gunthorpe
On Sun, Sep 27, 2020 at 09:46:47AM +0300, Leon Romanovsky wrote: > @@ -296,11 +223,17 @@ static struct ib_umem *__ib_umem_get(struct ib_device > *device, > goto umem_release; > > cur_base += ret * PAGE_SIZE; > - npages -= ret; > - > -

Re: [PATCH] mm: do not rely on mm == current->mm in __get_user_pages_locked

2020-09-29 Thread Jason Gunthorpe
k+0x1f/0x30 > CR2: 0064 > > This commit fixes the problem by using the mm pointer passed to the > function rather than the bogus one in current. > > Fixes: 008cfe4418b3 ("mm: Introduce mm_struct.has_pinned") > Cc: Jason Gunthorpe > Cc: Peter Xu >

Re: [Intel-gfx] [PATCH rdma-next v3 1/2] lib/scatterlist: Add support in dynamic allocation of SG table from pages

2020-09-28 Thread Jason Gunthorpe
On Fri, Sep 25, 2020 at 01:29:49PM +0100, Tvrtko Ursulin wrote: > > On 25/09/2020 12:58, Jason Gunthorpe wrote: > > On Fri, Sep 25, 2020 at 12:41:29PM +0100, Tvrtko Ursulin wrote: > > > > > > On 25/09/2020 08:13, Leon Romanovsky wrote: > > > > On Thu

Re: [Intel-gfx] [PATCH rdma-next v3 1/2] lib/scatterlist: Add support in dynamic allocation of SG table from pages

2020-09-28 Thread Jason Gunthorpe
On Fri, Sep 25, 2020 at 12:41:29PM +0100, Tvrtko Ursulin wrote: > > On 25/09/2020 08:13, Leon Romanovsky wrote: > > On Thu, Sep 24, 2020 at 09:21:20AM +0100, Tvrtko Ursulin wrote: > > > > > > On 22/09/2020 09:39, Leon Romanovsky wrote: > > > > From: Maor Gottlieb > > > > > > > > Extend

Re: [Intel-gfx] [PATCH rdma-next v3 1/2] lib/scatterlist: Add support in dynamic allocation of SG table from pages

2020-09-28 Thread Jason Gunthorpe
On Fri, Sep 25, 2020 at 10:13:30AM +0300, Leon Romanovsky wrote: > > > diff --git a/tools/testing/scatterlist/main.c > > > b/tools/testing/scatterlist/main.c > > > index 0a1464181226..4899359a31ac 100644 > > > +++ b/tools/testing/scatterlist/main.c > > > @@ -55,14 +55,13 @@ int main(void) > > >

Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap()

2020-09-17 Thread Jason Gunthorpe
On Thu, Sep 17, 2020 at 04:54:44PM +0200, Christian König wrote: > Am 17.09.20 um 16:35 schrieb Jason Gunthorpe: > > On Thu, Sep 17, 2020 at 02:24:29PM +0200, Christian König wrote: > > > Am 17.09.20 um 14:18 schrieb Jason Gunthorpe: > > > > On Thu, Sep 17, 2020

Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap()

2020-09-17 Thread Jason Gunthorpe
On Thu, Sep 17, 2020 at 06:06:14PM +0200, Christian König wrote: > > > If it is already taking a page fault I'm not sure the extra function > > > call indirection is going to be a big deal. Having a uniform VMA > > > sounds saner than every driver custom rolling something. > > > > > > When I

Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap()

2020-09-17 Thread Jason Gunthorpe
On Thu, Sep 17, 2020 at 02:24:29PM +0200, Christian König wrote: > Am 17.09.20 um 14:18 schrieb Jason Gunthorpe: > > On Thu, Sep 17, 2020 at 02:03:48PM +0200, Christian König wrote: > > > Am 17.09.20 um 13:31 schrieb Jason Gunthorpe: > > > > On Thu, Sep 17, 2020 at 1

Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap()

2020-09-17 Thread Jason Gunthorpe
On Thu, Sep 17, 2020 at 10:09:12AM +0200, Daniel Vetter wrote: > Yeah, but it doesn't work when forwarding from the drm chardev to the > dma-buf on the importer side, since you'd need a ton of different > address spaces. And you still rely on the core code picking up your > pgoff mangling, which

Re: [Linaro-mm-sig] Changing vma->vm_file in dma_buf_mmap()

2020-09-17 Thread Jason Gunthorpe
On Thu, Sep 17, 2020 at 02:03:48PM +0200, Christian König wrote: > Am 17.09.20 um 13:31 schrieb Jason Gunthorpe: > > On Thu, Sep 17, 2020 at 10:09:12AM +0200, Daniel Vetter wrote: > > > > > Yeah, but it doesn't work when forwarding from the drm chardev to the > >

Re: Changing vma->vm_file in dma_buf_mmap()

2020-09-16 Thread Jason Gunthorpe
On Wed, Sep 16, 2020 at 11:53:59AM +0200, Daniel Vetter wrote: > But within the driver, we generally need thousands of these, and that > tends to bring fd exhaustion problems with it. That's why all the private > buffer objects which aren't shared with other process or other drivers are > handles

Re: Changing vma->vm_file in dma_buf_mmap()

2020-09-15 Thread Jason Gunthorpe
On Mon, Sep 14, 2020 at 03:30:47PM +0200, Christian König wrote: > Am 14.09.20 um 15:29 schrieb Christian König: > > Hi Andrew, > > > > I'm the new DMA-buf maintainer and Daniel and others came up with > > patches extending the use of the dma_buf_mmap() function. > > > > Now this function is

Re: [trivial PATCH] treewide: Convert switch/case fallthrough; to break;

2020-09-10 Thread Jason Gunthorpe
On Wed, Sep 09, 2020 at 01:06:39PM -0700, Joe Perches wrote: > fallthrough to a separate case/default label break; isn't very readable. > > Convert pseudo-keyword fallthrough; statements to a simple break; when > the next label is case or default and the only statement in the next > label block

Re: [PATCH v3 00/23] device-dax: Support sub-dividing soft-reserved ranges

2020-08-05 Thread Jason Gunthorpe
On Fri, Jul 31, 2020 at 08:24:58PM -0700, Dan Williams wrote: > - Fix test_hmm and other compilation fixups (Ralph) The hmm parts look OK Acked-by: Jason Gunthorpe Jason ___ dri-devel mailing list dri-devel@lists.freedesktop.org ht

Re: linux-next: manual merge of the hmm tree with the drm tree

2020-08-04 Thread Jason Gunthorpe
On Thu, Jul 30, 2020 at 10:31:45AM -0700, Ralph Campbell wrote: > > On 7/30/20 5:03 AM, Jason Gunthorpe wrote: > > On Thu, Jul 30, 2020 at 07:21:10PM +1000, Stephen Rothwell wrote: > > > Hi all, > > > > > > Today's linux-next merge of the hmm tree got a c

Re: linux-next: manual merge of the hmm tree with the drm tree

2020-08-04 Thread Jason Gunthorpe
On Tue, Aug 04, 2020 at 09:29:30AM +1000, Ben Skeggs wrote: > On Tue, Aug 4, 2020 at 9:19 AM Jason Gunthorpe wrote: > > > > On Thu, Jul 30, 2020 at 10:31:45AM -0700, Ralph Campbell wrote: > > > > > > On 7/30/20 5:03 AM, Jason Gunthorpe wrote: > > >

Re: linux-next: manual merge of the hmm tree with the drm tree

2020-07-31 Thread Jason Gunthorpe
On Thu, Jul 30, 2020 at 07:21:10PM +1000, Stephen Rothwell wrote: > Hi all, > > Today's linux-next merge of the hmm tree got a conflict in: > > drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgp100.c > > between commit: > > 7763d24f3ba0 ("drm/nouveau/vmm/gp100-: fix mapping 2MB sysmem pages") >

Re: [PATCH 02/25] dma-fence: prime lockdep annotations

2020-07-14 Thread Jason Gunthorpe
On Fri, Jul 10, 2020 at 03:01:10PM +0200, Christian König wrote: > Am 10.07.20 um 14:54 schrieb Jason Gunthorpe: > > On Fri, Jul 10, 2020 at 02:48:16PM +0200, Christian König wrote: > > > Am 10.07.20 um 14:43 schrieb Jason Gunthorpe: > > > > On Thu, Jul 09, 2020 at 1

Re: [PATCH 02/25] dma-fence: prime lockdep annotations

2020-07-14 Thread Jason Gunthorpe
On Fri, Jul 10, 2020 at 04:02:35PM +0200, Daniel Vetter wrote: > > dma_fence only possibly makes some sense if you intend to expose the > > completion outside a single driver. > > > > The prefered kernel design pattern for this is to connect things with > > a function callback. > > > > So the

Re: [PATCH 02/25] dma-fence: prime lockdep annotations

2020-07-14 Thread Jason Gunthorpe
On Thu, Jul 09, 2020 at 10:09:11AM +0200, Daniel Vetter wrote: > Hi Jason, > > Below the paragraph I've added after our discussions around dma-fences > outside of drivers/gpu. Good enough for an ack on this, or want something > changed? > > Thanks, Daniel > > > + * Note that only GPU drivers

Re: [PATCH 02/25] dma-fence: prime lockdep annotations

2020-07-14 Thread Jason Gunthorpe
On Fri, Jul 10, 2020 at 02:48:16PM +0200, Christian König wrote: > Am 10.07.20 um 14:43 schrieb Jason Gunthorpe: > > On Thu, Jul 09, 2020 at 10:09:11AM +0200, Daniel Vetter wrote: > > > Hi Jason, > > > > > > Below the paragraph I've added after our discuss

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-06 Thread Jason Gunthorpe
On Thu, Jul 02, 2020 at 08:15:40PM +0200, Daniel Vetter wrote: > > > > 3. rdma driver worker gets busy to restart rx: > > > > 1. lock all dma-buf that are currently in use (dma_resv_lock). > > > > thanks to ww_mutex deadlock avoidance this is possible > > > Why all? Why not just

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-06 Thread Jason Gunthorpe
On Fri, Jul 03, 2020 at 02:52:03PM +0200, Daniel Vetter wrote: > So maybe I'm just totally confused about the rdma model. I thought: > - you bind a pile of memory for various transactions, that might > happen whenever. Kernel driver doesn't have much if any insight into > when memory isn't needed

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-03 Thread Jason Gunthorpe
On Tue, Jun 30, 2020 at 08:08:46PM +, Xiong, Jianxin wrote: > > From: Jason Gunthorpe > > Sent: Tuesday, June 30, 2020 12:17 PM > > To: Xiong, Jianxin > > Cc: linux-r...@vger.kernel.org; Doug Ledford ; Sumit > > Semwal ; Leon Romanovsky > > ; Vetter,

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-03 Thread Jason Gunthorpe
On Thu, Jul 02, 2020 at 03:10:00PM +0200, Daniel Vetter wrote: > On Wed, Jul 01, 2020 at 02:15:24PM -0300, Jason Gunthorpe wrote: > > On Wed, Jul 01, 2020 at 05:42:21PM +0200, Daniel Vetter wrote: > > > > >> All you need is the ability to stop wait

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-02 Thread Jason Gunthorpe
On Wed, Jul 01, 2020 at 11:03:06AM +0200, Christian König wrote: > Am 30.06.20 um 20:46 schrieb Xiong, Jianxin: > > > From: Jason Gunthorpe > > > Sent: Tuesday, June 30, 2020 10:35 AM > > > To: Xiong, Jianxin > > > Cc: linux-r...@vger.kernel.org; Do

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-02 Thread Jason Gunthorpe
On Wed, Jul 01, 2020 at 05:42:21PM +0200, Daniel Vetter wrote: > > >> All you need is the ability to stop wait for ongoing accesses to end and > > >> make sure that new ones grab a new mapping. > > > Swap and flush isn't a general HW ability either.. > > > > > > I'm unclear how this could be

Re: [RFC PATCH v2 0/3] RDMA: add dma-buf support

2020-07-01 Thread Jason Gunthorpe
On Tue, Jun 30, 2020 at 06:46:17PM +, Xiong, Jianxin wrote: > > From: Jason Gunthorpe > > Sent: Tuesday, June 30, 2020 10:35 AM > > To: Xiong, Jianxin > > Cc: linux-r...@vger.kernel.org; Doug Ledford ; Sumit > > Semwal ; Leon Romanovsky > > ; Ve

Re: [Linaro-mm-sig] [PATCH 04/18] dma-fence: prime lockdep annotations

2020-06-23 Thread Jason Gunthorpe
On Fri, Jun 19, 2020 at 04:10:11PM -0400, Jerome Glisse wrote: > Maybe we can audit how user ptr buffer are use today and see if > we can define a usage pattern that would allow to cut corner in > kernel. For instance we could use mmu notifier just to block CPU > pte update while we do GUP and

<    5   6   7   8   9   10   11   12   13   14   >