All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Resolve WMI query failures on some devices
@ 2022-06-07 20:43 Jorge Lopez
  2022-06-08 11:02 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Jorge Lopez @ 2022-06-07 20:43 UTC (permalink / raw)
  To: platform-driver-x86

WMI queries fail on some devices where the ACPI method HWMC
unconditionally attempts to create Fields beyond the buffer
if the buffer is too small, this breaks essential features
such as power profiles:

         CreateByteField (Arg1, 0x10, D008)
         CreateByteField (Arg1, 0x11, D009)
         CreateByteField (Arg1, 0x12, D010)
         CreateDWordField (Arg1, 0x10, D032)
         CreateField (Arg1, 0x80, 0x0400, D128)

In cases where args->data had zero length, ACPI BIOS Error
(bug): AE_AML_BUFFER_LIMIT, Field [D008] at bit
offset/length 128/8 exceeds size of target Buffer (128 bits)
(20211217/dsopcode-198) was obtained.

ACPI BIOS Error (bug): AE_AML_BUFFER_LIMIT, Field [D009] at bit
offset/length 136/8 exceeds size of target Buffer (136bits)
(20211217/dsopcode-198)

The original code created a buffer size of 128 bytes regardless if
the WMI call required a smaller buffer or not.  This particular
behavior occurs in older BIOS and reproduced in OMEN laptops.  Newer
BIOS handles buffer sizes properly and meets the latest specification
requirements.  This is the reason why testing with a dynamically
allocated buffer did not uncover any failures with the test systems at
hand.

This patch was tested on several OMEN, Elite, and Zbooks.  It was
confirmed the patch resolves HPWMI_FAN GET/SET calls in an OMEN
Laptop 15-ek0xxx.  No problems were reported when testing on several Elite
and Zbooks notebooks.

Signed-off-by: Jorge Lopez <jorge.lopez2@hp.com>

---
Based on the latest platform-drivers-x86.git/for-next
---
 drivers/platform/x86/hp-wmi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 0e9a25b56e0e..7bcfa07cc6ab 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -292,12 +292,14 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
 	struct bios_args *args = NULL;
 	int mid, actual_outsize, ret;
 	size_t bios_args_size;
+	int actual_insize;
 
 	mid = encode_outsize_for_pvsz(outsize);
 	if (WARN_ON(mid < 0))
 		return mid;
 
-	bios_args_size = struct_size(args, data, insize);
+	actual_insize = max(insize, 128);
+	bios_args_size = struct_size(args, data, actual_insize);
 	args = kmalloc(bios_args_size, GFP_KERNEL);
 	if (!args)
 		return -ENOMEM;
-- 
2.25.1


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

* Re: [PATCH] Resolve WMI query failures on some devices
  2022-06-07 20:43 [PATCH] Resolve WMI query failures on some devices Jorge Lopez
@ 2022-06-08 11:02 ` Andy Shevchenko
  2022-06-08 11:06   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2022-06-08 11:02 UTC (permalink / raw)
  To: Jorge Lopez; +Cc: Platform Driver

On Wed, Jun 8, 2022 at 8:06 AM Jorge Lopez <jorgealtxwork@gmail.com> wrote:
>
> WMI queries fail on some devices where the ACPI method HWMC
> unconditionally attempts to create Fields beyond the buffer
> if the buffer is too small, this breaks essential features
> such as power profiles:
>
>          CreateByteField (Arg1, 0x10, D008)
>          CreateByteField (Arg1, 0x11, D009)
>          CreateByteField (Arg1, 0x12, D010)
>          CreateDWordField (Arg1, 0x10, D032)
>          CreateField (Arg1, 0x80, 0x0400, D128)
>
> In cases where args->data had zero length, ACPI BIOS Error
> (bug): AE_AML_BUFFER_LIMIT, Field [D008] at bit
> offset/length 128/8 exceeds size of target Buffer (128 bits)
> (20211217/dsopcode-198) was obtained.
>
> ACPI BIOS Error (bug): AE_AML_BUFFER_LIMIT, Field [D009] at bit
> offset/length 136/8 exceeds size of target Buffer (136bits)
> (20211217/dsopcode-198)
>
> The original code created a buffer size of 128 bytes regardless if
> the WMI call required a smaller buffer or not.  This particular
> behavior occurs in older BIOS and reproduced in OMEN laptops.  Newer
> BIOS handles buffer sizes properly and meets the latest specification
> requirements.  This is the reason why testing with a dynamically
> allocated buffer did not uncover any failures with the test systems at
> hand.
>
> This patch was tested on several OMEN, Elite, and Zbooks.  It was
> confirmed the patch resolves HPWMI_FAN GET/SET calls in an OMEN
> Laptop 15-ek0xxx.  No problems were reported when testing on several Elite
> and Zbooks notebooks.

I am in general fine with the change, only a nit-pick below.
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Jorge Lopez <jorge.lopez2@hp.com>
>
> ---
> Based on the latest platform-drivers-x86.git/for-next
> ---
>  drivers/platform/x86/hp-wmi.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
> index 0e9a25b56e0e..7bcfa07cc6ab 100644
> --- a/drivers/platform/x86/hp-wmi.c
> +++ b/drivers/platform/x86/hp-wmi.c
> @@ -292,12 +292,14 @@ static int hp_wmi_perform_query(int query, enum hp_wmi_command command,
>         struct bios_args *args = NULL;
>         int mid, actual_outsize, ret;
>         size_t bios_args_size;
> +       int actual_insize;

We already have above similar variables, I would either put like this

         int mid, actual_inzise, actual_outsize, ret;

or this (my personal preference):

         int mid, actual_insize, actual_outsize;
         ...
         int ret;

>         mid = encode_outsize_for_pvsz(outsize);
>         if (WARN_ON(mid < 0))
>                 return mid;
>
> -       bios_args_size = struct_size(args, data, insize);
> +       actual_insize = max(insize, 128);
> +       bios_args_size = struct_size(args, data, actual_insize);
>         args = kmalloc(bios_args_size, GFP_KERNEL);
>         if (!args)
>                 return -ENOMEM;
> --
> 2.25.1
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] Resolve WMI query failures on some devices
  2022-06-08 11:02 ` Andy Shevchenko
@ 2022-06-08 11:06   ` Andy Shevchenko
  2022-06-08 15:25     ` Jorge Lopez
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2022-06-08 11:06 UTC (permalink / raw)
  To: Jorge Lopez; +Cc: Platform Driver

On Wed, Jun 8, 2022 at 1:02 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Wed, Jun 8, 2022 at 8:06 AM Jorge Lopez <jorgealtxwork@gmail.com> wrote:

...

> I am in general fine with the change, only a nit-pick below.
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

...and do not forget to include maintainers and other parties who
might be interested in this change. I can recommend to utilize my
"smart" [1] script for that.

[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] Resolve WMI query failures on some devices
  2022-06-08 11:06   ` Andy Shevchenko
@ 2022-06-08 15:25     ` Jorge Lopez
  0 siblings, 0 replies; 4+ messages in thread
From: Jorge Lopez @ 2022-06-08 15:25 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Platform Driver

Thanks, I'll check it out.

On Wed, Jun 8, 2022 at 6:07 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Wed, Jun 8, 2022 at 1:02 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Wed, Jun 8, 2022 at 8:06 AM Jorge Lopez <jorgealtxwork@gmail.com> wrote:
>
> ...
>
> > I am in general fine with the change, only a nit-pick below.
> > Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>
> ...and do not forget to include maintainers and other parties who
> might be interested in this change. I can recommend to utilize my
> "smart" [1] script for that.
>
> [1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh
>
> --
> With Best Regards,
> Andy Shevchenko

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

end of thread, other threads:[~2022-06-08 15:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 20:43 [PATCH] Resolve WMI query failures on some devices Jorge Lopez
2022-06-08 11:02 ` Andy Shevchenko
2022-06-08 11:06   ` Andy Shevchenko
2022-06-08 15:25     ` Jorge Lopez

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.