All of lore.kernel.org
 help / color / mirror / Atom feed
* [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs
@ 2017-03-29 23:28 Matt Brown
  2017-04-06  7:07 ` Oliver O'Halloran
  2017-04-06 13:06 ` Michael Ellerman
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Brown @ 2017-03-29 23:28 UTC (permalink / raw)
  To: linuxppc-dev

The HDAT data area is consumed by skiboot and turned into a device-tree. In
some cases we would like to look directly at the HDAT. This is not possible
through /dev/mem as it is reserved memory which is stopped by the /dev/mem
filter. There are also other memory areas which are reserved but could be
useful to view for debugging purposes.

This patch adds sysfs nodes to allow specified memory areas to be viewed.
sysfs nodes are created for each property in the device-tree under
/ibm,opal/firmware/exports/, and adds them to /sys/firmware/opal/exports/
with root read-only permissions.

Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
---
Changelog
v8
	- fixed error handling
	- added dynamic allocation of attributes
	- using of_property_read_u64_array for reading attr vals
	- reordered vars
	- renaming vars
---
 arch/powerpc/platforms/powernv/opal.c | 81 +++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 2822935..232f94e 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -604,6 +604,84 @@ static void opal_export_symmap(void)
 		pr_warn("Error %d creating OPAL symbols file\n", rc);
 }
 
+static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
+			     struct bin_attribute *bin_attr, char *buf,
+			     loff_t off, size_t count)
+{
+	return memory_read_from_buffer(buf, count, &off, bin_attr->private,
+				       bin_attr->size);
+}
+
+/*
+ * opal_export_attrs: creates a sysfs node for each property listed in
+ * the device-tree under /ibm,opal/firmware/exports/
+ * All new sysfs nodes are created under /opal/exports/.
+ * This allows for reserved memory regions (e.g. HDAT) to be read.
+ * The new sysfs nodes are only readable by root.
+ */
+static void opal_export_attrs(void)
+{
+	struct bin_attribute *attr_tmp;
+	struct device_node *np;
+	struct property *prop;
+	struct kobject *kobj;
+	u64 vals[2];
+	int rc, n;
+
+	/* Create new 'exports' directory - /sys/firmware/opal/exports */
+	kobj = kobject_create_and_add("exports", opal_kobj);
+	if (!kobj) {
+		pr_warn("kobject_create_and_add exports failed\n");
+		return;
+	}
+
+	np = of_find_node_by_path("/ibm,opal/firmware/exports");
+	if (!np)
+		return;
+
+	n = 0;
+	for (prop = np->properties; prop != NULL; prop = prop->next)
+		n++;
+
+	if (n < 2)
+		goto cleanup;
+
+	for_each_property_of_node(np, prop) {
+		if (!strcmp(prop->name, "name") ||
+				!strcmp(prop->name, "phandle"))
+			continue;
+
+		if (of_property_read_u64_array(np, prop->name, &vals[0], 2))
+			continue;
+
+		attr_tmp = kmalloc(sizeof(*attr_tmp), GFP_KERNEL);
+
+		if (attr_tmp == NULL) {
+			pr_warn("Failed kmalloc for bin_attribute attr_tmp");
+			continue;
+		}
+
+		attr_tmp->attr.name = kstrdup(prop->name, GFP_KERNEL);
+		attr_tmp->attr.mode = 0400;
+		attr_tmp->read = export_attr_read;
+		attr_tmp->private = __va(vals[0]);
+		attr_tmp->size = vals[1];
+
+		if (attr_tmp->attr.name == NULL) {
+			pr_warn("Failed kstrdup for bin_attribute attr.name");
+			kfree(attr_tmp);
+			continue;
+		}
+		rc = sysfs_create_bin_file(kobj, attr_tmp);
+		if (rc)
+			pr_warn("Error %d creating OPAL sysfs exports/%s file\n",
+				      rc, prop->name);
+	}
+
+cleanup:
+	of_node_put(np);
+}
+
 static void __init opal_dump_region_init(void)
 {
 	void *addr;
@@ -742,6 +820,9 @@ static int __init opal_init(void)
 		opal_msglog_sysfs_init();
 	}
 
+	/* Export all properties */
+	opal_export_attrs();
+
 	/* Initialize platform devices: IPMI backend, PRD & flash interface */
 	opal_pdev_init("ibm,opal-ipmi");
 	opal_pdev_init("ibm,opal-flash");
-- 
2.9.3

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

* Re: [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs
  2017-03-29 23:28 [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs Matt Brown
@ 2017-04-06  7:07 ` Oliver O'Halloran
  2017-04-10  5:30   ` Joel Stanley
  2017-04-06 13:06 ` Michael Ellerman
  1 sibling, 1 reply; 4+ messages in thread
From: Oliver O'Halloran @ 2017-04-06  7:07 UTC (permalink / raw)
  To: Matt Brown; +Cc: linuxppc-dev

On Thu, Mar 30, 2017 at 10:28 AM, Matt Brown
<matthew.brown.dev@gmail.com> wrote:
> The HDAT data area is consumed by skiboot and turned into a device-tree. In
> some cases we would like to look directly at the HDAT. This is not possible
> through /dev/mem as it is reserved memory which is stopped by the /dev/mem
> filter. There are also other memory areas which are reserved but could be
> useful to view for debugging purposes.
>
> This patch adds sysfs nodes to allow specified memory areas to be viewed.
> sysfs nodes are created for each property in the device-tree under
> /ibm,opal/firmware/exports/, and adds them to /sys/firmware/opal/exports/
> with root read-only permissions.
>
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>
> ---
> Changelog
> v8
>         - fixed error handling
>         - added dynamic allocation of attributes
>         - using of_property_read_u64_array for reading attr vals
>         - reordered vars
>         - renaming vars
> ---
>  arch/powerpc/platforms/powernv/opal.c | 81 +++++++++++++++++++++++++++++++++++
>  1 file changed, 81 insertions(+)
>
> diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
> index 2822935..232f94e 100644
> --- a/arch/powerpc/platforms/powernv/opal.c
> +++ b/arch/powerpc/platforms/powernv/opal.c
> @@ -604,6 +604,84 @@ static void opal_export_symmap(void)
>                 pr_warn("Error %d creating OPAL symbols file\n", rc);
>  }
>
> +static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
> +                            struct bin_attribute *bin_attr, char *buf,
> +                            loff_t off, size_t count)
> +{
> +       return memory_read_from_buffer(buf, count, &off, bin_attr->private,
> +                                      bin_attr->size);
> +}
> +
> +/*
> + * opal_export_attrs: creates a sysfs node for each property listed in
> + * the device-tree under /ibm,opal/firmware/exports/
> + * All new sysfs nodes are created under /opal/exports/.
> + * This allows for reserved memory regions (e.g. HDAT) to be read.
> + * The new sysfs nodes are only readable by root.
> + */
> +static void opal_export_attrs(void)
> +{
> +       struct bin_attribute *attr_tmp;
> +       struct device_node *np;
> +       struct property *prop;
> +       struct kobject *kobj;
> +       u64 vals[2];
> +       int rc, n;
> +
> +       /* Create new 'exports' directory - /sys/firmware/opal/exports */
> +       kobj = kobject_create_and_add("exports", opal_kobj);
> +       if (!kobj) {
> +               pr_warn("kobject_create_and_add exports failed\n");
> +               return;
> +       }
> +
> +       np = of_find_node_by_path("/ibm,opal/firmware/exports");
> +       if (!np)
> +               return;
> +
> +       n = 0;
> +       for (prop = np->properties; prop != NULL; prop = prop->next)
> +               n++;
> +
> +       if (n < 2)
> +               goto cleanup;
> +
> +       for_each_property_of_node(np, prop) {
> +               if (!strcmp(prop->name, "name") ||
> +                               !strcmp(prop->name, "phandle"))
> +                       continue;
> +
> +               if (of_property_read_u64_array(np, prop->name, &vals[0], 2))
> +                       continue;
> +
> +               attr_tmp = kmalloc(sizeof(*attr_tmp), GFP_KERNEL);
> +
> +               if (attr_tmp == NULL) {
> +                       pr_warn("Failed kmalloc for bin_attribute attr_tmp");
> +                       continue;
> +               }
> +
> +               attr_tmp->attr.name = kstrdup(prop->name, GFP_KERNEL);
> +               attr_tmp->attr.mode = 0400;
> +               attr_tmp->read = export_attr_read;
> +               attr_tmp->private = __va(vals[0]);
> +               attr_tmp->size = vals[1];
> +
> +               if (attr_tmp->attr.name == NULL) {
> +                       pr_warn("Failed kstrdup for bin_attribute attr.name");
> +                       kfree(attr_tmp);
> +                       continue;
> +               }
> +               rc = sysfs_create_bin_file(kobj, attr_tmp);
> +               if (rc)
> +                       pr_warn("Error %d creating OPAL sysfs exports/%s file\n",
> +                                     rc, prop->name);
> +       }
> +
> +cleanup:
> +       of_node_put(np);
> +}
> +
>  static void __init opal_dump_region_init(void)
>  {
>         void *addr;
> @@ -742,6 +820,9 @@ static int __init opal_init(void)
>                 opal_msglog_sysfs_init();
>         }
>
> +       /* Export all properties */
> +       opal_export_attrs();
> +
>         /* Initialize platform devices: IPMI backend, PRD & flash interface */
>         opal_pdev_init("ibm,opal-ipmi");
>         opal_pdev_init("ibm,opal-flash");
> --
> 2.9.3
>

Reviewed-by: Oliver O'Halloran <oohall@gmail.com>

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

* Re: [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs
  2017-03-29 23:28 [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs Matt Brown
  2017-04-06  7:07 ` Oliver O'Halloran
@ 2017-04-06 13:06 ` Michael Ellerman
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2017-04-06 13:06 UTC (permalink / raw)
  To: Matt Brown, linuxppc-dev

On Wed, 2017-03-29 at 23:28:01 UTC, Matt Brown wrote:
> The HDAT data area is consumed by skiboot and turned into a device-tree. In
> some cases we would like to look directly at the HDAT. This is not possible
> through /dev/mem as it is reserved memory which is stopped by the /dev/mem
> filter. There are also other memory areas which are reserved but could be
> useful to view for debugging purposes.
> 
> This patch adds sysfs nodes to allow specified memory areas to be viewed.
> sysfs nodes are created for each property in the device-tree under
> /ibm,opal/firmware/exports/, and adds them to /sys/firmware/opal/exports/
> with root read-only permissions.
> 
> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/11fe909d236263f62808dc3c73caf7

cheers

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

* Re: [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs
  2017-04-06  7:07 ` Oliver O'Halloran
@ 2017-04-10  5:30   ` Joel Stanley
  0 siblings, 0 replies; 4+ messages in thread
From: Joel Stanley @ 2017-04-10  5:30 UTC (permalink / raw)
  To: Oliver O'Halloran; +Cc: Matt Brown, linuxppc-dev

On Thu, Apr 6, 2017 at 4:37 PM, Oliver O'Halloran <oohall@gmail.com> wrote:
> On Thu, Mar 30, 2017 at 10:28 AM, Matt Brown
> <matthew.brown.dev@gmail.com> wrote:
>> The HDAT data area is consumed by skiboot and turned into a device-tree. In
>> some cases we would like to look directly at the HDAT. This is not possible
>> through /dev/mem as it is reserved memory which is stopped by the /dev/mem
>> filter. There are also other memory areas which are reserved but could be
>> useful to view for debugging purposes.
>>
>> This patch adds sysfs nodes to allow specified memory areas to be viewed.
>> sysfs nodes are created for each property in the device-tree under
>> /ibm,opal/firmware/exports/, and adds them to /sys/firmware/opal/exports/
>> with root read-only permissions.
>>
>> Signed-off-by: Matt Brown <matthew.brown.dev@gmail.com>

Thanks. I took the version that mpe put in the powerpc tree. It is
part of the 4.10.9-openpower1 kernel.

  https://github.com/open-power/op-build/pull/1016

Cheers,

Joel

>> ---
>> Changelog
>> v8
>>         - fixed error handling
>>         - added dynamic allocation of attributes
>>         - using of_property_read_u64_array for reading attr vals
>>         - reordered vars
>>         - renaming vars
>> ---
>>  arch/powerpc/platforms/powernv/opal.c | 81 +++++++++++++++++++++++++++++++++++
>>  1 file changed, 81 insertions(+)
>>
>> diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
>> index 2822935..232f94e 100644
>> --- a/arch/powerpc/platforms/powernv/opal.c
>> +++ b/arch/powerpc/platforms/powernv/opal.c
>> @@ -604,6 +604,84 @@ static void opal_export_symmap(void)
>>                 pr_warn("Error %d creating OPAL symbols file\n", rc);
>>  }
>>
>> +static ssize_t export_attr_read(struct file *fp, struct kobject *kobj,
>> +                            struct bin_attribute *bin_attr, char *buf,
>> +                            loff_t off, size_t count)
>> +{
>> +       return memory_read_from_buffer(buf, count, &off, bin_attr->private,
>> +                                      bin_attr->size);
>> +}
>> +
>> +/*
>> + * opal_export_attrs: creates a sysfs node for each property listed in
>> + * the device-tree under /ibm,opal/firmware/exports/
>> + * All new sysfs nodes are created under /opal/exports/.
>> + * This allows for reserved memory regions (e.g. HDAT) to be read.
>> + * The new sysfs nodes are only readable by root.
>> + */
>> +static void opal_export_attrs(void)
>> +{
>> +       struct bin_attribute *attr_tmp;
>> +       struct device_node *np;
>> +       struct property *prop;
>> +       struct kobject *kobj;
>> +       u64 vals[2];
>> +       int rc, n;
>> +
>> +       /* Create new 'exports' directory - /sys/firmware/opal/exports */
>> +       kobj = kobject_create_and_add("exports", opal_kobj);
>> +       if (!kobj) {
>> +               pr_warn("kobject_create_and_add exports failed\n");
>> +               return;
>> +       }
>> +
>> +       np = of_find_node_by_path("/ibm,opal/firmware/exports");
>> +       if (!np)
>> +               return;
>> +
>> +       n = 0;
>> +       for (prop = np->properties; prop != NULL; prop = prop->next)
>> +               n++;
>> +
>> +       if (n < 2)
>> +               goto cleanup;
>> +
>> +       for_each_property_of_node(np, prop) {
>> +               if (!strcmp(prop->name, "name") ||
>> +                               !strcmp(prop->name, "phandle"))
>> +                       continue;
>> +
>> +               if (of_property_read_u64_array(np, prop->name, &vals[0], 2))
>> +                       continue;
>> +
>> +               attr_tmp = kmalloc(sizeof(*attr_tmp), GFP_KERNEL);
>> +
>> +               if (attr_tmp == NULL) {
>> +                       pr_warn("Failed kmalloc for bin_attribute attr_tmp");
>> +                       continue;
>> +               }
>> +
>> +               attr_tmp->attr.name = kstrdup(prop->name, GFP_KERNEL);
>> +               attr_tmp->attr.mode = 0400;
>> +               attr_tmp->read = export_attr_read;
>> +               attr_tmp->private = __va(vals[0]);
>> +               attr_tmp->size = vals[1];
>> +
>> +               if (attr_tmp->attr.name == NULL) {
>> +                       pr_warn("Failed kstrdup for bin_attribute attr.name");
>> +                       kfree(attr_tmp);
>> +                       continue;
>> +               }
>> +               rc = sysfs_create_bin_file(kobj, attr_tmp);
>> +               if (rc)
>> +                       pr_warn("Error %d creating OPAL sysfs exports/%s file\n",
>> +                                     rc, prop->name);
>> +       }
>> +
>> +cleanup:
>> +       of_node_put(np);
>> +}
>> +
>>  static void __init opal_dump_region_init(void)
>>  {
>>         void *addr;
>> @@ -742,6 +820,9 @@ static int __init opal_init(void)
>>                 opal_msglog_sysfs_init();
>>         }
>>
>> +       /* Export all properties */
>> +       opal_export_attrs();
>> +
>>         /* Initialize platform devices: IPMI backend, PRD & flash interface */
>>         opal_pdev_init("ibm,opal-ipmi");
>>         opal_pdev_init("ibm,opal-flash");
>> --
>> 2.9.3
>>
>
> Reviewed-by: Oliver O'Halloran <oohall@gmail.com>

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

end of thread, other threads:[~2017-04-10  5:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 23:28 [v8] powerpc/powernv: add 'firmware/exports' attributes to sysfs Matt Brown
2017-04-06  7:07 ` Oliver O'Halloran
2017-04-10  5:30   ` Joel Stanley
2017-04-06 13:06 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.