Hi Claire,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.11-rc6 next-20210125]
[cannot apply to swiotlb/linux-next robh/for-next xen-tip/linux-next]
[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]
url:
https://github.com/0day-ci/linux/commits/Claire-Chang/Restricted-DMA/2021...
base:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
61556703b610a104de324e4f061dc6cf7b218b46
config: x86_64-randconfig-m001-20210209 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
smatch warnings:
kernel/dma/swiotlb.c:681 swiotlb_tbl_map_single() warn: unsigned 'index' is never
less than zero.
vim +/index +681 kernel/dma/swiotlb.c
659
660 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr,
661 size_t mapping_size, size_t alloc_size,
662 enum dma_data_direction dir,
663 unsigned long attrs)
664 {
665 struct swiotlb *swiotlb = get_swiotlb(hwdev);
666 dma_addr_t tbl_dma_addr = phys_to_dma_unencrypted(hwdev, swiotlb->start);
667 phys_addr_t tlb_addr;
668 unsigned int nslots, index;
669 int i;
670
671 if (mem_encrypt_active())
672 pr_warn_once("Memory encryption is active and system is using DMA bounce
buffers\n");
673
674 if (mapping_size > alloc_size) {
675 dev_warn_once(hwdev, "Invalid sizes (mapping: %zd bytes, alloc: %zd
bytes)",
676 mapping_size, alloc_size);
677 return (phys_addr_t)DMA_MAPPING_ERROR;
678 }
679
680 index = swiotlb_tbl_find_free_region(hwdev, tbl_dma_addr, alloc_size, attrs);
681 if (index < 0)
682 return
(phys_addr_t)DMA_MAPPING_ERROR;
683
684 tlb_addr = swiotlb->start + (index << IO_TLB_SHIFT);
685
686 /*
687 * Save away the mapping from the original address to the DMA address.
688 * This is needed when we sync the memory. Then we sync the buffer if
689 * needed.
690 */
691 nslots = ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
692 for (i = 0; i < nslots; i++)
693 swiotlb->orig_addr[index + i] = orig_addr + (i << IO_TLB_SHIFT);
694 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) &&
695 (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
696 swiotlb_bounce(orig_addr, tlb_addr, mapping_size, DMA_TO_DEVICE);
697
698 return tlb_addr;
699 }
700
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org