[PATCH v2 00/11] VFIO: misc cleanups

Zhenzhong Duan posted 11 patches 1 week, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240507064252.457884-1-zhenzhong.duan@intel.com
Maintainers: Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Tony Krowiak <akrowiak@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Jason Herne <jjherne@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Harsh Prateek Bora <harshpb@linux.ibm.com>
include/hw/vfio/vfio-common.h         |   6 +-
include/hw/vfio/vfio-container-base.h |  18 ++---
include/sysemu/iommufd.h              |   6 +-
backends/iommufd.c                    |  29 +++----
hw/vfio/ap.c                          |   6 +-
hw/vfio/ccw.c                         |   6 +-
hw/vfio/common.c                      |   6 +-
hw/vfio/container-base.c              |   8 +-
hw/vfio/container.c                   |  81 +++++++++----------
hw/vfio/cpr.c                         |   4 +-
hw/vfio/iommufd.c                     | 109 +++++++++++---------------
hw/vfio/pci.c                         |  12 ++-
hw/vfio/platform.c                    |   7 +-
hw/vfio/spapr.c                       |  28 +++----
backends/trace-events                 |   4 +-
15 files changed, 147 insertions(+), 183 deletions(-)
[PATCH v2 00/11] VFIO: misc cleanups
Posted by Zhenzhong Duan 1 week, 5 days ago
Hi

This is a cleanup series to change functions in hw/vfio/ to return bool 
when the error is passed through errp parameter, also some cleanup
with g_autofree.

See discussion at https://lists.gnu.org/archive/html/qemu-devel/2024-04/msg04782.html

This series processed below files:
hw/vfio/container.c
hw/vfio/iommufd.c
hw/vfio/cpr.c
backends/iommufd.c

So above files are clean now, there are still other files need processing
in hw/vfio.

Test done on x86 platform:
vfio device hotplug/unplug with different backend
reboot

Thanks
Zhenzhong

Changelog:
v2:
- split out g_autofree code as a patch (Cédric)
- add processing for more files

Zhenzhong Duan (11):
  vfio/pci: Use g_autofree in vfio_realize
  vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range()
  vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool
  vfio: Make VFIOIOMMUClass::setup() return bool
  vfio: Make VFIOIOMMUClass::add_window() and its wrapper return bool
  vfio/container: Make vfio_connect_container() return bool
  vfio/container: Make vfio_set_iommu() return bool
  vfio/container: Make vfio_get_device() return bool
  vfio/iommufd: Make iommufd_cdev_*() return bool
  vfio/cpr: Make vfio_cpr_register_container() return bool
  backends/iommufd: Make iommufd_backend_*() return bool

 include/hw/vfio/vfio-common.h         |   6 +-
 include/hw/vfio/vfio-container-base.h |  18 ++---
 include/sysemu/iommufd.h              |   6 +-
 backends/iommufd.c                    |  29 +++----
 hw/vfio/ap.c                          |   6 +-
 hw/vfio/ccw.c                         |   6 +-
 hw/vfio/common.c                      |   6 +-
 hw/vfio/container-base.c              |   8 +-
 hw/vfio/container.c                   |  81 +++++++++----------
 hw/vfio/cpr.c                         |   4 +-
 hw/vfio/iommufd.c                     | 109 +++++++++++---------------
 hw/vfio/pci.c                         |  12 ++-
 hw/vfio/platform.c                    |   7 +-
 hw/vfio/spapr.c                       |  28 +++----
 backends/trace-events                 |   4 +-
 15 files changed, 147 insertions(+), 183 deletions(-)

-- 
2.34.1


RE: [PATCH v2 00/11] VFIO: misc cleanups
Posted by Duan, Zhenzhong 5 days, 10 hours ago
Hi All,

When I looked into more functions passing 'Error **',
I see many are in "int testfunc(..., Error **errp)" format. I was a bit confused.

The qapi/error.h suggests:

* - Whenever practical, also return a value that indicates success /
 *   failure.  This can make the error checking more concise, and can
 *   avoid useless error object creation and destruction.  Note that
 *   we still have many functions returning void.  We recommend
 *   • bool-valued functions return true on success / false on failure,
 *   • pointer-valued functions return non-null / null pointer, and
 *   • integer-valued functions return non-negative / negative.

There are some functions like:

int testfunc(..., Error **errp)
{
    If (succeed) {
        return 0;
    } else {
        return -EINVAL;
    }
}

Does testfunc() follow 'integer-valued functions' as above or it should be changed to 'bool-valued functions'?

Is there a clear rule in which case to change 'int testfunc(... Error **errp)' to ' bool testfunc(... Error **errp)'?

Thanks
Zhenzhong

>-----Original Message-----
>From: Duan, Zhenzhong <zhenzhong.duan@intel.com>
><zhenzhong.duan@intel.com>
>Subject: [PATCH v2 00/11] VFIO: misc cleanups
>
>Hi
>
>This is a cleanup series to change functions in hw/vfio/ to return bool
>when the error is passed through errp parameter, also some cleanup
>with g_autofree.
>
>See discussion at https://lists.gnu.org/archive/html/qemu-devel/2024-
>04/msg04782.html
>
>This series processed below files:
>hw/vfio/container.c
>hw/vfio/iommufd.c
>hw/vfio/cpr.c
>backends/iommufd.c
>
>So above files are clean now, there are still other files need processing
>in hw/vfio.
>
>Test done on x86 platform:
>vfio device hotplug/unplug with different backend
>reboot
>
>Thanks
>Zhenzhong
>
>Changelog:
>v2:
>- split out g_autofree code as a patch (Cédric)
>- add processing for more files
>
>Zhenzhong Duan (11):
>  vfio/pci: Use g_autofree in vfio_realize
>  vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range()
>  vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool
>  vfio: Make VFIOIOMMUClass::setup() return bool
>  vfio: Make VFIOIOMMUClass::add_window() and its wrapper return bool
>  vfio/container: Make vfio_connect_container() return bool
>  vfio/container: Make vfio_set_iommu() return bool
>  vfio/container: Make vfio_get_device() return bool
>  vfio/iommufd: Make iommufd_cdev_*() return bool
>  vfio/cpr: Make vfio_cpr_register_container() return bool
>  backends/iommufd: Make iommufd_backend_*() return bool
>
> include/hw/vfio/vfio-common.h         |   6 +-
> include/hw/vfio/vfio-container-base.h |  18 ++---
> include/sysemu/iommufd.h              |   6 +-
> backends/iommufd.c                    |  29 +++----
> hw/vfio/ap.c                          |   6 +-
> hw/vfio/ccw.c                         |   6 +-
> hw/vfio/common.c                      |   6 +-
> hw/vfio/container-base.c              |   8 +-
> hw/vfio/container.c                   |  81 +++++++++----------
> hw/vfio/cpr.c                         |   4 +-
> hw/vfio/iommufd.c                     | 109 +++++++++++---------------
> hw/vfio/pci.c                         |  12 ++-
> hw/vfio/platform.c                    |   7 +-
> hw/vfio/spapr.c                       |  28 +++----
> backends/trace-events                 |   4 +-
> 15 files changed, 147 insertions(+), 183 deletions(-)
>
>--
>2.34.1

Re: [PATCH v2 00/11] VFIO: misc cleanups
Posted by Cédric Le Goater 2 days, 22 hours ago
On 5/7/24 08:42, Zhenzhong Duan wrote:
> Hi
> 
> This is a cleanup series to change functions in hw/vfio/ to return bool
> when the error is passed through errp parameter, also some cleanup
> with g_autofree.
> 
> See discussion at https://lists.gnu.org/archive/html/qemu-devel/2024-04/msg04782.html
> 
> This series processed below files:
> hw/vfio/container.c
> hw/vfio/iommufd.c
> hw/vfio/cpr.c
> backends/iommufd.c
> 
> So above files are clean now, there are still other files need processing
> in hw/vfio.
> 
> Test done on x86 platform:
> vfio device hotplug/unplug with different backend
> reboot
> 
> Thanks
> Zhenzhong
> 
> Changelog:
> v2:
> - split out g_autofree code as a patch (Cédric)
> - add processing for more files
> 
> Zhenzhong Duan (11):
>    vfio/pci: Use g_autofree in vfio_realize
>    vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range()
>    vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool
>    vfio: Make VFIOIOMMUClass::setup() return bool
>    vfio: Make VFIOIOMMUClass::add_window() and its wrapper return bool
>    vfio/container: Make vfio_connect_container() return bool
>    vfio/container: Make vfio_set_iommu() return bool
>    vfio/container: Make vfio_get_device() return bool
>    vfio/iommufd: Make iommufd_cdev_*() return bool
>    vfio/cpr: Make vfio_cpr_register_container() return bool
>    backends/iommufd: Make iommufd_backend_*() return bool


Applied to vfio-next.

Thanks,

C.