From e5c9a743e68983827fb71ca8b1f421b4131f47d3 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao Date: Wed, 19 Feb 2025 06:23:23 +0000 Subject: [PATCH] hv: pm: fix acpi register size calculation The Access Size field in ACPI GAS was not introduced before ACPI 2.0, Errata C. It is not guaranteed to be a non zero value, like QEMU programs it to 0. As it only indicates how many bytes it can be accessed at once, the register size should be determined by Bit Width and Bit Offset. In IO space, Bit Offset is always 0, the size is (Bit Width / 8). Tracked-On: #8771 Signed-off-by: Jiaqing Zhao Reviewed-by: Li Fei --- hypervisor/arch/x86/guest/pm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c index 88e83362c..11fbe8c38 100644 --- a/hypervisor/arch/x86/guest/pm.c +++ b/hypervisor/arch/x86/guest/pm.c @@ -251,13 +251,11 @@ static bool pm1ab_io_write(struct acrn_vcpu *vcpu, uint16_t addr, size_t width, static void register_gas_io_handler(struct acrn_vm *vm, uint32_t pio_idx, const struct acrn_acpi_generic_address *gas) { - uint8_t io_len[5] = {0U, 1U, 2U, 4U, 8U}; struct vm_io_range gas_io; - if ((gas->address != 0UL) && (gas->space_id == SPACE_SYSTEM_IO) - && (gas->access_size != 0U) && (gas->access_size <= 4U)) { + if ((gas->address != 0UL) && (gas->space_id == SPACE_SYSTEM_IO) && (gas->bit_width != 0U)) { gas_io.base = (uint16_t)gas->address; - gas_io.len = io_len[gas->access_size]; + gas_io.len = gas->bit_width / 8; register_pio_emulation_handler(vm, pio_idx, &gas_io, &pm1ab_io_read, &pm1ab_io_write);