Enable 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_syndrome1
component_id2 component_syndrome2
:
component_id(n) component_syndrome(n)
for example:
$comp_arr="0x1 0x2
>0x1 0x4
>0x2 0x4"
$cd /sys/kernel/debug/apei/einj/
$echo "$comp_arr" > einjv2_component_array
Signed-off-by: Zaid Alali <zaidal@os.amperecomputing.com>
---
drivers/acpi/apei/einj-core.c | 112 ++++++++++++++++++++++++++++++----
1 file changed, 101 insertions(+), 11 deletions(-)
diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
index 2c22615ac72c..66c5eea33095 100644
--- a/drivers/acpi/apei/einj-core.c
+++ b/drivers/acpi/apei/einj-core.c
@@ -87,6 +87,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 +117,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 +188,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)
{
@@ -304,11 +314,31 @@ 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) /
+ sizeof(v5param.einjv2_struct.component_arr[0]);
+ /*
+ * 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;
}
}
@@ -500,10 +530,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) {
@@ -523,8 +553,54 @@ 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) {
+ kfree(v5param);
+ goto err_out;
+ }
+ if (count >= nr_components) {
+ kfree(v5param);
+ 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:
@@ -548,7 +624,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)
@@ -600,6 +677,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 */
@@ -610,10 +690,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.
@@ -764,7 +849,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;
@@ -783,9 +868,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);
@@ -807,6 +894,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);
}
@@ -955,7 +1045,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);
--
2.43.0
On Thu, Apr 17, 2025 at 03:00:18PM -0700, Zaid Alali wrote:
> + if (is_V2) {
> + int count = 0, bytes_read, pos = 0, nr_parsed = 0, str_len;
> + unsigned int comp, synd;
I've been staring at the ACPI spec to try and figure out how many bits
are needed for comp and sync. The example in section 18.6.7 "Error
Injection Version 2 Operation" has this in step 6:
Component Syndrome Array [0] = { 00000000000000000000000000000004 , 000000000000000000000000A5A5A5A5 }
Which really looks like 128-bit values!
So are "unsigned int" adequate? Even "u64" looks like it would fall short.
> + 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,
Parsing user input with sscanf() is a bit fragile. Take a look at
rdtgroup_schemata_write() which uses:
while ((tok = strsep(&buf, "\n")) != NULL) {
to split input into lines, and then strim() and strsep() to break
up items within a line.
> + &synd, &bytes_read))) {
> + pos += bytes_read;
> +
> + if (nr_parsed != 2) {
> + kfree(v5param);
> + goto err_out;
> + }
> + if (count >= nr_components) {
> + kfree(v5param);
> + 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 {
-Tony
On Fri, Apr 18, 2025 at 01:01:55PM -0700, Luck, Tony wrote:
> On Thu, Apr 17, 2025 at 03:00:18PM -0700, Zaid Alali wrote:
> > + if (is_V2) {
> > + int count = 0, bytes_read, pos = 0, nr_parsed = 0, str_len;
> > + unsigned int comp, synd;
>
> I've been staring at the ACPI spec to try and figure out how many bits
> are needed for comp and sync. The example in section 18.6.7 "Error
> Injection Version 2 Operation" has this in step 6:
>
> Component Syndrome Array [0] = { 00000000000000000000000000000004 , 000000000000000000000000A5A5A5A5 }
>
> Which really looks like 128-bit values!
>
> So are "unsigned int" adequate? Even "u64" looks like it would fall short.
Hi Tony,
Hi Tony,
Thats a great point! I beleive I need to change "struct syndrom_array" to make all union members have
a 128-bit size
struct syndrome_array {
union {
u32 acpi_id; ====> all should be 128-bit long
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 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,
>
> Parsing user input with sscanf() is a bit fragile. Take a look at
> rdtgroup_schemata_write() which uses:
>
> while ((tok = strsep(&buf, "\n")) != NULL) {
>
> to split input into lines, and then strim() and strsep() to break
> up items within a line.
>
> > + &synd, &bytes_read))) {
> > + pos += bytes_read;
> > +
> > + if (nr_parsed != 2) {
> > + kfree(v5param);
> > + goto err_out;
> > + }
> > + if (count >= nr_components) {
> > + kfree(v5param);
> > + 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;
I also need to include another case here for EINJv2_VENDOR_ERROR
I will fix this in the next revision.
-Zaid
> > + }
> > + count++;
> > + if (pos >= str_len)
> > + break;
> > + }
© 2016 - 2025 Red Hat, Inc.