Functional test framework improvements & bug fixes
[PULL 2/6] tests/functional/qemu_test: drop *args argument from .get_vm()
In reply to Thomas HuthFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
It's redundant. Only one caller use it, and it may be simply substituted by .add_args().
Message-ID: <[email protected]>
--- tests/functional/migration.py | 3 ++- tests/functional/qemu_test/testcase.py | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-)
tests/functional/migration.py +2 -1
@@ -63,7 +63,8 @@ def migrate_vms(self, dst_uri, src_uri, dst_vm, src_vm): self.assert_dest_vm(dst_vm) def migrate(self, dst_uri, src_uri=None): - dst_vm = self.get_vm('-incoming', 'defer', name="dst-qemu") + dst_vm = self.get_vm("dst-qemu") + dst_vm.add_args('-incoming', 'defer') self.configure_machine(dst_vm) dst_vm.launch()
tests/functional/qemu_test/testcase.py +3 -6
@@ -381,7 +381,7 @@ def require_device(self, devicename): if helptxt.find(devicename) < 0: self.skipTest('no support for device ' + devicename) - def _new_vm(self, name, *args): + def _new_vm(self, name): vm = QEMUMachine(self.qemu_bin, name=name, base_temp_dir=self.workdir,
@@ -394,20 +394,17 @@ def _new_vm(self, name, *args): vm.add_args("-chardev", f"socket,id=backdoor,path={sockpath},server=on,wait=off", "-mon", "chardev=backdoor,mode=control") - - if args: - vm.add_args(*args) return vm @property def vm(self): return self.get_vm(name='default') - def get_vm(self, *args, name=None): + def get_vm(self, name=None): if not name: name = str(uuid.uuid4()) if self._vms.get(name) is None: - self._vms[name] = self._new_vm(name, *args) + self._vms[name] = self._new_vm(name) if self.cpu is not None: self._vms[name].add_args('-cpu', self.cpu) if self.machine is not None:
Signature · 1 line
2.55.0
[PULL 5/6] hw/net/vmxnet3: Do not abort if guest provides bad interrupt numbers
In reply to Thomas Huthvmxnet3_validate_interrupts() currently aborts via hw_error() if the guest provided bad interrupt numbers. This should not happen, QEMU should rather refuse to activate the device in this case instead. Thus propagate the error to the callers to handle it more gracefully there.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/539
Message-ID: <[email protected]>
--- hw/net/vmxnet3.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
hw/net/vmxnet3.c +26 -8
@@ -1336,32 +1336,46 @@ static bool vmxnet3_verify_intx(VMXNET3State *s, int intx) || intx == pci_get_byte(s->parent_obj.config + PCI_INTERRUPT_PIN) - 1; } -static void vmxnet3_validate_interrupt_idx (bool is_msix,int idx) +static bool vmxnet3_validate_irq_idx (const char *type,bool is_msix,int idx) {int max_ints = is_msix ?VMXNET3_MAX_INTRS :VMXNET3_MAX_NMSIX_INTRS ; +if (idx >= max_ints) { -hw_error ("Bad interrupt index: %d\n" , idx); +qemu_log_mask (LOG_GUEST_ERROR , +"vmxnet3: Bad %s queue interrupt index: %d\n" , + type, idx); +return false; } + +return true; } -static void vmxnet3_validate_interrupts (VMXNET3State *s) +static bool vmxnet3_validate_interrupts (VMXNET3State *s) {int i;VMW_CFPRN ("Verifying event interrupt index (%d)" , s->event_int_idx); -vmxnet3_validate_interrupt_idx (s->msix_used, s->event_int_idx); +if (!vmxnet3_validate_irq_idx ("event" , s->msix_used, s->event_int_idx)) { +return false; + }for (i =0 ; i < s->txq_num; i++) {int idx = s->txq_descr[i].intr_idx;VMW_CFPRN ("Verifying TX queue %d interrupt index (%d)" , i, idx); -vmxnet3_validate_interrupt_idx (s->msix_used, idx); +if (!vmxnet3_validate_irq_idx ("TX" , s->msix_used, idx)) { +return false; + } }for (i =0 ; i < s->rxq_num; i++) {int idx = s->rxq_descr[i].intr_idx;VMW_CFPRN ("Verifying RX queue %d interrupt index (%d)" , i, idx); -vmxnet3_validate_interrupt_idx (s->msix_used, idx); +if (!vmxnet3_validate_irq_idx ("RX" , s->msix_used, idx)) { +return false; + } } + +return true; }static bool vmxnet3_validate_queues (VMXNET3State *s)
@@ -1554,7 +1568,9 @@ static void vmxnet3_activate_device(VMXNET3State *s) sizeof(s->rxq_descr[i].rxq_stats)); } -vmxnet3_validate_interrupts (s); +if (!vmxnet3_validate_interrupts (s)) { +return ; + }/* Make sure everything is in place before device activation */ smp_wmb ();
@@ -2392,7 +2408,9 @@ static int vmxnet3_post_load(void *opaque, int version_id)if (!vmxnet3_validate_queues (s)) {return -1 ; } -vmxnet3_validate_interrupts (s); +if (!vmxnet3_validate_interrupts (s)) { +return -1 ; + }return 0 ; }
Signature · 1 line
2.55.0
[PULL 4/6] hw/usb/dev-uas: Don't abort if guest provided an undersized buffer for status
In reply to Thomas HuthQEMU currently aborts if the guest provides an undersized buffer for the status packet (8 bytes):
hw/usb/core.c:623: usb_packet_copy:
Assertion `p->actual_length + bytes <= iov->size' failed.
If we hit this situation, log a guest error and continue by simply only providing the bytes that the guest asked for. (Note: This is e.g. similar to the UAS_PIPE_ID_COMMAND case that also clamps the length with: length = MIN(sizeof(iu), p->iov.size))
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3900
Message-ID: <[email protected]>
--- hw/usb/dev-uas.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
hw/usb/dev-uas.c +17 -2
@@ -359,6 +359,7 @@ static void usb_uas_send_status_bh(void *opaque)UASDevice *uas = opaque;UASStatus *st;USBPacket *p; +uint32_t length;while ((st =QTAILQ_FIRST (&uas->results)) !=NULL ) {if (uas_using_streams (uas)) {
@@ -373,7 +374,14 @@ static void usb_uas_send_status_bh(void *opaque)break ; } -usb_packet_copy (p, &st->status, st->length); + length = st->length; +if (length > p->iov.size) { +qemu_log_mask (LOG_GUEST_ERROR , +"usb uas: packet (%zd) too small for status (%d)\n" , + p->iov.size, length); + length = p->iov.size; + } +usb_packet_copy (p, &st->status, length);QTAILQ_REMOVE (&uas->results, st, next);g_free (st);
@@ -875,7 +883,14 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)break ; } } -usb_packet_copy (p, &st->status, st->length); + length = st->length; +if (length > p->iov.size) { +qemu_log_mask (LOG_GUEST_ERROR , +"usb uas: packet (%zd) too small for status (%d)\n" , + p->iov.size, length); + length = p->iov.size; + } +usb_packet_copy (p, &st->status, length);QTAILQ_REMOVE (&uas->results, st, next);g_free (st);break ;
Signature · 1 line
2.55.0
[PULL 1/6] tests/functional: add skipWithoutSudo() decorator
In reply to Thomas HuthFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device.
Message-ID: <[email protected]>
--- tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tests/functional/qemu_test/decorators.py +16 -0
@@ -6,6 +6,7 @@ import os import platform import resource +import subprocess from unittest import skipIf, skipUnless from .cmd import which
@@ -177,3 +178,18 @@ def skipLockedMemoryTest(locked_memory): ulimit_memory == resource.RLIM_INFINITY or ulimit_memory >= locked_memory * 1024, f'Test required {locked_memory} kB of available locked memory', ) + +''' +Decorator to skip execution of a test if passwordless +sudo command is not available. +''' +def skipWithoutSudo(): + proc = subprocess.run(["sudo", "-n", "/bin/true"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True, + check=False) + + return skipUnless(proc.returncode == 0, + f'requires password-less sudo access: {proc.stdout}')
Signature · 1 line
2.55.0
[PULL 3/6] tests/testcase.py: passthrough monitor_address
In reply to Thomas HuthFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
We'll need it soon to implement test for cpr-exec mode of tap-fd-migration.
Message-ID: <[email protected]>
--- tests/functional/qemu_test/testcase.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
tests/functional/qemu_test/testcase.py +5 -4
@@ -381,11 +381,12 @@ def require_device(self, devicename): if helptxt.find(devicename) < 0: self.skipTest('no support for device ' + devicename) - def _new_vm(self, name): + def _new_vm(self, name, monitor_address): vm = QEMUMachine(self.qemu_bin, name=name, base_temp_dir=self.workdir, - log_dir=self.log_file()) + log_dir=self.log_file(), + monitor_address=monitor_address) self.log.debug('QEMUMachine "%s" created', name) self.log.debug('QEMUMachine "%s" temp_dir: %s', name, vm.temp_dir)
@@ -400,11 +401,11 @@ def _new_vm(self, name): def vm(self): return self.get_vm(name='default') - def get_vm(self, name=None): + def get_vm(self, name=None, monitor_address=None): if not name: name = str(uuid.uuid4()) if self._vms.get(name) is None: - self._vms[name] = self._new_vm(name) + self._vms[name] = self._new_vm(name, monitor_address) if self.cpu is not None: self._vms[name].add_args('-cpu', self.cpu) if self.machine is not None:
Signature · 1 line
2.55.0
Hi Richard!
The following changes since commit 539bc315538afe036a4b99088659aa82e3b489f2:
Merge tag 'pull-loongarch-20260813' of https://github.com/bibo-mao/qemu into staging (2026-08-13 07:16:25 -0700)
are available in the Git repository at:
https://gitlab.com/thuth/qemu.git tags/pull-request-2026-08-14
for you to fetch changes up to 4adfb431c0c3abd84909d1228b4954bfd68a1dbc:
hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits() (2026-08-14 09:14:58 +0200)
----------------------------------------------------------------
* Some minor updates to the functional testing framework
* Fix a guest-triggerable abort() in the usb uas code
* Fix a guest-triggerable abort() in the vmxnet3 code
* Fix a undefined behavior problem in the amd_iommu code
----------------------------------------------------------------
Thomas Huth (3):
hw/usb/dev-uas: Don't abort if guest provided an undersized buffer for status hw/net/vmxnet3: Do not abort if guest provides bad interrupt numbers hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits()
Vladimir Sementsov-Ogievskiy (3):
tests/functional: add skipWithoutSudo() decorator tests/functional/qemu_test: drop *args argument from .get_vm() tests/testcase.py: passthrough monitor_address
hw/i386/amd_iommu.c | 2 +- hw/net/vmxnet3.c | 34 ++++++++++++++++++++++++-------- hw/usb/dev-uas.c | 19 ++++++++++++++++-- tests/functional/migration.py | 3 ++- tests/functional/qemu_test/decorators.py | 16 +++++++++++++++ tests/functional/qemu_test/testcase.py | 12 +++++------ 6 files changed, 67 insertions(+), 19 deletions(-)
[PULL 6/6] hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits()
The code in amdvi_encode_event() calls amdvi_setevent_bits() with start = 64:
amdvi_setevent_bits(evt, addr, 64, 64);
and amdvi_setevent_bits() then calculates:
uint64_t mask = MAKE_64BIT_MASK(start, length);
but this MAKE_64BIT_MASK() macro shifts a value left by "start" bit positions. Shifting left by more than 63 is undefined behavior and could have unexpected results with different compilers / architectures.
Fix it by using "bitpos" instead, which was likely the original intended behavior anyway. (bitpos is calculated as bitpos = start % 64).
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3633
Message-ID: <[email protected]>
--- hw/i386/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/amd_iommu.c +1 -1
@@ -323,7 +323,7 @@ static void amdvi_setevent_bits(uint64_t *buffer, uint64_t value, int start, int length) {int index = start /64 , bitpos = start %64 ; -uint64_t mask =MAKE_64BIT_MASK (start, length); +uint64_t mask =MAKE_64BIT_MASK (bitpos, length); buffer[index] &= ~mask; buffer[index] |= (value << bitpos) & mask; }
Signature · 1 line
2.55.0
Richard Henderson
AppliedQuoted 12 lines · Thomas Huth
Hi Richard!
The following changes since commit
539bc315538afe036a4b99088659aa82e3b489f2:Merge tag 'pull-loongarch-20260813' ofhttps://github.com/bibo-mao/qemu into staging (2026-08-13 07:16:25 -0700)are available in the Git repository at:
https://gitlab.com/thuth/qemu.git tags/pull-request-2026-08-14for you to fetch changes up to
4adfb431c0c3abd84909d1228b4954bfd68a1dbc:
Quoted 7 lines
hw/i386/amd_iommu: Avoid undefined behavior in amdvi_setevent_bits() (2026-08-14 09:14:58 +0200)----------------------------------------------------------------
* Some minor updates to the functional testing framework
* Fix a guest-triggerableabort()in the usb uas code
* Fix a guest-triggerableabort()in the vmxnet3 code
* Fix a undefined behavior problem in theamd_iommucode
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.2 as appropriate.
r~