[Intel-gfx] [PATCH] dma-buf: add struct dma_buf_attach_info v2

kbuild test robot lkp at intel.com
Tue Apr 30 23:06:51 UTC 2019


Hi "Christian,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.1-rc7 next-20190430]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Christian-K-nig/dma-buf-add-struct-dma_buf_attach_info-v2/20190430-221017
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp at intel.com>


sparse warnings: (new ones prefixed by >>)

>> drivers/xen/gntdev-dmabuf.c:634:33: sparse: sparse: incorrect type in argument 1 (different base types) @@    expected struct dma_buf_attach_info const *info @@    got dma_buf_attach_info const *info @@
>> drivers/xen/gntdev-dmabuf.c:634:33: sparse:    expected struct dma_buf_attach_info const *info
>> drivers/xen/gntdev-dmabuf.c:634:33: sparse:    got struct dma_buf *[assigned] dma_buf
>> drivers/xen/gntdev-dmabuf.c:634:32: sparse: sparse: too many arguments for function dma_buf_attach

vim +634 drivers/xen/gntdev-dmabuf.c

bf8dc55b Oleksandr Andrushchenko 2018-07-20  605  
932d6562 Oleksandr Andrushchenko 2018-07-20  606  static struct gntdev_dmabuf *
932d6562 Oleksandr Andrushchenko 2018-07-20  607  dmabuf_imp_to_refs(struct gntdev_dmabuf_priv *priv, struct device *dev,
932d6562 Oleksandr Andrushchenko 2018-07-20  608  		   int fd, int count, int domid)
932d6562 Oleksandr Andrushchenko 2018-07-20  609  {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  610  	struct gntdev_dmabuf *gntdev_dmabuf, *ret;
e648feab Christian König         2019-04-30  611  	struct dma_buf_attach_info attach_info;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  612  	struct dma_buf *dma_buf;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  613  	struct dma_buf_attachment *attach;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  614  	struct sg_table *sgt;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  615  	struct sg_page_iter sg_iter;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  616  	int i;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  617  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  618  	dma_buf = dma_buf_get(fd);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  619  	if (IS_ERR(dma_buf))
bf8dc55b Oleksandr Andrushchenko 2018-07-20  620  		return ERR_CAST(dma_buf);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  621  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  622  	gntdev_dmabuf = dmabuf_imp_alloc_storage(count);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  623  	if (IS_ERR(gntdev_dmabuf)) {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  624  		ret = gntdev_dmabuf;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  625  		goto fail_put;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  626  	}
bf8dc55b Oleksandr Andrushchenko 2018-07-20  627  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  628  	gntdev_dmabuf->priv = priv;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  629  	gntdev_dmabuf->fd = fd;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  630  
e648feab Christian König         2019-04-30  631  	memset(&attach_info, 0, sizeof(attach_info));
e648feab Christian König         2019-04-30  632  	attach_info.dev = dev;
e648feab Christian König         2019-04-30  633  	attach_info.dmabuf = dma_buf;
bf8dc55b Oleksandr Andrushchenko 2018-07-20 @634  	attach = dma_buf_attach(dma_buf, dev);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  635  	if (IS_ERR(attach)) {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  636  		ret = ERR_CAST(attach);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  637  		goto fail_free_obj;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  638  	}
bf8dc55b Oleksandr Andrushchenko 2018-07-20  639  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  640  	gntdev_dmabuf->u.imp.attach = attach;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  641  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  642  	sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  643  	if (IS_ERR(sgt)) {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  644  		ret = ERR_CAST(sgt);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  645  		goto fail_detach;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  646  	}
bf8dc55b Oleksandr Andrushchenko 2018-07-20  647  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  648  	/* Check number of pages that imported buffer has. */
bf8dc55b Oleksandr Andrushchenko 2018-07-20  649  	if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  650  		ret = ERR_PTR(-EINVAL);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  651  		pr_debug("DMA buffer has %zu pages, user-space expects %d\n",
bf8dc55b Oleksandr Andrushchenko 2018-07-20  652  			 attach->dmabuf->size, gntdev_dmabuf->nr_pages);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  653  		goto fail_unmap;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  654  	}
bf8dc55b Oleksandr Andrushchenko 2018-07-20  655  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  656  	gntdev_dmabuf->u.imp.sgt = sgt;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  657  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  658  	/* Now convert sgt to array of pages and check for page validity. */
bf8dc55b Oleksandr Andrushchenko 2018-07-20  659  	i = 0;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  660  	for_each_sg_page(sgt->sgl, &sg_iter, sgt->nents, 0) {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  661  		struct page *page = sg_page_iter_page(&sg_iter);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  662  		/*
bf8dc55b Oleksandr Andrushchenko 2018-07-20  663  		 * Check if page is valid: this can happen if we are given
bf8dc55b Oleksandr Andrushchenko 2018-07-20  664  		 * a page from VRAM or other resources which are not backed
bf8dc55b Oleksandr Andrushchenko 2018-07-20  665  		 * by a struct page.
bf8dc55b Oleksandr Andrushchenko 2018-07-20  666  		 */
bf8dc55b Oleksandr Andrushchenko 2018-07-20  667  		if (!pfn_valid(page_to_pfn(page))) {
bf8dc55b Oleksandr Andrushchenko 2018-07-20  668  			ret = ERR_PTR(-EINVAL);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  669  			goto fail_unmap;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  670  		}
bf8dc55b Oleksandr Andrushchenko 2018-07-20  671  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  672  		gntdev_dmabuf->pages[i++] = page;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  673  	}
bf8dc55b Oleksandr Andrushchenko 2018-07-20  674  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  675  	ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages,
bf8dc55b Oleksandr Andrushchenko 2018-07-20  676  						      gntdev_dmabuf->u.imp.refs,
bf8dc55b Oleksandr Andrushchenko 2018-07-20  677  						      count, domid));
bf8dc55b Oleksandr Andrushchenko 2018-07-20  678  	if (IS_ERR(ret))
bf8dc55b Oleksandr Andrushchenko 2018-07-20  679  		goto fail_end_access;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  680  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  681  	pr_debug("Imported DMA buffer with fd %d\n", fd);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  682  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  683  	mutex_lock(&priv->lock);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  684  	list_add(&gntdev_dmabuf->next, &priv->imp_list);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  685  	mutex_unlock(&priv->lock);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  686  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  687  	return gntdev_dmabuf;
bf8dc55b Oleksandr Andrushchenko 2018-07-20  688  
bf8dc55b Oleksandr Andrushchenko 2018-07-20  689  fail_end_access:
bf8dc55b Oleksandr Andrushchenko 2018-07-20  690  	dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, count);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  691  fail_unmap:
bf8dc55b Oleksandr Andrushchenko 2018-07-20  692  	dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  693  fail_detach:
bf8dc55b Oleksandr Andrushchenko 2018-07-20  694  	dma_buf_detach(dma_buf, attach);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  695  fail_free_obj:
bf8dc55b Oleksandr Andrushchenko 2018-07-20  696  	dmabuf_imp_free_storage(gntdev_dmabuf);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  697  fail_put:
bf8dc55b Oleksandr Andrushchenko 2018-07-20  698  	dma_buf_put(dma_buf);
bf8dc55b Oleksandr Andrushchenko 2018-07-20  699  	return ret;
932d6562 Oleksandr Andrushchenko 2018-07-20  700  }
932d6562 Oleksandr Andrushchenko 2018-07-20  701  

:::::: The code at line 634 was first introduced by commit
:::::: bf8dc55b135873d8bc58bb8fbc91c52f3a902eea xen/gntdev: Implement dma-buf import functionality

:::::: TO: Oleksandr Andrushchenko <oleksandr_andrushchenko at epam.com>
:::::: CC: Boris Ostrovsky <boris.ostrovsky at oracle.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation


More information about the Intel-gfx mailing list