ACPI/APEI: Add BERT data driver
Luck, Tony
reviewerPATCH 1/1 ACPI/APEI: Add BERT data driver
From: Tony Luck <[email protected]>
The ACPI Boot Error Record Table provides a method for platform firmware to give information to the operating system about error that occurred prior to boot (of particular interest are problems that caused the previous OS instance to crash).
The BERT table simply provides the size and address of the error record in BIOS reserved memory. In an earlier age we might have used /dev/mem to retrieve this error record, but many systems disable /dev/mem for security reasons.
This driver provides read-only access to the data via a character special device "/dev/bert-data".
--- drivers/acpi/apei/Kconfig | 7 +++ drivers/acpi/apei/Makefile | 1 + drivers/acpi/apei/bert-data.c | 107 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 drivers/acpi/apei/bert-data.c
drivers/acpi/apei/Kconfig +7 -0
@@ -77,3 +77,10 @@ config ACPI_APEI_ERST_DEBUG error information to and from a persistent store. Enable this if you want to debugging and testing the ERST kernel support and firmware implementation. + +config ACPI_APEI_BERT_DATA + tristate "APEI BERT data driver" + depends on ACPI_APEI + help + This driver provides read access to the error record that + the ACPI/APEI/BERT table points at.
drivers/acpi/apei/Makefile +1 -0
@@ -2,5 +2,6 @@ obj-$(CONFIG_ACPI_APEI) += apei.o obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o +obj-$(CONFIG_ACPI_APEI_BERT_DATA) += bert-data.o apei-y := apei-base.o hest.o erst.o bert.o
drivers/acpi/apei/bert-data.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.11.0
Hi Tony,
Quoted 7 lines · Tony
From: Tony Luck <[email protected]>
The ACPI Boot Error Record Table provides a method for platform firmware to give information to the operating system about error that occurred prior to boot (of particular interest are problems that caused the previous OS instance to crash).
Quoted 7 lines
The BERT table simply provides the size and address of the error record in BIOS reserved memory. In an earlier age we might have used
/dev/memto retrieve this error record, but many systems disable/dev/memfor security reasons.This driver provides read-only access to the data via a character special device "
/dev/bert-data".
There is already a bert driver which prints the error record. Would it make sense to integrate the character device there instead of creating a new driver?
[...]
Luck, Tony
reviewerQuoted 3 lines · Punit Agrawal
There is already a bert driver which prints the error record. Would it make sense to integrate the character device there instead of creating a new driver?
Like this? The source code is smaller. But it doesn't offer the option to unload the driver and unmap the BERT data region after you have retrieved the error record.
Either looks plausible to me (but I'm hardly a disinterested party).
Votes?
-Tony
Quoted 1 line
From
cbeabf2d83fe91eebd960cd5cc1b61faaeed1441Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Tue, 15 Aug 2017 13:48:28 -0700
Subject: [PATCH] ACPI: APEI: Extend BERT driver to provide a character device
to access data
The BERT table simply provides the size and address of the error record in BIOS reserved memory. Currently this driver decodes the record to the console log. But other users of BERT may want to access the full binary record.
In an earlier age we might have used /dev/mem to retrieve this error record, but many systems disable /dev/mem for security reasons.
Extend this driver to provide read-only access to the data via a character special device "/dev/bert-data".
v2: (suggested by Punit Agrawal) don't make a whole new driver, merge
this functionality into the existing BERT driver.
--- drivers/acpi/apei/bert.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-)
drivers/acpi/apei/bert.c +42 -3
@@ -26,12 +26,16 @@#include <linux/init.h> #include <linux/acpi.h> #include <linux/io.h> +#include <linux/miscdevice.h> +#include <linux/uaccess.h> #include "apei-internal.h" #undef pr_fmt#define pr_fmt (fmt) "BERT: " fmt +static __iomem void *bert_data; +static unsigned int region_len;static int bert_disable; static void __init bert_print_all(struct acpi_bert_region *region,
@@ -95,12 +99,45 @@ static int __init bert_check_table(struct acpi_table_bert *bert_tab)return 0 ; } +static int bert_chrdev_open (struct inode *inode,struct file *file) +{ +if (file->f_flags & (O_WRONLY |O_RDWR )) +return -EPERM ; + inode->i_size = region_len; +return 0 ; +} + +static ssize_t bert_chrdev_read (struct file *filp,char __user *ubuf, +size_t usize,loff_t *off) +{ +if (*off > region_len) +return -EINVAL ; +if (*off + usize > region_len) + usize = region_len - *off; +if (copy_to_user (ubuf, bert_data + *off, usize)) +return -EFAULT ; + *off += usize; +return usize; +} + +static const struct file_operations bert_chrdev_ops = { + .open = bert_chrdev_open, + .read = bert_chrdev_read, + .llseek = default_llseek, +}; + +static struct miscdevice bert_chrdev_device = { + .minor =MISC_DYNAMIC_MINOR , + .name ="bert-data" , + .fops = &bert_chrdev_ops, + .mode =0444 , +}; +static int __init bert_init (void ) { -struct apei_resources bert_resources;struct acpi_bert_region *boot_error_region; +struct apei_resources bert_resources;struct acpi_table_bert *bert_tab; -unsigned int region_len;acpi_status status;int rc =0 ;
@@ -139,7 +176,9 @@ static int __init bert_init(void) boot_error_region =ioremap_cache (bert_tab->address, region_len);if (boot_error_region) {bert_print_all (boot_error_region, region_len); -iounmap (boot_error_region); + bert_data = boot_error_region; +if (misc_register (&bert_chrdev_device)) +iounmap (boot_error_region); }else { rc = -ENOMEM ; }
Signature · 1 line
2.11.0
Quoted 7 lines · Tony
Quoted 3 lines · Punit Agrawal
There is already a bert driver which prints the error record. Would it make sense to integrate the character device there instead of creating a new driver?
Like this? The source code is smaller. But it doesn't offer the option to unload the driver and unmap the BERT data region after you have retrieved the error record.
Is there any benefit in being able to unload the driver in real world usage?
It should be possible to convert the existing driver into a loadable module - thought that means re-printing the error records to the kernel log if the module is re-loaded. Not sure if that breaks any existing usecases.
One thing I missed commenting on in the previous version -
Have you thought of exposing the error records via /sys/firmware/acpi? The tables are already exposed there and as BERT is part of ACPI logically that's a better fit compared to a misc device.
Quoted 118 lines
Either looks plausible to me (but I'm hardly a disinterested party).
Votes?
-Tony
From
cbeabf2d83fe91eebd960cd5cc1b61faaeed1441Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Tue, 15 Aug 2017 13:48:28 -0700
Subject: [PATCH] ACPI: APEI: Extend BERT driver to provide a character device
to access dataThe BERT table simply provides the size and address of the error record in BIOS reserved memory. Currently this driver decodes the record to the console log. But other users of BERT may want to access the full binary record.
In an earlier age we might have used
/dev/memto retrieve this error record, but many systems disable/dev/memfor security reasons.Extend this driver to provide read-only access to the data via a character special device "
/dev/bert-data".Cc Len Brown <[email protected]>Cc Boris Petkov <[email protected]>Cc Tyler Baicar <[email protected]>Cc Punit Agrawal <[email protected]>Signed-off-by Tony Luck <[email protected]>v2: (suggested by Punit Agrawal) don't make a whole new driver, merge
this functionality into the existing BERT driver.--- drivers/acpi/apei/bert.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-)drivers/acpi/apei/bert.c +42
-3@@ -26,12 +26,16 @@#include <linux/init.h> #include <linux/acpi.h> #include <linux/io.h> +#include <linux/miscdevice.h> +#include <linux/uaccess.h> #include "apei-internal.h" #undef pr_fmt#define pr_fmt (fmt) "BERT: " fmt +static __iomem void *bert_data; +static unsigned int region_len;static int bert_disable; static void __init bert_print_all(struct acpi_bert_region *region,@@ -95,12 +99,45 @@ static int __init bert_check_table(struct acpi_table_bert *bert_tab)return 0 ; } +static int bert_chrdev_open (struct inode *inode,struct file *file) +{ +if (file->f_flags & (O_WRONLY |O_RDWR )) +return -EPERM ; + inode->i_size = region_len; +return 0 ; +} + +static ssize_t bert_chrdev_read (struct file *filp,char __user *ubuf, +size_t usize,loff_t *off) +{ +if (*off > region_len) +return -EINVAL ; +if (*off + usize > region_len) + usize = region_len - *off; +if (copy_to_user (ubuf, bert_data + *off, usize)) +return -EFAULT ; + *off += usize; +return usize; +} + +static const struct file_operations bert_chrdev_ops = { + .open = bert_chrdev_open, + .read = bert_chrdev_read, + .llseek = default_llseek, +}; + +static struct miscdevice bert_chrdev_device = { + .minor =MISC_DYNAMIC_MINOR , + .name ="bert-data" , + .fops = &bert_chrdev_ops, + .mode =0444 , +}; +static int __init bert_init (void ) { -struct apei_resources bert_resources;struct acpi_bert_region *boot_error_region; +struct apei_resources bert_resources;struct acpi_table_bert *bert_tab; -unsigned int region_len;acpi_status status;int rc =0 ;@@ -139,7 +176,9 @@ static int __init bert_init(void) boot_error_region =ioremap_cache (bert_tab->address, region_len);if (boot_error_region) {bert_print_all (boot_error_region, region_len); -iounmap (boot_error_region); + bert_data = boot_error_region; +if (misc_register (&bert_chrdev_device)) +iounmap (boot_error_region); }else { rc = -ENOMEM ; }
Luck, Tony
reviewerQuoted 5 lines
One thing I missed commenting on in the previous version -
Have you thought of exposing the error records via
/sys/firmware/acpi? The tables are already exposed there and as BERT is part of ACPI logically that's a better fit compared to a misc device.
That was my first thought :-)
But I got stuck on how to name things. The BERT entry appears in /sys/firmware/acpi/tables/ ... but the code doesn't know anything special about "BERT", it just iterates over all the tables and makes them all appear.
I thought about making it /sys/firmware/acpi/tables/BERT.data, but that seemed very ugly (this file isn't a "table", so why does it appear in the "tables" directory? So maybe /sys/firmware/acpi/table-data/BERT? Now the driver has to make another directory.
Thoughts?
-Tony
Quoted 13 lines · Tony
Quoted 5 lines
One thing I missed commenting on in the previous version -
Have you thought of exposing the error records via
/sys/firmware/acpi? The tables are already exposed there and as BERT is part of ACPI logically that's a better fit compared to a misc device.That was my first thought :-)
But I got stuck on how to name things. The BERT entry appears in
/sys/firmware/acpi/tables/... but the code doesn't know anything special about "BERT", it just iterates over all the tables and makes them all appear.
Quoted 6 lines
I thought about making it
/sys/firmware/acpi/tables/BERT.data, but that seemed very ugly (this file isn't a "table", so why does it appear in the "tables" directory? So maybe/sys/firmware/acpi/table-data/BERT? Now the driver has to make another directory.Thoughts?
I agree that keeping the error record out of the tables directory makes sense as it's not an ACPI table.
The best I could come up with was bert-data or bert-region in /sys/firmware/acpi/apei/.
Though, I am OK with "table-data/BERT" as well.
Quoted 6 lines
-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Luck, Tony
reviewerQuoted 1 line · Punit Agrawal
Though, I am OK with "table-data/BERT" as well.
So I coded this up ... and it looks much better than I thought it might. A bit larger than the previous version that modified drivers/acpi/apei/bert.c. But on the plus side easy to extend if there are other ACPI tables that point at interesting data.
It doesn't handle dynamic tables. That would add a lot of complexity and BERT isn't dynamic. Could be a later patch if someone has a need for it.
All names negotiable.
-Tony
Quoted 1 line
From
595562691d2747459235ddbc396949337605ac2aMon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Wed, 16 Aug 2017 15:36:28 -0700
Subject: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot
error region
The ACPI sysfs interface provides a way to read each ACPI table from userspace via entries in /sys/firmware/acpi/tables/
The BERT table simply provides the size and address of the error record in BIOS reserved memory and users may want access to this record.
In an earlier age we might have used /dev/mem to retrieve this error record, but many systems disable /dev/mem for security reasons.
Extend this driver to provide read-only access to the data via a file in a new directory /sys/firmware/acpi/tables-data/
v3: (suggested by Punit Agrawal) extend the /sys/firmware/acpi code to provide this functionality.
--- drivers/acpi/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
drivers/acpi/sysfs.c +79 -0
@@ -306,11 +306,13 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);/* * ACPI table sysfs I/F: * /sys/firmware/acpi/tables/ +* /sys/firmware/acpi/tables-data/ * /sys/firmware/acpi/tables/dynamic/ */ static LIST_HEAD (acpi_table_attr_list);static struct kobject *tables_kobj; +static struct kobject *tables_data_kobj;static struct kobject *dynamic_tables_kobj;static struct kobject *hotplug_kobj;
@@ -325,6 +327,11 @@ struct acpi_table_attr {struct list_head node; }; +struct acpi_data_attr { +struct bin_attribute attr; +u64 addr; +}; +static ssize_t acpi_table_show (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t offset,size_t count)
@@ -420,6 +427,70 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context)return AE_OK ; } +static ssize_t acpi_data_show (struct file *filp,struct kobject *kobj, +struct bin_attribute *bin_attr,char *buf, +loff_t offset,size_t count) +{ +struct acpi_data_attr *data_attr; +void __iomem *base; +ssize_t rc; + + data_attr = container_of(bin_attr, struct acpi_data_attr, attr); + + base =acpi_os_map_memory (data_attr->addr, data_attr->attr.size); +if (!base) +return -ENOMEM ; + rc =memory_read_from_buffer (buf, count, &offset, base, + data_attr->attr.size); +acpi_os_unmap_memory (base, data_attr->attr.size); + +return rc; +} + +static int acpi_bert_data_init (void *th,struct acpi_data_attr *data_attr) +{ +struct acpi_table_bert *bert = th; + +if (bert->header.length <sizeof (struct acpi_table_bert ) || + bert->region_length <sizeof (struct acpi_hest_generic_status )) { +kfree (data_attr); +return -EINVAL ; + } + data_attr->addr = bert->address; + data_attr->attr.size = bert->region_length; + data_attr->attr.attr.name ="BERT-DATA" ; + +return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +} + +static struct acpi_data_obj { +char *name; +int (*fn)(void *,struct acpi_data_attr *); +} acpi_data_objs[] = { + {ACPI_SIG_BERT , acpi_bert_data_init }, +}; + +#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs) + +static int acpi_table_data_init (struct acpi_table_header *th) +{ +struct acpi_data_attr *data_attr; +int i; + +for (i =0 ; i <NUM_ACPI_DATA_OBJS ; i++) { +if (ACPI_COMPARE_NAME (th->signature, acpi_data_objs[i].name)) { + data_attr =kzalloc (sizeof (*data_attr),GFP_KERNEL ); +if (!data_attr) +return -ENOMEM ; +sysfs_attr_init (&data_attr->attr.attr); + data_attr->attr.read = acpi_data_show; + data_attr->attr.attr.mode =0400 ; +return acpi_data_objs[i].fn (th, data_attr); + } + } +return 0 ; +} +static int acpi_tables_sysfs_init (void ) {struct acpi_table_attr *table_attr;
@@ -432,6 +503,10 @@ static int acpi_tables_sysfs_init(void)if (!tables_kobj) goto err; + tables_data_kobj =kobject_create_and_add ("tables-data" , acpi_kobj); +if (!tables_data_kobj) + goto err_tables_data; + dynamic_tables_kobj =kobject_create_and_add ("dynamic" , tables_kobj);if (!dynamic_tables_kobj) goto err_dynamic_tables;
@@ -456,13 +531,17 @@ static int acpi_tables_sysfs_init(void)return ret; }list_add_tail (&table_attr->node, &acpi_table_attr_list); +acpi_table_data_init (table_header); }kobject_uevent (tables_kobj,KOBJ_ADD ); +kobject_uevent (tables_data_kobj,KOBJ_ADD );kobject_uevent (dynamic_tables_kobj,KOBJ_ADD );return 0 ; err_dynamic_tables: +kobject_put (tables_data_kobj); +err_tables_data:kobject_put (tables_kobj); err:return -ENOMEM ;
Signature · 1 line
2.11.0
Rafael J. Wysocki
maintainerQuoted 8 lines · Tony
Quoted 1 line · Punit Agrawal
Though, I am OK with "table-data/BERT" as well.
So I coded this up ... and it looks much better than I thought it might. A bit larger than the previous version that modified
drivers/acpi/apei/bert.c. But on the plus side easy to extend if there are other ACPI tables that point at interesting data.
Quoted 5 lines
It doesn't handle dynamic tables. That would add a lot of complexity and BERT isn't dynamic. Could be a later patch if someone has a need for it.
All names negotiable.
OK
What about /sys/firmware/acpi/tables/data/ and then one file per table under it with the same name as the table file under tables/ ?
So in particular for BERT the data would be in/sys/firmware/acpi/tables/data/BERT ?
Thanks,
Rafael
Luck, Tony
reviewerQuoted 2 lines · Rafael J. Wysocki
What about
/sys/firmware/acpi/tables/data/and then one file per table under it with the same name as the table file under tables/ ?
"data" works. ACPI table names are all upper-case, so it can't conflict. Any programs that scan the whole directory have to already skip "dynamic", so they likely would not be confused by the appearance of a second directory.
For BERT there is only one blob of data. So naming it the same as the table is fine. Maybe other tables might have more than one thing? If so, they could use the table name as a prefix, or make a subdirectory. We can cross that bridge if anyone finds additional useful things to add.
Quoted 2 lines
So in particular for BERT the data would be in
/sys/firmware/acpi/tables/data/BERT?
Ok. Will re-spin the patch with these names.
-Tony
Rafael J. Wysocki
maintainerQuoted 9 lines · Tony
Quoted 2 lines · Rafael J. Wysocki
What about
/sys/firmware/acpi/tables/data/and then one file per table under it with the same name as the table file under tables/ ?"data" works. ACPI table names are all upper-case, so it can't conflict. Any programs that scan the whole directory have to already skip "dynamic", so they likely would not be confused by the appearance of a second directory.
Quoted 5 lines
For BERT there is only one blob of data. So naming it the same as the table is fine. Maybe other tables might have more than one thing? If so, they could use the table name as a prefix, or make a subdirectory. We can cross that bridge if anyone finds additional useful things to add.
Actually, there already are multiple SSDTs on the majority of systems and the corresponding files under tables/ are called SSDT1, SSDT2 etc., so we just need to follow the existing convention.
Thanks,
Rafael
Luck, Tony
reviewerPATCH 1/1 ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
From: Tony Luck <[email protected]>
The ACPI sysfs interface provides a way to read each ACPI table from userspace via entries in /sys/firmware/acpi/tables/
The BERT table simply provides the size and address of the error record in BIOS reserved memory and users may want access to this record.
In an earlier age we might have used /dev/mem to retrieve this error record, but many systems disable /dev/mem for security reasons.
Extend this driver to provide read-only access to the data via a file in a new directory /sys/firmware/acpi/tables/data/BERT
v4: (suggested by Punit Agrawal) extend the /sys/firmware/acpi code to provide this functionality. File/directory names changed to Rafael's suggestions
--- drivers/acpi/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
drivers/acpi/sysfs.c +79 -0
@@ -306,11 +306,13 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);/* * ACPI table sysfs I/F: * /sys/firmware/acpi/tables/ +* /sys/firmware/acpi/tables-data/ * /sys/firmware/acpi/tables/dynamic/ */ static LIST_HEAD (acpi_table_attr_list);static struct kobject *tables_kobj; +static struct kobject *tables_data_kobj;static struct kobject *dynamic_tables_kobj;static struct kobject *hotplug_kobj;
@@ -325,6 +327,11 @@ struct acpi_table_attr {struct list_head node; }; +struct acpi_data_attr { +struct bin_attribute attr; +u64 addr; +}; +static ssize_t acpi_table_show (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t offset,size_t count)
@@ -420,6 +427,70 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context)return AE_OK ; } +static ssize_t acpi_data_show (struct file *filp,struct kobject *kobj, +struct bin_attribute *bin_attr,char *buf, +loff_t offset,size_t count) +{ +struct acpi_data_attr *data_attr; +void __iomem *base; +ssize_t rc; + + data_attr = container_of(bin_attr, struct acpi_data_attr, attr); + + base =acpi_os_map_memory (data_attr->addr, data_attr->attr.size); +if (!base) +return -ENOMEM ; + rc =memory_read_from_buffer (buf, count, &offset, base, + data_attr->attr.size); +acpi_os_unmap_memory (base, data_attr->attr.size); + +return rc; +} + +static int acpi_bert_data_init (void *th,struct acpi_data_attr *data_attr) +{ +struct acpi_table_bert *bert = th; + +if (bert->header.length <sizeof (struct acpi_table_bert ) || + bert->region_length <sizeof (struct acpi_hest_generic_status )) { +kfree (data_attr); +return -EINVAL ; + } + data_attr->addr = bert->address; + data_attr->attr.size = bert->region_length; + data_attr->attr.attr.name ="BERT" ; + +return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +} + +static struct acpi_data_obj { +char *name; +int (*fn)(void *,struct acpi_data_attr *); +} acpi_data_objs[] = { + {ACPI_SIG_BERT , acpi_bert_data_init }, +}; + +#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs) + +static int acpi_table_data_init (struct acpi_table_header *th) +{ +struct acpi_data_attr *data_attr; +int i; + +for (i =0 ; i <NUM_ACPI_DATA_OBJS ; i++) { +if (ACPI_COMPARE_NAME (th->signature, acpi_data_objs[i].name)) { + data_attr =kzalloc (sizeof (*data_attr),GFP_KERNEL ); +if (!data_attr) +return -ENOMEM ; +sysfs_attr_init (&data_attr->attr.attr); + data_attr->attr.read = acpi_data_show; + data_attr->attr.attr.mode =0400 ; +return acpi_data_objs[i].fn (th, data_attr); + } + } +return 0 ; +} +static int acpi_tables_sysfs_init (void ) {struct acpi_table_attr *table_attr;
@@ -432,6 +503,10 @@ static int acpi_tables_sysfs_init(void)if (!tables_kobj) goto err; + tables_data_kobj =kobject_create_and_add ("data" , tables_kobj); +if (!tables_data_kobj) + goto err_tables_data; + dynamic_tables_kobj =kobject_create_and_add ("dynamic" , tables_kobj);if (!dynamic_tables_kobj) goto err_dynamic_tables;
@@ -456,13 +531,17 @@ static int acpi_tables_sysfs_init(void)return ret; }list_add_tail (&table_attr->node, &acpi_table_attr_list); +acpi_table_data_init (table_header); }kobject_uevent (tables_kobj,KOBJ_ADD ); +kobject_uevent (tables_data_kobj,KOBJ_ADD );kobject_uevent (dynamic_tables_kobj,KOBJ_ADD );return 0 ; err_dynamic_tables: +kobject_put (tables_data_kobj); +err_tables_data:kobject_put (tables_kobj); err:return -ENOMEM ;
Signature · 1 line
2.11.0
Re: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
Quoted 9 lines · Tony
From: Tony Luck <[email protected]>
The ACPI sysfs interface provides a way to read each ACPI table from userspace via entries in
/sys/firmware/acpi/tables/The BERT table simply provides the size and address of the error record in BIOS reserved memory and users may want access to this record.
Quoted 5 lines
In an earlier age we might have used
/dev/memto retrieve this error record, but many systems disable/dev/memfor security reasons.Extend this driver to provide read-only access to the data via a file in a new directory
/sys/firmware/acpi/tables/data/BERT
Should this not also have a capability check. Assuming file permissions are sufficient for grabbing a chunk of system memory holding error info doesn't seem too scary but it's at odds with a lot of other cases ?
Alan
Luck, Tony
reviewerRE: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
Quoted 3 lines
Should this not also have a capability check. Assuming file permissions are sufficient for grabbing a chunk of system memory holding error info doesn't seem too scary but it's at odds with a lot of other cases ?
At least one of those other cases (pstore) added a capability check and now regret it. There's a thread on reverting it. Look for:
Revert "pstore: Honor dmesg_restrict sysctl on dmesg dumps"
-Tony
Re: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
In reply to Luck, TonyQuoted 35 lines · Tony
From: Tony Luck <[email protected]>
The ACPI sysfs interface provides a way to read each ACPI table from userspace via entries in
/sys/firmware/acpi/tables/The BERT table simply provides the size and address of the error record in BIOS reserved memory and users may want access to this record.
In an earlier age we might have used
/dev/memto retrieve this error record, but many systems disable/dev/memfor security reasons.Extend this driver to provide read-only access to the data via a file in a new directory
/sys/firmware/acpi/tables/data/BERTCc Len Brown <[email protected]>Cc Boris Petkov <[email protected]>Cc Tyler Baicar <[email protected]>Cc Punit Agrawal <[email protected]>Signed-off-by Tony Luck <[email protected]>v4: (suggested by Punit Agrawal) extend the
/sys/firmware/acpicode to provide this functionality. File/directory names changed to Rafael's suggestions--- drivers/acpi/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)drivers/acpi/sysfs.c +0
-0
drivers/acpi/sysfs.c module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); · line 309
Quoted 4 lines
drivers/acpi/sysfs.c +1
-0@@ -306,11 +306,13 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);/* * ACPI table sysfs I/F: * /sys/firmware/acpi/tables/ +* /sys/firmware/acpi/tables-data/
Typo: Should be "/sys/firmware/acpi/tables/data/"
Quoted 10 lines
drivers/acpi/sysfs.c +1
-0* /sys/firmware/acpi/tables/dynamic/ */ static LIST_HEAD (acpi_table_attr_list);static struct kobject *tables_kobj; +static struct kobject *tables_data_kobj;static struct kobject *dynamic_tables_kobj;static struct kobject *hotplug_kobj;
drivers/acpi/sysfs.c struct acpi_table_attr { · line 333
Quoted 7 lines
drivers/acpi/sysfs.c +4
-0@@ -325,6 +327,11 @@ struct acpi_table_attr {struct list_head node; }; +struct acpi_data_attr { +struct bin_attribute attr; +u64 addr; +};
If all we are going to need is an address, it could also be stored in the "private" member of attr (similar to how it's done in pci-sysfs.c). But it goes against usage in the rest of the file so I am fine either ways.
Quoted 94 lines
drivers/acpi/sysfs.c +70
-0+static ssize_t acpi_table_show (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t offset,size_t count)@@ -420,6 +427,70 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context)return AE_OK ; } +static ssize_t acpi_data_show (struct file *filp,struct kobject *kobj, +struct bin_attribute *bin_attr,char *buf, +loff_t offset,size_t count) +{ +struct acpi_data_attr *data_attr; +void __iomem *base; +ssize_t rc; + + data_attr = container_of(bin_attr, struct acpi_data_attr, attr); + + base =acpi_os_map_memory (data_attr->addr, data_attr->attr.size); +if (!base) +return -ENOMEM ; + rc =memory_read_from_buffer (buf, count, &offset, base, + data_attr->attr.size); +acpi_os_unmap_memory (base, data_attr->attr.size); + +return rc; +} + +static int acpi_bert_data_init (void *th,struct acpi_data_attr *data_attr) +{ +struct acpi_table_bert *bert = th; + +if (bert->header.length <sizeof (struct acpi_table_bert ) || + bert->region_length <sizeof (struct acpi_hest_generic_status )) { +kfree (data_attr); +return -EINVAL ; + } + data_attr->addr = bert->address; + data_attr->attr.size = bert->region_length; + data_attr->attr.attr.name ="BERT" ; + +return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +} + +static struct acpi_data_obj { +char *name; +int (*fn)(void *,struct acpi_data_attr *); +} acpi_data_objs[] = { + {ACPI_SIG_BERT , acpi_bert_data_init }, +}; + +#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs) + +static int acpi_table_data_init (struct acpi_table_header *th) +{ +struct acpi_data_attr *data_attr; +int i; + +for (i =0 ; i <NUM_ACPI_DATA_OBJS ; i++) { +if (ACPI_COMPARE_NAME (th->signature, acpi_data_objs[i].name)) { + data_attr =kzalloc (sizeof (*data_attr),GFP_KERNEL ); +if (!data_attr) +return -ENOMEM ; +sysfs_attr_init (&data_attr->attr.attr); + data_attr->attr.read = acpi_data_show; + data_attr->attr.attr.mode =0400 ; +return acpi_data_objs[i].fn (th, data_attr); + } + } +return 0 ; +} +static int acpi_tables_sysfs_init (void ) {struct acpi_table_attr *table_attr;@@ -432,6 +503,10 @@ static int acpi_tables_sysfs_init(void)if (!tables_kobj) goto err; + tables_data_kobj =kobject_create_and_add ("data" , tables_kobj); +if (!tables_data_kobj) + goto err_tables_data; + dynamic_tables_kobj =kobject_create_and_add ("dynamic" , tables_kobj);if (!dynamic_tables_kobj) goto err_dynamic_tables;@@ -456,13 +531,17 @@ static int acpi_tables_sysfs_init(void)return ret; }list_add_tail (&table_attr->node, &acpi_table_attr_list); +acpi_table_data_init (table_header); }kobject_uevent (tables_kobj,KOBJ_ADD );
drivers/acpi/sysfs.c static int acpi_tables_sysfs_init(void) · line 547
Quoted 10 lines
drivers/acpi/sysfs.c +3
-0+kobject_uevent (tables_data_kobj,KOBJ_ADD );kobject_uevent (dynamic_tables_kobj,KOBJ_ADD );return 0 ; err_dynamic_tables: +kobject_put (tables_data_kobj); +err_tables_data:kobject_put (tables_kobj); err:return -ENOMEM ;
I like how this fits into existing infrastructure.
With the typo addressed -
Thanks,
Punit
Luck, Tony
reviewerPATCH v4 1/1 ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
From: Tony Luck <[email protected]>
The ACPI sysfs interface provides a way to read each ACPI table from userspace via entries in /sys/firmware/acpi/tables/
The BERT table simply provides the size and address of the error record in BIOS reserved memory and users may want access to this record.
In an earlier age we might have used /dev/mem to retrieve this error record, but many systems disable /dev/mem for security reasons.
Extend this driver to provide read-only access to the data via a file in a new directory /sys/firmware/acpi/tables/data/BERT
v4: fix typo reported by Punit
--- drivers/acpi/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
drivers/acpi/sysfs.c +79 -0
@@ -306,11 +306,13 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);/* * ACPI table sysfs I/F: * /sys/firmware/acpi/tables/ +* /sys/firmware/acpi/tables/data/ * /sys/firmware/acpi/tables/dynamic/ */ static LIST_HEAD (acpi_table_attr_list);static struct kobject *tables_kobj; +static struct kobject *tables_data_kobj;static struct kobject *dynamic_tables_kobj;static struct kobject *hotplug_kobj;
@@ -325,6 +327,11 @@ struct acpi_table_attr {struct list_head node; }; +struct acpi_data_attr { +struct bin_attribute attr; +u64 addr; +}; +static ssize_t acpi_table_show (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t offset,size_t count)
@@ -420,6 +427,70 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context)return AE_OK ; } +static ssize_t acpi_data_show (struct file *filp,struct kobject *kobj, +struct bin_attribute *bin_attr,char *buf, +loff_t offset,size_t count) +{ +struct acpi_data_attr *data_attr; +void __iomem *base; +ssize_t rc; + + data_attr = container_of(bin_attr, struct acpi_data_attr, attr); + + base =acpi_os_map_memory (data_attr->addr, data_attr->attr.size); +if (!base) +return -ENOMEM ; + rc =memory_read_from_buffer (buf, count, &offset, base, + data_attr->attr.size); +acpi_os_unmap_memory (base, data_attr->attr.size); + +return rc; +} + +static int acpi_bert_data_init (void *th,struct acpi_data_attr *data_attr) +{ +struct acpi_table_bert *bert = th; + +if (bert->header.length <sizeof (struct acpi_table_bert ) || + bert->region_length <sizeof (struct acpi_hest_generic_status )) { +kfree (data_attr); +return -EINVAL ; + } + data_attr->addr = bert->address; + data_attr->attr.size = bert->region_length; + data_attr->attr.attr.name ="BERT" ; + +return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +} + +static struct acpi_data_obj { +char *name; +int (*fn)(void *,struct acpi_data_attr *); +} acpi_data_objs[] = { + {ACPI_SIG_BERT , acpi_bert_data_init }, +}; + +#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs) + +static int acpi_table_data_init (struct acpi_table_header *th) +{ +struct acpi_data_attr *data_attr; +int i; + +for (i =0 ; i <NUM_ACPI_DATA_OBJS ; i++) { +if (ACPI_COMPARE_NAME (th->signature, acpi_data_objs[i].name)) { + data_attr =kzalloc (sizeof (*data_attr),GFP_KERNEL ); +if (!data_attr) +return -ENOMEM ; +sysfs_attr_init (&data_attr->attr.attr); + data_attr->attr.read = acpi_data_show; + data_attr->attr.attr.mode =0400 ; +return acpi_data_objs[i].fn (th, data_attr); + } + } +return 0 ; +} +static int acpi_tables_sysfs_init (void ) {struct acpi_table_attr *table_attr;
@@ -432,6 +503,10 @@ static int acpi_tables_sysfs_init(void)if (!tables_kobj) goto err; + tables_data_kobj =kobject_create_and_add ("data" , tables_kobj); +if (!tables_data_kobj) + goto err_tables_data; + dynamic_tables_kobj =kobject_create_and_add ("dynamic" , tables_kobj);if (!dynamic_tables_kobj) goto err_dynamic_tables;
@@ -456,13 +531,17 @@ static int acpi_tables_sysfs_init(void)return ret; }list_add_tail (&table_attr->node, &acpi_table_attr_list); +acpi_table_data_init (table_header); }kobject_uevent (tables_kobj,KOBJ_ADD ); +kobject_uevent (tables_data_kobj,KOBJ_ADD );kobject_uevent (dynamic_tables_kobj,KOBJ_ADD );return 0 ; err_dynamic_tables: +kobject_put (tables_data_kobj); +err_tables_data:kobject_put (tables_kobj); err:return -ENOMEM ;
Signature · 1 line
2.11.0
Luck, Tony
reviewerRE: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
In reply to Alan CoxQuoted 8 lines
Quoted 3 lines
Should this not also have a capability check. Assuming file permissions are sufficient for grabbing a chunk of system memory holding error info doesn't seem too scary but it's at odds with a lot of other cases ?
At least one of those other cases (pstore) added a capability check and now regret it. There's a thread on reverting it. Look for:
Revert "pstore: Honor
dmesg_restrictsysctl on dmesg dumps"
Here's at least part of that thread:
https://marc.info/?l=linux-kernel&m=150301241114262&w=2
Kees: you were OK with removing the capability check from pstore, right?
I'm now adding another place to access a blob of memory containing crash information from the previous kernel (pointed at by the ACPI BERT record).
-Tony
Rafael J. Wysocki
AppliedRe: [PATCH v4] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
In reply to Luck, TonyQuoted 149 lines · Tony
From: Tony Luck <[email protected]>
The ACPI sysfs interface provides a way to read each ACPI table from userspace via entries in
/sys/firmware/acpi/tables/The BERT table simply provides the size and address of the error record in BIOS reserved memory and users may want access to this record.
In an earlier age we might have used
/dev/memto retrieve this error record, but many systems disable/dev/memfor security reasons.Extend this driver to provide read-only access to the data via a file in a new directory
/sys/firmware/acpi/tables/data/BERTCc Len Brown <[email protected]>Cc Boris Petkov <[email protected]>Cc Tyler Baicar <[email protected]>Acked-by Punit Agrawal <[email protected]>Signed-off-by Tony Luck <[email protected]>v4: fix typo reported by Punit
--- drivers/acpi/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)drivers/acpi/sysfs.c +76
-0@@ -306,11 +306,13 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);/* * ACPI table sysfs I/F: * /sys/firmware/acpi/tables/ +* /sys/firmware/acpi/tables/data/ * /sys/firmware/acpi/tables/dynamic/ */ static LIST_HEAD (acpi_table_attr_list);static struct kobject *tables_kobj; +static struct kobject *tables_data_kobj;static struct kobject *dynamic_tables_kobj;static struct kobject *hotplug_kobj;@@ -325,6 +327,11 @@ struct acpi_table_attr {struct list_head node; }; +struct acpi_data_attr { +struct bin_attribute attr; +u64 addr; +}; +static ssize_t acpi_table_show (struct file *filp,struct kobject *kobj,struct bin_attribute *bin_attr,char *buf,loff_t offset,size_t count)@@ -420,6 +427,70 @@ acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context)return AE_OK ; } +static ssize_t acpi_data_show (struct file *filp,struct kobject *kobj, +struct bin_attribute *bin_attr,char *buf, +loff_t offset,size_t count) +{ +struct acpi_data_attr *data_attr; +void __iomem *base; +ssize_t rc; + + data_attr = container_of(bin_attr, struct acpi_data_attr, attr); + + base =acpi_os_map_memory (data_attr->addr, data_attr->attr.size); +if (!base) +return -ENOMEM ; + rc =memory_read_from_buffer (buf, count, &offset, base, + data_attr->attr.size); +acpi_os_unmap_memory (base, data_attr->attr.size); + +return rc; +} + +static int acpi_bert_data_init (void *th,struct acpi_data_attr *data_attr) +{ +struct acpi_table_bert *bert = th; + +if (bert->header.length <sizeof (struct acpi_table_bert ) || + bert->region_length <sizeof (struct acpi_hest_generic_status )) { +kfree (data_attr); +return -EINVAL ; + } + data_attr->addr = bert->address; + data_attr->attr.size = bert->region_length; + data_attr->attr.attr.name ="BERT" ; + +return sysfs_create_bin_file (tables_data_kobj, &data_attr->attr); +} + +static struct acpi_data_obj { +char *name; +int (*fn)(void *,struct acpi_data_attr *); +} acpi_data_objs[] = { + {ACPI_SIG_BERT , acpi_bert_data_init }, +}; + +#define NUM_ACPI_DATA_OBJS ARRAY_SIZE(acpi_data_objs) + +static int acpi_table_data_init (struct acpi_table_header *th) +{ +struct acpi_data_attr *data_attr; +int i; + +for (i =0 ; i <NUM_ACPI_DATA_OBJS ; i++) { +if (ACPI_COMPARE_NAME (th->signature, acpi_data_objs[i].name)) { + data_attr =kzalloc (sizeof (*data_attr),GFP_KERNEL ); +if (!data_attr) +return -ENOMEM ; +sysfs_attr_init (&data_attr->attr.attr); + data_attr->attr.read = acpi_data_show; + data_attr->attr.attr.mode =0400 ; +return acpi_data_objs[i].fn (th, data_attr); + } + } +return 0 ; +} +static int acpi_tables_sysfs_init (void ) {struct acpi_table_attr *table_attr;@@ -432,6 +503,10 @@ static int acpi_tables_sysfs_init(void)if (!tables_kobj) goto err; + tables_data_kobj =kobject_create_and_add ("data" , tables_kobj); +if (!tables_data_kobj) + goto err_tables_data; + dynamic_tables_kobj =kobject_create_and_add ("dynamic" , tables_kobj);if (!dynamic_tables_kobj) goto err_dynamic_tables;@@ -456,13 +531,17 @@ static int acpi_tables_sysfs_init(void)return ret; }list_add_tail (&table_attr->node, &acpi_table_attr_list); +acpi_table_data_init (table_header); }kobject_uevent (tables_kobj,KOBJ_ADD );
drivers/acpi/sysfs.c static int acpi_tables_sysfs_init(void) · line 547
Quoted 10 lines
drivers/acpi/sysfs.c +3
-0+kobject_uevent (tables_data_kobj,KOBJ_ADD );kobject_uevent (dynamic_tables_kobj,KOBJ_ADD );return 0 ; err_dynamic_tables: +kobject_put (tables_data_kobj); +err_tables_data:kobject_put (tables_kobj); err:return -ENOMEM ;
Applied, thanks!
Re: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
In reply to Luck, TonyQuoted 7 lines · Tony
Quoted 7 lines
Quoted 3 lines
Should this not also have a capability check. Assuming file permissions are sufficient for grabbing a chunk of system memory holding error info doesn't seem too scary but it's at odds with a lot of other cases ?
At least one of those other cases (pstore) added a capability check and now regret it. There's a thread on reverting it. Look for:
Quoted 7 lines
Quoted 1 line
Revert "pstore: Honor
dmesg_restrictsysctl on dmesg dumps"Here's at least part of that thread:
https://marc.info/?l=linux-kernel&m=150301241114262&w=2
Kees: you were OK with removing the capability check from pstore, right?
Yeah, as long as there is comparable protections.
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Luck, Tony
reviewerRe: [PATCH] ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
Quoted 10 lines · Kees Cook
Quoted 9 lines · Tony
Quoted 8 lines
Quoted 3 lines
Should this not also have a capability check. Assuming file permissions are sufficient for grabbing a chunk of system memory holding error info doesn't seem too scary but it's at odds with a lot of other cases ?
At least one of those other cases (pstore) added a capability check and now regret it. There's a thread on reverting it. Look for:
Revert "pstore: Honor
dmesg_restrictsysctl on dmesg dumps"
Quoted 7 lines
Quoted 5 lines
Here's at least part of that thread:
https://marc.info/?l=linux-kernel&m=150301241114262&w=2
Kees: you were OK with removing the capability check from pstore, right?
Yeah, as long as there is comparable protections.
File system permission protection is "0400":
# ls -al /sys/firmware/acpi/tables/data total 0 drwxr-xr-x. 2 root root 0 Aug 28 14:13 . drwxr-xr-x. 4 root root 0 Aug 28 14:10 .. -r--------. 1 root root 32768 Aug 28 14:13 BERT
-Tony