* [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR
@ 2025-05-21 16:42 Alex Bennée
2025-05-21 16:42 ` [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume Alex Bennée
` (19 more replies)
0 siblings, 20 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
Now the tree is open here is the state of my current maintainer
queues. I've tagged the virtio-gpu changes as Cc: qemu-stable but
given how close to release we were it didn't seem worth rushing them
in for 10.0. I've included a MAINTAINERS patch just to make sure I can
route any more fixes until a more full time maintainer volunteers.
Unless there are any major objections I intend to send the PR on Friday.
For v3
- addressed review comments
- included gdb/next patches
For v2
- addressed various comments (see bellow --- in commits)
- added Akihiko/Dmitry as virtio-gpu reviewers
The following still need review:
MAINTAINERS: add Akihiko and Dmitry as reviewers
MAINTAINERS: add myself to virtio-gpu for Odd Fixes
tests/Makefile: include test-plugins in per-arch build deps
tests/tcg: make aarch64 boot.S handle different starting modes
tests/docker: expose $HOME/.cache/qemu as docker volume
Alex.
Alex Bennée (12):
tests/docker: expose $HOME/.cache/qemu as docker volume
gitlab: disable debug info on CI builds
tests/tcg: make aarch64 boot.S handle different starting modes
tests/Makefile: include test-plugins in per-arch build deps
contrib/plugins: add a scaling factor to the ips arg
contrib/plugins: allow setting of instructions per quantum
MAINTAINERS: add myself to virtio-gpu for Odd Fixes
MAINTAINERS: add Akihiko and Dmitry as reviewers
hw/display: re-arrange memory region tracking
include/exec: fix assert in size_memop
include/gdbstub: fix include guard in commands.h
gdbstub: assert earlier in handle_read_all_regs
Dominik 'Disconnect3d' Czarnota (1):
gdbstub: Implement qGDBServerVersion packet
Dongwon Kim (1):
ui/gtk-gl-area: Remove extra draw call in refresh
Gustavo Romero (1):
tests/functional: Add PCI hotplug test for aarch64
Manos Pitsidianakis (3):
virtio-gpu: fix hang under TCG when unmapping blob
virtio-gpu: refactor async blob unmapping
gdbstub: update aarch64-core.xml
Nabih Estefan (1):
tests/qtest: fix igb test failure under --enable-ubsan
Yiwei Zhang (1):
virtio-gpu: support context init multiple timeline
MAINTAINERS | 11 +-
docs/about/emulation.rst | 4 +
include/exec/memop.h | 4 +-
include/gdbstub/commands.h | 2 +-
include/system/memory.h | 1 +
contrib/plugins/ips.c | 49 +++++-
gdbstub/gdbstub.c | 19 ++-
hw/display/virtio-gpu-virgl.c | 104 ++++++++---
tests/qtest/libqos/igb.c | 4 +-
ui/gtk-gl-area.c | 1 -
.gitlab-ci.d/buildtest-template.yml | 1 +
gdb-xml/aarch64-core.xml | 52 +++++-
tests/Makefile.include | 2 +-
tests/docker/Makefile.include | 10 +-
tests/functional/meson.build | 1 +
tests/functional/test_aarch64_hotplug_pci.py | 74 ++++++++
tests/tcg/aarch64/Makefile.softmmu-target | 3 +-
tests/tcg/aarch64/system/boot.S | 171 ++++++++++++++++++-
18 files changed, 464 insertions(+), 49 deletions(-)
create mode 100755 tests/functional/test_aarch64_hotplug_pci.py
--
2.39.5
^ permalink raw reply [flat|nested] 52+ messages in thread
* [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:23 ` Thomas Huth
2025-05-21 16:42 ` [PATCH v3 02/20] gitlab: disable debug info on CI builds Alex Bennée
` (18 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
If you want to run functional tests we should share .cache/qemu so we
don't force containers to continually re-download images.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- Share a whole .cache/qemu path.
---
tests/docker/Makefile.include | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index fa1cbb6726..3959d8a028 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -185,8 +185,10 @@ docker:
docker-help: docker
+# Where QEMU caches build artefacts
+DOCKER_QEMU_CACHE_DIR := $$HOME/.cache/qemu
# Use a global constant ccache directory to speed up repetitive builds
-DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
+DOCKER_QEMU_CCACHE_DIR := DOCKER_QEMU_CACHE_DIR/docker-ccache
# This rule if for directly running against an arbitrary docker target.
# It is called by the expanded docker targets (e.g. make
@@ -195,7 +197,7 @@ DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
#
docker-run: docker-qemu-src
- @mkdir -p "$(DOCKER_CCACHE_DIR)"
+ @mkdir -p "$(DOCKER_QEMU_CCACHE_DIR)"
@if test -z "$(IMAGE)" || test -z "$(TEST)"; \
then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
fi
@@ -222,8 +224,8 @@ docker-run: docker-qemu-src
-e V=$V -e J=$J -e DEBUG=$(DEBUG) \
-e SHOW_ENV=$(SHOW_ENV) \
$(if $(NOUSER),, \
- -e CCACHE_DIR=/var/tmp/ccache \
- -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
+ -v $(DOCKER_QEMU_CACHE_DIR):$(DOCKER_QEMU_CACHE_DIR) \
+ -e CCACHE_DIR=$(DOCKER_QEMU_CCACHE_DIR) \
) \
-v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
$(IMAGE) \
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 02/20] gitlab: disable debug info on CI builds
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
2025-05-21 16:42 ` [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 03/20] tests/tcg: make aarch64 boot.S handle different starting modes Alex Bennée
` (17 subsequent siblings)
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
Our default build enables debug info which adds hugely to the size of
the builds as well as the size of cached objects. Disable debug info
across the board to save space and reduce pressure on the CI system.
We still have a number of builds which explicitly enable debug and
related extra asserts like --enable-debug-tcg.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
.gitlab-ci.d/buildtest-template.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitlab-ci.d/buildtest-template.yml b/.gitlab-ci.d/buildtest-template.yml
index 118371e377..19663126ca 100644
--- a/.gitlab-ci.d/buildtest-template.yml
+++ b/.gitlab-ci.d/buildtest-template.yml
@@ -24,6 +24,7 @@
- ccache --zero-stats
- section_start configure "Running configure"
- ../configure --enable-werror --disable-docs --enable-fdt=system
+ --disable-debug-info
${TARGETS:+--target-list="$TARGETS"}
$CONFIGURE_ARGS ||
{ cat config.log meson-logs/meson-log.txt && exit 1; }
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 03/20] tests/tcg: make aarch64 boot.S handle different starting modes
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
2025-05-21 16:42 ` [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume Alex Bennée
2025-05-21 16:42 ` [PATCH v3 02/20] gitlab: disable debug info on CI builds Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:10 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan Alex Bennée
` (16 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Julian Armistead,
Jim MacArthur
Currently the boot.S code assumes everything starts at EL1. This will
break things like the memory test which will barf on unaligned memory
access when run at a higher level.
Adapt the boot code to do some basic verification of the starting mode
and the minimal configuration to move to the lower exception levels.
With this we can run the memory test with:
-M virt,secure=on
-M virt,secure=on,virtualization=on
-M virt,virtualisation=on
If a test needs to be at a particular EL it can use the semihosting
command line to indicate the level we should execute in.
Cc: Julian Armistead <julian.armistead@linaro.org>
Cc: Jim MacArthur <jim.macarthur@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v3
- create system stack so we _exit cleanly
- normalise EL string before compares
- catch when we start in a lower EL than we asked for
- default to EL1 when arg unclear
v2
- allow tests to control the final EL we end up at
- use tabs consistently
- validate command line arg is between 1 and 3
---
tests/tcg/aarch64/Makefile.softmmu-target | 3 +-
tests/tcg/aarch64/system/boot.S | 171 +++++++++++++++++++++-
2 files changed, 168 insertions(+), 6 deletions(-)
diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/Makefile.softmmu-target
index 9c52475b7a..f7a7d2b800 100644
--- a/tests/tcg/aarch64/Makefile.softmmu-target
+++ b/tests/tcg/aarch64/Makefile.softmmu-target
@@ -68,7 +68,8 @@ run-plugin-semiconsole-with-%: semiconsole
# vtimer test needs EL2
QEMU_EL2_MACHINE=-machine virt,virtualization=on,gic-version=2 -cpu cortex-a57 -smp 4
-run-vtimer: QEMU_OPTS=$(QEMU_EL2_MACHINE) $(QEMU_BASE_ARGS) -kernel
+QEMU_EL2_BASE_ARGS=-semihosting-config enable=on,target=native,chardev=output,arg="2"
+run-vtimer: QEMU_OPTS=$(QEMU_EL2_MACHINE) $(QEMU_EL2_BASE_ARGS) -kernel
# Simple Record/Replay Test
.PHONY: memory-record
diff --git a/tests/tcg/aarch64/system/boot.S b/tests/tcg/aarch64/system/boot.S
index a5df9c173d..78380a6f75 100644
--- a/tests/tcg/aarch64/system/boot.S
+++ b/tests/tcg/aarch64/system/boot.S
@@ -16,6 +16,7 @@
#define semihosting_call hlt 0xf000
#define SYS_WRITEC 0x03 /* character to debug channel */
#define SYS_WRITE0 0x04 /* string to debug channel */
+#define SYS_GET_CMDLINE 0x15 /* get command line */
#define SYS_EXIT 0x18
.align 12
@@ -70,21 +71,171 @@ lower_a32_sync:
lower_a32_irq:
lower_a32_fiq:
lower_a32_serror:
+ adr x1, .unexp_excp
+exit_msg:
mov x0, SYS_WRITE0
- adr x1, .error
semihosting_call
mov x0, 1 /* EXIT_FAILURE */
bl _exit
/* never returns */
.section .rodata
-.error:
- .string "Terminated by exception.\n"
+.unexp_excp:
+ .string "Unexpected exception.\n"
+.high_el_msg:
+ .string "Started in lower EL than requested.\n"
+
+ .align 8
+.get_cmd:
+ .quad cmdline
+ .quad 128
.text
.align 4
.global __start
__start:
+ /*
+ * Initialise the stack for whatever EL we are in before
+ * anything else, we need it to be able to _exit cleanly.
+ * It's smaller than the stack we pass to the C code but we
+ * don't need much.
+ */
+ adrp x0, system_stack_end
+ add x0, x0, :lo12:system_stack_end
+ mov sp, x0
+
+ /*
+ * The test can set the semihosting command line to the target
+ * EL needed for the test. However if no semihosting args are set we will
+ * end up with -kernel/-append data (see semihosting_arg_fallback).
+ * Keep the normalised target in w11.
+ */
+ mov x0, SYS_GET_CMDLINE
+ adr x1, .get_cmd
+ semihosting_call
+ adrp x10, cmdline
+ add x10, x10, :lo12:cmdline
+ ldrb w11, [x10]
+
+ /* sanity check, normalise char to EL, clamp to 1 if outside range */
+ subs w11, w11, #'0'
+ b.lt el_default
+ cmp w11, #3
+ b.gt el_default
+ b 1f
+
+el_high:
+ adr x1, .high_el_msg
+ b exit_msg
+
+el_default:
+ mov w11, #1
+
+1:
+ /* Determine current Exception Level */
+ mrs x0, CurrentEL
+ lsr x0, x0, #2 /* CurrentEL[3:2] contains the current EL */
+
+ /* Are we already in a lower EL than we want? */
+ cmp w11, w0
+ bgt el_high
+
+ /* Branch based on current EL */
+ cmp x0, #3
+ b.eq setup_el3
+ cmp x0, #2
+ b.eq setup_el2
+ cmp x0, #1
+ b.eq at_testel /* Already at EL1, skip transition */
+ /* Should not be at EL0 - error out */
+ b curr_sp0_sync
+
+setup_el3:
+ /* Ensure we trap if we get anything wrong */
+ adr x0, vector_table
+ msr vbar_el3, x0
+
+ /* Does the test want to be at EL3? */
+ cmp w11, #3
+ beq at_testel
+
+ /* Configure EL3 to for lower states (EL2 or EL1) */
+ mrs x0, scr_el3
+ orr x0, x0, #(1 << 10) /* RW = 1: EL2/EL1 execution state is AArch64 */
+ orr x0, x0, #(1 << 0) /* NS = 1: Non-secure state */
+ msr scr_el3, x0
+
+ /*
+ * We need to check if EL2 is actually enabled via ID_AA64PFR0_EL1,
+ * otherwise we should just jump straight to EL1.
+ */
+ mrs x0, id_aa64pfr0_el1
+ ubfx x0, x0, #8, #4 /* Extract EL2 field (bits 11:8) */
+ cbz x0, el2_not_present /* If field is 0 no EL2 */
+
+
+ /* Prepare SPSR for exception return to EL2 */
+ mov x0, #0x3c9 /* DAIF bits and EL2h mode (9) */
+ msr spsr_el3, x0
+
+ /* Set EL2 entry point */
+ adr x0, setup_el2
+ msr elr_el3, x0
+
+ /* Return to EL2 */
+ eret
+ nop
+
+el2_not_present:
+ /* Initialize SCTLR_EL1 with reset value */
+ msr sctlr_el1, xzr
+
+ /* Set EL1 entry point */
+ adr x0, at_testel
+ msr elr_el3, x0
+
+ /* Prepare SPSR for exception return to EL1h with interrupts masked */
+ mov x0, #0x3c5 /* DAIF bits and EL1h mode (5) */
+ msr spsr_el3, x0
+
+ isb /* Synchronization barrier */
+ eret /* Jump to EL1 */
+
+setup_el2:
+ /* Ensure we trap if we get anything wrong */
+ adr x0, vector_table
+ msr vbar_el2, x0
+
+ /* Does the test want to be at EL2? */
+ cmp w11, #2
+ beq at_testel
+
+ /* Configure EL2 to allow transition to EL1 */
+ mrs x0, hcr_el2
+ orr x0, x0, #(1 << 31) /* RW = 1: EL1 execution state is AArch64 */
+ msr hcr_el2, x0
+
+ /* Initialize SCTLR_EL1 with reset value */
+ msr sctlr_el1, xzr
+
+ /* Set EL1 entry point */
+ adr x0, at_testel
+ msr elr_el2, x0
+
+ /* Prepare SPSR for exception return to EL1 */
+ mov x0, #(0x5 << 0) /* EL1h (SPx), with interrupts disabled */
+ msr spsr_el2, x0
+
+ /* Return to EL1 */
+ eret
+
+ nop
+
+ /*
+ * At the target EL for the test, usually EL1. Note we still
+ * set everything up as if we were at EL1.
+ */
+at_testel:
/* Installs a table of exception vectors to catch and handle all
exceptions by terminating the process with a diagnostic. */
adr x0, vector_table
@@ -100,7 +251,7 @@ __start:
* maps RAM to the first Gb. The stage2 tables have two 2mb
* translation block entries covering a series of adjacent
* 4k pages.
- */
+ */
/* Stage 1 entry: indexed by IA[38:30] */
adr x1, . /* phys address */
@@ -198,7 +349,8 @@ __start:
orr x0, x0, #(3 << 16)
msr cpacr_el1, x0
- /* Setup some stack space and enter the test code.
+ /*
+ * Setup some stack space before we enter the test code.
* Assume everything except the return value is garbage when we
* return, we won't need it.
*/
@@ -233,6 +385,11 @@ __sys_outc:
ret
.data
+
+ .align 8
+cmdline:
+ .space 128, 0
+
.align 12
/* Translation table
@@ -246,6 +403,10 @@ ttb_stage2:
.space 4096, 0
.align 12
+system_stack:
+ .space 4096, 0
+system_stack_end:
+
stack:
.space 65536, 0
stack_end:
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (2 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 03/20] tests/tcg: make aarch64 boot.S handle different starting modes Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:19 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps Alex Bennée
` (15 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Nabih Estefan,
Richard Henderson
From: Nabih Estefan <nabihestefan@google.com>
../tests/qtest/libqos/igb.c:106:5: runtime error: load of misaligned address 0x562040be8e33 for type 'uint32_t', which requires 4 byte alignment
Instead of straight casting the uint8_t array, we can use ldl_le_p and
lduw_l_p to assure the unaligned access working properly against
uint32_t and uint16_t.
Signed-off-by: Nabih Estefan <nabihestefan@google.com>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20250429155621.2028198-1-nabihestefan@google.com>
[AJB: fix commit message, remove unneeded casts]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- change title to reflect test that failed
- re-phrase ldl functions to assure unaligned works
- remove excess ()'s
---
tests/qtest/libqos/igb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/qtest/libqos/igb.c b/tests/qtest/libqos/igb.c
index f40c4ec4cd..ab3ef6f0c3 100644
--- a/tests/qtest/libqos/igb.c
+++ b/tests/qtest/libqos/igb.c
@@ -104,10 +104,10 @@ static void igb_pci_start_hw(QOSGraphObject *obj)
e1000e_macreg_write(&d->e1000e, E1000_RDT(0), 0);
e1000e_macreg_write(&d->e1000e, E1000_RDH(0), 0);
e1000e_macreg_write(&d->e1000e, E1000_RA,
- le32_to_cpu(*(uint32_t *)address));
+ ldl_le_p(address));
e1000e_macreg_write(&d->e1000e, E1000_RA + 4,
E1000_RAH_AV | E1000_RAH_POOL_1 |
- le16_to_cpu(*(uint16_t *)(address + 4)));
+ lduw_le_p(address + 4));
/* Set supported receive descriptor mode */
e1000e_macreg_write(&d->e1000e,
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (3 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:37 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 06/20] tests/functional: Add PCI hotplug test for aarch64 Alex Bennée
` (14 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
The user can run a subset of the tcg tests directly, e.g.:
make run-tcg-tests-hexagon-linux-user
but in this case we fail if there has not been a full build to ensure
all the test-plugins are there. Fix the dependency to ensure we always
will build them before running tests.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
tests/Makefile.include | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 23fb722d42..7f7f62cbf6 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -46,7 +46,7 @@ $(foreach TARGET,$(TCG_TESTS_TARGETS), \
$(eval $(BUILD_DIR)/tests/tcg/config-$(TARGET).mak: config-host.mak))
.PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%)
-$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak
+$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak test-plugins
$(call quiet-command, \
$(MAKE) -C tests/tcg/$* $(SUBDIR_MAKEFLAGS), \
"BUILD","$* guest-tests")
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 06/20] tests/functional: Add PCI hotplug test for aarch64
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (4 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:43 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg Alex Bennée
` (13 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Eric Auger
From: Gustavo Romero <gustavo.romero@linaro.org>
Add a functional test, aarch64_hotplug_pci, to exercise PCI hotplug and
hot-unplug on arm64.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Message-Id: <20250512144629.182340-1-gustavo.romero@linaro.org>
[AJB: add qemu-arm link]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- add qemu-arm link to MAINTAINERS
---
MAINTAINERS | 6 ++
tests/functional/meson.build | 1 +
tests/functional/test_aarch64_hotplug_pci.py | 74 ++++++++++++++++++++
3 files changed, 81 insertions(+)
create mode 100755 tests/functional/test_aarch64_hotplug_pci.py
diff --git a/MAINTAINERS b/MAINTAINERS
index 7060cf49b9..818d7b9d5f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2078,6 +2078,12 @@ S: Supported
F: include/hw/pci/pcie_doe.h
F: hw/pci/pcie_doe.c
+ARM PCI Hotplug
+M: Gustavo Romero <gustavo.romero@linaro.org>
+L: qemu-arm@nongnu.org
+S: Supported
+F: tests/functional/test_aarch64_hotplug_pci.py
+
ACPI/SMBIOS
M: Michael S. Tsirkin <mst@redhat.com>
M: Igor Mammedov <imammedo@redhat.com>
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 52b4706cfe..2d68840fa2 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -83,6 +83,7 @@ tests_aarch64_system_quick = [
tests_aarch64_system_thorough = [
'aarch64_aspeed_ast2700',
'aarch64_aspeed_ast2700fc',
+ 'aarch64_hotplug_pci',
'aarch64_imx8mp_evk',
'aarch64_raspi3',
'aarch64_raspi4',
diff --git a/tests/functional/test_aarch64_hotplug_pci.py b/tests/functional/test_aarch64_hotplug_pci.py
new file mode 100755
index 0000000000..fa1bb62c8f
--- /dev/null
+++ b/tests/functional/test_aarch64_hotplug_pci.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# The test hotplugs a PCI device and checks it on a Linux guest.
+#
+# Copyright (c) 2025 Linaro Ltd.
+#
+# Author:
+# Gustavo Romero <gustavo.romero@linaro.org>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later. See the COPYING file in the top-level directory.
+
+from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern
+from qemu_test import BUILD_DIR
+
+class HotplugPCI(LinuxKernelTest):
+
+ ASSET_KERNEL = Asset(
+ ('https://ftp.debian.org/debian/dists/stable/main/installer-arm64/'
+ 'current/images/netboot/debian-installer/arm64/linux'),
+ '3821d4db56d42c6a4eac62f31846e35465940afd87746b4cfcdf5c9eca3117b2')
+
+ ASSET_INITRD = Asset(
+ ('https://ftp.debian.org/debian/dists/stable/main/installer-arm64/'
+ 'current/images/netboot/debian-installer/arm64/initrd.gz'),
+ '2583ec22b45265ad69e82f198674f53d4cd85be124fe012eedc2fd91156bc4b4')
+
+ def test_hotplug_pci(self):
+
+ self.set_machine('virt')
+ self.vm.add_args('-m', '512M')
+ self.vm.add_args('-cpu', 'cortex-a57')
+ self.vm.add_args('-append',
+ 'console=ttyAMA0,115200 init=/bin/sh')
+ self.vm.add_args('-device',
+ 'pcie-root-port,bus=pcie.0,chassis=1,slot=1,id=pcie.1')
+ self.vm.add_args('-bios', self.build_file('pc-bios',
+ 'edk2-aarch64-code.fd'))
+
+ # BusyBox prompt
+ prompt = "~ #"
+ self.launch_kernel(self.ASSET_KERNEL.fetch(),
+ self.ASSET_INITRD.fetch(),
+ wait_for=prompt)
+
+ # Check for initial state: 2 network adapters, lo and enp0s1.
+ exec_command_and_wait_for_pattern(self,
+ 'ls -l /sys/class/net | wc -l',
+ '2')
+
+ # Hotplug one network adapter to the root port, i.e. pcie.1 bus.
+ self.vm.cmd('device_add',
+ driver='virtio-net-pci',
+ bus='pcie.1',
+ addr=0,
+ id='na')
+ # Wait for the kernel to recognize the new device.
+ self.wait_for_console_pattern('virtio-pci')
+ self.wait_for_console_pattern('virtio_net')
+
+ # Check if there is a new network adapter.
+ exec_command_and_wait_for_pattern(self,
+ 'ls -l /sys/class/net | wc -l',
+ '3')
+
+ self.vm.cmd('device_del', id='na')
+ exec_command_and_wait_for_pattern(self,
+ 'ls -l /sys/class/net | wc -l',
+ '2')
+
+if __name__ == '__main__':
+ LinuxKernelTest.main()
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (5 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 06/20] tests/functional: Add PCI hotplug test for aarch64 Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:45 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 08/20] contrib/plugins: allow setting of instructions per quantum Alex Bennée
` (12 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
It's easy to get lost in zeros while setting the numbers of
instructions per second. Add a scaling suffix to make things simpler.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
v2
- normalise the suffix before a full strcmp0
- check endptr actually set
- fix checkpatch
- scale_entry -> ScaleEntry
- drop hz from suffix
---
contrib/plugins/ips.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c
index e5297dbb01..eb4418c25b 100644
--- a/contrib/plugins/ips.c
+++ b/contrib/plugins/ips.c
@@ -129,6 +129,18 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata)
qemu_plugin_scoreboard_free(vcpus);
}
+typedef struct {
+ const char *suffix;
+ unsigned long multipler;
+} ScaleEntry;
+
+/* a bit like units.h but not binary */
+static ScaleEntry scales[] = {
+ { "k", 1000 },
+ { "m", 1000 * 1000 },
+ { "g", 1000 * 1000 * 1000 },
+};
+
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
const qemu_info_t *info, int argc,
char **argv)
@@ -137,12 +149,32 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
char *opt = argv[i];
g_auto(GStrv) tokens = g_strsplit(opt, "=", 2);
if (g_strcmp0(tokens[0], "ips") == 0) {
- max_insn_per_second = g_ascii_strtoull(tokens[1], NULL, 10);
+ char *endptr = NULL;
+ max_insn_per_second = g_ascii_strtoull(tokens[1], &endptr, 10);
if (!max_insn_per_second && errno) {
fprintf(stderr, "%s: couldn't parse %s (%s)\n",
__func__, tokens[1], g_strerror(errno));
return -1;
}
+
+ if (endptr && *endptr != 0) {
+ g_autofree gchar *lower = g_utf8_strdown(endptr, -1);
+ unsigned long scale = 0;
+
+ for (int j = 0; j < G_N_ELEMENTS(scales); j++) {
+ if (g_strcmp0(lower, scales[j].suffix) == 0) {
+ scale = scales[j].multipler;
+ break;
+ }
+ }
+
+ if (scale) {
+ max_insn_per_second *= scale;
+ } else {
+ fprintf(stderr, "bad suffix: %s\n", endptr);
+ return -1;
+ }
+ }
} else {
fprintf(stderr, "option parsing failed: %s\n", opt);
return -1;
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 08/20] contrib/plugins: allow setting of instructions per quantum
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (6 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:55 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 09/20] MAINTAINERS: add myself to virtio-gpu for Odd Fixes Alex Bennée
` (11 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
The default is we update time every 1/10th of a second or so. However
for some cases we might want to update time more frequently. Allow
this to be set via the command line through the ipq argument.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
v3
- error checking for ipq
v2
- checkpatch fixes.
---
docs/about/emulation.rst | 4 ++++
contrib/plugins/ips.c | 15 ++++++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst
index a72591ee4d..456d01d5b0 100644
--- a/docs/about/emulation.rst
+++ b/docs/about/emulation.rst
@@ -811,6 +811,10 @@ This plugin can limit the number of Instructions Per Second that are executed::
* - ips=N
- Maximum number of instructions per cpu that can be executed in one second.
The plugin will sleep when the given number of instructions is reached.
+ * - ipq=N
+ - Instructions per quantum. How many instructions before we re-calculate time.
+ The lower the number the more accurate time will be, but the less efficient the plugin.
+ Defaults to ips/10
Other emulation features
------------------------
diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c
index eb4418c25b..f1523cbee3 100644
--- a/contrib/plugins/ips.c
+++ b/contrib/plugins/ips.c
@@ -145,6 +145,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
const qemu_info_t *info, int argc,
char **argv)
{
+ bool ipq_set = false;
+
for (int i = 0; i < argc; i++) {
char *opt = argv[i];
g_auto(GStrv) tokens = g_strsplit(opt, "=", 2);
@@ -175,6 +177,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
return -1;
}
}
+ } else if (g_strcmp0(tokens[0], "ipq") == 0) {
+ max_insn_per_quantum = g_ascii_strtoull(tokens[1], NULL, 10);
+
+ if (max_insn_per_quantum == 0 || max_insn_per_quantum == G_MAXUINT64) {
+ fprintf(stderr, "bad ipq value: %s\n", g_strerror(errno));
+ return -1;
+ }
+ ipq_set = true;
} else {
fprintf(stderr, "option parsing failed: %s\n", opt);
return -1;
@@ -182,7 +192,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
}
vcpus = qemu_plugin_scoreboard_new(sizeof(vCPUTime));
- max_insn_per_quantum = max_insn_per_second / NUM_TIME_UPDATE_PER_SEC;
+
+ if (!ipq_set) {
+ max_insn_per_quantum = max_insn_per_second / NUM_TIME_UPDATE_PER_SEC;
+ }
if (max_insn_per_quantum == 0) {
fprintf(stderr, "minimum of %d instructions per second needed\n",
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 09/20] MAINTAINERS: add myself to virtio-gpu for Odd Fixes
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (7 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 08/20] contrib/plugins: allow setting of instructions per quantum Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:16 ` Markus Armbruster
2025-05-21 16:42 ` [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers Alex Bennée
` (10 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
Seeing as I've taken a few patches to here now I might as well put
myself forward to maintain virtio-gpu. I've marked it as Odd Fixes as
it is not my core focus. If someone with more GPU experience comes
forward we can always update again.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
v2
- s/M:/S:/ for the maintainer entry
---
MAINTAINERS | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 818d7b9d5f..8dfb393c06 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2673,7 +2673,8 @@ F: hw/display/ramfb*.c
F: include/hw/display/ramfb.h
virtio-gpu
-S: Orphan
+M: Alex Bennée <alex.bennee@linaro.org>
+S: Odd Fixes
F: hw/display/virtio-gpu*
F: hw/display/virtio-vga.*
F: include/hw/virtio/virtio-gpu.h
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (8 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 09/20] MAINTAINERS: add myself to virtio-gpu for Odd Fixes Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:16 ` Markus Armbruster
` (2 more replies)
2025-05-21 16:42 ` [PATCH v3 11/20] hw/display: re-arrange memory region tracking Alex Bennée
` (9 subsequent siblings)
19 siblings, 3 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
Thanks for volunteering to help.
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
MAINTAINERS | 2 ++
1 file changed, 2 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 8dfb393c06..a14e2796e0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2674,6 +2674,8 @@ F: include/hw/display/ramfb.h
virtio-gpu
M: Alex Bennée <alex.bennee@linaro.org>
+R: Akihiko Odaki <akihiko.odaki@daynix.com>
+R: Dmitry Osipenko <dmitry.osipenko@collabora.com>
S: Odd Fixes
F: hw/display/virtio-gpu*
F: hw/display/virtio-vga.*
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 11/20] hw/display: re-arrange memory region tracking
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (9 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob Alex Bennée
` (8 subsequent siblings)
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Manos Pitsidianakis,
qemu-stable
QOM objects can be embedded in other QOM objects and managed as part
of their lifetime but this isn't the case for
virtio_gpu_virgl_hostmem_region. However before we can split it out we
need some other way of associating the wider data structure with the
memory region.
Fortunately MemoryRegion has an opaque pointer. This is passed down to
MemoryRegionOps for device type regions but is unused in the
memory_region_init_ram_ptr() case. Use the opaque to carry the
reference and allow the final MemoryRegion object to be reaped when
its reference count is cleared.
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250410122643.1747913-2-manos.pitsidianakis@linaro.org>
Cc: qemu-stable@nongnu.org
---
include/system/memory.h | 1 +
hw/display/virtio-gpu-virgl.c | 23 ++++++++---------------
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/include/system/memory.h b/include/system/memory.h
index fbbf4cf911..b3cef1acb5 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -783,6 +783,7 @@ struct MemoryRegion {
DeviceState *dev;
const MemoryRegionOps *ops;
+ /* opaque data, used by backends like @ops */
void *opaque;
MemoryRegion *container;
int mapped_via_alias; /* Mapped via an alias, container might be NULL */
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 145a0b3879..71a7500de9 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -52,17 +52,11 @@ virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
#if VIRGL_VERSION_MAJOR >= 1
struct virtio_gpu_virgl_hostmem_region {
- MemoryRegion mr;
+ MemoryRegion *mr;
struct VirtIOGPU *g;
bool finish_unmapping;
};
-static struct virtio_gpu_virgl_hostmem_region *
-to_hostmem_region(MemoryRegion *mr)
-{
- return container_of(mr, struct virtio_gpu_virgl_hostmem_region, mr);
-}
-
static void virtio_gpu_virgl_resume_cmdq_bh(void *opaque)
{
VirtIOGPU *g = opaque;
@@ -73,14 +67,12 @@ static void virtio_gpu_virgl_resume_cmdq_bh(void *opaque)
static void virtio_gpu_virgl_hostmem_region_free(void *obj)
{
MemoryRegion *mr = MEMORY_REGION(obj);
- struct virtio_gpu_virgl_hostmem_region *vmr;
+ struct virtio_gpu_virgl_hostmem_region *vmr = mr->opaque;
VirtIOGPUBase *b;
VirtIOGPUGL *gl;
- vmr = to_hostmem_region(mr);
- vmr->finish_unmapping = true;
-
b = VIRTIO_GPU_BASE(vmr->g);
+ vmr->finish_unmapping = true;
b->renderer_blocked--;
/*
@@ -118,8 +110,8 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
vmr = g_new0(struct virtio_gpu_virgl_hostmem_region, 1);
vmr->g = g;
+ mr = g_new0(MemoryRegion, 1);
- mr = &vmr->mr;
memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
memory_region_add_subregion(&b->hostmem, offset, mr);
memory_region_set_enabled(mr, true);
@@ -131,7 +123,9 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
* command processing until MR is fully unreferenced and freed.
*/
OBJECT(mr)->free = virtio_gpu_virgl_hostmem_region_free;
+ mr->opaque = vmr;
+ vmr->mr = mr;
res->mr = mr;
return 0;
@@ -142,16 +136,15 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
struct virtio_gpu_virgl_resource *res,
bool *cmd_suspended)
{
- struct virtio_gpu_virgl_hostmem_region *vmr;
VirtIOGPUBase *b = VIRTIO_GPU_BASE(g);
MemoryRegion *mr = res->mr;
+ struct virtio_gpu_virgl_hostmem_region *vmr;
int ret;
if (!mr) {
return 0;
}
-
- vmr = to_hostmem_region(res->mr);
+ vmr = mr->opaque;
/*
* Perform async unmapping in 3 steps:
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (10 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 11/20] hw/display: re-arrange memory region tracking Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 5:59 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 13/20] virtio-gpu: refactor async blob unmapping Alex Bennée
` (7 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Manos Pitsidianakis,
qemu-stable
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit fixes an indefinite hang when using VIRTIO GPU blob objects
under TCG in certain conditions.
The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
MemoryRegion and attaches it to an offset on a PCI BAR of the
VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
it.
Because virglrenderer commands are not thread-safe they are only
called on the main context and QEMU performs the cleanup in three steps
to prevent a use-after-free scenario where the guest can access the
region after it’s unmapped:
1. From the main context, the region’s field finish_unmapping is false
by default, so it sets a variable cmd_suspended, increases the
renderer_blocked variable, deletes the blob subregion, and unparents
the blob subregion causing its reference count to decrement.
2. From an RCU context, the MemoryView gets freed, the FlatView gets
recalculated, the free callback of the blob region
virtio_gpu_virgl_hostmem_region_free is called which sets the
region’s field finish_unmapping to true, allowing the main thread
context to finish replying to the command
3. From the main context, the command is processed again, but this time
finish_unmapping is true, so virgl_renderer_resource_unmap can be
called and a response is sent to the guest.
It happens so that under TCG, if the guest has no timers configured (and
thus no interrupt will cause the CPU to exit), the RCU thread does not
have enough time to grab the locks and recalculate the FlatView.
That’s not a big problem in practice since most guests will assume a
response will happen later in time and go on to do different things,
potentially triggering interrupts and allowing the RCU context to run.
If the guest waits for the unmap command to complete though, it blocks
indefinitely. Attaching to the QEMU monitor and force quitting the guest
allows the cleanup to continue.
There's no reason why the FlatView recalculation can't occur right away
when we delete the blob subregion, however. It does not, because when we
create the subregion we set the object as its own parent:
memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
The extra reference is what prevents freeing the memory region object in
the memory transaction of deleting the subregion.
This commit changes the owner object to the device, which removes the
extra owner reference in the memory region and causes the MR to be
freed right away in the main context.
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
Cc: qemu-stable@nongnu.org
---
hw/display/virtio-gpu-virgl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 71a7500de9..8fbe4e70cc 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
vmr->g = g;
mr = g_new0(MemoryRegion, 1);
- memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
+ memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
memory_region_add_subregion(&b->hostmem, offset, mr);
memory_region_set_enabled(mr, true);
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 13/20] virtio-gpu: refactor async blob unmapping
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (11 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 14/20] ui/gtk-gl-area: Remove extra draw call in refresh Alex Bennée
` (6 subsequent siblings)
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Manos Pitsidianakis,
qemu-stable
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Change the 3 part async cleanup of a blob memory mapping to check if the
unmapping has finished already after deleting the subregion; this
condition allows us to skip suspending the command and responding to the
guest right away.
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20250410122643.1747913-4-manos.pitsidianakis@linaro.org>
Cc: qemu-stable@nongnu.org
---
hw/display/virtio-gpu-virgl.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 8fbe4e70cc..32a32879f7 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -155,7 +155,32 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
* asynchronously by virtio_gpu_virgl_hostmem_region_free().
* 3. Finish the unmapping with final virgl_renderer_resource_unmap().
*/
+
+ /* 1. Check if we should start unmapping now */
+ if (!vmr->finish_unmapping) {
+ /* begin async unmapping. render will be unblocked once MR is freed */
+ b->renderer_blocked++;
+
+ memory_region_set_enabled(mr, false);
+ memory_region_del_subregion(&b->hostmem, mr);
+ object_unparent(OBJECT(mr));
+ /*
+ * The unmapping might have already finished at this point if no one
+ * else held a reference to the MR; if yes, we can skip suspending the
+ * command and unmap the resource right away.
+ */
+ *cmd_suspended = !vmr->finish_unmapping;
+ }
+
+ /*
+ * 2. if virtio_gpu_virgl_hostmem_region_free hasn't been executed yet, we
+ * have marked the command to be re-processed later by setting
+ * cmd_suspended to true. The freeing callback will be called from RCU
+ * context later.
+ */
+
if (vmr->finish_unmapping) {
+ /* 3. MemoryRegion has been freed, so finish unmapping */
res->mr = NULL;
g_free(vmr);
@@ -166,16 +191,6 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
__func__, strerror(-ret));
return ret;
}
- } else {
- *cmd_suspended = true;
-
- /* render will be unblocked once MR is freed */
- b->renderer_blocked++;
-
- /* memory region owns self res->mr object and frees it by itself */
- memory_region_set_enabled(mr, false);
- memory_region_del_subregion(&b->hostmem, mr);
- object_unparent(OBJECT(mr));
}
return 0;
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 14/20] ui/gtk-gl-area: Remove extra draw call in refresh
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (12 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 13/20] virtio-gpu: refactor async blob unmapping Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 15/20] virtio-gpu: support context init multiple timeline Alex Bennée
` (5 subsequent siblings)
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Dongwon Kim, Vivek Kasireddy
From: Dongwon Kim <dongwon.kim@intel.com>
This partially reverts commit 77bf310084dad38b3a2badf01766c659056f1cf2
which causes some guest display corruption when gtk-gl-area
is used for GTK rendering (e.g. Wayland Compositor) possibly due to
simulataneous accesses on the guest frame buffer by host compositor
and the guest.
Fixes: 77bf310084 ("ui/gtk: Draw guest frame at refresh cycle")
Reported-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reported-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
Message-Id: <20250214170813.2234754-1-dongwon.kim@intel.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
ui/gtk-gl-area.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 2c9a0db425..9f7dc697f2 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -129,7 +129,6 @@ void gd_gl_area_refresh(DisplayChangeListener *dcl)
if (vc->gfx.guest_fb.dmabuf &&
qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) {
- gd_gl_area_draw(vc);
return;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 15/20] virtio-gpu: support context init multiple timeline
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (13 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 14/20] ui/gtk-gl-area: Remove extra draw call in refresh Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 16/20] include/exec: fix assert in size_memop Alex Bennée
` (4 subsequent siblings)
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Yiwei Zhang, qemu-stable
From: Yiwei Zhang <zzyiwei@gmail.com>
Venus and later native contexts have their own fence context along with
multiple timelines within. Fences wtih VIRTIO_GPU_FLAG_INFO_RING_IDX in
the flags must be dispatched to be created on the target context. Fence
signaling also has to be handled on the specific timeline within that
target context.
Before this change, venus fencing is completely broken if the host
driver doesn't support implicit fencing with external memory objects.
Frames can go backwards along with random artifacts on screen if the
host driver doesn't attach an implicit fence to the render target. The
symptom could be hidden by certain guest wsi backend that waits on a
venus native VkFence object for the actual payload with limited present
modes or under special configs. e.g. x11 mailbox or xwayland.
After this change, everything related to venus fencing starts making
sense. Confirmed this via guest and host side perfetto tracing.
Cc: <qemu-stable@nongnu.org>
Fixes: 94d0ea1c1928 ("virtio-gpu: Support Venus context")
Signed-off-by: Yiwei Zhang <zzyiwei@gmail.com>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Message-Id: <20250518152651.334115-1-zzyiwei@gmail.com>
[AJB: remove version history from commit message]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
hw/display/virtio-gpu-virgl.c | 44 +++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 32a32879f7..900577a38c 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -978,6 +978,15 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
}
trace_virtio_gpu_fence_ctrl(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
+#if VIRGL_VERSION_MAJOR >= 1
+ if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX) {
+ virgl_renderer_context_create_fence(cmd->cmd_hdr.ctx_id,
+ VIRGL_RENDERER_FENCE_FLAG_MERGEABLE,
+ cmd->cmd_hdr.ring_idx,
+ cmd->cmd_hdr.fence_id);
+ return;
+ }
+#endif
virgl_renderer_create_fence(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
}
@@ -991,6 +1000,11 @@ static void virgl_write_fence(void *opaque, uint32_t fence)
* the guest can end up emitting fences out of order
* so we should check all fenced cmds not just the first one.
*/
+#if VIRGL_VERSION_MAJOR >= 1
+ if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX) {
+ continue;
+ }
+#endif
if (cmd->cmd_hdr.fence_id > fence) {
continue;
}
@@ -1005,6 +1019,29 @@ static void virgl_write_fence(void *opaque, uint32_t fence)
}
}
+#if VIRGL_VERSION_MAJOR >= 1
+static void virgl_write_context_fence(void *opaque, uint32_t ctx_id,
+ uint32_t ring_idx, uint64_t fence_id) {
+ VirtIOGPU *g = opaque;
+ struct virtio_gpu_ctrl_command *cmd, *tmp;
+
+ QTAILQ_FOREACH_SAFE(cmd, &g->fenceq, next, tmp) {
+ if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX &&
+ cmd->cmd_hdr.ctx_id == ctx_id && cmd->cmd_hdr.ring_idx == ring_idx &&
+ cmd->cmd_hdr.fence_id <= fence_id) {
+ trace_virtio_gpu_fence_resp(cmd->cmd_hdr.fence_id);
+ virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA);
+ QTAILQ_REMOVE(&g->fenceq, cmd, next);
+ g_free(cmd);
+ g->inflight--;
+ if (virtio_gpu_stats_enabled(g->parent_obj.conf)) {
+ trace_virtio_gpu_dec_inflight_fences(g->inflight);
+ }
+ }
+ }
+}
+#endif
+
static virgl_renderer_gl_context
virgl_create_context(void *opaque, int scanout_idx,
struct virgl_renderer_gl_ctx_param *params)
@@ -1039,11 +1076,18 @@ static int virgl_make_context_current(void *opaque, int scanout_idx,
}
static struct virgl_renderer_callbacks virtio_gpu_3d_cbs = {
+#if VIRGL_VERSION_MAJOR >= 1
+ .version = 3,
+#else
.version = 1,
+#endif
.write_fence = virgl_write_fence,
.create_gl_context = virgl_create_context,
.destroy_gl_context = virgl_destroy_context,
.make_current = virgl_make_context_current,
+#if VIRGL_VERSION_MAJOR >= 1
+ .write_context_fence = virgl_write_context_fence,
+#endif
};
static void virtio_gpu_print_stats(void *opaque)
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 16/20] include/exec: fix assert in size_memop
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (14 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 15/20] virtio-gpu: support context init multiple timeline Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 6:07 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 17/20] include/gdbstub: fix include guard in commands.h Alex Bennée
` (3 subsequent siblings)
19 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Richard Henderson
We can handle larger sized memops now, expand the range of the assert.
Fixes: 4b473e0c60 (tcg: Expand MO_SIZE to 3 bits)
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
v2
- instead of 128 use 1 << MO_SIZE for future proofing
v3
- fix comment, 1 << MO_SIZE goes to 1024
---
include/exec/memop.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/exec/memop.h b/include/exec/memop.h
index 407a47d82c..e934bde809 100644
--- a/include/exec/memop.h
+++ b/include/exec/memop.h
@@ -162,8 +162,8 @@ static inline unsigned memop_size(MemOp op)
static inline MemOp size_memop(unsigned size)
{
#ifdef CONFIG_DEBUG_TCG
- /* Power of 2 up to 8. */
- assert((size & (size - 1)) == 0 && size >= 1 && size <= 8);
+ /* Power of 2 up to 1024 */
+ assert((size & (size - 1)) == 0 && size >= 1 && size <= (1 << MO_SIZE));
#endif
return (MemOp)ctz32(size);
}
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 17/20] include/gdbstub: fix include guard in commands.h
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (15 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 16/20] include/exec: fix assert in size_memop Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 18/20] gdbstub: assert earlier in handle_read_all_regs Alex Bennée
` (2 subsequent siblings)
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
include/gdbstub/commands.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/gdbstub/commands.h b/include/gdbstub/commands.h
index 40f0514fe9..bff3674872 100644
--- a/include/gdbstub/commands.h
+++ b/include/gdbstub/commands.h
@@ -1,5 +1,5 @@
#ifndef GDBSTUB_COMMANDS_H
-#define GDBSTUB
+#define GDBSTUB_COMMANDS_H
typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx);
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 18/20] gdbstub: assert earlier in handle_read_all_regs
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (16 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 17/20] include/gdbstub: fix include guard in commands.h Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet Alex Bennée
2025-05-21 16:42 ` [PATCH v3 20/20] gdbstub: update aarch64-core.xml Alex Bennée
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
When things go wrong we want to assert on the register that failed to
be able to figure out what went wrong.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
gdbstub/gdbstub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 565f6b33a9..6023c80d25 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -1343,8 +1343,8 @@ static void handle_read_all_regs(GArray *params, void *user_ctx)
len += gdb_read_register(gdbserver_state.g_cpu,
gdbserver_state.mem_buf,
reg_id);
+ g_assert(len == gdbserver_state.mem_buf->len);
}
- g_assert(len == gdbserver_state.mem_buf->len);
gdb_memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, len);
gdb_put_strbuf();
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (17 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 18/20] gdbstub: assert earlier in handle_read_all_regs Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
2025-05-22 6:29 ` Akihiko Odaki
2025-05-25 15:25 ` Philippe Mathieu-Daudé
2025-05-21 16:42 ` [PATCH v3 20/20] gdbstub: update aarch64-core.xml Alex Bennée
19 siblings, 2 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin,
Dominik 'Disconnect3d' Czarnota,
Patryk 'patryk4815' Sondej
From: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
This commit adds support for the `qGDBServerVersion` packet to the qemu
gdbstub which could be used by clients to detect the QEMU version
(and, e.g., use a workaround for known bugs).
This packet is not documented/standarized by GDB but it was implemented
by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
This has been implemented by Patryk, who I included in Co-authored-by
and who asked me to send the patch.
[0] https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
[1] https://github.com/pwndbg/pwndbg/issues/2648
Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com>
Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
Message-Id: <20250403191340.53343-1-dominik.b.czarnota@gmail.com>
[AJB: fix include, checkpatch linewrap]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
gdbstub/gdbstub.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 6023c80d25..def0b7e877 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -28,6 +28,7 @@
#include "qemu/cutils.h"
#include "qemu/module.h"
#include "qemu/error-report.h"
+#include "qemu/target-info.h"
#include "trace.h"
#include "exec/gdbstub.h"
#include "gdbstub/commands.h"
@@ -1597,6 +1598,18 @@ static void handle_query_threads(GArray *params, void *user_ctx)
gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu);
}
+static void handle_query_gdb_server_version(GArray *params, void *user_ctx)
+{
+#if defined(CONFIG_USER_ONLY)
+ g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;",
+ target_name(), QEMU_VERSION);
+#else
+ g_string_printf(gdbserver_state.str_buf, "name:qemu-system-%s;version:%s;",
+ target_name(), QEMU_VERSION);
+#endif
+ gdb_put_strbuf();
+}
+
static void handle_query_first_threads(GArray *params, void *user_ctx)
{
gdbserver_state.query_cpu = gdb_first_attached_cpu();
@@ -1842,6 +1855,10 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = {
.handler = handle_query_threads,
.cmd = "sThreadInfo",
},
+ {
+ .handler = handle_query_gdb_server_version,
+ .cmd = "GDBServerVersion",
+ },
{
.handler = handle_query_first_threads,
.cmd = "fThreadInfo",
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [PATCH v3 20/20] gdbstub: update aarch64-core.xml
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
` (18 preceding siblings ...)
2025-05-21 16:42 ` [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet Alex Bennée
@ 2025-05-21 16:42 ` Alex Bennée
19 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-21 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Pierrick Bouvier, Alex Bennée, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, Manos Pitsidianakis
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Update aarch64-core.xml to include field definitions for PSTATE, which
in gdb is modelled in the cpsr (current program status register)
pseudo-register, named after the actual cpsr register in armv7.
Defining the fields layout of the register allows easy inspection of for
example, the current exception level (EL):
For example. Before booting a Linux guest, EL=2, but after booting and
Ctrl-C'ing in gdb, we get EL=0:
(gdb) info registers $cpsr
cpsr 0x20402009 [ SP EL=2 BTYPE=0 PAN C ]
(gdb) cont
Continuing.
^C
Thread 2 received signal SIGINT, Interrupt.
0x0000ffffaaff286c in ?? ()
(gdb) info registers $cpsr
cpsr 0x20001000 [ EL=0 BTYPE=0 SSBS C ]
The aarch64-core.xml has been updated to match exactly the version
retrieved from upstream gdb, retrieved in 2025-05-19 from HEAD commit
9f4dc0b137c86f6ff2098cb1ab69442c69d6023d.
Link: https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/features/aarch64-core.xml;h=b8046510b9a085d30463d37b3ecc8d435f5fb7a4;hb=HEAD
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Message-Id: <20250519-gdbstub-aarch64-pstate-xml-v1-1-b4dbe87fe7c6@linaro.org>
[AJB: expanded upstream link]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
gdb-xml/aarch64-core.xml | 52 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/gdb-xml/aarch64-core.xml b/gdb-xml/aarch64-core.xml
index e1e9dc3f91..b8046510b9 100644
--- a/gdb-xml/aarch64-core.xml
+++ b/gdb-xml/aarch64-core.xml
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!-- Copyright (C) 2009-2012 Free Software Foundation, Inc.
+<!-- Copyright (C) 2009-2025 Free Software Foundation, Inc.
Contributed by ARM Ltd.
Copying and distribution of this file, with or without modification,
@@ -42,5 +42,53 @@
<reg name="sp" bitsize="64" type="data_ptr"/>
<reg name="pc" bitsize="64" type="code_ptr"/>
- <reg name="cpsr" bitsize="32"/>
+
+ <flags id="cpsr_flags" size="4">
+ <!-- Stack Pointer. -->
+ <field name="SP" start="0" end="0"/>
+
+ <!-- Exception Level. -->
+ <field name="EL" start="2" end="3"/>
+ <!-- Execution state. -->
+ <field name="nRW" start="4" end="4"/>
+
+ <!-- FIQ interrupt mask. -->
+ <field name="F" start="6" end="6"/>
+ <!-- IRQ interrupt mask. -->
+ <field name="I" start="7" end="7"/>
+ <!-- SError interrupt mask. -->
+ <field name="A" start="8" end="8"/>
+ <!-- Debug exception mask. -->
+ <field name="D" start="9" end="9"/>
+
+ <!-- ARMv8.5-A: Branch Target Identification BTYPE. -->
+ <field name="BTYPE" start="10" end="11"/>
+
+ <!-- ARMv8.0-A: Speculative Store Bypass. -->
+ <field name="SSBS" start="12" end="12"/>
+
+ <!-- Illegal Execution state. -->
+ <field name="IL" start="20" end="20"/>
+ <!-- Software Step. -->
+ <field name="SS" start="21" end="21"/>
+ <!-- ARMv8.1-A: Privileged Access Never. -->
+ <field name="PAN" start="22" end="22"/>
+ <!-- ARMv8.2-A: User Access Override. -->
+ <field name="UAO" start="23" end="23"/>
+ <!-- ARMv8.4-A: Data Independent Timing. -->
+ <field name="DIT" start="24" end="24"/>
+ <!-- ARMv8.5-A: Tag Check Override. -->
+ <field name="TCO" start="25" end="25"/>
+
+ <!-- Overflow Condition flag. -->
+ <field name="V" start="28" end="28"/>
+ <!-- Carry Condition flag. -->
+ <field name="C" start="29" end="29"/>
+ <!-- Zero Condition flag. -->
+ <field name="Z" start="30" end="30"/>
+ <!-- Negative Condition flag. -->
+ <field name="N" start="31" end="31"/>
+ </flags>
+ <reg name="cpsr" bitsize="32" type="cpsr_flags"/>
+
</feature>
--
2.39.5
^ permalink raw reply related [flat|nested] 52+ messages in thread
* Re: [PATCH v3 03/20] tests/tcg: make aarch64 boot.S handle different starting modes
2025-05-21 16:42 ` [PATCH v3 03/20] tests/tcg: make aarch64 boot.S handle different starting modes Alex Bennée
@ 2025-05-22 5:10 ` Akihiko Odaki
0 siblings, 0 replies; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:10 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Julian Armistead, Jim MacArthur
On 2025/05/22 1:42, Alex Bennée wrote:
> Currently the boot.S code assumes everything starts at EL1. This will
> break things like the memory test which will barf on unaligned memory
> access when run at a higher level.
>
> Adapt the boot code to do some basic verification of the starting mode
> and the minimal configuration to move to the lower exception levels.
> With this we can run the memory test with:
>
> -M virt,secure=on
> -M virt,secure=on,virtualization=on
> -M virt,virtualisation=on
>
> If a test needs to be at a particular EL it can use the semihosting
> command line to indicate the level we should execute in.
>
> Cc: Julian Armistead <julian.armistead@linaro.org>
> Cc: Jim MacArthur <jim.macarthur@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>
> ---
> v3
> - create system stack so we _exit cleanly
> - normalise EL string before compares
> - catch when we start in a lower EL than we asked for
> - default to EL1 when arg unclear
> v2
> - allow tests to control the final EL we end up at
> - use tabs consistently
> - validate command line arg is between 1 and 3
> ---
> tests/tcg/aarch64/Makefile.softmmu-target | 3 +-
> tests/tcg/aarch64/system/boot.S | 171 +++++++++++++++++++++-
> 2 files changed, 168 insertions(+), 6 deletions(-)
>
> diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/Makefile.softmmu-target
> index 9c52475b7a..f7a7d2b800 100644
> --- a/tests/tcg/aarch64/Makefile.softmmu-target
> +++ b/tests/tcg/aarch64/Makefile.softmmu-target
> @@ -68,7 +68,8 @@ run-plugin-semiconsole-with-%: semiconsole
>
> # vtimer test needs EL2
> QEMU_EL2_MACHINE=-machine virt,virtualization=on,gic-version=2 -cpu cortex-a57 -smp 4
> -run-vtimer: QEMU_OPTS=$(QEMU_EL2_MACHINE) $(QEMU_BASE_ARGS) -kernel
> +QEMU_EL2_BASE_ARGS=-semihosting-config enable=on,target=native,chardev=output,arg="2"
> +run-vtimer: QEMU_OPTS=$(QEMU_EL2_MACHINE) $(QEMU_EL2_BASE_ARGS) -kernel
>
> # Simple Record/Replay Test
> .PHONY: memory-record
> diff --git a/tests/tcg/aarch64/system/boot.S b/tests/tcg/aarch64/system/boot.S
> index a5df9c173d..78380a6f75 100644
> --- a/tests/tcg/aarch64/system/boot.S
> +++ b/tests/tcg/aarch64/system/boot.S
> @@ -16,6 +16,7 @@
> #define semihosting_call hlt 0xf000
> #define SYS_WRITEC 0x03 /* character to debug channel */
> #define SYS_WRITE0 0x04 /* string to debug channel */
> +#define SYS_GET_CMDLINE 0x15 /* get command line */
> #define SYS_EXIT 0x18
>
> .align 12
> @@ -70,21 +71,171 @@ lower_a32_sync:
> lower_a32_irq:
> lower_a32_fiq:
> lower_a32_serror:
> + adr x1, .unexp_excp
> +exit_msg:
> mov x0, SYS_WRITE0
> - adr x1, .error
> semihosting_call
> mov x0, 1 /* EXIT_FAILURE */
> bl _exit
> /* never returns */
>
> .section .rodata
> -.error:
> - .string "Terminated by exception.\n"
> +.unexp_excp:
> + .string "Unexpected exception.\n"
> +.high_el_msg:
> + .string "Started in lower EL than requested.\n"
> +
> + .align 8
.get_cmd may be put before strings to avoid unnecessary padding for
alignment.
> +.get_cmd:
I pointed out a style problem with this label in the last review:
> This label is prefixed with a dot, which is inconsistent with the other
> labels except ".error".
>
> I guess ".error" is prefixed with a dot to make it local, but a local
> symbol needs to be prefixed with ".L" instead according to:
> https://sourceware.org/binutils/docs-2.41/as/Symbol-Names.html#Local-
> Symbol-Names
>
> > A local symbol is any symbol beginning with certain local label
> > prefixes. By default, the local label prefix is ‘.L’ for ELF systems
> > or ‘L’ for traditional a.out systems, but each target may have its own
> > set of local label prefixes. On the HPPA local symbols begin with
> > ‘L$’.
> + .quad cmdline
> + .quad 128
>
> .text
> .align 4
> .global __start
> __start:
> + /*
> + * Initialise the stack for whatever EL we are in before
> + * anything else, we need it to be able to _exit cleanly.
> + * It's smaller than the stack we pass to the C code but we
> + * don't need much.
> + */
> + adrp x0, system_stack_end
> + add x0, x0, :lo12:system_stack_end
> + mov sp, x0
> +
> + /*
> + * The test can set the semihosting command line to the target
> + * EL needed for the test. However if no semihosting args are set we will
> + * end up with -kernel/-append data (see semihosting_arg_fallback).
> + * Keep the normalised target in w11.
> + */
> + mov x0, SYS_GET_CMDLINE
> + adr x1, .get_cmd
> + semihosting_call
> + adrp x10, cmdline
> + add x10, x10, :lo12:cmdline
> + ldrb w11, [x10]
> +
> + /* sanity check, normalise char to EL, clamp to 1 if outside range */
> + subs w11, w11, #'0'
> + b.lt el_default
> + cmp w11, #3
> + b.gt el_default
> + b 1f
> +
> +el_high:
> + adr x1, .high_el_msg
> + b exit_msg
> +
> +el_default:
> + mov w11, #1
> +
> +1:
> + /* Determine current Exception Level */
> + mrs x0, CurrentEL
> + lsr x0, x0, #2 /* CurrentEL[3:2] contains the current EL */
> +
> + /* Are we already in a lower EL than we want? */
> + cmp w11, w0
> + bgt el_high
Shorter:
/* sanity check, normalise char to EL, clamp to 1 if outside range */
subs w11, w11, #'0'
mov w0, #1
cmp w11, #3
csel w11, w11, w0, GT
/* Determine current Exception Level */
mrs x0, CurrentEL
lsr x0, x0, #2
cmp w11, w0
ble el_correct
adr x1, high_el_msg
b exit_msg
el_correct:
> +
> + /* Branch based on current EL */
> + cmp x0, #3
> + b.eq setup_el3
> + cmp x0, #2
> + b.eq setup_el2
> + cmp x0, #1
> + b.eq at_testel /* Already at EL1, skip transition */
> + /* Should not be at EL0 - error out */
> + b curr_sp0_sync
This still says "Unexpected exception."
> +
> +setup_el3:
> + /* Ensure we trap if we get anything wrong */
> + adr x0, vector_table
> + msr vbar_el3, x0
> +
> + /* Does the test want to be at EL3? */
> + cmp w11, #3
> + beq at_testel
> +
> + /* Configure EL3 to for lower states (EL2 or EL1) */
> + mrs x0, scr_el3
> + orr x0, x0, #(1 << 10) /* RW = 1: EL2/EL1 execution state is AArch64 */
> + orr x0, x0, #(1 << 0) /* NS = 1: Non-secure state */
> + msr scr_el3, x0
> +
> + /*
> + * We need to check if EL2 is actually enabled via ID_AA64PFR0_EL1,
> + * otherwise we should just jump straight to EL1.
> + */
> + mrs x0, id_aa64pfr0_el1
> + ubfx x0, x0, #8, #4 /* Extract EL2 field (bits 11:8) */
> + cbz x0, el2_not_present /* If field is 0 no EL2 */
> +
> +
> + /* Prepare SPSR for exception return to EL2 */
> + mov x0, #0x3c9 /* DAIF bits and EL2h mode (9) */
> + msr spsr_el3, x0
> +
> + /* Set EL2 entry point */
> + adr x0, setup_el2
> + msr elr_el3, x0
> +
> + /* Return to EL2 */
> + eret
> + nop
NOP is still present here.
> +
> +el2_not_present:
> + /* Initialize SCTLR_EL1 with reset value */
> + msr sctlr_el1, xzr
> +
> + /* Set EL1 entry point */
> + adr x0, at_testel
> + msr elr_el3, x0
> +
> + /* Prepare SPSR for exception return to EL1h with interrupts masked */
> + mov x0, #0x3c5 /* DAIF bits and EL1h mode (5) */
> + msr spsr_el3, x0
> +
> + isb /* Synchronization barrier */
> + eret /* Jump to EL1 */
> +
> +setup_el2:
> + /* Ensure we trap if we get anything wrong */
> + adr x0, vector_table
> + msr vbar_el2, x0
> +
> + /* Does the test want to be at EL2? */
> + cmp w11, #2
> + beq at_testel
> +
> + /* Configure EL2 to allow transition to EL1 */
> + mrs x0, hcr_el2
> + orr x0, x0, #(1 << 31) /* RW = 1: EL1 execution state is AArch64 */
> + msr hcr_el2, x0
> +
> + /* Initialize SCTLR_EL1 with reset value */
> + msr sctlr_el1, xzr
> +
> + /* Set EL1 entry point */
> + adr x0, at_testel
> + msr elr_el2, x0
> +
> + /* Prepare SPSR for exception return to EL1 */
> + mov x0, #(0x5 << 0) /* EL1h (SPx), with interrupts disabled */
> + msr spsr_el2, x0
> +
> + /* Return to EL1 */
> + eret
> +
> + nop
> +
> + /*
> + * At the target EL for the test, usually EL1. Note we still
> + * set everything up as if we were at EL1.
> + */
> +at_testel:
> /* Installs a table of exception vectors to catch and handle all
> exceptions by terminating the process with a diagnostic. */
> adr x0, vector_table
> @@ -100,7 +251,7 @@ __start:
> * maps RAM to the first Gb. The stage2 tables have two 2mb
> * translation block entries covering a series of adjacent
> * 4k pages.
> - */
> + */
>
> /* Stage 1 entry: indexed by IA[38:30] */
> adr x1, . /* phys address */
> @@ -198,7 +349,8 @@ __start:
> orr x0, x0, #(3 << 16)
> msr cpacr_el1, x0
>
> - /* Setup some stack space and enter the test code.
> + /*
> + * Setup some stack space before we enter the test code.
> * Assume everything except the return value is garbage when we
> * return, we won't need it.
> */
> @@ -233,6 +385,11 @@ __sys_outc:
> ret
>
> .data
> +
> + .align 8
> +cmdline:
> + .space 128, 0
> +
> .align 12
>
> /* Translation table
> @@ -246,6 +403,10 @@ ttb_stage2:
> .space 4096, 0
>
> .align 12
> +system_stack:
> + .space 4096, 0
> +system_stack_end:
> +
> stack:
> .space 65536, 0
> stack_end:
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers
2025-05-21 16:42 ` [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers Alex Bennée
@ 2025-05-22 5:16 ` Markus Armbruster
2025-05-24 11:07 ` Michael S. Tsirkin
2025-05-25 15:20 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 52+ messages in thread
From: Markus Armbruster @ 2025-05-22 5:16 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
Alex Bennée <alex.bennee@linaro.org> writes:
> Thanks for volunteering to help.
>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> MAINTAINERS | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 8dfb393c06..a14e2796e0 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2674,6 +2674,8 @@ F: include/hw/display/ramfb.h
>
> virtio-gpu
> M: Alex Bennée <alex.bennee@linaro.org>
> +R: Akihiko Odaki <akihiko.odaki@daynix.com>
> +R: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> S: Odd Fixes
> F: hw/display/virtio-gpu*
> F: hw/display/virtio-vga.*
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 09/20] MAINTAINERS: add myself to virtio-gpu for Odd Fixes
2025-05-21 16:42 ` [PATCH v3 09/20] MAINTAINERS: add myself to virtio-gpu for Odd Fixes Alex Bennée
@ 2025-05-22 5:16 ` Markus Armbruster
0 siblings, 0 replies; 52+ messages in thread
From: Markus Armbruster @ 2025-05-22 5:16 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
Alex Bennée <alex.bennee@linaro.org> writes:
> Seeing as I've taken a few patches to here now I might as well put
> myself forward to maintain virtio-gpu. I've marked it as Odd Fixes as
> it is not my core focus. If someone with more GPU experience comes
> forward we can always update again.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>
> ---
> v2
> - s/M:/S:/ for the maintainer entry
> ---
> MAINTAINERS | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 818d7b9d5f..8dfb393c06 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2673,7 +2673,8 @@ F: hw/display/ramfb*.c
> F: include/hw/display/ramfb.h
>
> virtio-gpu
> -S: Orphan
> +M: Alex Bennée <alex.bennee@linaro.org>
> +S: Odd Fixes
> F: hw/display/virtio-gpu*
> F: hw/display/virtio-vga.*
> F: include/hw/virtio/virtio-gpu.h
Reviewed-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan
2025-05-21 16:42 ` [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan Alex Bennée
@ 2025-05-22 5:19 ` Akihiko Odaki
2025-05-25 15:18 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:19 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Nabih Estefan, Richard Henderson
On 2025/05/22 1:42, Alex Bennée wrote:
> From: Nabih Estefan <nabihestefan@google.com>
>
> ../tests/qtest/libqos/igb.c:106:5: runtime error: load of misaligned address 0x562040be8e33 for type 'uint32_t', which requires 4 byte alignment
>
> Instead of straight casting the uint8_t array, we can use ldl_le_p and
> lduw_l_p to assure the unaligned access working properly against
> uint32_t and uint16_t.
I think the subject should mention the problem (the unaligned access)
instead of the method used to detect it (UBSan).
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume
2025-05-21 16:42 ` [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume Alex Bennée
@ 2025-05-22 5:23 ` Thomas Huth
0 siblings, 0 replies; 52+ messages in thread
From: Thomas Huth @ 2025-05-22 5:23 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Paolo Bonzini, Akihiko Odaki, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
On 21/05/2025 18.42, Alex Bennée wrote:
> If you want to run functional tests we should share .cache/qemu so we
> don't force containers to continually re-download images.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Maybe add something about the ccache relocation to the commit message?
Anyway:
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps
2025-05-21 16:42 ` [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps Alex Bennée
@ 2025-05-22 5:37 ` Akihiko Odaki
2025-05-22 10:31 ` Alex Bennée
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:37 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
On 2025/05/22 1:42, Alex Bennée wrote:
> The user can run a subset of the tcg tests directly, e.g.:
>
> make run-tcg-tests-hexagon-linux-user
>
> but in this case we fail if there has not been a full build to ensure
> all the test-plugins are there. Fix the dependency to ensure we always
> will build them before running tests.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> tests/Makefile.include | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 23fb722d42..7f7f62cbf6 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -46,7 +46,7 @@ $(foreach TARGET,$(TCG_TESTS_TARGETS), \
> $(eval $(BUILD_DIR)/tests/tcg/config-$(TARGET).mak: config-host.mak))
>
> .PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%)
> -$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak
> +$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak test-plugins
I don't think this is going to work.
test-plugins will invoke run-ninja, which is defined as follows:
run-ninja: config-host.mak
ifneq ($(filter $(ninja-targets), $(ninja-cmd-goals)),)
+$(if $(MAKE.nq),@:,$(quiet-@)$(NINJA) $(NINJAFLAGS) \
$(sort $(filter $(ninja-targets), $(ninja-cmd-goals))) | cat)
$(ninja-cmd-goals) should contain test-plugins, but it doesn't if I
understand it correctly.
> $(call quiet-command, \
> $(MAKE) -C tests/tcg/$* $(SUBDIR_MAKEFLAGS), \
> "BUILD","$* guest-tests")
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 06/20] tests/functional: Add PCI hotplug test for aarch64
2025-05-21 16:42 ` [PATCH v3 06/20] tests/functional: Add PCI hotplug test for aarch64 Alex Bennée
@ 2025-05-22 5:43 ` Akihiko Odaki
0 siblings, 0 replies; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:43 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin, Eric Auger
On 2025/05/22 1:42, Alex Bennée wrote:
> From: Gustavo Romero <gustavo.romero@linaro.org>
>
> Add a functional test, aarch64_hotplug_pci, to exercise PCI hotplug and
> hot-unplug on arm64.
>
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Message-Id: <20250512144629.182340-1-gustavo.romero@linaro.org>
> [AJB: add qemu-arm link]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>
> ---
> v2
> - add qemu-arm link to MAINTAINERS
> ---
> MAINTAINERS | 6 ++
> tests/functional/meson.build | 1 +
> tests/functional/test_aarch64_hotplug_pci.py | 74 ++++++++++++++++++++
> 3 files changed, 81 insertions(+)
> create mode 100755 tests/functional/test_aarch64_hotplug_pci.py
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 7060cf49b9..818d7b9d5f 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2078,6 +2078,12 @@ S: Supported
> F: include/hw/pci/pcie_doe.h
> F: hw/pci/pcie_doe.c
>
> +ARM PCI Hotplug
> +M: Gustavo Romero <gustavo.romero@linaro.org>
> +L: qemu-arm@nongnu.org
> +S: Supported
> +F: tests/functional/test_aarch64_hotplug_pci.py
> +
> ACPI/SMBIOS
> M: Michael S. Tsirkin <mst@redhat.com>
> M: Igor Mammedov <imammedo@redhat.com>
> diff --git a/tests/functional/meson.build b/tests/functional/meson.build
> index 52b4706cfe..2d68840fa2 100644
> --- a/tests/functional/meson.build
> +++ b/tests/functional/meson.build
> @@ -83,6 +83,7 @@ tests_aarch64_system_quick = [
> tests_aarch64_system_thorough = [
> 'aarch64_aspeed_ast2700',
> 'aarch64_aspeed_ast2700fc',
> + 'aarch64_hotplug_pci',
> 'aarch64_imx8mp_evk',
> 'aarch64_raspi3',
> 'aarch64_raspi4',
> diff --git a/tests/functional/test_aarch64_hotplug_pci.py b/tests/functional/test_aarch64_hotplug_pci.py
> new file mode 100755
> index 0000000000..fa1bb62c8f
> --- /dev/null
> +++ b/tests/functional/test_aarch64_hotplug_pci.py
> @@ -0,0 +1,74 @@
> +#!/usr/bin/env python3
> +#
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# The test hotplugs a PCI device and checks it on a Linux guest.
> +#
> +# Copyright (c) 2025 Linaro Ltd.
> +#
> +# Author:
> +# Gustavo Romero <gustavo.romero@linaro.org>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later. See the COPYING file in the top-level directory.
> +
> +from qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern
> +from qemu_test import BUILD_DIR
> +
> +class HotplugPCI(LinuxKernelTest):
> +
> + ASSET_KERNEL = Asset(
> + ('https://ftp.debian.org/debian/dists/stable/main/installer-arm64/'
> + 'current/images/netboot/debian-installer/arm64/linux'),
> + '3821d4db56d42c6a4eac62f31846e35465940afd87746b4cfcdf5c9eca3117b2')
> +
> + ASSET_INITRD = Asset(
> + ('https://ftp.debian.org/debian/dists/stable/main/installer-arm64/'
> + 'current/images/netboot/debian-installer/arm64/initrd.gz'),
> + '2583ec22b45265ad69e82f198674f53d4cd85be124fe012eedc2fd91156bc4b4')
> +
> + def test_hotplug_pci(self):
> +
> + self.set_machine('virt')
> + self.vm.add_args('-m', '512M')
> + self.vm.add_args('-cpu', 'cortex-a57')
> + self.vm.add_args('-append',
> + 'console=ttyAMA0,115200 init=/bin/sh')
> + self.vm.add_args('-device',
> + 'pcie-root-port,bus=pcie.0,chassis=1,slot=1,id=pcie.1')
> + self.vm.add_args('-bios', self.build_file('pc-bios',
> + 'edk2-aarch64-code.fd'))
One call of self.vm.add_args should be sufficient:
self.vm.add_args('-m', '512M',
'-cpu', 'cortex-a57',
'-append',
'console=ttyAMA0,115200 init=/bin/sh',
'-device',
'pcie-root-port,bus=pcie.0,chassis=1,slot=1,id=pcie.1',
'-bios',
self.build_file('pc-bios', 'edk2-aarch64-code.fd'))
> +
> + # BusyBox prompt
> + prompt = "~ #"
> + self.launch_kernel(self.ASSET_KERNEL.fetch(),
> + self.ASSET_INITRD.fetch(),
> + wait_for=prompt)
> +
> + # Check for initial state: 2 network adapters, lo and enp0s1.
> + exec_command_and_wait_for_pattern(self,
> + 'ls -l /sys/class/net | wc -l',
Shorter: ls /sys/class/net | wc -l
> + '2')
> +
> + # Hotplug one network adapter to the root port, i.e. pcie.1 bus.
> + self.vm.cmd('device_add',
> + driver='virtio-net-pci',
> + bus='pcie.1',
> + addr=0,
> + id='na')
> + # Wait for the kernel to recognize the new device.
> + self.wait_for_console_pattern('virtio-pci')
> + self.wait_for_console_pattern('virtio_net')
> +
> + # Check if there is a new network adapter.
> + exec_command_and_wait_for_pattern(self,
> + 'ls -l /sys/class/net | wc -l',
> + '3')
> +
> + self.vm.cmd('device_del', id='na')
> + exec_command_and_wait_for_pattern(self,
> + 'ls -l /sys/class/net | wc -l',
> + '2')
> +
> +if __name__ == '__main__':
> + LinuxKernelTest.main()
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg
2025-05-21 16:42 ` [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg Alex Bennée
@ 2025-05-22 5:45 ` Akihiko Odaki
2025-05-25 15:19 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:45 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
On 2025/05/22 1:42, Alex Bennée wrote:
> It's easy to get lost in zeros while setting the numbers of
> instructions per second. Add a scaling suffix to make things simpler.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>
> ---
> v2
> - normalise the suffix before a full strcmp0
> - check endptr actually set
> - fix checkpatch
> - scale_entry -> ScaleEntry
> - drop hz from suffix
> ---
> contrib/plugins/ips.c | 34 +++++++++++++++++++++++++++++++++-
> 1 file changed, 33 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c
> index e5297dbb01..eb4418c25b 100644
> --- a/contrib/plugins/ips.c
> +++ b/contrib/plugins/ips.c
> @@ -129,6 +129,18 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata)
> qemu_plugin_scoreboard_free(vcpus);
> }
>
> +typedef struct {
> + const char *suffix;
> + unsigned long multipler;
As I suggested for the previous version, let's use uint32_t or uint64_t.
> +} ScaleEntry;
> +
> +/* a bit like units.h but not binary */
> +static ScaleEntry scales[] = {
> + { "k", 1000 },
> + { "m", 1000 * 1000 },
> + { "g", 1000 * 1000 * 1000 },
> +};
> +
> QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> const qemu_info_t *info, int argc,
> char **argv)
> @@ -137,12 +149,32 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> char *opt = argv[i];
> g_auto(GStrv) tokens = g_strsplit(opt, "=", 2);
> if (g_strcmp0(tokens[0], "ips") == 0) {
> - max_insn_per_second = g_ascii_strtoull(tokens[1], NULL, 10);
> + char *endptr = NULL;
> + max_insn_per_second = g_ascii_strtoull(tokens[1], &endptr, 10);
> if (!max_insn_per_second && errno) {
> fprintf(stderr, "%s: couldn't parse %s (%s)\n",
> __func__, tokens[1], g_strerror(errno));
> return -1;
> }
> +
> + if (endptr && *endptr != 0) {
> + g_autofree gchar *lower = g_utf8_strdown(endptr, -1);
> + unsigned long scale = 0;
> +
> + for (int j = 0; j < G_N_ELEMENTS(scales); j++) {
> + if (g_strcmp0(lower, scales[j].suffix) == 0) {
> + scale = scales[j].multipler;
> + break;
> + }
> + }
> +
> + if (scale) {
> + max_insn_per_second *= scale;
> + } else {
> + fprintf(stderr, "bad suffix: %s\n", endptr);
> + return -1;
> + }
> + }
> } else {
> fprintf(stderr, "option parsing failed: %s\n", opt);
> return -1;
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 08/20] contrib/plugins: allow setting of instructions per quantum
2025-05-21 16:42 ` [PATCH v3 08/20] contrib/plugins: allow setting of instructions per quantum Alex Bennée
@ 2025-05-22 5:55 ` Akihiko Odaki
0 siblings, 0 replies; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:55 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
On 2025/05/22 1:42, Alex Bennée wrote:
> The default is we update time every 1/10th of a second or so. However
> for some cases we might want to update time more frequently. Allow
> this to be set via the command line through the ipq argument.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>
> ---
> v3
> - error checking for ipq
> v2
> - checkpatch fixes.
> ---
> docs/about/emulation.rst | 4 ++++
> contrib/plugins/ips.c | 15 ++++++++++++++-
> 2 files changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst
> index a72591ee4d..456d01d5b0 100644
> --- a/docs/about/emulation.rst
> +++ b/docs/about/emulation.rst
> @@ -811,6 +811,10 @@ This plugin can limit the number of Instructions Per Second that are executed::
> * - ips=N
> - Maximum number of instructions per cpu that can be executed in one second.
> The plugin will sleep when the given number of instructions is reached.
> + * - ipq=N
> + - Instructions per quantum. How many instructions before we re-calculate time.
> + The lower the number the more accurate time will be, but the less efficient the plugin.
> + Defaults to ips/10
>
> Other emulation features
> ------------------------
> diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c
> index eb4418c25b..f1523cbee3 100644
> --- a/contrib/plugins/ips.c
> +++ b/contrib/plugins/ips.c
> @@ -145,6 +145,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> const qemu_info_t *info, int argc,
> char **argv)
> {
> + bool ipq_set = false;
> +
> for (int i = 0; i < argc; i++) {
> char *opt = argv[i];
> g_auto(GStrv) tokens = g_strsplit(opt, "=", 2);
> @@ -175,6 +177,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> return -1;
> }
> }
> + } else if (g_strcmp0(tokens[0], "ipq") == 0) {
> + max_insn_per_quantum = g_ascii_strtoull(tokens[1], NULL, 10);
> +
> + if (max_insn_per_quantum == 0 || max_insn_per_quantum == G_MAXUINT64) {
> + fprintf(stderr, "bad ipq value: %s\n", g_strerror(errno));
This check should follow one of ips.
First, it should check errno. Otherwise it may emit a cryptic message
saying: "bad ipq value: Success".
max_insn_per_quantum == G_MAXUINT64 is unnecessary. A sufficiently large
value of max_insn_per_quantum should result in the same behavior anyway:
a quantum never ends.
Following the check of ips is an easy way to implement a correct
checking and it also ensures consistency.
> + return -1;
> + }
> + ipq_set = true;
> } else {
> fprintf(stderr, "option parsing failed: %s\n", opt);
> return -1;
> @@ -182,7 +192,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> }
>
> vcpus = qemu_plugin_scoreboard_new(sizeof(vCPUTime));
> - max_insn_per_quantum = max_insn_per_second / NUM_TIME_UPDATE_PER_SEC;
> +
> + if (!ipq_set) {
> + max_insn_per_quantum = max_insn_per_second / NUM_TIME_UPDATE_PER_SEC;
> + }
>
> if (max_insn_per_quantum == 0) {
> fprintf(stderr, "minimum of %d instructions per second needed\n",
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-21 16:42 ` [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob Alex Bennée
@ 2025-05-22 5:59 ` Akihiko Odaki
2025-05-22 6:45 ` Alex Bennée
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 5:59 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Manos Pitsidianakis, qemu-stable
On 2025/05/22 1:42, Alex Bennée wrote:
> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>
> This commit fixes an indefinite hang when using VIRTIO GPU blob objects
> under TCG in certain conditions.
>
> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
> MemoryRegion and attaches it to an offset on a PCI BAR of the
> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
> it.
>
> Because virglrenderer commands are not thread-safe they are only
> called on the main context and QEMU performs the cleanup in three steps
> to prevent a use-after-free scenario where the guest can access the
> region after it’s unmapped:
>
> 1. From the main context, the region’s field finish_unmapping is false
> by default, so it sets a variable cmd_suspended, increases the
> renderer_blocked variable, deletes the blob subregion, and unparents
> the blob subregion causing its reference count to decrement.
>
> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
> recalculated, the free callback of the blob region
> virtio_gpu_virgl_hostmem_region_free is called which sets the
> region’s field finish_unmapping to true, allowing the main thread
> context to finish replying to the command
>
> 3. From the main context, the command is processed again, but this time
> finish_unmapping is true, so virgl_renderer_resource_unmap can be
> called and a response is sent to the guest.
>
> It happens so that under TCG, if the guest has no timers configured (and
> thus no interrupt will cause the CPU to exit), the RCU thread does not
> have enough time to grab the locks and recalculate the FlatView.
>
> That’s not a big problem in practice since most guests will assume a
> response will happen later in time and go on to do different things,
> potentially triggering interrupts and allowing the RCU context to run.
> If the guest waits for the unmap command to complete though, it blocks
> indefinitely. Attaching to the QEMU monitor and force quitting the guest
> allows the cleanup to continue.
>
> There's no reason why the FlatView recalculation can't occur right away
> when we delete the blob subregion, however. It does not, because when we
> create the subregion we set the object as its own parent:
>
> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
>
> The extra reference is what prevents freeing the memory region object in
> the memory transaction of deleting the subregion.
>
> This commit changes the owner object to the device, which removes the
> extra owner reference in the memory region and causes the MR to be
> freed right away in the main context.
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Tested-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
> Cc: qemu-stable@nongnu.org
> ---
> hw/display/virtio-gpu-virgl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> index 71a7500de9..8fbe4e70cc 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
> vmr->g = g;
> mr = g_new0(MemoryRegion, 1);
>
> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
> memory_region_add_subregion(&b->hostmem, offset, mr);
> memory_region_set_enabled(mr, true);
>
I suggest dropping this patch for now due to the reason I pointed out
for the first version of this series.
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 16/20] include/exec: fix assert in size_memop
2025-05-21 16:42 ` [PATCH v3 16/20] include/exec: fix assert in size_memop Alex Bennée
@ 2025-05-22 6:07 ` Akihiko Odaki
0 siblings, 0 replies; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 6:07 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Richard Henderson
On 2025/05/22 1:42, Alex Bennée wrote:
> We can handle larger sized memops now, expand the range of the assert.
>
> Fixes: 4b473e0c60 (tcg: Expand MO_SIZE to 3 bits)
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
> ---
> v2
> - instead of 128 use 1 << MO_SIZE for future proofing
> v3
> - fix comment, 1 << MO_SIZE goes to 1024
> ---
> include/exec/memop.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/exec/memop.h b/include/exec/memop.h
> index 407a47d82c..e934bde809 100644
> --- a/include/exec/memop.h
> +++ b/include/exec/memop.h
> @@ -162,8 +162,8 @@ static inline unsigned memop_size(MemOp op)
> static inline MemOp size_memop(unsigned size)
> {
> #ifdef CONFIG_DEBUG_TCG
> - /* Power of 2 up to 8. */
> - assert((size & (size - 1)) == 0 && size >= 1 && size <= 8);
> + /* Power of 2 up to 1024 */
> + assert((size & (size - 1)) == 0 && size >= 1 && size <= (1 << MO_SIZE));
You missed the following thread:
https://lore.kernel.org/qemu-devel/eec76ce0-c3ca-48ed-befe-e0930d4a39d9@linaro.org/
I think you need to check the replies to the previous versions of this
series. There are several comments not addressed.
> #endif
> return (MemOp)ctz32(size);
> }
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet
2025-05-21 16:42 ` [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet Alex Bennée
@ 2025-05-22 6:29 ` Akihiko Odaki
2025-05-22 10:05 ` Alex Bennée
2025-05-25 15:25 ` Philippe Mathieu-Daudé
1 sibling, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 6:29 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Dominik 'Disconnect3d' Czarnota,
Patryk 'patryk4815' Sondej
On 2025/05/22 1:42, Alex Bennée wrote:
> From: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>
> This commit adds support for the `qGDBServerVersion` packet to the qemu
> gdbstub which could be used by clients to detect the QEMU version
> (and, e.g., use a workaround for known bugs).
>
> This packet is not documented/standarized by GDB but it was implemented
> by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
>
> This has been implemented by Patryk, who I included in Co-authored-by
> and who asked me to send the patch.
>
> [0] https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
> [1] https://github.com/pwndbg/pwndbg/issues/2648
>
> Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com>
> Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
> Message-Id: <20250403191340.53343-1-dominik.b.czarnota@gmail.com>
> [AJB: fix include, checkpatch linewrap]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> gdbstub/gdbstub.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
> index 6023c80d25..def0b7e877 100644
> --- a/gdbstub/gdbstub.c
> +++ b/gdbstub/gdbstub.c
> @@ -28,6 +28,7 @@
> #include "qemu/cutils.h"
> #include "qemu/module.h"
> #include "qemu/error-report.h"
> +#include "qemu/target-info.h"
> #include "trace.h"
> #include "exec/gdbstub.h"
> #include "gdbstub/commands.h"
> @@ -1597,6 +1598,18 @@ static void handle_query_threads(GArray *params, void *user_ctx)
> gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu);
> }
>
> +static void handle_query_gdb_server_version(GArray *params, void *user_ctx)
> +{
> +#if defined(CONFIG_USER_ONLY)
> + g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;",
> + target_name(), QEMU_VERSION);
> +#else
> + g_string_printf(gdbserver_state.str_buf, "name:qemu-system-%s;version:%s;",
> + target_name(), QEMU_VERSION);
> +#endif
I sugguest passing "qemu" as the name property.
I guess LLDB developers chose to explicitly have the key-value pair
syntax so that users can have one unified logic for parsing and avoid
the mess of HTTP's User-Agent; there is a proposal for Web that
introduces key-value pairs in a similar manner:
https://developer.chrome.com/docs/privacy-security/user-agent-client-hints
If we embed more information like to the name property, users will need
to have an additional logic to know if it's QEMU or to know other
information. Instead, we can emit:
name:qemu;version:10.0.50;
and we can use something like follows if we want to tell more:
name:qemu;version:10.0.50;qemu-mode:system;qemu-target:hexagon;
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 5:59 ` Akihiko Odaki
@ 2025-05-22 6:45 ` Alex Bennée
2025-05-22 7:02 ` Akihiko Odaki
0 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-22 6:45 UTC (permalink / raw)
To: Akihiko Odaki
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Manos Pitsidianakis, qemu-stable
Akihiko Odaki <akihiko.odaki@daynix.com> writes:
> On 2025/05/22 1:42, Alex Bennée wrote:
>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>> This commit fixes an indefinite hang when using VIRTIO GPU blob
>> objects
>> under TCG in certain conditions.
>> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
>> MemoryRegion and attaches it to an offset on a PCI BAR of the
>> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
>> it.
>> Because virglrenderer commands are not thread-safe they are only
>> called on the main context and QEMU performs the cleanup in three steps
>> to prevent a use-after-free scenario where the guest can access the
>> region after it’s unmapped:
>> 1. From the main context, the region’s field finish_unmapping is
>> false
>> by default, so it sets a variable cmd_suspended, increases the
>> renderer_blocked variable, deletes the blob subregion, and unparents
>> the blob subregion causing its reference count to decrement.
>> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
>> recalculated, the free callback of the blob region
>> virtio_gpu_virgl_hostmem_region_free is called which sets the
>> region’s field finish_unmapping to true, allowing the main thread
>> context to finish replying to the command
>> 3. From the main context, the command is processed again, but this
>> time
>> finish_unmapping is true, so virgl_renderer_resource_unmap can be
>> called and a response is sent to the guest.
>> It happens so that under TCG, if the guest has no timers configured
>> (and
>> thus no interrupt will cause the CPU to exit), the RCU thread does not
>> have enough time to grab the locks and recalculate the FlatView.
>> That’s not a big problem in practice since most guests will assume a
>> response will happen later in time and go on to do different things,
>> potentially triggering interrupts and allowing the RCU context to run.
>> If the guest waits for the unmap command to complete though, it blocks
>> indefinitely. Attaching to the QEMU monitor and force quitting the guest
>> allows the cleanup to continue.
>> There's no reason why the FlatView recalculation can't occur right
>> away
>> when we delete the blob subregion, however. It does not, because when we
>> create the subregion we set the object as its own parent:
>> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
>> The extra reference is what prevents freeing the memory region
>> object in
>> the memory transaction of deleting the subregion.
>> This commit changes the owner object to the device, which removes
>> the
>> extra owner reference in the memory region and causes the MR to be
>> freed right away in the main context.
>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
>> Cc: qemu-stable@nongnu.org
>> ---
>> hw/display/virtio-gpu-virgl.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> diff --git a/hw/display/virtio-gpu-virgl.c
>> b/hw/display/virtio-gpu-virgl.c
>> index 71a7500de9..8fbe4e70cc 100644
>> --- a/hw/display/virtio-gpu-virgl.c
>> +++ b/hw/display/virtio-gpu-virgl.c
>> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
>> vmr->g = g;
>> mr = g_new0(MemoryRegion, 1);
>> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size,
>> data);
>> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
>> memory_region_add_subregion(&b->hostmem, offset, mr);
>> memory_region_set_enabled(mr, true);
>>
>
> I suggest dropping this patch for now due to the reason I pointed out
> for the first version of this series.
This fixes an actual bug - without it we get a hang.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 6:45 ` Alex Bennée
@ 2025-05-22 7:02 ` Akihiko Odaki
2025-05-22 7:31 ` Manos Pitsidianakis
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 7:02 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Manos Pitsidianakis, qemu-stable
On 2025/05/22 15:45, Alex Bennée wrote:
> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>
>> On 2025/05/22 1:42, Alex Bennée wrote:
>>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>> This commit fixes an indefinite hang when using VIRTIO GPU blob
>>> objects
>>> under TCG in certain conditions.
>>> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
>>> MemoryRegion and attaches it to an offset on a PCI BAR of the
>>> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
>>> it.
>>> Because virglrenderer commands are not thread-safe they are only
>>> called on the main context and QEMU performs the cleanup in three steps
>>> to prevent a use-after-free scenario where the guest can access the
>>> region after it’s unmapped:
>>> 1. From the main context, the region’s field finish_unmapping is
>>> false
>>> by default, so it sets a variable cmd_suspended, increases the
>>> renderer_blocked variable, deletes the blob subregion, and unparents
>>> the blob subregion causing its reference count to decrement.
>>> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
>>> recalculated, the free callback of the blob region
>>> virtio_gpu_virgl_hostmem_region_free is called which sets the
>>> region’s field finish_unmapping to true, allowing the main thread
>>> context to finish replying to the command
>>> 3. From the main context, the command is processed again, but this
>>> time
>>> finish_unmapping is true, so virgl_renderer_resource_unmap can be
>>> called and a response is sent to the guest.
>>> It happens so that under TCG, if the guest has no timers configured
>>> (and
>>> thus no interrupt will cause the CPU to exit), the RCU thread does not
>>> have enough time to grab the locks and recalculate the FlatView.
>>> That’s not a big problem in practice since most guests will assume a
>>> response will happen later in time and go on to do different things,
>>> potentially triggering interrupts and allowing the RCU context to run.
>>> If the guest waits for the unmap command to complete though, it blocks
>>> indefinitely. Attaching to the QEMU monitor and force quitting the guest
>>> allows the cleanup to continue.
>>> There's no reason why the FlatView recalculation can't occur right
>>> away
>>> when we delete the blob subregion, however. It does not, because when we
>>> create the subregion we set the object as its own parent:
>>> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
>>> The extra reference is what prevents freeing the memory region
>>> object in
>>> the memory transaction of deleting the subregion.
>>> This commit changes the owner object to the device, which removes
>>> the
>>> extra owner reference in the memory region and causes the MR to be
>>> freed right away in the main context.
>>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>>> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
>>> Cc: qemu-stable@nongnu.org
>>> ---
>>> hw/display/virtio-gpu-virgl.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>> diff --git a/hw/display/virtio-gpu-virgl.c
>>> b/hw/display/virtio-gpu-virgl.c
>>> index 71a7500de9..8fbe4e70cc 100644
>>> --- a/hw/display/virtio-gpu-virgl.c
>>> +++ b/hw/display/virtio-gpu-virgl.c
>>> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
>>> vmr->g = g;
>>> mr = g_new0(MemoryRegion, 1);
>>> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size,
>>> data);
>>> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
>>> memory_region_add_subregion(&b->hostmem, offset, mr);
>>> memory_region_set_enabled(mr, true);
>>>
>>
>> I suggest dropping this patch for now due to the reason I pointed out
>> for the first version of this series.
>
> This fixes an actual bug - without it we get a hang.
>
I understand that but it also introduces a regression; "[PATCH v3 14/20]
ui/gtk-gl-area: Remove extra draw call in refresh" is also a similar case.
Ideally such a bug should be fixed without regression, but I understand
it is sometimes difficult to do that and postponing the bug resolution
until figuring out the correct way does not make sense.
In such a case, a bug should be fixed minimizing the regression and the
documentation of the regression should be left in the code.
In particular, this patch can cause use-after-free whether TCG is used
or not. Instead, I suggest to avoid freeing memory regions at all on
TCG. It will surely leak memory, but won't result in use-after-free at
least and the other accelerators will be unaffected.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 7:02 ` Akihiko Odaki
@ 2025-05-22 7:31 ` Manos Pitsidianakis
2025-05-22 7:40 ` Akihiko Odaki
0 siblings, 1 reply; 52+ messages in thread
From: Manos Pitsidianakis @ 2025-05-22 7:31 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Alex Bennée, qemu-devel, Pierrick Bouvier, Thomas Huth,
Paolo Bonzini, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, qemu-stable
On Thu, May 22, 2025 at 10:03 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>
> On 2025/05/22 15:45, Alex Bennée wrote:
> > Akihiko Odaki <akihiko.odaki@daynix.com> writes:
> >
> >> On 2025/05/22 1:42, Alex Bennée wrote:
> >>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> >>> This commit fixes an indefinite hang when using VIRTIO GPU blob
> >>> objects
> >>> under TCG in certain conditions.
> >>> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
> >>> MemoryRegion and attaches it to an offset on a PCI BAR of the
> >>> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
> >>> it.
> >>> Because virglrenderer commands are not thread-safe they are only
> >>> called on the main context and QEMU performs the cleanup in three steps
> >>> to prevent a use-after-free scenario where the guest can access the
> >>> region after it’s unmapped:
> >>> 1. From the main context, the region’s field finish_unmapping is
> >>> false
> >>> by default, so it sets a variable cmd_suspended, increases the
> >>> renderer_blocked variable, deletes the blob subregion, and unparents
> >>> the blob subregion causing its reference count to decrement.
> >>> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
> >>> recalculated, the free callback of the blob region
> >>> virtio_gpu_virgl_hostmem_region_free is called which sets the
> >>> region’s field finish_unmapping to true, allowing the main thread
> >>> context to finish replying to the command
> >>> 3. From the main context, the command is processed again, but this
> >>> time
> >>> finish_unmapping is true, so virgl_renderer_resource_unmap can be
> >>> called and a response is sent to the guest.
> >>> It happens so that under TCG, if the guest has no timers configured
> >>> (and
> >>> thus no interrupt will cause the CPU to exit), the RCU thread does not
> >>> have enough time to grab the locks and recalculate the FlatView.
> >>> That’s not a big problem in practice since most guests will assume a
> >>> response will happen later in time and go on to do different things,
> >>> potentially triggering interrupts and allowing the RCU context to run.
> >>> If the guest waits for the unmap command to complete though, it blocks
> >>> indefinitely. Attaching to the QEMU monitor and force quitting the guest
> >>> allows the cleanup to continue.
> >>> There's no reason why the FlatView recalculation can't occur right
> >>> away
> >>> when we delete the blob subregion, however. It does not, because when we
> >>> create the subregion we set the object as its own parent:
> >>> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
> >>> The extra reference is what prevents freeing the memory region
> >>> object in
> >>> the memory transaction of deleting the subregion.
> >>> This commit changes the owner object to the device, which removes
> >>> the
> >>> extra owner reference in the memory region and causes the MR to be
> >>> freed right away in the main context.
> >>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> >>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> >>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> >>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
> >>> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
> >>> Cc: qemu-stable@nongnu.org
> >>> ---
> >>> hw/display/virtio-gpu-virgl.c | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>> diff --git a/hw/display/virtio-gpu-virgl.c
> >>> b/hw/display/virtio-gpu-virgl.c
> >>> index 71a7500de9..8fbe4e70cc 100644
> >>> --- a/hw/display/virtio-gpu-virgl.c
> >>> +++ b/hw/display/virtio-gpu-virgl.c
> >>> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
> >>> vmr->g = g;
> >>> mr = g_new0(MemoryRegion, 1);
> >>> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size,
> >>> data);
> >>> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
> >>> memory_region_add_subregion(&b->hostmem, offset, mr);
> >>> memory_region_set_enabled(mr, true);
> >>>
> >>
> >> I suggest dropping this patch for now due to the reason I pointed out
> >> for the first version of this series.
> >
> > This fixes an actual bug - without it we get a hang.
> >
>
> I understand that but it also introduces a regression; "[PATCH v3 14/20]
> ui/gtk-gl-area: Remove extra draw call in refresh" is also a similar case.
>
> Ideally such a bug should be fixed without regression, but I understand
> it is sometimes difficult to do that and postponing the bug resolution
> until figuring out the correct way does not make sense.
>
> In such a case, a bug should be fixed minimizing the regression and the
> documentation of the regression should be left in the code.
>
> In particular, this patch can cause use-after-free whether TCG is used
> or not. Instead, I suggest to avoid freeing memory regions at all on
> TCG. It will surely leak memory, but won't result in use-after-free at
> least and the other accelerators will be unaffected.
>
> Regards,
> Akihiko Odaki
We tested this fix with ASAN and didn't see anything. Do you have a
test case in mind that can reproduce this use-after-free? It'd help
make a certain decision on whether to drop this patch or not. I'm not
doubting that this can cause a use-after-free by the way, it's just
that it is hypothetical only. If it causes a use-after-free for sure
we should definitely drop it.
> Instead, I suggest to avoid freeing memory regions at all on
> TCG. It will surely leak memory, but won't result in use-after-free at
> least and the other accelerators will be unaffected.
Leaking memory for blob objects is also not ideal, since they are
frequently allocated. It's memory-safe but the leak can accumulate
over time.
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 7:31 ` Manos Pitsidianakis
@ 2025-05-22 7:40 ` Akihiko Odaki
2025-05-22 9:28 ` Alex Bennée
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 7:40 UTC (permalink / raw)
To: Manos Pitsidianakis
Cc: Alex Bennée, qemu-devel, Pierrick Bouvier, Thomas Huth,
Paolo Bonzini, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, qemu-stable
On 2025/05/22 16:31, Manos Pitsidianakis wrote:
> On Thu, May 22, 2025 at 10:03 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>>
>> On 2025/05/22 15:45, Alex Bennée wrote:
>>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>>
>>>> On 2025/05/22 1:42, Alex Bennée wrote:
>>>>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>>>> This commit fixes an indefinite hang when using VIRTIO GPU blob
>>>>> objects
>>>>> under TCG in certain conditions.
>>>>> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
>>>>> MemoryRegion and attaches it to an offset on a PCI BAR of the
>>>>> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
>>>>> it.
>>>>> Because virglrenderer commands are not thread-safe they are only
>>>>> called on the main context and QEMU performs the cleanup in three steps
>>>>> to prevent a use-after-free scenario where the guest can access the
>>>>> region after it’s unmapped:
>>>>> 1. From the main context, the region’s field finish_unmapping is
>>>>> false
>>>>> by default, so it sets a variable cmd_suspended, increases the
>>>>> renderer_blocked variable, deletes the blob subregion, and unparents
>>>>> the blob subregion causing its reference count to decrement.
>>>>> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
>>>>> recalculated, the free callback of the blob region
>>>>> virtio_gpu_virgl_hostmem_region_free is called which sets the
>>>>> region’s field finish_unmapping to true, allowing the main thread
>>>>> context to finish replying to the command
>>>>> 3. From the main context, the command is processed again, but this
>>>>> time
>>>>> finish_unmapping is true, so virgl_renderer_resource_unmap can be
>>>>> called and a response is sent to the guest.
>>>>> It happens so that under TCG, if the guest has no timers configured
>>>>> (and
>>>>> thus no interrupt will cause the CPU to exit), the RCU thread does not
>>>>> have enough time to grab the locks and recalculate the FlatView.
>>>>> That’s not a big problem in practice since most guests will assume a
>>>>> response will happen later in time and go on to do different things,
>>>>> potentially triggering interrupts and allowing the RCU context to run.
>>>>> If the guest waits for the unmap command to complete though, it blocks
>>>>> indefinitely. Attaching to the QEMU monitor and force quitting the guest
>>>>> allows the cleanup to continue.
>>>>> There's no reason why the FlatView recalculation can't occur right
>>>>> away
>>>>> when we delete the blob subregion, however. It does not, because when we
>>>>> create the subregion we set the object as its own parent:
>>>>> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
>>>>> The extra reference is what prevents freeing the memory region
>>>>> object in
>>>>> the memory transaction of deleting the subregion.
>>>>> This commit changes the owner object to the device, which removes
>>>>> the
>>>>> extra owner reference in the memory region and causes the MR to be
>>>>> freed right away in the main context.
>>>>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>>>>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>>>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>>>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>>>>> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
>>>>> Cc: qemu-stable@nongnu.org
>>>>> ---
>>>>> hw/display/virtio-gpu-virgl.c | 2 +-
>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>> diff --git a/hw/display/virtio-gpu-virgl.c
>>>>> b/hw/display/virtio-gpu-virgl.c
>>>>> index 71a7500de9..8fbe4e70cc 100644
>>>>> --- a/hw/display/virtio-gpu-virgl.c
>>>>> +++ b/hw/display/virtio-gpu-virgl.c
>>>>> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
>>>>> vmr->g = g;
>>>>> mr = g_new0(MemoryRegion, 1);
>>>>> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size,
>>>>> data);
>>>>> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
>>>>> memory_region_add_subregion(&b->hostmem, offset, mr);
>>>>> memory_region_set_enabled(mr, true);
>>>>>
>>>>
>>>> I suggest dropping this patch for now due to the reason I pointed out
>>>> for the first version of this series.
>>>
>>> This fixes an actual bug - without it we get a hang.
>>>
>>
>> I understand that but it also introduces a regression; "[PATCH v3 14/20]
>> ui/gtk-gl-area: Remove extra draw call in refresh" is also a similar case.
>>
>> Ideally such a bug should be fixed without regression, but I understand
>> it is sometimes difficult to do that and postponing the bug resolution
>> until figuring out the correct way does not make sense.
>>
>> In such a case, a bug should be fixed minimizing the regression and the
>> documentation of the regression should be left in the code.
>>
>> In particular, this patch can cause use-after-free whether TCG is used
>> or not. Instead, I suggest to avoid freeing memory regions at all on
>> TCG. It will surely leak memory, but won't result in use-after-free at
>> least and the other accelerators will be unaffected.
>>
>> Regards,
>> Akihiko Odaki
>
> We tested this fix with ASAN and didn't see anything. Do you have a
> test case in mind that can reproduce this use-after-free? It'd help
> make a certain decision on whether to drop this patch or not. I'm not
> doubting that this can cause a use-after-free by the way, it's just
> that it is hypothetical only. If it causes a use-after-free for sure
> we should definitely drop it.
No, I don't have a test case and it should rarely occur. More
concretely, a UAF occurs if the guest accesses the memory region while
trying to unmap it. It is just a theory indeed, but the theory says the
UAF is possible.
>
>> Instead, I suggest to avoid freeing memory regions at all on
>> TCG. It will surely leak memory, but won't result in use-after-free at
>> least and the other accelerators will be unaffected.
>
> Leaking memory for blob objects is also not ideal, since they are
> frequently allocated. It's memory-safe but the leak can accumulate
> over time.
>
Memory safety and leak free cannot be compatible unless RCU is fixed. We
need to choose either of them.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 7:40 ` Akihiko Odaki
@ 2025-05-22 9:28 ` Alex Bennée
2025-05-22 9:54 ` Akihiko Odaki
0 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-22 9:28 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Manos Pitsidianakis, qemu-devel, Pierrick Bouvier, Thomas Huth,
Paolo Bonzini, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, qemu-stable
Akihiko Odaki <akihiko.odaki@daynix.com> writes:
> On 2025/05/22 16:31, Manos Pitsidianakis wrote:
>> On Thu, May 22, 2025 at 10:03 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>>>
>>> On 2025/05/22 15:45, Alex Bennée wrote:
>>>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>>>
>>>>> On 2025/05/22 1:42, Alex Bennée wrote:
>>>>>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>>>>> This commit fixes an indefinite hang when using VIRTIO GPU blob
>>>>>> objects
>>>>>> under TCG in certain conditions.
>>>>>> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
>>>>>> MemoryRegion and attaches it to an offset on a PCI BAR of the
>>>>>> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
>>>>>> it.
>>>>>> Because virglrenderer commands are not thread-safe they are only
>>>>>> called on the main context and QEMU performs the cleanup in three steps
>>>>>> to prevent a use-after-free scenario where the guest can access the
>>>>>> region after it’s unmapped:
>>>>>> 1. From the main context, the region’s field finish_unmapping is
>>>>>> false
>>>>>> by default, so it sets a variable cmd_suspended, increases the
>>>>>> renderer_blocked variable, deletes the blob subregion, and unparents
>>>>>> the blob subregion causing its reference count to decrement.
>>>>>> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
>>>>>> recalculated, the free callback of the blob region
>>>>>> virtio_gpu_virgl_hostmem_region_free is called which sets the
>>>>>> region’s field finish_unmapping to true, allowing the main thread
>>>>>> context to finish replying to the command
>>>>>> 3. From the main context, the command is processed again, but this
>>>>>> time
>>>>>> finish_unmapping is true, so virgl_renderer_resource_unmap can be
>>>>>> called and a response is sent to the guest.
>>>>>> It happens so that under TCG, if the guest has no timers configured
>>>>>> (and
>>>>>> thus no interrupt will cause the CPU to exit), the RCU thread does not
>>>>>> have enough time to grab the locks and recalculate the FlatView.
>>>>>> That’s not a big problem in practice since most guests will assume a
>>>>>> response will happen later in time and go on to do different things,
>>>>>> potentially triggering interrupts and allowing the RCU context to run.
>>>>>> If the guest waits for the unmap command to complete though, it blocks
>>>>>> indefinitely. Attaching to the QEMU monitor and force quitting the guest
>>>>>> allows the cleanup to continue.
>>>>>> There's no reason why the FlatView recalculation can't occur right
>>>>>> away
>>>>>> when we delete the blob subregion, however. It does not, because when we
>>>>>> create the subregion we set the object as its own parent:
>>>>>> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
>>>>>> The extra reference is what prevents freeing the memory region
>>>>>> object in
>>>>>> the memory transaction of deleting the subregion.
>>>>>> This commit changes the owner object to the device, which removes
>>>>>> the
>>>>>> extra owner reference in the memory region and causes the MR to be
>>>>>> freed right away in the main context.
>>>>>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>>>>>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>>>>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>>>>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>>>>>> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
>>>>>> Cc: qemu-stable@nongnu.org
>>>>>> ---
>>>>>> hw/display/virtio-gpu-virgl.c | 2 +-
>>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>> diff --git a/hw/display/virtio-gpu-virgl.c
>>>>>> b/hw/display/virtio-gpu-virgl.c
>>>>>> index 71a7500de9..8fbe4e70cc 100644
>>>>>> --- a/hw/display/virtio-gpu-virgl.c
>>>>>> +++ b/hw/display/virtio-gpu-virgl.c
>>>>>> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
>>>>>> vmr->g = g;
>>>>>> mr = g_new0(MemoryRegion, 1);
>>>>>> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size,
>>>>>> data);
>>>>>> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
>>>>>> memory_region_add_subregion(&b->hostmem, offset, mr);
>>>>>> memory_region_set_enabled(mr, true);
>>>>>>
>>>>>
>>>>> I suggest dropping this patch for now due to the reason I pointed out
>>>>> for the first version of this series.
>>>>
>>>> This fixes an actual bug - without it we get a hang.
>>>>
>>>
>>> I understand that but it also introduces a regression; "[PATCH v3 14/20]
>>> ui/gtk-gl-area: Remove extra draw call in refresh" is also a similar case.
>>>
>>> Ideally such a bug should be fixed without regression, but I understand
>>> it is sometimes difficult to do that and postponing the bug resolution
>>> until figuring out the correct way does not make sense.
>>>
>>> In such a case, a bug should be fixed minimizing the regression and the
>>> documentation of the regression should be left in the code.
>>>
>>> In particular, this patch can cause use-after-free whether TCG is used
>>> or not. Instead, I suggest to avoid freeing memory regions at all on
>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>> least and the other accelerators will be unaffected.
>>>
>>> Regards,
>>> Akihiko Odaki
>> We tested this fix with ASAN and didn't see anything. Do you have a
>> test case in mind that can reproduce this use-after-free? It'd help
>> make a certain decision on whether to drop this patch or not. I'm not
>> doubting that this can cause a use-after-free by the way, it's just
>> that it is hypothetical only. If it causes a use-after-free for sure
>> we should definitely drop it.
>
> No, I don't have a test case and it should rarely occur. More
> concretely, a UAF occurs if the guest accesses the memory region while
> trying to unmap it. It is just a theory indeed, but the theory says
> the UAF is possible.
I have a test case this fixes which I think trumps a theoretical UAF
without a test case.
Why would the guest attempt to access after triggering the free itself?
Wouldn't it be correct to fault the guest for violating its own memory
safety rules?
>>> Instead, I suggest to avoid freeing memory regions at all on
>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>> least and the other accelerators will be unaffected.
>> Leaking memory for blob objects is also not ideal, since they are
>> frequently allocated. It's memory-safe but the leak can accumulate
>> over time.
>>
>
> Memory safety and leak free cannot be compatible unless RCU is fixed.
> We need to choose either of them.
How can the guest access something that is now unmapped? The RCU should
only run after the flatview has been updated.
>
> Regards,
> Akihiko Odaki
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 9:28 ` Alex Bennée
@ 2025-05-22 9:54 ` Akihiko Odaki
2025-05-27 10:05 ` Alex Bennée
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 9:54 UTC (permalink / raw)
To: Alex Bennée
Cc: Manos Pitsidianakis, qemu-devel, Pierrick Bouvier, Thomas Huth,
Paolo Bonzini, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, qemu-stable
On 2025/05/22 18:28, Alex Bennée wrote:
> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>
>> On 2025/05/22 16:31, Manos Pitsidianakis wrote:
>>> On Thu, May 22, 2025 at 10:03 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>>>>
>>>> On 2025/05/22 15:45, Alex Bennée wrote:
>>>>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>>>>
>>>>>> On 2025/05/22 1:42, Alex Bennée wrote:
>>>>>>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>>>>>> This commit fixes an indefinite hang when using VIRTIO GPU blob
>>>>>>> objects
>>>>>>> under TCG in certain conditions.
>>>>>>> The VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB VIRTIO command creates a
>>>>>>> MemoryRegion and attaches it to an offset on a PCI BAR of the
>>>>>>> VirtIOGPUdevice. The VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB command unmaps
>>>>>>> it.
>>>>>>> Because virglrenderer commands are not thread-safe they are only
>>>>>>> called on the main context and QEMU performs the cleanup in three steps
>>>>>>> to prevent a use-after-free scenario where the guest can access the
>>>>>>> region after it’s unmapped:
>>>>>>> 1. From the main context, the region’s field finish_unmapping is
>>>>>>> false
>>>>>>> by default, so it sets a variable cmd_suspended, increases the
>>>>>>> renderer_blocked variable, deletes the blob subregion, and unparents
>>>>>>> the blob subregion causing its reference count to decrement.
>>>>>>> 2. From an RCU context, the MemoryView gets freed, the FlatView gets
>>>>>>> recalculated, the free callback of the blob region
>>>>>>> virtio_gpu_virgl_hostmem_region_free is called which sets the
>>>>>>> region’s field finish_unmapping to true, allowing the main thread
>>>>>>> context to finish replying to the command
>>>>>>> 3. From the main context, the command is processed again, but this
>>>>>>> time
>>>>>>> finish_unmapping is true, so virgl_renderer_resource_unmap can be
>>>>>>> called and a response is sent to the guest.
>>>>>>> It happens so that under TCG, if the guest has no timers configured
>>>>>>> (and
>>>>>>> thus no interrupt will cause the CPU to exit), the RCU thread does not
>>>>>>> have enough time to grab the locks and recalculate the FlatView.
>>>>>>> That’s not a big problem in practice since most guests will assume a
>>>>>>> response will happen later in time and go on to do different things,
>>>>>>> potentially triggering interrupts and allowing the RCU context to run.
>>>>>>> If the guest waits for the unmap command to complete though, it blocks
>>>>>>> indefinitely. Attaching to the QEMU monitor and force quitting the guest
>>>>>>> allows the cleanup to continue.
>>>>>>> There's no reason why the FlatView recalculation can't occur right
>>>>>>> away
>>>>>>> when we delete the blob subregion, however. It does not, because when we
>>>>>>> create the subregion we set the object as its own parent:
>>>>>>> memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size, data);
>>>>>>> The extra reference is what prevents freeing the memory region
>>>>>>> object in
>>>>>>> the memory transaction of deleting the subregion.
>>>>>>> This commit changes the owner object to the device, which removes
>>>>>>> the
>>>>>>> extra owner reference in the memory region and causes the MR to be
>>>>>>> freed right away in the main context.
>>>>>>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>>>>>>> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
>>>>>>> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
>>>>>>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>>>>>>> Message-Id: <20250410122643.1747913-3-manos.pitsidianakis@linaro.org>
>>>>>>> Cc: qemu-stable@nongnu.org
>>>>>>> ---
>>>>>>> hw/display/virtio-gpu-virgl.c | 2 +-
>>>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>> diff --git a/hw/display/virtio-gpu-virgl.c
>>>>>>> b/hw/display/virtio-gpu-virgl.c
>>>>>>> index 71a7500de9..8fbe4e70cc 100644
>>>>>>> --- a/hw/display/virtio-gpu-virgl.c
>>>>>>> +++ b/hw/display/virtio-gpu-virgl.c
>>>>>>> @@ -112,7 +112,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
>>>>>>> vmr->g = g;
>>>>>>> mr = g_new0(MemoryRegion, 1);
>>>>>>> - memory_region_init_ram_ptr(mr, OBJECT(mr), "blob", size,
>>>>>>> data);
>>>>>>> + memory_region_init_ram_ptr(mr, OBJECT(g), "blob", size, data);
>>>>>>> memory_region_add_subregion(&b->hostmem, offset, mr);
>>>>>>> memory_region_set_enabled(mr, true);
>>>>>>>
>>>>>>
>>>>>> I suggest dropping this patch for now due to the reason I pointed out
>>>>>> for the first version of this series.
>>>>>
>>>>> This fixes an actual bug - without it we get a hang.
>>>>>
>>>>
>>>> I understand that but it also introduces a regression; "[PATCH v3 14/20]
>>>> ui/gtk-gl-area: Remove extra draw call in refresh" is also a similar case.
>>>>
>>>> Ideally such a bug should be fixed without regression, but I understand
>>>> it is sometimes difficult to do that and postponing the bug resolution
>>>> until figuring out the correct way does not make sense.
>>>>
>>>> In such a case, a bug should be fixed minimizing the regression and the
>>>> documentation of the regression should be left in the code.
>>>>
>>>> In particular, this patch can cause use-after-free whether TCG is used
>>>> or not. Instead, I suggest to avoid freeing memory regions at all on
>>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>>> least and the other accelerators will be unaffected.
>>>>
>>>> Regards,
>>>> Akihiko Odaki
>>> We tested this fix with ASAN and didn't see anything. Do you have a
>>> test case in mind that can reproduce this use-after-free? It'd help
>>> make a certain decision on whether to drop this patch or not. I'm not
>>> doubting that this can cause a use-after-free by the way, it's just
>>> that it is hypothetical only. If it causes a use-after-free for sure
>>> we should definitely drop it.
>>
>> No, I don't have a test case and it should rarely occur. More
>> concretely, a UAF occurs if the guest accesses the memory region while
>> trying to unmap it. It is just a theory indeed, but the theory says
>> the UAF is possible.
>
> I have a test case this fixes which I think trumps a theoretical UAF
> without a test case.
>
> Why would the guest attempt to access after triggering the free itself?
> Wouldn't it be correct to fault the guest for violating its own memory
> safety rules?
docs/devel/secure-coding-practices.rst says "Unexpected accesses must
not cause memory corruption or leaks in QEMU".
I'm not completely sure whether it is safe without concurrent accesses
either. In particular, KVM does not immediately update the guest memory
mapping, so it may result in a time window where the guest memory is
mapped to an unmapped host memory region, and I suspect that could cause
a problem. That also motivates limiting the scope of the change to TCG.
>
>>>> Instead, I suggest to avoid freeing memory regions at all on
>>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>>> least and the other accelerators will be unaffected.
>>> Leaking memory for blob objects is also not ideal, since they are
>>> frequently allocated. It's memory-safe but the leak can accumulate
>>> over time.
>>>
>>
>> Memory safety and leak free cannot be compatible unless RCU is fixed.
>> We need to choose either of them.
>
> How can the guest access something that is now unmapped? The RCU should
> only run after the flatview has been updated.
This patch bypasses RCU. That's why it solves the hang even though the
RCU itself is not fixed.
Let me summarize the theory and the actual behavior below:
The theory is that RCU satisfies the common requirement of concurrent
algorithms. More concretely:
1) It is race-free; for RCU, it means it prevents use-after-free.
2) It does not prevent forward progress.
The patch message suggests 2) is not satisfied. A proper fix would be to
change RCU to satisfy 2).
However, this patch workarounds the problem by circumventing RCU, which
solves 2) but it regresses 1).
My suggestion is to document and to limit the impact of 1) by:
a) Limiting the scope of the change to TCG.
b) Not freeing memory regions, which will prevent use-after-free while
leaking memory.
Manos said b) can be problematic because mappings are frequently
created. Whether b) makes sense or not depends on the probability and
impact of UAF and memory leak.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet
2025-05-22 6:29 ` Akihiko Odaki
@ 2025-05-22 10:05 ` Alex Bennée
2025-05-22 10:15 ` Akihiko Odaki
0 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-22 10:05 UTC (permalink / raw)
To: Akihiko Odaki
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Dominik 'Disconnect3d' Czarnota,
Patryk 'patryk4815' Sondej
Akihiko Odaki <akihiko.odaki@daynix.com> writes:
> On 2025/05/22 1:42, Alex Bennée wrote:
>> From: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>> This commit adds support for the `qGDBServerVersion` packet to the
>> qemu
>> gdbstub which could be used by clients to detect the QEMU version
>> (and, e.g., use a workaround for known bugs).
>> This packet is not documented/standarized by GDB but it was
>> implemented
>> by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
>> This has been implemented by Patryk, who I included in
>> Co-authored-by
>> and who asked me to send the patch.
>> [0]
>> https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
>> [1] https://github.com/pwndbg/pwndbg/issues/2648
>> Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com>
>> Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>> Message-Id: <20250403191340.53343-1-dominik.b.czarnota@gmail.com>
>> [AJB: fix include, checkpatch linewrap]
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> gdbstub/gdbstub.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
>> index 6023c80d25..def0b7e877 100644
>> --- a/gdbstub/gdbstub.c
>> +++ b/gdbstub/gdbstub.c
>> @@ -28,6 +28,7 @@
>> #include "qemu/cutils.h"
>> #include "qemu/module.h"
>> #include "qemu/error-report.h"
>> +#include "qemu/target-info.h"
>> #include "trace.h"
>> #include "exec/gdbstub.h"
>> #include "gdbstub/commands.h"
>> @@ -1597,6 +1598,18 @@ static void handle_query_threads(GArray *params, void *user_ctx)
>> gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu);
>> }
>> +static void handle_query_gdb_server_version(GArray *params, void
>> *user_ctx)
>> +{
>> +#if defined(CONFIG_USER_ONLY)
>> + g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;",
>> + target_name(), QEMU_VERSION);
>> +#else
>> + g_string_printf(gdbserver_state.str_buf, "name:qemu-system-%s;version:%s;",
>> + target_name(), QEMU_VERSION);
>> +#endif
>
> I sugguest passing "qemu" as the name property.
>
> I guess LLDB developers chose to explicitly have the key-value pair
> syntax so that users can have one unified logic for parsing and avoid
> the mess of HTTP's User-Agent; there is a proposal for Web that
> introduces key-value pairs in a similar manner:
> https://developer.chrome.com/docs/privacy-security/user-agent-client-hints
>
> If we embed more information like to the name property, users will
> need to have an additional logic to know if it's QEMU or to know other
> information. Instead, we can emit:
> name:qemu;version:10.0.50;
>
> and we can use something like follows if we want to tell more:
> name:qemu;version:10.0.50;qemu-mode:system;qemu-target:hexagon;
I think we are getting into bike shedding territory here. GDB does need
a decent way to communicate about supported targets and when it comes up
with one we shall implement it. But I don't think we need to give too
much thought to this custom response for now.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet
2025-05-22 10:05 ` Alex Bennée
@ 2025-05-22 10:15 ` Akihiko Odaki
0 siblings, 0 replies; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 10:15 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Dominik 'Disconnect3d' Czarnota,
Patryk 'patryk4815' Sondej
On 2025/05/22 19:05, Alex Bennée wrote:
> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>
>> On 2025/05/22 1:42, Alex Bennée wrote:
>>> From: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>>> This commit adds support for the `qGDBServerVersion` packet to the
>>> qemu
>>> gdbstub which could be used by clients to detect the QEMU version
>>> (and, e.g., use a workaround for known bugs).
>>> This packet is not documented/standarized by GDB but it was
>>> implemented
>>> by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
>>> This has been implemented by Patryk, who I included in
>>> Co-authored-by
>>> and who asked me to send the patch.
>>> [0]
>>> https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
>>> [1] https://github.com/pwndbg/pwndbg/issues/2648
>>> Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com>
>>> Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>>> Message-Id: <20250403191340.53343-1-dominik.b.czarnota@gmail.com>
>>> [AJB: fix include, checkpatch linewrap]
>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>> ---
>>> gdbstub/gdbstub.c | 17 +++++++++++++++++
>>> 1 file changed, 17 insertions(+)
>>> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
>>> index 6023c80d25..def0b7e877 100644
>>> --- a/gdbstub/gdbstub.c
>>> +++ b/gdbstub/gdbstub.c
>>> @@ -28,6 +28,7 @@
>>> #include "qemu/cutils.h"
>>> #include "qemu/module.h"
>>> #include "qemu/error-report.h"
>>> +#include "qemu/target-info.h"
>>> #include "trace.h"
>>> #include "exec/gdbstub.h"
>>> #include "gdbstub/commands.h"
>>> @@ -1597,6 +1598,18 @@ static void handle_query_threads(GArray *params, void *user_ctx)
>>> gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu);
>>> }
>>> +static void handle_query_gdb_server_version(GArray *params, void
>>> *user_ctx)
>>> +{
>>> +#if defined(CONFIG_USER_ONLY)
>>> + g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;",
>>> + target_name(), QEMU_VERSION);
>>> +#else
>>> + g_string_printf(gdbserver_state.str_buf, "name:qemu-system-%s;version:%s;",
>>> + target_name(), QEMU_VERSION);
>>> +#endif
>>
>> I sugguest passing "qemu" as the name property.
>>
>> I guess LLDB developers chose to explicitly have the key-value pair
>> syntax so that users can have one unified logic for parsing and avoid
>> the mess of HTTP's User-Agent; there is a proposal for Web that
>> introduces key-value pairs in a similar manner:
>> https://developer.chrome.com/docs/privacy-security/user-agent-client-hints
>>
>> If we embed more information like to the name property, users will
>> need to have an additional logic to know if it's QEMU or to know other
>> information. Instead, we can emit:
>> name:qemu;version:10.0.50;
>>
>> and we can use something like follows if we want to tell more:
>> name:qemu;version:10.0.50;qemu-mode:system;qemu-target:hexagon;
>
> I think we are getting into bike shedding territory here. GDB does need
> a decent way to communicate about supported targets and when it comes up
> with one we shall implement it. But I don't think we need to give too
> much thought to this custom response for now.
>
My suggestion is to pass just "qemu" as the name. The example with
"qemu-mode" and "qemu-target" is a demonstration of how additional
information should be provided, and I don't think we need to provide the
mode and target information now. We can think of details when adding
such information.
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps
2025-05-22 5:37 ` Akihiko Odaki
@ 2025-05-22 10:31 ` Alex Bennée
2025-05-22 10:35 ` Akihiko Odaki
0 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-22 10:31 UTC (permalink / raw)
To: Akihiko Odaki
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
Akihiko Odaki <akihiko.odaki@daynix.com> writes:
> On 2025/05/22 1:42, Alex Bennée wrote:
>> The user can run a subset of the tcg tests directly, e.g.:
>> make run-tcg-tests-hexagon-linux-user
>> but in this case we fail if there has not been a full build to
>> ensure
>> all the test-plugins are there. Fix the dependency to ensure we always
>> will build them before running tests.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> tests/Makefile.include | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index 23fb722d42..7f7f62cbf6 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -46,7 +46,7 @@ $(foreach TARGET,$(TCG_TESTS_TARGETS), \
>> $(eval $(BUILD_DIR)/tests/tcg/config-$(TARGET).mak: config-host.mak))
>> .PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%)
>> -$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak
>> +$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak test-plugins
>
> I don't think this is going to work.
>
> test-plugins will invoke run-ninja, which is defined as follows:
>
> run-ninja: config-host.mak
> ifneq ($(filter $(ninja-targets), $(ninja-cmd-goals)),)
> +$(if $(MAKE.nq),@:,$(quiet-@)$(NINJA) $(NINJAFLAGS) \
> $(sort $(filter $(ninja-targets), $(ninja-cmd-goals))) | cat)
>
> $(ninja-cmd-goals) should contain test-plugins, but it doesn't if I
> understand it correctly.
It certainly does:
➜ rm -rf tests/tcg/plugins/
🕙11:31:03 alex@draig:qemu.git/builds/all on HEAD (61e51c3) (REBASING 5/26) [$?]
➜ make test-plugins
/home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson introspect --targets --tests --benchmarks | /home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
[1/14] Compiling C object tests/tcg/plugins/libbb.so.p/bb.c.o
[2/14] Linking target tests/tcg/plugins/libbb.so
[3/14] Compiling C object tests/tcg/plugins/libempty.so.p/empty.c.o
[4/14] Linking target tests/tcg/plugins/libempty.so
[5/14] Compiling C object tests/tcg/plugins/libinline.so.p/inline.c.o
[6/14] Linking target tests/tcg/plugins/libinline.so
[7/14] Compiling C object tests/tcg/plugins/libinsn.so.p/insn.c.o
[8/14] Linking target tests/tcg/plugins/libinsn.so
[9/14] Compiling C object tests/tcg/plugins/libmem.so.p/mem.c.o
[10/14] Linking target tests/tcg/plugins/libmem.so
[11/14] Compiling C object tests/tcg/plugins/libreset.so.p/reset.c.o
[12/14] Linking target tests/tcg/plugins/libreset.so
[13/14] Compiling C object tests/tcg/plugins/libsyscall.so.p/syscall.c.o
[14/14] Linking target tests/tcg/plugins/libsyscall.so
>
>> $(call quiet-command, \
>> $(MAKE) -C tests/tcg/$* $(SUBDIR_MAKEFLAGS), \
>> "BUILD","$* guest-tests")
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps
2025-05-22 10:31 ` Alex Bennée
@ 2025-05-22 10:35 ` Akihiko Odaki
2025-05-25 15:18 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-22 10:35 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Philippe Mathieu-Daudé, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin
On 2025/05/22 19:31, Alex Bennée wrote:
> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>
>> On 2025/05/22 1:42, Alex Bennée wrote:
>>> The user can run a subset of the tcg tests directly, e.g.:
>>> make run-tcg-tests-hexagon-linux-user
>>> but in this case we fail if there has not been a full build to
>>> ensure
>>> all the test-plugins are there. Fix the dependency to ensure we always
>>> will build them before running tests.
>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>> ---
>>> tests/Makefile.include | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>>> index 23fb722d42..7f7f62cbf6 100644
>>> --- a/tests/Makefile.include
>>> +++ b/tests/Makefile.include
>>> @@ -46,7 +46,7 @@ $(foreach TARGET,$(TCG_TESTS_TARGETS), \
>>> $(eval $(BUILD_DIR)/tests/tcg/config-$(TARGET).mak: config-host.mak))
>>> .PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%)
>>> -$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak
>>> +$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%: $(BUILD_DIR)/tests/tcg/config-%.mak test-plugins
>>
>> I don't think this is going to work.
>>
>> test-plugins will invoke run-ninja, which is defined as follows:
>>
>> run-ninja: config-host.mak
>> ifneq ($(filter $(ninja-targets), $(ninja-cmd-goals)),)
>> +$(if $(MAKE.nq),@:,$(quiet-@)$(NINJA) $(NINJAFLAGS) \
>> $(sort $(filter $(ninja-targets), $(ninja-cmd-goals))) | cat)
>>
>> $(ninja-cmd-goals) should contain test-plugins, but it doesn't if I
>> understand it correctly.
>
> It certainly does:
>
> ➜ rm -rf tests/tcg/plugins/
> 🕙11:31:03 alex@draig:qemu.git/builds/all on HEAD (61e51c3) (REBASING 5/26) [$?]
> ➜ make test-plugins
> /home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson introspect --targets --tests --benchmarks | /home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
> [1/14] Compiling C object tests/tcg/plugins/libbb.so.p/bb.c.o
> [2/14] Linking target tests/tcg/plugins/libbb.so
> [3/14] Compiling C object tests/tcg/plugins/libempty.so.p/empty.c.o
> [4/14] Linking target tests/tcg/plugins/libempty.so
> [5/14] Compiling C object tests/tcg/plugins/libinline.so.p/inline.c.o
> [6/14] Linking target tests/tcg/plugins/libinline.so
> [7/14] Compiling C object tests/tcg/plugins/libinsn.so.p/insn.c.o
> [8/14] Linking target tests/tcg/plugins/libinsn.so
> [9/14] Compiling C object tests/tcg/plugins/libmem.so.p/mem.c.o
> [10/14] Linking target tests/tcg/plugins/libmem.so
> [11/14] Compiling C object tests/tcg/plugins/libreset.so.p/reset.c.o
> [12/14] Linking target tests/tcg/plugins/libreset.so
> [13/14] Compiling C object tests/tcg/plugins/libsyscall.so.p/syscall.c.o
> [14/14] Linking target tests/tcg/plugins/libsyscall.so
>
ninja-cmd-goals is defined as follows:
ninja-cmd-goals = $(or $(MAKECMDGOALS), all)
ninja-cmd-goals += $(foreach g, $(MAKECMDGOALS), $(.ninja-goals.$g))
If you run "make test-plugins", $(ninja-cmd-goals) will contain
"test-plugins" because $(MAKECMDGOALS) will be "test-plugins". It won't
if you run "make run-tcg-tests-hexagon-linux-user".
Regards,
Akihiko Odaki
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers
2025-05-21 16:42 ` [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers Alex Bennée
2025-05-22 5:16 ` Markus Armbruster
@ 2025-05-24 11:07 ` Michael S. Tsirkin
2025-05-25 15:20 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 52+ messages in thread
From: Michael S. Tsirkin @ 2025-05-24 11:07 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero
On Wed, May 21, 2025 at 05:42:40PM +0100, Alex Bennée wrote:
> Thanks for volunteering to help.
>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Great!
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> MAINTAINERS | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 8dfb393c06..a14e2796e0 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2674,6 +2674,8 @@ F: include/hw/display/ramfb.h
>
> virtio-gpu
> M: Alex Bennée <alex.bennee@linaro.org>
> +R: Akihiko Odaki <akihiko.odaki@daynix.com>
> +R: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> S: Odd Fixes
> F: hw/display/virtio-gpu*
> F: hw/display/virtio-vga.*
> --
> 2.39.5
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps
2025-05-22 10:35 ` Akihiko Odaki
@ 2025-05-25 15:18 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 52+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-25 15:18 UTC (permalink / raw)
To: Akihiko Odaki, Alex Bennée
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
On 22/5/25 11:35, Akihiko Odaki wrote:
> On 2025/05/22 19:31, Alex Bennée wrote:
>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>
>>> On 2025/05/22 1:42, Alex Bennée wrote:
>>>> The user can run a subset of the tcg tests directly, e.g.:
>>>> make run-tcg-tests-hexagon-linux-user
>>>> but in this case we fail if there has not been a full build to
>>>> ensure
>>>> all the test-plugins are there. Fix the dependency to ensure we always
>>>> will build them before running tests.
>>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>>> ---
>>>> tests/Makefile.include | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>>>> index 23fb722d42..7f7f62cbf6 100644
>>>> --- a/tests/Makefile.include
>>>> +++ b/tests/Makefile.include
>>>> @@ -46,7 +46,7 @@ $(foreach TARGET,$(TCG_TESTS_TARGETS), \
>>>> $(eval $(BUILD_DIR)/tests/tcg/config-$(TARGET).mak:
>>>> config-host.mak))
>>>> .PHONY: $(TCG_TESTS_TARGETS:%=build-tcg-tests-%)
>>>> -$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%:
>>>> $(BUILD_DIR)/tests/tcg/config-%.mak
>>>> +$(TCG_TESTS_TARGETS:%=build-tcg-tests-%): build-tcg-tests-%:
>>>> $(BUILD_DIR)/tests/tcg/config-%.mak test-plugins
>>>
>>> I don't think this is going to work.
>>>
>>> test-plugins will invoke run-ninja, which is defined as follows:
>>>
>>> run-ninja: config-host.mak
>>> ifneq ($(filter $(ninja-targets), $(ninja-cmd-goals)),)
>>> +$(if $(MAKE.nq),@:,$(quiet-@)$(NINJA) $(NINJAFLAGS) \
>>> $(sort $(filter $(ninja-targets), $(ninja-cmd-goals))) | cat)
>>>
>>> $(ninja-cmd-goals) should contain test-plugins, but it doesn't if I
>>> understand it correctly.
>>
>> It certainly does:
>>
>> ➜ rm -rf tests/tcg/plugins/
>> 🕙11:31:03 alex@draig:qemu.git/builds/all on HEAD (61e51c3)
>> (REBASING 5/26) [$?]
>> ➜ make test-plugins
>> /home/alex/lsrc/qemu.git/builds/all/pyvenv/bin/meson introspect --
>> targets --tests --benchmarks | /home/alex/lsrc/qemu.git/builds/all/
>> pyvenv/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
>> [1/14] Compiling C object tests/tcg/plugins/libbb.so.p/bb.c.o
>> [2/14] Linking target tests/tcg/plugins/libbb.so
>> [3/14] Compiling C object tests/tcg/plugins/libempty.so.p/empty.c.o
>> [4/14] Linking target tests/tcg/plugins/libempty.so
>> [5/14] Compiling C object tests/tcg/plugins/libinline.so.p/inline.c.o
>> [6/14] Linking target tests/tcg/plugins/libinline.so
>> [7/14] Compiling C object tests/tcg/plugins/libinsn.so.p/insn.c.o
>> [8/14] Linking target tests/tcg/plugins/libinsn.so
>> [9/14] Compiling C object tests/tcg/plugins/libmem.so.p/mem.c.o
>> [10/14] Linking target tests/tcg/plugins/libmem.so
>> [11/14] Compiling C object tests/tcg/plugins/libreset.so.p/reset.c.o
>> [12/14] Linking target tests/tcg/plugins/libreset.so
>> [13/14] Compiling C object tests/tcg/plugins/libsyscall.so.p/syscall.c.o
>> [14/14] Linking target tests/tcg/plugins/libsyscall.so
>>
>
> ninja-cmd-goals is defined as follows:
>
> ninja-cmd-goals = $(or $(MAKECMDGOALS), all)
> ninja-cmd-goals += $(foreach g, $(MAKECMDGOALS), $(.ninja-goals.$g))
>
> If you run "make test-plugins", $(ninja-cmd-goals) will contain "test-
> plugins" because $(MAKECMDGOALS) will be "test-plugins". It won't if you
> run "make run-tcg-tests-hexagon-linux-user".
It seems Akihiko is right, this patch doesn't fix my use case.
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan
2025-05-22 5:19 ` Akihiko Odaki
@ 2025-05-25 15:18 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 52+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-25 15:18 UTC (permalink / raw)
To: Akihiko Odaki, Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm, Mahmoud Mandour,
Sriram Yagnaraman, Dmitry Osipenko, Gustavo Romero,
Michael S. Tsirkin, Nabih Estefan, Richard Henderson
On 22/5/25 06:19, Akihiko Odaki wrote:
> On 2025/05/22 1:42, Alex Bennée wrote:
>> From: Nabih Estefan <nabihestefan@google.com>
>>
>> ../tests/qtest/libqos/igb.c:106:5: runtime error: load of
>> misaligned address 0x562040be8e33 for type 'uint32_t', which requires
>> 4 byte alignment
>>
>> Instead of straight casting the uint8_t array, we can use ldl_le_p and
>> lduw_l_p to assure the unaligned access working properly against
>> uint32_t and uint16_t.
>
> I think the subject should mention the problem (the unaligned access)
> instead of the method used to detect it (UBSan).
"tests/qtest: Avoid unaligned access in IGB test"
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg
2025-05-22 5:45 ` Akihiko Odaki
@ 2025-05-25 15:19 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 52+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-25 15:19 UTC (permalink / raw)
To: Akihiko Odaki, Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, John Snow,
Fabiano Rosas, Peter Xu, Marc-André Lureau, Alexandre Iooss,
Markus Armbruster, David Hildenbrand, Laurent Vivier,
Daniel P. Berrangé, Peter Maydell, qemu-arm, Mahmoud Mandour,
Sriram Yagnaraman, Dmitry Osipenko, Gustavo Romero,
Michael S. Tsirkin
On 22/5/25 06:45, Akihiko Odaki wrote:
> On 2025/05/22 1:42, Alex Bennée wrote:
>> It's easy to get lost in zeros while setting the numbers of
>> instructions per second. Add a scaling suffix to make things simpler.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>
>> ---
>> v2
>> - normalise the suffix before a full strcmp0
>> - check endptr actually set
>> - fix checkpatch
>> - scale_entry -> ScaleEntry
>> - drop hz from suffix
>> ---
>> contrib/plugins/ips.c | 34 +++++++++++++++++++++++++++++++++-
>> 1 file changed, 33 insertions(+), 1 deletion(-)
>>
>> diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c
>> index e5297dbb01..eb4418c25b 100644
>> --- a/contrib/plugins/ips.c
>> +++ b/contrib/plugins/ips.c
>> @@ -129,6 +129,18 @@ static void plugin_exit(qemu_plugin_id_t id, void
>> *udata)
>> qemu_plugin_scoreboard_free(vcpus);
>> }
>> +typedef struct {
>> + const char *suffix;
>> + unsigned long multipler;
>
> As I suggested for the previous version, let's use uint32_t or uint64_t.
>
>> +} ScaleEntry;
>> +
>> +/* a bit like units.h but not binary */
>> +static
const
>> ScaleEntry scales[] = {
>> + { "k", 1000 },
>> + { "m", 1000 * 1000 },
>> + { "g", 1000 * 1000 * 1000 },
>> +};
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers
2025-05-21 16:42 ` [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers Alex Bennée
2025-05-22 5:16 ` Markus Armbruster
2025-05-24 11:07 ` Michael S. Tsirkin
@ 2025-05-25 15:20 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 52+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-25 15:20 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, Akihiko Odaki,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin
On 21/5/25 17:42, Alex Bennée wrote:
> Thanks for volunteering to help.
>
> Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
> Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> MAINTAINERS | 2 ++
> 1 file changed, 2 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet
2025-05-21 16:42 ` [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet Alex Bennée
2025-05-22 6:29 ` Akihiko Odaki
@ 2025-05-25 15:25 ` Philippe Mathieu-Daudé
2025-05-27 9:16 ` Alex Bennée
1 sibling, 1 reply; 52+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-05-25 15:25 UTC (permalink / raw)
To: Alex Bennée, qemu-devel
Cc: Pierrick Bouvier, Thomas Huth, Paolo Bonzini, Akihiko Odaki,
John Snow, Fabiano Rosas, Peter Xu, Marc-André Lureau,
Alexandre Iooss, Markus Armbruster, David Hildenbrand,
Laurent Vivier, Daniel P. Berrangé, Peter Maydell, qemu-arm,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin,
Dominik 'Disconnect3d' Czarnota,
Patryk 'patryk4815' Sondej
On 21/5/25 17:42, Alex Bennée wrote:
> From: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>
> This commit adds support for the `qGDBServerVersion` packet to the qemu
> gdbstub which could be used by clients to detect the QEMU version
> (and, e.g., use a workaround for known bugs).
>
> This packet is not documented/standarized by GDB but it was implemented
> by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
>
> This has been implemented by Patryk, who I included in Co-authored-by
> and who asked me to send the patch.
>
> [0] https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
> [1] https://github.com/pwndbg/pwndbg/issues/2648
>
> Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com>
> Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
> Message-Id: <20250403191340.53343-1-dominik.b.czarnota@gmail.com>
> [AJB: fix include, checkpatch linewrap]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> gdbstub/gdbstub.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
> index 6023c80d25..def0b7e877 100644
> --- a/gdbstub/gdbstub.c
> +++ b/gdbstub/gdbstub.c
> @@ -28,6 +28,7 @@
> #include "qemu/cutils.h"
> #include "qemu/module.h"
> #include "qemu/error-report.h"
> +#include "qemu/target-info.h"
> #include "trace.h"
> #include "exec/gdbstub.h"
> #include "gdbstub/commands.h"
> @@ -1597,6 +1598,18 @@ static void handle_query_threads(GArray *params, void *user_ctx)
> gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu);
> }
>
> +static void handle_query_gdb_server_version(GArray *params, void *user_ctx)
> +{
> +#if defined(CONFIG_USER_ONLY)
> + g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;",
> + target_name(), QEMU_VERSION);
> +#else
> + g_string_printf(gdbserver_state.str_buf, "name:qemu-system-%s;version:%s;",
> + target_name(), QEMU_VERSION);
> +#endif
g_string_printf() isn't really justified, we usually call
g_string_append().
> + gdb_put_strbuf();
> +}
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet
2025-05-25 15:25 ` Philippe Mathieu-Daudé
@ 2025-05-27 9:16 ` Alex Bennée
0 siblings, 0 replies; 52+ messages in thread
From: Alex Bennée @ 2025-05-27 9:16 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Pierrick Bouvier, Thomas Huth, Paolo Bonzini,
Akihiko Odaki, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Mahmoud Mandour, Sriram Yagnaraman,
Dmitry Osipenko, Gustavo Romero, Michael S. Tsirkin,
Dominik 'Disconnect3d' Czarnota,
Patryk 'patryk4815' Sondej
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> On 21/5/25 17:42, Alex Bennée wrote:
>> From: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>> This commit adds support for the `qGDBServerVersion` packet to the
>> qemu
>> gdbstub which could be used by clients to detect the QEMU version
>> (and, e.g., use a workaround for known bugs).
>> This packet is not documented/standarized by GDB but it was
>> implemented
>> by LLDB gdbstub [0] and is helpful for projects like Pwndbg [1].
>> This has been implemented by Patryk, who I included in
>> Co-authored-by
>> and who asked me to send the patch.
>> [0]
>> https://lldb.llvm.org/resources/lldbgdbremote.html#qgdbserverversion
>> [1] https://github.com/pwndbg/pwndbg/issues/2648
>> Co-authored-by: Patryk 'patryk4815' Sondej <patryk.sondej@gmail.com>
>> Signed-off-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
>> Message-Id: <20250403191340.53343-1-dominik.b.czarnota@gmail.com>
>> [AJB: fix include, checkpatch linewrap]
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> gdbstub/gdbstub.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>> diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
>> index 6023c80d25..def0b7e877 100644
>> --- a/gdbstub/gdbstub.c
>> +++ b/gdbstub/gdbstub.c
>> @@ -28,6 +28,7 @@
>> #include "qemu/cutils.h"
>> #include "qemu/module.h"
>> #include "qemu/error-report.h"
>> +#include "qemu/target-info.h"
>> #include "trace.h"
>> #include "exec/gdbstub.h"
>> #include "gdbstub/commands.h"
>> @@ -1597,6 +1598,18 @@ static void handle_query_threads(GArray *params, void *user_ctx)
>> gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu);
>> }
>> +static void handle_query_gdb_server_version(GArray *params, void
>> *user_ctx)
>> +{
>> +#if defined(CONFIG_USER_ONLY)
>> + g_string_printf(gdbserver_state.str_buf, "name:qemu-%s;version:%s;",
>> + target_name(), QEMU_VERSION);
>> +#else
>> + g_string_printf(gdbserver_state.str_buf, "name:qemu-system-%s;version:%s;",
>> + target_name(), QEMU_VERSION);
>> +#endif
>
> g_string_printf() isn't really justified, we usually call
> g_string_append().
How is that meant to work with a format string?
>
>> + gdb_put_strbuf();
>> +}
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-22 9:54 ` Akihiko Odaki
@ 2025-05-27 10:05 ` Alex Bennée
2025-05-27 11:03 ` Akihiko Odaki
0 siblings, 1 reply; 52+ messages in thread
From: Alex Bennée @ 2025-05-27 10:05 UTC (permalink / raw)
To: Akihiko Odaki
Cc: Manos Pitsidianakis, qemu-devel, Pierrick Bouvier, Thomas Huth,
Paolo Bonzini, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, qemu-stable
Akihiko Odaki <akihiko.odaki@daynix.com> writes:
> On 2025/05/22 18:28, Alex Bennée wrote:
>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>
>>> On 2025/05/22 16:31, Manos Pitsidianakis wrote:
>>>> On Thu, May 22, 2025 at 10:03 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>>>>>
>>>>> On 2025/05/22 15:45, Alex Bennée wrote:
>>>>>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>>>>>
>>>>>>> On 2025/05/22 1:42, Alex Bennée wrote:
>>>>>>>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
<snip>
>>>>> In such a case, a bug should be fixed minimizing the regression and the
>>>>> documentation of the regression should be left in the code.
>>>>>
>>>>> In particular, this patch can cause use-after-free whether TCG is used
>>>>> or not. Instead, I suggest to avoid freeing memory regions at all on
>>>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>>>> least and the other accelerators will be unaffected.
>>>>>
>>>>> Regards,
>>>>> Akihiko Odaki
>>>> We tested this fix with ASAN and didn't see anything. Do you have a
>>>> test case in mind that can reproduce this use-after-free? It'd help
>>>> make a certain decision on whether to drop this patch or not. I'm not
>>>> doubting that this can cause a use-after-free by the way, it's just
>>>> that it is hypothetical only. If it causes a use-after-free for sure
>>>> we should definitely drop it.
>>>
>>> No, I don't have a test case and it should rarely occur. More
>>> concretely, a UAF occurs if the guest accesses the memory region while
>>> trying to unmap it. It is just a theory indeed, but the theory says
>>> the UAF is possible.
>> I have a test case this fixes which I think trumps a theoretical UAF
>> without a test case.
>> Why would the guest attempt to access after triggering the free
>> itself?
>> Wouldn't it be correct to fault the guest for violating its own memory
>> safety rules?
>
> docs/devel/secure-coding-practices.rst says "Unexpected accesses must
> not cause memory corruption or leaks in QEMU".
Agreed.
> I'm not completely sure whether it is safe without concurrent accesses
> either. In particular, KVM does not immediately update the guest
> memory mapping, so it may result in a time window where the guest
> memory is mapped to an unmapped host memory region, and I suspect that
> could cause a problem. That also motivates limiting the scope of the
> change to TCG.
Surely it does:
memory_region_set_enabled(mr, false);
memory_region_del_subregion(&b->hostmem, mr);
will trigger a rebuilding of the flatview - so after the memory region
is deleted any guest access should trigger a fault to the guest. Only
then do we unparent the memory region and finish the clean-up.
I don't think we want to have different paths for KVM and TCG here as it
will further complicate already complicated code.
>>>>> Instead, I suggest to avoid freeing memory regions at all on
>>>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>>>> least and the other accelerators will be unaffected.
>>>> Leaking memory for blob objects is also not ideal, since they are
>>>> frequently allocated. It's memory-safe but the leak can accumulate
>>>> over time.
>>>>
>>>
>>> Memory safety and leak free cannot be compatible unless RCU is fixed.
>>> We need to choose either of them.
>> How can the guest access something that is now unmapped? The RCU
>> should
>> only run after the flatview has been updated.
>
> This patch bypasses RCU. That's why it solves the hang even though the
> RCU itself is not fixed.
>
> Let me summarize the theory and the actual behavior below:
>
> The theory is that RCU satisfies the common requirement of concurrent
> algorithms. More concretely:
> 1) It is race-free; for RCU, it means it prevents use-after-free.
> 2) It does not prevent forward progress.
>
> The patch message suggests 2) is not satisfied. A proper fix would be
> to change RCU to satisfy 2).
Its mutually incompatible with virglrenderer - we have to block all
commands until the virgl resource is freed and we can't do that until
the memory region is unplugged.
So yes we do bypass RCU for this but by explicitly un-parenting the
resource once the mapping has been removed.
> However, this patch workarounds the problem by circumventing RCU,
> which solves 2) but it regresses 1).
I'm still not seeing how this happens and without a test case to
demonstrate it happening I can't hold this patch in limbo forever.
> My suggestion is to document and to limit the impact of 1) by:
> a) Limiting the scope of the change to TCG.
> b) Not freeing memory regions, which will prevent use-after-free while
> leaking memory.
>
> Manos said b) can be problematic because mappings are frequently
> created. Whether b) makes sense or not depends on the probability and
> impact of UAF and memory leak
Not freeing memory regions would lead to a DoS attack instead. I don't
think we can just accumulate region like that.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob
2025-05-27 10:05 ` Alex Bennée
@ 2025-05-27 11:03 ` Akihiko Odaki
0 siblings, 0 replies; 52+ messages in thread
From: Akihiko Odaki @ 2025-05-27 11:03 UTC (permalink / raw)
To: Alex Bennée
Cc: Manos Pitsidianakis, qemu-devel, Pierrick Bouvier, Thomas Huth,
Paolo Bonzini, John Snow, Fabiano Rosas, Peter Xu,
Marc-André Lureau, Alexandre Iooss, Markus Armbruster,
David Hildenbrand, Laurent Vivier, Daniel P. Berrangé,
Peter Maydell, qemu-arm, Philippe Mathieu-Daudé,
Mahmoud Mandour, Sriram Yagnaraman, Dmitry Osipenko,
Gustavo Romero, Michael S. Tsirkin, qemu-stable
On 2025/05/27 19:05, Alex Bennée wrote:
> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>
>> On 2025/05/22 18:28, Alex Bennée wrote:
>>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>>
>>>> On 2025/05/22 16:31, Manos Pitsidianakis wrote:
>>>>> On Thu, May 22, 2025 at 10:03 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
>>>>>>
>>>>>> On 2025/05/22 15:45, Alex Bennée wrote:
>>>>>>> Akihiko Odaki <akihiko.odaki@daynix.com> writes:
>>>>>>>
>>>>>>>> On 2025/05/22 1:42, Alex Bennée wrote:
>>>>>>>>> From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> <snip>
>>>>>> In such a case, a bug should be fixed minimizing the regression and the
>>>>>> documentation of the regression should be left in the code.
>>>>>>
>>>>>> In particular, this patch can cause use-after-free whether TCG is used
>>>>>> or not. Instead, I suggest to avoid freeing memory regions at all on
>>>>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>>>>> least and the other accelerators will be unaffected.
>>>>>>
>>>>>> Regards,
>>>>>> Akihiko Odaki
>>>>> We tested this fix with ASAN and didn't see anything. Do you have a
>>>>> test case in mind that can reproduce this use-after-free? It'd help
>>>>> make a certain decision on whether to drop this patch or not. I'm not
>>>>> doubting that this can cause a use-after-free by the way, it's just
>>>>> that it is hypothetical only. If it causes a use-after-free for sure
>>>>> we should definitely drop it.
>>>>
>>>> No, I don't have a test case and it should rarely occur. More
>>>> concretely, a UAF occurs if the guest accesses the memory region while
>>>> trying to unmap it. It is just a theory indeed, but the theory says
>>>> the UAF is possible.
>>> I have a test case this fixes which I think trumps a theoretical UAF
>>> without a test case.
>>> Why would the guest attempt to access after triggering the free
>>> itself?
>>> Wouldn't it be correct to fault the guest for violating its own memory
>>> safety rules?
>>
>> docs/devel/secure-coding-practices.rst says "Unexpected accesses must
>> not cause memory corruption or leaks in QEMU".
>
> Agreed.
>
>> I'm not completely sure whether it is safe without concurrent accesses
>> either. In particular, KVM does not immediately update the guest
>> memory mapping, so it may result in a time window where the guest
>> memory is mapped to an unmapped host memory region, and I suspect that
>> could cause a problem. That also motivates limiting the scope of the
>> change to TCG.
>
> Surely it does:
>
> memory_region_set_enabled(mr, false);
> memory_region_del_subregion(&b->hostmem, mr);
>
> will trigger a rebuilding of the flatview - so after the memory region
> is deleted any guest access should trigger a fault to the guest. Only
> then do we unparent the memory region and finish the clean-up.
I wrongly assumed it waits for RCU, but I found it is not true.
It is still not true that any guest access will trigger a fault to the
guest. QEMU's internal AddressSpace keeps the old FlatView until the RCU
changes, and some device may still have a DMA mapping.
>
> I don't think we want to have different paths for KVM and TCG here as it
> will further complicate already complicated code.
Complexity is not a problem here. Any concurrent code has complexity
needed for correctness and reliability. We should add complexity if
needed for reliablity; otherwise, we should remove it (even if it's
already simple).
>
>>>>>> Instead, I suggest to avoid freeing memory regions at all on
>>>>>> TCG. It will surely leak memory, but won't result in use-after-free at
>>>>>> least and the other accelerators will be unaffected.
>>>>> Leaking memory for blob objects is also not ideal, since they are
>>>>> frequently allocated. It's memory-safe but the leak can accumulate
>>>>> over time.
>>>>>
>>>>
>>>> Memory safety and leak free cannot be compatible unless RCU is fixed.
>>>> We need to choose either of them.
>>> How can the guest access something that is now unmapped? The RCU
>>> should
>>> only run after the flatview has been updated.
>>
>> This patch bypasses RCU. That's why it solves the hang even though the
>> RCU itself is not fixed.
>>
>> Let me summarize the theory and the actual behavior below:
>>
>> The theory is that RCU satisfies the common requirement of concurrent
>> algorithms. More concretely:
>> 1) It is race-free; for RCU, it means it prevents use-after-free.
>> 2) It does not prevent forward progress.
>>
>> The patch message suggests 2) is not satisfied. A proper fix would be
>> to change RCU to satisfy 2).
>
> Its mutually incompatible with virglrenderer - we have to block all
> commands until the virgl resource is freed and we can't do that until
> the memory region is unplugged.
>
> So yes we do bypass RCU for this but by explicitly un-parenting the
> resource once the mapping has been removed.
The problem is that RCU doesn't free the memory region when all commands
are blocked.
If we fix RCU, RCU will free the memory region, the virgl resource will
be freed then, and the commands will be unblocked.
>
>> However, this patch workarounds the problem by circumventing RCU,
>> which solves 2) but it regresses 1).
>
> I'm still not seeing how this happens and without a test case to
> demonstrate it happening I can't hold this patch in limbo forever.
Not a test case that runs on the guest, but adding the following change
to QEMU will demonstrate the issue:
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 145a0b387956..c97cd2dfd7b3 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -182,7 +182,11 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
/* memory region owns self res->mr object and frees it by
itself */
memory_region_set_enabled(mr, false);
memory_region_del_subregion(&b->hostmem, mr);
+ memory_region_ref(OBJECT(mr));
+ int k = b->renderer_blocked;
object_unparent(OBJECT(mr));
+ assert(k == b->renderer_blocked);
+ memory_region_unref(OBJECT(mr));
}
return 0;
memory_region_ref() and memory_region_unref() emulates the begin and end
of a DMA operation on mr, respectively. In a real world scenario,
address_space_map() and address_space_unmap() call these functions.
If the code is correct, object_unparent() should not free the memory
region while the DMA operation is ongoing, so the renderer will be kept
blocked. assert(k == b->renderer_blocked) checks that.
My proposal is to limit the impact of the regression as possible as we
can and to document it, not to postpone the solution until figuring out
the problem in RCU.
>
>> My suggestion is to document and to limit the impact of 1) by:
>> a) Limiting the scope of the change to TCG.
>> b) Not freeing memory regions, which will prevent use-after-free while
>> leaking memory.
>>
>> Manos said b) can be problematic because mappings are frequently
>> created. Whether b) makes sense or not depends on the probability and
>> impact of UAF and memory leak
>
> Not freeing memory regions would lead to a DoS attack instead. I don't
> think we can just accumulate region like that.
UAF also results in DoS, and it can have a bigger consequence due to
memory corruption. Memory leak is usually safer than UAF.
The question is whether memory leak causes a practical problem; it makes
sense to opt to UAF if the accumulation happens too quickly; we at least
know that UAF is rare.
Regards,
Akihiko Odaki
^ permalink raw reply related [flat|nested] 52+ messages in thread
end of thread, other threads:[~2025-05-27 11:04 UTC | newest]
Thread overview: 52+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-21 16:42 [PATCH v3 00/20] Maintainer updates for May (testing, plugins, virtio-gpu) - pre-PR Alex Bennée
2025-05-21 16:42 ` [PATCH v3 01/20] tests/docker: expose $HOME/.cache/qemu as docker volume Alex Bennée
2025-05-22 5:23 ` Thomas Huth
2025-05-21 16:42 ` [PATCH v3 02/20] gitlab: disable debug info on CI builds Alex Bennée
2025-05-21 16:42 ` [PATCH v3 03/20] tests/tcg: make aarch64 boot.S handle different starting modes Alex Bennée
2025-05-22 5:10 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 04/20] tests/qtest: fix igb test failure under --enable-ubsan Alex Bennée
2025-05-22 5:19 ` Akihiko Odaki
2025-05-25 15:18 ` Philippe Mathieu-Daudé
2025-05-21 16:42 ` [PATCH v3 05/20] tests/Makefile: include test-plugins in per-arch build deps Alex Bennée
2025-05-22 5:37 ` Akihiko Odaki
2025-05-22 10:31 ` Alex Bennée
2025-05-22 10:35 ` Akihiko Odaki
2025-05-25 15:18 ` Philippe Mathieu-Daudé
2025-05-21 16:42 ` [PATCH v3 06/20] tests/functional: Add PCI hotplug test for aarch64 Alex Bennée
2025-05-22 5:43 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg Alex Bennée
2025-05-22 5:45 ` Akihiko Odaki
2025-05-25 15:19 ` Philippe Mathieu-Daudé
2025-05-21 16:42 ` [PATCH v3 08/20] contrib/plugins: allow setting of instructions per quantum Alex Bennée
2025-05-22 5:55 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 09/20] MAINTAINERS: add myself to virtio-gpu for Odd Fixes Alex Bennée
2025-05-22 5:16 ` Markus Armbruster
2025-05-21 16:42 ` [PATCH v3 10/20] MAINTAINERS: add Akihiko and Dmitry as reviewers Alex Bennée
2025-05-22 5:16 ` Markus Armbruster
2025-05-24 11:07 ` Michael S. Tsirkin
2025-05-25 15:20 ` Philippe Mathieu-Daudé
2025-05-21 16:42 ` [PATCH v3 11/20] hw/display: re-arrange memory region tracking Alex Bennée
2025-05-21 16:42 ` [PATCH v3 12/20] virtio-gpu: fix hang under TCG when unmapping blob Alex Bennée
2025-05-22 5:59 ` Akihiko Odaki
2025-05-22 6:45 ` Alex Bennée
2025-05-22 7:02 ` Akihiko Odaki
2025-05-22 7:31 ` Manos Pitsidianakis
2025-05-22 7:40 ` Akihiko Odaki
2025-05-22 9:28 ` Alex Bennée
2025-05-22 9:54 ` Akihiko Odaki
2025-05-27 10:05 ` Alex Bennée
2025-05-27 11:03 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 13/20] virtio-gpu: refactor async blob unmapping Alex Bennée
2025-05-21 16:42 ` [PATCH v3 14/20] ui/gtk-gl-area: Remove extra draw call in refresh Alex Bennée
2025-05-21 16:42 ` [PATCH v3 15/20] virtio-gpu: support context init multiple timeline Alex Bennée
2025-05-21 16:42 ` [PATCH v3 16/20] include/exec: fix assert in size_memop Alex Bennée
2025-05-22 6:07 ` Akihiko Odaki
2025-05-21 16:42 ` [PATCH v3 17/20] include/gdbstub: fix include guard in commands.h Alex Bennée
2025-05-21 16:42 ` [PATCH v3 18/20] gdbstub: assert earlier in handle_read_all_regs Alex Bennée
2025-05-21 16:42 ` [PATCH v3 19/20] gdbstub: Implement qGDBServerVersion packet Alex Bennée
2025-05-22 6:29 ` Akihiko Odaki
2025-05-22 10:05 ` Alex Bennée
2025-05-22 10:15 ` Akihiko Odaki
2025-05-25 15:25 ` Philippe Mathieu-Daudé
2025-05-27 9:16 ` Alex Bennée
2025-05-21 16:42 ` [PATCH v3 20/20] gdbstub: update aarch64-core.xml Alex Bennée
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).