acpi/virt: suppress SPCR when UART0 has no serial backend
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
@@ -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
@@ -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
@@ -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
@@ -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
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
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Li Chen <[email protected]>Reviewed-by Sunil V L <[email protected]>---
v6 -> v7:
Do not gate DSDT UART devices onserial_hd(0); only gate SPCR. Drop theserial_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.
Renameserial_existtoserial_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@@ -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
-0spcr_setup (tables_blob, tables->linker, vms); }hw/loongarch/virt-acpi-build.c +1
-1@@ -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@@ -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@@ -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 ?: "",
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.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Li Chen <[email protected]>Reviewed-by Sunil V L <[email protected]>---
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 onserial_hd(0); only gate SPCR. Drop theserial_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.
Renameserial_existtoserial_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@@ -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@@ -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@@ -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@@ -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
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
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Li Chen <[email protected]>Reviewed-by Sunil V L <[email protected]>---
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