Hi Christian,
I love your patch! Yet something to improve:
[auto build test ERROR on v6.1-rc8] [also build test ERROR on linus/master] [cannot apply to drm-misc/drm-misc-next next-20221206] [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/Christian-K-nig/dma-buf-fix-d... patch link: https://lore.kernel.org/r/20221206151207.8801-1-christian.koenig%40amd.com patch subject: [PATCH] dma-buf: fix dma_buf_export init order config: s390-randconfig-r044-20221206 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036) 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 # install s390 cross compiling tool for clang build # apt-get install binutils-s390x-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/aa1f28d40a4dc78408327baefb83ee... git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Christian-K-nig/dma-buf-fix-dma_buf_export-init-order/20221206-231311 git checkout aa1f28d40a4dc78408327baefb83ee8fd34b6ef9 # 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=s390 SHELL=/bin/bash drivers/dma-buf/
If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
In file included from drivers/dma-buf/dma-buf.c:16: In file included from include/linux/dma-buf.h:16: In file included from include/linux/iosys-map.h:10: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:75: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x)) ^ include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16' #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) ^ In file included from drivers/dma-buf/dma-buf.c:16: In file included from include/linux/dma-buf.h:16: In file included from include/linux/iosys-map.h:10: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:75: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x)) ^ include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32' #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x)) ^ In file included from drivers/dma-buf/dma-buf.c:16: In file included from include/linux/dma-buf.h:16: In file included from include/linux/iosys-map.h:10: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:75: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^
drivers/dma-buf/dma-buf.c:633:25: error: incompatible integer to pointer conversion passing 'const size_t' (aka 'const unsigned long') to parameter of type 'struct dma_buf *' [-Wint-conversion]
file = dma_buf_getfile(exp_info->size, exp_info->flags); ^~~~~~~~~~~~~~ drivers/dma-buf/dma-buf.c:526:53: note: passing argument to parameter 'dmabuf' here static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags) ^ 12 warnings and 1 error generated.
vim +633 drivers/dma-buf/dma-buf.c
559 560 /** 561 * DOC: dma buf device access 562 * 563 * For device DMA access to a shared DMA buffer the usual sequence of operations 564 * is fairly simple: 565 * 566 * 1. The exporter defines his exporter instance using 567 * DEFINE_DMA_BUF_EXPORT_INFO() and calls dma_buf_export() to wrap a private 568 * buffer object into a &dma_buf. It then exports that &dma_buf to userspace 569 * as a file descriptor by calling dma_buf_fd(). 570 * 571 * 2. Userspace passes this file-descriptors to all drivers it wants this buffer 572 * to share with: First the file descriptor is converted to a &dma_buf using 573 * dma_buf_get(). Then the buffer is attached to the device using 574 * dma_buf_attach(). 575 * 576 * Up to this stage the exporter is still free to migrate or reallocate the 577 * backing storage. 578 * 579 * 3. Once the buffer is attached to all devices userspace can initiate DMA 580 * access to the shared buffer. In the kernel this is done by calling 581 * dma_buf_map_attachment() and dma_buf_unmap_attachment(). 582 * 583 * 4. Once a driver is done with a shared buffer it needs to call 584 * dma_buf_detach() (after cleaning up any mappings) and then release the 585 * reference acquired with dma_buf_get() by calling dma_buf_put(). 586 * 587 * For the detailed semantics exporters are expected to implement see 588 * &dma_buf_ops. 589 */ 590 591 /** 592 * dma_buf_export - Creates a new dma_buf, and associates an anon file 593 * with this buffer, so it can be exported. 594 * Also connect the allocator specific data and ops to the buffer. 595 * Additionally, provide a name string for exporter; useful in debugging. 596 * 597 * @exp_info: [in] holds all the export related information provided 598 * by the exporter. see &struct dma_buf_export_info 599 * for further details. 600 * 601 * Returns, on success, a newly created struct dma_buf object, which wraps the 602 * supplied private data and operations for struct dma_buf_ops. On either 603 * missing ops, or error in allocating struct dma_buf, will return negative 604 * error. 605 * 606 * For most cases the easiest way to create @exp_info is through the 607 * %DEFINE_DMA_BUF_EXPORT_INFO macro. 608 */ 609 struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) 610 { 611 struct dma_buf *dmabuf; 612 struct dma_resv *resv = exp_info->resv; 613 struct file *file; 614 size_t alloc_size = sizeof(struct dma_buf); 615 int ret; 616 617 if (WARN_ON(!exp_info->priv || !exp_info->ops 618 || !exp_info->ops->map_dma_buf 619 || !exp_info->ops->unmap_dma_buf 620 || !exp_info->ops->release)) 621 return ERR_PTR(-EINVAL); 622 623 if (WARN_ON(exp_info->ops->cache_sgt_mapping && 624 (exp_info->ops->pin || exp_info->ops->unpin))) 625 return ERR_PTR(-EINVAL); 626 627 if (WARN_ON(!exp_info->ops->pin != !exp_info->ops->unpin)) 628 return ERR_PTR(-EINVAL); 629 630 if (!try_module_get(exp_info->owner)) 631 return ERR_PTR(-ENOENT); 632
633 file = dma_buf_getfile(exp_info->size, exp_info->flags);
634 if (IS_ERR(file)) { 635 ret = PTR_ERR(file); 636 goto err_module; 637 } 638 639 if (!exp_info->resv) 640 alloc_size += sizeof(struct dma_resv); 641 else 642 /* prevent &dma_buf[1] == dma_buf->resv */ 643 alloc_size += 1; 644 dmabuf = kzalloc(alloc_size, GFP_KERNEL); 645 if (!dmabuf) { 646 ret = -ENOMEM; 647 goto err_file; 648 } 649 650 dmabuf->priv = exp_info->priv; 651 dmabuf->ops = exp_info->ops; 652 dmabuf->size = exp_info->size; 653 dmabuf->exp_name = exp_info->exp_name; 654 dmabuf->owner = exp_info->owner; 655 spin_lock_init(&dmabuf->name_lock); 656 init_waitqueue_head(&dmabuf->poll); 657 dmabuf->cb_in.poll = dmabuf->cb_out.poll = &dmabuf->poll; 658 dmabuf->cb_in.active = dmabuf->cb_out.active = 0; 659 mutex_init(&dmabuf->lock); 660 INIT_LIST_HEAD(&dmabuf->attachments); 661 662 if (!resv) { 663 dmabuf->resv = (struct dma_resv *)&dmabuf[1]; 664 dma_resv_init(dmabuf->resv); 665 } else { 666 dmabuf->resv = resv; 667 } 668 669 ret = dma_buf_stats_setup(dmabuf, file); 670 if (ret) 671 goto err_dmabuf; 672 673 file->private_data = dmabuf; 674 file->f_path.dentry->d_fsdata = dmabuf; 675 dmabuf->file = file; 676 677 mutex_lock(&db_list.lock); 678 list_add(&dmabuf->list_node, &db_list.head); 679 mutex_unlock(&db_list.lock); 680 681 return dmabuf; 682 683 err_dmabuf: 684 if (!resv) 685 dma_resv_fini(dmabuf->resv); 686 kfree(dmabuf); 687 err_file: 688 fput(file); 689 err_module: 690 module_put(exp_info->owner); 691 return ERR_PTR(ret); 692 } 693 EXPORT_SYMBOL_NS_GPL(dma_buf_export, DMA_BUF); 694