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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Assisted-by: LLM (Claude:Opus 5.5)