From: Lukas Wunner <lukas-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
To: Lyude Paul <lyude-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
David Airlie <airlied-cv59FeDIM0c@public.gmane.org>,
nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
Ben Skeggs <bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH 1/5] drm/nouveau: Prevent RPM callback recursion in suspend/resume paths
Date: Tue, 17 Jul 2018 20:20:41 +0200 [thread overview]
Message-ID: <20180717182041.GA18363@wunner.de> (raw)
In-Reply-To: <d7c25a7f41df70685c0c4726315592d1d9b561ff.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
On Tue, Jul 17, 2018 at 12:53:11PM -0400, Lyude Paul wrote:
> On Tue, 2018-07-17 at 09:16 +0200, Lukas Wunner wrote:
> > On Mon, Jul 16, 2018 at 07:59:25PM -0400, Lyude Paul wrote:
> > > In order to fix all of the spots that need to have runtime PM get/puts()
> > > added, we need to ensure that it's possible for us to call
> > > pm_runtime_get/put() in any context, regardless of how deep, since
> > > almost all of the spots that are currently missing refs can potentially
> > > get called in the runtime suspend/resume path. Otherwise, we'll try to
> > > resume the GPU as we're trying to resume the GPU (and vice-versa) and
> > > cause the kernel to deadlock.
> > >
> > > With this, it should be safe to call the pm runtime functions in any
> > > context in nouveau with one condition: any point in the driver that
> > > calls pm_runtime_get*() cannot hold any locks owned by nouveau that
> > > would be acquired anywhere inside nouveau_pmops_runtime_resume().
> > > This includes modesetting locks, i2c bus locks, etc.
> >
> > [snip]
> > > --- a/drivers/gpu/drm/nouveau/nouveau_drm.c
> > > +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
> > > @@ -835,6 +835,8 @@ nouveau_pmops_runtime_suspend(struct device *dev)
> > > return -EBUSY;
> > > }
> > >
> > > + dev->power.disable_depth++;
> > > +
> >
> > Anyway, if I understand the commit message correctly, you're hitting a
> > pm_runtime_get_sync() in a code path that itself is called during a
> > pm_runtime_get_sync(). Could you include stack traces in the commit
> > message? My gut feeling is that this patch masks a deeper issue,
> > e.g. if the runtime_resume code path does in fact directly poll outputs,
> > that would seem wrong. Runtime resume should merely make the card
> > accessible, i.e. reinstate power if necessary, put into PCI_D0,
> > restore registers, etc. Output polling should be scheduled
> > asynchronously.
>
> So: the reason that patch was added was mainly for the patches later in the
> series that add guards around the i2c bus and aux bus, since both of those
> require that the device be awake for it to work. Currently, the spot where it
> would recurse is:
Okay, the PCI device is suspending and the nvkm_i2c_aux_acquire()
wants it in resumed state, so is waiting forever for the device to
runtime suspend in order to resume it again immediately afterwards.
The deadlock in the stack trace you've posted could be resolved using
the technique I used in d61a5c106351 by adding the following to
include/linux/pm_runtime.h:
static inline bool pm_runtime_status_suspending(struct device *dev)
{
return dev->power.runtime_status == RPM_SUSPENDING;
}
static inline bool is_pm_work(struct device *dev)
{
struct work_struct *work = current_work();
return work && work->func == dev->power.work;
}
Then adding this to nvkm_i2c_aux_acquire():
struct device *dev = pad->i2c->subdev.device->dev;
if (!(is_pm_work(dev) && pm_runtime_status_suspending(dev))) {
ret = pm_runtime_get_sync(dev);
if (ret < 0 && ret != -EACCES)
return ret;
}
But here's the catch: This only works for an *async* runtime suspend.
It doesn't work for pm_runtime_put_sync(), pm_runtime_suspend() etc,
because then the runtime suspend is executed in the context of the caller,
not in the context of dev->power.work.
So it's not a full solution, but hopefully something that gets you
going. I'm not really familiar with the code paths leading to
nvkm_i2c_aux_acquire() to come up with a full solution off the top
of my head I'm afraid.
Note, it's not sufficient to just check pm_runtime_status_suspending(dev)
because if the runtime_suspend is carried out concurrently by something
else, this will return true but it's not guaranteed that the device is
actually kept awake until the i2c communication has been fully performed.
HTH,
Lukas
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau
next prev parent reply other threads:[~2018-07-17 18:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20180716235936.11268-1-lyude@redhat.com>
[not found] ` <20180716235936.11268-2-lyude@redhat.com>
2018-07-17 7:16 ` [Nouveau] [PATCH 1/5] drm/nouveau: Prevent RPM callback recursion in suspend/resume paths Lukas Wunner
[not found] ` <20180717071641.GA5411-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2018-07-17 7:39 ` Rafael J. Wysocki
2018-07-17 16:53 ` [Nouveau] " Lyude Paul
[not found] ` <d7c25a7f41df70685c0c4726315592d1d9b561ff.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-17 18:20 ` Lukas Wunner [this message]
[not found] ` <20180717182041.GA18363-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2018-07-17 18:24 ` Lyude Paul
2018-07-17 18:32 ` [Nouveau] " Lukas Wunner
2018-07-17 18:34 ` Lyude Paul
[not found] ` <2dbe75b1a83c025b9cddc229dbca9af6fb30111e.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-18 7:40 ` Rafael J. Wysocki
2018-07-18 7:47 ` Lukas Wunner
2018-07-18 7:38 ` Rafael J. Wysocki
[not found] ` <CAJZ5v0g8O8J0U8V-gLMe+NnTd3xgZ5_pjr9p2oci7yAfW54B-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-07-18 8:25 ` Lukas Wunner
[not found] ` <20180718082505.GB16072-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2018-07-18 8:35 ` Rafael J. Wysocki
2018-07-18 8:36 ` [Nouveau] " Lukas Wunner
2018-07-18 20:11 ` Lyude Paul
[not found] ` <2724dd5eee8a1e4e523e43915fa184ad5afe1c59.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-18 21:49 ` Rafael J. Wysocki
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=20180717182041.GA18363@wunner.de \
--to=lukas-jfq808j9c/izqb+pc5nmwq@public.gmane.org \
--cc=airlied-cv59FeDIM0c@public.gmane.org \
--cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lyude-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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;
as well as URLs for NNTP newsgroup(s).