All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 1/1] acpi/virt: suppress SPCR when UART0 has no serial backend
@ 2026-02-19 13:04 Li Chen
  2026-02-19 13:42 ` Igor Mammedov
  2026-02-20 14:50 ` Michael S. Tsirkin
  0 siblings, 2 replies; 4+ messages in thread
From: Li Chen @ 2026-02-19 13:04 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, qemu-riscv, Michael S . Tsirkin, Igor Mammedov,
	Ani Sinha, Peter Maydell, Shannon Zhao, Song Gao, Bibo Mao,
	Jiaxun Yang, Sunil V L, Palmer Dabbelt, Alistair Francis,
	Weiwei Li, Daniel Henrique Barboza, Liu Zhiwei,
	Philippe Mathieu-Daudé

From: Li Chen <chenl311@chinatelecom.cn>

virt machines always instantiate a PL011/16550 UART at slot 0 and describe
it in ACPI (DSDT and optional SPCR table). When the command line disables
the serial backend (e.g. "-serial none"), SPCR still points at UART0 and
the guest may pick it as the preferred console even though it is not
usable.

Only generate SPCR when UART0 has a chardev backend attached. Keep the
UART device description in DSDT unchanged so the guest-visible UART
topology does not change.

The bios-tables-test qtests use "-serial null" to keep SPCR enabled while
discarding firmware serial output, avoiding TAP stdout corruption.

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
---
v6 -> v7:
  Do not gate DSDT UART devices on serial_hd(0); only gate SPCR.
  Drop the serial_exists() helper added by v6.
  Keep bios-tables-test using "-serial null" (comment wording update).

v5 -> v6:
  Fix TAP parsing errors by using "-serial null" in bios-tables-test.

v4 -> v5:
  Also suppress UART device & SPCR when guest has no serial hardware on
  loongarch.
  Rename serial_exist to serial_exists.
  Fix style issues.

 hw/arm/virt-acpi-build.c       | 3 ++-
 hw/loongarch/virt-acpi-build.c | 2 +-
 hw/riscv/virt-acpi-build.c     | 3 ++-
 tests/qtest/bios-tables-test.c | 7 +++++--
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index c145678185..1411f98ea1 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -64,6 +64,7 @@
 #include "hw/virtio/virtio-acpi.h"
 #include "target/arm/cpu.h"
 #include "target/arm/multiprocessing.h"
+#include "system/system.h"
 
 #define ARM_SPI_BASE 32
 
@@ -1291,7 +1292,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
 
     acpi_add_table(table_offsets, tables_blob);
 
-    if (ms->acpi_spcr_enabled) {
+    if (ms->acpi_spcr_enabled && serial_hd(0)) {
         spcr_setup(tables_blob, tables->linker, vms);
     }
 
diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
index 54ac94e17d..dc8bbb9fdc 100644
--- a/hw/loongarch/virt-acpi-build.c
+++ b/hw/loongarch/virt-acpi-build.c
@@ -546,7 +546,7 @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine)
     build_srat(tables_blob, tables->linker, machine);
     acpi_add_table(table_offsets, tables_blob);
 
-    if (machine->acpi_spcr_enabled)
+    if (machine->acpi_spcr_enabled && serial_hd(0))
         spcr_setup(tables_blob, tables->linker, machine);
 
     if (machine->numa_state->num_nodes) {
diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
index f1406cb683..29080d1125 100644
--- a/hw/riscv/virt-acpi-build.c
+++ b/hw/riscv/virt-acpi-build.c
@@ -39,6 +39,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "system/reset.h"
+#include "system/system.h"
 
 #define ACPI_BUILD_TABLE_SIZE             0x20000
 #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
@@ -890,7 +891,7 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)
 
     acpi_add_table(table_offsets, tables_blob);
 
-    if (ms->acpi_spcr_enabled) {
+    if (ms->acpi_spcr_enabled && serial_hd(0)) {
         spcr_setup(tables_blob, tables->linker, s);
     }
 
diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index e489d94331..37f2b72d83 100644
--- a/tests/qtest/bios-tables-test.c
+++ b/tests/qtest/bios-tables-test.c
@@ -825,10 +825,13 @@ static char *test_acpi_create_args(test_data *data, const char *params)
         /*
          * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3)
          * when arm/virt boad starts to support it.
+         * NOTE: Explicitly add "-serial null" to keep SPCR enabled while
+         *       discarding firmware serial output (avoid corrupting TAP
+         *       stdout).
          */
         if (data->cd) {
             args = g_strdup_printf("-machine %s%s %s -accel tcg "
-                "-nodefaults -nographic "
+                "-nodefaults -serial null -nographic "
                 "-drive if=pflash,format=raw,file=%s,readonly=on "
                 "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
                 data->machine, data->machine_param ?: "",
@@ -836,7 +839,7 @@ static char *test_acpi_create_args(test_data *data, const char *params)
                 data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
         } else {
             args = g_strdup_printf("-machine %s%s %s -accel tcg "
-                "-nodefaults -nographic "
+                "-nodefaults -serial null -nographic "
                 "-drive if=pflash,format=raw,file=%s,readonly=on "
                 "-drive if=pflash,format=raw,file=%s,snapshot=on %s",
                 data->machine, data->machine_param ?: "",
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-22  3:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-19 13:04 [PATCH v7 1/1] acpi/virt: suppress SPCR when UART0 has no serial backend Li Chen
2026-02-19 13:42 ` Igor Mammedov
2026-02-20 14:50 ` Michael S. Tsirkin
2026-02-22  3:25   ` Li Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.