On Fri, Nov 13, 2020 at 03:30:04AM +0000, Xiong, Jianxin wrote: > > From: Jason Gunthorpe <jgg@xxxxxxxx> > > Sent: Thursday, November 12, 2020 4:31 PM > > To: Xiong, Jianxin <jianxin.xiong@xxxxxxxxx> > > Cc: linux-rdma@xxxxxxxxxxxxxxx; dri-devel@xxxxxxxxxxxxxxxxxxxxx; Doug Ledford <dledford@xxxxxxxxxx>; Leon Romanovsky > > <leon@xxxxxxxxxx>; Sumit Semwal <sumit.semwal@xxxxxxxxxx>; Christian Koenig <christian.koenig@xxxxxxx>; Vetter, Daniel > > <daniel.vetter@xxxxxxxxx> > > Subject: Re: [PATCH v10 1/6] RDMA/umem: Support importing dma-buf as user memory region > > > > On Tue, Nov 10, 2020 at 01:41:12PM -0800, Jianxin Xiong wrote: > > > +struct ib_umem *ib_umem_dmabuf_get(struct ib_device *device, > > > + unsigned long offset, size_t size, > > > + int fd, int access, > > > + const struct dma_buf_attach_ops *ops) { > > > + struct dma_buf *dmabuf; > > > + struct ib_umem_dmabuf *umem_dmabuf; > > > + struct ib_umem *umem; > > > + unsigned long end; > > > + long ret; > > > + > > > + if (check_add_overflow(offset, (unsigned long)size, &end)) > > > + return ERR_PTR(-EINVAL); > > > + > > > + if (unlikely(PAGE_ALIGN(end) < PAGE_SIZE)) > > > + return ERR_PTR(-EINVAL); > > > > This is weird, what does it do? > > This sequence is modeled after the following code from ib_umem_init_odp(): > > if (check_add_overflow(umem_odp->umem.address, > (unsigned long)umem_odp->umem.length, > &end)) > return -EOVERFLOW; > end = ALIGN(end, page_size); > if (unlikely(end < page_size)) > return -EOVERFLOW; > > The weird part seems to be checking if 'end' is 0, but that should have been covered > by check_add_overflow() already. I think the + if (unlikely(!ib_umem_num_pages(umem))) { Catches the same condition, no need to do it twice Jason _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel