Change ghes to use HEST-based offsets and add support for error inject
Subsystems (2)
PATCH 2/11 acpi/ghes: add a firmware file with HEST address
In reply to Mauro Carvalho ChehabStore HEST table address at GPA, placing its content at hest_addr_le variable.
---
Change from v8:
- hest_addr_lr is now pointing to the error source size and data.
--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)
hw/acpi/ghes.c +16 -1
@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)
@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into * hardware_errors_addr fw_cfg, once the former has been initialized. */ bios_linker_loader_write_pointer(linker, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, 0,
@@ -355,6 +356,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,acpi_table_begin (&table, table_data); +int hest_offset = table_data->len; +/* Error Source Count */ build_append_int_noprefix (table_data, num_sources,4 );for (i =0 ; i < num_sources; i++) {
@@ -362,6 +365,15 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, }acpi_table_end (linker, &table); + +/* +* tell firmware to write into GPA the address of HEST via fw_cfg, +* once initialized. +*/ +bios_linker_loader_write_pointer (linker, +ACPI_HEST_ADDR_FW_CFG_FILE ,0 , +sizeof (uint64_t ), +ACPI_BUILD_TABLE_FILE , hest_offset); } void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,
@@ -375,6 +387,9 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,fw_cfg_add_file_callback (s,ACPI_HW_ERROR_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->hw_error_le),sizeof (ags->hw_error_le), false); +fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , +NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); + ags->present = true; }
include/hw/acpi/ghes.h +1 -0
@@ -58,6 +58,7 @@ enum AcpiGhesNotifyType { };typedef struct AcpiGhesState { +uint64_t hest_addr_le;uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ }AcpiGhesState ;
Signature · 1 line
2.48.1
PATCH 3/11 acpi/ghes: Use HEST table offsets when preparing GHES records
In reply to Mauro Carvalho ChehabThere are two pointers that are needed during error injection:
1. The start address of the CPER block to be stored;
2. The address of the ack, which needs a reset before next error.
It is preferable to calculate them from the HEST table. This allows checking the source ID, the size of the table and the type of the HEST error block structures.
Yet, keep the old code, as this is needed for migration purposes.
--- hw/acpi/ghes.c | 98 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-)
hw/acpi/ghes.c +88 -10
@@ -61,6 +61,23 @@*/ #define ACPI_GHES_GESB_SIZE 20 +/* +* Offsets with regards to the start of the HEST table stored at +* ags->hest_addr_le, according with the memory layout map at +* docs/specs/acpi_hest_ghes.rst. +*/ + +/* ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 +* Table 18-382 Generic Hardware Error Source version 2 (GHESv2) Structure +*/ +#define HEST_GHES_V2_TABLE_SIZE 92 +#define GHES_ACK_OFFSET (64 + GAS_ADDR_OFFSET) + +/* ACPI 6.2: 18.3.2.7: Generic Hardware Error Source +* Table 18-380: 'Error Status Address' field +*/ +#define GHES_ERR_ST_ADDR_OFFSET (20 + GAS_ADDR_OFFSET) +/* * Values for error_severity field */
@@ -212,14 +229,6 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, {int i, error_status_block_offset; -/* -* TODO: Current version supports only one source. -* A further patch will drop this check, after adding a proper migration -* code, as, for the code to work, we need to store a bios pointer to the -* HEST table. -*/ -assert (num_sources ==1 ); -/* Build error_block_address */ for (i =0 ; i < num_sources; i++) {build_append_int_noprefix (hardware_errors,0 ,sizeof (uint64_t ));
@@ -419,6 +428,70 @@ static void get_hw_error_offsets(uint64_t ghes_addr, *read_ack_register_addr = ghes_addr +sizeof (uint64_t ); } +static void get_ghes_source_offsets (uint16_t source_id,uint64_t hest_addr, +uint64_t *cper_addr, +uint64_t *read_ack_start_addr, +Error **errp) +{ +uint64_t hest_err_block_addr, hest_read_ack_addr; +uint64_t err_source_struct, error_block_addr; +uint32_t num_sources, i; + +if (!hest_addr) { +return ; + } + +cpu_physical_memory_read (hest_addr, &num_sources,sizeof (num_sources)); + num_sources =le32_to_cpu (num_sources); + + err_source_struct = hest_addr +sizeof (num_sources); + +/* +* Currently, HEST Error source navigates only for GHESv2 tables +*/ + +for (i =0 ; i < num_sources; i++) { +uint64_t addr = err_source_struct; +uint16_t type, src_id; + +cpu_physical_memory_read (addr, &type,sizeof (type)); + type =le16_to_cpu (type); + +/* For now, we only know the size of GHESv2 table */ +if (type !=ACPI_GHES_SOURCE_GENERIC_ERROR_V2 ) { +error_setg (errp,"HEST: type %d not supported." , type); +return ; + } + +/* Compare CPER source address at the GHESv2 structure */ + addr +=sizeof (type); +cpu_physical_memory_read (addr, &src_id,sizeof (src_id)); + +if (src_id == source_id) { +break ; + } + + err_source_struct +=HEST_GHES_V2_TABLE_SIZE ; + } +if (i == num_sources) { +error_setg (errp,"HEST: Source %d not found." , source_id); +return ; + } + +/* Navigate though table address pointers */ + hest_err_block_addr = err_source_struct +GHES_ERR_ST_ADDR_OFFSET ; + hest_read_ack_addr = err_source_struct +GHES_ACK_OFFSET ; + +cpu_physical_memory_read (hest_err_block_addr, &error_block_addr, +sizeof (error_block_addr)); + +cpu_physical_memory_read (error_block_addr, cper_addr, +sizeof (*cper_addr)); + +cpu_physical_memory_read (hest_read_ack_addr, read_ack_start_addr, +sizeof (*read_ack_start_addr)); +} +void ghes_record_cper_errors (const void *cper,size_t len,uint16_t source_id,Error **errp) {
@@ -439,8 +512,13 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), - &cper_addr, &read_ack_register_addr); +if (!ags->hest_addr_le) { +get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), + &cper_addr, &read_ack_register_addr); + }else { +get_ghes_source_offsets (source_id,le64_to_cpu (ags->hest_addr_le), + &cper_addr, &read_ack_register_addr, errp); + }if (!cper_addr) {error_setg (errp,"can not find Generic Error Status Block" );
Signature · 1 line
2.48.1
cover Change ghes to use HEST-based offsets and add support for error inject
Now that the ghes preparation patches were merged, let's add support for error injection.
I'm opting to fold two patch series into one here:
1. https://lore.kernel.org/qemu-devel/[email protected]/
It is the first 5 patches containing changes to the math used to calculate offsets at HEST table and hardware_error firmware file, together with its migration code. Migration tested with both latest QEMU released kernel and upstream, on both directions.
There were no changes on this series since last submission, except for a conflict resolution at the migration table, due to upstream changes.
For more details, se the post of my previous submission.
2. It follows 6 patches from:
https://lore.kernel.org/qemu-devel/[email protected]/ containing the error injection code and script.
They add a new QAPI to allow injecting GHESv2 errors, and a script using such QAPI to inject ARM Processor Error records.
PS.: If I'm counting well, this is the 18th version of this series rebase.
Mauro Carvalho Chehab (11):
acpi/ghes: Prepare to support multiple sources on ghes acpi/ghes: add a firmware file with HEST address acpi/ghes: Use HEST table offsets when preparing GHES records acpi/generic_event_device: Update GHES migration to cover hest addr acpi/generic_event_device: add logic to detect if HEST addr is
available
acpi/ghes: add a notifier to notify when error data is ready acpi/ghes: Cleanup the code which gets ghes ged state acpi/generic_event_device: add an APEI error device arm/virt: Wire up a GED error device for ACPI / GHES qapi/acpi-hest: add an interface to do generic CPER error injection scripts/ghes_inject: add a script to generate GHES error inject
MAINTAINERS | 10 + hw/acpi/Kconfig | 5 + hw/acpi/aml-build.c | 10 + hw/acpi/generic_event_device.c | 38 ++ hw/acpi/ghes-stub.c | 4 +- hw/acpi/ghes.c | 184 +++++-- hw/acpi/ghes_cper.c | 32 ++ hw/acpi/ghes_cper_stub.c | 19 + hw/acpi/meson.build | 2 + hw/arm/virt-acpi-build.c | 35 +- hw/arm/virt.c | 19 +- hw/core/machine.c | 2 + include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 2 + include/hw/acpi/generic_event_device.h | 1 + include/hw/acpi/ghes.h | 36 +- include/hw/arm/virt.h | 2 + qapi/acpi-hest.json | 35 ++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + scripts/arm_processor_error.py | 377 +++++++++++++ scripts/ghes_inject.py | 51 ++ scripts/qmp_helper.py | 702 +++++++++++++++++++++++++ target/arm/kvm.c | 2 +- 24 files changed, 1517 insertions(+), 54 deletions(-) create mode 100644 hw/acpi/ghes_cper.c create mode 100644 hw/acpi/ghes_cper_stub.c create mode 100644 qapi/acpi-hest.json create mode 100644 scripts/arm_processor_error.py create mode 100755 scripts/ghes_inject.py create mode 100644 scripts/qmp_helper.py
Signature · 1 line
2.48.1
PATCH 1/11 acpi/ghes: Prepare to support multiple sources on ghes
The current code is actually dependent on having just one error structure with a single source.
As the number of sources should be arch-dependent, as it will depend on what kind of synchronous/assynchronous notifications will exist, change the logic to dynamically build the table.
Yet, for a proper support, we need to get the number of sources by reading the number from the HEST table. However, bios currently doesn't store a pointer to it.
For now just change the logic at table build time, while enforcing that it will behave like before with a single source ID.
A future patch will add a HEST table bios pointer and change the logic at acpi_ghes_record_errors() to dynamically use the new size.
--- hw/acpi/ghes.c | 43 ++++++++++++++++++++++++++-------------- hw/arm/virt-acpi-build.c | 5 +++++ include/hw/acpi/ghes.h | 21 +++++++++++++------- 3 files changed, 47 insertions(+), 22 deletions(-)
hw/acpi/ghes.c +28 -15
@@ -206,17 +206,26 @@ ghes_gen_err_data_uncorrectable_recoverable(GArray *block,* Initialize "etc/hardware_errors" and "etc/hardware_errors_addr" fw_cfg blobs. * See docs/specs/acpi_hest_ghes.rst for blobs format. */ -static void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker) +static void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker, +int num_sources) {int i, error_status_block_offset; +/* +* TODO: Current version supports only one source. +* A further patch will drop this check, after adding a proper migration +* code, as, for the code to work, we need to store a bios pointer to the +* HEST table. +*/ +assert (num_sources ==1 ); +/* Build error_block_address */ -for (i =0 ; i <ACPI_GHES_ERROR_SOURCE_COUNT ; i++) { +for (i =0 ; i < num_sources; i++) {build_append_int_noprefix (hardware_errors,0 ,sizeof (uint64_t )); }/* Build read_ack_register */ -for (i =0 ; i <ACPI_GHES_ERROR_SOURCE_COUNT ; i++) { +for (i =0 ; i < num_sources; i++) {/* * Initialize the value of read_ack_register to 1, so GHES can be * writable after (re)boot.
@@ -231,13 +240,13 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker)/* Reserve space for Error Status Data Block */ acpi_data_push (hardware_errors, -ACPI_GHES_MAX_RAW_DATA_LENGTH *ACPI_GHES_ERROR_SOURCE_COUNT ); +ACPI_GHES_MAX_RAW_DATA_LENGTH * num_sources);/* Tell guest firmware to place hardware_errors blob into RAM */ bios_linker_loader_alloc (linker,ACPI_HW_ERROR_FW_CFG_FILE , hardware_errors,sizeof (uint64_t ), false); -for (i =0 ; i <ACPI_GHES_ERROR_SOURCE_COUNT ; i++) { +for (i =0 ; i < num_sources; i++) {/* * Tell firmware to patch error_block_address entries to point to * corresponding "Generic Error Status Block"
@@ -263,10 +272,12 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker)/* Build Generic Hardware Error Source version 2 (GHESv2) */ static void build_ghes_v2 (GArray *table_data,BIOSLinker *linker, -enum AcpiGhesNotifyType notify, -uint16_t source_id) +const AcpiNotificationSourceId *notif_src, +uint16_t index,int num_sources) {uint64_t address_offset; +const uint16_t notify = notif_src->notify; +const uint16_t source_id = notif_src->source_id;/* * Type:
@@ -297,7 +308,7 @@ static void build_ghes_v2(GArray *table_data, address_offset +GAS_ADDR_OFFSET ,sizeof (uint64_t ),ACPI_HW_ERROR_FW_CFG_FILE , - source_id * sizeof(uint64_t)); + index * sizeof(uint64_t));/* Notification Structure */ build_ghes_hw_error_notification (table_data, notify);
@@ -317,8 +328,7 @@ static void build_ghes_v2(GArray *table_data, address_offset +GAS_ADDR_OFFSET ,sizeof (uint64_t ),ACPI_HW_ERROR_FW_CFG_FILE , - (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) - * sizeof(uint64_t)); + (num_sources + index) * sizeof(uint64_t));/* * Read Ack Preserve field
@@ -333,19 +343,23 @@ static void build_ghes_v2(GArray *table_data,/* Build Hardware Error Source Table */ void acpi_build_hest (GArray *table_data,GArray *hardware_errors,BIOSLinker *linker, +const AcpiNotificationSourceId *const notif_source, +int num_sources,const char *oem_id,const char *oem_table_id) {AcpiTable table = { .sig ="HEST" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id }; +int i; -build_ghes_error_table (hardware_errors, linker); +build_ghes_error_table (hardware_errors, linker, num_sources);acpi_table_begin (&table, table_data);/* Error Source Count */ -build_append_int_noprefix (table_data,ACPI_GHES_ERROR_SOURCE_COUNT ,4 ); -build_ghes_v2 (table_data, linker, -ACPI_GHES_NOTIFY_SEA ,ACPI_HEST_SRC_ID_SEA ); +build_append_int_noprefix (table_data, num_sources,4 ); +for (i =0 ; i < num_sources; i++) { +build_ghes_v2 (table_data, linker, ¬if_source[i], i, num_sources); + }acpi_table_end (linker, &table); }
@@ -410,7 +424,6 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -assert (ACPI_GHES_ERROR_SOURCE_COUNT ==1 );get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), &cper_addr, &read_ack_register_addr);
hw/arm/virt-acpi-build.c +5 -0
@@ -893,6 +893,10 @@ static void acpi_align_size(GArray *blob, unsigned align)g_array_set_size (blob,ROUND_UP (acpi_data_len (blob), align)); } +static const AcpiNotificationSourceId hest_ghes_notify[] = { + {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, +}; +static void virt_acpi_build (VirtMachineState *vms,AcpiBuildTables *tables) {
@@ -948,6 +952,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)if (vms->ras) {acpi_add_table (table_offsets, tables_blob);acpi_build_hest (tables_blob, tables->hardware_errors, tables->linker, + hest_ghes_notify,ARRAY_SIZE (hest_ghes_notify), vms->oem_id, vms->oem_table_id); }
include/hw/acpi/ghes.h +14 -7
@@ -57,20 +57,27 @@ enum AcpiGhesNotifyType { ACPI_GHES_NOTIFY_RESERVED = 12 }; -enum { -ACPI_HEST_SRC_ID_SEA =0 , -/* future ids go here */ - -ACPI_GHES_ERROR_SOURCE_COUNT -}; -typedef struct AcpiGhesState {uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ }AcpiGhesState ; +/* +* ID numbers used to fill HEST source ID field +*/ +enum AcpiGhesSourceID { +ACPI_HEST_SRC_ID_SYNC , +}; + +typedef struct AcpiNotificationSourceId { +enum AcpiGhesSourceID source_id; +enum AcpiGhesNotifyType notify; +}AcpiNotificationSourceId ; +void acpi_build_hest (GArray *table_data,GArray *hardware_errors,BIOSLinker *linker, +const AcpiNotificationSourceId *const notif_source, +int num_sources,const char *oem_id,const char *oem_table_id);void acpi_ghes_add_fw_cfg (AcpiGhesState *vms,FWCfgState *s,GArray *hardware_errors);
Signature · 1 line
2.48.1
PATCH 4/11 acpi/generic_event_device: Update GHES migration to cover hest addr
In reply to Mauro Carvalho ChehabThe GHES migration logic at GED should now support HEST table location too.
--- hw/acpi/generic_event_device.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
hw/acpi/generic_event_device.c +29 -0
@@ -386,6 +386,34 @@ static const VMStateDescription vmstate_ghes_state = { } }; +static const VMStateDescription vmstate_hest = { + .name ="acpi-hest" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_UINT64 (hest_addr_le, AcpiGhesState), +VMSTATE_END_OF_LIST () + }, +}; + +static bool hest_needed (void *opaque) +{ +AcpiGedState *s = opaque; +return s->ghes_state.hest_addr_le; +} + +static const VMStateDescription vmstate_hest_state = { + .name ="acpi-ged/hest" , + .version_id =1 , + .minimum_version_id =1 , + .needed = hest_needed, + .fields = (const VMStateField []) { +VMSTATE_STRUCT (ghes_state, AcpiGedState,1 , + vmstate_hest, AcpiGhesState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_acpi_ged = { .name ="acpi-ged" , .version_id =1 ,
@@ -398,6 +426,7 @@ static const VMStateDescription vmstate_acpi_ged = { &vmstate_memhp_state, &vmstate_cpuhp_state, &vmstate_ghes_state, + &vmstate_hest_state, NULL } };
Signature · 1 line
2.48.1
PATCH 5/11 acpi/generic_event_device: add logic to detect if HEST addr is available
In reply to Mauro Carvalho ChehabCreate a new property (x-has-hest-addr) and use it to detect if the GHES table offsets can be calculated from the HEST address (qemu 9.2 and upper) or via the legacy way via an offset obtained from the hardware_errors firmware file.
--- hw/acpi/generic_event_device.c | 1 + hw/acpi/ghes.c | 28 +++++++++++++++++++++------- hw/arm/virt-acpi-build.c | 30 ++++++++++++++++++++++++++---- hw/core/machine.c | 2 ++ include/hw/acpi/ghes.h | 1 + 5 files changed, 51 insertions(+), 11 deletions(-)
hw/acpi/generic_event_device.c +1 -0
@@ -318,6 +318,7 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)static const Property acpi_ged_properties[] = {DEFINE_PROP_UINT32 ("ged-event" , AcpiGedState, ged_event_bitmap,0 ), +DEFINE_PROP_BOOL ("x-has-hest-addr" , AcpiGedState, ghes_state.hest_lookup, true), };static const VMStateDescription vmstate_memhp_state = {
hw/acpi/ghes.c +21 -7
@@ -359,6 +359,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, {AcpiTable table = { .sig ="HEST" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id }; +AcpiGedState *acpi_ged_state; +AcpiGhesState *ags =NULL ;int i;build_ghes_error_table (hardware_errors, linker, num_sources);
@@ -379,10 +381,20 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,* tell firmware to write into GPA the address of HEST via fw_cfg, * once initialized. */ -bios_linker_loader_write_pointer (linker, -ACPI_HEST_ADDR_FW_CFG_FILE ,0 , -sizeof (uint64_t ), -ACPI_BUILD_TABLE_FILE , hest_offset); + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); +if (!acpi_ged_state) { +return ; + } + + ags = &acpi_ged_state->ghes_state; +if (ags->hest_lookup) { +bios_linker_loader_write_pointer (linker, +ACPI_HEST_ADDR_FW_CFG_FILE ,0 , +sizeof (uint64_t ), +ACPI_BUILD_TABLE_FILE , hest_offset); + } } void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,
@@ -396,8 +408,10 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,fw_cfg_add_file_callback (s,ACPI_HW_ERROR_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->hw_error_le),sizeof (ags->hw_error_le), false); -fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , -NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); +if (ags && ags->hest_lookup) { +fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , +NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); + } ags->present = true; }
@@ -512,7 +526,7 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -if (!ags->hest_addr_le) { +if (!ags->hest_lookup) {get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), &cper_addr, &read_ack_register_addr); }else {
hw/arm/virt-acpi-build.c +26 -4
@@ -897,6 +897,10 @@ static const AcpiNotificationSourceId hest_ghes_notify[] = { { ACPI_HEST_SRC_ID_SYNC, ACPI_GHES_NOTIFY_SEA }, }; +static const AcpiNotificationSourceId hest_ghes_notify_9_2[] = { + {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, +}; +static void virt_acpi_build (VirtMachineState *vms,AcpiBuildTables *tables) {
@@ -950,10 +954,28 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_dbg2 (tables_blob, tables->linker, vms);if (vms->ras) { -acpi_add_table (table_offsets, tables_blob); -acpi_build_hest (tables_blob, tables->hardware_errors, tables->linker, - hest_ghes_notify,ARRAY_SIZE (hest_ghes_notify), - vms->oem_id, vms->oem_table_id); +AcpiGhesState *ags; +AcpiGedState *acpi_ged_state; + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); +if (acpi_ged_state) { + ags = &acpi_ged_state->ghes_state; + +acpi_add_table (table_offsets, tables_blob); + +if (!ags->hest_lookup) { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify_9_2, +ARRAY_SIZE (hest_ghes_notify_9_2), + vms->oem_id, vms->oem_table_id); + }else { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify, +ARRAY_SIZE (hest_ghes_notify), + vms->oem_id, vms->oem_table_id); + } + } }if (ms->numa_state->num_nodes >0 ) {
hw/core/machine.c +2 -0
@@ -34,10 +34,12 @@#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/acpi/generic_event_device.h" #include "audio/audio.h" GlobalProperty hw_compat_9_2[] = { {"arm-cpu" ,"backcompat-pauth-default-use-qarma5" ,"true" }, + {TYPE_ACPI_GED ,"x-has-hest-addr" ,"false" }, };const size_t hw_compat_9_2_len =G_N_ELEMENTS (hw_compat_9_2);
include/hw/acpi/ghes.h +1 -0
@@ -61,6 +61,7 @@ typedef struct AcpiGhesState {uint64_t hest_addr_le;uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ +bool hest_lookup;/* True if HEST address is present */ } AcpiGhesState;/*
Signature · 1 line
2.48.1
PATCH 6/11 acpi/ghes: add a notifier to notify when error data is ready
In reply to Mauro Carvalho ChehabSome error injection notify methods are async, like GPIO notify. Add a notifier to be used when the error record is ready to be sent to the guest OS.
--- hw/acpi/ghes.c | 5 ++++- include/hw/acpi/ghes.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-)
hw/acpi/ghes.c +4 -1
@@ -506,6 +506,9 @@ static void get_ghes_source_offsets(uint16_t source_id, uint64_t hest_addr, sizeof(*read_ack_start_addr)); } +NotifierList acpi_generic_error_notifiers = +NOTIFIER_LIST_INITIALIZER (error_device_notifiers); +void ghes_record_cper_errors (const void *cper,size_t len,uint16_t source_id,Error **errp) {
@@ -561,7 +564,7 @@ void ghes_record_cper_errors(const void *cper, size_t len,/* Write the generic error data entry into guest memory */ cpu_physical_memory_write (cper_addr, cper, len); -return ; +notifier_list_notify (&acpi_generic_error_notifiers,NULL ); }int acpi_ghes_memory_errors (uint16_t source_id,uint64_t physical_address)
include/hw/acpi/ghes.h +3 -0
@@ -24,6 +24,9 @@#include "hw/acpi/bios-linker-loader.h" #include "qapi/error.h" +#include "qemu/notify.h" + +extern NotifierList acpi_generic_error_notifiers;/* * Values for Hardware Error Notification Type field
Signature · 1 line
2.48.1
PATCH 7/11 acpi/ghes: Cleanup the code which gets ghes ged state
In reply to Mauro Carvalho ChehabMove the check logic into a common function and simplify the code which checks if GHES is enabled and was properly setup.
--- hw/acpi/ghes-stub.c | 4 ++-- hw/acpi/ghes.c | 33 +++++++++++---------------------- include/hw/acpi/ghes.h | 9 +++++---- target/arm/kvm.c | 2 +- 4 files changed, 19 insertions(+), 29 deletions(-)
hw/acpi/ghes-stub.c +2 -2
@@ -16,7 +16,7 @@ int acpi_ghes_memory_errors(uint16_t source_id, uint64_t physical_address)return -1 ; } -bool acpi_ghes_present (void ) +AcpiGhesState *acpi_ghes_get_state (void ) { -return false; +return NULL ; }
hw/acpi/ghes.c +11 -22
@@ -420,10 +420,6 @@ static void get_hw_error_offsets(uint64_t ghes_addr,uint64_t *cper_addr, uint64_t *read_ack_register_addr) { -if (!ghes_addr) { -return ; - } -/* * non-HEST version supports only one source, so no need to change * the start offset based on the source ID. Also, we can't validate
@@ -451,10 +447,6 @@ static void get_ghes_source_offsets(uint16_t source_id, uint64_t hest_addr,uint64_t err_source_struct, error_block_addr;uint32_t num_sources, i; -if (!hest_addr) { -return ; - } -cpu_physical_memory_read (hest_addr, &num_sources,sizeof (num_sources)); num_sources =le32_to_cpu (num_sources);
@@ -513,7 +505,6 @@ void ghes_record_cper_errors(const void *cper, size_t len, uint16_t source_id, Error **errp) { uint64_t cper_addr = 0, read_ack_register_addr = 0, read_ack_register; -AcpiGedState *acpi_ged_state;AcpiGhesState *ags;if (len >ACPI_GHES_MAX_RAW_DATA_LENGTH ) {
@@ -521,13 +512,10 @@ void ghes_record_cper_errors(const void *cper, size_t len,return ; } - acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , -NULL )); -if (!acpi_ged_state) { -error_setg (errp,"Can't find ACPI_GED object" ); + ags =acpi_ghes_get_state (); +if (!ags) {return ; } - ags = &acpi_ged_state->ghes_state;if (!ags->hest_lookup) { get_hw_error_offsets(le64_to_cpu(ags->hw_error_le),
@@ -537,11 +525,6 @@ void ghes_record_cper_errors(const void *cper, size_t len, &cper_addr, &read_ack_register_addr, errp); } -if (!cper_addr) { -error_setg (errp,"can not find Generic Error Status Block" ); -return ; - } -cpu_physical_memory_read (read_ack_register_addr, &read_ack_register,sizeof (read_ack_register));
@@ -605,7 +588,7 @@ int acpi_ghes_memory_errors(uint16_t source_id, uint64_t physical_address)return 0 ; } -bool acpi_ghes_present (void ) +AcpiGhesState *acpi_ghes_get_state (void ) {AcpiGedState *acpi_ged_state;AcpiGhesState *ags;
@@ -614,8 +597,14 @@ bool acpi_ghes_present(void) NULL));if (!acpi_ged_state) { -return false; +return NULL ; } ags = &acpi_ged_state->ghes_state; -return ags->present; +if (!ags->present) { +return NULL ; + } +if (!ags->hw_error_le && !ags->hest_addr_le) { +return NULL ; + } +return ags; }
include/hw/acpi/ghes.h +5 -4
@@ -91,10 +91,11 @@ void ghes_record_cper_errors(const void *cper, size_t len, uint16_t source_id, Error **errp);/** -* acpi_ghes_present: Report whether ACPI GHES table is present +* acpi_ghes_get_state: Get a pointer for ACPI ghes state * -* Returns: true if the system has an ACPI GHES table and it is -* safe to call acpi_ghes_memory_errors() to record a memory error. +* Returns: a pointer to ghes state if the system has an ACPI GHES table, +* it is enabled and it is safe to call acpi_ghes_memory_errors() to record +* a memory error. Returns false, otherwise. */ -bool acpi_ghes_present (void ); +AcpiGhesState *acpi_ghes_get_state (void );#endif
target/arm/kvm.c +1 -1
@@ -2369,7 +2369,7 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)assert (code ==BUS_MCEERR_AR || code ==BUS_MCEERR_AO ); -if (acpi_ghes_present () && addr) { +if (acpi_ghes_get_state () && 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.48.1
PATCH 8/11 acpi/generic_event_device: add an APEI error device
In reply to Mauro Carvalho ChehabAdds a generic error device to handle generic hardware error events as specified at ACPI 6.5 specification at 18.3.2.7.2:
https://uefi.org/specs/ACPI/6.5/18_Platform_Error_Interfaces.html#event-notification-for-generic-error-sources
using HID PNP0C33.
The PNP0C33 device is used to report hardware errors to the guest via ACPI APEI Generic Hardware Error Source (GHES).
--- hw/acpi/aml-build.c | 10 ++++++++++ hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 2 ++ include/hw/acpi/generic_event_device.h | 1 + 5 files changed, 22 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -2614,3 +2614,13 @@ Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source)return var; } + +/* ACPI 5.0b: 18.3.2.6.2 Event Notification For Generic Error Sources */ +Aml *aml_error_device (void ) +{ +Aml *dev =aml_device (ACPI_APEI_ERROR_DEVICE ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C33" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +return dev; +}
hw/acpi/generic_event_device.c +8 -0
@@ -26,6 +26,7 @@ static const uint32_t ged_supported_events[] = {ACPI_GED_PWR_DOWN_EVT ,ACPI_GED_NVDIMM_HOTPLUG_EVT ,ACPI_GED_CPU_HOTPLUG_EVT , + ACPI_GED_ERROR_EVT, };/*
@@ -116,6 +117,11 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,aml_notify (aml_name (ACPI_POWER_BUTTON_DEVICE ), aml_int(0x80)));break ; +case ACPI_GED_ERROR_EVT : +aml_append (if_ctx, +aml_notify (aml_name (ACPI_APEI_ERROR_DEVICE ), +aml_int (0x80 ))); +break ;case ACPI_GED_NVDIMM_HOTPLUG_EVT : aml_append(if_ctx, aml_notify(aml_name("\\_SB.NVDR"),
@@ -295,6 +301,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) sel =ACPI_GED_MEM_HOTPLUG_EVT ; }else if (ev &ACPI_POWER_DOWN_STATUS ) { sel =ACPI_GED_PWR_DOWN_EVT ; + }else if (ev &ACPI_GENERIC_ERROR ) { + sel =ACPI_GED_ERROR_EVT ; }else if (ev &ACPI_NVDIMM_HOTPLUG_STATUS ) { sel =ACPI_GED_NVDIMM_HOTPLUG_EVT ; }else if (ev &ACPI_CPU_HOTPLUG_STATUS ) {
include/hw/acpi/acpi_dev_interface.h +1 -0
@@ -13,6 +13,7 @@ typedef enum {ACPI_NVDIMM_HOTPLUG_STATUS =16 ,ACPI_VMGENID_CHANGE_STATUS =32 ,ACPI_POWER_DOWN_STATUS =64 , +ACPI_GENERIC_ERROR =128 , } AcpiEventStatusBits;#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"
include/hw/acpi/aml-build.h +2 -0
@@ -252,6 +252,7 @@ struct CrsRangeSet {/* Consumer/Producer */ #define AML_SERIAL_BUS_FLAG_CONSUME_ONLY (1 << 1) +#define ACPI_APEI_ERROR_DEVICE "GEDD"/** * init_aml_allocator: *
@@ -382,6 +383,7 @@ Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel);Aml *aml_sleep (uint64_t msec);Aml *aml_i2c_serial_bus_device (uint16_t address,const char *resource_source); +Aml *aml_error_device (void );/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)G_GNUC_PRINTF (1 ,2 );
include/hw/acpi/generic_event_device.h +1 -0
@@ -101,6 +101,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 +#define ACPI_GED_ERROR_EVT 0x10 typedef struct GEDState { MemoryRegion evt;
Signature · 1 line
2.48.1
PATCH 9/11 arm/virt: Wire up a GED error device for ACPI / GHES
In reply to Mauro Carvalho ChehabAdds support to ARM virtualization to allow handling generic error ACPI Event via GED & error source device.
It is aligned with Linux Kernel patch:
https://lore.kernel.org/lkml/[email protected]/
---
Changes from v8:
- Added a call to the function that produces GHES generic records, as this is now added earlier in this series.
--- hw/arm/virt-acpi-build.c | 1 + hw/arm/virt.c | 12 +++++++++++- include/hw/arm/virt.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +1 -0
@@ -861,6 +861,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) }acpi_dsdt_add_power_button (scope); +aml_append (scope,aml_error_device ());#ifdef CONFIG_TPM acpi_dsdt_add_tpm (scope, vms);#endif
hw/arm/virt.c +11 -1
@@ -678,7 +678,7 @@ static inline DeviceState *create_acpi_ged(VirtMachineState *vms)DeviceState *dev;MachineState *ms =MACHINE (vms);int irq = vms->irqmap[VIRT_ACPI_GED ]; -uint32_t event =ACPI_GED_PWR_DOWN_EVT ; +uint32_t event =ACPI_GED_PWR_DOWN_EVT |ACPI_GED_ERROR_EVT ;if (ms->ram_slots) { event |=ACPI_GED_MEM_HOTPLUG_EVT ;
@@ -1010,6 +1010,13 @@ static void virt_powerdown_req(Notifier *n, void *opaque) } } +static void virt_generic_error_req (Notifier *n,void *opaque) +{ +VirtMachineState *s =container_of (n, VirtMachineState, generic_error_notifier); + +acpi_send_event (s->acpi_dev,ACPI_GENERIC_ERROR ); +} +static void create_gpio_keys (char *fdt,DeviceState *pl061_dev,uint32_t phandle) {
@@ -2404,6 +2411,9 @@ static void machvirt_init(MachineState *machine)if (has_ged && aarch64 && firmware_loaded &&virt_is_acpi_enabled (vms)) { vms->acpi_dev =create_acpi_ged (vms); + vms->generic_error_notifier.notify = virt_generic_error_req; +notifier_list_add (&acpi_generic_error_notifiers, + &vms->generic_error_notifier); }else {create_gpio_devices (vms,VIRT_GPIO , sysmem); }
include/hw/arm/virt.h +1 -0
@@ -176,6 +176,7 @@ struct VirtMachineState {DeviceState *gic;DeviceState *acpi_dev;Notifier powerdown_notifier; +Notifier generic_error_notifier;PCIBus *bus;char *oem_id;char *oem_table_id;
Signature · 1 line
2.48.1
PATCH 10/11 qapi/acpi-hest: add an interface to do generic CPER error injection
In reply to Mauro Carvalho ChehabCreates a QMP command to be used for generic ACPI APEI hardware error injection (HEST) via GHESv2, and add support for it for ARM guests.
Error injection uses ACPI_HEST_SRC_ID_QMP source ID to be platform independent. This is mapped at arch virt bindings, depending on the types supported by QEMU and by the BIOS. So, on ARM, this is supported via ACPI_GHES_NOTIFY_GPIO notification type.
This patch is co-authored:
- original ghes logic to inject a simple ARM record by Shiju Jose;
- generic logic to handle block addresses by Jonathan Cameron;
- generic GHESv2 error inject by Mauro Carvalho Chehab;
---
Changes since v9:
- ARM source IDs renamed to reflect SYNC/ASYNC;
- command name changed to better reflect what it does;
- some improvements at JSON documentation;
- add a check for QMP source at the notification logic.
--- MAINTAINERS | 7 +++++++ hw/acpi/Kconfig | 5 +++++ hw/acpi/ghes.c | 2 +- hw/acpi/ghes_cper.c | 32 ++++++++++++++++++++++++++++++++ hw/acpi/ghes_cper_stub.c | 19 +++++++++++++++++++ hw/acpi/meson.build | 2 ++ hw/arm/virt-acpi-build.c | 1 + hw/arm/virt.c | 7 +++++++ include/hw/acpi/ghes.h | 1 + include/hw/arm/virt.h | 1 + qapi/acpi-hest.json | 35 +++++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 13 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/ghes_cper.c create mode 100644 hw/acpi/ghes_cper_stub.c create mode 100644 qapi/acpi-hest.json
MAINTAINERS +7 -0
@@ -2075,6 +2075,13 @@ F: hw/acpi/ghes.c F: include/hw/acpi/ghes.h F: docs/specs/acpi_hest_ghes.rst +ACPI/HEST/GHES/ARM processor CPER +R: Mauro Carvalho Chehab <[email protected]> +S: Maintained +F: hw/arm/ghes_cper.c +F: hw/acpi/ghes_cper_stub.c +F: qapi/acpi-hest.json + ppc4xx L: [email protected] S: Orphan
hw/acpi/Kconfig +5 -0
@@ -51,6 +51,11 @@ config ACPI_APEI bool depends on ACPI +config GHES_CPER + bool + depends on ACPI_APEI + default y + config ACPI_PCI bool depends on ACPI && PCI
hw/acpi/ghes.c +1 -1
@@ -547,7 +547,7 @@ void ghes_record_cper_errors(const void *cper, size_t len,/* Write the generic error data entry into guest memory */ cpu_physical_memory_write (cper_addr, cper, len); -notifier_list_notify (&acpi_generic_error_notifiers,NULL ); +notifier_list_notify (&acpi_generic_error_notifiers, &source_id); }int acpi_ghes_memory_errors (uint16_t source_id,uint64_t physical_address)
hw/acpi/ghes_cper.c new file +32 -0
@@ -0,0 +1,32 @@ +/* +* CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" + +#include "qemu/base64.h" +#include "qemu/error-report.h" +#include "qemu/uuid.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" + +void qmp_inject_ghes_error (const char *qmp_cper,Error **errp) +{ + +uint8_t *cper; +size_t len; + + cper =qbase64_decode (qmp_cper,-1 , &len, errp); +if (!cper) { +error_setg (errp,"missing GHES CPER payload" ); +return ; + } + +ghes_record_cper_errors (cper, len,ACPI_HEST_SRC_ID_QMP , errp); +}
hw/acpi/ghes_cper_stub.c new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Stub interface for CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" + +void qmp_inject_ghes_error (const char *cper,Error **errp) +{ +error_setg (errp,"GHES QMP error inject is not compiled in" ); +}
hw/acpi/meson.build +2 -0
@@ -34,4 +34,6 @@ endif system_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c', 'acpi_interface.c')) system_ss.add(when: 'CONFIG_ACPI_PCI_BRIDGE', if_false: files('pci-bridge-stub.c')) system_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) +system_ss.add(when: 'CONFIG_GHES_CPER', if_true: files('ghes_cper.c')) +system_ss.add(when: 'CONFIG_GHES_CPER', if_false: files('ghes_cper_stub.c')) system_ss.add(files('acpi-qmp-cmds.c'))
hw/arm/virt-acpi-build.c +1 -0
@@ -896,6 +896,7 @@ static void acpi_align_size(GArray *blob, unsigned align)static const AcpiNotificationSourceId hest_ghes_notify[] = { {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, + {ACPI_HEST_SRC_ID_QMP ,ACPI_GHES_NOTIFY_GPIO }, };static const AcpiNotificationSourceId hest_ghes_notify_9_2[] = {
hw/arm/virt.c +7 -0
@@ -1012,6 +1012,13 @@ static void virt_powerdown_req(Notifier *n, void *opaque)static void virt_generic_error_req (Notifier *n,void *opaque) { +uint16_t *source_id = opaque; + +/* Currently, only QMP source ID is async */ +if (*source_id !=ACPI_HEST_SRC_ID_QMP ) { +return ; + } +VirtMachineState *s =container_of (n, VirtMachineState, generic_error_notifier);acpi_send_event (s->acpi_dev,ACPI_GENERIC_ERROR );
include/hw/acpi/ghes.h +1 -0
@@ -72,6 +72,7 @@ typedef struct AcpiGhesState {*/ enum AcpiGhesSourceID {ACPI_HEST_SRC_ID_SYNC , +ACPI_HEST_SRC_ID_QMP ,/* Use it only for QMP injected errors */ }; typedef struct AcpiNotificationSourceId {
include/hw/arm/virt.h +1 -0
@@ -33,6 +33,7 @@#include "exec/hwaddr.h" #include "qemu/notify.h" #include "hw/boards.h" +#include "hw/acpi/ghes.h" #include "hw/arm/boot.h" #include "hw/arm/bsa.h" #include "hw/block/flash.h"
qapi/acpi-hest.json new file +35 -0
@@ -0,0 +1,35 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# == GHESv2 CPER Error Injection +# +# Defined since ACPI Specification 6.1, +# section 18.3.2.8 Generic Hardware Error Source version 2. See: +# +# https://uefi.org/sites/default/files/resources/ACPI_6_1.pdf +## + + +## +# @inject-ghes-error: +# +# Inject an error with additional ACPI 6.1 GHESv2 error information +# +# @cper: contains a base64 encoded string with raw data for a single +# CPER record with Generic Error Status Block, Generic Error Data +# Entry and generic error data payload, as described at +# https://uefi.org/specs/UEFI/2.10/Apx_N_Common_Platform_Error_Record.html#format +# +# Features: +# +# @unstable: This command is experimental. +# +# Since: 9.2 +## +{ 'command': 'inject-ghes-error', + 'data': { + 'cper': 'str' + }, + 'features': [ 'unstable' ] +}
qapi/meson.build +1 -0
@@ -59,6 +59,7 @@ qapi_all_modules = [ if have_system qapi_all_modules += [ 'acpi', + 'acpi-hest', 'audio', 'cryptodev', 'qdev',
qapi/qapi-schema.json +1 -0
@@ -75,6 +75,7 @@ { 'include': 'misc-target.json' } { 'include': 'audio.json' } { 'include': 'acpi.json' } +{ 'include': 'acpi-hest.json' } { 'include': 'pci.json' } { 'include': 'stats.json' } { 'include': 'virtio.json' }
Signature · 1 line
2.48.1
PATCH 11/11 scripts/ghes_inject: add a script to generate GHES error inject
In reply to Mauro Carvalho ChehabUsing the QMP GHESv2 API requires preparing a raw data array containing a CPER record.
Add a helper script with subcommands to prepare such data.
Currently, only ARM Processor error CPER record is supported.
--- MAINTAINERS | 3 + scripts/arm_processor_error.py | 377 ++++++++++++++++++ scripts/ghes_inject.py | 51 +++ scripts/qmp_helper.py | 702 +++++++++++++++++++++++++++++++++ 4 files changed, 1133 insertions(+) create mode 100644 scripts/arm_processor_error.py create mode 100755 scripts/ghes_inject.py create mode 100644 scripts/qmp_helper.py
MAINTAINERS +3 -0
@@ -2081,6 +2081,9 @@ S: Maintained F: hw/arm/ghes_cper.c F: hw/acpi/ghes_cper_stub.c F: qapi/acpi-hest.json +F: scripts/ghes_inject.py +F: scripts/arm_processor_error.py +F: scripts/qmp_helper.py ppc4xx L: [email protected]
scripts/arm_processor_error.py new file +377 -0
377 lines not on this page · raw message
scripts/ghes_inject.py new file +51 -0
51 lines not on this page · raw message
scripts/qmp_helper.py new file +702 -0
702 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH 01/11] acpi/ghes: Prepare to support multiple sources on ghes
In reply to Mauro Carvalho ChehabQuoted 5 lines · On Wed, 22 Jan 2025 16:46:18 +0100 Mauro Carvalho Chehab…
The current code is actually dependent on having just one error structure with a single source.
As the number of sources should be arch-dependent, as it will depend on what kind of synchronous/assynchronous notifications will exist, change
asynchronous.
Quoted 14 lines
the logic to dynamically build the table.
Yet, for a proper support, we need to get the number of sources by reading the number from the HEST table. However, bios currently doesn't store a pointer to it.
For now just change the logic at table build time, while enforcing that it will behave like before with a single source ID.
A future patch will add a HEST table bios pointer and change the logic at
acpi_ghes_record_errors()to dynamically use the new size.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Mauro Carvalho ChehabQuoted 6 lines · On Wed, 22 Jan 2025 16:46:19 +0100 Mauro Carvalho Chehab…
Store HEST table address at GPA, placing its content at
hest_addr_levariable.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>
A few trivial things inline.
Jonathan
Quoted 6 lines
---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.Signed-off-by Mauro Carvalho Chehab <[email protected]>
Bonus. I guess you really like this patch :)
Quoted 18 lines
--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)hw/acpi/ghes.c +1
-0@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, · line 265
Quoted 5 lines
hw/acpi/ghes.c +1
-1@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into
Sneaky tidy up. No problem with it in general but adding noise here, so if there are others in the series maybe gather them up in a cleanup patch.
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 359
Quoted 8 lines
hw/acpi/ghes.c +1
-0* hardware_errors_addr fw_cfg, once the former has been initialized. */ bios_linker_loader_write_pointer(linker, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, 0,@@ -355,6 +356,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,acpi_table_begin (&table, table_data); +int hest_offset = table_data->len;
Local style looks to be traditional C with definitions at top. Maybe define hest_offset up a few lines and just set it here?
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 370
Quoted 11 lines
hw/acpi/ghes.c +4
-0+/* Error Source Count */ build_append_int_noprefix (table_data, num_sources,4 );for (i =0 ; i < num_sources; i++) {@@ -362,6 +365,15 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, }acpi_table_end (linker, &table); + +/* +* tell firmware to write into GPA the address of HEST via fw_cfg,
Given the tidy up above, fix this one to have a capital T, or was this where you meant to change it?
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 374
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* once initialized. +*/ + bios_linker_loader_write_pointer(linker, + ACPI_HEST_ADDR_FW_CFG_FILE, 0,
Could wrap less and stay under 80 chars as both lines above add up to 70 something
Quoted 3 lines
hw/acpi/ghes.c +2
-0+sizeof (uint64_t ), + ACPI_BUILD_TABLE_FILE, hest_offset); }
Re: [PATCH 03/11] acpi/ghes: Use HEST table offsets when preparing GHES records
In reply to Mauro Carvalho ChehabQuoted 5 lines · On Wed, 22 Jan 2025 16:46:20 +0100 Mauro Carvalho Chehab…
There are two pointers that are needed during error injection:
1. The start address of the CPER block to be stored;
2. The address of the ack, which needs a reset before next error.
Quoted 7 lines
It is preferable to calculate them from the HEST table. This allows checking the source ID, the size of the table and the type of the HEST error block structures.
Yet, keep the old code, as this is needed for migration purposes.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Generally looks good. A few bits that I think could be made easier to follow for anyone with the spec open in front of them.
Thanks,
Jonathan
Quoted 9 lines
--- hw/acpi/ghes.c | 98 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-)hw/acpi/ghes.c +0
-0
hw/acpi/ghes.c line 70
Quoted 10 lines
hw/acpi/ghes.c +7
-0@@ -61,6 +61,23 @@*/ #define ACPI_GHES_GESB_SIZE 20 +/* +* Offsets with regards to the start of the HEST table stored at +* ags->hest_addr_le, according with the memory layout map at +* docs/specs/acpi_hest_ghes.rst. +*/ + +/* ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2
Local multiline comment style seems to be always
/*
* ACPI 6.2:...
So perhaps good to copy that.
hw/acpi/ghes.c line 74
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* Table 18-382 Generic Hardware Error Source version 2 (GHESv2) Structure +*/ +#define HEST_GHES_V2_TABLE_SIZE 92 +#define GHES_ACK_OFFSET (64 + GAS_ADDR_OFFSET)
Using a GAS offset here to me obscures what is going on. I'd explicitly handle the GAS where you are reading this. We probably should sanity check the type as there are some crazy options that might turn up one day.
Maybe worth using spec term ofGHES_READ_ACK_...
Obviously it's a question of who you are for whether it is read or write, but maybe still worth using that term for easy checking against the specification.
hw/acpi/ghes.c line 76
Quoted 2 lines
hw/acpi/ghes.c +2
-0+ +/* ACPI 6.2: 18.3.2.7: Generic Hardware Error Source
same on comment format.
hw/acpi/ghes.c line 79
Quoted 3 lines
hw/acpi/ghes.c +3
-0+* Table 18-380: 'Error Status Address' field +*/ +#define GHES_ERR_ST_ADDR_OFFSET (20 + GAS_ADDR_OFFSET)
Maybe STS or spell out status? I found ST a bit confusing below.
Quoted 23 lines
hw/acpi/ghes.c +1
-8+/* * Values for error_severity field */ @@ -212,14 +229,6 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, {int i, error_status_block_offset; -/* -* TODO: Current version supports only one source. -* A further patch will drop this check, after adding a proper migration -* code, as, for the code to work, we need to store a bios pointer to the -* HEST table. -*/ -assert (num_sources ==1 ); -/* Build error_block_address */ for (i =0 ; i < num_sources; i++) {build_append_int_noprefix (hardware_errors,0 ,sizeof (uint64_t ));@@ -419,6 +428,70 @@ static void get_hw_error_offsets(uint64_t ghes_addr, *read_ack_register_addr = ghes_addr +sizeof (uint64_t ); }
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 440
Quoted 10 lines
hw/acpi/ghes.c +10
-0+static void get_ghes_source_offsets (uint16_t source_id,uint64_t hest_addr, +uint64_t *cper_addr, +uint64_t *read_ack_start_addr, +Error **errp) +{ +uint64_t hest_err_block_addr, hest_read_ack_addr; +uint64_t err_source_struct, error_block_addr; +uint32_t num_sources, i; + +if (!hest_addr) {
I guess it is a question of matching local code, but I'd be tempted to name this hest_body_addr as it isn't the start of the table but rather the bit after the header.
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 444
Quoted 4 lines
hw/acpi/ghes.c +4
-0+return ; + } + +cpu_physical_memory_read (hest_addr, &num_sources,sizeof (num_sources));
The hest_addr naming thing confused me a tiny bit here because obviously num_sources isn't the first thing in the table in the spec!
Quoted 9 lines
hw/acpi/ghes.c +9
-0+ num_sources =le32_to_cpu (num_sources); + + err_source_struct = hest_addr +sizeof (num_sources); + +/* +* Currently, HEST Error source navigates only for GHESv2 tables +*/ + +for (i =0 ; i < num_sources; i++) {
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 463
Quoted 10 lines
hw/acpi/ghes.c +10
-0+uint64_t addr = err_source_struct; +uint16_t type, src_id; + +cpu_physical_memory_read (addr, &type,sizeof (type)); + type =le16_to_cpu (type); + +/* For now, we only know the size of GHESv2 table */ +if (type !=ACPI_GHES_SOURCE_GENERIC_ERROR_V2 ) { +error_setg (errp,"HEST: type %d not supported." , type); +return ;
It's a pity we can't just skip them, but absence of a size field makes that tricky... Can add that later I guess along with sizes for each defined type including figuring out the variable length ones like IA-32 machine check. I guess this is why the whole ordering constraint for new types was added. Can't find the old ones if we don't know the size of the new ones, hence need new definitions at the end.
Anyhow, I'm fine with this but maybe a little more description in the comment would avoid someone going down same rat hole I just did.
Quoted 9 lines
hw/acpi/ghes.c +9
-0+ } + +/* Compare CPER source address at the GHESv2 structure */ + addr +=sizeof (type); +cpu_physical_memory_read (addr, &src_id,sizeof (src_id)); + +if (src_id == source_id) { +break ; + }
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 482
Quoted 10 lines
hw/acpi/ghes.c +10
-0+ + err_source_struct +=HEST_GHES_V2_TABLE_SIZE ; + } +if (i == num_sources) { +error_setg (errp,"HEST: Source %d not found." , source_id); +return ; + } + +/* Navigate though table address pointers */ + hest_err_block_addr = err_source_struct +GHES_ERR_ST_ADDR_OFFSET ;
So this is a bit confusing. I'd pull the GAS offset down here rather than putting it in the define. That way we can clearly see you are grabbing the address field. As above, should we check the type is 0x00? There are many fun things it could be but here I think we just want it to be memory space.
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 483
Quoted 1 line
hw/acpi/ghes.c +1
-0+ hest_read_ack_addr = err_source_struct +GHES_ACK_OFFSET ;
Perhaps move this down to above where it is used?
Same thing about GAS address offset being better found down here rather than hidden in GHES_ACK_OFFSET.
Quoted 30 lines
hw/acpi/ghes.c +18
-2+ +cpu_physical_memory_read (hest_err_block_addr, &error_block_addr, +sizeof (error_block_addr)); + +cpu_physical_memory_read (error_block_addr, cper_addr, +sizeof (*cper_addr)); + +cpu_physical_memory_read (hest_read_ack_addr, read_ack_start_addr, +sizeof (*read_ack_start_addr)); +} +void ghes_record_cper_errors (const void *cper,size_t len,uint16_t source_id,Error **errp) {@@ -439,8 +512,13 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), - &cper_addr, &read_ack_register_addr); +if (!ags->hest_addr_le) { +get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), + &cper_addr, &read_ack_register_addr); + }else { +get_ghes_source_offsets (source_id,le64_to_cpu (ags->hest_addr_le), + &cper_addr, &read_ack_register_addr, errp); + }if (!cper_addr) {error_setg (errp,"can not find Generic Error Status Block" );
Re: [PATCH 04/11] acpi/generic_event_device: Update GHES migration to cover hest addr
In reply to Mauro Carvalho ChehabQuoted 4 lines · On Wed, 22 Jan 2025 16:46:21 +0100 Mauro Carvalho Chehab…
The GHES migration logic at GED should now support HEST table location too.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
I'm not an expert on migration logic, but with that in mind, this looks fine to me.
Quoted 51 lines
--- hw/acpi/generic_event_device.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)hw/acpi/generic_event_device.c +29
-0@@ -386,6 +386,34 @@ static const VMStateDescription vmstate_ghes_state = { } }; +static const VMStateDescription vmstate_hest = { + .name ="acpi-hest" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_UINT64 (hest_addr_le, AcpiGhesState), +VMSTATE_END_OF_LIST () + }, +}; + +static bool hest_needed (void *opaque) +{ +AcpiGedState *s = opaque; +return s->ghes_state.hest_addr_le; +} + +static const VMStateDescription vmstate_hest_state = { + .name ="acpi-ged/hest" , + .version_id =1 , + .minimum_version_id =1 , + .needed = hest_needed, + .fields = (const VMStateField []) { +VMSTATE_STRUCT (ghes_state, AcpiGedState,1 , + vmstate_hest, AcpiGhesState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_acpi_ged = { .name ="acpi-ged" , .version_id =1 ,@@ -398,6 +426,7 @@ static const VMStateDescription vmstate_acpi_ged = { &vmstate_memhp_state, &vmstate_cpuhp_state, &vmstate_ghes_state, + &vmstate_hest_state, NULL } };
Re: [PATCH 05/11] acpi/generic_event_device: add logic to detect if HEST addr is available
In reply to Mauro Carvalho ChehabQuoted 6 lines · On Wed, 22 Jan 2025 16:46:22 +0100 Mauro Carvalho Chehab…
Create a new property (x-has-hest-addr) and use it to detect if the GHES table offsets can be calculated from the HEST address (qemu 9.2 and upper) or via the legacy way via an offset obtained from the
hardware_errorsfirmware file.Signed-off-by Mauro Carvalho Chehab <[email protected]>
Re: [PATCH 06/11] acpi/ghes: add a notifier to notify when error data is ready
In reply to Mauro Carvalho ChehabQuoted 5 lines · On Wed, 22 Jan 2025 16:46:23 +0100 Mauro Carvalho Chehab…
Some error injection notify methods are async, like GPIO notify. Add a notifier to be used when the error record is ready to be sent to the guest OS.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Re: [PATCH 07/11] acpi/ghes: Cleanup the code which gets ghes ged state
In reply to Mauro Carvalho ChehabQuoted 4 lines · On Wed, 22 Jan 2025 16:46:24 +0100 Mauro Carvalho Chehab…
Move the check logic into a common function and simplify the code which checks if GHES is enabled and was properly setup.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Seems a reasonable cleanup to me.
Re: [PATCH 09/11] arm/virt: Wire up a GED error device for ACPI / GHES
In reply to Mauro Carvalho ChehabQuoted 12 lines · On Wed, 22 Jan 2025 16:46:26 +0100 Mauro Carvalho Chehab…
Adds support to ARM virtualization to allow handling generic error ACPI Event via GED & error source device.
It is aligned with Linux Kernel patch:
https://lore.kernel.org/lkml/[email protected]/Co-authored-by Mauro Carvalho Chehab <[email protected]>Co-authored-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>Acked-by Igor Mammedov <[email protected]>
Quoted 8 lines
---
Changes from v8:
- Added a call to the function that produces GHES generic records, as this is now added earlier in this series.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Another bonus.
LGTM otherwise.
Re: [PATCH 10/11] qapi/acpi-hest: add an interface to do generic CPER error injection
In reply to Mauro Carvalho ChehabQuoted 22 lines · On Wed, 22 Jan 2025 16:46:27 +0100 Mauro Carvalho Chehab…
Creates a QMP command to be used for generic ACPI APEI hardware error injection (HEST) via GHESv2, and add support for it for ARM guests.
Error injection uses
ACPI_HEST_SRC_ID_QMPsource ID to be platform independent. This is mapped at arch virt bindings, depending on the types supported by QEMU and by the BIOS. So, on ARM, this is supported viaACPI_GHES_NOTIFY_GPIOnotification type.This patch is co-authored:
- original ghes logic to inject a simple ARM record by Shiju Jose;
- generic logic to handle block addresses by Jonathan Cameron;
- generic GHESv2 error inject by Mauro Carvalho Chehab;Co-authored-by Jonathan Cameron <[email protected]>Co-authored-by Shiju Jose <[email protected]>Co-authored-by Mauro Carvalho Chehab <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>---
Quoted 7 lines
Changes since v9:
- ARM source IDs renamed to reflect SYNC/ASYNC;
- command name changed to better reflect what it does;
- some improvements at JSON documentation;
- add a check for QMP source at the notification logic.Signed-off-by Mauro Carvalho Chehab <[email protected]>
Another bonus.
Few trivial formatting comments, otherwise looks fine to me.
Jonathan
Quoted 30 lines
hw/acpi/ghes.c +1
-1@@ -547,7 +547,7 @@ void ghes_record_cper_errors(const void *cper, size_t len,/* Write the generic error data entry into guest memory */ cpu_physical_memory_write (cper_addr, cper, len); -notifier_list_notify (&acpi_generic_error_notifiers,NULL ); +notifier_list_notify (&acpi_generic_error_notifiers, &source_id); }int acpi_ghes_memory_errors (uint16_t source_id,uint64_t physical_address)hw/acpi/ghes_cper.c new file +11
-0@@ -0,0 +1,32 @@ +/* +* CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h"
hw/acpi/ghes_cper.c line 21
Quoted 10 lines
hw/acpi/ghes_cper.c new file +10
-0+ +#include "qemu/base64.h" +#include "qemu/error-report.h" +#include "qemu/uuid.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" + +void qmp_inject_ghes_error (const char *qmp_cper,Error **errp) +{ +
Odd blank line that can go.
Quoted 17 lines
hw/acpi/ghes_cper.c new file +11
-0+uint8_t *cper; +size_t len; + + cper =qbase64_decode (qmp_cper,-1 , &len, errp); +if (!cper) { +error_setg (errp,"missing GHES CPER payload" ); +return ; + } + +ghes_record_cper_errors (cper, len,ACPI_HEST_SRC_ID_QMP , errp); +}hw/acpi/ghes_cper_stub.c new file +0
-0
hw/acpi/ghes_cper_stub.c line 8
Quoted 8 lines
hw/acpi/ghes_cper_stub.c new file +8
-0@@ -0,0 +1,19 @@ +/* +* Stub interface for CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*
Trivial but I'd drop these trailing blank lines as they don't add anything other than making people scroll further.
hw/acpi/ghes_cper_stub.c line 14
Quoted 6 lines
hw/acpi/ghes_cper_stub.c new file +6
-0+*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h"
Trivial but doe we need ghes.h?
Quoted 5 lines
hw/acpi/ghes_cper_stub.c new file +5
-0+ +void qmp_inject_ghes_error (const char *cper,Error **errp) +{ +error_setg (errp,"GHES QMP error inject is not compiled in" ); +}
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Jonathan CameronEm Thu, 23 Jan 2025 10:02:17 +0000
Jonathan Cameron <[email protected]> escreveu:
Quoted 7 lines
Quoted 6 lines
---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.Signed-off-by Mauro Carvalho Chehab <[email protected]>Bonus. I guess you really like this patch :)
There is something wrong here with git rebase - maybe related to .git/hooks/pre-commit running checkpatch: every time I do a rebase, it adds my SOB at the end of description, if not there already. Not a problem for normal patches, but when the patch has a version history, it ends placing such duplicated SOBs. That happens even using --no-signoff and with:
[format]
signOff = false
at git config. No idea how to fix it.
Thanks,
Mauro
---
This is the pre-commit hook:
#!/bin/sh
#
#
TMP=$(mktemp)
git diff --cached HEAD >$TMP
$PWD/scripts/checkpatch.pl --no-signoff -q $TMP >&2 ERR=$?
rm $TMP
exit $ERR
Re: [PATCH 11/11] scripts/ghes_inject: add a script to generate GHES error inject
In reply to Mauro Carvalho ChehabQuoted 8 lines · On Wed, 22 Jan 2025 16:46:28 +0100 Mauro Carvalho Chehab…
Using the QMP GHESv2 API requires preparing a raw data array containing a CPER record.
Add a helper script with subcommands to prepare such data.
Currently, only ARM Processor error CPER record is supported.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
My Python is poor at best, so take that into account!
Some usage examples might be good to have as well. Either in explicit docs or the patch description.
Jonathan
Quoted 16 lines
--- MAINTAINERS | 3 + scripts/arm_processor_error.py | 377 ++++++++++++++++++ scripts/ghes_inject.py | 51 +++ scripts/qmp_helper.py | 702 +++++++++++++++++++++++++++++++++ 4 files changed, 1133 insertions(+) create mode 100644 scripts/arm_processor_error.py create mode 100755 scripts/ghes_inject.py create mode 100644 scripts/qmp_helper.pyscripts/qmp_helper.py new file +0
-0
scripts/qmp_helper.py line 553
Quoted 10 lines
scripts/qmp_helper.py new file +7
-0+ def send_cper(self, notif_type, payload): + """Send commands to QEMU though QMP TCP socket""" + + # Fill CPER record header + + # NOTE: bits 4 to 13 of block status contain the number of + # data entries in the data section. This is currently unsupported.
Not controllable, so always set to 0 or 1? Or not set?
...
scripts/qmp_helper.py line 603
Quoted 2 lines
scripts/qmp_helper.py new file +2
-0+ self.send_cper_raw(cper_data) +
Trivial but maybe can improve consistency on spacing. 1 or 2 lines between functions. I don't care which.
scripts/qmp_helper.py line 648
Quoted 11 lines
scripts/qmp_helper.py new file +9
-0+ + def search_qom(self, path, prop, regex): +class cper_guid: + """ + Contains CPER GUID, as per: + https://uefi.org/specs/UEFI/2.10/Apx_N_Common_Platform_Error_Record.html + """ + + CPER_PROC_X86 = guid(0xDC3EA0B0, 0xA144, 0x4797,
Maybe follow the spec naming as IA32_X64?
scripts/qmp_helper.py line 653
Quoted 5 lines
scripts/qmp_helper.py new file +5
-0+ [0xB9, 0x5B, 0x53, 0xFA, + 0x24, 0x2B, 0x6E, 0x1D]) + + CPER_PROC_ITANIUM = guid(0xe429faf1, 0x3cb7, 0x11d4, + [0xbc, 0xa7, 0x00, 0x80,
To stop people falling down a hole, maybe call out that this is not the format in the spec which is weird for this one case.
scripts/qmp_helper.py line 666
Quoted 9 lines
scripts/qmp_helper.py new file +7
-0+ 0xc7, 0x3c, 0x88, 0x81]) + + + + CPER_PLATFORM_MEM2 = guid(0x61EC04FC, 0x48E6, 0xD813, + [0x25, 0xC9, 0x8D, 0xAA, + 0x44, 0x75, 0x0B, 0x12])
Huh. they missed this one in the big spec table but is there in N.2.6
Quoted 1 line
+
CPER_PCI_DEV= guid(0xEB5E4685,0xCA66,0x4769,
CPER_PCI_COMPONENT would match N.2.9 naming.
If I recall PCI terminology right, component covers a bunch of things that Device doesn't.
scripts/qmp_helper.py line 680
Quoted 4 lines
scripts/qmp_helper.py new file +4
-0+ [0xB6, 0xA2, 0x26, 0x06, + 0x8B, 0x00, 0x13, 0x26]) + + CPER_FW_ERROR = guid(0x81212A96, 0x09ED, 0x4996,
Another one oddly missing from the big table but not the broken out sections. Not our problem but this chunk of the spec could do with tidying up!
scripts/qmp_helper.py line 684
Quoted 4 lines
scripts/qmp_helper.py new file +4
-0+ [0x94, 0x71, 0x8D, 0x72, + 0x9C, 0x8E, 0x69, 0xED]) + + CPER_DMA_GENERIC = guid(0x5B51FEF7, 0xC79D, 0x4434,
CPER_DMAR
Nothing to do with DMA in general. All about x86 IOMMUs I think.
scripts/qmp_helper.py line 702
Quoted 8 lines
scripts/qmp_helper.py new file +7
-0+ [0x8F, 0x1B, 0xAA, 0x62, + 0xDE, 0x3E, 0x2C, 0x64]) + + + CPER_CXL_PROT_ERR = guid(0x80B9EFB4, 0x52B5, 0x4DE3, + [0xA7, 0x77, 0x68, 0x78, + 0x4B, 0x77, 0x10, 0x48])
Maybe add the one for FRU Memory poison from the new 2.11 UEFI spec. This will constantly need updating with new specs so no problem if you'd rather stick to 2.10 only for now.
Re: [PATCH 01/11] acpi/ghes: Prepare to support multiple sources on ghes
In reply to Mauro Carvalho ChehabQuoted 5 lines · On Wed, 22 Jan 2025 16:46:18 +0100 Mauro Carvalho Chehab…
The current code is actually dependent on having just one error structure with a single source.
As the number of sources should be arch-dependent, as it will depend on what kind of synchronous/assynchronous notifications will exist, change
I 'd drop 'synchronous/assynchronous' and just leave broader 'notifications'
Quoted 71 lines
the logic to dynamically build the table.
Yet, for a proper support, we need to get the number of sources by reading the number from the HEST table. However, bios currently doesn't store a pointer to it.
For now just change the logic at table build time, while enforcing that it will behave like before with a single source ID.
A future patch will add a HEST table bios pointer and change the logic at
acpi_ghes_record_errors()to dynamically use the new size.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>--- hw/acpi/ghes.c | 43 ++++++++++++++++++++++++++-------------- hw/arm/virt-acpi-build.c | 5 +++++ include/hw/acpi/ghes.h | 21 +++++++++++++------- 3 files changed, 47 insertions(+), 22 deletions(-)hw/acpi/ghes.c +14
-5@@ -206,17 +206,26 @@ ghes_gen_err_data_uncorrectable_recoverable(GArray *block,* Initialize "etc/hardware_errors" and "etc/hardware_errors_addr" fw_cfg blobs. * See docs/specs/acpi_hest_ghes.rst for blobs format. */ -static void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker) +static void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker, +int num_sources) {int i, error_status_block_offset; +/* +* TODO: Current version supports only one source. +* A further patch will drop this check, after adding a proper migration +* code, as, for the code to work, we need to store a bios pointer to the +* HEST table. +*/ +assert (num_sources ==1 ); +/* Build error_block_address */ -for (i =0 ; i <ACPI_GHES_ERROR_SOURCE_COUNT ; i++) { +for (i =0 ; i < num_sources; i++) {build_append_int_noprefix (hardware_errors,0 ,sizeof (uint64_t )); }/* Build read_ack_register */ -for (i =0 ; i <ACPI_GHES_ERROR_SOURCE_COUNT ; i++) { +for (i =0 ; i < num_sources; i++) {/* * Initialize the value of read_ack_register to 1, so GHES can be * writable after (re)boot. @@ -231,13 +240,13 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker)/* Reserve space for Error Status Data Block */ acpi_data_push (hardware_errors, -ACPI_GHES_MAX_RAW_DATA_LENGTH *ACPI_GHES_ERROR_SOURCE_COUNT ); +ACPI_GHES_MAX_RAW_DATA_LENGTH * num_sources);/* Tell guest firmware to place hardware_errors blob into RAM */ bios_linker_loader_alloc (linker,ACPI_HW_ERROR_FW_CFG_FILE , hardware_errors,sizeof (uint64_t ), false); -for (i =0 ; i <ACPI_GHES_ERROR_SOURCE_COUNT ; i++) { +for (i =0 ; i < num_sources; i++) {/* * Tell firmware to patch error_block_address entries to point to * corresponding "Generic Error Status Block"
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker) · line 273
Quoted 2 lines
hw/acpi/ghes.c +0
-0@@ -263,10 +272,12 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker)/* Build Generic Hardware Error Source version 2 (GHESv2) */ static void build_ghes_v2(GArray *table_data,
^^^^^^^^^^^^^
it's a bit unclear what name implies, maybe s/build_ghes_v2/build_ghes_v2_entry/
Quoted 115 lines
hw/acpi/ghes.c +14
-10BIOSLinker *linker, - enum AcpiGhesNotifyType notify, - uint16_t source_id) + const AcpiNotificationSourceId *notif_src, + uint16_t index, int num_sources) { uint64_t address_offset; +const uint16_t notify = notif_src->notify; +const uint16_t source_id = notif_src->source_id;/* * Type: @@ -297,7 +308,7 @@ static void build_ghes_v2(GArray *table_data, address_offset +GAS_ADDR_OFFSET ,sizeof (uint64_t ),ACPI_HW_ERROR_FW_CFG_FILE , - source_id * sizeof(uint64_t)); + index * sizeof(uint64_t));/* Notification Structure */ build_ghes_hw_error_notification (table_data, notify);@@ -317,8 +328,7 @@ static void build_ghes_v2(GArray *table_data, address_offset +GAS_ADDR_OFFSET ,sizeof (uint64_t ),ACPI_HW_ERROR_FW_CFG_FILE , - (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) - * sizeof(uint64_t)); + (num_sources + index) * sizeof(uint64_t));/* * Read Ack Preserve field @@ -333,19 +343,23 @@ static void build_ghes_v2(GArray *table_data,/* Build Hardware Error Source Table */ void acpi_build_hest (GArray *table_data,GArray *hardware_errors,BIOSLinker *linker, +const AcpiNotificationSourceId *const notif_source, +int num_sources,const char *oem_id,const char *oem_table_id) {AcpiTable table = { .sig ="HEST" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id }; +int i; -build_ghes_error_table (hardware_errors, linker); +build_ghes_error_table (hardware_errors, linker, num_sources);acpi_table_begin (&table, table_data);/* Error Source Count */ -build_append_int_noprefix (table_data,ACPI_GHES_ERROR_SOURCE_COUNT ,4 ); -build_ghes_v2 (table_data, linker, -ACPI_GHES_NOTIFY_SEA ,ACPI_HEST_SRC_ID_SEA ); +build_append_int_noprefix (table_data, num_sources,4 ); +for (i =0 ; i < num_sources; i++) { +build_ghes_v2 (table_data, linker, ¬if_source[i], i, num_sources); + }acpi_table_end (linker, &table); }@@ -410,7 +424,6 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -assert (ACPI_GHES_ERROR_SOURCE_COUNT ==1 );get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), &cper_addr, &read_ack_register_addr);hw/arm/virt-acpi-build.c +5
-0@@ -893,6 +893,10 @@ static void acpi_align_size(GArray *blob, unsigned align)g_array_set_size (blob,ROUND_UP (acpi_data_len (blob), align)); } +static const AcpiNotificationSourceId hest_ghes_notify[] = { + {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, +}; +static void virt_acpi_build (VirtMachineState *vms,AcpiBuildTables *tables) {@@ -948,6 +952,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)if (vms->ras) {acpi_add_table (table_offsets, tables_blob);acpi_build_hest (tables_blob, tables->hardware_errors, tables->linker, + hest_ghes_notify,ARRAY_SIZE (hest_ghes_notify), vms->oem_id, vms->oem_table_id); }include/hw/acpi/ghes.h +5
-7@@ -57,20 +57,27 @@ enum AcpiGhesNotifyType {ACPI_GHES_NOTIFY_RESERVED =12 }; -enum { -ACPI_HEST_SRC_ID_SEA =0 , -/* future ids go here */ - -ACPI_GHES_ERROR_SOURCE_COUNT -}; -typedef struct AcpiGhesState {uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ }AcpiGhesState ; +/* +* ID numbers used to fill HEST source ID field +*/ +enum AcpiGhesSourceID { +ACPI_HEST_SRC_ID_SYNC ,
include/hw/acpi/ghes.h enum AcpiGhesNotifyType { · line 79
Quoted 10 lines
include/hw/acpi/ghes.h +8
-0+}; + +typedef struct AcpiNotificationSourceId { +enum AcpiGhesSourceID source_id; +enum AcpiGhesNotifyType notify; +}AcpiNotificationSourceId ; + void acpi_build_hest(GArray *table_data, GArray *hardware_errors, BIOSLinker *linker, + const AcpiNotificationSourceId * const notif_source,
^^^ is this intentional?
Quoted 4 lines
include/hw/acpi/ghes.h +1
-0+int num_sources, const char *oem_id, const char *oem_table_id);void acpi_ghes_add_fw_cfg (AcpiGhesState *vms,FWCfgState *s,GArray *hardware_errors);
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Jonathan CameronQuoted 40 lines · On Thu, 23 Jan 2025 10:02:17 +0000 Jonathan Cameron…
Quoted 6 lines · On Wed, 22 Jan 2025 16:46:19 +0100 Mauro Carvalho Chehab…
Store HEST table address at GPA, placing its content at
hest_addr_levariable.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>A few trivial things inline.
Jonathan
Quoted 6 lines
---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.Signed-off-by Mauro Carvalho Chehab <[email protected]>Bonus. I guess you really like this patch :)
Quoted 20 lines
--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)hw/acpi/ghes.c +1
-0@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }
Quoted 6 lines
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, · line 265
Quoted 3 lines
hw/acpi/ghes.c +1
-1/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into Sneaky tidy up. No problem with it in general but adding noise here, so if there are others in the series maybe gather them up in a cleanup patch.
+1
Quoted 9 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 359
Quoted 9 lines
hw/acpi/ghes.c +1
-0* hardware_errors_addr fw_cfg, once the former has been initialized. */ bios_linker_loader_write_pointer(linker, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, 0,@@ -355,6 +356,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,acpi_table_begin (&table, table_data); +int hest_offset = table_data->len;
should be unsigned, and better uint32_t
but we have a zoo wrt type here all over the place.
Quoted 3 lines
Local style looks to be traditional C with definitions at top. Maybe define
hest_offsetup a few lines and just set it here?
yep, it applies to whole QEMU (i.e. definitions only at the start of the block)
Quoted 27 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 370
Quoted 12 lines
hw/acpi/ghes.c +4
-0+/* Error Source Count */ build_append_int_noprefix (table_data, num_sources,4 );for (i =0 ; i < num_sources; i++) {@@ -362,6 +365,15 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, }acpi_table_end (linker, &table); + +/* +* tell firmware to write into GPA the address of HEST via fw_cfg, Given the tidy up above, fix this one to have a capital T, or was this where you meant to change it?
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 374
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* once initialized. +*/ + bios_linker_loader_write_pointer(linker, + ACPI_HEST_ADDR_FW_CFG_FILE, 0,Could wrap less and stay under 80 chars as both lines above add up to 70 something
Quoted 3 lines
hw/acpi/ghes.c +2
-0+sizeof (uint64_t ), + ACPI_BUILD_TABLE_FILE, hest_offset); }
Re: [PATCH 03/11] acpi/ghes: Use HEST table offsets when preparing GHES records
In reply to Jonathan CameronEm Thu, 23 Jan 2025 10:29:19 +0000
Jonathan Cameron <[email protected]> escreveu:
Quoted 46 lines
Quoted 5 lines · On Wed, 22 Jan 2025 16:46:20 +0100 Mauro Carvalho Chehab…
There are two pointers that are needed during error injection:
1. The start address of the CPER block to be stored;
2. The address of the ack, which needs a reset before next error.Quoted 7 lines
It is preferable to calculate them from the HEST table. This allows checking the source ID, the size of the table and the type of the HEST error block structures.
Yet, keep the old code, as this is needed for migration purposes.
Signed-off-by Mauro Carvalho Chehab <[email protected]>Generally looks good. A few bits that I think could be made easier to follow for anyone with the spec open in front of them.
Thanks,
Jonathan
Quoted 9 lines
--- hw/acpi/ghes.c | 98 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-)hw/acpi/ghes.c +0
-0hw/acpi/ghes.c line 70
Quoted 10 lines
hw/acpi/ghes.c +7
-0@@ -61,6 +61,23 @@*/ #define ACPI_GHES_GESB_SIZE 20 +/* +* Offsets with regards to the start of the HEST table stored at +* ags->hest_addr_le, according with the memory layout map at +* docs/specs/acpi_hest_ghes.rst. +*/ + +/* ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 Local multiline comment style seems to be always
/*
* ACPI 6.2:...
Quoted 6 lines
So perhaps good to copy that.
hw/acpi/ghes.c
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* Table 18-382 Generic Hardware Error Source version 2 (GHESv2) Structure +*/ +#define HEST_GHES_V2_TABLE_SIZE 92 +#define GHES_ACK_OFFSET (64 +
)
Quoted 5 lines
Using a GAS offset here to me obscures what is going on. I'd explicitly handle the GAS where you are reading this. We probably should sanity check the type as there are some crazy options that might turn up one day.
See below.
Quoted 7 lines
Maybe worth using spec term of
GHES_READ_ACK_...Obviously it's a question of who you are for whether it is read or write, but maybe still worth using that term for easy checking against the specification.
Quoted 8 lines
hw/acpi/ghes.c line 76
Quoted 2 lines
hw/acpi/ghes.c +2
-0+ +/* ACPI 6.2: 18.3.2.7: Generic Hardware Error Source same on comment format.
hw/acpi/ghes.c line 79
Quoted 3 lines
hw/acpi/ghes.c +3
-0+* Table 18-380: 'Error Status Address' field +*/ +#define GHES_ERR_ST_ADDR_OFFSET (20 + GAS_ADDR_OFFSET)Maybe STS or spell out status? I found ST a bit confusing below.
Giving names is not an easy task... Removing _ST doesn't sound right, as everything is GHES_ERR. STS sounds weird to me as well. Maybe we could name them both as something like:
GHES_ERR_STATUS_ADDR_OFF
GHES_READ_ACK_ADDR_OFF
Quoted 23 lines
Quoted 23 lines
hw/acpi/ghes.c +1
-8+/* * Values for error_severity field */ @@ -212,14 +229,6 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, {int i, error_status_block_offset; -/* -* TODO: Current version supports only one source. -* A further patch will drop this check, after adding a proper migration -* code, as, for the code to work, we need to store a bios pointer to the -* HEST table. -*/ -assert (num_sources ==1 ); -/* Build error_block_address */ for (i =0 ; i < num_sources; i++) {build_append_int_noprefix (hardware_errors,0 ,sizeof (uint64_t ));@@ -419,6 +428,70 @@ static void get_hw_error_offsets(uint64_t ghes_addr, *read_ack_register_addr = ghes_addr +sizeof (uint64_t ); }
Quoted 13 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 440
Quoted 10 lines
hw/acpi/ghes.c +10
-0+static void get_ghes_source_offsets (uint16_t source_id,uint64_t hest_addr, +uint64_t *cper_addr, +uint64_t *read_ack_start_addr, +Error **errp) +{ +uint64_t hest_err_block_addr, hest_read_ack_addr; +uint64_t err_source_struct, error_block_addr; +uint32_t num_sources, i; + +if (!hest_addr) {I guess it is a question of matching local code, but I'd be tempted to name this
hest_body_addras it isn't the start of the table but rather the bit after the header.
This is named after hest_addr_le, which in turn was named after ghes_hw_le.
Besides, I guess such name was suggested on a past review. From my side, I'm OK with any name you/Igor pick.
Quoted 29 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 444
Quoted 5 lines
hw/acpi/ghes.c +4
-0+return ; + } + +cpu_physical_memory_read (hest_addr, &num_sources,sizeof (num_sources));The
hest_addrnaming thing confused me a tiny bit here because obviouslynum_sourcesisn't the first thing in the table in the spec!Quoted 9 lines
hw/acpi/ghes.c +9
-0+ num_sources =le32_to_cpu (num_sources); + + err_source_struct = hest_addr +sizeof (num_sources); + +/* +* Currently, HEST Error source navigates only for GHESv2 tables +*/ + +for (i =0 ; i < num_sources; i++) {hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 463
Quoted 10 lines
hw/acpi/ghes.c +10
-0+uint64_t addr = err_source_struct; +uint16_t type, src_id; + +cpu_physical_memory_read (addr, &type,sizeof (type)); + type =le16_to_cpu (type); + +/* For now, we only know the size of GHESv2 table */ +if (type !=ACPI_GHES_SOURCE_GENERIC_ERROR_V2 ) { +error_setg (errp,"HEST: type %d not supported." , type); +return ;
Quoted 7 lines
It's a pity we can't just skip them, but absence of a size field makes that tricky... Can add that later I guess along with sizes for each defined type including figuring out the variable length ones like IA-32 machine check. I guess this is why the whole ordering constraint for new types was added. Can't find the old ones if we don't know the size of the new ones, hence need new definitions at the end.
Yes. The variable sizes makes it harder to parse with current GHES types. It sounds they'll fix it for the next types, as the size of the record will be stored for types above 11.
So, at the end, we'll need to add a much more complex logic if/when we add non-GHES records.
Quoted 22 lines
Anyhow, I'm fine with this but maybe a little more description in the comment would avoid someone going down same rat hole I just did.
Quoted 17 lines
hw/acpi/ghes.c +17
-0+ } + +/* Compare CPER source address at the GHESv2 structure */ + addr +=sizeof (type); +cpu_physical_memory_read (addr, &src_id,sizeof (src_id)); + +if (src_id == source_id) { +break ; + } + + err_source_struct +=HEST_GHES_V2_TABLE_SIZE ; + } +if (i == num_sources) { +error_setg (errp,"HEST: Source %d not found." , source_id); +return ; + } +
Quoted 8 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 482
Quoted 2 lines
hw/acpi/ghes.c +2
-0+/* Navigate though table address pointers */ + hest_err_block_addr = err_source_struct +GHES_ERR_ST_ADDR_OFFSET ;So this is a bit confusing. I'd pull the GAS offset down here rather than putting it in the define. That way we can clearly see you are grabbing the address field. As above, should we check the type is
0x00? There are many fun things it could be but here I think we just want it to be memory space.
In short:
The type was already ensured when HEST table is built. I can't see any need to add extra checks. If you want this to be better documented, we could just do:
hest_err_block_addr = err_source_struct + GHES_ERR_STATUS_ADDR_OFF + GAS_OFFSET;
It follows a longer rationale:
If I understood well, and after some discussions we had today via chat, you basically want to add an additional check logic during error inject to check if the memory type filled at build_ghes_v2() here:
/* Build Generic Hardware Error Source version 2 (GHESv2) */ static void build_ghes_v2(GArray *table_data,
BIOSLinker *linker,
const AcpiNotificationSourceId *notif_src, uint16_t index, int num_sources)
{
...
/* Error Status Address */
build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0,
...
/*
* Read Ack Register
* ACPI 6.1: 18.3.2.8 Generic Hardware Error Source
* version 2 (GHESv2 - Type 10)
*/
build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0,
4 /* QWord access */, 0);
...
}was not modified and still remains AML_AS_SYSTEM_MEMORY, as otherwise the code at get_ghes_source_offsets() won't be able to use cpu_physical_memory_read/cpu_physical_memory_write. To make it right, IMO we would need to add something like this to aml-build.c:
int verify_gas_addr_space(uint64_t addr, AmlAddressSpace as)
{
uint64_t gas_header;
cpu_physical_memory_read(addr, &gas_header, 4);
gas_header = cpu_to_le64(0);
if ((gas_header & 0xff) != as)
return 1;
return 0;
}and at ghes.c do something like:
// Using current names just to better illustrate the changes
#define GHES_ACK_OFFSET 64 // don't add GAS_ADDR_OFFSET here
#define GHES_ERR_ST_ADDR_OFFSET 20 // don't add GAS_ADDR_OFFSET here
static void get_ghes_source_offsets(uint16_t source_id, uint64_t hest_addr,
uint64_t *cper_addr,
uint64_t *read_ack_start_addr,
Error **errp)
{
/* Navigate though table address pointers */
hest_err_block_addr = err_source_struct + GHES_ERR_ST_ADDR_OFFSET;
/* EXTRA CHECK LOGIC: Verify if build_ghes_v2() did his job */
if (verify_gas_addr_space(hest_err_block_addr, AML_AS_SYSTEM_MEMORY)} {
error_setg(errp, "HEST firmware is not using system memory!!!");
return;
}
hest_err_block_addr += GAS_ADDR_OFFSET;
hest_read_ack_addr = err_source_struct + GHES_ACK_OFFSET;
/* EXTRA CHECK LOGIC: Verify if build_ghes_v2() did his job */
if (verify_gas_addr_space(hest_read_ack_addr, AML_AS_SYSTEM_MEMORY)} {
error_setg(errp, "HEST firmware is not using system memory!!!");
return;
}
hest_read_ack_addr += GAS_ADDR_OFFSET;
cpu_physical_memory_read(hest_err_block_addr, &error_block_addr,
sizeof(error_block_addr));
cpu_physical_memory_read(error_block_addr, cper_addr,
sizeof(*cper_addr));
cpu_physical_memory_read(hest_read_ack_addr, read_ack_start_addr,
sizeof(*read_ack_start_addr));
}IMO, this is overkill:
- I can't see how such check will ever be triggered in practice;
- I can't see any reason why the HEST firmware would ever be stored on a non-system memory: firmware should always be at AML_AS_SYSTEM_MEMORY;
- As those offsets are related to fw_cfg, any change there would require changing the firmware binding logic. Plus, they'll very likely also require changes at BIOS code itself, as it would need to know how to store firmware files on some other memory type;
- Any change like that will certainly require adding backport support, as QEMU would need to check if BIOS would support different types of memory to store firmware instead of system memory. Also, QEMU 9.1 is only compatible with firmware stored on system's memory.
So, I don't see any benefit of doing that.
Quoted 34 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 483
Quoted 1 line
hw/acpi/ghes.c +1
-0+ hest_read_ack_addr = err_source_struct +GHES_ACK_OFFSET ;Perhaps move this down to above where it is used?
Same thing about GAS address offset being better found down here rather than hidden inGHES_ACK_OFFSET.Quoted 28 lines
hw/acpi/ghes.c +18
-2+ +cpu_physical_memory_read (hest_err_block_addr, &error_block_addr, +sizeof (error_block_addr)); + +cpu_physical_memory_read (error_block_addr, cper_addr, +sizeof (*cper_addr)); + +cpu_physical_memory_read (hest_read_ack_addr, read_ack_start_addr, +sizeof (*read_ack_start_addr)); +} +void ghes_record_cper_errors (const void *cper,size_t len,uint16_t source_id,Error **errp) {@@ -439,8 +512,13 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), - &cper_addr, &read_ack_register_addr); +if (!ags->hest_addr_le) { +get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), + &cper_addr, &read_ack_register_addr); + }else { +get_ghes_source_offsets (source_id,le64_to_cpu (ags->hest_addr_le), + &cper_addr, &read_ack_register_addr, errp); + }
Quoted 3 lines
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 524
Quoted 2 lines
hw/acpi/ghes.c +0
-0if (!cper_addr) {error_setg (errp,"can not find Generic Error Status Block" );
Thanks,
Mauro
Re: [PATCH 03/11] acpi/ghes: Use HEST table offsets when preparing GHES records
Quoted 10 lines · On Thu, 23 Jan 2025 19:23:50 +0100 Mauro Carvalho Chehab…
Em Thu, 23 Jan 2025 10:29:19 +0000
Jonathan Cameron <[email protected]> escreveu:Quoted 7 lines
Quoted 4 lines · On Wed, 22 Jan 2025 16:46:20 +0100 Mauro Carvalho Chehab…
There are two pointers that are needed during error injection:
1. The start address of the CPER block to be stored;
2. The address of the ack, which needs a reset before next error.
drop sentence after comma as it's not necessary (and confusing detail)
Quoted 68 lines
Quoted 39 lines
Quoted 8 lines
It is preferable to calculate them from the HEST table. This allows checking the source ID, the size of the table and the type of the HEST error block structures.
Yet, keep the old code, as this is needed for migration purposes.
Signed-off-by Mauro Carvalho Chehab <[email protected]>Generally looks good. A few bits that I think could be made easier to follow for anyone with the spec open in front of them.
Thanks,
Jonathan
Quoted 9 lines
--- hw/acpi/ghes.c | 98 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-)hw/acpi/ghes.c +0
-0hw/acpi/ghes.c line 70
Quoted 10 lines
hw/acpi/ghes.c +7
-0@@ -61,6 +61,23 @@*/ #define ACPI_GHES_GESB_SIZE 20 +/* +* Offsets with regards to the start of the HEST table stored at +* ags->hest_addr_le, according with the memory layout map at +* docs/specs/acpi_hest_ghes.rst. +*/ + +/* ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 Local multiline comment style seems to be always
/*
* ACPI 6.2:...Quoted 6 lines
So perhaps good to copy that.
hw/acpi/ghes.c
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* Table 18-382 Generic Hardware Error Source version 2 (GHESv2) Structure +*/ +#define HEST_GHES_V2_TABLE_SIZE 92 +#define GHES_ACK_OFFSET (64 +)
Quoted 5 lines
Using a GAS offset here to me obscures what is going on. I'd explicitly handle the GAS where you are reading this. We probably should sanity check the type as there are some crazy options that might turn up one day.
See below.
Quoted 14 lines
Maybe worth using spec term of
GHES_READ_ACK_...Obviously it's a question of who you are for whether it is read or write, but maybe still worth using that term for easy checking against the specification.
hw/acpi/ghes.c line 76
Quoted 2 lines
hw/acpi/ghes.c +2
-0+ +/* ACPI 6.2: 18.3.2.7: Generic Hardware Error Source same on comment format.
Quoted 3 lines
hw/acpi/ghes.c +3
-0+* Table 18-380: 'Error Status Address' field +*/ +#define GHES_ERR_ST_ADDR_OFFSET (20 + GAS_ADDR_OFFSET)
Quoted 8 lines
Quoted 1 line
Maybe STS or spell out status? I found ST a bit confusing below.
Giving names is not an easy task... Removing
_STdoesn't sound right, as everything isGHES_ERR. STS sounds weird to me as well. Maybe we could name them both as something like:
GHES_ERR_STATUS_ADDR_OFF
GHES_READ_ACK_ADDR_OFF
lgtm
Quoted 38 lines
Quoted 24 lines
Quoted 24 lines
hw/acpi/ghes.c +1
-8+/* * Values for error_severity field */ @@ -212,14 +229,6 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, {int i, error_status_block_offset; -/* -* TODO: Current version supports only one source. -* A further patch will drop this check, after adding a proper migration -* code, as, for the code to work, we need to store a bios pointer to the -* HEST table. -*/ -assert (num_sources ==1 ); -/* Build error_block_address */ for (i =0 ; i < num_sources; i++) {build_append_int_noprefix (hardware_errors,0 ,sizeof (uint64_t ));@@ -419,6 +428,70 @@ static void get_hw_error_offsets(uint64_t ghes_addr, *read_ack_register_addr = ghes_addr +sizeof (uint64_t ); }Quoted 13 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 440
Quoted 10 lines
hw/acpi/ghes.c +10
-0+static void get_ghes_source_offsets (uint16_t source_id,uint64_t hest_addr, +uint64_t *cper_addr, +uint64_t *read_ack_start_addr, +Error **errp) +{ +uint64_t hest_err_block_addr, hest_read_ack_addr; +uint64_t err_source_struct, error_block_addr; +uint32_t num_sources, i; + +if (!hest_addr) {I guess it is a question of matching local code, but I'd be tempted to name this
hest_body_addras it isn't the start of the table but rather the bit after the header.
Quoted 10 lines
This is named after
hest_addr_le, which in turn was named afterghes_hw_le.Besides, I guess such name was suggested on a past review. From my side, I'm OK with any name you/Igor pick.
Quoted 5 lines
Quoted 5 lines
hw/acpi/ghes.c +4
-0+return ; + } + +cpu_physical_memory_read (hest_addr, &num_sources,sizeof (num_sources));
if it were the HEST table addr, then hest_addr name is ok
however in that case you are reading value of "Header Signature" into num_sources. Which makes me think there is a bug here as one should read hest_addr + num_src_off
Quoted 7 lines
Quoted 7 lines
The
hest_addrnaming thing confused me a tiny bit here because obviouslynum_sourcesisn't the first thing in the table in the spec!Quoted 3 lines
hw/acpi/ghes.c +3
-0+ num_sources =le32_to_cpu (num_sources); + + err_source_struct = hest_addr +sizeof (num_sources);
the same issue wrt correct offset
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
hw/acpi/ghes.c +16
-0+ +/* +* Currently, HEST Error source navigates only for GHESv2 tables +*/ + +for (i =0 ; i < num_sources; i++) { +uint64_t addr = err_source_struct; +uint16_t type, src_id; + +cpu_physical_memory_read (addr, &type,sizeof (type)); + type =le16_to_cpu (type); + +/* For now, we only know the size of GHESv2 table */ +if (type !=ACPI_GHES_SOURCE_GENERIC_ERROR_V2 ) { +error_setg (errp,"HEST: type %d not supported." , type); +return ;
Quoted 8 lines
Quoted 8 lines
It's a pity we can't just skip them, but absence of a size field makes that tricky... Can add that later I guess along with sizes for each defined type including figuring out the variable length ones like IA-32 machine check. I guess this is why the whole ordering constraint for new types was added. Can't find the old ones if we don't know the size of the new ones, hence need new definitions at the end.
this error out may cause parsing issues in the future when migrating from new to old QEMU (but at least it's not fatal),
So I've given up on pushing for graceful 'skip' of not handled entries. (considering backward migration is not hard req for upstream qemu)
Though, tt's would be nice to have it in the same merge cycle as patch on top if possible.
Quoted 12 lines
Yes. The variable sizes makes it harder to parse with current GHES types. It sounds they'll fix it for the next types, as the size of the record will be stored for types above 11.
So, at the end, we'll need to add a much more complex logic if/when we add non-GHES records.
Quoted 5 lines
Anyhow, I'm fine with this but maybe a little more description in the comment would avoid someone going down same rat hole I just did.
Quoted 7 lines
Quoted 7 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 470
Quoted 7 lines
hw/acpi/ghes.c +7
-0+ } + +/* Compare CPER source address at the GHESv2 structure */ + addr +=sizeof (type); +cpu_physical_memory_read (addr, &src_id,sizeof (src_id)); + +if (src_id == source_id) {
missing le2cpu(src_id) here ???
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
hw/acpi/ghes.c +10
-0+break ; + } + + err_source_struct +=HEST_GHES_V2_TABLE_SIZE ; + } +if (i == num_sources) { +error_setg (errp,"HEST: Source %d not found." , source_id); +return ; + } +Quoted 8 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 482
Quoted 2 lines
hw/acpi/ghes.c +2
-0+/* Navigate though table address pointers */ + hest_err_block_addr = err_source_struct +GHES_ERR_ST_ADDR_OFFSET ;So this is a bit confusing. I'd pull the GAS offset down here rather than putting it in the define. That way we can clearly see you are grabbing the address field. As above, should we check the type is
0x00? There are many fun things it could be but here I think we just want it to be memory space.
Quoted 6 lines
In short:
The type was already ensured when HEST table is built. I can't see any need to add extra checks. If you want this to be better documented, we could just do:
1)
Quoted 1 line
hest_err_block_addr = err_source_struct + GHES_ERR_STATUS_ADDR_OFF + GAS_OFFSET;
I'd prefer this, _ST_ part in GHES_ERR_ST_ADDR_OFFSET also reads to me a bit confusing.
Quoted 99 lines
It follows a longer rationale:
If I understood well, and after some discussions we had today via chat, you basically want to add an additional check logic during error inject to check if the memory type filled at
build_ghes_v2()here:/* Build Generic Hardware Error Source version 2 (GHESv2) */ static void build_ghes_v2(GArray
*table_data,
BIOSLinker *linker,
const AcpiNotificationSourceId*notif_src,uint16_tindex, intnum_sources)
{
.../* Error Status Address */ build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, ... /* * Read Ack Register * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source * version 2 (GHESv2 - Type 10) */ build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, 4 /* QWord access */, 0); ... }was not modified and still remains
AML_AS_SYSTEM_MEMORY, as otherwise the code atget_ghes_source_offsets()won't be able to use cpu_physical_memory_read/cpu_physical_memory_write. To make it right, IMO we would need to add something like this toaml-build.c:int verify_gas_addr_space(uint64_t addr, AmlAddressSpace as) { uint64_t gas_header; cpu_physical_memory_read(addr, &gas_header, 4); gas_header = cpu_to_le64(0); if ((gas_header & 0xff) != as) return 1; return 0; }and at
ghes.cdo something like:// Using current names just to better illustrate the changes #define GHES_ACK_OFFSET 64 // don't add GAS_ADDR_OFFSET here #define GHES_ERR_ST_ADDR_OFFSET 20 // don't add GAS_ADDR_OFFSET here static void get_ghes_source_offsets(uint16_t source_id, uint64_t hest_addr, uint64_t *cper_addr, uint64_t *read_ack_start_addr, Error **errp) { /* Navigate though table address pointers */ hest_err_block_addr = err_source_struct + GHES_ERR_ST_ADDR_OFFSET; /* EXTRA CHECK LOGIC: Verify if build_ghes_v2() did his job */ if (verify_gas_addr_space(hest_err_block_addr, AML_AS_SYSTEM_MEMORY)} { error_setg(errp, "HEST firmware is not using system memory!!!"); return; } hest_err_block_addr += GAS_ADDR_OFFSET; hest_read_ack_addr = err_source_struct + GHES_ACK_OFFSET; /* EXTRA CHECK LOGIC: Verify if build_ghes_v2() did his job */ if (verify_gas_addr_space(hest_read_ack_addr, AML_AS_SYSTEM_MEMORY)} { error_setg(errp, "HEST firmware is not using system memory!!!"); return; } hest_read_ack_addr += GAS_ADDR_OFFSET; cpu_physical_memory_read(hest_err_block_addr, &error_block_addr, sizeof(error_block_addr)); cpu_physical_memory_read(error_block_addr, cper_addr, sizeof(*cper_addr)); cpu_physical_memory_read(hest_read_ack_addr, read_ack_start_addr, sizeof(*read_ack_start_addr)); }IMO, this is overkill:
- I can't see how such check will ever be triggered in practice;
- I can't see any reason why the HEST firmware would ever be stored on a non-system memory: firmware should always be atAML_AS_SYSTEM_MEMORY;
- As those offsets are related tofw_cfg, any change there would require changing the firmware binding logic. Plus, they'll very likely also require changes at BIOS code itself, as it would need to know how to store firmware files on some other memory type;
- Any change like that will certainly require adding backport support, as QEMU would need to check if BIOS would support different types of memory to store firmware instead of system memory. Also, QEMU 9.1 is only compatible with firmware stored on system's memory.
Quoted 1 line
So, I don't see any benefit of doing that.
+1
Quoted 6 lines
Quoted 6 lines
hw/acpi/ghes.c static void get_hw_error_offsets(uint64_t ghes_addr, · line 483
Quoted 2 lines
hw/acpi/ghes.c +1
-0+ hest_read_ack_addr = err_source_struct +GHES_ACK_OFFSET ;Perhaps move this down to above where it is used?
Same thing about GAS address offset being better found down here rather than hidden inGHES_ACK_OFFSET.
I'd treat it the same as [1]
Quoted 22 lines
Quoted 21 lines
Quoted 21 lines
hw/acpi/ghes.c +11
-2+ +cpu_physical_memory_read (hest_err_block_addr, &error_block_addr, +sizeof (error_block_addr)); + +cpu_physical_memory_read (error_block_addr, cper_addr, +sizeof (*cper_addr)); + +cpu_physical_memory_read (hest_read_ack_addr, read_ack_start_addr, +sizeof (*read_ack_start_addr)); +} +void ghes_record_cper_errors (const void *cper,size_t len,uint16_t source_id,Error **errp) {@@ -439,8 +512,13 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), - &cper_addr, &read_ack_register_addr);
Quoted 8 lines
Quoted 8 lines
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 522
Quoted 8 lines
hw/acpi/ghes.c +7
-0+if (!ags->hest_addr_le) { +get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), + &cper_addr, &read_ack_register_addr); + }else { +get_ghes_source_offsets (source_id,le64_to_cpu (ags->hest_addr_le), + &cper_addr, &read_ack_register_addr, errp); + }
it looks like returned addresses in le byteorder, and then caller uses them as is to access memory, where as it should use le2cpu on them 1st. I'd add here conversion so the caller would deal only with host byteorder (i.e. the same way as get_hw_error_offsets())
Quoted 9 lines
Quoted 3 lines
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 524
Quoted 2 lines
hw/acpi/ghes.c +0
-0if (!cper_addr) {error_setg (errp,"can not find Generic Error Status Block" );Thanks,
Mauro
Re: [PATCH 04/11] acpi/generic_event_device: Update GHES migration to cover hest addr
In reply to Mauro Carvalho ChehabQuoted 4 lines · On Wed, 22 Jan 2025 16:46:21 +0100 Mauro Carvalho Chehab…
The GHES migration logic at GED should now support HEST table location too.
Signed-off-by Mauro Carvalho Chehab <[email protected]>
Quoted 51 lines
--- hw/acpi/generic_event_device.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)hw/acpi/generic_event_device.c +29
-0@@ -386,6 +386,34 @@ static const VMStateDescription vmstate_ghes_state = { } }; +static const VMStateDescription vmstate_hest = { + .name ="acpi-hest" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_UINT64 (hest_addr_le, AcpiGhesState), +VMSTATE_END_OF_LIST () + }, +}; + +static bool hest_needed (void *opaque) +{ +AcpiGedState *s = opaque; +return s->ghes_state.hest_addr_le; +} + +static const VMStateDescription vmstate_hest_state = { + .name ="acpi-ged/hest" , + .version_id =1 , + .minimum_version_id =1 , + .needed = hest_needed, + .fields = (const VMStateField []) { +VMSTATE_STRUCT (ghes_state, AcpiGedState,1 , + vmstate_hest, AcpiGhesState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_acpi_ged = { .name ="acpi-ged" , .version_id =1 ,@@ -398,6 +426,7 @@ static const VMStateDescription vmstate_acpi_ged = { &vmstate_memhp_state, &vmstate_cpuhp_state, &vmstate_ghes_state, + &vmstate_hest_state, NULL } };
Re: [PATCH 05/11] acpi/generic_event_device: add logic to detect if HEST addr is available
In reply to Mauro Carvalho ChehabQuoted 3 lines · On Wed, 22 Jan 2025 16:46:22 +0100 Mauro Carvalho Chehab…
Create a new property (x-has-hest-addr) and use it to detect if the GHES table offsets can be calculated from the HEST address (qemu 9.2 and upper) or via the legacy way via an offset obtained
10.0 by now
Quoted 16 lines
from the
hardware_errorsfirmware file.Signed-off-by Mauro Carvalho Chehab <[email protected]>--- hw/acpi/generic_event_device.c | 1 + hw/acpi/ghes.c | 28 +++++++++++++++++++++------- hw/arm/virt-acpi-build.c | 30 ++++++++++++++++++++++++++---- hw/core/machine.c | 2 ++ include/hw/acpi/ghes.h | 1 + 5 files changed, 51 insertions(+), 11 deletions(-)hw/acpi/generic_event_device.c +0
-0
hw/acpi/generic_event_device.c static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) · line 321
Quoted 4 lines
hw/acpi/generic_event_device.c +1
-0@@ -318,6 +318,7 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)static const Property acpi_ged_properties[] = {DEFINE_PROP_UINT32 ("ged-event" , AcpiGedState, ged_event_bitmap,0 ), +DEFINE_PROP_BOOL ("x-has-hest-addr" , AcpiGedState, ghes_state.hest_lookup, true),
s/hest_lookup/use_hest_addr/
Quoted 17 lines
hw/acpi/generic_event_device.c +0
-0};static const VMStateDescription vmstate_memhp_state = {hw/acpi/ghes.c +2
-0@@ -359,6 +359,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, {AcpiTable table = { .sig ="HEST" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id }; +AcpiGedState *acpi_ged_state; +AcpiGhesState *ags =NULL ;int i;build_ghes_error_table (hardware_errors, linker, num_sources);
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 386
Quoted 10 lines
hw/acpi/ghes.c +3
-4@@ -379,10 +381,20 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,* tell firmware to write into GPA the address of HEST via fw_cfg, * once initialized. */ -bios_linker_loader_write_pointer (linker, -ACPI_HEST_ADDR_FW_CFG_FILE ,0 , -sizeof (uint64_t ), -ACPI_BUILD_TABLE_FILE , hest_offset); + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL ));
the caller, already did lookup,
just pass hest_lookup as an argument and use it here
Quoted 15 lines
hw/acpi/ghes.c +11
-0+if (!acpi_ged_state) { +return ; + } + + ags = &acpi_ged_state->ghes_state; +if (ags->hest_lookup) { +bios_linker_loader_write_pointer (linker, +ACPI_HEST_ADDR_FW_CFG_FILE ,0 , +sizeof (uint64_t ), +ACPI_BUILD_TABLE_FILE , hest_offset); + } } void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,
hw/acpi/ghes.c void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s, · line 409
Quoted 2 lines
hw/acpi/ghes.c +0
-0@@ -396,8 +408,10 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,fw_cfg_add_file_callback (s,ACPI_HW_ERROR_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->hw_error_le),sizeof (ags->hw_error_le), false);
btw shouldn't we disable hw_error_le if hest_lookup is active?
hw/acpi/ghes.c void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s, · line 411
Quoted 4 lines
hw/acpi/ghes.c +1
-2-fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , -NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); +if (ags && ags->hest_lookup) {
why bother with 'ags &&' if we don't do it hw_error_le?
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 529
Quoted 12 lines
hw/acpi/ghes.c +4
-1+fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , +NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); + } ags->present = true; }@@ -512,7 +526,7 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state; -if (!ags->hest_addr_le) { +if (!ags->hest_lookup) {
why? !ags->hest_addr_le is sufficient
Quoted 73 lines
hw/acpi/ghes.c +0
-0get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), &cper_addr, &read_ack_register_addr); }else {hw/arm/virt-acpi-build.c +26
-4@@ -897,6 +897,10 @@ static const AcpiNotificationSourceId hest_ghes_notify[] = { { ACPI_HEST_SRC_ID_SYNC, ACPI_GHES_NOTIFY_SEA }, }; +static const AcpiNotificationSourceId hest_ghes_notify_9_2[] = { + {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, +}; +static void virt_acpi_build (VirtMachineState *vms,AcpiBuildTables *tables) {@@ -950,10 +954,28 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_dbg2 (tables_blob, tables->linker, vms);if (vms->ras) { -acpi_add_table (table_offsets, tables_blob); -acpi_build_hest (tables_blob, tables->hardware_errors, tables->linker, - hest_ghes_notify,ARRAY_SIZE (hest_ghes_notify), - vms->oem_id, vms->oem_table_id); +AcpiGhesState *ags; +AcpiGedState *acpi_ged_state; + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); +if (acpi_ged_state) { + ags = &acpi_ged_state->ghes_state; + +acpi_add_table (table_offsets, tables_blob); + +if (!ags->hest_lookup) { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify_9_2, +ARRAY_SIZE (hest_ghes_notify_9_2), + vms->oem_id, vms->oem_table_id); + }else { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify, +ARRAY_SIZE (hest_ghes_notify), + vms->oem_id, vms->oem_table_id); + } + } }if (ms->numa_state->num_nodes >0 ) {hw/core/machine.c +2
-0@@ -34,10 +34,12 @@#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/acpi/generic_event_device.h" #include "audio/audio.h" GlobalProperty hw_compat_9_2[] = { {"arm-cpu" ,"backcompat-pauth-default-use-qarma5" ,"true" }, + {TYPE_ACPI_GED ,"x-has-hest-addr" ,"false" }, };const size_t hw_compat_9_2_len =G_N_ELEMENTS (hw_compat_9_2);include/hw/acpi/ghes.h +0
-0
include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 63
Quoted 3 lines
include/hw/acpi/ghes.h +0
-0@@ -61,6 +61,7 @@ typedef struct AcpiGhesState {uint64_t hest_addr_le;uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */
and perhaps reformulate this as well
include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 64
Quoted 1 line
include/hw/acpi/ghes.h +1
-0+bool hest_lookup;/* True if HEST address is present */
if device should use HEST addr for error source lookup
Quoted 3 lines
include/hw/acpi/ghes.h +0
-0} AcpiGhesState;/*
Re: [PATCH 07/11] acpi/ghes: Cleanup the code which gets ghes ged state
In reply to Mauro Carvalho ChehabQuoted 60 lines · On Wed, 22 Jan 2025 16:46:24 +0100 Mauro Carvalho Chehab…
Move the check logic into a common function and simplify the code which checks if GHES is enabled and was properly setup.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- hw/acpi/ghes-stub.c | 4 ++-- hw/acpi/ghes.c | 33 +++++++++++---------------------- include/hw/acpi/ghes.h | 9 +++++---- target/arm/kvm.c | 2 +- 4 files changed, 19 insertions(+), 29 deletions(-)hw/acpi/ghes-stub.c +2
-2@@ -16,7 +16,7 @@ int acpi_ghes_memory_errors(uint16_t source_id, uint64_t physical_address)return -1 ; } -bool acpi_ghes_present (void ) +AcpiGhesState *acpi_ghes_get_state (void ) { -return false; +return NULL ; }hw/acpi/ghes.c +0
-9@@ -420,10 +420,6 @@ static void get_hw_error_offsets(uint64_t ghes_addr,uint64_t *cper_addr, uint64_t *read_ack_register_addr) { -if (!ghes_addr) { -return ; - } -/* * non-HEST version supports only one source, so no need to change * the start offset based on the source ID. Also, we can't validate @@ -451,10 +447,6 @@ static void get_ghes_source_offsets(uint16_t source_id, uint64_t hest_addr,uint64_t err_source_struct, error_block_addr;uint32_t num_sources, i; -if (!hest_addr) { -return ; - } -cpu_physical_memory_read (hest_addr, &num_sources,sizeof (num_sources)); num_sources =le32_to_cpu (num_sources);@@ -513,7 +505,6 @@ void ghes_record_cper_errors(const void *cper, size_t len, uint16_t source_id, Error **errp) { uint64_t cper_addr = 0, read_ack_register_addr = 0, read_ack_register; -AcpiGedState *acpi_ged_state;AcpiGhesState *ags;if (len >ACPI_GHES_MAX_RAW_DATA_LENGTH ) {
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 515
Quoted 8 lines
hw/acpi/ghes.c +1
-4@@ -521,13 +512,10 @@ void ghes_record_cper_errors(const void *cper, size_t len,return ; } - acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , -NULL )); -if (!acpi_ged_state) { -error_setg (errp,"Can't find ACPI_GED object" ); + ags =acpi_ghes_get_state ();
1)
Quoted 31 lines
hw/acpi/ghes.c +2
-7+if (!ags) {return ; } - ags = &acpi_ged_state->ghes_state;if (!ags->hest_lookup) { get_hw_error_offsets(le64_to_cpu(ags->hw_error_le),@@ -537,11 +525,6 @@ void ghes_record_cper_errors(const void *cper, size_t len, &cper_addr, &read_ack_register_addr, errp); } -if (!cper_addr) { -error_setg (errp,"can not find Generic Error Status Block" ); -return ; - } -cpu_physical_memory_read (read_ack_register_addr, &read_ack_register,sizeof (read_ack_register));@@ -605,7 +588,7 @@ int acpi_ghes_memory_errors(uint16_t source_id, uint64_t physical_address)return 0 ; } -bool acpi_ghes_present (void ) +AcpiGhesState *acpi_ghes_get_state (void ) {AcpiGedState *acpi_ged_state;AcpiGhesState *ags;@@ -614,8 +597,14 @@ bool acpi_ghes_present(void) NULL));
hw/acpi/ghes.c bool acpi_ghes_present(void) · line 606
Quoted 10 lines
hw/acpi/ghes.c +4
-2if (!acpi_ged_state) { -return false; +return NULL ; } ags = &acpi_ged_state->ghes_state; -return ags->present; +if (!ags->present) { +return NULL ; + }
redundant check, check below vvvv should be sufficient
Quoted 30 lines
hw/acpi/ghes.c +4
-0+if (!ags->hw_error_le && !ags->hest_addr_le) { +return NULL ; + } +return ags;}
include/hw/acpi/ghes.h +5
-4@@ -91,10 +91,11 @@ void ghes_record_cper_errors(const void *cper, size_t len, uint16_t source_id, Error **errp);/** -* acpi_ghes_present: Report whether ACPI GHES table is present +* acpi_ghes_get_state: Get a pointer for ACPI ghes state * -* Returns: true if the system has an ACPI GHES table and it is -* safe to call acpi_ghes_memory_errors() to record a memory error. +* Returns: a pointer to ghes state if the system has an ACPI GHES table, +* it is enabled and it is safe to call acpi_ghes_memory_errors() to record +* a memory error. Returns false, otherwise. */ -bool acpi_ghes_present (void ); +AcpiGhesState *acpi_ghes_get_state (void );#endif target/arm/kvm.c +0
-0
target/arm/kvm.c void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) · line 2372
Quoted 5 lines
target/arm/kvm.c +1
-1@@ -2369,7 +2369,7 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)assert (code ==BUS_MCEERR_AR || code ==BUS_MCEERR_AO ); -if (acpi_ghes_present () && addr) { +if (acpi_ghes_get_state () && addr) {
double lookup, 1sh here and then in [1],
suggest store state here and pass it as an argument to down the call chain (i.e. to acpi_ghes_memory_errors() and below)
Quoted 3 lines
target/arm/kvm.c +0
-0ram_addr =qemu_ram_addr_from_host (addr);if (ram_addr !=RAM_ADDR_INVALID &&kvm_physical_memory_addr_from_host (c->kvm_state, addr, &paddr)) {
Re: [PATCH 08/11] acpi/generic_event_device: add an APEI error device
In reply to Mauro Carvalho ChehabQuoted 52 lines · On Wed, 22 Jan 2025 16:46:25 +0100 Mauro Carvalho Chehab…
Adds a generic error device to handle generic hardware error events as specified at ACPI 6.5 specification at 18.3.2.7.2:
https://uefi.org/specs/ACPI/6.5/18_Platform_Error_Interfaces.html#event-notification-for-generic-error-sources
using HID PNP0C33.The PNP0C33 device is used to report hardware errors to the guest via ACPI APEI Generic Hardware Error Source (GHES).
Co-authored-by Mauro Carvalho Chehab <[email protected]>Co-authored-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 10 ++++++++++ hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 2 ++ include/hw/acpi/generic_event_device.h | 1 + 5 files changed, 22 insertions(+)hw/acpi/aml-build.c +10
-0@@ -2614,3 +2614,13 @@ Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source)return var; } + +/* ACPI 5.0b: 18.3.2.6.2 Event Notification For Generic Error Sources */ +Aml *aml_error_device (void ) +{ +Aml *dev =aml_device (ACPI_APEI_ERROR_DEVICE ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C33" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +return dev; +}hw/acpi/generic_event_device.c +1
-0@@ -26,6 +26,7 @@ static const uint32_t ged_supported_events[] = {ACPI_GED_PWR_DOWN_EVT ,ACPI_GED_NVDIMM_HOTPLUG_EVT ,ACPI_GED_CPU_HOTPLUG_EVT , + ACPI_GED_ERROR_EVT, };/*
hw/acpi/generic_event_device.c void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev, · line 123
Quoted 7 lines
hw/acpi/generic_event_device.c +4
-0@@ -116,6 +117,11 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,aml_notify (aml_name (ACPI_POWER_BUTTON_DEVICE ), aml_int(0x80)));break ; +case ACPI_GED_ERROR_EVT : +aml_append (if_ctx, +aml_notify (aml_name (ACPI_APEI_ERROR_DEVICE ), +aml_int (0x80 )));
^^^^^
nit: perhaps add a comment with intent and ref to spec wrt above value
Quoted 57 lines
hw/acpi/generic_event_device.c +3
-0+break ;case ACPI_GED_NVDIMM_HOTPLUG_EVT : aml_append(if_ctx, aml_notify(aml_name("\\_SB.NVDR"),@@ -295,6 +301,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) sel =ACPI_GED_MEM_HOTPLUG_EVT ; }else if (ev &ACPI_POWER_DOWN_STATUS ) { sel =ACPI_GED_PWR_DOWN_EVT ; + }else if (ev &ACPI_GENERIC_ERROR ) { + sel =ACPI_GED_ERROR_EVT ; }else if (ev &ACPI_NVDIMM_HOTPLUG_STATUS ) { sel =ACPI_GED_NVDIMM_HOTPLUG_EVT ; }else if (ev &ACPI_CPU_HOTPLUG_STATUS ) {include/hw/acpi/acpi_dev_interface.h +1
-0@@ -13,6 +13,7 @@ typedef enum {ACPI_NVDIMM_HOTPLUG_STATUS =16 ,ACPI_VMGENID_CHANGE_STATUS =32 ,ACPI_POWER_DOWN_STATUS =64 , +ACPI_GENERIC_ERROR =128 , } AcpiEventStatusBits;#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"include/hw/acpi/aml-build.h +2
-0@@ -252,6 +252,7 @@ struct CrsRangeSet {/* Consumer/Producer */ #define AML_SERIAL_BUS_FLAG_CONSUME_ONLY (1 << 1) +#define ACPI_APEI_ERROR_DEVICE "GEDD"/** * init_aml_allocator: * @@ -382,6 +383,7 @@ Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel);Aml *aml_sleep (uint64_t msec);Aml *aml_i2c_serial_bus_device (uint16_t address,const char *resource_source); +Aml *aml_error_device (void );/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)G_GNUC_PRINTF (1 ,2 );include/hw/acpi/generic_event_device.h +1
-0@@ -101,6 +101,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 +#define ACPI_GED_ERROR_EVT 0x10 typedef struct GEDState { MemoryRegion evt;
Re: [PATCH 10/11] qapi/acpi-hest: add an interface to do generic CPER error injection
In reply to Mauro Carvalho ChehabQuoted 13 lines · On Wed, 22 Jan 2025 16:46:27 +0100 Mauro Carvalho Chehab…
Creates a QMP command to be used for generic ACPI APEI hardware error injection (HEST) via GHESv2, and add support for it for ARM guests.
Error injection uses
ACPI_HEST_SRC_ID_QMPsource ID to be platform independent. This is mapped at arch virt bindings, depending on the types supported by QEMU and by the BIOS. So, on ARM, this is supported viaACPI_GHES_NOTIFY_GPIOnotification type.This patch is co-authored:
- original ghes logic to inject a simple ARM record by Shiju Jose;
- generic logic to handle block addresses by Jonathan Cameron;
- generic GHESv2 error inject by Mauro Carvalho Chehab;
Quoted 6 lines
Co-authored-by Jonathan Cameron <[email protected]>Co-authored-by Shiju Jose <[email protected]>Co-authored-by Mauro Carvalho Chehab <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>
QMP is not my area, so just a cursory review
with nits below fixed up
Quoted 228 lines
---
Changes since v9:
- ARM source IDs renamed to reflect SYNC/ASYNC;
- command name changed to better reflect what it does;
- some improvements at JSON documentation;
- add a check for QMP source at the notification logic.Signed-off-by Mauro Carvalho Chehab <[email protected]>--- MAINTAINERS | 7 +++++++ hw/acpi/Kconfig | 5 +++++ hw/acpi/ghes.c | 2 +- hw/acpi/ghes_cper.c | 32 ++++++++++++++++++++++++++++++++ hw/acpi/ghes_cper_stub.c | 19 +++++++++++++++++++ hw/acpi/meson.build | 2 ++ hw/arm/virt-acpi-build.c | 1 + hw/arm/virt.c | 7 +++++++ include/hw/acpi/ghes.h | 1 + include/hw/arm/virt.h | 1 + qapi/acpi-hest.json | 35 +++++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 13 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 hw/acpi/ghes_cper.c create mode 100644 hw/acpi/ghes_cper_stub.c create mode 100644 qapi/acpi-hest.jsonMAINTAINERS +7
-0@@ -2075,6 +2075,13 @@ F: hw/acpi/ghes.c F: include/hw/acpi/ghes.h F: docs/specs/acpi_hest_ghes.rst +ACPI/HEST/GHES/ARM processor CPER +R: Mauro Carvalho Chehab <[email protected]> +S: Maintained +F: hw/arm/ghes_cper.c +F: hw/acpi/ghes_cper_stub.c +F: qapi/acpi-hest.json + ppc4xx L: [email protected] S: Orphanhw/acpi/Kconfig +5
-0@@ -51,6 +51,11 @@ config ACPI_APEI bool depends on ACPI +config GHES_CPER + bool + depends on ACPI_APEI + default y + config ACPI_PCI bool depends on ACPI && PCIhw/acpi/ghes.c +1
-1@@ -547,7 +547,7 @@ void ghes_record_cper_errors(const void *cper, size_t len,/* Write the generic error data entry into guest memory */ cpu_physical_memory_write (cper_addr, cper, len); -notifier_list_notify (&acpi_generic_error_notifiers,NULL ); +notifier_list_notify (&acpi_generic_error_notifiers, &source_id); }int acpi_ghes_memory_errors (uint16_t source_id,uint64_t physical_address)hw/acpi/ghes_cper.c new file +32
-0@@ -0,0 +1,32 @@ +/* +* CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" + +#include "qemu/base64.h" +#include "qemu/error-report.h" +#include "qemu/uuid.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" + +void qmp_inject_ghes_error (const char *qmp_cper,Error **errp) +{ + +uint8_t *cper; +size_t len; + + cper =qbase64_decode (qmp_cper,-1 , &len, errp); +if (!cper) { +error_setg (errp,"missing GHES CPER payload" ); +return ; + } + +ghes_record_cper_errors (cper, len,ACPI_HEST_SRC_ID_QMP , errp); +}hw/acpi/ghes_cper_stub.c new file +19
-0@@ -0,0 +1,19 @@ +/* +* Stub interface for CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" + +void qmp_inject_ghes_error (const char *cper,Error **errp) +{ +error_setg (errp,"GHES QMP error inject is not compiled in" ); +}hw/acpi/meson.build +2
-0@@ -34,4 +34,6 @@ endif system_ss.add(when: 'CONFIG_ACPI', if_false: files('acpi-stub.c', 'aml-build-stub.c', 'ghes-stub.c', 'acpi_interface.c')) system_ss.add(when: 'CONFIG_ACPI_PCI_BRIDGE', if_false: files('pci-bridge-stub.c')) system_ss.add_all(when: 'CONFIG_ACPI', if_true: acpi_ss) +system_ss.add(when: 'CONFIG_GHES_CPER', if_true: files('ghes_cper.c')) +system_ss.add(when: 'CONFIG_GHES_CPER', if_false: files('ghes_cper_stub.c')) system_ss.add(files('acpi-qmp-cmds.c'))hw/arm/virt-acpi-build.c +1
-0@@ -896,6 +896,7 @@ static void acpi_align_size(GArray *blob, unsigned align)static const AcpiNotificationSourceId hest_ghes_notify[] = { {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, + {ACPI_HEST_SRC_ID_QMP ,ACPI_GHES_NOTIFY_GPIO }, };static const AcpiNotificationSourceId hest_ghes_notify_9_2[] = {hw/arm/virt.c +7
-0@@ -1012,6 +1012,13 @@ static void virt_powerdown_req(Notifier *n, void *opaque)static void virt_generic_error_req (Notifier *n,void *opaque) { +uint16_t *source_id = opaque; + +/* Currently, only QMP source ID is async */ +if (*source_id !=ACPI_HEST_SRC_ID_QMP ) { +return ; + } +VirtMachineState *s =container_of (n, VirtMachineState, generic_error_notifier);acpi_send_event (s->acpi_dev,ACPI_GENERIC_ERROR );include/hw/acpi/ghes.h +1
-0@@ -72,6 +72,7 @@ typedef struct AcpiGhesState {*/ enum AcpiGhesSourceID {ACPI_HEST_SRC_ID_SYNC , +ACPI_HEST_SRC_ID_QMP ,/* Use it only for QMP injected errors */ }; typedef struct AcpiNotificationSourceId {include/hw/arm/virt.h +1
-0@@ -33,6 +33,7 @@#include "exec/hwaddr.h" #include "qemu/notify.h" #include "hw/boards.h" +#include "hw/acpi/ghes.h" #include "hw/arm/boot.h" #include "hw/arm/bsa.h" #include "hw/block/flash.h" qapi/acpi-hest.json new file +18
-0@@ -0,0 +1,35 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# == GHESv2 CPER Error Injection +# +# Defined since ACPI Specification 6.1, +# section 18.3.2.8 Generic Hardware Error Source version 2. See: +# +# https://uefi.org/sites/default/files/resources/ACPI_6_1.pdf +## + + +## +# @inject-ghes-error: +# +# Inject an error with additional ACPI 6.1 GHESv2 error information +#
qapi/acpi-hest.json line 28
Quoted 10 lines
qapi/acpi-hest.json new file +10
-0+# @cper: contains a base64 encoded string with raw data for a single +# CPER record with Generic Error Status Block, Generic Error Data +# Entry and generic error data payload, as described at +# https://uefi.org/specs/UEFI/2.10/Apx_N_Common_Platform_Error_Record.html#format +# +# Features: +# +# @unstable: This command is experimental. +# +# Since: 9.2
10.0
qapi/acpi-hest.json line 30
Quoted 2 lines
qapi/acpi-hest.json new file +2
-0+## +{ 'command': 'inject-ghes-error',
s/ghes/ghes-v2/
Quoted 29 lines
qapi/acpi-hest.json new file +5
-0+ 'data': { + 'cper': 'str' + }, + 'features': [ 'unstable' ] +}qapi/meson.build +1
-0@@ -59,6 +59,7 @@ qapi_all_modules = [ if have_system qapi_all_modules += [ 'acpi', + 'acpi-hest', 'audio', 'cryptodev', 'qdev',qapi/qapi-schema.json +1
-0@@ -75,6 +75,7 @@ { 'include': 'misc-target.json' } { 'include': 'audio.json' } { 'include': 'acpi.json' } +{ 'include': 'acpi-hest.json' } { 'include': 'pci.json' } { 'include': 'stats.json' } { 'include': 'virtio.json' }
Re: [PATCH 10/11] qapi/acpi-hest: add an interface to do generic CPER error injection
In reply to Jonathan CameronQuoted 50 lines · On Thu, 23 Jan 2025 11:00:32 +0000 Jonathan Cameron…
Quoted 22 lines · On Wed, 22 Jan 2025 16:46:27 +0100 Mauro Carvalho Chehab…
Creates a QMP command to be used for generic ACPI APEI hardware error injection (HEST) via GHESv2, and add support for it for ARM guests.
Error injection uses
ACPI_HEST_SRC_ID_QMPsource ID to be platform independent. This is mapped at arch virt bindings, depending on the types supported by QEMU and by the BIOS. So, on ARM, this is supported viaACPI_GHES_NOTIFY_GPIOnotification type.This patch is co-authored:
- original ghes logic to inject a simple ARM record by Shiju Jose;
- generic logic to handle block addresses by Jonathan Cameron;
- generic GHESv2 error inject by Mauro Carvalho Chehab;Co-authored-by Jonathan Cameron <[email protected]>Co-authored-by Shiju Jose <[email protected]>Co-authored-by Mauro Carvalho Chehab <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>---
Quoted 7 lines
Changes since v9:
- ARM source IDs renamed to reflect SYNC/ASYNC;
- command name changed to better reflect what it does;
- some improvements at JSON documentation;
- add a check for QMP source at the notification logic.Signed-off-by Mauro Carvalho Chehab <[email protected]>Another bonus.
Few trivial formatting comments, otherwise looks fine to me.
Jonathan
Quoted 12 lines
hw/acpi/ghes.c +1
-1@@ -547,7 +547,7 @@ void ghes_record_cper_errors(const void *cper, size_t len,/* Write the generic error data entry into guest memory */ cpu_physical_memory_write (cper_addr, cper, len); -notifier_list_notify (&acpi_generic_error_notifiers,NULL ); +notifier_list_notify (&acpi_generic_error_notifiers, &source_id); }
Quoted 11 lines
hw/acpi/ghes_cper.c line 4
Quoted 11 lines
hw/acpi/ghes.c +0
-0int acpi_ghes_memory_errors (uint16_t source_id,uint64_t physical_address)hw/acpi/ghes_cper.c new file +4
-0@@ -0,0 +1,32 @@ +/* +* CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD.
2025
Quoted 32 lines
Quoted 7 lines
hw/acpi/ghes_cper.c new file +7
-0+* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" hw/acpi/ghes_cper.c line 21
Quoted 10 lines
hw/acpi/ghes_cper.c new file +10
-0+ +#include "qemu/base64.h" +#include "qemu/error-report.h" +#include "qemu/uuid.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" + +void qmp_inject_ghes_error (const char *qmp_cper,Error **errp) +{ +Odd blank line that can go.
Quoted 13 lines
hw/acpi/ghes_cper.c new file +11
-0+uint8_t *cper; +size_t len; + + cper =qbase64_decode (qmp_cper,-1 , &len, errp); +if (!cper) { +error_setg (errp,"missing GHES CPER payload" ); +return ; + } + +ghes_record_cper_errors (cper, len,ACPI_HEST_SRC_ID_QMP , errp); +}hw/acpi/ghes_cper_stub.c new file +0
-0
Quoted 8 lines
hw/acpi/ghes_cper_stub.c line 4
Quoted 8 lines
index 000000000000..8782e2c02fa8
hw/acpi/ghes_cper_stub.c new file +4
-0@@ -0,0 +1,19 @@ +/* +* Stub interface for CPER payload parser for error injection +* +* Copyright(C) 2024 Huawei LTD.
2025
Quoted 22 lines
hw/acpi/ghes_cper_stub.c line 8
Quoted 4 lines
hw/acpi/ghes_cper_stub.c new file +4
-0+* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +* Trivial but I'd drop these trailing blank lines as they don't add anything other than making people scroll further.
hw/acpi/ghes_cper_stub.c line 14
Quoted 6 lines
hw/acpi/ghes_cper_stub.c new file +6
-0+*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-acpi-hest.h" +#include "hw/acpi/ghes.h" Trivial but doe we need
ghes.h?Quoted 5 lines
hw/acpi/ghes_cper_stub.c new file +5
-0+ +void qmp_inject_ghes_error (const char *cper,Error **errp) +{ +error_setg (errp,"GHES QMP error inject is not compiled in" ); +}
Quoted 16 lines · On Wed, 22 Jan 2025 16:46:17 +0100 Mauro Carvalho Chehab…
Now that the ghes preparation patches were merged, let's add support for error injection.
I'm opting to fold two patch series into one here:
1. https://lore.kernel.org/qemu-devel/[email protected]/
It is the first 5 patches containing changes to the math used to calculate offsets at HEST table and
hardware_errorfirmware file, together with its migration code. Migration tested with both latest QEMU released kernel and upstream, on both directions.There were no changes on this series since last submission, except for a conflict resolution at the migration table, due to upstream changes.
For more details, se the post of my previous submission.
Quoted 8 lines
2. It follows 6 patches from:
https://lore.kernel.org/qemu-devel/[email protected]/ containing the error injection code and script.They add a new QAPI to allow injecting GHESv2 errors, and a script using such QAPI to inject ARM Processor Error records.
PS.: If I'm counting well, this is the 18th version of this series rebase.
the series is more or less in good shape,
it requires a few fixups here and there, so I'd expect to to be ready on the next respin.
I'm done with this round of review.
PS:
the moment you'd start changing ACPI tables you need, 1st whitelist affected tables and then update expected blobs with new content. see comment at the beginning of tests/qtest/bios-tables-test.c
if you haven't done above 'make check-qtest' would fail, and if it didn't that likely means a missing test case (in that case please add one)
Quoted 47 lines
Mauro Carvalho Chehab (11):
acpi/ghes: Prepare to support multiple sources on ghes acpi/ghes: add a firmware file with HEST address acpi/ghes: Use HEST table offsets when preparing GHES records acpi/generic_event_device: Update GHES migration to cover hest addr acpi/generic_event_device: add logic to detect if HEST addr is
available
acpi/ghes: add a notifier to notify when error data is ready acpi/ghes: Cleanup the code which gets ghes ged state acpi/generic_event_device: add an APEI error device arm/virt: Wire up a GED error device for ACPI / GHES qapi/acpi-hest: add an interface to do generic CPER error injectionscripts/ghes_inject: add a script to generate GHES error injectMAINTAINERS | 10 + hw/acpi/Kconfig | 5 + hw/acpi/aml-build.c | 10 + hw/acpi/generic_event_device.c | 38 ++ hw/acpi/ghes-stub.c | 4 +- hw/acpi/ghes.c | 184 +++++-- hw/acpi/ghes_cper.c | 32 ++ hw/acpi/ghes_cper_stub.c | 19 + hw/acpi/meson.build | 2 + hw/arm/virt-acpi-build.c | 35 +- hw/arm/virt.c | 19 +- hw/core/machine.c | 2 + include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 2 + include/hw/acpi/generic_event_device.h | 1 + include/hw/acpi/ghes.h | 36 +- include/hw/arm/virt.h | 2 + qapi/acpi-hest.json | 35 ++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + scripts/arm_processor_error.py | 377 +++++++++++++ scripts/ghes_inject.py | 51 ++ scripts/qmp_helper.py | 702 +++++++++++++++++++++++++ target/arm/kvm.c | 2 +- 24 files changed, 1517 insertions(+), 54 deletions(-) create mode 100644 hw/acpi/ghes_cper.c create mode 100644 hw/acpi/ghes_cper_stub.c create mode 100644 qapi/acpi-hest.json create mode 100644 scripts/arm_processor_error.py create mode 100755 scripts/ghes_inject.py create mode 100644 scripts/qmp_helper.py
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Jonathan CameronEm Thu, 23 Jan 2025 10:02:17 +0000
Jonathan Cameron <[email protected]> escreveu:
Quoted 40 lines
Quoted 6 lines · On Wed, 22 Jan 2025 16:46:19 +0100 Mauro Carvalho Chehab…
Store HEST table address at GPA, placing its content at
hest_addr_levariable.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>A few trivial things inline.
Jonathan
Quoted 6 lines
---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.Signed-off-by Mauro Carvalho Chehab <[email protected]>Bonus. I guess you really like this patch :)
Quoted 20 lines
--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)hw/acpi/ghes.c +1
-0@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }
Quoted 6 lines
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, · line 265
Quoted 3 lines
hw/acpi/ghes.c +1
-1/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into Sneaky tidy up. No problem with it in general but adding noise here, so if there are others in the series maybe gather them up in a cleanup patch.
There are no other cleanups pending. Besides, as you noticed, this aligns with the comment below. So, I'm opting to add a note at the patch's description.
Quoted 6 lines
Quoted 6 lines
hw/acpi/ghes.c +0
-0* hardware_errors_addr fw_cfg, once the former has been initialized. */ bios_linker_loader_write_pointer(linker, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, 0,@@ -355,6 +356,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,
Quoted 6 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 359
Quoted 3 lines
hw/acpi/ghes.c +1
-0acpi_table_begin (&table, table_data); +int hest_offset = table_data->len;Local style looks to be traditional C with definitions at top. Maybe define
hest_offsetup a few lines and just set it here?
Ok. I'll follow Igor's suggestion of using uint32_t.
Quoted 7 lines
Quoted 7 lines
hw/acpi/ghes.c +1
-0+/* Error Source Count */ build_append_int_noprefix (table_data, num_sources,4 );for (i =0 ; i < num_sources; i++) {@@ -362,6 +365,15 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, }
Quoted 7 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 370
Quoted 4 lines
hw/acpi/ghes.c +3
-0acpi_table_end (linker, &table); + +/* +* tell firmware to write into GPA the address of HEST via fw_cfg, Given the tidy up above, fix this one to have a capital T, or was this where you meant to change it?
OK.
Quoted 6 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 374
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* once initialized. +*/ + bios_linker_loader_write_pointer(linker, + ACPI_HEST_ADDR_FW_CFG_FILE, 0,Could wrap less and stay under 80 chars as both lines above add up to 70 something
Why? This follows QEMU coding style and lines aren't longer than 80 columns. Besides, at least for my eyes and some experience doing maintainership on other projects over the years, it is a lot quicker to identify function parameters if they're properly aligned with the parenthesis.
Thanks,
Mauro
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Igor MammedovEm Thu, 23 Jan 2025 18:01:35 +0100
Igor Mammedov <[email protected]> escreveu:
Quoted 43 lines
Quoted 40 lines · On Thu, 23 Jan 2025 10:02:17 +0000 Jonathan Cameron…
Quoted 6 lines · On Wed, 22 Jan 2025 16:46:19 +0100 Mauro Carvalho Chehab…
Store HEST table address at GPA, placing its content at
hest_addr_levariable.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>A few trivial things inline.
Jonathan
Quoted 6 lines
---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.Signed-off-by Mauro Carvalho Chehab <[email protected]>Bonus. I guess you really like this patch :)
Quoted 20 lines
--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)hw/acpi/ghes.c +1
-0@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }
Quoted 8 lines
Quoted 6 lines
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, · line 265
Quoted 3 lines
hw/acpi/ghes.c +1
-1/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into Sneaky tidy up. No problem with it in general but adding noise here, so if there are others in the series maybe gather them up in a cleanup patch.
+1
If Ok, I would prefer to keep this here, as there's no other cleanups anymore, and writing a patch just for this seems overkill. Besides, it replicates a comment with a similar content on this patch.
So, instead, if OK to you, I would prefer to add a comment about it at the patch description.
Quoted 11 lines
Quoted 9 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 359
Quoted 9 lines
hw/acpi/ghes.c +1
-0* hardware_errors_addr fw_cfg, once the former has been initialized. */ bios_linker_loader_write_pointer(linker, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, 0,@@ -355,6 +356,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,acpi_table_begin (&table, table_data); +int hest_offset = table_data->len;should be unsigned, and better
uint32_t
but we have a zoo wrt type here all over the place.
Changed this one to uint32_t.
Quoted 4 lines
Quoted 2 lines
Local style looks to be traditional C with definitions at top. Maybe define
hest_offsetup a few lines and just set it here?yep, it applies to whole QEMU (i.e. definitions only at the start of the block)
Good to know. That's my personal style too. Yet, I guess I saw somewhere other places declaring variables in the middle of the code.
Quoted 20 lines
Quoted 20 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 370
Quoted 11 lines
hw/acpi/ghes.c +4
-0+/* Error Source Count */ build_append_int_noprefix (table_data, num_sources,4 );for (i =0 ; i < num_sources; i++) {@@ -362,6 +365,15 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, }acpi_table_end (linker, &table); + +/* +* tell firmware to write into GPA the address of HEST via fw_cfg, Given the tidy up above, fix this one to have a capital T, or was this where you meant to change it?
Quoted 4 lines
hw/acpi/ghes.c +4
-0+* once initialized. +*/ + bios_linker_loader_write_pointer(linker, + ACPI_HEST_ADDR_FW_CFG_FILE, 0,
Quoted 7 lines
Quoted 6 lines
Could wrap less and stay under 80 chars as both lines above add up to 70 something
Quoted 3 lines
hw/acpi/ghes.c +2
-0+sizeof (uint64_t ), + ACPI_BUILD_TABLE_FILE, hest_offset); }
Thanks,
Mauro
Re: [PATCH 05/11] acpi/generic_event_device: add logic to detect if HEST addr is available
In reply to Igor MammedovEm Fri, 24 Jan 2025 11:23:46 +0100
Igor Mammedov <[email protected]> escreveu:
Quoted 47 lines
Quoted 3 lines · On Wed, 22 Jan 2025 16:46:22 +0100 Mauro Carvalho Chehab…
Create a new property (x-has-hest-addr) and use it to detect if the GHES table offsets can be calculated from the HEST address (qemu 9.2 and upper) or via the legacy way via an offset obtained
10.0 by now
Quoted 16 lines
from the
hardware_errorsfirmware file.Signed-off-by Mauro Carvalho Chehab <[email protected]>--- hw/acpi/generic_event_device.c | 1 + hw/acpi/ghes.c | 28 +++++++++++++++++++++------- hw/arm/virt-acpi-build.c | 30 ++++++++++++++++++++++++++---- hw/core/machine.c | 2 ++ include/hw/acpi/ghes.h | 1 + 5 files changed, 51 insertions(+), 11 deletions(-)hw/acpi/generic_event_device.c +0
-0hw/acpi/generic_event_device.c static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) · line 321
Quoted 4 lines
hw/acpi/generic_event_device.c +1
-0@@ -318,6 +318,7 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)static const Property acpi_ged_properties[] = {DEFINE_PROP_UINT32 ("ged-event" , AcpiGedState, ged_event_bitmap,0 ), +DEFINE_PROP_BOOL ("x-has-hest-addr" , AcpiGedState, ghes_state.hest_lookup, true),s/hest_lookup/use_hest_addr/
Quoted 15 lines
hw/acpi/generic_event_device.c +0
-0};static const VMStateDescription vmstate_memhp_state = {hw/acpi/ghes.c +2
-0@@ -359,6 +359,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, {AcpiTable table = { .sig ="HEST" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id }; +AcpiGedState *acpi_ged_state; +AcpiGhesState *ags =NULL ;int i;
Quoted 15 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 386
Quoted 12 lines
hw/acpi/ghes.c +3
-4build_ghes_error_table (hardware_errors, linker, num_sources);@@ -379,10 +381,20 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,* tell firmware to write into GPA the address of HEST via fw_cfg, * once initialized. */ -bios_linker_loader_write_pointer (linker, -ACPI_HEST_ADDR_FW_CFG_FILE ,0 , -sizeof (uint64_t ), -ACPI_BUILD_TABLE_FILE , hest_offset); + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL ));the caller, already did lookup,
just passhest_lookupas an argument and use it here
for all the above: OK.
Quoted 13 lines
Quoted 13 lines
hw/acpi/ghes.c +11
-0+if (!acpi_ged_state) { +return ; + } + + ags = &acpi_ged_state->ghes_state; +if (ags->hest_lookup) { +bios_linker_loader_write_pointer (linker, +ACPI_HEST_ADDR_FW_CFG_FILE ,0 , +sizeof (uint64_t ), +ACPI_BUILD_TABLE_FILE , hest_offset); + } }
Quoted 6 lines
hw/acpi/ghes.c void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s, · line 409
Quoted 4 lines
hw/acpi/ghes.c +0
-0void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,@@ -396,8 +408,10 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,fw_cfg_add_file_callback (s,ACPI_HW_ERROR_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->hw_error_le),sizeof (ags->hw_error_le), false);btw shouldn't we disable
hw_error_leifhest_lookupis active?
Despite not being used, we still need the fw_cfg logic to recalculate the table offsets, solving the bios_linker stuff.
At the tests I did, not having a callback causes some fw_cfg issue when QEMU tries to load the firmware or tries to update it.
Quoted 6 lines
hw/acpi/ghes.c void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s, · line 411
Quoted 4 lines
hw/acpi/ghes.c +1
-2-fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , -NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); +if (ags && ags->hest_lookup) {why bother with 'ags &&' if we don't do it
hw_error_le?
Legacy stuff. I'll drop "ags &&".
Quoted 12 lines
Quoted 12 lines
hw/acpi/ghes.c +3
-0+fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , +NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); + } ags->present = true; }@@ -512,7 +526,7 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state;
Quoted 3 lines
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 529
Quoted 2 lines
hw/acpi/ghes.c +1
-1-if (!ags->hest_addr_le) { +if (!ags->hest_lookup) {why? !ags->hest_addr_le is sufficient
Either checking for "hest_addr_le" or for "use_hest_addr" would equally work, assuming that address == 0 is invalid. I opted to use the latest one because you requested on a previous review, and also because it makes clearer that this comes from the migration logic, which dictates what kind of lookup should be done.
From my side, either way works fine. What do you prefer?
Quoted 79 lines
Quoted 74 lines
hw/acpi/ghes.c +0
-0get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), &cper_addr, &read_ack_register_addr); }else {hw/arm/virt-acpi-build.c +26
-4@@ -897,6 +897,10 @@ static const AcpiNotificationSourceId hest_ghes_notify[] = { { ACPI_HEST_SRC_ID_SYNC, ACPI_GHES_NOTIFY_SEA }, }; +static const AcpiNotificationSourceId hest_ghes_notify_9_2[] = { + {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, +}; +static void virt_acpi_build (VirtMachineState *vms,AcpiBuildTables *tables) {@@ -950,10 +954,28 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_dbg2 (tables_blob, tables->linker, vms);if (vms->ras) { -acpi_add_table (table_offsets, tables_blob); -acpi_build_hest (tables_blob, tables->hardware_errors, tables->linker, - hest_ghes_notify,ARRAY_SIZE (hest_ghes_notify), - vms->oem_id, vms->oem_table_id); +AcpiGhesState *ags; +AcpiGedState *acpi_ged_state; + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); +if (acpi_ged_state) { + ags = &acpi_ged_state->ghes_state; + +acpi_add_table (table_offsets, tables_blob); + +if (!ags->hest_lookup) { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify_9_2, +ARRAY_SIZE (hest_ghes_notify_9_2), + vms->oem_id, vms->oem_table_id); + }else { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify, +ARRAY_SIZE (hest_ghes_notify), + vms->oem_id, vms->oem_table_id); + } + } }if (ms->numa_state->num_nodes >0 ) {hw/core/machine.c +2
-0@@ -34,10 +34,12 @@#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/acpi/generic_event_device.h" #include "audio/audio.h" GlobalProperty hw_compat_9_2[] = { {"arm-cpu" ,"backcompat-pauth-default-use-qarma5" ,"true" }, + {TYPE_ACPI_GED ,"x-has-hest-addr" ,"false" }, };const size_t hw_compat_9_2_len =G_N_ELEMENTS (hw_compat_9_2);include/hw/acpi/ghes.h +0
-0include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 63
Quoted 3 lines
include/hw/acpi/ghes.h +0
-0@@ -61,6 +61,7 @@ typedef struct AcpiGhesState {uint64_t hest_addr_le;uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ and perhaps reformulate this as well
Quoted 7 lines
include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 64
Quoted 1 line
include/hw/acpi/ghes.h +1
-0+bool hest_lookup;/* True if HEST address is present */ if device should use HEST addr for error source lookup
Quoted 3 lines
include/hw/acpi/ghes.h +0
-0} AcpiGhesState;/*
Thanks,
Mauro
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Mauro Carvalho ChehabQuoted 50 lines · On Tue, 28 Jan 2025 11:00:34 +0100 Mauro Carvalho Chehab…
Em Thu, 23 Jan 2025 10:02:17 +0000
Jonathan Cameron <[email protected]> escreveu:Quoted 40 lines
Quoted 6 lines · On Wed, 22 Jan 2025 16:46:19 +0100 Mauro Carvalho Chehab…
Store HEST table address at GPA, placing its content at
hest_addr_levariable.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>A few trivial things inline.
Jonathan
Quoted 6 lines
---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.Signed-off-by Mauro Carvalho Chehab <[email protected]>Bonus. I guess you really like this patch :)
Quoted 20 lines
--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)hw/acpi/ghes.c +1
-0@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }Quoted 6 lines
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, · line 265
Quoted 3 lines
hw/acpi/ghes.c +1
-1/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into Sneaky tidy up. No problem with it in general but adding noise here, so if there are others in the series maybe gather them up in a cleanup patch.
Quoted 3 lines
There are no other cleanups pending. Besides, as you noticed, this aligns with the comment below. So, I'm opting to add a note at the patch's description.
ok.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
hw/acpi/ghes.c +4
-0+* once initialized. +*/ + bios_linker_loader_write_pointer(linker, + ACPI_HEST_ADDR_FW_CFG_FILE, 0,
Quoted 6 lines
Quoted 1 line
Could wrap less and stay under 80 chars as both lines above add up to 70 something
Why? This follows QEMU coding style and lines aren't longer than 80 columns. Besides, at least for my eyes and some experience doing maintainership on other projects over the years, it is a lot quicker to identify function parameters if they're properly aligned with the parenthesis.
Ah. I didn't state this clearly enough.
bios_linker_loader_write_pointer(linker, ACPI_HEST_ADDR_FW_CFG_FILE, 0,
is also under 80 chars.
Quoted 3 lines
Thanks,
Mauro
Re: [PATCH 08/11] acpi/generic_event_device: add an APEI error device
In reply to Igor MammedovEm Fri, 24 Jan 2025 13:30:54 +0100
Igor Mammedov <[email protected]> escreveu:
Quoted 63 lines
Quoted 52 lines · On Wed, 22 Jan 2025 16:46:25 +0100 Mauro Carvalho Chehab…
Adds a generic error device to handle generic hardware error events as specified at ACPI 6.5 specification at 18.3.2.7.2:
https://uefi.org/specs/ACPI/6.5/18_Platform_Error_Interfaces.html#event-notification-for-generic-error-sources
using HID PNP0C33.The PNP0C33 device is used to report hardware errors to the guest via ACPI APEI Generic Hardware Error Source (GHES).
Co-authored-by Mauro Carvalho Chehab <[email protected]>Co-authored-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 10 ++++++++++ hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 2 ++ include/hw/acpi/generic_event_device.h | 1 + 5 files changed, 22 insertions(+)hw/acpi/aml-build.c +10
-0@@ -2614,3 +2614,13 @@ Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source)return var; } + +/* ACPI 5.0b: 18.3.2.6.2 Event Notification For Generic Error Sources */ +Aml *aml_error_device (void ) +{ +Aml *dev =aml_device (ACPI_APEI_ERROR_DEVICE ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C33" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +return dev; +}hw/acpi/generic_event_device.c +1
-0@@ -26,6 +26,7 @@ static const uint32_t ged_supported_events[] = {ACPI_GED_PWR_DOWN_EVT ,ACPI_GED_NVDIMM_HOTPLUG_EVT ,ACPI_GED_CPU_HOTPLUG_EVT , + ACPI_GED_ERROR_EVT, };/* hw/acpi/generic_event_device.c void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev, · line 123
Quoted 7 lines
hw/acpi/generic_event_device.c +4
-0@@ -116,6 +117,11 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,aml_notify (aml_name (ACPI_POWER_BUTTON_DEVICE ), aml_int(0x80)));break ; +case ACPI_GED_ERROR_EVT : +aml_append (if_ctx, +aml_notify (aml_name (ACPI_APEI_ERROR_DEVICE ), +aml_int (0x80 )));^^^^^
Quoted 1 line
nit: perhaps add a comment with intent and ref to spec wrt above value
Will add this as with a define:
/* * ACPI 5.0b: 5.6.6 Device Object Notifications * Table 5-135 Error Device Notification Values */ #define ERROR_DEVICE_NOTIFICATION 0x80
(the spec here is the same as we used on this patch for aml_error_device() function)
Quoted 56 lines
Quoted 56 lines
hw/acpi/generic_event_device.c +3
-0+break ;case ACPI_GED_NVDIMM_HOTPLUG_EVT : aml_append(if_ctx, aml_notify(aml_name("\\_SB.NVDR"),@@ -295,6 +301,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) sel =ACPI_GED_MEM_HOTPLUG_EVT ; }else if (ev &ACPI_POWER_DOWN_STATUS ) { sel =ACPI_GED_PWR_DOWN_EVT ; + }else if (ev &ACPI_GENERIC_ERROR ) { + sel =ACPI_GED_ERROR_EVT ; }else if (ev &ACPI_NVDIMM_HOTPLUG_STATUS ) { sel =ACPI_GED_NVDIMM_HOTPLUG_EVT ; }else if (ev &ACPI_CPU_HOTPLUG_STATUS ) {include/hw/acpi/acpi_dev_interface.h +1
-0@@ -13,6 +13,7 @@ typedef enum {ACPI_NVDIMM_HOTPLUG_STATUS =16 ,ACPI_VMGENID_CHANGE_STATUS =32 ,ACPI_POWER_DOWN_STATUS =64 , +ACPI_GENERIC_ERROR =128 , } AcpiEventStatusBits;#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"include/hw/acpi/aml-build.h +2
-0@@ -252,6 +252,7 @@ struct CrsRangeSet {/* Consumer/Producer */ #define AML_SERIAL_BUS_FLAG_CONSUME_ONLY (1 << 1) +#define ACPI_APEI_ERROR_DEVICE "GEDD"/** * init_aml_allocator: * @@ -382,6 +383,7 @@ Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel);Aml *aml_sleep (uint64_t msec);Aml *aml_i2c_serial_bus_device (uint16_t address,const char *resource_source); +Aml *aml_error_device (void );/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)G_GNUC_PRINTF (1 ,2 );include/hw/acpi/generic_event_device.h +1
-0@@ -101,6 +101,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 +#define ACPI_GED_ERROR_EVT 0x10
Quoted 3 lines
include/hw/acpi/generic_event_device.h OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED) · line 107
Quoted 2 lines
include/hw/acpi/generic_event_device.h +0
-0typedef struct GEDState { MemoryRegion evt;
Thanks,
Mauro
Re: [PATCH 08/11] acpi/generic_event_device: add an APEI error device
Quoted 70 lines · Mauro Carvalho Chehab
Em Fri, 24 Jan 2025 13:30:54 +0100
Igor Mammedov <[email protected]> escreveu:Quoted 63 lines
Quoted 52 lines · On Wed, 22 Jan 2025 16:46:25 +0100 Mauro Carvalho Chehab…
Adds a generic error device to handle generic hardware error events as specified at ACPI 6.5 specification at 18.3.2.7.2:
https://uefi.org/specs/ACPI/6.5/18_Platform_Error_Interfaces.html#event-notification-for-generic-error-sources
using HID PNP0C33.The PNP0C33 device is used to report hardware errors to the guest via ACPI APEI Generic Hardware Error Source (GHES).
Co-authored-by Mauro Carvalho Chehab <[email protected]>Co-authored-by Jonathan Cameron <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Igor Mammedov <[email protected]>--- hw/acpi/aml-build.c | 10 ++++++++++ hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/acpi_dev_interface.h | 1 + include/hw/acpi/aml-build.h | 2 ++ include/hw/acpi/generic_event_device.h | 1 + 5 files changed, 22 insertions(+)hw/acpi/aml-build.c +10
-0@@ -2614,3 +2614,13 @@ Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source)return var; } + +/* ACPI 5.0b: 18.3.2.6.2 Event Notification For Generic Error Sources */ +Aml *aml_error_device (void ) +{ +Aml *dev =aml_device (ACPI_APEI_ERROR_DEVICE ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C33" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +return dev; +}hw/acpi/generic_event_device.c +1
-0@@ -26,6 +26,7 @@ static const uint32_t ged_supported_events[] = {ACPI_GED_PWR_DOWN_EVT ,ACPI_GED_NVDIMM_HOTPLUG_EVT ,ACPI_GED_CPU_HOTPLUG_EVT , + ACPI_GED_ERROR_EVT, };/* hw/acpi/generic_event_device.c void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev, · line 123
Quoted 7 lines
hw/acpi/generic_event_device.c +4
-0@@ -116,6 +117,11 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,aml_notify (aml_name (ACPI_POWER_BUTTON_DEVICE ), aml_int(0x80)));break ; +case ACPI_GED_ERROR_EVT : +aml_append (if_ctx, +aml_notify (aml_name (ACPI_APEI_ERROR_DEVICE ), +aml_int (0x80 )));^^^^^Quoted 1 line
nit: perhaps add a comment with intent and ref to spec wrt above value
Will add this as with a define:
Quoted 8 lines
/* * ACPI 5.0b: 5.6.6 Device Object Notifications * Table 5-135 Error Device Notification Values */ #define ERROR_DEVICE_NOTIFICATION 0x80(the spec here is the same as we used on this patch for
aml_error_device()function)
we do not do a lot of defines definetely not for 1 time used constants.
just comment on top of the value.
Quoted 64 lines
Quoted 56 lines
Quoted 56 lines
hw/acpi/generic_event_device.c +3
-0+break ;case ACPI_GED_NVDIMM_HOTPLUG_EVT : aml_append(if_ctx, aml_notify(aml_name("\\_SB.NVDR"),@@ -295,6 +301,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) sel =ACPI_GED_MEM_HOTPLUG_EVT ; }else if (ev &ACPI_POWER_DOWN_STATUS ) { sel =ACPI_GED_PWR_DOWN_EVT ; + }else if (ev &ACPI_GENERIC_ERROR ) { + sel =ACPI_GED_ERROR_EVT ; }else if (ev &ACPI_NVDIMM_HOTPLUG_STATUS ) { sel =ACPI_GED_NVDIMM_HOTPLUG_EVT ; }else if (ev &ACPI_CPU_HOTPLUG_STATUS ) {include/hw/acpi/acpi_dev_interface.h +1
-0@@ -13,6 +13,7 @@ typedef enum {ACPI_NVDIMM_HOTPLUG_STATUS =16 ,ACPI_VMGENID_CHANGE_STATUS =32 ,ACPI_POWER_DOWN_STATUS =64 , +ACPI_GENERIC_ERROR =128 , } AcpiEventStatusBits;#define TYPE_ACPI_DEVICE_IF "acpi-device-interface"include/hw/acpi/aml-build.h +2
-0@@ -252,6 +252,7 @@ struct CrsRangeSet {/* Consumer/Producer */ #define AML_SERIAL_BUS_FLAG_CONSUME_ONLY (1 << 1) +#define ACPI_APEI_ERROR_DEVICE "GEDD"/** * init_aml_allocator: * @@ -382,6 +383,7 @@ Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel);Aml *aml_sleep (uint64_t msec);Aml *aml_i2c_serial_bus_device (uint16_t address,const char *resource_source); +Aml *aml_error_device (void );/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)G_GNUC_PRINTF (1 ,2 );include/hw/acpi/generic_event_device.h +1
-0@@ -101,6 +101,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 +#define ACPI_GED_ERROR_EVT 0x10Quoted 3 lines
include/hw/acpi/generic_event_device.h OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED) · line 107
Quoted 2 lines
include/hw/acpi/generic_event_device.h +0
-0typedef struct GEDState { MemoryRegion evt;Thanks,
Mauro
Re: [PATCH 05/11] acpi/generic_event_device: add logic to detect if HEST addr is available
In reply to Mauro Carvalho ChehabEm Tue, 28 Jan 2025 12:29:51 +0100
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 119 lines
Em Fri, 24 Jan 2025 11:23:46 +0100
Igor Mammedov <[email protected]> escreveu:Quoted 47 lines
Quoted 3 lines · On Wed, 22 Jan 2025 16:46:22 +0100 Mauro Carvalho Chehab…
Create a new property (x-has-hest-addr) and use it to detect if the GHES table offsets can be calculated from the HEST address (qemu 9.2 and upper) or via the legacy way via an offset obtained
10.0 by now
Quoted 16 lines
from the
hardware_errorsfirmware file.Signed-off-by Mauro Carvalho Chehab <[email protected]>--- hw/acpi/generic_event_device.c | 1 + hw/acpi/ghes.c | 28 +++++++++++++++++++++------- hw/arm/virt-acpi-build.c | 30 ++++++++++++++++++++++++++---- hw/core/machine.c | 2 ++ include/hw/acpi/ghes.h | 1 + 5 files changed, 51 insertions(+), 11 deletions(-)hw/acpi/generic_event_device.c +0
-0hw/acpi/generic_event_device.c static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) · line 321
Quoted 4 lines
hw/acpi/generic_event_device.c +1
-0@@ -318,6 +318,7 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)static const Property acpi_ged_properties[] = {DEFINE_PROP_UINT32 ("ged-event" , AcpiGedState, ged_event_bitmap,0 ), +DEFINE_PROP_BOOL ("x-has-hest-addr" , AcpiGedState, ghes_state.hest_lookup, true),s/hest_lookup/use_hest_addr/
Quoted 15 lines
hw/acpi/generic_event_device.c +0
-0};static const VMStateDescription vmstate_memhp_state = {hw/acpi/ghes.c +2
-0@@ -359,6 +359,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, {AcpiTable table = { .sig ="HEST" , .rev =1 , .oem_id = oem_id, .oem_table_id = oem_table_id }; +AcpiGedState *acpi_ged_state; +AcpiGhesState *ags =NULL ;int i;Quoted 15 lines
hw/acpi/ghes.c void acpi_build_hest(GArray *table_data, GArray *hardware_errors, · line 386
Quoted 12 lines
hw/acpi/ghes.c +3
-4build_ghes_error_table (hardware_errors, linker, num_sources);@@ -379,10 +381,20 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,* tell firmware to write into GPA the address of HEST via fw_cfg, * once initialized. */ -bios_linker_loader_write_pointer (linker, -ACPI_HEST_ADDR_FW_CFG_FILE ,0 , -sizeof (uint64_t ), -ACPI_BUILD_TABLE_FILE , hest_offset); + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL ));the caller, already did lookup,
just passhest_lookupas an argument and use it herefor all the above: OK.
Quoted 13 lines
Quoted 13 lines
hw/acpi/ghes.c +11
-0+if (!acpi_ged_state) { +return ; + } + + ags = &acpi_ged_state->ghes_state; +if (ags->hest_lookup) { +bios_linker_loader_write_pointer (linker, +ACPI_HEST_ADDR_FW_CFG_FILE ,0 , +sizeof (uint64_t ), +ACPI_BUILD_TABLE_FILE , hest_offset); + } }Quoted 6 lines
hw/acpi/ghes.c void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s, · line 409
Quoted 4 lines
hw/acpi/ghes.c +0
-0void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,@@ -396,8 +408,10 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,fw_cfg_add_file_callback (s,ACPI_HW_ERROR_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->hw_error_le),sizeof (ags->hw_error_le), false);btw shouldn't we disable
hw_error_leifhest_lookupis active?Despite not being used, we still need the
fw_cfglogic to recalculate the table offsets, solving thebios_linkerstuff.At the tests I did, not having a callback causes some
fw_cfgissue when QEMU tries to load the firmware or tries to update it.Quoted 6 lines
hw/acpi/ghes.c void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s, · line 411
Quoted 4 lines
hw/acpi/ghes.c +1
-2-fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , -NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); +if (ags && ags->hest_lookup) {why bother with 'ags &&' if we don't do it
hw_error_le?Legacy stuff. I'll drop "ags &&".
Quoted 12 lines
Quoted 12 lines
hw/acpi/ghes.c +3
-0+fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , +NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); + } ags->present = true; }@@ -512,7 +526,7 @@ void ghes_record_cper_errors(const void *cper, size_t len, } ags = &acpi_ged_state->ghes_state;Quoted 3 lines
hw/acpi/ghes.c void ghes_record_cper_errors(const void *cper, size_t len, · line 529
Quoted 2 lines
hw/acpi/ghes.c +1
-1-if (!ags->hest_addr_le) { +if (!ags->hest_lookup) {why? !ags->hest_addr_le is sufficient
Quoted 7 lines
Either checking for "
hest_addr_le" or for "use_hest_addr" would equally work, assuming that address == 0 is invalid. I opted to use the latest one because you requested on a previous review, and also because it makes clearer that this comes from the migration logic, which dictates what kind of lookup should be done.From my side, either way works fine. What do you prefer?
After sleeping on it, IMO checking for !ags->hest_addr_le is better here and will align with the new code from this patch:
acpi/ghes: Cleanup the code which gets ghes ged state
that will remove ags->present in favor of checking for both hw_error_le and hest_addr_le:
AcpiGhesState *acpi_ghes_get_state(void)
{
AcpiGedState *acpi_ged_state;
AcpiGhesState *ags;
if (!acpi_ged_state) {
return NULL;
}
ags = &acpi_ged_state->ghes_state;
if (!ags->hw_error_le && !ags->hest_addr_le) {
return NULL;
}
return ags;
}So, I'll drop this hunk.
Quoted 85 lines
Quoted 85 lines
Quoted 75 lines
hw/acpi/ghes.c +0
-0get_hw_error_offsets (le64_to_cpu (ags->hw_error_le), &cper_addr, &read_ack_register_addr); }else {hw/arm/virt-acpi-build.c +26
-4@@ -897,6 +897,10 @@ static const AcpiNotificationSourceId hest_ghes_notify[] = { { ACPI_HEST_SRC_ID_SYNC, ACPI_GHES_NOTIFY_SEA }, }; +static const AcpiNotificationSourceId hest_ghes_notify_9_2[] = { + {ACPI_HEST_SRC_ID_SYNC ,ACPI_GHES_NOTIFY_SEA }, +}; +static void virt_acpi_build (VirtMachineState *vms,AcpiBuildTables *tables) {@@ -950,10 +954,28 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_dbg2 (tables_blob, tables->linker, vms);if (vms->ras) { -acpi_add_table (table_offsets, tables_blob); -acpi_build_hest (tables_blob, tables->hardware_errors, tables->linker, - hest_ghes_notify,ARRAY_SIZE (hest_ghes_notify), - vms->oem_id, vms->oem_table_id); +AcpiGhesState *ags; +AcpiGedState *acpi_ged_state; + + acpi_ged_state =ACPI_GED (object_resolve_path_type ("" ,TYPE_ACPI_GED , +NULL )); +if (acpi_ged_state) { + ags = &acpi_ged_state->ghes_state; + +acpi_add_table (table_offsets, tables_blob); + +if (!ags->hest_lookup) { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify_9_2, +ARRAY_SIZE (hest_ghes_notify_9_2), + vms->oem_id, vms->oem_table_id); + }else { +acpi_build_hest (tables_blob, tables->hardware_errors, + tables->linker, hest_ghes_notify, +ARRAY_SIZE (hest_ghes_notify), + vms->oem_id, vms->oem_table_id); + } + } }if (ms->numa_state->num_nodes >0 ) {hw/core/machine.c +2
-0@@ -34,10 +34,12 @@#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-iommu.h" +#include "hw/acpi/generic_event_device.h" #include "audio/audio.h" GlobalProperty hw_compat_9_2[] = { {"arm-cpu" ,"backcompat-pauth-default-use-qarma5" ,"true" }, + {TYPE_ACPI_GED ,"x-has-hest-addr" ,"false" }, };const size_t hw_compat_9_2_len =G_N_ELEMENTS (hw_compat_9_2);include/hw/acpi/ghes.h +0
-0include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 63
Quoted 3 lines
include/hw/acpi/ghes.h +0
-0@@ -61,6 +61,7 @@ typedef struct AcpiGhesState {uint64_t hest_addr_le;uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ and perhaps reformulate this as well
include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 64
Quoted 1 line
include/hw/acpi/ghes.h +1
-0+bool hest_lookup;/* True if HEST address is present */ if device should use HEST addr for error source lookup
Quoted 2 lines
include/hw/acpi/ghes.h +0
-0} AcpiGhesState;
Quoted 7 lines
Quoted 2 lines
include/hw/acpi/ghes.h typedef struct AcpiGhesState { · line 67
Quoted 1 line
include/hw/acpi/ghes.h +0
-0/* Thanks,
Mauro
Thanks,
Mauro
Re: [PATCH 02/11] acpi/ghes: add a firmware file with HEST address
In reply to Mauro Carvalho ChehabQuoted 10 lines · On Wed, 22 Jan 2025 16:46:19 +0100 Mauro Carvalho Chehab…
Store HEST table address at GPA, placing its content at
hest_addr_levariable.Signed-off-by Mauro Carvalho Chehab <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>---
Change from v8:
-hest_addr_lris now pointing to the error source size and data.
that's confusing, variable name say it's HEST table address, while in practice it's (that + offset).
I'd very much prefer it being table start and then you'd add offset later on where it's going to be used.
Quoted 20 lines
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- hw/acpi/ghes.c | 17 ++++++++++++++++- include/hw/acpi/ghes.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)hw/acpi/ghes.c +1
-0@@ -30,6 +30,7 @@#define ACPI_HW_ERROR_FW_CFG_FILE "etc/hardware_errors"#define ACPI_HW_ERROR_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" +#define ACPI_HEST_ADDR_FW_CFG_FILE "etc/acpi_table_hest_addr"/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB)
hw/acpi/ghes.c static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, · line 265
Quoted 5 lines
hw/acpi/ghes.c +1
-1@@ -261,7 +262,7 @@ static void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker, }/* -* tell firmware to write hardware_errors GPA into +* Tell firmware to write hardware_errors GPA into
drop this hunk as it's not related to the patch
Quoted 50 lines
hw/acpi/ghes.c +14
-0* hardware_errors_addr fw_cfg, once the former has been initialized. */ bios_linker_loader_write_pointer(linker, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, 0,@@ -355,6 +356,8 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors,acpi_table_begin (&table, table_data); +int hest_offset = table_data->len; +/* Error Source Count */ build_append_int_noprefix (table_data, num_sources,4 );for (i =0 ; i < num_sources; i++) {@@ -362,6 +365,15 @@ void acpi_build_hest(GArray *table_data, GArray *hardware_errors, }acpi_table_end (linker, &table); + +/* +* tell firmware to write into GPA the address of HEST via fw_cfg, +* once initialized. +*/ +bios_linker_loader_write_pointer (linker, +ACPI_HEST_ADDR_FW_CFG_FILE ,0 , +sizeof (uint64_t ), +ACPI_BUILD_TABLE_FILE , hest_offset); } void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,@@ -375,6 +387,9 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,fw_cfg_add_file_callback (s,ACPI_HW_ERROR_ADDR_FW_CFG_FILE ,NULL ,NULL ,NULL , &(ags->hw_error_le),sizeof (ags->hw_error_le), false); +fw_cfg_add_file_callback (s,ACPI_HEST_ADDR_FW_CFG_FILE ,NULL ,NULL , +NULL , &(ags->hest_addr_le),sizeof (ags->hest_addr_le), false); + ags->present = true; }include/hw/acpi/ghes.h +1
-0@@ -58,6 +58,7 @@ enum AcpiGhesNotifyType { };typedef struct AcpiGhesState { +uint64_t hest_addr_le;uint64_t hw_error_le;bool present;/* True if GHES is present at all on this board */ }AcpiGhesState ;