[PATCH v10 1/6] RDMA/umem: Support importing dma-buf as user memory region

Jason Gunthorpe jgg at ziepe.ca
Fri Nov 13 12:49:06 UTC 2020


On Fri, Nov 13, 2020 at 03:30:04AM +0000, Xiong, Jianxin wrote:
> > From: Jason Gunthorpe <jgg at ziepe.ca>
> > Sent: Thursday, November 12, 2020 4:31 PM
> > To: Xiong, Jianxin <jianxin.xiong at intel.com>
> > Cc: linux-rdma at vger.kernel.org; dri-devel at lists.freedesktop.org; Doug Ledford <dledford at redhat.com>; Leon Romanovsky
> > <leon at kernel.org>; Sumit Semwal <sumit.semwal at linaro.org>; Christian Koenig <christian.koenig at amd.com>; Vetter, Daniel
> > <daniel.vetter at intel.com>
> > 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


More information about the dri-devel mailing list