[RFC PATCH v1] ACPI: APEI: EINJ: Add support for vendor defined error types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



According to ACPI specification 6.5, section 18.6.4, Vendor-Defined Error
types are supported by the system apart from standard error types if bit
31 is set in the output of GET_ERROR_TYPE Error Injection Action. While
the errors themselves and the length of their associated OEM Vendor data
structure might vary between vendors, the physical address of this very
structure can be computed through vendor_extension and length fields of
SET_ERROR_TYPE_WITH_ADDRESS Data Structure and Vendor Error Type Extension
Structure respectively (ACPI Spec 6.5, Table 18.31 and 18.32).

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 Vendor 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 Vendor 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 API. Userspace tools can
then populate their respective OEM Vendor structure instances and just
write to the file as part of injecting Vendor-defined Errors.

Additionally, since the debugfs files created through debugfs_create_blob
API are read-only, introduce a write callback to enable userspace tools to
write OEM Vendor structures into the oem_error file.

Note: Some checkpatch warnings are ignored to maintain coding style.

Suggested-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
Signed-off-by: Avadhut Naik <Avadhut.Naik@xxxxxxx>
---
 drivers/acpi/apei/einj.c | 25 ++++++++++++++++++++++++-
 fs/debugfs/file.c        | 27 ++++++++++++++++++++++-----
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index 013eb621dc92..99f6d495b627 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 oem_err;
 static char vendor_dev[64];
 
 /*
@@ -182,6 +183,16 @@ static int einj_timedout(u64 *t)
 	return 0;
 }
 
+static void get_oem_vendor_struct(u64 paddr, int offset,
+				  struct vendor_error_type_extension *v)
+{
+	u64 target_pa = paddr + offset + sizeof(struct vendor_error_type_extension);
+
+	oem_err.size = v->length - sizeof(struct vendor_error_type_extension);
+	if (oem_err.size)
+		oem_err.data = acpi_os_map_iomem(target_pa, oem_err.size);
+}
+
 static void check_vendor_extension(u64 paddr,
 				   struct set_error_type_with_address *v5param)
 {
@@ -194,6 +205,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,20 +608,25 @@ static const char * const einj_error_type_string[] = {
 	"0x00008000\tCXL.mem Protocol Correctable\n",
 	"0x00010000\tCXL.mem Protocol Uncorrectable non-fatal\n",
 	"0x00020000\tCXL.mem Protocol Uncorrectable fatal\n",
+	"0x80000000\tVendor Defined Error Types\n",
 };
 
 static int available_error_type_show(struct seq_file *m, void *v)
 {
 	int rc;
+	int pos = 0;
 	u32 available_error_type = 0;
 
 	rc = einj_get_available_error_type(&available_error_type);
 	if (rc)
 		return rc;
-	for (int pos = 0; pos < ARRAY_SIZE(einj_error_type_string); pos++)
+	for (; pos < ARRAY_SIZE(einj_error_type_string); pos++)
 		if (available_error_type & BIT(pos))
 			seq_puts(m, einj_error_type_string[pos]);
 
+	if (available_error_type & BIT(31))
+		seq_puts(m, einj_error_type_string[--pos]);
+
 	return 0;
 }
 
@@ -767,6 +784,10 @@ static int __init einj_init(void)
 				   einj_debug_dir, &vendor_flags);
 	}
 
+	if (oem_err.size)
+		debugfs_create_blob("oem_error", S_IWUSR, einj_debug_dir,
+				    &oem_err);
+
 	pr_info("Error INJection is initialized.\n");
 
 	return 0;
@@ -792,6 +813,8 @@ static void __exit einj_exit(void)
 			sizeof(struct einj_parameter);
 
 		acpi_os_unmap_iomem(einj_param, size);
+		if (oem_err.size)
+			acpi_os_unmap_iomem(oem_err.data, oem_err.size);
 	}
 	einj_exec_ctx_init(&ctx);
 	apei_exec_post_unmap_gars(&ctx);
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 1f971c880dde..6570745d2836 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -973,17 +973,34 @@ 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 +1009,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 +1024,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




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux