dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Takashi Iwai <tiwai@suse.de>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 05/15] vga_switcheroo: Drop client power state VGA_SWITCHEROO_INIT
Date: Sun, 25 Oct 2015 19:19:53 +0100	[thread overview]
Message-ID: <20151025181953.GA19646@wunner.de> (raw)
In-Reply-To: <20151002082248.GH3383@phenom.ffwll.local>

Hi Takashi,

gentle ping -- could you take a look at the patch below,
would this change be okay with you?

hda_intel.c:check_hdmi_disabled() is the sole caller of
vga_switcheroo_get_client_state() and only checks for the
return value VGA_SWITCHEROO_OFF, not for VGA_SWITCHEROO_INIT.

So why was VGA_SWITCHEROO_INIT introduced in the first place?
The only explanation I can think of is that for some reason you
wanted to *avoid* returning VGA_SWITCHEROO_OFF (even if the card
is in fact asleep) if no second GPU or no handler have registered
with vga_switcheroo. But as shown in the scenario below, this can
actually go awry.

With VGA_SWITCHEROO_INIT apparently not having a purpose but on the
other hand being harmful, I suggest to drop it with the patch below.

For the meaning of the vga_switcheroo power states, refer to
vga_switcheroo.h in drm-next:
http://cgit.freedesktop.org/~airlied/linux/tree/include/linux/vga_switcheroo.h?h=drm-next#n38

Thanks & best regards,

Lukas

On Fri, Oct 02, 2015 at 10:22:48AM +0200, Daniel Vetter wrote:
> On Tue, Sep 08, 2015 at 02:17:47PM +0200, Lukas Wunner wrote:
> > hda_intel.c:azx_probe() defers initialization of an audio controller
> > on the discrete GPU if the GPU is powered off. The power state of the
> > GPU is determined by calling vga_switcheroo_get_client_state().
> > 
> > vga_switcheroo_get_client_state() returns VGA_SWITCHEROO_INIT if
> > vga_switcheroo is not enabled, i.e. if no second GPU or no handler
> > has registered.
> > 
> > This can go wrong in the following scenario:
> > - Driver for the integrated GPU is not loaded.
> > - Driver for the discrete GPU registers with vga_switcheroo, uses driver
> >   power control to power down the GPU, handler cuts power to the GPU.
> > - Driver for the audio controller gets loaded after the GPU was powered
> >   down, calls vga_switcheroo_get_client_state() which returns
> >   VGA_SWITCHEROO_INIT instead of VGA_SWITCHEROO_OFF.
> > - Consequence: azx_probe() tries to initialize the audio controller even
> >   though the GPU is powered down.
> > 
> > The power state VGA_SWITCHEROO_INIT was introduced by c8e9cf7bb240
> > ("vga_switcheroo: Add a helper function to get the client state").
> > It is not apparent what its benefit might be. The idea seems to
> > be to initialize the audio controller even if the power state is
> > VGA_SWITCHEROO_OFF (were vga_switcheroo enabled), but as shown
> > above this can fail.
> > 
> > Drop VGA_SWITCHEROO_INIT to solve this.
> > 
> > Cc: Takashi Iwai <tiwai@suse.de>
> > Signed-off-by: Lukas Wunner <lukas@wunner.de>
> 
> Takashi, does this look good to you? Ack for merging through drm-misc?
> 
> I pulled in patch 4 meanwhile.
> -Daniel
> 
> > ---
> >  drivers/gpu/vga/vga_switcheroo.c | 2 --
> >  include/linux/vga_switcheroo.h   | 5 -----
> >  2 files changed, 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
> > index 2138162..845e47d 100644
> > --- a/drivers/gpu/vga/vga_switcheroo.c
> > +++ b/drivers/gpu/vga/vga_switcheroo.c
> > @@ -355,8 +355,6 @@ int vga_switcheroo_get_client_state(struct pci_dev *pdev)
> >  	client = find_client_from_pci(&vgasr_priv.clients, pdev);
> >  	if (!client)
> >  		ret = VGA_SWITCHEROO_NOT_FOUND;
> > -	else if (!vgasr_priv.active)
> > -		ret = VGA_SWITCHEROO_INIT;
> >  	else
> >  		ret = client->pwr_state;
> >  	mutex_unlock(&vgasr_mutex);
> > diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
> > index 3764991..95bfbeb0 100644
> > --- a/include/linux/vga_switcheroo.h
> > +++ b/include/linux/vga_switcheroo.h
> > @@ -39,10 +39,6 @@ struct pci_dev;
> >   * enum vga_switcheroo_state - client power state
> >   * @VGA_SWITCHEROO_OFF: off
> >   * @VGA_SWITCHEROO_ON: on
> > - * @VGA_SWITCHEROO_INIT: client has registered with vga_switcheroo but
> > - * 	vga_switcheroo is not enabled, i.e. no second client or no handler
> > - * 	has registered. Only used in vga_switcheroo_get_client_state() which
> > - * 	in turn is only called from hda_intel.c
> >   * @VGA_SWITCHEROO_NOT_FOUND: client has not registered with vga_switcheroo.
> >   * 	Only used in vga_switcheroo_get_client_state() which in turn is only
> >   * 	called from hda_intel.c
> > @@ -53,7 +49,6 @@ enum vga_switcheroo_state {
> >  	VGA_SWITCHEROO_OFF,
> >  	VGA_SWITCHEROO_ON,
> >  	/* below are referred only from vga_switcheroo_get_client_state() */
> > -	VGA_SWITCHEROO_INIT,
> >  	VGA_SWITCHEROO_NOT_FOUND,
> >  };
> >  
> > -- 
> > 1.8.5.2 (Apple Git-48)
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2015-10-25 18:19 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 13:18 [PATCH 01/15] vga_switcheroo: Document _ALL_ the things! Lukas Wunner
2015-08-29 12:29 ` [PATCH 02/15] DocBook: Add vga_switcheroo Subsystem Guide Lukas Wunner
2015-08-27 14:43   ` [PATCH 03/15] vga_switcheroo: Set active attribute to false for audio clients Lukas Wunner
2015-08-23 21:23     ` [PATCH 04/15] vga_switcheroo: Add missing locking Lukas Wunner
2015-09-08 12:17       ` [PATCH 05/15] vga_switcheroo: Drop client power state VGA_SWITCHEROO_INIT Lukas Wunner
2015-08-28  9:56         ` [PATCH 06/15] vga_switcheroo: Use enum vga_switcheroo_state instead of int Lukas Wunner
2015-08-28 11:30           ` [PATCH 07/15] vga_switcheroo: Use VGA_SWITCHEROO_UNKNOWN_ID instead of -1 Lukas Wunner
2015-08-28 10:54             ` [PATCH 08/15] vga_switcheroo: Use enum vga_switcheroo_client_id instead of int Lukas Wunner
2015-09-05 11:40               ` [PATCH 09/15] vga_switcheroo: Sort headers alphabetically Lukas Wunner
2015-09-04 18:49                 ` [PATCH 10/15] ALSA: hda - Spell vga_switcheroo consistently Lukas Wunner
2015-09-04 19:06                   ` [PATCH 11/15] drm/i915: " Lukas Wunner
2015-09-05  9:09                     ` [PATCH 12/15] drm/nouveau: " Lukas Wunner
2015-09-05  9:14                       ` [PATCH 13/15] drm/radeon: " Lukas Wunner
2015-09-05  9:17                         ` [PATCH 14/15] drm/amdgpu: " Lukas Wunner
2015-09-05  9:22                           ` [PATCH 15/15] drm: " Lukas Wunner
2015-09-22  9:20                             ` Daniel Vetter
2015-09-23 21:45                           ` [PATCH 14/15] drm/amdgpu: " Alex Deucher
2015-09-22  9:20                     ` [PATCH 11/15] drm/i915: " Daniel Vetter
2015-10-02  7:35           ` [PATCH 06/15] vga_switcheroo: Use enum vga_switcheroo_state instead of int Jani Nikula
2015-10-02  8:22         ` [PATCH 05/15] vga_switcheroo: Drop client power state VGA_SWITCHEROO_INIT Daniel Vetter
2015-10-25 18:19           ` Lukas Wunner [this message]
2015-10-26  7:24             ` Takashi Iwai
2015-08-27 14:43     ` [PATCH v1.1 03/15] vga_switcheroo: Set active attribute to false for audio clients Lukas Wunner
2015-09-23  7:13       ` Daniel Vetter
2015-09-24  9:40         ` Takashi Iwai
2015-09-24 15:13           ` Daniel Vetter
2015-10-01 16:19             ` Lukas Wunner
2015-09-24  9:37       ` Takashi Iwai
2015-09-17 17:15     ` [PATCH " Lukas Wunner
2015-09-22  9:17       ` Daniel Vetter
2015-09-19 16:44     ` Takashi Iwai
2015-09-19 17:50       ` Lukas Wunner
2015-09-24  9:39         ` Takashi Iwai
2015-09-22  8:38   ` [PATCH 02/15] DocBook: Add vga_switcheroo Subsystem Guide Daniel Vetter
2015-09-17 16:34 ` [PATCH 01/15] vga_switcheroo: Document _ALL_ the things! Danilo Cesar Lemes de Paula
2015-09-17 17:31   ` Lukas Wunner
2015-09-17 17:56     ` Danilo Cesar Lemes de Paula

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=20151025181953.GA19646@wunner.de \
    --to=lukas@wunner.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tiwai@suse.de \
    /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