Skip to contentSkip to conversation

Introduce support for Dell SMBIOS over WMI

PATCH Superseded Mario Limonciello 6 participants 36 messages Oct 9, 2017 – Oct 12, 2017

Subsystems (2)

v6 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v6 cover Introduce support for Dell SMBIOS over WMI

The existing way that the dell-smbios helper module and associated other drivers (dell-laptop, dell-wmi) communicate with the platform really isn't secure. It requires creating a buffer in physical DMA32 memory space and passing that to the platform via SMM.

Since the platform got a physical memory pointer, you've just got to trust that the platform has only modified (and accessed) memory within that buffer.

Dell Platform designers recognize this security risk and offer a safer way to communicate with the platform over ACPI. This is in turn exposed via a WMI interface to the OS.

When communicating over WMI-ACPI the communication doesn't occur with physical memory pointers. When the ASL is invoked, the fixed length ACPI buffer is copied to a small operating region. The ASL will invoke the SMI, and SMM will only have access to this operating region. When the ASL returns the buffer is copied back for the OS to process.

This method of communication should also deprecate the usage of the dcdbas kernel module and software dependent upon it's interface. Instead offer a character device interface for communicating with this ASL method to allow userspace to use instead.

To faciliate that this patch series introduces a generic way for WMI drivers to be able to create discoverable character devices with a predictable IOCTL interface through the WMI bus when desired. Requiring WMI drivers to explicitly ask for this functionality will act as an effective vendor whitelist to character device creation.

Some of this work is the basis for what will be a proper interpreter of MOF in the kernel and controls for what drivers will be able to do with that MOF.

NOTE: This patch series is intended to go on top of platform-drivers-x86 linux-next.

For convenience the entire series including those is also available here:
https://github.com/superm1/linux/tree/wmi-smbios
changes between v5 and v6:
* Adjust Kconfig for dell-smbios to not depend on anything.
- SMM and WMI drivers will both select dell-smbios
- Technically the module can run on it's own (it's just not useful)
* Add a new tokens sysfs interface
* Rework blacklisting into easily expandable structures
* Lock modules during ioctl call from WMI bus
* drop references to compat ioctl in both WMI and dell-smbios-wmi drivers. (Made sure ioctl worked in both 32 and 64 userspace though)
* dell-smbios-wmi
- s/buffer_size/req_buf_size/ to make it clearer that userspace doesn't get to set this, it's set internally.
- read just buffer length before reading whole structure from userspace
- if buffer length is too big, show a warning
- I tried to rename argument for unlocked_ioctl, but this caused problems in matching initialization lists, so still casting.
- Add comments clarifying everything happening in ioctl
changes between v4 and v5:
* Remove Andy's S suggested by in sysfs tokens patch
* Make some output in dell-wmi-descriptor debug only
* Adjust various Kconfig dependencies as recommended by Darren
* Drop patch to set dell-smbios to default on ACPI_WMI,
it's not needed after the Kconfig dependencies rework
* Move WSMT check patch to after WMI driver is introduced.
* Make common smbios call return value int as there could be errors now with drivers not being loaded.
* Make SMBIOS call methods for all drivers return status
* Reorder patches 2 and 4.
* Don't export symbols for calling functions on dispatchers
* wmi patch:
- use sprintf instead of strcpy
- remove needless bool for tracking found
- adjust logic to look for instance_count - 1, it's zero based not 1 based.
- Pass a callback to unlocked_ioctl instead of full file operations object
- ioctl: Don't fail on no bound WMI driver
- Add missing header for uapi
- Make helper macros include data types
- add compat ioctl
* dell-smbios:
- Add filtering functionality for SMBIOS calling interface
- Use dev_dbg rather than pr_debug where possible
* dell-smbios-wmi:
- test for handle on b1 table
- correct misc flags comment
- drop access checks
- use dev_dbg instead of pr_* calls
- use filtering functionality
- add mutexes around list add/remove
- switch from get_first_device to get_first_priv and inline
- add mutex locking to prevent unloading mid-call.
- update to new ioctl passing
- fix userspace uapi to use __u32 instead of u32
- Don't use a header file for internal only use
- make sure it works with compat ioctl
* dell-laptop: make dell_smbios_send_request local function for boilerplate calls.
* ioctl patch
- Change API to have a simpler structure to pass back and forth
- Rename header file
- Export to sysfs properly
- Add the size of the length variable into the requested buffersize to sysfs, do math in the driver when copying data around.
changes between v3 and v4:
* Make Dell WMI notifications driver fail notifications fail when WMI descriptor driver is unavailable.
* Add a patch to check for Dell OEM string to stop dell-smbios module from being loaded in unsupported systems manually.
* Split Dell WMI descriptor into it's own driver for others to query.
* Test the misc BIOS flags table to decide whether to run in WMI or SMI mode.
* s/dell-wmi-smbios/dell-smbios/ in a few patch titles
* Add missing Suggested-by to a patch from v2 (Sorry Andy S!)
* Adjust cleanup order of wmi character device.
* Fix a remaining reference to /dev/wmi-$driver
* Use get_order to get size for pages
* Split up dell-smbios into 3 drivers:
dell-smbios
-> dell-smbios-smm
-> dell-smbios-wmi
If either of the two dispatcher drivers is unloaded but the other still works, gracefully fall back to that driver
* Remove unneded open and release on file operations in WMI driver
* Switch to misc character device in WMI bus.
* Query the size of the calling interface buffer from WMI descriptor driver.
* Require userspace to use this information to build an appropriately sized buffer.
* Verify the size of buffer passed from userspace matches expectation of buffer processed in kernel.
* Add more documentation about the IOCTL API.
* Add in a recommendation from Andy S about outputing tokens
* Add a patch to test for non-functional SMM due to WSMT
* Define macros for IOCTL's through the WMI bus.
* Pass all IOCTL calls for WMI drivers through WMI bus
WMI bus will guarantee instance count matches and prevent creating too many more IOCTLs.
changes between v2 and v3:
* Drop patches 1-7, they're in Darren's review tree now
* Add missing newline on new Documentation
* Add Reviewed by from Edward O'Callaghan
* Adjust path of character device from /dev/wmi-$driver to /dev/wmi/$driver
* Store wmi_device pointer rather than using a boolean has_wmi to indicate driver is running in WMI mode
* Don't guard free_page from freeing NULL (this is OK)
* New patch: add wmidev_evaluate_method to wmi bus as recommended by Andy L
* Adjust ACPI-WMI interface for this patch change ^
* Add back in sysfs token patch, drop 2nd and 3rd ioctls per discussion on mailing list.
* On sysfs interface: adjust the delimiter to be tabs
* Drop the rename dell-smbios -> dell-wmi-smbios patch
* Remove/move some unnecessary tests for CONFIG_DCDBAS
* Reword s/platform/SMM/ in the WMI-ACPI patch.
* Update Kconfig to recommend using CONFIG_DCDBAS on old machines.
* Allocate buffer to the same pointer regardless of the struct assigned to it. Keep track of the buffer size for cleaning up.
* Explain policy around character device creation in commit message
changes between v1 and v2:
* Introduce another patch to sort the includes in wmi.c
* Introduce another patch to cleanup dell_wmi_check_descriptor_buffer checks.
* Add a commit message to the pr_fmt commit
* Introduce includes to wmi.c in proper location
* Add Reviewed-by to relevant patches from Pali
* Make the WMI introduction patch fallback to legacy SMI
if compiled with CONFIG_DCDBAS
* Separate format of WMI and SMI buffers. WMI buffer supports more arguments and data.
* Adjust the rename patch for changes to fallback
* Drop sysfs token creation patch
* Adjust WMI descriptor check patch for changes to fallback
* introduce another patch to remove needless includes in dell-smbios.c
* Add token ioctl interface to character device.
- Can query number of tokens
- Can query values in all tokens
* Expose format of all buffers and IOCTL commands to uapi header
* Drop the read interface from character device. It doesn't make sense with multiple different ioctl methods.
* Default WMI interface to 32k (This would normally be queried via MOF, but that's not possible yet)
* Create separate buffers for WMI and SMI. If WMI is available, free the SMI buffer.
* Reorder patches so all fixups come first in the series.

Mario Limonciello (14):
platform/x86: wmi: Add new method wmidev_evaluate_method platform/x86: dell-wmi: increase severity of some failures platform/x86: dell-wmi: clean up wmi descriptor check platform/x86: dell-wmi: allow 32k return size in the descriptor platform/x86: dell-wmi-descriptor: split WMI descriptor into it's own
driver
platform/x86: wmi: Don't allow drivers to get each other's GUIDs platform/x86: dell-smbios: only run if proper oem string is detected platform/x86: dell-smbios: Add a sysfs interface for SMBIOS tokens platform/x86: dell-smbios: Introduce dispatcher for SMM calls platform/x86: dell-smbios: add filtering capability for requests platform/x86: dell-smbios-wmi: Add new WMI dispatcher driver platform/x86: dell-smbios-smm: test for WSMT
platform/x86: wmi: create character devices when requested by drivers platform/x86: dell-smbios-wmi: introduce userspace interface

 Documentation/ABI/testing/dell-smbios-wmi          |  41 ++
 .../ABI/testing/sysfs-platform-dell-smbios         |  20 +
 .../ABI/testing/sysfs-platform-dell-smbios-wmi     |  10 +
 MAINTAINERS                                        |  26 ++
 drivers/platform/x86/Kconfig                       |  34 +-
 drivers/platform/x86/Makefile                      |   3 +
 drivers/platform/x86/dell-laptop.c                 | 255 +++++-------
 drivers/platform/x86/dell-smbios-smm.c             | 170 ++++++++
 drivers/platform/x86/dell-smbios-wmi.c             | 314 +++++++++++++++
 drivers/platform/x86/dell-smbios.c                 | 434 +++++++++++++++++++--
 drivers/platform/x86/dell-smbios.h                 |  26 +-
 drivers/platform/x86/dell-wmi-descriptor.c         | 162 ++++++++
 drivers/platform/x86/dell-wmi-descriptor.h         |  18 +
 drivers/platform/x86/dell-wmi.c                    |  99 +----
 drivers/platform/x86/wmi.c                         | 114 +++++-
 include/linux/wmi.h                                |  13 +-
 include/uapi/linux/dell-smbios.h                   |  42 ++
 include/uapi/linux/wmi.h                           |  19 +
 18 files changed, 1469 insertions(+), 331 deletions(-)
 create mode 100644 Documentation/ABI/testing/dell-smbios-wmi
 create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-smbios
 create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-smbios-wmi
 create mode 100644 drivers/platform/x86/dell-smbios-smm.c
 create mode 100644 drivers/platform/x86/dell-smbios-wmi.c
 create mode 100644 drivers/platform/x86/dell-wmi-descriptor.c
 create mode 100644 drivers/platform/x86/dell-wmi-descriptor.h
 create mode 100644 include/uapi/linux/dell-smbios.h
 create mode 100644 include/uapi/linux/wmi.h
Signature · 1 line
2.14.1
#1 lore raw

PATCH v6 1/14 platform/x86: wmi: Add new method wmidev_evaluate_method

Drivers properly using the wmibus can pass their wmi_device pointer rather than the GUID back to the WMI bus to evaluate the proper methods.

Any "new" drivers added that use the WMI bus should use this rather than the old wmi_evaluate_method that would take the GUID.

---
 drivers/platform/x86/wmi.c | 28 ++++++++++++++++++++++++----
 include/linux/wmi.h        |  6 ++++++
 2 files changed, 30 insertions(+), 4 deletions(-)
drivers/platform/x86/wmi.c +24 -4
index 7a05843aff19..4d73a87c2ddf 100644
@@ -200,6 +200,28 @@ static acpi_status wmi_method_enable(struct wmi_block *wblock, int enable)
  */
 acpi_status wmi_evaluate_method(const char *guid_string, u8 instance,
 u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
+{
+	struct wmi_block *wblock = NULL;
+
+	if (!find_guid(guid_string, &wblock))
+		return AE_ERROR;
+	return wmidev_evaluate_method(&wblock->dev, instance, method_id,
+				      in, out);
+}
+EXPORT_SYMBOL_GPL(wmi_evaluate_method);
+
+/**
+ * wmidev_evaluate_method - Evaluate a WMI method
+ * @wdev: A wmi bus device from a driver
+ * @instance: Instance index
+ * @method_id: Method ID to call
+ * &in: Buffer containing input for the method call
+ * &out: Empty buffer to return the method results
+ *
+ * Call an ACPI-WMI method
+ */
+acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance,
+	u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
 {
 	struct guid_block *block = NULL;
 	struct wmi_block *wblock = NULL;
@@ -209,9 +231,7 @@ u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
 	union acpi_object params[3];
 	char method[5] = "WM";
 
-	if (!find_guid(guid_string, &wblock))
-		return AE_ERROR;
-
+	wblock = container_of(wdev, struct wmi_block, dev);
 	block = &wblock->gblock;
 	handle = wblock->acpi_device->handle;
 
@@ -246,7 +266,7 @@ u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
 
 	return status;
 }
-EXPORT_SYMBOL_GPL(wmi_evaluate_method);
+EXPORT_SYMBOL_GPL(wmidev_evaluate_method);
 
 static acpi_status __query_block(struct wmi_block *wblock, u8 instance,
 				 struct acpi_buffer *out)
include/linux/wmi.h +6 -0
index cd0d7734dc49..2cd10c3b89e9 100644
@@ -26,6 +26,12 @@ struct wmi_device {
 	bool setable;
 };
 
+/* evaluate the ACPI method associated with this device */
+extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev,
+					  u8 instance, u32 method_id,
+					  const struct acpi_buffer *in,
+					  struct acpi_buffer *out);
+
 /* Caller must kfree the result. */
 extern union acpi_object *wmidev_block_query(struct wmi_device *wdev,
 					     u8 instance);
Signature · 1 line
2.14.1
#2 lore raw

PATCH v6 2/14 platform/x86: dell-wmi: increase severity of some failures

In reply to Mario Limonciello

There is a lot of error checking in place for the format of the WMI descriptor buffer, but some of the potentially raised issues should be considered critical failures.

If the buffer size or header don't match, this is a good indication that the buffer format changed in a way that the rest of the data should not be relied upon.

For the remaining data set vectors, continue to notate a warning in undefined results, but as those are fields that the descriptor intended to refer to other applications, don't fail if they're new values.

---
 drivers/platform/x86/dell-wmi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/platform/x86/dell-wmi.c +7 -6
index 1fbef560ca67..2cfaaa8faf0a 100644
@@ -657,17 +657,18 @@ static int dell_wmi_check_descriptor_buffer(struct wmi_device *wdev)
 		dev_err(&wdev->dev,
 			"Dell descriptor buffer has invalid length (%d)\n",
 			obj->buffer.length);
-		if (obj->buffer.length < 16) {
-			ret = -EINVAL;
-			goto out;
-		}
+		ret = -EINVAL;
+		goto out;
 	}
 
 	buffer = (u32 *)obj->buffer.pointer;
 
-	if (buffer[0] != 0x4C4C4544 && buffer[1] != 0x494D5720)
-		dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature (%*ph)\n",
+	if (buffer[0] != 0x4C4C4544 && buffer[1] != 0x494D5720) {
+		dev_err(&wdev->dev, "Dell descriptor buffer has invalid signature (%*ph)\n",
 			8, buffer);
+		ret = -EINVAL;
+		goto out;
+	}
 
 	if (buffer[2] != 0 && buffer[2] != 1)
 		dev_warn(&wdev->dev, "Dell descriptor buffer has unknown version (%d)\n",
Signature · 1 line
2.14.1
#3 lore raw

PATCH v6 3/14 platform/x86: dell-wmi: clean up wmi descriptor check

In reply to Mario Limonciello

Some cases the wrong type was used for errors and checks can be done more cleanly.

---
 drivers/platform/x86/dell-wmi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/platform/x86/dell-wmi.c +5 -5
index 2cfaaa8faf0a..ece2fe341f01 100644
@@ -663,19 +663,19 @@ static int dell_wmi_check_descriptor_buffer(struct wmi_device *wdev)
 
 	buffer = (u32 *)obj->buffer.pointer;
 
-	if (buffer[0] != 0x4C4C4544 && buffer[1] != 0x494D5720) {
-		dev_err(&wdev->dev, "Dell descriptor buffer has invalid signature (%*ph)\n",
-			8, buffer);
+	if (strncmp(obj->string.pointer, "DELL WMI", 8) != 0) {
+		dev_err(&wdev->dev, "Dell descriptor buffer has invalid signature (%8ph)\n",
+			buffer);
 		ret = -EINVAL;
 		goto out;
 	}
 
 	if (buffer[2] != 0 && buffer[2] != 1)
-		dev_warn(&wdev->dev, "Dell descriptor buffer has unknown version (%d)\n",
+		dev_warn(&wdev->dev, "Dell descriptor buffer has unknown version (%u)\n",
 			buffer[2]);
 
 	if (buffer[3] != 4096)
-		dev_warn(&wdev->dev, "Dell descriptor buffer has invalid buffer length (%d)\n",
+		dev_warn(&wdev->dev, "Dell descriptor buffer has invalid buffer length (%u)\n",
 			buffer[3]);
 
 	priv->interface_version = buffer[2];
Signature · 1 line
2.14.1
#4 lore raw

PATCH v6 4/14 platform/x86: dell-wmi: allow 32k return size in the descriptor

In reply to Mario Limonciello

Some platforms this year will be adopting 32k WMI buffer, so don't complain when encountering those.

---
 drivers/platform/x86/dell-wmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/dell-wmi.c +2 -2
index ece2fe341f01..c8c7f4f9326c 100644
@@ -624,7 +624,7 @@ static void dell_wmi_input_destroy(struct wmi_device *wdev)
  * Vendor Signature          0       4    "DELL"
  * Object Signature          4       4    " WMI"
  * WMI Interface Version     8       4    <version>
- * WMI buffer length        12       4    4096
+ * WMI buffer length        12       4    4096 or 32768
  */
 static int dell_wmi_check_descriptor_buffer(struct wmi_device *wdev)
 {
@@ -674,7 +674,7 @@ static int dell_wmi_check_descriptor_buffer(struct wmi_device *wdev)
 		dev_warn(&wdev->dev, "Dell descriptor buffer has unknown version (%u)\n",
 			buffer[2]);
 
-	if (buffer[3] != 4096)
+	if (desc_buffer[3] != 4096 && desc_buffer[3] != 32768)
 		dev_warn(&wdev->dev, "Dell descriptor buffer has invalid buffer length (%u)\n",
 			buffer[3]);
 
Signature · 1 line
2.14.1
#5 lore raw

PATCH v6 5/14 platform/x86: dell-wmi-descriptor: split WMI descriptor into it's own driver

In reply to Mario Limonciello

All communication on individual GUIDs should occur in separate drivers. Allowing a driver to communicate with the bus to another GUID is just a hack that discourages drivers to adopt the bus model.

The information found from the WMI descriptor driver is now exported for use by other drivers.

---
 MAINTAINERS                                |   5 +
 drivers/platform/x86/Kconfig               |   5 +
 drivers/platform/x86/Makefile              |   1 +
 drivers/platform/x86/dell-wmi-descriptor.c | 162 +++++++++++++++++++++++++++++
 drivers/platform/x86/dell-wmi-descriptor.h |  18 ++++
 drivers/platform/x86/dell-wmi.c            |  89 ++--------------
 6 files changed, 198 insertions(+), 82 deletions(-)
 create mode 100644 drivers/platform/x86/dell-wmi-descriptor.c
 create mode 100644 drivers/platform/x86/dell-wmi-descriptor.h
MAINTAINERS +5 -0
index 08b96f77f618..659dbeec4191 100644
@@ -4002,6 +4002,11 @@ M:	Pali Rohár <[email protected]>
 S:	Maintained
 F:	drivers/platform/x86/dell-wmi.c
 
+DELL WMI DESCRIPTOR DRIVER
+M:	Mario Limonciello <[email protected]>
+S:	Maintained
+F:	drivers/platform/x86/dell-wmi-descriptor.c
+
 DELTA ST MEDIA DRIVER
 M:	Hugues Fruchet <[email protected]>
 L:	[email protected]
drivers/platform/x86/Kconfig +5 -0
index 1f7959ff055c..7722923c968c 100644
@@ -121,6 +121,7 @@ config DELL_WMI
 	depends on DMI
 	depends on INPUT
 	depends on ACPI_VIDEO || ACPI_VIDEO = n
+	select DELL_WMI_DESCRIPTOR
 	select DELL_SMBIOS
 	select INPUT_SPARSEKMAP
 	---help---
@@ -129,6 +130,10 @@ config DELL_WMI
 	  To compile this driver as a module, choose M here: the module will
 	  be called dell-wmi.
 
+config DELL_WMI_DESCRIPTOR
+	tristate
+	depends on ACPI_WMI
+
 config DELL_WMI_AIO
 	tristate "WMI Hotkeys for Dell All-In-One series"
 	depends on ACPI_WMI
drivers/platform/x86/Makefile +1 -0
index 2b315d0df3b7..8636f5d3424f 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_COMPAL_LAPTOP)	+= compal-laptop.o
 obj-$(CONFIG_DELL_SMBIOS)	+= dell-smbios.o
 obj-$(CONFIG_DELL_LAPTOP)	+= dell-laptop.o
 obj-$(CONFIG_DELL_WMI)		+= dell-wmi.o
+obj-$(CONFIG_DELL_WMI_DESCRIPTOR)	+= dell-wmi-descriptor.o
 obj-$(CONFIG_DELL_WMI_AIO)	+= dell-wmi-aio.o
 obj-$(CONFIG_DELL_WMI_LED)	+= dell-wmi-led.o
 obj-$(CONFIG_DELL_SMO8800)	+= dell-smo8800.o
drivers/platform/x86/dell-wmi-descriptor.c new file +162 -0

162 lines not on this page · raw message

drivers/platform/x86/dell-wmi-descriptor.h new file +18 -0
new file mode 100644
index 000000000000..3e652c6da034
@@ -0,0 +1,18 @@
+/*
+ *
+ *  Copyright (c) 2017 Dell Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#ifndef _DELL_WMI_DESCRIPTOR_H_
+#define _DELL_WMI_DESCRIPTOR_H_
+
+#include <linux/wmi.h>
+
+bool dell_wmi_get_interface_version(u32 *version);
+bool dell_wmi_get_size(u32 *size);
+
+#endif
drivers/platform/x86/dell-wmi.c +7 -82

139 lines not on this page · raw message

Signature · 1 line
2.14.1
#6 lore raw

Re: [PATCH v6 05/14] platform/x86: dell-wmi-descriptor: split WMI descriptor into it's own driver

drivers/platform/x86/dell-wmi-descriptor.c line 41

Quoted 9 lines · On Monday 09 October 2017 17:51:43 Mario Limonciello wrote:
drivers/platform/x86/dell-wmi-descriptor.c new file +9 -0
+bool dell_wmi_get_interface_version(u32 *version)
+{
+	struct descriptor_priv *priv;
+
+	priv = list_first_entry_or_null(&wmi_list,
+					struct descriptor_priv,
+					list);
+	if (!priv)
+		return false;

This introduce race condition. In case callee of this function is executed before binding 8D9DDCBC-A997-11DA-B012-B622A1EF5492 WMI device into this dell-wmi-descriptor driver, then this function dell_wmi_get_interface_version() returns false. Even it is running on supported machine.

Loading of modulus and also binding devices to drivers (registered by modules) is is asynchronous.

In case everything is linked into vmlinux binary, this problem could happen too. Binding & initialization of WMI device to this driver can be postponed and callee (dell-wmi) would get false.

Quoted 4 lines
drivers/platform/x86/dell-wmi-descriptor.c new file +4 -0
+	*version = priv->interface_version;
+	return true;
+}
+EXPORT_SYMBOL_GPL(dell_wmi_get_interface_version);

drivers/platform/x86/dell-wmi-descriptor.c line 55

Quoted 10 lines
drivers/platform/x86/dell-wmi-descriptor.c new file +10 -0
+
+bool dell_wmi_get_size(u32 *size)
+{
+	struct descriptor_priv *priv;
+
+	priv = list_first_entry_or_null(&wmi_list,
+					struct descriptor_priv,
+					list);
+	if (!priv)
+		return false;

And same there.

Quoted 4 lines
drivers/platform/x86/dell-wmi-descriptor.c new file +4 -0
+	*size = priv->size;
+	return true;
+}
+EXPORT_SYMBOL_GPL(dell_wmi_get_size);
Signature · 2 lines
Pali Rohár
[email protected]
#7 lore raw

RE: [PATCH v6 05/14] platform/x86: dell-wmi-descriptor: split WMI descriptor into it's own driver

Quoted 28 lines

-----Original Message-----
From: Pali Rohár [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 3:18 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Greg KH <[email protected]>
Subject: Re: [PATCH v6 05/14] platform/x86: dell-wmi-descriptor: split WMI descriptor into it's own driver

drivers/platform/x86/dell-wmi-descriptor.c line 41

Quoted 9 lines · On Monday 09 October 2017 17:51:43 Mario Limonciello wrote:
drivers/platform/x86/dell-wmi-descriptor.c new file +9 -0
+bool dell_wmi_get_interface_version(u32 *version)
+{
+	struct descriptor_priv *priv;
+
+	priv = list_first_entry_or_null(&wmi_list,
+					struct descriptor_priv,
+					list);
+	if (!priv)
+		return false;

This introduce race condition. In case callee of this function is executed before binding 8D9DDCBC-A997-11DA-B012-B622A1EF5492 WMI device into this dell-wmi-descriptor driver, then this function dell_wmi_get_interface_version() returns false. Even it is running on supported machine.

Quoted 3 lines

Loading of modulus and also binding devices to drivers (registered by modules) is is asynchronous.

I suppose you're right, module dependency ordering doesn't necessarily guarantee binding. I'll add in some deferred probing and binding checking.

Quoted 30 lines

In case everything is linked into vmlinux binary, this problem could happen too. Binding & initialization of WMI device to this driver can be postponed and callee (dell-wmi) would get false.

Quoted 4 lines
drivers/platform/x86/dell-wmi-descriptor.c new file +4 -0
+	*version = priv->interface_version;
+	return true;
+}
+EXPORT_SYMBOL_GPL(dell_wmi_get_interface_version);

drivers/platform/x86/dell-wmi-descriptor.c line 55

Quoted 10 lines
drivers/platform/x86/dell-wmi-descriptor.c new file +10 -0
+
+bool dell_wmi_get_size(u32 *size)
+{
+	struct descriptor_priv *priv;
+
+	priv = list_first_entry_or_null(&wmi_list,
+					struct descriptor_priv,
+					list);
+	if (!priv)
+		return false;

And same there.

drivers/platform/x86/dell-wmi-descriptor.c line 59

Quoted 4 lines
drivers/platform/x86/dell-wmi-descriptor.c new file +4 -0
+	*size = priv->size;
+	return true;
+}
+EXPORT_SYMBOL_GPL(dell_wmi_get_size);

--
Pali Rohár
[email protected]

#8 lore raw

PATCH v6 6/14 platform/x86: wmi: Don't allow drivers to get each other's GUIDs

In reply to Mario Limonciello

The only driver using this was dell-wmi, and it really was a hack. The driver was getting a data attribute from another driver and this type of action should not be encouraged.

Rather drivers that need to interact with one another should pass data back and forth via exported functions.

---
 drivers/platform/x86/wmi.c | 17 -----------------
 include/linux/wmi.h        |  4 ----
 2 files changed, 21 deletions(-)
drivers/platform/x86/wmi.c +0 -17
index 4d73a87c2ddf..bcb41c1c7f52 100644
@@ -368,23 +368,6 @@ union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance)
 }
 EXPORT_SYMBOL_GPL(wmidev_block_query);
 
-struct wmi_device *wmidev_get_other_guid(struct wmi_device *wdev,
-					 const char *guid_string)
-{
-	struct wmi_block *this_wb = container_of(wdev, struct wmi_block, dev);
-	struct wmi_block *other_wb;
-
-	if (!find_guid(guid_string, &other_wb))
-		return NULL;
-
-	if (other_wb->acpi_device != this_wb->acpi_device)
-		return NULL;
-
-	get_device(&other_wb->dev.dev);
-	return &other_wb->dev;
-}
-EXPORT_SYMBOL_GPL(wmidev_get_other_guid);
-
 /**
  * wmi_set_block - Write to a WMI block
  * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
include/linux/wmi.h +0 -4
index 2cd10c3b89e9..ddee427e0721 100644
@@ -36,10 +36,6 @@ extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev,
 extern union acpi_object *wmidev_block_query(struct wmi_device *wdev,
 					     u8 instance);
 
-/* Gets another device on the same bus.  Caller must put_device the result. */
-extern struct wmi_device *wmidev_get_other_guid(struct wmi_device *wdev,
-						const char *guid_string);
-
 struct wmi_device_id {
 	const char *guid_string;
 };
Signature · 1 line
2.14.1
#9 lore raw

PATCH v6 7/14 platform/x86: dell-smbios: only run if proper oem string is detected

In reply to Mario Limonciello

The proper way to indicate that a system is a 'supported' Dell System is by the presence of this string in OEM strings.

Allowing the driver to load on non-Dell systems will have undefined results.

---
 drivers/platform/x86/dell-smbios.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/platform/x86/dell-smbios.c +7 -0
index e9b1ca07c872..7e779278d054 100644
@@ -172,8 +172,15 @@ static void __init find_tokens(const struct dmi_header *dm, void *dummy)
 
 static int __init dell_smbios_init(void)
 {
+	const struct dmi_device *valid;
 	int ret;
 
+	valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Dell System", NULL);
+	if (!valid) {
+		pr_err("Unable to run on non-Dell system\n");
+		return -ENODEV;
+	}
+
 	dmi_walk(find_tokens, NULL);
 
 	if (!da_tokens)  {
Signature · 1 line
2.14.1
#10 lore raw

PATCH v6 8/14 platform/x86: dell-smbios: Add a sysfs interface for SMBIOS tokens

In reply to Mario Limonciello

Currently userspace tools can access system tokens via the dcdbas kernel module and a SMI call that will cause the platform to execute SMM code.

With a goal in mind of deprecating the dcdbas kernel module a different method for accessing these tokens from userspace needs to be created.

This is intentionally marked to only be readable as root as it can contain sensitive information about the platform's configuration.

While adding this interface I found that some tokens are duplicated. These need to be ignored from sysfs to avoid duplicate files.

MAINTAINERS was missing for this driver. Add myself and Pali to maintainers list for it.

---
 .../ABI/testing/sysfs-platform-dell-smbios         |  20 ++
 MAINTAINERS                                        |   7 +
 drivers/platform/x86/dell-smbios.c                 | 205 ++++++++++++++++++++-
 3 files changed, 231 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-smbios
Documentation/ABI/testing/sysfs-platform-dell-smbios new file +20 -0
new file mode 100644
index 000000000000..6700189832f5
@@ -0,0 +1,20 @@
+What:		/sys/devices/platform/<platform>/tokens/*
+Date:		November 2017
+KernelVersion:	4.15
+Contact:	"Mario Limonciello" <[email protected]>
+Description:
+		A read-only description of Dell platform tokens
+		available on the machine.
+
+		Each token attribute is available as a pair of
+		sysfs attributes readable by root.
+
+		For example the token ID "5" would be available
+		as the following attributes:
+
+		0005_location
+		0005_value
+
+		Tokens will vary from machine to machine, and
+		only tokens available on that machine will be
+		displayed.
MAINTAINERS +7 -0
index 659dbeec4191..2e3f2aea0370 100644
@@ -3967,6 +3967,13 @@ M:	"Maciej W. Rozycki" <[email protected]>
 S:	Maintained
 F:	drivers/net/fddi/defxx.*
 
+DELL SMBIOS DRIVER
+M:	Pali Rohár <[email protected]>
+M:	Mario Limonciello <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/x86/dell-smbios.*
+
 DELL LAPTOP DRIVER
 M:	Matthew Garrett <[email protected]>
 M:	Pali Rohár <[email protected]>
drivers/platform/x86/dell-smbios.c +204 -1

246 lines not on this page · raw message

Signature · 1 line
2.14.1
#11 lore raw

PATCH v6 9/14 platform/x86: dell-smbios: Introduce dispatcher for SMM calls

In reply to Mario Limonciello

This splits up the dell-smbios driver into two drivers:
* dell-smbios
* dell-smbios-smm

dell-smbios can operate with multiple different dispatcher drivers to perform SMBIOS operations.

Also modify the interface that dell-laptop and dell-wmi use align to this model more closely. Rather than a single global buffer being allocated for all drivers, each driver will allocate and be responsible for it's own buffer. The pointer will be passed to the calling function and each dispatcher driver will then internally copy it to the proper location to perform it's call.

---
 MAINTAINERS                            |   6 +
 drivers/platform/x86/Kconfig           |  15 +-
 drivers/platform/x86/Makefile          |   1 +
 drivers/platform/x86/dell-laptop.c     | 255 ++++++++++++---------------------
 drivers/platform/x86/dell-smbios-smm.c | 136 ++++++++++++++++++
 drivers/platform/x86/dell-smbios.c     | 113 +++++++++------
 drivers/platform/x86/dell-smbios.h     |  13 +-
 drivers/platform/x86/dell-wmi.c        |  11 +-
 8 files changed, 329 insertions(+), 221 deletions(-)
 create mode 100644 drivers/platform/x86/dell-smbios-smm.c
MAINTAINERS +6 -0
index 2e3f2aea0370..8faf08ebcfee 100644
@@ -3974,6 +3974,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/platform/x86/dell-smbios.*
 
+DELL SMBIOS SMM DRIVER
+M:	Mario Limonciello <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/x86/dell-smbios-smm.c
+
 DELL LAPTOP DRIVER
 M:	Matthew Garrett <[email protected]>
 M:	Pali Rohár <[email protected]>
drivers/platform/x86/Kconfig +11 -4
index 7722923c968c..53a2de781de6 100644
@@ -93,12 +93,19 @@ config ASUS_LAPTOP
 
 config DELL_SMBIOS
 	tristate
-	select DCDBAS
+
+config DELL_SMBIOS_SMM
+	tristate "Dell SMBIOS calling interface (SMM implementation)"
+	depends on DCDBAS
+	default DCDBAS
+	select DELL_SMBIOS
 	---help---
-	This module provides common functions for kernel modules using
-	Dell SMBIOS.
+	This provides an implementation for the Dell SMBIOS calling interface
+	communicated over SMI/SMM.
 
-	If you have a Dell laptop, say Y or M here.
+	If you have a Dell computer from <=2017 you should say Y or M here.
+	If you aren't sure and this module doesn't work for your computer
+	it just won't load.
 
 config DELL_LAPTOP
 	tristate "Dell Laptop Extras"
drivers/platform/x86/Makefile +1 -0
index 8636f5d3424f..e743615241f8 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_MSI_LAPTOP)	+= msi-laptop.o
 obj-$(CONFIG_ACPI_CMPC)		+= classmate-laptop.o
 obj-$(CONFIG_COMPAL_LAPTOP)	+= compal-laptop.o
 obj-$(CONFIG_DELL_SMBIOS)	+= dell-smbios.o
+obj-$(CONFIG_DELL_SMBIOS_SMM)	+= dell-smbios-smm.o
 obj-$(CONFIG_DELL_LAPTOP)	+= dell-laptop.o
 obj-$(CONFIG_DELL_WMI)		+= dell-wmi.o
 obj-$(CONFIG_DELL_WMI_DESCRIPTOR)	+= dell-wmi-descriptor.o
drivers/platform/x86/dell-laptop.c +89 -166

506 lines not on this page · raw message

drivers/platform/x86/dell-smbios-smm.c new file +136 -0

136 lines not on this page · raw message

drivers/platform/x86/dell-smbios.c +71 -42

176 lines not on this page · raw message

drivers/platform/x86/dell-smbios.h +8 -5
index 45cbc2292cd3..fe28964da499 100644
@@ -16,6 +16,8 @@
 #ifndef _DELL_SMBIOS_H_
 #define _DELL_SMBIOS_H_
 
+#include <linux/device.h>
+
 struct notifier_block;
 
 /* This structure will be modified by the firmware when we enter
@@ -37,12 +39,13 @@ struct calling_interface_token {
 	};
 };
 
-int dell_smbios_error(int value);
 
-struct calling_interface_buffer *dell_smbios_get_buffer(void);
-void dell_smbios_clear_buffer(void);
-void dell_smbios_release_buffer(void);
-void dell_smbios_send_request(int class, int select);
+int dell_smbios_register_device(struct device *d, void *call_fn);
+void dell_smbios_unregister_device(struct device *d);
+
+void dell_smbios_get_smm_address(int *address, int *command);
+int dell_smbios_error(int value);
+int dell_smbios_call(struct calling_interface_buffer *buffer);
 
 struct calling_interface_token *dell_smbios_find_token(int tokenid);
 
drivers/platform/x86/dell-wmi.c +7 -4
index 90d7e8e55e9b..b74f48d17116 100644
@@ -641,13 +641,16 @@ static int dell_wmi_events_set_enabled(bool enable)
 	struct calling_interface_buffer *buffer;
 	int ret;
 
-	buffer = dell_smbios_get_buffer();
+	buffer = (void *)get_zeroed_page(GFP_KERNEL);
+	buffer->class = 17;
+	buffer->select = 3;
 	buffer->input[0] = 0x10000;
 	buffer->input[1] = 0x51534554;
 	buffer->input[3] = enable;
-	dell_smbios_send_request(17, 3);
-	ret = buffer->output[0];
-	dell_smbios_release_buffer();
+	ret = dell_smbios_call(buffer);
+	if (ret == 0)
+		ret = buffer->output[0];
+	free_page((unsigned long)buffer);
 
 	return dell_smbios_error(ret);
 }
Signature · 1 line
2.14.1
#12 lore raw

Re: [PATCH v6 09/14] platform/x86: dell-smbios: Introduce dispatcher for SMM calls

drivers/platform/x86/dell-laptop.c static void dell_rfkill_update_hw_state(struct rfkill *rfkill, int radio, · line 482

Quoted 13 lines · On Monday 09 October 2017 17:51:47 Mario Limonciello wrote:

static void dell_rfkill_query(struct rfkill *rfkill, void *data) {

drivers/platform/x86/dell-laptop.c +1 -5
-	struct calling_interface_buffer *buffer;
 	int radio = ((unsigned long)data & 0xF);
 	int hwswitch;
 	int status;
 	int ret;
 
-	buffer = dell_smbios_get_buffer();
-
-	dell_smbios_send_request(17, 11);
-	ret = buffer->output[0];
+	ret = dell_send_request(17, 11, 0, 0, 0, 0);

Basically I do not like function which takes ten numeric parameters. Before in this code there was just function with 2 parameters, now there are lot of zero parameters, without information what which parameter means...

drivers/platform/x86/dell-smbios.c static struct calling_interface_token *da_tokens; · line 58

Quoted 10 lines
drivers/platform/x86/dell-smbios.c +6 -0
index ade248646578..386130811a34 100644
+void dell_smbios_get_smm_address(int *address, int *code)
+{
+	*address = da_command_address;
+	*code = da_command_code;
+}
+EXPORT_SYMBOL_GPL(dell_smbios_get_smm_address);

Should not be this function in dell-smbios-smm driver instead of the dispatcher? It has in name "smm" and also is specific for smm driver...

drivers/platform/x86/dell-wmi.c static int dell_wmi_events_set_enabled(bool enable) · line 644

Quoted 10 lines
drivers/platform/x86/dell-wmi.c +1 -1
index 90d7e8e55e9b..b74f48d17116 100644
@@ -641,13 +641,16 @@ static int dell_wmi_events_set_enabled(bool enable)
 	struct calling_interface_buffer *buffer;
 	int ret;
 
-	buffer = dell_smbios_get_buffer();
+	buffer = (void *)get_zeroed_page(GFP_KERNEL);

It is still needed to ask for page? Is not enough to allocate memory via some *alloc function?

Quoted 15 lines
drivers/platform/x86/dell-wmi.c +6 -3
+	buffer->class = 17;
+	buffer->select = 3;
 	buffer->input[0] = 0x10000;
 	buffer->input[1] = 0x51534554;
 	buffer->input[3] = enable;
-	dell_smbios_send_request(17, 3);
-	ret = buffer->output[0];
-	dell_smbios_release_buffer();
+	ret = dell_smbios_call(buffer);
+	if (ret == 0)
+		ret = buffer->output[0];
+	free_page((unsigned long)buffer);
 
 	return dell_smbios_error(ret);
 }
Signature · 2 lines
Pali Rohár
[email protected]
#13 lore raw

RE: [PATCH v6 09/14] platform/x86: dell-smbios: Introduce dispatcher for SMM calls

Quoted 20 lines

-----Original Message-----
From: Pali Rohár [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 11:01 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Greg KH <[email protected]>
Subject: Re: [PATCH v6 09/14] platform/x86: dell-smbios: Introduce dispatcher for SMM calls

Quoted 8 lines · On Monday 09 October 2017 17:51:47 Mario Limonciello wrote:

static void dell_rfkill_query(struct rfkill *rfkill, void *data) {

drivers/platform/x86/dell-laptop.c +0 -1
-	struct calling_interface_buffer *buffer;
 	int radio = ((unsigned long)data & 0xF);
 	int hwswitch;
 	int status;
 	int ret;
Quoted 11 lines

drivers/platform/x86/dell-laptop.c static int dell_rfkill_set(void *data, bool blocked) · line 433

Quoted 5 lines
drivers/platform/x86/dell-laptop.c +1 -4
-	buffer = dell_smbios_get_buffer();
-
-	dell_smbios_send_request(17, 11);
-	ret = buffer->output[0];
+	ret = dell_send_request(17, 11, 0, 0, 0, 0);

Basically I do not like function which takes ten numeric parameters. Before in this code there was just function with 2 parameters, now there are lot of zero parameters, without information what which parameter means...

In an earlier patch Darren wanted to keep dell_send_request around and remove code that was duplicated multiple times to clear buffer, set arguments etc, can you please comment on what exactly you would prefer?

It's very obvious if you look at the dell_send_request function what is happening.

Quoted 14 lines

drivers/platform/x86/dell-

Quoted 1 line
drivers/platform/x86/dell- renamed from drivers/platform/x86/dell-smbios.c +0 -0

smbios.c

drivers/platform/x86/dell-smbios.c static struct calling_interface_token *da_tokens; · line 58

Quoted 9 lines

index ade248646578..386130811a34 100644

drivers/platform/x86/dell-smbios.c +6 -0
+void dell_smbios_get_smm_address(int *address, int *code)
+{
+	*address = da_command_address;
+	*code = da_command_code;
+}
+EXPORT_SYMBOL_GPL(dell_smbios_get_smm_address);

Should not be this function in dell-smbios-smm driver instead of the dispatcher? It has in name "smm" and also is specific for smm driver...

That would mean parsing DA table in both drivers. Since it was already available in dell-smbios driver, it made sense to me to export it to the other driver this way.

Quoted 9 lines
Quoted 9 lines
drivers/platform/x86/dell-wmi.c +0 -0
index 90d7e8e55e9b..b74f48d17116 100644
@@ -641,13 +641,16 @@ static int dell_wmi_events_set_enabled(bool enable)
 	struct calling_interface_buffer *buffer;
 	int ret;
 
Quoted 5 lines

drivers/platform/x86/dell-wmi.c static int dell_wmi_events_set_enabled(bool enable) · line 644

Quoted 2 lines
drivers/platform/x86/dell-wmi.c +1 -1
-	buffer = dell_smbios_get_buffer();
+	buffer = (void *)get_zeroed_page(GFP_KERNEL);

It is still needed to ask for page? Is not enough to allocate memory via some *alloc function?

I think this particular one may be able to get away with less memory than a page. I'll confirm.

Quoted 20 lines
Quoted 6 lines
drivers/platform/x86/dell-wmi.c +2 -0
+	buffer->class = 17;
+	buffer->select = 3;
 	buffer->input[0] = 0x10000;
 	buffer->input[1] = 0x51534554;
 	buffer->input[3] = enable;

drivers/platform/x86/dell-wmi.c static int dell_wmi_events_set_enabled(bool enable) · line 656

Quoted 10 lines
drivers/platform/x86/dell-wmi.c +4 -3
-	dell_smbios_send_request(17, 3);
-	ret = buffer->output[0];
-	dell_smbios_release_buffer();
+	ret = dell_smbios_call(buffer);
+	if (ret == 0)
+		ret = buffer->output[0];
+	free_page((unsigned long)buffer);
 
 	return dell_smbios_error(ret);
 }

--
Pali Rohár
[email protected]

#14 lore raw

Re: [PATCH v6 09/14] platform/x86: dell-smbios: Introduce dispatcher for SMM calls

Quoted 32 lines · On Tue, Oct 10, 2017 at 07:14:53PM +0000, [email protected] wrote:
Quoted 20 lines

-----Original Message-----
From: Pali Rohár [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 11:01 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Greg KH <[email protected]>
Subject: Re: [PATCH v6 09/14] platform/x86: dell-smbios: Introduce dispatcher for SMM calls

Quoted 8 lines · On Monday 09 October 2017 17:51:47 Mario Limonciello wrote:

static void dell_rfkill_query(struct rfkill *rfkill, void *data) {

drivers/platform/x86/dell-laptop.c +0 -1
-	struct calling_interface_buffer *buffer;
 	int radio = ((unsigned long)data & 0xF);
 	int hwswitch;
 	int status;
 	int ret;
Quoted 11 lines

drivers/platform/x86/dell-laptop.c static int dell_rfkill_set(void *data, bool blocked) · line 433

Quoted 5 lines
drivers/platform/x86/dell-laptop.c +1 -4
-	buffer = dell_smbios_get_buffer();
-
-	dell_smbios_send_request(17, 11);
-	ret = buffer->output[0];
+	ret = dell_send_request(17, 11, 0, 0, 0, 0);

Basically I do not like function which takes ten numeric parameters. Before in this code there was just function with 2 parameters, now there are lot of zero parameters, without information what which parameter means...

Quoted 3 lines

In an earlier patch Darren wanted to keep dell_send_request around and remove code that was duplicated multiple times to clear buffer, set arguments etc, can you please comment on what exactly you would prefer?

There was a lot of boilerplate, and I think I suggested keeping the same interface of dell_send_request(class, select) (with 2 arguments) rather than replacing it with 3 or 4 lines of allocating and populating the buffer with the same values.

I see you've updated this in v7 with two calls. I'd call that a reasonable compromise.

Quoted 2 lines

It's very obvious if you look at the dell_send_request function what is happening.

There have been numerous analysis indicating that the more arguments a function has, the more likely bugs are to be found in those functions. 6 is a lot.

Signature · 2 lines
Darren Hart
VMware Open Source Technology Center
#15 lore raw

PATCH v6 10/14 platform/x86: dell-smbios: add filtering capability for requests

In reply to Mario Limonciello

There are some categories of tokens and SMBIOS calls that it makes sense to protect userspace from accessing. These are calls that may write to one time use fields or activate hardware debugging capabilities. They are not intended for general purpose use.

This same functionality may be be later extended to also intercept calls that may cause kernel functionality to get out of sync if the same functions are used by other drivers.

---
 drivers/platform/x86/dell-smbios.c | 123 +++++++++++++++++++++++++++++++++++++
 drivers/platform/x86/dell-smbios.h |   2 +
 2 files changed, 125 insertions(+)
drivers/platform/x86/dell-smbios.c +123 -0
index 386130811a34..3279d3f07be8 100644
@@ -32,6 +32,7 @@ struct calling_interface_structure {
 	struct calling_interface_token tokens[];
 } __packed;
 
+static u32 da_supported_commands;
 static int da_command_address;
 static int da_command_code;
 static int da_num_tokens;
@@ -48,6 +49,54 @@ struct smbios_device {
 	int (*call_fn)(struct calling_interface_buffer *);
 };
 
+
+/* calls that should be blacklisted. may contain diagnostics,
+ * debugging information or are write once functions
+ */
+struct smbios_call {
+	int class;
+	int select;
+};
+
+static struct smbios_call call_blacklist[] = {
+	{01, 07},
+	{06, 05},
+	{11, 03},
+	{11, 07},
+	{11, 11},
+	{19, -1},
+};
+
+/* tokens corresponding to diagnostics or write once locations */
+struct token_range {
+	u16 exact_value;
+	u16 min;
+	u16 max;
+};
+
+static struct token_range token_blacklist[] = {
+	{0x0000, 0x0175, 0x0176},
+	{0x0000, 0x0195, 0x0197},
+	{0x0000, 0x01DC, 0x01DD},
+	{0x0000, 0x027D, 0x0284},
+	{0x02E3, 0x0000, 0x0000},
+	{0x02FF, 0x0000, 0x0000},
+	{0x0000, 0x0300, 0x0302},
+	{0x0000, 0x0325, 0x0326},
+	{0x0000, 0x0332, 0x0335},
+	{0x0350, 0x0000, 0x0000},
+	{0x0363, 0x0000, 0x0000},
+	{0x0368, 0x0000, 0x0000},
+	{0x0000, 0x03F6, 0x03F7},
+	{0x0000, 0x049E, 0x049F},
+	{0x0000, 0x04A0, 0x04A3},
+	{0x0000, 0x04E6, 0x04E7},
+	{0x0000, 0x4000, 0x7FFF},
+	{0x0000, 0x9000, 0x9001},
+	{0x0000, 0xA000, 0xBFFF},
+	{0x0000, 0xEFF0, 0xEFFF},
+};
+
 static LIST_HEAD(smbios_device_list);
 
 void dell_smbios_get_smm_address(int *address, int *code)
@@ -107,6 +156,72 @@ void dell_smbios_unregister_device(struct device *d)
 }
 EXPORT_SYMBOL_GPL(dell_smbios_unregister_device);
 
+int dell_smbios_call_filter(struct device *d,
+			    struct calling_interface_buffer *buffer)
+{
+	int i;
+	u16 t = 0;
+
+	/* can't make calls over 30 */
+	if (buffer->class > 30) {
+		dev_dbg(d, "buffer->class too big: %d\n", buffer->class);
+		return -EINVAL;
+	}
+
+	/* supported calls on the particular system */
+	if (!(da_supported_commands & (1 << buffer->class))) {
+		dev_dbg(d, "invalid command, supported commands: 0x%8x\n",
+			da_supported_commands);
+		return -EINVAL;
+	}
+
+	/* match against call blacklist  */
+	for (i = 0; i < ARRAY_SIZE(call_blacklist); i++) {
+		if (buffer->class != call_blacklist[i].class)
+			continue;
+		if (buffer->select != call_blacklist[i].select &&
+		    call_blacklist[i].select != -1)
+			continue;
+		dev_dbg(d, "blacklisted command: %d/%d\n",
+			buffer->class, buffer->select);
+		return -EINVAL;
+	}
+
+	/* if a token call, find token ID */
+	if ((buffer->class == 0 && buffer->select < 3) ||
+	    (buffer->class == 1 && buffer->select < 3)) {
+		for (i = 0; i < da_num_tokens; i++) {
+			/* find the matching token ID */
+			if (da_tokens[i].location != buffer->input[0])
+				continue;
+			t = da_tokens[i].tokenID;
+			break;
+		}
+	/* not a token call */
+	} else
+		return 0;
+
+	/* token call; but token didn't exist */
+	if (!t) {
+		dev_dbg(d, "token at location %u doesn't exist\n",
+			buffer->input[0]);
+		return -EINVAL;
+	}
+	/* match against token blacklist */
+	for (i = 0; i < ARRAY_SIZE(token_blacklist); i++) {
+		if (token_blacklist[i].exact_value &&
+		    t == token_blacklist[i].exact_value)
+			return -EINVAL;
+		if (!token_blacklist[i].min || !token_blacklist[i].max)
+			continue;
+		if (t >= token_blacklist[i].min && t <= token_blacklist[i].max)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dell_smbios_call_filter);
+
 int dell_smbios_call(struct calling_interface_buffer *buffer)
 {
 	int (*call_fn)(struct calling_interface_buffer *) = NULL;
@@ -130,6 +245,13 @@ int dell_smbios_call(struct calling_interface_buffer *buffer)
 		goto out_smbios_call;
 	}
 
+	if (dell_smbios_call_filter(selected_dev, buffer)) {
+		ret = -EINVAL;
+		dev_err(selected_dev, "Invalid call %d/%d:%8x\n",
+			buffer->class, buffer->select, buffer->input[0]);
+		goto out_smbios_call;
+	}
+
 	ret = call_fn(buffer);
 
 out_smbios_call:
@@ -187,6 +309,7 @@ static void __init parse_da_table(const struct dmi_header *dm)
 
 	da_command_address = table->cmdIOAddress;
 	da_command_code = table->cmdIOCode;
+	da_supported_commands = table->supportedCmds;
 
 	new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
 				 sizeof(struct calling_interface_token),
drivers/platform/x86/dell-smbios.h +2 -0
index fe28964da499..c743c58831e5 100644
@@ -45,6 +45,8 @@ void dell_smbios_unregister_device(struct device *d);
 
 void dell_smbios_get_smm_address(int *address, int *command);
 int dell_smbios_error(int value);
+int dell_smbios_call_filter(struct device *d,
+			    struct calling_interface_buffer *buffer);
 int dell_smbios_call(struct calling_interface_buffer *buffer);
 
 struct calling_interface_token *dell_smbios_find_token(int tokenid);
Signature · 1 line
2.14.1
#16 lore raw

Re: [PATCH v6 10/14] platform/x86: dell-smbios: add filtering capability for requests

Quoted 12 lines · On Monday 09 October 2017 17:51:48 Mario Limonciello wrote:
drivers/platform/x86/dell-smbios.c +12 -0
+static struct token_range token_blacklist[] = {
+	{0x0000, 0x0175, 0x0176},
+	{0x0000, 0x0195, 0x0197},
+	{0x0000, 0x01DC, 0x01DD},
+	{0x0000, 0x027D, 0x0284},
+	{0x02E3, 0x0000, 0x0000},
+	{0x02FF, 0x0000, 0x0000},
+	{0x0000, 0x0300, 0x0302},
+	{0x0000, 0x0325, 0x0326},
+	{0x0000, 0x0332, 0x0335},
+	{0x0350, 0x0000, 0x0000},
+	{0x0363, 0x0000, 0x0000},

drivers/platform/x86/dell-smbios.c struct smbios_device { · line 98

Quoted 10 lines
drivers/platform/x86/dell-smbios.c +10 -0
+	{0x0368, 0x0000, 0x0000},
+	{0x0000, 0x03F6, 0x03F7},
+	{0x0000, 0x049E, 0x049F},
+	{0x0000, 0x04A0, 0x04A3},
+	{0x0000, 0x04E6, 0x04E7},
+	{0x0000, 0x4000, 0x7FFF},
+	{0x0000, 0x9000, 0x9001},
+	{0x0000, 0xA000, 0xBFFF},
+	{0x0000, 0xEFF0, 0xEFFF},
+};

Hi! There should be information what is hidden in those tokens, so other people would be able to review why are those token blacklisted.

Signature · 2 lines
Pali Rohár
[email protected]
#17 lore raw

RE: [PATCH v6 10/14] platform/x86: dell-smbios: add filtering capability for requests

Quoted 29 lines

-----Original Message-----
From: Pali Rohár [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 1:32 PM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Greg KH <[email protected]>
Subject: Re: [PATCH v6 10/14] platform/x86: dell-smbios: add filtering capability for requests

Quoted 17 lines · On Monday 09 October 2017 17:51:48 Mario Limonciello wrote:
drivers/platform/x86/dell-smbios.c +17 -0
+static struct token_range token_blacklist[] = {
+	{0x0000, 0x0175, 0x0176},
+	{0x0000, 0x0195, 0x0197},
+	{0x0000, 0x01DC, 0x01DD},
+	{0x0000, 0x027D, 0x0284},
+	{0x02E3, 0x0000, 0x0000},
+	{0x02FF, 0x0000, 0x0000},
+	{0x0000, 0x0300, 0x0302},
+	{0x0000, 0x0325, 0x0326},
+	{0x0000, 0x0332, 0x0335},
+	{0x0350, 0x0000, 0x0000},
+	{0x0363, 0x0000, 0x0000},
+	{0x0368, 0x0000, 0x0000},
+	{0x0000, 0x03F6, 0x03F7},
+	{0x0000, 0x049E, 0x049F},
+	{0x0000, 0x04A0, 0x04A3},
+	{0x0000, 0x04E6, 0x04E7},
Quoted 9 lines

drivers/platform/x86/dell-smbios.c struct smbios_device { · line 98

Quoted 5 lines
drivers/platform/x86/dell-smbios.c +5 -0
+	{0x0000, 0x4000, 0x7FFF},
+	{0x0000, 0x9000, 0x9001},
+	{0x0000, 0xA000, 0xBFFF},
+	{0x0000, 0xEFF0, 0xEFFF},
+};

Hi! There should be information what is hidden in those tokens, so other people would be able to review why are those token blacklisted.

I'll add some comments explaining what I can about why they're blacklisted. Most of them are for use during manufacturing time and those I won't explain further.

#18 lore raw

PATCH v6 11/14 platform/x86: dell-smbios-wmi: Add new WMI dispatcher driver

In reply to Mario Limonciello

The dell-smbios stack only currently uses an SMI interface which grants direct access to physical memory to the firmware SMM methods via a pointer.

This dispatcher driver adds a WMI-ACPI interface that is detected by WMI probe and preferred over the SMI interface in dell-smbios.

Changing this to operate over WMI-ACPI will use an ACPI OperationRegion for a buffer of data storage when SMM calls are performed.

This is a safer approach to use in kernel drivers as the SMM will only have access to that OperationRegion.

---
 MAINTAINERS                            |   6 +
 drivers/platform/x86/Kconfig           |  14 ++
 drivers/platform/x86/Makefile          |   1 +
 drivers/platform/x86/dell-smbios-wmi.c | 229 +++++++++++++++++++++++++++++++++
 4 files changed, 250 insertions(+)
 create mode 100644 drivers/platform/x86/dell-smbios-wmi.c
MAINTAINERS +6 -0
index 8faf08ebcfee..e7514b616e13 100644
@@ -3980,6 +3980,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/platform/x86/dell-smbios-smm.c
 
+DELL SMBIOS WMI DRIVER
+M:	Mario Limonciello <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/platform/x86/dell-smbios-wmi.c
+
 DELL LAPTOP DRIVER
 M:	Matthew Garrett <[email protected]>
 M:	Pali Rohár <[email protected]>
drivers/platform/x86/Kconfig +14 -0
index 53a2de781de6..83aee9068c64 100644
@@ -94,6 +94,20 @@ config ASUS_LAPTOP
 config DELL_SMBIOS
 	tristate
 
+config DELL_SMBIOS_WMI
+	tristate "Dell SMBIOS calling interface (WMI implementation)"
+	depends on ACPI_WMI
+	select DELL_WMI_DESCRIPTOR
+	default ACPI_WMI
+	select DELL_SMBIOS
+	---help---
+	This provides an implementation for the Dell SMBIOS calling interface
+	communicated over ACPI-WMI.
+
+	If you have a Dell computer from >2007 you should say Y or M here.
+	If you aren't sure and this module doesn't work for your computer
+	it just won't load.
+
 config DELL_SMBIOS_SMM
 	tristate "Dell SMBIOS calling interface (SMM implementation)"
 	depends on DCDBAS
drivers/platform/x86/Makefile +1 -0
index e743615241f8..1c4234861de0 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_MSI_LAPTOP)	+= msi-laptop.o
 obj-$(CONFIG_ACPI_CMPC)		+= classmate-laptop.o
 obj-$(CONFIG_COMPAL_LAPTOP)	+= compal-laptop.o
 obj-$(CONFIG_DELL_SMBIOS)	+= dell-smbios.o
+obj-$(CONFIG_DELL_SMBIOS_WMI)	+= dell-smbios-wmi.o
 obj-$(CONFIG_DELL_SMBIOS_SMM)	+= dell-smbios-smm.o
 obj-$(CONFIG_DELL_LAPTOP)	+= dell-laptop.o
 obj-$(CONFIG_DELL_WMI)		+= dell-wmi.o
drivers/platform/x86/dell-smbios-wmi.c new file +229 -0

229 lines not on this page · raw message

Signature · 1 line
2.14.1
#19 lore raw

Re: [PATCH v6 11/14] platform/x86: dell-smbios-wmi: Add new WMI dispatcher driver

reproduce:

Hi Mario,

[auto build test ERROR on platform-drivers-x86/for-next]
[also build test ERROR on v4.14-rc4 next-20171009]
[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/Mario-Limonciello/Introduce-support-for-Dell-SMBIOS-over-WMI/20171012-082742
base:   git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git for-next
config: x86_64-randconfig-x018-201741 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

In file included from include/linux/kobject.h:21:0,

                    from include/linux/module.h:17,
                    from drivers/platform/x86/dell-smbios.c:18:
   drivers/platform/x86/dell-smbios.c: In function 'build_tokens_sysfs':
>> include/linux/sysfs.h:54:8: error: 'struct device_attribute' has no member named 'key'
     (attr)->key = &__key;    \
           ^
>> drivers/platform/x86/dell-smbios.c:443:3: note: in expansion of macro 'sysfs_attr_init'
      sysfs_attr_init(&token_location_attrs[i]);
      ^~~~~~~~~~~~~~~
>> include/linux/sysfs.h:54:8: error: 'struct device_attribute' has no member named 'key'
     (attr)->key = &__key;    \
           ^
   drivers/platform/x86/dell-smbios.c:455:3: note: in expansion of macro 'sysfs_attr_init'
      sysfs_attr_init(&token_value_attrs[i]);
      ^~~~~~~~~~~~~~~
--
   In file included from include/linux/kobject.h:21:0,
                    from include/linux/module.h:17,
                    from drivers/platform//x86/dell-smbios.c:18:
   drivers/platform//x86/dell-smbios.c: In function 'build_tokens_sysfs':
>> include/linux/sysfs.h:54:8: error: 'struct device_attribute' has no member named 'key'
     (attr)->key = &__key;    \
           ^
   drivers/platform//x86/dell-smbios.c:443:3: note: in expansion of macro 'sysfs_attr_init'
      sysfs_attr_init(&token_location_attrs[i]);
      ^~~~~~~~~~~~~~~
>> include/linux/sysfs.h:54:8: error: 'struct device_attribute' has no member named 'key'
     (attr)->key = &__key;    \
           ^
   drivers/platform//x86/dell-smbios.c:455:3: note: in expansion of macro 'sysfs_attr_init'
      sysfs_attr_init(&token_value_attrs[i]);
      ^~~~~~~~~~~~~~~

vim +54 include/linux/sysfs.h

^1da177e Linus Torvalds    2005-04-16  38  
35960258 Eric W. Biederman 2010-02-12  39  /**
35960258 Eric W. Biederman 2010-02-12  40   *	sysfs_attr_init - initialize a dynamically allocated sysfs attribute
35960258 Eric W. Biederman 2010-02-12  41   *	@attr: struct attribute to initialize
35960258 Eric W. Biederman 2010-02-12  42   *
35960258 Eric W. Biederman 2010-02-12  43   *	Initialize a dynamically allocated struct attribute so we can
35960258 Eric W. Biederman 2010-02-12  44   *	make lockdep happy.  This is a new requirement for attributes
35960258 Eric W. Biederman 2010-02-12  45   *	and initially this is only needed when lockdep is enabled.
35960258 Eric W. Biederman 2010-02-12  46   *	Lockdep gives a nice error when your attribute is added to
35960258 Eric W. Biederman 2010-02-12  47   *	sysfs if you don't have this.
35960258 Eric W. Biederman 2010-02-12  48   */
6992f533 Eric W. Biederman 2010-02-11  49  #ifdef CONFIG_DEBUG_LOCK_ALLOC
6992f533 Eric W. Biederman 2010-02-11  50  #define sysfs_attr_init(attr)				\
6992f533 Eric W. Biederman 2010-02-11  51  do {							\
6992f533 Eric W. Biederman 2010-02-11  52  	static struct lock_class_key __key;		\
6992f533 Eric W. Biederman 2010-02-11  53  							\
6992f533 Eric W. Biederman 2010-02-11 @54  	(attr)->key = &__key;				\
6992f533 Eric W. Biederman 2010-02-11  55  } while (0)
6992f533 Eric W. Biederman 2010-02-11  56  #else
6992f533 Eric W. Biederman 2010-02-11  57  #define sysfs_attr_init(attr) do {} while (0)
6992f533 Eric W. Biederman 2010-02-11  58  #endif

6992f533 Eric W. Biederman 2010-02-11 59

:::::: The code at line 54 was first introduced by commit
:::::: 6992f5334995af474c2b58d010d08bc597f0f2fe sysfs: Use one lockdep class per sysfs attribute.

:::::: TO: Eric W. Biederman <[email protected]> :::::: CC: Greg Kroah-Hartman <[email protected]>

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

#20 lore raw

PATCH v6 12/14 platform/x86: dell-smbios-smm: test for WSMT

In reply to Mario Limonciello

WSMT is as an attestation to the OS that the platform won't modify memory outside of pre-defined areas.

If a platform has WSMT enabled in BIOS setup, SMM calls through dcdbas will fail. The only way to access platform data in these instances is through the WMI SMBIOS calling interface.

---
 drivers/platform/x86/dell-smbios-smm.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/platform/x86/dell-smbios-smm.c +34 -0
index 223531e43fea..ba315753e847 100644
@@ -25,6 +25,8 @@ static struct calling_interface_buffer *buffer;
 struct platform_device *platform_device;
 static DEFINE_MUTEX(smm_mutex);
 
+#define WSMT_EN_TOKEN	0x04EC
+
 static const struct dmi_system_id dell_device_table[] __initconst = {
 	{
 		.ident = "Dell laptop",
@@ -76,6 +78,30 @@ int dell_smbios_smm_call(struct calling_interface_buffer *input)
 	return 0;
 }
 
+static int test_wsmt_enabled(void)
+{
+	struct calling_interface_token *token;
+
+	/* if token doesn't exist, SMM will work */
+	token = dell_smbios_find_token(WSMT_EN_TOKEN);
+	if (!token)
+		return 0;
+
+	/* if token exists, try to access over SMM */
+	buffer->class = 0;
+	buffer->select = 0;
+	memset(buffer, 0, sizeof(struct calling_interface_buffer));
+	buffer->input[0] = token->location;
+	dell_smbios_smm_call(buffer);
+
+	/* if lookup failed, we know WSMT was enabled */
+	if (buffer->output[0] != 0)
+		return 1;
+
+	/* query token status if it didn't fail */
+	return (buffer->output[1] == token->value);
+}
+
 static int __init dell_smbios_smm_init(void)
 {
 	int ret;
@@ -88,6 +114,13 @@ static int __init dell_smbios_smm_init(void)
 		return -ENOMEM;
 	dell_smbios_get_smm_address(&da_command_address, &da_command_code);
 
+	ret = test_wsmt_enabled();
+	pr_debug("WSMT enable test: %d\n", ret);
+	if (ret) {
+		ret = -ENODEV;
+		goto fail_wsmt;
+	}
+
 	platform_device = platform_device_alloc("dell-smbios", 1);
 	if (!platform_device) {
 		ret = -ENOMEM;
@@ -111,6 +144,7 @@ static int __init dell_smbios_smm_init(void)
 fail_platform_device_add:
 	platform_device_put(platform_device);
 
+fail_wsmt:
 fail_platform_device_alloc:
 	free_page((unsigned long)buffer);
 	return ret;
Signature · 1 line
2.14.1
#21 lore raw

Re: [PATCH v6 12/14] platform/x86: dell-smbios-smm: test for WSMT

Quoted 17 lines · On Monday 09 October 2017 17:51:50 Mario Limonciello wrote:

WSMT is as an attestation to the OS that the platform won't modify memory outside of pre-defined areas.

If a platform has WSMT enabled in BIOS setup, SMM calls through dcdbas will fail. The only way to access platform data in these instances is through the WMI SMBIOS calling interface.

---
 drivers/platform/x86/dell-smbios-smm.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/platform/x86/dell-smbios-smm.c +0 -0
index 223531e43fea..ba315753e847 100644

drivers/platform/x86/dell-smbios-smm.c static struct calling_interface_buffer *buffer; · line 28

Quoted 4 lines
drivers/platform/x86/dell-smbios-smm.c +1 -0
@@ -25,6 +25,8 @@ static struct calling_interface_buffer *buffer;
 struct platform_device *platform_device;
 static DEFINE_MUTEX(smm_mutex);
 
+#define WSMT_EN_TOKEN	0x04EC

Maybe there should be some comment in code what does this WSMT abbreviation mean...

Quoted 3 lines
drivers/platform/x86/dell-smbios-smm.c +0 -0
 static const struct dmi_system_id dell_device_table[] __initconst = {
 	{
 		.ident = "Dell laptop",
Signature · 2 lines
Pali Rohár
[email protected]
#22 lore raw

PATCH v6 13/14 platform/x86: wmi: create character devices when requested by drivers

In reply to Mario Limonciello

For WMI operations that are only Set or Query read or write sysfs attributes created by WMI vendor drivers make sense.

For other WMI operations that are run on Method, there needs to be a way to guarantee to userspace that the results from the method call belong to the data request to the method call. Sysfs attributes don't work well in this scenario because two userspace processes may be competing at reading/writing an attribute and step on each other's data.

When a WMI vendor driver declares an ioctl callback in the wmi_driver the WMI bus driver will create a character device that maps to that function.

That character device will correspond to this path:
/dev/wmi/$driver

The WMI bus driver will interpret the IOCTL calls, test them for a valid instance and pass them on to the vendor driver to run.

This creates an implicit policy that only driver per character device. If a module matches multiple GUID's, the wmi_devices will need to be all handled by the same wmi_driver if the same character device is used.

The WMI vendor drivers will be responsible for managing access to this character device and proper locking on it.

When a WMI vendor driver is unloaded the WMI bus driver will clean up the character device.

---
 MAINTAINERS                |  1 +
 drivers/platform/x86/wmi.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/wmi.h        |  3 ++
 include/uapi/linux/wmi.h   | 19 +++++++++++++
 4 files changed, 92 insertions(+)
 create mode 100644 include/uapi/linux/wmi.h
MAINTAINERS +1 -0
index e7514b616e13..2a99ee9fd883 100644
@@ -372,6 +372,7 @@ ACPI WMI DRIVER
 L:	[email protected]
 S:	Orphan
 F:	drivers/platform/x86/wmi.c
+F:	include/uapi/linux/wmi.h
 
 AD1889 ALSA SOUND DRIVER
 M:	Thibaut Varene <[email protected]>
drivers/platform/x86/wmi.c +69 -0

99 lines not on this page · raw message

include/linux/wmi.h +3 -0
index ddee427e0721..259d6ec87dd5 100644
@@ -18,6 +18,7 @@
 
 #include <linux/device.h>
 #include <linux/acpi.h>
+#include <uapi/linux/wmi.h>
 
 struct wmi_device {
 	struct device dev;
@@ -47,6 +48,8 @@ struct wmi_driver {
 	int (*probe)(struct wmi_device *wdev);
 	int (*remove)(struct wmi_device *wdev);
 	void (*notify)(struct wmi_device *device, union acpi_object *data);
+	long (*unlocked_ioctl)(struct wmi_device *wdev, unsigned int cmd,
+				unsigned long arg);
 };
 
 extern int __must_check __wmi_driver_register(struct wmi_driver *driver,
include/uapi/linux/wmi.h new file +19 -0
new file mode 100644
index 000000000000..2d8285ae4bd1
@@ -0,0 +1,19 @@
+/*
+ *  User API methods for ACPI-WMI mapping driver
+ *
+ *  Copyright (C) 2017 Dell, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#ifndef _UAPI_LINUX_WMI_H
+#define _UAPI_LINUX_WMI_H
+
+#define WMI_IOC 'W'
+#define WMI_IO(instance)		_IO(WMI_IOC, instance)
+#define WMI_IOR(instance, type)		_IOR(WMI_IOC, instance, type)
+#define WMI_IOW(instance, type)		_IOW(WMI_IOC, instance, type)
+#define WMI_IOWR(instance, type)	_IOWR(WMI_IOC, instance, type)
+
+#endif
Signature · 1 line
2.14.1
#23 lore raw

Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 4 lines · Mario Limonciello
drivers/platform/x86/wmi.c +4 -0
+static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+	struct wmi_driver *wdriver = NULL;
+	struct wmi_block *wblock = NULL;

drivers/platform/x86/wmi.c static int wmi_dev_match(struct device *dev, struct device_driver *driver) · line 783

Quoted 10 lines
drivers/platform/x86/wmi.c +10 -0
+	const char *driver_name;
+	struct list_head *p;
+	int ret;
+
+	if (_IOC_TYPE(cmd) != WMI_IOC)
+		return -ENOTTY;
+
+	driver_name = filp->f_path.dentry->d_iname;
+
+	list_for_each(p, &wmi_block_list) {

No locking while walking the list, you are brave :(

#24 lore raw

Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

In reply to Mario Limonciello
Quoted 10 lines · Mario Limonciello
include/uapi/linux/wmi.h new file +7 -0
@@ -0,0 +1,19 @@
+/*
+ *  User API methods for ACPI-WMI mapping driver
+ *
+ *  Copyright (C) 2017 Dell, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as

include/uapi/linux/wmi.h line 17

Quoted 10 lines
include/uapi/linux/wmi.h new file +10 -0
+ *  published by the Free Software Foundation.
+ */
+#ifndef _UAPI_LINUX_WMI_H
+#define _UAPI_LINUX_WMI_H
+
+#define WMI_IOC 'W'
+#define WMI_IO(instance)		_IO(WMI_IOC, instance)
+#define WMI_IOR(instance, type)		_IOR(WMI_IOC, instance, type)
+#define WMI_IOW(instance, type)		_IOW(WMI_IOC, instance, type)
+#define WMI_IOWR(instance, type)	_IOWR(WMI_IOC, instance, type)

Are these really needed in a uapi .h file? Who needs them? And why not just use a "normal" ioctl macro in your individual driver .h file? Do these really help?

thanks,

greg k-h

Quoted 4 lines
include/uapi/linux/wmi.h new file +2 -0
+
+#endif
Signature · 1 line
2.14.1
#25 lore raw

RE: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 28 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 6:07 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 16 lines · Mario Limonciello
include/uapi/linux/wmi.h new file +13 -0
@@ -0,0 +1,19 @@
+/*
+ *  User API methods for ACPI-WMI mapping driver
+ *
+ *  Copyright (C) 2017 Dell, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#ifndef _UAPI_LINUX_WMI_H
+#define _UAPI_LINUX_WMI_H
+
+#define WMI_IOC 'W'
Quoted 9 lines

include/uapi/linux/wmi.h line 17

Quoted 4 lines
include/uapi/linux/wmi.h new file +4 -0
+#define WMI_IO(instance)		_IO(WMI_IOC, instance)
+#define WMI_IOR(instance, type)		_IOR(WMI_IOC, instance, type)
+#define WMI_IOW(instance, type)		_IOW(WMI_IOC, instance, type)
+#define WMI_IOWR(instance, type)	_IOWR(WMI_IOC, instance, type)

Are these really needed in a uapi .h file? Who needs them? And why not just use a "normal" ioctl macro in your individual driver .h file? Do these really help?

Since this is setting precedent that WMI drivers will use the IOC 'W' and the WMI bus driver will dispatch calls to the proper drivers, I think they make sense to include.

I'm a little unclear - do you disagree? Or do you just think I need to include a comment in the header file with this information?

Thanks,

#26 lore raw

Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 37 lines · On Tue, Oct 10, 2017 at 01:41:45PM +0000, [email protected] wrote:
Quoted 28 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 6:07 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 16 lines · Mario Limonciello
include/uapi/linux/wmi.h new file +13 -0
@@ -0,0 +1,19 @@
+/*
+ *  User API methods for ACPI-WMI mapping driver
+ *
+ *  Copyright (C) 2017 Dell, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#ifndef _UAPI_LINUX_WMI_H
+#define _UAPI_LINUX_WMI_H
+
+#define WMI_IOC 'W'
Quoted 9 lines

include/uapi/linux/wmi.h line 17

Quoted 4 lines
include/uapi/linux/wmi.h new file +4 -0
+#define WMI_IO(instance)		_IO(WMI_IOC, instance)
+#define WMI_IOR(instance, type)		_IOR(WMI_IOC, instance, type)
+#define WMI_IOW(instance, type)		_IOW(WMI_IOC, instance, type)
+#define WMI_IOWR(instance, type)	_IOWR(WMI_IOC, instance, type)

Are these really needed in a uapi .h file? Who needs them? And why not just use a "normal" ioctl macro in your individual driver .h file? Do these really help?

Quoted 2 lines

Since this is setting precedent that WMI drivers will use the IOC 'W' and the WMI bus driver will dispatch calls to the proper drivers, I think they make sense to include.

But who will use those macros? Those drivers?

As the individual drivers have to define the correct "instance, type", this seems like a header file that is wrapping things unnecessarily. Why not just put all of the needed WMI ioctls in a single file, one for all of the drivers? No need to have special per-driver ioctl .h files, right?

thanks,

greg k-h

#27 lore raw

RE: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 58 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 8:58 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 5 lines · On Tue, Oct 10, 2017 at 01:41:45PM +0000, [email protected] wrote:
Quoted 5 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 6:07 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko

<[email protected]>;

Quoted 4 lines
Quoted 4 lines

LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 13/14] platform/x86: wmi: create character devices

when

Quoted 13 lines
Quoted 13 lines

requested by drivers

Quoted 10 lines · Mario Limonciello
include/uapi/linux/wmi.h new file +7 -0
@@ -0,0 +1,19 @@
+/*
+ *  User API methods for ACPI-WMI mapping driver
+ *
+ *  Copyright (C) 2017 Dell, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
Quoted 8 lines
Quoted 8 lines

include/uapi/linux/wmi.h

Quoted 8 lines
include/uapi/linux/wmi.h new file +8 -0
+ *  published by the Free Software Foundation.
+ */
+#ifndef _UAPI_LINUX_WMI_H
+#define _UAPI_LINUX_WMI_H
+
+#define WMI_IOC 'W'
+#define WMI_IO(instance)		_IO(WMI_IOC, instance)
+#define WMI_IOR(instance, type)		_IOR(WMI_IOC, instance,

type)

Quoted 1 line
Quoted 1 line

include/uapi/linux/wmi.h line 16

Quoted 1 line
include/uapi/linux/wmi.h new file +1 -0
+#define WMI_IOW(instance, type)		_IOW(WMI_IOC,

instance, type)

Quoted 7 lines
Quoted 6 lines

include/uapi/linux/wmi.h line 17

Quoted 1 line
include/uapi/linux/wmi.h new file +1 -0
+#define WMI_IOWR(instance, type)	_IOWR(WMI_IOC, instance, type)

Are these really needed in a uapi .h file? Who needs them? And why not just use a "normal" ioctl macro in your individual driver .h file? Do these really help?

Since this is setting precedent that WMI drivers will use the IOC 'W' and the

WMI

Quoted 1 line

bus driver will dispatch calls to the proper drivers, I think they make sense to

include.

Quoted 8 lines

But who will use those macros? Those drivers?

As the individual drivers have to define the correct "instance, type", this seems like a header file that is wrapping things unnecessarily. Why not just put all of the needed WMI ioctls in a single file, one for all of the drivers? No need to have special per-driver ioctl .h files, right?

Sounds good to me. I'll reshuffle.

#28 lore raw

Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

In reply to Mario Limonciello

drivers/platform/x86/wmi.c static int wmi_dev_match(struct device *dev, struct device_driver *driver) · line 798

Quoted 3 lines · On Monday 09 October 2017 17:51:51 Mario Limonciello wrote:
drivers/platform/x86/wmi.c +3 -0
+	/* make sure we're not calling a higher instance than exists*/
+	if (_IOC_NR(cmd) > wblock->gblock.instance_count - 1)
+		return -EINVAL;

Is this condition really working? instance_count is unsigned, cmd is also unsigned... and when instance_count is zero, then IIRC error would not be thrown.

Signature · 2 lines
Pali Rohár
[email protected]
#29 lore raw

RE: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 11 lines

-----Original Message-----
From: Pali Rohár [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 2:12 PM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Greg KH <[email protected]>
Subject: Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 9 lines

drivers/platform/x86/wmi.c static int wmi_dev_match(struct device *dev, struct device_driver *driver) · line 798

Quoted 3 lines · On Monday 09 October 2017 17:51:51 Mario Limonciello wrote:
drivers/platform/x86/wmi.c +3 -0
+	/* make sure we're not calling a higher instance than exists*/
+	if (_IOC_NR(cmd) > wblock->gblock.instance_count - 1)
+		return -EINVAL;

Is this condition really working? instance_count is unsigned, cmd is also unsigned... and when instance_count is zero, then IIRC error would not be thrown.

But instance count can't be zero. MOF would fall apart with a zero instance count. If a broken BIOS was shipped with an instance count of zero bigger problems would have happened.

#30 lore raw

Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 21 lines · On Tue, 10 Oct 2017 19:24:11 +0000 <[email protected]> wrote:
Quoted 11 lines

-----Original Message-----
From: Pali Rohár [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 2:12 PM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Greg KH <[email protected]>
Subject: Re: [PATCH v6 13/14] platform/x86: wmi: create character devices when requested by drivers

Quoted 9 lines

drivers/platform/x86/wmi.c static int wmi_dev_match(struct device *dev, struct device_driver *driver) · line 798

Quoted 3 lines · On Monday 09 October 2017 17:51:51 Mario Limonciello wrote:
drivers/platform/x86/wmi.c +3 -0
+	/* make sure we're not calling a higher instance than exists*/
+	if (_IOC_NR(cmd) > wblock->gblock.instance_count - 1)
+		return -EINVAL;  

Is this condition really working? instance_count is unsigned, cmd is also unsigned... and when instance_count is zero, then IIRC error would not be thrown.

Quoted 3 lines

But instance count can't be zero. MOF would fall apart with a zero instance count. If a broken BIOS was shipped with an instance count of zero bigger problems would have happened.

Maybe but you can still write the test correctly using >= instead.

Alan

#31 lore raw

PATCH v6 14/14 platform/x86: dell-smbios-wmi: introduce userspace interface

In reply to Mario Limonciello

It's important for the driver to provide a R/W ioctl to ensure that two competing userspace processes don't race to provide or read each others data.

This userspace character device will be used to perform SMBIOS calls from any applications.

It provides an ioctl that will allow passing the WMI calling interface buffer between userspace and kernel space.

This character device is intended to deprecate the dcdbas kernel module and the interface that it provides to userspace.

To use the character device the buffer needed for the machine will also be needed. This information is exported to a sysfs attribute.

The API for interacting with this interface is defined in documentation as well as a uapi header provides the format of the structures.

---
 Documentation/ABI/testing/dell-smbios-wmi          |  41 ++++++++
 .../ABI/testing/sysfs-platform-dell-smbios-wmi     |  10 ++
 MAINTAINERS                                        |   1 +
 drivers/platform/x86/dell-smbios-wmi.c             | 107 ++++++++++++++++++---
 drivers/platform/x86/dell-smbios.h                 |  11 +--
 include/uapi/linux/dell-smbios.h                   |  42 ++++++++
 6 files changed, 191 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/ABI/testing/dell-smbios-wmi
 create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-smbios-wmi
 create mode 100644 include/uapi/linux/dell-smbios.h
Documentation/ABI/testing/dell-smbios-wmi new file +41 -0
new file mode 100644
index 000000000000..e067e955fcc9
@@ -0,0 +1,41 @@
+What:		/dev/wmi/dell-smbios
+Date:		November 2017
+KernelVersion:	4.15
+Contact:	"Mario Limonciello" <[email protected]>
+Description:
+		Perform SMBIOS calls on supported Dell machines.
+		through the Dell ACPI-WMI interface.
+
+		IOCTL's and buffer formats are defined in:
+		<uapi/linux/dell-smbios.h>
+
+		1) To perform a call from userspace, you'll need to first
+		determine the minimum size of the calling interface buffer
+		for your machine.
+		Platforms that contain larger buffers can return larger
+		objects from the system firmware.
+		Commonly this size is either 4k or 32k.
+
+		To determine the size of the buffer, refer to:
+		sysfs-platform-dell-smbios-wmi
+
+		2) After you've determined the minimum size of the calling
+		interface buffer, you can allocate a structure that represents
+		the structure documented above.
+
+		3) In the 'length' object store the size of the buffer you
+		determined above and allocated.
+
+		4) In this buffer object, prepare as necessary for the SMBIOS
+		call you're interested in.  Typically SMBIOS buffers have
+		"class", "select", and "input" defined to values that coincide
+		with the data you are interested in.
+		Documenting class/select/input values is outside of the scope
+		of this documentation. Check with the libsmbios project for
+		further documentation on these values.
+
+		6) Run the call by using ioctl() as described in the header.
+
+		7) The output will be returned in the buffer object.
+
+		8) Be sure to free up your allocated object.
Documentation/ABI/testing/sysfs-platform-dell-smbios-wmi new file +10 -0
new file mode 100644
index 000000000000..33f0fb73f785
@@ -0,0 +1,10 @@
+What:		/sys/devices/platform/<platform>/required_buffer_size
+Date:		November 2017
+KernelVersion:	4.15
+Contact:	"Mario Limonciello" <[email protected]>
+Description:
+		A read-only description of the size of a calling
+		interface buffer that can be passed to Dell
+		firmware.
+
+		Commonly this size is either 4k or 32k.
MAINTAINERS +1 -0
index 2a99ee9fd883..4940f3c7481b 100644
@@ -3986,6 +3986,7 @@ M:	Mario Limonciello <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	drivers/platform/x86/dell-smbios-wmi.c
+F:	include/uapi/linux/dell-smbios.h
 
 DELL LAPTOP DRIVER
 M:	Matthew Garrett <[email protected]>
drivers/platform/x86/dell-smbios-wmi.c +96 -11

157 lines not on this page · raw message

drivers/platform/x86/dell-smbios.h +1 -10
index c743c58831e5..04995136114c 100644
@@ -17,19 +17,10 @@
 #define _DELL_SMBIOS_H_
 
 #include <linux/device.h>
+#include <uapi/linux/dell-smbios.h>
 
 struct notifier_block;
 
-/* This structure will be modified by the firmware when we enter
- * system management mode, hence the volatiles */
-
-struct calling_interface_buffer {
-	u16 class;
-	u16 select;
-	volatile u32 input[4];
-	volatile u32 output[4];
-} __packed;
-
 struct calling_interface_token {
 	u16 tokenID;
 	u16 location;
include/uapi/linux/dell-smbios.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.14.1
#32 lore raw

Re: [PATCH v6 14/14] platform/x86: dell-smbios-wmi: introduce userspace interface

drivers/platform/x86/dell-smbios-wmi.c static int dell_smbios_wmi_probe(struct wmi_device *wdev) · line 214

Quoted 3 lines · Mario Limonciello
drivers/platform/x86/dell-smbios-wmi.c +3 -0
+	ret = device_create_file(&wdev->dev, &priv->req_buf_size_attr);
+	if (ret)
+		goto fail_create_sysfs;

Why isn't the "WMI core" creating this sysfs file? Why have per-driver sysfs files, making all of the different apis totally different? It's a "common" attribute that they are all going to have to provide, right?

That way you also don't race with userspace :)

thanks,

greg k-h

#33 lore raw

RE: [PATCH v6 14/14] platform/x86: dell-smbios-wmi: introduce userspace interface

Quoted 13 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, October 10, 2017 8:59 AM
To: Limonciello, Mario <[email protected]>
Cc: [email protected]; Andy Shevchenko <[email protected]>; LKML <[email protected]>; [email protected]; Andy Lutomirski <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 14/14] platform/x86: dell-smbios-wmi: introduce userspace interface

Quoted 9 lines

drivers/platform/x86/dell-smbios-wmi.c static int dell_smbios_wmi_probe(struct wmi_device *wdev) · line 214

Quoted 3 lines · Mario Limonciello
drivers/platform/x86/dell-smbios-wmi.c +3 -0
+	ret = device_create_file(&wdev->dev, &priv->req_buf_size_attr);
+	if (ret)
+		goto fail_create_sysfs;

Why isn't the "WMI core" creating this sysfs file? Why have per-driver sysfs files, making all of the different apis totally different? It's a "common" attribute that they are all going to have to provide, right?

I hadn't really thought about that. I suppose it's entirely reasonable to have a way that all WMI ioctls for future drivers will advertise the size of their expected buffer the same way.

So this does beg a question to others on this distribution who have worked on WMI drivers- do you know of any WM**/ methods with multiple instances that use different buffer sizes, or is it reasonable to expect that the buffer size is consistent between instances?

Even in advanced MOF designs I haven't seen it, but this makes me wonder if an attribute should be created for every instance to be future proof. (For example $GUID/required_buffer_size/instance0, $GUID/required_buffer_size/instance1 etc)

Quoted 5 lines

That way you also don't race with userspace :)

thanks,

greg k-h

#34 lore raw

Re: [PATCH v6 14/14] platform/x86: dell-smbios-wmi: introduce userspace interface

In reply to Mario Limonciello
reproduce:

Hi Mario,

[auto build test WARNING on platform-drivers-x86/for-next]
[also build test WARNING on next-20171009]
[cannot apply to v4.14-rc4]
[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/Mario-Limonciello/Introduce-support-for-Dell-SMBIOS-over-WMI/20171012-082742
base:   git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git for-next
config: i386-tinyconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

>> ./usr/include/linux/dell-smbios.h:21: found __[us]{8,16,32,64} type without #include <linux/types.h>

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

#35 lore raw

Re: [PATCH v6 14/14] platform/x86: dell-smbios-wmi: introduce userspace interface

In reply to Mario Limonciello
reproduce:

Hi Mario,

[auto build test WARNING on platform-drivers-x86/for-next]
[also build test WARNING on next-20171009]
[cannot apply to v4.14-rc4]
[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/Mario-Limonciello/Introduce-support-for-Dell-SMBIOS-over-WMI/20171012-082742
base:   git://git.infradead.org/users/dvhart/linux-platform-drivers-x86.git for-next
config: x86_64-randconfig-x018-201741 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

In file included from include/linux/kobject.h:21:0,

                    from include/linux/dmi.h:5,
                    from drivers/platform/x86/dell-smbios-wmi.c:12:
   drivers/platform/x86/dell-smbios-wmi.c: In function 'dell_smbios_wmi_probe':
   include/linux/sysfs.h:54:8: error: 'struct device_attribute' has no member named 'key'
     (attr)->key = &__key;    \
           ^
>> drivers/platform/x86/dell-smbios-wmi.c:207:2: note: in expansion of macro 'sysfs_attr_init'
     sysfs_attr_init(&priv->req_buf_size_attr);
     ^~~~~~~~~~~~~~~

vim +/sysfs_attr_init +207 drivers/platform/x86/dell-smbios-wmi.c

    11	
  > 12	#include <linux/dmi.h>
    13	#include <linux/list.h>
    14	#include <linux/module.h>
    15	#include <linux/mutex.h>
    16	#include <linux/uaccess.h>
    17	#include <linux/wmi.h>
    18	#include <uapi/linux/dell-smbios.h>
    19	#include "dell-smbios.h"
    20	#include "dell-wmi-descriptor.h"
    21	static DEFINE_MUTEX(call_mutex);
    22	static DEFINE_MUTEX(list_mutex);
    23	static int wmi_supported;
    24	
    25	struct misc_bios_flags_structure {
    26		struct dmi_header header;
    27		u16 flags0;
    28	} __packed;
    29	#define FLAG_HAS_ACPI_WMI 0x02
    30	
    31	#define DELL_WMI_SMBIOS_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
    32	
    33	struct wmi_smbios_priv {
    34		struct wmi_smbios_buffer *buf;
    35		struct device_attribute req_buf_size_attr;
    36		struct list_head list;
    37		struct wmi_device *wdev;
    38		struct device *child;
    39		u32 req_buf_size;
    40	};
    41	static LIST_HEAD(wmi_list);
    42	
    43	static inline struct wmi_smbios_priv *get_first_smbios_priv(void)
    44	{
    45		return list_first_entry_or_null(&wmi_list,
    46						struct wmi_smbios_priv,
    47						list);
    48	}
    49	
    50	static int run_smbios_call(struct wmi_device *wdev)
    51	{
    52		struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
    53		struct wmi_smbios_priv *priv;
    54		struct acpi_buffer input;
    55		union acpi_object *obj;
    56		acpi_status status;
    57	
    58		priv = dev_get_drvdata(&wdev->dev);
    59		input.length = priv->req_buf_size;
    60		input.pointer = &priv->buf->std;
    61	
    62		dev_dbg(&wdev->dev, "evaluating: %x/%x [%x,%x,%x,%x]\n",
    63			priv->buf->std.class, priv->buf->std.select,
    64			priv->buf->std.input[0], priv->buf->std.input[1],
    65			priv->buf->std.input[2], priv->buf->std.input[3]);
    66	
    67		status = wmidev_evaluate_method(wdev, 0, 1, &input, &output);
    68		if (ACPI_FAILURE(status))
    69			return -EIO;
    70		obj = (union acpi_object *)output.pointer;
    71		if (obj->type != ACPI_TYPE_BUFFER) {
    72			dev_dbg(&wdev->dev, "received type: %d\n", obj->type);
    73			if (obj->type == ACPI_TYPE_INTEGER)
    74				dev_dbg(&wdev->dev, "SMBIOS call failed: %llu\n",
    75					obj->integer.value);
    76			return -EIO;
    77		}
    78		memcpy(&priv->buf->std, obj->buffer.pointer, obj->buffer.length);
    79	
    80		return 0;
    81	}
    82	
    83	int dell_smbios_wmi_call(struct calling_interface_buffer *buffer)
    84	{
    85		struct wmi_smbios_priv *priv;
    86		size_t difference;
    87		size_t size;
    88		int ret;
    89	
    90		priv = get_first_smbios_priv();
    91		if (!priv)
    92			return -ENODEV;
    93	
    94		size = sizeof(struct calling_interface_buffer);
    95		difference = priv->req_buf_size - sizeof(u64) - size;
    96	
    97		mutex_lock(&call_mutex);
    98		memset(&priv->buf->ext, 0, difference);
    99		memcpy(&priv->buf->std, buffer, size);
   100		ret = run_smbios_call(priv->wdev);
   101		memcpy(buffer, &priv->buf->std, size);
   102		mutex_unlock(&call_mutex);
   103	
   104		return ret;
   105	}
   106	
   107	static long dell_smbios_wmi_ioctl(struct wmi_device *wdev, unsigned int cmd,
   108					  unsigned long arg)
   109	{
   110		struct wmi_smbios_buffer __user *input =
   111			(struct wmi_smbios_buffer __user *) arg;
   112		struct wmi_smbios_priv *priv;
   113		int ret = 0;
   114		u64 size;
   115	
   116		switch (cmd) {
   117		case DELL_WMI_SMBIOS_CMD:
   118			priv = dev_get_drvdata(&wdev->dev);
   119			if (!priv)
   120				return -ENODEV;
   121			mutex_lock(&call_mutex);
   122			/* read the size that userspace is sending */
   123			if (get_user(size, &input->length)) {
   124				dev_dbg(&wdev->dev, "Read length from user failed\n");
   125				ret = -EFAULT;
   126				goto fail_smbios_cmd;
   127			}
   128			/* if it's too big, this is OK, we'll only use what we need */
   129			if (size > priv->req_buf_size)
   130				dev_warn(&wdev->dev,
   131					"Buffer %lld is bigger than required %d\n",
   132					size, priv->req_buf_size);
   133			/* if it's too small, abort */
   134			if (size < priv->req_buf_size) {
   135				dev_err(&wdev->dev,
   136					"Buffer %lld too small, need at least %d\n",
   137					size, priv->req_buf_size);
   138				ret = -EINVAL;
   139				goto fail_smbios_cmd;
   140			}
   141			/* read the structure from userspace */
   142			if (copy_from_user(priv->buf, input, priv->req_buf_size)) {
   143				dev_dbg(&wdev->dev, "Copy %llu from user failed\n",
   144					size);
   145				ret = -EFAULT;
   146				goto fail_smbios_cmd;
   147			}
   148			/* check for any calls we should avoid */
   149			if (dell_smbios_call_filter(&wdev->dev, &priv->buf->std)) {
   150				dev_err(&wdev->dev, "Invalid call %d/%d:%8x\n",
   151					priv->buf->std.class, priv->buf->std.select,
   152					priv->buf->std.input[0]);
   153				ret = -EFAULT;
   154				goto fail_smbios_cmd;
   155			}
   156			ret = run_smbios_call(priv->wdev);
   157			if (ret != 0)
   158				goto fail_smbios_cmd;
   159			/* return the result (only up to our internal buffer size) */
   160			if (copy_to_user(input, priv->buf, priv->req_buf_size)) {
   161				dev_dbg(&wdev->dev, "Copy %d to user failed\n",
   162				priv->req_buf_size);
   163				ret = -EFAULT;
   164			}
   165	fail_smbios_cmd:
   166			mutex_unlock(&call_mutex);
   167			break;
   168		default:
   169			dev_dbg(&wdev->dev, "unsupported ioctl: %d [%d, %d, %d, %d].\n",
   170				cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd),
   171				_IOC_SIZE(cmd));
   172			ret = -ENOIOCTLCMD;
   173		}
   174		return ret;
   175	}
   176	
   177	static ssize_t req_buf_size_show(struct device *dev,
   178					struct device_attribute *attr, char *buf)
   179	{
   180		struct wmi_smbios_priv *priv = dev_get_drvdata(dev);
   181	
   182		return sprintf(buf, "%d\n", priv->req_buf_size);
   183	}
   184	
   185	static int dell_smbios_wmi_probe(struct wmi_device *wdev)
   186	{
   187		struct wmi_smbios_priv *priv;
   188		int count;
   189		int ret;
   190	
   191		priv = devm_kzalloc(&wdev->dev, sizeof(struct wmi_smbios_priv),
   192				    GFP_KERNEL);
   193		if (!priv)
   194			return -ENOMEM;
   195	
   196		/* WMI buffer size will be either 4k or 32k depending on machine */
   197		if (!dell_wmi_get_size(&priv->req_buf_size))
   198			return -EINVAL;
   199		/* add in the length object we will use internally with ioctl */
   200		priv->req_buf_size += sizeof(u64);
   201	
   202		count = get_order(priv->req_buf_size);
   203		priv->buf = (void *)__get_free_pages(GFP_KERNEL, count);
   204		if (!priv->buf)
   205			return -ENOMEM;
   206	
 > 207		sysfs_attr_init(&priv->req_buf_size_attr);

208 priv->req_buf_size_attr.attr.name = "required_buffer_size";
209 priv->req_buf_size_attr.attr.mode = 0444;
210 priv->req_buf_size_attr.show = req_buf_size_show;
211
212 ret = device_create_file(&wdev->dev, &priv->req_buf_size_attr);
213 if (ret)
214 goto fail_create_sysfs;
215
216 /* ID is used by dell-smbios to set priority of drivers */
217 wdev->dev.id = 1;
218 ret = dell_smbios_register_device(&wdev->dev, &dell_smbios_wmi_call);
219 if (ret)
220 goto fail_register;
221
222 priv->wdev = wdev;
223 dev_set_drvdata(&wdev->dev, priv);
224 mutex_lock(&list_mutex);
225 list_add_tail(&priv->list, &wmi_list);
226 mutex_unlock(&list_mutex);
227
228 return 0;
229
230 fail_register:
231 device_remove_file(&wdev->dev, &priv->req_buf_size_attr);
232
233 fail_create_sysfs:
234 free_pages((unsigned long)priv->buf, count);
235 return ret;
236 }
237

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