arm/acpi/pci/cxl: ACPI based FW First error injection.
cover arm/acpi/pci/cxl: ACPI based FW First error injection.
I've had a version of this code for many years (and occasionally mention it as test platform for kernel patches) and it keeps coming in handy, so time to share the CXL version.
What is this?
- ACPI + UEFI specs define a means of notifying the OS of errors that firmware has handled (gathered up data etc, reset the relevant error tracking units etc) in a set of standard formats (UEFI spec appendix N).
- ARM virt already supports standard HEST ACPI table description of Synchronous External Abort (SEA) for memory errors. This series builds on this to add a GHESv2 / Generic Error Device / GPIO interrupt path for asynchronous error reporting.
- CXL and PCI AER both already have injection commands (via HMP / QMP) These are repurposed to perform FW first injection if the guest OS has not negotiated OS first handling (so before the CXL / PCIE _OSC is called or when it doesn't negotiate control of AER / CXL Memory Errors).
- The OS normally negotiates for control of error registers via _OSC. Previously QEMU unconditionally granted control of these registers. This series includes a machine parameter to allow the 'FW' to not let the OS take control and tracks whether the OS has asked for control or not. Note this code relies on the standard handshake - it's not remotely correct if the OS does follow that flow - this can be hardened with some more AML magic.
Alternatives:
- In theory we could emulate a management controller running appropriate firmware and have that actually handle the errors. It's much easier to instead intercept them before the error reporting messages are sent and result logged in the root ports error registers. As far as the guest is concerned it doesn't matter if these registers are handled via the firmware or never got written in the first place (the guest isn't allowed to touch these registers anyway!) This is sort of same argument for why we build ACPI tables in general in QEMU rather than making that an EDK2 problem.
Why?
- The kernel CXL code supports both firmware first and native RAS. As only some vendors have adopted a FW first model and hardware availability is limited this code has proven challenging to test.
Why an RFC?
- Small matter that the ARM CXL support isn't upstream.
- I'm assuming adding this support to QEMU will be controversial.
- There are some loose ends, TODOs and Fixme's in the code.
- Only one type of CXL event currently handled - should provide them all CXL Protocol and AER error reporting is more complete.
- I should probably figure out how to do this for x86 as apparently people also want to use that architecture ;)
Thanks to Shiju Jose for help testing this.
Based on: Random stack of patches on my gitlab.com/jic23/qemu cxl-2024-02-05-draft branch. Specifically:
https://gitlab.com/jic23/qemu/-/commit/0fa064b9c8eeef468d8a19e87f39f230b4fa4da9
All comments welcome - particularly anyone who can advise on what the HEST table should look like an x86 machine - too many options!
Jonathan Cameron (11):
hw/pci: Add pcie_find_dvsec() utility.
hw/acpi: Allow GPEX _OSC to keep fw first control of AER and CXL
errors.
arm/virt: Add fw-first-ras property.
acpi/ghes: Support GPIO error source.
arm/virt: Wire up GPIO error source for ACPI / GHES
acpi: pci/cxl: Stash the OSC control parameters. pci/aer: Support firmware first error injection via GHESv2 hw/pci/aer: Default to error handling on.
cxl/ras: Set registers to sensible state for FW first ras cxl/type3: FW first protocol error injection. cxl/type3: Add firmware first error reporting for general media
events.
include/hw/acpi/cxl.h | 2 +- include/hw/acpi/ghes.h | 14 + include/hw/arm/virt.h | 1 + include/hw/boards.h | 1 + include/hw/cxl/cxl.h | 2 + include/hw/pci-host/gpex.h | 1 + include/hw/pci/pcie.h | 1 + hw/acpi/cxl-stub.c | 2 +- hw/acpi/cxl.c | 50 ++- hw/acpi/ghes-stub.c | 25 ++ hw/acpi/ghes.c | 634 +++++++++++++++++++++++++++++++++- hw/arm/virt-acpi-build.c | 71 +++- hw/arm/virt.c | 32 +- hw/cxl/cxl-component-utils.c | 4 +- hw/i386/acpi-build.c | 2 +- hw/mem/cxl_type3.c | 42 ++- hw/pci-bridge/cxl_root_port.c | 1 - hw/pci-host/gpex-acpi.c | 17 +- hw/pci-host/gpex.c | 1 + hw/pci/pcie.c | 30 ++ hw/pci/pcie_aer.c | 35 +- 21 files changed, 914 insertions(+), 54 deletions(-)
Signature · 1 line
2.39.2
RFC PATCH 1/11 hw/pci: Add pcie_find_dvsec() utility.
Simple search code used to find first instance of a PCIe Designated Vendor-Specific Extended Capability.
--- include/hw/pci/pcie.h | 1 + hw/pci/pcie.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
include/hw/pci/pcie.h +1 -0
@@ -127,6 +127,7 @@ bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev);/* PCI express extended capability helper functions */ uint16_t pcie_find_capability (PCIDevice *dev,uint16_t cap_id); +uint16_t pcie_find_dvsec (PCIDevice *dev,uint16_t vid,uint16_t id);void pcie_add_capability (PCIDevice *dev,uint16_t cap_id,uint8_t cap_ver,uint16_t offset,uint16_t size);
hw/pci/pcie.c +24 -0
@@ -944,6 +944,30 @@ uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id)return pcie_find_capability_list (dev, cap_id,NULL ); } +uint16_t pcie_find_dvsec (PCIDevice *dev,uint16_t vid,uint16_t id) +{ +uint16_t prev =0 ; +uint16_t next; + +while (1 ) { +uint32_t head1; + + next =pcie_find_capability_list (dev,0x23 , &prev); +if (!next) { +break ; + } + head1 =pci_get_long (dev->config + next +4 ); +if ((head1 &0xFFFF ) == vid) { +uint16_t head2 =pci_get_word (dev->config + next +8 ); +if (head2 == id) { +return next; + } + } + prev = next; + } +return 0 ; +} +static void pcie_ext_cap_set_next (PCIDevice *dev,uint16_t pos,uint16_t next) {uint32_t header =pci_get_long (dev->config + pos);
Signature · 1 line
2.39.2
RFC PATCH 2/11 hw/acpi: Allow GPEX _OSC to keep fw first control of AER and CXL errors.
In reply to Jonathan Cameron--- include/hw/acpi/cxl.h | 2 +- include/hw/pci-host/gpex.h | 1 + hw/acpi/cxl-stub.c | 2 +- hw/acpi/cxl.c | 31 +++++++++++++++++++++++++++---- hw/i386/acpi-build.c | 2 +- hw/pci-host/gpex-acpi.c | 17 +++++++++++------ hw/pci-host/gpex.c | 1 + 7 files changed, 43 insertions(+), 13 deletions(-)
include/hw/acpi/cxl.h +1 -1
@@ -24,7 +24,7 @@void cxl_build_cedt (GArray *table_offsets,GArray *table_data,BIOSLinker *linker,const char *oem_id,const char *oem_table_id,CXLState *cxl_state); -void build_cxl_osc_method (Aml *dev); +void build_cxl_osc_method (Aml *dev,bool fw_first);void build_cxl_dsm_method (Aml *dev);#endif
include/hw/pci-host/gpex.h +1 -0
@@ -47,6 +47,7 @@ struct GPEXConfig {MemMapEntry pio;int irq;PCIBus *bus; +bool fw_first_ras; };struct GPEXHost {
hw/acpi/cxl-stub.c +1 -1
@@ -6,7 +6,7 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/cxl.h" -void build_cxl_osc_method (Aml *dev) +void build_cxl_osc_method (Aml *dev,bool fw_first) {g_assert_not_reached (); }
hw/acpi/cxl.c +27 -4
@@ -27,6 +27,7 @@#include "hw/acpi/aml-build.h" #include "hw/acpi/bios-linker-loader.h" #include "hw/acpi/cxl.h" +#include "hw/acpi/ghes.h" #include "qapi/error.h" #include "qemu/uuid.h"
@@ -222,11 +223,12 @@ void cxl_build_cedt(GArray *table_offsets, GArray *table_data,acpi_table_end (linker, &table); } -static Aml *__build_cxl_osc_method (void ) +static Aml *__build_cxl_osc_method (bool fw_first) {Aml *method, *if_uuid, *else_uuid, *if_arg1_not_1, *if_cxl, *if_caps_masked;Aml *a_ctrl =aml_local (0 );Aml *a_cdw1 =aml_name ("CDW1" ); +Aml *cxl_ctrl =aml_local (2 ); method =aml_method ("_OSC" ,4 ,AML_NOTSERIALIZED );/* CDW1 is used for the return value so is present whether or not a match occurs */
@@ -260,7 +262,11 @@ static Aml *__build_cxl_osc_method(void)* Allows OS control for all 5 features: * PCIeHotplug SHPCHotplug PME AER PCIeCapability */ -aml_append (if_uuid,aml_and (a_ctrl,aml_int (0x1F ), a_ctrl)); +if (fw_first) { +aml_append (if_uuid,aml_and (a_ctrl,aml_int (0x17 ), a_ctrl)); + }else { +aml_append (if_uuid,aml_and (a_ctrl,aml_int (0x1F ), a_ctrl)); + }/* * Check _OSC revision.
@@ -290,6 +296,23 @@ static Aml *__build_cxl_osc_method(void)aml_append (if_cxl,aml_create_dword_field (aml_arg (3 ),aml_int (12 ),"CDW4" ));/* CXL capabilities */ aml_append (if_cxl,aml_create_dword_field (aml_arg (3 ),aml_int (16 ),"CDW5" )); + +aml_append (if_cxl,aml_store (aml_name ("CDW5" ), cxl_ctrl)); +if (fw_first) { +aml_append (if_cxl,aml_and (cxl_ctrl,aml_int (0x0 ), cxl_ctrl)); + }else { +/* Only allow CXL Memory Error Reporting */ +aml_append (if_cxl,aml_and (cxl_ctrl,aml_int (0x1 ), cxl_ctrl)); + } + + if_caps_masked =aml_if (aml_lnot (aml_equal (aml_name ("CDW5" ), cxl_ctrl))); + +/* Capability bits were masked */ +aml_append (if_caps_masked,aml_or (a_cdw1,aml_int (0x10 ), a_cdw1)); +aml_append (if_cxl, if_caps_masked); + +aml_append (if_cxl,aml_store (cxl_ctrl,aml_name ("CDW5" ))); +aml_append (if_cxl,aml_store (aml_name ("CDW4" ),aml_name ("SUPC" )));aml_append (if_cxl,aml_store (aml_name ("CDW5" ),aml_name ("CTRC" )));
@@ -316,11 +339,11 @@ static Aml *__build_cxl_osc_method(void)return method; } -void build_cxl_osc_method (Aml *dev) +void build_cxl_osc_method (Aml *dev,bool fw_first) {aml_append (dev,aml_name_decl ("SUPP" ,aml_int (0 )));aml_append (dev,aml_name_decl ("CTRL" ,aml_int (0 )));aml_append (dev,aml_name_decl ("SUPC" ,aml_int (0 )));aml_append (dev,aml_name_decl ("CTRC" ,aml_int (0 ))); -aml_append (dev,__build_cxl_osc_method ()); +aml_append (dev,__build_cxl_osc_method (fw_first)); }
hw/i386/acpi-build.c +1 -1
@@ -1655,7 +1655,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (aml_pkg,aml_eisaid ("PNP0A08" ));aml_append (aml_pkg,aml_eisaid ("PNP0A03" ));aml_append (dev,aml_name_decl ("_CID" , aml_pkg)); -build_cxl_osc_method (dev); +build_cxl_osc_method (dev, false); }else if (pci_bus_is_express (bus)) {aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0A08" )));aml_append (dev,aml_name_decl ("_CID" ,aml_eisaid ("PNP0A03" )));
hw/pci-host/gpex-acpi.c +11 -6
@@ -49,7 +49,7 @@ static void acpi_dsdt_add_pci_route_table(Aml *dev, uint32_t irq) } } -static void acpi_dsdt_add_pci_osc (Aml *dev) +static void acpi_dsdt_add_pci_osc (Aml *dev,bool fw_first_aer) {Aml *method, *UUID , *ifctx, *ifctx1, *elsectx, *buf;
@@ -79,8 +79,13 @@ static void acpi_dsdt_add_pci_osc(Aml *dev)* Allow OS control for all 5 features: * PCIeHotplug SHPCHotplug PME AER PCIeCapability. */ -aml_append (ifctx,aml_and (aml_name ("CTRL" ),aml_int (0x1F ), -aml_name ("CTRL" ))); +if (fw_first_aer) { +aml_append (ifctx,aml_and (aml_name ("CTRL" ),aml_int (0x17 ), +aml_name ("CTRL" ))); + }else { +aml_append (ifctx,aml_and (aml_name ("CTRL" ),aml_int (0x1F ), +aml_name ("CTRL" ))); + } ifctx1 =aml_if (aml_lnot (aml_equal (aml_arg (1 ),aml_int (0x1 )))); aml_append(ifctx1, aml_or(aml_name("CDW1"), aml_int(0x08),
@@ -186,9 +191,9 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg)aml_append (dev,aml_name_decl ("_CRS" , crs));if (is_cxl) { -build_cxl_osc_method (dev); +build_cxl_osc_method (dev, cfg->fw_first_ras); }else { -acpi_dsdt_add_pci_osc (dev); +acpi_dsdt_add_pci_osc (dev, cfg->fw_first_ras); }aml_append (scope, dev);
@@ -263,7 +268,7 @@ void acpi_dsdt_add_gpex(Aml *scope, struct GPEXConfig *cfg) }aml_append (dev,aml_name_decl ("_CRS" , rbuf)); -acpi_dsdt_add_pci_osc (dev); +acpi_dsdt_add_pci_osc (dev, cfg->fw_first_ras);Aml *dev_res0 =aml_device ("%s" ,"RES0" );aml_append (dev_res0,aml_name_decl ("_HID" ,aml_string ("PNP0C02" )));
hw/pci-host/gpex.c +1 -0
@@ -166,6 +166,7 @@ static Property gpex_host_properties[] = { gpex_cfg.mmio64.base, 0),DEFINE_PROP_SIZE (PCI_HOST_ABOVE_4G_MMIO_SIZE , GPEXHost, gpex_cfg.mmio64.size,0 ), +DEFINE_PROP_BOOL ("fw_first_ras" , GPEXHost, gpex_cfg.fw_first_ras, false), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.39.2
RFC PATCH 3/11 arm/virt: Add fw-first-ras property.
In reply to Jonathan CameronProvide a machine parameter to request firmware first RAS handling and no hand over to the OS via _OSC.
Includes a bug fix as register access is not in CDW5 but only in CXW4 (OS support field).
--- include/hw/arm/virt.h | 1 + hw/acpi/cxl.c | 3 --- hw/arm/virt-acpi-build.c | 1 + hw/arm/virt.c | 20 ++++++++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-)
include/hw/arm/virt.h +1 -0
@@ -153,6 +153,7 @@ struct VirtMachineState {bool tcg_its;bool virt;bool ras; +bool fw_first_ras;bool mte;bool dtb_randomness;OnOffAuto acpi;
hw/acpi/cxl.c +0 -3
@@ -316,9 +316,6 @@ static Aml *__build_cxl_osc_method(bool fw_first)aml_append (if_cxl,aml_store (aml_name ("CDW4" ),aml_name ("SUPC" )));aml_append (if_cxl,aml_store (aml_name ("CDW5" ),aml_name ("CTRC" ))); -/* CXL 2.0 Port/Device Register access */ -aml_append (if_cxl, -aml_or (aml_name ("CDW5" ),aml_int (0x1 ),aml_name ("CDW5" )));aml_append (if_uuid, if_cxl);aml_append (if_uuid,aml_return (aml_arg (3 )));
hw/arm/virt-acpi-build.c +1 -0
@@ -208,6 +208,7 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap, .ecam = memmap[ecam_id], .irq = irq, .bus = vms->bus, + .fw_first_ras = vms->fw_first_ras, };if (vms->highmem_mmio) {
hw/arm/virt.c +20 -0
@@ -2864,6 +2864,20 @@ static void virt_set_ras(Object *obj, bool value, Error **errp) vms->ras = value; } +static bool virt_get_fw_first_ras (Object *obj,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + +return vms->fw_first_ras; +} + +static void virt_set_fw_first_ras (Object *obj,bool value,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (obj); + + vms->fw_first_ras = value; +} +static bool virt_get_mte (Object *obj,Error **errp) {VirtMachineState *vms =VIRT_MACHINE (obj);
@@ -3400,6 +3414,12 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)"Set on/off to enable/disable reporting host memory errors " "to a KVM guest using ACPI and guest external abort exceptions"); +object_class_property_add_bool (oc,"fw-first-ras" , virt_get_fw_first_ras, + virt_set_fw_first_ras); +object_class_property_set_description (oc,"fw-first-ras" , +"Set on/off to control PCI/CXL _OSC allow the guest to" +"obtain permission to do native handling of AER and CXL errors" ); +object_class_property_add_bool (oc,"mte" , virt_get_mte, virt_set_mte);object_class_property_set_description (oc,"mte" , "Set on/off to enable/disable emulating a "
Signature · 1 line
2.39.2
RFC PATCH 4/11 acpi/ghes: Support GPIO error source.
In reply to Jonathan Cameron--- include/hw/acpi/ghes.h | 1 + hw/acpi/ghes.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-)
include/hw/acpi/ghes.h +1 -0
@@ -58,6 +58,7 @@ enum AcpiGhesNotifyType {enum {ACPI_HEST_SRC_ID_SEA =0 , +ACPI_HEST_SRC_ID_GPIO =1 ,/* future ids go here */ ACPI_HEST_SRC_ID_RESERVED , };
hw/acpi/ghes.c +6 -2
@@ -34,8 +34,8 @@/* The max size in bytes for one error block */ #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB) -/* Now only support ARMv8 SEA notification type error source */ -#define ACPI_GHES_ERROR_SOURCE_COUNT 1 +/* Support ARMv8 SEA notification type error source and GPIO interrupt. */ +#define ACPI_GHES_ERROR_SOURCE_COUNT 2/* Generic Hardware Error Source version 2 */ #define ACPI_GHES_SOURCE_GENERIC_ERROR_V2 10
@@ -327,6 +327,9 @@ static void build_ghes_v2(GArray *table_data, int source_id, BIOSLinker *linker)*/ build_ghes_hw_error_notification (table_data,ACPI_GHES_NOTIFY_SEA );break ; +case ACPI_HEST_SRC_ID_GPIO : +build_ghes_hw_error_notification (table_data,ACPI_GHES_NOTIFY_GPIO ); +break ;default :error_report ("Not support this error source" );abort ();
@@ -370,6 +373,7 @@ void acpi_build_hest(GArray *table_data, BIOSLinker *linker,/* Error Source Count */ build_append_int_noprefix (table_data,ACPI_GHES_ERROR_SOURCE_COUNT ,4 );build_ghes_v2 (table_data,ACPI_HEST_SRC_ID_SEA , linker); +build_ghes_v2 (table_data,ACPI_HEST_SRC_ID_GPIO , linker);acpi_table_end (linker, &table); }
Signature · 1 line
2.39.2
RFC PATCH 5/11 arm/virt: Wire up GPIO error source for ACPI / GHES
In reply to Jonathan CameronIncludes creation of a GED - Generic Event Device
--- include/hw/boards.h | 1 + hw/arm/virt-acpi-build.c | 29 +++++++++++++++++++++++++---- hw/arm/virt.c | 12 +++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-)
include/hw/boards.h +1 -0
@@ -301,6 +301,7 @@ struct MachineClass {const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);int64_t (*get_default_cpu_node_id)(const MachineState *ms,int idx);ram_addr_t (*fixup_ram_size)(ram_addr_t size); +void (*set_error)(void ); };/**
hw/arm/virt-acpi-build.c +25 -4
@@ -64,6 +64,7 @@#define ARM_SPI_BASE 32 +#define ACPI_GENERIC_EVENT_DEVICE "GEDD"#define ACPI_BUILD_TABLE_SIZE 0x20000static void acpi_dsdt_add_cpus (Aml *scope,VirtMachineState *vms)
@@ -242,9 +243,14 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,Aml *aei =aml_resource_template ();/* Pin 3 for power button */ -const uint32_t pin_list[1 ] = {3 }; +uint32_t pin =3 ;aml_append (aei,aml_gpio_int (AML_CONSUMER ,AML_EDGE ,AML_ACTIVE_HIGH , -AML_EXCLUSIVE ,AML_PULL_UP ,0 , pin_list,1 , +AML_EXCLUSIVE ,AML_PULL_UP ,0 , &pin,1 , +"GPO0" ,NULL ,0 )); + pin =6 ; +/* Pin 8 for generic error */ +aml_append (aei,aml_gpio_int (AML_CONSUMER ,AML_EDGE ,AML_ACTIVE_HIGH , +AML_EXCLUSIVE ,AML_PULL_UP ,0 , &pin,1 ,"GPO0" ,NULL ,0 ));aml_append (dev,aml_name_decl ("_AEI" , aei));
@@ -253,6 +259,11 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,aml_append (method,aml_notify (aml_name (ACPI_POWER_BUTTON_DEVICE ),aml_int (0x80 )));aml_append (dev, method); + method =aml_method ("_E06" ,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_notify (aml_name (ACPI_GENERIC_EVENT_DEVICE ), +aml_int (0x80 ))); +aml_append (dev, method); +aml_append (scope, dev); }
@@ -885,6 +896,15 @@ static void build_fadt_rev6(GArray *table_data, BIOSLinker *linker,build_fadt (table_data, linker, &fadt, vms->oem_id, vms->oem_table_id); } +static void acpi_dsdt_add_generic_event_device (Aml *scope) +{ +Aml *dev =aml_device (ACPI_GENERIC_EVENT_DEVICE ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C33" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xF ))); +aml_append (scope, dev); +} +/* DSDT */ static void build_dsdt (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms)
@@ -926,9 +946,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) irqmap[VIRT_ACPI_GED ] +ARM_SPI_BASE ,AML_SYSTEM_MEMORY , memmap[VIRT_ACPI_GED].base); }else { -acpi_dsdt_add_gpio (scope, &memmap[VIRT_GPIO ], - (irqmap[VIRT_GPIO ] +ARM_SPI_BASE )); } +acpi_dsdt_add_gpio (scope, &memmap[VIRT_GPIO ], + (irqmap[VIRT_GPIO ] +ARM_SPI_BASE ));if (vms->acpi_dev) { uint32_t event = object_property_get_uint(OBJECT(vms->acpi_dev),
@@ -942,6 +962,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) }acpi_dsdt_add_power_button (scope); +acpi_dsdt_add_generic_event_device (scope);#ifdef CONFIG_TPM acpi_dsdt_add_tpm (scope, vms);#endif
hw/arm/virt.c +11 -1
@@ -914,6 +914,13 @@ static void create_rtc(const VirtMachineState *vms) }static DeviceState *gpio_key_dev; + +static DeviceState *gpio_error_dev; +static void virt_set_error (void ) +{ +qemu_set_irq (qdev_get_gpio_in (gpio_error_dev,0 ),1 ); +} +static void virt_powerdown_req (Notifier *n,void *opaque) {VirtMachineState *s =container_of (n, VirtMachineState, powerdown_notifier);
@@ -931,6 +938,8 @@ static void create_gpio_keys(char *fdt, DeviceState *pl061_dev, { gpio_key_dev =sysbus_create_simple ("gpio-key" ,-1 ,qdev_get_gpio_in (pl061_dev,3 )); + gpio_error_dev =sysbus_create_simple ("gpio-key" ,-1 , +qdev_get_gpio_in (pl061_dev,6 ));qemu_fdt_add_subnode (fdt,"/gpio-keys" );qemu_fdt_setprop_string (fdt,"/gpio-keys" ,"compatible" ,"gpio-keys" );
@@ -2606,8 +2615,8 @@ static void machvirt_init(MachineState *machine)if (has_ged && aarch64 && firmware_loaded &&virt_is_acpi_enabled (vms)) { vms->acpi_dev =create_acpi_ged (vms); }else { -create_gpio_devices (vms,VIRT_GPIO , sysmem); } +create_gpio_devices (vms,VIRT_GPIO , sysmem);if (vms->secure && !vmc->no_secure_gpio) {create_gpio_devices (vms,VIRT_SECURE_GPIO , secure_sysmem);
@@ -3337,6 +3346,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->default_ram_id ="mach-virt.ram" ; mc->default_nic ="virtio-net-pci" ; + mc->set_error = virt_set_error;object_class_property_add (oc,"acpi" ,"OnOffAuto" , virt_get_acpi, virt_set_acpi,NULL ,NULL );
Signature · 1 line
2.39.2
RFC PATCH 6/11 acpi: pci/cxl: Stash the OSC control parameters.
In reply to Jonathan CameronAllow QEMU to know what was successfully requested by the OS via _OSC. Note this handling is very minimal and assumes last written Control parameters were accepted (which they should be if the OS is obeying the rules for negotiating this stuff).
--- include/hw/acpi/ghes.h | 3 +++ hw/acpi/cxl.c | 16 +++++++++++++++ hw/acpi/ghes-stub.c | 10 +++++++++ hw/acpi/ghes.c | 44 ++++++++++++++++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 41 ++++++++++++++++++++++++++++++++++++- 5 files changed, 113 insertions(+), 1 deletion(-)
include/hw/acpi/ghes.h +3 -0
@@ -66,6 +66,7 @@ enum {typedef struct AcpiGhesState {uint64_t ghes_addr_le;bool present;/* True if GHES is present at all on this board */ +uint64_t pci_osc_addr_le; }AcpiGhesState ;void build_ghes_error_table (GArray *hardware_errors,BIOSLinker *linker);
@@ -82,4 +83,6 @@ int acpi_ghes_record_errors(uint8_t notify, uint64_t error_physical_addr);* safe to call acpi_ghes_record_errors() to record a memory error. */ bool acpi_ghes_present (void ); +bool acpi_fw_first_pci (void ); +bool acpi_fw_first_cxl_mem (void );#endif
hw/acpi/cxl.c +16 -0
@@ -228,11 +228,27 @@ static Aml *__build_cxl_osc_method(bool fw_first)Aml *method, *if_uuid, *else_uuid, *if_arg1_not_1, *if_cxl, *if_caps_masked;Aml *a_ctrl =aml_local (0 );Aml *a_cdw1 =aml_name ("CDW1" ); +Aml *cxl_osc_mem =aml_local (1 );Aml *cxl_ctrl =aml_local (2 ); +Aml *field; + method =aml_method ("_OSC" ,4 ,AML_NOTSERIALIZED );/* CDW1 is used for the return value so is present whether or not a match occurs */ aml_append (method,aml_create_dword_field (aml_arg (3 ),aml_int (0 ),"CDW1" )); +if (acpi_ghes_present ()) { +aml_append (method,aml_store (aml_name ("COSC" ), cxl_osc_mem)); +aml_append (method,aml_operation_region ("CXLA" ,AML_SYSTEM_MEMORY , + cxl_osc_mem,64 )); + + field =aml_field ("CXLA" ,AML_DWORD_ACC ,AML_NOLOCK ,AML_PRESERVE ); +aml_append (field,aml_named_field ("ODW1" ,32 )); +aml_append (field,aml_named_field ("ODW2" ,32 )); +aml_append (method, field); +/* Store the value for querying later */ +aml_append (method,aml_store (aml_name ("CTRL" ),aml_name ("ODW1" ))); +aml_append (method,aml_store (aml_name ("CTRC" ),aml_name ("ODW2" ))); + }/* * Generate shared section between:
hw/acpi/ghes-stub.c +10 -0
@@ -20,3 +20,13 @@ bool acpi_ghes_present(void) {return false; } + +bool acpi_fw_first_pci (void ) +{ +return false; +} + +bool acpi_fw_first_cxl_mem (void ) +{ +return false; +}
hw/acpi/ghes.c +44 -0
47 lines not on this page · raw message
hw/arm/virt-acpi-build.c +40 -1
77 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH 7/11 pci/aer: Support firmware first error injection via GHESv2
In reply to Jonathan CameronIf the machine supports firmware first error injection enable those flows.
--- include/hw/acpi/ghes.h | 3 + hw/acpi/ghes-stub.c | 4 + hw/acpi/ghes.c | 250 +++++++++++++++++++++++++++++++++++++++-- hw/pci/pcie_aer.c | 35 ++++-- 4 files changed, 271 insertions(+), 21 deletions(-)
include/hw/acpi/ghes.h +3 -0
@@ -76,6 +76,9 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *vms, FWCfgState *s, GArray *hardware_errors);int acpi_ghes_record_errors (uint8_t notify,uint64_t error_physical_addr); +typedef struct PCIDevice PCIDevice ; +bool ghes_record_aer_errors (PCIDevice *dev,uint32_t notify); +/** * acpi_ghes_present: Report whether ACPI GHES table is present *
hw/acpi/ghes-stub.c +4 -0
@@ -11,6 +11,10 @@#include "qemu/osdep.h" #include "hw/acpi/ghes.h" +bool ghes_record_aer_errors (PCIDevice *dev,uint32_t notify) +{ +return true; +}int acpi_ghes_record_errors (uint8_t source_id,uint64_t physical_address) {return -1 ;
hw/acpi/ghes.c +239 -11
292 lines not on this page · raw message
hw/pci/pcie_aer.c +25 -10
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "migration/vmstate.h" +#include "hw/boards.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pcie.h" #include "hw/pci/msix.h"
@@ -27,6 +28,7 @@#include "hw/pci/pci_bus.h" #include "hw/pci/pcie_regs.h" #include "pci-internal.h" +#include "hw/acpi/ghes.h" //#define DEBUG_PCIE #ifdef DEBUG_PCIE
@@ -638,6 +640,8 @@ static bool pcie_aer_inject_uncor_error(PCIEAERInject *inj, bool is_fatal)*/ int pcie_aer_inject_error (PCIDevice *dev,const PCIEAERErr *err) { +MachineState *machine =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (machine);uint8_t *aer_cap =NULL ;uint16_t devctl =0 ;uint16_t devsta =0 ;
@@ -701,16 +705,27 @@ int pcie_aer_inject_error(PCIDevice *dev, const PCIEAERErr *err) }/* send up error message */ - inj.msg.source_id = err->source_id; -pcie_aer_msg (dev, &inj.msg); - -if (inj.log_overflow) { -PCIEAERErr header_log_overflow = { - .status =PCI_ERR_COR_HL_OVERFLOW , - .flags =PCIE_AER_ERR_IS_CORRECTABLE , - }; -int ret =pcie_aer_inject_error (dev, &header_log_overflow); -assert (!ret); +if (!acpi_fw_first_pci ()) { + inj.msg.source_id = err->source_id; +pcie_aer_msg (dev, &inj.msg); + +if (inj.log_overflow) { +PCIEAERErr header_log_overflow = { + .status =PCI_ERR_COR_HL_OVERFLOW , + .flags =PCIE_AER_ERR_IS_CORRECTABLE , + }; +int ret =pcie_aer_inject_error (dev, &header_log_overflow); +assert (!ret); + } + }else { +ghes_record_aer_errors (dev,ACPI_GHES_NOTIFY_GPIO ); +if (mc->set_error) { + mc->set_error (); + } +/* Simulation a firmware clearing status */ +/* Bit hacky but we only injected one error so this should be fine */ +pci_set_long (aer_cap +PCI_ERR_UNCOR_STATUS ,0 ); +pci_set_long (aer_cap +PCI_ERR_COR_STATUS ,0 ); }return 0 ; }
Signature · 1 line
2.39.2
RFC PATCH 8/11 hw/pci/aer: Default to error handling on.
In reply to Jonathan CameronThis should be dependent on the platform supporting FW first.
--- hw/pci/pcie.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/pci/pcie.c +6 -0
@@ -304,6 +304,12 @@ void pcie_cap_deverr_init(PCIDevice *dev)uint32_t pos = dev->exp.exp_cap;pci_long_test_and_set_mask (dev->config + pos +PCI_EXP_DEVCAP ,PCI_EXP_DEVCAP_RBER ); + +/* HACK - FW first settings - how to do this cleanly? */ +pci_long_test_and_set_mask (dev->config + pos +PCI_EXP_DEVCTL , +PCI_EXP_DEVCTL_CERE |PCI_EXP_DEVCTL_NFERE | +PCI_EXP_DEVCTL_FERE |PCI_EXP_DEVCTL_URRE ); +pci_long_test_and_set_mask (dev->wmask + pos +PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_CERE |PCI_EXP_DEVCTL_NFERE |PCI_EXP_DEVCTL_FERE |PCI_EXP_DEVCTL_URRE );
Signature · 1 line
2.39.2
RFC PATCH 9/11 cxl/ras: Set registers to sensible state for FW first ras
In reply to Jonathan CameronEven if we are doing native RAS, until the point where the OS requests it via an _OSC the firmware may well be handling any errors from CXL devices. As such configure them as if a firmware has been doing so.
--- hw/cxl/cxl-component-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/cxl/cxl-component-utils.c +2 -2
@@ -217,13 +217,13 @@ static void ras_init_common(uint32_t *reg_state, uint32_t *write_msk)stl_le_p (reg_state +R_CXL_RAS_UNC_ERR_STATUS ,0 );stl_le_p (write_msk +R_CXL_RAS_UNC_ERR_STATUS ,0x1cfff );/* Bits 12-13 and 17-31 reserved in CXL 2.0 */ -stl_le_p (reg_state +R_CXL_RAS_UNC_ERR_MASK ,0x1cfff ); +stl_le_p (reg_state +R_CXL_RAS_UNC_ERR_MASK ,0 /*0x1cfff*/ );stl_le_p (write_msk +R_CXL_RAS_UNC_ERR_MASK ,0x1cfff );stl_le_p (reg_state +R_CXL_RAS_UNC_ERR_SEVERITY ,0x1cfff );stl_le_p (write_msk +R_CXL_RAS_UNC_ERR_SEVERITY ,0x1cfff );stl_le_p (reg_state +R_CXL_RAS_COR_ERR_STATUS ,0 );stl_le_p (write_msk +R_CXL_RAS_COR_ERR_STATUS ,0x7f ); -stl_le_p (reg_state +R_CXL_RAS_COR_ERR_MASK ,0x7f ); +stl_le_p (reg_state +R_CXL_RAS_COR_ERR_MASK ,0 /*0x7f*/ );stl_le_p (write_msk +R_CXL_RAS_COR_ERR_MASK ,0x7f );/* CXL switches and devices must set */ stl_le_p (reg_state +R_CXL_RAS_ERR_CAP_CTRL ,0x200 );
Signature · 1 line
2.39.2
RFC PATCH 10/11 cxl/type3: FW first protocol error injection.
In reply to Jonathan CameronNote this is only hooked up to type 3 device so far. Injection via the same interface as for native errors.
e.g.
{ "execute": "cxl-inject-uncorrectable-errors",
"arguments": {
"path": "/machine/peripheral/cxl-pmem2",
"errors": [
{
"type": "cache-address-parity",
"header": [ 3, 4]
}
]}}
--- include/hw/acpi/ghes.h | 4 + include/hw/cxl/cxl.h | 2 + hw/acpi/ghes-stub.c | 5 + hw/acpi/ghes.c | 212 ++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 28 ++++- hw/pci-bridge/cxl_root_port.c | 1 - 6 files changed, 248 insertions(+), 4 deletions(-)
include/hw/acpi/ghes.h +4 -0
@@ -79,6 +79,10 @@ int acpi_ghes_record_errors(uint8_t notify, uint64_t error_physical_addr);typedef struct PCIDevice PCIDevice ;bool ghes_record_aer_errors (PCIDevice *dev,uint32_t notify); +typedef struct CXLError CXLError ; +bool ghes_record_cxl_errors (PCIDevice *dev,PCIEAERErr *err, +CXLError *cxl_err,uint32_t notify); +/** * acpi_ghes_present: Report whether ACPI GHES table is present *
include/hw/cxl/cxl.h +2 -0
@@ -57,6 +57,8 @@ struct CXLHost {bool passthrough; }; +#define TYPE_CXL_ROOT_PORT "cxl-rp" +#define TYPE_PXB_CXL_HOST "pxb-cxl-host"OBJECT_DECLARE_SIMPLE_TYPE (CXLHost,PXB_CXL_HOST )
hw/acpi/ghes-stub.c +5 -0
@@ -19,6 +19,11 @@ int acpi_ghes_record_errors(uint8_t source_id, uint64_t physical_address) {return -1 ; } +bool ghes_record_cxl_errors (PCIDevice *dev,PCIEAERErr *err, +CXLError *cxl_err,uint32_t notify) +{ +return false; +}bool acpi_ghes_present (void ) {
hw/acpi/ghes.c +212 -0
236 lines not on this page · raw message
hw/mem/cxl_type3.c +25 -3
@@ -29,6 +29,8 @@#include "hw/cxl/cxl.h" #include "hw/pci/msix.h" #include "hw/pci/spdm.h" +#include "hw/boards.h" +#include "hw/acpi/ghes.h" #define DWORD_BYTE 4#define CXL_CAPACITY_MULTIPLIER (256 * MiB)
@@ -1520,6 +1522,8 @@ void qmp_cxl_inject_uncorrectable_errors(const char *path, CXLUncorErrorRecordList *errors, Error **errp) { +MachineState *machine =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (machine);Object *obj =object_resolve_path (path,NULL );static PCIEAERErr err = {};CXLType3Dev *ct3d;
@@ -1605,7 +1609,16 @@ void qmp_cxl_inject_uncorrectable_errors(const char *path, }stl_le_p (reg_state +R_CXL_RAS_UNC_ERR_STATUS , unc_err); -pcie_aer_inject_error (PCI_DEVICE (obj), &err); +if (!acpi_fw_first_pci ()) { +pcie_aer_inject_error (PCI_DEVICE (obj), &err); + }else { +ghes_record_cxl_errors (PCI_DEVICE (obj), &err, +QTAILQ_FIRST (&ct3d->error_list), +ACPI_GHES_NOTIFY_GPIO ); +if (mc->set_error) { + mc->set_error (); + } + }return ; }
@@ -1613,6 +1626,8 @@ void qmp_cxl_inject_uncorrectable_errors(const char *path,void qmp_cxl_inject_correctable_error (const char *path,CxlCorErrorType type,Error **errp) { +MachineState *machine =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (machine);static PCIEAERErr err = {};Object *obj =object_resolve_path (path,NULL );CXLType3Dev *ct3d;
@@ -1650,8 +1665,15 @@ void qmp_cxl_inject_correctable_error(const char *path, CxlCorErrorType type, cor_err |= (1 << cxl_err_type);stl_le_p (reg_state +R_CXL_RAS_COR_ERR_STATUS , cor_err); - -pcie_aer_inject_error (PCI_DEVICE (obj), &err); +if (!acpi_fw_first_pci ()) { +pcie_aer_inject_error (PCI_DEVICE (obj), &err); + }else { +ghes_record_cxl_errors (PCI_DEVICE (obj), &err,NULL , +ACPI_GHES_NOTIFY_GPIO ); +if (mc->set_error) { + mc->set_error (); + } + } } static void cxl_assign_event_header(CXLEventRecordHdr *hdr,
hw/pci-bridge/cxl_root_port.c +0 -1
@@ -54,7 +54,6 @@ typedef struct CXLRootPort {PCIResReserve res_reserve; } CXLRootPort; -#define TYPE_CXL_ROOT_PORT "cxl-rp"DECLARE_INSTANCE_CHECKER (CXLRootPort,CXL_ROOT_PORT ,TYPE_CXL_ROOT_PORT )/*
Signature · 1 line
2.39.2
RFC PATCH 11/11 cxl/type3: Add firmware first error reporting for general media events.
In reply to Jonathan CameronInitial code for Firmware First injection of general media events. PoC level only - issue to be solved include:
* Mapping to CPER error types (recoverable etc).
* Some record details are tricky to establish so for now are not provided.
--- include/hw/acpi/ghes.h | 3 ++ hw/acpi/ghes-stub.c | 6 +++ hw/acpi/ghes.c | 120 +++++++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 14 +++-- 4 files changed, 140 insertions(+), 3 deletions(-)
include/hw/acpi/ghes.h +3 -0
@@ -83,6 +83,9 @@ typedef struct CXLError CXLError;bool ghes_record_cxl_errors (PCIDevice *dev,PCIEAERErr *err,CXLError *cxl_err,uint32_t notify); +typedef struct CXLEventGenMedia CXLEventGenMedia ; +bool ghes_record_cxl_event_gm (PCIDevice *dev, +CXLEventGenMedia *gem,uint32_t notify);/** * acpi_ghes_present: Report whether ACPI GHES table is present *
hw/acpi/ghes-stub.c +6 -0
@@ -25,6 +25,12 @@ bool ghes_record_cxl_errors(PCIDevice *dev, PCIEAERErr *err,return false; } +bool ghes_record_cxl_event_gm (PCIDevice *dev,CXLEventGenMedia *gen, +uint32_t notify) +{ +return false; +} +bool acpi_ghes_present (void ) {return false;
hw/acpi/ghes.c +120 -0
138 lines not on this page · raw message
hw/mem/cxl_type3.c +11 -3
@@ -1734,6 +1734,8 @@ void qmp_cxl_inject_general_media_event(const char *path, CxlEventLog log,const char *component_id, Error **errp) { + MachineState *machine = MACHINE(qdev_get_machine()); +MachineClass *mc =MACHINE_GET_CLASS (machine);Object *obj =object_resolve_path (path,NULL );CXLEventGenMedia gem;CXLEventRecordHdr *hdr = &gem.hdr;
@@ -1792,9 +1794,15 @@ void qmp_cxl_inject_general_media_event(const char *path, CxlEventLog log, }stw_le_p (&gem.validity_flags, valid_flags); - -if (cxl_event_insert (cxlds, enc_log, (CXLEventRecordRaw *)&gem)) { -cxl_event_irq_assert (ct3d); +if (!acpi_fw_first_pci ()) { +if (cxl_event_insert (cxlds, enc_log, (CXLEventRecordRaw *)&gem)) { +cxl_event_irq_assert (ct3d); + } + }else { +ghes_record_cxl_event_gm (PCI_DEVICE (ct3d), &gem,ACPI_GHES_NOTIFY_GPIO ); +if (mc->set_error) { + mc->set_error (); + } } }
Signature · 1 line
2.39.2