Skip to contentSkip to conversation

acpi/virt: suppress SPCR when UART0 has no serial backend

PATCH In review Li Chen 3 participants 4 messages Feb 19 – Feb 22 RISC-V

lore
Share & tools
lore

Li Chen

author
#0 lore raw

PATCH v7 1/1 acpi/virt: suppress SPCR when UART0 has no serial backend

From: Li Chen <[email protected]>

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.

---
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(-)
hw/arm/virt-acpi-build.c +2 -1
index c145678185..1411f98ea1 100644
@@ -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);
     }
 
hw/loongarch/virt-acpi-build.c +1 -1
index 54ac94e17d..dc8bbb9fdc 100644
@@ -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) {
hw/riscv/virt-acpi-build.c +2 -1
index f1406cb683..29080d1125 100644
@@ -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);
     }
 
tests/qtest/bios-tables-test.c +5 -2
index e489d94331..37f2b72d83 100644
@@ -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 ?: "",
Signature · 1 line
2.52.0
#1 lore raw
Quoted 8 lines · On Thu, 19 Feb 2026 21:04:02 +0800 Li Chen <[email protected]> wrote:

From: Li Chen <[email protected]>

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.

Quoted 4 lines

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.

I've though consensus was, if device (frontend) exists, we should keep it described in ACPI (regardless of backend state).

Quoted 2 lines

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

It's tests issue, I'd say fix it there.
See for more below.

Quoted 37 lines

---
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(-)
hw/arm/virt-acpi-build.c +1 -0
index c145678185..1411f98ea1 100644
@@ -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
 

hw/arm/virt-acpi-build.c void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) · line 1295

Quoted 5 lines
hw/arm/virt-acpi-build.c +1 -1
@@ -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->acpio_spcr_enabled && serial_hd(0)) {

if you really need to disable spcr,
add a knob to do so instead of gating it on backend state.

Having serial console configured and sent to /dev/null
is a legit config (ex: testing that writes to console do not explode machine, but not really caring where writes end up)

Quoted 65 lines
hw/arm/virt-acpi-build.c +0 -0
         spcr_setup(tables_blob, tables->linker, vms);
     }
 
hw/loongarch/virt-acpi-build.c +1 -1
index 54ac94e17d..dc8bbb9fdc 100644
@@ -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) {
hw/riscv/virt-acpi-build.c +2 -1
index f1406cb683..29080d1125 100644
@@ -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);
     }
 
tests/qtest/bios-tables-test.c +5 -2
index e489d94331..37f2b72d83 100644
@@ -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 lore raw
In reply to Li Chen
Quoted 12 lines · Li Chen

From: Li Chen <[email protected]>

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.

Quoted 7 lines

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

---

So -serial null gives a device -serial none hides it from guest. Sensible. And yet, out of abundance of caution, maybe keep the legacy behaviour for existing machine types. No?

Quoted 105 lines

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(-)
hw/arm/virt-acpi-build.c +2 -1
index c145678185..1411f98ea1 100644
@@ -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);
     }
 
hw/loongarch/virt-acpi-build.c +1 -1
index 54ac94e17d..dc8bbb9fdc 100644
@@ -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) {
hw/riscv/virt-acpi-build.c +2 -1
index f1406cb683..29080d1125 100644
@@ -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);
     }
 
tests/qtest/bios-tables-test.c +5 -2
index e489d94331..37f2b72d83 100644
@@ -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 ?: "",
Signature · 1 line
2.52.0
author
#3 lore raw

Hi Michael,

---- On Fri, 20 Feb 2026 22:50:57 +0800 Michael S. Tsirkin <[email protected]> wrote ---

Quoted 16 lines · Li Chen
Quoted 15 lines

From: Li Chen <[email protected]>

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.

Quoted 8 lines
Quoted 4 lines

---

So -serial null gives a device -serial none hides it from guest. Sensible. And yet, out of abundance of caution, maybe keep the legacy behaviour for existing machine types. No?

Thanks. I see your point about being cautious with legacy behaviour. Given you and Igor's feedback, gating SPCR on chardev backend state is not the right approach, so I'll drop this patch.

Regards,
Li​