Remove process freezer from suspend to RAM pathway
Subsystems (3)
Quoted 11 lines
Spinning in the driver with the lock not held is impossible, since the driver is called with the lock already acquired.
Failing with
-ERETRYis non-transparent. I would prefer to block such requests at their source, before the lock is acquired. Perhaps in the driver core, perhaps even earlier.(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
Quoted 4 lines
You're missing the point. If the driver and the freezer are both solid, there's no reason they can't share the work. If many drivers can pass off part of their workload to the single freezer, it's a net win.
I've explained already multiple times that the freezer will not do what you guys expect it to do. IOs can be submited at non-task time and there is no clear distinction between IO generating threads that must and those that must not be frozen.
I really can't understand why you guys work so hard at trying to avoid the right solutions systematically.
Quoted 4 lines
So it isn't a question of how solid the drivers are; it's a question of how solid the freezer is. And bear in mind that if you convince people the freezer is not solid enough to be used, then you will have to find an alternative for purposes of hibernation.
Because I'm intimately convinced that the freezer is a wrong approach that cannot be made solid enough.
Quoted 3 lines
Quoted 1 line
The freezer is a flawed concept in the first place.
<... Long and cogent argument which I will skip over for now ...>
Too bad, that's where the interesting points that show that the freezer cannot work are..
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Quoted 10 lines
Quoted 7 lines
I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
What about systems with no BIOS? I think this would be very hard or even impossible to make work.
You made the same mistake I did when reading Nigel's mail ... BIOs -> Block IO requests, not BIOS :-)
Ben.
Quoted 11 lines
Spinning in the driver with the lock not held is impossible, since the driver is called with the lock already acquired.
Failing with
-ERETRYis non-transparent. I would prefer to block such requests at their source, before the lock is acquired. Perhaps in the driver core, perhaps even earlier.(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
Quoted 4 lines
You're missing the point. If the driver and the freezer are both solid, there's no reason they can't share the work. If many drivers can pass off part of their workload to the single freezer, it's a net win.
I've explained already multiple times that the freezer will not do what you guys expect it to do. IOs can be submited at non-task time and there is no clear distinction between IO generating threads that must and those that must not be frozen.
I really can't understand why you guys work so hard at trying to avoid the right solutions systematically.
Quoted 4 lines
So it isn't a question of how solid the drivers are; it's a question of how solid the freezer is. And bear in mind that if you convince people the freezer is not solid enough to be used, then you will have to find an alternative for purposes of hibernation.
Because I'm intimately convinced that the freezer is a wrong approach that cannot be made solid enough.
Quoted 3 lines
Quoted 1 line
The freezer is a flawed concept in the first place.
<... Long and cogent argument which I will skip over for now ...>
Too bad, that's where the interesting points that show that the freezer cannot work are..
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Quoted 10 lines
Quoted 7 lines
I even tend to think that we could do STD that way too, in fact, while Linus is right saying it's a different problem than STR, we could even probably re-use some of the STR infrastructure in some hackish way, still without a freezer. We could have ways to block page cache writeout, for example, to prevent new post-snapshot dirty data from hitting the platter, and use direct BIOs for writeout. That's just an example.
What about systems with no BIOS? I think this would be very hard or even impossible to make work.
You made the same mistake I did when reading Nigel's mail ... BIOs -> Block IO requests, not BIOS :-)
Ben.
Quoted 5 lines
Quoted 3 lines
Well... 2 things here. Either you have a freezer in which case the chances of the above scenario are increased,
How so? :-)
I meant you have a freezer that freezes uninterruptible tasks.
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
You misunderstood. Stop trying to incite riot, calm down, and pay attention to what I actually wrote. I'll explain it again in more explicit terms:
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Normally a waitqueue or a struct completion would be used for this purpose. But either one puts the burden on the driver of defining a data structure and signalling it at the right time. That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer). In fact, we definitely don't want to unblock plug events until this later time.
So instead, why not have the PM core take care of all this? There could be a block_task_until_suspend_is_over() routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
Does that make you happier?
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
Quoted 4 lines
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
Quoted 5 lines
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right? And we must not allow driver binding or unbinding. But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration. It has to be done at a time when no device semaphores are held.
You also agree that kernel threads and workqueues must be allowed to operate during suspend. But consider this: By writing the appropriate sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
(And rather than trying to manage a waitqueue or struct completion, it would be easiest to jump directly into the freezer! The driver or the core wouldn't have to worry about waking up all these blocked threads.)
That's wrong. The freezer is NOT a solution for that sort of thing. Just because you guys can't get your locking right.
You misunderstood. Stop trying to incite riot, calm down, and pay attention to what I actually wrote. I'll explain it again in more explicit terms:
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Normally a waitqueue or a struct completion would be used for this purpose. But either one puts the burden on the driver of defining a data structure and signalling it at the right time. That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer). In fact, we definitely don't want to unblock plug events until this later time.
So instead, why not have the PM core take care of all this? There could be a block_task_until_suspend_is_over() routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
Does that make you happier?
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Face it, we should seriously look into doing suspend/resume without a freezer.
I'm willing to try, although I think it will be a tremendous amount of work to verify that every driver does the right thing. There's lots of support missing. For example, don't you think we should block all sysfs I/O during suspend? And likewise for insmod/rmmod?
Quoted 4 lines
sysfs is a matter of driver. If a sysfs read/write callback in a driver is hitting the HW, it most certainly already has some kind of locking. That locking can/should be extended to deal with blocking when the HW is suspended.
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
Quoted 5 lines
However, since it seems that people universally consider it very hard to get right (I don't but heh), Linus and Paul have come up with a solution for most simple enough directly-mapped drivers such as PCI (ok, that doesn't include USB) which is to simply do the HW suspend in a late callback after IRQs are off, and not bother with the rest.
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right? And we must not allow driver binding or unbinding. But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration. It has to be done at a time when no device semaphores are held.
You also agree that kernel threads and workqueues must be allowed to operate during suspend. But consider this: By writing the appropriate sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Alan Stern
Quoted 7 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
That's true. That was one of the reason I've always wanted the pre-suspend and post-resume hooks. (I prefer keeping the ordering there too, rather than a notifier, but a notifier is fine I suppose).
Among the clients we want here the firmware stuff, the allocators, etc... to get themselves in conditions that won't deadlock during suspend cycle.
I think that's a much bigger issue overall than freezer vs. no freezer :-)
Ben.
Quoted 5 lines
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Yes. The main thing I see here is that here is nothing common among drivers in what a "request" is and how it's processed.
For example, for block drivers, it's actually fairly simple to just stop processing the request queue and wait for pending ones to complete.
For network, in a similar vein, we can mostly just tell the network stack to stop sending us packets.
That's what I call the "main path". This is often the trivial part to deal with, mostly because for a whole lot of drivers, it can be done via a couple of helpers in the subsystem that the driver provides a service too, via a helper, asking that subsystem to stop calling into the said driver (the asking should be done by the driver itself of course, for ordering reasons).
We have some helpers, but I think not enough, and that's where we should focus imho. For example, I added fb_set_suspend() so that fbdev's can request fbcon to stop accessing them (it doesn't solve the problem of userland mmap's, that will have to be done, if we want to do it, in a more sneaky way, using VM tricks, but the DRM nowadays has the infrastructure to do it).
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like change_mtu or set_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
Quoted 2 lines
Normally a waitqueue or a struct completion would be used for this purpose.
I think there's no "normal" scenario, each driver or family of drivers will do things very differently.
Quoted 2 lines
But either one puts the burden on the driver of defining a data structure and signalling it at the right time.
Yes.
Quoted 3 lines
That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer).
In fact, the best is to have parallel suspend/resume of drivers and asynchronous resume but that's out of topic :-) (For the record, I did some bits like ADB resume like that, that is asynchronous, to speed up wakeup time).
Quoted 3 lines
In fact, we definitely don't want to unblock plug events until this later time.
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 8 lines
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Quoted 5 lines
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right?
Registration is fine, binding/ubinding is not (no problem putting the driver on/off a list, though of course, you can't unregister a bound driver without unbinding, it's prefectly find to unregister an unbound driver).
Quoted 1 line
And we must not allow driver binding or unbinding.
That's where the meat is.
Quoted 6 lines
But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration.
It has to be done at a time when no device semaphores are held.
I think that should indeed be handled within the driver core. Though I tend to think our driver core is a bit of a locking mess at the moment :-) (Who says it could use more RCU-like constructs ?).
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
The only remaining annoying case is manual bind/unbind via sysfs which is a good candidate for the above described icebox.
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Cheers,
Ben.
Quoted 5 lines
You agree that drivers need to block various activities during suspend. Principally I/O requests, but other things as well. So when one of these requests arrives, the driver has to make it wait somehow and then has to allow it to proceed at the appropriate time.
Yes. The main thing I see here is that here is nothing common among drivers in what a "request" is and how it's processed.
For example, for block drivers, it's actually fairly simple to just stop processing the request queue and wait for pending ones to complete.
For network, in a similar vein, we can mostly just tell the network stack to stop sending us packets.
That's what I call the "main path". This is often the trivial part to deal with, mostly because for a whole lot of drivers, it can be done via a couple of helpers in the subsystem that the driver provides a service too, via a helper, asking that subsystem to stop calling into the said driver (the asking should be done by the driver itself of course, for ordering reasons).
We have some helpers, but I think not enough, and that's where we should focus imho. For example, I added fb_set_suspend() so that fbdev's can request fbcon to stop accessing them (it doesn't solve the problem of userland mmap's, that will have to be done, if we want to do it, in a more sneaky way, using VM tricks, but the DRM nowadays has the infrastructure to do it).
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like change_mtu or set_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
Quoted 2 lines
Normally a waitqueue or a struct completion would be used for this purpose.
I think there's no "normal" scenario, each driver or family of drivers will do things very differently.
Quoted 2 lines
But either one puts the burden on the driver of defining a data structure and signalling it at the right time.
Yes.
Quoted 3 lines
That time is generally when the device is resumed, but there's nothing wrong with delaying it slightly, to after all the devices have been resumed (i.e., the time when the current PM code takes everything out of the freezer).
In fact, the best is to have parallel suspend/resume of drivers and asynchronous resume but that's out of topic :-) (For the record, I did some bits like ADB resume like that, that is asynchronous, to speed up wakeup time).
Quoted 3 lines
In fact, we definitely don't want to unblock plug events until this later time.
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)
I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 8 lines
User tasks can cause driver binding by writing to sysfs. Binding _can't_ be blocked in the driver; by then it's already too late. If it is going to be blocked at all, it has to be blocked earlier. One possibility is in the sysfs attribute code; another is to block all sysfs access.
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Quoted 5 lines
Ben, you haven't given enough thought to the work needed to avoid locking problems.
For instance, you agree that during suspend we must not allow device or driver registration or unregistration, right?
Registration is fine, binding/ubinding is not (no problem putting the driver on/off a list, though of course, you can't unregister a bound driver without unbinding, it's prefectly find to unregister an unbound driver).
Quoted 1 line
And we must not allow driver binding or unbinding.
That's where the meat is.
Quoted 6 lines
But these events generally involve acquiring a device semaphore, in the driver core and quite often in the core's caller. Since that semaphore is also needed for calling the suspend and resume methods, we have to be very careful about blocking binding/unbinding/registration/unregistration.
It has to be done at a time when no device semaphores are held.
I think that should indeed be handled within the driver core. Though I tend to think our driver core is a bit of a locking mess at the moment :-) (Who says it could use more RCU-like constructs ?).
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
The only remaining annoying case is manual bind/unbind via sysfs which is a good candidate for the above described icebox.
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Cheers,
Ben.
Quoted 7 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
Cheers,
Ben.
Quoted 7 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
Cheers,
Ben.
Quoted 4 lines · Alan Stern
In answer to both questions: We need the freezer in order to implement hibernate. Even if we take your advice and stop using the freezer during suspend, these issues would still remain and would need to be solved.
Stepping back for a minute, let's think about what the freezer is trying to achieve. I think that currently there are three basic design goals:
A. Ensure that device drivers don't get I/O requests after being
suspended.
B. Ensure that driver suspend routines don't end up blocking forever
on mutexes or semaphores held by frozen tasks.
C. Provide a way to get an atomic snapshot of memory for hibernation.
Now, it's easy enough to freeze all processes (or all except one), if you don't have goal B. Just offline non-boot cpus and disable interrupts, or use stop_machine(). But goal B implies that you can't necessarily just stop all tasks wherever they are. In fact it means there are points where it is safe to stop a given task, and there may be points where it isn't safe to stop it - and there is no practical way to determine those points reliably.[1]
That implies to me that we can have a freezer as long as we do nothing that can sleep, while tasks are frozen. In other words, I think the freezer is a viable option for hibernation as long as we restrict driver hibernate routines to doing only things which don't sleep. I _think_ that should be doable since hibernate routines only need to wait for outstanding DMAs to complete, as I understand it, which can be done by polling.
Paul.
[1] For a start, there's no way to determine which mutexes a task holds. Even if there were, we would then also have to know which mutexes it is going to try to acquire before it releases the one we want, which is pretty much unknowable.
One can say "we'll only freeze kernel tasks that ask to be frozen" but then one has no way to guarantee A, and we still don't reliably guarantee B if we have user-level filesystems or device drivers.
Quoted 4 lines · Alan Stern
In answer to both questions: We need the freezer in order to implement hibernate. Even if we take your advice and stop using the freezer during suspend, these issues would still remain and would need to be solved.
Stepping back for a minute, let's think about what the freezer is trying to achieve. I think that currently there are three basic design goals:
A. Ensure that device drivers don't get I/O requests after being
suspended.
B. Ensure that driver suspend routines don't end up blocking forever
on mutexes or semaphores held by frozen tasks.
C. Provide a way to get an atomic snapshot of memory for hibernation.
Now, it's easy enough to freeze all processes (or all except one), if you don't have goal B. Just offline non-boot cpus and disable interrupts, or use stop_machine(). But goal B implies that you can't necessarily just stop all tasks wherever they are. In fact it means there are points where it is safe to stop a given task, and there may be points where it isn't safe to stop it - and there is no practical way to determine those points reliably.[1]
That implies to me that we can have a freezer as long as we do nothing that can sleep, while tasks are frozen. In other words, I think the freezer is a viable option for hibernation as long as we restrict driver hibernate routines to doing only things which don't sleep. I _think_ that should be doable since hibernate routines only need to wait for outstanding DMAs to complete, as I understand it, which can be done by polling.
Paul.
[1] For a start, there's no way to determine which mutexes a task holds. Even if there were, we would then also have to know which mutexes it is going to try to acquire before it releases the one we want, which is pretty much unknowable.
One can say "we'll only freeze kernel tasks that ask to be frozen" but then one has no way to guarantee A, and we still don't reliably guarantee B if we have user-level filesystems or device drivers.
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Pavel MachekQuoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you are basically just thinking of where to prop it up further. To continute this brilliant analogy, Rafael's patch at least demolishes the worst part of the house, where bricks are already falling on our head ;)
Quoted 2 lines
Not ideal, but neither is allowing malicious filesystems in the first place...
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
Quoted 9 lines
Quoted 6 lines
Look at it this way: the task of the freezer is to stop new I/O hitting the hardware. But it is totally indiscriminate about what it stops, it tries to stop _everything_ even things which have nothing to do with hardware.
Not nice.
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Miklos
Re: [PATCH] Remove process freezer from suspend to RAM pathway (philosophical)
In reply to Alan Stern* Alan Stern <Date: Fri, 6 Jul 2007 11:13:14 -0400 (EDT)>
Quoted 10 lines
Quoted 8 lines
Why are you guys working so hard and spending so much energy to try to avoid doing the right thing is beyond my understanding...
Quoted 3 lines
It _does_ apply to kernel threads. That's exactly why I wrote above that kernel threads which try to do I/O during a suspend will need extra attention.
Ok none at all if you don't have a freezer.
In answer to both questions: We need the freezer in order to
Non of *complex* living creatures survive motionless freezing (with ice).
That's why stupid me just don't care about all that stuff in the Linux. It's nice to see somebody approaches this from technical, but not off-topical POV :).
____
Off topically about Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediQuoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
And this must be called sleep, deep sleep or something like that. Because preparing for sleeping takes place, sleeping itself is a process, life requires. Waking up, staying all day fresh and active is the needed goal.
Thus, whole freeze/ice idea was dead-born, IMHO :)
WRT this, busy-loop _waiting_ that was called sleep, usleep or nanosleep is another wrong-named concept. I imagine somebody after one minute sleep :)
____
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediHi!
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Quoted 11 lines
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you
Nice way to have useful discussion. Not.
Look, Linux was not designed with malicious filesystems in mind. In particular, suspend was not designed with malicious filesystems in mind, and VFS was not designed with malicious filesystems in mind. That's why you have the nastiness with deadlocks... which you are unable/unwilling to solve because you'd have to redesign VFS and meet Al Viro.
Now.. freezer already includes timeout; if some part of kernel knows nothing about suspend or had crashed, it will abort after some time, telling you which part to blame. Another timeout for detecting malicious userspace filesystems will not hurt much in this old house. (Maybe you don't want to auto abort them, just tell user what happened.
We are stuck with refrigerator for now, and at least for hibernation, I don't see any feasible alternative.
And now, can we get that sysrq-t trace? Dealing with 'unable to freeze' may be hard, but the deadlock Matthew saw should be simple bug for us to fix.
Quoted 6 lines
Quoted 2 lines
Not ideal, but neither is allowing malicious filesystems in the first place...
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
Quoted 4 lines
Quoted 2 lines
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Anything that's used in today's notebooks, I'd say...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediHi!
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Quoted 11 lines
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you
Nice way to have useful discussion. Not.
Look, Linux was not designed with malicious filesystems in mind. In particular, suspend was not designed with malicious filesystems in mind, and VFS was not designed with malicious filesystems in mind. That's why you have the nastiness with deadlocks... which you are unable/unwilling to solve because you'd have to redesign VFS and meet Al Viro.
Now.. freezer already includes timeout; if some part of kernel knows nothing about suspend or had crashed, it will abort after some time, telling you which part to blame. Another timeout for detecting malicious userspace filesystems will not hurt much in this old house. (Maybe you don't want to auto abort them, just tell user what happened.
We are stuck with refrigerator for now, and at least for hibernation, I don't see any feasible alternative.
And now, can we get that sysrq-t trace? Dealing with 'unable to freeze' may be hard, but the deadlock Matthew saw should be simple bug for us to fix.
Quoted 6 lines
Quoted 2 lines
Not ideal, but neither is allowing malicious filesystems in the first place...
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
Quoted 4 lines
Quoted 2 lines
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Anything that's used in today's notebooks, I'd say...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
Quoted 3 lines · Pavel Machek
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
If your variant doesn't handle compromised NFS server, your variant is needs to be fixed...
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediQuoted 11 lines · Miklos Szeredi
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
And then you also would like to have a consistent state of the system after the resume, but if the state were inconsistent before the suspend that would be difficult to get.
Quoted 8 lines
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Quoted 7 lines
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you are basically just thinking of where to prop it up further. To continute this brilliant analogy, Rafael's patch at least demolishes the worst part of the house, where bricks are already falling on our head ;)
Actually, this isn't correct and I have some testing problems with this patch (as I expected, BTW), so it's not going anywhere. Alternative ideas will be appreciated. :-)
Quoted 12 lines
Quoted 2 lines
Not ideal, but neither is allowing malicious filesystems in the first place...
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
Quoted 5 lines
Quoted 5 lines
Look at it this way: the task of the freezer is to stop new I/O hitting the hardware. But it is totally indiscriminate about what it stops, it tries to stop _everything_ even things which have nothing to do with hardware.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Not nice.
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Well, you know why that actually started to be a real problem? Because sufficiently many people have started to use suspend/hibernation and it actually works for quite a lot of them. This makes people to try exotic combinations like suspend+FUSE and they find that doesn't work.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Pavel MachekQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Which is pretty much impossible, given the unix filesystem API. To be able to react to sigstop, the operations in question need to be restartable. Which they are not, so they can't react to sigstop. End of story.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Quoted 5 lines
Quoted 3 lines
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you
Nice way to have useful discussion. Not.
Sorry, didn't mean to offend you.
Quoted 6 lines
Look, Linux was not designed with malicious filesystems in mind. In particular, suspend was not designed with malicious filesystems in mind, and VFS was not designed with malicious filesystems in mind. That's why you have the nastiness with deadlocks... which you are unable/unwilling to solve because you'd have to redesign VFS and meet Al Viro.
No, I don't think we need to redesign the VFS, and also I think the malicious filesystem thing has been adequately taken care of in fuse.
You may not like the fact that one process can cause another to go into uninterruptible sleep, but in fact there's nothing wrong with that. The effects are localized to the mount owner, it won't cause any system-wide ill, it's in fact no worse than a malicious process doing ptrace().
And as explained above it's unavoidable due to the well established userspace API. The _point_ of fuse is to let this API be used by unmodified programs and the filesystem be provided by a userspace process. After showing me the right way to do this with Podfuk, this should not come as a surprise to you.
So the fact that the freezer can't handle this is unfortunate, but it's just a symptom of the brokenness of it, not something that fuse introduced. Not being able to suspend with NFS (or other network filesystems) when the network is lost shows that this is a deeper problem.
And for some reason you seem not to accept that. You think that the problem is with fuse, NFS, CIFS, whatever, and not the freezer, when in fact it's quite clear, that neither of the above should have anything to do with power management. Even if it was possible to fix them, it would still be just fixing the symptoms.
Quoted 8 lines
Now.. freezer already includes timeout; if some part of kernel knows nothing about suspend or had crashed, it will abort after some time, telling you which part to blame. Another timeout for detecting malicious userspace filesystems will not hurt much in this old house. (Maybe you don't want to auto abort them, just tell user what happened.
We are stuck with refrigerator for now, and at least for hibernation, I don't see any feasible alternative.
Even for hibernation, I don't see, why we would need all processes being effectively in a stopped state.
As stated otherwise in the thread, suspend2 in fact allowed processes to be in uninterruptible sleep instead, without negative side effects.
The current freezer does too much for suspend and for hibernate too.
Quoted 7 lines
Quoted 3 lines
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
It doesn't have to be malicious, it's enough if the server crashes, or the network connection is lost.
Do we want to maintain the status quo, just because we can live with it?
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Anything that's used in today's notebooks, I'd say...
Which is what, 10% of all the drivers? Then it really not as bad as you try to make it sound. And with the late suspend call (whatever it does) that can take care of most of those, it really becomes just a few drivers and subsystems to fix.
Miklos
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Al ViroQuoted 7 lines · Al Viro
Quoted 3 lines · Pavel Machek
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
If your variant doesn't handle compromised NFS server, your variant is needs to be fixed...
That would depend on the type of compromise, right?
Remember that the fundamental contract between a client and a server includes the client extending some trust to that server. Whether it's appropriate to extend that trust (at any given moment) is an out-of-band security issue. Trust is not a protocol issue ... more like an operational issue, and only slightly an implementation issue.
A malicious filesystem could do many things. It could send private data off to someone who wasn't intended to receive that data. It could return falsified data. It could do any variety of things outside the protocol specification...
And *MOST* of those would be impractical to defend against in code. Which is why I have such a hard time agreeing with your comment about "fixing" a client that doesn't try to defend itself. (Unless by "client" you also include the whole operational side of the client, including regular re-validation of the trust extended to that server... which would at best minimize damage caused by compromises.)
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Al ViroQuoted 7 lines · Al Viro
Quoted 3 lines · Pavel Machek
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
If your variant doesn't handle compromised NFS server, your variant is needs to be fixed...
That would depend on the type of compromise, right?
Remember that the fundamental contract between a client and a server includes the client extending some trust to that server. Whether it's appropriate to extend that trust (at any given moment) is an out-of-band security issue. Trust is not a protocol issue ... more like an operational issue, and only slightly an implementation issue.
A malicious filesystem could do many things. It could send private data off to someone who wasn't intended to receive that data. It could return falsified data. It could do any variety of things outside the protocol specification...
And *MOST* of those would be impractical to defend against in code. Which is why I have such a hard time agreeing with your comment about "fixing" a client that doesn't try to defend itself. (Unless by "client" you also include the whole operational side of the client, including regular re-validation of the trust extended to that server... which would at best minimize damage caused by compromises.)
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediQuoted 12 lines · Miklos Szeredi
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
Quoted 7 lines
Quoted 2 lines
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Which is pretty much impossible, given the unix filesystem API. To be able to react to sigstop, the operations in question need to be restartable. Which they are not, so they can't react to sigstop. End of story.
Or not. That depends on your willingness to cooperate, I'd say. :-)
Quoted 23 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Quoted 5 lines
Quoted 3 lines
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you
Nice way to have useful discussion. Not.
Sorry, didn't mean to offend you.
Quoted 6 lines
Look, Linux was not designed with malicious filesystems in mind. In particular, suspend was not designed with malicious filesystems in mind, and VFS was not designed with malicious filesystems in mind. That's why you have the nastiness with deadlocks... which you are unable/unwilling to solve because you'd have to redesign VFS and meet Al Viro.
Quoted 6 lines
No, I don't think we need to redesign the VFS, and also I think the malicious filesystem thing has been adequately taken care of in fuse.
You may not like the fact that one process can cause another to go into uninterruptible sleep, but in fact there's nothing wrong with that.
Well, this introduces interdependencies between processes that do not exist otherwise. Even if that isn't wrong per se, it's something that needs consideration in any case.
IMO, FUSE breaks one of the assumptions that the freezer is based on and saying that the freezer is broken because of that is unfair.
Quoted 10 lines
The effects are localized to the mount owner, it won't cause any system-wide ill, it's in fact no worse than a malicious process doing
ptrace().And as explained above it's unavoidable due to the well established userspace API. The _point_ of fuse is to let this API be used by unmodified programs and the filesystem be provided by a userspace process. After showing me the right way to do this with Podfuk, this should not come as a surprise to you.
Quoted 5 lines
So the fact that the freezer can't handle this is unfortunate, but it's just a symptom of the brokenness of it, not something that fuse introduced. Not being able to suspend with NFS (or other network filesystems) when the network is lost shows that this is a deeper problem.
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
In fact, NFS and similar filesystems should always be unmounted before the suspend/hibernation to avoid problems that may arise after the resume, if they become unavailable at that time.
Quoted 4 lines
And for some reason you seem not to accept that. You think that the problem is with fuse, NFS, CIFS, whatever, and not the freezer, when in fact it's quite clear, that neither of the above should have anything to do with power management.
IMHO, it's not _that_ clear.
Quoted 2 lines
Even if it was possible to fix them, it would still be just fixing the symptoms.
I don't think we need to fix the network filesystems.
If there's a mounted filesystem and we have at least one process waiting for it to become available in the D state (ie. uninterruptible), then the system is not in a consistent state and should not be suspended.
Quoted 6 lines
Quoted 6 lines
Now.. freezer already includes timeout; if some part of kernel knows nothing about suspend or had crashed, it will abort after some time, telling you which part to blame. Another timeout for detecting malicious userspace filesystems will not hurt much in this old house. (Maybe you don't want to auto abort them, just tell user what happened.
Quoted 8 lines
Quoted 2 lines
We are stuck with refrigerator for now, and at least for hibernation, I don't see any feasible alternative.
Even for hibernation, I don't see, why we would need all processes being effectively in a stopped state.
As stated otherwise in the thread, suspend2 in fact allowed processes to be in uninterruptible sleep instead, without negative side effects.
And yet, Nigel thinks that the freezer is necessary for the hibernation. Strange, no?
Quoted 1 line
The current freezer does too much for suspend and for hibernate too.
Yes, it does. It's quilte similar to the BKL in that. Still, for now, there's no infrastructure for a more fine grained approach and instead of working on introducing one, we're losing time in this thread.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
Quoted 5 lines
It doesn't have to be malicious, it's enough if the server crashes, or the network connection is lost.
Do we want to maintain the status quo, just because we can live with it?
Say you're standing on a cliff and you have three choices:
(1) stay where you are (well, this is not attractive in the long run)
(2) jump down
(3) look for a path to go down slowly?
Which one will you choose?
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Anything that's used in today's notebooks, I'd say...
Which is what, 10% of all the drivers? Then it really not as bad as you try to make it sound. And with the late suspend call (whatever it does) that can take care of most of those, it really becomes just a few drivers and subsystems to fix.
Are they fixed _now_?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediQuoted 12 lines · Miklos Szeredi
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
What I'd like, is a suspend, that works reliably, regardless of the state of any userspace filesystem, network servers and such.
Quoted 7 lines
Quoted 2 lines
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Which is pretty much impossible, given the unix filesystem API. To be able to react to sigstop, the operations in question need to be restartable. Which they are not, so they can't react to sigstop. End of story.
Or not. That depends on your willingness to cooperate, I'd say. :-)
Quoted 23 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Quoted 5 lines
Quoted 3 lines
Arbitrary time limits, nice. Not.
This freezer is like an old house that's close to collapsing, and you
Nice way to have useful discussion. Not.
Sorry, didn't mean to offend you.
Quoted 6 lines
Look, Linux was not designed with malicious filesystems in mind. In particular, suspend was not designed with malicious filesystems in mind, and VFS was not designed with malicious filesystems in mind. That's why you have the nastiness with deadlocks... which you are unable/unwilling to solve because you'd have to redesign VFS and meet Al Viro.
Quoted 6 lines
No, I don't think we need to redesign the VFS, and also I think the malicious filesystem thing has been adequately taken care of in fuse.
You may not like the fact that one process can cause another to go into uninterruptible sleep, but in fact there's nothing wrong with that.
Well, this introduces interdependencies between processes that do not exist otherwise. Even if that isn't wrong per se, it's something that needs consideration in any case.
IMO, FUSE breaks one of the assumptions that the freezer is based on and saying that the freezer is broken because of that is unfair.
Quoted 10 lines
The effects are localized to the mount owner, it won't cause any system-wide ill, it's in fact no worse than a malicious process doing
ptrace().And as explained above it's unavoidable due to the well established userspace API. The _point_ of fuse is to let this API be used by unmodified programs and the filesystem be provided by a userspace process. After showing me the right way to do this with Podfuk, this should not come as a surprise to you.
Quoted 5 lines
So the fact that the freezer can't handle this is unfortunate, but it's just a symptom of the brokenness of it, not something that fuse introduced. Not being able to suspend with NFS (or other network filesystems) when the network is lost shows that this is a deeper problem.
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
In fact, NFS and similar filesystems should always be unmounted before the suspend/hibernation to avoid problems that may arise after the resume, if they become unavailable at that time.
Quoted 4 lines
And for some reason you seem not to accept that. You think that the problem is with fuse, NFS, CIFS, whatever, and not the freezer, when in fact it's quite clear, that neither of the above should have anything to do with power management.
IMHO, it's not _that_ clear.
Quoted 2 lines
Even if it was possible to fix them, it would still be just fixing the symptoms.
I don't think we need to fix the network filesystems.
If there's a mounted filesystem and we have at least one process waiting for it to become available in the D state (ie. uninterruptible), then the system is not in a consistent state and should not be suspended.
Quoted 6 lines
Quoted 6 lines
Now.. freezer already includes timeout; if some part of kernel knows nothing about suspend or had crashed, it will abort after some time, telling you which part to blame. Another timeout for detecting malicious userspace filesystems will not hurt much in this old house. (Maybe you don't want to auto abort them, just tell user what happened.
Quoted 8 lines
Quoted 2 lines
We are stuck with refrigerator for now, and at least for hibernation, I don't see any feasible alternative.
Even for hibernation, I don't see, why we would need all processes being effectively in a stopped state.
As stated otherwise in the thread, suspend2 in fact allowed processes to be in uninterruptible sleep instead, without negative side effects.
And yet, Nigel thinks that the freezer is necessary for the hibernation. Strange, no?
Quoted 1 line
The current freezer does too much for suspend and for hibernate too.
Yes, it does. It's quilte similar to the BKL in that. Still, for now, there's no infrastructure for a more fine grained approach and instead of working on introducing one, we're losing time in this thread.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Malicious programs are not something specific to fuse. A lot of the multiuser/multitasking OS design is about isolating things, so such a program is limited in the damage it can do.
I'm talking malicious _filesystems_ here, and yes, fuse is first of this kind. We want to handle unresponding NFS, but I believe handling malicious NFS server nicely is slightly out of scope.
Quoted 5 lines
It doesn't have to be malicious, it's enough if the server crashes, or the network connection is lost.
Do we want to maintain the status quo, just because we can live with it?
Say you're standing on a cliff and you have three choices:
(1) stay where you are (well, this is not attractive in the long run)
(2) jump down
(3) look for a path to go down slowly?
Which one will you choose?
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Not nice, but we don't know any better for now. "Just fix all the drivers" basically means "just fix 90% of kernel".
And how much of that 90% currently has any power management?
Anything that's used in today's notebooks, I'd say...
Which is what, 10% of all the drivers? Then it really not as bad as you try to make it sound. And with the late suspend call (whatever it does) that can take care of most of those, it really becomes just a few drivers and subsystems to fix.
Are they fixed _now_?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 11 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Quoted 6 lines
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
Well, no matter how much bad names you will call it, that's what in use right now and it's not _that_ easy to get rid of.
I'm perfectly fine with readying drivers etc. for dropping the freezer, but in the meantime bugs in the freezer need to be fixed, if possible.
And if it deadlocks, there is a bug in it.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Discussion at this level would be totally counterproductive and wouldn't lead to anything constructive, so let me avoid commenting your abusive remarks.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 22 lines · Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Quoted 6 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Exactly.
And if we really want to get rid of the freezer, we need to _prepare_ for that. At least, we need to have an idea of how we will do thing when the freezer is not there.
For example, how will we check if the system is not in a state in which the resume is likely to fail?
There are more questions like that, IMO, and we should at least have a list of them _before_ we remove the freezer.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 11 lines · Alan Stern
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 2 lines
Quoted 2 lines
And guess what ? It's what we do on powerbooks, and it works fine, without a freezer :-)
If you remember, one of the things I've been advocating has always been that we should put on hold all plug activity (unplug might be alright as long as the user events are just delayed) when we start suspending. No new devices, no new bindings. "hub" type devices are respondible for bringing in the new stuff after resume.
Quoted 6 lines
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
Well, no matter how much bad names you will call it, that's what in use right now and it's not _that_ easy to get rid of.
I'm perfectly fine with readying drivers etc. for dropping the freezer, but in the meantime bugs in the freezer need to be fixed, if possible.
And if it deadlocks, there is a bug in it.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Discussion at this level would be totally counterproductive and wouldn't lead to anything constructive, so let me avoid commenting your abusive remarks.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 22 lines · Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines
Which is exactly my point. It _doesn't_ work fine without a freezer, because the USB stack currently relies on the freezer to prevent plug activity.
Putting on hold plug activity has nothing, NOTHING, to do with the half assed piece of deadlocking crap we have now we call a freezer.
You're wrong; it _does_ have something to do with the freezer. The connection is that the code uses the freezer to put plug activity on hold.
You probably meant to say that it _should_ have nothing to do with the freezer. That's a different matter. But in any case you should write what you actually mean, rather than just putting down something as inflammatory as possible.
Quoted 3 lines
As long as you guys keep mixing up all the issues and coming up with totally bogus solutions that cannot work, we won't have a useful suspend (either to RAM or to disk) in linux.
Quoted 6 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
Exactly.
And if we really want to get rid of the freezer, we need to _prepare_ for that. At least, we need to have an idea of how we will do thing when the freezer is not there.
For example, how will we check if the system is not in a state in which the resume is likely to fail?
There are more questions like that, IMO, and we should at least have a list of them _before_ we remove the freezer.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Rafael J. WysockiQuoted 6 lines · Rafael J. Wysocki
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
In fact, NFS and similar filesystems should always be unmounted before the suspend/hibernation to avoid problems that may arise after the resume, if they become unavailable at that time.
Ah, thanks for clarifying that. [mentally putting the entire thing into "unusable due to idiotic design imposing idiotic limitations" bin and stepping out of this thread]
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Rafael J. WysockiQuoted 6 lines · Rafael J. Wysocki
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
In fact, NFS and similar filesystems should always be unmounted before the suspend/hibernation to avoid problems that may arise after the resume, if they become unavailable at that time.
Ah, thanks for clarifying that. [mentally putting the entire thing into "unusable due to idiotic design imposing idiotic limitations" bin and stepping out of this thread]
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 7 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
That's true. That was one of the reason I've always wanted the pre-suspend and post-resume hooks. (I prefer keeping the ordering there too, rather than a notifier, but a notifier is fine I suppose).
Quoted 6 lines
Among the clients we want here the firmware stuff, the allocators, etc... to get themselves in conditions that won't deadlock during suspend cycle.
I think that's a much bigger issue overall than freezer vs. no freezer :-)
Yes. The freezer is only one part of the PM infrastructure that we have currently and that is not very sophisticated, so to speak.
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 7 lines
In my defense, you should realize that until Rafael's notifier chain was added (just a few weeks ago, still not in mainline I believe) there was no other way to do it. Plug activity needs to be stopped before the child devices are suspended, and the PM core does not send any notification to drivers at that time. All it does is activate the freezer.
That's true. That was one of the reason I've always wanted the pre-suspend and post-resume hooks. (I prefer keeping the ordering there too, rather than a notifier, but a notifier is fine I suppose).
Quoted 6 lines
Among the clients we want here the firmware stuff, the allocators, etc... to get themselves in conditions that won't deadlock during suspend cycle.
I think that's a much bigger issue overall than freezer vs. no freezer :-)
Yes. The freezer is only one part of the PM infrastructure that we have currently and that is not very sophisticated, so to speak.
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]
Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]
Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Rafael J. WysockiQuoted 9 lines
Quoted 7 lines
Quoted 2 lines
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Which is pretty much impossible, given the unix filesystem API. To be able to react to sigstop, the operations in question need to be restartable. Which they are not, so they can't react to sigstop. End of story.
Or not. That depends on your willingness to cooperate, I'd say. :-)
Do you actually understand what I'm talking about? Because it sure doesn't depend on my cooperation.
Maybe I'm stupid, and I'm missing something obvious. In that case please explain how you propose to make filesystem operations, like rename() restartable.
Quoted 10 lines
Quoted 3 lines
You may not like the fact that one process can cause another to go into uninterruptible sleep, but in fact there's nothing wrong with that.
Well, this introduces interdependencies between processes that do not exist otherwise. Even if that isn't wrong per se, it's something that needs consideration in any case.
IMO, FUSE breaks one of the assumptions that the freezer is based on and saying that the freezer is broken because of that is unfair.
The freezer is not broken because of that, it's broken anyway. What we are seeing is a _symptom_ of it being broken.
And by broken, I don't mean it's buggy or that it was badly designed. I just mean, that it's simply not what suspend should depend on, to protect drivers.
Quoted 8 lines
Quoted 5 lines
So the fact that the freezer can't handle this is unfortunate, but it's just a symptom of the brokenness of it, not something that fuse introduced. Not being able to suspend with NFS (or other network filesystems) when the network is lost shows that this is a deeper problem.
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
Saying the system must be in a "consistent" state, and defining consistent as "every process is stopped", is just an arbitrary limitation that fits what the freezer does now. Yes the _hardware_ state must be consistent, but that has nothing to do with either fuse or NFS. Can't you see that?
Quoted 5 lines
Quoted 2 lines
As stated otherwise in the thread, suspend2 in fact allowed processes to be in uninterruptible sleep instead, without negative side effects.
And yet, Nigel thinks that the freezer is necessary for the hibernation. Strange, no?
I'm totally ignorant about why the freezer is necessary for hibernate. Please explain.
Yes, we need to make sure, that nothing is scheduled during (and possibly after) taking the snapshot. But AFAICS that could be achieved by unplugging all but one CPU.
Miklos
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 8 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 8 lines
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over device_add() will immediately return an error. We could even add a new ESUSPENDING code to errno.h; it would come in handy in a few places.
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things. device_add() isn't on a hot path, so adding an extra check and srcu_read_lock() won't hurt.
Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a WARN_ON() in device_add() would be a good idea.
Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Alan Stern
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).
This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 8 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 8 lines
Quoted 1 line
Does that make you happier?
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over device_add() will immediately return an error. We could even add a new ESUSPENDING code to errno.h; it would come in handy in a few places.
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things. device_add() isn't on a hot path, so adding an extra check and srcu_read_lock() won't hurt.
Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a WARN_ON() in device_add() would be a good idea.
Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?
Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Alan Stern
Quoted 4 lines · Benjamin Herrenschmidt
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
This wouldn't need any special infrastructure. Just a regular waitqueue defined in the device's private data structure.
Alan Stern
Quoted 4 lines · Benjamin Herrenschmidt
Note that we could have also a per-device "icebox" (just a waitqueue). Might be nice for a device to resume whatever it froze just after it resumed itself, might even be necessary in case whatever thread got frozen is necessary for handling child devices.
This wouldn't need any special infrastructure. Just a regular waitqueue defined in the device's private data structure.
Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
Alan Stern
Hi!
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Well, that way you'd have to teach applications about suspend... Which is quite bad. You mentioned it -- returning random errors will be very bad for machines like OLPC that want to suspend automatically. Plus it is a step back from current implementation, and ABI change, too...
Quoted 12 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Quoted 6 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing
Kernel threads already send _themselves_ to the refrigerator. [Plus we put all the userland there, which is what you don't like, but kernel can not rely on userland after suspend starts, anyway, so it should not hurt].
Anyway.. PPC currently suspends without freezer, which puts rules on drivers. ("Must handle i/o requests after .suspend() method is ran, must not use GFP_KERNEL to do so, must not try to synchronously communicate with userspace before _all_ devices are unfrozen") I am not certain what the exact rules are, but you seem to know them. Could we get Doc*/power/suspend_wo_freezer.txt describing them for driver authors? That way we can make sure drivers work on ppc, too, and maybe get rid of freezer in the long run.
Quoted 7 lines
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
This is how it works currently in -mm.
(Plus, the rule is that threads that decide _not to_ stop themselves should not do any I/O.)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Well, that way you'd have to teach applications about suspend... Which is quite bad. You mentioned it -- returning random errors will be very bad for machines like OLPC that want to suspend automatically. Plus it is a step back from current implementation, and ABI change, too...
Quoted 12 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Quoted 6 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing
Kernel threads already send _themselves_ to the refrigerator. [Plus we put all the userland there, which is what you don't like, but kernel can not rely on userland after suspend starts, anyway, so it should not hurt].
Anyway.. PPC currently suspends without freezer, which puts rules on drivers. ("Must handle i/o requests after .suspend() method is ran, must not use GFP_KERNEL to do so, must not try to synchronously communicate with userspace before _all_ devices are unfrozen") I am not certain what the exact rules are, but you seem to know them. Could we get Doc*/power/suspend_wo_freezer.txt describing them for driver authors? That way we can make sure drivers work on ppc, too, and maybe get rid of freezer in the long run.
Quoted 7 lines
Quoted 2 lines
You also agree that kernel threads and workqueues must be allowed to operate during suspend.
Yes, unless kernel threads explicitely decide to stop themselves (for example, khubd is a good candidate for that). Again, not a 3rd party trying to decide what to freeze and what not, but the drivers or kernel threads themselves deciding it.
This is how it works currently in -mm.
(Plus, the rule is that threads that decide _not to_ stop themselves should not do any I/O.)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediQuoted 8 lines · Miklos Szeredi
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Which is pretty much impossible, given the unix filesystem API. To be able to react to sigstop, the operations in question need to be restartable. Which they are not, so they can't react to sigstop. End of story.
Quoted 8 lines
Quoted 1 line
Or not. That depends on your willingness to cooperate, I'd say. :-)
Do you actually understand what I'm talking about? Because it sure doesn't depend on my cooperation.
Maybe I'm stupid, and I'm missing something obvious. In that case please explain how you propose to make filesystem operations, like
rename()restartable.
I'm not proposing that, sorry. I'm not a filesystem expert, so don't think I can propose a working solution here, right now. Still, maybe something like in fork.c, line 1409-1411 might work (I know that it won't solve the "other tasks may be waiting on VFS mutexes" issue, but at least it may decrease the probability of freezer failure).
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
You may not like the fact that one process can cause another to go into uninterruptible sleep, but in fact there's nothing wrong with that.
Well, this introduces interdependencies between processes that do not exist otherwise. Even if that isn't wrong per se, it's something that needs consideration in any case.
IMO, FUSE breaks one of the assumptions that the freezer is based on and saying that the freezer is broken because of that is unfair.
Quoted 6 lines
The freezer is not broken because of that, it's broken anyway. What we are seeing is a _symptom_ of it being broken.
And by broken, I don't mean it's buggy or that it was badly designed. I just mean, that it's simply not what suspend should depend on, to protect drivers.
Please have a look at the documentation update at the bottom of this patch:
It says what the freezer is for in the first place. :-)
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
So the fact that the freezer can't handle this is unfortunate, but it's just a symptom of the brokenness of it, not something that fuse introduced. Not being able to suspend with NFS (or other network filesystems) when the network is lost shows that this is a deeper problem.
Quoted 8 lines
Quoted 2 lines
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
Saying the system must be in a "consistent" state, and defining consistent as "every process is stopped", is just an arbitrary limitation that fits what the freezer does now. Yes the _hardware_ state must be consistent, but that has nothing to do with either fuse or NFS. Can't you see that?
Well, I can agree as far as FUSE is concerned. Still, imagine that you have an NFS share mounted, which is unavailable at the moment and one of the tasks waits for an I/O on it to complete (it might hold some locks needed for suspending, but say it doesn't). Then you suspend, take the box somewhere else and attach to a different network with a different NFS server. Now, you resume and you have a mess to recover from. Yes, it _should_ be recoverable, but refusing to suspend in such a case is not okerkill, IMHO.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As stated otherwise in the thread, suspend2 in fact allowed processes to be in uninterruptible sleep instead, without negative side effects.
And yet, Nigel thinks that the freezer is necessary for the hibernation. Strange, no?
I'm totally ignorant about why the freezer is necessary for hibernate. Please explain.
See above. :-)
Quoted 3 lines
Yes, we need to make sure, that nothing is scheduled during (and possibly after) taking the snapshot. But AFAICS that could be achieved by unplugging all but one CPU.
Actually, we want things to get scheduled, because we need some of them to save the image (to make things more difficult, we don't know what will be needed to save the image in advance ;-)).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Hi!
Quoted 11 lines
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It should be in -mm, IIRC.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
You could use try_to_freeze(), but you want it to be separate routine so it can be grepped for... Can you #define icebox_me try_to_freeze for testing?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 11 lines
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It should be in -mm, IIRC.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
You could use try_to_freeze(), but you want it to be separate routine so it can be grepped for... Can you #define icebox_me try_to_freeze for testing?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 11 lines · Rafael J. Wysocki
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
Ben.
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediQuoted 8 lines · Miklos Szeredi
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Well, fix userspace filesystems and maybe NFS. If they react to sigstop in timely manner, they will work with suspend properly, too.
Which is pretty much impossible, given the unix filesystem API. To be able to react to sigstop, the operations in question need to be restartable. Which they are not, so they can't react to sigstop. End of story.
Quoted 8 lines
Quoted 1 line
Or not. That depends on your willingness to cooperate, I'd say. :-)
Do you actually understand what I'm talking about? Because it sure doesn't depend on my cooperation.
Maybe I'm stupid, and I'm missing something obvious. In that case please explain how you propose to make filesystem operations, like
rename()restartable.
I'm not proposing that, sorry. I'm not a filesystem expert, so don't think I can propose a working solution here, right now. Still, maybe something like in fork.c, line 1409-1411 might work (I know that it won't solve the "other tasks may be waiting on VFS mutexes" issue, but at least it may decrease the probability of freezer failure).
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines
You may not like the fact that one process can cause another to go into uninterruptible sleep, but in fact there's nothing wrong with that.
Well, this introduces interdependencies between processes that do not exist otherwise. Even if that isn't wrong per se, it's something that needs consideration in any case.
IMO, FUSE breaks one of the assumptions that the freezer is based on and saying that the freezer is broken because of that is unfair.
Quoted 6 lines
The freezer is not broken because of that, it's broken anyway. What we are seeing is a _symptom_ of it being broken.
And by broken, I don't mean it's buggy or that it was badly designed. I just mean, that it's simply not what suspend should depend on, to protect drivers.
Please have a look at the documentation update at the bottom of this patch:
It says what the freezer is for in the first place. :-)
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
So the fact that the freezer can't handle this is unfortunate, but it's just a symptom of the brokenness of it, not something that fuse introduced. Not being able to suspend with NFS (or other network filesystems) when the network is lost shows that this is a deeper problem.
Quoted 8 lines
Quoted 2 lines
Well, the system that cannot access its filesystems is not in a consistent state, so it generally is not reasonable to suspend or hibernate it.
Saying the system must be in a "consistent" state, and defining consistent as "every process is stopped", is just an arbitrary limitation that fits what the freezer does now. Yes the _hardware_ state must be consistent, but that has nothing to do with either fuse or NFS. Can't you see that?
Well, I can agree as far as FUSE is concerned. Still, imagine that you have an NFS share mounted, which is unavailable at the moment and one of the tasks waits for an I/O on it to complete (it might hold some locks needed for suspending, but say it doesn't). Then you suspend, take the box somewhere else and attach to a different network with a different NFS server. Now, you resume and you have a mess to recover from. Yes, it _should_ be recoverable, but refusing to suspend in such a case is not okerkill, IMHO.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As stated otherwise in the thread, suspend2 in fact allowed processes to be in uninterruptible sleep instead, without negative side effects.
And yet, Nigel thinks that the freezer is necessary for the hibernation. Strange, no?
I'm totally ignorant about why the freezer is necessary for hibernate. Please explain.
See above. :-)
Quoted 3 lines
Yes, we need to make sure, that nothing is scheduled during (and possibly after) taking the snapshot. But AFAICS that could be achieved by unplugging all but one CPU.
Actually, we want things to get scheduled, because we need some of them to save the image (to make things more difficult, we don't know what will be needed to save the image in advance ;-)).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Hi!
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
But userspace must not be neccessary for kernel functioning, so that's quite okay. And we do need to solve the workqueues.
Quoted 8 lines
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
:-). Or perhaps freezer is not _that_ evil after all?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 8 lines
Quoted 7 lines
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
We actually had patches for freezeable workqueues at one point.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 8 lines
Quoted 7 lines
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
We actually had patches for freezeable workqueues at one point.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to try_to_icebox() again if they do something that may schedule (such as __get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.
True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Ben.
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to try_to_icebox() again if they do something that may schedule (such as __get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.
True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Ben.
Quoted 10 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
I think looking at the kmallo/gfp issue I mentioned earlier should be done asap. I can try to spare some time for it this week but I can't promise, I'm actually swamped by something totally unrelated at the moment.
Another issue that's been a problem forever with suspend is the synchronous request_firmware interface. Lots of drivers do that in resume() which will generally not work.
Ben.
Quoted 10 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
I'm all for changing this infrastructure, but in an organized way (ie. we discuss what to do next, we do that and then we go to the next step) and in the order that everyone will be comfortable with.
So, let's finish this thread and start over from discussing what needs to be done, how (ie. in what order etc.) we are going to do that and who is going to do what. Shall we?
Quoted 8 lines
IMO we should start by using the new notifier chain and by implementing a central "icebox" routine. Then we can forbid device registration during suspend.
It might also be a good idea to add a freezable keventd-like workqueue specifically intended for things that need to block during a suspend. Although maybe this will end up being unnecessary; it's too soon to tell.
I think looking at the kmallo/gfp issue I mentioned earlier should be done asap. I can try to spare some time for it this week but I can't promise, I'm actually swamped by something totally unrelated at the moment.
Another issue that's been a problem forever with suspend is the synchronous request_firmware interface. Lots of drivers do that in resume() which will generally not work.
Ben.
Quoted 26 lines · Alan Stern
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Quoted 3 lines
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
And are they?
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Agreed.
Quoted 21 lines
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It's in -mm. The patches queued up in -mm are also in my patchset at
http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.22-rc7/patches/
Quoted 24 lines
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 10 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
Quoted 8 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine?
Yes, I think so.
Quoted 5 lines
Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Hmm, I think this would be functionally equivalent to a modified freezer with the following changes:
(1) the actual freezing functionality is not hooked up to the signal code, but instead there are many invocations of try_to_freeze() all over the place,
(2) the freezer doesn't wait for tasks to freeze, only sets their TIF_FREEZE flags and exits, where TIF_FREEZE now means "there's a suspend in progress, please freeze yourself if need be".
BTW, this is similar to what I'd like to have for kernel threads RSN, except for the "doesn't wait" part.
IMO, something like this might be used for hibernation too, but in that case we need to do something about the tasks that haven't gone to the icebox.
I have some implementation-related questions:
* do we want each task to be notified individually or do we want a global variable, say "pm_entering_sleep_state", that will mean "now you're supposed to go to the icebox"
* at what point exactly this should be activated (ie. before the freezer or after it)
* how do we release tasks from the icebox (all at a time or individually, and if the latter then how exactly).
Quoted 22 lines
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
Quoted 7 lines
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
This last thing is a good idea, IMHO.
Quoted 11 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
I think we should do something like that in the beginning and probably try to add some flexibility later on.
Quoted 27 lines
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a
WARN_ON()indevice_add()would be a good idea.Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 26 lines · Alan Stern
I'll make this reply short by agreeing up front with most of what you say.
Quoted 4 lines · Benjamin Herrenschmidt
But that's only the "main" path. Aside for that, almost all drivers also have sideband "request" input and some driver don't actually live behind a subsystem. That ranges from ioctl, to direct read/write on a char dev from userland.
Yes, these are the problem cases.
Quoted 4 lines
I think many of those cases can fairly well deal with just taking a PM semaphore, that's how I did for a couple of things in the past, provided that the request path isn't deadlocking with the semaphore held because of the system suspending of course.
That's what USB does as well (for the drivers which have runtime PM support -- at the moment only a few of them).
Quoted 5 lines
But in a whole lot of cases, it's, I beleive, perfectly kosher to just return an error. You're trying to capture frame from your camera while the machine is suspended ? error. At worst, your capture app will be unhappy when you wakeup, nothing terrible and totally fixable in userland if it's a problem.
Quoted 3 lines
We can try falling back on this approach for now. If the drivers are smart enough to fail cleanly when the device is already suspended, it should work.
And are they?
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Agreed.
Quoted 21 lines
Quoted 6 lines
In some cases, we could use a little bit more help from the subsystem. Network for example, could have some explicit knowledge of the suspend state, and in addition to stopping the queue would also stop calling into things like
change_mtuorset_multicast, provided it's agreed that the driver will account for those changes on resume (the actual MTU values or multicast lists are still updated in the netdev).This will be up to the people responsible for the subsystems. I can take care of USB.
Quoted 10 lines
There are two things I believe. There's a generic issue with usermode helpers that make no sense to call between pre-suspend and post-resume, and there's the specific issue of adding/removing devices.
I believe that "bus" drivers such as USB should indeed get a first round of notifications to tell them to stop performing bus plug/unplug operations (it's debatable whether we want to keep unplug going provided we can stack up the usermode events and re-send them later though, but let's say no for the sake of simplicity).
Quoted 3 lines
Yes. Rafael, how close is your new notifier chain to mainline? Can it at least be added to Greg KH's development tree so that I can start using it?
It's in -mm. The patches queued up in -mm are also in my patchset at
http://www.sisk.pl/kernel/hibernation_and_suspend/2.6.22-rc7/patches/
Quoted 24 lines
Quoted 11 lines
Quoted 7 lines
So instead, why not have the PM core take care of all this? There could be a
block_task_until_suspend_is_over()routine available for all drivers to use. Its effect would be exactly the same as sending the current task into the freezer, but it wouldn't be the freezer that exists now. It would just be some routine that blocks until the system suspend is over. We could call it "the icebox" instead of "the freezer". :-)I'm not totally sure about that. I like some of it, but I think it's fairly different conceptually from the freezer (and the implementation could be as trivial as a single system wide wait queue).
Exactly.
Quoted 10 lines
Basically it has a very big difference to the current freezer, and I like that, which is that we don't have some 3rd party trying to find out what to freeze and what not (the freezer), but instead, we have explicitely drivers or kernel threads sending -themselves- to the "icebox" when they think it's a good idea. Think of it as lazy freezing -> you only freeze lazy tasks that are trying to do something that cannot be done because of suspend.
Quoted 1 line
Does that make you happier?
Quoted 8 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
That's what I had in mind. Rafael, can we add an "icebox" routine?
Yes, I think so.
Quoted 5 lines
Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Hmm, I think this would be functionally equivalent to a modified freezer with the following changes:
(1) the actual freezing functionality is not hooked up to the signal code, but instead there are many invocations of try_to_freeze() all over the place,
(2) the freezer doesn't wait for tasks to freeze, only sets their TIF_FREEZE flags and exits, where TIF_FREEZE now means "there's a suspend in progress, please freeze yourself if need be".
BTW, this is similar to what I'd like to have for kernel threads RSN, except for the "doesn't wait" part.
IMO, something like this might be used for hibernation too, but in that case we need to do something about the tasks that haven't gone to the icebox.
I have some implementation-related questions:
* do we want each task to be notified individually or do we want a global variable, say "pm_entering_sleep_state", that will mean "now you're supposed to go to the icebox"
* at what point exactly this should be activated (ie. before the freezer or after it)
* how do we release tasks from the icebox (all at a time or individually, and if the latter then how exactly).
Quoted 22 lines
Quoted 9 lines
Quoted 2 lines
Of course, another possibility is simply to fail the bind. But that's not very satisfying, since suspends should be transparent.
I don't think suspend has to be -that- transparent (though there is some debate on whether it should be if we're gonna do some kind of fast "light" suspend for things like OLPC) but overall, I agree that a bind operation on sysfs should probably block until resume, and it does make sense to have the logic to do that in sysfs itself. It could perfectly use the above icebox thingy you came up with.
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
Quoted 7 lines
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.
This last thing is a good idea, IMHO.
Quoted 11 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.Quoted 5 lines
Regarding unbinding, that's debatable, it might be perfectly allright to unbind while suspended, though then, there is the question of a driver being later on bound to a piece of HW that is suspended (though I suppose that could happen today... some machines have their firmware leave some devices off at boot).
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
I think we should do something like that in the beginning and probably try to add some flexibility later on.
Quoted 27 lines
Quoted 6 lines
As a general matter, If we have those pre-suspend/post-resume notifiers and we adapt the few (there isn't that much) bus drivers so that they stop all probe/unprobe operations before the suspend dance starts, we avoid a lot of that problem. At this point, it becomes fair enough for bind/unbind, in the core, to return an error (and maybe even stack trace in dmesg to catch the culprits) while suspend in in progress.
Putting a
WARN_ON()indevice_add()would be a good idea.Quoted 7 lines
Quoted 6 lines
But consider this: By writing the appropriate
sysfs attribute, a user task can cause a workqueue item to be queued to keventd that tries to unregister a device. That really puts you on the
spot: Unregistration can't be allowed to fail, it can't be allowed to succeed during a suspend, and keventd can't be blocked! So what should we do?Quoted 5 lines
We can either stop it at the sysfs write level, or we can have the workqueue task reschedule itself later until we are resumed. In fact, worqueue items being what they are (queue items), we could imagine having a special list where they enqueue themselves to rescheduled after resume.
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
Quoted 8 lines
Quoted 3 lines
Don't get me wrong, I never said we don't need generic infrastructure and utilities, such as your proposed icebox scheme, or some of those workqueue bits, helpers in subsystems, etc...
I hope that everyone will agree that now is a good time to get started on them. There shouldn't be any problem about having them present along with the freezer, and then it will be all that much easier to remove the freezer later on if that's what we decide to do.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Rafael J. Wysocki
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Quoted 5 lines
Quoted 3 lines
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
Quoted 8 lines
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has PF_FROZEN (or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it after device_suspend() (or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Rafael J. Wysocki
On Sunday, 8 July 2007 07:14, Benjamin Herrenschmidt wrote:
[--snip--]Quoted 5 lines
I just think that the freezer approach, as it is, is backward. We can't have a 3rd party try to discriminate what to freeze and what not, it will always get something wrong, and in some cases with the wrong timing or ordering.
Quoted 5 lines
Quoted 3 lines
Nice discussion, except for one thing: the freezer doesn't decide what to freeze. For example, even right now kernel threads decide if they want to be frozen.
Somewhat... userspace doesn't and workqueues are a gray area.
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
Quoted 8 lines
Also, I've been thinking this "icebox" idea a bit more and it seems in fact a bit racy in some areas, at least for use by things like drivers, unless we end up doing something aking to an RCU on suspend, waiting for all tasks to reach userland once, but that has the same annoyances as the current freezer.
Thus I'm tempted to go back to saying that driver can handle things locally :-)
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has PF_FROZEN (or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it after device_suspend() (or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 3 lines · Rafael J. Wysocki
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
That and keventd workqueues... my point is you may well end up with something in a workqueue doing things that should have been blocked after the freeze.
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (stop_machine looks good enough to me).
Ben
Quoted 3 lines · Rafael J. Wysocki
Workqueues are kernel threads and the creator decides if they are going to freeze. There are only two freezable worqueues in the entire tree right now.
That and keventd workqueues... my point is you may well end up with something in a workqueue doing things that should have been blocked after the freeze.
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (stop_machine looks good enough to me).
Ben
Quoted 37 lines · Benjamin Herrenschmidt
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 8 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardwareThose are akin, in some ways, to the freezer races.
I'm not sure what races you're referring to, but never mind. :-)
This is the reason why the freezer waits for tasks to freeze, actually.
Quoted 3 lines
Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland).
This is what the freezer does, isn't it? ;-)
Quoted 3 lines
That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Well, can't we do:
drivers_sysfs_write()
while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's the difference?
hit hardware
unlock_suspend()
where the PM core must wait for the suspend lock to get released (say with a timeout)?
Quoted 36 lines
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 7 lines
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Hmm, perhaps we can use a special workqueue that's created before the suspend (say by the PM core) and starts processing jobs after the resume?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 37 lines · Benjamin Herrenschmidt
Quoted 4 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print errors out, I don't see the problem there. At one point, we'll need a cleaner way to also notify userland in which case our daemon could become more intelligent and stop servicings things before sleep and resume afterward :-)
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
In most cases, that "helper" thing would sit on the client subsystem, since it's the one feeding drivers with requests. The main ones I see at hand are block, alsa, net, fb/drm... Some of them already have infrastructure to do it, some my need some more work.
Quoted 7 lines
Quoted 6 lines
I think it's a fairly significant change from the current freezer and I also think it's a very good idea. The more I think about it, the more I like it, in the sense that it's a simple drop-in that you could put in a lot of the ioctl path of drivers to just block tasks that are trying to call in while suspending, and could be used selectively by things like the USB hub threads.
Quoted 6 lines
That's what I had in mind. Rafael, can we add an "icebox" routine? Like Ben says, it doesn't need to be much more than a waitqueue that the current task puts itself on if a suspend is in progress. Callers arriving at a time when the icebox isn't activated should simply return without blocking. Basically the icebox should be active at the same times as the existing freezer.
Quoted 8 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardwareThose are akin, in some ways, to the freezer races.
I'm not sure what races you're referring to, but never mind. :-)
This is the reason why the freezer waits for tasks to freeze, actually.
Quoted 3 lines
Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland).
This is what the freezer does, isn't it? ;-)
Quoted 3 lines
That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
Well, can't we do:
drivers_sysfs_write()
while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's the difference?
hit hardware
unlock_suspend()
where the PM core must wait for the suspend lock to get released (say with a timeout)?
Quoted 36 lines
Quoted 20 lines
Here's a wacky idea which just might work:
In order to prevent binding and unbinding, while suspending devices all the PM core has to do is avoid dropping the device semaphores! It can release the semaphores as it resumes the devices.
Of course, for this to work it's necessary to avoid changes to the device list during the suspend. However I believe the iteration can be made safe against unregistration, so we only have to prevent device registration. (And anyway, it won't be possible to unregister a device while the PM core is holding its semaphore.)
If we are willing to be somewhat non-transparent, this is easy to accomplish. After the notifier chain has been alerted about the upcoming suspend, we tell the driver core to disallow adding new devices. Maybe use SRCU to synchronize with registration calls that are in progress. Thus, until the suspend is over
device_add()will immediately return an error. We could even add a new ESUSPENDING code toerrno.h; it would come in handy in a few places.Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
Quoted 4 lines
I have had the same thought, that unbinding and unregistration would be easier to handle than binding and registration. As it happens, holding the device semaphore will block both all three -- which makes life simpler.
Yup. Fair and simple.
Quoted 7 lines
Quoted 4 lines
There are other possibilities too. For example, instead of using keventd these attributes could use a separate workqueue which would put itself in the icebox during a suspend. Or maybe sysfs can be reworked so that they don't need to use a workqueue at all.
I think having a facility for a given workqueue entry to requeue itself for after resume might be of use for drivers too.
Hmm, perhaps we can use a special workqueue that's created before the suspend (say by the PM core) and starts processing jobs after the resume?
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Benjamin HerrenschmidtHi!
Quoted 9 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Benjamin HerrenschmidtHi!
Quoted 9 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 7 lines · Pavel Machek
Quoted 7 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
David Lang
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekHi,
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to [email protected]Hi!
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Quoted 7 lines
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to [email protected]Hi!
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Quoted 7 lines
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekHi,
Quoted 9 lines · Pavel Machek
Hi!
Quoted 7 lines
Quoted 6 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the driver due to suspend has
PF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with any task waiting on I/O while the freezer is running ;-)).
Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).
Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi!
Quoted 32 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
Quoted 3 lines
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
Nice summary, thanks.
Quoted 2 lines
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Actually there are _2_ freezer vs FUSE issues, and one of them should be simple to solve, once we have sysrq-t of the deadlock. (Or did I miss it somewhere with discussion going on 10 lists in parallel?)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi!
Quoted 32 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
that's queued up in -mm contains a freezer documentation update, in which the reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for suspend (ie. any transition to a system sleep state other than hibernation), but some of us (eg. me) think that it wouldn't be reasonable to drop the freezer from the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not at this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and the PM core. We also need to do some work on the PM core in order to introduce a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
Quoted 3 lines
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
Nice summary, thanks.
Quoted 2 lines
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
Actually there are _2_ freezer vs FUSE issues, and one of them should be simple to solve, once we have sysrq-t of the deadlock. (Or did I miss it somewhere with discussion going on 10 lists in parallel?)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekQuoted 22 lines · Pavel Machek
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
David Lang
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Pavel MachekQuoted 22 lines · Pavel Machek
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
David Lang
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 34 lines · On Sun 2007-07-08 16:20:46, [email protected] wrote:
Quoted 23 lines · Pavel Machek
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at
least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Quoted 4 lines
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently; second would eat 5-15% of your cpu, permanently. Not very suitable.
Who says current solution is unreliable?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to [email protected]Quoted 34 lines · On Sun 2007-07-08 16:20:46, [email protected] wrote:
Quoted 23 lines · Pavel Machek
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at
least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
Quoted 8 lines
Quoted 3 lines
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Quoted 4 lines
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently; second would eat 5-15% of your cpu, permanently. Not very suitable.
Who says current solution is unreliable?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
Quoted 35 lines · Pavel Machek
Quoted 34 lines · On Sun 2007-07-08 16:20:46, [email protected] wrote:
Quoted 31 lines · Pavel Machek
Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Actaully, I'm perfectly fine with that, as long as each task blocked by the
driver due to suspend hasPF_FROZEN(or something similar) set. Then, at
least theoretically, we'll be able to drop the freezer from the suspend code
path and move it afterdevice_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem with
any task waiting on I/O while the freezer is running ;-)).Quoted 7 lines
Quoted 2 lines
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Quoted 7 lines
instead of trying to freeze most of the system, could you do something like start a virtual machine sandbox to write the data out, and not let any userspace other then the sandbox operate?
you would need to throw away disk buffers so that you don't mix current pending I/O with I/O from the sandbox, and this would be a visable change for how suspend is setup, but wouldn't this work?
It feels kind of expensive, but yes, we could use another kernel for doing the dump. Kdump people are using that. We could use hypervisor for doing the dump. Xen people are doing that. (But I do not think any of those solutions is suitable for "lets hibernate my notebook" case).
Quoted 7 lines
Quoted 4 lines
expensive and reliable beats efficiant and unrelaible.
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently; second would eat 5-15% of your cpu, permanently. Not very suitable.
how much overlap is there between the two approaches? are they close enough to be able to give the user the choice of which to use depending on their machine (new machines with the hardware virtualization support may want the hypervisor, other hardware may want to sacrafice 8M of ram)
Quoted 1 line
Who says current solution is unreliable?
users report problems, suspend* developers repeatedly state that the problems are that the rest of the kernel needs to be fixed to work properly with the existing approach.
I think it's safe to say that it doesn't work in the general case, even though it does work in some specific cases.
David Lang
Quoted 10 lines
drivers_sysfs_write()while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's the difference?hit hardware
unlock_suspend()where the PM core must wait for the suspend lock to get released (say with a timeout)?
Somewhat. What I'd like is to have that a construct of that sort on a per-driver basis though :-) Now the question is, in what way would the above be different from a simple suspend mutex ? I've been using mutexes in the past for a couple of drivers (iirc, that's how I did it for dmasound_pmac, though that driver is long past obsolescence now).
But yes, that's the idea, something under control of drivers, instead of a 3rd party freezer that tries to hit at processes.
Quoted 2 lines
Hmm, perhaps we can use a special workqueue that's created before the suspend (say by the PM core) and starts processing jobs after the resume?
Yeah, whatever the implementation is, though, the interface should be transparent. But then, I see little use of that. Mostly things like this sysfs write to unbind Alan was talking about. Driver workqueues probably need to be functioning all the way until the driver itself is suspended, in which case, the driver may just flush_worqueues in it's suspend path at the right time to make sure it doesn't exit with something still pending.
Ben.
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines
drivers_sysfs_write()while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's thedifference?
hit hardware
unlock_suspend()where the PM core must wait for the suspend lock to get released (say with a timeout)?
Somewhat. What I'd like is to have that a construct of that sort on a per-driver basis though :-) Now the question is, in what way would the above be different from a simple suspend mutex ? I've been using mutexes in the past for a couple of drivers (iirc, that's how I did it for
dmasound_pmac, though that driver is long past obsolescence now).
I agree completely. It's a bit trickier if you want to do work in uninterruptable contexts:
driver_suspend_callback(...)
{
dev_suspend_lock(dev);
put_hardware_to_sleep(dev);
}driver_resume_callback(...)
{
wake_hardware_up(dev);
dev_suspend_unlock(dev);
}Then for sleep-capable contexts:
dev_suspend_lock(dev); dev_suspend_unlock(dev);
And for no-sleep contexts like interrupts etc:
if (!dev_suspend_trylock(dev)) return postpone_work_for_later(dev, ...); do_stuff_with(dev); dev_suspend_unlock(dev);
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Then when you put your driver to sleep, things trying to do IO will automatically "freeze" themselves exactly until the device is woken again.
Assuming the driver model and subsystem get the ordering right for which devices to suspend/resume, then it's impossible to deadlock or cause hardware confusion. And even further, if you manage to make the automagic mutex-debugging code work with the noninterruptable trylock it will yell at you when the driver model does nasty deadlock-y things.
On the other hand, if the driver model *doesn't* get the ordering right then it's fundamentally impossible to reliably suspend and resume.
Cheers,
Kyle Moffett
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines
drivers_sysfs_write()while(!suspend_trylock()) try_to_icebox() --> or even try_to_freeze(), what's thedifference?
hit hardware
unlock_suspend()where the PM core must wait for the suspend lock to get released (say with a timeout)?
Somewhat. What I'd like is to have that a construct of that sort on a per-driver basis though :-) Now the question is, in what way would the above be different from a simple suspend mutex ? I've been using mutexes in the past for a couple of drivers (iirc, that's how I did it for
dmasound_pmac, though that driver is long past obsolescence now).
I agree completely. It's a bit trickier if you want to do work in uninterruptable contexts:
driver_suspend_callback(...)
{
dev_suspend_lock(dev);
put_hardware_to_sleep(dev);
}driver_resume_callback(...)
{
wake_hardware_up(dev);
dev_suspend_unlock(dev);
}Then for sleep-capable contexts:
dev_suspend_lock(dev); dev_suspend_unlock(dev);
And for no-sleep contexts like interrupts etc:
if (!dev_suspend_trylock(dev)) return postpone_work_for_later(dev, ...); do_stuff_with(dev); dev_suspend_unlock(dev);
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Then when you put your driver to sleep, things trying to do IO will automatically "freeze" themselves exactly until the device is woken again.
Assuming the driver model and subsystem get the ordering right for which devices to suspend/resume, then it's impossible to deadlock or cause hardware confusion. And even further, if you manage to make the automagic mutex-debugging code work with the noninterruptable trylock it will yell at you when the driver model does nasty deadlock-y things.
On the other hand, if the driver model *doesn't* get the ordering right then it's fundamentally impossible to reliably suspend and resume.
Cheers,
Kyle Moffett
Quoted 7 lines
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Most of the time, the interrupt/atomic contexts are part of what I call the "main path" of the driver, which doesn't need most of this stuff.
Depending on what is "upstream" from the driver, you typically set a condition stopping the flow of "interrupt" activity and wait for it to drain in suspend. For example, a block driver would instruct the driver to stop processing the request queue and wait for pending in flight requests to drain, or a network driver would stop the tx queue and wait for pending/concurrent xmit() callbacks to complete (basically sync. bh and sync. with NAPI poll).
In both examples, helpers can be provided in the block layer or network stack to make that easier.
In many cases, the driver may just turn off something in the chip in "suspend" (using a low level spinlock that it already has if it has an irq path to sync. HW access) and set some flag/state to instruct the irq handler to not restart, then synchronize_irq().
All those techniques are fairly simple and well known. The main source of problems are the "sideband" channels, such as sysfs accesses to driver tunables, ioctl's, etc... for which I believe mutexes can solve 90% of them.
Ben.
Quoted 7 lines
You could do this with a straight mutex except for the dev_suspend_trylock/unlock bit in uninterruptable contexts, but I seem to recall somebody saying that could be made to work if there was a real need for it. Alternatively you could just drive the "Generic Mutex" guys up the wall by inventing your own pseudo-mutex with a spinlock, a boolean value, and a waitqueue.
Most of the time, the interrupt/atomic contexts are part of what I call the "main path" of the driver, which doesn't need most of this stuff.
Depending on what is "upstream" from the driver, you typically set a condition stopping the flow of "interrupt" activity and wait for it to drain in suspend. For example, a block driver would instruct the driver to stop processing the request queue and wait for pending in flight requests to drain, or a network driver would stop the tx queue and wait for pending/concurrent xmit() callbacks to complete (basically sync. bh and sync. with NAPI poll).
In both examples, helpers can be provided in the block layer or network stack to make that easier.
In many cases, the driver may just turn off something in the chip in "suspend" (using a low level spinlock that it already has if it has an irq path to sync. HW access) and set some flag/state to instruct the irq handler to not restart, then synchronize_irq().
All those techniques are fairly simple and well known. The main source of problems are the "sideband" channels, such as sysfs accesses to driver tunables, ioctl's, etc... for which I believe mutexes can solve 90% of them.
Ben.
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than -ERESTARTSYS is not an option. We can't simply change the ABI.
Regards
Oliver
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than -ERESTARTSYS is not an option. We can't simply change the ABI.
Regards
Oliver
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.
Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
Regards
Oliver
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.
Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
Regards
Oliver
Quoted 10 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than
-ERESTARTSYSis not an option. We can't simply change the ABI.
Ugh ? Why returning an error from the printer driver to the userland print server/daemon would prevent the machine from "surviving" ? I would be happy with -EIO personally :-)
Ben.
Quoted 5 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.
Quoted 7 lines
Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
True, pre-loading is the best approach.
Ben.
Am Montag, 9. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 8 lines · Oliver Neukum
Quoted 7 lines
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Quoted 7 lines
Quoted 3 lines
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than
-ERESTARTSYSis not an option. We can't simply change the ABI.Ugh ? Why returning an error from the printer driver to the userland print server/daemon would prevent the machine from "surviving" ? I would be happy with
-EIOpersonally :-)
Surviving is a bit strongly worded.
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Regards
Oliver
Am Montag, 9. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 8 lines · Oliver Neukum
Quoted 7 lines
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
Quoted 7 lines
Quoted 3 lines
Not necessarily. The machine must survive going to sleep while you are printing. Any other error return than
-ERESTARTSYSis not an option. We can't simply change the ABI.Ugh ? Why returning an error from the printer driver to the userland print server/daemon would prevent the machine from "surviving" ? I would be happy with
-EIOpersonally :-)
Surviving is a bit strongly worded.
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Regards
Oliver
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Rafael J. WysockiQuoted 5 lines
Please have a look at the documentation update at the bottom of this patch:
It says what the freezer is for in the first place. :-)
Thanks, good description.
Quoted 7 lines
Quoted 3 lines
Yes, we need to make sure, that nothing is scheduled during (and possibly after) taking the snapshot. But AFAICS that could be achieved by unplugging all but one CPU.
Actually, we want things to get scheduled, because we need some of them to save the image (to make things more difficult, we don't know what will be needed to save the image in advance ;-)).
Well, kexecing a new kernel (as being pursued in one of the subthreads) to do the saving should take care of that.
In that case the "we need suspend to be invisible to userspace" as a reason to use the freezer would also be moot, since if you don't schedule userspace after offlining the CPUs, it can't notice this.
Miklos
Quoted 3 lines · Oliver Neukum
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Who says ?
If I'm talking to a USB printer, it will notice the USB bus being suspended, believe me. It's actually likely to screw up whatever job is in progress. It make perfect sense to error out attempts to talk to it when suspended.
I don't think "transparent" is an absolute requirement. In some cases, it doesn't make sense and the printer is a good example of that. The printing daemon is typically something that will ideally need to grow knowledge about suspend/resume to interrupt things at the right time.
That's one of the thing... we don't even have the kernel right, so we are light-years from having the rest of userland right.
For example, from a user point of view, what should happen if you suspend while printing ?
Well, it's a matter of policy (thus should be configurable), but I would exect (as a former Mac user) something around the lines of this as a default:
- If the laptop's clamshell has been closed, it's likely that the
user's just picking up the laptop for a ride, makes sense to abort jobs in progress.
- If this is a manual action via the menus, displaying a dialog asking
if you really want to suspend before your page is finished makes sense (with that dialog disappearing and the machine going to sleep if you just wait and let it print).
That sort of thing requires much more than just kernel collaboration of course, but a whole infrastructure in userland as well.
So no, suspend is -not- transparent, doesn't have to be, it's something that is to be decided on a case-by-case basis (or rather, driver-per-driver and possibly via policy settings).
Ben.
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediAm Montag, 9. Juli 2007 schrieb Miklos Szeredi:
Quoted 3 lines
In that case the "we need suspend to be invisible to userspace" as a reason to use the freezer would also be moot, since if you don't schedule userspace after offlining the CPUs, it can't notice this.
After? Can you do the offlining atomically?
Regards
Oliver
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediAm Montag, 9. Juli 2007 schrieb Miklos Szeredi:
Quoted 3 lines
In that case the "we need suspend to be invisible to userspace" as a reason to use the freezer would also be moot, since if you don't schedule userspace after offlining the CPUs, it can't notice this.
After? Can you do the offlining atomically?
Regards
Oliver
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
Quoted 5 lines
Quoted 3 lines
In that case the "we need suspend to be invisible to userspace" as a reason to use the freezer would also be moot, since if you don't schedule userspace after offlining the CPUs, it can't notice this.
After? Can you do the offlining atomically?
Don't know. Wait for all CPUs to reach a scheduling point and then take them offline? Doesn't sound too difficult.
Miklos
Hi!
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Why not ? Printer is offline when machine is asleep... trying to print
...filesystems are offline, too, when the machine is asleep. Yet, unmounting everything on suspend would not result in useful suspend support.
Yes, I believe we should be transparent.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 6 lines · Pavel Machek
Hi!
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
But I'm not sure it's a good idea in the long run. Think of a printer daemon, for example. It shouldn't have to experience unexpected I/O problems merely because someone has decided to put the system to sleep.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Why not ? Printer is offline when machine is asleep... trying to print
...filesystems are offline, too, when the machine is asleep. Yet, unmounting everything on suspend would not result in useful suspend support.
Yes, I believe we should be transparent.
You just compared apple and oranges... Try printing and half way through the page, suspend your USB bus, and see how the printer reacts.
Ben.
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Quoted 5 lines
Quoted 3 lines
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
True, pre-loading is the best approach.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Oliver Neukum
Am Sonntag, 8. Juli 2007 schrieb Benjamin Herrenschmidt:
Quoted 3 lines
Another issue that's been a problem forever with suspend is the synchronous
request_firmwareinterface. Lots of drivers do that inresume()which will generally not work.Unfortunately yes they do. We now have the notifier chains, which can be used. Firmware, especially if it is large, must be requested while the system is still fully functional and paging will work.
Quoted 5 lines
Quoted 3 lines
Asynchronocity will not help much because the devices must work after resumingand delaying that will not help with respect to needing devices to get at the firmware.
True, pre-loading is the best approach.
Agreed.
Greetings,
Rafael
Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
sysrq-t dumps of s2ram/fuse deadlock (was Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Rafael J. WysockiHi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
Matthew, you seem to be the only one able to produce them...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 17 lines · Benjamin Herrenschmidt
Quoted 3 lines · Oliver Neukum
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Who says ?
If I'm talking to a USB printer, it will notice the USB bus being suspended, believe me. It's actually likely to screw up whatever job is in progress. It make perfect sense to error out attempts to talk to it when suspended.
I don't think "transparent" is an absolute requirement. In some cases, it doesn't make sense and the printer is a good example of that. The printing daemon is typically something that will ideally need to grow knowledge about suspend/resume to interrupt things at the right time.
Quoted 5 lines
That's one of the thing... we don't even have the kernel right, so we are light-years from having the rest of userland right.
For example, from a user point of view, what should happen if you suspend while printing ?
There might be other existing things with a semantics that might be worth looking at, e.g.:
I don't have an USB printer, but what happens if you unplug the printer while printing, wait 30 seconds, and plug it in again?
Wait 3 hours?
Could this work theoretically?
Does it work in practice?
This are non-theoretical use cases kernel and userspace already somehow handle today, and for userspace an USB printer disconnected for 3 hours and a 3 hour suspend might simply be the same with the latter not requiring any extra userspace handling.
Another example might be mounted NFS file systems:
The case that a client's ethernet cable gets unplugged for 24 hours and plugged in again is a real life use case NFS and all applications already have to handle.
Quoted 13 lines
Well, it's a matter of policy (thus should be configurable), but I would exect (as a former Mac user) something around the lines of this as a default:
- If the laptop's clamshell has been closed, it's likely that the
user's just picking up the laptop for a ride, makes sense to abort jobs in progress.- If this is a manual action via the menus, displaying a dialog asking
if you really want to suspend before your page is finished makes sense (with that dialog disappearing and the machine going to sleep if you just wait and let it print).
Quoted 6 lines
That sort of thing requires much more than just kernel collaboration of course, but a whole infrastructure in userland as well.
So no, suspend is -not- transparent, doesn't have to be, it's something that is to be decided on a case-by-case basis (or rather, driver-per-driver and possibly via policy settings).
But keep in mind that every piece that does not work transparently might result in less use cases for suspend.
There are cases like CD burning while suspending that might not be solvable, but as much as possible should work as transparently as possible.
Quoted 1 line
Ben.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 17 lines · Benjamin Herrenschmidt
Quoted 3 lines · Oliver Neukum
Suspension is to be transparent. Apart from a jump in the system clock user space must not notice, thus returning errors due to suspension is not an option.
Who says ?
If I'm talking to a USB printer, it will notice the USB bus being suspended, believe me. It's actually likely to screw up whatever job is in progress. It make perfect sense to error out attempts to talk to it when suspended.
I don't think "transparent" is an absolute requirement. In some cases, it doesn't make sense and the printer is a good example of that. The printing daemon is typically something that will ideally need to grow knowledge about suspend/resume to interrupt things at the right time.
Quoted 5 lines
That's one of the thing... we don't even have the kernel right, so we are light-years from having the rest of userland right.
For example, from a user point of view, what should happen if you suspend while printing ?
There might be other existing things with a semantics that might be worth looking at, e.g.:
I don't have an USB printer, but what happens if you unplug the printer while printing, wait 30 seconds, and plug it in again?
Wait 3 hours?
Could this work theoretically?
Does it work in practice?
This are non-theoretical use cases kernel and userspace already somehow handle today, and for userspace an USB printer disconnected for 3 hours and a 3 hour suspend might simply be the same with the latter not requiring any extra userspace handling.
Another example might be mounted NFS file systems:
The case that a client's ethernet cable gets unplugged for 24 hours and plugged in again is a real life use case NFS and all applications already have to handle.
Quoted 13 lines
Well, it's a matter of policy (thus should be configurable), but I would exect (as a former Mac user) something around the lines of this as a default:
- If the laptop's clamshell has been closed, it's likely that the
user's just picking up the laptop for a ride, makes sense to abort jobs in progress.- If this is a manual action via the menus, displaying a dialog asking
if you really want to suspend before your page is finished makes sense (with that dialog disappearing and the machine going to sleep if you just wait and let it print).
Quoted 6 lines
That sort of thing requires much more than just kernel collaboration of course, but a whole infrastructure in userland as well.
So no, suspend is -not- transparent, doesn't have to be, it's something that is to be decided on a case-by-case basis (or rather, driver-per-driver and possibly via policy settings).
But keep in mind that every piece that does not work transparently might result in less use cases for suspend.
There are cases like CD burning while suspending that might not be solvable, but as much as possible should work as transparently as possible.
Quoted 1 line
Ben.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedRe: hibernation/snapshot design
In reply to Pavel MachekPavel Machek <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 2 lines
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently;
As I have stated in other messages, the kdump approach would not waste any RAM permanently. The reason that kdump must reserve memory at boot is that on panic, it cannot attempt to nicely stop drivers, and consequently there might be ongoing DMAs that could clobber anything but the reserved area; this reason does not apply to hibernate, though. I'll quote a previous message in which I stated a solution that can be used:
Immediately before jumping to the new kernel, the first X bytes (where X is the amount of memory the new kernel will get, typically 16MB or 64MB) of physical memory are backed up into the arbitrary discontiguous pages that are made available. This will not take very long, because copying even 64MB of memory is extremely fast. Then the new kernel is free to use the first X bytes of contiguous physical memory. Problem solved.
Signature · 1 line
Jeremy Maitin-Shepard
Re: hibernation/snapshot design
In reply to Pavel MachekPavel Machek <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 2 lines
why do you say that neither would work for the "lets hibernate my notebook" case?
Both would work. One would eat 8-64MB of your RAM, permanently;
As I have stated in other messages, the kdump approach would not waste any RAM permanently. The reason that kdump must reserve memory at boot is that on panic, it cannot attempt to nicely stop drivers, and consequently there might be ongoing DMAs that could clobber anything but the reserved area; this reason does not apply to hibernate, though. I'll quote a previous message in which I stated a solution that can be used:
Immediately before jumping to the new kernel, the first X bytes (where X is the amount of memory the new kernel will get, typically 16MB or 64MB) of physical memory are backed up into the arbitrary discontiguous pages that are made available. This will not take very long, because copying even 64MB of memory is extremely fast. Then the new kernel is free to use the first X bytes of contiguous physical memory. Problem solved.
Signature · 1 line
Jeremy Maitin-Shepard
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
That's why I thought I would be able to handle it! :-)
Quoted 7 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Quoted 6 lines
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
It depends on what kind of race you're worried about. In general a sysfs access that causes I/O isn't much different from a char device's read or write. For such cases the driver would have to do something like this:
drivers_sysfs_write()
{
restart:
mutex_lock(private_io_mutex);
if (device is suspended) {
mutex_unlock(private_io_mutex);
icebox();
goto restart;
}
... hit hardware ...
mutex_unlock(private_io_mutex);
}And of course the suspend method would have to acquire the private_io_mutex. Some drivers might be able to use the device semaphore instead of adding a new mutex.
I'm more concerned about races involving device registration. The best solution I can come up with is to use an rwsem:
drivers_sysfs_write()
{
down_read(private_rwsem);
... register/unregister devices ...
up_read(private_rwsem);
}where the suspend notifer callout would do down_write() and the resume callout would do up_write(). Can you suggest anything better?
Quoted 8 lines
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
-ESUSPENDING would naturally imply that the caller should retry after the resume.
Alan Stern
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines
This will be up to the people responsible for the subsystems. I can take care of USB.
USB is not that much of a problem in the sense that for most "leaf" drivers, USB is a provider (ie, the bus they sit on), not the client (like the network stack is to network drivers).
That's why I thought I would be able to handle it! :-)
Quoted 7 lines
There is still the race of:
drivers_sysfs_write() try_to_icebox() <---- <sleep request gets here> hit hardware
Quoted 6 lines
Those are akin, in some ways, to the freezer races. Some kind of RCU might take care of them if we enable the icebox, then wait for all tasks to hit an explicit schedule point once (or return to userland). That would mean that drivers need to
try_to_icebox()again if they do something that may schedule (such as__get_user). So it's not a magic solution, it has issues, but it can handle a lot of the simplest cases.
It depends on what kind of race you're worried about. In general a sysfs access that causes I/O isn't much different from a char device's read or write. For such cases the driver would have to do something like this:
drivers_sysfs_write()
{
restart:
mutex_lock(private_io_mutex);
if (device is suspended) {
mutex_unlock(private_io_mutex);
icebox();
goto restart;
}
... hit hardware ...
mutex_unlock(private_io_mutex);
}And of course the suspend method would have to acquire the private_io_mutex. Some drivers might be able to use the device semaphore instead of adding a new mutex.
I'm more concerned about races involving device registration. The best solution I can come up with is to use an rwsem:
drivers_sysfs_write()
{
down_read(private_rwsem);
... register/unregister devices ...
up_read(private_rwsem);
}where the suspend notifer callout would do down_write() and the resume callout would do up_write(). Can you suggest anything better?
Quoted 8 lines
Quoted 4 lines
Drivers are already prepared for device registration to fail (or they ought to be), so this change shouldn't knock the bottom out of things.
device_add()isn't on a hot path, so adding an extra check andsrcu_read_lock()won't hurt.True. Also, bus drivers could just flag the port with something saying "try registering again later". Don't underestimate the power of "try later" constructs :-)
-ESUSPENDING would naturally imply that the caller should retry after the resume.
Alan Stern
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Pavel MachekQuoted 13 lines
Quoted 6 lines
Quoted 2 lines
We can just wait for all fuse requests to be serviced before proceeding further with freeze, right?
Right. Nice way to slow down or stop the suspend with an unprivileged process. Avoiding that sort of DoS is one of the design goals of fuse.
So you want me to handle _malicious_ filesystems now?
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
Quoted 6 lines
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Not ideal, but neither is allowing malicious filesystems in the first place...
Actually there's also a non-malicious case in which waiting for requests to finish won't work: when one fuse filesystem is accessing another.
Since we are blocking new fuse requests, that might block a fuse daemon, which in turn makes it impossible to finish the pending request.
And this is not at all theoretical, I know that encfs is used over various other fuse filesystems like sshfs or ntfs-3g.
Yeah, stacking userspace filesystems could be done entirely in userspace, and I'm actually working on that (with fuse-2.7.0 already supporting some basic stacking).
But the point is, that the "wait for fuse to quiescence" hack would not work in todays environment.
Miklos
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi.
Quoted 6 lines · On Monday 09 July 2007 09:01:27 Rafael J. Wysocki wrote:
Hi,
Quoted 3 lines · Pavel Machek
Hi!
Quoted 1 line
Quoted 1 line
Actaully, I'm perfectly fine with that, as long as each task blocked
by the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
driver due to suspend has
PF_FROZEN(or something similar) set. Then,
at
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
least theoretically, we'll be able to drop the freezer from the
suspend code
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
path and move it after
device_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem
with
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Quoted 10 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
Quoted 2 lines
that's queued up in -mm contains a freezer documentation update, in which
the
Quoted 5 lines
reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for
suspend
Quoted 1 line
(ie. any transition to a system sleep state other than hibernation), but
some
Quoted 1 line
of us (eg. me) think that it wouldn't be reasonable to drop the freezer
from
Quoted 5 lines
the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not
at
Quoted 4 lines
this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and
the
Quoted 1 line
PM core. We also need to do some work on the PM core in order to
introduce
Quoted 9 lines
a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
(Finally catching up on emails since Saturday!)
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Rafael J. WysockiHi.
Quoted 6 lines · On Monday 09 July 2007 09:01:27 Rafael J. Wysocki wrote:
Hi,
Quoted 3 lines · Pavel Machek
Hi!
Quoted 1 line
Quoted 1 line
Actaully, I'm perfectly fine with that, as long as each task blocked
by the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
driver due to suspend has
PF_FROZEN(or something similar) set. Then,
at
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
least theoretically, we'll be able to drop the freezer from the
suspend code
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
path and move it after
device_suspend()(or the hibernation-specific equivalent) for hibernation (in that case there shouldn't be a problem
with
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
any task waiting on I/O while the freezer is running ;-)).
I don't see the need for a freezer for snapshot but that's a different issue. (
stop_machinelooks good enough to me).
Quoted 10 lines
Quoted 4 lines
Freezer is not needed for snapshot -- it is needed so that we can write out the snapshot to disk without the need for special
drivers/block/simple-ide-for-suspend.c. (We are doing snapshot, then write to disk from userland code in uswsusp).Yes.
BTW, this patch:
Quoted 2 lines
that's queued up in -mm contains a freezer documentation update, in which
the
Quoted 5 lines
reasons of using it, as well as its limitations, are described.
To summarize what was previously said in this thread:
* Apparently, we agree that the freezer is _generally_ not needed for
suspend
Quoted 1 line
(ie. any transition to a system sleep state other than hibernation), but
some
Quoted 1 line
of us (eg. me) think that it wouldn't be reasonable to drop the freezer
from
Quoted 5 lines
the suspend code path _right_ _now_ .
* Some of us, including you, Nigel and me, think that the freezer is needed for hibernation (please see the document in the patch above for details). In the (very) long run this might be avoided too, but (IMO) certainly not
at
Quoted 4 lines
this point.
* We seem to agree that in order to remove the freezer from the suspend code path some work needs to be done on device drivers, driver midlayers and
the
Quoted 1 line
PM core. We also need to do some work on the PM core in order to
introduce
Quoted 9 lines
a separate hibernation framework and IMO it would be reasonable to synchronize these efforts.
* We are now to decide what to do so that the freezer can be safely removed from the suspend code path and how to integrate that change with the hibernation code path (if possible and reasonable).
* The freezer vs FUSE issue that started this thread remains unresolved, so it would be desirable to provide a short-term fix (need not be very nice).
(Finally catching up on emails since Saturday!)
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Re: Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Nigel CunninghamQuoted 1 line · Nigel Cunningham
(Finally catching up on emails since Saturday!)
Yes, I know what you mean; I was occupied with other work stuff on Friday and not well on Saturday, and by that stage there was a backlog of about 500 emails for me to wade through... :/
Quoted 4 lines
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Sure. As I pointed out in another email, it's unrealistic to expect the freezer to be able to stop everything in a state where any arbitrary mutex is free. But as long as you don't need to do anything that depends on getting a mutex while the system is frozen, there should be no problem.
Paul.
Re: [linux-pm] Re: hibernation/snapshot design [was Re: [PATCH] Remove process freezer from suspend to RAM pathway]
In reply to Nigel CunninghamQuoted 1 line · Nigel Cunningham
(Finally catching up on emails since Saturday!)
Yes, I know what you mean; I was occupied with other work stuff on Friday and not well on Saturday, and by that stage there was a backlog of about 500 emails for me to wade through... :/
Quoted 4 lines
The freezer is also essential for doing a full image of memory - you have to be able to guarantee that some of the image won't change in order to be able to write it out before the atomic copy. Of course the freezer alone isn't enough, but it solves 95% of the issue.
Sure. As I pointed out in another email, it's unrealistic to expect the freezer to be able to stop everything in a state where any arbitrary mutex is free. But as long as you don't need to do anything that depends on getting a mutex while the system is frozen, there should be no problem.
Paul.
Hi.
Sorry for the long delay. Busy weekend and my motivation for working on programming is almost zero at the moment...
Quoted 29 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Quoted 20 lines · Nigel Cunningham
Quoted 19 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 10 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
Quoted 5 lines
Quoted 2 lines
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
Quoted 7 lines
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a non-
trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.
Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Quoted 2 lines
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed? Why stop them in the first place?
Quoted 7 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.
Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 13 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep- handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
Quoted 8 lines
(d) Use IPMIs again to get all the CPUs together, which should be
easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an atomic
snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too. That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory allocated
during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).
You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Quoted 4 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the read-
only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().
Readonly halves? I don't get that, sorry.
Quoted 4 lines
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Quoted 10 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
Quoted 10 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel memory
and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Hi.
Sorry for the long delay. Busy weekend and my motivation for working on programming is almost zero at the moment...
Quoted 29 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Quoted 20 lines · Nigel Cunningham
Quoted 19 lines · On Friday 06 July 2007 13:54:15 Benjamin Herrenschmidt wrote:
Quoted 10 lines · Nigel Cunningham
Nice try :) Okay then, you remove the freezer, try hibernating, then get back to me after you've fixed your filesystem because some process that wasn't frozen started writing things after the atomic copy (making the on disk filesystem inconsistent with the snapshot).
As Pavel rightly said, you can get rid of the freezer, but you're only going to have to implement another one that does the essentially the same thing, even if it is at some other level.
I was mostly talking about STR... Regarding STD, we have a different problem and we all know it. The freezer is one somewhat horrible way to get it working for now, I would prefer something more along the way that blocks the page cache from writing out new dirty pages though, except those specifically flagged by the snapshot.
Quoted 5 lines
Quoted 2 lines
That is, some kind of proper snapshotting facility, as linus was describing some time ago.
The kind of thing Linus was talking about would limit you (as swsusp and uswsusp do now) to only half the amount of memory.
How so? Suppose hibernate is implemented like this:
Quoted 7 lines
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a non-
trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.
Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Quoted 2 lines
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed? Why stop them in the first place?
Quoted 7 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.
Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 13 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep- handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
Quoted 8 lines
(d) Use IPMIs again to get all the CPUs together, which should be
easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an atomic
snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too. That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory allocated
during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).
You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Quoted 4 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the read-
only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().
Readonly halves? I don't get that, sorry.
Quoted 4 lines
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Quoted 10 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
Quoted 10 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel memory
and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
Regards,
Nigel
Signature · 2 lines
See http://www.tuxonice.net for Howtos, FAQs, mailing lists, wiki and bugzilla info.
Thanks for the detailed reply!
Quoted 11 lines · Nigel Cunningham
Quoted 8 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Suppose hibernate is implemented like this:
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a
non-trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
The reason it's _required_ to be done from userspace is that userspace is the only one which can figure out "These processes need to run for suspend to work", and then let those processes continue running after the freeze. The *ONLY* reason this even stops processes at all is so we can do the post-device-mapper-snapshot code with very little usably-free RAM (IE: only about 1MB for a standard desktop system).
Quoted 1 line
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Well, you *do* want it to have semi-signal semantics, processes which receive it must not get back to userspace code so that they don't start allocating more memory when we're trying to do the freeze. You also don't want a process to be able to trap it (IE: like SIGSTOP or SIGKILL).
On the other hand, it should be delivered asynchronously (IE: It doesn't break an interruptable sleep or respond to most is-a-signal-present checks). You don't actually care if its sleeping in the kernel somewhere, just as long as it doesn't allocate much memory.
You would probably need a new signal "SIGFREEZE" which causes the process to be ignored as runnable the next time they schedule but never actually gets delivered, and a "SIGUNFREEZE" which does the reverse. That way userspace could selectively resume processes based on its policy of "this needs to run for hibernation".
Quoted 3 lines
Quoted 1 line
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed?
It's userspace's job to know which ones are needed. For example, if you are hibernating over NFS then you need to resume the various NFS/RPC daemons and threads.
Quoted 1 line
Why stop them in the first place?
So they aren't allocating memory when we are doing the device-mapper snapshot.
Quoted 18 lines
Quoted 3 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 11 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep-handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
(d) Use IPMIs again to get all the CPUs together, which should
be easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an
atomic snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Quoted 1 line
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too.
It may be simpler, but it really screws up things like cpusets, processor affinity, etc. It also ties hibernation to the presently very-flakey CPU-hotplug support, which is probably not what we want.
Quoted 1 line
That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
IMHO if the user pulls a CPU while the box is hibernated, then he/she gets what he/she deserves. If you really want to support that, then the user must do the hotplug operation *manually* before suspending. Anything else is just going to be shooting ourselves in the foot repeatedly.
Quoted 1 line
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
You could pretty easily have a spare 128MB swap partition somewhere which is not used during system operation but is "swapon"ed by userspace after the COW snapshot to provide extra backing store.
Quoted 8 lines
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory
allocated during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Who says we have to use this swap to write the image? That may be the default use-case, but it's certainly shouldn't be mandatory. Really, for the write-image-to-swap case you would just need to preallocate sufficient memory for the bmap tables beforehand, then populate them at this phase.
Quoted 5 lines
Quoted 3 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the
read-only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().Readonly halves? I don't get that, sorry.
Well, each page is copy-on-write, so the FD reference would always provide access to the original page data, whereas the processes may end up copying the page so they can write to it. The trick would be that shared pages need to remain shared between processes even after the copy-on-write. This is likely to be the trickiest part.
Quoted 3 lines
Quoted 1 line
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Yes, but at this point we're basically running a segment of userspace with full kernel services available. Like I said above we can just add a dedicated 128MB swap device to provide some spare backing store. When you start running low on memory it might even page out to the swap device a part of the atomic copy of kernel memory.
Quoted 5 lines
Quoted 3 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
No, but a kernel write to a DM-snapshot calls the DM-snapshot code which copies the segment(s) to the snapshot device and modifies them there. Basically disk-filesystem pagecache pages would be synced and protected by the DM snapshot, while anonymous memory pages would be CoW-ed. And it might not be an unreasonable requirement to state that the disk-based filesystems must all be mapped through DM-snapshot devices (even just straight 1:1 linear mappings), so that they can be trivially snapshotted.
Quoted 10 lines
Quoted 8 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel
memory and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
I suppose you could record swap-outs done to SIGFREEZEd processes specially, so that they would be swapped in again before resuming userspace. That would effectively result in the same thing.
Cheers,
Kyle Moffett
Thanks for the detailed reply!
Quoted 11 lines · Nigel Cunningham
Quoted 8 lines · On Friday 06 July 2007 15:01:48 Kyle Moffett wrote:
Suppose hibernate is implemented like this:
(1) Userspace program calls
sys_freeze_processes()
(a) Pokes all CPUs with IPMIs and tells them to finish the
currently running timeslot then stop
(b) Atomically sends SIGSTOP to all userspace processes in a
non-trappable way, except the calling process and any process which is ptracing it.
(c) Returns to the calling process.Ok. First, I'll ignore the specification that userspace does this - I don't think it matters whether it's userspace or kernel that does the suspending and I'm yet to see a good reason for it to be [required to be] done from userspace.
The reason it's _required_ to be done from userspace is that userspace is the only one which can figure out "These processes need to run for suspend to work", and then let those processes continue running after the freeze. The *ONLY* reason this even stops processes at all is so we can do the post-device-mapper-snapshot code with very little usably-free RAM (IE: only about 1MB for a standard desktop system).
Quoted 1 line
In this first step, you've reinvented the first part of the current freezer implementation. The reason we don't use a real signal is precisely so we can have an untrappable SIGSTOP. In this regard, I particularly remember Win4Lin from a few years ago. It would die if you sent it a real signal, so we had to do it this way. No doubt there are other instances I'm not aware of.
Well, you *do* want it to have semi-signal semantics, processes which receive it must not get back to userspace code so that they don't start allocating more memory when we're trying to do the freeze. You also don't want a process to be able to trap it (IE: like SIGSTOP or SIGKILL).
On the other hand, it should be delivered asynchronously (IE: It doesn't break an interruptable sleep or respond to most is-a-signal-present checks). You don't actually care if its sleeping in the kernel somewhere, just as long as it doesn't allocate much memory.
You would probably need a new signal "SIGFREEZE" which causes the process to be ignored as runnable the next time they schedule but never actually gets delivered, and a "SIGUNFREEZE" which does the reverse. That way userspace could selectively resume processes based on its policy of "this needs to run for hibernation".
Quoted 3 lines
Quoted 1 line
(2) Userspace process sends SIGCONT to only those processes which are necessary for sync and a device-mapper snapshot.
How do you determine which ones are needed?
It's userspace's job to know which ones are needed. For example, if you are hibernating over NFS then you need to resume the various NFS/RPC daemons and threads.
Quoted 1 line
Why stop them in the first place?
So they aren't allocating memory when we are doing the device-mapper snapshot.
Quoted 18 lines
Quoted 3 lines
(3) Userspace calls
sys_snapshot_kernel(snapshot_overhead_pages)
(a) Kernel starts freeing memory and swapping stuff out to make
room for a copy of *kernel* memory (not pagecache, not process RAM). It does the same for at leastsnapshot_overhead_pagesextra (used by userspace later). It then allocates this memory to keep it from going away. Since most processes are stopped we won't have much else competing with us for the RAM.Ok. So now you also need processes running that are needed for swapping, because freeing that memory might involve swapping. Fully agree with the logic though (not really surprising - this is what I do in Suspend2^wTuxOnIce).
Quoted 11 lines
(a) Kernel uses the device-mapper up-call-into-filesystem
machinery to get all mounted filesystems synced and ready for a DM snapshot. This may include sending data via the userspace processes resumed in (2). Any deadlocks here are userspace's fault (see (2)). Will need some modification to handle doing multiple blockdevs at a time. Anything using FUSE is basically perma-synced anyways (no dep-handling needed), and anything using loop should already be handled by DM. This includes allocating memory for the basic snapshot datastructures.
(b) At this point all blockdev operations should be halted and
disk caches flushed; that's all we care about.
(c) Go through the device tree and quiesce DMA and shut off
interrupts. Since all the disks are synced this is easy.
(d) Use IPMIs again to get all the CPUs together, which should
be easy as most processes are sleeping in IO or SIGSTOPed, and we're getting no interrupts.
(e) One CPU turns off all interrupts on itself and takes an
atomic snapshot of kernel memory into the previously allocated storage. Once again, does not include pagecache. The kernel also records a list of what pages *are* included in the pagecache. It then marks all userspace pages as copy-on-write.
Quoted 1 line
Hotplugging cpus (when all those locking issues are taken care of) is simpler. Prior to cpu hotplugging, I used IMPIs to put secondary cpus into a tight loop, so I know it's possible to do it this way too.
It may be simpler, but it really screws up things like cpusets, processor affinity, etc. It also ties hibernation to the presently very-flakey CPU-hotplug support, which is probably not what we want.
Quoted 1 line
That way, though, you have less flexibility. What if a cpu really is plugged in between hibernate and resume? With cpu hotplugging, it's handled properly and transparently. Without cpu hotplugging, you could be using uninitialised data after the atomic restore.
IMHO if the user pulls a CPU while the box is hibernated, then he/she gets what he/she deserves. If you really want to support that, then the user must do the hotplug operation *manually* before suspending. Anything else is just going to be shooting ourselves in the foot repeatedly.
Quoted 1 line
Marking userspace as COW makes things more complicated, too. You then have to add code to the COW handling to update the list of pages that need to be saved, and you reduce the reliability of the whole process. You can't predict beforehand how many of these COW pages are going to be needed, and therefore can't know how much memory to free earlier on in the process. If you run out of memory, what will be the effect?
You could pretty easily have a spare 128MB swap partition somewhere which is not used during system operation but is "swapon"ed by userspace after the COW snapshot to provide extra backing store.
Quoted 8 lines
Quoted 6 lines
(f) That CPU finalizes the modified DM snapshot using the
previously-allocated memory.
(g) That CPU frees up thesnapshot_overhead_pagesmemory
allocated during step (a) for userspace to use.
(h) The CPU does the equivalent of a "swapoff -a" without
overwriting any data already on any swap device(s).You still need to remember what swap you're going to use to write the image. You'll probably want to get this information (and allocate the swap) sooner rather than later so that you're not racing against the memory freeing earlier, and don't run into issues with bmapping the pages or having enough memory to record the bdevs & sector numbers (not usually an issue, but if swap is highly fragmented...).
Who says we have to use this swap to write the image? That may be the default use-case, but it's certainly shouldn't be mandatory. Really, for the write-image-to-swap case you would just need to preallocate sufficient memory for the bmap tables beforehand, then populate them at this phase.
Quoted 5 lines
Quoted 3 lines
(i) The CPU then IPMI-signals the other CPUs to wake them up
(j) The kernel returns a FD-reference to the snapshot and the
read-only halves of the CoW pagecache to the process which calledsys_snapshot_kernel().Readonly halves? I don't get that, sorry.
Well, each page is copy-on-write, so the FD reference would always provide access to the original page data, whereas the processes may end up copying the page so they can write to it. The trick would be that shared pages need to remain shared between processes even after the copy-on-write. This is likely to be the trickiest part.
Quoted 3 lines
Quoted 1 line
(4) The userspace process now has a reference to the copy of the kernel pages and the unmodified pagecache pages. Since 99% of the processes aren't running, we aren't going to be having to CoW many of the pagecache pages.
Mmm, but you still don't know how many.
Yes, but at this point we're basically running a segment of userspace with full kernel services available. Like I said above we can just add a dedicated 128MB swap device to provide some spare backing store. When you start running low on memory it might even page out to the swap device a part of the atomic copy of kernel memory.
Quoted 5 lines
Quoted 3 lines
(5) The userspace process uses
read()or other syscalls to get data out of the kernel-snapshot FD in small chunks, within itssnapshot_overhead_pageslimit. It compresses these and writes them out to the snapshot-storage blockdev (must not be mounted during snapshot), or to any network server.(6) The userspace process syncs the disks and halts the system. Any changed filesystem pages after the pseudo-DM-snapshot should have been stored in semi-volatile storage somewhere and will be discarded on the next reboot.
Are you thinking the changed filesystem pages are caught by COW? (AFAIUI, kernel writes aren't). If (as I expect), you're thinking about filesystem writes to DM based storage, what about non DM-based filesystem pages?
No, but a kernel write to a DM-snapshot calls the DM-snapshot code which copies the segment(s) to the snapshot device and modifies them there. Basically disk-filesystem pagecache pages would be synced and protected by the DM snapshot, while anonymous memory pages would be CoW-ed. And it might not be an unreasonable requirement to state that the disk-based filesystems must all be mapped through DM-snapshot devices (even just straight 1:1 linear mappings), so that they can be trivially snapshotted.
Quoted 10 lines
Quoted 8 lines
So basically your hibernate-overhead would consist of:
(1) The pages necessary for the atomic snapshot of kernel
memory and the list of pagecache pages at that time
(2) A little memory necessary for the kernel non-persistent DM
snapshot datastructures.
(3) Thesnapshot_overhead_pagesneeded by userspace.If you're using swap devices then you can save 99% of the state of the running kernel with an initial swapout overhead of virtually nothing beyond the size of the unswappable kernel memory.
FWIW, let me note an important variation from how Suspend2 works; it might provide food for thought. In Suspend2, we treat the processes that remain stopped throughout the whole process specially. We write their data to disk before the atomic copy (usually 70 or 80% of memory), and then use the memory they occupy for the destination of the atomic copy. This further reduces the amount of memory that has to be freed, almost always to zero.
I suppose you could record swap-outs done to SIGFREEZEd processes specially, so that they would be swapped in again before resuming userspace. That would effectively result in the same thing.
Cheers,
Kyle Moffett
sysrq-t dumps of s2ram/fuse deadlock (was Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Rafael J. WysockiHi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
Matthew, you seem to be the only one able to produce them...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: sysrq-t dumps of s2ram/fuse deadlock (was Re: [PATCH] Remove process freezer from suspend to RAM pathway)
Quoted 5 lines · Pavel Machek
Hi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
I can produce them, but haven't managed to do that in any way that lets me get them off the system yet.
Quoted 1 line
Matthew, you seem to be the only one able to produce them...
sys_sync may not do anything on a fuse filesystem, but if you've loopback-mounted an ext3 filesystem from that fuse filesystem then it's going to result in writes to it and deadlock.
Signature · 1 line
Matthew Garrett | [email protected]
Re: sysrq-t dumps of s2ram/fuse deadlock (was Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Pavel MachekQuoted 5 lines · Pavel Machek
Hi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
I can produce them, but haven't managed to do that in any way that lets me get them off the system yet.
Quoted 1 line
Matthew, you seem to be the only one able to produce them...
sys_sync may not do anything on a fuse filesystem, but if you've loopback-mounted an ext3 filesystem from that fuse filesystem then it's going to result in writes to it and deadlock.
Signature · 1 line
Matthew Garrett | [email protected]
Re: sysrq-t dumps of s2ram/fuse deadlock
Quoted 9 lines · Matthew Garrett
Quoted 5 lines · Pavel Machek
Hi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
I can produce them, but haven't managed to do that in any way that lets me get them off the system yet.
If you can see them, then perhaps you could use a digital camera or just copy the text manually.
[snip]
Signature · 1 line
Jeremy Maitin-Shepard
Re: sysrq-t dumps of s2ram/fuse deadlock (was Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Matthew GarrettQuoted 7 lines · Matthew Garrett
Quoted 5 lines · Pavel Machek
Hi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
Quoted 8 lines
I can produce them, but haven't managed to do that in any way that lets me get them off the system yet.
Quoted 1 line
Matthew, you seem to be the only one able to produce them...
sys_syncmay not do anything on a fuse filesystem, but if you've loopback-mounted an ext3 filesystem from that fuse filesystem then it's going to result in writes to it and deadlock.
Aha, yes, that explains the problem. Thanks!
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 7 lines
Quoted 4 lines
They will not trigger 100% of the time, but sporadically and generally at random.
At least the freezer problems are reproducible. ;-)
Our experience with powermacs has been that it isn't actually all that hard to get it right for the drivers you care about.
So... will you fix input and usb? Their maintainers seem to prefer simplicity of frozen system.
Also, can you write down rules for drivers to follow?
Like... 'if you get a request after system suspend started, you may not kmalloc(GFP_KERNEL)'
- because disk driver may be already suspended
- hmm, what happens if disk driver _is_ suspended? Let's say I'm v4l driver on cpu1. Someone may talk to me _while_ disk driver is being suspended... and if I'm after disk driver in pci order, I may only learn about suspend _after_ I do the wrong kmalloc.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: malicious filesystems (was Re: Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediHi!
Quoted 13 lines
Quoted 6 lines
So you want me to handle _malicious_ filesystems now?
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
Quoted 6 lines
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Not ideal, but neither is allowing malicious filesystems in the first place...
Quoted 7 lines
Actually there's also a non-malicious case in which waiting for requests to finish won't work: when one fuse filesystem is accessing another.
Since we are blocking new fuse requests, that might block a fuse daemon, which in turn makes it impossible to finish the pending request.
Hmm, yes, this is ugly. But will it hurt? We'll just wait for number of active fuse requests to go down to 0 before proceeding. It may still livelock on system with busy fused-s, but we'll detect that with timeout, and I believe it is 'don't do that' situation.
Quoted 6 lines
And this is not at all theoretical, I know that encfs is used over various other fuse filesystems like sshfs or ntfs-3g.
Yeah, stacking userspace filesystems could be done entirely in userspace, and I'm actually working on that (with fuse-2.7.0 already supporting some basic stacking).
Great.
Quoted 2 lines
But the point is, that the "wait for fuse to quiescence" hack would not work in todays environment.
Ok, I'll just blame fuse here. 'You have to write to /sys files for SIGKILL to work' is not funny.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 7 lines
Quoted 4 lines
They will not trigger 100% of the time, but sporadically and generally at random.
At least the freezer problems are reproducible. ;-)
Our experience with powermacs has been that it isn't actually all that hard to get it right for the drivers you care about.
So... will you fix input and usb? Their maintainers seem to prefer simplicity of frozen system.
Also, can you write down rules for drivers to follow?
Like... 'if you get a request after system suspend started, you may not kmalloc(GFP_KERNEL)'
- because disk driver may be already suspended
- hmm, what happens if disk driver _is_ suspended? Let's say I'm v4l driver on cpu1. Someone may talk to me _while_ disk driver is being suspended... and if I'm after disk driver in pci order, I may only learn about suspend _after_ I do the wrong kmalloc.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Miklos SzerediHi!
Quoted 13 lines
Quoted 6 lines
So you want me to handle _malicious_ filesystems now?
That should be easy... :-). You already have nasty deadlocks in FUSE, and you solve them by "root can echo 1 > abort"... so allow me the same possibility.
Quoted 6 lines
We can tell fused we are freezing, and if all the requests are not serviced within, say, 30 seconds, we call the filesystem malicious and do echo 1 > abort.
Not ideal, but neither is allowing malicious filesystems in the first place...
Quoted 7 lines
Actually there's also a non-malicious case in which waiting for requests to finish won't work: when one fuse filesystem is accessing another.
Since we are blocking new fuse requests, that might block a fuse daemon, which in turn makes it impossible to finish the pending request.
Hmm, yes, this is ugly. But will it hurt? We'll just wait for number of active fuse requests to go down to 0 before proceeding. It may still livelock on system with busy fused-s, but we'll detect that with timeout, and I believe it is 'don't do that' situation.
Quoted 6 lines
And this is not at all theoretical, I know that encfs is used over various other fuse filesystems like sshfs or ntfs-3g.
Yeah, stacking userspace filesystems could be done entirely in userspace, and I'm actually working on that (with fuse-2.7.0 already supporting some basic stacking).
Great.
Quoted 2 lines
But the point is, that the "wait for fuse to quiescence" hack would not work in todays environment.
Ok, I'll just blame fuse here. 'You have to write to /sys files for SIGKILL to work' is not funny.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: sysrq-t dumps of s2ram/fuse deadlock (was Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Matthew GarrettQuoted 7 lines · Matthew Garrett
Quoted 5 lines · Pavel Machek
Hi!
Can we get them? They are neccessary for debugging 'what in suspend calls fuse' problem. And yes, that problem is there even when you remove freezer.
Quoted 8 lines
I can produce them, but haven't managed to do that in any way that lets me get them off the system yet.
Quoted 1 line
Matthew, you seem to be the only one able to produce them...
sys_syncmay not do anything on a fuse filesystem, but if you've loopback-mounted an ext3 filesystem from that fuse filesystem then it's going to result in writes to it and deadlock.
Aha, yes, that explains the problem. Thanks!
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
In reply to Pavel MachekQuoted 10 lines
Quoted 7 lines
Actually there's also a non-malicious case in which waiting for requests to finish won't work: when one fuse filesystem is accessing another.
Since we are blocking new fuse requests, that might block a fuse daemon, which in turn makes it impossible to finish the pending request.
Hmm, yes, this is ugly. But will it hurt? We'll just wait for number of active fuse requests to go down to 0 before proceeding.
I'm thinking of the following situation, immediately after we begin to wait for fuse requests to subside:
- task A is performing file operation O1
- O1 is being served by task B
- task B needs to perform O2 before finishing O1
Since we don't allow new requests, O2 will never start. So O1 will never finish. So the number of fuse requests will never go to 0.
Quoted 2 lines
It may still livelock on system with busy fused-s, but we'll detect that with timeout, and I believe it is 'don't do that' situation.
There are no busy fused's. If we allowed O2 to go through, everything would be nice and dandy. But we cannot know that O2 needs to be let through, and other fuse requests must not.
Quoted 7 lines
Quoted 6 lines
And this is not at all theoretical, I know that encfs is used over various other fuse filesystems like sshfs or ntfs-3g.
Yeah, stacking userspace filesystems could be done entirely in userspace, and I'm actually working on that (with fuse-2.7.0 already supporting some basic stacking).
Quoted 7 lines
Great.
Quoted 2 lines
But the point is, that the "wait for fuse to quiescence" hack would not work in todays environment.
Ok, I'll just blame fuse here. 'You have to write to /sys files for SIGKILL to work' is not funny.
SIGKILL won't work on a stopped task. Neither on a traced task. Neither on a zombie (how many newbies are thoroughly confused about that ;)
And it won't work on a task that is hanging on an NFS mount, when the network broke.
Oh, and it won't work on a deadlocked fuse filesystem. How many of these have you met? How many of the others?
Miklos
Re: malicious filesystems (was Re: [linux-pm] Re: [PATCH] Remove process freezer from suspend to RAM pathway)
Quoted 7 lines
Quoted 2 lines
Ok, I'll just blame fuse here. 'You have to write to /sys files for SIGKILL to work' is not funny.
SIGKILL won't work on a stopped task. Neither on a traced task. Neither on a zombie (how many newbies are thoroughly confused about that ;)
Quoted 5 lines
And it won't work on a task that is hanging on an NFS mount, when the network broke.
Oh, and it won't work on a deadlocked fuse filesystem. How many of these have you met? How many of the others?
And maybe someday, when I'm feeling _really_ bored, I may start hacking the VFS to make it possible for tasks to be killed while waiting on a mutex. Can a task doing a page fault be interrupted? I don't see why not.
But, it's _not_ going to happen now, to fix the problems with suspend. Hacking fuse (however broken it may be) or the VFS is not the right way to fix those problems. It may be easier than fixing the drivers, though I doubt it. But even if it's the easier way it's not the _right_ way.
We want the various subsystems in the kernel to be less dependent on each other not more. And the freezer is just adding unnecessary dependence on totally unrelated code. And that does not only impact fuse, but a lot of other code in the kernel, in the form of try_to_freeze() calls all over the place.
Is that so hard to understand?
You can bash fuse all you want, I really don't mind. But please stop trying to prove, that this situation is best handled in fuse. It just won't happen, not because I'm lazy to do the work but because I don't have the guts to do something so obviously wrong.
Miklos