All of lore.kernel.org
 help / color / mirror / Atom feed
From: Darren Hart <dvhart@infradead.org>
To: Mario Limonciello <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 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface
Date: Fri, 29 Sep 2017 17:51:27 -0700	[thread overview]
Message-ID: <20170930005127.GA13307@fury> (raw)
In-Reply-To: <7b632baafbfdc6c55c4d56225c54fd441b747286.1506571188.git.mario.limonciello@dell.com>

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

  parent reply	other threads:[~2017-09-30  0:51 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-28  4:02 [PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI Mario Limonciello
2017-09-28  4:02 ` [PATCH v3 1/8] platform/x86: wmi: Add new method wmidev_evaluate_method Mario Limonciello
2017-09-28  4:02 ` [PATCH v3 2/8] platform/x86: dell-smbios: Introduce a WMI-ACPI interface Mario Limonciello
2017-09-28  6:53   ` Pali Rohár
2017-09-28 22:43     ` Mario.Limonciello
2017-09-28 22:43       ` Mario.Limonciello
2017-09-29  7:35       ` Pali Rohár
2017-09-30 20:01         ` Mario.Limonciello
2017-09-30 20:01           ` Mario.Limonciello
2017-09-30 21:06           ` Pali Rohár
2017-09-30  0:51   ` Darren Hart [this message]
2017-09-30  7:15     ` Pali Rohár
2017-09-30 19:56       ` Mario.Limonciello
2017-09-30 19:56         ` Mario.Limonciello
2017-09-28  4:02 ` [PATCH v3 3/8] platform/x86: dell-wmi-smbios: Use Dell WMI descriptor check Mario Limonciello
2017-09-30  1:29   ` Darren Hart
2017-09-30 19:48     ` Mario.Limonciello
2017-09-30 19:48       ` Mario.Limonciello
2017-09-30 20:01       ` Pali Rohár
2017-10-02 14:15         ` Mario.Limonciello
2017-10-02 14:15           ` Mario.Limonciello
2017-10-02 14:37           ` Pali Rohár
2017-10-01  8:43     ` Andy Shevchenko
2017-09-28  4:02 ` [PATCH v3 4/8] platform/x86: wmi: create character devices when requested by drivers Mario Limonciello
2017-09-30  1:52   ` Darren Hart
2017-09-30  8:12     ` Greg Kroah-Hartman
2017-09-30 19:26       ` Mario.Limonciello
2017-09-30 19:26         ` Mario.Limonciello
2017-10-01 13:23         ` Greg KH
2017-10-01 14:25           ` Mario.Limonciello
2017-10-01 14:25             ` Mario.Limonciello
2017-10-01 18:03             ` Greg KH
2017-10-02  0:57       ` Darren Hart
2017-10-02  9:24         ` Greg Kroah-Hartman
2017-10-02 14:33           ` Darren Hart
2017-10-03  9:23   ` Greg KH
2017-10-03 15:09     ` Mario.Limonciello
2017-10-03 15:09       ` Mario.Limonciello
2017-10-03 15:10     ` Darren Hart
2017-10-03 16:48       ` Andy Lutomirski
2017-10-03 17:46         ` Greg KH
2017-10-03 18:38         ` Mario.Limonciello
2017-10-03 18:38           ` Mario.Limonciello
2017-10-03 19:31           ` Andy Lutomirski
2017-10-03  9:23   ` Greg KH
2017-10-03 15:13     ` Mario.Limonciello
2017-10-03 15:13       ` Mario.Limonciello
2017-09-28  4:02 ` [PATCH v3 5/8] platform/x86: dell-wmi-smbios: introduce character device for userspace Mario Limonciello
2017-09-30  2:06   ` Darren Hart
2017-09-30 19:45     ` Mario.Limonciello
2017-09-30 19:45       ` Mario.Limonciello
2017-10-03  9:26   ` Greg KH
2017-10-03 15:09     ` Mario.Limonciello
2017-10-03 15:09       ` Mario.Limonciello
2017-10-03 15:20     ` Darren Hart
2017-10-03 15:49       ` Mario.Limonciello
2017-10-03 15:49         ` Mario.Limonciello
2017-10-05  0:02         ` Darren Hart
2017-10-05 15:10           ` Mario.Limonciello
2017-10-05 15:10             ` Mario.Limonciello
2017-09-28  4:02 ` [PATCH v3 6/8] platform/x86: dell-wmi-smbios: Add a sysfs interface for SMBIOS tokens Mario Limonciello
2017-09-30  2:10   ` Darren Hart
2017-10-01  8:51     ` Andy Shevchenko
2017-09-28  4:02 ` [PATCH v3 7/8] platform/x86: Kconfig: Change the default settings for dell-wmi-smbios Mario Limonciello
2017-09-28  4:02 ` [PATCH v3 8/8] platform/x86: dell-wmi-smbios: clean up wmi descriptor check Mario Limonciello
2017-10-02 13:15   ` Andy Shevchenko
2017-10-02 13:26     ` Mario.Limonciello
2017-10-02 13:26       ` Mario.Limonciello
2017-09-30  2:16 ` [PATCH v3 0/8] Introduce support for Dell SMBIOS over WMI Darren Hart
2017-09-30 19:56   ` Mario.Limonciello
2017-09-30 19:56     ` Mario.Limonciello
2017-10-05  2:44     ` Darren Hart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170930005127.GA13307@fury \
    --to=dvhart@infradead.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mario.limonciello@dell.com \
    --cc=pali.rohar@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=quasisec@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.