linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v1] ACPI: APEI: EINJ: Add support for vendor defined error types
@ 2023-05-16 18:32 Avadhut Naik
  2023-05-16 19:25 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Avadhut Naik @ 2023-05-16 18:32 UTC (permalink / raw)
  To: rafael, gregkh, lenb, linux-acpi, linux-fsdevel
  Cc: Avadhut.Naik, yazen.ghannam, linux-kernel

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@amd.com>
Signed-off-by: Avadhut Naik <Avadhut.Naik@amd.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH v1] ACPI: APEI: EINJ: Add support for vendor defined error types
  2023-05-16 18:32 [RFC PATCH v1] ACPI: APEI: EINJ: Add support for vendor defined error types Avadhut Naik
@ 2023-05-16 19:25 ` Greg KH
  2023-05-16 21:36   ` Avadhut Naik
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2023-05-16 19:25 UTC (permalink / raw)
  To: Avadhut Naik
  Cc: rafael, lenb, linux-acpi, linux-fsdevel, yazen.ghannam, linux-kernel

On Tue, May 16, 2023 at 06:32:28PM +0000, Avadhut Naik wrote:
> 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.

When you say "additionally", that's usually a huge hint that you need to
split this up into multiple patches.

Please do so here.

Also note that debugfs is almost never a valid api for anything you care
about for having a running system, as it is locked down for root access
only and some distros refuse to enable it at all due to its security
leakage.  So be careful about creating an api here that you might need
to use on a normal running system.


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

That's not good, please follow the right style for new code.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH v1] ACPI: APEI: EINJ: Add support for vendor defined error types
  2023-05-16 19:25 ` Greg KH
@ 2023-05-16 21:36   ` Avadhut Naik
  0 siblings, 0 replies; 3+ messages in thread
From: Avadhut Naik @ 2023-05-16 21:36 UTC (permalink / raw)
  To: Greg KH
  Cc: rafael, lenb, linux-acpi, linux-fsdevel, yazen.ghannam,
	linux-kernel, Avadhut Naik

Hi,

On 5/16/2023 14:25, Greg KH wrote:
> On Tue, May 16, 2023 at 06:32:28PM +0000, Avadhut Naik wrote:
>> 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.
> 
> When you say "additionally", that's usually a huge hint that you need to
> split this up into multiple patches.
> 
> Please do so here.
	Will do. Will have a separate patch for debugfs changes.
> 
> Also note that debugfs is almost never a valid api for anything you care
> about for having a running system, as it is locked down for root access
> only and some distros refuse to enable it at all due to its security
> leakage.  So be careful about creating an api here that you might need
> to use on a normal running system.
	I think we should be good in this case. The patch mainly attempts
to extend the functionality of einj module, if supported by the system.
The module itself, I think, requires for the debugfs to be mounted.

> 
> 
>>
>> Note: Some checkpatch warnings are ignored to maintain coding style.
> 
> That's not good, please follow the right style for new code.

	Noted. The only checkpatch warning that was ignored was pertaining
to the usage of S_IWUSR macro with debugfs_create_blob. Had noticed that a
majority of einj module's debugfs files have been created with S_IRUSR and
S_IWUSR macros. So used them to maintain uniformity.
	Will switch to octal permissions though.

Thanks,
Avadhut Naik

> 
> thanks,
> 
> greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-16 21:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 18:32 [RFC PATCH v1] ACPI: APEI: EINJ: Add support for vendor defined error types Avadhut Naik
2023-05-16 19:25 ` Greg KH
2023-05-16 21:36   ` Avadhut Naik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).