tree:   https://github.com/jgunthorpe/linux vfio_iommufd
head:   a249441ba6fd9d658f4a1b568453e3a742d12686
commit: e44299750e287f3d64d207a5af7abb021634a31b [9/11] vfio: Make 
vfio_container optionally compiled
config: openrisc-randconfig-m041-20221024
compiler: or1k-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
drivers/vfio/vfio_main.c:1690 vfio_file_enforced_coherent() warn: assigning 
(-95) to unsigned variable 'ret'

Old smatch warnings:
drivers/vfio/vfio_main.c:1907 vfio_pin_pages() warn: impossible condition 
'(iova > (~0)) => (0-u32max > u32max)'
drivers/vfio/vfio_main.c:1974 vfio_dma_rw() warn: impossible condition '(iova > 
(~0)) => (0-u32max > u32max)'

vim +/ret +1690 drivers/vfio/vfio_main.c

a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1671  /**
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1672   * 
vfio_file_enforced_coherent - True if the DMA associated with the VFIO file
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1673   *    
    is always CPU cache coherent

This comment sort of feels like returning false on error is the correct
thing but in the rest of the code it seems like returning true on error
is correct.

a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1674   * 
@file: VFIO group file
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1675   *
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1676   * 
Enforced coherency means that the IOMMU ignores things like the PCIe no-snoop
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1677   * 
bit in DMA transactions. A return of false indicates that the user has
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1678   * 
rights to access additional instructions such as wbinvd on x86.
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1679   */
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1680  bool 
vfio_file_enforced_coherent(struct file *file)
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1681  {
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1682        
struct vfio_group *group = file->private_data;
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1683        
bool ret;
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1684  
b1b8132a651cf6 drivers/vfio/vfio_main.c Alex Williamson 2022-10-07  1685        
if (!vfio_file_is_group(file))
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1686        
        return true;
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1687  
c82e81ab256955 drivers/vfio/vfio_main.c Jason Gunthorpe 2022-09-29  1688        
mutex_lock(&group->group_lock);
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1689        
if (group->container) {
1408640d578887 drivers/vfio/vfio_main.c Jason Gunthorpe 2022-09-22 @1690        
        ret = vfio_container_ioctl_check_extension(group->container,
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1691        
                                                   VFIO_DMA_CC_IOMMU);

But this returns true if vfio_container_ioctl_check_extension() returns
a negative error code.  (I haven't looked at the git branch and I
suspect it's different from linux-next)

14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1692        
} else if (group->iommufd) {
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1693        
        struct vfio_device *device;
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1694  
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1695        
        /*
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1696        
         * FIXME this is in the wrong order for KVM, the KVM will be set
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1697        
         * after the group is opened and container set, but before the
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1698        
         * device fds are created, so it will not see the iommufd bind
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1699        
         * at this point.
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1700        
         */
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1701        
        mutex_lock(&group->device_lock);
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1702        
        ret = true;
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1703        
        list_for_each_entry(device, &group->device_list, group_next) {
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1704        
                if (!vfio_device_try_get_registration(device))
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1705        
                        continue;
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1706        
                ret &= vfio_iommufd_enforced_coherent(device);
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1707        
                vfio_device_put_registration(device);
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1708        
        }
14b6d451b4bcfb drivers/vfio/vfio_main.c Jason Gunthorpe 2022-08-08  1709        
        mutex_unlock(&group->device_lock);
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1710        
} else {
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1711        
        /*
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1712        
         * Since the coherency state is determined only once a container
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1713        
         * is attached the user must do so before they can prove they
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1714        
         * have permission.
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1715        
         */
e0e29bdb594adf drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-16  1716        
        ret = true;
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1717        
}
c82e81ab256955 drivers/vfio/vfio_main.c Jason Gunthorpe 2022-09-29  1718        
mutex_unlock(&group->group_lock);
a905ad043f32bb drivers/vfio/vfio.c      Jason Gunthorpe 2022-05-04  1719        
return ret;
c0560f51cf7747 drivers/vfio/vfio.c      Yan Zhao        2020-03-24  1720  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp
_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to