Messages in this thread | | | From | "Rafael J. Wysocki" <> | Date | Thu, 14 Jul 2022 20:48:44 +0200 | Subject | Re: [PATCH v2 3/4] PM: hibernate: allow wait_for_device_probe() to timeout when resuming from hibernation |
| |
On Tue, Jul 12, 2022 at 3:52 AM Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> wrote: > > On 2022/07/12 3:14, Rafael J. Wysocki wrote: > > On Mon, Jul 11, 2022 at 1:21 PM Tetsuo Handa > > <penguin-kernel@i-love.sakura.ne.jp> wrote: > >> > >> On 2022/07/11 17:12, Greg KH wrote: > >>> creating a > >>> locking loop like this should be resolved first, > >> > >> Rafael and Arjan, can we agree with removing wait_for_device_probe() from snapshot_open() ? > > > > No, we can't. > > Then, can we defer wait_for_device_probe() till first write()/ioctl() > which is called without locks?
Yes, wait_for_device_probe() can be deferred to right before the first actual access.
> kernel/power/user.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/kernel/power/user.c b/kernel/power/user.c > index a00a728ddfc1..92aecb989c76 100644 > --- a/kernel/power/user.c > +++ b/kernel/power/user.c > @@ -26,6 +26,7 @@ > > #include "power.h" > > +static bool need_wait; > > static struct snapshot_data { > struct snapshot_handle handle; > @@ -78,7 +79,7 @@ static int snapshot_open(struct inode *inode, struct file *filp) > * Resuming. We may need to wait for the image device to > * appear. > */ > - wait_for_device_probe(); > + need_wait = true; > > data->swap = -1; > data->mode = O_WRONLY; > @@ -168,6 +169,11 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf, > ssize_t res; > loff_t pg_offp = *offp & ~PAGE_MASK; > > + if (need_wait) { > + wait_for_device_probe(); > + need_wait = false; > + } > + > lock_system_sleep(); > > data = filp->private_data; > @@ -244,6 +250,11 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd, > loff_t size; > sector_t offset; > > + if (need_wait) { > + wait_for_device_probe(); > + need_wait = false; > + } > + > if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC) > return -ENOTTY; > if (_IOC_NR(cmd) > SNAPSHOT_IOC_MAXNR) > -- > 2.18.4
| |