mbox series

[v3,00/37] vfio: Adopt iommufd

Message ID 20231026103104.1686921-1-zhenzhong.duan@intel.com (mailing list archive)
Headers show
Series vfio: Adopt iommufd | expand

Message

Duan, Zhenzhong Oct. 26, 2023, 10:30 a.m. UTC
Hi,

Thanks all for giving guides and comments on previous series, here is
the v3 of pure iommufd support part.

Based on Cédric's suggestion, this series includes an effort to remove
spapr code from container.c, now all spapr functions are moved to spapr.c
or spapr_pci_vfio.c, but there are still a few trival check on
VFIO_SPAPR_TCE_*_IOMMU which I am not sure if deserved to introduce many
callbacks and duplicate code just to remove them. Some functions are moved
to spapr.c instead of spapr_pci_vfio.c to avoid compile issue because
spapr_pci_vfio.c is arch specific, or else we need to introduce stub
functions to those spapr functions moved.


PATCH 1-5: Move spapr functions to spapr*.c
PATCH 6-18: Abstract out base container
PATCH 19-22: Introduce sparpr container and its specific interface
PATCH 23: Add --enable/--disable-iommufd config support
PATCH 24: Introduce iommufd object
PATCH 25-29: add IOMMUFD container and cdev support
PATCH 30-37: fd passing for IOMMUFD object and cdev


We have done wide test with different combinations, e.g:
- PCI device were tested
- FD passing and hot reset with some trick.
- device hotplug test with legacy and iommufd backends
- with or without vIOMMU for legacy and iommufd backends
- divices linked to different iommufds
- VFIO migration with a E800 net card(no dirty sync support) passthrough
- platform, ccw and ap were only compile-tested due to environment limit


Given some iommufd kernel limitations, the iommufd backend is
not yet fully on par with the legacy backend w.r.t. features like:
- p2p mappings (you will see related error traces)
- dirty page sync
- and etc.


qemu code: https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_cdev_v3
Based on vfio-next, commit id: fd0e1c8bc1

--------------------------------------------------------------------------

Below are some background and graph about the design:

With the introduction of iommufd, the Linux kernel provides a generic
interface for userspace drivers to propagate their DMA mappings to kernel
for assigned devices. This series does the porting of the VFIO devices
onto the /dev/iommu uapi and let it coexist with the legacy implementation.

At QEMU level, interactions with the /dev/iommu are abstracted by a new
iommufd object (compiled in with the CONFIG_IOMMUFD option).

Any QEMU device (e.g. vfio device) wishing to use /dev/iommu must be
linked with an iommufd object. In this series, the vfio-pci device is
granted with such capability (other VFIO devices are not yet ready):

It gets a new optional parameter named iommufd which allows to pass
an iommufd object:

    -object iommufd,id=iommufd0
    -device vfio-pci,host=0000:02:00.0,iommufd=iommufd0

Note the /dev/iommu and vfio cdev can be externally opened by a
management layer. In such a case the fd is passed:

    -object iommufd,id=iommufd0,fd=22
    -device vfio-pci,iommufd=iommufd0,fd=23

If the fd parameter is not passed, the fd is opened by QEMU.
See https://www.mail-archive.com/qemu-devel@nongnu.org/msg937155.html
for detailed discuss on this requirement.

If no iommufd option is passed to the vfio-pci device, iommufd is not
used and the end-user gets the behavior based on the legacy vfio iommu
interfaces:

    -device vfio-pci,host=0000:02:00.0

While the legacy kernel interface is group-centric, the new iommufd
interface is device-centric, relying on device fd and iommufd.

To support both interfaces in the QEMU VFIO device we reworked the vfio
container abstraction so that the generic VFIO code can use either
backend.

The VFIOContainer object becomes a base object derived into
a) the legacy VFIO container and
b) the new iommufd based container.

The base object implements generic code such as code related to
memory_listener and address space management whereas the derived
objects implement callbacks specific to either BE, legacy and
iommufd. Indeed each backend has its own way to setup secure context
and dma management interface. The below diagram shows how it looks
like with both BEs.

                    VFIO                           AddressSpace/Memory
    +-------+  +----------+  +-----+  +-----+
    |  pci  |  | platform |  |  ap |  | ccw |
    +---+---+  +----+-----+  +--+--+  +--+--+     +----------------------+
        |           |           |        |        |   AddressSpace       |
        |           |           |        |        +------------+---------+
    +---V-----------V-----------V--------V----+               /
    |           VFIOAddressSpace              | <------------+
    |                  |                      |  MemoryListener
    |          VFIOContainer list             |
    +-------+----------------------------+----+
            |                            |
            |                            |
    +-------V------+            +--------V----------+
    |   iommufd    |            |    vfio legacy    |
    |  container   |            |     container     |
    +-------+------+            +--------+----------+
            |                            |
            | /dev/iommu                 | /dev/vfio/vfio
            | /dev/vfio/devices/vfioX    | /dev/vfio/$group_id
Userspace   |                            |
============+============================+===========================
Kernel      |  device fd                 |
            +---------------+            | group/container fd
            | (BIND_IOMMUFD |            | (SET_CONTAINER/SET_IOMMU)
            |  ATTACH_IOAS) |            | device fd
            |               |            |
            |       +-------V------------V-----------------+
    iommufd |       |                vfio                  |
(map/unmap  |       +---------+--------------------+-------+
ioas_copy)  |                 |                    | map/unmap
            |                 |                    |
     +------V------+    +-----V------+      +------V--------+
     | iommfd core |    |  device    |      |  vfio iommu   |
     +-------------+    +------------+      +---------------+

[Secure Context setup]
- iommufd BE: uses device fd and iommufd to setup secure context
              (bind_iommufd, attach_ioas)
- vfio legacy BE: uses group fd and container fd to setup secure context
                  (set_container, set_iommu)
[Device access]
- iommufd BE: device fd is opened through /dev/vfio/devices/vfioX
- vfio legacy BE: device fd is retrieved from group fd ioctl
[DMA Mapping flow]
1. VFIOAddressSpace receives MemoryRegion add/del via MemoryListener
2. VFIO populates DMA map/unmap via the container BEs
   *) iommufd BE: uses iommufd
   *) vfio legacy BE: uses container fd


Changelog:
v3:
- Rename base container as VFIOContainerBase and legacy container as container (Cédric)
- Drop VFIO_IOMMU_BACKEND_OPS class and use struct instead (Cédric)
- Cleanup container.c by introducing spapr backend and move spapr code out (Cédric)
- Introduce vfio_iommu_spapr_ops (Cédric)
- Add doc of iommufd in qom.json and have iommufd member sorted (Markus)
- patch19 and patch21 are splitted to two parts to facilitate review

v2:
- patch "vfio: Add base container" in v1 is split into patch1-15 per Cédric
- add fd passing to platform/ap/ccw vfio device
- add (uintptr_t) cast in iommufd_backend_map_dma() per Cédric
- rename char_dev.h to chardev_open.h for same naming scheme per Daniel
- add full copyright per Daniel and Jason


Note changelog below are from full IOMMUFD series:

v1:
- Alloc hwpt instead of using auto hwpt
- elaborate iommufd code per Nicolin
- consolidate two patches and drop as.c
- typo error fix and function rename

rfcv4:
- rebase on top of v8.0.3
- Add one patch from Yi which is about vfio device add in kvm
- Remove IOAS_COPY optimization and focus on functions in this patchset
- Fix wrong name issue reported and fix suggested by Matthew
- Fix compilation issue reported and fix sugggsted by Nicolin
- Use query_dirty_bitmap callback to replace get_dirty_bitmap for better
granularity
- Add dev_iter_next() callback to avoid adding so many callback
  at container scope, add VFIODevice.hwpt to support that
- Restore all functions back to common from container whenever possible,
  mainly migration and reset related functions
- Add --enable/disable-iommufd config option, enabled by default in linux
- Remove VFIODevice.hwpt_next as it's redundant with VFIODevice.next
- Adapt new VFIO_DEVICE_PCI_HOT_RESET uAPI for IOMMUFD backed device
- vfio_kvm_device_add/del_group call vfio_kvm_device_add/del_fd to remove
redundant code
- Add FD passing support for vfio device backed by IOMMUFD
- Fix hot unplug resource leak issue in vfio_legacy_detach_device()
- Fix FD leak in vfio_get_devicefd()

rfcv3:
- rebase on top of v7.2.0
- Fix the compilation with CONFIG_IOMMUFD unset by using true classes for
  VFIO backends
- Fix use after free in error path, reported by Alister
- Split common.c in several steps to ease the review

rfcv2:
- remove the first three patches of rfcv1
- add open cdev helper suggested by Jason
- remove the QOMification of the VFIOContainer and simply use standard ops
(David)
- add "-object iommufd" suggested by Alex

Thanks
Zhenzhong

Eric Auger (11):
  vfio/container: Switch to dma_map|unmap API
  vfio/common: Move giommu_list in base container
  vfio/container: Move space field to base container
  vfio/container: Switch to IOMMU BE
    set_dirty_page_tracking/query_dirty_bitmap API
  vfio/container: Convert functions to base container
  vfio/container: Move vrdl_list, pgsizes and dma_max_mappings to base
    container
  vfio/container: Move listener to base container
  vfio/container: Move dirty_pgsizes and max_dirty_bitmap_size to base
    container
  vfio/container: Implement attach/detach_device
  backends/iommufd: Introduce the iommufd object
  vfio/pci: Allow the selection of a given iommu backend

Yi Liu (2):
  util/char_dev: Add open_cdev()
  vfio/iommufd: Implement the iommufd backend

Zhenzhong Duan (24):
  vfio/container: Move IBM EEH related functions into spapr_pci_vfio.c
  vfio/container: Move vfio_container_add/del_section_window into
    spapr.c
  vfio/container: Move spapr specific init/deinit into spapr.c
  vfio/spapr: Make vfio_spapr_create/remove_window static
  vfio/common: Move vfio_host_win_add/del into spapr.c
  vfio: Introduce base object for VFIOContainer and targetted interface
  vfio/container: Introduce a empty VFIOIOMMUOps
  vfio/container: Move per container device list in base container
  vfio/container: Move iova_ranges to base container
  vfio/spapr: Introduce spapr backend and target interface
  vfio/spapr: switch to spapr IOMMU BE add/del_section_window
  vfio/spapr: Move prereg_listener into spapr container
  vfio/spapr: Move hostwin_list into spapr container
  Add iommufd configure option
  vfio/iommufd: Switch to manual hwpt allocation
  vfio/iommufd: Add support for iova_ranges
  vfio/iommufd: Bypass EEH if iommufd backend
  vfio/pci: Extract out a helper vfio_pci_get_pci_hot_reset_info
  vfio/pci: Adapt vfio pci hot reset support with iommufd BE
  vfio/pci: Make vfio cdev pre-openable by passing a file handle
  vfio: Allow the selection of a given iommu backend for platform ap and
    ccw
  vfio/platform: Make vfio cdev pre-openable by passing a file handle
  vfio/ap: Make vfio cdev pre-openable by passing a file handle
  vfio/ccw: Make vfio cdev pre-openable by passing a file handle

 MAINTAINERS                           |  13 +
 meson.build                           |   6 +
 qapi/qom.json                         |  20 +
 include/hw/vfio/vfio-common.h         | 120 ++----
 include/hw/vfio/vfio-container-base.h | 126 ++++++
 include/hw/vfio/vfio-platform.h       |   1 +
 include/hw/vfio/vfio.h                |   7 -
 include/qemu/chardev_open.h           |  16 +
 include/sysemu/iommufd.h              |  46 +++
 backends/iommufd-stub.c               |  59 +++
 backends/iommufd.c                    | 268 ++++++++++++
 hw/ppc/spapr_pci_vfio.c               | 100 ++++-
 hw/vfio/ap.c                          |  38 +-
 hw/vfio/ccw.c                         |  40 +-
 hw/vfio/common.c                      | 323 +++++++--------
 hw/vfio/container-base.c              | 131 ++++++
 hw/vfio/container.c                   | 434 ++++----------------
 hw/vfio/helpers.c                     |  34 +-
 hw/vfio/iommufd.c                     | 562 ++++++++++++++++++++++++++
 hw/vfio/pci.c                         | 253 ++++++++++--
 hw/vfio/platform.c                    |  45 ++-
 hw/vfio/spapr.c                       | 293 ++++++++++++--
 util/chardev_open.c                   |  81 ++++
 backends/Kconfig                      |   4 +
 backends/meson.build                  |   5 +
 backends/trace-events                 |  12 +
 hw/vfio/meson.build                   |   4 +
 hw/vfio/trace-events                  |  17 +-
 meson_options.txt                     |   2 +
 qemu-options.hx                       |  13 +
 scripts/meson-buildoptions.sh         |   3 +
 util/meson.build                      |   1 +
 32 files changed, 2400 insertions(+), 677 deletions(-)
 create mode 100644 include/hw/vfio/vfio-container-base.h
 delete mode 100644 include/hw/vfio/vfio.h
 create mode 100644 include/qemu/chardev_open.h
 create mode 100644 include/sysemu/iommufd.h
 create mode 100644 backends/iommufd-stub.c
 create mode 100644 backends/iommufd.c
 create mode 100644 hw/vfio/container-base.c
 create mode 100644 hw/vfio/iommufd.c
 create mode 100644 util/chardev_open.c

Comments

Markus Armbruster Oct. 26, 2023, 1:27 p.m. UTC | #1
Zhenzhong Duan <zhenzhong.duan@intel.com> writes:

> Hi,
>
> Thanks all for giving guides and comments on previous series, here is
> the v3 of pure iommufd support part.
>
> Based on Cédric's suggestion, this series includes an effort to remove
> spapr code from container.c, now all spapr functions are moved to spapr.c
> or spapr_pci_vfio.c, but there are still a few trival check on
> VFIO_SPAPR_TCE_*_IOMMU which I am not sure if deserved to introduce many
> callbacks and duplicate code just to remove them. Some functions are moved
> to spapr.c instead of spapr_pci_vfio.c to avoid compile issue because
> spapr_pci_vfio.c is arch specific, or else we need to introduce stub
> functions to those spapr functions moved.

[...]

> qemu code: https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_cdev_v3
> Based on vfio-next, commit id: fd0e1c8bc1

I fetched this, and get several compile errors with Clang (but not with
GCC):

    FAILED: libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o 
    clang -m64 -mcx16 -Ilibqemu-x86_64-softmmu.fa.p -I. -I.. -Itarget/i386 -I../target/i386 -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -I/usr/include/PCSC -fcolor-diagnostics -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wmissing-format-attribute -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem linux-headers -iquote . -iquote /work/armbru/qemu -iquote /work/armbru/qemu/include -iquote /work/armbru/qemu/host/include/x86_64 -iquote /work/armbru/qemu/host/include/generic -iquote /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -fsanitize=fuzzer-no-link -fPIE -isystem../linux-headers -isystemlinux-headers -DNEED_CPU_H '-DCONFIG_TARGET="x86_64-softmmu-config-target.h"' '-DCONFIG_DEVICES="x86_64-softmmu-config-devices.h"' -MD -MQ libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o -MF libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o.d -o libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o -c ../hw/vfio/common.c
    ../hw/vfio/common.c:682:40: error: variable 'hostwin' is uninitialized when used here [-Werror,-Wuninitialized]
            hwaddr pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
                                           ^~~~~~~
    ../hw/vfio/common.c:578:31: note: initialize the variable 'hostwin' to silence this warning
        VFIOHostDMAWindow *hostwin;
                                  ^
                                   = NULL
    ../hw/vfio/common.c:785:33: error: variable 'hostwin' is uninitialized when used here [-Werror,-Wuninitialized]
            pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
                                    ^~~~~~~
    ../hw/vfio/common.c:783:35: note: initialize the variable 'hostwin' to silence this warning
            VFIOHostDMAWindow *hostwin;
                                      ^
                                       = NULL
    2 errors generated.
    FAILED: tests/unit/test-resv-mem.p/test-resv-mem.c.o 
    clang -m64 -mcx16 -Itests/unit/test-resv-mem.p -Itests/unit -I../tests/unit -I. -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -fcolor-diagnostics -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wmissing-format-attribute -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem linux-headers -iquote . -iquote /work/armbru/qemu -iquote /work/armbru/qemu/include -iquote /work/armbru/qemu/host/include/x86_64 -iquote /work/armbru/qemu/host/include/generic -iquote /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -fsanitize=fuzzer-no-link -fPIE -MD -MQ tests/unit/test-resv-mem.p/test-resv-mem.c.o -MF tests/unit/test-resv-mem.p/test-resv-mem.c.o.d -o tests/unit/test-resv-mem.p/test-resv-mem.c.o -c ../tests/unit/test-resv-mem.c
    ../tests/unit/test-resv-mem.c:42:9: error: variable 'i' set but not used [-Werror,-Wunused-but-set-variable]
        int i = 0;
            ^
    1 error generated.

Delete @i, please.
Duan, Zhenzhong Oct. 27, 2023, 6:17 a.m. UTC | #2
Hi Markus,

>-----Original Message-----
>From: Markus Armbruster <armbru@redhat.com>
>Sent: Thursday, October 26, 2023 9:27 PM
>Subject: Re: [PATCH v3 00/37] vfio: Adopt iommufd
>
>Zhenzhong Duan <zhenzhong.duan@intel.com> writes:
>
>> Hi,
>>
>> Thanks all for giving guides and comments on previous series, here is
>> the v3 of pure iommufd support part.
>>
>> Based on Cédric's suggestion, this series includes an effort to remove
>> spapr code from container.c, now all spapr functions are moved to spapr.c
>> or spapr_pci_vfio.c, but there are still a few trival check on
>> VFIO_SPAPR_TCE_*_IOMMU which I am not sure if deserved to introduce many
>> callbacks and duplicate code just to remove them. Some functions are moved
>> to spapr.c instead of spapr_pci_vfio.c to avoid compile issue because
>> spapr_pci_vfio.c is arch specific, or else we need to introduce stub
>> functions to those spapr functions moved.
>
>[...]
>
>> qemu code:
>https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_cdev_v3
>> Based on vfio-next, commit id: fd0e1c8bc1
>
>I fetched this, and get several compile errors with Clang (but not with
>GCC):
>
>    FAILED: libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o
>    clang -m64 -mcx16 -Ilibqemu-x86_64-softmmu.fa.p -I. -I.. -Itarget/i386 -
>I../target/i386 -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -
>I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -
>I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -
>I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -
>I/usr/include/PCSC -fcolor-diagnostics -Wall -Winvalid-pch -Werror -std=gnu11 -
>O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -
>Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wtype-limits -
>Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body
>-Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wmissing-format-
>attribute -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-
>negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-
>tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-
>at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>/work/armbru/qemu/include -iquote /work/armbru/qemu/host/include/x86_64 -
>iquote /work/armbru/qemu/host/include/generic -iquote
>/work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>fsanitize=fuzzer-no-link -fPIE -isystem../linux-headers -isystemlinux-headers -
>DNEED_CPU_H '-DCONFIG_TARGET="x86_64-softmmu-config-target.h"' '-
>DCONFIG_DEVICES="x86_64-softmmu-config-devices.h"' -MD -MQ libqemu-
>x86_64-softmmu.fa.p/hw_vfio_common.c.o -MF libqemu-x86_64-
>softmmu.fa.p/hw_vfio_common.c.o.d -o libqemu-x86_64-
>softmmu.fa.p/hw_vfio_common.c.o -c ../hw/vfio/common.c
>    ../hw/vfio/common.c:682:40: error: variable 'hostwin' is uninitialized when
>used here [-Werror,-Wuninitialized]
>            hwaddr pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>                                           ^~~~~~~
>    ../hw/vfio/common.c:578:31: note: initialize the variable 'hostwin' to silence
>this warning
>        VFIOHostDMAWindow *hostwin;
>                                  ^
>                                   = NULL
>    ../hw/vfio/common.c:785:33: error: variable 'hostwin' is uninitialized when
>used here [-Werror,-Wuninitialized]
>            pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>                                    ^~~~~~~
>    ../hw/vfio/common.c:783:35: note: initialize the variable 'hostwin' to silence
>this warning
>            VFIOHostDMAWindow *hostwin;
>                                      ^
>                                       = NULL
>    2 errors generated.
>    FAILED: tests/unit/test-resv-mem.p/test-resv-mem.c.o
>    clang -m64 -mcx16 -Itests/unit/test-resv-mem.p -Itests/unit -I../tests/unit -I. -
>Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -
>I/usr/include/sysprof-4 -fcolor-diagnostics -Wall -Winvalid-pch -Werror -
>std=gnu11 -O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-
>prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -
>Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -
>Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -
>Wmissing-format-attribute -Wno-initializer-overrides -Wno-missing-include-dirs -
>Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-
>tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-
>at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>/work/armbru/qemu/include -iquote /work/armbru/qemu/host/include/x86_64 -
>iquote /work/armbru/qemu/host/include/generic -iquote
>/work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>fsanitize=fuzzer-no-link -fPIE -MD -MQ tests/unit/test-resv-mem.p/test-resv-
>mem.c.o -MF tests/unit/test-resv-mem.p/test-resv-mem.c.o.d -o tests/unit/test-
>resv-mem.p/test-resv-mem.c.o -c ../tests/unit/test-resv-mem.c
>    ../tests/unit/test-resv-mem.c:42:9: error: variable 'i' set but not used [-
>Werror,-Wunused-but-set-variable]
>        int i = 0;
>            ^
>    1 error generated.
>
>Delete @i, please.

Thanks for your report, I'll fix it and build with both compilers next time.
About second error, I'll send a separate patch as it's unrelated to this series.

BRs.
Zhenzhong
Cédric Le Goater Oct. 27, 2023, 7:45 a.m. UTC | #3
On 10/27/23 08:17, Duan, Zhenzhong wrote:
> Hi Markus,
> 
>> -----Original Message-----
>> From: Markus Armbruster <armbru@redhat.com>
>> Sent: Thursday, October 26, 2023 9:27 PM
>> Subject: Re: [PATCH v3 00/37] vfio: Adopt iommufd
>>
>> Zhenzhong Duan <zhenzhong.duan@intel.com> writes:
>>
>>> Hi,
>>>
>>> Thanks all for giving guides and comments on previous series, here is
>>> the v3 of pure iommufd support part.
>>>
>>> Based on Cédric's suggestion, this series includes an effort to remove
>>> spapr code from container.c, now all spapr functions are moved to spapr.c
>>> or spapr_pci_vfio.c, but there are still a few trival check on
>>> VFIO_SPAPR_TCE_*_IOMMU which I am not sure if deserved to introduce many
>>> callbacks and duplicate code just to remove them. Some functions are moved
>>> to spapr.c instead of spapr_pci_vfio.c to avoid compile issue because
>>> spapr_pci_vfio.c is arch specific, or else we need to introduce stub
>>> functions to those spapr functions moved.
>>
>> [...]
>>
>>> qemu code:
>> https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_cdev_v3
>>> Based on vfio-next, commit id: fd0e1c8bc1
>>
>> I fetched this, and get several compile errors with Clang (but not with
>> GCC):
>>
>>     FAILED: libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o
>>     clang -m64 -mcx16 -Ilibqemu-x86_64-softmmu.fa.p -I. -I.. -Itarget/i386 -
>> I../target/i386 -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -
>> I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -
>> I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -
>> I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -
>> I/usr/include/PCSC -fcolor-diagnostics -Wall -Winvalid-pch -Werror -std=gnu11 -
>> O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-prototypes -
>> Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wtype-limits -
>> Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body
>> -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wmissing-format-
>> attribute -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-
>> negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-
>> tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-
>> at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>> linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>> /work/armbru/qemu/include -iquote /work/armbru/qemu/host/include/x86_64 -
>> iquote /work/armbru/qemu/host/include/generic -iquote
>> /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>> D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>> common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>> fsanitize=fuzzer-no-link -fPIE -isystem../linux-headers -isystemlinux-headers -
>> DNEED_CPU_H '-DCONFIG_TARGET="x86_64-softmmu-config-target.h"' '-
>> DCONFIG_DEVICES="x86_64-softmmu-config-devices.h"' -MD -MQ libqemu-
>> x86_64-softmmu.fa.p/hw_vfio_common.c.o -MF libqemu-x86_64-
>> softmmu.fa.p/hw_vfio_common.c.o.d -o libqemu-x86_64-
>> softmmu.fa.p/hw_vfio_common.c.o -c ../hw/vfio/common.c
>>     ../hw/vfio/common.c:682:40: error: variable 'hostwin' is uninitialized when
>> used here [-Werror,-Wuninitialized]
>>             hwaddr pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>>                                            ^~~~~~~
>>     ../hw/vfio/common.c:578:31: note: initialize the variable 'hostwin' to silence
>> this warning
>>         VFIOHostDMAWindow *hostwin;
>>                                   ^
>>                                    = NULL
>>     ../hw/vfio/common.c:785:33: error: variable 'hostwin' is uninitialized when
>> used here [-Werror,-Wuninitialized]
>>             pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>>                                     ^~~~~~~
>>     ../hw/vfio/common.c:783:35: note: initialize the variable 'hostwin' to silence
>> this warning
>>             VFIOHostDMAWindow *hostwin;
>>                                       ^
>>                                        = NULL
>>     2 errors generated.
>>     FAILED: tests/unit/test-resv-mem.p/test-resv-mem.c.o
>>     clang -m64 -mcx16 -Itests/unit/test-resv-mem.p -Itests/unit -I../tests/unit -I. -
>> Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -
>> I/usr/include/sysprof-4 -fcolor-diagnostics -Wall -Winvalid-pch -Werror -
>> std=gnu11 -O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-
>> prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -
>> Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -
>> Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -
>> Wmissing-format-attribute -Wno-initializer-overrides -Wno-missing-include-dirs -
>> Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-
>> tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-not-
>> at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>> linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>> /work/armbru/qemu/include -iquote /work/armbru/qemu/host/include/x86_64 -
>> iquote /work/armbru/qemu/host/include/generic -iquote
>> /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>> D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>> common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>> fsanitize=fuzzer-no-link -fPIE -MD -MQ tests/unit/test-resv-mem.p/test-resv-
>> mem.c.o -MF tests/unit/test-resv-mem.p/test-resv-mem.c.o.d -o tests/unit/test-
>> resv-mem.p/test-resv-mem.c.o -c ../tests/unit/test-resv-mem.c
>>     ../tests/unit/test-resv-mem.c:42:9: error: variable 'i' set but not used [-
>> Werror,-Wunused-but-set-variable]
>>         int i = 0;
>>             ^
>>     1 error generated.
>>
>> Delete @i, please.
> 
> Thanks for your report, I'll fix it and build with both compilers next time.

a compile on a fedora rawhide also reports :

../hw/vfio/iommufd.c: In function ‘vfio_get_info_iova_range’:
../hw/vfio/iommufd.c:370:27: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
   370 |     info->allowed_iovas = (uint64_t)(info + 1);
       |                           ^
../hw/vfio/iommufd.c:377:19: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
   377 |     iova_ranges = (struct iommu_iova_range *)info->allowed_iovas;
       |                   ^
cc1: all warnings being treated as errors


> About second error, I'll send a separate patch as it's unrelated to this series.


Since this is a big series, I suggest that you take this patch in your build
environment,


diff --git a/meson.build b/meson.build
index 72a57288a026325d5ff753131c037e99f6f35c1a..c946cbef5b29e23475dc4cf345655e0466cbfade 100644
--- a/meson.build
+++ b/meson.build
@@ -462,6 +462,9 @@ warn_flags = [
    '-Wno-tautological-type-limit-compare',
    '-Wno-psabi',
    '-Wno-gnu-variable-sized-type-not-at-end',
+  '-Wshadow=local',
+  '-Wno-error=shadow=local',
+  '-Wno-error=shadow=compatible-local',
  ]
  
  if targetos != 'darwin'


Thanks,

C.
Duan, Zhenzhong Oct. 27, 2023, 8:16 a.m. UTC | #4
Hi Cédric,

>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Sent: Friday, October 27, 2023 3:46 PM
>Subject: Re: [PATCH v3 00/37] vfio: Adopt iommufd
>
>On 10/27/23 08:17, Duan, Zhenzhong wrote:
>> Hi Markus,
>>
>>> -----Original Message-----
>>> From: Markus Armbruster <armbru@redhat.com>
>>> Sent: Thursday, October 26, 2023 9:27 PM
>>> Subject: Re: [PATCH v3 00/37] vfio: Adopt iommufd
>>>
>>> Zhenzhong Duan <zhenzhong.duan@intel.com> writes:
>>>
>>>> Hi,
>>>>
>>>> Thanks all for giving guides and comments on previous series, here is
>>>> the v3 of pure iommufd support part.
>>>>
>>>> Based on Cédric's suggestion, this series includes an effort to remove
>>>> spapr code from container.c, now all spapr functions are moved to spapr.c
>>>> or spapr_pci_vfio.c, but there are still a few trival check on
>>>> VFIO_SPAPR_TCE_*_IOMMU which I am not sure if deserved to introduce
>many
>>>> callbacks and duplicate code just to remove them. Some functions are moved
>>>> to spapr.c instead of spapr_pci_vfio.c to avoid compile issue because
>>>> spapr_pci_vfio.c is arch specific, or else we need to introduce stub
>>>> functions to those spapr functions moved.
>>>
>>> [...]
>>>
>>>> qemu code:
>>> https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_cdev_v3
>>>> Based on vfio-next, commit id: fd0e1c8bc1
>>>
>>> I fetched this, and get several compile errors with Clang (but not with
>>> GCC):
>>>
>>>     FAILED: libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o
>>>     clang -m64 -mcx16 -Ilibqemu-x86_64-softmmu.fa.p -I. -I.. -Itarget/i386 -
>>> I../target/i386 -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -
>>> I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -
>>> I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -
>>> I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -
>>> I/usr/include/PCSC -fcolor-diagnostics -Wall -Winvalid-pch -Werror -
>std=gnu11 -
>>> O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-
>prototypes -
>>> Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wtype-limits -
>>> Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-
>body
>>> -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wmissing-format-
>>> attribute -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-
>>> negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-
>>> tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-
>not-
>>> at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>>> linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>>> /work/armbru/qemu/include -iquote
>/work/armbru/qemu/host/include/x86_64 -
>>> iquote /work/armbru/qemu/host/include/generic -iquote
>>> /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>>> D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>>> common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>>> fsanitize=fuzzer-no-link -fPIE -isystem../linux-headers -isystemlinux-headers -
>>> DNEED_CPU_H '-DCONFIG_TARGET="x86_64-softmmu-config-target.h"' '-
>>> DCONFIG_DEVICES="x86_64-softmmu-config-devices.h"' -MD -MQ libqemu-
>>> x86_64-softmmu.fa.p/hw_vfio_common.c.o -MF libqemu-x86_64-
>>> softmmu.fa.p/hw_vfio_common.c.o.d -o libqemu-x86_64-
>>> softmmu.fa.p/hw_vfio_common.c.o -c ../hw/vfio/common.c
>>>     ../hw/vfio/common.c:682:40: error: variable 'hostwin' is uninitialized when
>>> used here [-Werror,-Wuninitialized]
>>>             hwaddr pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>>>                                            ^~~~~~~
>>>     ../hw/vfio/common.c:578:31: note: initialize the variable 'hostwin' to
>silence
>>> this warning
>>>         VFIOHostDMAWindow *hostwin;
>>>                                   ^
>>>                                    = NULL
>>>     ../hw/vfio/common.c:785:33: error: variable 'hostwin' is uninitialized when
>>> used here [-Werror,-Wuninitialized]
>>>             pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>>>                                     ^~~~~~~
>>>     ../hw/vfio/common.c:783:35: note: initialize the variable 'hostwin' to
>silence
>>> this warning
>>>             VFIOHostDMAWindow *hostwin;
>>>                                       ^
>>>                                        = NULL
>>>     2 errors generated.
>>>     FAILED: tests/unit/test-resv-mem.p/test-resv-mem.c.o
>>>     clang -m64 -mcx16 -Itests/unit/test-resv-mem.p -Itests/unit -I../tests/unit -I.
>-
>>> Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
>-
>>> I/usr/include/sysprof-4 -fcolor-diagnostics -Wall -Winvalid-pch -Werror -
>>> std=gnu11 -O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -
>Wmissing-
>>> prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -
>>> Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-
>qualifiers -
>>> Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -
>>> Wmissing-format-attribute -Wno-initializer-overrides -Wno-missing-include-
>dirs -
>>> Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -
>Wno-
>>> tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-
>not-
>>> at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>>> linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>>> /work/armbru/qemu/include -iquote
>/work/armbru/qemu/host/include/x86_64 -
>>> iquote /work/armbru/qemu/host/include/generic -iquote
>>> /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>>> D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>>> common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>>> fsanitize=fuzzer-no-link -fPIE -MD -MQ tests/unit/test-resv-mem.p/test-resv-
>>> mem.c.o -MF tests/unit/test-resv-mem.p/test-resv-mem.c.o.d -o
>tests/unit/test-
>>> resv-mem.p/test-resv-mem.c.o -c ../tests/unit/test-resv-mem.c
>>>     ../tests/unit/test-resv-mem.c:42:9: error: variable 'i' set but not used [-
>>> Werror,-Wunused-but-set-variable]
>>>         int i = 0;
>>>             ^
>>>     1 error generated.
>>>
>>> Delete @i, please.
>>
>> Thanks for your report, I'll fix it and build with both compilers next time.
>
>a compile on a fedora rawhide also reports :
>
>../hw/vfio/iommufd.c: In function ‘vfio_get_info_iova_range’:
>../hw/vfio/iommufd.c:370:27: error: cast from pointer to integer of different size
>[-Werror=pointer-to-int-cast]
>   370 |     info->allowed_iovas = (uint64_t)(info + 1);
>       |                           ^
>../hw/vfio/iommufd.c:377:19: error: cast to pointer from integer of different size
>[-Werror=int-to-pointer-cast]
>   377 |     iova_ranges = (struct iommu_iova_range *)info->allowed_iovas;
>       |                   ^
>cc1: all warnings being treated as errors

I failed to understand this warning, is your env a 32bit fedora?

>
>
>> About second error, I'll send a separate patch as it's unrelated to this series.
>
>
>Since this is a big series, I suggest that you take this patch in your build
>environment,

Got it, will do, thanks for your suggestions.

BRs.
Zhenzhong

>
>
>diff --git a/meson.build b/meson.build
>index
>72a57288a026325d5ff753131c037e99f6f35c1a..c946cbef5b29e23475dc4cf3456
>55e0466cbfade 100644
>--- a/meson.build
>+++ b/meson.build
>@@ -462,6 +462,9 @@ warn_flags = [
>    '-Wno-tautological-type-limit-compare',
>    '-Wno-psabi',
>    '-Wno-gnu-variable-sized-type-not-at-end',
>+  '-Wshadow=local',
>+  '-Wno-error=shadow=local',
>+  '-Wno-error=shadow=compatible-local',
>  ]
>
>  if targetos != 'darwin'
>
>
>Thanks,
>
>C.
Cédric Le Goater Oct. 27, 2023, 1:43 p.m. UTC | #5
On 10/27/23 10:16, Duan, Zhenzhong wrote:
> Hi Cédric,
> 
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Sent: Friday, October 27, 2023 3:46 PM
>> Subject: Re: [PATCH v3 00/37] vfio: Adopt iommufd
>>
>> On 10/27/23 08:17, Duan, Zhenzhong wrote:
>>> Hi Markus,
>>>
>>>> -----Original Message-----
>>>> From: Markus Armbruster <armbru@redhat.com>
>>>> Sent: Thursday, October 26, 2023 9:27 PM
>>>> Subject: Re: [PATCH v3 00/37] vfio: Adopt iommufd
>>>>
>>>> Zhenzhong Duan <zhenzhong.duan@intel.com> writes:
>>>>
>>>>> Hi,
>>>>>
>>>>> Thanks all for giving guides and comments on previous series, here is
>>>>> the v3 of pure iommufd support part.
>>>>>
>>>>> Based on Cédric's suggestion, this series includes an effort to remove
>>>>> spapr code from container.c, now all spapr functions are moved to spapr.c
>>>>> or spapr_pci_vfio.c, but there are still a few trival check on
>>>>> VFIO_SPAPR_TCE_*_IOMMU which I am not sure if deserved to introduce
>> many
>>>>> callbacks and duplicate code just to remove them. Some functions are moved
>>>>> to spapr.c instead of spapr_pci_vfio.c to avoid compile issue because
>>>>> spapr_pci_vfio.c is arch specific, or else we need to introduce stub
>>>>> functions to those spapr functions moved.
>>>>
>>>> [...]
>>>>
>>>>> qemu code:
>>>> https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_cdev_v3
>>>>> Based on vfio-next, commit id: fd0e1c8bc1
>>>>
>>>> I fetched this, and get several compile errors with Clang (but not with
>>>> GCC):
>>>>
>>>>      FAILED: libqemu-x86_64-softmmu.fa.p/hw_vfio_common.c.o
>>>>      clang -m64 -mcx16 -Ilibqemu-x86_64-softmmu.fa.p -I. -I.. -Itarget/i386 -
>>>> I../target/i386 -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/pixman-1 -
>>>> I/usr/include/capstone -I/usr/include/spice-server -I/usr/include/spice-1 -
>>>> I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -
>>>> I/usr/include/sysprof-4 -I/usr/include/nss3 -I/usr/include/nspr4 -
>>>> I/usr/include/PCSC -fcolor-diagnostics -Wall -Winvalid-pch -Werror -
>> std=gnu11 -
>>>> O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -Wmissing-
>> prototypes -
>>>> Wstrict-prototypes -Wredundant-decls -Wold-style-definition -Wtype-limits -
>>>> Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-
>> body
>>>> -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wmissing-format-
>>>> attribute -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-shift-
>>>> negative-value -Wno-string-plus-int -Wno-typedef-redefinition -Wno-
>>>> tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-
>> not-
>>>> at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>>>> linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>>>> /work/armbru/qemu/include -iquote
>> /work/armbru/qemu/host/include/x86_64 -
>>>> iquote /work/armbru/qemu/host/include/generic -iquote
>>>> /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>>>> D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>>>> common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>>>> fsanitize=fuzzer-no-link -fPIE -isystem../linux-headers -isystemlinux-headers -
>>>> DNEED_CPU_H '-DCONFIG_TARGET="x86_64-softmmu-config-target.h"' '-
>>>> DCONFIG_DEVICES="x86_64-softmmu-config-devices.h"' -MD -MQ libqemu-
>>>> x86_64-softmmu.fa.p/hw_vfio_common.c.o -MF libqemu-x86_64-
>>>> softmmu.fa.p/hw_vfio_common.c.o.d -o libqemu-x86_64-
>>>> softmmu.fa.p/hw_vfio_common.c.o -c ../hw/vfio/common.c
>>>>      ../hw/vfio/common.c:682:40: error: variable 'hostwin' is uninitialized when
>>>> used here [-Werror,-Wuninitialized]
>>>>              hwaddr pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>>>>                                             ^~~~~~~
>>>>      ../hw/vfio/common.c:578:31: note: initialize the variable 'hostwin' to
>> silence
>>>> this warning
>>>>          VFIOHostDMAWindow *hostwin;
>>>>                                    ^
>>>>                                     = NULL
>>>>      ../hw/vfio/common.c:785:33: error: variable 'hostwin' is uninitialized when
>>>> used here [-Werror,-Wuninitialized]
>>>>              pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
>>>>                                      ^~~~~~~
>>>>      ../hw/vfio/common.c:783:35: note: initialize the variable 'hostwin' to
>> silence
>>>> this warning
>>>>              VFIOHostDMAWindow *hostwin;
>>>>                                        ^
>>>>                                         = NULL
>>>>      2 errors generated.
>>>>      FAILED: tests/unit/test-resv-mem.p/test-resv-mem.c.o
>>>>      clang -m64 -mcx16 -Itests/unit/test-resv-mem.p -Itests/unit -I../tests/unit -I.
>> -
>>>> Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
>> -
>>>> I/usr/include/sysprof-4 -fcolor-diagnostics -Wall -Winvalid-pch -Werror -
>>>> std=gnu11 -O2 -g -fstack-protector-strong -Wundef -Wwrite-strings -
>> Wmissing-
>>>> prototypes -Wstrict-prototypes -Wredundant-decls -Wold-style-definition -
>>>> Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-
>> qualifiers -
>>>> Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -
>>>> Wmissing-format-attribute -Wno-initializer-overrides -Wno-missing-include-
>> dirs -
>>>> Wno-shift-negative-value -Wno-string-plus-int -Wno-typedef-redefinition -
>> Wno-
>>>> tautological-type-limit-compare -Wno-psabi -Wno-gnu-variable-sized-type-
>> not-
>>>> at-end -Wthread-safety -isystem /work/armbru/qemu/linux-headers -isystem
>>>> linux-headers -iquote . -iquote /work/armbru/qemu -iquote
>>>> /work/armbru/qemu/include -iquote
>> /work/armbru/qemu/host/include/x86_64 -
>>>> iquote /work/armbru/qemu/host/include/generic -iquote
>>>> /work/armbru/qemu/tcg/i386 -pthread -D_GNU_SOURCE -
>>>> D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-
>>>> common -fwrapv -fsanitize-coverage-allowlist=instrumentation-filter -
>>>> fsanitize=fuzzer-no-link -fPIE -MD -MQ tests/unit/test-resv-mem.p/test-resv-
>>>> mem.c.o -MF tests/unit/test-resv-mem.p/test-resv-mem.c.o.d -o
>> tests/unit/test-
>>>> resv-mem.p/test-resv-mem.c.o -c ../tests/unit/test-resv-mem.c
>>>>      ../tests/unit/test-resv-mem.c:42:9: error: variable 'i' set but not used [-
>>>> Werror,-Wunused-but-set-variable]
>>>>          int i = 0;
>>>>              ^
>>>>      1 error generated.
>>>>
>>>> Delete @i, please.
>>>
>>> Thanks for your report, I'll fix it and build with both compilers next time.
>>
>> a compile on a fedora rawhide also reports :
>>
>> ../hw/vfio/iommufd.c: In function ‘vfio_get_info_iova_range’:
>> ../hw/vfio/iommufd.c:370:27: error: cast from pointer to integer of different size
>> [-Werror=pointer-to-int-cast]
>>    370 |     info->allowed_iovas = (uint64_t)(info + 1);
>>        |                           ^
>> ../hw/vfio/iommufd.c:377:19: error: cast to pointer from integer of different size
>> [-Werror=int-to-pointer-cast]
>>    377 |     iova_ranges = (struct iommu_iova_range *)info->allowed_iovas;
>>        |                   ^
>> cc1: all warnings being treated as errors
> 
> I failed to understand this warning, is your env a 32bit fedora?

it's not a rawhide but a 32bit indeed.

Thanks,

C.


> 
>>
>>
>>> About second error, I'll send a separate patch as it's unrelated to this series.
>>
>>
>> Since this is a big series, I suggest that you take this patch in your build
>> environment,
> 
> Got it, will do, thanks for your suggestions.
> 
> BRs.
> Zhenzhong
> 
>>
>>
>> diff --git a/meson.build b/meson.build
>> index
>> 72a57288a026325d5ff753131c037e99f6f35c1a..c946cbef5b29e23475dc4cf3456
>> 55e0466cbfade 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -462,6 +462,9 @@ warn_flags = [
>>     '-Wno-tautological-type-limit-compare',
>>     '-Wno-psabi',
>>     '-Wno-gnu-variable-sized-type-not-at-end',
>> +  '-Wshadow=local',
>> +  '-Wno-error=shadow=local',
>> +  '-Wno-error=shadow=compatible-local',
>>   ]
>>
>>   if targetos != 'darwin'
>>
>>
>> Thanks,
>>
>> C.
>