Enable EINJv2 Support
Subsystems (3)
v5 cover Enable EINJv2 Support
The goal of this update is to allow the driver to simultaneously support EINJ and EINJv2. The implementation follows the approved ACPI specs(1)(2) that enables the driver to discover system capabilities through GET_ERROR_TYPE.
Note: The first two ACPICA patches are to be dropped once merged in ACPICA project, see pull request(3).
(1) https://github.com/tianocore/edk2/issues/9449
(2) https://github.com/tianocore/edk2/issues/9017
(3) https://github.com/acpica/acpica/pull/977
Note: This revision includes a minor change to the user interface, where users no longer input component array size, instead the size of the array is parsed by counting lines from user input.
Zaid Alali (9):
ACPICA: Update values to hex to follow ACPI specs
ACPICA: Add EINJv2 get error type action
ACPI: APEI: EINJ: Fix kernel test robot sparse warning
ACPI: APEI: EINJ: Remove redundant calls to
einj_get_available_error_type
ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities
ACPI: APEI: EINJ: Add einjv2 extension struct
ACPI: APEI: EINJ: Add debugfs files for EINJv2 support
ACPI: APEI: EINJ: Enable EINJv2 error injections
ACPI: APEI: EINJ: Update the documentation for EINJv2 support
.../firmware-guide/acpi/apei/einj.rst | 33 +- drivers/acpi/apei/apei-internal.h | 2 +- drivers/acpi/apei/einj-core.c | 322 +++++++++++++----- drivers/acpi/apei/einj-cxl.c | 2 +- include/acpi/actbl1.h | 25 +- 5 files changed, 291 insertions(+), 93 deletions(-)
Signature · 1 line
2.43.0
PATCH v5 1/9 ACPICA: Update values to hex to follow ACPI specs
ACPI specs(1) define Error Injection Actions in hex values. This commit intends to update values from decimal to hex to be consistent with ACPI specs. This commit and the following one are not to be merged and will come form ACPICA project see pull request(2).
(1) https://uefi.org/specs/ACPI/6.5/18_Platform_Error_Interfaces.html
(2) https://github.com/acpica/acpica/pull/977
--- include/acpi/actbl1.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
include/acpi/actbl1.h +12 -12
@@ -1024,18 +1024,18 @@ struct acpi_einj_entry {/* Values for Action field above */ enum acpi_einj_actions { -ACPI_EINJ_BEGIN_OPERATION =0 , -ACPI_EINJ_GET_TRIGGER_TABLE =1 , -ACPI_EINJ_SET_ERROR_TYPE =2 , -ACPI_EINJ_GET_ERROR_TYPE =3 , -ACPI_EINJ_END_OPERATION =4 , -ACPI_EINJ_EXECUTE_OPERATION =5 , -ACPI_EINJ_CHECK_BUSY_STATUS =6 , -ACPI_EINJ_GET_COMMAND_STATUS =7 , -ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS =8 , -ACPI_EINJ_GET_EXECUTE_TIMINGS =9 , -ACPI_EINJ_ACTION_RESERVED =10 ,/* 10 and greater are reserved */ -ACPI_EINJ_TRIGGER_ERROR =0xFF /* Except for this value */ +ACPI_EINJ_BEGIN_OPERATION =0x0 , +ACPI_EINJ_GET_TRIGGER_TABLE =0x1 , +ACPI_EINJ_SET_ERROR_TYPE =0x2 , +ACPI_EINJ_GET_ERROR_TYPE =0x3 , +ACPI_EINJ_END_OPERATION =0x4 , +ACPI_EINJ_EXECUTE_OPERATION =0x5 , +ACPI_EINJ_CHECK_BUSY_STATUS =0x6 , +ACPI_EINJ_GET_COMMAND_STATUS =0x7 , +ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS =0x8 , +ACPI_EINJ_GET_EXECUTE_TIMINGS =0x9 , +ACPI_EINJ_ACTION_RESERVED =0xA ,/* 0xA and greater are reserved */ +ACPI_EINJ_TRIGGER_ERROR =0xFF /* Except for this value */ };/* Values for Instruction field above */
Signature · 1 line
2.43.0
PATCH v5 2/9 ACPICA: Add EINJv2 get error type action
In reply to Zaid AlaliAdd EINJV2_GET_ERROR_TYPE as defined in the approved new ACPI specs(1)(2).
Proposed ACPI spces for EINJv2:
(1) https://github.com/tianocore/edk2/issues/9449
(2) https://github.com/tianocore/edk2/issues/9017
This commit is not a direct merge, it will come from ACPICA project, see pull request(3).
(3) https://github.com/acpica/acpica/pull/977
--- include/acpi/actbl1.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/acpi/actbl1.h +2 -1
@@ -1034,7 +1034,8 @@ enum acpi_einj_actions {ACPI_EINJ_GET_COMMAND_STATUS =0x7 ,ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS =0x8 ,ACPI_EINJ_GET_EXECUTE_TIMINGS =0x9 , -ACPI_EINJ_ACTION_RESERVED =0xA ,/* 0xA and greater are reserved */ +ACPI_EINJV2_GET_ERROR_TYPE =0x11 , +ACPI_EINJ_ACTION_RESERVED =0x12 ,/* 0x12 and greater are reserved */ ACPI_EINJ_TRIGGER_ERROR = 0xFF /* Except for this value */ };
Signature · 1 line
2.43.0
PATCH v5 3/9 ACPI: APEI: EINJ: Fix kernel test robot sparse warning
In reply to Zaid AlaliThis patch fixes the kernel test robot warning reported here:
https://lore.kernel.org/all/[email protected]/
--- drivers/acpi/apei/einj-core.c | 106 +++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 46 deletions(-)
drivers/acpi/apei/einj-core.c +60 -46
@@ -149,7 +149,7 @@ static DEFINE_MUTEX(einj_mutex);*/ bool einj_initialized__ro_after_init ; -static void *einj_param; +static void __iomem *einj_param;static void einj_exec_ctx_init (struct apei_exec_context *ctx) {
@@ -214,24 +214,26 @@ static void check_vendor_extension(u64 paddr, struct set_error_type_with_address *v5param) {int offset = v5param->vendor_extension; -struct vendor_error_type_extension *v; +struct vendor_error_type_extension v; +struct vendor_error_type_extension __iomem *p;u32 sbdf;if (!offset)return ; - v =acpi_os_map_iomem (paddr + offset,sizeof (*v)); -if (!v) + p =acpi_os_map_iomem (paddr + offset,sizeof (*p)); +if (!p)return ; -get_oem_vendor_struct (paddr, offset, v); - sbdf = v->pcie_sbdf; +memcpy_fromio (&v, p,sizeof (v)); +get_oem_vendor_struct (paddr, offset, &v); + sbdf = v.pcie_sbdf;sprintf (vendor_dev,"%x:%x:%x.%x vendor_id=%x device_id=%x rev_id=%x\n" , sbdf >>24 , (sbdf >>16 ) &0xff , (sbdf >>11 ) &0x1f , (sbdf >>8 ) &0x7 , - v->vendor_id, v->device_id, v->rev_id); -acpi_os_unmap_iomem (v,sizeof (*v)); + v.vendor_id, v.device_id, v.rev_id); +acpi_os_unmap_iomem (p,sizeof (v)); } -static void *einj_get_parameter_address (void ) +static void __iomem *einj_get_parameter_address (void ) {int i;u64 pa_v4 =0 , pa_v5 =0 ;
@@ -252,26 +254,30 @@ static void *einj_get_parameter_address(void) entry++; }if (pa_v5) { -struct set_error_type_with_address *v5param; +struct set_error_type_with_address v5param; +struct set_error_type_with_address __iomem *p; - v5param =acpi_os_map_iomem (pa_v5,sizeof (*v5param)); -if (v5param) { + p =acpi_os_map_iomem (pa_v5,sizeof (*p)); +if (p) { +memcpy_fromio (&v5param, p,sizeof (v5param)); acpi5 =1 ; -check_vendor_extension (pa_v5, v5param); -return v5param; +check_vendor_extension (pa_v5, &v5param); +return p; } }if (param_extension && pa_v4) { -struct einj_parameter *v4param; +struct einj_parameter v4param; +struct einj_parameter __iomem *p; - v4param =acpi_os_map_iomem (pa_v4,sizeof (*v4param)); -if (!v4param) + p =acpi_os_map_iomem (pa_v4,sizeof (*p)); +if (!p)return NULL ; -if (v4param->reserved1 || v4param->reserved2) { -acpi_os_unmap_iomem (v4param,sizeof (*v4param)); +memcpy_fromio (&v4param, p,sizeof (v4param)); +if (v4param.reserved1 || v4param.reserved2) { +acpi_os_unmap_iomem (p,sizeof (v4param));return NULL ; } -return v4param; +return p; }return NULL ;
@@ -317,7 +323,7 @@ static struct acpi_generic_address *einj_get_trigger_parameter_region(static int __einj_error_trigger (u64 trigger_paddr,u32 type,u64 param1,u64 param2) { -struct acpi_einj_trigger *trigger_tab =NULL ; +struct acpi_einj_trigger trigger_tab;struct apei_exec_context trigger_ctx;struct apei_resources trigger_resources;struct acpi_whea_header *trigger_entry;
@@ -325,54 +331,57 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,u32 table_size;int rc = -EIO ;struct acpi_generic_address *trigger_param_region =NULL ; +struct acpi_einj_trigger __iomem *p; - r =request_mem_region (trigger_paddr,sizeof (*trigger_tab), + r =request_mem_region (trigger_paddr,sizeof (trigger_tab),"APEI EINJ Trigger Table" );if (!r) {pr_err ("Can not request [mem %#010llx-%#010llx] for Trigger table\n" , (unsigned long long )trigger_paddr, (unsigned long long )trigger_paddr + -sizeof (*trigger_tab) -1 ); +sizeof (trigger_tab) -1 ); goto out; } - trigger_tab =ioremap_cache (trigger_paddr,sizeof (*trigger_tab)); -if (!trigger_tab) { + p =ioremap_cache (trigger_paddr,sizeof (*p)); +if (!p) {pr_err ("Failed to map trigger table!\n" ); goto out_rel_header; } - rc =einj_check_trigger_header (trigger_tab); +memcpy_fromio (&trigger_tab, p,sizeof (trigger_tab)); + rc =einj_check_trigger_header (&trigger_tab);if (rc) {pr_warn (FW_BUG "Invalid trigger error action table.\n" ); goto out_rel_header; }/* No action structures in the TRIGGER_ERROR table, nothing to do */ -if (!trigger_tab->entry_count) +if (!trigger_tab.entry_count) goto out_rel_header; rc = -EIO ; - table_size = trigger_tab->table_size; - r =request_mem_region (trigger_paddr +sizeof (*trigger_tab), - table_size -sizeof (*trigger_tab), + table_size = trigger_tab.table_size; + r =request_mem_region (trigger_paddr +sizeof (trigger_tab), + table_size -sizeof (trigger_tab),"APEI EINJ Trigger Table" );if (!r) {pr_err ("Can not request [mem %#010llx-%#010llx] for Trigger Table Entry\n" , - (unsigned long long )trigger_paddr +sizeof (*trigger_tab), + (unsigned long long )trigger_paddr +sizeof (trigger_tab), (unsigned long long )trigger_paddr + table_size -1 ); goto out_rel_header; } -iounmap (trigger_tab); - trigger_tab =ioremap_cache (trigger_paddr, table_size); -if (!trigger_tab) { +iounmap (p); + p =ioremap_cache (trigger_paddr, table_size); +if (!p) {pr_err ("Failed to map trigger table!\n" ); goto out_rel_entry; } +memcpy_fromio (&trigger_tab, p,sizeof (trigger_tab)); trigger_entry = (struct acpi_whea_header *) - ((char *)trigger_tab +sizeof (struct acpi_einj_trigger )); + ((char *)&trigger_tab +sizeof (struct acpi_einj_trigger ));apei_resources_init (&trigger_resources);apei_exec_ctx_init (&trigger_ctx, einj_ins_type,ARRAY_SIZE (einj_ins_type), - trigger_entry, trigger_tab->entry_count); + trigger_entry, trigger_tab.entry_count); rc =apei_exec_collect_resources (&trigger_ctx, &trigger_resources);if (rc) goto out_fini;
@@ -390,7 +399,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,apei_resources_init (&addr_resources); trigger_param_region =einj_get_trigger_parameter_region ( - trigger_tab, param1, param2); + &trigger_tab, param1, param2);if (trigger_param_region) { rc = apei_resources_add(&addr_resources, trigger_param_region->address,
@@ -419,13 +428,13 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type, out_fini:apei_resources_fini (&trigger_resources); out_rel_entry: -release_mem_region (trigger_paddr +sizeof (*trigger_tab), - table_size -sizeof (*trigger_tab)); +release_mem_region (trigger_paddr +sizeof (trigger_tab), + table_size -sizeof (trigger_tab)); out_rel_header: -release_mem_region (trigger_paddr,sizeof (*trigger_tab)); +release_mem_region (trigger_paddr,sizeof (trigger_tab)); out: -if (trigger_tab) -iounmap (trigger_tab); +if (p) +iounmap (p);return rc; }
@@ -444,8 +453,10 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,return rc;apei_exec_ctx_set_input (&ctx, type);if (acpi5) { -struct set_error_type_with_address *v5param = einj_param; +struct set_error_type_with_address *v5param, v5_struct; + v5param = &v5_struct; +memcpy_fromio (v5param, einj_param,sizeof (*v5param)); v5param->type = type;if (type &ACPI5_VENDOR_BIT ) {switch (vendor_flags) {
@@ -490,15 +501,18 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,break ; } } +memcpy_toio (einj_param, v5param,sizeof (*v5param)); }else { rc =apei_exec_run (&ctx,ACPI_EINJ_SET_ERROR_TYPE );if (rc)return rc;if (einj_param) { -struct einj_parameter *v4param = einj_param; +struct einj_parameter v4param; - v4param->param1 = param1; - v4param->param2 = param2; +memcpy_fromio (&v4param, einj_param,sizeof (v4param)); + v4param.param1 = param1; + v4param.param2 = param2; +memcpy_toio (einj_param, &v4param,sizeof (v4param)); } } rc =apei_exec_run (&ctx,ACPI_EINJ_EXECUTE_OPERATION );
Signature · 1 line
2.43.0
Re: [PATCH v5 3/9] ACPI: APEI: EINJ: Fix kernel test robot sparse warning
On Thu, 3 Apr 2025 16:13:33 -0700
Zaid Alali <[email protected]> wrote:
Probably don't need to mention robot in the commit title.
Quoted 2 lines
This patch fixes the kernel test robot warning reported here:
https://lore.kernel.org/all/[email protected]/
Good perhaps to use the tags suggested in that message. That helps acknowledge the usefulness of that service and them tracking the closure of reports.
Quoted 2 lines
Signed-off-by Zaid Alali <[email protected]>
Otherwise you fixed the one thing I pointed out in v4 so
Re: [PATCH v5 3/9] ACPI: APEI: EINJ: Fix kernel test robot sparse warning
In reply to Zaid AlaliQuoted 4 lines · Zaid Alali
This patch fixes the kernel test robot warning reported here:
https://lore.kernel.org/all/[email protected]/Signed-off-by Zaid Alali <[email protected]>
[snip]
PATCH v5 4/9 ACPI: APEI: EINJ: Remove redundant calls to einj_get_available_error_type
In reply to Zaid AlaliA single call to einj_get_available_error_type in init function is sufficient to save the return value in a global variable to be used later in various places in the code. This commit does not introduce any functional changes, but only removing unnecessary redundant function calls.
--- drivers/acpi/apei/einj-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/acpi/apei/einj-core.c +9 -13
@@ -83,6 +83,8 @@ static struct debugfs_blob_wrapper vendor_blob;static struct debugfs_blob_wrapper vendor_errors;static char vendor_dev[64 ]; +static u32 available_error_type; +/* * Some BIOSes allow parameters to the SET_ERROR_TYPE entries in the * EINJ table through an unpublished extension. Use with caution as
@@ -662,14 +664,9 @@ static struct { u32 mask; const char *str; } const einj_error_type_string[] = {static int available_error_type_show (struct seq_file *m,void *v) { -int rc; -u32 error_type =0 ; - rc =einj_get_available_error_type (&error_type); -if (rc) -return rc;for (int pos =0 ; pos <ARRAY_SIZE (einj_error_type_string); pos++) -if (error_type & einj_error_type_string[pos].mask) +if (available_error_type & einj_error_type_string[pos].mask)seq_printf (m,"0x%08x\t%s\n" , einj_error_type_string[pos].mask, einj_error_type_string[pos].str);
@@ -692,8 +689,7 @@ bool einj_is_cxl_error_type(u64 type)int einj_validate_error_type (u64 type) { -u32 tval, vendor, available_error_type =0 ; -int rc; +u32 tval, vendor;/* Only low 32 bits for error type are valid */ if (type &GENMASK_ULL (63 ,32 ))
@@ -709,13 +705,9 @@ int einj_validate_error_type(u64 type)/* Only one error type can be specified */ if (tval & (tval -1 ))return -EINVAL ; -if (!vendor) { - rc =einj_get_available_error_type (&available_error_type); -if (rc) -return rc; +if (!vendor)if (!(type & available_error_type))return -EINVAL ; - }return 0 ; }
@@ -791,6 +783,10 @@ static int __init einj_probe(struct platform_device *pdev) goto err_put_table; } + rc =einj_get_available_error_type (&available_error_type); +if (rc) +return rc; + rc = -ENOMEM ; einj_debug_dir =debugfs_create_dir ("einj" ,apei_get_debugfs_dir ());
Signature · 1 line
2.43.0
Re: [PATCH v5 4/9] ACPI: APEI: EINJ: Remove redundant calls to einj_get_available_error_type
Quoted 8 lines · Zaid Alali
A single call to
einj_get_available_error_typein init function is sufficient to save the return value in a global variable to be used later in various places in the code. This commit does not introduce any functional changes, but only removing unnecessary redundant function calls.Signed-off-by Zaid Alali <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>
[snip]
PATCH v5 5/9 ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities
In reply to Zaid AlaliEnable the driver to show all supported error injections for EINJ and EINJv2 at the same time. EINJv2 capabilities can be discovered by checking the return value of get_error_type, where bit 30 set indicates EINJv2 support.
--- drivers/acpi/apei/apei-internal.h | 2 +- drivers/acpi/apei/einj-core.c | 64 ++++++++++++++++++++++++------- drivers/acpi/apei/einj-cxl.c | 2 +- 3 files changed, 52 insertions(+), 16 deletions(-)
drivers/acpi/apei/apei-internal.h +1 -1
@@ -131,7 +131,7 @@ static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus)int apei_osc_setup (void ); -int einj_get_available_error_type (u32 *type); +int einj_get_available_error_type (u32 *type,int einj_action);int einj_error_inject (u32 type,u32 flags,u64 param1,u64 param2,u64 param3,u64 param4); int einj_cxl_rch_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
drivers/acpi/apei/einj-core.c +50 -14
145 lines not on this page · raw message
drivers/acpi/apei/einj-cxl.c +1 -1
@@ -30,7 +30,7 @@ int einj_cxl_available_error_type_show(struct seq_file *m, void *v)int cxl_err, rc;u32 available_error_type =0 ; - rc =einj_get_available_error_type (&available_error_type); + rc =einj_get_available_error_type (&available_error_type,ACPI_EINJ_GET_ERROR_TYPE );if (rc)return rc;
Signature · 1 line
2.43.0
Re: [PATCH v5 5/9] ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities
Quoted 6 lines · On Thu, 3 Apr 2025 16:13:35 -0700 Zaid Alali <[email protected]>…
Enable the driver to show all supported error injections for EINJ and EINJv2 at the same time. EINJv2 capabilities can be discovered by checking the return value of
get_error_type, where bit 30 set indicates EINJv2 support.Signed-off-by Zaid Alali <[email protected]>
I gave a tag for v4. If there is a reason you dropped it then should say under the ---
Anyhow, at first glance this is the same code so I'll assume that it was missed by accident and give it again
Re: [PATCH v5 5/9] ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities
In reply to Zaid AlaliQuoted 6 lines · Zaid Alali
Enable the driver to show all supported error injections for EINJ and EINJv2 at the same time. EINJv2 capabilities can be discovered by checking the return value of
get_error_type, where bit 30 set indicates EINJv2 support.Signed-off-by Zaid Alali <[email protected]>
[snip]
drivers/acpi/apei/einj-core.c static int __einj_get_available_error_type(u32 *type) · line 179
Quoted 6 lines
drivers/acpi/apei/einj-core.c +1
-1@@ -174,12 +176,12 @@ static int __einj_get_available_error_type(u32 *type) }/* Get error injection capabilities of the platform */ -int einj_get_available_error_type (u32 *type) +int einj_get_available_error_type (u32 *type,int einj_action)
Why require two separate calls to get each error mask?
IOW Why not:
int einj_get_available_error_type(u32 *type, u32 *type2)
And have the query determine if type2 is supported?
Ira
[snip]
PATCH v5 6/9 ACPI: APEI: EINJ: Add einjv2 extension struct
In reply to Zaid AlaliAdd einjv2 extension struct and EINJv2 error types to prepare the driver for EINJv2 support. ACPI specifications(1) enables EINJv2 by extending set_error_type_with_address struct.
(1) https://github.com/tianocore/edk2/issues/9449
--- drivers/acpi/apei/einj-core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/acpi/apei/einj-core.c +23 -0
@@ -50,6 +50,28 @@*/ static int acpi5; +struct syndrome_array { +union { +u32 acpi_id; +u32 device_id; +u32 pcie_sbdf; +u8 vendor_id[16 ]; + } comp_id; +union { +u32 proc_synd; +u32 mem_synd; +u32 pcie_synd; +u8 vendor_synd[16 ]; + } comp_synd; +}; + +struct einjv2_extension_struct { +u32 length; +u16 revision; +u16 component_arr_count; + struct syndrome_array component_arr[] __counted_by(component_arr_count); +}; +struct set_error_type_with_address {u32 type;u32 vendor_extension;
@@ -58,6 +80,7 @@ struct set_error_type_with_address {u64 memory_address;u64 memory_address_range;u32 pcie_sbdf; +struct einjv2_extension_struct einjv2_struct; };enum {SETWA_FLAGS_APICID =1 ,
Signature · 1 line
2.43.0
Re: [PATCH v5 6/9] ACPI: APEI: EINJ: Add einjv2 extension struct
Quoted 6 lines · On Thu, 3 Apr 2025 16:13:36 -0700 Zaid Alali <[email protected]>…
Add einjv2 extension struct and EINJv2 error types to prepare the driver for EINJv2 support. ACPI specifications(1) enables EINJv2 by extending
set_error_type_with_addressstruct.
See v4 reply which had a tag and a note that this should use a link tag with # [1] after it.
With that fixed up
Quoted 1 line
Signed-off-by Zaid Alali <[email protected]>
PATCH v5 7/9 ACPI: APEI: EINJ: Add debugfs files for EINJv2 support
In reply to Zaid AlaliCreate a debugfs blob file to be used for reading the user input for the component array. EINJv2 enables users to inject errors to multiple components/devices at the same time using component array.
--- drivers/acpi/apei/einj-core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/acpi/apei/einj-core.c +17 -0
@@ -33,6 +33,7 @@#define SLEEP_UNIT_MAX 5000/* 5ms */ /* Firmware should respond within 1 seconds */ #define FIRMWARE_TIMEOUT (1 * USEC_PER_SEC) +#define COMP_ARR_SIZE 1024#define ACPI65_EINJV2_SUPP BIT(30)#define ACPI5_VENDOR_BIT BIT(31)#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \
@@ -107,6 +108,8 @@ static struct debugfs_blob_wrapper vendor_blob;static struct debugfs_blob_wrapper vendor_errors;static char vendor_dev[64 ]; +static struct debugfs_blob_wrapper einjv2_component_arr; +static void *user_input;static u32 available_error_type;static u32 available_error_type_v2;
@@ -890,6 +893,17 @@ static int __init einj_probe(struct platform_device *pdev) &error_param4);debugfs_create_x32 ("notrigger" ,S_IRUSR |S_IWUSR , einj_debug_dir, ¬rigger); +if (available_error_type &ACPI65_EINJV2_SUPP ) { + user_input =kzalloc (COMP_ARR_SIZE ,GFP_KERNEL ); +if (!user_input) { + rc = -ENOMEM ; + goto err_alloc; + } + einjv2_component_arr.data = user_input; + einjv2_component_arr.size =COMP_ARR_SIZE ; +debugfs_create_blob ("einjv2_component_array" ,S_IRUSR |S_IWUSR , + einj_debug_dir, &einjv2_component_arr); + } }if (vendor_dev[0 ]) {
@@ -909,6 +923,8 @@ static int __init einj_probe(struct platform_device *pdev)return 0 ; +err_alloc: +apei_exec_post_unmap_gars (&ctx); err_release:apei_resources_release (&einj_resources); err_fini:
@@ -933,6 +949,7 @@ static void __exit einj_remove(struct platform_device *pdev)if (vendor_errors.size)acpi_os_unmap_memory (vendor_errors.data, vendor_errors.size); } +kfree (user_input);einj_exec_ctx_init (&ctx);apei_exec_post_unmap_gars (&ctx);apei_resources_release (&einj_resources);
Signature · 1 line
2.43.0
Re: [PATCH v5 7/9] ACPI: APEI: EINJ: Add debugfs files for EINJv2 support
Quoted 6 lines · On Thu, 3 Apr 2025 16:13:37 -0700 Zaid Alali <[email protected]>…
Create a debugfs blob file to be used for reading the user input for the component array. EINJv2 enables users to inject errors to multiple components/devices at the same time using component array.
Signed-off-by Zaid Alali <[email protected]>
Hmm. Maybe you didn't get my emails?
Re: [PATCH v5 7/9] ACPI: APEI: EINJ: Add debugfs files for EINJv2 support
In reply to Zaid AlaliQuoted 6 lines · Zaid Alali
Create a debugfs blob file to be used for reading the user input for the component array. EINJv2 enables users to inject errors to multiple components/devices at the same time using component array.
Signed-off-by Zaid Alali <[email protected]>
[snip]
Quoted 19 lines
(quoted diff) +11
-0@@ -890,6 +893,17 @@ static int __init einj_probe(struct platform_device *pdev) &error_param4); debugfs_create_x32("notrigger", S_IRUSR | S_IWUSR, einj_debug_dir, ¬rigger); + if (available_error_type & ACPI65_EINJV2_SUPP) { + user_input = kzalloc(COMP_ARR_SIZE, GFP_KERNEL); + if (!user_input) { + rc = -ENOMEM; + goto err_alloc; + } + einjv2_component_arr.data = user_input; + einjv2_component_arr.size = COMP_ARR_SIZE; + debugfs_create_blob("einjv2_component_array", S_IRUSR | S_IWUSR, + einj_debug_dir, &einjv2_component_arr); + } } if (vendor_dev[0]) {
Review static int __init einj_probe(struct platform_device *pdev) · line 927
Quoted 5 lines
(quoted diff) +2
-0@@ -909,6 +923,8 @@ static int __init einj_probe(struct platform_device *pdev) return 0; +err_alloc: + apei_exec_post_unmap_gars(&ctx);
The addition of an unmap call without a corresponding map call threw me. I see that this is needed in this flow.
Why not attempt the kzalloc() right off in the function? This avoids the extra goto and all the unwind path.
Like:
drivers/acpi/apei/einj-core.c +4 -0
@@ -771,6 +771,10 @@ static int __init einj_probe(struct platform_device *pdev)return -EINVAL ; } + user_input =kzalloc (COMP_ARR_SIZE ,GFP_KERNEL ); +if (!user_input) +return -ENOMEM ; + rc =einj_check_table (einj_tab);if (rc) {pr_warn (FW_BUG "Invalid EINJ table.\n" );
Or, perhaps better, just disable einjv2 if the alloc fails and not fail the probe?
Ira
[snip]
PATCH v5 8/9 ACPI: APEI: EINJ: Enable EINJv2 error injections
In reply to Zaid AlaliEnable the driver to inject EINJv2 type errors. The component array values are parsed from user_input and expected to contain hex values for component id and syndrome separated by space, and multiple components are separated by new line as follows:
component_id1 component_syndrome1component_id2 component_syndrome2
:component_id(n) component_syndrome(n)
for example:
$comp_arr="0x1 0x2
Quoted 2 lines
0x10x40x20x4"
$cd /sys/kernel/debug/apei/einj/
$echo "$comp_arr" > einjv2_component_array
--- drivers/acpi/apei/einj-core.c | 108 ++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 11 deletions(-)
drivers/acpi/apei/einj-core.c +97 -11
@@ -34,6 +34,7 @@/* Firmware should respond within 1 seconds */ #define FIRMWARE_TIMEOUT (1 * USEC_PER_SEC)#define COMP_ARR_SIZE 1024 +#define COMPONENT_LEN 32#define ACPI65_EINJV2_SUPP BIT(30)#define ACPI5_VENDOR_BIT BIT(31)#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \
@@ -87,6 +88,13 @@ enum {SETWA_FLAGS_APICID =1 ,SETWA_FLAGS_MEM =2 ,SETWA_FLAGS_PCIE_SBDF =4 , + SETWA_FLAGS_EINJV2 = 8, +}; + +enum { +EINJV2_PROCESSOR_ERROR =0x1 , +EINJV2_MEMORY_ERROR =0x2 , +EINJV2_PCIE_ERROR =0x4 , };/*
@@ -110,6 +118,7 @@ static char vendor_dev[64];static struct debugfs_blob_wrapper einjv2_component_arr;static void *user_input; +static int nr_components;static u32 available_error_type;static u32 available_error_type_v2;
@@ -180,6 +189,8 @@ static DEFINE_MUTEX(einj_mutex);bool einj_initialized__ro_after_init ;static void __iomem *einj_param; +static u32 v5param_size; +static bool is_V2;static void einj_exec_ctx_init (struct apei_exec_context *ctx) {
@@ -287,11 +298,30 @@ static void __iomem *einj_get_parameter_address(void)struct set_error_type_with_address v5param;struct set_error_type_with_address __iomem *p; + v5param_size =sizeof (v5param); p =acpi_os_map_iomem (pa_v5,sizeof (*p));if (p) { -memcpy_fromio (&v5param, p,sizeof (v5param)); +int offset, len; + +memcpy_fromio (&v5param, p, v5param_size); acpi5 =1 ;check_vendor_extension (pa_v5, &v5param); +if (available_error_type &ACPI65_EINJV2_SUPP ) { + len = v5param.einjv2_struct.length; + offset = offsetof(struct einjv2_extension_struct , component_arr); + nr_components = (len - offset) /COMPONENT_LEN ; +/* +* The first call to acpi_os_map_iomem above does not include the +* component array, instead it is used to read and calculate maximum +* number of components supported by the system. Below, the mapping +* is expanded to include the component array. +*/ +acpi_os_unmap_iomem (p, v5param_size); + offset = offsetof(struct set_error_type_with_address , einjv2_struct); + v5param_size = offset +struct_size (&v5param.einjv2_struct, + component_arr, nr_components); + p =acpi_os_map_iomem (pa_v5, v5param_size); + }return p; } }
@@ -483,10 +513,10 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,return rc;apei_exec_ctx_set_input (&ctx, type);if (acpi5) { -struct set_error_type_with_address *v5param, v5_struct; +struct set_error_type_with_address *v5param; - v5param = &v5_struct; -memcpy_fromio (v5param, einj_param,sizeof (*v5param)); + v5param =kmalloc (v5param_size,GFP_KERNEL ); +memcpy_fromio (v5param, einj_param, v5param_size); v5param->type = type;if (type &ACPI5_VENDOR_BIT ) {switch (vendor_flags) {
@@ -506,8 +536,50 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, v5param->flags = flags; v5param->memory_address = param1; v5param->memory_address_range = param2; - v5param->apicid = param3; - v5param->pcie_sbdf = param4; + +if (is_V2) { +int count =0 , bytes_read, pos =0 , nr_parsed =0 , str_len; +unsigned int comp, synd; +struct syndrome_array *component_arr; + + component_arr = v5param->einjv2_struct.component_arr; + str_len =strlen (user_input); + +while ((nr_parsed =sscanf (user_input + pos,"%x %x\n%n" , &comp, + &synd, &bytes_read))) { + pos += bytes_read; + +if (nr_parsed !=2 ) + goto err_out; +if (count >= nr_components) + goto err_out; + +switch (type) { +case EINJV2_PROCESSOR_ERROR : + component_arr[count].comp_id.acpi_id = comp; + component_arr[count].comp_synd.proc_synd = synd; +break ; +case EINJV2_MEMORY_ERROR : + component_arr[count].comp_id.device_id = comp; + component_arr[count].comp_synd.mem_synd = synd; +break ; +case EINJV2_PCIE_ERROR : + component_arr[count].comp_id.pcie_sbdf = comp; + component_arr[count].comp_synd.pcie_synd = synd; +break ; + } + count++; +if (pos >= str_len) +break ; + } + v5param->einjv2_struct.component_arr_count = count; + +/* clear buffer after user input for next injection */ +memset (user_input,0 ,COMP_ARR_SIZE ); + }else { + v5param->apicid = param3; + v5param->pcie_sbdf = param4; + } }else {switch (type) {case ACPI_EINJ_PROCESSOR_CORRECTABLE :
@@ -531,7 +603,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,break ; } } -memcpy_toio (einj_param, v5param,sizeof (*v5param)); +memcpy_toio (einj_param, v5param, v5param_size); +kfree (v5param); }else { rc =apei_exec_run (&ctx,ACPI_EINJ_SET_ERROR_TYPE );if (rc)
@@ -583,6 +656,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, rc =apei_exec_run_optional (&ctx,ACPI_EINJ_END_OPERATION );return rc; +err_out: +memset (user_input,0 ,COMP_ARR_SIZE ); +return -EINVAL ; }/* Inject the specified hardware error */
@@ -593,10 +669,15 @@ int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, u64 param3,u64 base_addr, size;/* If user manually set "flags", make sure it is legal */ -if (flags && (flags & - ~(SETWA_FLAGS_APICID |SETWA_FLAGS_MEM |SETWA_FLAGS_PCIE_SBDF ))) +if (flags && (flags & ~(SETWA_FLAGS_APICID |SETWA_FLAGS_MEM | +SETWA_FLAGS_PCIE_SBDF |SETWA_FLAGS_EINJV2 )))return -EINVAL ; +/* check if type is a valid EINJv2 error type */ +if (is_V2) { +if (!(type & available_error_type_v2)) +return -EINVAL ; + }/* * We need extra sanity checks for memory errors. * Other types leap directly to injection.
@@ -746,7 +827,7 @@ int einj_validate_error_type(u64 type)if (tval & (tval -1 ))return -EINVAL ;if (!vendor) -if (!(type & available_error_type)) +if (!(type & (available_error_type | available_error_type_v2)))return -EINVAL ;return 0 ;
@@ -765,9 +846,11 @@ static ssize_t error_type_set(struct file *file, const char __user *buf,if (strncmp (einj_buf,"V2_" ,3 ) ==0 ) {if (!sscanf (einj_buf,"V2_%llx" , &val))return -EINVAL ; + is_V2 = true; }else {if (!sscanf (einj_buf,"%llx" , &val))return -EINVAL ; + is_V2 = false; } rc =einj_validate_error_type (val);
@@ -789,6 +872,9 @@ static int error_inject_set(void *data, u64 val)if (!error_type)return -EINVAL ; +if (is_V2) + error_flags |=SETWA_FLAGS_EINJV2 ; +return einj_error_inject (error_type, error_flags, error_param1, error_param2, error_param3, error_param4); }
@@ -942,7 +1028,7 @@ static void __exit einj_remove(struct platform_device *pdev)if (einj_param) {acpi_size size = (acpi5) ? -sizeof (struct set_error_type_with_address ) : + v5param_size :sizeof (struct einj_parameter );acpi_os_unmap_iomem (einj_param, size);
Signature · 1 line
2.43.0
Re: [PATCH v5 8/9] ACPI: APEI: EINJ: Enable EINJv2 error injections
Quoted 28 lines · On Thu, 3 Apr 2025 16:13:38 -0700 Zaid Alali <[email protected]>…
Enable the driver to inject EINJv2 type errors. The component array values are parsed from
user_inputand expected to contain hex values for component id and syndrome separated by space, and multiple components are separated by new line as follows:
component_id1component_syndrome1component_id2component_syndrome2
:component_id(n)component_syndrome(n)for example:
$comp_arr="0x1
0x2Quoted 2 lines
0x10x40x20x4"$cd
/sys/kernel/debug/apei/einj/
$echo "$comp_arr" >einjv2_component_arraySigned-off-by Zaid Alali <[email protected]>--- drivers/acpi/apei/einj-core.c | 108 ++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 11 deletions(-)drivers/acpi/apei/einj-core.c +0
-0
drivers/acpi/apei/einj-core.c line 37
Quoted 4 lines
drivers/acpi/apei/einj-core.c +1
-0@@ -34,6 +34,7 @@/* Firmware should respond within 1 seconds */ #define FIRMWARE_TIMEOUT (1 * USEC_PER_SEC)#define COMP_ARR_SIZE 1024 +#define COMPONENT_LEN 32
The thing this is a length of is a component syndrome (I think) so the naming is confusing. Better to just use sizeof(struct syndrome_array) or even better the sizeof(v5param.einjv2_struct->component_arr[0]) or similar so we don't even need to check the types match.
Always better to establish size of elements from their definitions rather than to add another define for it.
Quoted 211 lines
drivers/acpi/apei/einj-core.c +96
-11#define ACPI65_EINJV2_SUPP BIT(30)#define ACPI5_VENDOR_BIT BIT(31)#define MEM_ERROR_MASK (ACPI_EINJ_MEMORY_CORRECTABLE | \@@ -87,6 +88,13 @@ enum {SETWA_FLAGS_APICID =1 ,SETWA_FLAGS_MEM =2 ,SETWA_FLAGS_PCIE_SBDF =4 , + SETWA_FLAGS_EINJV2 = 8, +}; + +enum { +EINJV2_PROCESSOR_ERROR =0x1 , +EINJV2_MEMORY_ERROR =0x2 , +EINJV2_PCIE_ERROR =0x4 , };/* @@ -110,6 +118,7 @@ static char vendor_dev[64];static struct debugfs_blob_wrapper einjv2_component_arr;static void *user_input; +static int nr_components;static u32 available_error_type;static u32 available_error_type_v2;@@ -180,6 +189,8 @@ static DEFINE_MUTEX(einj_mutex);bool einj_initialized__ro_after_init ;static void __iomem *einj_param; +static u32 v5param_size; +static bool is_V2;static void einj_exec_ctx_init (struct apei_exec_context *ctx) {@@ -287,11 +298,30 @@ static void __iomem *einj_get_parameter_address(void)struct set_error_type_with_address v5param;struct set_error_type_with_address __iomem *p; + v5param_size =sizeof (v5param); p =acpi_os_map_iomem (pa_v5,sizeof (*p));if (p) { -memcpy_fromio (&v5param, p,sizeof (v5param)); +int offset, len; + +memcpy_fromio (&v5param, p, v5param_size); acpi5 =1 ;check_vendor_extension (pa_v5, &v5param); +if (available_error_type &ACPI65_EINJV2_SUPP ) { + len = v5param.einjv2_struct.length; + offset = offsetof(struct einjv2_extension_struct , component_arr); + nr_components = (len - offset) /COMPONENT_LEN ; +/* +* The first call to acpi_os_map_iomem above does not include the +* component array, instead it is used to read and calculate maximum +* number of components supported by the system. Below, the mapping +* is expanded to include the component array. +*/ +acpi_os_unmap_iomem (p, v5param_size); + offset = offsetof(struct set_error_type_with_address , einjv2_struct); + v5param_size = offset +struct_size (&v5param.einjv2_struct, + component_arr, nr_components); + p =acpi_os_map_iomem (pa_v5, v5param_size); + }return p; } }@@ -483,10 +513,10 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,return rc;apei_exec_ctx_set_input (&ctx, type);if (acpi5) { -struct set_error_type_with_address *v5param, v5_struct; +struct set_error_type_with_address *v5param; - v5param = &v5_struct; -memcpy_fromio (v5param, einj_param,sizeof (*v5param)); + v5param =kmalloc (v5param_size,GFP_KERNEL ); +memcpy_fromio (v5param, einj_param, v5param_size); v5param->type = type;if (type &ACPI5_VENDOR_BIT ) {switch (vendor_flags) {@@ -506,8 +536,50 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, v5param->flags = flags; v5param->memory_address = param1; v5param->memory_address_range = param2; - v5param->apicid = param3; - v5param->pcie_sbdf = param4; + +if (is_V2) { +int count =0 , bytes_read, pos =0 , nr_parsed =0 , str_len; +unsigned int comp, synd; +struct syndrome_array *component_arr; + + component_arr = v5param->einjv2_struct.component_arr; + str_len =strlen (user_input); + +while ((nr_parsed =sscanf (user_input + pos,"%x %x\n%n" , &comp, + &synd, &bytes_read))) { + pos += bytes_read; + +if (nr_parsed !=2 ) + goto err_out; +if (count >= nr_components) + goto err_out; + +switch (type) { +case EINJV2_PROCESSOR_ERROR : + component_arr[count].comp_id.acpi_id = comp; + component_arr[count].comp_synd.proc_synd = synd; +break ; +case EINJV2_MEMORY_ERROR : + component_arr[count].comp_id.device_id = comp; + component_arr[count].comp_synd.mem_synd = synd; +break ; +case EINJV2_PCIE_ERROR : + component_arr[count].comp_id.pcie_sbdf = comp; + component_arr[count].comp_synd.pcie_synd = synd; +break ; + } + count++; +if (pos >= str_len) +break ; + } + v5param->einjv2_struct.component_arr_count = count; + +/* clear buffer after user input for next injection */ +memset (user_input,0 ,COMP_ARR_SIZE ); + }else { + v5param->apicid = param3; + v5param->pcie_sbdf = param4; + } }else {switch (type) {case ACPI_EINJ_PROCESSOR_CORRECTABLE :@@ -531,7 +603,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,break ; } } -memcpy_toio (einj_param, v5param,sizeof (*v5param)); +memcpy_toio (einj_param, v5param, v5param_size); +kfree (v5param); }else { rc =apei_exec_run (&ctx,ACPI_EINJ_SET_ERROR_TYPE );if (rc)@@ -583,6 +656,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, rc =apei_exec_run_optional (&ctx,ACPI_EINJ_END_OPERATION );return rc; +err_out: +memset (user_input,0 ,COMP_ARR_SIZE ); +return -EINVAL ; }/* Inject the specified hardware error */ @@ -593,10 +669,15 @@ int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, u64 param3,u64 base_addr, size;/* If user manually set "flags", make sure it is legal */ -if (flags && (flags & - ~(SETWA_FLAGS_APICID |SETWA_FLAGS_MEM |SETWA_FLAGS_PCIE_SBDF ))) +if (flags && (flags & ~(SETWA_FLAGS_APICID |SETWA_FLAGS_MEM | +SETWA_FLAGS_PCIE_SBDF |SETWA_FLAGS_EINJV2 )))return -EINVAL ; +/* check if type is a valid EINJv2 error type */ +if (is_V2) { +if (!(type & available_error_type_v2)) +return -EINVAL ; + }/* * We need extra sanity checks for memory errors. * Other types leap directly to injection. @@ -746,7 +827,7 @@ int einj_validate_error_type(u64 type)if (tval & (tval -1 ))return -EINVAL ;if (!vendor) -if (!(type & available_error_type)) +if (!(type & (available_error_type | available_error_type_v2)))return -EINVAL ;return 0 ;@@ -765,9 +846,11 @@ static ssize_t error_type_set(struct file *file, const char __user *buf,if (strncmp (einj_buf,"V2_" ,3 ) ==0 ) {if (!sscanf (einj_buf,"V2_%llx" , &val))return -EINVAL ; + is_V2 = true; }else {if (!sscanf (einj_buf,"%llx" , &val))return -EINVAL ; + is_V2 = false; } rc =einj_validate_error_type (val);@@ -789,6 +872,9 @@ static int error_inject_set(void *data, u64 val)if (!error_type)return -EINVAL ; +if (is_V2) + error_flags |=SETWA_FLAGS_EINJV2 ; +return einj_error_inject (error_type, error_flags, error_param1, error_param2, error_param3, error_param4); }@@ -942,7 +1028,7 @@ static void __exit einj_remove(struct platform_device *pdev)if (einj_param) {acpi_size size = (acpi5) ? -sizeof (struct set_error_type_with_address ) : + v5param_size :sizeof (struct einj_parameter );acpi_os_unmap_iomem (einj_param, size);
Re: [PATCH v5 8/9] ACPI: APEI: EINJ: Enable EINJv2 error injections
In reply to Zaid AlaliQuoted 20 lines · Zaid Alali
Enable the driver to inject EINJv2 type errors. The component array values are parsed from
user_inputand expected to contain hex values for component id and syndrome separated by space, and multiple components are separated by new line as follows:
component_id1component_syndrome1component_id2component_syndrome2
:component_id(n)component_syndrome(n)for example:
$comp_arr="0x1
0x2Quoted 2 lines
0x10x40x20x4"$cd
/sys/kernel/debug/apei/einj/
$echo "$comp_arr" >einjv2_component_arraySigned-off-by Zaid Alali <[email protected]>---
[snip]
Quoted 27 lines
drivers/acpi/apei/einj-core.c +10
-5@@ -483,10 +513,10 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,return rc;apei_exec_ctx_set_input (&ctx, type);if (acpi5) { -struct set_error_type_with_address *v5param, v5_struct; +struct set_error_type_with_address *v5param; - v5param = &v5_struct; -memcpy_fromio (v5param, einj_param,sizeof (*v5param)); + v5param =kmalloc (v5param_size,GFP_KERNEL ); +memcpy_fromio (v5param, einj_param, v5param_size); v5param->type = type;if (type &ACPI5_VENDOR_BIT ) {switch (vendor_flags) {@@ -506,8 +536,50 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, v5param->flags = flags; v5param->memory_address = param1; v5param->memory_address_range = param2; - v5param->apicid = param3; - v5param->pcie_sbdf = param4; + +if (is_V2) { +int count =0 , bytes_read, pos =0 , nr_parsed =0 , str_len; +unsigned int comp, synd; +struct syndrome_array *component_arr; + + component_arr = v5param->einjv2_struct.component_arr;
drivers/acpi/apei/einj-core.c static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, · line 555
Quoted 10 lines
drivers/acpi/apei/einj-core.c +10
-0+ str_len =strlen (user_input); + +while ((nr_parsed =sscanf (user_input + pos,"%x %x\n%n" , &comp, + &synd, &bytes_read))) { + pos += bytes_read; + +if (nr_parsed !=2 ) + goto err_out; +if (count >= nr_components) + goto err_out;
It is hard to tell but I think these err_out's skip the kfree?
Regardless it is better to use the cleanup functions[1] on that kmalloc and let the destructors clean up for you.
Ira
[1] include/linux/cleanup.h
Quoted 49 lines
drivers/acpi/apei/einj-core.c +32
-1+ +switch (type) { +case EINJV2_PROCESSOR_ERROR : + component_arr[count].comp_id.acpi_id = comp; + component_arr[count].comp_synd.proc_synd = synd; +break ; +case EINJV2_MEMORY_ERROR : + component_arr[count].comp_id.device_id = comp; + component_arr[count].comp_synd.mem_synd = synd; +break ; +case EINJV2_PCIE_ERROR : + component_arr[count].comp_id.pcie_sbdf = comp; + component_arr[count].comp_synd.pcie_synd = synd; +break ; + } + count++; +if (pos >= str_len) +break ; + } + v5param->einjv2_struct.component_arr_count = count; + +/* clear buffer after user input for next injection */ +memset (user_input,0 ,COMP_ARR_SIZE ); + }else { + v5param->apicid = param3; + v5param->pcie_sbdf = param4; + } }else {switch (type) {case ACPI_EINJ_PROCESSOR_CORRECTABLE :@@ -531,7 +603,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,break ; } } -memcpy_toio (einj_param, v5param,sizeof (*v5param)); +memcpy_toio (einj_param, v5param, v5param_size); +kfree (v5param); }else { rc =apei_exec_run (&ctx,ACPI_EINJ_SET_ERROR_TYPE );if (rc)@@ -583,6 +656,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, rc =apei_exec_run_optional (&ctx,ACPI_EINJ_END_OPERATION );return rc; +err_out: +memset (user_input,0 ,COMP_ARR_SIZE ); +return -EINVAL ; }
[snip]
Re: [PATCH v5 8/9] ACPI: APEI: EINJ: Enable EINJv2 error injections
Quoted 64 lines · Ira Weiny
Quoted 20 lines · Zaid Alali
Enable the driver to inject EINJv2 type errors. The component array values are parsed from
user_inputand expected to contain hex values for component id and syndrome separated by space, and multiple components are separated by new line as follows:
component_id1component_syndrome1component_id2component_syndrome2
:component_id(n)component_syndrome(n)for example:
$comp_arr="0x1
0x2Quoted 2 lines
0x10x40x20x4"$cd
/sys/kernel/debug/apei/einj/
$echo "$comp_arr" >einjv2_component_arraySigned-off-by Zaid Alali <[email protected]>---
[snip]
Quoted 27 lines
drivers/acpi/apei/einj-core.c +10
-5@@ -483,10 +513,10 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,return rc;apei_exec_ctx_set_input (&ctx, type);if (acpi5) { -struct set_error_type_with_address *v5param, v5_struct; +struct set_error_type_with_address *v5param; - v5param = &v5_struct; -memcpy_fromio (v5param, einj_param,sizeof (*v5param)); + v5param =kmalloc (v5param_size,GFP_KERNEL ); +memcpy_fromio (v5param, einj_param, v5param_size); v5param->type = type;if (type &ACPI5_VENDOR_BIT ) {switch (vendor_flags) {@@ -506,8 +536,50 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, v5param->flags = flags; v5param->memory_address = param1; v5param->memory_address_range = param2; - v5param->apicid = param3; - v5param->pcie_sbdf = param4; + +if (is_V2) { +int count =0 , bytes_read, pos =0 , nr_parsed =0 , str_len; +unsigned int comp, synd; +struct syndrome_array *component_arr; + + component_arr = v5param->einjv2_struct.component_arr;drivers/acpi/apei/einj-core.c static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, · line 555
Quoted 10 lines
drivers/acpi/apei/einj-core.c +10
-0+ str_len =strlen (user_input); + +while ((nr_parsed =sscanf (user_input + pos,"%x %x\n%n" , &comp, + &synd, &bytes_read))) { + pos += bytes_read; + +if (nr_parsed !=2 ) + goto err_out; +if (count >= nr_components) + goto err_out;It is hard to tell but I think these err_out's skip the kfree?
Quoted 6 lines
Regardless it is better to use the cleanup functions[1] on that kmalloc and let the destructors clean up for you.
Ira
[1]
include/linux/cleanup.h
Good catch! I will fix this in the next revision.
Zaid
Quoted 52 lines
Quoted 50 lines
drivers/acpi/apei/einj-core.c +32
-1+ +switch (type) { +case EINJV2_PROCESSOR_ERROR : + component_arr[count].comp_id.acpi_id = comp; + component_arr[count].comp_synd.proc_synd = synd; +break ; +case EINJV2_MEMORY_ERROR : + component_arr[count].comp_id.device_id = comp; + component_arr[count].comp_synd.mem_synd = synd; +break ; +case EINJV2_PCIE_ERROR : + component_arr[count].comp_id.pcie_sbdf = comp; + component_arr[count].comp_synd.pcie_synd = synd; +break ; + } + count++; +if (pos >= str_len) +break ; + } + v5param->einjv2_struct.component_arr_count = count; + +/* clear buffer after user input for next injection */ +memset (user_input,0 ,COMP_ARR_SIZE ); + }else { + v5param->apicid = param3; + v5param->pcie_sbdf = param4; + } }else {switch (type) {case ACPI_EINJ_PROCESSOR_CORRECTABLE :@@ -531,7 +603,8 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,break ; } } -memcpy_toio (einj_param, v5param,sizeof (*v5param)); +memcpy_toio (einj_param, v5param, v5param_size); +kfree (v5param); }else { rc =apei_exec_run (&ctx,ACPI_EINJ_SET_ERROR_TYPE );if (rc)@@ -583,6 +656,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, rc =apei_exec_run_optional (&ctx,ACPI_EINJ_END_OPERATION );return rc; +err_out: +memset (user_input,0 ,COMP_ARR_SIZE ); +return -EINVAL ; }[snip]
PATCH v5 9/9 ACPI: APEI: EINJ: Update the documentation for EINJv2 support
In reply to Zaid AlaliAdd documentation for the updated ACPI specs for EINJv2(1)(2)
(1) https://github.com/tianocore/edk2/issues/9449
(2) https://github.com/tianocore/edk2/issues/9017
--- .../firmware-guide/acpi/apei/einj.rst | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+)
Documentation/firmware-guide/acpi/apei/einj.rst +32 -0
@@ -59,6 +59,9 @@ The following files belong to it: 0x00000200 Platform Correctable 0x00000400 Platform Uncorrectable non-fatal 0x00000800 Platform Uncorrectable fatal + V2_0x00000001 EINJV2 Processor Error + V2_0x00000002 EINJV2 Memory Error + V2_0x00000004 EINJV2 PCI Express Error ================ =================================== The format of the file contents are as above, except present are only
@@ -88,6 +91,8 @@ The following files belong to it: Memory address and mask valid (param1 and param2). Bit 2 PCIe (seg,bus,dev,fn) valid (see param4 below). + Bit 3 + EINJv2 extension structure is valid If set to zero, legacy behavior is mimicked where the type of injection specifies just one bit set, and param1 is multiplexed.
@@ -122,6 +127,13 @@ The following files belong to it: this actually works depends on what operations the BIOS actually includes in the trigger phase. +- einjv2_component_array + + The contents of this file are used to set the "Component Array" field + of the EINJv2 Extension Structure. The expected format is hex values + for component id and syndrome separated by space, and multiple + components are separated by new line. + CXL error types are supported from ACPI 6.5 onwards (given a CXL port is present). The EINJ user interface for CXL error types is at <debugfs mount point>/cxl. The following files belong to it:
@@ -194,6 +206,26 @@ An error injection example:: # echo 0x8 > error_type # Choose correctable memory error # echo 1 > error_inject # Inject now +An EINJv2 error injection example:: + + # cd /sys/kernel/debug/apei/einj + # cat available_error_type # See which errors can be injected + 0x00000002 Processor Uncorrectable non-fatal + 0x00000008 Memory Correctable + 0x00000010 Memory Uncorrectable non-fatal + V2_0x00000001 EINJV2 Processor Error + V2_0x00000002 EINJV2 Memory Error + + # echo 0x12345000 > param1 # Set memory address for injection + # echo 0xfffffffffffff000 > param2 # Range - anywhere in this page + # comp_arr="0x1 0x2 # Fill in the component array + >0x1 0x4 + >0x2 0x4" + # echo "$comp_arr" > einjv2_component_array + # echo V2_0x2 > error_type # Choose EINJv2 memory error + # echo 0xa > flags # set flags to indicate EINJv2 + # echo 1 > error_inject # Inject now + You should see something like this in dmesg:: [22715.830801] EDAC sbridge MC3: HANDLING MCE MEMORY ERROR
Signature · 1 line
2.43.0
Re: [PATCH v5 9/9] ACPI: APEI: EINJ: Update the documentation for EINJv2 support
Quoted 4 lines · On Thu, 3 Apr 2025 16:13:39 -0700 Zaid Alali <[email protected]>…
Add documentation for the updated ACPI specs for EINJv2(1)(2)
(1) https://github.com/tianocore/edk2/issues/9449
(2) https://github.com/tianocore/edk2/issues/9017
I forgot to highlight these should probably be link tags as per earlier patch review. Other than that, looks good.
Quoted 8 lines · On Thu, 3 Apr 2025 16:13:30 -0700 Zaid Alali <[email protected]>…
The goal of this update is to allow the driver to simultaneously support EINJ and EINJv2. The implementation follows the approved ACPI specs(1)(2) that enables the driver to discover system capabilities through
GET_ERROR_TYPE.Note: The first two ACPICA patches are to be dropped once merged in ACPICA project, see pull request(3).
Quoted 7 lines
(1) https://github.com/tianocore/edk2/issues/9449
(2) https://github.com/tianocore/edk2/issues/9017
(3) https://github.com/acpica/acpica/pull/977Note: This revision includes a minor change to the user interface, where users no longer input component array size, instead the size of the array is parsed by counting lines from user input.
No change log here or in patches. Ideal is a summary of the big stuff here and details under the --- in each individual patch.
Quoted 20 lines
Zaid Alali (9):
ACPICA: Update values to hex to follow ACPI specs
ACPICA: Add EINJv2 get error type action
ACPI: APEI: EINJ: Fix kernel test robot sparse warning
ACPI: APEI: EINJ: Remove redundant calls to
einj_get_available_error_type
ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities
ACPI: APEI: EINJ: Add einjv2 extension struct
ACPI: APEI: EINJ: Add debugfs files for EINJv2 support
ACPI: APEI: EINJ: Enable EINJv2 error injections
ACPI: APEI: EINJ: Update the documentation for EINJv2 support.../firmware-guide/acpi/apei/einj.rst | 33 +- drivers/acpi/apei/apei-internal.h | 2 +- drivers/acpi/apei/einj-core.c | 322 +++++++++++++----- drivers/acpi/apei/einj-cxl.c | 2 +- include/acpi/actbl1.h | 25 +- 5 files changed, 291 insertions(+), 93 deletions(-)