[PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes

Michael S. Tsirkin posted 47 patches 2 years, 1 month ago
Failed in applying to current master (apply log)
There is a newer version of this series
docs/pcie_sriov.txt                        | 115 +++++++++++
docs/specs/pci-ids.txt                     |   1 +
configure                                  |   4 +-
hw/i386/intel_iommu_internal.h             |   1 +
include/hw/acpi/acpi-defs.h                |   1 +
include/hw/i386/intel_iommu.h              |   1 +
include/hw/i386/pc.h                       |   2 +
include/hw/i386/x86.h                      |   2 -
include/hw/input/i8042.h                   |  15 ++
include/hw/misc/pvpanic.h                  |   8 -
include/hw/pci-bridge/xio3130_downstream.h |  15 ++
include/hw/pci/pci.h                       |  12 +-
include/hw/pci/pci_regs.h                  |   1 +
include/hw/pci/pcie.h                      |   7 +
include/hw/pci/pcie_sriov.h                |  77 ++++++++
include/hw/virtio/vhost-user-i2c.h         |   3 +
include/hw/virtio/vhost-user.h             |   3 +-
include/hw/virtio/virtio-iommu.h           |   1 +
include/qemu/event_notifier.h              |   1 +
include/qemu/typedefs.h                    |   2 +
include/standard-headers/linux/pvpanic.h   |   9 +
hw/acpi/aml-build.c                        |   8 +-
hw/acpi/erst.c                             |   5 -
hw/acpi/pcihp.c                            |  12 +-
hw/i386/acpi-build.c                       |   8 +
hw/i386/acpi-microvm.c                     |   6 +
hw/i386/intel_iommu.c                      |  14 +-
hw/i386/pc.c                               |  30 ++-
hw/i386/pc_piix.c                          |   1 +
hw/i386/pc_sysfw_ovmf.c                    |  18 +-
hw/i386/x86.c                              |  16 +-
hw/misc/pvpanic-isa.c                      |   4 +-
hw/misc/pvpanic-pci.c                      |   4 +-
hw/misc/pvpanic.c                          |   5 +-
hw/net/virtio-net.c                        |  13 +-
hw/pci-bridge/pci_expander_bridge.c        |   6 +
hw/pci-bridge/xio3130_downstream.c         |   5 +-
hw/pci-bridge/xio3130_upstream.c           |   2 +-
hw/pci/pci.c                               | 104 +++++++---
hw/pci/pcie.c                              |  16 ++
hw/pci/pcie_sriov.c                        | 302 +++++++++++++++++++++++++++++
hw/smbios/smbios.c                         |  80 ++++++--
hw/virtio/vhost-user-i2c.c                 |  11 +-
hw/virtio/vhost-user.c                     |  61 +++---
hw/virtio/vhost-vdpa.c                     |  21 +-
hw/virtio/vhost-vsock-common.c             |  10 +-
hw/virtio/vhost.c                          |   6 +-
hw/virtio/virtio-bus.c                     |  12 +-
hw/virtio/virtio-iommu.c                   |  99 ++++++++--
qom/object.c                               |   6 +-
tests/qtest/virtio-iommu-test.c            |   2 +
util/event_notifier-posix.c                |   5 +
MAINTAINERS                                |   1 -
docs/about/deprecated.rst                  |   8 +
docs/interop/vhost-user.rst                |  20 ++
docs/specs/acpi_erst.rst                   | 200 +++++++++++++++++++
docs/specs/index.rst                       |   1 +
hw/pci/meson.build                         |   1 +
hw/pci/trace-events                        |   5 +
hw/virtio/trace-events                     |   4 +-
meson.build                                |   2 +-
qemu-options.hx                            |   3 +-
scripts/update-linux-headers.sh            |   3 +-
tests/data/acpi/q35/FACP                   | Bin 244 -> 244 bytes
tests/data/acpi/q35/FACP.nosmm             | Bin 244 -> 244 bytes
tests/data/acpi/q35/FACP.slic              | Bin 244 -> 244 bytes
tests/data/acpi/q35/FACP.xapic             | Bin 244 -> 244 bytes
67 files changed, 1243 insertions(+), 178 deletions(-)
create mode 100644 docs/pcie_sriov.txt
create mode 100644 include/hw/pci-bridge/xio3130_downstream.h
create mode 100644 include/hw/pci/pcie_sriov.h
create mode 100644 include/standard-headers/linux/pvpanic.h
create mode 100644 hw/pci/pcie_sriov.c
create mode 100644 docs/specs/acpi_erst.rst
[PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Michael S. Tsirkin 2 years, 1 month ago
The following changes since commit 6629bf78aac7e53f83fd0bcbdbe322e2302dfd1f:

  Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20220302' into staging (2022-03-03 14:46:48 +0000)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 41d137fc631bd9315ff84727d780757d25054c58:

  hw/acpi/microvm: turn on 8042 bit in FADT boot architecture flags if present (2022-03-06 16:06:16 -0500)

----------------------------------------------------------------
virtio,pc,pci: features, cleanups, fixes

vhost-user enabled on non-linux systems
beginning of nvme sriov support
bigger tx queue for vdpa
virtio iommu bypass
An FADT flag to detect legacy keyboards.

Fixes, cleanups all over the place

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

----------------------------------------------------------------
Ani Sinha (7):
      MAINTAINERS: no need to add my name explicitly as a reviewer for VIOT tables
      docs/acpi/erst: add device id for ACPI ERST device in pci-ids.txt
      hw/acpi/erst: clean up unused IS_UEFI_CPER_RECORD macro
      hw/smbios: code cleanup - use macro definitions for table header handles
      hw/smbios: fix overlapping table handle numbers with large memory vms
      hw/smbios: add assertion to ensure handles of tables 19 and 32 do not collide
      hw/acpi/microvm: turn on 8042 bit in FADT boot architecture flags if present

Dov Murik (2):
      hw/i386: Improve bounds checking in OVMF table parsing
      hw/i386: Replace magic number with field length calculation

Eric DeVolder (1):
      ACPI ERST: specification for ERST support

Eugenio Pérez (1):
      virtio-net: Unlimit tx queue size if peer is vdpa

Halil Pasic (1):
      virtio: fix the condition for iommu_platform not supported

Igor Mammedov (4):
      pci: expose TYPE_XIO3130_DOWNSTREAM name
      acpi: pcihp: pcie: set power on cap on parent slot
      x86: cleanup unused compat_apic_id_mode
      pci: drop COMPAT_PROP_PCP for 2.0 machine types

Jason Wang (1):
      intel_iommu: support snoop control

Jean-Philippe Brucker (3):
      virtio-iommu: Default to bypass during boot
      virtio-iommu: Support bypass domain
      tests/qtest/virtio-iommu-test: Check bypass config

Joelle van Dyne (1):
      pc: add option to disable PS/2 mouse/keyboard

Jonathan Cameron (3):
      hw/pci-bridge/pxb: Fix missing swizzle
      pci-bridge/xio3130_upstream: Fix error handling
      pci-bridge/xio3130_downstream: Fix error handling

Knut Omang (2):
      pcie: Add support for Single Root I/O Virtualization (SR/IOV)
      pcie: Add some SR/IOV API documentation in docs/pcie_sriov.txt

Laurent Vivier (2):
      hw/virtio: vdpa: Fix leak of host-notifier memory-region
      vhost-vdpa: make notifiers _init()/_uninit() symmetric

Liav Albani (3):
      tests/acpi: i386: allow FACP acpi table changes
      hw/acpi: add indication for i8042 in IA-PC boot flags of the FADT table
      tests/acpi: i386: update FACP table differences

Michael S. Tsirkin (1):
      qom: assert integer does not overflow

Patrick Venture (1):
      hw/smbios: Add table 4 parameter, "processor-id"

Sergio Lopez (4):
      event_notifier: add event_notifier_get_wfd()
      vhost: use wfd on functions setting vring call fd
      configure, meson: allow enabling vhost-user on all POSIX systems
      docs: vhost-user: add subsection for non-Linux platforms

Stefano Garzarella (1):
      vhost-vsock: detach the virqueue element in case of error

Thomas Huth (1):
      hw/i386/pc_piix: Mark the machine types from version 1.4 to 1.7 as deprecated

Viresh Kumar (1):
      hw/vhost-user-i2c: Add support for VIRTIO_I2C_F_ZERO_LENGTH_REQUEST

Xueming Li (2):
      vhost-user: remove VirtQ notifier restore
      vhost-user: fix VirtQ notifier cleanup

Zhenwei Pi (2):
      headers: Add pvpanic.h
      hw/misc/pvpanic: Use standard headers instead

Zhenzhong Duan (1):
      pci: show id info when pci BDF conflict

Łukasz Gieryk (2):
      pcie: Add a helper to the SR/IOV API
      pcie: Add 1.2 version token for the Power Management Capability

 docs/pcie_sriov.txt                        | 115 +++++++++++
 docs/specs/pci-ids.txt                     |   1 +
 configure                                  |   4 +-
 hw/i386/intel_iommu_internal.h             |   1 +
 include/hw/acpi/acpi-defs.h                |   1 +
 include/hw/i386/intel_iommu.h              |   1 +
 include/hw/i386/pc.h                       |   2 +
 include/hw/i386/x86.h                      |   2 -
 include/hw/input/i8042.h                   |  15 ++
 include/hw/misc/pvpanic.h                  |   8 -
 include/hw/pci-bridge/xio3130_downstream.h |  15 ++
 include/hw/pci/pci.h                       |  12 +-
 include/hw/pci/pci_regs.h                  |   1 +
 include/hw/pci/pcie.h                      |   7 +
 include/hw/pci/pcie_sriov.h                |  77 ++++++++
 include/hw/virtio/vhost-user-i2c.h         |   3 +
 include/hw/virtio/vhost-user.h             |   3 +-
 include/hw/virtio/virtio-iommu.h           |   1 +
 include/qemu/event_notifier.h              |   1 +
 include/qemu/typedefs.h                    |   2 +
 include/standard-headers/linux/pvpanic.h   |   9 +
 hw/acpi/aml-build.c                        |   8 +-
 hw/acpi/erst.c                             |   5 -
 hw/acpi/pcihp.c                            |  12 +-
 hw/i386/acpi-build.c                       |   8 +
 hw/i386/acpi-microvm.c                     |   6 +
 hw/i386/intel_iommu.c                      |  14 +-
 hw/i386/pc.c                               |  30 ++-
 hw/i386/pc_piix.c                          |   1 +
 hw/i386/pc_sysfw_ovmf.c                    |  18 +-
 hw/i386/x86.c                              |  16 +-
 hw/misc/pvpanic-isa.c                      |   4 +-
 hw/misc/pvpanic-pci.c                      |   4 +-
 hw/misc/pvpanic.c                          |   5 +-
 hw/net/virtio-net.c                        |  13 +-
 hw/pci-bridge/pci_expander_bridge.c        |   6 +
 hw/pci-bridge/xio3130_downstream.c         |   5 +-
 hw/pci-bridge/xio3130_upstream.c           |   2 +-
 hw/pci/pci.c                               | 104 +++++++---
 hw/pci/pcie.c                              |  16 ++
 hw/pci/pcie_sriov.c                        | 302 +++++++++++++++++++++++++++++
 hw/smbios/smbios.c                         |  80 ++++++--
 hw/virtio/vhost-user-i2c.c                 |  11 +-
 hw/virtio/vhost-user.c                     |  61 +++---
 hw/virtio/vhost-vdpa.c                     |  21 +-
 hw/virtio/vhost-vsock-common.c             |  10 +-
 hw/virtio/vhost.c                          |   6 +-
 hw/virtio/virtio-bus.c                     |  12 +-
 hw/virtio/virtio-iommu.c                   |  99 ++++++++--
 qom/object.c                               |   6 +-
 tests/qtest/virtio-iommu-test.c            |   2 +
 util/event_notifier-posix.c                |   5 +
 MAINTAINERS                                |   1 -
 docs/about/deprecated.rst                  |   8 +
 docs/interop/vhost-user.rst                |  20 ++
 docs/specs/acpi_erst.rst                   | 200 +++++++++++++++++++
 docs/specs/index.rst                       |   1 +
 hw/pci/meson.build                         |   1 +
 hw/pci/trace-events                        |   5 +
 hw/virtio/trace-events                     |   4 +-
 meson.build                                |   2 +-
 qemu-options.hx                            |   3 +-
 scripts/update-linux-headers.sh            |   3 +-
 tests/data/acpi/q35/FACP                   | Bin 244 -> 244 bytes
 tests/data/acpi/q35/FACP.nosmm             | Bin 244 -> 244 bytes
 tests/data/acpi/q35/FACP.slic              | Bin 244 -> 244 bytes
 tests/data/acpi/q35/FACP.xapic             | Bin 244 -> 244 bytes
 67 files changed, 1243 insertions(+), 178 deletions(-)
 create mode 100644 docs/pcie_sriov.txt
 create mode 100644 include/hw/pci-bridge/xio3130_downstream.h
 create mode 100644 include/hw/pci/pcie_sriov.h
 create mode 100644 include/standard-headers/linux/pvpanic.h
 create mode 100644 hw/pci/pcie_sriov.c
 create mode 100644 docs/specs/acpi_erst.rst


Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Peter Maydell 2 years, 1 month ago
On Mon, 7 Mar 2022 at 10:01, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> The following changes since commit 6629bf78aac7e53f83fd0bcbdbe322e2302dfd1f:
>
>   Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20220302' into staging (2022-03-03 14:46:48 +0000)
>
> are available in the Git repository at:
>
>   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
>
> for you to fetch changes up to 41d137fc631bd9315ff84727d780757d25054c58:
>
>   hw/acpi/microvm: turn on 8042 bit in FADT boot architecture flags if present (2022-03-06 16:06:16 -0500)
>
> ----------------------------------------------------------------
> virtio,pc,pci: features, cleanups, fixes
>
> vhost-user enabled on non-linux systems
> beginning of nvme sriov support
> bigger tx queue for vdpa
> virtio iommu bypass
> An FADT flag to detect legacy keyboards.
>
> Fixes, cleanups all over the place
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Fails to build on the build-system-centos job:

libqemu-ppc64-softmmu.fa.p/hw_virtio_virtio.c.o: In function
`qmp_decode_features':
/builds/qemu-project/qemu/build/../hw/virtio/virtio.c:4155: undefined
reference to `gpu_map'
/builds/qemu-project/qemu/build/../hw/virtio/virtio.c:4155: undefined
reference to `gpu_map'
collect2: error: ld returned 1 exit status

https://gitlab.com/qemu-project/qemu/-/jobs/2172339948

thanks
-- PMM
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Peter Maydell 2 years, 1 month ago
On Mon, 7 Mar 2022 at 17:06, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Mon, 7 Mar 2022 at 10:01, Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > The following changes since commit 6629bf78aac7e53f83fd0bcbdbe322e2302dfd1f:
> >
> >   Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20220302' into staging (2022-03-03 14:46:48 +0000)
> >
> > are available in the Git repository at:
> >
> >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> >
> > for you to fetch changes up to 41d137fc631bd9315ff84727d780757d25054c58:
> >
> >   hw/acpi/microvm: turn on 8042 bit in FADT boot architecture flags if present (2022-03-06 16:06:16 -0500)
> >
> > ----------------------------------------------------------------
> > virtio,pc,pci: features, cleanups, fixes
> >
> > vhost-user enabled on non-linux systems
> > beginning of nvme sriov support
> > bigger tx queue for vdpa
> > virtio iommu bypass
> > An FADT flag to detect legacy keyboards.
> >
> > Fixes, cleanups all over the place
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> Fails to build on the build-system-centos job:
>
> libqemu-ppc64-softmmu.fa.p/hw_virtio_virtio.c.o: In function
> `qmp_decode_features':
> /builds/qemu-project/qemu/build/../hw/virtio/virtio.c:4155: undefined
> reference to `gpu_map'
> /builds/qemu-project/qemu/build/../hw/virtio/virtio.c:4155: undefined
> reference to `gpu_map'
> collect2: error: ld returned 1 exit status
>
> https://gitlab.com/qemu-project/qemu/-/jobs/2172339948

Also fails on cross-win64-system:

https://gitlab.com/qemu-project/qemu/-/jobs/2172339938

../hw/virtio/virtio.c: In function 'qmp_x_query_virtio_vhost_queue_status':
../hw/virtio/virtio.c:4358:30: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
4358 | status->desc = (uint64_t)(unsigned long)hdev->vqs[queue].desc;
| ^
../hw/virtio/virtio.c:4359:31: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
4359 | status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail;
| ^
../hw/virtio/virtio.c:4360:30: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
4360 | status->used = (uint64_t)(unsigned long)hdev->vqs[queue].used;
| ^
cc1: all warnings being treated as errors

-- PMM



>
> thanks
> -- PMM



-- 
12345678901234567890123456789012345678901234567890123456789012345678901234567890
         1         2         3         4         5         6         7         8
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Michael S. Tsirkin 2 years, 1 month ago
On Mon, Mar 07, 2022 at 05:13:16PM +0000, Peter Maydell wrote:
> On Mon, 7 Mar 2022 at 17:06, Peter Maydell <peter.maydell@linaro.org> wrote:
> >
> > On Mon, 7 Mar 2022 at 10:01, Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > The following changes since commit 6629bf78aac7e53f83fd0bcbdbe322e2302dfd1f:
> > >
> > >   Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20220302' into staging (2022-03-03 14:46:48 +0000)
> > >
> > > are available in the Git repository at:
> > >
> > >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> > >
> > > for you to fetch changes up to 41d137fc631bd9315ff84727d780757d25054c58:
> > >
> > >   hw/acpi/microvm: turn on 8042 bit in FADT boot architecture flags if present (2022-03-06 16:06:16 -0500)
> > >
> > > ----------------------------------------------------------------
> > > virtio,pc,pci: features, cleanups, fixes
> > >
> > > vhost-user enabled on non-linux systems
> > > beginning of nvme sriov support
> > > bigger tx queue for vdpa
> > > virtio iommu bypass
> > > An FADT flag to detect legacy keyboards.
> > >
> > > Fixes, cleanups all over the place
> > >
> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >
> > Fails to build on the build-system-centos job:
> >
> > libqemu-ppc64-softmmu.fa.p/hw_virtio_virtio.c.o: In function
> > `qmp_decode_features':
> > /builds/qemu-project/qemu/build/../hw/virtio/virtio.c:4155: undefined
> > reference to `gpu_map'
> > /builds/qemu-project/qemu/build/../hw/virtio/virtio.c:4155: undefined
> > reference to `gpu_map'
> > collect2: error: ld returned 1 exit status
> >
> > https://gitlab.com/qemu-project/qemu/-/jobs/2172339948
> 
> Also fails on cross-win64-system:
> 
> https://gitlab.com/qemu-project/qemu/-/jobs/2172339938
> 
> ../hw/virtio/virtio.c: In function 'qmp_x_query_virtio_vhost_queue_status':
> ../hw/virtio/virtio.c:4358:30: error: cast from pointer to integer of
> different size [-Werror=pointer-to-int-cast]
> 4358 | status->desc = (uint64_t)(unsigned long)hdev->vqs[queue].desc;
> | ^
> ../hw/virtio/virtio.c:4359:31: error: cast from pointer to integer of
> different size [-Werror=pointer-to-int-cast]
> 4359 | status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail;
> | ^
> ../hw/virtio/virtio.c:4360:30: error: cast from pointer to integer of
> different size [-Werror=pointer-to-int-cast]
> 4360 | status->used = (uint64_t)(unsigned long)hdev->vqs[queue].used;
> | ^
> cc1: all warnings being treated as errors
> 
> -- PMM

I dropped these for now but I really question the value of this warning,
as you can see the reason we have the buggy cast to unsigned long
is because someone wanted to shut up the warning on a 32 bit system.

Now, I could maybe get behind this if it simply warned about a cast that
loses information (cast to a smaller integer) or integer/pointer cast
that does not go through uintptr_t without regard to size.

> 
> 
> >
> > thanks
> > -- PMM
> 
> 
> 
> -- 
> 12345678901234567890123456789012345678901234567890123456789012345678901234567890
>          1         2         3         4         5         6         7         8
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Peter Maydell 2 years, 1 month ago
On Mon, 7 Mar 2022 at 22:52, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Mon, Mar 07, 2022 at 05:13:16PM +0000, Peter Maydell wrote:
> > Also fails on cross-win64-system:
> >
> > https://gitlab.com/qemu-project/qemu/-/jobs/2172339938
> >
> > ../hw/virtio/virtio.c: In function 'qmp_x_query_virtio_vhost_queue_status':
> > ../hw/virtio/virtio.c:4358:30: error: cast from pointer to integer of
> > different size [-Werror=pointer-to-int-cast]
> > 4358 | status->desc = (uint64_t)(unsigned long)hdev->vqs[queue].desc;
> > | ^
> > ../hw/virtio/virtio.c:4359:31: error: cast from pointer to integer of
> > different size [-Werror=pointer-to-int-cast]
> > 4359 | status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail;
> > | ^
> > ../hw/virtio/virtio.c:4360:30: error: cast from pointer to integer of
> > different size [-Werror=pointer-to-int-cast]
> > 4360 | status->used = (uint64_t)(unsigned long)hdev->vqs[queue].used;
> > | ^
> > cc1: all warnings being treated as errors

> I dropped these for now but I really question the value of this warning,
> as you can see the reason we have the buggy cast to unsigned long
> is because someone wanted to shut up the warning on a 32 bit system.
>
> Now, I could maybe get behind this if it simply warned about a cast that
> loses information (cast to a smaller integer) or integer/pointer cast
> that does not go through uintptr_t without regard to size.

This *is* warning about losing information. On 64-bit Windows
pointers are 64 bits but 'long' is 32 bits, so the path
pointer -> long -> uint64_t drops the top half of the pointer.

thanks
-- PMM
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Michael S. Tsirkin 2 years, 1 month ago
On Tue, Mar 08, 2022 at 09:05:27AM +0000, Peter Maydell wrote:
> On Mon, 7 Mar 2022 at 22:52, Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Mon, Mar 07, 2022 at 05:13:16PM +0000, Peter Maydell wrote:
> > > Also fails on cross-win64-system:
> > >
> > > https://gitlab.com/qemu-project/qemu/-/jobs/2172339938
> > >
> > > ../hw/virtio/virtio.c: In function 'qmp_x_query_virtio_vhost_queue_status':
> > > ../hw/virtio/virtio.c:4358:30: error: cast from pointer to integer of
> > > different size [-Werror=pointer-to-int-cast]
> > > 4358 | status->desc = (uint64_t)(unsigned long)hdev->vqs[queue].desc;
> > > | ^
> > > ../hw/virtio/virtio.c:4359:31: error: cast from pointer to integer of
> > > different size [-Werror=pointer-to-int-cast]
> > > 4359 | status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail;
> > > | ^
> > > ../hw/virtio/virtio.c:4360:30: error: cast from pointer to integer of
> > > different size [-Werror=pointer-to-int-cast]
> > > 4360 | status->used = (uint64_t)(unsigned long)hdev->vqs[queue].used;
> > > | ^
> > > cc1: all warnings being treated as errors
> 
> > I dropped these for now but I really question the value of this warning,
> > as you can see the reason we have the buggy cast to unsigned long
> > is because someone wanted to shut up the warning on a 32 bit system.
> >
> > Now, I could maybe get behind this if it simply warned about a cast that
> > loses information (cast to a smaller integer) or integer/pointer cast
> > that does not go through uintptr_t without regard to size.
> 
> This *is* warning about losing information. On 64-bit Windows
> pointers are 64 bits but 'long' is 32 bits, so the path
> pointer -> long -> uint64_t drops the top half of the pointer.
> 
> thanks
> -- PMM

Yes obviously. My point is that this:
(uint64_t)hdev->vqs[queue].avail
is always harmless but it warns on a 32 bit system.

And someone trying to fix that *is* what resulted in
(uint64_t)(unsigned long)hdev->vqs[queue].avail


IOW I don't really see how
(uint64_t)(uintptr_t)hdev->vqs[queue].avail
is better than
(uint64_t)hdev->vqs[queue].avail

except as a way to say "yes I do intend to cast pointer to integer
here, I did not forget to dereference the pointer". But if that
latter is what gcc is trying to warn about, then it should
just warn about any cast to integer except to uintptr_t,
without respect to size.

-- 
MST
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Peter Maydell 2 years, 1 month ago
On Tue, 8 Mar 2022 at 11:01, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Mar 08, 2022 at 09:05:27AM +0000, Peter Maydell wrote:
> > On Mon, 7 Mar 2022 at 22:52, Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > On Mon, Mar 07, 2022 at 05:13:16PM +0000, Peter Maydell wrote:
> > > > Also fails on cross-win64-system:
> > > >
> > > > https://gitlab.com/qemu-project/qemu/-/jobs/2172339938
> > > >
> > > > ../hw/virtio/virtio.c: In function 'qmp_x_query_virtio_vhost_queue_status':
> > > > ../hw/virtio/virtio.c:4358:30: error: cast from pointer to integer of
> > > > different size [-Werror=pointer-to-int-cast]
> > > > 4358 | status->desc = (uint64_t)(unsigned long)hdev->vqs[queue].desc;
> > > > | ^
> > > > ../hw/virtio/virtio.c:4359:31: error: cast from pointer to integer of
> > > > different size [-Werror=pointer-to-int-cast]
> > > > 4359 | status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail;
> > > > | ^
> > > > ../hw/virtio/virtio.c:4360:30: error: cast from pointer to integer of
> > > > different size [-Werror=pointer-to-int-cast]
> > > > 4360 | status->used = (uint64_t)(unsigned long)hdev->vqs[queue].used;
> > > > | ^
> > > > cc1: all warnings being treated as errors
> >
> > > I dropped these for now but I really question the value of this warning,
> > > as you can see the reason we have the buggy cast to unsigned long
> > > is because someone wanted to shut up the warning on a 32 bit system.
> > >
> > > Now, I could maybe get behind this if it simply warned about a cast that
> > > loses information (cast to a smaller integer) or integer/pointer cast
> > > that does not go through uintptr_t without regard to size.
> >
> > This *is* warning about losing information. On 64-bit Windows
> > pointers are 64 bits but 'long' is 32 bits, so the path
> > pointer -> long -> uint64_t drops the top half of the pointer.

> Yes obviously. My point is that this:
> (uint64_t)hdev->vqs[queue].avail
> is always harmless but it warns on a 32 bit system.

True, I suppose. But compiler warnings are often like that: we
take the hit of having to tweak some things we know to be OK in
order to catch the real bugs in other cases.

> And someone trying to fix that *is* what resulted in
> (uint64_t)(unsigned long)hdev->vqs[queue].avail

Using 'unsigned long' in a cast (or anything else) is often
the wrong thing in QEMU...

> IOW I don't really see how
> (uint64_t)(uintptr_t)hdev->vqs[queue].avail
> is better than
> (uint64_t)hdev->vqs[queue].avail
>
> except as a way to say "yes I do intend to cast pointer to integer
> here, I did not forget to dereference the pointer". But if that
> latter is what gcc is trying to warn about, then it should
> just warn about any cast to integer except to uintptr_t,
> without respect to size.

What is the uint64_t cast bringing to the table? Wouldn't
just status->desc = (uintptr_t)hdev->vqs[queue].desc;
work ?

thanks
-- PMM
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Michael S. Tsirkin 2 years, 1 month ago
On Tue, Mar 08, 2022 at 11:18:38AM +0000, Peter Maydell wrote:
> On Tue, 8 Mar 2022 at 11:01, Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Tue, Mar 08, 2022 at 09:05:27AM +0000, Peter Maydell wrote:
> > > On Mon, 7 Mar 2022 at 22:52, Michael S. Tsirkin <mst@redhat.com> wrote:
> > > >
> > > > On Mon, Mar 07, 2022 at 05:13:16PM +0000, Peter Maydell wrote:
> > > > > Also fails on cross-win64-system:
> > > > >
> > > > > https://gitlab.com/qemu-project/qemu/-/jobs/2172339938
> > > > >
> > > > > ../hw/virtio/virtio.c: In function 'qmp_x_query_virtio_vhost_queue_status':
> > > > > ../hw/virtio/virtio.c:4358:30: error: cast from pointer to integer of
> > > > > different size [-Werror=pointer-to-int-cast]
> > > > > 4358 | status->desc = (uint64_t)(unsigned long)hdev->vqs[queue].desc;
> > > > > | ^
> > > > > ../hw/virtio/virtio.c:4359:31: error: cast from pointer to integer of
> > > > > different size [-Werror=pointer-to-int-cast]
> > > > > 4359 | status->avail = (uint64_t)(unsigned long)hdev->vqs[queue].avail;
> > > > > | ^
> > > > > ../hw/virtio/virtio.c:4360:30: error: cast from pointer to integer of
> > > > > different size [-Werror=pointer-to-int-cast]
> > > > > 4360 | status->used = (uint64_t)(unsigned long)hdev->vqs[queue].used;
> > > > > | ^
> > > > > cc1: all warnings being treated as errors
> > >
> > > > I dropped these for now but I really question the value of this warning,
> > > > as you can see the reason we have the buggy cast to unsigned long
> > > > is because someone wanted to shut up the warning on a 32 bit system.
> > > >
> > > > Now, I could maybe get behind this if it simply warned about a cast that
> > > > loses information (cast to a smaller integer) or integer/pointer cast
> > > > that does not go through uintptr_t without regard to size.
> > >
> > > This *is* warning about losing information. On 64-bit Windows
> > > pointers are 64 bits but 'long' is 32 bits, so the path
> > > pointer -> long -> uint64_t drops the top half of the pointer.
> 
> > Yes obviously. My point is that this:
> > (uint64_t)hdev->vqs[queue].avail
> > is always harmless but it warns on a 32 bit system.
> 
> True, I suppose. But compiler warnings are often like that: we
> take the hit of having to tweak some things we know to be OK in
> order to catch the real bugs in other cases.
> 
> > And someone trying to fix that *is* what resulted in
> > (uint64_t)(unsigned long)hdev->vqs[queue].avail
> 
> Using 'unsigned long' in a cast (or anything else) is often
> the wrong thing in QEMU...
> 
> > IOW I don't really see how
> > (uint64_t)(uintptr_t)hdev->vqs[queue].avail
> > is better than
> > (uint64_t)hdev->vqs[queue].avail
> >
> > except as a way to say "yes I do intend to cast pointer to integer
> > here, I did not forget to dereference the pointer". But if that
> > latter is what gcc is trying to warn about, then it should
> > just warn about any cast to integer except to uintptr_t,
> > without respect to size.
> 
> What is the uint64_t cast bringing to the table? Wouldn't
> just status->desc = (uintptr_t)hdev->vqs[queue].desc;
> work ?
> 
> thanks
> -- PMM

True too. I would be happy if this gave a warning:

struct {
	uint32_t foo;
} bar = { .foo = (uintptr_t)hdev->vqs[queue].avail }

but of course it doesn't, uintptr_t is just an integer
type as far as gcc is concerned :(

Maybe adding things like that to sparse might be practical.

Generally sparse seems to mainly gain features from the
kernel, QEMU's needs are different. Could be useful to collect
ideas e.g. for a GSoC project.

-- 
MST
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Philippe Mathieu-Daudé 2 years, 1 month ago
On 8/3/22 12:18, Peter Maydell wrote:
> On Tue, 8 Mar 2022 at 11:01, Michael S. Tsirkin <mst@redhat.com> wrote:
>>
>> On Tue, Mar 08, 2022 at 09:05:27AM +0000, Peter Maydell wrote:
>>> On Mon, 7 Mar 2022 at 22:52, Michael S. Tsirkin <mst@redhat.com> wrote:

>>>> Now, I could maybe get behind this if it simply warned about a cast that
>>>> loses information (cast to a smaller integer) or integer/pointer cast
>>>> that does not go through uintptr_t without regard to size.
>>>
>>> This *is* warning about losing information. On 64-bit Windows
>>> pointers are 64 bits but 'long' is 32 bits, so the path
>>> pointer -> long -> uint64_t drops the top half of the pointer.
> 
>> Yes obviously. My point is that this:
>> (uint64_t)hdev->vqs[queue].avail
>> is always harmless but it warns on a 32 bit system.
> 
> True, I suppose. But compiler warnings are often like that: we
> take the hit of having to tweak some things we know to be OK in
> order to catch the real bugs in other cases.
> 
>> And someone trying to fix that *is* what resulted in
>> (uint64_t)(unsigned long)hdev->vqs[queue].avail
> 
> Using 'unsigned long' in a cast (or anything else) is often
> the wrong thing in QEMU...

$ git grep -F '(unsigned long)' | wc -l
      273

Ouch :/

These require cleanup:

target/i386/sev.c:170:    input.data = (__u64)(unsigned long)data;
target/i386/sev.c:188:    arg.data = (unsigned long)data;
target/i386/sev.c:243:    range.addr = (__u64)(unsigned long)host;
target/i386/sev.c:273:    range.addr = (__u64)(unsigned long)host;
target/i386/sev.c:730:    update.uaddr = (__u64)(unsigned long)addr;

And we might add a Gitlab issue to look at the hw/ ones:

$ git grep -F '(unsigned long)' hw | wc -l
       76
Re: [PULL v2 00/47] virtio,pc,pci: features, cleanups, fixes
Posted by Peter Maydell 2 years, 1 month ago
On Tue, 15 Mar 2022 at 18:35, Philippe Mathieu-Daudé
<philippe.mathieu.daude@gmail.com> wrote:
> On 8/3/22 12:18, Peter Maydell wrote:
> > Using 'unsigned long' in a cast (or anything else) is often
> > the wrong thing in QEMU...
>
> $ git grep -F '(unsigned long)' | wc -l
>       273
>
> Ouch :/

Only "often", not "always" :-) We have some APIs that work on
'long', usually because they're generic APIs borrowed from the
Linux kernel like the clear_bit/set_bit functions. And sometimes
you're interfacing to a host OS API whose types are 'long'.
So it's only one of those things that I tend to have in the
back of my head during code review, rather than something I think
we could enforce automatically.

The stuff in sev.c you list does look a bit suspicious, but
it's not actually buggy because that's all KVM code so we
know 'unsigned long' and pointers are the same size.
'uintptr_t' would be better, though.

thanks
-- PMM