mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Luke D. Jones" <luke@ljones.dev>
Cc: corentin.chary@gmail.com, acpi4asus-user@lists.sourceforge.net,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	markgross@kernel.org, jdelvare@suse.com, linux@roeck-us.net
Subject: Re: [PATCH v2 6/8] platform/x86: asus-wmi: add safety checks to gpu switching
Date: Wed, 12 Jul 2023 16:47:28 +0200	[thread overview]
Message-ID: <7ad305d4-3acb-1447-bdbe-077c83972978@redhat.com> (raw)
In-Reply-To: <20230630053552.976579-7-luke@ljones.dev>

Hi,

On 6/30/23 07:35, Luke D. Jones wrote:
> Add safety checking to dgpu_disable, egpu_enable, gpu_mux_mode.
> 
> These checks prevent users from doing such things as:
> - disabling the dGPU while is muxed to drive the internal screen
> - enabling the eGPU which also disables the dGPU, while muxed to
>   the internal screen
> - switching the MUX to dGPU while the dGPU is disabled
> 
> Signed-off-by: Luke D. Jones <luke@ljones.dev>
> ---
>  drivers/platform/x86/asus-wmi.c | 50 ++++++++++++++++++++++++++++++++-
>  1 file changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 821addb284d7..602426a7fb41 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -645,6 +645,18 @@ static ssize_t dgpu_disable_store(struct device *dev,
>  	if (disable > 1)
>  		return -EINVAL;
>  
> +	if (asus->gpu_mux_mode_available) {
> +		result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX);
> +		if (result < 0)
> +			/* An error here may signal greater failure of GPU handling */
> +			return result;
> +		if (!result && disable) {
> +			err = -ENODEV;
> +			pr_warn("Can not disable dGPU when the MUX is in dGPU mode: %d\n", err);
> +			return err;
> +		}
> +	}
> +
>  	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, disable, &result);
>  	if (err) {
>  		pr_warn("Failed to set dgpu disable: %d\n", err);
> @@ -693,7 +705,7 @@ static ssize_t egpu_enable_store(struct device *dev,
>  	if (enable > 1)
>  		return -EINVAL;
>  
> -	err = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED);
> +	result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED);
>  	if (err < 0)
>  		return err;
>  	if (err < 1) {

This seems like a stray and undesired change. I'll drop this err -> result change
when merging this.

Otherwise looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans





> @@ -702,6 +714,18 @@ static ssize_t egpu_enable_store(struct device *dev,
>  		return err;
>  	}
>  
> +	if (asus->gpu_mux_mode_available) {
> +		result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX);
> +		if (result < 0)
> +			/* An error here may signal greater failure of GPU handling */
> +			return result;
> +		if (!result && enable) {
> +			err = -ENODEV;
> +			pr_warn("Can not enable eGPU when the MUX is in dGPU mode: %d\n", err);
> +			return err;
> +		}
> +	}
> +
>  	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result);
>  	if (err) {
>  		pr_warn("Failed to set egpu disable: %d\n", err);
> @@ -764,6 +788,30 @@ static ssize_t gpu_mux_mode_store(struct device *dev,
>  	if (optimus > 1)
>  		return -EINVAL;
>  
> +	if (asus->dgpu_disable_available) {
> +		result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_DGPU);
> +		if (result < 0)
> +			/* An error here may signal greater failure of GPU handling */
> +			return result;
> +		if (result && !optimus) {
> +			err = -ENODEV;
> +			pr_warn("Can not switch MUX to dGPU mode when dGPU is disabled: %d\n", err);
> +			return err;
> +		}
> +	}
> +
> +	if (asus->egpu_enable_available) {
> +		result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU);
> +		if (result < 0)
> +			/* An error here may signal greater failure of GPU handling */
> +			return result;
> +		if (result && !optimus) {
> +			err = -ENODEV;
> +			pr_warn("Can not switch MUX to dGPU mode when eGPU is enabled: %d\n", err);
> +			return err;
> +		}
> +	}
> +
>  	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_GPU_MUX, optimus, &result);
>  	if (err) {
>  		dev_err(dev, "Failed to set GPU MUX mode: %d\n", err);


  reply	other threads:[~2023-07-12 14:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30  5:35 [PATCH v2 0/8] platform/x86: asus-wmi: Luke D. Jones
2023-06-30  5:35 ` [PATCH v2 1/8] platform/x86: asus-wmi: add support for showing charger mode Luke D. Jones
2023-07-04 11:33   ` Hans de Goede
2023-06-30  5:35 ` [PATCH v2 2/8] platform/x86: asus-wmi: add support for showing middle fan RPM Luke D. Jones
2023-07-04 11:33   ` Hans de Goede
2023-06-30  5:35 ` [PATCH v2 3/8] platform/x86: asus-wmi: support middle fan custom curves Luke D. Jones
2023-07-04 11:34   ` Hans de Goede
2023-06-30  5:35 ` [PATCH v2 4/8] platform/x86: asus-wmi: add WMI method to show if egpu connected Luke D. Jones
2023-07-12 14:43   ` Hans de Goede
2023-06-30  5:35 ` [PATCH v2 5/8] platform/x86: asus-wmi: don't allow eGPU switching if eGPU not connected Luke D. Jones
2023-07-12 14:43   ` Hans de Goede
2023-06-30  5:35 ` [PATCH v2 6/8] platform/x86: asus-wmi: add safety checks to gpu switching Luke D. Jones
2023-07-12 14:47   ` Hans de Goede [this message]
2023-06-30  5:35 ` [PATCH v2 7/8] platform/x86: asus-wmi: support setting mini-LED mode Luke D. Jones
2023-07-12 14:48   ` Hans de Goede
2023-06-30  5:35 ` [PATCH v2 8/8] platform/x86: asus-wmi: expose dGPU and CPU tunables for ROG Luke D. Jones
2023-07-11  9:55   ` kernel test robot
2023-07-12 14:57   ` Hans de Goede
2023-07-12 15:18 ` [PATCH v2 0/8] platform/x86: asus-wmi: Hans de Goede

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=7ad305d4-3acb-1447-bdbe-077c83972978@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=acpi4asus-user@lists.sourceforge.net \
    --cc=corentin.chary@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=luke@ljones.dev \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®