On Thu, Apr 03, 2025 at 04:56:57PM +0200, Jan Kara wrote: > On Wed 02-04-25 16:07:31, Christian Brauner wrote: > > For some kernel subsystems it is paramount that they are guaranteed that > > they are the owner of the freeze to avoid any risk of deadlocks. This is > > the case for the power subsystem. Enable it to recognize whether it did > > actually freeze the filesystem. > > > > If userspace has 10 filesystems and suspend/hibernate manges to freeze 5 > > and then fails on the 6th for whatever odd reason (current or future) > > then power needs to undo the freeze of the first 5 filesystems. It can't > > just walk the list again because while it's unlikely that a new > > filesystem got added in the meantime it still cannot tell which > > filesystems the power subsystem actually managed to get a freeze > > reference count on that needs to be dropped during thaw. > > > > There's various ways out of this ugliness. For example, record the > > filesystems the power subsystem managed to freeze on a temporary list in > > the callbacks and then walk that list backwards during thaw to undo the > > freezing or make sure that the power subsystem just actually exclusively > > freezes things it can freeze and marking such filesystems as being owned > > by power for the duration of the suspend or resume cycle. I opted for > > the latter as that seemed the clean thing to do even if it means more > > code changes. > > > > Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx> > > I have realized a slight catch with this approach that if hibernation races > with filesystem freezing (e.g. DM reconfiguration), then hibernation need > not freeze a filesystem because it's already frozen but userspace may thaw > the filesystem before hibernation actually happens (relatively harmless). > If the race happens the other way around, DM reconfiguration may > unexpectedly fail with EBUSY (rather unexpected). So somehow tracking which > fs was frozen by suspend while properly nesting with other freeze users may > be actually a better approach (maybe just a sb flag even though it's > somewhat hacky?). The approach that I originally had was to add FREEZE_POWER which adds a simple boolean into the sb_writers instead of a holder and then this simply nests with the rest. I'll try to post that diff tomorrow.