Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1741159 > unrolled thread
| Started by | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| First post | 2017-09-28 06:10 +0200 |
| Last post | 2017-09-30 22:00 +0200 |
| Articles | 20 — 5 participants |
Back to article view | Back to linux.kernel
[PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI Mario Limonciello <mario.limonciello@dell.com> - 2017-09-28 06:10 +0200
[PATCH v3 1/8] platform/x86: wmi: Add new method wmidev_evaluate_method Mario Limonciello <mario.limonciello@dell.com> - 2017-09-28 06:10 +0200
[PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check Mario Limonciello <mario.limonciello@dell.com> - 2017-09-28 06:10 +0200
Re: [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-10-02 15:20 +0200
RE: [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check <Mario.Limonciello@dell.com> - 2017-10-02 15:30 +0200
[PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Mario Limonciello <mario.limonciello@dell.com> - 2017-09-28 06:10 +0200
Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Pali Rohár <pali.rohar@gmail.com> - 2017-09-28 09:00 +0200
RE: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface <Mario.Limonciello@dell.com> - 2017-09-29 00:50 +0200
Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Pali Rohár <pali.rohar@gmail.com> - 2017-09-29 09:40 +0200
RE: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface <Mario.Limonciello@dell.com> - 2017-09-30 22:10 +0200
Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Pali Rohár <pali.rohar@gmail.com> - 2017-09-30 23:10 +0200
Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Darren Hart <dvhart@infradead.org> - 2017-09-30 03:00 +0200
Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Pali Rohár <pali.rohar@gmail.com> - 2017-09-30 09:20 +0200
RE: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface <Mario.Limonciello@dell.com> - 2017-09-30 22:00 +0200
[PATCH v3 7/8] platform/x86: Kconfig: Change the default settings for dell-wmi-smbios Mario Limonciello <mario.limonciello@dell.com> - 2017-09-28 06:10 +0200
[PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace Mario Limonciello <mario.limonciello@dell.com> - 2017-09-28 06:10 +0200
Re: [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace Darren Hart <dvhart@infradead.org> - 2017-09-30 04:10 +0200
RE: [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace <Mario.Limonciello@dell.com> - 2017-09-30 21:50 +0200
Re: [PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI Darren Hart <dvhart@infradead.org> - 2017-09-30 04:20 +0200
RE: [PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI <Mario.Limonciello@dell.com> - 2017-09-30 22:00 +0200
| From | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| Date | 2017-09-28 06:10 +0200 |
| Subject | [PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI |
| Message-ID | <uuyj7-40H-7@gated-at.bofh.it> |
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 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.
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 (8):
platform/x86: wmi: Add new method wmidev_evaluate_method
platform/x86: dell-smbios: Introduce a WMI-ACPI interface
platform/x86: dell-wmi-smbios: Use Dell WMI descriptor check
platform/x86: wmi: create character devices when requested by drivers
platform/x86: dell-wmi-smbios: introduce character device for
userspace
platform/x86: dell-wmi-smbios: Add a sysfs interface for SMBIOS tokens
platform/x86: Kconfig: Change the default settings for dell-wmi-smbios
platform/x86: dell-wmi-smbios: clean up wmi descriptor check
Documentation/ABI/testing/dell-wmi-smbios | 11 +
.../ABI/testing/sysfs-platform-dell-wmi-smbios | 16 ++
MAINTAINERS | 6 +
drivers/platform/x86/Kconfig | 15 +-
drivers/platform/x86/dell-smbios.c | 315 +++++++++++++++++++--
drivers/platform/x86/dell-smbios.h | 15 +-
drivers/platform/x86/dell-wmi.c | 75 +----
drivers/platform/x86/wmi.c | 126 ++++++++-
include/linux/wmi.h | 7 +
include/uapi/linux/dell-wmi-smbios.h | 30 ++
10 files changed, 498 insertions(+), 118 deletions(-)
create mode 100644 Documentation/ABI/testing/dell-wmi-smbios
create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-wmi-smbios
create mode 100644 include/uapi/linux/dell-wmi-smbios.h
--
2.14.1
[toc] | [next] | [standalone]
| From | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| Date | 2017-09-28 06:10 +0200 |
| Subject | [PATCH v3 1/8] platform/x86: wmi: Add new method wmidev_evaluate_method |
| Message-ID | <uuyj7-40H-15@gated-at.bofh.it> |
| In reply to | #1741159 |
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.
Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
drivers/platform/x86/wmi.c | 28 ++++++++++++++++++++++++----
include/linux/wmi.h | 6 ++++++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 7a05843aff19..4d73a87c2ddf 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -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)
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index cd0d7734dc49..2cd10c3b89e9 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -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);
--
2.14.1
[toc] | [prev] | [next] | [standalone]
| From | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| Date | 2017-09-28 06:10 +0200 |
| Subject | [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check |
| Message-ID | <uuyj7-40H-17@gated-at.bofh.it> |
| In reply to | #1741159 |
Some cases the wrong type was used for errors and checks can be done more cleanly. Signed-off-by: Mario Limonciello <mario.limonciello@dell.com> Reviewed-by: Edward O'Callaghan <quasisec@google.com> --- drivers/platform/x86/dell-smbios.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios.c index ac176953e46e..d75b6971588e 100644 --- a/drivers/platform/x86/dell-smbios.c +++ b/drivers/platform/x86/dell-smbios.c @@ -346,16 +346,16 @@ int dell_wmi_check_descriptor_buffer(struct wmi_device *wdev, u32 *version) } desc_buffer = (u32 *)obj->buffer.pointer; - if (desc_buffer[0] != 0x4C4C4544 && desc_buffer[1] != 0x494D5720) - dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature (%*ph)\n", - 8, desc_buffer); + if (strncmp(obj->string.pointer, "DELL WMI", 8) != 0) + dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature (%8ph)\n", + desc_buffer); if (desc_buffer[2] != 0 && desc_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", desc_buffer[2]); if (desc_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", desc_buffer[3]); *version = desc_buffer[2]; -- 2.14.1
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2017-10-02 15:20 +0200 |
| Subject | Re: [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check |
| Message-ID | <uw8Nz-7JN-1@gated-at.bofh.it> |
| In reply to | #1741161 |
On Thu, Sep 28, 2017 at 7:02 AM, Mario Limonciello <mario.limonciello@dell.com> wrote: > Some cases the wrong type was used for errors and checks can be > done more cleanly. Oops, I forgot about this patch, so, please, disregard my comment WRT to strncmp() use to the other patch. > Signed-off-by: Mario Limonciello <mario.limonciello@dell.com> > Reviewed-by: Edward O'Callaghan <quasisec@google.com> Btw, missed Suggested-by? > - if (desc_buffer[0] != 0x4C4C4544 && desc_buffer[1] != 0x494D5720) > - dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature (%*ph)\n", > - 8, desc_buffer); > + if (strncmp(obj->string.pointer, "DELL WMI", 8) != 0) > + dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature (%8ph)\n", > + desc_buffer); And as Darren pointed out, this fixes the logic bug as well. -- With Best Regards, Andy Shevchenko
[toc] | [prev] | [next] | [standalone]
| From | <Mario.Limonciello@dell.com> |
|---|---|
| Date | 2017-10-02 15:30 +0200 |
| Subject | RE: [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check |
| Message-ID | <uw8Xg-7MY-21@gated-at.bofh.it> |
| In reply to | #1743213 |
> -----Original Message----- > From: Andy Shevchenko [mailto:andy.shevchenko@gmail.com] > Sent: Monday, October 2, 2017 8:16 AM > To: Limonciello, Mario <Mario_Limonciello@Dell.com> > Cc: dvhart@infradead.org; LKML <linux-kernel@vger.kernel.org>; Platform Driver > <platform-driver-x86@vger.kernel.org>; Andy Lutomirski <luto@kernel.org>; > quasisec@google.com; Pali Rohár <pali.rohar@gmail.com> > Subject: Re: [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi > descriptor check > > On Thu, Sep 28, 2017 at 7:02 AM, Mario Limonciello > <mario.limonciello@dell.com> wrote: > > Some cases the wrong type was used for errors and checks can be > > done more cleanly. > > Oops, I forgot about this patch, so, please, disregard my comment WRT > to strncmp() use to the other patch. > > > > Signed-off-by: Mario Limonciello <mario.limonciello@dell.com> > > Reviewed-by: Edward O'Callaghan <quasisec@google.com> > > Btw, missed Suggested-by? Yes sorry about that. I'll add that for when I get v4 out. > > > > - if (desc_buffer[0] != 0x4C4C4544 && desc_buffer[1] != 0x494D5720) > > - dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature > (%*ph)\n", > > - 8, desc_buffer); > > + if (strncmp(obj->string.pointer, "DELL WMI", 8) != 0) > > + dev_warn(&wdev->dev, "Dell descriptor buffer has invalid signature > (%8ph)\n", > > + desc_buffer); > > And as Darren pointed out, this fixes the logic bug as well. > > -- > With Best Regards, > Andy Shevchenko
[toc] | [prev] | [next] | [standalone]
| From | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| Date | 2017-09-28 06:10 +0200 |
| Subject | [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uuyj8-40H-19@gated-at.bofh.it> |
| In reply to | #1741159 |
The driver currently uses an SMI interface which grants direct access
to physical memory to the firmware SMM methods via a pointer.
Now add a WMI-ACPI interface that is detected by WMI probe and preferred
over the SMI interface.
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.
As a result, this change removes the dependency on this driver on the
dcdbas kernel module. It's now an optional compilation option.
When modifying this, add myself to MAINTAINERS.
Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
MAINTAINERS | 6 ++
drivers/platform/x86/Kconfig | 14 ++--
drivers/platform/x86/dell-smbios.c | 128 ++++++++++++++++++++++++++++++++-----
drivers/platform/x86/dell-smbios.h | 15 ++++-
4 files changed, 138 insertions(+), 25 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 08b96f77f618..6d76b09f46cc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3990,6 +3990,12 @@ S: Maintained
F: drivers/hwmon/dell-smm-hwmon.c
F: include/uapi/linux/i8k.h
+DELL SMBIOS DRIVER
+M: Pali Rohár <pali.rohar@gmail.com>
+M: Mario Limonciello <mario.limonciello@dell.com>
+S: Maintained
+F: drivers/platform/x86/dell-smbios.*
+
DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas)
M: Doug Warzecha <Douglas_Warzecha@dell.com>
S: Maintained
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 1f7959ff055c..415886d7a857 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -92,13 +92,17 @@ config ASUS_LAPTOP
If you have an ACPI-compatible ASUS laptop, say Y or M here.
config DELL_SMBIOS
- tristate
- select DCDBAS
+ tristate "Dell SMBIOS calling interface"
+ depends on ACPI_WMI
---help---
- This module provides common functions for kernel modules using
- Dell SMBIOS.
+ This module provides common functions for kernel modules and
+ userspace using Dell SMBIOS.
+
+ If you have a Dell computer, say Y or M here.
- If you have a Dell laptop, say Y or M here.
+ If you have a machine from < 2007 without a WMI interface you
+ may also want to enable CONFIG_DCDBAS to allow this driver to
+ work.
config DELL_LAPTOP
tristate "Dell Laptop Extras"
diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios.c
index e9b1ca07c872..4472817ee045 100644
--- a/drivers/platform/x86/dell-smbios.c
+++ b/drivers/platform/x86/dell-smbios.c
@@ -4,6 +4,7 @@
* Copyright (c) Red Hat <mjg@redhat.com>
* Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
* Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
+ * Copyright (c) 2017 Dell Inc.
*
* Based on documentation in the libsmbios package:
* Copyright (C) 2005-2014 Dell Inc.
@@ -22,9 +23,15 @@
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/io.h>
-#include "../../firmware/dcdbas.h"
+#include <linux/wmi.h>
#include "dell-smbios.h"
+#ifdef CONFIG_DCDBAS
+#include "../../firmware/dcdbas.h"
+#endif
+
+#define DELL_WMI_SMBIOS_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
+
struct calling_interface_structure {
struct dmi_header header;
u16 cmdIOAddress;
@@ -33,12 +40,14 @@ struct calling_interface_structure {
struct calling_interface_token tokens[];
} __packed;
-static struct calling_interface_buffer *buffer;
+static void *buffer;
+static size_t bufferlen;
static DEFINE_MUTEX(buffer_mutex);
static int da_command_address;
static int da_command_code;
static int da_num_tokens;
+struct wmi_device *wmi_dev;
static struct calling_interface_token *da_tokens;
int dell_smbios_error(int value)
@@ -60,13 +69,15 @@ struct calling_interface_buffer *dell_smbios_get_buffer(void)
{
mutex_lock(&buffer_mutex);
dell_smbios_clear_buffer();
+ if (wmi_dev)
+ return &((struct wmi_calling_interface_buffer *) buffer)->smi;
return buffer;
}
EXPORT_SYMBOL_GPL(dell_smbios_get_buffer);
void dell_smbios_clear_buffer(void)
{
- memset(buffer, 0, sizeof(struct calling_interface_buffer));
+ memset(buffer, 0, bufferlen);
}
EXPORT_SYMBOL_GPL(dell_smbios_clear_buffer);
@@ -76,7 +87,36 @@ void dell_smbios_release_buffer(void)
}
EXPORT_SYMBOL_GPL(dell_smbios_release_buffer);
-void dell_smbios_send_request(int class, int select)
+static int run_wmi_smbios_call(struct wmi_calling_interface_buffer *buf)
+{
+ struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
+ struct acpi_buffer input;
+ union acpi_object *obj;
+ acpi_status status;
+
+ input.length = sizeof(struct wmi_calling_interface_buffer);
+ input.pointer = buf;
+
+ status = wmidev_evaluate_method(wmi_dev, 0, 1, &input, &output);
+ if (ACPI_FAILURE(status)) {
+ pr_err("%x/%x [%x,%x,%x,%x] call failed\n",
+ buf->smi.class, buf->smi.select,
+ buf->smi.input[0], buf->smi.input[1],
+ buf->smi.input[2], buf->smi.input[3]);
+ return -EIO;
+ }
+ obj = (union acpi_object *)output.pointer;
+ if (obj->type != ACPI_TYPE_BUFFER) {
+ pr_err("invalid type : %d\n", obj->type);
+ return -EIO;
+ }
+ memcpy(buf, obj->buffer.pointer, input.length);
+
+ return 0;
+}
+
+#ifdef CONFIG_DCDBAS
+static void run_smi_smbios_call(struct calling_interface_buffer *buf)
{
struct smi_cmd command;
@@ -85,12 +125,28 @@ void dell_smbios_send_request(int class, int select)
command.command_code = da_command_code;
command.ebx = virt_to_phys(buffer);
command.ecx = 0x42534931;
-
- buffer->class = class;
- buffer->select = select;
-
dcdbas_smi_request(&command);
}
+#else
+static void run_smi_smbios_call(struct calling_interface_buffer *buf) {}
+#endif /* CONFIG_DCDBAS */
+
+void dell_smbios_send_request(int class, int select)
+{
+ if (wmi_dev) {
+ struct wmi_calling_interface_buffer *buf = buffer;
+
+ buf->smi.class = class;
+ buf->smi.select = select;
+ run_wmi_smbios_call(buf);
+ } else {
+ struct calling_interface_buffer *buf = buffer;
+
+ buf->class = class;
+ buf->select = select;
+ run_smi_smbios_call(buf);
+ }
+}
EXPORT_SYMBOL_GPL(dell_smbios_send_request);
struct calling_interface_token *dell_smbios_find_token(int tokenid)
@@ -170,10 +226,43 @@ static void __init find_tokens(const struct dmi_header *dm, void *dummy)
}
}
-static int __init dell_smbios_init(void)
+static int dell_smbios_wmi_probe(struct wmi_device *wdev)
+{
+ /* no longer need the SMI page */
+ free_page((unsigned long)buffer);
+
+ /* WMI buffer should be 32k */
+ buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
+ if (!buffer)
+ return -ENOMEM;
+ bufferlen = sizeof(struct wmi_calling_interface_buffer);
+ wmi_dev = wdev;
+ return 0;
+}
+
+static int dell_smbios_wmi_remove(struct wmi_device *wdev)
{
- int ret;
+ wmi_dev = NULL;
+ free_pages((unsigned long)buffer, 3);
+ return 0;
+}
+static const struct wmi_device_id dell_smbios_wmi_id_table[] = {
+ { .guid_string = DELL_WMI_SMBIOS_GUID },
+ { },
+};
+
+static struct wmi_driver dell_wmi_smbios_driver = {
+ .driver = {
+ .name = "dell-smbios",
+ },
+ .probe = dell_smbios_wmi_probe,
+ .remove = dell_smbios_wmi_remove,
+ .id_table = dell_smbios_wmi_id_table,
+};
+
+static int __init dell_smbios_init(void)
+{
dmi_walk(find_tokens, NULL);
if (!da_tokens) {
@@ -181,34 +270,39 @@ static int __init dell_smbios_init(void)
return -ENODEV;
}
+#ifdef CONFIG_DCDBAS
/*
* Allocate buffer below 4GB for SMI data--only 32-bit physical addr
* is passed to SMI handler.
*/
buffer = (void *)__get_free_page(GFP_KERNEL | GFP_DMA32);
+ bufferlen = sizeof(struct calling_interface_buffer);
+#else
+ buffer = NULL;
+#endif /* CONFIG_DCDBAS */
+ wmi_driver_register(&dell_wmi_smbios_driver);
+
if (!buffer) {
- ret = -ENOMEM;
- goto fail_buffer;
+ kfree(da_tokens);
+ return -ENOMEM;
}
-
return 0;
-
-fail_buffer:
- kfree(da_tokens);
- return ret;
}
static void __exit dell_smbios_exit(void)
{
kfree(da_tokens);
free_page((unsigned long)buffer);
+ wmi_driver_unregister(&dell_wmi_smbios_driver);
}
subsys_initcall(dell_smbios_init);
module_exit(dell_smbios_exit);
+
MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
+MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
MODULE_DESCRIPTION("Common functions for kernel modules using Dell SMBIOS");
MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell-smbios.h
index 45cbc2292cd3..2f6fce81ee69 100644
--- a/drivers/platform/x86/dell-smbios.h
+++ b/drivers/platform/x86/dell-smbios.h
@@ -4,6 +4,7 @@
* Copyright (c) Red Hat <mjg@redhat.com>
* Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
* Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
+ * Copyright (c) 2017 Dell Inc.
*
* Based on documentation in the libsmbios package:
* Copyright (C) 2005-2014 Dell Inc.
@@ -18,9 +19,10 @@
struct notifier_block;
-/* This structure will be modified by the firmware when we enter
- * system management mode, hence the volatiles */
-
+/* If called through fallback SMI rather than WMI 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;
@@ -28,6 +30,13 @@ struct calling_interface_buffer {
volatile u32 output[4];
} __packed;
+struct wmi_calling_interface_buffer {
+ struct calling_interface_buffer smi;
+ u32 argattrib;
+ u32 blength;
+ u8 data[32724];
+} __packed;
+
struct calling_interface_token {
u16 tokenID;
u16 location;
--
2.14.1
[toc] | [prev] | [next] | [standalone]
| From | Pali Rohár <pali.rohar@gmail.com> |
|---|---|
| Date | 2017-09-28 09:00 +0200 |
| Subject | Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uuAXE-5v7-7@gated-at.bofh.it> |
| In reply to | #1741162 |
[Multipart message — attachments visible in raw view] — view raw
On Thursday 28 September 2017 06:02:14 Mario Limonciello wrote:
> The driver currently uses an SMI interface which grants direct access
> to physical memory to the firmware SMM methods via a pointer.
>
> Now add a WMI-ACPI interface that is detected by WMI probe and preferred
> over the SMI interface.
>
> 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.
>
> As a result, this change removes the dependency on this driver on the
> dcdbas kernel module. It's now an optional compilation option.
>
> When modifying this, add myself to MAINTAINERS.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
> ---
> MAINTAINERS | 6 ++
> drivers/platform/x86/Kconfig | 14 ++--
> drivers/platform/x86/dell-smbios.c | 128 ++++++++++++++++++++++++++++++++-----
> drivers/platform/x86/dell-smbios.h | 15 ++++-
> 4 files changed, 138 insertions(+), 25 deletions(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 08b96f77f618..6d76b09f46cc 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3990,6 +3990,12 @@ S: Maintained
> F: drivers/hwmon/dell-smm-hwmon.c
> F: include/uapi/linux/i8k.h
>
> +DELL SMBIOS DRIVER
> +M: Pali Rohár <pali.rohar@gmail.com>
> +M: Mario Limonciello <mario.limonciello@dell.com>
> +S: Maintained
> +F: drivers/platform/x86/dell-smbios.*
> +
> DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas)
> M: Doug Warzecha <Douglas_Warzecha@dell.com>
> S: Maintained
> diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> index 1f7959ff055c..415886d7a857 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -92,13 +92,17 @@ config ASUS_LAPTOP
> If you have an ACPI-compatible ASUS laptop, say Y or M here.
>
> config DELL_SMBIOS
> - tristate
> - select DCDBAS
> + tristate "Dell SMBIOS calling interface"
> + depends on ACPI_WMI
> ---help---
> - This module provides common functions for kernel modules using
> - Dell SMBIOS.
> + This module provides common functions for kernel modules and
> + userspace using Dell SMBIOS.
> +
> + If you have a Dell computer, say Y or M here.
>
> - If you have a Dell laptop, say Y or M here.
> + If you have a machine from < 2007 without a WMI interface you
> + may also want to enable CONFIG_DCDBAS to allow this driver to
> + work.
>
> config DELL_LAPTOP
> tristate "Dell Laptop Extras"
> diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios.c
> index e9b1ca07c872..4472817ee045 100644
> --- a/drivers/platform/x86/dell-smbios.c
> +++ b/drivers/platform/x86/dell-smbios.c
> @@ -4,6 +4,7 @@
> * Copyright (c) Red Hat <mjg@redhat.com>
> * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
> * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
> + * Copyright (c) 2017 Dell Inc.
> *
> * Based on documentation in the libsmbios package:
> * Copyright (C) 2005-2014 Dell Inc.
> @@ -22,9 +23,15 @@
> #include <linux/mutex.h>
> #include <linux/slab.h>
> #include <linux/io.h>
> -#include "../../firmware/dcdbas.h"
> +#include <linux/wmi.h>
> #include "dell-smbios.h"
>
> +#ifdef CONFIG_DCDBAS
> +#include "../../firmware/dcdbas.h"
> +#endif
> +
> +#define DELL_WMI_SMBIOS_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
> +
> struct calling_interface_structure {
> struct dmi_header header;
> u16 cmdIOAddress;
> @@ -33,12 +40,14 @@ struct calling_interface_structure {
> struct calling_interface_token tokens[];
> } __packed;
>
> -static struct calling_interface_buffer *buffer;
> +static void *buffer;
> +static size_t bufferlen;
> static DEFINE_MUTEX(buffer_mutex);
>
> static int da_command_address;
> static int da_command_code;
> static int da_num_tokens;
> +struct wmi_device *wmi_dev;
> static struct calling_interface_token *da_tokens;
>
> int dell_smbios_error(int value)
> @@ -60,13 +69,15 @@ struct calling_interface_buffer *dell_smbios_get_buffer(void)
> {
> mutex_lock(&buffer_mutex);
> dell_smbios_clear_buffer();
> + if (wmi_dev)
> + return &((struct wmi_calling_interface_buffer *) buffer)->smi;
> return buffer;
> }
> EXPORT_SYMBOL_GPL(dell_smbios_get_buffer);
>
> void dell_smbios_clear_buffer(void)
> {
> - memset(buffer, 0, sizeof(struct calling_interface_buffer));
> + memset(buffer, 0, bufferlen);
> }
> EXPORT_SYMBOL_GPL(dell_smbios_clear_buffer);
>
> @@ -76,7 +87,36 @@ void dell_smbios_release_buffer(void)
> }
> EXPORT_SYMBOL_GPL(dell_smbios_release_buffer);
>
> -void dell_smbios_send_request(int class, int select)
> +static int run_wmi_smbios_call(struct wmi_calling_interface_buffer *buf)
> +{
> + struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
> + struct acpi_buffer input;
> + union acpi_object *obj;
> + acpi_status status;
> +
> + input.length = sizeof(struct wmi_calling_interface_buffer);
> + input.pointer = buf;
> +
> + status = wmidev_evaluate_method(wmi_dev, 0, 1, &input, &output);
> + if (ACPI_FAILURE(status)) {
> + pr_err("%x/%x [%x,%x,%x,%x] call failed\n",
> + buf->smi.class, buf->smi.select,
> + buf->smi.input[0], buf->smi.input[1],
> + buf->smi.input[2], buf->smi.input[3]);
> + return -EIO;
> + }
> + obj = (union acpi_object *)output.pointer;
> + if (obj->type != ACPI_TYPE_BUFFER) {
> + pr_err("invalid type : %d\n", obj->type);
> + return -EIO;
> + }
> + memcpy(buf, obj->buffer.pointer, input.length);
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_DCDBAS
> +static void run_smi_smbios_call(struct calling_interface_buffer *buf)
> {
> struct smi_cmd command;
>
> @@ -85,12 +125,28 @@ void dell_smbios_send_request(int class, int select)
> command.command_code = da_command_code;
> command.ebx = virt_to_phys(buffer);
> command.ecx = 0x42534931;
> -
> - buffer->class = class;
> - buffer->select = select;
> -
> dcdbas_smi_request(&command);
> }
> +#else
> +static void run_smi_smbios_call(struct calling_interface_buffer *buf) {}
> +#endif /* CONFIG_DCDBAS */
> +
> +void dell_smbios_send_request(int class, int select)
> +{
> + if (wmi_dev) {
> + struct wmi_calling_interface_buffer *buf = buffer;
> +
> + buf->smi.class = class;
> + buf->smi.select = select;
> + run_wmi_smbios_call(buf);
> + } else {
> + struct calling_interface_buffer *buf = buffer;
> +
> + buf->class = class;
> + buf->select = select;
> + run_smi_smbios_call(buf);
> + }
> +}
> EXPORT_SYMBOL_GPL(dell_smbios_send_request);
>
> struct calling_interface_token *dell_smbios_find_token(int tokenid)
> @@ -170,10 +226,43 @@ static void __init find_tokens(const struct dmi_header *dm, void *dummy)
> }
> }
>
> -static int __init dell_smbios_init(void)
> +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> +{
> + /* no longer need the SMI page */
> + free_page((unsigned long)buffer);
> +
> + /* WMI buffer should be 32k */
> + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
> + if (!buffer)
> + return -ENOMEM;
> + bufferlen = sizeof(struct wmi_calling_interface_buffer);
> + wmi_dev = wdev;
> + return 0;
> +}
> +
> +static int dell_smbios_wmi_remove(struct wmi_device *wdev)
> {
> - int ret;
> + wmi_dev = NULL;
> + free_pages((unsigned long)buffer, 3);
> + return 0;
> +}
This code does not seem to be safe. dell_smbios_wmi_probe and
dell_smbios_wmi_remove are called at any time when kernel register new
device which matches some properties OR when user manually bind this
driver to that device.
buffer and wmi_dev is shared as a global variable which means that when
there are two devices which want to bind to this driver, kernel would
get double free at removing time.
Devices from the bus subsystem should not use global shared variables,
but rather allocate own memory...
Also note that user can at any time unbound device from driver and also
can bind it again.
> +static const struct wmi_device_id dell_smbios_wmi_id_table[] = {
> + { .guid_string = DELL_WMI_SMBIOS_GUID },
> + { },
> +};
> +
> +static struct wmi_driver dell_wmi_smbios_driver = {
> + .driver = {
> + .name = "dell-smbios",
> + },
> + .probe = dell_smbios_wmi_probe,
> + .remove = dell_smbios_wmi_remove,
> + .id_table = dell_smbios_wmi_id_table,
> +};
> +
> +static int __init dell_smbios_init(void)
> +{
> dmi_walk(find_tokens, NULL);
>
> if (!da_tokens) {
> @@ -181,34 +270,39 @@ static int __init dell_smbios_init(void)
> return -ENODEV;
> }
>
> +#ifdef CONFIG_DCDBAS
> /*
> * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
> * is passed to SMI handler.
> */
> buffer = (void *)__get_free_page(GFP_KERNEL | GFP_DMA32);
> + bufferlen = sizeof(struct calling_interface_buffer);
> +#else
> + buffer = NULL;
> +#endif /* CONFIG_DCDBAS */
> + wmi_driver_register(&dell_wmi_smbios_driver);
> +
> if (!buffer) {
> - ret = -ENOMEM;
> - goto fail_buffer;
> + kfree(da_tokens);
> + return -ENOMEM;
> }
> -
> return 0;
> -
> -fail_buffer:
> - kfree(da_tokens);
> - return ret;
> }
>
> static void __exit dell_smbios_exit(void)
> {
> kfree(da_tokens);
> free_page((unsigned long)buffer);
> + wmi_driver_unregister(&dell_wmi_smbios_driver);
> }
>
> subsys_initcall(dell_smbios_init);
> module_exit(dell_smbios_exit);
>
> +
> MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
> MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
> MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
> +MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
> MODULE_DESCRIPTION("Common functions for kernel modules using Dell SMBIOS");
> MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell-smbios.h
> index 45cbc2292cd3..2f6fce81ee69 100644
> --- a/drivers/platform/x86/dell-smbios.h
> +++ b/drivers/platform/x86/dell-smbios.h
> @@ -4,6 +4,7 @@
> * Copyright (c) Red Hat <mjg@redhat.com>
> * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
> * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
> + * Copyright (c) 2017 Dell Inc.
> *
> * Based on documentation in the libsmbios package:
> * Copyright (C) 2005-2014 Dell Inc.
> @@ -18,9 +19,10 @@
>
> struct notifier_block;
>
> -/* This structure will be modified by the firmware when we enter
> - * system management mode, hence the volatiles */
> -
> +/* If called through fallback SMI rather than WMI 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;
> @@ -28,6 +30,13 @@ struct calling_interface_buffer {
> volatile u32 output[4];
> } __packed;
>
> +struct wmi_calling_interface_buffer {
> + struct calling_interface_buffer smi;
> + u32 argattrib;
> + u32 blength;
> + u8 data[32724];
> +} __packed;
> +
> struct calling_interface_token {
> u16 tokenID;
> u16 location;
>
--
Pali Rohár
pali.rohar@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | <Mario.Limonciello@dell.com> |
|---|---|
| Date | 2017-09-29 00:50 +0200 |
| Subject | RE: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uuPMZ-6pH-5@gated-at.bofh.it> |
| In reply to | #1741219 |
> -----Original Message-----
> From: Pali Rohár [mailto:pali.rohar@gmail.com]
> Sent: Thursday, September 28, 2017 2:54 AM
> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> Cc: dvhart@infradead.org; Andy Shevchenko <andy.shevchenko@gmail.com>;
> LKML <linux-kernel@vger.kernel.org>; platform-driver-x86@vger.kernel.org; Andy
> Lutomirski <luto@kernel.org>; quasisec@google.com
> Subject: Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI
> interface
>
> On Thursday 28 September 2017 06:02:14 Mario Limonciello wrote:
> > The driver currently uses an SMI interface which grants direct access
> > to physical memory to the firmware SMM methods via a pointer.
> >
> > Now add a WMI-ACPI interface that is detected by WMI probe and preferred
> > over the SMI interface.
> >
> > 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.
> >
> > As a result, this change removes the dependency on this driver on the
> > dcdbas kernel module. It's now an optional compilation option.
> >
> > When modifying this, add myself to MAINTAINERS.
> >
> > Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
> > ---
> > MAINTAINERS | 6 ++
> > drivers/platform/x86/Kconfig | 14 ++--
> > drivers/platform/x86/dell-smbios.c | 128 ++++++++++++++++++++++++++++++++-
> ----
> > drivers/platform/x86/dell-smbios.h | 15 ++++-
> > 4 files changed, 138 insertions(+), 25 deletions(-)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 08b96f77f618..6d76b09f46cc 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -3990,6 +3990,12 @@ S: Maintained
> > F: drivers/hwmon/dell-smm-hwmon.c
> > F: include/uapi/linux/i8k.h
> >
> > +DELL SMBIOS DRIVER
> > +M: Pali Rohár <pali.rohar@gmail.com>
> > +M: Mario Limonciello <mario.limonciello@dell.com>
> > +S: Maintained
> > +F: drivers/platform/x86/dell-smbios.*
> > +
> > DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas)
> > M: Doug Warzecha <Douglas_Warzecha@dell.com>
> > S: Maintained
> > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
> > index 1f7959ff055c..415886d7a857 100644
> > --- a/drivers/platform/x86/Kconfig
> > +++ b/drivers/platform/x86/Kconfig
> > @@ -92,13 +92,17 @@ config ASUS_LAPTOP
> > If you have an ACPI-compatible ASUS laptop, say Y or M here.
> >
> > config DELL_SMBIOS
> > - tristate
> > - select DCDBAS
> > + tristate "Dell SMBIOS calling interface"
> > + depends on ACPI_WMI
> > ---help---
> > - This module provides common functions for kernel modules using
> > - Dell SMBIOS.
> > + This module provides common functions for kernel modules and
> > + userspace using Dell SMBIOS.
> > +
> > + If you have a Dell computer, say Y or M here.
> >
> > - If you have a Dell laptop, say Y or M here.
> > + If you have a machine from < 2007 without a WMI interface you
> > + may also want to enable CONFIG_DCDBAS to allow this driver to
> > + work.
> >
> > config DELL_LAPTOP
> > tristate "Dell Laptop Extras"
> > diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-
> smbios.c
> > index e9b1ca07c872..4472817ee045 100644
> > --- a/drivers/platform/x86/dell-smbios.c
> > +++ b/drivers/platform/x86/dell-smbios.c
> > @@ -4,6 +4,7 @@
> > * Copyright (c) Red Hat <mjg@redhat.com>
> > * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
> > * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
> > + * Copyright (c) 2017 Dell Inc.
> > *
> > * Based on documentation in the libsmbios package:
> > * Copyright (C) 2005-2014 Dell Inc.
> > @@ -22,9 +23,15 @@
> > #include <linux/mutex.h>
> > #include <linux/slab.h>
> > #include <linux/io.h>
> > -#include "../../firmware/dcdbas.h"
> > +#include <linux/wmi.h>
> > #include "dell-smbios.h"
> >
> > +#ifdef CONFIG_DCDBAS
> > +#include "../../firmware/dcdbas.h"
> > +#endif
> > +
> > +#define DELL_WMI_SMBIOS_GUID "A80593CE-A997-11DA-B012-
> B622A1EF5492"
> > +
> > struct calling_interface_structure {
> > struct dmi_header header;
> > u16 cmdIOAddress;
> > @@ -33,12 +40,14 @@ struct calling_interface_structure {
> > struct calling_interface_token tokens[];
> > } __packed;
> >
> > -static struct calling_interface_buffer *buffer;
> > +static void *buffer;
> > +static size_t bufferlen;
> > static DEFINE_MUTEX(buffer_mutex);
> >
> > static int da_command_address;
> > static int da_command_code;
> > static int da_num_tokens;
> > +struct wmi_device *wmi_dev;
> > static struct calling_interface_token *da_tokens;
> >
> > int dell_smbios_error(int value)
> > @@ -60,13 +69,15 @@ struct calling_interface_buffer
> *dell_smbios_get_buffer(void)
> > {
> > mutex_lock(&buffer_mutex);
> > dell_smbios_clear_buffer();
> > + if (wmi_dev)
> > + return &((struct wmi_calling_interface_buffer *) buffer)->smi;
> > return buffer;
> > }
> > EXPORT_SYMBOL_GPL(dell_smbios_get_buffer);
> >
> > void dell_smbios_clear_buffer(void)
> > {
> > - memset(buffer, 0, sizeof(struct calling_interface_buffer));
> > + memset(buffer, 0, bufferlen);
> > }
> > EXPORT_SYMBOL_GPL(dell_smbios_clear_buffer);
> >
> > @@ -76,7 +87,36 @@ void dell_smbios_release_buffer(void)
> > }
> > EXPORT_SYMBOL_GPL(dell_smbios_release_buffer);
> >
> > -void dell_smbios_send_request(int class, int select)
> > +static int run_wmi_smbios_call(struct wmi_calling_interface_buffer *buf)
> > +{
> > + struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
> > + struct acpi_buffer input;
> > + union acpi_object *obj;
> > + acpi_status status;
> > +
> > + input.length = sizeof(struct wmi_calling_interface_buffer);
> > + input.pointer = buf;
> > +
> > + status = wmidev_evaluate_method(wmi_dev, 0, 1, &input, &output);
> > + if (ACPI_FAILURE(status)) {
> > + pr_err("%x/%x [%x,%x,%x,%x] call failed\n",
> > + buf->smi.class, buf->smi.select,
> > + buf->smi.input[0], buf->smi.input[1],
> > + buf->smi.input[2], buf->smi.input[3]);
> > + return -EIO;
> > + }
> > + obj = (union acpi_object *)output.pointer;
> > + if (obj->type != ACPI_TYPE_BUFFER) {
> > + pr_err("invalid type : %d\n", obj->type);
> > + return -EIO;
> > + }
> > + memcpy(buf, obj->buffer.pointer, input.length);
> > +
> > + return 0;
> > +}
> > +
> > +#ifdef CONFIG_DCDBAS
> > +static void run_smi_smbios_call(struct calling_interface_buffer *buf)
> > {
> > struct smi_cmd command;
> >
> > @@ -85,12 +125,28 @@ void dell_smbios_send_request(int class, int select)
> > command.command_code = da_command_code;
> > command.ebx = virt_to_phys(buffer);
> > command.ecx = 0x42534931;
> > -
> > - buffer->class = class;
> > - buffer->select = select;
> > -
> > dcdbas_smi_request(&command);
> > }
> > +#else
> > +static void run_smi_smbios_call(struct calling_interface_buffer *buf) {}
> > +#endif /* CONFIG_DCDBAS */
> > +
> > +void dell_smbios_send_request(int class, int select)
> > +{
> > + if (wmi_dev) {
> > + struct wmi_calling_interface_buffer *buf = buffer;
> > +
> > + buf->smi.class = class;
> > + buf->smi.select = select;
> > + run_wmi_smbios_call(buf);
> > + } else {
> > + struct calling_interface_buffer *buf = buffer;
> > +
> > + buf->class = class;
> > + buf->select = select;
> > + run_smi_smbios_call(buf);
> > + }
> > +}
> > EXPORT_SYMBOL_GPL(dell_smbios_send_request);
> >
> > struct calling_interface_token *dell_smbios_find_token(int tokenid)
> > @@ -170,10 +226,43 @@ static void __init find_tokens(const struct dmi_header
> *dm, void *dummy)
> > }
> > }
> >
> > -static int __init dell_smbios_init(void)
> > +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> > +{
> > + /* no longer need the SMI page */
> > + free_page((unsigned long)buffer);
> > +
> > + /* WMI buffer should be 32k */
> > + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
> > + if (!buffer)
> > + return -ENOMEM;
> > + bufferlen = sizeof(struct wmi_calling_interface_buffer);
> > + wmi_dev = wdev;
> > + return 0;
> > +}
> > +
> > +static int dell_smbios_wmi_remove(struct wmi_device *wdev)
> > {
> > - int ret;
> > + wmi_dev = NULL;
> > + free_pages((unsigned long)buffer, 3);
> > + return 0;
> > +}
>
> This code does not seem to be safe. dell_smbios_wmi_probe and
> dell_smbios_wmi_remove are called at any time when kernel register new
> device which matches some properties OR when user manually bind this
> driver to that device.
>
I'll adjust for the assumptions I made about it only happening at module init.
> buffer and wmi_dev is shared as a global variable which means that when
> there are two devices which want to bind to this driver, kernel would
> get double free at removing time.
But there is only one GUID in id_table. How can two devices bind to this?
This should be an impossible scenario.
>
> Devices from the bus subsystem should not use global shared variables,
> but rather allocate own memory...
Part of the problem is that this module can operate in two modes now.
I think there will have to be global shared variables when operating in SMI
mode. Or maybe put those bits into a platform_device for SMI mode usage?
The problem I think then becomes how do you handle dell_smbios_send_request?
Without global shared memory for the module the dell-laptop and dell-wmi
modules won't be able to use this.
>
> Also note that user can at any time unbound device from driver and also
> can bind it again.
I'll make some adjustments to account for this.
>
> > +static const struct wmi_device_id dell_smbios_wmi_id_table[] = {
> > + { .guid_string = DELL_WMI_SMBIOS_GUID },
> > + { },
> > +};
> > +
> > +static struct wmi_driver dell_wmi_smbios_driver = {
> > + .driver = {
> > + .name = "dell-smbios",
> > + },
> > + .probe = dell_smbios_wmi_probe,
> > + .remove = dell_smbios_wmi_remove,
> > + .id_table = dell_smbios_wmi_id_table,
> > +};
> > +
> > +static int __init dell_smbios_init(void)
> > +{
> > dmi_walk(find_tokens, NULL);
> >
> > if (!da_tokens) {
> > @@ -181,34 +270,39 @@ static int __init dell_smbios_init(void)
> > return -ENODEV;
> > }
> >
> > +#ifdef CONFIG_DCDBAS
> > /*
> > * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
> > * is passed to SMI handler.
> > */
> > buffer = (void *)__get_free_page(GFP_KERNEL | GFP_DMA32);
> > + bufferlen = sizeof(struct calling_interface_buffer);
> > +#else
> > + buffer = NULL;
> > +#endif /* CONFIG_DCDBAS */
> > + wmi_driver_register(&dell_wmi_smbios_driver);
> > +
> > if (!buffer) {
> > - ret = -ENOMEM;
> > - goto fail_buffer;
> > + kfree(da_tokens);
> > + return -ENOMEM;
> > }
> > -
> > return 0;
> > -
> > -fail_buffer:
> > - kfree(da_tokens);
> > - return ret;
> > }
> >
> > static void __exit dell_smbios_exit(void)
> > {
> > kfree(da_tokens);
> > free_page((unsigned long)buffer);
> > + wmi_driver_unregister(&dell_wmi_smbios_driver);
> > }
> >
> > subsys_initcall(dell_smbios_init);
> > module_exit(dell_smbios_exit);
> >
> > +
> > MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
> > MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
> > MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
> > +MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
> > MODULE_DESCRIPTION("Common functions for kernel modules using Dell
> SMBIOS");
> > MODULE_LICENSE("GPL");
> > diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell-
> smbios.h
> > index 45cbc2292cd3..2f6fce81ee69 100644
> > --- a/drivers/platform/x86/dell-smbios.h
> > +++ b/drivers/platform/x86/dell-smbios.h
> > @@ -4,6 +4,7 @@
> > * Copyright (c) Red Hat <mjg@redhat.com>
> > * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
> > * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
> > + * Copyright (c) 2017 Dell Inc.
> > *
> > * Based on documentation in the libsmbios package:
> > * Copyright (C) 2005-2014 Dell Inc.
> > @@ -18,9 +19,10 @@
> >
> > struct notifier_block;
> >
> > -/* This structure will be modified by the firmware when we enter
> > - * system management mode, hence the volatiles */
> > -
> > +/* If called through fallback SMI rather than WMI 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;
> > @@ -28,6 +30,13 @@ struct calling_interface_buffer {
> > volatile u32 output[4];
> > } __packed;
> >
> > +struct wmi_calling_interface_buffer {
> > + struct calling_interface_buffer smi;
> > + u32 argattrib;
> > + u32 blength;
> > + u8 data[32724];
> > +} __packed;
> > +
> > struct calling_interface_token {
> > u16 tokenID;
> > u16 location;
> >
>
> --
> Pali Rohár
> pali.rohar@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Pali Rohár <pali.rohar@gmail.com> |
|---|---|
| Date | 2017-09-29 09:40 +0200 |
| Subject | Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uuY3U-3eu-7@gated-at.bofh.it> |
| In reply to | #1741840 |
On Thursday 28 September 2017 22:43:36 Mario.Limonciello@dell.com wrote:
> > > @@ -170,10 +226,43 @@ static void __init find_tokens(const struct dmi_header
> > *dm, void *dummy)
> > > }
> > > }
> > >
> > > -static int __init dell_smbios_init(void)
> > > +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> > > +{
> > > + /* no longer need the SMI page */
> > > + free_page((unsigned long)buffer);
> > > +
> > > + /* WMI buffer should be 32k */
> > > + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
> > > + if (!buffer)
> > > + return -ENOMEM;
> > > + bufferlen = sizeof(struct wmi_calling_interface_buffer);
> > > + wmi_dev = wdev;
> > > + return 0;
> > > +}
> > > +
> > > +static int dell_smbios_wmi_remove(struct wmi_device *wdev)
> > > {
> > > - int ret;
> > > + wmi_dev = NULL;
> > > + free_pages((unsigned long)buffer, 3);
> > > + return 0;
> > > +}
> >
> > This code does not seem to be safe. dell_smbios_wmi_probe and
> > dell_smbios_wmi_remove are called at any time when kernel register new
> > device which matches some properties OR when user manually bind this
> > driver to that device.
> >
> I'll adjust for the assumptions I made about it only happening at module init.
>
> > buffer and wmi_dev is shared as a global variable which means that when
> > there are two devices which want to bind to this driver, kernel would
> > get double free at removing time.
>
> But there is only one GUID in id_table.
That is truth, but ...
> How can two devices bind to this?
> This should be an impossible scenario.
... in ACPI DSDT can be more WMI _WDG buffers which could lead to more
wmi buses and each could have own GUID. Therefore there is a theoretical
chance that specially prepared ACPI DSDT code can cause this problem.
> > Devices from the bus subsystem should not use global shared variables,
> > but rather allocate own memory...
>
> Part of the problem is that this module can operate in two modes now.
> I think there will have to be global shared variables when operating in SMI
> mode. Or maybe put those bits into a platform_device for SMI mode usage?
>
> The problem I think then becomes how do you handle dell_smbios_send_request?
> Without global shared memory for the module the dell-laptop and dell-wmi
> modules won't be able to use this.
The whole problem is that SMBIOS calls are implemented via singleton
pattern. And this singleton "instance" needs to use something which is
not a singleton, but a dynamic objects (wmi device <--> driver pattern).
Idea how to handle it:
* put wmi smbios call function into own driver
* put smm smbios call function into own driver
* create dispatcher function which take first available device of one of
the above driver and call on them smbios call function
This problem is very similar to problems in objects world... driver as a
class and device as a instance.
(Or if somebody has a better idea, let us know...)
> > Also note that user can at any time unbound device from driver and also
> > can bind it again.
> I'll make some adjustments to account for this.
To prevent crashing kernel, this needs to be written correctly. And user
should not be able to crash kernel just when trying to unbound driver
from the device.
--
Pali Rohár
pali.rohar@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | <Mario.Limonciello@dell.com> |
|---|---|
| Date | 2017-09-30 22:10 +0200 |
| Subject | RE: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uvwff-qT-1@gated-at.bofh.it> |
| In reply to | #1741953 |
> -----Original Message-----
> From: Pali Rohár [mailto:pali.rohar@gmail.com]
> Sent: Friday, September 29, 2017 2:36 AM
> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> Cc: dvhart@infradead.org; andy.shevchenko@gmail.com; linux-
> kernel@vger.kernel.org; platform-driver-x86@vger.kernel.org; luto@kernel.org;
> quasisec@google.com
> Subject: Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI
> interface
>
> On Thursday 28 September 2017 22:43:36 Mario.Limonciello@dell.com wrote:
> > > > @@ -170,10 +226,43 @@ static void __init find_tokens(const struct
> dmi_header
> > > *dm, void *dummy)
> > > > }
> > > > }
> > > >
> > > > -static int __init dell_smbios_init(void)
> > > > +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> > > > +{
> > > > + /* no longer need the SMI page */
> > > > + free_page((unsigned long)buffer);
> > > > +
> > > > + /* WMI buffer should be 32k */
> > > > + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
> > > > + if (!buffer)
> > > > + return -ENOMEM;
> > > > + bufferlen = sizeof(struct wmi_calling_interface_buffer);
> > > > + wmi_dev = wdev;
> > > > + return 0;
> > > > +}
> > > > +
> > > > +static int dell_smbios_wmi_remove(struct wmi_device *wdev)
> > > > {
> > > > - int ret;
> > > > + wmi_dev = NULL;
> > > > + free_pages((unsigned long)buffer, 3);
> > > > + return 0;
> > > > +}
> > >
> > > This code does not seem to be safe. dell_smbios_wmi_probe and
> > > dell_smbios_wmi_remove are called at any time when kernel register new
> > > device which matches some properties OR when user manually bind this
> > > driver to that device.
> > >
> > I'll adjust for the assumptions I made about it only happening at module init.
> >
> > > buffer and wmi_dev is shared as a global variable which means that when
> > > there are two devices which want to bind to this driver, kernel would
> > > get double free at removing time.
> >
> > But there is only one GUID in id_table.
>
> That is truth, but ...
>
> > How can two devices bind to this?
> > This should be an impossible scenario.
>
> ... in ACPI DSDT can be more WMI _WDG buffers which could lead to more
> wmi buses and each could have own GUID. Therefore there is a theoretical
> chance that specially prepared ACPI DSDT code can cause this problem.
I guess I'm a bit confused - is this for protecting a user who patches their own
DSDT or from a vendor releasing a system with two _WDG buffers with the
same GUID?
I don't believe MOF has a concept of which WDG buffer GUIDs are assigned
to. That could lead to massively undefined behavior too since the WDG buffer
will potentially assign different ASL to process for each GUID.
>
> > > Devices from the bus subsystem should not use global shared variables,
> > > but rather allocate own memory...
> >
> > Part of the problem is that this module can operate in two modes now.
> > I think there will have to be global shared variables when operating in SMI
> > mode. Or maybe put those bits into a platform_device for SMI mode usage?
> >
> > The problem I think then becomes how do you handle
> dell_smbios_send_request?
> > Without global shared memory for the module the dell-laptop and dell-wmi
> > modules won't be able to use this.
>
> The whole problem is that SMBIOS calls are implemented via singleton
> pattern. And this singleton "instance" needs to use something which is
> not a singleton, but a dynamic objects (wmi device <--> driver pattern).
>
> Idea how to handle it:
> * put wmi smbios call function into own driver
> * put smm smbios call function into own driver
> * create dispatcher function which take first available device of one of
> the above driver and call on them smbios call function
>
> This problem is very similar to problems in objects world... driver as a
> class and device as a instance.
>
> (Or if somebody has a better idea, let us know...)
So I like the 3rd idea the most, and it's what I'm working on. I've got some
problems with it that I'm still fixing, but unless someone tells me otherwise
I'll go for that with v4.
>
> > > Also note that user can at any time unbound device from driver and also
> > > can bind it again.
> > I'll make some adjustments to account for this.
>
> To prevent crashing kernel, this needs to be written correctly. And user
> should not be able to crash kernel just when trying to unbound driver
> from the device.
>
Agree.
[toc] | [prev] | [next] | [standalone]
| From | Pali Rohár <pali.rohar@gmail.com> |
|---|---|
| Date | 2017-09-30 23:10 +0200 |
| Subject | Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uvxbj-12x-3@gated-at.bofh.it> |
| In reply to | #1742684 |
[Multipart message — attachments visible in raw view] — view raw
On Saturday 30 September 2017 22:01:04 Mario.Limonciello@dell.com wrote:
> > -----Original Message-----
> > From: Pali Rohár [mailto:pali.rohar@gmail.com]
> > Sent: Friday, September 29, 2017 2:36 AM
> > To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> > Cc: dvhart@infradead.org; andy.shevchenko@gmail.com; linux-
> > kernel@vger.kernel.org; platform-driver-x86@vger.kernel.org;
> > luto@kernel.org; quasisec@google.com
> > Subject: Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a
> > WMI-ACPI interface
> >
> > On Thursday 28 September 2017 22:43:36 Mario.Limonciello@dell.com
> > wrote:
> > > > > @@ -170,10 +226,43 @@ static void __init find_tokens(const
> > > > > struct
> >
> > dmi_header
> >
> > > > *dm, void *dummy)
> > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > -static int __init dell_smbios_init(void)
> > > > > +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> > > > > +{
> > > > > + /* no longer need the SMI page */
> > > > > + free_page((unsigned long)buffer);
> > > > > +
> > > > > + /* WMI buffer should be 32k */
> > > > > + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
> > > > > + if (!buffer)
> > > > > + return -ENOMEM;
> > > > > + bufferlen = sizeof(struct wmi_calling_interface_buffer);
> > > > > + wmi_dev = wdev;
> > > > > + return 0;
> > > > > +}
> > > > > +
> > > > > +static int dell_smbios_wmi_remove(struct wmi_device *wdev)
> > > > >
> > > > > {
> > > > >
> > > > > - int ret;
> > > > > + wmi_dev = NULL;
> > > > > + free_pages((unsigned long)buffer, 3);
> > > > > + return 0;
> > > > > +}
> > > >
> > > > This code does not seem to be safe. dell_smbios_wmi_probe and
> > > > dell_smbios_wmi_remove are called at any time when kernel
> > > > register new device which matches some properties OR when user
> > > > manually bind this driver to that device.
> > >
> > > I'll adjust for the assumptions I made about it only happening at
> > > module init.
> > >
> > > > buffer and wmi_dev is shared as a global variable which means
> > > > that when there are two devices which want to bind to this
> > > > driver, kernel would get double free at removing time.
> > >
> > > But there is only one GUID in id_table.
> >
> > That is truth, but ...
> >
> > > How can two devices bind to this?
> > > This should be an impossible scenario.
> >
> > ... in ACPI DSDT can be more WMI _WDG buffers which could lead to
> > more wmi buses and each could have own GUID. Therefore there is a
> > theoretical chance that specially prepared ACPI DSDT code can
> > cause this problem.
>
> I guess I'm a bit confused - is this for protecting a user who
> patches their own DSDT or from a vendor releasing a system with two
> _WDG buffers with the same GUID?
It is protection for memory corruption done by dell-smbios driver in
case such DSDT would be parsed by kernel (either by user who patches
original DSDT or when vendor created such DSDT by mistake or by
malicious software which patch/provide such DSDT...).
DSDT is from kernel point of view external (possible untrusted) data.
ACPI parser in kernel parse it if they are syntactically correct, but
semantic or e.g. _WDG meaning is up to consumer -- in our case wmi and
dell-smbios wmi drivers.
> I don't believe MOF has a concept of which WDG buffer GUIDs are
> assigned to. That could lead to massively undefined behavior too
> since the WDG buffer will potentially assign different ASL to
> process for each GUID.
Yes, that would lead to undefined behaviour. But still it should not
crash kernel. Either treat such thing as "corrupted data" and refuse to
use it or treat it in deterministic way, e.g. "first come, first serve"
or load it driver for all guids...
E.g. DSDT on Thinkpads has more _WDG buffers and I was told that some
machines with Nvidia graphics cards really have duplicate WMI GUIDs in
_WDG. So such situation really happen in world, it is not just
theoretical.
> > The whole problem is that SMBIOS calls are implemented via
> > singleton pattern. And this singleton "instance" needs to use
> > something which is not a singleton, but a dynamic objects (wmi
> > device <--> driver pattern).
> >
> > Idea how to handle it:
> > * put wmi smbios call function into own driver
> > * put smm smbios call function into own driver
> > * create dispatcher function which take first available device of
> > one of
> >
> > the above driver and call on them smbios call function
> >
> > This problem is very similar to problems in objects world... driver
> > as a class and device as a instance.
> >
> > (Or if somebody has a better idea, let us know...)
>
> So I like the 3rd idea the most, and it's what I'm working on. I've
> got some problems with it that I'm still fixing, but unless someone
> tells me otherwise I'll go for that with v4.
All above 3 points (*) were meant as one solution. Putting wmi and smm
calls into own drivers and then creating dispatcher function which would
use available device of one of those two drivers.
--
Pali Rohár
pali.rohar@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Darren Hart <dvhart@infradead.org> |
|---|---|
| Date | 2017-09-30 03:00 +0200 |
| Subject | Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uveil-5bX-1@gated-at.bofh.it> |
| In reply to | #1741162 |
On Wed, Sep 27, 2017 at 11:02:14PM -0500, Mario Limonciello wrote:
> The driver currently uses an SMI interface which grants direct access
> to physical memory to the firmware SMM methods via a pointer.
>
> Now add a WMI-ACPI interface that is detected by WMI probe and preferred
> over the SMI interface.
>
> 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.
>
> As a result, this change removes the dependency on this driver on the
> dcdbas kernel module. It's now an optional compilation option.
>
> When modifying this, add myself to MAINTAINERS.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
> ---
...
> +DELL SMBIOS DRIVER
> +M: Pali Rohár <pali.rohar@gmail.com>
> +M: Mario Limonciello <mario.limonciello@dell.com>
> +S: Maintained
> +F: drivers/platform/x86/dell-smbios.*
Pali, do you agree with this?
...
> int dell_smbios_error(int value)
> @@ -60,13 +69,15 @@ struct calling_interface_buffer *dell_smbios_get_buffer(void)
> {
> mutex_lock(&buffer_mutex);
> dell_smbios_clear_buffer();
> + if (wmi_dev)
> + return &((struct wmi_calling_interface_buffer *) buffer)->smi;
> return buffer;
Hrm, my hope had been to make this transparent at this level. ... This
may need more thought. I don't care for the casting here.... hopefully
enlightenment lies below...
> +static int run_wmi_smbios_call(struct wmi_calling_interface_buffer *buf)
> +{
> + struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
> + struct acpi_buffer input;
> + union acpi_object *obj;
> + acpi_status status;
> +
> + input.length = sizeof(struct wmi_calling_interface_buffer);
> + input.pointer = buf;
> +
> + status = wmidev_evaluate_method(wmi_dev, 0, 1, &input, &output);
> + if (ACPI_FAILURE(status)) {
> + pr_err("%x/%x [%x,%x,%x,%x] call failed\n",
> + buf->smi.class, buf->smi.select,
> + buf->smi.input[0], buf->smi.input[1],
> + buf->smi.input[2], buf->smi.input[3]);
> + return -EIO;
> + }
> + obj = (union acpi_object *)output.pointer;
> + if (obj->type != ACPI_TYPE_BUFFER) {
> + pr_err("invalid type : %d\n", obj->type);
> + return -EIO;
> + }
We ensure we don't write beyond buf, but we havne't ensured we don't read beyond
obj.
if (obj->length != input.length) { // or maybe >= ??
pr_err("invalid buffer length : %d\n", obj->length);
return -EINVAL;
}
> -static int __init dell_smbios_init(void)
> +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> +{
> + /* no longer need the SMI page */
> + free_page((unsigned long)buffer);
> +
> + /* WMI buffer should be 32k */
> + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
Assuming PAGE_SIZE here (I know, this driver, this architecture,
etc...). But, please use get_order() to determine number of pages
from a linear size:
__get_free_pages(GFP_KERNEL, get_order(32768));
> + if (!buffer)
> + return -ENOMEM;
> + bufferlen = sizeof(struct wmi_calling_interface_buffer);
Use a consistent way to allocate and set the len. Maybe set bufferlen
above and use get_order(bufferlen).
> + wmi_dev = wdev;
> + return 0;
> +}
> +
> +static int dell_smbios_wmi_remove(struct wmi_device *wdev)
> {
> - int ret;
> + wmi_dev = NULL;
> + free_pages((unsigned long)buffer, 3);
> + return 0;
> +}
>
> +static const struct wmi_device_id dell_smbios_wmi_id_table[] = {
> + { .guid_string = DELL_WMI_SMBIOS_GUID },
> + { },
> +};
> +
> +static struct wmi_driver dell_wmi_smbios_driver = {
> + .driver = {
> + .name = "dell-smbios",
> + },
> + .probe = dell_smbios_wmi_probe,
> + .remove = dell_smbios_wmi_remove,
> + .id_table = dell_smbios_wmi_id_table,
> +};
> +
> +static int __init dell_smbios_init(void)
> +{
> dmi_walk(find_tokens, NULL);
>
> if (!da_tokens) {
> @@ -181,34 +270,39 @@ static int __init dell_smbios_init(void)
> return -ENODEV;
> }
>
> +#ifdef CONFIG_DCDBAS
If this cannot be avoided, then use IS_ENABLED(CONFIG_DCDBAS).
I still think we should be to come up with a cleaner way to deal with
the two buffers than a bunch of #ifdefs and if (wdev) {} else {} blocks.
...
> diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell-smbios.h
...
> -/* This structure will be modified by the firmware when we enter
> - * system management mode, hence the volatiles */
> -
> +/* If called through fallback SMI rather than WMI this structure will be
> + * modified by the firmware when we enter system management mode, hence the
> + * volatiles
> + */
Follow coding style when modifying comment blocks (even when they
didn't before) please. See coding-style 8) COmmenting.
/*
* If called ...
...
* volatiles.
*/
--
Darren Hart
VMware Open Source Technology Center
[toc] | [prev] | [next] | [standalone]
| From | Pali Rohár <pali.rohar@gmail.com> |
|---|---|
| Date | 2017-09-30 09:20 +0200 |
| Subject | Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uvke6-YT-17@gated-at.bofh.it> |
| In reply to | #1742419 |
[Multipart message — attachments visible in raw view] — view raw
On Saturday 30 September 2017 02:51:27 Darren Hart wrote:
> > +DELL SMBIOS DRIVER
> > +M: Pali Rohár <pali.rohar@gmail.com>
> > +M: Mario Limonciello <mario.limonciello@dell.com>
> > +S: Maintained
> > +F: drivers/platform/x86/dell-smbios.*
>
> Pali, do you agree with this?
Yes, no problem.
> > -static int __init dell_smbios_init(void)
> > +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> > +{
> > + /* no longer need the SMI page */
> > + free_page((unsigned long)buffer);
> > +
> > + /* WMI buffer should be 32k */
> > + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
>
> Assuming PAGE_SIZE here (I know, this driver, this architecture,
> etc...). But, please use get_order() to determine number of pages
> from a linear size:
>
> __get_free_pages(GFP_KERNEL, get_order(32768));
I agree that specifying size (instead of count) explicitly lead to more
readable code.
--
Pali Rohár
pali.rohar@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | <Mario.Limonciello@dell.com> |
|---|---|
| Date | 2017-09-30 22:00 +0200 |
| Subject | RE: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface |
| Message-ID | <uvw5A-83-3@gated-at.bofh.it> |
| In reply to | #1742538 |
> -----Original Message-----
> From: Pali Rohár [mailto:pali.rohar@gmail.com]
> Sent: Saturday, September 30, 2017 2:16 AM
> To: Darren Hart <dvhart@infradead.org>
> Cc: Limonciello, Mario <Mario_Limonciello@Dell.com>; Andy Shevchenko
> <andy.shevchenko@gmail.com>; LKML <linux-kernel@vger.kernel.org>;
> platform-driver-x86@vger.kernel.org; Andy Lutomirski <luto@kernel.org>;
> quasisec@google.com
> Subject: Re: [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI
> interface
>
> On Saturday 30 September 2017 02:51:27 Darren Hart wrote:
> > > +DELL SMBIOS DRIVER
> > > +M: Pali Rohár <pali.rohar@gmail.com>
> > > +M: Mario Limonciello <mario.limonciello@dell.com>
> > > +S: Maintained
> > > +F: drivers/platform/x86/dell-smbios.*
> >
> > Pali, do you agree with this?
>
> Yes, no problem.
>
> > > -static int __init dell_smbios_init(void)
> > > +static int dell_smbios_wmi_probe(struct wmi_device *wdev)
> > > +{
> > > + /* no longer need the SMI page */
> > > + free_page((unsigned long)buffer);
> > > +
> > > + /* WMI buffer should be 32k */
> > > + buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
> >
> > Assuming PAGE_SIZE here (I know, this driver, this architecture,
> > etc...). But, please use get_order() to determine number of pages
> > from a linear size:
> >
> > __get_free_pages(GFP_KERNEL, get_order(32768));
>
> I agree that specifying size (instead of count) explicitly lead to more
> readable code.
>
Alright will adjust.
[toc] | [prev] | [next] | [standalone]
| From | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| Date | 2017-09-28 06:10 +0200 |
| Subject | [PATCH v3 7/8] platform/x86: Kconfig: Change the default settings for dell-wmi-smbios |
| Message-ID | <uuyj8-40H-23@gated-at.bofh.it> |
| In reply to | #1741159 |
The dell-wmi-smbios driver should be enabled by default when ACPI_WMI
is enabled (like many other WMI drivers).
Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
drivers/platform/x86/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 415886d7a857..a83c275019a4 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -94,6 +94,7 @@ config ASUS_LAPTOP
config DELL_SMBIOS
tristate "Dell SMBIOS calling interface"
depends on ACPI_WMI
+ default ACPI_WMI
---help---
This module provides common functions for kernel modules and
userspace using Dell SMBIOS.
--
2.14.1
[toc] | [prev] | [next] | [standalone]
| From | Mario Limonciello <mario.limonciello@dell.com> |
|---|---|
| Date | 2017-09-28 06:10 +0200 |
| Subject | [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace |
| Message-ID | <uuyj8-40H-27@gated-at.bofh.it> |
| In reply to | #1741159 |
This userspace character device will be used to perform SMBIOS calls
from any applications.
It provides an ioctl that will allow passing the 32k 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.
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.
The character device will only be created if the WMI interface was
found.
The API for interacting with this interface is defined in documentation
as well as a uapi header provides the format of the structures.
Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
---
Documentation/ABI/testing/dell-wmi-smbios | 11 ++++
drivers/platform/x86/dell-smbios.c | 100 ++++++++++++++++++++++++------
drivers/platform/x86/dell-smbios.h | 19 +-----
include/uapi/linux/dell-wmi-smbios.h | 30 +++++++++
4 files changed, 124 insertions(+), 36 deletions(-)
create mode 100644 Documentation/ABI/testing/dell-wmi-smbios
create mode 100644 include/uapi/linux/dell-wmi-smbios.h
diff --git a/Documentation/ABI/testing/dell-wmi-smbios b/Documentation/ABI/testing/dell-wmi-smbios
new file mode 100644
index 000000000000..0a4200688cb0
--- /dev/null
+++ b/Documentation/ABI/testing/dell-wmi-smbios
@@ -0,0 +1,11 @@
+What: /dev/wmi-dell-wmi-smbios
+Date: October 2017
+KernelVersion: 4.15
+Contact: "Mario Limonciello" <mario.limonciello@dell.com>
+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-wmi-smbios.h>
+
diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios.c
index 5d793b012e5e..4174afbade13 100644
--- a/drivers/platform/x86/dell-smbios.c
+++ b/drivers/platform/x86/dell-smbios.c
@@ -24,6 +24,7 @@
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/wmi.h>
+#include <linux/uaccess.h>
#include "dell-smbios.h"
#ifdef CONFIG_DCDBAS
@@ -41,8 +42,9 @@ struct calling_interface_structure {
struct calling_interface_token tokens[];
} __packed;
-static void *buffer;
-static size_t bufferlen;
+static void *internal_buffer;
+static size_t internal_bufferlen;
+static struct wmi_calling_interface_buffer *devfs_buffer;
static DEFINE_MUTEX(buffer_mutex);
static int da_command_address;
@@ -70,15 +72,15 @@ struct calling_interface_buffer *dell_smbios_get_buffer(void)
{
mutex_lock(&buffer_mutex);
dell_smbios_clear_buffer();
- if (wmi_dev)
- return &((struct wmi_calling_interface_buffer *) buffer)->smi;
- return buffer;
+ if (!wmi_dev)
+ return internal_buffer;
+ return &((struct wmi_calling_interface_buffer *) internal_buffer)->smi;
}
EXPORT_SYMBOL_GPL(dell_smbios_get_buffer);
void dell_smbios_clear_buffer(void)
{
- memset(buffer, 0, bufferlen);
+ memset(internal_buffer, 0, internal_bufferlen);
}
EXPORT_SYMBOL_GPL(dell_smbios_clear_buffer);
@@ -135,13 +137,13 @@ static void run_smi_smbios_call(struct calling_interface_buffer *buf) {}
void dell_smbios_send_request(int class, int select)
{
if (wmi_dev) {
- struct wmi_calling_interface_buffer *buf = buffer;
+ struct wmi_calling_interface_buffer *buf = internal_buffer;
buf->smi.class = class;
buf->smi.select = select;
run_wmi_smbios_call(buf);
} else {
- struct calling_interface_buffer *buf = buffer;
+ struct calling_interface_buffer *buf = internal_buffer;
buf->class = class;
buf->select = select;
@@ -227,6 +229,49 @@ static void __init find_tokens(const struct dmi_header *dm, void *dummy)
}
}
+static int dell_wmi_smbios_open(struct inode *inode, struct file *file)
+{
+ return nonseekable_open(inode, file);
+}
+
+static int dell_wmi_smbios_release(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+static long dell_wmi_smbios_ioctl(struct file *filp, unsigned int cmd,
+ unsigned long arg)
+{
+ void __user *p = (void __user *) arg;
+ size_t size;
+ int ret = 0;
+
+ if (_IOC_TYPE(cmd) != DELL_WMI_SMBIOS_IOC)
+ return -ENOTTY;
+
+ switch (cmd) {
+ case DELL_WMI_SMBIOS_CALL_CMD:
+ size = sizeof(struct wmi_calling_interface_buffer);
+ mutex_lock(&buffer_mutex);
+ if (copy_from_user(devfs_buffer, p, size)) {
+ ret = -EFAULT;
+ goto fail_smbios_cmd;
+ }
+ ret = run_wmi_smbios_call(devfs_buffer);
+ if (ret != 0)
+ goto fail_smbios_cmd;
+ if (copy_to_user(p, devfs_buffer, size))
+ ret = -EFAULT;
+fail_smbios_cmd:
+ mutex_unlock(&buffer_mutex);
+ break;
+ default:
+ pr_err("unsupported ioctl: %d.\n", cmd);
+ ret = -ENOIOCTLCMD;
+ }
+ return ret;
+}
+
/*
* Descriptor buffer is 128 byte long and contains:
*
@@ -309,22 +354,33 @@ static int dell_smbios_wmi_probe(struct wmi_device *wdev)
return -ENODEV;
/* no longer need the SMI page */
- free_page((unsigned long)buffer);
+ free_page((unsigned long)internal_buffer);
/* WMI buffer should be 32k */
- buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
- if (!buffer)
+ internal_buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
+ if (!internal_buffer)
return -ENOMEM;
- bufferlen = sizeof(struct wmi_calling_interface_buffer);
+ internal_bufferlen = sizeof(struct wmi_calling_interface_buffer);
+
+ devfs_buffer = (void *)__get_free_pages(GFP_KERNEL, 3);
+ if (!devfs_buffer) {
+ ret = -ENOMEM;
+ goto fail_devfs_buffer;
+ }
wmi_dev = wdev;
return 0;
+
+fail_devfs_buffer:
+ free_pages((unsigned long)internal_buffer, 3);
+ return ret;
}
static int dell_smbios_wmi_remove(struct wmi_device *wdev)
{
wmi_dev = NULL;
- free_pages((unsigned long)buffer, 3);
+ free_pages((unsigned long)internal_buffer, 3);
+ free_pages((unsigned long)devfs_buffer, 3);
return 0;
}
@@ -333,6 +389,13 @@ static const struct wmi_device_id dell_smbios_wmi_id_table[] = {
{ },
};
+static const struct file_operations dell_wmi_smbios_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = dell_wmi_smbios_ioctl,
+ .open = dell_wmi_smbios_open,
+ .release = dell_wmi_smbios_release,
+};
+
static struct wmi_driver dell_wmi_smbios_driver = {
.driver = {
.name = "dell-smbios",
@@ -340,6 +403,7 @@ static struct wmi_driver dell_wmi_smbios_driver = {
.probe = dell_smbios_wmi_probe,
.remove = dell_smbios_wmi_remove,
.id_table = dell_smbios_wmi_id_table,
+ .file_operations = &dell_wmi_smbios_fops,
};
static int __init dell_smbios_init(void)
@@ -356,14 +420,14 @@ static int __init dell_smbios_init(void)
* Allocate buffer below 4GB for SMI data--only 32-bit physical addr
* is passed to SMI handler.
*/
- buffer = (void *)__get_free_page(GFP_KERNEL | GFP_DMA32);
- bufferlen = sizeof(struct calling_interface_buffer);
+ internal_buffer = (void *)__get_free_page(GFP_KERNEL | GFP_DMA32);
+ internal_bufferlen = sizeof(struct calling_interface_buffer);
#else
- buffer = NULL;
+ internal_buffer = NULL;
#endif /* CONFIG_DCDBAS */
wmi_driver_register(&dell_wmi_smbios_driver);
- if (!buffer) {
+ if (!internal_buffer) {
kfree(da_tokens);
return -ENOMEM;
}
@@ -373,7 +437,7 @@ static int __init dell_smbios_init(void)
static void __exit dell_smbios_exit(void)
{
kfree(da_tokens);
- free_page((unsigned long)buffer);
+ free_page((unsigned long)internal_buffer);
wmi_driver_unregister(&dell_wmi_smbios_driver);
}
diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell-smbios.h
index be9ec1ccf8bf..3b0e2e3f6ede 100644
--- a/drivers/platform/x86/dell-smbios.h
+++ b/drivers/platform/x86/dell-smbios.h
@@ -18,27 +18,10 @@
#define _DELL_SMBIOS_H_
#include <linux/wmi.h>
+#include <uapi/linux/dell-wmi-smbios.h>
struct notifier_block;
-/* If called through fallback SMI rather than WMI 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 wmi_calling_interface_buffer {
- struct calling_interface_buffer smi;
- u32 argattrib;
- u32 blength;
- u8 data[32724];
-} __packed;
-
struct calling_interface_token {
u16 tokenID;
u16 location;
diff --git a/include/uapi/linux/dell-wmi-smbios.h b/include/uapi/linux/dell-wmi-smbios.h
new file mode 100644
index 000000000000..adbe57dd055b
--- /dev/null
+++ b/include/uapi/linux/dell-wmi-smbios.h
@@ -0,0 +1,30 @@
+#ifndef _UAPI_DELL_WMI_SMBIOS_H_
+#define _UAPI_DELL_WMI_SMBIOS_H_
+
+#include <linux/ioctl.h>
+
+/* If called through fallback SMI rather than WMI 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 wmi_calling_interface_buffer {
+ struct calling_interface_buffer smi;
+ u32 argattrib;
+ u32 blength;
+ u8 data[32724];
+} __packed;
+
+#define DELL_WMI_SMBIOS_IOC 'D'
+/* run SMBIOS calling interface command
+ * note - 32k is too big for size, so this can not be encoded in macro properly
+ */
+#define DELL_WMI_SMBIOS_CALL_CMD _IOWR(DELL_WMI_SMBIOS_IOC, 0, u8)
+
+#endif /* _UAPI_DELL_WMI_SMBIOS_H_ */
--
2.14.1
[toc] | [prev] | [next] | [standalone]
| From | Darren Hart <dvhart@infradead.org> |
|---|---|
| Date | 2017-09-30 04:10 +0200 |
| Subject | Re: [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace |
| Message-ID | <uvfo5-69K-5@gated-at.bofh.it> |
| In reply to | #1741165 |
On Wed, Sep 27, 2017 at 11:02:17PM -0500, Mario Limonciello wrote:
> This userspace character device will be used to perform SMBIOS calls
> from any applications.
>
> It provides an ioctl that will allow passing the 32k 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.
>
> 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.
>
> The character device will only be created if the WMI interface was
> found.
>
> The API for interacting with this interface is defined in documentation
> as well as a uapi header provides the format of the structures.
>
> Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
> ---
> Documentation/ABI/testing/dell-wmi-smbios | 11 ++++
> drivers/platform/x86/dell-smbios.c | 100 ++++++++++++++++++++++++------
> drivers/platform/x86/dell-smbios.h | 19 +-----
> include/uapi/linux/dell-wmi-smbios.h | 30 +++++++++
> 4 files changed, 124 insertions(+), 36 deletions(-)
> create mode 100644 Documentation/ABI/testing/dell-wmi-smbios
> create mode 100644 include/uapi/linux/dell-wmi-smbios.h
>
> diff --git a/Documentation/ABI/testing/dell-wmi-smbios b/Documentation/ABI/testing/dell-wmi-smbios
> new file mode 100644
> index 000000000000..0a4200688cb0
> --- /dev/null
> +++ b/Documentation/ABI/testing/dell-wmi-smbios
> @@ -0,0 +1,11 @@
> +What: /dev/wmi-dell-wmi-smbios
/dev/wmi/dell-smbios
> +Date: October 2017
> +KernelVersion: 4.15
> +Contact: "Mario Limonciello" <mario.limonciello@dell.com>
> +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-wmi-smbios.h>
> +
> diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-smbios.c
> index 5d793b012e5e..4174afbade13 100644
> --- a/drivers/platform/x86/dell-smbios.c
> +++ b/drivers/platform/x86/dell-smbios.c
> @@ -24,6 +24,7 @@
> #include <linux/slab.h>
> #include <linux/io.h>
> #include <linux/wmi.h>
> +#include <linux/uaccess.h>
> #include "dell-smbios.h"
>
> #ifdef CONFIG_DCDBAS
> @@ -41,8 +42,9 @@ struct calling_interface_structure {
> struct calling_interface_token tokens[];
> } __packed;
>
> -static void *buffer;
> -static size_t bufferlen;
> +static void *internal_buffer;
> +static size_t internal_bufferlen;
A large portion of this changeset is dedicated to renaming these two variables,
but it isn't clear why, and not mentioned in the changelog. Seems like
unnecessary churn. Or if we really should rename it... can it be done earlier in
the series when we're working with those buffers for functional reasons?
--
Darren Hart
VMware Open Source Technology Center
[toc] | [prev] | [next] | [standalone]
| From | <Mario.Limonciello@dell.com> |
|---|---|
| Date | 2017-09-30 21:50 +0200 |
| Subject | RE: [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace |
| Message-ID | <uvvVU-8vi-9@gated-at.bofh.it> |
| In reply to | #1742451 |
> -----Original Message-----
> From: Darren Hart [mailto:dvhart@infradead.org]
> Sent: Friday, September 29, 2017 9:06 PM
> To: Limonciello, Mario <Mario_Limonciello@Dell.com>
> Cc: Andy Shevchenko <andy.shevchenko@gmail.com>; LKML <linux-
> kernel@vger.kernel.org>; platform-driver-x86@vger.kernel.org; Andy Lutomirski
> <luto@kernel.org>; quasisec@google.com; pali.rohar@gmail.com
> Subject: Re: [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character
> device for userspace
>
> On Wed, Sep 27, 2017 at 11:02:17PM -0500, Mario Limonciello wrote:
> > This userspace character device will be used to perform SMBIOS calls
> > from any applications.
> >
> > It provides an ioctl that will allow passing the 32k 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.
> >
> > 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.
> >
> > The character device will only be created if the WMI interface was
> > found.
> >
> > The API for interacting with this interface is defined in documentation
> > as well as a uapi header provides the format of the structures.
> >
> > Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
> > ---
> > Documentation/ABI/testing/dell-wmi-smbios | 11 ++++
> > drivers/platform/x86/dell-smbios.c | 100 ++++++++++++++++++++++++---
> ---
> > drivers/platform/x86/dell-smbios.h | 19 +-----
> > include/uapi/linux/dell-wmi-smbios.h | 30 +++++++++
> > 4 files changed, 124 insertions(+), 36 deletions(-)
> > create mode 100644 Documentation/ABI/testing/dell-wmi-smbios
> > create mode 100644 include/uapi/linux/dell-wmi-smbios.h
> >
> > diff --git a/Documentation/ABI/testing/dell-wmi-smbios
> b/Documentation/ABI/testing/dell-wmi-smbios
> > new file mode 100644
> > index 000000000000..0a4200688cb0
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/dell-wmi-smbios
> > @@ -0,0 +1,11 @@
> > +What: /dev/wmi-dell-wmi-smbios
>
> /dev/wmi/dell-smbios
>
> > +Date: October 2017
> > +KernelVersion: 4.15
> > +Contact: "Mario Limonciello" <mario.limonciello@dell.com>
> > +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-wmi-smbios.h>
> > +
> > diff --git a/drivers/platform/x86/dell-smbios.c b/drivers/platform/x86/dell-
> smbios.c
> > index 5d793b012e5e..4174afbade13 100644
> > --- a/drivers/platform/x86/dell-smbios.c
> > +++ b/drivers/platform/x86/dell-smbios.c
> > @@ -24,6 +24,7 @@
> > #include <linux/slab.h>
> > #include <linux/io.h>
> > #include <linux/wmi.h>
> > +#include <linux/uaccess.h>
> > #include "dell-smbios.h"
> >
> > #ifdef CONFIG_DCDBAS
> > @@ -41,8 +42,9 @@ struct calling_interface_structure {
> > struct calling_interface_token tokens[];
> > } __packed;
> >
> > -static void *buffer;
> > -static size_t bufferlen;
> > +static void *internal_buffer;
> > +static size_t internal_bufferlen;
>
> A large portion of this changeset is dedicated to renaming these two variables,
> but it isn't clear why, and not mentioned in the changelog. Seems like
> unnecessary churn. Or if we really should rename it... can it be done earlier in
> the series when we're working with those buffers for functional reasons?
>
So the main reason for renaming was to make it easier to distinguish between
the character device buffer and internal buffer. With my current (in process)
change it's much easier to distinguish. I'll drop the renaming.
[toc] | [prev] | [next] | [standalone]
| From | Darren Hart <dvhart@infradead.org> |
|---|---|
| Date | 2017-09-30 04:20 +0200 |
| Message-ID | <uvfxN-6jP-13@gated-at.bofh.it> |
| In reply to | #1741159 |
On Wed, Sep 27, 2017 at 11:02:12PM -0500, Mario Limonciello wrote: > 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 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. > Mario, Looking pretty good in general. My biggest concern is around the dell-smbios.c "buffer" logic which is starting to look really hacked together as it tries to deal with the existing interface and the new WMI interface. Really seems like we should be able to introduce one level of abstraction that would clean it up. If not - can you explain your rationale in that patch? My other concern is the freeform structure around creating the file operations in each driver for the chardev IOCTL. It seems like we need some kind of defined mapping from METHOD index to IOCTL number, or else some way to advertise what it is? -- Darren Hart VMware Open Source Technology Center
[toc] | [prev] | [next] | [standalone]
| From | <Mario.Limonciello@dell.com> |
|---|---|
| Date | 2017-09-30 22:00 +0200 |
| Message-ID | <uvw5B-83-15@gated-at.bofh.it> |
| In reply to | #1742454 |
> -----Original Message----- > From: Darren Hart [mailto:dvhart@infradead.org] > Sent: Friday, September 29, 2017 9:17 PM > To: Limonciello, Mario <Mario_Limonciello@Dell.com> > Cc: Andy Shevchenko <andy.shevchenko@gmail.com>; LKML <linux- > kernel@vger.kernel.org>; platform-driver-x86@vger.kernel.org; Andy Lutomirski > <luto@kernel.org>; quasisec@google.com; pali.rohar@gmail.com > Subject: Re: [PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI > > On Wed, Sep 27, 2017 at 11:02:12PM -0500, Mario Limonciello wrote: > > 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 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. > > > > Mario, > > Looking pretty good in general. Darren, Thanks. > > My biggest concern is around the dell-smbios.c "buffer" logic which is > starting to look really hacked together as it tries to deal with the > existing interface and the new WMI interface. Really seems like we > should be able to introduce one level of abstraction that would clean it > up. If not - can you explain your rationale in that patch? > I've got some changes that I'm working out issues with still that do it like one of Pali's proposals. It creates the WMI buffer associated to the WMI device in a private memory structure. Then the WMI remove function will be responsible to clean it up. So on unload no if/else magic. During initialization I am reading a different flag from SMBIOS tables to tell if we'll support WMI or not even if the WMI device hasn't yet been enumerated. This approach will allow unbinding and rebinding WMI without causing problems. Does that sound better? If not, can you please give me some more direction on what you mean by one level of abstraction? The "decision" of which to handle will have to live somewhere so there's going to have to be some if/else logic to know which way to go even if you abstract further up. > My other concern is the freeform structure around creating the file > operations in each driver for the chardev IOCTL. It seems like we need > some kind of defined mapping from METHOD index to IOCTL number, or else > some way to advertise what it is? > I was originally thinking it would be a good way to do this cleanly too, but my main concern is this one character device may handle multiple methods problem. If you map method instance (index) to ioctl number you will most likely run into clashes. So maybe it's worth not allowing that? So I've got another idea. How about instead of a variety of freeform ioctl per driver, provide three ioctl functions for all the character devices that come in through the WMI bus to use (say IOC 'W') with either read, write or write/read. The WMI bus should be able to know which driver to pass it on to by the character device used. That example I mentioned the one character device for a driver with 3 different GUIDs that could contain methods would require then splitting it up into say 3 different drivers with 3 different character devices. Otherwise this might still require some creative thinking.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web