From: Zaid Alali <zaidal@os.amperecomputing.com>
To: Ira Weiny <ira.weiny@intel.com>
Cc: rafael@kernel.org, lenb@kernel.org, james.morse@arm.com,
tony.luck@intel.com, bp@alien8.de, robert.moore@intel.com,
dan.j.williams@intel.com, Jonathan.Cameron@huawei.com,
Benjamin.Cheatham@amd.com, Avadhut.Naik@amd.com,
viro@zeniv.linux.org.uk, arnd@arndb.de, dave.jiang@intel.com,
sthanneeru.opensrc@micron.com, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev
Subject: Re: [PATCH v5 8/9] ACPI: APEI: EINJ: Enable EINJv2 error injections
Date: Tue, 15 Apr 2025 15:09:15 -0700 [thread overview]
Message-ID: <Z_7ZC9w8Yu3Ybm-g@zaid-VirtualBox> (raw)
In-Reply-To: <67eff305b2094_9807c2941e@iweiny-mobl.notmuch>
On Fri, Apr 04, 2025 at 09:56:05AM -0500, Ira Weiny wrote:
> Zaid Alali wrote:
> > 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>
> > ---
>
> [snip]
>
> > @@ -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;
>
> 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
Good catch! I will fix this in the next revision.
Zaid
>
> > +
> > + 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]
next prev parent reply other threads:[~2025-04-15 22:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 23:13 [PATCH v5 0/9] Enable EINJv2 Support Zaid Alali
2025-04-03 23:13 ` [PATCH v5 1/9] ACPICA: Update values to hex to follow ACPI specs Zaid Alali
2025-04-03 23:13 ` [PATCH v5 2/9] ACPICA: Add EINJv2 get error type action Zaid Alali
2025-04-03 23:13 ` [PATCH v5 3/9] ACPI: APEI: EINJ: Fix kernel test robot sparse warning Zaid Alali
2025-04-04 9:20 ` Jonathan Cameron
2025-04-04 14:12 ` Ira Weiny
2025-04-03 23:13 ` [PATCH v5 4/9] ACPI: APEI: EINJ: Remove redundant calls to einj_get_available_error_type Zaid Alali
2025-04-04 14:11 ` Ira Weiny
2025-04-03 23:13 ` [PATCH v5 5/9] ACPI: APEI: EINJ: Enable the discovery of EINJv2 capabilities Zaid Alali
2025-04-04 9:22 ` Jonathan Cameron
2025-04-04 14:24 ` Ira Weiny
2025-04-03 23:13 ` [PATCH v5 6/9] ACPI: APEI: EINJ: Add einjv2 extension struct Zaid Alali
2025-04-04 9:24 ` Jonathan Cameron
2025-04-03 23:13 ` [PATCH v5 7/9] ACPI: APEI: EINJ: Add debugfs files for EINJv2 support Zaid Alali
2025-04-04 9:25 ` Jonathan Cameron
2025-04-04 14:46 ` Ira Weiny
2025-04-03 23:13 ` [PATCH v5 8/9] ACPI: APEI: EINJ: Enable EINJv2 error injections Zaid Alali
2025-04-04 9:31 ` Jonathan Cameron
2025-04-04 14:56 ` Ira Weiny
2025-04-15 22:09 ` Zaid Alali [this message]
2025-04-03 23:13 ` [PATCH v5 9/9] ACPI: APEI: EINJ: Update the documentation for EINJv2 support Zaid Alali
2025-04-04 9:33 ` Jonathan Cameron
2025-04-04 9:25 ` [PATCH v5 0/9] Enable EINJv2 Support Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z_7ZC9w8Yu3Ybm-g@zaid-VirtualBox \
--to=zaidal@os.amperecomputing.com \
--cc=Avadhut.Naik@amd.com \
--cc=Benjamin.Cheatham@amd.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=acpica-devel@lists.linux.dev \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=ira.weiny@intel.com \
--cc=james.morse@arm.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
--cc=sthanneeru.opensrc@micron.com \
--cc=tony.luck@intel.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox