linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] dmi-id: export oem strings to sysfs
@ 2016-07-14  8:01 Allen Hung
  2016-07-14  8:01 ` [PATCH 1/2] dmi-id: don't free dev structure after calling device_register Allen Hung
  2016-07-14  8:01 ` [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs Allen Hung
  0 siblings, 2 replies; 14+ messages in thread
From: Allen Hung @ 2016-07-14  8:01 UTC (permalink / raw)
  To: Jean Delvare, linux-kernel; +Cc: Mario Limonciello, Allen Hung

*** BLURB HERE ***

Allen Hung (2):
  dmi-id: don't free dev structure after calling device_register
  dmi-id: add dmi/id/oem group for exporting oem strings to sysfs

 drivers/firmware/dmi-id.c | 116 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 112 insertions(+), 4 deletions(-)

-- 
2.7.4

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

* [PATCH 1/2] dmi-id: don't free dev structure after calling device_register
  2016-07-14  8:01 [PATCH 0/2] dmi-id: export oem strings to sysfs Allen Hung
@ 2016-07-14  8:01 ` Allen Hung
  2016-07-18 17:09   ` Jean Delvare
  2016-07-14  8:01 ` [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs Allen Hung
  1 sibling, 1 reply; 14+ messages in thread
From: Allen Hung @ 2016-07-14  8:01 UTC (permalink / raw)
  To: Jean Delvare, linux-kernel; +Cc: Mario Limonciello, Allen Hung

dmi_dev is freed in error exit code but, according to the document
of device_register, it should never directly free device structure
after calling this function, even if it returned an error! Use
put_device() instead.

Signed-off-by: Allen Hung <allen_hung@dell.com>
---
 drivers/firmware/dmi-id.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
index 94a58a0..44c0139 100644
--- a/drivers/firmware/dmi-id.c
+++ b/drivers/firmware/dmi-id.c
@@ -229,14 +229,14 @@ static int __init dmi_id_init(void)
 
 	ret = device_register(dmi_dev);
 	if (ret)
-		goto fail_free_dmi_dev;
+		goto fail_put_dmi_dev;
 
 	return 0;
 
-fail_free_dmi_dev:
-	kfree(dmi_dev);
-fail_class_unregister:
+fail_put_dmi_dev:
+	put_device(dmi_dev);
 
+fail_class_unregister:
 	class_unregister(&dmi_class);
 
 	return ret;
-- 
2.7.4

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

* [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-14  8:01 [PATCH 0/2] dmi-id: export oem strings to sysfs Allen Hung
  2016-07-14  8:01 ` [PATCH 1/2] dmi-id: don't free dev structure after calling device_register Allen Hung
@ 2016-07-14  8:01 ` Allen Hung
  2016-07-14  9:16   ` kbuild test robot
  2016-07-19  9:03   ` Jean Delvare
  1 sibling, 2 replies; 14+ messages in thread
From: Allen Hung @ 2016-07-14  8:01 UTC (permalink / raw)
  To: Jean Delvare, linux-kernel; +Cc: Mario Limonciello, Allen Hung

The oem strings in DMI system identification information of the BIOS have
been parsed and stored as dmi devices in dmi_scan.c but they are not
exported to userspace via sysfs.

The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
As the number of oem strings are dynamic, a group "oem" is added to the
device and the strings will be added to the group as string1, string2, ...,
and stringN.

Signed-off-by: Allen Hung <allen_hung@dell.com>
---
 drivers/firmware/dmi-id.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
index 44c0139..f284a07 100644
--- a/drivers/firmware/dmi-id.c
+++ b/drivers/firmware/dmi-id.c
@@ -58,6 +58,107 @@ DEFINE_DMI_ATTR_WITH_SHOW(chassis_version,	0444, DMI_CHASSIS_VERSION);
 DEFINE_DMI_ATTR_WITH_SHOW(chassis_serial,	0400, DMI_CHASSIS_SERIAL);
 DEFINE_DMI_ATTR_WITH_SHOW(chassis_asset_tag,	0444, DMI_CHASSIS_ASSET_TAG);
 
+static struct attribute *dmi_oem_attrs[] = {
+	NULL,
+};
+
+static const char oem_group[] = "oem";
+
+static struct attribute_group dmi_oem_attr_group = {
+	.attrs = dmi_oem_attrs,
+	.name  = oem_group,
+};
+
+static LIST_HEAD(dmi_oem_attrs_list);
+
+struct dmi_oem_attribute {
+	struct device_attribute dev_attr;
+	const char *oem_string;
+	char buf[32];
+	bool is_added:1;
+	struct list_head list;
+};
+
+#define to_dmi_oem_attr(_dev_attr) \
+	container_of(_dev_attr, struct dmi_oem_attribute, dev_attr)
+
+static ssize_t sys_dmi_oem_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *page)
+{
+	struct dmi_oem_attribute *oa = to_dmi_oem_attr(attr);
+	ssize_t len;
+
+	strlcpy(page, oa->oem_string, PAGE_SIZE-1);
+	len = strlen(page);
+	page[len++] = '\n';
+	page[len] = 0;
+	return len;
+}
+
+static int __init dmi_id_init_oem_attr_group(void)
+{
+	int i, ret;
+	const struct dmi_device *dev;
+	struct dmi_oem_attribute *oa, *tmp;
+	struct device_attribute dev_attr_tmpl =
+		__ATTR(, 0444, sys_dmi_oem_show, NULL);
+
+	ret = sysfs_create_group(&dmi_dev->kobj, &dmi_oem_attr_group);
+	if (ret)
+		return ret;
+
+	/* All devices with type=DMI_DEV_TYPE_OEM_STRING will be found in
+	 * the reverse order of what they were parsed in dmi_scan.c. However,
+	 * we do want to expose the OEM strings to sysfs in the same order as
+	 * what they were originally parsed. A linked list with 2-pass method
+	 * is used here to reverse the reserved order.
+	 *
+	 * Pass 1: find out all "OEM string" devices and add each "oem string"
+	 * to a linked list.
+	 */
+	dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, NULL);
+	while (dev)  {
+		oa = kzalloc(sizeof(*oa), GFP_KERNEL);
+		if (!oa) {
+			ret = -ENOMEM;
+			goto failed;
+		}
+		oa->dev_attr = dev_attr_tmpl;
+		oa->oem_string = dev->name;
+		list_add(&oa->list, &dmi_oem_attrs_list);
+		dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev);
+	}
+
+	/* Pass 2: traverse the list and add each string as a file to "oem"
+	 * group
+	 */
+	i = 0;
+	list_for_each_entry(oa, &dmi_oem_attrs_list, list) {
+		snprintf(oa->buf, sizeof(oa->buf), "string%d", ++i);
+		oa->dev_attr.attr.name = oa->buf;
+		ret = sysfs_add_file_to_group(
+			&dmi_dev->kobj, &oa->dev_attr.attr, oem_group);
+		if (ret)
+			goto failed;
+		oa->is_added = 1;
+	}
+
+	return 0;
+
+failed:
+	list_for_each_entry_safe(oa, tmp, &dmi_oem_attrs_list, list) {
+		if (oa->is_added)
+			sysfs_remove_file_from_group(
+				&dmi_dev->kobj,	&oa->dev_attr.attr, oem_group);
+		list_del(&oa->list);
+		kfree(oa);
+	}
+	sysfs_remove_group(&dmi_dev->kobj, &dmi_oem_attr_group);
+
+	return ret;
+}
+
 static void ascii_filter(char *d, const char *s)
 {
 	/* Filter out characters we don't want to see in the modalias string */
@@ -231,8 +332,15 @@ static int __init dmi_id_init(void)
 	if (ret)
 		goto fail_put_dmi_dev;
 
+	ret = dmi_id_init_oem_attr_group();
+	if (ret)
+		goto fail_dev_unregister;
+
 	return 0;
 
+fail_dev_unregister:
+	device_unregister(dmi_dev);
+
 fail_put_dmi_dev:
 	put_device(dmi_dev);
 
-- 
2.7.4

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

* Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-14  8:01 ` [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs Allen Hung
@ 2016-07-14  9:16   ` kbuild test robot
  2016-07-19  9:03   ` Jean Delvare
  1 sibling, 0 replies; 14+ messages in thread
From: kbuild test robot @ 2016-07-14  9:16 UTC (permalink / raw)
  To: Allen Hung
  Cc: kbuild-all, Jean Delvare, linux-kernel, Mario Limonciello, Allen Hung

[-- Attachment #1: Type: text/plain, Size: 1446 bytes --]

Hi,

[auto build test ERROR on v4.7-rc7]
[also build test ERROR on next-20160713]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Allen-Hung/dmi-id-export-oem-strings-to-sysfs/20160714-161631
config: i386-defconfig (attached as .config)
compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/firmware/dmi-id.c: In function 'dmi_id_init_oem_attr_group':
>> drivers/firmware/dmi-id.c:107:28: error: 'dmi_dev' undeclared (first use in this function)
     ret = sysfs_create_group(&dmi_dev->kobj, &dmi_oem_attr_group);
                               ^~~~~~~
   drivers/firmware/dmi-id.c:107:28: note: each undeclared identifier is reported only once for each function it appears in

vim +/dmi_dev +107 drivers/firmware/dmi-id.c

   101		int i, ret;
   102		const struct dmi_device *dev;
   103		struct dmi_oem_attribute *oa, *tmp;
   104		struct device_attribute dev_attr_tmpl =
   105			__ATTR(, 0444, sys_dmi_oem_show, NULL);
   106	
 > 107		ret = sysfs_create_group(&dmi_dev->kobj, &dmi_oem_attr_group);
   108		if (ret)
   109			return ret;
   110	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 24901 bytes --]

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

* Re: [PATCH 1/2] dmi-id: don't free dev structure after calling device_register
  2016-07-14  8:01 ` [PATCH 1/2] dmi-id: don't free dev structure after calling device_register Allen Hung
@ 2016-07-18 17:09   ` Jean Delvare
  0 siblings, 0 replies; 14+ messages in thread
From: Jean Delvare @ 2016-07-18 17:09 UTC (permalink / raw)
  To: Allen Hung; +Cc: linux-kernel, Mario Limonciello

On Thu, 14 Jul 2016 16:01:22 +0800, Allen Hung wrote:
> dmi_dev is freed in error exit code but, according to the document
> of device_register, it should never directly free device structure
> after calling this function, even if it returned an error! Use
> put_device() instead.
> 
> Signed-off-by: Allen Hung <allen_hung@dell.com>
> ---
>  drivers/firmware/dmi-id.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
> index 94a58a0..44c0139 100644
> --- a/drivers/firmware/dmi-id.c
> +++ b/drivers/firmware/dmi-id.c
> @@ -229,14 +229,14 @@ static int __init dmi_id_init(void)
>  
>  	ret = device_register(dmi_dev);
>  	if (ret)
> -		goto fail_free_dmi_dev;
> +		goto fail_put_dmi_dev;
>  
>  	return 0;
>  
> -fail_free_dmi_dev:
> -	kfree(dmi_dev);
> -fail_class_unregister:
> +fail_put_dmi_dev:
> +	put_device(dmi_dev);
>  
> +fail_class_unregister:
>  	class_unregister(&dmi_class);
>  
>  	return ret;

Good catch. Applied, thanks.

-- 
Jean Delvare
SUSE L3 Support

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

* Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-14  8:01 ` [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs Allen Hung
  2016-07-14  9:16   ` kbuild test robot
@ 2016-07-19  9:03   ` Jean Delvare
  2016-07-19 14:47     ` Mario_Limonciello
  2016-07-26 21:03     ` Mario_Limonciello
  1 sibling, 2 replies; 14+ messages in thread
From: Jean Delvare @ 2016-07-19  9:03 UTC (permalink / raw)
  To: Allen Hung; +Cc: Jean Delvare, linux-kernel, Mario Limonciello

Hello Allen,

On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
> The oem strings in DMI system identification information of the BIOS have
> been parsed and stored as dmi devices in dmi_scan.c but they are not
> exported to userspace via sysfs.

They are intended for internal consumption by the kernel drivers.

> The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
> As the number of oem strings are dynamic, a group "oem" is added to the
> device and the strings will be added to the group as string1, string2, ...,
> and stringN.

What is the use case? You can already get these strings easily using
dmidecode:

# dmidecode -qt 11
OEM Strings
	String 1: Dell System
	String 2: 1[05A4]
	String 3: 3[1.0]
	String 4: 12[www.dell.com]
	String 5: 14[1]
	String 6: 15[3]
	String 7:  

If needed, a dedicated option could be added to dmidecode to extract
specific OEM strings. Or existing option -s could be extended for that
purpose.

Also your code doesn't even build. I won't review this patch until I
know why it is needed, and it builds (without warning.)

One comment below though:

> 
> Signed-off-by: Allen Hung <allen_hung@dell.com>
> ---
>  drivers/firmware/dmi-id.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 108 insertions(+)
> 
> diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
> index 44c0139..f284a07 100644
> --- a/drivers/firmware/dmi-id.c
> +++ b/drivers/firmware/dmi-id.c
> (...)
> +static int __init dmi_id_init_oem_attr_group(void)
> +{
> +	int i, ret;
> +	const struct dmi_device *dev;
> +	struct dmi_oem_attribute *oa, *tmp;
> +	struct device_attribute dev_attr_tmpl =
> +		__ATTR(, 0444, sys_dmi_oem_show, NULL);

I'd be very careful about permissions. OEM strings could contain pretty
much everything, including serial numbers or passwords. Making these
files world-readable doesn't strike me as the best of the ideas.

-- 
Jean Delvare
SUSE L3 Support

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

* RE: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-19  9:03   ` Jean Delvare
@ 2016-07-19 14:47     ` Mario_Limonciello
  2016-08-02 13:43       ` Jean Delvare
  2016-07-26 21:03     ` Mario_Limonciello
  1 sibling, 1 reply; 14+ messages in thread
From: Mario_Limonciello @ 2016-07-19 14:47 UTC (permalink / raw)
  To: jdelvare, Allen_Hung; +Cc: jdelvare, linux-kernel

Hi Jean,

I worked with Allen on this concept, so I've got some comments below.

> -----Original Message-----
> From: Jean Delvare [mailto:jdelvare@suse.de]
> Sent: Tuesday, July 19, 2016 4:03 AM
> To: Hung, Allen <Allen_Hung@Dell.com>
> Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
> Limonciello, Mario <Mario_Limonciello@Dell.com>
> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
> strings to sysfs
> 
> Hello Allen,
> 
> On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
> > The oem strings in DMI system identification information of the BIOS have
> > been parsed and stored as dmi devices in dmi_scan.c but they are not
> > exported to userspace via sysfs.
> 
> They are intended for internal consumption by the kernel drivers.
> 
> > The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
> > As the number of oem strings are dynamic, a group "oem" is added to the
> > device and the strings will be added to the group as string1, string2, ...,
> > and stringN.
> 
> What is the use case? You can already get these strings easily using
> dmidecode:
> 
> # dmidecode -qt 11
> OEM Strings
> 	String 1: Dell System
> 	String 2: 1[05A4]
> 	String 3: 3[1.0]
> 	String 4: 12[www.dell.com]
> 	String 5: 14[1]
> 	String 6: 15[3]
> 	String 7:
> 
> If needed, a dedicated option could be added to dmidecode to extract
> specific OEM strings. Or existing option -s could be extended for that
> purpose.

The main purpose was to be able to parse these easily from userspace
without needing dmidecode installed and handling its output 
(with tools such as grep, sed, and awk).

For example in an initramfs, typically dmidecode isn't included, but there
is value to being able to make decisions on things related to the values of 
those OEM strings.

Instead this allows userspace to iterate the oem/ directory and directly
look at the values of these strings.

> 
> Also your code doesn't even build. I won't review this patch until I
> know why it is needed, and it builds (without warning.)
> 

Allen had a mistake in that submission when he was refactoring it prior to 
LKML submission.  
He resubmitted it the next day fixing that mistake:
https://patchwork.kernel.org/patch/9231473/

> One comment below though:
> 
> >
> > Signed-off-by: Allen Hung <allen_hung@dell.com>
> > ---
> >  drivers/firmware/dmi-id.c | 108
> ++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 108 insertions(+)
> >
> > diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
> > index 44c0139..f284a07 100644
> > --- a/drivers/firmware/dmi-id.c
> > +++ b/drivers/firmware/dmi-id.c
> > (...)
> > +static int __init dmi_id_init_oem_attr_group(void)
> > +{
> > +	int i, ret;
> > +	const struct dmi_device *dev;
> > +	struct dmi_oem_attribute *oa, *tmp;
> > +	struct device_attribute dev_attr_tmpl =
> > +		__ATTR(, 0444, sys_dmi_oem_show, NULL);
> 
> I'd be very careful about permissions. OEM strings could contain pretty
> much everything, including serial numbers or passwords. Making these
> files world-readable doesn't strike me as the best of the ideas.
> 

At least on Dell systems, the values in these strings are OK to be world
readable, but I understand this concern and agree that Allen should adjust
these permissions in the next version if you agree with the concept of this
patch.

Thanks,

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

* RE: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-19  9:03   ` Jean Delvare
  2016-07-19 14:47     ` Mario_Limonciello
@ 2016-07-26 21:03     ` Mario_Limonciello
  2016-07-29  9:59       ` Allen Hung
  1 sibling, 1 reply; 14+ messages in thread
From: Mario_Limonciello @ 2016-07-26 21:03 UTC (permalink / raw)
  To: jdelvare, Allen_Hung; +Cc: jdelvare, linux-kernel

> -----Original Message-----
> From: Limonciello, Mario
> Sent: Tuesday, July 19, 2016 9:48 AM
> To: 'Jean Delvare' <jdelvare@suse.de>; Hung, Allen <Allen_Hung@Dell.com>
> Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org
> Subject: RE: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
> strings to sysfs
> 
> Hi Jean,
> 
> I worked with Allen on this concept, so I've got some comments below.
> 
> > -----Original Message-----
> > From: Jean Delvare [mailto:jdelvare@suse.de]
> > Sent: Tuesday, July 19, 2016 4:03 AM
> > To: Hung, Allen <Allen_Hung@Dell.com>
> > Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
> > Limonciello, Mario <Mario_Limonciello@Dell.com>
> > Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
> > strings to sysfs
> >
> > Hello Allen,
> >
> > On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
> > > The oem strings in DMI system identification information of the BIOS
> have
> > > been parsed and stored as dmi devices in dmi_scan.c but they are not
> > > exported to userspace via sysfs.
> >
> > They are intended for internal consumption by the kernel drivers.
> >
> > > The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
> > > As the number of oem strings are dynamic, a group "oem" is added to the
> > > device and the strings will be added to the group as string1, string2, ...,
> > > and stringN.
> >
> > What is the use case? You can already get these strings easily using
> > dmidecode:
> >
> > # dmidecode -qt 11
> > OEM Strings
> > 	String 1: Dell System
> > 	String 2: 1[05A4]
> > 	String 3: 3[1.0]
> > 	String 4: 12[www.dell.com]
> > 	String 5: 14[1]
> > 	String 6: 15[3]
> > 	String 7:
> >
> > If needed, a dedicated option could be added to dmidecode to extract
> > specific OEM strings. Or existing option -s could be extended for that
> > purpose.
> 
> The main purpose was to be able to parse these easily from userspace
> without needing dmidecode installed and handling its output
> (with tools such as grep, sed, and awk).
> 
> For example in an initramfs, typically dmidecode isn't included, but there
> is value to being able to make decisions on things related to the values of
> those OEM strings.
> 
> Instead this allows userspace to iterate the oem/ directory and directly
> look at the values of these strings.
> 
> >
> > Also your code doesn't even build. I won't review this patch until I
> > know why it is needed, and it builds (without warning.)
> >
> 
> Allen had a mistake in that submission when he was refactoring it prior to
> LKML submission.
> He resubmitted it the next day fixing that mistake:
> https://patchwork.kernel.org/patch/9231473/
> 
> > One comment below though:
> >
> > >
> > > Signed-off-by: Allen Hung <allen_hung@dell.com>
> > > ---
> > >  drivers/firmware/dmi-id.c | 108
> > ++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 108 insertions(+)
> > >
> > > diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
> > > index 44c0139..f284a07 100644
> > > --- a/drivers/firmware/dmi-id.c
> > > +++ b/drivers/firmware/dmi-id.c
> > > (...)
> > > +static int __init dmi_id_init_oem_attr_group(void)
> > > +{
> > > +	int i, ret;
> > > +	const struct dmi_device *dev;
> > > +	struct dmi_oem_attribute *oa, *tmp;
> > > +	struct device_attribute dev_attr_tmpl =
> > > +		__ATTR(, 0444, sys_dmi_oem_show, NULL);
> >
> > I'd be very careful about permissions. OEM strings could contain pretty
> > much everything, including serial numbers or passwords. Making these
> > files world-readable doesn't strike me as the best of the ideas.
> >
> 
> At least on Dell systems, the values in these strings are OK to be world
> readable, but I understand this concern and agree that Allen should adjust
> these permissions in the next version if you agree with the concept of this
> patch.
> 
> Thanks,

Hi jean,

Did you have any comments about Allen's updated patch or my above
comments?

If necessary, Allen can resend with the fix to OEM strings permissions
and we can discuss further then.

Thanks,

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

* Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-26 21:03     ` Mario_Limonciello
@ 2016-07-29  9:59       ` Allen Hung
  0 siblings, 0 replies; 14+ messages in thread
From: Allen Hung @ 2016-07-29  9:59 UTC (permalink / raw)
  To: Limonciello, Mario, Jean Delvare; +Cc: Jean Delvare, linux-kernel

On 07/27/2016 05:03 AM, Limonciello, Mario wrote:
>> -----Original Message-----
>> From: Limonciello, Mario
>> Sent: Tuesday, July 19, 2016 9:48 AM
>> To: 'Jean Delvare' <jdelvare@suse.de>; Hung, Allen <Allen_Hung@Dell.com>
>> Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org
>> Subject: RE: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
>> strings to sysfs
>>
>> Hi Jean,
>>
>> I worked with Allen on this concept, so I've got some comments below.
>>
>>> -----Original Message-----
>>> From: Jean Delvare [mailto:jdelvare@suse.de]
>>> Sent: Tuesday, July 19, 2016 4:03 AM
>>> To: Hung, Allen <Allen_Hung@Dell.com>
>>> Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
>>> Limonciello, Mario <Mario_Limonciello@Dell.com>
>>> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
>>> strings to sysfs
>>>
>>> Hello Allen,
>>>
>>> On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
>>>> The oem strings in DMI system identification information of the BIOS
>> have
>>>> been parsed and stored as dmi devices in dmi_scan.c but they are not
>>>> exported to userspace via sysfs.
>>>
>>> They are intended for internal consumption by the kernel drivers.
>>>
>>>> The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
>>>> As the number of oem strings are dynamic, a group "oem" is added to the
>>>> device and the strings will be added to the group as string1, string2, ...,
>>>> and stringN.
>>>
>>> What is the use case? You can already get these strings easily using
>>> dmidecode:
>>>
>>> # dmidecode -qt 11
>>> OEM Strings
>>> 	String 1: Dell System
>>> 	String 2: 1[05A4]
>>> 	String 3: 3[1.0]
>>> 	String 4: 12[www.dell.com]
>>> 	String 5: 14[1]
>>> 	String 6: 15[3]
>>> 	String 7:
>>>
>>> If needed, a dedicated option could be added to dmidecode to extract
>>> specific OEM strings. Or existing option -s could be extended for that
>>> purpose.
>>
>> The main purpose was to be able to parse these easily from userspace
>> without needing dmidecode installed and handling its output
>> (with tools such as grep, sed, and awk).
>>
>> For example in an initramfs, typically dmidecode isn't included, but there
>> is value to being able to make decisions on things related to the values of
>> those OEM strings.
>>
>> Instead this allows userspace to iterate the oem/ directory and directly
>> look at the values of these strings.
>>
>>>
>>> Also your code doesn't even build. I won't review this patch until I
>>> know why it is needed, and it builds (without warning.)
>>>
>>
>> Allen had a mistake in that submission when he was refactoring it prior to
>> LKML submission.
>> He resubmitted it the next day fixing that mistake:
>> https://patchwork.kernel.org/patch/9231473/
>>
>>> One comment below though:
>>>
>>>>
>>>> Signed-off-by: Allen Hung <allen_hung@dell.com>
>>>> ---
>>>>  drivers/firmware/dmi-id.c | 108
>>> ++++++++++++++++++++++++++++++++++++++++++++++
>>>>  1 file changed, 108 insertions(+)
>>>>
>>>> diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
>>>> index 44c0139..f284a07 100644
>>>> --- a/drivers/firmware/dmi-id.c
>>>> +++ b/drivers/firmware/dmi-id.c
>>>> (...)
>>>> +static int __init dmi_id_init_oem_attr_group(void)
>>>> +{
>>>> +	int i, ret;
>>>> +	const struct dmi_device *dev;
>>>> +	struct dmi_oem_attribute *oa, *tmp;
>>>> +	struct device_attribute dev_attr_tmpl =
>>>> +		__ATTR(, 0444, sys_dmi_oem_show, NULL);
>>>
>>> I'd be very careful about permissions. OEM strings could contain pretty
>>> much everything, including serial numbers or passwords. Making these
>>> files world-readable doesn't strike me as the best of the ideas.
>>>
>>
>> At least on Dell systems, the values in these strings are OK to be world
>> readable, but I understand this concern and agree that Allen should adjust
>> these permissions in the next version if you agree with the concept of this
>> patch.
>>
>> Thanks,
> 
> Hi jean,
> 
> Did you have any comments about Allen's updated patch or my above
> comments?
> 
> If necessary, Allen can resend with the fix to OEM strings permissions
> and we can discuss further then.
> 
> Thanks,
> 
Hi Jean,
I didn't send my earlier fix beginning with "PATCH v2" so it may bring up some confusing. I am sorry about it.
I have just resent it with prefix "PATCH v2" and the OEM string permissions still remain what they were in my first submission.
Hope we can get the feedbacks from you.

Regards,
Allen

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

* Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-19 14:47     ` Mario_Limonciello
@ 2016-08-02 13:43       ` Jean Delvare
  2016-08-02 18:56         ` Mario_Limonciello
  0 siblings, 1 reply; 14+ messages in thread
From: Jean Delvare @ 2016-08-02 13:43 UTC (permalink / raw)
  To: Mario_Limonciello; +Cc: Allen_Hung, linux-kernel

Hi Mario, Allen,

On Tue, 19 Jul 2016 14:47:57 +0000, Mario_Limonciello@Dell.com wrote:
> Hi Jean,
> 
> I worked with Allen on this concept, so I've got some comments below.
> 
> > -----Original Message-----
> > From: Jean Delvare [mailto:jdelvare@suse.de]
> > Sent: Tuesday, July 19, 2016 4:03 AM
> > To: Hung, Allen <Allen_Hung@Dell.com>
> > Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
> > Limonciello, Mario <Mario_Limonciello@Dell.com>
> > Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
> > strings to sysfs
> > 
> > Hello Allen,
> > 
> > On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
> > > The oem strings in DMI system identification information of the BIOS have
> > > been parsed and stored as dmi devices in dmi_scan.c but they are not
> > > exported to userspace via sysfs.
> > 
> > They are intended for internal consumption by the kernel drivers.
> > 
> > > The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
> > > As the number of oem strings are dynamic, a group "oem" is added to the
> > > device and the strings will be added to the group as string1, string2, ...,
> > > and stringN.
> > 
> > What is the use case? You can already get these strings easily using
> > dmidecode:
> > 
> > # dmidecode -qt 11
> > OEM Strings
> > 	String 1: Dell System
> > 	String 2: 1[05A4]
> > 	String 3: 3[1.0]
> > 	String 4: 12[www.dell.com]
> > 	String 5: 14[1]
> > 	String 6: 15[3]
> > 	String 7:
> > 
> > If needed, a dedicated option could be added to dmidecode to extract
> > specific OEM strings. Or existing option -s could be extended for that
> > purpose.
> 
> The main purpose was to be able to parse these easily from userspace
> without needing dmidecode installed and handling its output 
> (with tools such as grep, sed, and awk).

As I just stated above: dmidecode could be extended to extract the oem
strings directly if there is a need for it.

> For example in an initramfs, typically dmidecode isn't included, but there
> is value to being able to make decisions on things related to the values of 
> those OEM strings.

dmidecode is not included because nobody needs it. If you need it, you
can include it. 15 years ago, udev was not included in initramfs
either. But we still decided that this stuff should be done in
user-space and we wrote udev and added it to initramfs. It is in the
nature of initramfs to evolve with new needs, and to only include what
is needed on a given machine. mkinitrd/dracut checks the needs
dynamically. Why would it not work in your case?

I would appreciate more details than "there is value..." I would like
to hear about an actual use case.

> Instead this allows userspace to iterate the oem/ directory and directly
> look at the values of these strings.

At the cost of code which will run at every boot, and kernel memory
which will be used forever, on all systems. This is why I am reluctant.
You don't put things in the kernel because this is the easiest way to
fulfill your immediate need. You put things in the kernel because you
absolutely have to, or at the very least because it is where it makes
the most sense. At this point I am not convinced this is the case here.
I see no reason why the same can't be implemented easily in user-space
(dmidecode and dracut.)

> > Also your code doesn't even build. I won't review this patch until I
> > know why it is needed, and it builds (without warning.)
> 
> Allen had a mistake in that submission when he was refactoring it prior to 
> LKML submission.  
> He resubmitted it the next day fixing that mistake:
> https://patchwork.kernel.org/patch/9231473/

Sorry, my bad. The updated patch was already available when I
complained, just had not crawled far enough in my mailbox at the time I
replied.

-- 
Jean Delvare
SUSE L3 Support

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

* RE: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-08-02 13:43       ` Jean Delvare
@ 2016-08-02 18:56         ` Mario_Limonciello
  2016-08-15  9:55           ` Allen Hung
  0 siblings, 1 reply; 14+ messages in thread
From: Mario_Limonciello @ 2016-08-02 18:56 UTC (permalink / raw)
  To: jdelvare; +Cc: Allen_Hung, linux-kernel

> -----Original Message-----
> From: Jean Delvare [mailto:jdelvare@suse.de]
> Sent: Tuesday, August 2, 2016 8:43 AM
> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> Cc: Hung, Allen <Allen_Hung@Dell.com>; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
> strings to sysfs
> 
> Hi Mario, Allen,
> 
> On Tue, 19 Jul 2016 14:47:57 +0000, Mario_Limonciello@Dell.com wrote:
> > Hi Jean,
> >
> > I worked with Allen on this concept, so I've got some comments below.
> >
> > > -----Original Message-----
> > > From: Jean Delvare [mailto:jdelvare@suse.de]
> > > Sent: Tuesday, July 19, 2016 4:03 AM
> > > To: Hung, Allen <Allen_Hung@Dell.com>
> > > Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
> > > Limonciello, Mario <Mario_Limonciello@Dell.com>
> > > Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting
> oem
> > > strings to sysfs
> > >
> > > Hello Allen,
> > >
> > > On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
> > > > The oem strings in DMI system identification information of the BIOS
> have
> > > > been parsed and stored as dmi devices in dmi_scan.c but they are not
> > > > exported to userspace via sysfs.
> > >
> > > They are intended for internal consumption by the kernel drivers.
> > >
> > > > The patch intends to export oem strings to sysfs device
> /sys/class/dmi/id.
> > > > As the number of oem strings are dynamic, a group "oem" is added to
> the
> > > > device and the strings will be added to the group as string1, string2, ...,
> > > > and stringN.
> > >
> > > What is the use case? You can already get these strings easily using
> > > dmidecode:
> > >
> > > # dmidecode -qt 11
> > > OEM Strings
> > > 	String 1: Dell System
> > > 	String 2: 1[05A4]
> > > 	String 3: 3[1.0]
> > > 	String 4: 12[www.dell.com]
> > > 	String 5: 14[1]
> > > 	String 6: 15[3]
> > > 	String 7:
> > >
> > > If needed, a dedicated option could be added to dmidecode to extract
> > > specific OEM strings. Or existing option -s could be extended for that
> > > purpose.
> >
> > The main purpose was to be able to parse these easily from userspace
> > without needing dmidecode installed and handling its output
> > (with tools such as grep, sed, and awk).
> 
> As I just stated above: dmidecode could be extended to extract the oem
> strings directly if there is a need for it.
> 
> > For example in an initramfs, typically dmidecode isn't included, but there
> > is value to being able to make decisions on things related to the values of
> > those OEM strings.
> 
> dmidecode is not included because nobody needs it. If you need it, you
> can include it. 15 years ago, udev was not included in initramfs
> either. But we still decided that this stuff should be done in
> user-space and we wrote udev and added it to initramfs. It is in the
> nature of initramfs to evolve with new needs, and to only include what
> is needed on a given machine. mkinitrd/dracut checks the needs
> dynamically. Why would it not work in your case?
> 
> I would appreciate more details than "there is value..." I would like
> to hear about an actual use case.
> 
> > Instead this allows userspace to iterate the oem/ directory and directly
> > look at the values of these strings.
> 
> At the cost of code which will run at every boot, and kernel memory
> which will be used forever, on all systems. This is why I am reluctant.
> You don't put things in the kernel because this is the easiest way to
> fulfill your immediate need. You put things in the kernel because you
> absolutely have to, or at the very least because it is where it makes
> the most sense. At this point I am not convinced this is the case here.
> I see no reason why the same can't be implemented easily in user-space
> (dmidecode and dracut.)

Thanks, when you put it this way your reluctance makes a lot more sense.
I don't disagree that this could live in several different levels of the software
stack.

The main reason that we want to have OEM tags exported is to access one
particular OEM strings on Dell systems from userspace applications that should
run on Dell systems (not just the initramfs).

There is string  that indicates that the system is a Dell System.  Normally this
would be obvious from other SMBIOS strings (such as System Vendor)
but Dell also does "OEM systems", which means that they might have 
custom branding applied that has otherwise removed the Vendor and
Product information.

Other strings indicate information that can be used to determine the
original product model number and lots of other details.

On a system like this it's not possible to know it's a Dell system and what
model it was before rebranding without looking at the OEM strings.

So by exporting the OEM strings from sysfs, it's possible to accurately 
identify Dell systems regardless of whether they have custom branding
applied without needing to rely on calling dmidecode.

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

* Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-08-02 18:56         ` Mario_Limonciello
@ 2016-08-15  9:55           ` Allen Hung
  2016-08-24  8:05             ` Allen Hung
  0 siblings, 1 reply; 14+ messages in thread
From: Allen Hung @ 2016-08-15  9:55 UTC (permalink / raw)
  To: Limonciello, Mario, Jean Delvare; +Cc: linux-kernel

On 08/03/2016 02:56 AM, Limonciello, Mario wrote:
>> -----Original Message-----
>> From: Jean Delvare [mailto:jdelvare@suse.de]
>> Sent: Tuesday, August 2, 2016 8:43 AM
>> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
>> Cc: Hung, Allen <Allen_Hung@Dell.com>; linux-kernel@vger.kernel.org
>> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
>> strings to sysfs
>>
>> Hi Mario, Allen,
>>
>> On Tue, 19 Jul 2016 14:47:57 +0000, Mario_Limonciello@Dell.com wrote:
>>> Hi Jean,
>>>
>>> I worked with Allen on this concept, so I've got some comments below.
>>>
>>>> -----Original Message-----
>>>> From: Jean Delvare [mailto:jdelvare@suse.de]
>>>> Sent: Tuesday, July 19, 2016 4:03 AM
>>>> To: Hung, Allen <Allen_Hung@Dell.com>
>>>> Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
>>>> Limonciello, Mario <Mario_Limonciello@Dell.com>
>>>> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting
>> oem
>>>> strings to sysfs
>>>>
>>>> Hello Allen,
>>>>
>>>> On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
>>>>> The oem strings in DMI system identification information of the BIOS
>> have
>>>>> been parsed and stored as dmi devices in dmi_scan.c but they are not
>>>>> exported to userspace via sysfs.
>>>>
>>>> They are intended for internal consumption by the kernel drivers.
>>>>
>>>>> The patch intends to export oem strings to sysfs device
>> /sys/class/dmi/id.
>>>>> As the number of oem strings are dynamic, a group "oem" is added to
>> the
>>>>> device and the strings will be added to the group as string1, string2, ...,
>>>>> and stringN.
>>>>
>>>> What is the use case? You can already get these strings easily using
>>>> dmidecode:
>>>>
>>>> # dmidecode -qt 11
>>>> OEM Strings
>>>> 	String 1: Dell System
>>>> 	String 2: 1[05A4]
>>>> 	String 3: 3[1.0]
>>>> 	String 4: 12[www.dell.com]
>>>> 	String 5: 14[1]
>>>> 	String 6: 15[3]
>>>> 	String 7:
>>>>
>>>> If needed, a dedicated option could be added to dmidecode to extract
>>>> specific OEM strings. Or existing option -s could be extended for that
>>>> purpose.
>>>
>>> The main purpose was to be able to parse these easily from userspace
>>> without needing dmidecode installed and handling its output
>>> (with tools such as grep, sed, and awk).
>>
>> As I just stated above: dmidecode could be extended to extract the oem
>> strings directly if there is a need for it.
>>
>>> For example in an initramfs, typically dmidecode isn't included, but there
>>> is value to being able to make decisions on things related to the values of
>>> those OEM strings.
>>
>> dmidecode is not included because nobody needs it. If you need it, you
>> can include it. 15 years ago, udev was not included in initramfs
>> either. But we still decided that this stuff should be done in
>> user-space and we wrote udev and added it to initramfs. It is in the
>> nature of initramfs to evolve with new needs, and to only include what
>> is needed on a given machine. mkinitrd/dracut checks the needs
>> dynamically. Why would it not work in your case?
>>
>> I would appreciate more details than "there is value..." I would like
>> to hear about an actual use case.
>>
>>> Instead this allows userspace to iterate the oem/ directory and directly
>>> look at the values of these strings.
>>
>> At the cost of code which will run at every boot, and kernel memory
>> which will be used forever, on all systems. This is why I am reluctant.
>> You don't put things in the kernel because this is the easiest way to
>> fulfill your immediate need. You put things in the kernel because you
>> absolutely have to, or at the very least because it is where it makes
>> the most sense. At this point I am not convinced this is the case here.
>> I see no reason why the same can't be implemented easily in user-space
>> (dmidecode and dracut.)
> 
> Thanks, when you put it this way your reluctance makes a lot more sense.
> I don't disagree that this could live in several different levels of the software
> stack.
> 
> The main reason that we want to have OEM tags exported is to access one
> particular OEM strings on Dell systems from userspace applications that should
> run on Dell systems (not just the initramfs).
> 
> There is string  that indicates that the system is a Dell System.  Normally this
> would be obvious from other SMBIOS strings (such as System Vendor)
> but Dell also does "OEM systems", which means that they might have 
> custom branding applied that has otherwise removed the Vendor and
> Product information.
> 
> Other strings indicate information that can be used to determine the
> original product model number and lots of other details.
> 
> On a system like this it's not possible to know it's a Dell system and what
> model it was before rebranding without looking at the OEM strings.
> 
> So by exporting the OEM strings from sysfs, it's possible to accurately 
> identify Dell systems regardless of whether they have custom branding
> applied without needing to rely on calling dmidecode.
> 
Hi Jean,

I revised the patch to turn the exporting of OEM strings into a sub-option under 
config DMIID and is disabled by default. We can turn on this kernel option only on
the systems Dell is going to ship, and it will not waste any memory on other systems
unless it is otherwise enabled. We don't disagree this is not a must in kernel but
the revised patch is meant to retain the value Mario wrote above, and to avoid the
waste on the systems those don't need it. Also, the file permissions are adjusted 
as 0400.
It was sent with the same title with the tag prefix "[PATCH v3 2/2] ..." in prefix.

Regards,
Allen

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

* Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-08-15  9:55           ` Allen Hung
@ 2016-08-24  8:05             ` Allen Hung
  0 siblings, 0 replies; 14+ messages in thread
From: Allen Hung @ 2016-08-24  8:05 UTC (permalink / raw)
  To: Limonciello, Mario, Jean Delvare; +Cc: linux-kernel

On 08/15/2016 05:55 PM, Allen Hung wrote:
> On 08/03/2016 02:56 AM, Limonciello, Mario wrote:
>>> -----Original Message-----
>>> From: Jean Delvare [mailto:jdelvare@suse.de]
>>> Sent: Tuesday, August 2, 2016 8:43 AM
>>> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
>>> Cc: Hung, Allen <Allen_Hung@Dell.com>; linux-kernel@vger.kernel.org
>>> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem
>>> strings to sysfs
>>>
>>> Hi Mario, Allen,
>>>
>>> On Tue, 19 Jul 2016 14:47:57 +0000, Mario_Limonciello@Dell.com wrote:
>>>> Hi Jean,
>>>>
>>>> I worked with Allen on this concept, so I've got some comments below.
>>>>
>>>>> -----Original Message-----
>>>>> From: Jean Delvare [mailto:jdelvare@suse.de]
>>>>> Sent: Tuesday, July 19, 2016 4:03 AM
>>>>> To: Hung, Allen <Allen_Hung@Dell.com>
>>>>> Cc: Jean Delvare <jdelvare@suse.com>; linux-kernel@vger.kernel.org;
>>>>> Limonciello, Mario <Mario_Limonciello@Dell.com>
>>>>> Subject: Re: [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting
>>> oem
>>>>> strings to sysfs
>>>>>
>>>>> Hello Allen,
>>>>>
>>>>> On Thu, 14 Jul 2016 16:01:23 +0800, Allen Hung wrote:
>>>>>> The oem strings in DMI system identification information of the BIOS
>>> have
>>>>>> been parsed and stored as dmi devices in dmi_scan.c but they are not
>>>>>> exported to userspace via sysfs.
>>>>>
>>>>> They are intended for internal consumption by the kernel drivers.
>>>>>
>>>>>> The patch intends to export oem strings to sysfs device
>>> /sys/class/dmi/id.
>>>>>> As the number of oem strings are dynamic, a group "oem" is added to
>>> the
>>>>>> device and the strings will be added to the group as string1, string2, ...,
>>>>>> and stringN.
>>>>>
>>>>> What is the use case? You can already get these strings easily using
>>>>> dmidecode:
>>>>>
>>>>> # dmidecode -qt 11
>>>>> OEM Strings
>>>>> 	String 1: Dell System
>>>>> 	String 2: 1[05A4]
>>>>> 	String 3: 3[1.0]
>>>>> 	String 4: 12[www.dell.com]
>>>>> 	String 5: 14[1]
>>>>> 	String 6: 15[3]
>>>>> 	String 7:
>>>>>
>>>>> If needed, a dedicated option could be added to dmidecode to extract
>>>>> specific OEM strings. Or existing option -s could be extended for that
>>>>> purpose.
>>>>
>>>> The main purpose was to be able to parse these easily from userspace
>>>> without needing dmidecode installed and handling its output
>>>> (with tools such as grep, sed, and awk).
>>>
>>> As I just stated above: dmidecode could be extended to extract the oem
>>> strings directly if there is a need for it.
>>>
>>>> For example in an initramfs, typically dmidecode isn't included, but there
>>>> is value to being able to make decisions on things related to the values of
>>>> those OEM strings.
>>>
>>> dmidecode is not included because nobody needs it. If you need it, you
>>> can include it. 15 years ago, udev was not included in initramfs
>>> either. But we still decided that this stuff should be done in
>>> user-space and we wrote udev and added it to initramfs. It is in the
>>> nature of initramfs to evolve with new needs, and to only include what
>>> is needed on a given machine. mkinitrd/dracut checks the needs
>>> dynamically. Why would it not work in your case?
>>>
>>> I would appreciate more details than "there is value..." I would like
>>> to hear about an actual use case.
>>>
>>>> Instead this allows userspace to iterate the oem/ directory and directly
>>>> look at the values of these strings.
>>>
>>> At the cost of code which will run at every boot, and kernel memory
>>> which will be used forever, on all systems. This is why I am reluctant.
>>> You don't put things in the kernel because this is the easiest way to
>>> fulfill your immediate need. You put things in the kernel because you
>>> absolutely have to, or at the very least because it is where it makes
>>> the most sense. At this point I am not convinced this is the case here.
>>> I see no reason why the same can't be implemented easily in user-space
>>> (dmidecode and dracut.)
>>
>> Thanks, when you put it this way your reluctance makes a lot more sense.
>> I don't disagree that this could live in several different levels of the software
>> stack.
>>
>> The main reason that we want to have OEM tags exported is to access one
>> particular OEM strings on Dell systems from userspace applications that should
>> run on Dell systems (not just the initramfs).
>>
>> There is string  that indicates that the system is a Dell System.  Normally this
>> would be obvious from other SMBIOS strings (such as System Vendor)
>> but Dell also does "OEM systems", which means that they might have 
>> custom branding applied that has otherwise removed the Vendor and
>> Product information.
>>
>> Other strings indicate information that can be used to determine the
>> original product model number and lots of other details.
>>
>> On a system like this it's not possible to know it's a Dell system and what
>> model it was before rebranding without looking at the OEM strings.
>>
>> So by exporting the OEM strings from sysfs, it's possible to accurately 
>> identify Dell systems regardless of whether they have custom branding
>> applied without needing to rely on calling dmidecode.
>>
> Hi Jean,
> 
> I revised the patch to turn the exporting of OEM strings into a sub-option under 
> config DMIID and is disabled by default. We can turn on this kernel option only on
> the systems Dell is going to ship, and it will not waste any memory on other systems
> unless it is otherwise enabled. We don't disagree this is not a must in kernel but
> the revised patch is meant to retain the value Mario wrote above, and to avoid the
> waste on the systems those don't need it. Also, the file permissions are adjusted 
> as 0400.
> It was sent with the same title with the tag prefix "[PATCH v3 2/2] ..." in prefix.
> 
> Regards,
> Allen
> 
Hi Jean,

Please let us know if you have feedbacks on my patch "[PATCH v3 2/2] dmi-id: add 
dmi/id/oem group for exporting oem strings to sysfs" sent on August 15.

Regards,
Allen

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

* [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs
  2016-07-15  9:42 [PATCH 0/2] dmi-id: export " Allen Hung
@ 2016-07-15  9:42 ` Allen Hung
  0 siblings, 0 replies; 14+ messages in thread
From: Allen Hung @ 2016-07-15  9:42 UTC (permalink / raw)
  To: Jean Delvare, linux-kernel; +Cc: Mario Limonciello, Allen Hung

The oem strings in DMI system identification information of the BIOS have
been parsed and stored as dmi devices in dmi_scan.c but they are not
exported to userspace via sysfs.

The patch intends to export oem strings to sysfs device /sys/class/dmi/id.
As the number of oem strings are dynamic, a group "oem" is added to the
device and the strings will be added to the group as string1, string2, ...,
and stringN.

Signed-off-by: Allen Hung <allen_hung@dell.com>
---
 drivers/firmware/dmi-id.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
index 44c0139..503b635 100644
--- a/drivers/firmware/dmi-id.c
+++ b/drivers/firmware/dmi-id.c
@@ -58,6 +58,44 @@ DEFINE_DMI_ATTR_WITH_SHOW(chassis_version,	0444, DMI_CHASSIS_VERSION);
 DEFINE_DMI_ATTR_WITH_SHOW(chassis_serial,	0400, DMI_CHASSIS_SERIAL);
 DEFINE_DMI_ATTR_WITH_SHOW(chassis_asset_tag,	0444, DMI_CHASSIS_ASSET_TAG);
 
+static struct attribute *dmi_oem_attrs[] = {
+	NULL,
+};
+
+static const char oem_group[] = "oem";
+
+static struct attribute_group dmi_oem_attr_group = {
+	.attrs = dmi_oem_attrs,
+	.name  = oem_group,
+};
+
+static LIST_HEAD(dmi_oem_attrs_list);
+
+struct dmi_oem_attribute {
+	struct device_attribute dev_attr;
+	const char *oem_string;
+	char buf[32];
+	bool is_added:1;
+	struct list_head list;
+};
+
+#define to_dmi_oem_attr(_dev_attr) \
+	container_of(_dev_attr, struct dmi_oem_attribute, dev_attr)
+
+static ssize_t sys_dmi_oem_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *page)
+{
+	struct dmi_oem_attribute *oa = to_dmi_oem_attr(attr);
+	ssize_t len;
+
+	strlcpy(page, oa->oem_string, PAGE_SIZE-1);
+	len = strlen(page);
+	page[len++] = '\n';
+	page[len] = 0;
+	return len;
+}
+
 static void ascii_filter(char *d, const char *s)
 {
 	/* Filter out characters we don't want to see in the modalias string */
@@ -204,6 +242,69 @@ static void __init dmi_id_init_attr_table(void)
 	sys_dmi_attributes[i++] = &sys_dmi_modalias_attr.attr;
 }
 
+static int __init dmi_id_init_oem_attr_group(void)
+{
+	int i, ret;
+	const struct dmi_device *dev;
+	struct dmi_oem_attribute *oa, *tmp;
+	struct device_attribute dev_attr_tmpl =
+		__ATTR(, 0444, sys_dmi_oem_show, NULL);
+
+	ret = sysfs_create_group(&dmi_dev->kobj, &dmi_oem_attr_group);
+	if (ret)
+		return ret;
+
+	/* All devices with type=DMI_DEV_TYPE_OEM_STRING will be found in
+	 * the reverse order of what they were parsed in dmi_scan.c. However,
+	 * we do want to expose the OEM strings to sysfs in the same order as
+	 * what they were originally parsed. A linked list with 2-pass method
+	 * is used here to reverse the reserved order.
+	 *
+	 * Pass 1: find out all "OEM string" devices and add each "oem string"
+	 * to a linked list.
+	 */
+	dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, NULL);
+	while (dev)  {
+		oa = kzalloc(sizeof(*oa), GFP_KERNEL);
+		if (!oa) {
+			ret = -ENOMEM;
+			goto failed;
+		}
+		oa->dev_attr = dev_attr_tmpl;
+		oa->oem_string = dev->name;
+		list_add(&oa->list, &dmi_oem_attrs_list);
+		dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev);
+	}
+
+	/* Pass 2: traverse the list and add each string as a file to "oem"
+	 * group
+	 */
+	i = 0;
+	list_for_each_entry(oa, &dmi_oem_attrs_list, list) {
+		snprintf(oa->buf, sizeof(oa->buf), "string%d", ++i);
+		oa->dev_attr.attr.name = oa->buf;
+		ret = sysfs_add_file_to_group(
+			&dmi_dev->kobj, &oa->dev_attr.attr, oem_group);
+		if (ret)
+			goto failed;
+		oa->is_added = 1;
+	}
+
+	return 0;
+
+failed:
+	list_for_each_entry_safe(oa, tmp, &dmi_oem_attrs_list, list) {
+		if (oa->is_added)
+			sysfs_remove_file_from_group(
+				&dmi_dev->kobj,	&oa->dev_attr.attr, oem_group);
+		list_del(&oa->list);
+		kfree(oa);
+	}
+	sysfs_remove_group(&dmi_dev->kobj, &dmi_oem_attr_group);
+
+	return ret;
+}
+
 static int __init dmi_id_init(void)
 {
 	int ret;
@@ -231,8 +332,15 @@ static int __init dmi_id_init(void)
 	if (ret)
 		goto fail_put_dmi_dev;
 
+	ret = dmi_id_init_oem_attr_group();
+	if (ret)
+		goto fail_dev_unregister;
+
 	return 0;
 
+fail_dev_unregister:
+	device_unregister(dmi_dev);
+
 fail_put_dmi_dev:
 	put_device(dmi_dev);
 
-- 
2.7.4

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

end of thread, other threads:[~2016-08-24  8:06 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14  8:01 [PATCH 0/2] dmi-id: export oem strings to sysfs Allen Hung
2016-07-14  8:01 ` [PATCH 1/2] dmi-id: don't free dev structure after calling device_register Allen Hung
2016-07-18 17:09   ` Jean Delvare
2016-07-14  8:01 ` [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting oem strings to sysfs Allen Hung
2016-07-14  9:16   ` kbuild test robot
2016-07-19  9:03   ` Jean Delvare
2016-07-19 14:47     ` Mario_Limonciello
2016-08-02 13:43       ` Jean Delvare
2016-08-02 18:56         ` Mario_Limonciello
2016-08-15  9:55           ` Allen Hung
2016-08-24  8:05             ` Allen Hung
2016-07-26 21:03     ` Mario_Limonciello
2016-07-29  9:59       ` Allen Hung
2016-07-15  9:42 [PATCH 0/2] dmi-id: export " Allen Hung
2016-07-15  9:42 ` [PATCH 2/2] dmi-id: add dmi/id/oem group for exporting " Allen Hung

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).