hw/vfio/common.c | 2 +- util/vfio-helpers.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
In a few places we report errno formatted as a negative integer.
This is not as user friendly as it can be. Use strerror() and/or
error_setg_errno() instead.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
hw/vfio/common.c | 2 +-
util/vfio-helpers.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 5ca11488d6..a3a2a82d99 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -352,7 +352,7 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova,
return 0;
}
- error_report("VFIO_MAP_DMA: %d", -errno);
+ error_report("VFIO_MAP_DMA failed: %s", strerror(errno));
return -errno;
}
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 813f7ec564..ddd9a96e76 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -545,7 +545,7 @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size,
trace_qemu_vfio_do_mapping(s, host, size, iova);
if (ioctl(s->container, VFIO_IOMMU_MAP_DMA, &dma_map)) {
- error_report("VFIO_MAP_DMA: %d", -errno);
+ error_report("VFIO_MAP_DMA failed: %s", strerror(errno));
return -errno;
}
return 0;
@@ -570,7 +570,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping,
assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size));
assert(index >= 0 && index < s->nr_mappings);
if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
- error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno);
+ error_setg_errno(errp, errno, "VFIO_UNMAP_DMA failed");
}
memmove(mapping, &s->mappings[index + 1],
sizeof(s->mappings[0]) * (s->nr_mappings - index - 1));
@@ -669,7 +669,7 @@ int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s)
trace_qemu_vfio_dma_reset_temporary(s);
qemu_mutex_lock(&s->lock);
if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
- error_report("VFIO_UNMAP_DMA: %d", -errno);
+ error_report("VFIO_UNMAP_DMA failed: %s", strerror(errno));
qemu_mutex_unlock(&s->lock);
return -errno;
}
--
2.24.1
On Fri, Feb 14, 2020 at 09:47:39AM +0100, Michal Privoznik wrote: >In a few places we report errno formatted as a negative integer. >This is not as user friendly as it can be. Use strerror() and/or >error_setg_errno() instead. > >Signed-off-by: Michal Privoznik <mprivozn@redhat.com> >--- > hw/vfio/common.c | 2 +- > util/vfio-helpers.c | 6 +++--- > 2 files changed, 4 insertions(+), 4 deletions(-) > Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
On 2/14/20 9:47 AM, Michal Privoznik wrote: > In a few places we report errno formatted as a negative integer. > This is not as user friendly as it can be. Use strerror() and/or > error_setg_errno() instead. > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > --- > hw/vfio/common.c | 2 +- > util/vfio-helpers.c | 6 +++--- > 2 files changed, 4 insertions(+), 4 deletions(-) > BTW the reason I've noticed these is because I'm seeing some errors when assigning my NVMe disk to qemu. This is the full command line: /home/zippy/work/qemu/qemu.git/x86_64-softmmu/qemu-system-x86_64 \ -name guest=fedora,debug-threads=on \ -S \ -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-2-fedora/master-key.aes \ -machine pc-i440fx-4.1,accel=kvm,usb=off,dump-guest-core=off \ -cpu host \ -m size=4194304k,slots=16,maxmem=1099511627776k \ -overcommit mem-lock=off \ -smp 4,sockets=1,dies=1,cores=2,threads=2 \ -object iothread,id=iothread1 \ -object iothread,id=iothread2 \ -object iothread,id=iothread3 \ -object iothread,id=iothread4 \ -mem-prealloc \ -mem-path /hugepages2M/libvirt/qemu/2-fedora \ -numa node,nodeid=0,cpus=0,mem=4096 \ -uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ -no-user-config \ -nodefaults \ -chardev socket,id=charmonitor,fd=31,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc \ -no-shutdown \ -global PIIX4_PM.disable_s3=0 \ -global PIIX4_PM.disable_s4=0 \ -boot menu=on,strict=on \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x4 \ -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/fedora.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-2-format","read-only":false,"discard":"unmap","driver":"qcow2","file":"libvirt-2-storage","backing":null}' \ -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-2-format,id=scsi0-0-0-0,bootindex=1 \ -blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=libvirt-1-format,id=virtio-disk0 \ -netdev tap,fd=33,id=hostnet0,vhost=on,vhostfd=34 \ -device virtio-net-pci,host_mtu=9000,netdev=hostnet0,id=net0,mac=52:54:00:a4:6f:91,bus=pci.0,addr=0x3 \ -chardev pty,id=charserial0 \ -device isa-serial,chardev=charserial0,id=serial0 \ -chardev socket,id=charchannel0,fd=35,server,nowait \ -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 \ -spice port=5900,addr=0.0.0.0,disable-ticketing,seamless-migration=on \ -device virtio-vga,id=video0,virgl=on,max_outputs=1,bus=pci.0,addr=0x2 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on And these are the errors I see: 2020-02-14T09:06:18.183167Z qemu-system-x86_64: VFIO_MAP_DMA failed: Invalid argument 2020-02-14T09:10:49.753767Z qemu-system-x86_64: VFIO_MAP_DMA failed: Cannot allocate memory 2020-02-14T09:11:04.530344Z qemu-system-x86_64: VFIO_MAP_DMA failed: No space left on device 2020-02-14T09:11:04.531087Z qemu-system-x86_64: VFIO_MAP_DMA failed: No space left on device 2020-02-14T09:11:04.531230Z qemu-system-x86_64: VFIO_MAP_DMA failed: No space left on device I'm doing nothing with the disk inside the guest, but: # dd if=/dev/vda of=/dev/null status=progress (the disk appears as /dev/vda in the guest). Surprisingly, I do not see these errors when I use the traditional PCI assignment (-device vfio-pci). My versions of kernel and qemu: moe ~ # uname -r 5.4.15-gentoo moe ~ # /home/zippy/work/qemu/qemu.git/x86_64-softmmu/qemu-system-x86_64 --version QEMU emulator version 4.2.50 (v4.2.0-1439-g5d6542bea7-dirty) Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers Do you guys want me to file a bug? Michal
On Fri, 14 Feb 2020 10:19:50 +0100 Michal Privoznik <mprivozn@redhat.com> wrote: > On 2/14/20 9:47 AM, Michal Privoznik wrote: > > In a few places we report errno formatted as a negative integer. > > This is not as user friendly as it can be. Use strerror() and/or > > error_setg_errno() instead. > > > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > > --- > > hw/vfio/common.c | 2 +- > > util/vfio-helpers.c | 6 +++--- > > 2 files changed, 4 insertions(+), 4 deletions(-) > > > > BTW the reason I've noticed these is because I'm seeing some errors when > assigning my NVMe disk to qemu. This is the full command line: > > > /home/zippy/work/qemu/qemu.git/x86_64-softmmu/qemu-system-x86_64 \ > -name guest=fedora,debug-threads=on \ > -S \ > -object > secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-2-fedora/master-key.aes > \ > -machine pc-i440fx-4.1,accel=kvm,usb=off,dump-guest-core=off \ > -cpu host \ > -m size=4194304k,slots=16,maxmem=1099511627776k \ > -overcommit mem-lock=off \ > -smp 4,sockets=1,dies=1,cores=2,threads=2 \ > -object iothread,id=iothread1 \ > -object iothread,id=iothread2 \ > -object iothread,id=iothread3 \ > -object iothread,id=iothread4 \ > -mem-prealloc \ > -mem-path /hugepages2M/libvirt/qemu/2-fedora \ > -numa node,nodeid=0,cpus=0,mem=4096 \ > -uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ > -no-user-config \ > -nodefaults \ > -chardev socket,id=charmonitor,fd=31,server,nowait \ > -mon chardev=charmonitor,id=monitor,mode=control \ > -rtc base=utc \ > -no-shutdown \ > -global PIIX4_PM.disable_s3=0 \ > -global PIIX4_PM.disable_s4=0 \ > -boot menu=on,strict=on \ > -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ > -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x4 \ > -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 \ > -blockdev > '{"driver":"file","filename":"/var/lib/libvirt/images/fedora.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' > \ > -blockdev > '{"node-name":"libvirt-2-format","read-only":false,"discard":"unmap","driver":"qcow2","file":"libvirt-2-storage","backing":null}' > \ > -device > scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-2-format,id=scsi0-0-0-0,bootindex=1 > \ > -blockdev > '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' > \ > -blockdev > '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' > \ > -device > virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=libvirt-1-format,id=virtio-disk0 > \ > -netdev tap,fd=33,id=hostnet0,vhost=on,vhostfd=34 \ > -device > virtio-net-pci,host_mtu=9000,netdev=hostnet0,id=net0,mac=52:54:00:a4:6f:91,bus=pci.0,addr=0x3 > \ > -chardev pty,id=charserial0 \ > -device isa-serial,chardev=charserial0,id=serial0 \ > -chardev socket,id=charchannel0,fd=35,server,nowait \ > -device > virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 > \ > -spice port=5900,addr=0.0.0.0,disable-ticketing,seamless-migration=on \ > -device virtio-vga,id=video0,virgl=on,max_outputs=1,bus=pci.0,addr=0x2 \ > -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7 \ > -sandbox > on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ > -msg timestamp=on > > And these are the errors I see: > > 2020-02-14T09:06:18.183167Z qemu-system-x86_64: VFIO_MAP_DMA failed: > Invalid argument > 2020-02-14T09:10:49.753767Z qemu-system-x86_64: VFIO_MAP_DMA failed: > Cannot allocate memory > 2020-02-14T09:11:04.530344Z qemu-system-x86_64: VFIO_MAP_DMA failed: No > space left on device > 2020-02-14T09:11:04.531087Z qemu-system-x86_64: VFIO_MAP_DMA failed: No > space left on device > 2020-02-14T09:11:04.531230Z qemu-system-x86_64: VFIO_MAP_DMA failed: No > space left on device I feel obligated to reply given the VFIO issues, but TBH I've never used the nvme-vfio driver and don't consider myself the maintainer of the vfio-helpers. I'd guess the latter ENOSPC errors indicate we've exhausted the number of separate DMA mappings that a vfio user is allowed to create. We had to put a cap on this to prevent malicious users and it was set to 64K, which seemed like orders of magnitude more than we use for device assignment, but perhaps not enough for this driver. There's a dma_entry_limit module option on the vfio_iommu_type1 module that can be bumped up to see if it resolves this issue. The initial EINVAL and ENOMEM errors might however indicate the driver has already gone into the weeds before we get to the latter problem though. > I'm doing nothing with the disk inside the guest, but: > > # dd if=/dev/vda of=/dev/null status=progress > > (the disk appears as /dev/vda in the guest). Surprisingly, I do not see > these errors when I use the traditional PCI assignment (-device > vfio-pci). Not really surprising, entirely different models of using the device. Device assignment should also give better performance, especially if we really are exhausting the number of mappings a user can have inflight concurrently. > My versions of kernel and qemu: > > moe ~ # uname -r > 5.4.15-gentoo > moe ~ # /home/zippy/work/qemu/qemu.git/x86_64-softmmu/qemu-system-x86_64 > --version > QEMU emulator version 4.2.50 (v4.2.0-1439-g5d6542bea7-dirty) > Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers > > Do you guys want me to file a bug? Probably a good idea. Thanks, Alex
On 2/14/20 4:49 PM, Alex Williamson wrote: > On Fri, 14 Feb 2020 10:19:50 +0100 > Michal Privoznik <mprivozn@redhat.com> wrote: > >> >> Do you guys want me to file a bug? > > Probably a good idea. Thanks, Since I'm reproducing this against upstream, I've reported it here: https://bugs.launchpad.net/qemu/+bug/1863333 Michal
On Fri, Feb 14, 2020 at 10:20 AM Michal Privoznik <mprivozn@redhat.com> wrote: > On 2/14/20 9:47 AM, Michal Privoznik wrote: > > In a few places we report errno formatted as a negative integer. > > This is not as user friendly as it can be. Use strerror() and/or > > error_setg_errno() instead. > > > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > > --- > > hw/vfio/common.c | 2 +- > > util/vfio-helpers.c | 6 +++--- > > 2 files changed, 4 insertions(+), 4 deletions(-) > > > > BTW the reason I've noticed these is because I'm seeing some errors when > assigning my NVMe disk to qemu. This is the full command line: > > > /home/zippy/work/qemu/qemu.git/x86_64-softmmu/qemu-system-x86_64 \ > -name guest=fedora,debug-threads=on \ > -S \ > -object > secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-2-fedora/master-key.aes > \ > -machine pc-i440fx-4.1,accel=kvm,usb=off,dump-guest-core=off \ > -cpu host \ > -m size=4194304k,slots=16,maxmem=1099511627776k \ > -overcommit mem-lock=off \ > -smp 4,sockets=1,dies=1,cores=2,threads=2 \ > -object iothread,id=iothread1 \ > -object iothread,id=iothread2 \ > -object iothread,id=iothread3 \ > -object iothread,id=iothread4 \ > -mem-prealloc \ > -mem-path /hugepages2M/libvirt/qemu/2-fedora \ > -numa node,nodeid=0,cpus=0,mem=4096 \ > -uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ > -no-user-config \ > -nodefaults \ > -chardev socket,id=charmonitor,fd=31,server,nowait \ > -mon chardev=charmonitor,id=monitor,mode=control \ > -rtc base=utc \ > -no-shutdown \ > -global PIIX4_PM.disable_s3=0 \ > -global PIIX4_PM.disable_s4=0 \ > -boot menu=on,strict=on \ > -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ > -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x4 \ > -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 \ > -blockdev > '{"driver":"file","filename":"/var/lib/libvirt/images/fedora.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' > \ > -blockdev > '{"node-name":"libvirt-2-format","read-only":false,"discard":"unmap","driver":"qcow2","file":"libvirt-2-storage","backing":null}' > \ > -device > scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-2-format,id=scsi0-0-0-0,bootindex=1 > \ > -blockdev > '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' > \ > -blockdev > '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' > \ > -device > virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=libvirt-1-format,id=virtio-disk0 > \ > -netdev tap,fd=33,id=hostnet0,vhost=on,vhostfd=34 \ > -device > virtio-net-pci,host_mtu=9000,netdev=hostnet0,id=net0,mac=52:54:00:a4:6f:91,bus=pci.0,addr=0x3 > \ > -chardev pty,id=charserial0 \ > -device isa-serial,chardev=charserial0,id=serial0 \ > -chardev socket,id=charchannel0,fd=35,server,nowait \ > -device > virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.qemu.guest_agent.0 > \ > -spice port=5900,addr=0.0.0.0,disable-ticketing,seamless-migration=on \ > -device virtio-vga,id=video0,virgl=on,max_outputs=1,bus=pci.0,addr=0x2 \ > -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7 \ > -sandbox > on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ > -msg timestamp=on > > And these are the errors I see: > > 2020-02-14T09:06:18.183167Z qemu-system-x86_64: VFIO_MAP_DMA failed: > Invalid argument > 2020-02-14T09:10:49.753767Z qemu-system-x86_64: VFIO_MAP_DMA failed: > Cannot allocate memory > 2020-02-14T09:11:04.530344Z qemu-system-x86_64: VFIO_MAP_DMA failed: No > space left on device > 2020-02-14T09:11:04.531087Z qemu-system-x86_64: VFIO_MAP_DMA failed: No > space left on device > 2020-02-14T09:11:04.531230Z qemu-system-x86_64: VFIO_MAP_DMA failed: No > space left on device > > > I'm doing nothing with the disk inside the guest, but: > > # dd if=/dev/vda of=/dev/null status=progress > > (the disk appears as /dev/vda in the guest). Surprisingly, I do not see > these errors when I use the traditional PCI assignment (-device > vfio-pci). My versions of kernel and qemu: > > moe ~ # uname -r > 5.4.15-gentoo > moe ~ # /home/zippy/work/qemu/qemu.git/x86_64-softmmu/qemu-system-x86_64 > --version > QEMU emulator version 4.2.50 (v4.2.0-1439-g5d6542bea7-dirty) > Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers > > Do you guys want me to file a bug? As you already have all the information, and it is a simple copy/paste, I'd say "yes"
On Fri, 14 Feb 2020 09:47:39 +0100 Michal Privoznik <mprivozn@redhat.com> wrote: > In a few places we report errno formatted as a negative integer. > This is not as user friendly as it can be. Use strerror() and/or > error_setg_errno() instead. > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > --- > hw/vfio/common.c | 2 +- > util/vfio-helpers.c | 6 +++--- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/hw/vfio/common.c b/hw/vfio/common.c > index 5ca11488d6..a3a2a82d99 100644 > --- a/hw/vfio/common.c > +++ b/hw/vfio/common.c > @@ -352,7 +352,7 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova, > return 0; > } > > - error_report("VFIO_MAP_DMA: %d", -errno); > + error_report("VFIO_MAP_DMA failed: %s", strerror(errno)); > return -errno; > } I think you missed the one in vfio_dma_unmap(). (...) The other file looks good.
On 2/14/20 10:47 AM, Cornelia Huck wrote: > On Fri, 14 Feb 2020 09:47:39 +0100 > Michal Privoznik <mprivozn@redhat.com> wrote: > >> In a few places we report errno formatted as a negative integer. >> This is not as user friendly as it can be. Use strerror() and/or >> error_setg_errno() instead. >> >> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> >> --- >> hw/vfio/common.c | 2 +- >> util/vfio-helpers.c | 6 +++--- >> 2 files changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/hw/vfio/common.c b/hw/vfio/common.c >> index 5ca11488d6..a3a2a82d99 100644 >> --- a/hw/vfio/common.c >> +++ b/hw/vfio/common.c >> @@ -352,7 +352,7 @@ static int vfio_dma_map(VFIOContainer *container, hwaddr iova, >> return 0; >> } >> >> - error_report("VFIO_MAP_DMA: %d", -errno); >> + error_report("VFIO_MAP_DMA failed: %s", strerror(errno)); >> return -errno; >> } > > I think you missed the one in vfio_dma_unmap(). > Indeed, will send v2. Michal
© 2016 - 2024 Red Hat, Inc.