All of lore.kernel.org
 help / color / mirror / Atom feed
* [jgunthorpe:vfio_iommufd 9/11] drivers/vfio/vfio_main.c:1690 vfio_file_enforced_coherent() warn: assigning (-95) to unsigned variable 'ret'
@ 2022-10-25 14:21 Dan Carpenter
  2022-10-25 16:22 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-10-25 14:21 UTC (permalink / raw)
  To: kbuild, Jason Gunthorpe; +Cc: lkp, kbuild-all, linux-kernel

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 <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

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

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

* Re: [jgunthorpe:vfio_iommufd 9/11] drivers/vfio/vfio_main.c:1690 vfio_file_enforced_coherent() warn: assigning (-95) to unsigned variable 'ret'
  2022-10-25 14:21 [jgunthorpe:vfio_iommufd 9/11] drivers/vfio/vfio_main.c:1690 vfio_file_enforced_coherent() warn: assigning (-95) to unsigned variable 'ret' Dan Carpenter
@ 2022-10-25 16:22 ` Jason Gunthorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2022-10-25 16:22 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: kbuild, lkp, kbuild-all, linux-kernel

On Tue, Oct 25, 2022 at 05:21:36PM +0300, Dan Carpenter wrote:
> 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

Dan! Thank you for looking at this branch, I'm going to be getting it
in linux-next very soon, so I will fix whatever your tools will spot!
Let me know


> 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.

Oddly, true is the correct result. "false" means you have proven you
are worthy and that cannot happen on error cases.

> 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)

Yes, I should not take this shortcut, we would be better to explicitly
return false on error return.

But good news, I just deleted this code, so all fixed :)

Jason

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

end of thread, other threads:[~2022-10-25 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25 14:21 [jgunthorpe:vfio_iommufd 9/11] drivers/vfio/vfio_main.c:1690 vfio_file_enforced_coherent() warn: assigning (-95) to unsigned variable 'ret' Dan Carpenter
2022-10-25 16:22 ` Jason Gunthorpe

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.