kvm: Fix crash due to access uninitialized kvm_state
PATCH v2 1/1 kvm: Fix crash due to access uninitialized kvm_state
Runs into core dump on arm64 and the backtrace extracted from the core dump is shown as below. It's caused by accessing uninitialized @kvm_state in kvm_flush_coalesced_mmio_buffer() due to commit 176d073029 ("hw/arm/virt: Use machine_memory_devices_init()"), where the machine's memory region is added earlier than before.
main
qemu_init
configure_accelerators
qemu_opts_foreach
do_configure_accelerator
accel_init_machine
kvm_init
virt_kvm_type
virt_set_memmap
machine_memory_devices_init
memory_region_add_subregion
memory_region_add_subregion_common
memory_region_update_container_subregions
memory_region_transaction_begin
qemu_flush_coalesced_mmio_buffer
kvm_flush_coalesced_mmio_buffer
Fix it by bailing early in kvm_flush_coalesced_mmio_buffer() on the uninitialized @kvm_state. With this applied, no crash is observed on arm64.
---
v2: Bail early in kvm_flush_coalesced_mmio_buffer() on the uninitialized
@kvm_state and improved changelog (David/Peter)
--- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +1 -1
@@ -2812,7 +2812,7 @@ void kvm_flush_coalesced_mmio_buffer(void) {KVMState *s = kvm_state; -if (s->coalesced_flush_in_progress) { +if (!s || s->coalesced_flush_in_progress) {return ; }
Signature · 1 line
2.41.0
Quoted 41 lines · Gavin Shan
Runs into core dump on arm64 and the backtrace extracted from the core dump is shown as below. It's caused by accessing uninitialized @kvm_state in
kvm_flush_coalesced_mmio_buffer()due to commit176d073029("hw/arm/virt: Usemachine_memory_devices_init()"), where the machine's memory region is added earlier than before.main
qemu_init
configure_accelerators
qemu_opts_foreach
do_configure_accelerator
accel_init_machine
kvm_init
virt_kvm_type
virt_set_memmap
machine_memory_devices_init
memory_region_add_subregion
memory_region_add_subregion_common
memory_region_update_container_subregions
memory_region_transaction_begin
qemu_flush_coalesced_mmio_buffer
kvm_flush_coalesced_mmio_bufferFix it by bailing early in
kvm_flush_coalesced_mmio_buffer()on the uninitialized @kvm_state. With this applied, no crash is observed on arm64.Fixes 176d073029 ("hw/arm/virt: Use machine_memory_devices_init()")Signed-off-by Gavin Shan <[email protected]>---
v2: Bail early inkvm_flush_coalesced_mmio_buffer()on the uninitialized
@kvm_state and improved changelog (David/Peter)--- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/kvm/kvm-all.c +0
-0
accel/kvm/kvm-all.c void kvm_flush_coalesced_mmio_buffer(void) · line 2818
Quoted 8 lines
accel/kvm/kvm-all.c +1
-1@@ -2812,7 +2812,7 @@ void kvm_flush_coalesced_mmio_buffer(void) {KVMState *s = kvm_state; -if (s->coalesced_flush_in_progress) { +if (!s || s->coalesced_flush_in_progress) {return ; }
Thanks Gavin!
Signature · 3 lines
Cheers, David / dhildenb
Peter Maydell
AppliedQuoted 54 lines · David Hildenbrand
Quoted 41 lines · Gavin Shan
Runs into core dump on arm64 and the backtrace extracted from the core dump is shown as below. It's caused by accessing uninitialized @kvm_state in
kvm_flush_coalesced_mmio_buffer()due to commit176d073029("hw/arm/virt: Usemachine_memory_devices_init()"), where the machine's memory region is added earlier than before.main
qemu_init
configure_accelerators
qemu_opts_foreach
do_configure_accelerator
accel_init_machine
kvm_init
virt_kvm_type
virt_set_memmap
machine_memory_devices_init
memory_region_add_subregion
memory_region_add_subregion_common
memory_region_update_container_subregions
memory_region_transaction_begin
qemu_flush_coalesced_mmio_buffer
kvm_flush_coalesced_mmio_bufferFix it by bailing early in
kvm_flush_coalesced_mmio_buffer()on the uninitialized @kvm_state. With this applied, no crash is observed on arm64.Fixes 176d073029 ("hw/arm/virt: Use machine_memory_devices_init()")Signed-off-by Gavin Shan <[email protected]>---
v2: Bail early inkvm_flush_coalesced_mmio_buffer()on the uninitialized
@kvm_state and improved changelog (David/Peter)--- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/kvm/kvm-all.c +0
-0accel/kvm/kvm-all.c void kvm_flush_coalesced_mmio_buffer(void) · line 2818
Quoted 8 lines
accel/kvm/kvm-all.c +1
-1@@ -2812,7 +2812,7 @@ void kvm_flush_coalesced_mmio_buffer(void) {KVMState *s = kvm_state; -if (s->coalesced_flush_in_progress) { +if (!s || s->coalesced_flush_in_progress) {return ; }Thanks Gavin!
Quoted 1 line
Reviewed-by David Hildenbrand <[email protected]>
Applied to target-arm.next, thanks.
-- PMM
Quoted 27 lines · Gavin Shan
Runs into core dump on arm64 and the backtrace extracted from the core dump is shown as below. It's caused by accessing uninitialized @kvm_state in
kvm_flush_coalesced_mmio_buffer()due to commit176d073029("hw/arm/virt: Usemachine_memory_devices_init()"), where the machine's memory region is added earlier than before.main
qemu_init
configure_accelerators
qemu_opts_foreach
do_configure_accelerator
accel_init_machine
kvm_init
virt_kvm_type
virt_set_memmap
machine_memory_devices_init
memory_region_add_subregion
memory_region_add_subregion_common
memory_region_update_container_subregions
memory_region_transaction_begin
qemu_flush_coalesced_mmio_buffer
kvm_flush_coalesced_mmio_bufferFix it by bailing early in
kvm_flush_coalesced_mmio_buffer()on the uninitialized @kvm_state. With this applied, no crash is observed on arm64.
Quoted 8 lines
Fixes 176d073029 ("hw/arm/virt: Use machine_memory_devices_init()")Signed-off-by Gavin Shan <[email protected]>---
v2: Bail early inkvm_flush_coalesced_mmio_buffer()on the uninitialized
@kvm_state and improved changelog (David/Peter)--- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)