Re: [PATCH] dma-buf: cma_heap: Check for device max segment size when attaching

2022-08-23 Thread kernel test robot
Hi Andrew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.0-rc2 next-20220823]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Andrew-Davis/dma-buf-cma_heap-Check-for-device-max-segment-size-when-attaching/20220823-073240
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
config: x86_64-randconfig-a002-20220822 
(https://download.01.org/0day-ci/archive/20220823/202208231555.eczoe9tv-...@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project 
f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/intel-lab-lkp/linux/commit/f390cef50ba6681ea767283e413cb8e9f8f2b426
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Andrew-Davis/dma-buf-cma_heap-Check-for-device-max-segment-size-when-attaching/20220823-073240
git checkout f390cef50ba6681ea767283e413cb8e9f8f2b426
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 
O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/dma-buf/heaps/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/dma-buf/heaps/cma_heap.c:61:9: warning: mixing declarations and code 
>> is incompatible with standards before C99 [-Wdeclaration-after-statement]
   size_t max_segment = dma_get_max_seg_size(attachment->dev);
  ^
   1 warning generated.


vim +61 drivers/dma-buf/heaps/cma_heap.c

49  
50  static int cma_heap_attach(struct dma_buf *dmabuf,
51 struct dma_buf_attachment *attachment)
52  {
53  struct cma_heap_buffer *buffer = dmabuf->priv;
54  struct dma_heap_attachment *a;
55  int ret;
56  
57  a = kzalloc(sizeof(*a), GFP_KERNEL);
58  if (!a)
59  return -ENOMEM;
60  
  > 61  size_t max_segment = dma_get_max_seg_size(attachment->dev);
62  ret = sg_alloc_table_from_pages_segment(>table, 
buffer->pages,
63  buffer->pagecount, 0,
64  buffer->pagecount << 
PAGE_SHIFT,
65  max_segment, 
GFP_KERNEL);
66  if (ret) {
67  kfree(a);
68  return ret;
69  }
70  
71  a->dev = attachment->dev;
72  INIT_LIST_HEAD(>list);
73  a->mapped = false;
74  
75  attachment->priv = a;
76  
77  mutex_lock(>lock);
78  list_add(>list, >attachments);
79  mutex_unlock(>lock);
80  
81  return 0;
82  }
83  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


Re: [PATCH] dma-buf: cma_heap: Check for device max segment size when attaching

2022-08-22 Thread kernel test robot
Hi Andrew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.0-rc2 next-20220822]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Andrew-Davis/dma-buf-cma_heap-Check-for-device-max-segment-size-when-attaching/20220823-073240
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
config: s390-allyesconfig 
(https://download.01.org/0day-ci/archive/20220823/202208230840.nplcmvvn-...@intel.com/config)
compiler: s390-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/intel-lab-lkp/linux/commit/f390cef50ba6681ea767283e413cb8e9f8f2b426
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Andrew-Davis/dma-buf-cma_heap-Check-for-device-max-segment-size-when-attaching/20220823-073240
git checkout f390cef50ba6681ea767283e413cb8e9f8f2b426
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 
O=build_dir ARCH=s390 SHELL=/bin/bash drivers/dma-buf/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

   drivers/dma-buf/heaps/cma_heap.c: In function 'cma_heap_attach':
>> drivers/dma-buf/heaps/cma_heap.c:61:9: warning: ISO C90 forbids mixed 
>> declarations and code [-Wdeclaration-after-statement]
  61 | size_t max_segment = dma_get_max_seg_size(attachment->dev);
 | ^~


vim +61 drivers/dma-buf/heaps/cma_heap.c

49  
50  static int cma_heap_attach(struct dma_buf *dmabuf,
51 struct dma_buf_attachment *attachment)
52  {
53  struct cma_heap_buffer *buffer = dmabuf->priv;
54  struct dma_heap_attachment *a;
55  int ret;
56  
57  a = kzalloc(sizeof(*a), GFP_KERNEL);
58  if (!a)
59  return -ENOMEM;
60  
  > 61  size_t max_segment = dma_get_max_seg_size(attachment->dev);
62  ret = sg_alloc_table_from_pages_segment(>table, 
buffer->pages,
63  buffer->pagecount, 0,
64  buffer->pagecount << 
PAGE_SHIFT,
65  max_segment, 
GFP_KERNEL);
66  if (ret) {
67  kfree(a);
68  return ret;
69  }
70  
71  a->dev = attachment->dev;
72  INIT_LIST_HEAD(>list);
73  a->mapped = false;
74  
75  attachment->priv = a;
76  
77  mutex_lock(>lock);
78  list_add(>list, >attachments);
79  mutex_unlock(>lock);
80  
81  return 0;
82  }
83  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


[PATCH] dma-buf: cma_heap: Check for device max segment size when attaching

2022-08-22 Thread Andrew Davis
Although there is usually not such a limitation (and when there is it is
often only because the driver forgot to change the super small default),
it is still correct here to break scatterlist element into chunks of
dma_max_mapping_size().

This might cause some issues for users with misbehaving drivers. If
bisecting has landed you on this commit, make sure your drivers both set
dma_set_max_seg_size() and are checking for contiguousness correctly.

Signed-off-by: Andrew Davis 
---
 drivers/dma-buf/heaps/cma_heap.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 28fb04eccdd0..cacc84cb5ece 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -58,10 +58,11 @@ static int cma_heap_attach(struct dma_buf *dmabuf,
if (!a)
return -ENOMEM;
 
-   ret = sg_alloc_table_from_pages(>table, buffer->pages,
-   buffer->pagecount, 0,
-   buffer->pagecount << PAGE_SHIFT,
-   GFP_KERNEL);
+   size_t max_segment = dma_get_max_seg_size(attachment->dev);
+   ret = sg_alloc_table_from_pages_segment(>table, buffer->pages,
+   buffer->pagecount, 0,
+   buffer->pagecount << PAGE_SHIFT,
+   max_segment, GFP_KERNEL);
if (ret) {
kfree(a);
return ret;
-- 
2.36.1