| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/12 17:40 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"DEBUG_VFS",
"OVERLAY_FS",
"IPC_NS"
],
"FocusSymbols": [
"mntput_unmounted",
"mntput_unheld",
"mntput_final_locked",
"mntput_queue_cleanup",
"do_umount",
"path_umount",
"kern_unmount_array",
"ovl_free_fs",
"ovl_free_fs_rcu",
"free_ipc_ns"
],
"KMSANReasoning": "The patch optimizes VFS mount teardown in fs/namespace.c, fs/overlayfs/params.c, and ipc/namespace.c by skipping unnecessary RCU grace periods when an unmounted tree holds the sole reference to a mount. It modifies reference counting, memory barriers, locking guards, and delayed cleanup (e.g. via call_rcu and task work).\n\nThe primary risks introduced by these changes relate to object lifecycles, memory ordering, and concurrency: specifically, use-after-free (UAF) or premature freeing if a reference is dropped or a structure is cleaned up while an RCU reader or concurrent path walker still holds or accesses it. These failure modes (UAF, double-free, list corruption, locking bugs) are directly monitored and detected by KASAN and LOCKDEP.\n\nKMSAN detects reads of uninitialized memory and information leaks to user space. The patch does not introduce any data copies to user space (no copy_to_user, put_user, netlink messages, or ioctl outputs), does not allocate complex uninitialized memory buffers, and does not add conditional logic reading uninitialized struct fields. All new local variables and list heads (e.g. HLIST_HEAD, LIST_HEAD, loop counters) are properly initialized. Therefore, there are no uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch series modifies core VFS mount lifecycle and reference counting logic by eliding RCU grace periods for mounts that have only a single reference (mntput_unheld, mntput_unmounted). It also adds new assertions (VFS_WARN_ON_ONCE, VFS_BUG_ON) for mount invariants, refactors do_umount locking and reference cleanup, adjusts kern_unmount_array, defers overlayfs cleanup via RCU to safeguard concurrent RCU pathwalks (ovl_free_fs, ovl_free_fs_rcu), and alters IPC namespace destruction. All modified code resides in core subsystems reachable via standard unmount, mount, namespace, and overlayfs operations in virtualized environments. Fuzzing is warranted to uncover concurrency races and verify the new refcount invariants.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/12 17:40 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit e0aa6941f4f130737b972ad9bf165994c6b8e61d\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Mon Oct 12 17:40:03 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/litmus-tests/README b/Documentation/litmus-tests/README\nindex 6c666f3422ea3..47fca037c6e14 100644\n--- a/Documentation/litmus-tests/README\n+++ b/Documentation/litmus-tests/README\n@@ -38,6 +38,101 @@ cmpxchg-fail-unordered-2.litmus\n acquire operation.\n \n \n+fs (/fs directory)\n+------------------\n+\n+The reference count of a mount is split into per-CPU gets and puts. A\n+holder drops a reference on the fast path of mntput_no_expire() without\n+mount_lock, a walker in __legitimize_mnt() takes one during an RCU path\n+walk, and the unmounter sums the counters under mount_lock with\n+mnt_get_count() to decide whether it can finish the mount off without\n+waiting for a grace period. The tests spell write_seqlock() out as a\n+spinlock, a seqcount store and smp_wmb(), read_seqbegin() and\n+read_seqretry() as READ_ONCE() and smp_rmb(), and the per-CPU counters\n+as one variable per CPU.\n+\n+mnt-sum-misses-fastpath-put.litmus\n+ Demonstrates that the sum under mount_lock can miss a put on the\n+ fast path of mntput_no_expire(), which is why mntput_unmounted()\n+ falls back to a grace period when the count is not one.\n+\n+mnt-holder-get-before-put.litmus\n+ Demonstrates that a fast-path put the sum counts has its get counted\n+ too: the smp_wmb() in mntput_no_expire() pairs with the smp_mb()\n+ between the puts pass and the gets pass of mnt_get_count().\n+\n+mnt-holder-get-before-put-nowmb.litmus\n+ The same without the holder's smp_wmb(); the sum can count the put\n+ but not the get.\n+\n+mnt-holder-get-before-put-nomb.litmus\n+ The same without the smp_mb() inside mnt_get_count(); an smp_mb()\n+ ahead of the puts pass does not stand in for it.\n+\n+mnt-holder-get-before-put-getsfirst.litmus\n+ The same with the gets summed before the puts; the order of the two\n+ passes is part of the pairing.\n+\n+mnt-gp-sees-fastpath-put.litmus\n+ Demonstrates that after the grace period of mntput_unmounted() the\n+ plain mntput() sees the fast-path put the sum missed, because the\n+ holder's read-side critical section ended before the grace period.\n+\n+mnt-gp-sees-fastpath-put-sync-rcu.litmus\n+ The same with synchronize_rcu() in place of\n+ synchronize_rcu_expedited().\n+\n+mnt-gp-sees-fastpath-put-nogp.litmus\n+ The same with an smp_mb() in place of the grace period; the put can\n+ still be missed.\n+\n+mnt-walker-get-vs-seqcount.litmus\n+ Demonstrates the store buffering pairing between the increment and\n+ smp_mb() of __legitimize_mnt() and the seqcount store and the\n+ smp_mb() of mnt_get_count() under mount_lock: the walker cannot\n+ keep a reference to a mount the sum finishes off.\n+\n+mnt-walker-get-vs-seqcount-no-outer-mb.litmus\n+ The same with the sum as the tree has it, without an smp_mb()\n+ between taking mount_lock and the sum; the smp_mb() inside\n+ mnt_get_count() is the one that pairs.\n+\n+mnt-walker-get-vs-seqcount-nomb.litmus\n+ The same without the walker's smp_mb(); the walker can keep a\n+ reference to a freed mount.\n+\n+mnt-walker-bail-sees-doomed.litmus\n+ Demonstrates that a walker which sees the seqcount change and reads\n+ -\u003emnt_flags under mount_lock finds MNT_DOOMED on a mount the sum\n+ finished off; mount_lock orders the two critical sections.\n+\n+mnt-walker-bail-sees-doomed-nolock.litmus\n+ The same with -\u003emnt_flags read outside mount_lock; the walker can\n+ miss MNT_DOOMED.\n+\n+mnt-walker-late-sees-new-pwd.litmus\n+ Demonstrates that a walker which starts after the sum finished a\n+ mount off cannot reach it through the old cwd of a holder whose put\n+ the sum counted: the holder orders the new fs-\u003epwd before the put\n+ and the smp_mb() of mnt_get_count() orders the load of the put\n+ before the seqcount store the walker samples.\n+\n+mnt-walker-late-sees-new-pwd-nowmb.litmus\n+ The same without the smp_wmb()s that order the new fs-\u003epwd before\n+ the put; the walker can read the old cwd.\n+\n+mnt-walker-late-sees-new-pwd-nomb.litmus\n+ The same without the smp_mb() inside mnt_get_count(); the walker can\n+ read the old cwd.\n+\n+mnt-kern-unmount-holder-get-before-put.litmus\n+ The holder test for kern_unmount_array(), where mnt_make_shortterm()\n+ clears -\u003emnt_ns with a plain WRITE_ONCE() outside mount_lock.\n+\n+mnt-kern-unmount-gp-sees-fastpath-put.litmus\n+ The grace period test for kern_unmount_array().\n+\n+\n locking (/locking directory)\n ----------------------------\n \ndiff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus\nnew file mode 100644\nindex 0000000000000..b0b4037217a4c\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus\n@@ -0,0 +1,75 @@\n+C mnt-gp-sees-fastpath-put-nogp\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-gp-sees-fastpath-put.litmus with an smp_mb() in place of the\n+ * grace period. A barrier orders the unmounter's own accesses and\n+ * waits for nothing: the holder's read-side critical section may still\n+ * be running and the second sum misses the put like the first one.\n+ * Only a grace period covers a fast-path put the sum missed.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r3;\n+\tint r5;\n+\tint r6;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+\n+\tsmp_mb();\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 5);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tWRITE_ONCE(*puts_u, 1);\n+\tr5 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr6 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 6);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r5=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus\nnew file mode 100644\nindex 0000000000000..e8d4b17f14264\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus\n@@ -0,0 +1,73 @@\n+C mnt-gp-sees-fastpath-put-sync-rcu\n+\n+(*\n+ * Result: Never\n+ *\n+ * mnt-gp-sees-fastpath-put.litmus with synchronize_rcu() in place of\n+ * synchronize_rcu_expedited(). To the memory model the two are the\n+ * same fence.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r3;\n+\tint r5;\n+\tint r6;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+\n+\tsynchronize_rcu();\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 5);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tWRITE_ONCE(*puts_u, 1);\n+\tr5 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr6 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 6);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r5=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus\nnew file mode 100644\nindex 0000000000000..b60100fdab5ef\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus\n@@ -0,0 +1,79 @@\n+C mnt-gp-sees-fastpath-put\n+\n+(*\n+ * Result: Never\n+ *\n+ * The sum of mntput_unheld() can miss the put of a holder on the fast\n+ * path of mntput_no_expire(), see mnt-sum-misses-fastpath-put.litmus.\n+ * mntput_unmounted() then waits in synchronize_rcu_expedited() and\n+ * drops the own reference with a plain mntput(), which sums again in\n+ * mntput_no_expire_slowpath() under mount_lock. The holder read\n+ * -\u003emnt_ns non-NULL inside rcu_read_lock() before umount_tree() stored\n+ * NULL, so its read-side critical section, and the put inside it, ends\n+ * before the grace period does. The first sum may miss the put\n+ * (1:r1), the second one never does (1:r5=1).\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r3;\n+\tint r5;\n+\tint r6;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+\n+\tsynchronize_rcu_expedited();\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 5);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tWRITE_ONCE(*puts_u, 1);\n+\tr5 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr6 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 6);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r5=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus\nnew file mode 100644\nindex 0000000000000..d20470a276fed\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus\n@@ -0,0 +1,63 @@\n+C mnt-holder-get-before-put-getsfirst\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-holder-get-before-put.litmus with mnt_get_count() summing the\n+ * gets before the puts, the smp_mb() still between the two passes.\n+ * The order of the passes is part of the pairing: read first, the\n+ * gets pass can predate a get whose put is then counted.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\tWRITE_ONCE(*gets_h, 2);\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r1=1 /\\ 1:r3=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus\nnew file mode 100644\nindex 0000000000000..2da4353bc0870\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus\n@@ -0,0 +1,62 @@\n+C mnt-holder-get-before-put-nomb\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-holder-get-before-put.litmus without the smp_mb() between the\n+ * puts pass and the gets pass of mnt_get_count(). The smp_mb() ahead\n+ * of the puts pass is still there and does not help: the barrier that\n+ * pairs with the holder's smp_wmb() has to sit between the two loads.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\tWRITE_ONCE(*gets_h, 2);\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r1=1 /\\ 1:r3=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus\nnew file mode 100644\nindex 0000000000000..d9070e813e478\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus\n@@ -0,0 +1,62 @@\n+C mnt-holder-get-before-put-nowmb\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-holder-get-before-put.litmus without the smp_wmb() between the\n+ * get and the fast-path put in mntput_no_expire(). Nothing orders the\n+ * two stores: the sum counts the put but not the get and finishes the\n+ * mount off under the holder.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\tWRITE_ONCE(*gets_h, 2);\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r1=1 /\\ 1:r3=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus\nnew file mode 100644\nindex 0000000000000..414c303dcbb61\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus\n@@ -0,0 +1,73 @@\n+C mnt-holder-get-before-put\n+\n+(*\n+ * Result: Never\n+ *\n+ * A holder with a reference of its own (gets_h=1) does a transient\n+ * mntget() and drops it on the fast path of mntput_no_expire(): the\n+ * store to its gets counter, READ_ONCE(-\u003emnt_ns) non-NULL, smp_wmb(),\n+ * the store to its puts counter. umount_tree() clears -\u003emnt_ns under\n+ * write_seqlock() and mntput_unheld() sums with mnt_get_count(): the\n+ * puts pass, smp_mb(), the gets pass. The smp_wmb() pairs with that\n+ * smp_mb(), so a put the sum counts has its get counted too. The bad\n+ * outcome is the sum counting the put (1:r1=1) but not the get\n+ * (1:r3=1): a count of one, and the mount finished off under the\n+ * reference the holder still has. Message passing, smp_wmb() on the\n+ * holder's side and smp_mb() on the sum's. The sum is modelled with\n+ * an smp_mb() ahead of the puts pass as well; it takes no part in\n+ * this, see the -nomb variant. A put that lands on another CPU's\n+ * counter after a migration is the same test, the model has no CPUs.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\tWRITE_ONCE(*gets_h, 2);\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r1=1 /\\ 1:r3=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus\nnew file mode 100644\nindex 0000000000000..59dd434e6a76e\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus\n@@ -0,0 +1,70 @@\n+C mnt-kern-unmount-gp-sees-fastpath-put\n+\n+(*\n+ * Result: Never\n+ *\n+ * mnt-gp-sees-fastpath-put.litmus for kern_unmount_array(), where\n+ * mnt_make_shortterm() clears -\u003emnt_ns with a plain WRITE_ONCE()\n+ * outside mount_lock. The holder still read it non-NULL inside\n+ * rcu_read_lock() before the store, so its read-side critical section\n+ * ends before the grace period of mntput_unmounted() does and the\n+ * plain mntput() that follows sees its put.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r3;\n+\tint r5;\n+\tint r6;\n+\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+\n+\tsynchronize_rcu_expedited();\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 5);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tWRITE_ONCE(*puts_u, 1);\n+\tr5 = READ_ONCE(*puts_h);\n+\tsmp_mb();\n+\tr6 = READ_ONCE(*gets_h);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 6);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r5=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus b/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus\nnew file mode 100644\nindex 0000000000000..dd7976f06b930\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus\n@@ -0,0 +1,60 @@\n+C mnt-kern-unmount-holder-get-before-put\n+\n+(*\n+ * Result: Never\n+ *\n+ * mnt-holder-get-before-put.litmus for kern_unmount_array(), where\n+ * mnt_make_shortterm() clears -\u003emnt_ns with a plain WRITE_ONCE(),\n+ * outside mount_lock and without a seqcount write, before\n+ * mntput_unmounted() sums under the lock. The pairing is unchanged:\n+ * the holder's smp_wmb() against the smp_mb() of mnt_get_count(),\n+ * neither of which needs the lock or the seqcount. Only holders are\n+ * modelled.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\tWRITE_ONCE(*gets_h, 2);\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r1=1 /\\ 1:r3=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus\nnew file mode 100644\nindex 0000000000000..34347c6a2b255\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus\n@@ -0,0 +1,69 @@\n+C mnt-sum-misses-fastpath-put\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * A holder drops its reference on the fast path of mntput_no_expire():\n+ * READ_ONCE(-\u003emnt_ns) non-NULL under rcu_read_lock(), smp_wmb(), the\n+ * put. umount_tree() clears -\u003emnt_ns under write_seqlock() and\n+ * mntput_unheld() sums the counters with mnt_get_count() under the\n+ * lock. The holder read -\u003emnt_ns before it was cleared (0:r0=1) and\n+ * the sum still does not count its put (1:r1=0): the put is simply\n+ * later. The sum comes out at two, so mntput_unmounted() has to wait\n+ * for the holder's read-side critical section before the plain\n+ * mntput() that drops the own reference, see\n+ * mnt-gp-sees-fastpath-put.litmus. This is why the grace period\n+ * branch exists, not a bug.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+}\n+\n+P0(int *mnt_ns, int *gets_h, int *puts_h)\n+{\n+\tint r0;\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+exists (0:r0=1 /\\ 1:r1=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus\nnew file mode 100644\nindex 0000000000000..233f2e65d25d7\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus\n@@ -0,0 +1,89 @@\n+C mnt-walker-bail-sees-doomed-nolock\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-walker-bail-sees-doomed.litmus with the walker reading\n+ * -\u003emnt_flags outside mount_lock. Nothing orders that read against\n+ * the sum's critical section: the walker can read the flags before\n+ * MNT_DOOMED is set and keep a reference to a mount the sum has\n+ * finished off. This is why __legitimize_mnt() looks under the lock.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_w=0;\n+\tputs_w=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tflags=0;\n+\tseq=0;\n+\tfreed=0;\n+}\n+\n+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)\n+{\n+\tint r0;\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\n+\tr0 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tsmp_rmb();\n+\tr1 = READ_ONCE(*seq);\n+\tif (r1 == 0) {\n+\t\tWRITE_ONCE(*gets_w, 1);\n+\t\tsmp_mb();\n+\t\tsmp_rmb();\n+\t\tr2 = READ_ONCE(*seq);\n+\t\tif (r2 != 0) {\n+\t\t\tr3 = READ_ONCE(*flags);\n+\t\t\tif (r3 != 0) {\n+\t\t\t\tWRITE_ONCE(*puts_w, 1);\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_w);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_w);\n+\tr4 = READ_ONCE(*gets_u);\n+\tif (r3 == 0) {\n+\t\tWRITE_ONCE(*flags, 3);\n+\t\tWRITE_ONCE(*freed, 1);\n+\t}\n+\tif (r3 == 1) {\n+\t\tif (r1 == 1) {\n+\t\t\tWRITE_ONCE(*flags, 3);\n+\t\t\tWRITE_ONCE(*freed, 1);\n+\t\t}\n+\t}\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+filter (0:r0=0)\n+exists (0:r1=0 /\\ ~(0:r2=0) /\\ 0:r3=0 /\\ freed=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus\nnew file mode 100644\nindex 0000000000000..187619db7fb6d\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus\n@@ -0,0 +1,95 @@\n+C mnt-walker-bail-sees-doomed\n+\n+(*\n+ * Result: Never\n+ *\n+ * A lazy unmount: umount_tree() clears -\u003emnt_ns under write_seqlock()\n+ * without setting MNT_SYNC_UMOUNT, and mntput_unheld() sets MNT_DOOMED\n+ * (flags=3) when the sum says nothing else holds the mount. A walker\n+ * in __legitimize_mnt() that sees the seqcount change takes mount_lock\n+ * and reads -\u003emnt_flags there. Not both the walker finding no flag\n+ * set (0:r3=0, it keeps the reference) and the mount being finished\n+ * off (freed=1). mount_lock orders the two critical sections: either\n+ * the walker's comes first and the sum counts its increment, or the\n+ * sum's does and the walker finds MNT_DOOMED.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_w=0;\n+\tputs_w=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tflags=0;\n+\tseq=0;\n+\tfreed=0;\n+}\n+\n+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)\n+{\n+\tint r0;\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\n+\tr0 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tsmp_rmb();\n+\tr1 = READ_ONCE(*seq);\n+\tif (r1 == 0) {\n+\t\tWRITE_ONCE(*gets_w, 1);\n+\t\tsmp_mb();\n+\t\tsmp_rmb();\n+\t\tr2 = READ_ONCE(*seq);\n+\t\tif (r2 != 0) {\n+\t\t\tspin_lock(mlock);\n+\t\t\tr3 = READ_ONCE(*flags);\n+\t\t\tif (r3 != 0) {\n+\t\t\t\tWRITE_ONCE(*puts_w, 1);\n+\t\t\t}\n+\t\t\tspin_unlock(mlock);\n+\t\t}\n+\t}\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_w);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_w);\n+\tr4 = READ_ONCE(*gets_u);\n+\tif (r3 == 0) {\n+\t\tWRITE_ONCE(*flags, 3);\n+\t\tWRITE_ONCE(*freed, 1);\n+\t}\n+\tif (r3 == 1) {\n+\t\tif (r1 == 1) {\n+\t\t\tWRITE_ONCE(*flags, 3);\n+\t\t\tWRITE_ONCE(*freed, 1);\n+\t\t}\n+\t}\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+filter (0:r0=0)\n+exists (0:r1=0 /\\ ~(0:r2=0) /\\ 0:r3=0 /\\ freed=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus\nnew file mode 100644\nindex 0000000000000..66e65920e4912\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus\n@@ -0,0 +1,92 @@\n+C mnt-walker-get-vs-seqcount-no-outer-mb\n+\n+(*\n+ * Result: Never\n+ *\n+ * mnt-walker-get-vs-seqcount.litmus with the sum as mntput_unheld()\n+ * has it: write_seqlock(), the puts pass, the smp_mb() of\n+ * mnt_get_count(), the gets pass, and no smp_mb() between taking the\n+ * lock and the sum. The inner smp_mb() comes after the seqcount store\n+ * and before the gets loads in program order, which is all store\n+ * buffering asks of the unmounter's side.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_w=0;\n+\tputs_w=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tflags=0;\n+\tseq=0;\n+\tfreed=0;\n+}\n+\n+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)\n+{\n+\tint r0;\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\n+\tr0 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tsmp_rmb();\n+\tr1 = READ_ONCE(*seq);\n+\tif (r1 == 0) {\n+\t\tWRITE_ONCE(*gets_w, 1);\n+\t\tsmp_mb();\n+\t\tsmp_rmb();\n+\t\tr2 = READ_ONCE(*seq);\n+\t\tif (r2 != 0) {\n+\t\t\tspin_lock(mlock);\n+\t\t\tr3 = READ_ONCE(*flags);\n+\t\t\tif (r3 != 0) {\n+\t\t\t\tWRITE_ONCE(*puts_w, 1);\n+\t\t\t}\n+\t\t\tspin_unlock(mlock);\n+\t\t}\n+\t}\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tWRITE_ONCE(*flags, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tr1 = READ_ONCE(*puts_w);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_w);\n+\tr4 = READ_ONCE(*gets_u);\n+\tif (r3 == 0) {\n+\t\tWRITE_ONCE(*flags, 3);\n+\t\tWRITE_ONCE(*freed, 1);\n+\t}\n+\tif (r3 == 1) {\n+\t\tif (r1 == 1) {\n+\t\t\tWRITE_ONCE(*flags, 3);\n+\t\t\tWRITE_ONCE(*freed, 1);\n+\t\t}\n+\t}\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+filter (0:r0=0)\n+exists (0:r1=0 /\\ 0:r2=0 /\\ freed=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus\nnew file mode 100644\nindex 0000000000000..e3297207e7609\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus\n@@ -0,0 +1,92 @@\n+C mnt-walker-get-vs-seqcount-nomb\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-walker-get-vs-seqcount.litmus without the smp_mb() between the\n+ * increment and the re-read of the seqcount in __legitimize_mnt().\n+ * The smp_rmb() of read_seqretry() does not order a store against a\n+ * later load: the walker sees the seqcount unchanged and keeps its\n+ * reference while the sum misses the increment and finishes the mount\n+ * off.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_w=0;\n+\tputs_w=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tflags=0;\n+\tseq=0;\n+\tfreed=0;\n+}\n+\n+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)\n+{\n+\tint r0;\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\n+\tr0 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tsmp_rmb();\n+\tr1 = READ_ONCE(*seq);\n+\tif (r1 == 0) {\n+\t\tWRITE_ONCE(*gets_w, 1);\n+\t\tsmp_rmb();\n+\t\tr2 = READ_ONCE(*seq);\n+\t\tif (r2 != 0) {\n+\t\t\tspin_lock(mlock);\n+\t\t\tr3 = READ_ONCE(*flags);\n+\t\t\tif (r3 != 0) {\n+\t\t\t\tWRITE_ONCE(*puts_w, 1);\n+\t\t\t}\n+\t\t\tspin_unlock(mlock);\n+\t\t}\n+\t}\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tWRITE_ONCE(*flags, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_w);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_w);\n+\tr4 = READ_ONCE(*gets_u);\n+\tif (r3 == 0) {\n+\t\tWRITE_ONCE(*flags, 3);\n+\t\tWRITE_ONCE(*freed, 1);\n+\t}\n+\tif (r3 == 1) {\n+\t\tif (r1 == 1) {\n+\t\t\tWRITE_ONCE(*flags, 3);\n+\t\t\tWRITE_ONCE(*freed, 1);\n+\t\t}\n+\t}\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+filter (0:r0=0)\n+exists (0:r1=0 /\\ 0:r2=0 /\\ freed=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus\nnew file mode 100644\nindex 0000000000000..46ca500f8d508\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus\n@@ -0,0 +1,102 @@\n+C mnt-walker-get-vs-seqcount\n+\n+(*\n+ * Result: Never\n+ *\n+ * A walker in __legitimize_mnt() increments its gets counter, does\n+ * smp_mb() and re-reads the seqcount of mount_lock with\n+ * read_seqretry(); if it changed, the walker takes mount_lock and\n+ * drops the reference again when it finds MNT_SYNC_UMOUNT or\n+ * MNT_DOOMED. umount_tree() stores the seqcount when it takes\n+ * write_seqlock(), clears -\u003emnt_ns and sets MNT_SYNC_UMOUNT;\n+ * mntput_unheld() takes the lock again and sums with mnt_get_count():\n+ * the puts pass, smp_mb(), the gets pass. Store buffering between the\n+ * walker's increment and the unmounter's seqcount store: not both the\n+ * walker seeing the seqcount unchanged (0:r1=0, 0:r2=0, it keeps the\n+ * reference) and the sum missing the increment (freed=1, the mount is\n+ * finished off). The walker's smp_mb() and the smp_mb() of\n+ * mnt_get_count() are the two full barriers that takes. The sum is\n+ * modelled with a further smp_mb() ahead of the puts pass, which the\n+ * -no-outer-mb variant drops.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tgets_w=0;\n+\tputs_w=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tflags=0;\n+\tseq=0;\n+\tfreed=0;\n+}\n+\n+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)\n+{\n+\tint r0;\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\n+\tr0 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tsmp_rmb();\n+\tr1 = READ_ONCE(*seq);\n+\tif (r1 == 0) {\n+\t\tWRITE_ONCE(*gets_w, 1);\n+\t\tsmp_mb();\n+\t\tsmp_rmb();\n+\t\tr2 = READ_ONCE(*seq);\n+\t\tif (r2 != 0) {\n+\t\t\tspin_lock(mlock);\n+\t\t\tr3 = READ_ONCE(*flags);\n+\t\t\tif (r3 != 0) {\n+\t\t\t\tWRITE_ONCE(*puts_w, 1);\n+\t\t\t}\n+\t\t\tspin_unlock(mlock);\n+\t\t}\n+\t}\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tWRITE_ONCE(*flags, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tsmp_mb();\n+\tr1 = READ_ONCE(*puts_w);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_w);\n+\tr4 = READ_ONCE(*gets_u);\n+\tif (r3 == 0) {\n+\t\tWRITE_ONCE(*flags, 3);\n+\t\tWRITE_ONCE(*freed, 1);\n+\t}\n+\tif (r3 == 1) {\n+\t\tif (r1 == 1) {\n+\t\t\tWRITE_ONCE(*flags, 3);\n+\t\t\tWRITE_ONCE(*freed, 1);\n+\t\t}\n+\t}\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+filter (0:r0=0)\n+exists (0:r1=0 /\\ 0:r2=0 /\\ freed=1)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus\nnew file mode 100644\nindex 0000000000000..38d52c31f0b82\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus\n@@ -0,0 +1,89 @@\n+C mnt-walker-late-sees-new-pwd-nomb\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-walker-late-sees-new-pwd.litmus without the smp_mb() between the\n+ * puts pass and the gets pass of mnt_get_count(). The smp_wmb() of\n+ * write_sequnlock() orders stores only: the load of the put can be\n+ * satisfied after the seqcount store of the unlock and a walker that\n+ * samples the seqcount after the sum still reads the old cwd.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tpwd=0;\n+\tfseq=0;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tseq=0;\n+}\n+\n+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)\n+{\n+\tint r0;\n+\n+\tspin_lock(fslock);\n+\tWRITE_ONCE(*fseq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*pwd, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*fseq, 2);\n+\tspin_unlock(fslock);\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+P2(int *seq, int *fseq, int *pwd)\n+{\n+\tint r5;\n+\tint r6;\n+\tint r7;\n+\tint r8;\n+\n+\tr5 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tr7 = READ_ONCE(*fseq);\n+\tsmp_rmb();\n+\tr6 = READ_ONCE(*pwd);\n+\tsmp_rmb();\n+\tr8 = READ_ONCE(*fseq);\n+}\n+\n+filter (2:r7=0 /\\ 2:r8=0 \\/ 2:r7=2 /\\ 2:r8=2)\n+exists (1:r1=1 /\\ 2:r5=4 /\\ 2:r6=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus\nnew file mode 100644\nindex 0000000000000..d3d68619311ee\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus\n@@ -0,0 +1,88 @@\n+C mnt-walker-late-sees-new-pwd-nowmb\n+\n+(*\n+ * Result: Sometimes\n+ *\n+ * mnt-walker-late-sees-new-pwd.litmus without the smp_wmb() of\n+ * write_sequnlock() after the store of the new fs-\u003epwd and without the\n+ * smp_wmb() on the fast path of mntput_no_expire(). Nothing orders the\n+ * new fs-\u003epwd before the put: the sum can count the put while a walker\n+ * that samples the seqcount after the sum still reads the old cwd.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tpwd=0;\n+\tfseq=0;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tseq=0;\n+}\n+\n+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)\n+{\n+\tint r0;\n+\n+\tspin_lock(fslock);\n+\tWRITE_ONCE(*fseq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*pwd, 1);\n+\tWRITE_ONCE(*fseq, 2);\n+\tspin_unlock(fslock);\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+P2(int *seq, int *fseq, int *pwd)\n+{\n+\tint r5;\n+\tint r6;\n+\tint r7;\n+\tint r8;\n+\n+\tr5 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tr7 = READ_ONCE(*fseq);\n+\tsmp_rmb();\n+\tr6 = READ_ONCE(*pwd);\n+\tsmp_rmb();\n+\tr8 = READ_ONCE(*fseq);\n+}\n+\n+filter (2:r7=0 /\\ 2:r8=0 \\/ 2:r7=2 /\\ 2:r8=2)\n+exists (1:r1=1 /\\ 2:r5=4 /\\ 2:r6=0)\ndiff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus\nnew file mode 100644\nindex 0000000000000..3e195dd4317a8\n--- /dev/null\n+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus\n@@ -0,0 +1,103 @@\n+C mnt-walker-late-sees-new-pwd\n+\n+(*\n+ * Result: Never\n+ *\n+ * A holder has its cwd on the mount and chdir()s away right before\n+ * mntput_unheld() sums. set_fs_pwd() stores the new fs-\u003epwd under\n+ * write_seqlock() of fs-\u003eseq and then drops the reference to the old cwd\n+ * on the fast path of mntput_no_expire(): smp_wmb(), the put.\n+ * umount_tree() clears -\u003emnt_ns under write_seqlock() of mount_lock and\n+ * mntput_unheld() sums with mnt_get_count() under the lock: the puts\n+ * pass, smp_mb(), the gets pass. The sum counts the put (1:r1=1), comes\n+ * out at one and finishes the mount off. A walker whose path_init()\n+ * samples the seqcount of mount_lock after that critical section\n+ * (2:r5=4) and then reads fs-\u003epwd must not read the old cwd (2:r6=0).\n+ * Its seqcount sample would never change again and __legitimize_mnt()\n+ * would hand it a reference to the finished mount. The smp_wmb() of\n+ * write_sequnlock() orders the new fs-\u003epwd before the put and so does\n+ * the smp_wmb() of the fast path, either one is enough. The smp_mb() of\n+ * mnt_get_count() orders the load of the put before the seqcount store\n+ * of the unlock, and the walker orders its loads with smp_rmb(). A\n+ * holder that already sees -\u003emnt_ns NULL puts under mount_lock, which\n+ * orders the put anyway.\n+ *)\n+\n+{\n+\tmnt_ns=1;\n+\tpwd=0;\n+\tfseq=0;\n+\tgets_h=1;\n+\tputs_h=0;\n+\tgets_u=1;\n+\tputs_u=0;\n+\tseq=0;\n+}\n+\n+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)\n+{\n+\tint r0;\n+\n+\tspin_lock(fslock);\n+\tWRITE_ONCE(*fseq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*pwd, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*fseq, 2);\n+\tspin_unlock(fslock);\n+\n+\trcu_read_lock();\n+\tr0 = READ_ONCE(*mnt_ns);\n+\tif (r0) {\n+\t\tsmp_wmb();\n+\t\tWRITE_ONCE(*puts_h, 1);\n+\t}\n+\trcu_read_unlock();\n+}\n+\n+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)\n+{\n+\tint r1;\n+\tint r2;\n+\tint r3;\n+\tint r4;\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 1);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*mnt_ns, 0);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 2);\n+\tspin_unlock(mlock);\n+\n+\tspin_lock(mlock);\n+\tWRITE_ONCE(*seq, 3);\n+\tsmp_wmb();\n+\tr1 = READ_ONCE(*puts_h);\n+\tr2 = READ_ONCE(*puts_u);\n+\tsmp_mb();\n+\tr3 = READ_ONCE(*gets_h);\n+\tr4 = READ_ONCE(*gets_u);\n+\tsmp_wmb();\n+\tWRITE_ONCE(*seq, 4);\n+\tspin_unlock(mlock);\n+}\n+\n+P2(int *seq, int *fseq, int *pwd)\n+{\n+\tint r5;\n+\tint r6;\n+\tint r7;\n+\tint r8;\n+\n+\tr5 = READ_ONCE(*seq);\n+\tsmp_rmb();\n+\tr7 = READ_ONCE(*fseq);\n+\tsmp_rmb();\n+\tr6 = READ_ONCE(*pwd);\n+\tsmp_rmb();\n+\tr8 = READ_ONCE(*fseq);\n+}\n+\n+filter (2:r7=0 /\\ 2:r8=0 \\/ 2:r7=2 /\\ 2:r8=2)\n+exists (1:r1=1 /\\ 2:r5=4 /\\ 2:r6=0)\ndiff --git a/fs/namespace.c b/fs/namespace.c\nindex 3ed3766f3a183..e6b3a3206f3a8 100644\n--- a/fs/namespace.c\n+++ b/fs/namespace.c\n@@ -1410,10 +1410,47 @@ static void delayed_mntput(struct work_struct *unused)\n }\n static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput);\n \n-static void noinline mntput_no_expire_slowpath(struct mount *mnt)\n+/*\n+ * The count reached zero under mount_lock so we doom the mount and\n+ * cleanup everything.\n+ */\n+static void mntput_final_locked(struct mount *mnt, struct list_head *shrink)\n {\n \tstruct mnt_cover *cover;\n \tstruct hlist_node *n;\n+\n+\tVFS_WARN_ON_ONCE(mnt-\u003emnt.mnt_flags \u0026 MNT_DOOMED);\n+\tmnt-\u003emnt.mnt_flags |= MNT_DOOMED;\n+\n+\tmnt_del_instance(mnt);\n+\tif (unlikely(!list_empty(\u0026mnt-\u003emnt_expire)))\n+\t\tlist_del(\u0026mnt-\u003emnt_expire);\n+\n+\t/* nothing stays attached to an unmounted mount */\n+\tVFS_WARN_ON_ONCE(!list_empty(\u0026mnt-\u003emnt_mounts));\n+\thlist_for_each_entry_safe(cover, n, \u0026mnt-\u003emnt_covers, node)\n+\t\tdrop_cover(cover, shrink);\n+}\n+\n+/* cleanup_mnt() sleeps: from task work, or the workqueue for kernel threads */\n+static void mntput_queue_cleanup(struct mount *mnt)\n+{\n+\tif (likely(!(mnt-\u003emnt.mnt_flags \u0026 MNT_INTERNAL))) {\n+\t\tstruct task_struct *task = current;\n+\t\tif (likely(!(task-\u003eflags \u0026 PF_KTHREAD))) {\n+\t\t\tinit_task_work(\u0026mnt-\u003emnt_rcu, __cleanup_mnt);\n+\t\t\tif (!task_work_add(task, \u0026mnt-\u003emnt_rcu, TWA_RESUME))\n+\t\t\t\treturn;\n+\t\t}\n+\t\tif (llist_add(\u0026mnt-\u003emnt_llist, \u0026delayed_mntput_list))\n+\t\t\tschedule_delayed_work(\u0026delayed_mntput_work, 1);\n+\t\treturn;\n+\t}\n+\tcleanup_mnt(mnt);\n+}\n+\n+static void noinline mntput_no_expire_slowpath(struct mount *mnt)\n+{\n \tLIST_HEAD(list);\n \tint count;\n \n@@ -1437,32 +1474,11 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)\n \t\tunlock_mount_hash();\n \t\treturn;\n \t}\n-\tmnt-\u003emnt.mnt_flags |= MNT_DOOMED;\n+\tmntput_final_locked(mnt, \u0026list);\n \trcu_read_unlock();\n-\n-\tmnt_del_instance(mnt);\n-\tif (unlikely(!list_empty(\u0026mnt-\u003emnt_expire)))\n-\t\tlist_del(\u0026mnt-\u003emnt_expire);\n-\n-\t/* nothing stays attached to an unmounted mount */\n-\tVFS_WARN_ON_ONCE(!list_empty(\u0026mnt-\u003emnt_mounts));\n-\thlist_for_each_entry_safe(cover, n, \u0026mnt-\u003emnt_covers, node)\n-\t\tdrop_cover(cover, \u0026list);\n \tunlock_mount_hash();\n \tshrink_dentry_list(\u0026list);\n-\n-\tif (likely(!(mnt-\u003emnt.mnt_flags \u0026 MNT_INTERNAL))) {\n-\t\tstruct task_struct *task = current;\n-\t\tif (likely(!(task-\u003eflags \u0026 PF_KTHREAD))) {\n-\t\t\tinit_task_work(\u0026mnt-\u003emnt_rcu, __cleanup_mnt);\n-\t\t\tif (!task_work_add(task, \u0026mnt-\u003emnt_rcu, TWA_RESUME))\n-\t\t\t\treturn;\n-\t\t}\n-\t\tif (llist_add(\u0026mnt-\u003emnt_llist, \u0026delayed_mntput_list))\n-\t\t\tschedule_delayed_work(\u0026delayed_mntput_work, 1);\n-\t\treturn;\n-\t}\n-\tcleanup_mnt(mnt);\n+\tmntput_queue_cleanup(mnt);\n }\n \n static void mntput_no_expire(struct mount *mnt)\n@@ -1473,10 +1489,12 @@ static void mntput_no_expire(struct mount *mnt)\n \t\t * Since we don't do lock_mount_hash() here,\n \t\t * -\u003emnt_ns can change under us. However, if it's\n \t\t * non-NULL, then there's a reference that won't\n-\t\t * be dropped until after an RCU delay done after\n-\t\t * turning -\u003emnt_ns NULL. So if we observe it\n-\t\t * non-NULL under rcu_read_lock(), the reference\n-\t\t * we are dropping is not the final one.\n+\t\t * be dropped until after turning -\u003emnt_ns NULL and\n+\t\t * either an RCU delay or a look under mount_lock\n+\t\t * that found it to be the only one left, which it\n+\t\t * isn't while ours is counted (mntput_unheld()).\n+\t\t * So if we observe it non-NULL under rcu_read_lock(),\n+\t\t * the reference we are dropping is not the final one.\n \t\t */\n \t\tsmp_wmb();\t/* pairs with the smp_mb() in mnt_get_count() */\n \t\tmnt_dec_count(mnt);\n@@ -1486,6 +1504,77 @@ static void mntput_no_expire(struct mount *mnt)\n \tmntput_no_expire_slowpath(mnt);\n }\n \n+DEFINE_FREE(mntput_no_expire, struct mount *, if (_T) mntput_no_expire(_T))\n+\n+/*\n+ * Drop the own reference of a mount that has left its namespace without\n+ * waiting for a grace period. mnt_get_count() is biased towards gets,\n+ * i.e., it overcounts rather than undercounts. So if the count under\n+ * mount_lock is one we know its ours and we're going to drop it.\n+ *\n+ * Called under mount_lock, the cleanup of the mount is left to the caller.\n+ * Returns false if somebody else still references the mount.\n+ */\n+static bool mntput_unheld(struct mount *mnt, struct list_head *shrink)\n+{\n+\tVFS_BUG_ON(mnt-\u003emnt_ns);\n+\tif (mnt_get_count(mnt) != 1)\n+\t\treturn false;\n+\tmnt_dec_count(mnt);\n+\tmntput_final_locked(mnt, shrink);\n+\treturn true;\n+}\n+\n+/* peeks per mount_lock hold, pathwalks spin while it is held */\n+#define MNTPUT_UNMOUNTED_BATCH 16\n+\n+/*\n+ * Put the mounts umount_tree() collected. Ideally, every mount just has a\n+ * single reference count which means that we can elide the grace period.\n+ * We batch mntput_unheld() as mnt_get_count() needs to sum over every cpu.\n+ * On big machines it's not that fast. If there are mounts with held references\n+ * we need the grace period.\n+ */\n+static void mntput_unmounted(struct hlist_head *head)\n+{\n+\tstruct hlist_node *p;\n+\tstruct mount *m;\n+\tHLIST_HEAD(held);\n+\n+\twhile (!hlist_empty(head)) {\n+\t\tunsigned int n = 0;\n+\t\tHLIST_HEAD(unheld);\n+\t\tLIST_HEAD(shrink);\n+\n+\t\tlock_mount_hash();\n+\t\thlist_for_each_entry_safe(m, p, head, mnt_umount) {\n+\t\t\thlist_del(\u0026m-\u003emnt_umount);\n+\t\t\tif (mntput_unheld(m, \u0026shrink))\n+\t\t\t\thlist_add_head(\u0026m-\u003emnt_umount, \u0026unheld);\n+\t\t\telse\n+\t\t\t\thlist_add_head(\u0026m-\u003emnt_umount, \u0026held);\n+\t\t\tif (++n == MNTPUT_UNMOUNTED_BATCH)\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tunlock_mount_hash();\n+\t\tshrink_dentry_list(\u0026shrink);\n+\n+\t\thlist_for_each_entry_safe(m, p, \u0026unheld, mnt_umount) {\n+\t\t\thlist_del(\u0026m-\u003emnt_umount);\n+\t\t\tmntput_queue_cleanup(m);\n+\t\t}\n+\t}\n+\n+\tif (hlist_empty(\u0026held))\n+\t\treturn;\n+\n+\tsynchronize_rcu_expedited();\n+\thlist_for_each_entry_safe(m, p, \u0026held, mnt_umount) {\n+\t\thlist_del(\u0026m-\u003emnt_umount);\n+\t\tmntput(\u0026m-\u003emnt);\n+\t}\n+}\n+\n void mntput(struct vfsmount *mnt)\n {\n \tif (mnt) {\n@@ -1509,9 +1598,11 @@ EXPORT_SYMBOL(mntget);\n /*\n * Make a mount point inaccessible to new lookups.\n * Because there may still be current users, the caller MUST WAIT\n- * for an RCU grace period before destroying the mount point.\n+ * for an RCU grace period before destroying the mount point, unless\n+ * it finds under mount_lock that it holds the only reference left,\n+ * see mntput_unheld().\n */\n-void mnt_make_shortterm(struct vfsmount *mnt)\n+static void mnt_make_shortterm(struct vfsmount *mnt)\n {\n \tif (mnt)\n \t\tWRITE_ONCE(real_mount(mnt)-\u003emnt_ns, NULL);\n@@ -1764,8 +1855,6 @@ static void free_mnt_ns(struct mnt_namespace *);\n static void namespace_unlock(void)\n {\n \tstruct hlist_head head;\n-\tstruct hlist_node *p;\n-\tstruct mount *m;\n \tstruct mnt_namespace *ns = emptied_ns;\n \tLIST_HEAD(list);\n \n@@ -1796,12 +1885,7 @@ static void namespace_unlock(void)\n \tif (likely(hlist_empty(\u0026head)))\n \t\treturn;\n \n-\tsynchronize_rcu_expedited();\n-\n-\thlist_for_each_entry_safe(m, p, \u0026head, mnt_umount) {\n-\t\thlist_del(\u0026m-\u003emnt_umount);\n-\t\tmntput(\u0026m-\u003emnt);\n-\t}\n+\tmntput_unmounted(\u0026head);\n }\n \n static inline void namespace_lock(void)\n@@ -1919,8 +2003,10 @@ static int do_umount_root(struct super_block *sb)\n \treturn ret;\n }\n \n+/* Unmount @mnt, dropping the reference the caller holds to it on every path. */\n static int do_umount(struct mount *mnt, int flags)\n {\n+\tstruct mount *ref __free(mntput_no_expire) = mnt;\n \tstruct super_block *sb = mnt-\u003emnt.mnt_sb;\n \tint retval;\n \n@@ -1987,37 +2073,36 @@ static int do_umount(struct mount *mnt, int flags)\n \t\treturn do_umount_root(sb);\n \t}\n \n-\tnamespace_lock();\n-\tlock_mount_hash();\n+\tguard(namespace_excl)();\n+\tguard(mount_writer)();\n \n \t/* Repeat the earlier racy checks, now that we are holding the locks */\n-\tretval = -EINVAL;\n \tif (!check_mnt(mnt))\n-\t\tgoto out;\n+\t\treturn -EINVAL;\n \n \tif (mnt-\u003emnt.mnt_flags \u0026 MNT_LOCKED)\n-\t\tgoto out;\n+\t\treturn -EINVAL;\n \n \tif (!mnt_has_parent(mnt)) /* not the absolute root */\n-\t\tgoto out;\n+\t\treturn -EINVAL;\n \n \tevent++;\n \tif (flags \u0026 MNT_DETACH) {\n \t\tumount_tree(mnt, UMOUNT_PROPAGATE);\n-\t\tretval = 0;\n \t} else {\n \t\tsmp_mb(); // paired with __legitimize_mnt()\n \t\tshrink_submounts(mnt);\n-\t\tretval = -EBUSY;\n-\t\tif (!propagate_mount_busy(mnt, 2)) {\n-\t\t\tumount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);\n-\t\t\tretval = 0;\n-\t\t}\n+\t\tif (propagate_mount_busy(mnt, 2))\n+\t\t\treturn -EBUSY;\n+\t\tumount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);\n \t}\n-out:\n-\tunlock_mount_hash();\n-\tnamespace_unlock();\n-\treturn retval;\n+\t/*\n+\t * By definition the caller's reference isn't the last\n+\t * one, so drop it.\n+\t */\n+\tmnt_dec_count(mnt);\n+\tretain_and_null_ptr(ref);\n+\treturn 0;\n }\n \n /*\n@@ -2101,12 +2186,12 @@ int path_umount(const struct path *path, int flags)\n \tint ret;\n \n \tret = can_umount(path, flags);\n-\tif (!ret)\n-\t\tret = do_umount(mnt, flags);\n-\n \t/* we mustn't call path_put() as that would clear mnt_expiry_mark */\n \tdput(path-\u003edentry);\n-\tmntput_no_expire(mnt);\n+\tif (ret)\n+\t\tmntput_no_expire(mnt);\n+\telse\n+\t\tret = do_umount(mnt, flags);\n \treturn ret;\n }\n \n@@ -6515,23 +6600,23 @@ EXPORT_SYMBOL_GPL(kern_mount);\n void kern_unmount(struct vfsmount *mnt)\n {\n \t/* release long term mount so mount point can be released */\n-\tif (!IS_ERR(mnt)) {\n-\t\tmnt_make_shortterm(mnt);\n-\t\tsynchronize_rcu();\t/* yecchhh... */\n-\t\tmntput(mnt);\n-\t}\n+\tif (!IS_ERR(mnt))\n+\t\tkern_unmount_array(\u0026mnt, 1);\n }\n EXPORT_SYMBOL(kern_unmount);\n \n void kern_unmount_array(struct vfsmount *mnt[], unsigned int num)\n {\n+\tHLIST_HEAD(head);\n \tunsigned int i;\n \n-\tfor (i = 0; i \u003c num; i++)\n+\tfor (i = 0; i \u003c num; i++) {\n+\t\tif (!mnt[i])\n+\t\t\tcontinue;\n \t\tmnt_make_shortterm(mnt[i]);\n-\tsynchronize_rcu_expedited();\n-\tfor (i = 0; i \u003c num; i++)\n-\t\tmntput(mnt[i]);\n+\t\thlist_add_head(\u0026real_mount(mnt[i])-\u003emnt_umount, \u0026head);\n+\t}\n+\tmntput_unmounted(\u0026head);\n }\n EXPORT_SYMBOL(kern_unmount_array);\n \ndiff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h\nindex 80cad4ea96a3e..8ce962ed158e3 100644\n--- a/fs/overlayfs/ovl_entry.h\n+++ b/fs/overlayfs/ovl_entry.h\n@@ -92,6 +92,8 @@ struct ovl_fs {\n \t/* r/o snapshot of upperdir sb's only taken on volatile mounts */\n \terrseq_t errseq;\n \tbool casefold;\n+\t/* -\u003elayers, -\u003efs and -\u003ecreator_cred are read by rcu pathwalks */\n+\tstruct rcu_head rcu;\n };\n \n /* Number of lower layers, not including data-only layers */\ndiff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c\nindex c93fcaa45d4a3..36fa3a3274a69 100644\n--- a/fs/overlayfs/params.c\n+++ b/fs/overlayfs/params.c\n@@ -837,6 +837,26 @@ int ovl_init_fs_context(struct fs_context *fc)\n \n }\n \n+/*\n+ * ovl_permission() and ovl_dentry_revalidate_common() run in rcu pathwalk\n+ * mode and read -\u003elayers[].mnt, -\u003efs and -\u003ecreator_cred through the\n+ * superblock, so those go only after a grace period. The mounts themselves\n+ * are rcu-freed by kern_unmount_array().\n+ */\n+static void ovl_free_fs_rcu(struct rcu_head *head)\n+{\n+\tstruct ovl_fs *ofs = container_of(head, struct ovl_fs, rcu);\n+\n+\tkfree(ofs-\u003elayers);\n+\tkfree(ofs-\u003efs);\n+\tkfree(ofs-\u003econfig.lowerdirs);\n+\tkfree(ofs-\u003econfig.upperdir);\n+\tkfree(ofs-\u003econfig.workdir);\n+\tif (ofs-\u003ecreator_cred)\n+\t\tput_cred(ofs-\u003ecreator_cred);\n+\tkfree(ofs);\n+}\n+\n void ovl_free_fs(struct ovl_fs *ofs)\n {\n \tstruct vfsmount **mounts;\n@@ -860,17 +880,10 @@ void ovl_free_fs(struct ovl_fs *ofs)\n \t\tmounts[i] = ofs-\u003elayers[i].mnt;\n \t}\n \tkern_unmount_array(mounts, ofs-\u003enumlayer);\n-\tkfree(ofs-\u003elayers);\n \tfor (i = 0; i \u003c ofs-\u003enumfs; i++)\n \t\tfree_anon_bdev(ofs-\u003efs[i].pseudo_dev);\n-\tkfree(ofs-\u003efs);\n \n-\tkfree(ofs-\u003econfig.lowerdirs);\n-\tkfree(ofs-\u003econfig.upperdir);\n-\tkfree(ofs-\u003econfig.workdir);\n-\tif (ofs-\u003ecreator_cred)\n-\t\tput_cred(ofs-\u003ecreator_cred);\n-\tkfree(ofs);\n+\tcall_rcu(\u0026ofs-\u003ercu, ovl_free_fs_rcu);\n }\n \n int ovl_fs_params_verify(const struct ovl_fs_context *ctx,\ndiff --git a/include/linux/mount.h b/include/linux/mount.h\nindex b16ba5d456057..2342929e2fff0 100644\n--- a/include/linux/mount.h\n+++ b/include/linux/mount.h\n@@ -74,7 +74,6 @@ extern void mnt_drop_write(struct vfsmount *mnt);\n extern void mnt_drop_write_file(struct file *file);\n extern void mntput(struct vfsmount *mnt);\n extern struct vfsmount *mntget(struct vfsmount *mnt);\n-extern void mnt_make_shortterm(struct vfsmount *mnt);\n extern struct vfsmount *mnt_clone_internal(const struct path *path);\n extern bool __mnt_is_readonly(const struct vfsmount *mnt);\n extern bool mnt_may_suid(struct vfsmount *mnt);\ndiff --git a/ipc/namespace.c b/ipc/namespace.c\nindex 1e71353bdb4a3..24706b910654a 100644\n--- a/ipc/namespace.c\n+++ b/ipc/namespace.c\n@@ -21,7 +21,8 @@\n #include \"util.h\"\n \n /*\n- * The work queue is used to avoid the cost of synchronize_rcu in kern_unmount.\n+ * The work queue keeps the teardown of a namespace out of the callers of\n+ * put_ipc_ns(), the eviction of an mqueue inode among them.\n */\n static void free_ipc(struct work_struct *unused);\n static DECLARE_WORK(free_ipc_work, free_ipc);\n@@ -149,11 +150,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,\n \n static void free_ipc_ns(struct ipc_namespace *ns)\n {\n-\t/*\n-\t * Caller needs to wait for an RCU grace period to have passed\n-\t * after making the mount point inaccessible to new accesses.\n-\t */\n-\tmntput(ns-\u003emq_mnt);\n+\tkern_unmount(ns-\u003emq_mnt);\n \tsem_exit_ns(ns);\n \tmsg_exit_ns(ns);\n \tshm_exit_ns(ns);\n@@ -164,7 +161,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)\n \tdec_ipc_namespaces(ns-\u003eucounts);\n \tput_user_ns(ns-\u003euser_ns);\n \tns_common_free(ns);\n-\tkfree(ns);\n+\tkfree_rcu(ns, ns.ns_rcu);\n }\n \n static LLIST_HEAD(free_ipc_list);\n@@ -173,12 +170,6 @@ static void free_ipc(struct work_struct *unused)\n \tstruct llist_node *node = llist_del_all(\u0026free_ipc_list);\n \tstruct ipc_namespace *n, *t;\n \n-\tllist_for_each_entry_safe(n, t, node, mnt_llist)\n-\t\tmnt_make_shortterm(n-\u003emq_mnt);\n-\n-\t/* Wait for any last users to have gone away. */\n-\tsynchronize_rcu();\n-\n \tllist_for_each_entry_safe(n, t, node, mnt_llist)\n \t\tfree_ipc_ns(n);\n }\ndiff --git a/tools/testing/selftests/filesystems/mount_cycle/.gitignore b/tools/testing/selftests/filesystems/mount_cycle/.gitignore\nindex 30f7dd071bcbb..7b9c4f79053c1 100644\n--- a/tools/testing/selftests/filesystems/mount_cycle/.gitignore\n+++ b/tools/testing/selftests/filesystems/mount_cycle/.gitignore\n@@ -6,3 +6,4 @@ mount_cover_test\n locked_handle_test\n nsfs_rbind_loop_test\n overmount_ns_file_test\n+unheld_umount_test\ndiff --git a/tools/testing/selftests/filesystems/mount_cycle/Makefile b/tools/testing/selftests/filesystems/mount_cycle/Makefile\nindex fbe8c5e19d424..333b7225d89e3 100644\n--- a/tools/testing/selftests/filesystems/mount_cycle/Makefile\n+++ b/tools/testing/selftests/filesystems/mount_cycle/Makefile\n@@ -1,6 +1,6 @@\n # SPDX-License-Identifier: GPL-2.0\n TEST_GEN_PROGS := loop_cycle_test unmounted_tree_test overmount_reparent_test mount_cover_test locked_handle_test\n-TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test\n+TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test unheld_umount_test\n \n CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)\n \ndiff --git a/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c b/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c\nnew file mode 100644\nindex 0000000000000..96e3db277e494\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c\n@@ -0,0 +1,262 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * A mount that nothing else references is torn down before umount(2)\n+ * returns, lazy or not, before the last close of the file that kept it\n+ * alive returns, and before the task that took a mount namespace down\n+ * with it can be reaped. A loop device shows when that has happened: the\n+ * filesystem claims it, and an exclusive open of the device succeeds\n+ * only once the filesystem has let go.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+#include \u003csys/mount.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/wait.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003clinux/loop.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+\n+#define IMAGE_SIZE\t(1440 * 1024)\n+#define SECTOR\t\t512\n+\n+/* A blank FAT12 floppy image: boot sector, two FATs, an empty root directory. */\n+static int write_fat12(int fd)\n+{\n+\tunsigned char sector[SECTOR] = {\n+\t\t0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1',\n+\t\t[11] = 0x00, 0x02,\t/* bytes per sector: 512 */\n+\t\t[13] = 1,\t\t/* sectors per cluster */\n+\t\t[14] = 1, 0,\t\t/* reserved sectors */\n+\t\t[16] = 2,\t\t/* FATs */\n+\t\t[17] = 0xe0, 0x00,\t/* root directory entries: 224 */\n+\t\t[19] = 0x40, 0x0b,\t/* total sectors: 2880 */\n+\t\t[21] = 0xf0,\t\t/* media descriptor */\n+\t\t[22] = 9, 0,\t\t/* sectors per FAT */\n+\t\t[24] = 18, 0,\t\t/* sectors per track */\n+\t\t[26] = 2, 0,\t\t/* heads */\n+\t\t[38] = 0x29,\t\t/* extended boot signature */\n+\t\t[39] = 0x12, 0x34, 0x56, 0x78,\n+\t\t[43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',\n+\t\t[54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ',\n+\t\t[510] = 0x55, 0xaa,\n+\t};\n+\tunsigned char fat[SECTOR] = { 0xf0, 0xff, 0xff };\n+\n+\tif (pwrite(fd, sector, SECTOR, 0) != SECTOR)\n+\t\treturn -1;\n+\t/* the first FAT and the second one, one sector each is enough */\n+\tif (pwrite(fd, fat, SECTOR, 1 * SECTOR) != SECTOR ||\n+\t pwrite(fd, fat, SECTOR, 10 * SECTOR) != SECTOR)\n+\t\treturn -1;\n+\treturn ftruncate(fd, IMAGE_SIZE);\n+}\n+\n+/* Bind a free loop device to the open image @ifd; the device number. */\n+static int loop_bind(int ifd)\n+{\n+\tint cfd, lfd, n;\n+\tchar dev[32];\n+\n+\tcfd = open(\"/dev/loop-control\", O_RDWR);\n+\tif (cfd \u003c 0)\n+\t\treturn -1;\n+\tn = ioctl(cfd, LOOP_CTL_GET_FREE);\n+\tclose(cfd);\n+\tif (n \u003c 0)\n+\t\treturn -1;\n+\tsnprintf(dev, sizeof(dev), \"/dev/loop%d\", n);\n+\tlfd = open(dev, O_RDWR);\n+\tif (lfd \u003c 0)\n+\t\treturn -1;\n+\tif (ioctl(lfd, LOOP_SET_FD, ifd))\n+\t\tn = -1;\n+\tclose(lfd);\n+\treturn n;\n+}\n+\n+/* Mount the loop device at @mp: vfat, or msdos. */\n+static int loop_mount(const char *dev, const char *mp)\n+{\n+\tif (!mount(dev, mp, \"vfat\", 0, NULL))\n+\t\treturn 0;\n+\treturn mount(dev, mp, \"msdos\", 0, NULL);\n+}\n+\n+/*\n+ * An exclusive open of the device fails with EBUSY while a filesystem\n+ * holds it. No retries: the point is that it has been let go by now.\n+ */\n+static bool loop_free(const char *dev)\n+{\n+\tint lfd = open(dev, O_RDONLY | O_EXCL);\n+\n+\tif (lfd \u003c 0)\n+\t\treturn false;\n+\tclose(lfd);\n+\treturn true;\n+}\n+\n+/* Tell the loop device to let go of its image. */\n+static void loop_clear(const char *dev)\n+{\n+\tint lfd = open(dev, O_RDWR);\n+\n+\tif (lfd \u003e= 0) {\n+\t\tioctl(lfd, LOOP_CLR_FD);\n+\t\tclose(lfd);\n+\t}\n+}\n+\n+FIXTURE(unheld_umount) {\n+\tchar dir[64];\n+\tchar mp[80];\n+\tchar dev[32];\n+};\n+\n+FIXTURE_SETUP(unheld_umount)\n+{\n+\tchar img[80];\n+\tint ifd, n;\n+\n+\tif (geteuid() != 0)\n+\t\tSKIP(return, \"test requires CAP_SYS_ADMIN\");\n+\tif (access(\"/dev/loop-control\", R_OK | W_OK))\n+\t\tSKIP(return, \"test requires loop devices\");\n+\n+\tASSERT_EQ(unshare(CLONE_NEWNS), 0);\n+\tASSERT_EQ(mount(\"\", \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\n+\tsnprintf(self-\u003edir, sizeof(self-\u003edir), \"/tmp/unheld_umount.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003edir), NULL);\n+\tASSERT_EQ(mount(\"tmpfs\", self-\u003edir, \"tmpfs\", 0, NULL), 0);\n+\n+\tsnprintf(img, sizeof(img), \"%s/img\", self-\u003edir);\n+\tifd = open(img, O_RDWR | O_CREAT | O_EXCL, 0600);\n+\tASSERT_GE(ifd, 0);\n+\tASSERT_EQ(write_fat12(ifd), 0);\n+\tn = loop_bind(ifd);\n+\tclose(ifd);\t/* the loop device holds the file from now on */\n+\tASSERT_GE(n, 0);\n+\tsnprintf(self-\u003edev, sizeof(self-\u003edev), \"/dev/loop%d\", n);\n+\n+\tsnprintf(self-\u003emp, sizeof(self-\u003emp), \"%s/mnt\", self-\u003edir);\n+\tASSERT_EQ(mkdir(self-\u003emp, 0755), 0);\n+\t/* the harness skips the teardown after a SKIP() here */\n+\tif (loop_mount(self-\u003edev, self-\u003emp)) {\n+\t\tloop_clear(self-\u003edev);\n+\t\tSKIP(return, \"test requires a FAT filesystem\");\n+\t}\n+\tumount2(self-\u003emp, 0);\n+}\n+\n+FIXTURE_TEARDOWN(unheld_umount)\n+{\n+\tumount2(self-\u003emp, MNT_DETACH);\n+\tloop_clear(self-\u003edev);\n+\tumount2(self-\u003edir, MNT_DETACH);\n+\trmdir(self-\u003edir);\n+}\n+\n+/* A synchronous umount(2) returns with the filesystem shut down. */\n+TEST_F(unheld_umount, sync_umount_releases_before_return)\n+{\n+\tASSERT_EQ(loop_mount(self-\u003edev, self-\u003emp), 0);\n+\tASSERT_FALSE(loop_free(self-\u003edev));\n+\tASSERT_EQ(umount2(self-\u003emp, 0), 0);\n+\tEXPECT_TRUE(loop_free(self-\u003edev))\n+\t\tTH_LOG(\"%s is still claimed after umount(2) returned\", self-\u003edev);\n+}\n+\n+/* So does a lazy one when nothing else references the mount. */\n+TEST_F(unheld_umount, lazy_umount_idle_releases_before_return)\n+{\n+\tASSERT_EQ(loop_mount(self-\u003edev, self-\u003emp), 0);\n+\tASSERT_FALSE(loop_free(self-\u003edev));\n+\tASSERT_EQ(umount2(self-\u003emp, MNT_DETACH), 0);\n+\tEXPECT_TRUE(loop_free(self-\u003edev))\n+\t\tTH_LOG(\"%s is still claimed after umount2(MNT_DETACH) returned\", self-\u003edev);\n+}\n+\n+/*\n+ * A lazy umount of a mount that a file descriptor holds leaves the\n+ * filesystem alive; the close that drops the last reference shuts it\n+ * down before it returns.\n+ */\n+TEST_F(unheld_umount, lazy_umount_held_releases_on_close)\n+{\n+\tint fd;\n+\n+\tASSERT_EQ(loop_mount(self-\u003edev, self-\u003emp), 0);\n+\tfd = open(self-\u003emp, O_PATH | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(fd, 0);\n+\tASSERT_EQ(umount2(self-\u003emp, MNT_DETACH), 0);\n+\tEXPECT_FALSE(loop_free(self-\u003edev))\n+\t\tTH_LOG(\"%s was released while a file on it was still open\", self-\u003edev);\n+\tASSERT_EQ(close(fd), 0);\n+\tEXPECT_TRUE(loop_free(self-\u003edev))\n+\t\tTH_LOG(\"%s is still claimed after the last file on it was closed\", self-\u003edev);\n+}\n+\n+/* A synchronous umount(2) of a held mount is refused, nothing changes. */\n+TEST_F(unheld_umount, sync_umount_held_refused)\n+{\n+\tint fd;\n+\n+\tASSERT_EQ(loop_mount(self-\u003edev, self-\u003emp), 0);\n+\tfd = open(self-\u003emp, O_PATH | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(fd, 0);\n+\tEXPECT_EQ(umount2(self-\u003emp, 0), -1);\n+\tEXPECT_EQ(errno, EBUSY);\n+\tEXPECT_FALSE(loop_free(self-\u003edev));\n+\tASSERT_EQ(close(fd), 0);\n+\tASSERT_EQ(umount2(self-\u003emp, 0), 0);\n+\tEXPECT_TRUE(loop_free(self-\u003edev));\n+}\n+\n+/*\n+ * The mounts of a mount namespace go with its last task: by the time\n+ * that task can be reaped the filesystems it had mounted are shut down.\n+ */\n+TEST_F(unheld_umount, namespace_death_releases_before_reap)\n+{\n+\tint status, to_parent[2], to_child[2];\n+\tpid_t pid;\n+\tchar c;\n+\n+\tASSERT_EQ(pipe(to_parent), 0);\n+\tASSERT_EQ(pipe(to_child), 0);\n+\tpid = fork();\n+\tASSERT_GE(pid, 0);\n+\tif (pid == 0) {\n+\t\tclose(to_parent[0]);\n+\t\tclose(to_child[1]);\n+\t\tif (unshare(CLONE_NEWNS) || loop_mount(self-\u003edev, self-\u003emp))\n+\t\t\t_exit(1);\n+\t\tif (write(to_parent[1], \"\", 1) != 1)\n+\t\t\t_exit(2);\n+\t\t/* leave once the parent has looked, with the mount in place */\n+\t\tif (read(to_child[0], \u0026c, 1) != 0)\n+\t\t\t_exit(3);\n+\t\t_exit(0);\n+\t}\n+\tclose(to_parent[1]);\n+\tclose(to_child[0]);\n+\tASSERT_EQ(read(to_parent[0], \u0026c, 1), 1);\n+\tEXPECT_FALSE(loop_free(self-\u003edev))\n+\t\tTH_LOG(\"%s is not claimed by the child's mount\", self-\u003edev);\n+\tclose(to_child[1]);\n+\tASSERT_EQ(waitpid(pid, \u0026status, 0), pid);\n+\tASSERT_EQ(status, 0);\n+\tclose(to_parent[0]);\n+\tEXPECT_TRUE(loop_free(self-\u003edev))\n+\t\tTH_LOG(\"%s is still claimed after the namespace's last task was reaped\", self-\u003edev);\n+}\n+\n+TEST_HARNESS_MAIN\n"
} |
| 2/1 | 2026/10/12 17:40 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"DEBUG_VFS",
"OVERLAY_FS",
"IPC_NS"
],
"FocusSymbols": [
"mntput_unmounted",
"mntput_unheld",
"mntput_final_locked",
"mntput_queue_cleanup",
"do_umount",
"path_umount",
"kern_unmount_array",
"ovl_free_fs",
"ovl_free_fs_rcu",
"free_ipc_ns"
],
"Reasoning": "The patch series modifies core VFS mount lifecycle and reference counting logic by eliding RCU grace periods for mounts that have only a single reference (mntput_unheld, mntput_unmounted). It also adds new assertions (VFS_WARN_ON_ONCE, VFS_BUG_ON) for mount invariants, refactors do_umount locking and reference cleanup, adjusts kern_unmount_array, defers overlayfs cleanup via RCU to safeguard concurrent RCU pathwalks (ovl_free_fs, ovl_free_fs_rcu), and alters IPC namespace destruction. All modified code resides in core subsystems reachable via standard unmount, mount, namespace, and overlayfs operations in virtualized environments. Fuzzing is warranted to uncover concurrency races and verify the new refcount invariants.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit e0aa6941f4f130737b972ad9bf165994c6b8e61d
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Oct 12 17:40:03 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/litmus-tests/README b/Documentation/litmus-tests/README
index 6c666f3422ea3..47fca037c6e14 100644
--- a/Documentation/litmus-tests/README
+++ b/Documentation/litmus-tests/README
@@ -38,6 +38,101 @@ cmpxchg-fail-unordered-2.litmus
acquire operation.
+fs (/fs directory)
+------------------
+
+The reference count of a mount is split into per-CPU gets and puts. A
+holder drops a reference on the fast path of mntput_no_expire() without
+mount_lock, a walker in __legitimize_mnt() takes one during an RCU path
+walk, and the unmounter sums the counters under mount_lock with
+mnt_get_count() to decide whether it can finish the mount off without
+waiting for a grace period. The tests spell write_seqlock() out as a
+spinlock, a seqcount store and smp_wmb(), read_seqbegin() and
+read_seqretry() as READ_ONCE() and smp_rmb(), and the per-CPU counters
+as one variable per CPU.
+
+mnt-sum-misses-fastpath-put.litmus
+ Demonstrates that the sum under mount_lock can miss a put on the
+ fast path of mntput_no_expire(), which is why mntput_unmounted()
+ falls back to a grace period when the count is not one.
+
+mnt-holder-get-before-put.litmus
+ Demonstrates that a fast-path put the sum counts has its get counted
+ too: the smp_wmb() in mntput_no_expire() pairs with the smp_mb()
+ between the puts pass and the gets pass of mnt_get_count().
+
+mnt-holder-get-before-put-nowmb.litmus
+ The same without the holder's smp_wmb(); the sum can count the put
+ but not the get.
+
+mnt-holder-get-before-put-nomb.litmus
+ The same without the smp_mb() inside mnt_get_count(); an smp_mb()
+ ahead of the puts pass does not stand in for it.
+
+mnt-holder-get-before-put-getsfirst.litmus
+ The same with the gets summed before the puts; the order of the two
+ passes is part of the pairing.
+
+mnt-gp-sees-fastpath-put.litmus
+ Demonstrates that after the grace period of mntput_unmounted() the
+ plain mntput() sees the fast-path put the sum missed, because the
+ holder's read-side critical section ended before the grace period.
+
+mnt-gp-sees-fastpath-put-sync-rcu.litmus
+ The same with synchronize_rcu() in place of
+ synchronize_rcu_expedited().
+
+mnt-gp-sees-fastpath-put-nogp.litmus
+ The same with an smp_mb() in place of the grace period; the put can
+ still be missed.
+
+mnt-walker-get-vs-seqcount.litmus
+ Demonstrates the store buffering pairing between the increment and
+ smp_mb() of __legitimize_mnt() and the seqcount store and the
+ smp_mb() of mnt_get_count() under mount_lock: the walker cannot
+ keep a reference to a mount the sum finishes off.
+
+mnt-walker-get-vs-seqcount-no-outer-mb.litmus
+ The same with the sum as the tree has it, without an smp_mb()
+ between taking mount_lock and the sum; the smp_mb() inside
+ mnt_get_count() is the one that pairs.
+
+mnt-walker-get-vs-seqcount-nomb.litmus
+ The same without the walker's smp_mb(); the walker can keep a
+ reference to a freed mount.
+
+mnt-walker-bail-sees-doomed.litmus
+ Demonstrates that a walker which sees the seqcount change and reads
+ ->mnt_flags under mount_lock finds MNT_DOOMED on a mount the sum
+ finished off; mount_lock orders the two critical sections.
+
+mnt-walker-bail-sees-doomed-nolock.litmus
+ The same with ->mnt_flags read outside mount_lock; the walker can
+ miss MNT_DOOMED.
+
+mnt-walker-late-sees-new-pwd.litmus
+ Demonstrates that a walker which starts after the sum finished a
+ mount off cannot reach it through the old cwd of a holder whose put
+ the sum counted: the holder orders the new fs->pwd before the put
+ and the smp_mb() of mnt_get_count() orders the load of the put
+ before the seqcount store the walker samples.
+
+mnt-walker-late-sees-new-pwd-nowmb.litmus
+ The same without the smp_wmb()s that order the new fs->pwd before
+ the put; the walker can read the old cwd.
+
+mnt-walker-late-sees-new-pwd-nomb.litmus
+ The same without the smp_mb() inside mnt_get_count(); the walker can
+ read the old cwd.
+
+mnt-kern-unmount-holder-get-before-put.litmus
+ The holder test for kern_unmount_array(), where mnt_make_shortterm()
+ clears ->mnt_ns with a plain WRITE_ONCE() outside mount_lock.
+
+mnt-kern-unmount-gp-sees-fastpath-put.litmus
+ The grace period test for kern_unmount_array().
+
+
locking (/locking directory)
----------------------------
diff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus
new file mode 100644
index 0000000000000..b0b4037217a4c
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus
@@ -0,0 +1,75 @@
+C mnt-gp-sees-fastpath-put-nogp
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-gp-sees-fastpath-put.litmus with an smp_mb() in place of the
+ * grace period. A barrier orders the unmounter's own accesses and
+ * waits for nothing: the holder's read-side critical section may still
+ * be running and the second sum misses the put like the first one.
+ * Only a grace period covers a fast-path put the sum missed.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ smp_mb();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus
new file mode 100644
index 0000000000000..e8d4b17f14264
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus
@@ -0,0 +1,73 @@
+C mnt-gp-sees-fastpath-put-sync-rcu
+
+(*
+ * Result: Never
+ *
+ * mnt-gp-sees-fastpath-put.litmus with synchronize_rcu() in place of
+ * synchronize_rcu_expedited(). To the memory model the two are the
+ * same fence.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ synchronize_rcu();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus
new file mode 100644
index 0000000000000..b60100fdab5ef
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus
@@ -0,0 +1,79 @@
+C mnt-gp-sees-fastpath-put
+
+(*
+ * Result: Never
+ *
+ * The sum of mntput_unheld() can miss the put of a holder on the fast
+ * path of mntput_no_expire(), see mnt-sum-misses-fastpath-put.litmus.
+ * mntput_unmounted() then waits in synchronize_rcu_expedited() and
+ * drops the own reference with a plain mntput(), which sums again in
+ * mntput_no_expire_slowpath() under mount_lock. The holder read
+ * ->mnt_ns non-NULL inside rcu_read_lock() before umount_tree() stored
+ * NULL, so its read-side critical section, and the put inside it, ends
+ * before the grace period does. The first sum may miss the put
+ * (1:r1), the second one never does (1:r5=1).
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ synchronize_rcu_expedited();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus
new file mode 100644
index 0000000000000..d20470a276fed
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus
@@ -0,0 +1,63 @@
+C mnt-holder-get-before-put-getsfirst
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-holder-get-before-put.litmus with mnt_get_count() summing the
+ * gets before the puts, the smp_mb() still between the two passes.
+ * The order of the passes is part of the pairing: read first, the
+ * gets pass can predate a get whose put is then counted.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus
new file mode 100644
index 0000000000000..2da4353bc0870
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus
@@ -0,0 +1,62 @@
+C mnt-holder-get-before-put-nomb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-holder-get-before-put.litmus without the smp_mb() between the
+ * puts pass and the gets pass of mnt_get_count(). The smp_mb() ahead
+ * of the puts pass is still there and does not help: the barrier that
+ * pairs with the holder's smp_wmb() has to sit between the two loads.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus
new file mode 100644
index 0000000000000..d9070e813e478
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus
@@ -0,0 +1,62 @@
+C mnt-holder-get-before-put-nowmb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-holder-get-before-put.litmus without the smp_wmb() between the
+ * get and the fast-path put in mntput_no_expire(). Nothing orders the
+ * two stores: the sum counts the put but not the get and finishes the
+ * mount off under the holder.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus
new file mode 100644
index 0000000000000..414c303dcbb61
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus
@@ -0,0 +1,73 @@
+C mnt-holder-get-before-put
+
+(*
+ * Result: Never
+ *
+ * A holder with a reference of its own (gets_h=1) does a transient
+ * mntget() and drops it on the fast path of mntput_no_expire(): the
+ * store to its gets counter, READ_ONCE(->mnt_ns) non-NULL, smp_wmb(),
+ * the store to its puts counter. umount_tree() clears ->mnt_ns under
+ * write_seqlock() and mntput_unheld() sums with mnt_get_count(): the
+ * puts pass, smp_mb(), the gets pass. The smp_wmb() pairs with that
+ * smp_mb(), so a put the sum counts has its get counted too. The bad
+ * outcome is the sum counting the put (1:r1=1) but not the get
+ * (1:r3=1): a count of one, and the mount finished off under the
+ * reference the holder still has. Message passing, smp_wmb() on the
+ * holder's side and smp_mb() on the sum's. The sum is modelled with
+ * an smp_mb() ahead of the puts pass as well; it takes no part in
+ * this, see the -nomb variant. A put that lands on another CPU's
+ * counter after a migration is the same test, the model has no CPUs.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus
new file mode 100644
index 0000000000000..59dd434e6a76e
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus
@@ -0,0 +1,70 @@
+C mnt-kern-unmount-gp-sees-fastpath-put
+
+(*
+ * Result: Never
+ *
+ * mnt-gp-sees-fastpath-put.litmus for kern_unmount_array(), where
+ * mnt_make_shortterm() clears ->mnt_ns with a plain WRITE_ONCE()
+ * outside mount_lock. The holder still read it non-NULL inside
+ * rcu_read_lock() before the store, so its read-side critical section
+ * ends before the grace period of mntput_unmounted() does and the
+ * plain mntput() that follows sees its put.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ WRITE_ONCE(*mnt_ns, 0);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ synchronize_rcu_expedited();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus b/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus
new file mode 100644
index 0000000000000..dd7976f06b930
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus
@@ -0,0 +1,60 @@
+C mnt-kern-unmount-holder-get-before-put
+
+(*
+ * Result: Never
+ *
+ * mnt-holder-get-before-put.litmus for kern_unmount_array(), where
+ * mnt_make_shortterm() clears ->mnt_ns with a plain WRITE_ONCE(),
+ * outside mount_lock and without a seqcount write, before
+ * mntput_unmounted() sums under the lock. The pairing is unchanged:
+ * the holder's smp_wmb() against the smp_mb() of mnt_get_count(),
+ * neither of which needs the lock or the seqcount. Only holders are
+ * modelled.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ WRITE_ONCE(*mnt_ns, 0);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus
new file mode 100644
index 0000000000000..34347c6a2b255
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus
@@ -0,0 +1,69 @@
+C mnt-sum-misses-fastpath-put
+
+(*
+ * Result: Sometimes
+ *
+ * A holder drops its reference on the fast path of mntput_no_expire():
+ * READ_ONCE(->mnt_ns) non-NULL under rcu_read_lock(), smp_wmb(), the
+ * put. umount_tree() clears ->mnt_ns under write_seqlock() and
+ * mntput_unheld() sums the counters with mnt_get_count() under the
+ * lock. The holder read ->mnt_ns before it was cleared (0:r0=1) and
+ * the sum still does not count its put (1:r1=0): the put is simply
+ * later. The sum comes out at two, so mntput_unmounted() has to wait
+ * for the holder's read-side critical section before the plain
+ * mntput() that drops the own reference, see
+ * mnt-gp-sees-fastpath-put.litmus. This is why the grace period
+ * branch exists, not a bug.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=0)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus
new file mode 100644
index 0000000000000..233f2e65d25d7
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus
@@ -0,0 +1,89 @@
+C mnt-walker-bail-sees-doomed-nolock
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-bail-sees-doomed.litmus with the walker reading
+ * ->mnt_flags outside mount_lock. Nothing orders that read against
+ * the sum's critical section: the walker can read the flags before
+ * MNT_DOOMED is set and keep a reference to a mount the sum has
+ * finished off. This is why __legitimize_mnt() looks under the lock.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ ~(0:r2=0) /\ 0:r3=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus
new file mode 100644
index 0000000000000..187619db7fb6d
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus
@@ -0,0 +1,95 @@
+C mnt-walker-bail-sees-doomed
+
+(*
+ * Result: Never
+ *
+ * A lazy unmount: umount_tree() clears ->mnt_ns under write_seqlock()
+ * without setting MNT_SYNC_UMOUNT, and mntput_unheld() sets MNT_DOOMED
+ * (flags=3) when the sum says nothing else holds the mount. A walker
+ * in __legitimize_mnt() that sees the seqcount change takes mount_lock
+ * and reads ->mnt_flags there. Not both the walker finding no flag
+ * set (0:r3=0, it keeps the reference) and the mount being finished
+ * off (freed=1). mount_lock orders the two critical sections: either
+ * the walker's comes first and the sum counts its increment, or the
+ * sum's does and the walker finds MNT_DOOMED.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ ~(0:r2=0) /\ 0:r3=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus
new file mode 100644
index 0000000000000..66e65920e4912
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus
@@ -0,0 +1,92 @@
+C mnt-walker-get-vs-seqcount-no-outer-mb
+
+(*
+ * Result: Never
+ *
+ * mnt-walker-get-vs-seqcount.litmus with the sum as mntput_unheld()
+ * has it: write_seqlock(), the puts pass, the smp_mb() of
+ * mnt_get_count(), the gets pass, and no smp_mb() between taking the
+ * lock and the sum. The inner smp_mb() comes after the seqcount store
+ * and before the gets loads in program order, which is all store
+ * buffering asks of the unmounter's side.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ WRITE_ONCE(*flags, 1);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ 0:r2=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus
new file mode 100644
index 0000000000000..e3297207e7609
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus
@@ -0,0 +1,92 @@
+C mnt-walker-get-vs-seqcount-nomb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-get-vs-seqcount.litmus without the smp_mb() between the
+ * increment and the re-read of the seqcount in __legitimize_mnt().
+ * The smp_rmb() of read_seqretry() does not order a store against a
+ * later load: the walker sees the seqcount unchanged and keeps its
+ * reference while the sum misses the increment and finishes the mount
+ * off.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ WRITE_ONCE(*flags, 1);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ 0:r2=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus
new file mode 100644
index 0000000000000..46ca500f8d508
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus
@@ -0,0 +1,102 @@
+C mnt-walker-get-vs-seqcount
+
+(*
+ * Result: Never
+ *
+ * A walker in __legitimize_mnt() increments its gets counter, does
+ * smp_mb() and re-reads the seqcount of mount_lock with
+ * read_seqretry(); if it changed, the walker takes mount_lock and
+ * drops the reference again when it finds MNT_SYNC_UMOUNT or
+ * MNT_DOOMED. umount_tree() stores the seqcount when it takes
+ * write_seqlock(), clears ->mnt_ns and sets MNT_SYNC_UMOUNT;
+ * mntput_unheld() takes the lock again and sums with mnt_get_count():
+ * the puts pass, smp_mb(), the gets pass. Store buffering between the
+ * walker's increment and the unmounter's seqcount store: not both the
+ * walker seeing the seqcount unchanged (0:r1=0, 0:r2=0, it keeps the
+ * reference) and the sum missing the increment (freed=1, the mount is
+ * finished off). The walker's smp_mb() and the smp_mb() of
+ * mnt_get_count() are the two full barriers that takes. The sum is
+ * modelled with a further smp_mb() ahead of the puts pass, which the
+ * -no-outer-mb variant drops.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ WRITE_ONCE(*flags, 1);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ 0:r2=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus
new file mode 100644
index 0000000000000..38d52c31f0b82
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus
@@ -0,0 +1,89 @@
+C mnt-walker-late-sees-new-pwd-nomb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-late-sees-new-pwd.litmus without the smp_mb() between the
+ * puts pass and the gets pass of mnt_get_count(). The smp_wmb() of
+ * write_sequnlock() orders stores only: the load of the put can be
+ * satisfied after the seqcount store of the unlock and a walker that
+ * samples the seqcount after the sum still reads the old cwd.
+ *)
+
+{
+ mnt_ns=1;
+ pwd=0;
+ fseq=0;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+ seq=0;
+}
+
+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)
+{
+ int r0;
+
+ spin_lock(fslock);
+ WRITE_ONCE(*fseq, 1);
+ smp_wmb();
+ WRITE_ONCE(*pwd, 1);
+ smp_wmb();
+ WRITE_ONCE(*fseq, 2);
+ spin_unlock(fslock);
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+P2(int *seq, int *fseq, int *pwd)
+{
+ int r5;
+ int r6;
+ int r7;
+ int r8;
+
+ r5 = READ_ONCE(*seq);
+ smp_rmb();
+ r7 = READ_ONCE(*fseq);
+ smp_rmb();
+ r6 = READ_ONCE(*pwd);
+ smp_rmb();
+ r8 = READ_ONCE(*fseq);
+}
+
+filter (2:r7=0 /\ 2:r8=0 \/ 2:r7=2 /\ 2:r8=2)
+exists (1:r1=1 /\ 2:r5=4 /\ 2:r6=0)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus
new file mode 100644
index 0000000000000..d3d68619311ee
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus
@@ -0,0 +1,88 @@
+C mnt-walker-late-sees-new-pwd-nowmb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-late-sees-new-pwd.litmus without the smp_wmb() of
+ * write_sequnlock() after the store of the new fs->pwd and without the
+ * smp_wmb() on the fast path of mntput_no_expire(). Nothing orders the
+ * new fs->pwd before the put: the sum can count the put while a walker
+ * that samples the seqcount after the sum still reads the old cwd.
+ *)
+
+{
+ mnt_ns=1;
+ pwd=0;
+ fseq=0;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+ seq=0;
+}
+
+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)
+{
+ int r0;
+
+ spin_lock(fslock);
+ WRITE_ONCE(*fseq, 1);
+ smp_wmb();
+ WRITE_ONCE(*pwd, 1);
+ WRITE_ONCE(*fseq, 2);
+ spin_unlock(fslock);
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+P2(int *seq, int *fseq, int *pwd)
+{
+ int r5;
+ int r6;
+ int r7;
+ int r8;
+
+ r5 = READ_ONCE(*seq);
+ smp_rmb();
+ r7 = READ_ONCE(*fseq);
+ smp_rmb();
+ r6 = READ_ONCE(*pwd);
+ smp_rmb();
+ r8 = READ_ONCE(*fseq);
+}
+
+filter (2:r7=0 /\ 2:r8=0 \/ 2:r7=2 /\ 2:r8=2)
+exists (1:r1=1 /\ 2:r5=4 /\ 2:r6=0)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus
new file mode 100644
index 0000000000000..3e195dd4317a8
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus
@@ -0,0 +1,103 @@
+C mnt-walker-late-sees-new-pwd
+
+(*
+ * Result: Never
+ *
+ * A holder has its cwd on the mount and chdir()s away right before
+ * mntput_unheld() sums. set_fs_pwd() stores the new fs->pwd under
+ * write_seqlock() of fs->seq and then drops the reference to the old cwd
+ * on the fast path of mntput_no_expire(): smp_wmb(), the put.
+ * umount_tree() clears ->mnt_ns under write_seqlock() of mount_lock and
+ * mntput_unheld() sums with mnt_get_count() under the lock: the puts
+ * pass, smp_mb(), the gets pass. The sum counts the put (1:r1=1), comes
+ * out at one and finishes the mount off. A walker whose path_init()
+ * samples the seqcount of mount_lock after that critical section
+ * (2:r5=4) and then reads fs->pwd must not read the old cwd (2:r6=0).
+ * Its seqcount sample would never change again and __legitimize_mnt()
+ * would hand it a reference to the finished mount. The smp_wmb() of
+ * write_sequnlock() orders the new fs->pwd before the put and so does
+ * the smp_wmb() of the fast path, either one is enough. The smp_mb() of
+ * mnt_get_count() orders the load of the put before the seqcount store
+ * of the unlock, and the walker orders its loads with smp_rmb(). A
+ * holder that already sees ->mnt_ns NULL puts under mount_lock, which
+ * orders the put anyway.
+ *)
+
+{
+ mnt_ns=1;
+ pwd=0;
+ fseq=0;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+ seq=0;
+}
+
+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)
+{
+ int r0;
+
+ spin_lock(fslock);
+ WRITE_ONCE(*fseq, 1);
+ smp_wmb();
+ WRITE_ONCE(*pwd, 1);
+ smp_wmb();
+ WRITE_ONCE(*fseq, 2);
+ spin_unlock(fslock);
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+P2(int *seq, int *fseq, int *pwd)
+{
+ int r5;
+ int r6;
+ int r7;
+ int r8;
+
+ r5 = READ_ONCE(*seq);
+ smp_rmb();
+ r7 = READ_ONCE(*fseq);
+ smp_rmb();
+ r6 = READ_ONCE(*pwd);
+ smp_rmb();
+ r8 = READ_ONCE(*fseq);
+}
+
+filter (2:r7=0 /\ 2:r8=0 \/ 2:r7=2 /\ 2:r8=2)
+exists (1:r1=1 /\ 2:r5=4 /\ 2:r6=0)
diff --git a/fs/namespace.c b/fs/namespace.c
index 3ed3766f3a183..e6b3a3206f3a8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1410,10 +1410,47 @@ static void delayed_mntput(struct work_struct *unused)
}
static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput);
-static void noinline mntput_no_expire_slowpath(struct mount *mnt)
+/*
+ * The count reached zero under mount_lock so we doom the mount and
+ * cleanup everything.
+ */
+static void mntput_final_locked(struct mount *mnt, struct list_head *shrink)
{
struct mnt_cover *cover;
struct hlist_node *n;
+
+ VFS_WARN_ON_ONCE(mnt->mnt.mnt_flags & MNT_DOOMED);
+ mnt->mnt.mnt_flags |= MNT_DOOMED;
+
+ mnt_del_instance(mnt);
+ if (unlikely(!list_empty(&mnt->mnt_expire)))
+ list_del(&mnt->mnt_expire);
+
+ /* nothing stays attached to an unmounted mount */
+ VFS_WARN_ON_ONCE(!list_empty(&mnt->mnt_mounts));
+ hlist_for_each_entry_safe(cover, n, &mnt->mnt_covers, node)
+ drop_cover(cover, shrink);
+}
+
+/* cleanup_mnt() sleeps: from task work, or the workqueue for kernel threads */
+static void mntput_queue_cleanup(struct mount *mnt)
+{
+ if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) {
+ struct task_struct *task = current;
+ if (likely(!(task->flags & PF_KTHREAD))) {
+ init_task_work(&mnt->mnt_rcu, __cleanup_mnt);
+ if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME))
+ return;
+ }
+ if (llist_add(&mnt->mnt_llist, &delayed_mntput_list))
+ schedule_delayed_work(&delayed_mntput_work, 1);
+ return;
+ }
+ cleanup_mnt(mnt);
+}
+
+static void noinline mntput_no_expire_slowpath(struct mount *mnt)
+{
LIST_HEAD(list);
int count;
@@ -1437,32 +1474,11 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)
unlock_mount_hash();
return;
}
- mnt->mnt.mnt_flags |= MNT_DOOMED;
+ mntput_final_locked(mnt, &list);
rcu_read_unlock();
-
- mnt_del_instance(mnt);
- if (unlikely(!list_empty(&mnt->mnt_expire)))
- list_del(&mnt->mnt_expire);
-
- /* nothing stays attached to an unmounted mount */
- VFS_WARN_ON_ONCE(!list_empty(&mnt->mnt_mounts));
- hlist_for_each_entry_safe(cover, n, &mnt->mnt_covers, node)
- drop_cover(cover, &list);
unlock_mount_hash();
shrink_dentry_list(&list);
-
- if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) {
- struct task_struct *task = current;
- if (likely(!(task->flags & PF_KTHREAD))) {
- init_task_work(&mnt->mnt_rcu, __cleanup_mnt);
- if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME))
- return;
- }
- if (llist_add(&mnt->mnt_llist, &delayed_mntput_list))
- schedule_delayed_work(&delayed_mntput_work, 1);
- return;
- }
- cleanup_mnt(mnt);
+ mntput_queue_cleanup(mnt);
}
static void mntput_no_expire(struct mount *mnt)
@@ -1473,10 +1489,12 @@ static void mntput_no_expire(struct mount *mnt)
* Since we don't do lock_mount_hash() here,
* ->mnt_ns can change under us. However, if it's
* non-NULL, then there's a reference that won't
- * be dropped until after an RCU delay done after
- * turning ->mnt_ns NULL. So if we observe it
- * non-NULL under rcu_read_lock(), the reference
- * we are dropping is not the final one.
+ * be dropped until after turning ->mnt_ns NULL and
+ * either an RCU delay or a look under mount_lock
+ * that found it to be the only one left, which it
+ * isn't while ours is counted (mntput_unheld()).
+ * So if we observe it non-NULL under rcu_read_lock(),
+ * the reference we are dropping is not the final one.
*/
smp_wmb(); /* pairs with the smp_mb() in mnt_get_count() */
mnt_dec_count(mnt);
@@ -1486,6 +1504,77 @@ static void mntput_no_expire(struct mount *mnt)
mntput_no_expire_slowpath(mnt);
}
+DEFINE_FREE(mntput_no_expire, struct mount *, if (_T) mntput_no_expire(_T))
+
+/*
+ * Drop the own reference of a mount that has left its namespace without
+ * waiting for a grace period. mnt_get_count() is biased towards gets,
+ * i.e., it overcounts rather than undercounts. So if the count under
+ * mount_lock is one we know its ours and we're going to drop it.
+ *
+ * Called under mount_lock, the cleanup of the mount is left to the caller.
+ * Returns false if somebody else still references the mount.
+ */
+static bool mntput_unheld(struct mount *mnt, struct list_head *shrink)
+{
+ VFS_BUG_ON(mnt->mnt_ns);
+ if (mnt_get_count(mnt) != 1)
+ return false;
+ mnt_dec_count(mnt);
+ mntput_final_locked(mnt, shrink);
+ return true;
+}
+
+/* peeks per mount_lock hold, pathwalks spin while it is held */
+#define MNTPUT_UNMOUNTED_BATCH 16
+
+/*
+ * Put the mounts umount_tree() collected. Ideally, every mount just has a
+ * single reference count which means that we can elide the grace period.
+ * We batch mntput_unheld() as mnt_get_count() needs to sum over every cpu.
+ * On big machines it's not that fast. If there are mounts with held references
+ * we need the grace period.
+ */
+static void mntput_unmounted(struct hlist_head *head)
+{
+ struct hlist_node *p;
+ struct mount *m;
+ HLIST_HEAD(held);
+
+ while (!hlist_empty(head)) {
+ unsigned int n = 0;
+ HLIST_HEAD(unheld);
+ LIST_HEAD(shrink);
+
+ lock_mount_hash();
+ hlist_for_each_entry_safe(m, p, head, mnt_umount) {
+ hlist_del(&m->mnt_umount);
+ if (mntput_unheld(m, &shrink))
+ hlist_add_head(&m->mnt_umount, &unheld);
+ else
+ hlist_add_head(&m->mnt_umount, &held);
+ if (++n == MNTPUT_UNMOUNTED_BATCH)
+ break;
+ }
+ unlock_mount_hash();
+ shrink_dentry_list(&shrink);
+
+ hlist_for_each_entry_safe(m, p, &unheld, mnt_umount) {
+ hlist_del(&m->mnt_umount);
+ mntput_queue_cleanup(m);
+ }
+ }
+
+ if (hlist_empty(&held))
+ return;
+
+ synchronize_rcu_expedited();
+ hlist_for_each_entry_safe(m, p, &held, mnt_umount) {
+ hlist_del(&m->mnt_umount);
+ mntput(&m->mnt);
+ }
+}
+
void mntput(struct vfsmount *mnt)
{
if (mnt) {
@@ -1509,9 +1598,11 @@ EXPORT_SYMBOL(mntget);
/*
* Make a mount point inaccessible to new lookups.
* Because there may still be current users, the caller MUST WAIT
- * for an RCU grace period before destroying the mount point.
+ * for an RCU grace period before destroying the mount point, unless
+ * it finds under mount_lock that it holds the only reference left,
+ * see mntput_unheld().
*/
-void mnt_make_shortterm(struct vfsmount *mnt)
+static void mnt_make_shortterm(struct vfsmount *mnt)
{
if (mnt)
WRITE_ONCE(real_mount(mnt)->mnt_ns, NULL);
@@ -1764,8 +1855,6 @@ static void free_mnt_ns(struct mnt_namespace *);
static void namespace_unlock(void)
{
struct hlist_head head;
- struct hlist_node *p;
- struct mount *m;
struct mnt_namespace *ns = emptied_ns;
LIST_HEAD(list);
@@ -1796,12 +1885,7 @@ static void namespace_unlock(void)
if (likely(hlist_empty(&head)))
return;
- synchronize_rcu_expedited();
-
- hlist_for_each_entry_safe(m, p, &head, mnt_umount) {
- hlist_del(&m->mnt_umount);
- mntput(&m->mnt);
- }
+ mntput_unmounted(&head);
}
static inline void namespace_lock(void)
@@ -1919,8 +2003,10 @@ static int do_umount_root(struct super_block *sb)
return ret;
}
+/* Unmount @mnt, dropping the reference the caller holds to it on every path. */
static int do_umount(struct mount *mnt, int flags)
{
+ struct mount *ref __free(mntput_no_expire) = mnt;
struct super_block *sb = mnt->mnt.mnt_sb;
int retval;
@@ -1987,37 +2073,36 @@ static int do_umount(struct mount *mnt, int flags)
return do_umount_root(sb);
}
- namespace_lock();
- lock_mount_hash();
+ guard(namespace_excl)();
+ guard(mount_writer)();
/* Repeat the earlier racy checks, now that we are holding the locks */
- retval = -EINVAL;
if (!check_mnt(mnt))
- goto out;
+ return -EINVAL;
if (mnt->mnt.mnt_flags & MNT_LOCKED)
- goto out;
+ return -EINVAL;
if (!mnt_has_parent(mnt)) /* not the absolute root */
- goto out;
+ return -EINVAL;
event++;
if (flags & MNT_DETACH) {
umount_tree(mnt, UMOUNT_PROPAGATE);
- retval = 0;
} else {
smp_mb(); // paired with __legitimize_mnt()
shrink_submounts(mnt);
- retval = -EBUSY;
- if (!propagate_mount_busy(mnt, 2)) {
- umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
- retval = 0;
- }
+ if (propagate_mount_busy(mnt, 2))
+ return -EBUSY;
+ umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
}
-out:
- unlock_mount_hash();
- namespace_unlock();
- return retval;
+ /*
+ * By definition the caller's reference isn't the last
+ * one, so drop it.
+ */
+ mnt_dec_count(mnt);
+ retain_and_null_ptr(ref);
+ return 0;
}
/*
@@ -2101,12 +2186,12 @@ int path_umount(const struct path *path, int flags)
int ret;
ret = can_umount(path, flags);
- if (!ret)
- ret = do_umount(mnt, flags);
-
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
dput(path->dentry);
- mntput_no_expire(mnt);
+ if (ret)
+ mntput_no_expire(mnt);
+ else
+ ret = do_umount(mnt, flags);
return ret;
}
@@ -6515,23 +6600,23 @@ EXPORT_SYMBOL_GPL(kern_mount);
void kern_unmount(struct vfsmount *mnt)
{
/* release long term mount so mount point can be released */
- if (!IS_ERR(mnt)) {
- mnt_make_shortterm(mnt);
- synchronize_rcu(); /* yecchhh... */
- mntput(mnt);
- }
+ if (!IS_ERR(mnt))
+ kern_unmount_array(&mnt, 1);
}
EXPORT_SYMBOL(kern_unmount);
void kern_unmount_array(struct vfsmount *mnt[], unsigned int num)
{
+ HLIST_HEAD(head);
unsigned int i;
- for (i = 0; i < num; i++)
+ for (i = 0; i < num; i++) {
+ if (!mnt[i])
+ continue;
mnt_make_shortterm(mnt[i]);
- synchronize_rcu_expedited();
- for (i = 0; i < num; i++)
- mntput(mnt[i]);
+ hlist_add_head(&real_mount(mnt[i])->mnt_umount, &head);
+ }
+ mntput_unmounted(&head);
}
EXPORT_SYMBOL(kern_unmount_array);
diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
index 80cad4ea96a3e..8ce962ed158e3 100644
--- a/fs/overlayfs/ovl_entry.h
+++ b/fs/overlayfs/ovl_entry.h
@@ -92,6 +92,8 @@ struct ovl_fs {
/* r/o snapshot of upperdir sb's only taken on volatile mounts */
errseq_t errseq;
bool casefold;
+ /* ->layers, ->fs and ->creator_cred are read by rcu pathwalks */
+ struct rcu_head rcu;
};
/* Number of lower layers, not including data-only layers */
diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index c93fcaa45d4a3..36fa3a3274a69 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -837,6 +837,26 @@ int ovl_init_fs_context(struct fs_context *fc)
}
+/*
+ * ovl_permission() and ovl_dentry_revalidate_common() run in rcu pathwalk
+ * mode and read ->layers[].mnt, ->fs and ->creator_cred through the
+ * superblock, so those go only after a grace period. The mounts themselves
+ * are rcu-freed by kern_unmount_array().
+ */
+static void ovl_free_fs_rcu(struct rcu_head *head)
+{
+ struct ovl_fs *ofs = container_of(head, struct ovl_fs, rcu);
+
+ kfree(ofs->layers);
+ kfree(ofs->fs);
+ kfree(ofs->config.lowerdirs);
+ kfree(ofs->config.upperdir);
+ kfree(ofs->config.workdir);
+ if (ofs->creator_cred)
+ put_cred(ofs->creator_cred);
+ kfree(ofs);
+}
+
void ovl_free_fs(struct ovl_fs *ofs)
{
struct vfsmount **mounts;
@@ -860,17 +880,10 @@ void ovl_free_fs(struct ovl_fs *ofs)
mounts[i] = ofs->layers[i].mnt;
}
kern_unmount_array(mounts, ofs->numlayer);
- kfree(ofs->layers);
for (i = 0; i < ofs->numfs; i++)
free_anon_bdev(ofs->fs[i].pseudo_dev);
- kfree(ofs->fs);
- kfree(ofs->config.lowerdirs);
- kfree(ofs->config.upperdir);
- kfree(ofs->config.workdir);
- if (ofs->creator_cred)
- put_cred(ofs->creator_cred);
- kfree(ofs);
+ call_rcu(&ofs->rcu, ovl_free_fs_rcu);
}
int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
diff --git a/include/linux/mount.h b/include/linux/mount.h
index b16ba5d456057..2342929e2fff0 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -74,7 +74,6 @@ extern void mnt_drop_write(struct vfsmount *mnt);
extern void mnt_drop_write_file(struct file *file);
extern void mntput(struct vfsmount *mnt);
extern struct vfsmount *mntget(struct vfsmount *mnt);
-extern void mnt_make_shortterm(struct vfsmount *mnt);
extern struct vfsmount *mnt_clone_internal(const struct path *path);
extern bool __mnt_is_readonly(const struct vfsmount *mnt);
extern bool mnt_may_suid(struct vfsmount *mnt);
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 1e71353bdb4a3..24706b910654a 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -21,7 +21,8 @@
#include "util.h"
/*
- * The work queue is used to avoid the cost of synchronize_rcu in kern_unmount.
+ * The work queue keeps the teardown of a namespace out of the callers of
+ * put_ipc_ns(), the eviction of an mqueue inode among them.
*/
static void free_ipc(struct work_struct *unused);
static DECLARE_WORK(free_ipc_work, free_ipc);
@@ -149,11 +150,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
static void free_ipc_ns(struct ipc_namespace *ns)
{
- /*
- * Caller needs to wait for an RCU grace period to have passed
- * after making the mount point inaccessible to new accesses.
- */
- mntput(ns->mq_mnt);
+ kern_unmount(ns->mq_mnt);
sem_exit_ns(ns);
msg_exit_ns(ns);
shm_exit_ns(ns);
@@ -164,7 +161,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
dec_ipc_namespaces(ns->ucounts);
put_user_ns(ns->user_ns);
ns_common_free(ns);
- kfree(ns);
+ kfree_rcu(ns, ns.ns_rcu);
}
static LLIST_HEAD(free_ipc_list);
@@ -173,12 +170,6 @@ static void free_ipc(struct work_struct *unused)
struct llist_node *node = llist_del_all(&free_ipc_list);
struct ipc_namespace *n, *t;
- llist_for_each_entry_safe(n, t, node, mnt_llist)
- mnt_make_shortterm(n->mq_mnt);
-
- /* Wait for any last users to have gone away. */
- synchronize_rcu();
-
llist_for_each_entry_safe(n, t, node, mnt_llist)
free_ipc_ns(n);
}
diff --git a/tools/testing/selftests/filesystems/mount_cycle/.gitignore b/tools/testing/selftests/filesystems/mount_cycle/.gitignore
index 30f7dd071bcbb..7b9c4f79053c1 100644
--- a/tools/testing/selftests/filesystems/mount_cycle/.gitignore
+++ b/tools/testing/selftests/filesystems/mount_cycle/.gitignore
@@ -6,3 +6,4 @@ mount_cover_test
locked_handle_test
nsfs_rbind_loop_test
overmount_ns_file_test
+unheld_umount_test
diff --git a/tools/testing/selftests/filesystems/mount_cycle/Makefile b/tools/testing/selftests/filesystems/mount_cycle/Makefile
index fbe8c5e19d424..333b7225d89e3 100644
--- a/tools/testing/selftests/filesystems/mount_cycle/Makefile
+++ b/tools/testing/selftests/filesystems/mount_cycle/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
TEST_GEN_PROGS := loop_cycle_test unmounted_tree_test overmount_reparent_test mount_cover_test locked_handle_test
-TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test
+TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test unheld_umount_test
CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
diff --git a/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c b/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c
new file mode 100644
index 0000000000000..96e3db277e494
--- /dev/null
+++ b/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c
@@ -0,0 +1,262 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A mount that nothing else references is torn down before umount(2)
+ * returns, lazy or not, before the last close of the file that kept it
+ * alive returns, and before the task that took a mount namespace down
+ * with it can be reaped. A loop device shows when that has happened: the
+ * filesystem claims it, and an exclusive open of the device succeeds
+ * only once the filesystem has let go.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <linux/loop.h>
+
+#include "../../kselftest_harness.h"
+
+#define IMAGE_SIZE (1440 * 1024)
+#define SECTOR 512
+
+/* A blank FAT12 floppy image: boot sector, two FATs, an empty root directory. */
+static int write_fat12(int fd)
+{
+ unsigned char sector[SECTOR] = {
+ 0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1',
+ [11] = 0x00, 0x02, /* bytes per sector: 512 */
+ [13] = 1, /* sectors per cluster */
+ [14] = 1, 0, /* reserved sectors */
+ [16] = 2, /* FATs */
+ [17] = 0xe0, 0x00, /* root directory entries: 224 */
+ [19] = 0x40, 0x0b, /* total sectors: 2880 */
+ [21] = 0xf0, /* media descriptor */
+ [22] = 9, 0, /* sectors per FAT */
+ [24] = 18, 0, /* sectors per track */
+ [26] = 2, 0, /* heads */
+ [38] = 0x29, /* extended boot signature */
+ [39] = 0x12, 0x34, 0x56, 0x78,
+ [43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',
+ [54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ',
+ [510] = 0x55, 0xaa,
+ };
+ unsigned char fat[SECTOR] = { 0xf0, 0xff, 0xff };
+
+ if (pwrite(fd, sector, SECTOR, 0) != SECTOR)
+ return -1;
+ /* the first FAT and the second one, one sector each is enough */
+ if (pwrite(fd, fat, SECTOR, 1 * SECTOR) != SECTOR ||
+ pwrite(fd, fat, SECTOR, 10 * SECTOR) != SECTOR)
+ return -1;
+ return ftruncate(fd, IMAGE_SIZE);
+}
+
+/* Bind a free loop device to the open image @ifd; the device number. */
+static int loop_bind(int ifd)
+{
+ int cfd, lfd, n;
+ char dev[32];
+
+ cfd = open("/dev/loop-control", O_RDWR);
+ if (cfd < 0)
+ return -1;
+ n = ioctl(cfd, LOOP_CTL_GET_FREE);
+ close(cfd);
+ if (n < 0)
+ return -1;
+ snprintf(dev, sizeof(dev), "/dev/loop%d", n);
+ lfd = open(dev, O_RDWR);
+ if (lfd < 0)
+ return -1;
+ if (ioctl(lfd, LOOP_SET_FD, ifd))
+ n = -1;
+ close(lfd);
+ return n;
+}
+
+/* Mount the loop device at @mp: vfat, or msdos. */
+static int loop_mount(const char *dev, const char *mp)
+{
+ if (!mount(dev, mp, "vfat", 0, NULL))
+ return 0;
+ return mount(dev, mp, "msdos", 0, NULL);
+}
+
+/*
+ * An exclusive open of the device fails with EBUSY while a filesystem
+ * holds it. No retries: the point is that it has been let go by now.
+ */
+static bool loop_free(const char *dev)
+{
+ int lfd = open(dev, O_RDONLY | O_EXCL);
+
+ if (lfd < 0)
+ return false;
+ close(lfd);
+ return true;
+}
+
+/* Tell the loop device to let go of its image. */
+static void loop_clear(const char *dev)
+{
+ int lfd = open(dev, O_RDWR);
+
+ if (lfd >= 0) {
+ ioctl(lfd, LOOP_CLR_FD);
+ close(lfd);
+ }
+}
+
+FIXTURE(unheld_umount) {
+ char dir[64];
+ char mp[80];
+ char dev[32];
+};
+
+FIXTURE_SETUP(unheld_umount)
+{
+ char img[80];
+ int ifd, n;
+
+ if (geteuid() != 0)
+ SKIP(return, "test requires CAP_SYS_ADMIN");
+ if (access("/dev/loop-control", R_OK | W_OK))
+ SKIP(return, "test requires loop devices");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/unheld_umount.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0);
+
+ snprintf(img, sizeof(img), "%s/img", self->dir);
+ ifd = open(img, O_RDWR | O_CREAT | O_EXCL, 0600);
+ ASSERT_GE(ifd, 0);
+ ASSERT_EQ(write_fat12(ifd), 0);
+ n = loop_bind(ifd);
+ close(ifd); /* the loop device holds the file from now on */
+ ASSERT_GE(n, 0);
+ snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", n);
+
+ snprintf(self->mp, sizeof(self->mp), "%s/mnt", self->dir);
+ ASSERT_EQ(mkdir(self->mp, 0755), 0);
+ /* the harness skips the teardown after a SKIP() here */
+ if (loop_mount(self->dev, self->mp)) {
+ loop_clear(self->dev);
+ SKIP(return, "test requires a FAT filesystem");
+ }
+ umount2(self->mp, 0);
+}
+
+FIXTURE_TEARDOWN(unheld_umount)
+{
+ umount2(self->mp, MNT_DETACH);
+ loop_clear(self->dev);
+ umount2(self->dir, MNT_DETACH);
+ rmdir(self->dir);
+}
+
+/* A synchronous umount(2) returns with the filesystem shut down. */
+TEST_F(unheld_umount, sync_umount_releases_before_return)
+{
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ ASSERT_FALSE(loop_free(self->dev));
+ ASSERT_EQ(umount2(self->mp, 0), 0);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after umount(2) returned", self->dev);
+}
+
+/* So does a lazy one when nothing else references the mount. */
+TEST_F(unheld_umount, lazy_umount_idle_releases_before_return)
+{
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ ASSERT_FALSE(loop_free(self->dev));
+ ASSERT_EQ(umount2(self->mp, MNT_DETACH), 0);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after umount2(MNT_DETACH) returned", self->dev);
+}
+
+/*
+ * A lazy umount of a mount that a file descriptor holds leaves the
+ * filesystem alive; the close that drops the last reference shuts it
+ * down before it returns.
+ */
+TEST_F(unheld_umount, lazy_umount_held_releases_on_close)
+{
+ int fd;
+
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ fd = open(self->mp, O_PATH | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(umount2(self->mp, MNT_DETACH), 0);
+ EXPECT_FALSE(loop_free(self->dev))
+ TH_LOG("%s was released while a file on it was still open", self->dev);
+ ASSERT_EQ(close(fd), 0);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after the last file on it was closed", self->dev);
+}
+
+/* A synchronous umount(2) of a held mount is refused, nothing changes. */
+TEST_F(unheld_umount, sync_umount_held_refused)
+{
+ int fd;
+
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ fd = open(self->mp, O_PATH | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ EXPECT_EQ(umount2(self->mp, 0), -1);
+ EXPECT_EQ(errno, EBUSY);
+ EXPECT_FALSE(loop_free(self->dev));
+ ASSERT_EQ(close(fd), 0);
+ ASSERT_EQ(umount2(self->mp, 0), 0);
+ EXPECT_TRUE(loop_free(self->dev));
+}
+
+/*
+ * The mounts of a mount namespace go with its last task: by the time
+ * that task can be reaped the filesystems it had mounted are shut down.
+ */
+TEST_F(unheld_umount, namespace_death_releases_before_reap)
+{
+ int status, to_parent[2], to_child[2];
+ pid_t pid;
+ char c;
+
+ ASSERT_EQ(pipe(to_parent), 0);
+ ASSERT_EQ(pipe(to_child), 0);
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ close(to_parent[0]);
+ close(to_child[1]);
+ if (unshare(CLONE_NEWNS) || loop_mount(self->dev, self->mp))
+ _exit(1);
+ if (write(to_parent[1], "", 1) != 1)
+ _exit(2);
+ /* leave once the parent has looked, with the mount in place */
+ if (read(to_child[0], &c, 1) != 0)
+ _exit(3);
+ _exit(0);
+ }
+ close(to_parent[1]);
+ close(to_child[0]);
+ ASSERT_EQ(read(to_parent[0], &c, 1), 1);
+ EXPECT_FALSE(loop_free(self->dev))
+ TH_LOG("%s is not claimed by the child's mount", self->dev);
+ close(to_child[1]);
+ ASSERT_EQ(waitpid(pid, &status, 0), pid);
+ ASSERT_EQ(status, 0);
+ close(to_parent[0]);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after the namespace's last task was reaped", self->dev);
+}
+
+TEST_HARNESS_MAIN
|
| 3/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31207 output: 31 thoughts: 1213 Thoughts: **Patch Series Evaluation: A Deep Dive into VFS, OverlayFS, and IPC Namespace Refactoring** Alright, let's break this down. The task is to evaluate a Linux kernel patch series. My initial thought? Let's dive straight into the diff. The scope is broad: `Documentation/litmus-tests`, several files within `fs/`, `include/linux/`, and `tools/testing/`. This immediately tells me it's not a trivial change. My immediate focus gravitates towards `fs/namespace.c`, `fs/overlayfs/*`, and `ipc/namespace.c`. These are core components, especially the VFS mount and unmount handling. The changes there are significant – a whole new set of functions like `mntput_final_locked`, `mntput_queue_cleanup`, and `mntput_unheld` – and a complete refactoring of how mount references are managed. `VFS_WARN_ON_ONCE` and `VFS_BUG_ON` checks are a clear indication of careful consideration given to potentially problematic edge cases, hinting at complex concurrency issues related to reference counting and unmounting. The overlayfs changes, particularly the RCU-based `ovl_free_fs`, confirm that they're trying to avoid lockups. And the IPC namespace changes, with the shift to `kfree_rcu`, further support this. I'm seeing a fundamental optimization and refactoring across crucial areas: VFS mount handling (the very heart of how filesystems are managed), overlayfs (a popular stacked filesystem), and IPC namespaces (critical for inter-process communication). Litmus tests have been added which tells me they are serious about memory model correctness, especially when bypassing grace periods. The tests verify aspects of the mount reference counting optimization when the count is one. The presence of runtime checks (`VFS_WARN_ON_ONCE`, `VFS_BUG_ON`) strengthens the idea that these changes are touching core VFS code. And core VFS is definitely reachable by system calls (`umount2`, `mount`, `unshare`, etc.). Given this, `WorthFuzzing` is a resounding "true." This is absolutely worth fuzzing. The triage philosophy specifically calls out core subsystems like memory management, synchronization/locking, VFS, and syscall handling – all of which are directly impacted here. Now, we need to get into the nitty-gritty: `EnableConfigs`, `FocusSymbols`, and the underlying `Reasoning`. I'll need to use grep or read the files to determine what Kconfig options are required to enable this code and identify the exact symbols that are modified or newly introduced which could be useful `FocusSymbols`. Time to dig deeper and look at the actual code! |
| 4/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "config OVERLAY_FS",
"PathPrefixes": [
"fs/overlayfs/"
]
}Results: {
"Output": "fs/overlayfs/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/overlayfs/Kconfig:2:config OVERLAY_FS\nfs/overlayfs/Kconfig-3-\ttristate \"Overlay filesystem support\"\n--\nfs/overlayfs/Kconfig-14-\nfs/overlayfs/Kconfig:15:config OVERLAY_FS_REDIRECT_DIR\nfs/overlayfs/Kconfig-16-\tbool \"Overlayfs: turn on redirect directory feature by default\"\n--\nfs/overlayfs/Kconfig-30-\nfs/overlayfs/Kconfig:31:config OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW\nfs/overlayfs/Kconfig-32-\tbool \"Overlayfs: follow redirects even if redirects are turned off\"\n--\nfs/overlayfs/Kconfig-45-\nfs/overlayfs/Kconfig:46:config OVERLAY_FS_INDEX\nfs/overlayfs/Kconfig-47-\tbool \"Overlayfs: turn on inodes index feature by default\"\n--\nfs/overlayfs/Kconfig-64-\nfs/overlayfs/Kconfig:65:config OVERLAY_FS_NFS_EXPORT\nfs/overlayfs/Kconfig-66-\tbool \"Overlayfs: turn on NFS export feature by default\"\n--\nfs/overlayfs/Kconfig-92-\nfs/overlayfs/Kconfig:93:config OVERLAY_FS_XINO_AUTO\nfs/overlayfs/Kconfig-94-\tbool \"Overlayfs: auto enable inode number mapping\"\n--\nfs/overlayfs/Kconfig-110-\nfs/overlayfs/Kconfig:111:config OVERLAY_FS_METACOPY\nfs/overlayfs/Kconfig-112-\tbool \"Overlayfs: turn on metadata only copy up feature by default\"\n--\nfs/overlayfs/Kconfig-128-\nfs/overlayfs/Kconfig:129:config OVERLAY_FS_DEBUG\nfs/overlayfs/Kconfig-130-\tbool \"Overlayfs: turn on extra debugging checks\"\n"
} |
| 5/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33539 output: 31 thoughts: 13 Thoughts: Here's my take on those thoughts: **Analyzing the IPC/Namespace Kconfig Dependencies** Okay, let's dive into `ipc/namespace.c` and its Kconfig dependencies. This is where the core configuration elements related to inter-process communication and namespaces are defined. My primary interest is understanding how different features are enabled or disabled based on the broader system configuration. I need to identify which Kconfig symbols are relevant and how they influence the build and functionality of the namespace implementation. I'll be looking for cross-dependencies and potential conflicts, especially as they relate to security features and resource isolation. I expect to be tracing the logic to map the configuration options to the conditional compilation directives and understand the relationships between various Kconfig options, ensuring everything aligns with my understanding of the system's design principles. |
| 6/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "IPC_NS",
"PathPrefixes": [
"init/",
"ipc/"
]
}Results: {
"Output": "init/Kconfig=1440=config TIME_NS_VDSO\n--\ninit/Kconfig-1442-\ninit/Kconfig:1443:config IPC_NS\ninit/Kconfig-1444-\tbool \"IPC namespace\"\n--\nipc/Makefile=9=obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o\nipc/Makefile:10:obj-$(CONFIG_IPC_NS) += namespace.o\nipc/Makefile-11-obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o\n--\nipc/msg.c=1306=int msg_init_ns(struct ipc_namespace *ns)\n--\nipc/msg.c-1328-\nipc/msg.c:1329:#ifdef CONFIG_IPC_NS\nipc/msg.c-1330-void msg_exit_ns(struct ipc_namespace *ns)\n--\nipc/msgutil.c=22=DEFINE_SPINLOCK(mq_lock);\n--\nipc/msgutil.c-26- * compiled when either CONFIG_SYSVIPC and CONFIG_POSIX_MQUEUE\nipc/msgutil.c:27: * and not CONFIG_IPC_NS.\nipc/msgutil.c-28- */\n--\nipc/sem.c=249=void sem_init_ns(struct ipc_namespace *ns)\n--\nipc/sem.c-258-\nipc/sem.c:259:#ifdef CONFIG_IPC_NS\nipc/sem.c-260-void sem_exit_ns(struct ipc_namespace *ns)\n--\nipc/shm.c=124=static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)\n--\nipc/shm.c-139-\nipc/shm.c:140:#ifdef CONFIG_IPC_NS\nipc/shm.c-141-void shm_exit_ns(struct ipc_namespace *ns)\n"
} |
| 7/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34254 output: 29 thoughts: 17 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into IPC Namespace Configuration** Alright, let's zero in on `init/Kconfig`. We need to understand how the IPC namespace configuration is being handled. I need to refresh my memory, specifically around `config IPC_NS`. We likely have some dependencies or interactions there that I want to quickly evaluate. This likely involves understanding the different build options, perhaps some conditionals that would drive the inclusion or exclusion of this functionality in the kernel. My goal is to grasp the intricacies related to the IPC namespace configuration and its effects. |
| 8/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "config IPC_NS",
"PathPrefixes": [
"init/Kconfig"
]
}Results: {
"Output": "init/Kconfig=1440=config TIME_NS_VDSO\n--\ninit/Kconfig-1442-\ninit/Kconfig:1443:config IPC_NS\ninit/Kconfig-1444-\tbool \"IPC namespace\"\n"
} |
| 9/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34503 output: 33 thoughts: 18 Thoughts: Here's a summary of my thought process, as requested: **Navigating the Kconfig Labyrinth** Okay, so I'm diving back into this configuration maze. I need to get a better handle on how this particular feature is controlled. Let's start by zeroing in on `init/Kconfig`. This is usually a good place to begin unraveling kernel configurations, so I'll check around line 1443. That should give me a specific starting point within the file to understand the configuration related to the feature. I'm hoping to get a clearer picture from there and see how it might influence other modules. |
| 10/2 | 2026/10/12 17:40 | tool | read-file |
0mArgs:{
"File": "init/Kconfig",
"FirstLine": 1440,
"LineCount": 20
}Results: {
"Contents": "1440:\tconfig TIME_NS_VDSO\n1441:\t\tdef_bool TIME_NS \u0026\u0026 GENERIC_GETTIMEOFDAY\n1442:\t\n1443:\tconfig IPC_NS\n1444:\t\tbool \"IPC namespace\"\n1445:\t\tdepends on (SYSVIPC || POSIX_MQUEUE)\n1446:\t\tdefault y\n1447:\t\thelp\n1448:\t\t In this namespace tasks work with IPC ids which correspond to\n1449:\t\t different IPC objects in different namespaces.\n1450:\t\n1451:\tconfig USER_NS\n1452:\t\tbool \"User namespace\"\n1453:\t\tdefault n\n1454:\t\thelp\n1455:\t\t This allows containers, i.e. vservers, to use user namespaces\n1456:\t\t to provide different user info for different servers.\n1457:\t\n1458:\t\t When user namespaces are enabled in the kernel it is\n1459:\t\t recommended that the MEMCG option also be enabled and that\n"
} |
| 11/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34969 output: 27 thoughts: 46 Thoughts: Okay, let's see. My mind immediately jumps to `fs/namespace.c`. Is that relevant here? Hmm, right, it's part of the standard Virtual File System, isn't it? I know it's a standard part of the VFS because I can see that it's included in the `fs/Makefile` as an object file. It’s part of the default VFS build. Okay, that confirms that I can expect it to be a normal part of the standard VFS, it's not some add-on module. Let's make absolutely sure by checking that `fs/Makefile` again. |
| 12/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "namespace\\.o",
"PathPrefixes": [
"fs/Makefile"
]
}Results: {
"Output": "fs/Makefile=10=obj-y :=\topen.o read_write.o file_table.o super.o \\\n--\nfs/Makefile-12-\t\tioctl.o readdir.o select.o dcache.o inode.o \\\nfs/Makefile:13:\t\tattr.o bad_inode.o file.o filesystems.o namespace.o \\\nfs/Makefile-14-\t\tseq_file.o xattr.o libfs.o fs-writeback.o \\\n--\nfs/Makefile=21=obj-$(CONFIG_BUFFER_HEAD)\t+= buffer.o mpage.o\nfs/Makefile:22:obj-$(CONFIG_PROC_FS)\t\t+= proc_namespace.o\nfs/Makefile-23-obj-$(CONFIG_LEGACY_DIRECT_IO)\t+= direct-io.o\n"
} |
| 13/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35384 output: 29 thoughts: 42 Thoughts: Okay, here's my interpretation of those thoughts, framed as my own: **Navigating the Filesystem Build Process** Alright, so `fs/namespace.c` is always built – that's a given, `obj-y` in the build system confirms that. Now, I'm thinking about overlayfs. I need to understand how *that* fits into the build process. My instinct is to check the `fs/overlayfs/Makefile`. That's where the critical build configuration for overlayfs will live. Let's see what we can find there. |
| 14/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "obj-",
"PathPrefixes": [
"fs/overlayfs/Makefile"
]
}Results: {
"Output": "fs/overlayfs/Makefile-5-\nfs/overlayfs/Makefile:6:obj-$(CONFIG_OVERLAY_FS) += overlay.o\nfs/overlayfs/Makefile-7-\n"
} |
| 15/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35633 output: 30 thoughts: 91 Thoughts: Okay, here's my summary, tailored for an expert audience, as if it were my thought process: **Configuration Dependency Check** Right, let me see... I'm configuring this system. I know OverlayFS needs `CONFIG_OVERLAY_FS`, that's a given. And IPC namespaces, well, those depend on `CONFIG_IPC_NS`, which in turn requires either `SYSVIPC` or `POSIX_MQUEUE`. That's standard stuff. Hmm, but I should probably confirm if there aren't any other configs I'm missing related to the environment. I need to confirm whether `VFS_WARN_ON_ONCE` or `VFS_BUG_ON` are guarded by any debug configs, or if they're always defined regardless of the debug options. Gotta check those definitions because I want to ensure my setup will handle any underlying kernel warnings. |
| 16/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "VFS_WARN_ON_ONCE|VFS_BUG_ON"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 508 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (21 files in total):\nfs/coredump.c:1\nfs/exec.c:1\nfs/file.c:3\nfs/fs_struct.c:3\nfs/inode.c:10\nfs/libfs.c:2\nfs/locks.c:2\nfs/namei.c:6\nfs/namespace.c:11\nfs/nsfs.c:2\nfs/pidfs.c:8\nfs/super.c:6\ninclude/linux/file.h:3\ninclude/linux/fs.h:2\ninclude/linux/fs_struct.h:1\ninclude/linux/fscrypt.h:2\ninclude/linux/ns_common.h:13\ninclude/linux/vfsdebug.h:7\nkernel/fork.c:2\nkernel/nscommon.c:18\nkernel/nstree.c:9\n\nfs/coredump.c=1063=static void coredump_cleanup(struct core_name *cn, struct coredump_params *cprm)\n--\nfs/coredump.c-1067-\tif (cn-\u003ecore_pipe_limit) {\nfs/coredump.c:1068:\t\tVFS_WARN_ON_ONCE(cn-\u003ecore_type != COREDUMP_PIPE);\nfs/coredump.c-1069-\t\tatomic_dec(\u0026core_pipe_count);\n--\nfs/exec.c=117=bool path_noexec(const struct path *path)\n--\nfs/exec.c-119-\t/* If it's an anonymous inode make sure that we catch any shenanigans. */\nfs/exec.c:120:\tVFS_WARN_ON_ONCE(IS_ANON_FILE(d_inode(path-\u003edentry)) \u0026\u0026\nfs/exec.c-121-\t\t\t !(path-\u003emnt-\u003emnt_sb-\u003es_iflags \u0026 SB_I_NOEXEC));\n--\nfs/file.c=569=static int alloc_fd(unsigned start, unsigned end, unsigned flags)\n--\nfs/file.c-606-\terror = fd;\nfs/file.c:607:\tVFS_BUG_ON(rcu_access_pointer(fdt-\u003efd[fd]) != NULL);\nfs/file.c-608-\n--\nfs/file.c=659=static void noinline fd_install_slowpath(unsigned int fd, struct file *file)\n--\nfs/file.c-665-\tfdt = files_fdtable(files);\nfs/file.c:666:\tVFS_BUG_ON(rcu_access_pointer(fdt-\u003efd[fd]) != NULL);\nfs/file.c-667-\trcu_assign_pointer(fdt-\u003efd[fd], file);\n--\nfs/file.c=679=void fd_install(unsigned int fd, struct file *file)\n--\nfs/file.c-695-\tfdt = rcu_dereference_sched(files-\u003efdt);\nfs/file.c:696:\tVFS_BUG_ON(rcu_access_pointer(fdt-\u003efd[fd]) != NULL);\nfs/file.c-697-\trcu_assign_pointer(fdt-\u003efd[fd], file);\n--\nfs/fs_struct.c=132=int unshare_fs_struct(void)\n--\nfs/fs_struct.c-142-\tread_seqlock_excl(\u0026fs-\u003eseq);\nfs/fs_struct.c:143:\tVFS_WARN_ON_ONCE(fs != current-\u003efs);\nfs/fs_struct.c-144-\tkill = !--fs-\u003eusers;\n--\nfs/fs_struct.c=200=struct fs_struct *switch_fs_struct(struct fs_struct *new_fs)\n--\nfs/fs_struct.c-205-\t\tfs = current-\u003efs;\nfs/fs_struct.c:206:\t\tVFS_WARN_ON_ONCE(fs != current-\u003ereal_fs);\nfs/fs_struct.c-207-\t\tread_seqlock_excl(\u0026fs-\u003eseq);\n--\nfs/fs_struct.c=231=void __init init_userspace_fs(void)\n--\nfs/fs_struct.c-240-\nfs/fs_struct.c:241:\tVFS_WARN_ON_ONCE(current-\u003epid != 1);\nfs/fs_struct.c-242-\n--\nfs/inode.c=1577=void ihold(struct inode *inode)\nfs/inode.c-1578-{\nfs/inode.c:1579:\tVFS_BUG_ON_INODE(icount_read_once(inode) \u003c 1, inode);\nfs/inode.c-1580-\tWARN_ON(atomic_inc_return(\u0026inode-\u003ei_count) \u003c 2);\n--\nfs/inode.c=1584=struct inode *igrab(struct inode *inode)\n--\nfs/inode.c-1589-\tif (atomic_add_unless(\u0026inode-\u003ei_count, 1, 0)) {\nfs/inode.c:1590:\t\tVFS_BUG_ON_INODE(inode_state_read_once(inode) \u0026 (I_FREEING | I_WILL_FREE), inode);\nfs/inode.c-1591-\t\treturn inode;\n--\nfs/inode.c=1634=static bool igrab_from_hash(struct inode *inode)\n--\nfs/inode.c-1641-\tif (atomic_add_unless(\u0026inode-\u003ei_count, 1, 0)) {\nfs/inode.c:1642:\t\tVFS_BUG_ON_INODE(inode_state_read_once(inode) \u0026 (I_FREEING | I_WILL_FREE), inode);\nfs/inode.c-1643-\t\treturn true;\n--\nfs/inode.c=1970=static void iput_final(struct inode *inode)\n--\nfs/inode.c-1976-\tWARN_ON(inode_state_read(inode) \u0026 I_NEW);\nfs/inode.c:1977:\tVFS_BUG_ON_INODE(icount_read(inode) != 0, inode);\nfs/inode.c-1978-\n--\nfs/inode.c-1995-\t */\nfs/inode.c:1996:\tVFS_BUG_ON_INODE(icount_read(inode) != 0, inode);\nfs/inode.c-1997-\n--\nfs/inode.c=2026=void iput(struct inode *inode)\n--\nfs/inode.c-2033-\tlockdep_assert_not_held(\u0026inode-\u003ei_lock);\nfs/inode.c:2034:\tVFS_BUG_ON_INODE(inode_state_read_once(inode) \u0026 (I_FREEING | I_CLEAR), inode);\nfs/inode.c-2035-\t/*\n--\nfs/inode.c-2039-\t */\nfs/inode.c:2040:\tVFS_BUG_ON_INODE(icount_read_once(inode) \u003c 1, inode);\nfs/inode.c-2041-\n--\nfs/inode.c=2071=void iput_not_last(struct inode *inode)\nfs/inode.c-2072-{\nfs/inode.c:2073:\tVFS_BUG_ON_INODE(inode_state_read_once(inode) \u0026 (I_FREEING | I_CLEAR), inode);\nfs/inode.c:2074:\tVFS_BUG_ON_INODE(icount_read_once(inode) \u003c 2, inode);\nfs/inode.c-2075-\n--\nfs/inode.c=2591=static void __wait_on_freeing_inode(struct inode *inode, bool hash_locked, bool rcu_locked)\n--\nfs/inode.c-2595-\nfs/inode.c:2596:\tVFS_BUG_ON(!hash_locked \u0026\u0026 !rcu_locked);\nfs/inode.c-2597-\n--\nfs/libfs.c=2230=int path_from_stashed(struct dentry **stashed, struct vfsmount *mnt, void *data,\n--\nfs/libfs.c-2264-\tpath-\u003emnt = mntget(mnt);\nfs/libfs.c:2265:\tVFS_WARN_ON_ONCE(path-\u003edentry-\u003ed_fsdata != stashed);\nfs/libfs.c:2266:\tVFS_WARN_ON_ONCE(d_inode(path-\u003edentry)-\u003ei_private != data);\nfs/libfs.c-2267-\treturn 0;\n--\nfs/locks.c=177=locks_get_lock_context(struct inode *inode, int type)\n--\nfs/locks.c-199-\tif (!(inode-\u003ei_opflags \u0026 IOP_FLCTX)) {\nfs/locks.c:200:\t\tVFS_BUG_ON_INODE(inode-\u003ei_flctx, inode);\nfs/locks.c-201-\t\tWRITE_ONCE(inode-\u003ei_flctx, ctx);\n--\nfs/locks.c-207-\t} else {\nfs/locks.c:208:\t\tVFS_BUG_ON_INODE(!inode-\u003ei_flctx, inode);\nfs/locks.c-209-\t\tspin_unlock(\u0026inode-\u003ei_lock);\n--\nfs/namei.c=683=static __always_inline int lookup_inode_permission_may_exec(struct mnt_idmap *idmap,\n--\nfs/namei.c-686-\t/* Lookup already checked this to return -ENOTDIR */\nfs/namei.c:687:\tVFS_BUG_ON_INODE(!S_ISDIR(inode-\u003ei_mode), inode);\nfs/namei.c:688:\tVFS_BUG_ON((mask \u0026 ~MAY_NOT_BLOCK) != 0);\nfs/namei.c-689-\n--\nfs/namei.c=887=static bool legitimize_links(struct nameidata *nd)\n--\nfs/namei.c-890-\nfs/namei.c:891:\tVFS_BUG_ON(nd-\u003eflags \u0026 LOOKUP_CACHED);\nfs/namei.c-892-\n--\nfs/namei.c=935=static bool try_to_unlazy(struct nameidata *nd)\n--\nfs/namei.c-938-\nfs/namei.c:939:\tVFS_BUG_ON(!(nd-\u003eflags \u0026 LOOKUP_RCU));\nfs/namei.c-940-\n--\nfs/namei.c=976=static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry)\n--\nfs/namei.c-979-\nfs/namei.c:980:\tVFS_BUG_ON(!(nd-\u003eflags \u0026 LOOKUP_RCU));\nfs/namei.c-981-\n--\nfs/namei.c=4260=static int may_open(struct mnt_idmap *idmap, const struct path *path,\n--\nfs/namei.c-4294-\tdefault:\nfs/namei.c:4295:\t\tVFS_BUG_ON_INODE(!IS_ANON_FILE(inode), inode);\nfs/namei.c-4296-\t}\n--\nfs/namespace.c=1417=static void mntput_final_locked(struct mount *mnt, struct list_head *shrink)\n--\nfs/namespace.c-1421-\nfs/namespace.c:1422:\tVFS_WARN_ON_ONCE(mnt-\u003emnt.mnt_flags \u0026 MNT_DOOMED);\nfs/namespace.c-1423-\tmnt-\u003emnt.mnt_flags |= MNT_DOOMED;\n--\nfs/namespace.c-1429-\t/* nothing stays attached to an unmounted mount */\nfs/namespace.c:1430:\tVFS_WARN_ON_ONCE(!list_empty(\u0026mnt-\u003emnt_mounts));\nfs/namespace.c-1431-\thlist_for_each_entry_safe(cover, n, \u0026mnt-\u003emnt_covers, node)\n--\nfs/namespace.c=1452=static void noinline mntput_no_expire_slowpath(struct mount *mnt)\n--\nfs/namespace.c-1456-\nfs/namespace.c:1457:\tVFS_BUG_ON(mnt-\u003emnt_ns);\nfs/namespace.c-1458-\tlock_mount_hash();\n--\nfs/namespace.c=1518=static bool mntput_unheld(struct mount *mnt, struct list_head *shrink)\nfs/namespace.c-1519-{\nfs/namespace.c:1520:\tVFS_BUG_ON(mnt-\u003emnt_ns);\nfs/namespace.c-1521-\tif (mnt_get_count(mnt) != 1)\n--\nfs/namespace.c=1855=static void namespace_unlock(void)\n--\nfs/namespace.c-1878-\t\t/* Make sure we notice when we leak mounts. */\nfs/namespace.c:1879:\t\tVFS_WARN_ON_ONCE(!mnt_ns_empty(ns));\nfs/namespace.c-1880-\t\tfree_mnt_ns(ns);\n--\nfs/namespace.c=1916=static void umount_tree(struct mount *mnt, enum umount_tree_flags how)\n--\nfs/namespace.c-1926-\t\t/* A mount is unmounted once. */\nfs/namespace.c:1927:\t\tVFS_WARN_ON_ONCE(p-\u003emnt.mnt_flags \u0026 MNT_UMOUNT);\nfs/namespace.c-1928-\t\tp-\u003emnt.mnt_flags |= MNT_UMOUNT;\n--\nfs/namespace.c=3290=static struct mnt_namespace *create_new_namespace(struct path *path,\n--\nfs/namespace.c-3321-\nfs/namespace.c:3322:\tVFS_WARN_ON_ONCE(old_ns_root-\u003emnt.mnt_sb-\u003es_type != \u0026nullfs_fs_type);\nfs/namespace.c-3323-\n--\nfs/namespace.c=4052=static void lock_mount_exact(const struct path *path,\n--\nfs/namespace.c-4059-\t/* Assert that inode_lock() locked the correct inode. */\nfs/namespace.c:4060:\tVFS_WARN_ON_ONCE(copy_mount \u0026\u0026 !path_mounted(path));\nfs/namespace.c-4061-\n--\nfs/namespace.c=4133=void mark_mounts_for_expiry(struct list_head *mounts)\n--\nfs/namespace.c-4154-\t\t/* lock_mnt_tree() leaves expirable mounts alone */\nfs/namespace.c:4155:\t\tVFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));\nfs/namespace.c-4156-\t\tif (!xchg(\u0026mnt-\u003emnt_expiry_mark, 1) ||\n--\nfs/namespace.c=6469=static void __init init_mount_tree(void)\n--\nfs/namespace.c-6496-\nfs/namespace.c:6497:\tVFS_WARN_ON_ONCE(real_mount(nullfs_mnt)-\u003emnt_id != 1);\n\n"
} |
| 17/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39940 output: 35 thoughts: 44 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating VFS Debugging Macros** Alright, I want to quickly understand the conditional compilation around those VFS debugging macros, specifically `VFS_WARN_ON_ONCE` and `VFS_BUG_ON`. My first thought is to take a look at `include/linux/vfsdebug.h`. I'm curious if their behavior, or even their very presence, is governed by any specific kernel configuration options. Knowing this will immediately inform my understanding of when and how these checks are active, and what the potential impact might be on a running system. This will help me diagnose issues in the future if I get a bug report. I'm going to look for any preprocessor directives that might guard their definitions. Understanding this dependency helps me understand when these macros will work and when they will do nothing. |
| 18/2 | 2026/10/12 17:40 | tool | read-file |
0mArgs:{
"File": "include/linux/vfsdebug.h",
"FirstLine": 1,
"LineCount": 50
}Results: {
"Contents": " 1:\t/* SPDX-License-Identifier: GPL-2.0 */\n 2:\t#ifndef LINUX_VFS_DEBUG_H\n 3:\t#define LINUX_VFS_DEBUG_H 1\n 4:\t\n 5:\t#include \u003clinux/bug.h\u003e\n 6:\t\n 7:\tstruct inode;\n 8:\t\n 9:\t#ifdef CONFIG_DEBUG_VFS\n 10:\tvoid dump_inode(struct inode *inode, const char *reason);\n 11:\t\n 12:\t#define VFS_BUG_ON(cond) BUG_ON(cond)\n 13:\t#define VFS_WARN_ON(cond) (void)WARN_ON(cond)\n 14:\t#define VFS_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)\n 15:\t#define VFS_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)\n 16:\t#define VFS_WARN(cond, format...) (void)WARN(cond, format)\n 17:\t\n 18:\t#define VFS_BUG_ON_INODE(cond, inode)\t\t({\t\t\t\\\n 19:\t\tif (unlikely(!!(cond))) {\t\t\t\t\t\\\n 20:\t\t\tdump_inode(inode, \"VFS_BUG_ON_INODE(\" #cond\")\");\\\n 21:\t\t\tBUG_ON(1);\t\t\t\t\t\t\\\n 22:\t\t}\t\t\t\t\t\t\t\t\\\n 23:\t})\n 24:\t\n 25:\t#define VFS_WARN_ON_INODE(cond, inode)\t\t({\t\t\t\\\n 26:\t\tint __ret_warn = !!(cond);\t\t\t\t\t\\\n 27:\t\t\t\t\t\t\t\t\t\t\\\n 28:\t\tif (unlikely(__ret_warn)) {\t\t\t\t\t\\\n 29:\t\t\tdump_inode(inode, \"VFS_WARN_ON_INODE(\" #cond\")\");\\\n 30:\t\t\tWARN_ON(1);\t\t\t\t\t\t\\\n 31:\t\t}\t\t\t\t\t\t\t\t\\\n 32:\t\tunlikely(__ret_warn);\t\t\t\t\t\t\\\n 33:\t})\n 34:\t#else\n 35:\t#define VFS_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)\n 36:\t#define VFS_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)\n 37:\t#define VFS_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)\n 38:\t#define VFS_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)\n 39:\t#define VFS_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)\n 40:\t\n 41:\t#define VFS_BUG_ON_INODE(cond, inode) VFS_BUG_ON(cond)\n 42:\t#define VFS_WARN_ON_INODE(cond, inode) BUILD_BUG_ON_INVALID(cond)\n 43:\t#endif /* CONFIG_DEBUG_VFS */\n 44:\t\n 45:\t#endif\n"
} |
| 19/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40994 output: 19 thoughts: 253 Thoughts: **Analyzing VFS Debugging in the Linux Kernel** Right, let's dive into this. My initial instinct was correct; I needed to check `include/linux/vfsdebug.h`. Lines 9-43 are where it's at, and as I suspected, `#ifdef CONFIG_DEBUG_VFS` is the key. Under that configuration, `VFS_BUG_ON(cond)` and `VFS_WARN_ON_ONCE(cond)` resolve to `BUG_ON(cond)` and `(void)WARN_ON_ONCE(cond)` respectively. That's good - standard kernel bug reporting. But without `CONFIG_DEBUG_VFS`... they become `BUILD_BUG_ON_INVALID(cond)`! That's a significant difference – these assertions become compile-time checks, ensuring no invalid conditions are *ever* introduced in a production kernel. Looking at the patch itself, in `mntput_final_locked`, there are `VFS_WARN_ON_ONCE` checks for `MNT_DOOMED` and an empty mounts list. Then, in `mntput_unheld`, there's a `VFS_BUG_ON` check for `mnt->mnt_ns`. It's clear that *`DEBUG_VFS` is essential for these to have any runtime effect*. Without it, they're just compile-time assertions. So, to really understand the implications of this patch and see what assertions it enables and disables, I need to understand when and how `CONFIG_DEBUG_VFS` is defined. Back to the Kconfig I go. |
| 20/2 | 2026/10/12 17:40 | tool | grepper |
0mArgs:{
"Expression": "config DEBUG_VFS"
}Results: {
"Output": "lib/Kconfig.debug=839=config ARCH_HAS_DEBUG_VM_PGTABLE\n--\nlib/Kconfig.debug-844-\nlib/Kconfig.debug:845:config DEBUG_VFS\nlib/Kconfig.debug-846-\tbool \"Debug VFS\"\n"
} |
| 21/2 | 2026/10/12 17:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41697 output: 34 thoughts: 19 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into Debugging Configuration** Okay, so I'm thinking, where should I start looking for this particular debug-related configuration? I need to understand how this is being handled. Let's start with `lib/Kconfig.debug`. It's generally the go-to place for debug-specific options. I'm going to jump to around line 845, that seems like a likely location for the relevant section based on past experience with this codebase and Kconfig structures. That's a reasonable first step to get my bearings and see what’s defined around there. I'm expecting to find either the definition I’m searching for, or pointers towards the relevant code/configuration. |
| 22/2 | 2026/10/12 17:41 | tool | read-file |
0mArgs:{
"File": "lib/Kconfig.debug",
"FirstLine": 843,
"LineCount": 20
}Results: {
"Contents": " 843:\t\t build and run DEBUG_VM_PGTABLE.\n 844:\t\n 845:\tconfig DEBUG_VFS\n 846:\t\tbool \"Debug VFS\"\n 847:\t\tdepends on DEBUG_KERNEL\n 848:\t\thelp\n 849:\t\t Enable this to turn on extended checks in the VFS layer that may impact\n 850:\t\t performance.\n 851:\t\n 852:\t\t If unsure, say N.\n 853:\t\n 854:\tconfig DEBUG_VM_IRQSOFF\n 855:\t\tdef_bool DEBUG_VM \u0026\u0026 !PREEMPT_RT\n 856:\t\n 857:\tconfig DEBUG_VM\n 858:\t\tbool \"Debug VM\"\n 859:\t\tdepends on DEBUG_KERNEL\n 860:\t\thelp\n 861:\t\t Enable this to turn on extended checks in the virtual-memory system\n 862:\t\t that may impact performance.\n"
} |
| 23/2 | 2026/10/12 17:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42179 output: 27 thoughts: 1154 Thoughts: **Analyzing the Impact of RCU-Delayed Free and Unmount Refactoring** Okay, so I'm diving into this patch. First, I need to understand what's being modified and why. The presence of `DEBUG_VFS` suggests it's related to some debugging or tracing feature. I see `OVERLAY_FS` being touched, specifically in `fs/overlayfs/ovl_entry.h` and `fs/overlayfs/params.c`. It looks like they're now using RCU-delayed freeing for the `ovl_fs` struct, and the unmounting of layers is delegated to `kern_unmount_array()`. That's a pretty significant change in resource management for overlay filesystems. Then there's `IPC_NS` which now uses `kern_unmount` and `kfree_rcu` instead of `mntput` for namespace cleanup. Makes sense. Let me take a look at *all* the changed files. I see `fs/namespace.c`, which is clearly central to the changes. OverlayFS, IPC namespaces are involved, of course. I see a few `tools/testing/selftests/...` and `Documentation/litmus-tests/...` files which might be useful for testing and documentation changes. Now, let's break down the functions. A lot of static functions in `fs/namespace.c` have been added, modified, or re-organized. I notice that many of the changes revolve around `mntput` and unmounting. I see things like `mntput_final_locked`, `mntput_queue_cleanup`, `mntput_unheld`, `mntput_unmounted`, `mntput_no_expire_slowpath`, `mntput_no_expire`, `mnt_make_shortterm`, `namespace_unlock`, `do_umount`, `path_umount`, `kern_unmount`, and `kern_unmount_array`. That `mntput_no_expire_slowpath` is marked as `noinline` which is interesting. In `fs/overlayfs/params.c`, there's `ovl_free_fs_rcu` (an RCU callback, which supports my initial guess) and `ovl_free_fs`. And in `ipc/namespace.c`, I see `free_ipc_ns` and `free_ipc`. This all seems to be about the lifecycle of mounts and namespaces, especially as they're cleaned up. I'm thinking about whether some of these static functions, like `mntput_unmounted` or `mntput_unheld` might be inlined by the compiler. If they are, it will impact how I should approach coverage analysis and tracing. But now, from the instructions, I remember that static functions in `.c` files might or might not be inlined. I remember the goal of this review: * Figure out the logic being changed. * Figure out entrypoints to the feature that is added or changed. If they are not static inline functions in a header, I should be able to target them with symbols. Let me see. `mntput_unmounted` has loops, locks, and `synchronize_rcu_expedited()`. It's clearly not a trivial function and therefore *probably* not inlined. `mntput_final_locked` has loops and calls `drop_cover`. And `mntput_no_expire_slowpath` is explicitly marked `noinline`! `path_umount` is global and non-static, so it's exported and can be called from syscalls (`sys_umount`). Now, I need to find the callers of `path_umount` to identify the entrypoints. |
| 24/2 | 2026/10/12 17:41 | tool | grepper |
0mArgs:{
"Expression": "path_umount",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/init.c=47=int __init init_umount(const char *name, int flags)\n--\nfs/init.c-57-\t\treturn ret;\nfs/init.c:58:\treturn path_umount(\u0026path, flags);\nfs/init.c-59-}\n--\nfs/internal.h=92=int path_mount(const char *dev_name, const struct path *path,\nfs/internal.h-93-\t\tconst char *type_page, unsigned long flags, void *data_page);\nfs/internal.h:94:int path_umount(const struct path *path, int flags);\nfs/internal.h-95-int path_pivot_root(struct path *new, struct path *old);\n--\nfs/namespace.c=2164=static int can_umount(const struct path *path, int flags)\n--\nfs/namespace.c-2182-// caller is responsible for flags being sane\nfs/namespace.c:2183:int path_umount(const struct path *path, int flags)\nfs/namespace.c-2184-{\n--\nfs/namespace.c=2198=static int ksys_umount(char __user *name, int flags)\n--\nfs/namespace.c-2212-\t\treturn ret;\nfs/namespace.c:2213:\treturn path_umount(\u0026path, flags);\nfs/namespace.c-2214-}\n"
} |
| 25/2 | 2026/10/12 17:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44538 output: 29 thoughts: 43 Thoughts: Here's my thought process, as if I were analyzing this code: **Unraveling the Umount Path** Okay, so `ksys_umount` is where this whole unmount operation kicks off. That makes sense. It looks like `ksys_umount` then hands the baton to `path_umount`. Good, good, tracking the call chain here. Now, `path_umount` is calling `do_umount`. Alright, that sounds about right – `do_umount` is probably where the heavy lifting of the unmount actually happens. But now I need to understand the locking implications. Where's the critical section? The function I really need to understand is `namespace_unlock`, because that's likely the end of the line, the final critical section. So, where does `namespace_unlock` fit into this? Who calls *it*? I need to check the call graph to see what functions directly invoke `namespace_unlock`. Knowing the callers of `namespace_unlock` will show me the control flow to identify where it is called. |
| 26/2 | 2026/10/12 17:41 | tool | grepper |
0mArgs:{
"Expression": "namespace_unlock",
"PathPrefixes": [
"fs/namespace.c"
]
}Results: {
"Output": "fs/namespace.c=90=static inline void namespace_lock(void);\nfs/namespace.c:91:static void namespace_unlock(void);\nfs/namespace.c:92:DEFINE_LOCK_GUARD_0(namespace_excl, namespace_lock(), namespace_unlock())\nfs/namespace.c-93-DEFINE_LOCK_GUARD_0(namespace_shared, down_read(\u0026namespace_sem),\n--\nfs/namespace.c=1854=static void free_mnt_ns(struct mnt_namespace *);\nfs/namespace.c:1855:static void namespace_unlock(void)\nfs/namespace.c-1856-{\n--\nfs/namespace.c=2917=static void do_lock_mount(const struct path *path,\n--\nfs/namespace.c-2962-\t\t\tres-\u003eparent = ERR_PTR(err);\nfs/namespace.c:2963:\t\t\tnamespace_unlock();\nfs/namespace.c-2964-\t\t\tinode_unlock(dentry-\u003ed_inode);\n--\nfs/namespace.c=2983=static void __unlock_mount(struct pinned_mountpoint *m)\n--\nfs/namespace.c-2988-\tread_sequnlock_excl(\u0026mount_lock);\nfs/namespace.c:2989:\tnamespace_unlock();\nfs/namespace.c-2990-}\n--\nfs/namespace.c=4052=static void lock_mount_exact(const struct path *path,\n--\nfs/namespace.c-4070-\tif (unlikely(err)) {\nfs/namespace.c:4071:\t\tnamespace_unlock();\nfs/namespace.c-4072-\t\tinode_unlock(dentry-\u003ed_inode);\n--\nfs/namespace.c=5167=static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr)\n--\nfs/namespace.c-5191-\t\tif (!anon_ns_root(mnt) \u0026\u0026 !check_mnt(mnt)) {\nfs/namespace.c:5192:\t\t\tnamespace_unlock();\nfs/namespace.c-5193-\t\t\treturn -EINVAL;\n--\nfs/namespace.c-5197-\t\t\tif (err) {\nfs/namespace.c:5198:\t\t\t\tnamespace_unlock();\nfs/namespace.c-5199-\t\t\t\treturn err;\n--\nfs/namespace.c-5225-\t\t\tcleanup_group_ids(mnt, NULL);\nfs/namespace.c:5226:\t\tnamespace_unlock();\nfs/namespace.c-5227-\t}\n"
} |
| 27/2 | 2026/10/12 17:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 45498 output: 306 thoughts: 1994 Thoughts: **Analysis of Filesystem Teardown and Reference Counting for Fuzzing** Alright, let's break this down. My goal here is to identify the key areas of this code change that are ripe for fuzzing. The patch is touching core VFS mount teardown, so it's critical to ensure robustness. First, I see `namespace_unlock` is a key function called by `do_umount`, which is a pivotal function during umount operations. Inside `namespace_unlock`, `mntput_unmounted` is called, which handles unmounting mounts. `mntput_unheld` is a function inside of `mntput_unmounted` that checks mount counts, and will eventually decrement the mount count, and then call `mntput_final_locked`. `kern_unmount_array` is called for unmounting as well, as well as `ovl_free_fs`, during overlayfs teardown, which calls `kern_unmount_array`. IPC namespace destruction also calls `kern_unmount_array`. This suggests significant modification in how unmount operations are processed. Now, the crucial question: is this code reachable and worth fuzzing? Absolutely. The code's functionality is directly accessible through standard syscalls like `umount2`, `mount`, and `unshare` (especially with `CLONE_NEWNS`), plus overlayfs mounts/unmounts, and IPC namespace destruction. This runs on standard x86_64 VMs, so we can consider it ideal for fuzzing. My primary focus then turns to what *specifically* to target. I need to avoid picking ubiquitous functions that are called everywhere, so I will start by reviewing what functions are the most important. After the initial review, I have made a decision on the focus symbols, avoiding those that are used more generally. This lead me to the following: `mntput_unmounted`, `mntput_unheld`, `mntput_final_locked`, `mntput_queue_cleanup`, `do_umount`, `path_umount`, `kern_unmount_array`, `ovl_free_fs`, `ovl_free_fs_rcu`, and `free_ipc_ns`. These functions are specific to this patch's core logic: specifically VFS mount cleanup. Next, I need to identify the configurations needed to enable the code paths and assertions I want to target. I need `DEBUG_VFS` for the assertions, `OVERLAY_FS` for the overlayfs code, and `IPC_NS` for IPC namespace teardown. It's important to make sure all these are activated. I've confirmed that the patch is indeed worth fuzzing due to changes in core VFS mount teardown, particularly related to reference counting and the introduction of new assertions. `mntput_unheld` skipping the RCU grace period under specific mount_lock conditions and the refactor of `do_umount` all signal areas of potential concurrency bugs or race conditions. Overlayfs and IPC teardown modifications further increase the need for thorough testing. Now, let's recap the fuzzing parameters. - `WorthFuzzing`: `true` - `EnableConfigs`: `["DEBUG_VFS", "OVERLAY_FS", "IPC_NS"]` - `FocusSymbols`: `["mntput_unmounted", "mntput_unheld", "mntput_final_locked", "mntput_queue_cleanup", "do_umount", "path_umount", "kern_unmount_array", "ovl_free_fs", "ovl_free_fs_rcu", "free_ipc_ns"]` - `Reasoning`: Concise explanation of key points. Everything checks out. I'm ready to proceed. |
| 28/2 | 2026/10/12 17:41 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"DEBUG_VFS",
"OVERLAY_FS",
"IPC_NS"
],
"FocusSymbols": [
"mntput_unmounted",
"mntput_unheld",
"mntput_final_locked",
"mntput_queue_cleanup",
"do_umount",
"path_umount",
"kern_unmount_array",
"ovl_free_fs",
"ovl_free_fs_rcu",
"free_ipc_ns"
],
"Reasoning": "The patch series modifies core VFS mount lifecycle and reference counting logic by eliding RCU grace periods for mounts that have only a single reference (mntput_unheld, mntput_unmounted). It also adds new assertions (VFS_WARN_ON_ONCE, VFS_BUG_ON) for mount invariants, refactors do_umount locking and reference cleanup, adjusts kern_unmount_array, defers overlayfs cleanup via RCU to safeguard concurrent RCU pathwalks (ovl_free_fs, ovl_free_fs_rcu), and alters IPC namespace destruction. All modified code resides in core subsystems reachable via standard unmount, mount, namespace, and overlayfs operations in virtualized environments. Fuzzing is warranted to uncover concurrency races and verify the new refcount invariants.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"DEBUG_VFS",
"OVERLAY_FS",
"IPC_NS"
],
"FocusSymbols": [
"mntput_unmounted",
"mntput_unheld",
"mntput_final_locked",
"mntput_queue_cleanup",
"do_umount",
"path_umount",
"kern_unmount_array",
"ovl_free_fs",
"ovl_free_fs_rcu",
"free_ipc_ns"
],
"Reasoning": "The patch series modifies core VFS mount lifecycle and reference counting logic by eliding RCU grace periods for mounts that have only a single reference (mntput_unheld, mntput_unmounted). It also adds new assertions (VFS_WARN_ON_ONCE, VFS_BUG_ON) for mount invariants, refactors do_umount locking and reference cleanup, adjusts kern_unmount_array, defers overlayfs cleanup via RCU to safeguard concurrent RCU pathwalks (ovl_free_fs, ovl_free_fs_rcu), and alters IPC namespace destruction. All modified code resides in core subsystems reachable via standard unmount, mount, namespace, and overlayfs operations in virtualized environments. Fuzzing is warranted to uncover concurrency races and verify the new refcount invariants.",
"WorthFuzzing": true
} |
| 29/1 | 2026/10/12 17:41 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 30/2 | 2026/10/12 17:41 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch optimizes VFS mount teardown in fs/namespace.c, fs/overlayfs/params.c, and ipc/namespace.c by skipping unnecessary RCU grace periods when an unmounted tree holds the sole reference to a mount. It modifies reference counting, memory barriers, locking guards, and delayed cleanup (e.g. via call_rcu and task work).\n\nThe primary risks introduced by these changes relate to object lifecycles, memory ordering, and concurrency: specifically, use-after-free (UAF) or premature freeing if a reference is dropped or a structure is cleaned up while an RCU reader or concurrent path walker still holds or accesses it. These failure modes (UAF, double-free, list corruption, locking bugs) are directly monitored and detected by KASAN and LOCKDEP.\n\nKMSAN detects reads of uninitialized memory and information leaks to user space. The patch does not introduce any data copies to user space (no copy_to_user, put_user, netlink messages, or ioctl outputs), does not allocate complex uninitialized memory buffers, and does not add conditional logic reading uninitialized struct fields. All new local variables and list heads (e.g. HLIST_HEAD, LIST_HEAD, loop counters) are properly initialized. Therefore, there are no uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit e0aa6941f4f130737b972ad9bf165994c6b8e61d
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Oct 12 17:40:03 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/litmus-tests/README b/Documentation/litmus-tests/README
index 6c666f3422ea3..47fca037c6e14 100644
--- a/Documentation/litmus-tests/README
+++ b/Documentation/litmus-tests/README
@@ -38,6 +38,101 @@ cmpxchg-fail-unordered-2.litmus
acquire operation.
+fs (/fs directory)
+------------------
+
+The reference count of a mount is split into per-CPU gets and puts. A
+holder drops a reference on the fast path of mntput_no_expire() without
+mount_lock, a walker in __legitimize_mnt() takes one during an RCU path
+walk, and the unmounter sums the counters under mount_lock with
+mnt_get_count() to decide whether it can finish the mount off without
+waiting for a grace period. The tests spell write_seqlock() out as a
+spinlock, a seqcount store and smp_wmb(), read_seqbegin() and
+read_seqretry() as READ_ONCE() and smp_rmb(), and the per-CPU counters
+as one variable per CPU.
+
+mnt-sum-misses-fastpath-put.litmus
+ Demonstrates that the sum under mount_lock can miss a put on the
+ fast path of mntput_no_expire(), which is why mntput_unmounted()
+ falls back to a grace period when the count is not one.
+
+mnt-holder-get-before-put.litmus
+ Demonstrates that a fast-path put the sum counts has its get counted
+ too: the smp_wmb() in mntput_no_expire() pairs with the smp_mb()
+ between the puts pass and the gets pass of mnt_get_count().
+
+mnt-holder-get-before-put-nowmb.litmus
+ The same without the holder's smp_wmb(); the sum can count the put
+ but not the get.
+
+mnt-holder-get-before-put-nomb.litmus
+ The same without the smp_mb() inside mnt_get_count(); an smp_mb()
+ ahead of the puts pass does not stand in for it.
+
+mnt-holder-get-before-put-getsfirst.litmus
+ The same with the gets summed before the puts; the order of the two
+ passes is part of the pairing.
+
+mnt-gp-sees-fastpath-put.litmus
+ Demonstrates that after the grace period of mntput_unmounted() the
+ plain mntput() sees the fast-path put the sum missed, because the
+ holder's read-side critical section ended before the grace period.
+
+mnt-gp-sees-fastpath-put-sync-rcu.litmus
+ The same with synchronize_rcu() in place of
+ synchronize_rcu_expedited().
+
+mnt-gp-sees-fastpath-put-nogp.litmus
+ The same with an smp_mb() in place of the grace period; the put can
+ still be missed.
+
+mnt-walker-get-vs-seqcount.litmus
+ Demonstrates the store buffering pairing between the increment and
+ smp_mb() of __legitimize_mnt() and the seqcount store and the
+ smp_mb() of mnt_get_count() under mount_lock: the walker cannot
+ keep a reference to a mount the sum finishes off.
+
+mnt-walker-get-vs-seqcount-no-outer-mb.litmus
+ The same with the sum as the tree has it, without an smp_mb()
+ between taking mount_lock and the sum; the smp_mb() inside
+ mnt_get_count() is the one that pairs.
+
+mnt-walker-get-vs-seqcount-nomb.litmus
+ The same without the walker's smp_mb(); the walker can keep a
+ reference to a freed mount.
+
+mnt-walker-bail-sees-doomed.litmus
+ Demonstrates that a walker which sees the seqcount change and reads
+ ->mnt_flags under mount_lock finds MNT_DOOMED on a mount the sum
+ finished off; mount_lock orders the two critical sections.
+
+mnt-walker-bail-sees-doomed-nolock.litmus
+ The same with ->mnt_flags read outside mount_lock; the walker can
+ miss MNT_DOOMED.
+
+mnt-walker-late-sees-new-pwd.litmus
+ Demonstrates that a walker which starts after the sum finished a
+ mount off cannot reach it through the old cwd of a holder whose put
+ the sum counted: the holder orders the new fs->pwd before the put
+ and the smp_mb() of mnt_get_count() orders the load of the put
+ before the seqcount store the walker samples.
+
+mnt-walker-late-sees-new-pwd-nowmb.litmus
+ The same without the smp_wmb()s that order the new fs->pwd before
+ the put; the walker can read the old cwd.
+
+mnt-walker-late-sees-new-pwd-nomb.litmus
+ The same without the smp_mb() inside mnt_get_count(); the walker can
+ read the old cwd.
+
+mnt-kern-unmount-holder-get-before-put.litmus
+ The holder test for kern_unmount_array(), where mnt_make_shortterm()
+ clears ->mnt_ns with a plain WRITE_ONCE() outside mount_lock.
+
+mnt-kern-unmount-gp-sees-fastpath-put.litmus
+ The grace period test for kern_unmount_array().
+
+
locking (/locking directory)
----------------------------
diff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus
new file mode 100644
index 0000000000000..b0b4037217a4c
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-nogp.litmus
@@ -0,0 +1,75 @@
+C mnt-gp-sees-fastpath-put-nogp
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-gp-sees-fastpath-put.litmus with an smp_mb() in place of the
+ * grace period. A barrier orders the unmounter's own accesses and
+ * waits for nothing: the holder's read-side critical section may still
+ * be running and the second sum misses the put like the first one.
+ * Only a grace period covers a fast-path put the sum missed.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ smp_mb();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus
new file mode 100644
index 0000000000000..e8d4b17f14264
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put-sync-rcu.litmus
@@ -0,0 +1,73 @@
+C mnt-gp-sees-fastpath-put-sync-rcu
+
+(*
+ * Result: Never
+ *
+ * mnt-gp-sees-fastpath-put.litmus with synchronize_rcu() in place of
+ * synchronize_rcu_expedited(). To the memory model the two are the
+ * same fence.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ synchronize_rcu();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus
new file mode 100644
index 0000000000000..b60100fdab5ef
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-gp-sees-fastpath-put.litmus
@@ -0,0 +1,79 @@
+C mnt-gp-sees-fastpath-put
+
+(*
+ * Result: Never
+ *
+ * The sum of mntput_unheld() can miss the put of a holder on the fast
+ * path of mntput_no_expire(), see mnt-sum-misses-fastpath-put.litmus.
+ * mntput_unmounted() then waits in synchronize_rcu_expedited() and
+ * drops the own reference with a plain mntput(), which sums again in
+ * mntput_no_expire_slowpath() under mount_lock. The holder read
+ * ->mnt_ns non-NULL inside rcu_read_lock() before umount_tree() stored
+ * NULL, so its read-side critical section, and the put inside it, ends
+ * before the grace period does. The first sum may miss the put
+ * (1:r1), the second one never does (1:r5=1).
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ synchronize_rcu_expedited();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus
new file mode 100644
index 0000000000000..d20470a276fed
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-getsfirst.litmus
@@ -0,0 +1,63 @@
+C mnt-holder-get-before-put-getsfirst
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-holder-get-before-put.litmus with mnt_get_count() summing the
+ * gets before the puts, the smp_mb() still between the two passes.
+ * The order of the passes is part of the pairing: read first, the
+ * gets pass can predate a get whose put is then counted.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus
new file mode 100644
index 0000000000000..2da4353bc0870
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nomb.litmus
@@ -0,0 +1,62 @@
+C mnt-holder-get-before-put-nomb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-holder-get-before-put.litmus without the smp_mb() between the
+ * puts pass and the gets pass of mnt_get_count(). The smp_mb() ahead
+ * of the puts pass is still there and does not help: the barrier that
+ * pairs with the holder's smp_wmb() has to sit between the two loads.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus
new file mode 100644
index 0000000000000..d9070e813e478
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put-nowmb.litmus
@@ -0,0 +1,62 @@
+C mnt-holder-get-before-put-nowmb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-holder-get-before-put.litmus without the smp_wmb() between the
+ * get and the fast-path put in mntput_no_expire(). Nothing orders the
+ * two stores: the sum counts the put but not the get and finishes the
+ * mount off under the holder.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus b/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus
new file mode 100644
index 0000000000000..414c303dcbb61
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-holder-get-before-put.litmus
@@ -0,0 +1,73 @@
+C mnt-holder-get-before-put
+
+(*
+ * Result: Never
+ *
+ * A holder with a reference of its own (gets_h=1) does a transient
+ * mntget() and drops it on the fast path of mntput_no_expire(): the
+ * store to its gets counter, READ_ONCE(->mnt_ns) non-NULL, smp_wmb(),
+ * the store to its puts counter. umount_tree() clears ->mnt_ns under
+ * write_seqlock() and mntput_unheld() sums with mnt_get_count(): the
+ * puts pass, smp_mb(), the gets pass. The smp_wmb() pairs with that
+ * smp_mb(), so a put the sum counts has its get counted too. The bad
+ * outcome is the sum counting the put (1:r1=1) but not the get
+ * (1:r3=1): a count of one, and the mount finished off under the
+ * reference the holder still has. Message passing, smp_wmb() on the
+ * holder's side and smp_mb() on the sum's. The sum is modelled with
+ * an smp_mb() ahead of the puts pass as well; it takes no part in
+ * this, see the -nomb variant. A put that lands on another CPU's
+ * counter after a migration is the same test, the model has no CPUs.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus
new file mode 100644
index 0000000000000..59dd434e6a76e
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-kern-unmount-gp-sees-fastpath-put.litmus
@@ -0,0 +1,70 @@
+C mnt-kern-unmount-gp-sees-fastpath-put
+
+(*
+ * Result: Never
+ *
+ * mnt-gp-sees-fastpath-put.litmus for kern_unmount_array(), where
+ * mnt_make_shortterm() clears ->mnt_ns with a plain WRITE_ONCE()
+ * outside mount_lock. The holder still read it non-NULL inside
+ * rcu_read_lock() before the store, so its read-side critical section
+ * ends before the grace period of mntput_unmounted() does and the
+ * plain mntput() that follows sees its put.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r3;
+ int r5;
+ int r6;
+
+ WRITE_ONCE(*mnt_ns, 0);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+
+ synchronize_rcu_expedited();
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 5);
+ smp_wmb();
+ smp_mb();
+ WRITE_ONCE(*puts_u, 1);
+ r5 = READ_ONCE(*puts_h);
+ smp_mb();
+ r6 = READ_ONCE(*gets_h);
+ smp_wmb();
+ WRITE_ONCE(*seq, 6);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r5=0)
diff --git a/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus b/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus
new file mode 100644
index 0000000000000..dd7976f06b930
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-kern-unmount-holder-get-before-put.litmus
@@ -0,0 +1,60 @@
+C mnt-kern-unmount-holder-get-before-put
+
+(*
+ * Result: Never
+ *
+ * mnt-holder-get-before-put.litmus for kern_unmount_array(), where
+ * mnt_make_shortterm() clears ->mnt_ns with a plain WRITE_ONCE(),
+ * outside mount_lock and without a seqcount write, before
+ * mntput_unmounted() sums under the lock. The pairing is unchanged:
+ * the holder's smp_wmb() against the smp_mb() of mnt_get_count(),
+ * neither of which needs the lock or the seqcount. Only holders are
+ * modelled.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ WRITE_ONCE(*gets_h, 2);
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ WRITE_ONCE(*mnt_ns, 0);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=1 /\ 1:r3=1)
diff --git a/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus b/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus
new file mode 100644
index 0000000000000..34347c6a2b255
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-sum-misses-fastpath-put.litmus
@@ -0,0 +1,69 @@
+C mnt-sum-misses-fastpath-put
+
+(*
+ * Result: Sometimes
+ *
+ * A holder drops its reference on the fast path of mntput_no_expire():
+ * READ_ONCE(->mnt_ns) non-NULL under rcu_read_lock(), smp_wmb(), the
+ * put. umount_tree() clears ->mnt_ns under write_seqlock() and
+ * mntput_unheld() sums the counters with mnt_get_count() under the
+ * lock. The holder read ->mnt_ns before it was cleared (0:r0=1) and
+ * the sum still does not count its put (1:r1=0): the put is simply
+ * later. The sum comes out at two, so mntput_unmounted() has to wait
+ * for the holder's read-side critical section before the plain
+ * mntput() that drops the own reference, see
+ * mnt-gp-sees-fastpath-put.litmus. This is why the grace period
+ * branch exists, not a bug.
+ *)
+
+{
+ mnt_ns=1;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+}
+
+P0(int *mnt_ns, int *gets_h, int *puts_h)
+{
+ int r0;
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+exists (0:r0=1 /\ 1:r1=0)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus
new file mode 100644
index 0000000000000..233f2e65d25d7
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed-nolock.litmus
@@ -0,0 +1,89 @@
+C mnt-walker-bail-sees-doomed-nolock
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-bail-sees-doomed.litmus with the walker reading
+ * ->mnt_flags outside mount_lock. Nothing orders that read against
+ * the sum's critical section: the walker can read the flags before
+ * MNT_DOOMED is set and keep a reference to a mount the sum has
+ * finished off. This is why __legitimize_mnt() looks under the lock.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ ~(0:r2=0) /\ 0:r3=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus
new file mode 100644
index 0000000000000..187619db7fb6d
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-bail-sees-doomed.litmus
@@ -0,0 +1,95 @@
+C mnt-walker-bail-sees-doomed
+
+(*
+ * Result: Never
+ *
+ * A lazy unmount: umount_tree() clears ->mnt_ns under write_seqlock()
+ * without setting MNT_SYNC_UMOUNT, and mntput_unheld() sets MNT_DOOMED
+ * (flags=3) when the sum says nothing else holds the mount. A walker
+ * in __legitimize_mnt() that sees the seqcount change takes mount_lock
+ * and reads ->mnt_flags there. Not both the walker finding no flag
+ * set (0:r3=0, it keeps the reference) and the mount being finished
+ * off (freed=1). mount_lock orders the two critical sections: either
+ * the walker's comes first and the sum counts its increment, or the
+ * sum's does and the walker finds MNT_DOOMED.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ ~(0:r2=0) /\ 0:r3=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus
new file mode 100644
index 0000000000000..66e65920e4912
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-no-outer-mb.litmus
@@ -0,0 +1,92 @@
+C mnt-walker-get-vs-seqcount-no-outer-mb
+
+(*
+ * Result: Never
+ *
+ * mnt-walker-get-vs-seqcount.litmus with the sum as mntput_unheld()
+ * has it: write_seqlock(), the puts pass, the smp_mb() of
+ * mnt_get_count(), the gets pass, and no smp_mb() between taking the
+ * lock and the sum. The inner smp_mb() comes after the seqcount store
+ * and before the gets loads in program order, which is all store
+ * buffering asks of the unmounter's side.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ WRITE_ONCE(*flags, 1);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ 0:r2=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus
new file mode 100644
index 0000000000000..e3297207e7609
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount-nomb.litmus
@@ -0,0 +1,92 @@
+C mnt-walker-get-vs-seqcount-nomb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-get-vs-seqcount.litmus without the smp_mb() between the
+ * increment and the re-read of the seqcount in __legitimize_mnt().
+ * The smp_rmb() of read_seqretry() does not order a store against a
+ * later load: the walker sees the seqcount unchanged and keeps its
+ * reference while the sum misses the increment and finishes the mount
+ * off.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ WRITE_ONCE(*flags, 1);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ 0:r2=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus
new file mode 100644
index 0000000000000..46ca500f8d508
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-get-vs-seqcount.litmus
@@ -0,0 +1,102 @@
+C mnt-walker-get-vs-seqcount
+
+(*
+ * Result: Never
+ *
+ * A walker in __legitimize_mnt() increments its gets counter, does
+ * smp_mb() and re-reads the seqcount of mount_lock with
+ * read_seqretry(); if it changed, the walker takes mount_lock and
+ * drops the reference again when it finds MNT_SYNC_UMOUNT or
+ * MNT_DOOMED. umount_tree() stores the seqcount when it takes
+ * write_seqlock(), clears ->mnt_ns and sets MNT_SYNC_UMOUNT;
+ * mntput_unheld() takes the lock again and sums with mnt_get_count():
+ * the puts pass, smp_mb(), the gets pass. Store buffering between the
+ * walker's increment and the unmounter's seqcount store: not both the
+ * walker seeing the seqcount unchanged (0:r1=0, 0:r2=0, it keeps the
+ * reference) and the sum missing the increment (freed=1, the mount is
+ * finished off). The walker's smp_mb() and the smp_mb() of
+ * mnt_get_count() are the two full barriers that takes. The sum is
+ * modelled with a further smp_mb() ahead of the puts pass, which the
+ * -no-outer-mb variant drops.
+ *)
+
+{
+ mnt_ns=1;
+ gets_w=0;
+ puts_w=0;
+ gets_u=1;
+ puts_u=0;
+ flags=0;
+ seq=0;
+ freed=0;
+}
+
+P0(spinlock_t *mlock, int *seq, int *gets_w, int *puts_w, int *flags)
+{
+ int r0;
+ int r1;
+ int r2;
+ int r3;
+
+ r0 = READ_ONCE(*seq);
+ smp_rmb();
+ smp_rmb();
+ r1 = READ_ONCE(*seq);
+ if (r1 == 0) {
+ WRITE_ONCE(*gets_w, 1);
+ smp_mb();
+ smp_rmb();
+ r2 = READ_ONCE(*seq);
+ if (r2 != 0) {
+ spin_lock(mlock);
+ r3 = READ_ONCE(*flags);
+ if (r3 != 0) {
+ WRITE_ONCE(*puts_w, 1);
+ }
+ spin_unlock(mlock);
+ }
+ }
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *flags, int *gets_w, int *puts_w, int *gets_u, int *puts_u, int *freed)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ WRITE_ONCE(*flags, 1);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ smp_mb();
+ r1 = READ_ONCE(*puts_w);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_w);
+ r4 = READ_ONCE(*gets_u);
+ if (r3 == 0) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ if (r3 == 1) {
+ if (r1 == 1) {
+ WRITE_ONCE(*flags, 3);
+ WRITE_ONCE(*freed, 1);
+ }
+ }
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+filter (0:r0=0)
+exists (0:r1=0 /\ 0:r2=0 /\ freed=1)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus
new file mode 100644
index 0000000000000..38d52c31f0b82
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nomb.litmus
@@ -0,0 +1,89 @@
+C mnt-walker-late-sees-new-pwd-nomb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-late-sees-new-pwd.litmus without the smp_mb() between the
+ * puts pass and the gets pass of mnt_get_count(). The smp_wmb() of
+ * write_sequnlock() orders stores only: the load of the put can be
+ * satisfied after the seqcount store of the unlock and a walker that
+ * samples the seqcount after the sum still reads the old cwd.
+ *)
+
+{
+ mnt_ns=1;
+ pwd=0;
+ fseq=0;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+ seq=0;
+}
+
+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)
+{
+ int r0;
+
+ spin_lock(fslock);
+ WRITE_ONCE(*fseq, 1);
+ smp_wmb();
+ WRITE_ONCE(*pwd, 1);
+ smp_wmb();
+ WRITE_ONCE(*fseq, 2);
+ spin_unlock(fslock);
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+P2(int *seq, int *fseq, int *pwd)
+{
+ int r5;
+ int r6;
+ int r7;
+ int r8;
+
+ r5 = READ_ONCE(*seq);
+ smp_rmb();
+ r7 = READ_ONCE(*fseq);
+ smp_rmb();
+ r6 = READ_ONCE(*pwd);
+ smp_rmb();
+ r8 = READ_ONCE(*fseq);
+}
+
+filter (2:r7=0 /\ 2:r8=0 \/ 2:r7=2 /\ 2:r8=2)
+exists (1:r1=1 /\ 2:r5=4 /\ 2:r6=0)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus
new file mode 100644
index 0000000000000..d3d68619311ee
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd-nowmb.litmus
@@ -0,0 +1,88 @@
+C mnt-walker-late-sees-new-pwd-nowmb
+
+(*
+ * Result: Sometimes
+ *
+ * mnt-walker-late-sees-new-pwd.litmus without the smp_wmb() of
+ * write_sequnlock() after the store of the new fs->pwd and without the
+ * smp_wmb() on the fast path of mntput_no_expire(). Nothing orders the
+ * new fs->pwd before the put: the sum can count the put while a walker
+ * that samples the seqcount after the sum still reads the old cwd.
+ *)
+
+{
+ mnt_ns=1;
+ pwd=0;
+ fseq=0;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+ seq=0;
+}
+
+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)
+{
+ int r0;
+
+ spin_lock(fslock);
+ WRITE_ONCE(*fseq, 1);
+ smp_wmb();
+ WRITE_ONCE(*pwd, 1);
+ WRITE_ONCE(*fseq, 2);
+ spin_unlock(fslock);
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+P2(int *seq, int *fseq, int *pwd)
+{
+ int r5;
+ int r6;
+ int r7;
+ int r8;
+
+ r5 = READ_ONCE(*seq);
+ smp_rmb();
+ r7 = READ_ONCE(*fseq);
+ smp_rmb();
+ r6 = READ_ONCE(*pwd);
+ smp_rmb();
+ r8 = READ_ONCE(*fseq);
+}
+
+filter (2:r7=0 /\ 2:r8=0 \/ 2:r7=2 /\ 2:r8=2)
+exists (1:r1=1 /\ 2:r5=4 /\ 2:r6=0)
diff --git a/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus
new file mode 100644
index 0000000000000..3e195dd4317a8
--- /dev/null
+++ b/Documentation/litmus-tests/fs/mnt-walker-late-sees-new-pwd.litmus
@@ -0,0 +1,103 @@
+C mnt-walker-late-sees-new-pwd
+
+(*
+ * Result: Never
+ *
+ * A holder has its cwd on the mount and chdir()s away right before
+ * mntput_unheld() sums. set_fs_pwd() stores the new fs->pwd under
+ * write_seqlock() of fs->seq and then drops the reference to the old cwd
+ * on the fast path of mntput_no_expire(): smp_wmb(), the put.
+ * umount_tree() clears ->mnt_ns under write_seqlock() of mount_lock and
+ * mntput_unheld() sums with mnt_get_count() under the lock: the puts
+ * pass, smp_mb(), the gets pass. The sum counts the put (1:r1=1), comes
+ * out at one and finishes the mount off. A walker whose path_init()
+ * samples the seqcount of mount_lock after that critical section
+ * (2:r5=4) and then reads fs->pwd must not read the old cwd (2:r6=0).
+ * Its seqcount sample would never change again and __legitimize_mnt()
+ * would hand it a reference to the finished mount. The smp_wmb() of
+ * write_sequnlock() orders the new fs->pwd before the put and so does
+ * the smp_wmb() of the fast path, either one is enough. The smp_mb() of
+ * mnt_get_count() orders the load of the put before the seqcount store
+ * of the unlock, and the walker orders its loads with smp_rmb(). A
+ * holder that already sees ->mnt_ns NULL puts under mount_lock, which
+ * orders the put anyway.
+ *)
+
+{
+ mnt_ns=1;
+ pwd=0;
+ fseq=0;
+ gets_h=1;
+ puts_h=0;
+ gets_u=1;
+ puts_u=0;
+ seq=0;
+}
+
+P0(spinlock_t *fslock, int *fseq, int *pwd, int *mnt_ns, int *puts_h)
+{
+ int r0;
+
+ spin_lock(fslock);
+ WRITE_ONCE(*fseq, 1);
+ smp_wmb();
+ WRITE_ONCE(*pwd, 1);
+ smp_wmb();
+ WRITE_ONCE(*fseq, 2);
+ spin_unlock(fslock);
+
+ rcu_read_lock();
+ r0 = READ_ONCE(*mnt_ns);
+ if (r0) {
+ smp_wmb();
+ WRITE_ONCE(*puts_h, 1);
+ }
+ rcu_read_unlock();
+}
+
+P1(spinlock_t *mlock, int *seq, int *mnt_ns, int *gets_h, int *puts_h, int *gets_u, int *puts_u)
+{
+ int r1;
+ int r2;
+ int r3;
+ int r4;
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 1);
+ smp_wmb();
+ WRITE_ONCE(*mnt_ns, 0);
+ smp_wmb();
+ WRITE_ONCE(*seq, 2);
+ spin_unlock(mlock);
+
+ spin_lock(mlock);
+ WRITE_ONCE(*seq, 3);
+ smp_wmb();
+ r1 = READ_ONCE(*puts_h);
+ r2 = READ_ONCE(*puts_u);
+ smp_mb();
+ r3 = READ_ONCE(*gets_h);
+ r4 = READ_ONCE(*gets_u);
+ smp_wmb();
+ WRITE_ONCE(*seq, 4);
+ spin_unlock(mlock);
+}
+
+P2(int *seq, int *fseq, int *pwd)
+{
+ int r5;
+ int r6;
+ int r7;
+ int r8;
+
+ r5 = READ_ONCE(*seq);
+ smp_rmb();
+ r7 = READ_ONCE(*fseq);
+ smp_rmb();
+ r6 = READ_ONCE(*pwd);
+ smp_rmb();
+ r8 = READ_ONCE(*fseq);
+}
+
+filter (2:r7=0 /\ 2:r8=0 \/ 2:r7=2 /\ 2:r8=2)
+exists (1:r1=1 /\ 2:r5=4 /\ 2:r6=0)
diff --git a/fs/namespace.c b/fs/namespace.c
index 3ed3766f3a183..e6b3a3206f3a8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1410,10 +1410,47 @@ static void delayed_mntput(struct work_struct *unused)
}
static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput);
-static void noinline mntput_no_expire_slowpath(struct mount *mnt)
+/*
+ * The count reached zero under mount_lock so we doom the mount and
+ * cleanup everything.
+ */
+static void mntput_final_locked(struct mount *mnt, struct list_head *shrink)
{
struct mnt_cover *cover;
struct hlist_node *n;
+
+ VFS_WARN_ON_ONCE(mnt->mnt.mnt_flags & MNT_DOOMED);
+ mnt->mnt.mnt_flags |= MNT_DOOMED;
+
+ mnt_del_instance(mnt);
+ if (unlikely(!list_empty(&mnt->mnt_expire)))
+ list_del(&mnt->mnt_expire);
+
+ /* nothing stays attached to an unmounted mount */
+ VFS_WARN_ON_ONCE(!list_empty(&mnt->mnt_mounts));
+ hlist_for_each_entry_safe(cover, n, &mnt->mnt_covers, node)
+ drop_cover(cover, shrink);
+}
+
+/* cleanup_mnt() sleeps: from task work, or the workqueue for kernel threads */
+static void mntput_queue_cleanup(struct mount *mnt)
+{
+ if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) {
+ struct task_struct *task = current;
+ if (likely(!(task->flags & PF_KTHREAD))) {
+ init_task_work(&mnt->mnt_rcu, __cleanup_mnt);
+ if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME))
+ return;
+ }
+ if (llist_add(&mnt->mnt_llist, &delayed_mntput_list))
+ schedule_delayed_work(&delayed_mntput_work, 1);
+ return;
+ }
+ cleanup_mnt(mnt);
+}
+
+static void noinline mntput_no_expire_slowpath(struct mount *mnt)
+{
LIST_HEAD(list);
int count;
@@ -1437,32 +1474,11 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)
unlock_mount_hash();
return;
}
- mnt->mnt.mnt_flags |= MNT_DOOMED;
+ mntput_final_locked(mnt, &list);
rcu_read_unlock();
-
- mnt_del_instance(mnt);
- if (unlikely(!list_empty(&mnt->mnt_expire)))
- list_del(&mnt->mnt_expire);
-
- /* nothing stays attached to an unmounted mount */
- VFS_WARN_ON_ONCE(!list_empty(&mnt->mnt_mounts));
- hlist_for_each_entry_safe(cover, n, &mnt->mnt_covers, node)
- drop_cover(cover, &list);
unlock_mount_hash();
shrink_dentry_list(&list);
-
- if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) {
- struct task_struct *task = current;
- if (likely(!(task->flags & PF_KTHREAD))) {
- init_task_work(&mnt->mnt_rcu, __cleanup_mnt);
- if (!task_work_add(task, &mnt->mnt_rcu, TWA_RESUME))
- return;
- }
- if (llist_add(&mnt->mnt_llist, &delayed_mntput_list))
- schedule_delayed_work(&delayed_mntput_work, 1);
- return;
- }
- cleanup_mnt(mnt);
+ mntput_queue_cleanup(mnt);
}
static void mntput_no_expire(struct mount *mnt)
@@ -1473,10 +1489,12 @@ static void mntput_no_expire(struct mount *mnt)
* Since we don't do lock_mount_hash() here,
* ->mnt_ns can change under us. However, if it's
* non-NULL, then there's a reference that won't
- * be dropped until after an RCU delay done after
- * turning ->mnt_ns NULL. So if we observe it
- * non-NULL under rcu_read_lock(), the reference
- * we are dropping is not the final one.
+ * be dropped until after turning ->mnt_ns NULL and
+ * either an RCU delay or a look under mount_lock
+ * that found it to be the only one left, which it
+ * isn't while ours is counted (mntput_unheld()).
+ * So if we observe it non-NULL under rcu_read_lock(),
+ * the reference we are dropping is not the final one.
*/
smp_wmb(); /* pairs with the smp_mb() in mnt_get_count() */
mnt_dec_count(mnt);
@@ -1486,6 +1504,77 @@ static void mntput_no_expire(struct mount *mnt)
mntput_no_expire_slowpath(mnt);
}
+DEFINE_FREE(mntput_no_expire, struct mount *, if (_T) mntput_no_expire(_T))
+
+/*
+ * Drop the own reference of a mount that has left its namespace without
+ * waiting for a grace period. mnt_get_count() is biased towards gets,
+ * i.e., it overcounts rather than undercounts. So if the count under
+ * mount_lock is one we know its ours and we're going to drop it.
+ *
+ * Called under mount_lock, the cleanup of the mount is left to the caller.
+ * Returns false if somebody else still references the mount.
+ */
+static bool mntput_unheld(struct mount *mnt, struct list_head *shrink)
+{
+ VFS_BUG_ON(mnt->mnt_ns);
+ if (mnt_get_count(mnt) != 1)
+ return false;
+ mnt_dec_count(mnt);
+ mntput_final_locked(mnt, shrink);
+ return true;
+}
+
+/* peeks per mount_lock hold, pathwalks spin while it is held */
+#define MNTPUT_UNMOUNTED_BATCH 16
+
+/*
+ * Put the mounts umount_tree() collected. Ideally, every mount just has a
+ * single reference count which means that we can elide the grace period.
+ * We batch mntput_unheld() as mnt_get_count() needs to sum over every cpu.
+ * On big machines it's not that fast. If there are mounts with held references
+ * we need the grace period.
+ */
+static void mntput_unmounted(struct hlist_head *head)
+{
+ struct hlist_node *p;
+ struct mount *m;
+ HLIST_HEAD(held);
+
+ while (!hlist_empty(head)) {
+ unsigned int n = 0;
+ HLIST_HEAD(unheld);
+ LIST_HEAD(shrink);
+
+ lock_mount_hash();
+ hlist_for_each_entry_safe(m, p, head, mnt_umount) {
+ hlist_del(&m->mnt_umount);
+ if (mntput_unheld(m, &shrink))
+ hlist_add_head(&m->mnt_umount, &unheld);
+ else
+ hlist_add_head(&m->mnt_umount, &held);
+ if (++n == MNTPUT_UNMOUNTED_BATCH)
+ break;
+ }
+ unlock_mount_hash();
+ shrink_dentry_list(&shrink);
+
+ hlist_for_each_entry_safe(m, p, &unheld, mnt_umount) {
+ hlist_del(&m->mnt_umount);
+ mntput_queue_cleanup(m);
+ }
+ }
+
+ if (hlist_empty(&held))
+ return;
+
+ synchronize_rcu_expedited();
+ hlist_for_each_entry_safe(m, p, &held, mnt_umount) {
+ hlist_del(&m->mnt_umount);
+ mntput(&m->mnt);
+ }
+}
+
void mntput(struct vfsmount *mnt)
{
if (mnt) {
@@ -1509,9 +1598,11 @@ EXPORT_SYMBOL(mntget);
/*
* Make a mount point inaccessible to new lookups.
* Because there may still be current users, the caller MUST WAIT
- * for an RCU grace period before destroying the mount point.
+ * for an RCU grace period before destroying the mount point, unless
+ * it finds under mount_lock that it holds the only reference left,
+ * see mntput_unheld().
*/
-void mnt_make_shortterm(struct vfsmount *mnt)
+static void mnt_make_shortterm(struct vfsmount *mnt)
{
if (mnt)
WRITE_ONCE(real_mount(mnt)->mnt_ns, NULL);
@@ -1764,8 +1855,6 @@ static void free_mnt_ns(struct mnt_namespace *);
static void namespace_unlock(void)
{
struct hlist_head head;
- struct hlist_node *p;
- struct mount *m;
struct mnt_namespace *ns = emptied_ns;
LIST_HEAD(list);
@@ -1796,12 +1885,7 @@ static void namespace_unlock(void)
if (likely(hlist_empty(&head)))
return;
- synchronize_rcu_expedited();
-
- hlist_for_each_entry_safe(m, p, &head, mnt_umount) {
- hlist_del(&m->mnt_umount);
- mntput(&m->mnt);
- }
+ mntput_unmounted(&head);
}
static inline void namespace_lock(void)
@@ -1919,8 +2003,10 @@ static int do_umount_root(struct super_block *sb)
return ret;
}
+/* Unmount @mnt, dropping the reference the caller holds to it on every path. */
static int do_umount(struct mount *mnt, int flags)
{
+ struct mount *ref __free(mntput_no_expire) = mnt;
struct super_block *sb = mnt->mnt.mnt_sb;
int retval;
@@ -1987,37 +2073,36 @@ static int do_umount(struct mount *mnt, int flags)
return do_umount_root(sb);
}
- namespace_lock();
- lock_mount_hash();
+ guard(namespace_excl)();
+ guard(mount_writer)();
/* Repeat the earlier racy checks, now that we are holding the locks */
- retval = -EINVAL;
if (!check_mnt(mnt))
- goto out;
+ return -EINVAL;
if (mnt->mnt.mnt_flags & MNT_LOCKED)
- goto out;
+ return -EINVAL;
if (!mnt_has_parent(mnt)) /* not the absolute root */
- goto out;
+ return -EINVAL;
event++;
if (flags & MNT_DETACH) {
umount_tree(mnt, UMOUNT_PROPAGATE);
- retval = 0;
} else {
smp_mb(); // paired with __legitimize_mnt()
shrink_submounts(mnt);
- retval = -EBUSY;
- if (!propagate_mount_busy(mnt, 2)) {
- umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
- retval = 0;
- }
+ if (propagate_mount_busy(mnt, 2))
+ return -EBUSY;
+ umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
}
-out:
- unlock_mount_hash();
- namespace_unlock();
- return retval;
+ /*
+ * By definition the caller's reference isn't the last
+ * one, so drop it.
+ */
+ mnt_dec_count(mnt);
+ retain_and_null_ptr(ref);
+ return 0;
}
/*
@@ -2101,12 +2186,12 @@ int path_umount(const struct path *path, int flags)
int ret;
ret = can_umount(path, flags);
- if (!ret)
- ret = do_umount(mnt, flags);
-
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
dput(path->dentry);
- mntput_no_expire(mnt);
+ if (ret)
+ mntput_no_expire(mnt);
+ else
+ ret = do_umount(mnt, flags);
return ret;
}
@@ -6515,23 +6600,23 @@ EXPORT_SYMBOL_GPL(kern_mount);
void kern_unmount(struct vfsmount *mnt)
{
/* release long term mount so mount point can be released */
- if (!IS_ERR(mnt)) {
- mnt_make_shortterm(mnt);
- synchronize_rcu(); /* yecchhh... */
- mntput(mnt);
- }
+ if (!IS_ERR(mnt))
+ kern_unmount_array(&mnt, 1);
}
EXPORT_SYMBOL(kern_unmount);
void kern_unmount_array(struct vfsmount *mnt[], unsigned int num)
{
+ HLIST_HEAD(head);
unsigned int i;
- for (i = 0; i < num; i++)
+ for (i = 0; i < num; i++) {
+ if (!mnt[i])
+ continue;
mnt_make_shortterm(mnt[i]);
- synchronize_rcu_expedited();
- for (i = 0; i < num; i++)
- mntput(mnt[i]);
+ hlist_add_head(&real_mount(mnt[i])->mnt_umount, &head);
+ }
+ mntput_unmounted(&head);
}
EXPORT_SYMBOL(kern_unmount_array);
diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h
index 80cad4ea96a3e..8ce962ed158e3 100644
--- a/fs/overlayfs/ovl_entry.h
+++ b/fs/overlayfs/ovl_entry.h
@@ -92,6 +92,8 @@ struct ovl_fs {
/* r/o snapshot of upperdir sb's only taken on volatile mounts */
errseq_t errseq;
bool casefold;
+ /* ->layers, ->fs and ->creator_cred are read by rcu pathwalks */
+ struct rcu_head rcu;
};
/* Number of lower layers, not including data-only layers */
diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index c93fcaa45d4a3..36fa3a3274a69 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -837,6 +837,26 @@ int ovl_init_fs_context(struct fs_context *fc)
}
+/*
+ * ovl_permission() and ovl_dentry_revalidate_common() run in rcu pathwalk
+ * mode and read ->layers[].mnt, ->fs and ->creator_cred through the
+ * superblock, so those go only after a grace period. The mounts themselves
+ * are rcu-freed by kern_unmount_array().
+ */
+static void ovl_free_fs_rcu(struct rcu_head *head)
+{
+ struct ovl_fs *ofs = container_of(head, struct ovl_fs, rcu);
+
+ kfree(ofs->layers);
+ kfree(ofs->fs);
+ kfree(ofs->config.lowerdirs);
+ kfree(ofs->config.upperdir);
+ kfree(ofs->config.workdir);
+ if (ofs->creator_cred)
+ put_cred(ofs->creator_cred);
+ kfree(ofs);
+}
+
void ovl_free_fs(struct ovl_fs *ofs)
{
struct vfsmount **mounts;
@@ -860,17 +880,10 @@ void ovl_free_fs(struct ovl_fs *ofs)
mounts[i] = ofs->layers[i].mnt;
}
kern_unmount_array(mounts, ofs->numlayer);
- kfree(ofs->layers);
for (i = 0; i < ofs->numfs; i++)
free_anon_bdev(ofs->fs[i].pseudo_dev);
- kfree(ofs->fs);
- kfree(ofs->config.lowerdirs);
- kfree(ofs->config.upperdir);
- kfree(ofs->config.workdir);
- if (ofs->creator_cred)
- put_cred(ofs->creator_cred);
- kfree(ofs);
+ call_rcu(&ofs->rcu, ovl_free_fs_rcu);
}
int ovl_fs_params_verify(const struct ovl_fs_context *ctx,
diff --git a/include/linux/mount.h b/include/linux/mount.h
index b16ba5d456057..2342929e2fff0 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -74,7 +74,6 @@ extern void mnt_drop_write(struct vfsmount *mnt);
extern void mnt_drop_write_file(struct file *file);
extern void mntput(struct vfsmount *mnt);
extern struct vfsmount *mntget(struct vfsmount *mnt);
-extern void mnt_make_shortterm(struct vfsmount *mnt);
extern struct vfsmount *mnt_clone_internal(const struct path *path);
extern bool __mnt_is_readonly(const struct vfsmount *mnt);
extern bool mnt_may_suid(struct vfsmount *mnt);
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 1e71353bdb4a3..24706b910654a 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -21,7 +21,8 @@
#include "util.h"
/*
- * The work queue is used to avoid the cost of synchronize_rcu in kern_unmount.
+ * The work queue keeps the teardown of a namespace out of the callers of
+ * put_ipc_ns(), the eviction of an mqueue inode among them.
*/
static void free_ipc(struct work_struct *unused);
static DECLARE_WORK(free_ipc_work, free_ipc);
@@ -149,11 +150,7 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
static void free_ipc_ns(struct ipc_namespace *ns)
{
- /*
- * Caller needs to wait for an RCU grace period to have passed
- * after making the mount point inaccessible to new accesses.
- */
- mntput(ns->mq_mnt);
+ kern_unmount(ns->mq_mnt);
sem_exit_ns(ns);
msg_exit_ns(ns);
shm_exit_ns(ns);
@@ -164,7 +161,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
dec_ipc_namespaces(ns->ucounts);
put_user_ns(ns->user_ns);
ns_common_free(ns);
- kfree(ns);
+ kfree_rcu(ns, ns.ns_rcu);
}
static LLIST_HEAD(free_ipc_list);
@@ -173,12 +170,6 @@ static void free_ipc(struct work_struct *unused)
struct llist_node *node = llist_del_all(&free_ipc_list);
struct ipc_namespace *n, *t;
- llist_for_each_entry_safe(n, t, node, mnt_llist)
- mnt_make_shortterm(n->mq_mnt);
-
- /* Wait for any last users to have gone away. */
- synchronize_rcu();
-
llist_for_each_entry_safe(n, t, node, mnt_llist)
free_ipc_ns(n);
}
diff --git a/tools/testing/selftests/filesystems/mount_cycle/.gitignore b/tools/testing/selftests/filesystems/mount_cycle/.gitignore
index 30f7dd071bcbb..7b9c4f79053c1 100644
--- a/tools/testing/selftests/filesystems/mount_cycle/.gitignore
+++ b/tools/testing/selftests/filesystems/mount_cycle/.gitignore
@@ -6,3 +6,4 @@ mount_cover_test
locked_handle_test
nsfs_rbind_loop_test
overmount_ns_file_test
+unheld_umount_test
diff --git a/tools/testing/selftests/filesystems/mount_cycle/Makefile b/tools/testing/selftests/filesystems/mount_cycle/Makefile
index fbe8c5e19d424..333b7225d89e3 100644
--- a/tools/testing/selftests/filesystems/mount_cycle/Makefile
+++ b/tools/testing/selftests/filesystems/mount_cycle/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
TEST_GEN_PROGS := loop_cycle_test unmounted_tree_test overmount_reparent_test mount_cover_test locked_handle_test
-TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test
+TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test unheld_umount_test
CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
diff --git a/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c b/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c
new file mode 100644
index 0000000000000..96e3db277e494
--- /dev/null
+++ b/tools/testing/selftests/filesystems/mount_cycle/unheld_umount_test.c
@@ -0,0 +1,262 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A mount that nothing else references is torn down before umount(2)
+ * returns, lazy or not, before the last close of the file that kept it
+ * alive returns, and before the task that took a mount namespace down
+ * with it can be reaped. A loop device shows when that has happened: the
+ * filesystem claims it, and an exclusive open of the device succeeds
+ * only once the filesystem has let go.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <linux/loop.h>
+
+#include "../../kselftest_harness.h"
+
+#define IMAGE_SIZE (1440 * 1024)
+#define SECTOR 512
+
+/* A blank FAT12 floppy image: boot sector, two FATs, an empty root directory. */
+static int write_fat12(int fd)
+{
+ unsigned char sector[SECTOR] = {
+ 0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1',
+ [11] = 0x00, 0x02, /* bytes per sector: 512 */
+ [13] = 1, /* sectors per cluster */
+ [14] = 1, 0, /* reserved sectors */
+ [16] = 2, /* FATs */
+ [17] = 0xe0, 0x00, /* root directory entries: 224 */
+ [19] = 0x40, 0x0b, /* total sectors: 2880 */
+ [21] = 0xf0, /* media descriptor */
+ [22] = 9, 0, /* sectors per FAT */
+ [24] = 18, 0, /* sectors per track */
+ [26] = 2, 0, /* heads */
+ [38] = 0x29, /* extended boot signature */
+ [39] = 0x12, 0x34, 0x56, 0x78,
+ [43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',
+ [54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ',
+ [510] = 0x55, 0xaa,
+ };
+ unsigned char fat[SECTOR] = { 0xf0, 0xff, 0xff };
+
+ if (pwrite(fd, sector, SECTOR, 0) != SECTOR)
+ return -1;
+ /* the first FAT and the second one, one sector each is enough */
+ if (pwrite(fd, fat, SECTOR, 1 * SECTOR) != SECTOR ||
+ pwrite(fd, fat, SECTOR, 10 * SECTOR) != SECTOR)
+ return -1;
+ return ftruncate(fd, IMAGE_SIZE);
+}
+
+/* Bind a free loop device to the open image @ifd; the device number. */
+static int loop_bind(int ifd)
+{
+ int cfd, lfd, n;
+ char dev[32];
+
+ cfd = open("/dev/loop-control", O_RDWR);
+ if (cfd < 0)
+ return -1;
+ n = ioctl(cfd, LOOP_CTL_GET_FREE);
+ close(cfd);
+ if (n < 0)
+ return -1;
+ snprintf(dev, sizeof(dev), "/dev/loop%d", n);
+ lfd = open(dev, O_RDWR);
+ if (lfd < 0)
+ return -1;
+ if (ioctl(lfd, LOOP_SET_FD, ifd))
+ n = -1;
+ close(lfd);
+ return n;
+}
+
+/* Mount the loop device at @mp: vfat, or msdos. */
+static int loop_mount(const char *dev, const char *mp)
+{
+ if (!mount(dev, mp, "vfat", 0, NULL))
+ return 0;
+ return mount(dev, mp, "msdos", 0, NULL);
+}
+
+/*
+ * An exclusive open of the device fails with EBUSY while a filesystem
+ * holds it. No retries: the point is that it has been let go by now.
+ */
+static bool loop_free(const char *dev)
+{
+ int lfd = open(dev, O_RDONLY | O_EXCL);
+
+ if (lfd < 0)
+ return false;
+ close(lfd);
+ return true;
+}
+
+/* Tell the loop device to let go of its image. */
+static void loop_clear(const char *dev)
+{
+ int lfd = open(dev, O_RDWR);
+
+ if (lfd >= 0) {
+ ioctl(lfd, LOOP_CLR_FD);
+ close(lfd);
+ }
+}
+
+FIXTURE(unheld_umount) {
+ char dir[64];
+ char mp[80];
+ char dev[32];
+};
+
+FIXTURE_SETUP(unheld_umount)
+{
+ char img[80];
+ int ifd, n;
+
+ if (geteuid() != 0)
+ SKIP(return, "test requires CAP_SYS_ADMIN");
+ if (access("/dev/loop-control", R_OK | W_OK))
+ SKIP(return, "test requires loop devices");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/unheld_umount.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0);
+
+ snprintf(img, sizeof(img), "%s/img", self->dir);
+ ifd = open(img, O_RDWR | O_CREAT | O_EXCL, 0600);
+ ASSERT_GE(ifd, 0);
+ ASSERT_EQ(write_fat12(ifd), 0);
+ n = loop_bind(ifd);
+ close(ifd); /* the loop device holds the file from now on */
+ ASSERT_GE(n, 0);
+ snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", n);
+
+ snprintf(self->mp, sizeof(self->mp), "%s/mnt", self->dir);
+ ASSERT_EQ(mkdir(self->mp, 0755), 0);
+ /* the harness skips the teardown after a SKIP() here */
+ if (loop_mount(self->dev, self->mp)) {
+ loop_clear(self->dev);
+ SKIP(return, "test requires a FAT filesystem");
+ }
+ umount2(self->mp, 0);
+}
+
+FIXTURE_TEARDOWN(unheld_umount)
+{
+ umount2(self->mp, MNT_DETACH);
+ loop_clear(self->dev);
+ umount2(self->dir, MNT_DETACH);
+ rmdir(self->dir);
+}
+
+/* A synchronous umount(2) returns with the filesystem shut down. */
+TEST_F(unheld_umount, sync_umount_releases_before_return)
+{
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ ASSERT_FALSE(loop_free(self->dev));
+ ASSERT_EQ(umount2(self->mp, 0), 0);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after umount(2) returned", self->dev);
+}
+
+/* So does a lazy one when nothing else references the mount. */
+TEST_F(unheld_umount, lazy_umount_idle_releases_before_return)
+{
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ ASSERT_FALSE(loop_free(self->dev));
+ ASSERT_EQ(umount2(self->mp, MNT_DETACH), 0);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after umount2(MNT_DETACH) returned", self->dev);
+}
+
+/*
+ * A lazy umount of a mount that a file descriptor holds leaves the
+ * filesystem alive; the close that drops the last reference shuts it
+ * down before it returns.
+ */
+TEST_F(unheld_umount, lazy_umount_held_releases_on_close)
+{
+ int fd;
+
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ fd = open(self->mp, O_PATH | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(umount2(self->mp, MNT_DETACH), 0);
+ EXPECT_FALSE(loop_free(self->dev))
+ TH_LOG("%s was released while a file on it was still open", self->dev);
+ ASSERT_EQ(close(fd), 0);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after the last file on it was closed", self->dev);
+}
+
+/* A synchronous umount(2) of a held mount is refused, nothing changes. */
+TEST_F(unheld_umount, sync_umount_held_refused)
+{
+ int fd;
+
+ ASSERT_EQ(loop_mount(self->dev, self->mp), 0);
+ fd = open(self->mp, O_PATH | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ EXPECT_EQ(umount2(self->mp, 0), -1);
+ EXPECT_EQ(errno, EBUSY);
+ EXPECT_FALSE(loop_free(self->dev));
+ ASSERT_EQ(close(fd), 0);
+ ASSERT_EQ(umount2(self->mp, 0), 0);
+ EXPECT_TRUE(loop_free(self->dev));
+}
+
+/*
+ * The mounts of a mount namespace go with its last task: by the time
+ * that task can be reaped the filesystems it had mounted are shut down.
+ */
+TEST_F(unheld_umount, namespace_death_releases_before_reap)
+{
+ int status, to_parent[2], to_child[2];
+ pid_t pid;
+ char c;
+
+ ASSERT_EQ(pipe(to_parent), 0);
+ ASSERT_EQ(pipe(to_child), 0);
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ close(to_parent[0]);
+ close(to_child[1]);
+ if (unshare(CLONE_NEWNS) || loop_mount(self->dev, self->mp))
+ _exit(1);
+ if (write(to_parent[1], "", 1) != 1)
+ _exit(2);
+ /* leave once the parent has looked, with the mount in place */
+ if (read(to_child[0], &c, 1) != 0)
+ _exit(3);
+ _exit(0);
+ }
+ close(to_parent[1]);
+ close(to_child[0]);
+ ASSERT_EQ(read(to_parent[0], &c, 1), 1);
+ EXPECT_FALSE(loop_free(self->dev))
+ TH_LOG("%s is not claimed by the child's mount", self->dev);
+ close(to_child[1]);
+ ASSERT_EQ(waitpid(pid, &status, 0), pid);
+ ASSERT_EQ(status, 0);
+ close(to_parent[0]);
+ EXPECT_TRUE(loop_free(self->dev))
+ TH_LOG("%s is still claimed after the namespace's last task was reaped", self->dev);
+}
+
+TEST_HARNESS_MAIN
|
| 31/3 | 2026/10/12 17:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30419 output: 315 thoughts: 2980 Thoughts: **Analysis of the Patch Series and KMSAN Need** Okay, let's break this down. The request is to determine if this patch series necessitates a dedicated KMSAN fuzzing session. My initial thought is to be thorough. First, I need to understand what this patch touches. It's a broad scope: documentation, several filesystem components (namespace, overlayfs), an include file, and IPC. There is also a change to the selftests. I'll start by focusing on the core logic changes in `namespace.c`, `overlayfs`, and `ipc/namespace.c`, which seem to be the most critical areas. I see helpers and refactoring focused on `mntput_no_expire_slowpath` for mount teardown, and changes to RCU usage within overlayfs. Also, changes related to IPC namespace cleanup which could be related to unmounting. I will analyze the use of variables and structs: in fs/namespace.c, a lot of mount structure management, with new helpers for cleanup of mounts, which includes reference count updates and RCU synchronization. There's also `mntput_unheld` which does a `VFS_BUG_ON`, and the use of the `HLIST_HEAD` and `LIST_HEAD` macros for internal lists, and a variable `n`. `do_umount` uses RAII for the mount structure. The `kern_unmount_array` uses an `HLIST_HEAD`. The logic seems correct, as the variables are initialized. In overlayfs, an `rcu_head` is added, and RCU calls used to free structures after unmounting. In `ipc/namespace.c`, the patch uses `kfree_rcu` and `kern_unmount`, nothing seems wrong. Now, I'll go through the instructions. The rules state that a KMSAN session is resource intensive and should only be triggered if this is specifically needed. There are instructions on deciding if NeedsKMSAN is true or false. It focuses on kernel data structures sent to userspace, uninitialized variables in conditional logic, complex structure allocations, and how bounds can result in memory leaks. However, the instructions state that, if the patch involves the typical bugs, like out-of-bounds access, array overflows, null pointers, locking, or use-after-free, then we can use KASAN. I need to apply those rules to the changes I observed in the patch. I'm looking for anything that touches user-space copy functions (`copy_to_user`, etc.) and/or deals with uninitialized memory. From my analysis, this patch does not touch any user-space copies. Also, after reviewing the variables and structs modified in namespace.c, overlayfs, and ipc/namespace.c, none of the variables are uninitialized, and the existing mount structures are being correctly managed through refcounts and RCU. The patch primarily touches mount teardown and refactoring RCU usage. If I look at what kinds of issues are likely to be in the patch, these would be classic KASAN / LOCKDEP issues: race conditions, concurrency issues, premature frees -> UAF, double frees, or refcount leaks or underflows, and UAF / memory corruption / lifecycle / locking issues. These are all things that KASAN and LOCKDEP are designed to catch! This is not something KMSAN handles. I do not see any new allocations of uninitialized memory. Nothing is being copied to userspace and nothing is being exposed. Let's double-check again for uninitialized memory. I'm seeing that the variables and lists are initialized correctly. No allocations of uninitialized fields. There are no kernel-to-user copies. So, my conclusion is that KMSAN is not required. So, the conclusion is clear. The patch refactors VFS mount teardown, OverlayFS, and IPC namespace cleanup with RCU synchronization. The main risks are the usual concurrency issues, and incorrect reference counting, which can cause UAFs, lock order issues, etc. But, KASAN is specifically designed to catch those concurrency bugs. KMSAN isn't needed here. KASAN is better. I'll set `NeedsKMSAN=false` and move on. |
| 32/3 | 2026/10/12 17:42 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch optimizes VFS mount teardown in fs/namespace.c, fs/overlayfs/params.c, and ipc/namespace.c by skipping unnecessary RCU grace periods when an unmounted tree holds the sole reference to a mount. It modifies reference counting, memory barriers, locking guards, and delayed cleanup (e.g. via call_rcu and task work).\n\nThe primary risks introduced by these changes relate to object lifecycles, memory ordering, and concurrency: specifically, use-after-free (UAF) or premature freeing if a reference is dropped or a structure is cleaned up while an RCU reader or concurrent path walker still holds or accesses it. These failure modes (UAF, double-free, list corruption, locking bugs) are directly monitored and detected by KASAN and LOCKDEP.\n\nKMSAN detects reads of uninitialized memory and information leaks to user space. The patch does not introduce any data copies to user space (no copy_to_user, put_user, netlink messages, or ioctl outputs), does not allocate complex uninitialized memory buffers, and does not add conditional logic reading uninitialized struct fields. All new local variables and list heads (e.g. HLIST_HEAD, LIST_HEAD, loop counters) are properly initialized. Therefore, there are no uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch optimizes VFS mount teardown in fs/namespace.c, fs/overlayfs/params.c, and ipc/namespace.c by skipping unnecessary RCU grace periods when an unmounted tree holds the sole reference to a mount. It modifies reference counting, memory barriers, locking guards, and delayed cleanup (e.g. via call_rcu and task work).\n\nThe primary risks introduced by these changes relate to object lifecycles, memory ordering, and concurrency: specifically, use-after-free (UAF) or premature freeing if a reference is dropped or a structure is cleaned up while an RCU reader or concurrent path walker still holds or accesses it. These failure modes (UAF, double-free, list corruption, locking bugs) are directly monitored and detected by KASAN and LOCKDEP.\n\nKMSAN detects reads of uninitialized memory and information leaks to user space. The patch does not introduce any data copies to user space (no copy_to_user, put_user, netlink messages, or ioctl outputs), does not allocate complex uninitialized memory buffers, and does not add conditional logic reading uninitialized struct fields. All new local variables and list heads (e.g. HLIST_HEAD, LIST_HEAD, loop counters) are properly initialized. Therefore, there are no uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|