2023-06-21 04:08:00

by Avadhut Naik

[permalink] [raw]
Subject: [PATCH v4 0/4] Add support for Vendor Defined Error Types in Einj Module

From: Avadhut Naik <[email protected]>

This patchset adds support for Vendor Defined Error types in the einj
module by exporting a binary blob file in module's debugfs directory.
Userspace tools can write OEM Defined Structures into the blob file as
part of injecting Vendor defined errors.

The first patch refactors available_error_type_show() function to ensure
all errors supported by the platform are output through einj module's
available_error_type file in debugfs.

The second patch adds a write callback for binary blobs created through
debugfs_create_blob() API.

The third patch fixes the permissions of panicinfo file in debugfs to
ensure it remains read-only

The fourth patch adds the required support i.e. establishing the memory
mapping and exporting it through debugfs blob file for Vendor-defined
Error types.

Changes in v2:
- Split the v1 patch, as was recommended, to have a separate patch for
changes in debugfs.
- Refactored available_error_type_show() function into a separate patch.
- Changed file permissions to octal format to remove checkpatch warnings.

Changes in v3:
- Use BIT macro for generating error masks instead of hex values since
ACPI spec uses bit numbers.
- Handle the corner case of acpi_os_map_iomem() returning NULL through
a local variable to a store the size of OEM defined data structure.

Changes in v4:
- Fix permissions for panicinfo file in debugfs.
- Replace acpi_os_map_iomem() and acpi_os_unmap_iomem() calls with
acpi_os_map_memory() and acpi_os_unmap_memory() respectively to avert
sparse warnings as suggested by Alexey.

Avadhut Naik (4):
ACPI: APEI: EINJ: Refactor available_error_type_show()
fs: debugfs: Add write functionality to debugfs blobs
platform/chrome: cros_ec_debugfs: Fix permissions for panicinfo
ACPI: APEI: EINJ: Add support for vendor defined error types

drivers/acpi/apei/einj.c | 67 ++++++++++++++++-------
drivers/platform/chrome/cros_ec_debugfs.c | 2 +-
fs/debugfs/file.c | 28 ++++++++--
3 files changed, 70 insertions(+), 27 deletions(-)

--
2.34.1



2023-06-21 04:11:49

by Avadhut Naik

[permalink] [raw]
Subject: [PATCH v4 2/4] fs: debugfs: Add write functionality to debugfs blobs

From: Avadhut Naik <[email protected]>

Currently, debugfs_create_blob() creates read-only debugfs binary blob
files.

In some cases, however, userspace tools need to write variable length
data structures into predetermined memory addresses. An example is when
injecting Vendor-defined error types through the einj module. In such
cases, the functionality to write to these blob files in debugfs would
be desired since the mapping aspect can be handled within the modules
with userspace tools only needing to write into the blob files.

Implement a write callback to enable writing to these blob files in
debugfs.

Signed-off-by: Avadhut Naik <[email protected]>
Reviewed-by: Alexey Kardashevskiy <[email protected]>
---
fs/debugfs/file.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 1f971c880dde..fab5a562b57c 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -973,17 +973,35 @@ static ssize_t read_file_blob(struct file *file, char __user *user_buf,
return r;
}

+static ssize_t write_file_blob(struct file *file, const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ struct debugfs_blob_wrapper *blob = file->private_data;
+ struct dentry *dentry = F_DENTRY(file);
+ ssize_t r;
+
+ r = debugfs_file_get(dentry);
+ if (unlikely(r))
+ return r;
+ r = simple_write_to_buffer(blob->data, blob->size, ppos, user_buf,
+ count);
+
+ debugfs_file_put(dentry);
+ return r;
+}
+
static const struct file_operations fops_blob = {
.read = read_file_blob,
+ .write = write_file_blob,
.open = simple_open,
.llseek = default_llseek,
};

/**
- * debugfs_create_blob - create a debugfs file that is used to read a binary blob
+ * debugfs_create_blob - create a debugfs file that is used to read and write
+ * a binary blob
* @name: a pointer to a string containing the name of the file to create.
- * @mode: the read permission that the file should have (other permissions are
- * masked out)
+ * @mode: the permission that the file should have
* @parent: a pointer to the parent dentry for this file. This should be a
* directory dentry if set. If this parameter is %NULL, then the
* file will be created in the root of the debugfs filesystem.
@@ -992,7 +1010,7 @@ static const struct file_operations fops_blob = {
*
* This function creates a file in debugfs with the given name that exports
* @blob->data as a binary blob. If the @mode variable is so set it can be
- * read from. Writing is not supported.
+ * read from and written to.
*
* This function will return a pointer to a dentry if it succeeds. This
* pointer must be passed to the debugfs_remove() function when the file is
@@ -1007,7 +1025,7 @@ struct dentry *debugfs_create_blob(const char *name, umode_t mode,
struct dentry *parent,
struct debugfs_blob_wrapper *blob)
{
- return debugfs_create_file_unsafe(name, mode & 0444, parent, blob, &fops_blob);
+ return debugfs_create_file_unsafe(name, mode, parent, blob, &fops_blob);
}
EXPORT_SYMBOL_GPL(debugfs_create_blob);

--
2.34.1


2023-06-21 04:26:44

by Avadhut Naik

[permalink] [raw]
Subject: [PATCH v4 3/4] platform/chrome: cros_ec_debugfs: Fix permissions for panicinfo

From: Avadhut Naik <[email protected]>

The debugfs_create_blob() function has been used to create read-only binary
blobs in debugfs. The function filters out permissions, other than S_IRUSR,
S_IRGRP and S_IROTH, provided while creating the blobs.

The very behavior though is being changed through previous patch in the
series (fs: debugfs: Add write functionality to debugfs blobs) which makes
the binary blobs writable.

As such, rectify the permissions of panicinfo file to ensure it remains
read-only.

Signed-off-by: Avadhut Naik <[email protected]>
---
drivers/platform/chrome/cros_ec_debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c
index c876120e0ebc..4428dcbd2a68 100644
--- a/drivers/platform/chrome/cros_ec_debugfs.c
+++ b/drivers/platform/chrome/cros_ec_debugfs.c
@@ -454,7 +454,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
debug_info->panicinfo_blob.data = data;
debug_info->panicinfo_blob.size = ret;

- debugfs_create_blob("panicinfo", S_IFREG | 0444, debug_info->dir,
+ debugfs_create_blob("panicinfo", 0444, debug_info->dir,
&debug_info->panicinfo_blob);

return 0;
--
2.34.1


2023-06-21 04:26:47

by Avadhut Naik

[permalink] [raw]
Subject: [PATCH v4 4/4] ACPI: APEI: EINJ: Add support for vendor defined error types

From: Avadhut Naik <[email protected]>

Vendor-Defined Error types are supported by the platform apart from
standard error types if bit 31 is set in the output of GET_ERROR_TYPE
Error Injection Action.[1] While the errors themselves and the length
of their associated "OEM Defined data structure" might vary between
vendors, the physical address of this structure can be computed through
vendor_extension and length fields of "SET_ERROR_TYPE_WITH_ADDRESS" and
"Vendor Error Type Extension" Structures respectively.[2][3]

Currently, however, the einj module only computes the physical address of
Vendor Error Type Extension Structure. Neither does it compute the physical
address of OEM Defined structure nor does it establish the memory mapping
required for injecting Vendor-defined errors. Consequently, userspace
tools have to establish the very mapping through /dev/mem, nopat kernel
parameter and system calls like mmap/munmap initially before injecting
Vendor-defined errors.

Circumvent the issue by computing the physical address of OEM Defined data
structure and establishing the required mapping with the structure. Create
a new file "oem_error", if the system supports Vendor-defined errors, to
export this mapping, through debugfs_create_blob(). Userspace tools can
then populate their respective OEM Defined structure instances and just
write to the file as part of injecting Vendor-defined Errors.

[1] ACPI specification 6.5, section 18.6.4
[2] ACPI specification 6.5, Table 18.31
[3] ACPI specification 6.5, Table 18.32

Suggested-by: Yazen Ghannam <[email protected]>
Signed-off-by: Avadhut Naik <[email protected]>
Reviewed-by: Alexey Kardashevskiy <[email protected]>
---
drivers/acpi/apei/einj.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index ee360fcb1618..0ae2cd325da0 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -73,6 +73,7 @@ static u32 notrigger;

static u32 vendor_flags;
static struct debugfs_blob_wrapper vendor_blob;
+static struct debugfs_blob_wrapper vendor_errors;
static char vendor_dev[64];

/*
@@ -182,6 +183,21 @@ static int einj_timedout(u64 *t)
return 0;
}

+static void get_oem_vendor_struct(u64 paddr, int offset,
+ struct vendor_error_type_extension *v)
+{
+ unsigned long vendor_size;
+ u64 target_pa = paddr + offset + sizeof(struct vendor_error_type_extension);
+
+ vendor_size = v->length - sizeof(struct vendor_error_type_extension);
+
+ if (vendor_size)
+ vendor_errors.data = acpi_os_map_memory(target_pa, vendor_size);
+
+ if (vendor_errors.data)
+ vendor_errors.size = vendor_size;
+}
+
static void check_vendor_extension(u64 paddr,
struct set_error_type_with_address *v5param)
{
@@ -194,6 +210,7 @@ static void check_vendor_extension(u64 paddr,
v = acpi_os_map_iomem(paddr + offset, sizeof(*v));
if (!v)
return;
+ 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,
@@ -596,6 +613,7 @@ static struct { u32 mask; const char *str; } const einj_error_type_string[] = {
{BIT(15), "CXL.mem Protocol Correctable"},
{BIT(16), "CXL.mem Protocol Uncorrectable non-fatal"},
{BIT(17), "CXL.mem Protocol Uncorrectable fatal"},
+ {BIT(31), "Vendor Defined Error Types"},
};

static int available_error_type_show(struct seq_file *m, void *v)
@@ -768,6 +786,10 @@ static int __init einj_init(void)
einj_debug_dir, &vendor_flags);
}

+ if (vendor_errors.size)
+ debugfs_create_blob("oem_error", 0200, einj_debug_dir,
+ &vendor_errors);
+
pr_info("Error INJection is initialized.\n");

return 0;
@@ -793,6 +815,8 @@ static void __exit einj_exit(void)
sizeof(struct einj_parameter);

acpi_os_unmap_iomem(einj_param, size);
+ if (vendor_errors.size)
+ acpi_os_unmap_memory(vendor_errors.data, vendor_errors.size);
}
einj_exec_ctx_init(&ctx);
apei_exec_post_unmap_gars(&ctx);
--
2.34.1


2023-06-23 08:23:17

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v4 3/4] platform/chrome: cros_ec_debugfs: Fix permissions for panicinfo

On Wed, Jun 21, 2023 at 03:51:01AM +0000, Avadhut Naik wrote:
> From: Avadhut Naik <[email protected]>
>
> The debugfs_create_blob() function has been used to create read-only binary
> blobs in debugfs. The function filters out permissions, other than S_IRUSR,
> S_IRGRP and S_IROTH, provided while creating the blobs.
>
> The very behavior though is being changed through previous patch in the
> series (fs: debugfs: Add write functionality to debugfs blobs) which makes
> the binary blobs writable.
>
> As such, rectify the permissions of panicinfo file to ensure it remains
> read-only.
>
> Signed-off-by: Avadhut Naik <[email protected]>

Reviewed-by: Greg Kroah-Hartman <[email protected]>

2023-06-23 08:24:29

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v4 2/4] fs: debugfs: Add write functionality to debugfs blobs

On Wed, Jun 21, 2023 at 03:51:00AM +0000, Avadhut Naik wrote:
> From: Avadhut Naik <[email protected]>
>
> Currently, debugfs_create_blob() creates read-only debugfs binary blob
> files.
>
> In some cases, however, userspace tools need to write variable length
> data structures into predetermined memory addresses. An example is when
> injecting Vendor-defined error types through the einj module. In such
> cases, the functionality to write to these blob files in debugfs would
> be desired since the mapping aspect can be handled within the modules
> with userspace tools only needing to write into the blob files.
>
> Implement a write callback to enable writing to these blob files in
> debugfs.
>
> Signed-off-by: Avadhut Naik <[email protected]>
> Reviewed-by: Alexey Kardashevskiy <[email protected]>

Reviewed-by: Greg Kroah-Hartman <[email protected]>

2023-08-11 06:36:47

by Naik, Avadhut

[permalink] [raw]
Subject: [PATCH v4 0/4] Add support for Vendor Defined Error Types in Einj Module



On 6/20/2023 22:50, Avadhut Naik wrote:
> From: Avadhut Naik <[email protected]>
>
> This patchset adds support for Vendor Defined Error types in the einj
> module by exporting a binary blob file in module's debugfs directory.
> Userspace tools can write OEM Defined Structures into the blob file as
> part of injecting Vendor defined errors.
>
> The first patch refactors available_error_type_show() function to ensure
> all errors supported by the platform are output through einj module's
> available_error_type file in debugfs.
>
> The second patch adds a write callback for binary blobs created through
> debugfs_create_blob() API.
>
> The third patch fixes the permissions of panicinfo file in debugfs to
> ensure it remains read-only
>
> The fourth patch adds the required support i.e. establishing the memory
> mapping and exporting it through debugfs blob file for Vendor-defined
> Error types.
>
> Changes in v2:
> - Split the v1 patch, as was recommended, to have a separate patch for
> changes in debugfs.
> - Refactored available_error_type_show() function into a separate patch.
> - Changed file permissions to octal format to remove checkpatch warnings.
>
> Changes in v3:
> - Use BIT macro for generating error masks instead of hex values since
> ACPI spec uses bit numbers.
> - Handle the corner case of acpi_os_map_iomem() returning NULL through
> a local variable to a store the size of OEM defined data structure.
>
> Changes in v4:
> - Fix permissions for panicinfo file in debugfs.
> - Replace acpi_os_map_iomem() and acpi_os_unmap_iomem() calls with
> acpi_os_map_memory() and acpi_os_unmap_memory() respectively to avert
> sparse warnings as suggested by Alexey.
>
> Avadhut Naik (4):
> ACPI: APEI: EINJ: Refactor available_error_type_show()
> fs: debugfs: Add write functionality to debugfs blobs
> platform/chrome: cros_ec_debugfs: Fix permissions for panicinfo
> ACPI: APEI: EINJ: Add support for vendor defined error types
>
> drivers/acpi/apei/einj.c | 67 ++++++++++++++++-------
> drivers/platform/chrome/cros_ec_debugfs.c | 2 +-
> fs/debugfs/file.c | 28 ++++++++--
> 3 files changed, 70 insertions(+), 27 deletions(-)
>
Hi everyone,

Any further comments on this set? Specifically, for the changes being introduced
in the einj module.

--
Thanks,
Avadhut Naik