Repository navigation
Conversation
remove() cancelled the deferred-flush work and then removed the namespaces. That loses data and can use freed memory: - The cancelled work stood for a flush that queue_rq() had already completed to the filesystem. Cancelling it means that flush never reaches the drive. - Removing a namespace flushes its disk. With the grace period set (flush_interval, 1000 ms by default), that flush can arm the work again. The work then runs on flush_ns after namespace removal has freed it. Add apple_nvme_stop_deferred_flush(). It sets the interval to 0 and then runs any deferred flush while its namespace still exists. Later flushes go straight to the drive. A new flush_lock covers the interval check and the arming in apple_nvme_delayed_flush(), and the clearing here. So a flush that read a non-zero interval has finished arming before the work is flushed, and none can arm it afterwards. The lock is taken only for flush requests on controllers that use the grace period. Call it from remove() before nvme_remove_namespaces(), and from shutdown() in place of the plain flush_delayed_work(), so flushes issued during shutdown also reach the drive before it is disabled. Checked with a host harness that compiles the real apple_nvme_delayed_flush() text with stubbed work calls under ASan and UBSan, and widens the window between reading the interval and arming. With an earlier version of this fix (clear with WRITE_ONCE(), then flush), the work was armed after the namespace was freed in 3 of 3 runs. With this version, the deferred flush ran before the free and nothing was armed afterwards, 3 of 3. Not built as a kernel module here, and not run on hardware. Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
|
@Alyx-ML checking open drafts today. To come out of draft, this still needs:
If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done. |
|
Thanks for checking. This is still needed, and it merges cleanly with Assisted-by: LLM (Claude:Opus 5.5) |
|
@Alyx-ML |
Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which). This includes the race DjDeveloperr found in the #2755 version.
Summary
Evidence
A host harness compiles the real
apple_nvme_delayed_flush()text with stubbed work calls underASan and UBSan, and widens the window between reading the interval and arming:
WRITE_ONCE(), then flush): the work was armed afterthe namespace was freed, in 3 of 3 runs.
Build: passed, Apple build and KUnit. There is no nvme KUnit suite. This does not change the default
flush_interval; that is in #2989.Needed before merging: on a Mac with
flush_interval=1000, a shutdown and a reboot duringfsync-heavy writes.
Merge Danger
Door: two-way
Blast Radius: nvme remove and shutdown
The lock is taken only for flush requests on controllers that use the grace period.