All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
@ 2020-04-30  1:30 kbuild test robot
  0 siblings, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2020-04-30  1:30 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 27228 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200428132005.21424-6-m.szyprowski@samsung.com>
References: <20200428132005.21424-6-m.szyprowski@samsung.com>
TO: Marek Szyprowski <m.szyprowski@samsung.com>

Hi Marek,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on drm-exynos/exynos-drm-next]
[also build test WARNING on next-20200429]
[cannot apply to drm-intel/for-linux-next tegra-drm/drm/tegra/for-next linus/master v5.7-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Marek-Szyprowski/DRM-fix-struct-sg_table-nents-vs-orig_nents-misuse/20200429-040352
base:   https://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git exynos-drm-next
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-191-gc51a0382-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
:::::: branch date: 29 hours ago
:::::: commit date: 29 hours ago

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


sparse warnings: (new ones prefixed by >>)

   drivers/gpu/drm/exynos/exynos_drm_g2d.c:516:9: sparse: sparse: Expected ; at end of statement
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:516:9: sparse: sparse: got if
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:522:20: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:522:20: sparse: sparse: got ->
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:523:20: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:523:20: sparse: sparse: got ->
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:525:23: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:525:23: sparse: sparse: got &
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:527:16: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:527:16: sparse: sparse: got ->
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:527:9: sparse: sparse: Trying to use reserved word 'if' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:529:28: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:529:28: sparse: sparse: got ->
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:530:9: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:530:9: sparse: sparse: got }
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:534:9: sparse: sparse: Trying to use reserved word 'return' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:534:16: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:534:16: sparse: sparse: got &
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:536:18: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:536:18: sparse: sparse: got :
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:539:13: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:539:13: sparse: sparse: got :
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:542:17: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:542:17: sparse: sparse: got :
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:545:21: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:545:21: sparse: sparse: got :
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:548:9: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:548:9: sparse: sparse: got :
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:551:9: sparse: sparse: Trying to use reserved word 'return' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:551:16: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:551:16: sparse: sparse: got ERR_PTR
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:552:1: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:552:1: sparse: sparse: got }
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got =
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'for' as identifier
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'do' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got {
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got !
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'if' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got }
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got *
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'typeof' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got }
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'do' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got {
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got !
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'if' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got }
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ) in function declarator
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got *
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Trying to use reserved word 'typeof' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got }
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got &
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:559:9: sparse: sparse: got )
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:563:12: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:563:12: sparse: sparse: got ->
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:564:1: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:564:1: sparse: sparse: got }
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:570:9: sparse: sparse: Trying to use reserved word 'switch' as identifier
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:571:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:572:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:573:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:574:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:575:9: sparse: sparse: not in switch scope
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:577:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:578:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:580:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:581:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:582:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:583:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:584:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:585:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:587:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:588:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:590:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:591:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:593:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:594:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:596:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:597:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:601:17: sparse: sparse: break/continue not in iterator scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:604:9: sparse: sparse: Trying to use reserved word 'return' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:604:16: sparse: sparse: Expected ; at end of declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:604:16: sparse: sparse: got reg_type
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:605:1: sparse: sparse: Expected ; at the end of type declaration
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:605:1: sparse: sparse: got }
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:611:9: sparse: sparse: Trying to use reserved word 'switch' as identifier
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:612:9: sparse: sparse: not in switch scope
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:613:9: sparse: sparse: not in switch scope
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:615:17: sparse: sparse: too many errors

# https://github.com/0day-ci/linux/commit/e3b3dfab5ae2bb2842aaa4f90c41b264cb18900c
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout e3b3dfab5ae2bb2842aaa4f90c41b264cb18900c
vim +/if +527 drivers/gpu/drm/exynos/exynos_drm_g2d.c

2a3098ff6c2109 Inki Dae         2012-11-04  418  
eb4d9796fa3404 Marek Szyprowski 2018-07-09  419  static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
2a3098ff6c2109 Inki Dae         2012-11-04  420  					unsigned long userptr,
2a3098ff6c2109 Inki Dae         2012-11-04  421  					unsigned long size,
2a3098ff6c2109 Inki Dae         2012-11-04  422  					struct drm_file *filp,
3aa2a5c14076e2 Marek Szyprowski 2018-07-09  423  					void **obj)
2a3098ff6c2109 Inki Dae         2012-11-04  424  {
2a3098ff6c2109 Inki Dae         2012-11-04  425  	struct drm_exynos_file_private *file_priv = filp->driver_priv;
2a3098ff6c2109 Inki Dae         2012-11-04  426  	struct g2d_cmdlist_userptr *g2d_userptr;
2a3098ff6c2109 Inki Dae         2012-11-04  427  	struct sg_table	*sgt;
2a3098ff6c2109 Inki Dae         2012-11-04  428  	unsigned long start, end;
2a3098ff6c2109 Inki Dae         2012-11-04  429  	unsigned int npages, offset;
2a3098ff6c2109 Inki Dae         2012-11-04  430  	int ret;
2a3098ff6c2109 Inki Dae         2012-11-04  431  
2a3098ff6c2109 Inki Dae         2012-11-04  432  	if (!size) {
6f83d20838c099 Inki Dae         2019-04-15  433  		DRM_DEV_ERROR(g2d->dev, "invalid userptr size.\n");
2a3098ff6c2109 Inki Dae         2012-11-04  434  		return ERR_PTR(-EINVAL);
2a3098ff6c2109 Inki Dae         2012-11-04  435  	}
2a3098ff6c2109 Inki Dae         2012-11-04  436  
2a3098ff6c2109 Inki Dae         2012-11-04  437  	/* check if userptr already exists in userptr_list. */
eb4d9796fa3404 Marek Szyprowski 2018-07-09  438  	list_for_each_entry(g2d_userptr, &file_priv->userptr_list, list) {
2a3098ff6c2109 Inki Dae         2012-11-04  439  		if (g2d_userptr->userptr == userptr) {
2a3098ff6c2109 Inki Dae         2012-11-04  440  			/*
2a3098ff6c2109 Inki Dae         2012-11-04  441  			 * also check size because there could be same address
2a3098ff6c2109 Inki Dae         2012-11-04  442  			 * and different size.
2a3098ff6c2109 Inki Dae         2012-11-04  443  			 */
2a3098ff6c2109 Inki Dae         2012-11-04  444  			if (g2d_userptr->size == size) {
2a3098ff6c2109 Inki Dae         2012-11-04  445  				atomic_inc(&g2d_userptr->refcount);
3aa2a5c14076e2 Marek Szyprowski 2018-07-09  446  				*obj = g2d_userptr;
2a3098ff6c2109 Inki Dae         2012-11-04  447  
2a3098ff6c2109 Inki Dae         2012-11-04  448  				return &g2d_userptr->dma_addr;
2a3098ff6c2109 Inki Dae         2012-11-04  449  			}
2a3098ff6c2109 Inki Dae         2012-11-04  450  
2a3098ff6c2109 Inki Dae         2012-11-04  451  			/*
2a3098ff6c2109 Inki Dae         2012-11-04  452  			 * at this moment, maybe g2d dma is accessing this
2a3098ff6c2109 Inki Dae         2012-11-04  453  			 * g2d_userptr memory region so just remove this
2a3098ff6c2109 Inki Dae         2012-11-04  454  			 * g2d_userptr object from userptr_list not to be
2a3098ff6c2109 Inki Dae         2012-11-04  455  			 * referred again and also except it the userptr
2a3098ff6c2109 Inki Dae         2012-11-04  456  			 * pool to be released after the dma access completion.
2a3098ff6c2109 Inki Dae         2012-11-04  457  			 */
2a3098ff6c2109 Inki Dae         2012-11-04  458  			g2d_userptr->out_of_list = true;
2a3098ff6c2109 Inki Dae         2012-11-04  459  			g2d_userptr->in_pool = false;
2a3098ff6c2109 Inki Dae         2012-11-04  460  			list_del_init(&g2d_userptr->list);
2a3098ff6c2109 Inki Dae         2012-11-04  461  
2a3098ff6c2109 Inki Dae         2012-11-04  462  			break;
2a3098ff6c2109 Inki Dae         2012-11-04  463  		}
2a3098ff6c2109 Inki Dae         2012-11-04  464  	}
2a3098ff6c2109 Inki Dae         2012-11-04  465  
2a3098ff6c2109 Inki Dae         2012-11-04  466  	g2d_userptr = kzalloc(sizeof(*g2d_userptr), GFP_KERNEL);
38bb5253a95f2e Sachin Kamat     2013-08-19  467  	if (!g2d_userptr)
2a3098ff6c2109 Inki Dae         2012-11-04  468  		return ERR_PTR(-ENOMEM);
2a3098ff6c2109 Inki Dae         2012-11-04  469  
2a3098ff6c2109 Inki Dae         2012-11-04  470  	atomic_set(&g2d_userptr->refcount, 1);
63540f01917c0d Jan Kara         2015-07-20  471  	g2d_userptr->size = size;
2a3098ff6c2109 Inki Dae         2012-11-04  472  
2a3098ff6c2109 Inki Dae         2012-11-04  473  	start = userptr & PAGE_MASK;
2a3098ff6c2109 Inki Dae         2012-11-04  474  	offset = userptr & ~PAGE_MASK;
2a3098ff6c2109 Inki Dae         2012-11-04  475  	end = PAGE_ALIGN(userptr + size);
2a3098ff6c2109 Inki Dae         2012-11-04  476  	npages = (end - start) >> PAGE_SHIFT;
63540f01917c0d Jan Kara         2015-07-20  477  	g2d_userptr->vec = frame_vector_create(npages);
63540f01917c0d Jan Kara         2015-07-20  478  	if (!g2d_userptr->vec) {
4bb615c5fbb4f3 Seung-Woo Kim    2013-07-03  479  		ret = -ENOMEM;
4bb615c5fbb4f3 Seung-Woo Kim    2013-07-03  480  		goto err_free;
2a3098ff6c2109 Inki Dae         2012-11-04  481  	}
2a3098ff6c2109 Inki Dae         2012-11-04  482  
7f23b3504a0df6 Lorenzo Stoakes  2016-10-13  483  	ret = get_vaddr_frames(start, npages, FOLL_FORCE | FOLL_WRITE,
7f23b3504a0df6 Lorenzo Stoakes  2016-10-13  484  		g2d_userptr->vec);
63540f01917c0d Jan Kara         2015-07-20  485  	if (ret != npages) {
6f83d20838c099 Inki Dae         2019-04-15  486  		DRM_DEV_ERROR(g2d->dev,
6f83d20838c099 Inki Dae         2019-04-15  487  			      "failed to get user pages from userptr.\n");
63540f01917c0d Jan Kara         2015-07-20  488  		if (ret < 0)
63540f01917c0d Jan Kara         2015-07-20  489  			goto err_destroy_framevec;
2a3098ff6c2109 Inki Dae         2012-11-04  490  		ret = -EFAULT;
63540f01917c0d Jan Kara         2015-07-20  491  		goto err_put_framevec;
2a3098ff6c2109 Inki Dae         2012-11-04  492  	}
63540f01917c0d Jan Kara         2015-07-20  493  	if (frame_vector_to_pages(g2d_userptr->vec) < 0) {
2a3098ff6c2109 Inki Dae         2012-11-04  494  		ret = -EFAULT;
63540f01917c0d Jan Kara         2015-07-20  495  		goto err_put_framevec;
2a3098ff6c2109 Inki Dae         2012-11-04  496  	}
2a3098ff6c2109 Inki Dae         2012-11-04  497  
e44a5c00169df6 Sachin Kamat     2013-01-25  498  	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
2a3098ff6c2109 Inki Dae         2012-11-04  499  	if (!sgt) {
2a3098ff6c2109 Inki Dae         2012-11-04  500  		ret = -ENOMEM;
63540f01917c0d Jan Kara         2015-07-20  501  		goto err_put_framevec;
2a3098ff6c2109 Inki Dae         2012-11-04  502  	}
2a3098ff6c2109 Inki Dae         2012-11-04  503  
63540f01917c0d Jan Kara         2015-07-20  504  	ret = sg_alloc_table_from_pages(sgt,
63540f01917c0d Jan Kara         2015-07-20  505  					frame_vector_pages(g2d_userptr->vec),
63540f01917c0d Jan Kara         2015-07-20  506  					npages, offset, size, GFP_KERNEL);
2a3098ff6c2109 Inki Dae         2012-11-04  507  	if (ret < 0) {
6f83d20838c099 Inki Dae         2019-04-15  508  		DRM_DEV_ERROR(g2d->dev, "failed to get sgt from pages.\n");
2a3098ff6c2109 Inki Dae         2012-11-04  509  		goto err_free_sgt;
2a3098ff6c2109 Inki Dae         2012-11-04  510  	}
2a3098ff6c2109 Inki Dae         2012-11-04  511  
2a3098ff6c2109 Inki Dae         2012-11-04  512  	g2d_userptr->sgt = sgt;
2a3098ff6c2109 Inki Dae         2012-11-04  513  
e3b3dfab5ae2bb Marek Szyprowski 2020-04-28  514  	sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
e3b3dfab5ae2bb Marek Szyprowski 2020-04-28  515  				sgt->orig_nents, DMA_BIDIRECTIONAL)
e3b3dfab5ae2bb Marek Szyprowski 2020-04-28  516  	if (!sgt->nents) {
6f83d20838c099 Inki Dae         2019-04-15  517  		DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
6aa5e85d7c1578 Joonyoung Shim   2016-04-22  518  		ret = -ENOMEM;
067ed3311f7961 YoungJun Cho     2013-03-11  519  		goto err_sg_free_table;
2a3098ff6c2109 Inki Dae         2012-11-04  520  	}
2a3098ff6c2109 Inki Dae         2012-11-04  521  
2a3098ff6c2109 Inki Dae         2012-11-04  522  	g2d_userptr->dma_addr = sgt->sgl[0].dma_address;
2a3098ff6c2109 Inki Dae         2012-11-04  523  	g2d_userptr->userptr = userptr;
2a3098ff6c2109 Inki Dae         2012-11-04  524  
eb4d9796fa3404 Marek Szyprowski 2018-07-09  525  	list_add_tail(&g2d_userptr->list, &file_priv->userptr_list);
2a3098ff6c2109 Inki Dae         2012-11-04  526  
2a3098ff6c2109 Inki Dae         2012-11-04 @527  	if (g2d->current_pool + (npages << PAGE_SHIFT) < g2d->max_pool) {
2a3098ff6c2109 Inki Dae         2012-11-04  528  		g2d->current_pool += npages << PAGE_SHIFT;
2a3098ff6c2109 Inki Dae         2012-11-04  529  		g2d_userptr->in_pool = true;
2a3098ff6c2109 Inki Dae         2012-11-04  530  	}
2a3098ff6c2109 Inki Dae         2012-11-04  531  
3aa2a5c14076e2 Marek Szyprowski 2018-07-09  532  	*obj = g2d_userptr;
2a3098ff6c2109 Inki Dae         2012-11-04  533  
2a3098ff6c2109 Inki Dae         2012-11-04 @534  	return &g2d_userptr->dma_addr;
2a3098ff6c2109 Inki Dae         2012-11-04  535  
067ed3311f7961 YoungJun Cho     2013-03-11  536  err_sg_free_table:
2a3098ff6c2109 Inki Dae         2012-11-04  537  	sg_free_table(sgt);
067ed3311f7961 YoungJun Cho     2013-03-11  538  
067ed3311f7961 YoungJun Cho     2013-03-11  539  err_free_sgt:
2a3098ff6c2109 Inki Dae         2012-11-04  540  	kfree(sgt);
2a3098ff6c2109 Inki Dae         2012-11-04  541  
63540f01917c0d Jan Kara         2015-07-20  542  err_put_framevec:
63540f01917c0d Jan Kara         2015-07-20  543  	put_vaddr_frames(g2d_userptr->vec);
2a3098ff6c2109 Inki Dae         2012-11-04  544  
63540f01917c0d Jan Kara         2015-07-20  545  err_destroy_framevec:
63540f01917c0d Jan Kara         2015-07-20  546  	frame_vector_destroy(g2d_userptr->vec);
4bb615c5fbb4f3 Seung-Woo Kim    2013-07-03  547  
4bb615c5fbb4f3 Seung-Woo Kim    2013-07-03  548  err_free:
2a3098ff6c2109 Inki Dae         2012-11-04  549  	kfree(g2d_userptr);
2a3098ff6c2109 Inki Dae         2012-11-04  550  
2a3098ff6c2109 Inki Dae         2012-11-04  551  	return ERR_PTR(ret);
2a3098ff6c2109 Inki Dae         2012-11-04  552  }
2a3098ff6c2109 Inki Dae         2012-11-04  553  
eb4d9796fa3404 Marek Szyprowski 2018-07-09  554  static void g2d_userptr_free_all(struct g2d_data *g2d, struct drm_file *filp)
2a3098ff6c2109 Inki Dae         2012-11-04  555  {
2a3098ff6c2109 Inki Dae         2012-11-04  556  	struct drm_exynos_file_private *file_priv = filp->driver_priv;
2a3098ff6c2109 Inki Dae         2012-11-04  557  	struct g2d_cmdlist_userptr *g2d_userptr, *n;
2a3098ff6c2109 Inki Dae         2012-11-04  558  
eb4d9796fa3404 Marek Szyprowski 2018-07-09 @559  	list_for_each_entry_safe(g2d_userptr, n, &file_priv->userptr_list, list)
2a3098ff6c2109 Inki Dae         2012-11-04  560  		if (g2d_userptr->in_pool)
3aa2a5c14076e2 Marek Szyprowski 2018-07-09  561  			g2d_userptr_put_dma_addr(g2d, g2d_userptr, true);
2a3098ff6c2109 Inki Dae         2012-11-04  562  
2a3098ff6c2109 Inki Dae         2012-11-04  563  	g2d->current_pool = 0;
2a3098ff6c2109 Inki Dae         2012-11-04  564  }
2a3098ff6c2109 Inki Dae         2012-11-04  565  
6f83d20838c099 Inki Dae         2019-04-15  566  static enum g2d_reg_type g2d_get_reg_type(struct g2d_data *g2d, int reg_offset)
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  567  {
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  568  	enum g2d_reg_type reg_type;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  569  
9963cb6ef9e6f9 YoungJun Cho     2013-03-13 @570  	switch (reg_offset) {
9963cb6ef9e6f9 YoungJun Cho     2013-03-13 @571  	case G2D_SRC_BASE_ADDR:
ed4dc2718d3510 Tobias Jakobi    2016-05-25  572  	case G2D_SRC_STRIDE:
2dec17c70e7567 YoungJun Cho     2013-03-11  573  	case G2D_SRC_COLOR_MODE:
2dec17c70e7567 YoungJun Cho     2013-03-11  574  	case G2D_SRC_LEFT_TOP:
2dec17c70e7567 YoungJun Cho     2013-03-11  575  	case G2D_SRC_RIGHT_BOTTOM:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  576  		reg_type = REG_TYPE_SRC;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13 @577  		break;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  578  	case G2D_SRC_PLANE2_BASE_ADDR:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  579  		reg_type = REG_TYPE_SRC_PLANE2;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  580  		break;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  581  	case G2D_DST_BASE_ADDR:
ed4dc2718d3510 Tobias Jakobi    2016-05-25  582  	case G2D_DST_STRIDE:
2dec17c70e7567 YoungJun Cho     2013-03-11  583  	case G2D_DST_COLOR_MODE:
2dec17c70e7567 YoungJun Cho     2013-03-11  584  	case G2D_DST_LEFT_TOP:
2dec17c70e7567 YoungJun Cho     2013-03-11  585  	case G2D_DST_RIGHT_BOTTOM:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  586  		reg_type = REG_TYPE_DST;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  587  		break;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  588  	case G2D_DST_PLANE2_BASE_ADDR:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  589  		reg_type = REG_TYPE_DST_PLANE2;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  590  		break;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  591  	case G2D_PAT_BASE_ADDR:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  592  		reg_type = REG_TYPE_PAT;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  593  		break;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  594  	case G2D_MSK_BASE_ADDR:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  595  		reg_type = REG_TYPE_MSK;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  596  		break;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  597  	default:
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  598  		reg_type = REG_TYPE_NONE;
6f83d20838c099 Inki Dae         2019-04-15  599  		DRM_DEV_ERROR(g2d->dev, "Unknown register offset![%d]\n",
6f83d20838c099 Inki Dae         2019-04-15  600  			      reg_offset);
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  601  		break;
5cdbc8d993074f Sachin Kamat     2014-01-16  602  	}
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  603  
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  604  	return reg_type;
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  605  }
9963cb6ef9e6f9 YoungJun Cho     2013-03-13  606  
2dec17c70e7567 YoungJun Cho     2013-03-11  607  static unsigned long g2d_get_buf_bpp(unsigned int format)
2dec17c70e7567 YoungJun Cho     2013-03-11  608  {
2dec17c70e7567 YoungJun Cho     2013-03-11  609  	unsigned long bpp;
2dec17c70e7567 YoungJun Cho     2013-03-11  610  
2dec17c70e7567 YoungJun Cho     2013-03-11  611  	switch (format) {
2dec17c70e7567 YoungJun Cho     2013-03-11  612  	case G2D_FMT_XRGB8888:
2dec17c70e7567 YoungJun Cho     2013-03-11  613  	case G2D_FMT_ARGB8888:
2dec17c70e7567 YoungJun Cho     2013-03-11  614  		bpp = 4;
2dec17c70e7567 YoungJun Cho     2013-03-11 @615  		break;
2dec17c70e7567 YoungJun Cho     2013-03-11  616  	case G2D_FMT_RGB565:
2dec17c70e7567 YoungJun Cho     2013-03-11  617  	case G2D_FMT_XRGB1555:
2dec17c70e7567 YoungJun Cho     2013-03-11  618  	case G2D_FMT_ARGB1555:
2dec17c70e7567 YoungJun Cho     2013-03-11  619  	case G2D_FMT_XRGB4444:
2dec17c70e7567 YoungJun Cho     2013-03-11  620  	case G2D_FMT_ARGB4444:
2dec17c70e7567 YoungJun Cho     2013-03-11  621  		bpp = 2;
2dec17c70e7567 YoungJun Cho     2013-03-11  622  		break;
2dec17c70e7567 YoungJun Cho     2013-03-11  623  	case G2D_FMT_PACKED_RGB888:
2dec17c70e7567 YoungJun Cho     2013-03-11  624  		bpp = 3;
2dec17c70e7567 YoungJun Cho     2013-03-11  625  		break;
2dec17c70e7567 YoungJun Cho     2013-03-11  626  	default:
2dec17c70e7567 YoungJun Cho     2013-03-11  627  		bpp = 1;
2dec17c70e7567 YoungJun Cho     2013-03-11  628  		break;
2dec17c70e7567 YoungJun Cho     2013-03-11  629  	}
2dec17c70e7567 YoungJun Cho     2013-03-11  630  
2dec17c70e7567 YoungJun Cho     2013-03-11  631  	return bpp;
2dec17c70e7567 YoungJun Cho     2013-03-11  632  }
2dec17c70e7567 YoungJun Cho     2013-03-11  633  

:::::: The code at line 527 was first introduced by commit
:::::: 2a3098ff6c2109557868f9f230f4725312dcb882 drm/exynos: add userptr feature for g2d module

:::::: TO: Inki Dae <inki.dae@samsung.com>
:::::: CC: Inki Dae <inki.dae@samsung.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
  2020-04-28 13:19     ` Marek Szyprowski
                       ` (3 preceding siblings ...)
  (?)
@ 2020-04-28 21:59     ` kbuild test robot
  -1 siblings, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2020-04-28 21:59 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6186 bytes --]

Hi Marek,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on drm-exynos/exynos-drm-next]
[also build test ERROR on next-20200428]
[cannot apply to drm-intel/for-linux-next tegra-drm/drm/tegra/for-next linus/master v5.7-rc3]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Marek-Szyprowski/DRM-fix-struct-sg_table-nents-vs-orig_nents-misuse/20200429-040352
base:   https://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git exynos-drm-next
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=m68k 

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

All errors (new ones prefixed by >>):

   drivers/gpu/drm/exynos/exynos_drm_g2d.c: In function 'g2d_userptr_get_dma_addr':
>> drivers/gpu/drm/exynos/exynos_drm_g2d.c:516:2: error: expected ';' before 'if'
     516 |  if (!sgt->nents) {
         |  ^~
   drivers/gpu/drm/exynos/exynos_drm_g2d.c:536:1: warning: label 'err_sg_free_table' defined but not used [-Wunused-label]
     536 | err_sg_free_table:
         | ^~~~~~~~~~~~~~~~~

vim +516 drivers/gpu/drm/exynos/exynos_drm_g2d.c

   418	
   419	static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
   420						unsigned long userptr,
   421						unsigned long size,
   422						struct drm_file *filp,
   423						void **obj)
   424	{
   425		struct drm_exynos_file_private *file_priv = filp->driver_priv;
   426		struct g2d_cmdlist_userptr *g2d_userptr;
   427		struct sg_table	*sgt;
   428		unsigned long start, end;
   429		unsigned int npages, offset;
   430		int ret;
   431	
   432		if (!size) {
   433			DRM_DEV_ERROR(g2d->dev, "invalid userptr size.\n");
   434			return ERR_PTR(-EINVAL);
   435		}
   436	
   437		/* check if userptr already exists in userptr_list. */
   438		list_for_each_entry(g2d_userptr, &file_priv->userptr_list, list) {
   439			if (g2d_userptr->userptr == userptr) {
   440				/*
   441				 * also check size because there could be same address
   442				 * and different size.
   443				 */
   444				if (g2d_userptr->size == size) {
   445					atomic_inc(&g2d_userptr->refcount);
   446					*obj = g2d_userptr;
   447	
   448					return &g2d_userptr->dma_addr;
   449				}
   450	
   451				/*
   452				 * at this moment, maybe g2d dma is accessing this
   453				 * g2d_userptr memory region so just remove this
   454				 * g2d_userptr object from userptr_list not to be
   455				 * referred again and also except it the userptr
   456				 * pool to be released after the dma access completion.
   457				 */
   458				g2d_userptr->out_of_list = true;
   459				g2d_userptr->in_pool = false;
   460				list_del_init(&g2d_userptr->list);
   461	
   462				break;
   463			}
   464		}
   465	
   466		g2d_userptr = kzalloc(sizeof(*g2d_userptr), GFP_KERNEL);
   467		if (!g2d_userptr)
   468			return ERR_PTR(-ENOMEM);
   469	
   470		atomic_set(&g2d_userptr->refcount, 1);
   471		g2d_userptr->size = size;
   472	
   473		start = userptr & PAGE_MASK;
   474		offset = userptr & ~PAGE_MASK;
   475		end = PAGE_ALIGN(userptr + size);
   476		npages = (end - start) >> PAGE_SHIFT;
   477		g2d_userptr->vec = frame_vector_create(npages);
   478		if (!g2d_userptr->vec) {
   479			ret = -ENOMEM;
   480			goto err_free;
   481		}
   482	
   483		ret = get_vaddr_frames(start, npages, FOLL_FORCE | FOLL_WRITE,
   484			g2d_userptr->vec);
   485		if (ret != npages) {
   486			DRM_DEV_ERROR(g2d->dev,
   487				      "failed to get user pages from userptr.\n");
   488			if (ret < 0)
   489				goto err_destroy_framevec;
   490			ret = -EFAULT;
   491			goto err_put_framevec;
   492		}
   493		if (frame_vector_to_pages(g2d_userptr->vec) < 0) {
   494			ret = -EFAULT;
   495			goto err_put_framevec;
   496		}
   497	
   498		sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
   499		if (!sgt) {
   500			ret = -ENOMEM;
   501			goto err_put_framevec;
   502		}
   503	
   504		ret = sg_alloc_table_from_pages(sgt,
   505						frame_vector_pages(g2d_userptr->vec),
   506						npages, offset, size, GFP_KERNEL);
   507		if (ret < 0) {
   508			DRM_DEV_ERROR(g2d->dev, "failed to get sgt from pages.\n");
   509			goto err_free_sgt;
   510		}
   511	
   512		g2d_userptr->sgt = sgt;
   513	
   514		sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
   515					sgt->orig_nents, DMA_BIDIRECTIONAL)
 > 516		if (!sgt->nents) {
   517			DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
   518			ret = -ENOMEM;
   519			goto err_sg_free_table;
   520		}
   521	
   522		g2d_userptr->dma_addr = sgt->sgl[0].dma_address;
   523		g2d_userptr->userptr = userptr;
   524	
   525		list_add_tail(&g2d_userptr->list, &file_priv->userptr_list);
   526	
   527		if (g2d->current_pool + (npages << PAGE_SHIFT) < g2d->max_pool) {
   528			g2d->current_pool += npages << PAGE_SHIFT;
   529			g2d_userptr->in_pool = true;
   530		}
   531	
   532		*obj = g2d_userptr;
   533	
   534		return &g2d_userptr->dma_addr;
   535	
   536	err_sg_free_table:
   537		sg_free_table(sgt);
   538	
   539	err_free_sgt:
   540		kfree(sgt);
   541	
   542	err_put_framevec:
   543		put_vaddr_frames(g2d_userptr->vec);
   544	
   545	err_destroy_framevec:
   546		frame_vector_destroy(g2d_userptr->vec);
   547	
   548	err_free:
   549		kfree(g2d_userptr);
   550	
   551		return ERR_PTR(ret);
   552	}
   553	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 53996 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
       [not found] ` <CGME20200428132025eucas1p15cf78bdedef6eebc477c7e8429a6f971@eucas1p1.samsung.com>
                       ` (2 preceding siblings ...)
  (?)
@ 2020-04-28 13:19     ` Marek Szyprowski
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Szyprowski @ 2020-04-28 13:19 UTC (permalink / raw)
  To: dri-devel, iommu, linaro-mm-sig, linux-kernel
  Cc: Marek Szyprowski, Christoph Hellwig, Robin Murphy,
	Bartlomiej Zolnierkiewicz, Sumit Semwal, Benjamin Gaignard,
	intel-gfx, linux-arm-kernel, amd-gfx, David Airlie,
	Daniel Vetter

The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the
numer of the created entries in the DMA address space. However the
subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be
called with the original number of entries passed to dma_map_sg. The
sg_table->nents in turn holds the result of the dma_map_sg call as stated
in include/linux/scatterlist.h. Adapt the code to obey those rules.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index fcee33a..e27715c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -396,7 +396,7 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d,
 
 out:
 	dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl,
-			g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL);
+		     g2d_userptr->sgt->orig_nents, DMA_BIDIRECTIONAL);
 
 	pages = frame_vector_pages(g2d_userptr->vec);
 	if (!IS_ERR(pages)) {
@@ -511,8 +511,9 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
 
 	g2d_userptr->sgt = sgt;
 
-	if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents,
-				DMA_BIDIRECTIONAL)) {
+	sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
+				sgt->orig_nents, DMA_BIDIRECTIONAL)
+	if (!sgt->nents) {
 		DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
 		ret = -ENOMEM;
 		goto err_sg_free_table;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
@ 2020-04-28 13:19     ` Marek Szyprowski
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Szyprowski @ 2020-04-28 13:19 UTC (permalink / raw)
  To: dri-devel, iommu, linaro-mm-sig, linux-kernel
  Cc: Daniel Vetter, Bartlomiej Zolnierkiewicz, David Airlie,
	intel-gfx, amd-gfx, Christoph Hellwig, Benjamin Gaignard,
	Robin Murphy, Sumit Semwal, linux-arm-kernel

The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the
numer of the created entries in the DMA address space. However the
subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be
called with the original number of entries passed to dma_map_sg. The
sg_table->nents in turn holds the result of the dma_map_sg call as stated
in include/linux/scatterlist.h. Adapt the code to obey those rules.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index fcee33a..e27715c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -396,7 +396,7 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d,
 
 out:
 	dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl,
-			g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL);
+		     g2d_userptr->sgt->orig_nents, DMA_BIDIRECTIONAL);
 
 	pages = frame_vector_pages(g2d_userptr->vec);
 	if (!IS_ERR(pages)) {
@@ -511,8 +511,9 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
 
 	g2d_userptr->sgt = sgt;
 
-	if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents,
-				DMA_BIDIRECTIONAL)) {
+	sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
+				sgt->orig_nents, DMA_BIDIRECTIONAL)
+	if (!sgt->nents) {
 		DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
 		ret = -ENOMEM;
 		goto err_sg_free_table;
-- 
1.9.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
@ 2020-04-28 13:19     ` Marek Szyprowski
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Szyprowski @ 2020-04-28 13:19 UTC (permalink / raw)
  To: dri-devel, iommu, linaro-mm-sig, linux-kernel
  Cc: Daniel Vetter, Bartlomiej Zolnierkiewicz, David Airlie,
	intel-gfx, amd-gfx, Christoph Hellwig, Benjamin Gaignard,
	Robin Murphy, Sumit Semwal, linux-arm-kernel, Marek Szyprowski

The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the
numer of the created entries in the DMA address space. However the
subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be
called with the original number of entries passed to dma_map_sg. The
sg_table->nents in turn holds the result of the dma_map_sg call as stated
in include/linux/scatterlist.h. Adapt the code to obey those rules.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index fcee33a..e27715c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -396,7 +396,7 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d,
 
 out:
 	dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl,
-			g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL);
+		     g2d_userptr->sgt->orig_nents, DMA_BIDIRECTIONAL);
 
 	pages = frame_vector_pages(g2d_userptr->vec);
 	if (!IS_ERR(pages)) {
@@ -511,8 +511,9 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
 
 	g2d_userptr->sgt = sgt;
 
-	if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents,
-				DMA_BIDIRECTIONAL)) {
+	sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
+				sgt->orig_nents, DMA_BIDIRECTIONAL)
+	if (!sgt->nents) {
 		DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
 		ret = -ENOMEM;
 		goto err_sg_free_table;
-- 
1.9.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
@ 2020-04-28 13:19     ` Marek Szyprowski
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Szyprowski @ 2020-04-28 13:19 UTC (permalink / raw)
  To: dri-devel, iommu, linaro-mm-sig, linux-kernel
  Cc: Bartlomiej Zolnierkiewicz, David Airlie, intel-gfx, amd-gfx,
	Christoph Hellwig, Robin Murphy, linux-arm-kernel,
	Marek Szyprowski

The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the
numer of the created entries in the DMA address space. However the
subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be
called with the original number of entries passed to dma_map_sg. The
sg_table->nents in turn holds the result of the dma_map_sg call as stated
in include/linux/scatterlist.h. Adapt the code to obey those rules.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index fcee33a..e27715c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -396,7 +396,7 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d,
 
 out:
 	dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl,
-			g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL);
+		     g2d_userptr->sgt->orig_nents, DMA_BIDIRECTIONAL);
 
 	pages = frame_vector_pages(g2d_userptr->vec);
 	if (!IS_ERR(pages)) {
@@ -511,8 +511,9 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
 
 	g2d_userptr->sgt = sgt;
 
-	if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents,
-				DMA_BIDIRECTIONAL)) {
+	sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
+				sgt->orig_nents, DMA_BIDIRECTIONAL)
+	if (!sgt->nents) {
 		DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
 		ret = -ENOMEM;
 		goto err_sg_free_table;
-- 
1.9.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse
@ 2020-04-28 13:19     ` Marek Szyprowski
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Szyprowski @ 2020-04-28 13:19 UTC (permalink / raw)
  To: dri-devel, iommu, linaro-mm-sig, linux-kernel
  Cc: Daniel Vetter, Bartlomiej Zolnierkiewicz, David Airlie,
	intel-gfx, amd-gfx, Christoph Hellwig, Benjamin Gaignard,
	Robin Murphy, Sumit Semwal, linux-arm-kernel, Marek Szyprowski

The Documentation/DMA-API-HOWTO.txt states that dma_map_sg returns the
numer of the created entries in the DMA address space. However the
subsequent calls to dma_sync_sg_for_{device,cpu} and dma_unmap_sg must be
called with the original number of entries passed to dma_map_sg. The
sg_table->nents in turn holds the result of the dma_map_sg call as stated
in include/linux/scatterlist.h. Adapt the code to obey those rules.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index fcee33a..e27715c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -396,7 +396,7 @@ static void g2d_userptr_put_dma_addr(struct g2d_data *g2d,
 
 out:
 	dma_unmap_sg(to_dma_dev(g2d->drm_dev), g2d_userptr->sgt->sgl,
-			g2d_userptr->sgt->nents, DMA_BIDIRECTIONAL);
+		     g2d_userptr->sgt->orig_nents, DMA_BIDIRECTIONAL);
 
 	pages = frame_vector_pages(g2d_userptr->vec);
 	if (!IS_ERR(pages)) {
@@ -511,8 +511,9 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct g2d_data *g2d,
 
 	g2d_userptr->sgt = sgt;
 
-	if (!dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl, sgt->nents,
-				DMA_BIDIRECTIONAL)) {
+	sgt->nents = dma_map_sg(to_dma_dev(g2d->drm_dev), sgt->sgl,
+				sgt->orig_nents, DMA_BIDIRECTIONAL)
+	if (!sgt->nents) {
 		DRM_DEV_ERROR(g2d->dev, "failed to map sgt with dma region.\n");
 		ret = -ENOMEM;
 		goto err_sg_free_table;
-- 
1.9.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-30  1:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30  1:30 [RFC 05/17] drm: exynos: fix sg_table nents vs. orig_nents misuse kbuild test robot
  -- strict thread matches above, loose matches on Subject: below --
2020-04-28 13:19 [RFC 00/17] DRM: fix struct " Marek Szyprowski
     [not found] ` <CGME20200428132025eucas1p15cf78bdedef6eebc477c7e8429a6f971@eucas1p1.samsung.com>
2020-04-28 13:19   ` [RFC 05/17] drm: exynos: fix " Marek Szyprowski
2020-04-28 13:19     ` Marek Szyprowski
2020-04-28 13:19     ` Marek Szyprowski
2020-04-28 13:19     ` Marek Szyprowski
2020-04-28 13:19     ` Marek Szyprowski
2020-04-28 21:59     ` kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.