hw/acpi, arm: Provide and use acpi_ghes_present()
cover hw/acpi, arm: Provide and use acpi_ghes_present()
Currently the Arm code in target/arm/kvm64.c which decides whether it should report memory errors via the ACPI GHES table works only with the 'virt' board; in fact it won't even link if the virt board is configured out of the QEMU binary.
This patchset replaces those virt-specific checks with a single new acpi_ghes_present() function which tells the caller whether it's OK to report errors by calling acpi_ghes_record_errors(). The mechanism we use is a simple flag in the AcpiGhesState which gets sent if the board calls acpi_ghes_add_fw_cfg() to set up the GHES stuff.
We need also to provide 'stub' versions of both acpi_ghes_present() and acpi_ghes_record_errors() so that we can link even if no board using ACPI GHES has been configured into the binary.
(You can test that this series is necessary by commenting out the 'CONFIG_ARM_VIRT=y' line in default-configs/devices/arm-softmmu.mak and building with KVM enabled on an AArch64 host.)
I have tested with 'make' and 'make check' but nothing beyond that; testing by somebody who has a guest setup that uses GHES would be helpful just to check I haven't accidentally broken it.
thanks
-- PMM
Peter Maydell (3):
hw/acpi: Provide stub version of acpi_ghes_record_errors() hw/acpi: Provide function acpi_ghes_present() target/arm: Use acpi_ghes_present() to see if we report ACPI memory
errors
include/hw/acpi/ghes.h | 9 +++++++++ hw/acpi/ghes-stub.c | 22 ++++++++++++++++++++++ hw/acpi/ghes.c | 17 +++++++++++++++++ target/arm/kvm64.c | 6 +----- hw/acpi/meson.build | 6 +++--- 5 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 hw/acpi/ghes-stub.c
Signature · 1 line
2.20.1
PATCH 1/3 hw/acpi: Provide stub version of acpi_ghes_record_errors()
Generic code in target/arm wants to call acpi_ghes_record_errors(); provide a stub version so that we don't fail to link when CONFIG_ACPI_APEI is not set. This requires us to add a new ghes-stub.c file to contain it and the meson.build mechanics to use it when appropriate.
--- hw/acpi/ghes-stub.c | 17 +++++++++++++++++ hw/acpi/meson.build | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 hw/acpi/ghes-stub.c
hw/acpi/ghes-stub.c new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Support for generating APEI tables and recording CPER for Guests: +* stub functions. +* +* Copyright (c) 2021 Linaro, Ltd +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/acpi/ghes.h" + +int acpi_ghes_record_errors (uint8_t source_id,uint64_t physical_address) +{ +return -1 ; +}
hw/acpi/meson.build +3 -3
@@ -13,13 +13,13 @@ acpi_ss.add(when: 'CONFIG_ACPI_PCI', if_true: files('pci.c')) acpi_ss.add(when: 'CONFIG_ACPI_VMGENID', if_true: files('vmgenid.c')) acpi_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_device.c')) acpi_ss.add(when: 'CONFIG_ACPI_HMAT', if_true: files('hmat.c')) -acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c')) +acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c'), if_false:('ghes-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86', if_true: files('core.c', 'piix4.c', 'pcihp.c'), if_false: files('acpi-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('ich9.c', 'tco.c')) acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'), if_false: files('ipmi-stub.c')) acpi_ss.add(when: 'CONFIG_PC', if_false: files('acpi-x86-stub.c')) acpi_ss.add(when: 'CONFIG_TPM', if_true: files('tpm.c')) -softmmu_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c')) +softmmu_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c')) softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('acpi-stub.c', 'aml-build-stub.c', - 'acpi-x86-stub.c', 'ipmi-stub.c')) + 'acpi-x86-stub.c', 'ipmi-stub.c', 'ghes-stub.c'))
Signature · 1 line
2.20.1
Re: [PATCH 1/3] hw/acpi: Provide stub version of acpi_ghes_record_errors()
hw/acpi/meson.build acpi_ss.add(when: 'CONFIG_ACPI_PCI', if_true: files('pci.c')) · line 25
Quoted 5 lines · Peter Maydell
hw/acpi/meson.build +2
-1+softmmu_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c')) softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('acpi-stub.c', 'aml-build-stub.c', - 'acpi-x86-stub.c', 'ipmi-stub.c')) + 'acpi-x86-stub.c', 'ipmi-stub.c', 'ghes-stub.c'))
Gosh that last line is confusing. I see it's documented in build-system.rst, but yeesh.
r~
Re: [PATCH 1/3] hw/acpi: Provide stub version of acpi_ghes_record_errors()
Quoted 10 lines · Richard Henderson
Quoted 8 lines · Peter Maydell
+softmmu_ss.add(when: '
CONFIG_ACPI',if_false:files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c'))
softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss)softmmu_ss.add(when: 'CONFIG_ALL',if_true: files('acpi-stub.c', 'aml-build-stub.c', - 'acpi-x86-stub.c', 'ipmi-stub.c'))
+ 'acpi-x86-stub.c', 'ipmi-stub.c', 'ghes-stub.c'))
Quoted 3 lines
Gosh that last line is confusing. I see it's documented in
build-system.rst, but yeesh.Reviewed-by Richard Henderson <[email protected]>
Yeah, it's vestigial of the makefiles and I should remove it.
That said, here:
Quoted 1 line
+acpi_ss.add(when: '
CONFIG_ACPI_APEI',if_true: files('ghes.c'), if_false:('ghes-stub.c'))
There's a missing "files" after if_false.
Paolo
Re: [PATCH 1/3] hw/acpi: Provide stub version of acpi_ghes_record_errors()
Quoted 18 lines · Paolo Bonzini
Quoted 11 lines · Richard Henderson
Quoted 9 lines · Peter Maydell
+softmmu_ss.add(when: '
CONFIG_ACPI',if_false:files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c'))
softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss)softmmu_ss.add(when: 'CONFIG_ALL',if_true: files('acpi-stub.c',
'aml-build-stub.c',
- 'acpi-x86-stub.c',
'ipmi-stub.c'))
+ 'acpi-x86-stub.c',
'ipmi-stub.c', 'ghes-stub.c'))Quoted 4 lines
Gosh that last line is confusing. I see it's documented in
build-system.rst, but yeesh.Reviewed-by Richard Henderson <[email protected]>
Quoted 7 lines
Yeah, it's vestigial of the makefiles and I should remove it.
That said, here:
Quoted 1 line
+acpi_ss.add(when: '
CONFIG_ACPI_APEI',if_true: files('ghes.c'), if_false:('ghes-stub.c'))There's a missing "files" after
if_false.
Thanks for finding this bug -- I have requeued the patches to target-arm.next with the "files" added.
-- PMM
Re: [PATCH 1/3] hw/acpi: Provide stub version of acpi_ghes_record_errors()
In reply to Peter MaydellQuoted 59 lines · Peter Maydell
Generic code in target/arm wants to call
acpi_ghes_record_errors(); provide a stub version so that we don't fail to link whenCONFIG_ACPI_APEIis not set. This requires us to add a newghes-stub.cfile to contain it and the meson.build mechanics to use it when appropriate.Signed-off-by Peter Maydell <[email protected]>--- hw/acpi/ghes-stub.c | 17 +++++++++++++++++ hw/acpi/meson.build | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 hw/acpi/ghes-stub.chw/acpi/ghes-stub.c new file +17
-0@@ -0,0 +1,17 @@ +/* +* Support for generating APEI tables and recording CPER for Guests: +* stub functions. +* +* Copyright (c) 2021 Linaro, Ltd +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/acpi/ghes.h" + +int acpi_ghes_record_errors (uint8_t source_id,uint64_t physical_address) +{ +return -1 ; +}hw/acpi/meson.build +3
-4@@ -13,13 +13,13 @@ acpi_ss.add(when: 'CONFIG_ACPI_PCI', if_true: files('pci.c')) acpi_ss.add(when: 'CONFIG_ACPI_VMGENID', if_true: files('vmgenid.c')) acpi_ss.add(when: 'CONFIG_ACPI_HW_REDUCED', if_true: files('generic_event_device.c')) acpi_ss.add(when: 'CONFIG_ACPI_HMAT', if_true: files('hmat.c')) -acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c')) +acpi_ss.add(when: 'CONFIG_ACPI_APEI', if_true: files('ghes.c'), if_false:('ghes-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86', if_true: files('core.c', 'piix4.c', 'pcihp.c'), if_false: files('acpi-stub.c')) acpi_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('ich9.c', 'tco.c')) acpi_ss.add(when: 'CONFIG_IPMI', if_true: files('ipmi.c'), if_false: files('ipmi-stub.c')) acpi_ss.add(when: 'CONFIG_PC', if_false: files('acpi-x86-stub.c')) acpi_ss.add(when: 'CONFIG_TPM', if_true: files('tpm.c')) -softmmu_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c')) +softmmu_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c')) softmmu_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('acpi-stub.c', 'aml-build-stub.c', - 'acpi-x86-stub.c', 'ipmi-stub.c')) + 'acpi-x86-stub.c', 'ipmi-stub.c', 'ghes-stub.c')) --
Quoted 2 lines
2.20.1
PATCH 2/3 hw/acpi: Provide function acpi_ghes_present()
In reply to Peter MaydellAllow code elsewhere in the system to check whether the ACPI GHES table is present, so it can determine whether it is OK to try to record an error by calling acpi_ghes_record_errors().
(We don't need to migrate the new 'present' field in AcpiGhesState, because it is set once at system initialization and doesn't change.)
--- include/hw/acpi/ghes.h | 9 +++++++++ hw/acpi/ghes-stub.c | 5 +++++ hw/acpi/ghes.c | 17 +++++++++++++++++ 3 files changed, 31 insertions(+)
include/hw/acpi/ghes.h +9 -0
@@ -64,6 +64,7 @@ enum {typedef struct AcpiGhesState {uint64_t ghes_addr_le; +bool present;/* True if GHES is present at all on this board */ }AcpiGhesState ;void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker);
@@ -72,4 +73,12 @@ void acpi_build_hest(GArray *table_data, BIOSLinker *linker,void acpi_ghes_add_fw_cfg (AcpiGhesState *vms,FWCfgState *s,GArray *hardware_errors);int acpi_ghes_record_errors (uint8_t notify,uint64_t error_physical_addr); + +/** +* acpi_ghes_present: Report whether ACPI GHES table is present +* +* Returns: true if the system has an ACPI GHES table and it is +* safe to call acpi_ghes_record_errors() to record a memory error. +*/ +bool acpi_ghes_present (void );#endif
hw/acpi/ghes-stub.c +5 -0
@@ -15,3 +15,8 @@ int acpi_ghes_record_errors(uint8_t source_id, uint64_t physical_address) {return -1 ; } + +bool acpi_ghes_present (void ) +{ +return false; +}
hw/acpi/ghes.c +17 -0
@@ -386,6 +386,8 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,/* Create a read-write fw_cfg file for Address */ fw_cfg_add_file_callback (s,ACPI_GHES_DATA_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->ghes_addr_le),sizeof (ags->ghes_addr_le), false); + + ags->present = true; }int acpi_ghes_record_errors (uint8_t source_id,uint64_t physical_address)
@@ -443,3 +445,18 @@ int acpi_ghes_record_errors(uint8_t source_id, uint64_t physical_address)return ret; } + +bool acpi_ghes_present (void ) +{ +AcpiGedState *acpi_ged_state; +AcpiGhesState *ags; + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); + +if (!acpi_ged_state) { +return false; + } + ags = &acpi_ged_state->ghes_state; +return ags->present; +}
Signature · 1 line
2.20.1
Re: [PATCH 2/3] hw/acpi: Provide function acpi_ghes_present()
Quoted 7 lines · Peter Maydell
Allow code elsewhere in the system to check whether the ACPI GHES table is present, so it can determine whether it is OK to try to record an error by calling
acpi_ghes_record_errors().(We don't need to migrate the new 'present' field in AcpiGhesState, because it is set once at system initialization and doesn't change.)
Quoted 6 lines
Signed-off-by Peter Maydell<[email protected]>--- include/hw/acpi/ghes.h | 9 +++++++++ hw/acpi/ghes-stub.c | 5 +++++ hw/acpi/ghes.c | 17 +++++++++++++++++ 3 files changed, 31 insertions(+)
r~
Re: [PATCH 2/3] hw/acpi: Provide function acpi_ghes_present()
In reply to Peter MaydellQuoted 86 lines · Peter Maydell
Allow code elsewhere in the system to check whether the ACPI GHES table is present, so it can determine whether it is OK to try to record an error by calling
acpi_ghes_record_errors().(We don't need to migrate the new 'present' field in AcpiGhesState, because it is set once at system initialization and doesn't change.)
Signed-off-by Peter Maydell <[email protected]>--- include/hw/acpi/ghes.h | 9 +++++++++ hw/acpi/ghes-stub.c | 5 +++++ hw/acpi/ghes.c | 17 +++++++++++++++++ 3 files changed, 31 insertions(+)include/hw/acpi/ghes.h +9
-0@@ -64,6 +64,7 @@ enum {typedef struct AcpiGhesState {uint64_t ghes_addr_le; +bool present;/* True if GHES is present at all on this board */ }AcpiGhesState ;void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker);@@ -72,4 +73,12 @@ void acpi_build_hest(GArray *table_data, BIOSLinker *linker,void acpi_ghes_add_fw_cfg (AcpiGhesState *vms,FWCfgState *s,GArray *hardware_errors);int acpi_ghes_record_errors (uint8_t notify,uint64_t error_physical_addr); + +/** +* acpi_ghes_present: Report whether ACPI GHES table is present +* +* Returns: true if the system has an ACPI GHES table and it is +* safe to call acpi_ghes_record_errors() to record a memory error. +*/ +bool acpi_ghes_present (void );#endif hw/acpi/ghes-stub.c +5
-0@@ -15,3 +15,8 @@ int acpi_ghes_record_errors(uint8_t source_id, uint64_t physical_address) {return -1 ; } + +bool acpi_ghes_present (void ) +{ +return false; +}hw/acpi/ghes.c +17
-1@@ -386,6 +386,8 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,/* Create a read-write fw_cfg file for Address */ fw_cfg_add_file_callback (s,ACPI_GHES_DATA_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->ghes_addr_le),sizeof (ags->ghes_addr_le), false); + + ags->present = true; }int acpi_ghes_record_errors (uint8_t source_id,uint64_t physical_address)@@ -443,3 +445,18 @@ int acpi_ghes_record_errors(uint8_t source_id, uint64_t physical_address)return ret; } + +bool acpi_ghes_present (void ) +{ +AcpiGedState *acpi_ged_state; +AcpiGhesState *ags; + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); + +if (!acpi_ged_state) { +return false; + } + ags = &acpi_ged_state->ghes_state; +return ags->present; +} --
Quoted 2 lines
2.20.1
PATCH 3/3 target/arm: Use acpi_ghes_present() to see if we report ACPI memory errors
In reply to Peter MaydellThe virt_is_acpi_enabled() function is specific to the virt board, as is the check for its 'ras' property. Use the new acpi_ghes_present() function to check whether we should report memory errors via acpi_ghes_record_errors().
This avoids a link error if QEMU was built without support for the virt board, and provides a mechanism that can be used by any future board models that want to add ACPI memory error reporting support (they only need to call acpi_ghes_add_fw_cfg()).
--- target/arm/kvm64.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
target/arm/kvm64.c +1 -5
@@ -1410,14 +1410,10 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) {ram_addr_t ram_addr;hwaddr paddr; -Object *obj =qdev_get_machine (); -VirtMachineState *vms =VIRT_MACHINE (obj); -bool acpi_enabled =virt_is_acpi_enabled (vms);assert (code ==BUS_MCEERR_AR || code ==BUS_MCEERR_AO ); -if (acpi_enabled && addr && -object_property_get_bool (obj,"ras" ,NULL )) { +if (acpi_ghes_present () && addr) { ram_addr =qemu_ram_addr_from_host (addr);if (ram_addr !=RAM_ADDR_INVALID &&kvm_physical_memory_addr_from_host (c->kvm_state, addr, &paddr)) {
Signature · 1 line
2.20.1
Re: [PATCH 3/3] target/arm: Use acpi_ghes_present() to see if we report ACPI memory errors
Quoted 10 lines · Peter Maydell
The
virt_is_acpi_enabled()function is specific to the virt board, as is the check for its 'ras' property. Use the newacpi_ghes_present()function to check whether we should report memory errors viaacpi_ghes_record_errors().This avoids a link error if QEMU was built without support for the virt board, and provides a mechanism that can be used by any future board models that want to add ACPI memory error reporting support (they only need to call
acpi_ghes_add_fw_cfg()).
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/kvm64.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
r~
Re: [PATCH 3/3] target/arm: Use acpi_ghes_present() to see if we report ACPI memory errors
In reply to Peter MaydellQuoted 37 lines · Peter Maydell
The
virt_is_acpi_enabled()function is specific to the virt board, as is the check for its 'ras' property. Use the newacpi_ghes_present()function to check whether we should report memory errors viaacpi_ghes_record_errors().This avoids a link error if QEMU was built without support for the virt board, and provides a mechanism that can be used by any future board models that want to add ACPI memory error reporting support (they only need to call
acpi_ghes_add_fw_cfg()).Signed-off-by Peter Maydell <[email protected]>--- target/arm/kvm64.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)target/arm/kvm64.c +1
-6@@ -1410,14 +1410,10 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) {ram_addr_t ram_addr;hwaddr paddr; -Object *obj =qdev_get_machine (); -VirtMachineState *vms =VIRT_MACHINE (obj); -bool acpi_enabled =virt_is_acpi_enabled (vms);assert (code ==BUS_MCEERR_AR || code ==BUS_MCEERR_AO ); -if (acpi_enabled && addr && -object_property_get_bool (obj,"ras" ,NULL )) { +if (acpi_ghes_present () && addr) { ram_addr =qemu_ram_addr_from_host (addr);if (ram_addr !=RAM_ADDR_INVALID &&kvm_physical_memory_addr_from_host (c->kvm_state, addr, &paddr)) { --
Quoted 2 lines
2.20.1
Quoted 17 lines · Peter Maydell
Currently the Arm code in
target/arm/kvm64.cwhich decides whether it should report memory errors via the ACPI GHES table works only with the 'virt' board; in fact it won't even link if the virt board is configured out of the QEMU binary.This patchset replaces those virt-specific checks with a single new
acpi_ghes_present()function which tells the caller whether it's OK to report errors by callingacpi_ghes_record_errors(). The mechanism we use is a simple flag in the AcpiGhesState which gets sent if the board callsacpi_ghes_add_fw_cfg()to set up the GHES stuff.We need also to provide 'stub' versions of both
acpi_ghes_present()andacpi_ghes_record_errors()so that we can link even if no board using ACPI GHES has been configured into the binary.
Quoted 7 lines
(You can test that this series is necessary by commenting out the '
CONFIG_ARM_VIRT=y' line in default-configs/devices/arm-softmmu.mak and building with KVM enabled on an AArch64 host.)I have tested with 'make' and 'make check' but nothing beyond that; testing by somebody who has a guest setup that uses GHES would be helpful just to check I haven't accidentally broken it.
Thanks for the review; I've applied this to target-arm.next.
-- PMM