| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/11 16:15 | flow | patch-triage |
21mArgs:null Results: {
"EnableConfigs": [
"BLOCK",
"QUOTA"
],
"FocusSymbols": [
"reconfigure_super",
"freeze_super",
"thaw_super",
"vfs_clean_context",
"quotactl_block",
"fs_bdev_freeze",
"fs_super_thaw",
"do_emergency_remount",
"fserror_report",
"fserror_unmount"
],
"KMSANReasoning": "The patch series addresses VFS-level filesystem freezing/thawing synchronization, emergency remount locking and lifetime semantics, memory barriers before wait_var wakeups, fserror event allocation checks against SB_BORN, and preserving SB_RDONLY during fs_context reconfiguration.\n\nNone of the changes introduce or modify any kernel-to-user memory copy operations, uninitialized stack/heap allocations, or conditional branches on uninitialized memory. All variables and fields modified are scalar flags, reference counts, or waitqueue primitives. Any potential issues introduced by these changes relate to synchronization, reference counting, or locking, which are well-covered by LOCKDEP and KASAN. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch series modifies core VFS logic across multiple areas: superblock reconfiguration (reconfigure_super, vfs_clean_context), filesystem and block-device freeze/thaw state handling (freeze_super, thaw_super, fs_bdev_freeze, fs_super_thaw), quota syscall synchronization on frozen filesystems (quotactl_block), emergency remount refcounting/locking (do_emergency_remount), and memory barriers / initialization checks in filesystem error reporting (fserror_pending_dec, fserror_alloc_event). These paths are reachable from userspace in standard virtualized environments via mount, fsopen/fspick/fsconfig, quotactl, and freeze ioctls, making them prime targets for fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/11 16:15 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 49cd28e4b9cb8c0a01dbd19cfdcd9b28bf17b398\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Oct 11 16:15:06 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/fs/fs_context.c b/fs/fs_context.c\nindex a50584df97bea..ba99e673458a8 100644\n--- a/fs/fs_context.c\n+++ b/fs/fs_context.c\n@@ -544,6 +544,7 @@ void vfs_clean_context(struct fs_context *fc)\n \tfc-\u003efs_private = NULL;\n \tfc-\u003es_fs_info = NULL;\n \tfc-\u003esb_flags = 0;\n+\tfc-\u003esb_flags_mask = 0;\n \tsecurity_free_mnt_opts(\u0026fc-\u003esecurity);\n \tkfree(fc-\u003esource);\n \tfc-\u003esource = NULL;\ndiff --git a/fs/fserror.c b/fs/fserror.c\nindex 1e4d11fd9562f..90ce04d585149 100644\n--- a/fs/fserror.c\n+++ b/fs/fserror.c\n@@ -35,8 +35,15 @@ void fserror_unmount(struct super_block *sb)\n \n static inline void fserror_pending_dec(struct super_block *sb)\n {\n-\tif (refcount_dec_and_test(\u0026sb-\u003es_pending_errors))\n+\tif (refcount_dec_and_test(\u0026sb-\u003es_pending_errors)) {\n+\t\t/*\n+\t\t * refcount_dec_and_test() isn't fully ordered but wake_up_var()\n+\t\t * needs a full barrier between the store and its waitqueue check.\n+\t\t * Pairs with the barrier in prepare_to_wait_event().\n+\t\t */\n+\t\tsmp_mb();\n \t\twake_up_var(\u0026sb-\u003es_pending_errors);\n+\t}\n }\n \n static inline void fserror_free_event(struct fserror_event *event)\n@@ -89,6 +96,13 @@ static inline struct fserror_event *fserror_alloc_event(struct super_block *sb,\n \t\treturn NULL;\n \tif (!(sb-\u003es_flags \u0026 SB_ACTIVE))\n \t\tgoto out_pending;\n+\t/*\n+\t * xfs and f2fs set SB_ACTIVE while filling the superblock. Nobody can\n+\t * listen before the superblock is born and if the mount fails nothing\n+\t * waits for the event.\n+\t */\n+\tif (!(sb-\u003es_flags \u0026 SB_BORN))\n+\t\tgoto out_pending;\n \n \tevent = mempool_alloc(\u0026fserror_events_pool, gfp_flags);\n \tif (!event)\ndiff --git a/fs/quota/quota.c b/fs/quota/quota.c\nindex 33bacd7075800..d55ef08de833e 100644\n--- a/fs/quota/quota.c\n+++ b/fs/quota/quota.c\n@@ -894,11 +894,15 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)\n \t\t\tup_write(\u0026sb-\u003es_umount);\n \t\telse\n \t\t\tup_read(\u0026sb-\u003es_umount);\n-\t\t/* Wait for sb to unfreeze */\n-\t\tsb_start_write(sb);\n-\t\tsb_end_write(sb);\n+\t\t/*\n+\t\t * Wait for sb to unfreeze. A read-only superblock is frozen\n+\t\t * without taking s_writers so sb_start_write() won't wait.\n+\t\t */\n+\t\terror = wait_var_event_killable(\u0026sb-\u003es_writers.frozen,\n+\t\t\t\tREAD_ONCE(sb-\u003es_writers.frozen) == SB_UNFROZEN);\n \t\tput_super(sb);\n-\t\tcond_resched();\n+\t\tif (error)\n+\t\t\treturn ERR_PTR(error);\n \t\tgoto retry;\n \t}\n \treturn sb;\ndiff --git a/fs/super.c b/fs/super.c\nindex 1d5ccf540a9bf..657958a1d1352 100644\n--- a/fs/super.c\n+++ b/fs/super.c\n@@ -935,9 +935,8 @@ void drop_super_exclusive(struct super_block *sb)\n }\n \n enum super_iter_flags_t {\n-\tSUPER_ITER_EXCL\t\t= (1U \u003c\u003c 0),\n-\tSUPER_ITER_UNLOCKED\t= (1U \u003c\u003c 1),\n-\tSUPER_ITER_REVERSE\t= (1U \u003c\u003c 2),\n+\tSUPER_ITER_UNLOCKED\t= (1U \u003c\u003c 0),\n+\tSUPER_ITER_REVERSE\t= (1U \u003c\u003c 1),\n };\n \n static inline struct super_block *first_super(enum super_iter_flags_t flags)\n@@ -959,7 +958,6 @@ static void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,\n \t\t\t enum super_iter_flags_t flags)\n {\n \tstruct super_block *sb, *p = NULL;\n-\tbool excl = flags \u0026 SUPER_ITER_EXCL;\n \n \tspin_lock(\u0026sb_lock);\n \n@@ -976,9 +974,9 @@ static void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,\n \n \t\tif (flags \u0026 SUPER_ITER_UNLOCKED) {\n \t\t\tf(sb, arg);\n-\t\t} else if (super_lock(sb, excl)) {\n+\t\t} else if (super_lock_shared(sb)) {\n \t\t\tf(sb, arg);\n-\t\t\tsuper_unlock(sb, excl);\n+\t\t\tsuper_unlock_shared(sb);\n \t\t}\n \n \t\tif (p)\n@@ -1077,6 +1075,14 @@ int reconfigure_super(struct fs_context *fc)\n \tif (sb-\u003es_writers.frozen != SB_UNFROZEN)\n \t\treturn -EBUSY;\n \n+\t/*\n+\t * Filesystems take fc-\u003esb_flags \u0026 SB_RDONLY as the read-only state the\n+\t * superblock ends up in. If that isn't being changed, e.g., fspick()\n+\t * without \"ro\" or \"rw\", it's the current one.\n+\t */\n+\tif (!(fc-\u003esb_flags_mask \u0026 SB_RDONLY))\n+\t\tfc-\u003esb_flags = (fc-\u003esb_flags \u0026 ~SB_RDONLY) | (sb-\u003es_flags \u0026 SB_RDONLY);\n+\n \tretval = security_sb_remount(sb, fc-\u003esecurity);\n \tif (retval)\n \t\treturn retval;\n@@ -1158,23 +1164,34 @@ int reconfigure_super(struct fs_context *fc)\n \n static void do_emergency_remount_callback(struct super_block *sb, void *unused)\n {\n-\tif (sb-\u003es_bdev \u0026\u0026 !sb_rdonly(sb)) {\n-\t\tstruct fs_context *fc;\n+\tstruct fs_context *fc = NULL;\n+\n+\tif (!super_lock_excl(sb))\n+\t\treturn;\n \n+\t/* Make sure no reference put under s_umount is the last one. */\n+\tatomic_inc(\u0026sb-\u003es_active);\n+\tif (sb-\u003es_bdev \u0026\u0026 !sb_rdonly(sb)) {\n \t\tfc = fs_context_for_reconfigure(sb-\u003es_root,\n \t\t\t\t\tSB_RDONLY | SB_FORCE, SB_RDONLY);\n-\t\tif (!IS_ERR(fc)) {\n-\t\t\tif (parse_monolithic_mount_data(fc, NULL) == 0)\n-\t\t\t\t(void)reconfigure_super(fc);\n-\t\t\tput_fs_context(fc);\n-\t\t}\n+\t\tif (!IS_ERR(fc) \u0026\u0026 parse_monolithic_mount_data(fc, NULL) == 0)\n+\t\t\t(void)reconfigure_super(fc);\n \t}\n+\tsuper_unlock_excl(sb);\n+\n+\t/*\n+\t * Our active reference may be the last one by now, so only drop it\n+\t * after s_umount has been released.\n+\t */\n+\tif (!IS_ERR_OR_NULL(fc))\n+\t\tput_fs_context(fc);\n+\tdeactivate_super(sb);\n }\n \n static void do_emergency_remount(struct work_struct *work)\n {\n \t__iterate_supers(do_emergency_remount_callback, NULL,\n-\t\t\t SUPER_ITER_EXCL | SUPER_ITER_REVERSE);\n+\t\t\t SUPER_ITER_UNLOCKED | SUPER_ITER_REVERSE);\n \tkfree(work);\n \tprintk(\"Emergency Remount complete\\n\");\n }\n@@ -1483,10 +1500,29 @@ static int fs_super_freeze(struct super_block *sb)\n \n static int fs_super_thaw(struct super_block *sb)\n {\n-\tif (sb-\u003es_op-\u003ethaw_super)\n-\t\treturn sb-\u003es_op-\u003ethaw_super(sb,\n+\tint error;\n+\n+\tif (sb-\u003es_op-\u003ethaw_super) {\n+\t\terror = sb-\u003es_op-\u003ethaw_super(sb,\n \t\t\t\tFREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n-\treturn thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n+\t\t/* -EINVAL means the freeze is gone already. */\n+\t\tif (error == -EINVAL)\n+\t\t\treturn 0;\n+\t\treturn error;\n+\t}\n+\n+\t/* The caller holds an active reference. */\n+\tif (WARN_ON_ONCE(!super_lock_excl(sb)))\n+\t\treturn 0;\n+\n+\t/* FITHAW or an emergency thaw may have dropped the freeze already. */\n+\tif (sb-\u003es_writers.frozen != SB_FREEZE_COMPLETE ||\n+\t !sb-\u003es_writers.freeze_ucount) {\n+\t\tsuper_unlock_excl(sb);\n+\t\treturn 0;\n+\t}\n+\treturn thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE,\n+\t\t\t\t NULL);\n }\n \n static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)\n@@ -1544,7 +1580,8 @@ static void fs_bdev_sync(struct block_device *bdev)\n *\n * Return: 0, or the error from the one superblock on a single-fs device. When\n * several superblocks share @bdev a per-superblock failure is swallowed\n- * (see below), but a sync_blockdev() failure is always reported.\n+ * (see below). A sync_blockdev() failure is only reported if no\n+ * live superblock uses @bdev.\n */\n static int fs_bdev_freeze(struct block_device *bdev)\n {\n@@ -1575,8 +1612,17 @@ static int fs_bdev_freeze(struct block_device *bdev)\n \t */\n \tif (error \u0026\u0026 count \u003e 1)\n \t\terror = 0;\n-\tif (!error)\n-\t\terror = sync_blockdev(bdev);\n+\tif (error)\n+\t\treturn error;\n+\n+\t/*\n+\t * An error tells bdev_freeze() that nothing is frozen and nobody would\n+\t * ever thaw a superblock frozen above. So only report a failed sync if\n+\t * no superblock uses the device.\n+\t */\n+\terror = sync_blockdev(bdev);\n+\tif (count)\n+\t\terror = 0;\n \treturn error;\n }\n \n@@ -1589,7 +1635,8 @@ static int fs_bdev_freeze(struct block_device *bdev)\n * frozen more than once (by the kernel or via another device).\n *\n * Return: 0, or the first error on a single-fs device; a shared device swallows\n- * per-superblock errors, as fs_bdev_freeze() does.\n+ * per-superblock errors, as fs_bdev_freeze() does. A superblock that\n+ * lost the freeze already, e.g., to FITHAW, counts as thawed.\n */\n static int fs_bdev_thaw(struct block_device *bdev)\n {\n@@ -2057,6 +2104,13 @@ static void sb_freeze_unlock(struct super_block *sb, int level)\n \t\tpercpu_up_write(sb-\u003es_writers.rw_sem + level);\n }\n \n+static inline void sb_freeze_wake(struct super_block *sb)\n+{\n+\t/* wake_up_var() needs a full barrier after storing s_writers.frozen. */\n+\tsmp_mb();\n+\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+}\n+\n static int wait_for_partially_frozen(struct super_block *sb)\n {\n \tint ret = 0;\n@@ -2154,14 +2208,15 @@ static inline bool may_unfreeze(struct super_block *sb, enum freeze_holder who,\n \t\t\treturn false;\n \t\tif (WARN_ON_ONCE(!freeze_owner))\n \t\t\treturn false;\n-\t\tif (WARN_ON_ONCE(sb-\u003es_writers.freeze_kcount == 0))\n-\t\t\treturn false;\n \t\t/* This isn't exclusively frozen. */\n \t\tif (!sb-\u003es_writers.freeze_owner)\n \t\t\treturn false;\n \t\t/* This isn't exclusively frozen by us. */\n \t\tif (sb-\u003es_writers.freeze_owner != freeze_owner)\n \t\t\treturn false;\n+\t\t/* An exclusive freeze always holds a kernel reference. */\n+\t\tif (WARN_ON_ONCE(sb-\u003es_writers.freeze_kcount == 0))\n+\t\t\treturn false;\n \t\t/*\n \t\t * This is still frozen multiple times so we're just\n \t\t * going to drop our reference count and undo our\n@@ -2281,7 +2336,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre\n \t\tWARN_ON_ONCE(freeze_inc(sb, who) \u003e 1);\n \t\tsb-\u003es_writers.freeze_owner = freeze_owner;\n \t\tsb-\u003es_writers.frozen = SB_FREEZE_COMPLETE;\n-\t\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+\t\tsb_freeze_wake(sb);\n \t\tsuper_unlock_excl(sb);\n \t\treturn 0;\n \t}\n@@ -2301,7 +2356,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre\n \tif (ret) {\n \t\tsb-\u003es_writers.frozen = SB_UNFROZEN;\n \t\tsb_freeze_unlock(sb, SB_FREEZE_PAGEFAULT);\n-\t\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+\t\tsb_freeze_wake(sb);\n \t\tdeactivate_locked_super(sb);\n \t\treturn ret;\n \t}\n@@ -2317,7 +2372,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre\n \t\t\t\t\"VFS:Filesystem freeze failed\\n\");\n \t\t\tsb-\u003es_writers.frozen = SB_UNFROZEN;\n \t\t\tsb_freeze_unlock(sb, SB_FREEZE_FS);\n-\t\t\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+\t\t\tsb_freeze_wake(sb);\n \t\t\tdeactivate_locked_super(sb);\n \t\t\treturn ret;\n \t\t}\n@@ -2329,7 +2384,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre\n \tWARN_ON_ONCE(freeze_inc(sb, who) \u003e 1);\n \tsb-\u003es_writers.freeze_owner = freeze_owner;\n \tsb-\u003es_writers.frozen = SB_FREEZE_COMPLETE;\n-\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+\tsb_freeze_wake(sb);\n \tlockdep_sb_freeze_release(sb);\n \tsuper_unlock_excl(sb);\n \treturn 0;\n@@ -2366,7 +2421,7 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,\n \tif (sb_rdonly(sb)) {\n \t\tsb-\u003es_writers.frozen = SB_UNFROZEN;\n \t\tsb-\u003es_writers.freeze_owner = NULL;\n-\t\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+\t\tsb_freeze_wake(sb);\n \t\tgoto out_deactivate;\n \t}\n \n@@ -2384,7 +2439,7 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,\n \n \tsb-\u003es_writers.frozen = SB_UNFROZEN;\n \tsb-\u003es_writers.freeze_owner = NULL;\n-\twake_up_var(\u0026sb-\u003es_writers.frozen);\n+\tsb_freeze_wake(sb);\n \tsb_freeze_unlock(sb, SB_FREEZE_FS);\n out_deactivate:\n \tdeactivate_locked_super(sb);\ndiff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile\nindex bc4fdb6f53375..a60778626c8c9 100644\n--- a/tools/testing/selftests/Makefile\n+++ b/tools/testing/selftests/Makefile\n@@ -38,6 +38,7 @@ TARGETS += filesystems/epoll\n TARGETS += filesystems/eventfd\n TARGETS += filesystems/failfs\n TARGETS += filesystems/fat\n+TARGETS += filesystems/freeze\n TARGETS += filesystems/openat2\n TARGETS += filesystems/open_tree_ns\n TARGETS += filesystems/overlayfs\ndiff --git a/tools/testing/selftests/filesystems/.gitignore b/tools/testing/selftests/filesystems/.gitignore\nindex 62f7b1c466497..fa2b6f0bb6a4f 100644\n--- a/tools/testing/selftests/filesystems/.gitignore\n+++ b/tools/testing/selftests/filesystems/.gitignore\n@@ -8,3 +8,4 @@ kernfs_test\n idmapped_tmpfile\n ustat_test\n rw_hint_test\n+fspick_reconfigure_test\ndiff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile\nindex 93e2cc9123b04..ef1b4f6a0f826 100644\n--- a/tools/testing/selftests/filesystems/Makefile\n+++ b/tools/testing/selftests/filesystems/Makefile\n@@ -2,9 +2,11 @@\n \n CFLAGS += $(KHDR_INCLUDES)\n TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test\n-TEST_GEN_PROGS += idmapped_tmpfile\n+TEST_GEN_PROGS += idmapped_tmpfile fspick_reconfigure_test\n TEST_GEN_PROGS_EXTENDED := dnotify_test\n \n+LOCAL_HDRS += wrappers.h freeze/loop_util.h\n+\n include ../lib.mk\n \n $(OUTPUT)/idmapped_tmpfile: LDLIBS += -lcap\ndiff --git a/tools/testing/selftests/filesystems/freeze/.gitignore b/tools/testing/selftests/filesystems/freeze/.gitignore\nnew file mode 100644\nindex 0000000000000..28f1fe73f19b7\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/.gitignore\n@@ -0,0 +1,4 @@\n+# SPDX-License-Identifier: GPL-2.0-only\n+quotactl_test\n+bdev_freeze_test\n+bdev_thaw_test\ndiff --git a/tools/testing/selftests/filesystems/freeze/Makefile b/tools/testing/selftests/filesystems/freeze/Makefile\nnew file mode 100644\nindex 0000000000000..acd246e1b14bb\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/Makefile\n@@ -0,0 +1,8 @@\n+# SPDX-License-Identifier: GPL-2.0\n+CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)\n+LOCAL_HDRS += loop_util.h\n+\n+TEST_GEN_PROGS := quotactl_test\n+TEST_GEN_PROGS += bdev_freeze_test bdev_thaw_test\n+\n+include ../../lib.mk\ndiff --git a/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c b/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c\nnew file mode 100644\nindex 0000000000000..0a13111a85d35\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c\n@@ -0,0 +1,234 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * A failed block device freeze must not leave the filesystem frozen.\n+ *\n+ * bdev_freeze() takes an error from the holder's -\u003efreeze() to mean that\n+ * nothing was frozen and drops bd_fsfreeze_count, so its callers (dm's\n+ * lock_fs(), the filesystem shutdown ioctls) never call bdev_thaw(). Leave a\n+ * writeback error on the block device's page cache and freeze the device\n+ * through EXT4_IOC_SHUTDOWN: either the freeze succeeds, or the superblock\n+ * must not stay frozen. The filesystem is mounted read-only so that\n+ * freeze_super() doesn't sync the device and consume the error itself.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003clinux/fs.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstdint.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 \u003cunistd.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+#include \"loop_util.h\"\n+\n+#define IMG_SIZE (64 \u003c\u003c 20)\n+\n+#ifndef EXT4_IOC_SHUTDOWN\n+#define EXT4_IOC_SHUTDOWN _IOR('X', 125, uint32_t)\n+#endif\n+#ifndef EXT4_GOING_FLAGS_DEFAULT\n+#define EXT4_GOING_FLAGS_DEFAULT 0x0\n+#endif\n+\n+#define FMR \"/sys/kernel/debug/fail_make_request\"\n+#define FMR_VAL_LEN 32\n+\n+/* Global fail_make_request settings that fail exactly the next bio. */\n+static const struct {\n+\tconst char *name;\n+\tconst char *val;\n+} fmr_attrs[] = {\n+\t{ \"probability\", \"100\" },\n+\t{ \"interval\", \"1\" },\n+\t{ \"times\", \"1\" },\n+\t{ \"verbose\", \"0\" },\n+};\n+\n+FIXTURE(bdev_freeze) {\n+\tchar dir[64];\n+\tchar img[96];\n+\tchar mnt[96];\n+\tchar dev[32];\n+\tchar fail[64];\n+\t/* the settings the test found, restored in the teardown */\n+\tchar fmr[ARRAY_SIZE(fmr_attrs)][FMR_VAL_LEN];\n+\tint nr_fmr;\n+\tint loop;\n+\tint mntfd;\n+};\n+\n+static int read_file(const char *path, char *buf, size_t size)\n+{\n+\tssize_t n;\n+\tint fd;\n+\n+\tfd = open(path, O_RDONLY | O_CLOEXEC);\n+\tif (fd \u003c 0)\n+\t\treturn -1;\n+\tn = read(fd, buf, size - 1);\n+\tclose(fd);\n+\tif (n \u003c= 0)\n+\t\treturn -1;\n+\tbuf[n] = '\\0';\n+\treturn 0;\n+}\n+\n+static int write_file(const char *path, const char *val)\n+{\n+\tint fd, ret;\n+\n+\tfd = open(path, O_WRONLY | O_CLOEXEC);\n+\tif (fd \u003c 0)\n+\t\treturn -1;\n+\tret = write(fd, val, strlen(val)) == (ssize_t)strlen(val) ? 0 : -1;\n+\tclose(fd);\n+\treturn ret;\n+}\n+\n+static void bdev_freeze_cleanup(FIXTURE_DATA(bdev_freeze) *self)\n+{\n+\tchar path[128];\n+\n+\tif (self-\u003efail[0])\n+\t\twrite_file(self-\u003efail, \"0\");\n+\tfor (int i = 0; i \u003c self-\u003enr_fmr; i++) {\n+\t\tsnprintf(path, sizeof(path), FMR \"/%s\", fmr_attrs[i].name);\n+\t\twrite_file(path, self-\u003efmr[i]);\n+\t}\n+\tif (self-\u003emntfd \u003e= 0) {\n+\t\t/* don't leave a frozen superblock behind if the test failed */\n+\t\tioctl(self-\u003emntfd, FITHAW, 0);\n+\t\tclose(self-\u003emntfd);\n+\t\tumount2(self-\u003emnt, MNT_DETACH);\n+\t}\n+\tif (self-\u003eloop \u003e= 0)\n+\t\tloop_clear(self-\u003eloop);\n+\tunlink(self-\u003eimg);\n+\trmdir(self-\u003emnt);\n+\trmdir(self-\u003edir);\n+}\n+\n+FIXTURE_SETUP(bdev_freeze)\n+{\n+\tchar cmd[160];\n+\tint fd, ret;\n+\n+\tself-\u003eloop = -1;\n+\tself-\u003emntfd = -1;\n+\tself-\u003enr_fmr = 0;\n+\tself-\u003efail[0] = '\\0';\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+\tif (access(FMR \"/probability\", W_OK))\n+\t\tSKIP(return, \"test requires CONFIG_FAIL_MAKE_REQUEST and debugfs\");\n+\n+\tASSERT_EQ(unshare(CLONE_NEWNS), 0);\n+\tASSERT_EQ(mount(NULL, \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\n+\tsnprintf(self-\u003edir, sizeof(self-\u003edir), \"/tmp/bdev_freeze.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003edir), NULL);\n+\tsnprintf(self-\u003eimg, sizeof(self-\u003eimg), \"%s/img\", self-\u003edir);\n+\tsnprintf(self-\u003emnt, sizeof(self-\u003emnt), \"%s/mnt\", self-\u003edir);\n+\t/* The harness doesn't run the teardown when the setup fails. */\n+\tASSERT_EQ(mkdir(self-\u003emnt, 0700), 0)\n+\t\tbdev_freeze_cleanup(self);\n+\n+\tfd = open(self-\u003eimg, O_RDWR | O_CREAT | O_CLOEXEC, 0600);\n+\tASSERT_GE(fd, 0)\n+\t\tbdev_freeze_cleanup(self);\n+\tASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)\n+\t\tbdev_freeze_cleanup(self);\n+\n+\tsnprintf(cmd, sizeof(cmd), \"mkfs.ext4 -q -F %s \u003e/dev/null 2\u003e\u00261\", self-\u003eimg);\n+\tret = system(cmd);\n+\tif (ret) {\n+\t\tclose(fd);\n+\t\tbdev_freeze_cleanup(self);\n+\t\tSKIP(return, \"mkfs.ext4 failed or is not available\");\n+\t}\n+\n+\tself-\u003eloop = loop_bind(fd);\n+\tclose(fd);\n+\tif (loop_missing(self-\u003eloop)) {\n+\t\tbdev_freeze_cleanup(self);\n+\t\tSKIP(return, \"test requires loop devices\");\n+\t}\n+\tASSERT_GE(self-\u003eloop, 0)\n+\t\tbdev_freeze_cleanup(self);\n+\tsnprintf(self-\u003edev, sizeof(self-\u003edev), \"/dev/loop%d\", self-\u003eloop);\n+\tsnprintf(self-\u003efail, sizeof(self-\u003efail), \"/sys/block/loop%d/make-it-fail\", self-\u003eloop);\n+\n+\tif (mount(self-\u003edev, self-\u003emnt, \"ext4\", MS_RDONLY, NULL)) {\n+\t\tif (errno == ENODEV) {\n+\t\t\tbdev_freeze_cleanup(self);\n+\t\t\tSKIP(return, \"kernel lacks ext4\");\n+\t\t}\n+\t\tASSERT_EQ(errno, 0)\n+\t\t\tbdev_freeze_cleanup(self);\n+\t}\n+\tself-\u003emntfd = open(self-\u003emnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(self-\u003emntfd, 0)\n+\t\tbdev_freeze_cleanup(self);\n+}\n+\n+FIXTURE_TEARDOWN(bdev_freeze)\n+{\n+\tbdev_freeze_cleanup(self);\n+}\n+\n+TEST_F(bdev_freeze, sync_error_does_not_strand_freeze)\n+{\n+\tuint32_t flags = EXT4_GOING_FLAGS_DEFAULT;\n+\toff_t off = IMG_SIZE - 4096;\n+\tchar buf[4096], path[128];\n+\tint fd, ret, err;\n+\n+\t/* Without bdev_allow_write_mounted the mount blocks writers. */\n+\tfd = open(self-\u003edev, O_RDWR | O_CLOEXEC);\n+\tif (fd \u003c 0 \u0026\u0026 errno == EBUSY)\n+\t\tSKIP(return, \"writes to mounted block devices are blocked\");\n+\tASSERT_GE(fd, 0);\n+\n+\tfor (int i = 0; i \u003c ARRAY_SIZE(fmr_attrs); i++) {\n+\t\tsnprintf(path, sizeof(path), FMR \"/%s\", fmr_attrs[i].name);\n+\t\tASSERT_EQ(read_file(path, self-\u003efmr[i], sizeof(self-\u003efmr[i])), 0);\n+\t\tself-\u003enr_fmr = i + 1;\n+\t\tASSERT_EQ(write_file(path, fmr_attrs[i].val), 0);\n+\t}\n+\n+\tmemset(buf, 0x5a, sizeof(buf));\n+\tASSERT_EQ(pwrite(fd, buf, sizeof(buf), off), sizeof(buf));\n+\n+\t/*\n+\t * Start writeback of that page and let it fail. Don't wait for it\n+\t * with an error check: that would consume AS_EIO on the mapping.\n+\t */\n+\tASSERT_EQ(write_file(self-\u003efail, \"1\"), 0);\n+\tASSERT_EQ(sync_file_range(fd, off, sizeof(buf), SYNC_FILE_RANGE_WRITE), 0);\n+\tASSERT_EQ(write_file(self-\u003efail, \"0\"), 0);\n+\t/* The mount keeps the device open, so this close doesn't flush. */\n+\tclose(fd);\n+\n+\t/* bdev_freeze() -\u003e fs_bdev_freeze() -\u003e sync_blockdev() fails */\n+\tret = ioctl(self-\u003emntfd, EXT4_IOC_SHUTDOWN, \u0026flags);\n+\terr = errno;\n+\tTH_LOG(\"EXT4_IOC_SHUTDOWN: %d (%s)\", ret, ret ? strerror(err) : \"ok\");\n+\n+\t/* FITHAW only succeeds on a frozen superblock. */\n+\tret = ioctl(self-\u003emntfd, FITHAW, 0);\n+\tASSERT_NE(ret, 0)\n+\t\tTH_LOG(\"superblock left frozen after the block device freeze failed\");\n+\tASSERT_EQ(errno, EINVAL);\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c b/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c\nnew file mode 100644\nindex 0000000000000..9bb21293093c6\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c\n@@ -0,0 +1,251 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Thawing a superblock behind the block layer's back.\n+ *\n+ * A device-mapper suspend freezes the filesystem on the device through\n+ * bdev_freeze() with the same userspace holder FIFREEZE uses, so FITHAW can\n+ * drop that freeze while the device is still suspended. The resume then\n+ * finds nothing left to thaw. Check that it still thaws the device so that\n+ * it can be mounted again afterwards. The filesystem is mounted read-only\n+ * so the freeze and the thaw don't need to write to the suspended device.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003clinux/dm-ioctl.h\u003e\n+#include \u003clinux/fs.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstdint.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/sysmacros.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+#include \"loop_util.h\"\n+\n+#define IMG_SIZE (64 \u003c\u003c 20)\n+\n+FIXTURE(bdev_thaw) {\n+\tchar dir[64];\n+\tchar img[96];\n+\tchar mnt[96];\n+\tchar node[96];\n+\tchar name[32];\n+\tint loop;\n+\tint mntfd;\n+\tbool tmpfs;\n+\tbool dm;\n+\tbool suspended;\n+\tbool mounted;\n+};\n+\n+static int dm_ioctl(unsigned long cmd, const char *name, uint32_t flags, dev_t *dev)\n+{\n+\tstruct dm_ioctl dmi = {\n+\t\t.version = { DM_VERSION_MAJOR, 0, 0 },\n+\t\t.data_size = sizeof(dmi),\n+\t\t.data_start = sizeof(dmi),\n+\t\t.flags = flags,\n+\t};\n+\tint fd, ret = 0;\n+\n+\tstrncpy(dmi.name, name, sizeof(dmi.name) - 1);\n+\tfd = open(\"/dev/mapper/control\", O_RDWR | O_CLOEXEC);\n+\tif (fd \u003c 0)\n+\t\treturn -errno;\n+\tif (ioctl(fd, cmd, \u0026dmi))\n+\t\tret = -errno;\n+\telse if (dev)\n+\t\t*dev = makedev((dmi.dev \u003e\u003e 8) \u0026 0xfff,\n+\t\t\t (dmi.dev \u0026 0xff) | ((dmi.dev \u003e\u003e 12) \u0026 0xfff00));\n+\tclose(fd);\n+\treturn ret;\n+}\n+\n+/* Remove @name now, or on its last close if udev still has it open. */\n+static int dm_remove(const char *name)\n+{\n+\treturn dm_ioctl(DM_DEV_REMOVE, name, DM_DEFERRED_REMOVE, NULL);\n+}\n+\n+/* Create @name as a linear mapping of all of @backing and make it live. */\n+static int dm_create_linear(const char *name, dev_t backing, uint64_t sectors,\n+\t\t\t dev_t *dev)\n+{\n+\tstruct {\n+\t\tstruct dm_ioctl dmi;\n+\t\tstruct dm_target_spec spec;\n+\t\tchar params[64];\n+\t} __attribute__((aligned(8))) t = {};\n+\tint fd, ret;\n+\n+\tret = dm_ioctl(DM_DEV_CREATE, name, 0, NULL);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tt.dmi.version[0] = DM_VERSION_MAJOR;\n+\tt.dmi.data_size = sizeof(t);\n+\tt.dmi.data_start = sizeof(t.dmi);\n+\tt.dmi.target_count = 1;\n+\tstrncpy(t.dmi.name, name, sizeof(t.dmi.name) - 1);\n+\tt.spec.length = sectors;\n+\tstrcpy(t.spec.target_type, \"linear\");\n+\tsnprintf(t.params, sizeof(t.params), \"%u:%u 0\", major(backing), minor(backing));\n+\n+\tfd = open(\"/dev/mapper/control\", O_RDWR | O_CLOEXEC);\n+\tif (fd \u003e= 0) {\n+\t\tret = ioctl(fd, DM_TABLE_LOAD, \u0026t) ? -errno : 0;\n+\t\tclose(fd);\n+\t} else {\n+\t\tret = -errno;\n+\t}\n+\t/* Resuming makes the loaded table live. */\n+\tif (!ret)\n+\t\tret = dm_ioctl(DM_DEV_SUSPEND, name, 0, dev);\n+\tif (ret)\n+\t\tdm_remove(name);\n+\treturn ret;\n+}\n+\n+static void bdev_thaw_cleanup(FIXTURE_DATA(bdev_thaw) *self)\n+{\n+\tif (self-\u003esuspended)\n+\t\tdm_ioctl(DM_DEV_SUSPEND, self-\u003ename, 0, NULL);\n+\tif (self-\u003emntfd \u003e= 0)\n+\t\tclose(self-\u003emntfd);\n+\tif (self-\u003emounted)\n+\t\tumount2(self-\u003emnt, MNT_DETACH);\n+\tif (self-\u003edm)\n+\t\tdm_remove(self-\u003ename);\n+\tif (self-\u003eloop \u003e= 0)\n+\t\tloop_clear(self-\u003eloop);\n+\tunlink(self-\u003enode);\n+\tunlink(self-\u003eimg);\n+\trmdir(self-\u003emnt);\n+\tif (self-\u003etmpfs)\n+\t\tumount2(self-\u003edir, MNT_DETACH);\n+\trmdir(self-\u003edir);\n+}\n+\n+FIXTURE_SETUP(bdev_thaw)\n+{\n+\tchar cmd[160], dev[32];\n+\tstruct stat st;\n+\tdev_t dmdev;\n+\tint fd, ret;\n+\n+\tself-\u003eloop = -1;\n+\tself-\u003emntfd = -1;\n+\tself-\u003etmpfs = false;\n+\tself-\u003edm = false;\n+\tself-\u003esuspended = false;\n+\tself-\u003emounted = false;\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+\tif (access(\"/dev/mapper/control\", R_OK | W_OK))\n+\t\tSKIP(return, \"test requires device-mapper\");\n+\n+\tASSERT_EQ(unshare(CLONE_NEWNS), 0);\n+\tASSERT_EQ(mount(NULL, \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\n+\tsnprintf(self-\u003edir, sizeof(self-\u003edir), \"/tmp/bdev_thaw.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003edir), NULL);\n+\t/* /tmp may be mounted nodev, the dm node needs a tmpfs of our own. */\n+\tASSERT_EQ(mount(\"tmpfs\", self-\u003edir, \"tmpfs\", MS_NOSUID | MS_NOEXEC, NULL), 0)\n+\t\trmdir(self-\u003edir);\n+\tself-\u003etmpfs = true;\n+\tsnprintf(self-\u003eimg, sizeof(self-\u003eimg), \"%s/img\", self-\u003edir);\n+\tsnprintf(self-\u003emnt, sizeof(self-\u003emnt), \"%s/mnt\", self-\u003edir);\n+\tsnprintf(self-\u003enode, sizeof(self-\u003enode), \"%s/dm\", self-\u003edir);\n+\tsnprintf(self-\u003ename, sizeof(self-\u003ename), \"bdev_thaw_%d\", getpid());\n+\t/* The harness doesn't run the teardown when the setup fails. */\n+\tASSERT_EQ(mkdir(self-\u003emnt, 0700), 0)\n+\t\tbdev_thaw_cleanup(self);\n+\n+\tfd = open(self-\u003eimg, O_RDWR | O_CREAT | O_CLOEXEC, 0600);\n+\tASSERT_GE(fd, 0)\n+\t\tbdev_thaw_cleanup(self);\n+\tASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)\n+\t\tbdev_thaw_cleanup(self);\n+\n+\tsnprintf(cmd, sizeof(cmd), \"mkfs.ext4 -q -F %s \u003e/dev/null 2\u003e\u00261\", self-\u003eimg);\n+\tret = system(cmd);\n+\tif (ret) {\n+\t\tclose(fd);\n+\t\tbdev_thaw_cleanup(self);\n+\t\tSKIP(return, \"mkfs.ext4 failed or is not available\");\n+\t}\n+\n+\tself-\u003eloop = loop_bind(fd);\n+\tclose(fd);\n+\tif (loop_missing(self-\u003eloop)) {\n+\t\tbdev_thaw_cleanup(self);\n+\t\tSKIP(return, \"test requires loop devices\");\n+\t}\n+\tASSERT_GE(self-\u003eloop, 0)\n+\t\tbdev_thaw_cleanup(self);\n+\tsnprintf(dev, sizeof(dev), \"/dev/loop%d\", self-\u003eloop);\n+\tASSERT_EQ(stat(dev, \u0026st), 0)\n+\t\tbdev_thaw_cleanup(self);\n+\n+\tASSERT_EQ(dm_create_linear(self-\u003ename, st.st_rdev, IMG_SIZE \u003e\u003e 9, \u0026dmdev), 0)\n+\t\tbdev_thaw_cleanup(self);\n+\tself-\u003edm = true;\n+\tASSERT_EQ(mknod(self-\u003enode, S_IFBLK | 0600, dmdev), 0)\n+\t\tbdev_thaw_cleanup(self);\n+\n+\tif (mount(self-\u003enode, self-\u003emnt, \"ext4\", MS_RDONLY, NULL)) {\n+\t\tif (errno == ENODEV) {\n+\t\t\tbdev_thaw_cleanup(self);\n+\t\t\tSKIP(return, \"kernel lacks ext4\");\n+\t\t}\n+\t\tASSERT_EQ(errno, 0)\n+\t\t\tbdev_thaw_cleanup(self);\n+\t}\n+\tself-\u003emounted = true;\n+\tself-\u003emntfd = open(self-\u003emnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(self-\u003emntfd, 0)\n+\t\tbdev_thaw_cleanup(self);\n+}\n+\n+FIXTURE_TEARDOWN(bdev_thaw)\n+{\n+\tbdev_thaw_cleanup(self);\n+}\n+\n+TEST_F(bdev_thaw, fithaw_during_dm_suspend)\n+{\n+\t/* A suspend with lockfs freezes the filesystem through bdev_freeze(). */\n+\tASSERT_EQ(dm_ioctl(DM_DEV_SUSPEND, self-\u003ename, DM_SUSPEND_FLAG, NULL), 0);\n+\tself-\u003esuspended = true;\n+\n+\t/* FITHAW drops the freeze the suspend holds. */\n+\tif (ioctl(self-\u003emntfd, FITHAW, 0)) {\n+\t\tASSERT_EQ(errno, EINVAL);\n+\t\tSKIP(return, \"FITHAW doesn't drop a device-mapper freeze\");\n+\t}\n+\n+\t/* The resume's bdev_thaw() finds nothing left to thaw. */\n+\tASSERT_EQ(dm_ioctl(DM_DEV_SUSPEND, self-\u003ename, 0, NULL), 0);\n+\tself-\u003esuspended = false;\n+\n+\tclose(self-\u003emntfd);\n+\tself-\u003emntfd = -1;\n+\tASSERT_EQ(umount2(self-\u003emnt, 0), 0);\n+\tself-\u003emounted = false;\n+\n+\tASSERT_EQ(mount(self-\u003enode, self-\u003emnt, \"ext4\", MS_RDONLY, NULL), 0)\n+\t\tTH_LOG(\"device still frozen after the resume: %s\", strerror(errno));\n+\tself-\u003emounted = true;\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/freeze/config b/tools/testing/selftests/filesystems/freeze/config\nnew file mode 100644\nindex 0000000000000..d03720cda9a98\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/config\n@@ -0,0 +1,9 @@\n+CONFIG_BLK_DEV_DM=y\n+CONFIG_BLK_DEV_LOOP=y\n+CONFIG_DEBUG_FS=y\n+CONFIG_EXT4_FS=y\n+CONFIG_FAIL_MAKE_REQUEST=y\n+CONFIG_FAULT_INJECTION=y\n+CONFIG_FAULT_INJECTION_DEBUG_FS=y\n+CONFIG_MD=y\n+CONFIG_QUOTA=y\ndiff --git a/tools/testing/selftests/filesystems/freeze/loop_util.h b/tools/testing/selftests/filesystems/freeze/loop_util.h\nnew file mode 100644\nindex 0000000000000..fcea5be6030d5\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/loop_util.h\n@@ -0,0 +1,64 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H\n+#define __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H\n+\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003clinux/loop.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+/* How often to retry when somebody else binds the free device first. */\n+#define LOOP_BIND_TRIES 64\n+\n+/* Bind a free loop device to @fd; its number or -errno. */\n+static inline int loop_bind(int fd)\n+{\n+\tfor (int i = 0; i \u003c LOOP_BIND_TRIES; i++) {\n+\t\tchar dev[32];\n+\t\tint cfd, lfd, n, err;\n+\n+\t\tcfd = open(\"/dev/loop-control\", O_RDWR | O_CLOEXEC);\n+\t\tif (cfd \u003c 0)\n+\t\t\treturn -errno;\n+\t\tn = ioctl(cfd, LOOP_CTL_GET_FREE);\n+\t\terr = errno;\n+\t\tclose(cfd);\n+\t\tif (n \u003c 0)\n+\t\t\treturn -err;\n+\t\tsnprintf(dev, sizeof(dev), \"/dev/loop%d\", n);\n+\t\tlfd = open(dev, O_RDWR | O_CLOEXEC);\n+\t\tif (lfd \u003c 0)\n+\t\t\treturn -errno;\n+\t\terr = ioctl(lfd, LOOP_SET_FD, fd) ? errno : 0;\n+\t\tclose(lfd);\n+\t\tif (!err)\n+\t\t\treturn n;\n+\t\tif (err != EBUSY)\n+\t\t\treturn -err;\n+\t}\n+\treturn -EBUSY;\n+}\n+\n+/* Did loop_bind() fail because there are no loop device nodes or no driver? */\n+static inline bool loop_missing(int ret)\n+{\n+\treturn ret == -ENOENT || ret == -ENODEV;\n+}\n+\n+static inline void loop_clear(int n)\n+{\n+\tchar dev[32];\n+\tint fd;\n+\n+\tsnprintf(dev, sizeof(dev), \"/dev/loop%d\", n);\n+\tfd = open(dev, O_RDWR | O_CLOEXEC);\n+\tif (fd \u003c 0)\n+\t\treturn;\n+\tioctl(fd, LOOP_CLR_FD, 0);\n+\tclose(fd);\n+}\n+\n+#endif /* __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H */\ndiff --git a/tools/testing/selftests/filesystems/freeze/quotactl_test.c b/tools/testing/selftests/filesystems/freeze/quotactl_test.c\nnew file mode 100644\nindex 0000000000000..24772e531eb4c\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/freeze/quotactl_test.c\n@@ -0,0 +1,256 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * quotactl(2) on a frozen superblock.\n+ *\n+ * Commands that modify quota wait in quotactl_block() for a frozen\n+ * superblock to be thawed. A read-only superblock is frozen without\n+ * taking s_writers so that wait can't be built on sb_start_write(). Check\n+ * that a caller waiting on a frozen read-only or read-write superblock can\n+ * be killed and that it is woken up when the superblock is thawed.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003clinux/fs.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003csignal.h\u003e\n+#include \u003cstdbool.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/quota.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003csys/wait.h\u003e\n+#include \u003ctime.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+#include \"../../kselftest_harness.h\"\n+#include \"loop_util.h\"\n+\n+#define IMG_SIZE (64 \u003c\u003c 20)\n+#define POLL_MS 10\n+/* How long the child gets to block in quotactl() or to go away. */\n+#define WAIT_MS 3000\n+\n+FIXTURE(frozen) {\n+\tchar dir[64];\n+\tchar img[96];\n+\tchar mnt[96];\n+\tchar dev[32];\n+\tint loop;\n+\tint mntfd;\n+\tpid_t pid;\n+\tbool frozen;\n+};\n+\n+FIXTURE_VARIANT(frozen) {\n+\tunsigned long flags;\n+};\n+\n+FIXTURE_VARIANT_ADD(frozen, ro) {\n+\t.flags = MS_RDONLY,\n+};\n+\n+FIXTURE_VARIANT_ADD(frozen, rw) {\n+\t.flags = 0,\n+};\n+\n+/* Fork a child that calls quotactl(Q_SETQUOTA) on @dev and exits. */\n+static pid_t quotactl_child(const char *dev)\n+{\n+\tpid_t pid;\n+\n+\tpid = fork();\n+\tif (pid == 0) {\n+\t\tstruct if_dqblk dq = {};\n+\n+\t\tquotactl(QCMD(Q_SETQUOTA, USRQUOTA), dev, 0, (void *)\u0026dq);\n+\t\t_exit(0);\n+\t}\n+\treturn pid;\n+}\n+\n+/* Reap @pid within @ms milliseconds; true if it went away. */\n+static bool reap(pid_t pid, int *status, int ms)\n+{\n+\tstruct timespec ts = { .tv_nsec = POLL_MS * 1000 * 1000 };\n+\n+\tfor (int i = 0; i \u003c ms / POLL_MS; i++) {\n+\t\tpid_t ret = waitpid(pid, status, WNOHANG);\n+\n+\t\tif (ret == pid)\n+\t\t\treturn true;\n+\t\tif (ret \u003c 0)\n+\t\t\treturn false;\n+\t\tnanosleep(\u0026ts, NULL);\n+\t}\n+\treturn false;\n+}\n+\n+/* Wait up to @ms milliseconds for @pid to sleep in the kernel. */\n+static bool blocked(pid_t pid, int ms)\n+{\n+\tstruct timespec ts = { .tv_nsec = POLL_MS * 1000 * 1000 };\n+\tchar path[64], buf[512], *p, state;\n+\n+\tsnprintf(path, sizeof(path), \"/proc/%d/stat\", pid);\n+\tfor (int i = 0; i \u003c ms / POLL_MS; i++) {\n+\t\tssize_t n;\n+\t\tint fd;\n+\n+\t\tfd = open(path, O_RDONLY | O_CLOEXEC);\n+\t\tif (fd \u003c 0)\n+\t\t\treturn false;\n+\t\tn = read(fd, buf, sizeof(buf) - 1);\n+\t\tclose(fd);\n+\t\tif (n \u003c= 0)\n+\t\t\treturn false;\n+\t\tbuf[n] = '\\0';\n+\t\t/* \"pid (comm) state ...\" */\n+\t\tp = strrchr(buf, ')');\n+\t\tif (p \u0026\u0026 sscanf(p, \") %c\", \u0026state) == 1 \u0026\u0026\n+\t\t (state == 'D' || state == 'S'))\n+\t\t\treturn true;\n+\t\tnanosleep(\u0026ts, NULL);\n+\t}\n+\treturn false;\n+}\n+\n+static void frozen_cleanup(FIXTURE_DATA(frozen) *self)\n+{\n+\tint status;\n+\n+\tif (self-\u003epid \u003e 0)\n+\t\tkill(self-\u003epid, SIGKILL);\n+\t/* The thaw also lets a waiter go that ignored SIGKILL. */\n+\tif (self-\u003efrozen)\n+\t\tioctl(self-\u003emntfd, FITHAW, 0);\n+\tif (self-\u003epid \u003e 0)\n+\t\treap(self-\u003epid, \u0026status, WAIT_MS);\n+\tif (self-\u003emntfd \u003e= 0) {\n+\t\tclose(self-\u003emntfd);\n+\t\tumount2(self-\u003emnt, MNT_DETACH);\n+\t}\n+\tif (self-\u003eloop \u003e= 0)\n+\t\tloop_clear(self-\u003eloop);\n+\tunlink(self-\u003eimg);\n+\trmdir(self-\u003emnt);\n+\trmdir(self-\u003edir);\n+}\n+\n+FIXTURE_SETUP(frozen)\n+{\n+\tchar cmd[160];\n+\tint fd, ret;\n+\n+\tself-\u003eloop = -1;\n+\tself-\u003emntfd = -1;\n+\tself-\u003epid = -1;\n+\tself-\u003efrozen = false;\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+\t/* Without a device this fails with ENODEV, or ENOSYS without quotactl(). */\n+\tif (quotactl(QCMD(Q_GETINFO, USRQUOTA), NULL, 0, NULL) \u0026\u0026 errno == ENOSYS)\n+\t\tSKIP(return, \"kernel lacks quotactl()\");\n+\n+\tASSERT_EQ(unshare(CLONE_NEWNS), 0);\n+\tASSERT_EQ(mount(NULL, \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\n+\tsnprintf(self-\u003edir, sizeof(self-\u003edir), \"/tmp/freeze_quotactl.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003edir), NULL);\n+\tsnprintf(self-\u003eimg, sizeof(self-\u003eimg), \"%s/img\", self-\u003edir);\n+\tsnprintf(self-\u003emnt, sizeof(self-\u003emnt), \"%s/mnt\", self-\u003edir);\n+\t/* The harness doesn't run the teardown when the setup fails. */\n+\tASSERT_EQ(mkdir(self-\u003emnt, 0700), 0)\n+\t\tfrozen_cleanup(self);\n+\n+\tfd = open(self-\u003eimg, O_RDWR | O_CREAT | O_CLOEXEC, 0600);\n+\tASSERT_GE(fd, 0)\n+\t\tfrozen_cleanup(self);\n+\tASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)\n+\t\tfrozen_cleanup(self);\n+\n+\tsnprintf(cmd, sizeof(cmd), \"mkfs.ext4 -q -F %s \u003e/dev/null 2\u003e\u00261\", self-\u003eimg);\n+\tret = system(cmd);\n+\tif (ret) {\n+\t\tclose(fd);\n+\t\tfrozen_cleanup(self);\n+\t\tSKIP(return, \"mkfs.ext4 failed or is not available\");\n+\t}\n+\n+\tself-\u003eloop = loop_bind(fd);\n+\tclose(fd);\n+\tif (loop_missing(self-\u003eloop)) {\n+\t\tfrozen_cleanup(self);\n+\t\tSKIP(return, \"test requires loop devices\");\n+\t}\n+\tASSERT_GE(self-\u003eloop, 0)\n+\t\tfrozen_cleanup(self);\n+\tsnprintf(self-\u003edev, sizeof(self-\u003edev), \"/dev/loop%d\", self-\u003eloop);\n+\n+\tif (mount(self-\u003edev, self-\u003emnt, \"ext4\", variant-\u003eflags, NULL)) {\n+\t\tif (errno == ENODEV) {\n+\t\t\tfrozen_cleanup(self);\n+\t\t\tSKIP(return, \"kernel lacks ext4\");\n+\t\t}\n+\t\tASSERT_EQ(errno, 0)\n+\t\t\tfrozen_cleanup(self);\n+\t}\n+\tself-\u003emntfd = open(self-\u003emnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);\n+\tASSERT_GE(self-\u003emntfd, 0)\n+\t\tfrozen_cleanup(self);\n+}\n+\n+FIXTURE_TEARDOWN(frozen)\n+{\n+\tfrozen_cleanup(self);\n+}\n+\n+TEST_F(frozen, waiter_is_killable)\n+{\n+\tint status;\n+\n+\tASSERT_EQ(ioctl(self-\u003emntfd, FIFREEZE, 0), 0);\n+\tself-\u003efrozen = true;\n+\n+\tself-\u003epid = quotactl_child(self-\u003edev);\n+\tASSERT_GT(self-\u003epid, 0);\n+\tASSERT_TRUE(blocked(self-\u003epid, WAIT_MS))\n+\t\tTH_LOG(\"quotactl() doesn't wait on a frozen superblock\");\n+\n+\tASSERT_EQ(kill(self-\u003epid, SIGKILL), 0);\n+\tASSERT_TRUE(reap(self-\u003epid, \u0026status, WAIT_MS))\n+\t\tTH_LOG(\"quotactl() waiter survived SIGKILL on a frozen superblock\");\n+\tself-\u003epid = -1;\n+\tASSERT_TRUE(WIFSIGNALED(status));\n+\tASSERT_EQ(WTERMSIG(status), SIGKILL);\n+}\n+\n+TEST_F(frozen, waiter_wakes_on_thaw)\n+{\n+\tint status;\n+\n+\tASSERT_EQ(ioctl(self-\u003emntfd, FIFREEZE, 0), 0);\n+\tself-\u003efrozen = true;\n+\n+\tself-\u003epid = quotactl_child(self-\u003edev);\n+\tASSERT_GT(self-\u003epid, 0);\n+\tASSERT_TRUE(blocked(self-\u003epid, WAIT_MS))\n+\t\tTH_LOG(\"quotactl() doesn't wait on a frozen superblock\");\n+\n+\tASSERT_EQ(ioctl(self-\u003emntfd, FITHAW, 0), 0);\n+\tself-\u003efrozen = false;\n+\n+\tASSERT_TRUE(reap(self-\u003epid, \u0026status, WAIT_MS))\n+\t\tTH_LOG(\"quotactl() waiter wasn't woken by the thaw\");\n+\tself-\u003epid = -1;\n+\tASSERT_TRUE(WIFEXITED(status));\n+\tASSERT_EQ(WEXITSTATUS(status), 0);\n+}\n+\n+TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/filesystems/fspick_reconfigure_test.c b/tools/testing/selftests/filesystems/fspick_reconfigure_test.c\nnew file mode 100644\nindex 0000000000000..a184a5af06d4d\n--- /dev/null\n+++ b/tools/testing/selftests/filesystems/fspick_reconfigure_test.c\n@@ -0,0 +1,231 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Reconfiguring a read-only superblock through fspick().\n+ *\n+ * fspick() creates a reconfiguration context whose flag mask is empty until\n+ * \"ro\" or \"rw\" is set. Filesystems decide whether to go read-write from\n+ * fc-\u003esb_flags, so a reconfiguration without either must leave a read-only\n+ * superblock read-only. Check that writes through a read-write bind mount of\n+ * a read-only ext4 superblock are still refused after such a reconfiguration\n+ * and that an explicit \"rw\" still makes the superblock read-write.\n+ *\n+ * After fsmount() and after each reconfiguration the context can be used for\n+ * the next reconfiguration. A \"ro\" set before must not carry over into it.\n+ */\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+#include \"wrappers.h\"\n+#include \"freeze/loop_util.h\"\n+#include \"../kselftest_harness.h\"\n+\n+#define IMG_SIZE (64 \u003c\u003c 20)\n+\n+#ifndef MNT_DETACH\n+#define MNT_DETACH 2\n+#endif\n+\n+static inline int sys_fspick(int dfd, const char *path, unsigned int flags)\n+{\n+\treturn syscall(__NR_fspick, dfd, path, flags);\n+}\n+\n+static inline int sys_umount2(const char *path, int flags)\n+{\n+\treturn syscall(__NR_umount2, path, flags);\n+}\n+\n+FIXTURE(fspick_ro) {\n+\tchar dir[64];\n+\tchar img[96];\n+\tchar mnt[96];\n+\tchar bind[96];\n+\tint loop;\n+\tbool mounted;\n+\tbool bound;\n+};\n+\n+static void fspick_ro_cleanup(FIXTURE_DATA(fspick_ro) *self)\n+{\n+\tif (self-\u003ebound)\n+\t\tsys_umount2(self-\u003ebind, MNT_DETACH);\n+\tif (self-\u003emounted)\n+\t\tsys_umount2(self-\u003emnt, MNT_DETACH);\n+\tif (self-\u003eloop \u003e= 0)\n+\t\tloop_clear(self-\u003eloop);\n+\tunlink(self-\u003eimg);\n+\trmdir(self-\u003ebind);\n+\trmdir(self-\u003emnt);\n+\trmdir(self-\u003edir);\n+}\n+\n+/* Mount @dev read-only and add a read-write bind mount of it. */\n+static int fspick_ro_mount(FIXTURE_DATA(fspick_ro) *self, const char *dev)\n+{\n+\tif (sys_mount(dev, self-\u003emnt, \"ext4\", MS_RDONLY, NULL))\n+\t\treturn -errno;\n+\tself-\u003emounted = true;\n+\n+\t/* A read-write bind mount only refuses writes if the superblock does. */\n+\tif (sys_mount(self-\u003emnt, self-\u003ebind, NULL, MS_BIND, NULL))\n+\t\treturn -errno;\n+\tself-\u003ebound = true;\n+\tif (sys_mount(NULL, self-\u003ebind, NULL, MS_REMOUNT | MS_BIND, NULL))\n+\t\treturn -errno;\n+\treturn 0;\n+}\n+\n+FIXTURE_SETUP(fspick_ro)\n+{\n+\tchar cmd[160], dev[32];\n+\tint fd, ret;\n+\n+\tself-\u003eloop = -1;\n+\tself-\u003emounted = false;\n+\tself-\u003ebound = false;\n+\n+\tif (geteuid() != 0)\n+\t\tSKIP(return, \"test requires root\");\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(sys_mount(NULL, \"/\", NULL, MS_REC | MS_PRIVATE, NULL), 0);\n+\n+\tsnprintf(self-\u003edir, sizeof(self-\u003edir), \"/tmp/fspick_ro.XXXXXX\");\n+\tASSERT_NE(mkdtemp(self-\u003edir), NULL);\n+\tsnprintf(self-\u003eimg, sizeof(self-\u003eimg), \"%s/img\", self-\u003edir);\n+\tsnprintf(self-\u003emnt, sizeof(self-\u003emnt), \"%s/mnt\", self-\u003edir);\n+\tsnprintf(self-\u003ebind, sizeof(self-\u003ebind), \"%s/bind\", self-\u003edir);\n+\tASSERT_EQ(mkdir(self-\u003emnt, 0700), 0);\n+\tASSERT_EQ(mkdir(self-\u003ebind, 0700), 0);\n+\n+\tfd = open(self-\u003eimg, O_RDWR | O_CREAT | O_CLOEXEC, 0600);\n+\tASSERT_GE(fd, 0);\n+\tASSERT_EQ(ftruncate(fd, IMG_SIZE), 0);\n+\n+\tsnprintf(cmd, sizeof(cmd), \"mkfs.ext4 -q -F %s \u003e/dev/null 2\u003e\u00261\", self-\u003eimg);\n+\tret = system(cmd);\n+\tif (ret) {\n+\t\tclose(fd);\n+\t\tfspick_ro_cleanup(self);\n+\t\tSKIP(return, \"mkfs.ext4 failed or is not available\");\n+\t}\n+\n+\t/* The harness skips the teardown if the setup fails, so clean up. */\n+\tself-\u003eloop = loop_bind(fd);\n+\tclose(fd);\n+\tif (self-\u003eloop \u003c 0) {\n+\t\tfspick_ro_cleanup(self);\n+\t\tASSERT_GE(self-\u003eloop, 0);\n+\t}\n+\tsnprintf(dev, sizeof(dev), \"/dev/loop%d\", self-\u003eloop);\n+\n+\tret = fspick_ro_mount(self, dev);\n+\tif (ret) {\n+\t\tfspick_ro_cleanup(self);\n+\t\tif (ret == -ENODEV)\n+\t\t\tSKIP(return, \"kernel lacks ext4\");\n+\t\tASSERT_EQ(ret, 0);\n+\t}\n+}\n+\n+FIXTURE_TEARDOWN(fspick_ro)\n+{\n+\tfspick_ro_cleanup(self);\n+}\n+\n+static int reconfigure(const char *path, const char *flag)\n+{\n+\tint fd, ret = 0;\n+\n+\tfd = sys_fspick(AT_FDCWD, path, FSPICK_CLOEXEC);\n+\tif (fd \u003c 0)\n+\t\treturn -errno;\n+\tif (flag \u0026\u0026 sys_fsconfig(fd, FSCONFIG_SET_FLAG, flag, NULL, 0))\n+\t\tret = -errno;\n+\tif (!ret \u0026\u0026 sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0))\n+\t\tret = -errno;\n+\tclose(fd);\n+\treturn ret;\n+}\n+\n+static int create_file(const char *dir)\n+{\n+\tchar path[128];\n+\tint fd;\n+\n+\tsnprintf(path, sizeof(path), \"%s/file\", dir);\n+\tfd = open(path, O_RDWR | O_CREAT | O_CLOEXEC, 0600);\n+\tif (fd \u003c 0)\n+\t\treturn -errno;\n+\tclose(fd);\n+\treturn 0;\n+}\n+\n+TEST_F(fspick_ro, reconfigure_keeps_ro)\n+{\n+\tASSERT_EQ(create_file(self-\u003ebind), -EROFS);\n+\n+\tASSERT_EQ(reconfigure(self-\u003emnt, NULL), 0);\n+\tASSERT_EQ(create_file(self-\u003ebind), -EROFS)\n+\t\tTH_LOG(\"reconfiguration without \\\"rw\\\" made the superblock read-write\");\n+}\n+\n+TEST_F(fspick_ro, reconfigure_rw)\n+{\n+\tASSERT_EQ(reconfigure(self-\u003emnt, \"rw\"), 0);\n+\tASSERT_EQ(create_file(self-\u003ebind), 0);\n+}\n+\n+TEST_F(fspick_ro, reconfigure_after_fsmount_keeps_ro)\n+{\n+\tchar dev[32];\n+\tint fd, mfd;\n+\n+\t/* Make room for the new mount, the bind mount keeps the superblock. */\n+\tASSERT_EQ(sys_umount2(self-\u003emnt, 0), 0);\n+\tself-\u003emounted = false;\n+\n+\tsnprintf(dev, sizeof(dev), \"/dev/loop%d\", self-\u003eloop);\n+\tfd = sys_fsopen(\"ext4\", FSOPEN_CLOEXEC);\n+\tASSERT_GE(fd, 0);\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_STRING, \"source\", dev, 0), 0);\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_FLAG, \"ro\", NULL, 0), 0);\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0);\n+\tmfd = sys_fsmount(fd, FSMOUNT_CLOEXEC, 0);\n+\tASSERT_GE(mfd, 0);\n+\tASSERT_EQ(sys_move_mount(mfd, \"\", AT_FDCWD, self-\u003emnt,\n+\t\t\t\t MOVE_MOUNT_F_EMPTY_PATH), 0);\n+\tself-\u003emounted = true;\n+\tclose(mfd);\n+\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);\n+\tclose(fd);\n+\tASSERT_EQ(create_file(self-\u003ebind), -EROFS)\n+\t\tTH_LOG(\"reconfiguration after fsmount() made the superblock read-write\");\n+}\n+\n+TEST_F(fspick_ro, reconfigure_twice_keeps_ro)\n+{\n+\tint fd;\n+\n+\tfd = sys_fspick(AT_FDCWD, self-\u003emnt, FSPICK_CLOEXEC);\n+\tASSERT_GE(fd, 0);\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_FLAG, \"ro\", NULL, 0), 0);\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);\n+\tASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);\n+\tclose(fd);\n+\tASSERT_EQ(create_file(self-\u003ebind), -EROFS)\n+\t\tTH_LOG(\"second reconfiguration made the superblock read-write\");\n+}\n+\n+TEST_HARNESS_MAIN\n"
} |
| 2/1 | 2026/10/11 16:15 | agent | patch-evaluator |
13mModel:core Args: null Results: {
"EnableConfigs": [
"BLOCK",
"QUOTA"
],
"FocusSymbols": [
"reconfigure_super",
"freeze_super",
"thaw_super",
"vfs_clean_context",
"quotactl_block",
"fs_bdev_freeze",
"fs_super_thaw",
"do_emergency_remount",
"fserror_report",
"fserror_unmount"
],
"Reasoning": "The patch series modifies core VFS logic across multiple areas: superblock reconfiguration (reconfigure_super, vfs_clean_context), filesystem and block-device freeze/thaw state handling (freeze_super, thaw_super, fs_bdev_freeze, fs_super_thaw), quota syscall synchronization on frozen filesystems (quotactl_block), emergency remount refcounting/locking (do_emergency_remount), and memory barriers / initialization checks in filesystem error reporting (fserror_pending_dec, fserror_alloc_event). These paths are reachable from userspace in standard virtualized environments via mount, fsopen/fspick/fsconfig, quotactl, and freeze ioctls, making them prime targets for fuzzing.",
"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 49cd28e4b9cb8c0a01dbd19cfdcd9b28bf17b398
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Oct 11 16:15:06 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/fs_context.c b/fs/fs_context.c
index a50584df97bea..ba99e673458a8 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -544,6 +544,7 @@ void vfs_clean_context(struct fs_context *fc)
fc->fs_private = NULL;
fc->s_fs_info = NULL;
fc->sb_flags = 0;
+ fc->sb_flags_mask = 0;
security_free_mnt_opts(&fc->security);
kfree(fc->source);
fc->source = NULL;
diff --git a/fs/fserror.c b/fs/fserror.c
index 1e4d11fd9562f..90ce04d585149 100644
--- a/fs/fserror.c
+++ b/fs/fserror.c
@@ -35,8 +35,15 @@ void fserror_unmount(struct super_block *sb)
static inline void fserror_pending_dec(struct super_block *sb)
{
- if (refcount_dec_and_test(&sb->s_pending_errors))
+ if (refcount_dec_and_test(&sb->s_pending_errors)) {
+ /*
+ * refcount_dec_and_test() isn't fully ordered but wake_up_var()
+ * needs a full barrier between the store and its waitqueue check.
+ * Pairs with the barrier in prepare_to_wait_event().
+ */
+ smp_mb();
wake_up_var(&sb->s_pending_errors);
+ }
}
static inline void fserror_free_event(struct fserror_event *event)
@@ -89,6 +96,13 @@ static inline struct fserror_event *fserror_alloc_event(struct super_block *sb,
return NULL;
if (!(sb->s_flags & SB_ACTIVE))
goto out_pending;
+ /*
+ * xfs and f2fs set SB_ACTIVE while filling the superblock. Nobody can
+ * listen before the superblock is born and if the mount fails nothing
+ * waits for the event.
+ */
+ if (!(sb->s_flags & SB_BORN))
+ goto out_pending;
event = mempool_alloc(&fserror_events_pool, gfp_flags);
if (!event)
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 33bacd7075800..d55ef08de833e 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -894,11 +894,15 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)
up_write(&sb->s_umount);
else
up_read(&sb->s_umount);
- /* Wait for sb to unfreeze */
- sb_start_write(sb);
- sb_end_write(sb);
+ /*
+ * Wait for sb to unfreeze. A read-only superblock is frozen
+ * without taking s_writers so sb_start_write() won't wait.
+ */
+ error = wait_var_event_killable(&sb->s_writers.frozen,
+ READ_ONCE(sb->s_writers.frozen) == SB_UNFROZEN);
put_super(sb);
- cond_resched();
+ if (error)
+ return ERR_PTR(error);
goto retry;
}
return sb;
diff --git a/fs/super.c b/fs/super.c
index 1d5ccf540a9bf..657958a1d1352 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -935,9 +935,8 @@ void drop_super_exclusive(struct super_block *sb)
}
enum super_iter_flags_t {
- SUPER_ITER_EXCL = (1U << 0),
- SUPER_ITER_UNLOCKED = (1U << 1),
- SUPER_ITER_REVERSE = (1U << 2),
+ SUPER_ITER_UNLOCKED = (1U << 0),
+ SUPER_ITER_REVERSE = (1U << 1),
};
static inline struct super_block *first_super(enum super_iter_flags_t flags)
@@ -959,7 +958,6 @@ static void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,
enum super_iter_flags_t flags)
{
struct super_block *sb, *p = NULL;
- bool excl = flags & SUPER_ITER_EXCL;
spin_lock(&sb_lock);
@@ -976,9 +974,9 @@ static void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,
if (flags & SUPER_ITER_UNLOCKED) {
f(sb, arg);
- } else if (super_lock(sb, excl)) {
+ } else if (super_lock_shared(sb)) {
f(sb, arg);
- super_unlock(sb, excl);
+ super_unlock_shared(sb);
}
if (p)
@@ -1077,6 +1075,14 @@ int reconfigure_super(struct fs_context *fc)
if (sb->s_writers.frozen != SB_UNFROZEN)
return -EBUSY;
+ /*
+ * Filesystems take fc->sb_flags & SB_RDONLY as the read-only state the
+ * superblock ends up in. If that isn't being changed, e.g., fspick()
+ * without "ro" or "rw", it's the current one.
+ */
+ if (!(fc->sb_flags_mask & SB_RDONLY))
+ fc->sb_flags = (fc->sb_flags & ~SB_RDONLY) | (sb->s_flags & SB_RDONLY);
+
retval = security_sb_remount(sb, fc->security);
if (retval)
return retval;
@@ -1158,23 +1164,34 @@ int reconfigure_super(struct fs_context *fc)
static void do_emergency_remount_callback(struct super_block *sb, void *unused)
{
- if (sb->s_bdev && !sb_rdonly(sb)) {
- struct fs_context *fc;
+ struct fs_context *fc = NULL;
+
+ if (!super_lock_excl(sb))
+ return;
+ /* Make sure no reference put under s_umount is the last one. */
+ atomic_inc(&sb->s_active);
+ if (sb->s_bdev && !sb_rdonly(sb)) {
fc = fs_context_for_reconfigure(sb->s_root,
SB_RDONLY | SB_FORCE, SB_RDONLY);
- if (!IS_ERR(fc)) {
- if (parse_monolithic_mount_data(fc, NULL) == 0)
- (void)reconfigure_super(fc);
- put_fs_context(fc);
- }
+ if (!IS_ERR(fc) && parse_monolithic_mount_data(fc, NULL) == 0)
+ (void)reconfigure_super(fc);
}
+ super_unlock_excl(sb);
+
+ /*
+ * Our active reference may be the last one by now, so only drop it
+ * after s_umount has been released.
+ */
+ if (!IS_ERR_OR_NULL(fc))
+ put_fs_context(fc);
+ deactivate_super(sb);
}
static void do_emergency_remount(struct work_struct *work)
{
__iterate_supers(do_emergency_remount_callback, NULL,
- SUPER_ITER_EXCL | SUPER_ITER_REVERSE);
+ SUPER_ITER_UNLOCKED | SUPER_ITER_REVERSE);
kfree(work);
printk("Emergency Remount complete\n");
}
@@ -1483,10 +1500,29 @@ static int fs_super_freeze(struct super_block *sb)
static int fs_super_thaw(struct super_block *sb)
{
- if (sb->s_op->thaw_super)
- return sb->s_op->thaw_super(sb,
+ int error;
+
+ if (sb->s_op->thaw_super) {
+ error = sb->s_op->thaw_super(sb,
FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);
- return thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);
+ /* -EINVAL means the freeze is gone already. */
+ if (error == -EINVAL)
+ return 0;
+ return error;
+ }
+
+ /* The caller holds an active reference. */
+ if (WARN_ON_ONCE(!super_lock_excl(sb)))
+ return 0;
+
+ /* FITHAW or an emergency thaw may have dropped the freeze already. */
+ if (sb->s_writers.frozen != SB_FREEZE_COMPLETE ||
+ !sb->s_writers.freeze_ucount) {
+ super_unlock_excl(sb);
+ return 0;
+ }
+ return thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE,
+ NULL);
}
static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)
@@ -1544,7 +1580,8 @@ static void fs_bdev_sync(struct block_device *bdev)
*
* Return: 0, or the error from the one superblock on a single-fs device. When
* several superblocks share @bdev a per-superblock failure is swallowed
- * (see below), but a sync_blockdev() failure is always reported.
+ * (see below). A sync_blockdev() failure is only reported if no
+ * live superblock uses @bdev.
*/
static int fs_bdev_freeze(struct block_device *bdev)
{
@@ -1575,8 +1612,17 @@ static int fs_bdev_freeze(struct block_device *bdev)
*/
if (error && count > 1)
error = 0;
- if (!error)
- error = sync_blockdev(bdev);
+ if (error)
+ return error;
+
+ /*
+ * An error tells bdev_freeze() that nothing is frozen and nobody would
+ * ever thaw a superblock frozen above. So only report a failed sync if
+ * no superblock uses the device.
+ */
+ error = sync_blockdev(bdev);
+ if (count)
+ error = 0;
return error;
}
@@ -1589,7 +1635,8 @@ static int fs_bdev_freeze(struct block_device *bdev)
* frozen more than once (by the kernel or via another device).
*
* Return: 0, or the first error on a single-fs device; a shared device swallows
- * per-superblock errors, as fs_bdev_freeze() does.
+ * per-superblock errors, as fs_bdev_freeze() does. A superblock that
+ * lost the freeze already, e.g., to FITHAW, counts as thawed.
*/
static int fs_bdev_thaw(struct block_device *bdev)
{
@@ -2057,6 +2104,13 @@ static void sb_freeze_unlock(struct super_block *sb, int level)
percpu_up_write(sb->s_writers.rw_sem + level);
}
+static inline void sb_freeze_wake(struct super_block *sb)
+{
+ /* wake_up_var() needs a full barrier after storing s_writers.frozen. */
+ smp_mb();
+ wake_up_var(&sb->s_writers.frozen);
+}
+
static int wait_for_partially_frozen(struct super_block *sb)
{
int ret = 0;
@@ -2154,14 +2208,15 @@ static inline bool may_unfreeze(struct super_block *sb, enum freeze_holder who,
return false;
if (WARN_ON_ONCE(!freeze_owner))
return false;
- if (WARN_ON_ONCE(sb->s_writers.freeze_kcount == 0))
- return false;
/* This isn't exclusively frozen. */
if (!sb->s_writers.freeze_owner)
return false;
/* This isn't exclusively frozen by us. */
if (sb->s_writers.freeze_owner != freeze_owner)
return false;
+ /* An exclusive freeze always holds a kernel reference. */
+ if (WARN_ON_ONCE(sb->s_writers.freeze_kcount == 0))
+ return false;
/*
* This is still frozen multiple times so we're just
* going to drop our reference count and undo our
@@ -2281,7 +2336,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
WARN_ON_ONCE(freeze_inc(sb, who) > 1);
sb->s_writers.freeze_owner = freeze_owner;
sb->s_writers.frozen = SB_FREEZE_COMPLETE;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
super_unlock_excl(sb);
return 0;
}
@@ -2301,7 +2356,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
if (ret) {
sb->s_writers.frozen = SB_UNFROZEN;
sb_freeze_unlock(sb, SB_FREEZE_PAGEFAULT);
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
deactivate_locked_super(sb);
return ret;
}
@@ -2317,7 +2372,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
"VFS:Filesystem freeze failed\n");
sb->s_writers.frozen = SB_UNFROZEN;
sb_freeze_unlock(sb, SB_FREEZE_FS);
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
deactivate_locked_super(sb);
return ret;
}
@@ -2329,7 +2384,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
WARN_ON_ONCE(freeze_inc(sb, who) > 1);
sb->s_writers.freeze_owner = freeze_owner;
sb->s_writers.frozen = SB_FREEZE_COMPLETE;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
lockdep_sb_freeze_release(sb);
super_unlock_excl(sb);
return 0;
@@ -2366,7 +2421,7 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
if (sb_rdonly(sb)) {
sb->s_writers.frozen = SB_UNFROZEN;
sb->s_writers.freeze_owner = NULL;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
goto out_deactivate;
}
@@ -2384,7 +2439,7 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
sb->s_writers.frozen = SB_UNFROZEN;
sb->s_writers.freeze_owner = NULL;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
sb_freeze_unlock(sb, SB_FREEZE_FS);
out_deactivate:
deactivate_locked_super(sb);
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index bc4fdb6f53375..a60778626c8c9 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -38,6 +38,7 @@ TARGETS += filesystems/epoll
TARGETS += filesystems/eventfd
TARGETS += filesystems/failfs
TARGETS += filesystems/fat
+TARGETS += filesystems/freeze
TARGETS += filesystems/openat2
TARGETS += filesystems/open_tree_ns
TARGETS += filesystems/overlayfs
diff --git a/tools/testing/selftests/filesystems/.gitignore b/tools/testing/selftests/filesystems/.gitignore
index 62f7b1c466497..fa2b6f0bb6a4f 100644
--- a/tools/testing/selftests/filesystems/.gitignore
+++ b/tools/testing/selftests/filesystems/.gitignore
@@ -8,3 +8,4 @@ kernfs_test
idmapped_tmpfile
ustat_test
rw_hint_test
+fspick_reconfigure_test
diff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile
index 93e2cc9123b04..ef1b4f6a0f826 100644
--- a/tools/testing/selftests/filesystems/Makefile
+++ b/tools/testing/selftests/filesystems/Makefile
@@ -2,9 +2,11 @@
CFLAGS += $(KHDR_INCLUDES)
TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test
-TEST_GEN_PROGS += idmapped_tmpfile
+TEST_GEN_PROGS += idmapped_tmpfile fspick_reconfigure_test
TEST_GEN_PROGS_EXTENDED := dnotify_test
+LOCAL_HDRS += wrappers.h freeze/loop_util.h
+
include ../lib.mk
$(OUTPUT)/idmapped_tmpfile: LDLIBS += -lcap
diff --git a/tools/testing/selftests/filesystems/freeze/.gitignore b/tools/testing/selftests/filesystems/freeze/.gitignore
new file mode 100644
index 0000000000000..28f1fe73f19b7
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/.gitignore
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+quotactl_test
+bdev_freeze_test
+bdev_thaw_test
diff --git a/tools/testing/selftests/filesystems/freeze/Makefile b/tools/testing/selftests/filesystems/freeze/Makefile
new file mode 100644
index 0000000000000..acd246e1b14bb
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
+LOCAL_HDRS += loop_util.h
+
+TEST_GEN_PROGS := quotactl_test
+TEST_GEN_PROGS += bdev_freeze_test bdev_thaw_test
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c b/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c
new file mode 100644
index 0000000000000..0a13111a85d35
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A failed block device freeze must not leave the filesystem frozen.
+ *
+ * bdev_freeze() takes an error from the holder's ->freeze() to mean that
+ * nothing was frozen and drops bd_fsfreeze_count, so its callers (dm's
+ * lock_fs(), the filesystem shutdown ioctls) never call bdev_thaw(). Leave a
+ * writeback error on the block device's page cache and freeze the device
+ * through EXT4_IOC_SHUTDOWN: either the freeze succeeds, or the superblock
+ * must not stay frozen. The filesystem is mounted read-only so that
+ * freeze_super() doesn't sync the device and consume the error itself.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "loop_util.h"
+
+#define IMG_SIZE (64 << 20)
+
+#ifndef EXT4_IOC_SHUTDOWN
+#define EXT4_IOC_SHUTDOWN _IOR('X', 125, uint32_t)
+#endif
+#ifndef EXT4_GOING_FLAGS_DEFAULT
+#define EXT4_GOING_FLAGS_DEFAULT 0x0
+#endif
+
+#define FMR "/sys/kernel/debug/fail_make_request"
+#define FMR_VAL_LEN 32
+
+/* Global fail_make_request settings that fail exactly the next bio. */
+static const struct {
+ const char *name;
+ const char *val;
+} fmr_attrs[] = {
+ { "probability", "100" },
+ { "interval", "1" },
+ { "times", "1" },
+ { "verbose", "0" },
+};
+
+FIXTURE(bdev_freeze) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char dev[32];
+ char fail[64];
+ /* the settings the test found, restored in the teardown */
+ char fmr[ARRAY_SIZE(fmr_attrs)][FMR_VAL_LEN];
+ int nr_fmr;
+ int loop;
+ int mntfd;
+};
+
+static int read_file(const char *path, char *buf, size_t size)
+{
+ ssize_t n;
+ int fd;
+
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+ n = read(fd, buf, size - 1);
+ close(fd);
+ if (n <= 0)
+ return -1;
+ buf[n] = '\0';
+ return 0;
+}
+
+static int write_file(const char *path, const char *val)
+{
+ int fd, ret;
+
+ fd = open(path, O_WRONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+ ret = write(fd, val, strlen(val)) == (ssize_t)strlen(val) ? 0 : -1;
+ close(fd);
+ return ret;
+}
+
+static void bdev_freeze_cleanup(FIXTURE_DATA(bdev_freeze) *self)
+{
+ char path[128];
+
+ if (self->fail[0])
+ write_file(self->fail, "0");
+ for (int i = 0; i < self->nr_fmr; i++) {
+ snprintf(path, sizeof(path), FMR "/%s", fmr_attrs[i].name);
+ write_file(path, self->fmr[i]);
+ }
+ if (self->mntfd >= 0) {
+ /* don't leave a frozen superblock behind if the test failed */
+ ioctl(self->mntfd, FITHAW, 0);
+ close(self->mntfd);
+ umount2(self->mnt, MNT_DETACH);
+ }
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->img);
+ rmdir(self->mnt);
+ rmdir(self->dir);
+}
+
+FIXTURE_SETUP(bdev_freeze)
+{
+ char cmd[160];
+ int fd, ret;
+
+ self->loop = -1;
+ self->mntfd = -1;
+ self->nr_fmr = 0;
+ self->fail[0] = '\0';
+
+ 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");
+ if (access(FMR "/probability", W_OK))
+ SKIP(return, "test requires CONFIG_FAIL_MAKE_REQUEST and debugfs");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/bdev_freeze.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ /* The harness doesn't run the teardown when the setup fails. */
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0)
+ bdev_freeze_cleanup(self);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0)
+ bdev_freeze_cleanup(self);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)
+ bdev_freeze_cleanup(self);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ bdev_freeze_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (loop_missing(self->loop)) {
+ bdev_freeze_cleanup(self);
+ SKIP(return, "test requires loop devices");
+ }
+ ASSERT_GE(self->loop, 0)
+ bdev_freeze_cleanup(self);
+ snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", self->loop);
+ snprintf(self->fail, sizeof(self->fail), "/sys/block/loop%d/make-it-fail", self->loop);
+
+ if (mount(self->dev, self->mnt, "ext4", MS_RDONLY, NULL)) {
+ if (errno == ENODEV) {
+ bdev_freeze_cleanup(self);
+ SKIP(return, "kernel lacks ext4");
+ }
+ ASSERT_EQ(errno, 0)
+ bdev_freeze_cleanup(self);
+ }
+ self->mntfd = open(self->mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(self->mntfd, 0)
+ bdev_freeze_cleanup(self);
+}
+
+FIXTURE_TEARDOWN(bdev_freeze)
+{
+ bdev_freeze_cleanup(self);
+}
+
+TEST_F(bdev_freeze, sync_error_does_not_strand_freeze)
+{
+ uint32_t flags = EXT4_GOING_FLAGS_DEFAULT;
+ off_t off = IMG_SIZE - 4096;
+ char buf[4096], path[128];
+ int fd, ret, err;
+
+ /* Without bdev_allow_write_mounted the mount blocks writers. */
+ fd = open(self->dev, O_RDWR | O_CLOEXEC);
+ if (fd < 0 && errno == EBUSY)
+ SKIP(return, "writes to mounted block devices are blocked");
+ ASSERT_GE(fd, 0);
+
+ for (int i = 0; i < ARRAY_SIZE(fmr_attrs); i++) {
+ snprintf(path, sizeof(path), FMR "/%s", fmr_attrs[i].name);
+ ASSERT_EQ(read_file(path, self->fmr[i], sizeof(self->fmr[i])), 0);
+ self->nr_fmr = i + 1;
+ ASSERT_EQ(write_file(path, fmr_attrs[i].val), 0);
+ }
+
+ memset(buf, 0x5a, sizeof(buf));
+ ASSERT_EQ(pwrite(fd, buf, sizeof(buf), off), sizeof(buf));
+
+ /*
+ * Start writeback of that page and let it fail. Don't wait for it
+ * with an error check: that would consume AS_EIO on the mapping.
+ */
+ ASSERT_EQ(write_file(self->fail, "1"), 0);
+ ASSERT_EQ(sync_file_range(fd, off, sizeof(buf), SYNC_FILE_RANGE_WRITE), 0);
+ ASSERT_EQ(write_file(self->fail, "0"), 0);
+ /* The mount keeps the device open, so this close doesn't flush. */
+ close(fd);
+
+ /* bdev_freeze() -> fs_bdev_freeze() -> sync_blockdev() fails */
+ ret = ioctl(self->mntfd, EXT4_IOC_SHUTDOWN, &flags);
+ err = errno;
+ TH_LOG("EXT4_IOC_SHUTDOWN: %d (%s)", ret, ret ? strerror(err) : "ok");
+
+ /* FITHAW only succeeds on a frozen superblock. */
+ ret = ioctl(self->mntfd, FITHAW, 0);
+ ASSERT_NE(ret, 0)
+ TH_LOG("superblock left frozen after the block device freeze failed");
+ ASSERT_EQ(errno, EINVAL);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c b/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c
new file mode 100644
index 0000000000000..9bb21293093c6
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c
@@ -0,0 +1,251 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Thawing a superblock behind the block layer's back.
+ *
+ * A device-mapper suspend freezes the filesystem on the device through
+ * bdev_freeze() with the same userspace holder FIFREEZE uses, so FITHAW can
+ * drop that freeze while the device is still suspended. The resume then
+ * finds nothing left to thaw. Check that it still thaws the device so that
+ * it can be mounted again afterwards. The filesystem is mounted read-only
+ * so the freeze and the thaw don't need to write to the suspended device.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/dm-ioctl.h>
+#include <linux/fs.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "loop_util.h"
+
+#define IMG_SIZE (64 << 20)
+
+FIXTURE(bdev_thaw) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char node[96];
+ char name[32];
+ int loop;
+ int mntfd;
+ bool tmpfs;
+ bool dm;
+ bool suspended;
+ bool mounted;
+};
+
+static int dm_ioctl(unsigned long cmd, const char *name, uint32_t flags, dev_t *dev)
+{
+ struct dm_ioctl dmi = {
+ .version = { DM_VERSION_MAJOR, 0, 0 },
+ .data_size = sizeof(dmi),
+ .data_start = sizeof(dmi),
+ .flags = flags,
+ };
+ int fd, ret = 0;
+
+ strncpy(dmi.name, name, sizeof(dmi.name) - 1);
+ fd = open("/dev/mapper/control", O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ if (ioctl(fd, cmd, &dmi))
+ ret = -errno;
+ else if (dev)
+ *dev = makedev((dmi.dev >> 8) & 0xfff,
+ (dmi.dev & 0xff) | ((dmi.dev >> 12) & 0xfff00));
+ close(fd);
+ return ret;
+}
+
+/* Remove @name now, or on its last close if udev still has it open. */
+static int dm_remove(const char *name)
+{
+ return dm_ioctl(DM_DEV_REMOVE, name, DM_DEFERRED_REMOVE, NULL);
+}
+
+/* Create @name as a linear mapping of all of @backing and make it live. */
+static int dm_create_linear(const char *name, dev_t backing, uint64_t sectors,
+ dev_t *dev)
+{
+ struct {
+ struct dm_ioctl dmi;
+ struct dm_target_spec spec;
+ char params[64];
+ } __attribute__((aligned(8))) t = {};
+ int fd, ret;
+
+ ret = dm_ioctl(DM_DEV_CREATE, name, 0, NULL);
+ if (ret)
+ return ret;
+
+ t.dmi.version[0] = DM_VERSION_MAJOR;
+ t.dmi.data_size = sizeof(t);
+ t.dmi.data_start = sizeof(t.dmi);
+ t.dmi.target_count = 1;
+ strncpy(t.dmi.name, name, sizeof(t.dmi.name) - 1);
+ t.spec.length = sectors;
+ strcpy(t.spec.target_type, "linear");
+ snprintf(t.params, sizeof(t.params), "%u:%u 0", major(backing), minor(backing));
+
+ fd = open("/dev/mapper/control", O_RDWR | O_CLOEXEC);
+ if (fd >= 0) {
+ ret = ioctl(fd, DM_TABLE_LOAD, &t) ? -errno : 0;
+ close(fd);
+ } else {
+ ret = -errno;
+ }
+ /* Resuming makes the loaded table live. */
+ if (!ret)
+ ret = dm_ioctl(DM_DEV_SUSPEND, name, 0, dev);
+ if (ret)
+ dm_remove(name);
+ return ret;
+}
+
+static void bdev_thaw_cleanup(FIXTURE_DATA(bdev_thaw) *self)
+{
+ if (self->suspended)
+ dm_ioctl(DM_DEV_SUSPEND, self->name, 0, NULL);
+ if (self->mntfd >= 0)
+ close(self->mntfd);
+ if (self->mounted)
+ umount2(self->mnt, MNT_DETACH);
+ if (self->dm)
+ dm_remove(self->name);
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->node);
+ unlink(self->img);
+ rmdir(self->mnt);
+ if (self->tmpfs)
+ umount2(self->dir, MNT_DETACH);
+ rmdir(self->dir);
+}
+
+FIXTURE_SETUP(bdev_thaw)
+{
+ char cmd[160], dev[32];
+ struct stat st;
+ dev_t dmdev;
+ int fd, ret;
+
+ self->loop = -1;
+ self->mntfd = -1;
+ self->tmpfs = false;
+ self->dm = false;
+ self->suspended = false;
+ self->mounted = false;
+
+ 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");
+ if (access("/dev/mapper/control", R_OK | W_OK))
+ SKIP(return, "test requires device-mapper");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/bdev_thaw.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ /* /tmp may be mounted nodev, the dm node needs a tmpfs of our own. */
+ ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", MS_NOSUID | MS_NOEXEC, NULL), 0)
+ rmdir(self->dir);
+ self->tmpfs = true;
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ snprintf(self->node, sizeof(self->node), "%s/dm", self->dir);
+ snprintf(self->name, sizeof(self->name), "bdev_thaw_%d", getpid());
+ /* The harness doesn't run the teardown when the setup fails. */
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0)
+ bdev_thaw_cleanup(self);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0)
+ bdev_thaw_cleanup(self);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)
+ bdev_thaw_cleanup(self);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ bdev_thaw_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (loop_missing(self->loop)) {
+ bdev_thaw_cleanup(self);
+ SKIP(return, "test requires loop devices");
+ }
+ ASSERT_GE(self->loop, 0)
+ bdev_thaw_cleanup(self);
+ snprintf(dev, sizeof(dev), "/dev/loop%d", self->loop);
+ ASSERT_EQ(stat(dev, &st), 0)
+ bdev_thaw_cleanup(self);
+
+ ASSERT_EQ(dm_create_linear(self->name, st.st_rdev, IMG_SIZE >> 9, &dmdev), 0)
+ bdev_thaw_cleanup(self);
+ self->dm = true;
+ ASSERT_EQ(mknod(self->node, S_IFBLK | 0600, dmdev), 0)
+ bdev_thaw_cleanup(self);
+
+ if (mount(self->node, self->mnt, "ext4", MS_RDONLY, NULL)) {
+ if (errno == ENODEV) {
+ bdev_thaw_cleanup(self);
+ SKIP(return, "kernel lacks ext4");
+ }
+ ASSERT_EQ(errno, 0)
+ bdev_thaw_cleanup(self);
+ }
+ self->mounted = true;
+ self->mntfd = open(self->mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(self->mntfd, 0)
+ bdev_thaw_cleanup(self);
+}
+
+FIXTURE_TEARDOWN(bdev_thaw)
+{
+ bdev_thaw_cleanup(self);
+}
+
+TEST_F(bdev_thaw, fithaw_during_dm_suspend)
+{
+ /* A suspend with lockfs freezes the filesystem through bdev_freeze(). */
+ ASSERT_EQ(dm_ioctl(DM_DEV_SUSPEND, self->name, DM_SUSPEND_FLAG, NULL), 0);
+ self->suspended = true;
+
+ /* FITHAW drops the freeze the suspend holds. */
+ if (ioctl(self->mntfd, FITHAW, 0)) {
+ ASSERT_EQ(errno, EINVAL);
+ SKIP(return, "FITHAW doesn't drop a device-mapper freeze");
+ }
+
+ /* The resume's bdev_thaw() finds nothing left to thaw. */
+ ASSERT_EQ(dm_ioctl(DM_DEV_SUSPEND, self->name, 0, NULL), 0);
+ self->suspended = false;
+
+ close(self->mntfd);
+ self->mntfd = -1;
+ ASSERT_EQ(umount2(self->mnt, 0), 0);
+ self->mounted = false;
+
+ ASSERT_EQ(mount(self->node, self->mnt, "ext4", MS_RDONLY, NULL), 0)
+ TH_LOG("device still frozen after the resume: %s", strerror(errno));
+ self->mounted = true;
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/freeze/config b/tools/testing/selftests/filesystems/freeze/config
new file mode 100644
index 0000000000000..d03720cda9a98
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/config
@@ -0,0 +1,9 @@
+CONFIG_BLK_DEV_DM=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_DEBUG_FS=y
+CONFIG_EXT4_FS=y
+CONFIG_FAIL_MAKE_REQUEST=y
+CONFIG_FAULT_INJECTION=y
+CONFIG_FAULT_INJECTION_DEBUG_FS=y
+CONFIG_MD=y
+CONFIG_QUOTA=y
diff --git a/tools/testing/selftests/filesystems/freeze/loop_util.h b/tools/testing/selftests/filesystems/freeze/loop_util.h
new file mode 100644
index 0000000000000..fcea5be6030d5
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/loop_util.h
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H
+#define __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H
+
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/loop.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+/* How often to retry when somebody else binds the free device first. */
+#define LOOP_BIND_TRIES 64
+
+/* Bind a free loop device to @fd; its number or -errno. */
+static inline int loop_bind(int fd)
+{
+ for (int i = 0; i < LOOP_BIND_TRIES; i++) {
+ char dev[32];
+ int cfd, lfd, n, err;
+
+ cfd = open("/dev/loop-control", O_RDWR | O_CLOEXEC);
+ if (cfd < 0)
+ return -errno;
+ n = ioctl(cfd, LOOP_CTL_GET_FREE);
+ err = errno;
+ close(cfd);
+ if (n < 0)
+ return -err;
+ snprintf(dev, sizeof(dev), "/dev/loop%d", n);
+ lfd = open(dev, O_RDWR | O_CLOEXEC);
+ if (lfd < 0)
+ return -errno;
+ err = ioctl(lfd, LOOP_SET_FD, fd) ? errno : 0;
+ close(lfd);
+ if (!err)
+ return n;
+ if (err != EBUSY)
+ return -err;
+ }
+ return -EBUSY;
+}
+
+/* Did loop_bind() fail because there are no loop device nodes or no driver? */
+static inline bool loop_missing(int ret)
+{
+ return ret == -ENOENT || ret == -ENODEV;
+}
+
+static inline void loop_clear(int n)
+{
+ char dev[32];
+ int fd;
+
+ snprintf(dev, sizeof(dev), "/dev/loop%d", n);
+ fd = open(dev, O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return;
+ ioctl(fd, LOOP_CLR_FD, 0);
+ close(fd);
+}
+
+#endif /* __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H */
diff --git a/tools/testing/selftests/filesystems/freeze/quotactl_test.c b/tools/testing/selftests/filesystems/freeze/quotactl_test.c
new file mode 100644
index 0000000000000..24772e531eb4c
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/quotactl_test.c
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * quotactl(2) on a frozen superblock.
+ *
+ * Commands that modify quota wait in quotactl_block() for a frozen
+ * superblock to be thawed. A read-only superblock is frozen without
+ * taking s_writers so that wait can't be built on sb_start_write(). Check
+ * that a caller waiting on a frozen read-only or read-write superblock can
+ * be killed and that it is woken up when the superblock is thawed.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/quota.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "loop_util.h"
+
+#define IMG_SIZE (64 << 20)
+#define POLL_MS 10
+/* How long the child gets to block in quotactl() or to go away. */
+#define WAIT_MS 3000
+
+FIXTURE(frozen) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char dev[32];
+ int loop;
+ int mntfd;
+ pid_t pid;
+ bool frozen;
+};
+
+FIXTURE_VARIANT(frozen) {
+ unsigned long flags;
+};
+
+FIXTURE_VARIANT_ADD(frozen, ro) {
+ .flags = MS_RDONLY,
+};
+
+FIXTURE_VARIANT_ADD(frozen, rw) {
+ .flags = 0,
+};
+
+/* Fork a child that calls quotactl(Q_SETQUOTA) on @dev and exits. */
+static pid_t quotactl_child(const char *dev)
+{
+ pid_t pid;
+
+ pid = fork();
+ if (pid == 0) {
+ struct if_dqblk dq = {};
+
+ quotactl(QCMD(Q_SETQUOTA, USRQUOTA), dev, 0, (void *)&dq);
+ _exit(0);
+ }
+ return pid;
+}
+
+/* Reap @pid within @ms milliseconds; true if it went away. */
+static bool reap(pid_t pid, int *status, int ms)
+{
+ struct timespec ts = { .tv_nsec = POLL_MS * 1000 * 1000 };
+
+ for (int i = 0; i < ms / POLL_MS; i++) {
+ pid_t ret = waitpid(pid, status, WNOHANG);
+
+ if (ret == pid)
+ return true;
+ if (ret < 0)
+ return false;
+ nanosleep(&ts, NULL);
+ }
+ return false;
+}
+
+/* Wait up to @ms milliseconds for @pid to sleep in the kernel. */
+static bool blocked(pid_t pid, int ms)
+{
+ struct timespec ts = { .tv_nsec = POLL_MS * 1000 * 1000 };
+ char path[64], buf[512], *p, state;
+
+ snprintf(path, sizeof(path), "/proc/%d/stat", pid);
+ for (int i = 0; i < ms / POLL_MS; i++) {
+ ssize_t n;
+ int fd;
+
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return false;
+ n = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (n <= 0)
+ return false;
+ buf[n] = '\0';
+ /* "pid (comm) state ..." */
+ p = strrchr(buf, ')');
+ if (p && sscanf(p, ") %c", &state) == 1 &&
+ (state == 'D' || state == 'S'))
+ return true;
+ nanosleep(&ts, NULL);
+ }
+ return false;
+}
+
+static void frozen_cleanup(FIXTURE_DATA(frozen) *self)
+{
+ int status;
+
+ if (self->pid > 0)
+ kill(self->pid, SIGKILL);
+ /* The thaw also lets a waiter go that ignored SIGKILL. */
+ if (self->frozen)
+ ioctl(self->mntfd, FITHAW, 0);
+ if (self->pid > 0)
+ reap(self->pid, &status, WAIT_MS);
+ if (self->mntfd >= 0) {
+ close(self->mntfd);
+ umount2(self->mnt, MNT_DETACH);
+ }
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->img);
+ rmdir(self->mnt);
+ rmdir(self->dir);
+}
+
+FIXTURE_SETUP(frozen)
+{
+ char cmd[160];
+ int fd, ret;
+
+ self->loop = -1;
+ self->mntfd = -1;
+ self->pid = -1;
+ self->frozen = false;
+
+ 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");
+ /* Without a device this fails with ENODEV, or ENOSYS without quotactl(). */
+ if (quotactl(QCMD(Q_GETINFO, USRQUOTA), NULL, 0, NULL) && errno == ENOSYS)
+ SKIP(return, "kernel lacks quotactl()");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/freeze_quotactl.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ /* The harness doesn't run the teardown when the setup fails. */
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0)
+ frozen_cleanup(self);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0)
+ frozen_cleanup(self);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)
+ frozen_cleanup(self);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ frozen_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (loop_missing(self->loop)) {
+ frozen_cleanup(self);
+ SKIP(return, "test requires loop devices");
+ }
+ ASSERT_GE(self->loop, 0)
+ frozen_cleanup(self);
+ snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", self->loop);
+
+ if (mount(self->dev, self->mnt, "ext4", variant->flags, NULL)) {
+ if (errno == ENODEV) {
+ frozen_cleanup(self);
+ SKIP(return, "kernel lacks ext4");
+ }
+ ASSERT_EQ(errno, 0)
+ frozen_cleanup(self);
+ }
+ self->mntfd = open(self->mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(self->mntfd, 0)
+ frozen_cleanup(self);
+}
+
+FIXTURE_TEARDOWN(frozen)
+{
+ frozen_cleanup(self);
+}
+
+TEST_F(frozen, waiter_is_killable)
+{
+ int status;
+
+ ASSERT_EQ(ioctl(self->mntfd, FIFREEZE, 0), 0);
+ self->frozen = true;
+
+ self->pid = quotactl_child(self->dev);
+ ASSERT_GT(self->pid, 0);
+ ASSERT_TRUE(blocked(self->pid, WAIT_MS))
+ TH_LOG("quotactl() doesn't wait on a frozen superblock");
+
+ ASSERT_EQ(kill(self->pid, SIGKILL), 0);
+ ASSERT_TRUE(reap(self->pid, &status, WAIT_MS))
+ TH_LOG("quotactl() waiter survived SIGKILL on a frozen superblock");
+ self->pid = -1;
+ ASSERT_TRUE(WIFSIGNALED(status));
+ ASSERT_EQ(WTERMSIG(status), SIGKILL);
+}
+
+TEST_F(frozen, waiter_wakes_on_thaw)
+{
+ int status;
+
+ ASSERT_EQ(ioctl(self->mntfd, FIFREEZE, 0), 0);
+ self->frozen = true;
+
+ self->pid = quotactl_child(self->dev);
+ ASSERT_GT(self->pid, 0);
+ ASSERT_TRUE(blocked(self->pid, WAIT_MS))
+ TH_LOG("quotactl() doesn't wait on a frozen superblock");
+
+ ASSERT_EQ(ioctl(self->mntfd, FITHAW, 0), 0);
+ self->frozen = false;
+
+ ASSERT_TRUE(reap(self->pid, &status, WAIT_MS))
+ TH_LOG("quotactl() waiter wasn't woken by the thaw");
+ self->pid = -1;
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/fspick_reconfigure_test.c b/tools/testing/selftests/filesystems/fspick_reconfigure_test.c
new file mode 100644
index 0000000000000..a184a5af06d4d
--- /dev/null
+++ b/tools/testing/selftests/filesystems/fspick_reconfigure_test.c
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Reconfiguring a read-only superblock through fspick().
+ *
+ * fspick() creates a reconfiguration context whose flag mask is empty until
+ * "ro" or "rw" is set. Filesystems decide whether to go read-write from
+ * fc->sb_flags, so a reconfiguration without either must leave a read-only
+ * superblock read-only. Check that writes through a read-write bind mount of
+ * a read-only ext4 superblock are still refused after such a reconfiguration
+ * and that an explicit "rw" still makes the superblock read-write.
+ *
+ * After fsmount() and after each reconfiguration the context can be used for
+ * the next reconfiguration. A "ro" set before must not carry over into it.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "wrappers.h"
+#include "freeze/loop_util.h"
+#include "../kselftest_harness.h"
+
+#define IMG_SIZE (64 << 20)
+
+#ifndef MNT_DETACH
+#define MNT_DETACH 2
+#endif
+
+static inline int sys_fspick(int dfd, const char *path, unsigned int flags)
+{
+ return syscall(__NR_fspick, dfd, path, flags);
+}
+
+static inline int sys_umount2(const char *path, int flags)
+{
+ return syscall(__NR_umount2, path, flags);
+}
+
+FIXTURE(fspick_ro) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char bind[96];
+ int loop;
+ bool mounted;
+ bool bound;
+};
+
+static void fspick_ro_cleanup(FIXTURE_DATA(fspick_ro) *self)
+{
+ if (self->bound)
+ sys_umount2(self->bind, MNT_DETACH);
+ if (self->mounted)
+ sys_umount2(self->mnt, MNT_DETACH);
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->img);
+ rmdir(self->bind);
+ rmdir(self->mnt);
+ rmdir(self->dir);
+}
+
+/* Mount @dev read-only and add a read-write bind mount of it. */
+static int fspick_ro_mount(FIXTURE_DATA(fspick_ro) *self, const char *dev)
+{
+ if (sys_mount(dev, self->mnt, "ext4", MS_RDONLY, NULL))
+ return -errno;
+ self->mounted = true;
+
+ /* A read-write bind mount only refuses writes if the superblock does. */
+ if (sys_mount(self->mnt, self->bind, NULL, MS_BIND, NULL))
+ return -errno;
+ self->bound = true;
+ if (sys_mount(NULL, self->bind, NULL, MS_REMOUNT | MS_BIND, NULL))
+ return -errno;
+ return 0;
+}
+
+FIXTURE_SETUP(fspick_ro)
+{
+ char cmd[160], dev[32];
+ int fd, ret;
+
+ self->loop = -1;
+ self->mounted = false;
+ self->bound = false;
+
+ if (geteuid() != 0)
+ SKIP(return, "test requires root");
+ if (access("/dev/loop-control", R_OK | W_OK))
+ SKIP(return, "test requires loop devices");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(sys_mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/fspick_ro.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ snprintf(self->bind, sizeof(self->bind), "%s/bind", self->dir);
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0);
+ ASSERT_EQ(mkdir(self->bind, 0700), 0);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ fspick_ro_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ /* The harness skips the teardown if the setup fails, so clean up. */
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (self->loop < 0) {
+ fspick_ro_cleanup(self);
+ ASSERT_GE(self->loop, 0);
+ }
+ snprintf(dev, sizeof(dev), "/dev/loop%d", self->loop);
+
+ ret = fspick_ro_mount(self, dev);
+ if (ret) {
+ fspick_ro_cleanup(self);
+ if (ret == -ENODEV)
+ SKIP(return, "kernel lacks ext4");
+ ASSERT_EQ(ret, 0);
+ }
+}
+
+FIXTURE_TEARDOWN(fspick_ro)
+{
+ fspick_ro_cleanup(self);
+}
+
+static int reconfigure(const char *path, const char *flag)
+{
+ int fd, ret = 0;
+
+ fd = sys_fspick(AT_FDCWD, path, FSPICK_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ if (flag && sys_fsconfig(fd, FSCONFIG_SET_FLAG, flag, NULL, 0))
+ ret = -errno;
+ if (!ret && sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0))
+ ret = -errno;
+ close(fd);
+ return ret;
+}
+
+static int create_file(const char *dir)
+{
+ char path[128];
+ int fd;
+
+ snprintf(path, sizeof(path), "%s/file", dir);
+ fd = open(path, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ if (fd < 0)
+ return -errno;
+ close(fd);
+ return 0;
+}
+
+TEST_F(fspick_ro, reconfigure_keeps_ro)
+{
+ ASSERT_EQ(create_file(self->bind), -EROFS);
+
+ ASSERT_EQ(reconfigure(self->mnt, NULL), 0);
+ ASSERT_EQ(create_file(self->bind), -EROFS)
+ TH_LOG("reconfiguration without \"rw\" made the superblock read-write");
+}
+
+TEST_F(fspick_ro, reconfigure_rw)
+{
+ ASSERT_EQ(reconfigure(self->mnt, "rw"), 0);
+ ASSERT_EQ(create_file(self->bind), 0);
+}
+
+TEST_F(fspick_ro, reconfigure_after_fsmount_keeps_ro)
+{
+ char dev[32];
+ int fd, mfd;
+
+ /* Make room for the new mount, the bind mount keeps the superblock. */
+ ASSERT_EQ(sys_umount2(self->mnt, 0), 0);
+ self->mounted = false;
+
+ snprintf(dev, sizeof(dev), "/dev/loop%d", self->loop);
+ fd = sys_fsopen("ext4", FSOPEN_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_STRING, "source", dev, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_FLAG, "ro", NULL, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0);
+ mfd = sys_fsmount(fd, FSMOUNT_CLOEXEC, 0);
+ ASSERT_GE(mfd, 0);
+ ASSERT_EQ(sys_move_mount(mfd, "", AT_FDCWD, self->mnt,
+ MOVE_MOUNT_F_EMPTY_PATH), 0);
+ self->mounted = true;
+ close(mfd);
+
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);
+ close(fd);
+ ASSERT_EQ(create_file(self->bind), -EROFS)
+ TH_LOG("reconfiguration after fsmount() made the superblock read-write");
+}
+
+TEST_F(fspick_ro, reconfigure_twice_keeps_ro)
+{
+ int fd;
+
+ fd = sys_fspick(AT_FDCWD, self->mnt, FSPICK_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_FLAG, "ro", NULL, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);
+ close(fd);
+ ASSERT_EQ(create_file(self->bind), -EROFS)
+ TH_LOG("second reconfiguration made the superblock read-write");
+}
+
+TEST_HARNESS_MAIN
|
| 3/2 | 2026/10/11 16:15 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20900 output: 68 thoughts: 776 Thoughts: **Analyzing a Core VFS Patch Series** Okay, let's dive into this patch series. My initial impression is that this is touching *core* VFS code, which immediately piques my interest. We're looking at changes across `fs/fs_context.c`, `fs/fserror.c`, `fs/quota/quota.c`, and particularly, `fs/super.c`. These are all crucial parts of the VFS, making them prime candidates for further investigation. The inclusion of selftests in `tools/testing/selftests/...` suggests an attempt at thoroughness, which is good to see. Now, let's break down the changes. The addition of `fc->sb_flags_mask = 0;` in `vfs_clean_context()` looks like an attempt at better context management, potentially impacting how file systems are initialized or cleaned up. The `fserror_pending_dec()` modifications, with the `smp_mb()` before `wake_up_var()`, along with the new `fserror_alloc_event()` check, suggest work on error handling and synchronization. That's always worth a close look to ensure correctness. The `quotactl_block()` changes, replacing write locks with `wait_var_event_killable()`, seem to be an effort to improve quota handling concurrency, which is interesting from a performance and deadlock perspective. The significant changes in `fs/super.c` are where it gets even more interesting. We're talking about modifications to flags, locking mechanisms (shared versus exclusive locks), and the `reconfigure_super()` logic. The addition of the conditional `fc->sb_flags = (fc->sb_flags & ~SB_RDONLY) | (sb->s_flags & SB_RDONLY);` in `reconfigure_super()` is particularly intriguing. This is where I'd suspect potential interactions with mounting and remounting. The rewritten locking and ref logic in `do_emergency_remount_callback` also raise a red flag. I’ll need to understand the new logic surrounding freezing and thawing of superblocks, given the new flags and the function calls to `thaw_super_locked`, `sb_freeze_wake`, `freeze_super`, etc. This needs serious scrutiny to verify that everything is sane. The reordering of the checks in `may_unfreeze()` and the assertion `WARN_ON_ONCE(sb->s_writers.freeze_kcount == 0)` suggests that there were prior assumptions about how this code was intended to operate. Considering the "WorthFuzzing" criteria, this patch series seems to tick all the boxes. We are looking at modifications to locking and synchronization, VFS core functionality, and what looks like the introduction of runtime assertions and defensive checks. Therefore, the next steps are clear. I'll need to use my tools to dig deeper into the code. Let's start with a thorough git inspection of the modified files. |
| 4/2 | 2026/10/11 16:16 | tool | grepper |
0mArgs:{
"Expression": "fserror_pending_dec|fserror_alloc_event|vfs_clean_context|reconfigure_super|quotactl_block|fs_super_thaw|fs_bdev_freeze",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/fs_context.c=515=int parse_monolithic_mount_data(struct fs_context *fc, void *data)\n--\nfs/fs_context.c-538- */\nfs/fs_context.c:539:void vfs_clean_context(struct fs_context *fc)\nfs/fs_context.c-540-{\n--\nfs/fserror.c=24=void fserror_unmount(struct super_block *sb)\n--\nfs/fserror.c-35-\nfs/fserror.c:36:static inline void fserror_pending_dec(struct super_block *sb)\nfs/fserror.c-37-{\n--\nfs/fserror.c=49=static inline void fserror_free_event(struct fserror_event *event)\nfs/fserror.c-50-{\nfs/fserror.c:51:\tfserror_pending_dec(event-\u003esb);\nfs/fserror.c-52-\tmempool_free(event, \u0026fserror_events_pool);\n--\nfs/fserror.c=55=static void fserror_worker(struct work_struct *work)\n--\nfs/fserror.c-79-\nfs/fserror.c:80:static inline struct fserror_event *fserror_alloc_event(struct super_block *sb,\nfs/fserror.c-81-\t\t\t\t\t\t\tgfp_t gfp_flags)\n--\nfs/fserror.c-118-out_pending:\nfs/fserror.c:119:\tfserror_pending_dec(sb);\nfs/fserror.c-120-\treturn NULL;\n--\nfs/fserror.c=147=void fserror_report(struct super_block *sb, struct inode *inode,\n--\nfs/fserror.c-158-\nfs/fserror.c:159:\tevent = fserror_alloc_event(sb, gfp);\nfs/fserror.c-160-\tif (!event)\n--\nfs/fsopen.c=251=static int vfs_cmd_reconfigure(struct fs_context *fc)\n--\nfs/fsopen.c-267-\tdown_write(\u0026sb-\u003es_umount);\nfs/fsopen.c:268:\tret = reconfigure_super(fc);\nfs/fsopen.c-269-\tup_write(\u0026sb-\u003es_umount);\n--\nfs/fsopen.c-274-\nfs/fsopen.c:275:\tvfs_clean_context(fc);\nfs/fsopen.c-276-\treturn 0;\n--\nfs/internal.h=47=extern int parse_monolithic_mount_data(struct fs_context *, void *);\nfs/internal.h:48:extern void vfs_clean_context(struct fs_context *fc);\nfs/internal.h-49-extern int finish_clean_context(struct fs_context *fc);\n--\nfs/internal.h=131=void fput_close(struct file *);\n--\nfs/internal.h-135- */\nfs/internal.h:136:extern int reconfigure_super(struct fs_context *);\nfs/internal.h-137-extern bool super_trylock_shared(struct super_block *sb);\n--\nfs/namespace.c=1899=static int do_umount_root(struct super_block *sb)\n--\nfs/namespace.c-1913-\t\t\tif (!ret)\nfs/namespace.c:1914:\t\t\t\tret = reconfigure_super(fc);\nfs/namespace.c-1915-\t\t\tput_fs_context(fc);\n--\nfs/namespace.c=3491=static int do_remount(const struct path *path, int sb_flags,\n--\nfs/namespace.c-3522-\t\tif (ns_capable(sb-\u003es_user_ns, CAP_SYS_ADMIN)) {\nfs/namespace.c:3523:\t\t\terr = reconfigure_super(fc);\nfs/namespace.c-3524-\t\t\tif (!err) {\n--\nfs/namespace.c=4588=SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,\n--\nfs/namespace.c-4675-\t */\nfs/namespace.c:4676:\tvfs_clean_context(fc);\nfs/namespace.c-4677-\n--\nfs/nfs/super.c=1031=int nfs_reconfigure(struct fs_context *fc)\n--\nfs/nfs/super.c-1050-\t * noac is a special case. It implies -o sync, but that's not\nfs/nfs/super.c:1051:\t * necessarily reflected in the mtab options. reconfigure_super\nfs/nfs/super.c-1052-\t * will clear SB_SYNCHRONOUS if -o sync wasn't specified in the\n--\nfs/quota/quota.c=856=static bool quotactl_cmd_onoff(int cmd)\n--\nfs/quota/quota.c-865- */\nfs/quota/quota.c:866:static struct super_block *quotactl_block(const char __user *special, int cmd)\nfs/quota/quota.c-867-{\n--\nfs/quota/quota.c=921=SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,\n--\nfs/quota/quota.c-958-\nfs/quota/quota.c:959:\tsb = quotactl_block(special, cmds);\nfs/quota/quota.c-960-\tif (IS_ERR(sb)) {\n--\nfs/super.c=1041=struct super_block *user_get_super(dev_t dev, bool excl)\n--\nfs/super.c-1059-/**\nfs/super.c:1060: * reconfigure_super - asks filesystem to change superblock parameters\nfs/super.c-1061- * @fc: The superblock and configuration\n--\nfs/super.c-1064- */\nfs/super.c:1065:int reconfigure_super(struct fs_context *fc)\nfs/super.c-1066-{\n--\nfs/super.c=1165=static void do_emergency_remount_callback(struct super_block *sb, void *unused)\n--\nfs/super.c-1177-\t\tif (!IS_ERR(fc) \u0026\u0026 parse_monolithic_mount_data(fc, NULL) == 0)\nfs/super.c:1178:\t\t\t(void)reconfigure_super(fc);\nfs/super.c-1179-\t}\n--\nfs/super.c=1493=static int fs_super_freeze(struct super_block *sb)\n--\nfs/super.c-1500-\nfs/super.c:1501:static int fs_super_thaw(struct super_block *sb)\nfs/super.c-1502-{\n--\nfs/super.c=1555=static void fs_bdev_sync(struct block_device *bdev)\n--\nfs/super.c-1573-/**\nfs/super.c:1574: * fs_bdev_freeze - freeze every superblock using a block device\nfs/super.c-1575- * @bdev: block device\n--\nfs/super.c-1585- */\nfs/super.c:1586:static int fs_bdev_freeze(struct block_device *bdev)\nfs/super.c-1587-{\n--\nfs/super.c-1632- *\nfs/super.c:1633: * The counterpart to fs_bdev_freeze(): thaw each live superblock using @bdev.\nfs/super.c-1634- * A zero return does not imply a superblock is fully unfrozen; it may have been\n--\nfs/super.c-1637- * Return: 0, or the first error on a single-fs device; a shared device swallows\nfs/super.c:1638: * per-superblock errors, as fs_bdev_freeze() does. A superblock that\nfs/super.c-1639- * lost the freeze already, e.g., to FITHAW, counts as thawed.\n--\nfs/super.c=1641=static int fs_bdev_thaw(struct block_device *bdev)\n--\nfs/super.c-1654-\t\t\tcontinue;\nfs/super.c:1655:\t\terr = fs_super_thaw(sb_dev-\u003esd_sb);\nfs/super.c-1656-\t\tif (err \u0026\u0026 !error)\n--\nfs/super.c-1661-\nfs/super.c:1662:\t/* Shared device: swallow per-superblock errors, like fs_bdev_freeze(). */\nfs/super.c-1663-\tif (error \u0026\u0026 count \u003e 1)\n--\nfs/super.c=1668=static const struct blk_holder_ops fs_holder_ops = {\n--\nfs/super.c-1670-\t.sync\t\t\t= fs_bdev_sync,\nfs/super.c:1671:\t.freeze\t\t\t= fs_bdev_freeze,\nfs/super.c-1672-\t.thaw\t\t\t= fs_bdev_thaw,\n"
} |
| 5/2 | 2026/10/11 16:16 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24770 output: 30 thoughts: 21 Thoughts: Here's a summary of my thought process: **Diving into `fserror.c`** Okay, so I need to understand how file system errors are handled and potentially configured. My first thought is to dive into `fserror.c`. I need to figure out what config options, if any, control its behavior, or more specifically, how the functions and structures within `fserror.c` are actually *used* in the larger system. I'm looking for the configuration guards and usage patterns, so I can grasp its role and integration. This should shed light on how we can manage error handling in this module. |
| 6/2 | 2026/10/11 16:16 | tool | grepper |
0mArgs:{
"Expression": "fserror",
"PathPrefixes": [
"fs/",
"include/"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 631 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (34 files in total):\nfs/Makefile:1\nfs/btrfs/fs.h:2\nfs/ext4/ioctl.c:2\nfs/ext4/super.c:5\nfs/f2fs/compress.c:2\nfs/f2fs/data.c:2\nfs/f2fs/dir.c:2\nfs/f2fs/inline.c:3\nfs/f2fs/inode.c:5\nfs/f2fs/node.c:5\nfs/f2fs/recovery.c:2\nfs/f2fs/segment.c:2\nfs/f2fs/super.c:5\nfs/f2fs/sysfs.c:2\nfs/f2fs/verity.c:2\nfs/f2fs/xattr.c:5\nfs/fserror.c:30\nfs/iomap/bio.c:1\nfs/iomap/buffered-io.c:6\nfs/iomap/direct-io.c:7\nfs/iomap/ioend.c:3\nfs/super.c:3\nfs/xfs/xfs_fsops.c:2\nfs/xfs/xfs_health.c:10\nfs/xfs/xfs_healthmon.c:3\nfs/xfs/xfs_healthmon.h:1\nfs/xfs/xfs_icache.c:1\nfs/xfs/xfs_notify_failure.c:2\nfs/xfs/xfs_super.c:2\nfs/xfs/xfs_trace.c:1\nfs/xfs/xfs_trace.h:2\nfs/xfs/xfs_verify_media.c:2\ninclude/linux/fs/super_types.h:3\ninclude/linux/fserror.h:18\n\nfs/Makefile=10=obj-y :=\topen.o read_write.o file_table.o super.o \\\n--\nfs/Makefile-18-\t\tkernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \\\nfs/Makefile:19:\t\tfile_attr.o fserror.o nullfs.o failfs.o\nfs/Makefile-20-\n--\nfs/btrfs/fs.h-29-#include \u003clinux/xxhash.h\u003e\nfs/btrfs/fs.h:30:#include \u003clinux/fserror.h\u003e\nfs/btrfs/fs.h-31-#include \u003cuapi/linux/btrfs.h\u003e\n--\nfs/btrfs/fs.h=1224=static inline void btrfs_force_shutdown(struct btrfs_fs_info *fs_info)\n--\nfs/btrfs/fs.h-1237-\t\tbtrfs_crit(fs_info, \"emergency shutdown\");\nfs/btrfs/fs.h:1238:\t\tfserror_report_shutdown(fs_info-\u003esb, GFP_KERNEL);\nfs/btrfs/fs.h-1239-\t}\n--\nfs/ext4/ioctl.c-28-#include \u003ctrace/events/ext4.h\u003e\nfs/ext4/ioctl.c:29:#include \u003clinux/fserror.h\u003e\nfs/ext4/ioctl.c-30-\n--\nfs/ext4/ioctl.c=810=int ext4_force_shutdown(struct super_block *sb, u32 flags)\n--\nfs/ext4/ioctl.c-853-\tclear_opt(sb, DISCARD);\nfs/ext4/ioctl.c:854:\tfserror_report_shutdown(sb, GFP_KERNEL);\nfs/ext4/ioctl.c-855-\treturn 0;\n--\nfs/ext4/super.c-50-#include \u003clinux/fs_parser.h\u003e\nfs/ext4/super.c:51:#include \u003clinux/fserror.h\u003e\nfs/ext4/super.c-52-\n--\nfs/ext4/super.c=814=void __ext4_error(struct super_block *sb, const char *function,\n--\nfs/ext4/super.c-833-\t}\nfs/ext4/super.c:834:\tfserror_report_metadata(sb, error ? -abs(error) : -EFSCORRUPTED,\nfs/ext4/super.c-835-\t\t\t\tGFP_ATOMIC);\n--\nfs/ext4/super.c=840=void __ext4_error_inode(struct inode *inode, const char *function,\n--\nfs/ext4/super.c-866-\t}\nfs/ext4/super.c:867:\tfserror_report_file_metadata(inode,\nfs/ext4/super.c-868-\t\t\t\t error ? -abs(error) : -EFSCORRUPTED,\n--\nfs/ext4/super.c=875=void __ext4_error_file(struct file *file, const char *function,\n--\nfs/ext4/super.c-908-\t}\nfs/ext4/super.c:909:\tfserror_report_file_metadata(inode, -EFSCORRUPTED, GFP_ATOMIC);\nfs/ext4/super.c-910-\n--\nfs/ext4/super.c=958=void __ext4_std_error(struct super_block *sb, const char *function,\n--\nfs/ext4/super.c-977-\t}\nfs/ext4/super.c:978:\tfserror_report_metadata(sb, errno ? -abs(errno) : -EFSCORRUPTED,\nfs/ext4/super.c-979-\t\t\t\tGFP_ATOMIC);\n--\nfs/f2fs/compress.c-16-#include \u003clinux/folio_batch.h\u003e\nfs/f2fs/compress.c:17:#include \u003clinux/fserror.h\u003e\nfs/f2fs/compress.c-18-\n--\nfs/f2fs/compress.c=733=void f2fs_decompress_cluster(struct decompress_io_ctx *dic, bool in_task)\n--\nfs/f2fs/compress.c-763-\t\tf2fs_handle_error(sbi, ERROR_FAIL_DECOMPRESSION);\nfs/f2fs/compress.c:764:\t\tfserror_report_file_metadata(dic-\u003einode, ret, GFP_NOFS);\nfs/f2fs/compress.c-765-\t\tgoto out_release;\n--\nfs/f2fs/data.c-22-#include \u003clinux/iomap.h\u003e\nfs/f2fs/data.c:23:#include \u003clinux/fserror.h\u003e\nfs/f2fs/data.c-24-\n--\nfs/f2fs/data.c=1650=int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)\n--\nfs/f2fs/data.c-1780-\t\t\t\t\tERROR_CORRUPTED_CLUSTER);\nfs/f2fs/data.c:1781:\t\t\tfserror_report_file_metadata(inode, err, GFP_NOFS);\nfs/f2fs/data.c-1782-\t\t\tgoto sync_out;\n--\nfs/f2fs/dir.c-13-#include \u003clinux/unicode.h\u003e\nfs/f2fs/dir.c:14:#include \u003clinux/fserror.h\u003e\nfs/f2fs/dir.c-15-#include \"f2fs.h\"\n--\nfs/f2fs/dir.c=980=int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,\n--\nfs/f2fs/dir.c-1029-\t\t\tf2fs_handle_error(sbi, ERROR_CORRUPTED_DIRENT);\nfs/f2fs/dir.c:1030:\t\t\tfserror_report_file_metadata(d-\u003einode, err, GFP_NOFS);\nfs/f2fs/dir.c-1031-\t\t\tgoto out;\n--\nfs/f2fs/inline.c-11-#include \u003clinux/fiemap.h\u003e\nfs/f2fs/inline.c:12:#include \u003clinux/fserror.h\u003e\nfs/f2fs/inline.c-13-\n--\nfs/f2fs/inline.c=146=int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)\n--\nfs/f2fs/inline.c-182-\t\tf2fs_handle_error(fio.sbi, ERROR_INVALID_BLKADDR);\nfs/f2fs/inline.c:183:\t\tfserror_report_file_metadata(dn-\u003einode, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/inline.c-184-\t\treturn -EFSCORRUPTED;\n--\nfs/f2fs/inline.c=413=static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,\n--\nfs/f2fs/inline.c-439-\t\terr = -EFSCORRUPTED;\nfs/f2fs/inline.c:440:\t\tfserror_report_file_metadata(dn.inode, err, GFP_NOFS);\nfs/f2fs/inline.c-441-\t\tgoto out;\n--\nfs/f2fs/inode.c-14-#include \u003clinux/zstd.h\u003e\nfs/f2fs/inode.c:15:#include \u003clinux/fserror.h\u003e\nfs/f2fs/inode.c-16-\n--\nfs/f2fs/inode.c=427=static int do_read_inode(struct inode *inode)\n--\nfs/f2fs/inode.c-496-\t\tf2fs_handle_error(sbi, ERROR_CORRUPTED_INODE);\nfs/f2fs/inode.c:497:\t\tfserror_report_file_metadata(inode, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/inode.c-498-\t\treturn -EFSCORRUPTED;\n--\nfs/f2fs/inode.c-558-\t\tf2fs_handle_error(sbi, ERROR_CORRUPTED_INODE);\nfs/f2fs/inode.c:559:\t\tfserror_report_file_metadata(inode, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/inode.c-560-\t\treturn -EFSCORRUPTED;\n--\nfs/f2fs/inode.c=589=struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)\n--\nfs/f2fs/inode.c-606-\t\t\tf2fs_handle_error(sbi, ERROR_CORRUPTED_INODE);\nfs/f2fs/inode.c:607:\t\t\tfserror_report_file_metadata(inode, ret, GFP_NOFS);\nfs/f2fs/inode.c-608-\t\t\treturn ERR_PTR(ret);\n--\nfs/f2fs/inode.c=795=void f2fs_update_inode_page(struct inode *inode)\n--\nfs/f2fs/inode.c-814-stop_checkpoint:\nfs/f2fs/inode.c:815:\t\tfserror_report_file_metadata(inode, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/inode.c-816-\t\tf2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_UPDATE_INODE);\n--\nfs/f2fs/node.c-14-#include \u003clinux/swap.h\u003e\nfs/f2fs/node.c:15:#include \u003clinux/fserror.h\u003e\nfs/f2fs/node.c-16-\n--\nfs/f2fs/node.c=1196=int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from)\n--\nfs/f2fs/node.c-1279-\t\t\tf2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);\nfs/f2fs/node.c:1280:\t\t\tfserror_report_file_metadata(dn.inode, -EFSCORRUPTED,\nfs/f2fs/node.c-1281-\t\t\t\t\t\t\t\tGFP_NOFS);\n--\nfs/f2fs/node.c=1529=int f2fs_sanity_check_node_footer(struct f2fs_sb_info *sbi,\n--\nfs/f2fs/node.c-1576-\tf2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER);\nfs/f2fs/node.c:1577:\tfserror_report_file_metadata(folio-\u003emapping-\u003ehost,\nfs/f2fs/node.c-1578-\t\t\t-EFSCORRUPTED, in_irq ? GFP_NOWAIT : GFP_NOFS);\n--\nfs/f2fs/node.c=1753=static bool __write_node_folio(struct folio *folio, bool atomic, bool do_fsync,\n--\nfs/f2fs/node.c-1800-\t\t\t\t\tNODE_TYPE_REGULAR, false)) {\nfs/f2fs/node.c:1801:\t\tfserror_report_metadata(sbi-\u003esb, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/node.c-1802-\t\tf2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_CORRUPTED_NID);\n--\nfs/f2fs/node.c=2709=bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)\n--\nfs/f2fs/node.c-2733-\t\t\t\t\t\t\t\ti-\u003enid);\nfs/f2fs/node.c:2734:\t\t\tfserror_report_metadata(sbi-\u003esb, -EFSCORRUPTED,\nfs/f2fs/node.c-2735-\t\t\t\t\t\t\t\tGFP_NOFS);\n--\nfs/f2fs/recovery.c-11-#include \u003clinux/sched/mm.h\u003e\nfs/f2fs/recovery.c:12:#include \u003clinux/fserror.h\u003e\nfs/f2fs/recovery.c-13-#include \"f2fs.h\"\n--\nfs/f2fs/recovery.c=647=static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,\n--\nfs/f2fs/recovery.c-703-\t\tf2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER);\nfs/f2fs/recovery.c:704:\t\tfserror_report_file_metadata(dn.inode, err, GFP_NOFS);\nfs/f2fs/recovery.c-705-\t\tgoto err;\n--\nfs/f2fs/segment.c-19-#include \u003clinux/random.h\u003e\nfs/f2fs/segment.c:20:#include \u003clinux/fserror.h\u003e\nfs/f2fs/segment.c-21-\n--\nfs/f2fs/segment.c=2870=static int get_new_segment(struct f2fs_sb_info *sbi,\n--\nfs/f2fs/segment.c-3004-\t\tret = -EFSCORRUPTED;\nfs/f2fs/segment.c:3005:\t\tfserror_report_metadata(sbi-\u003esb, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/segment.c-3006-\t\tf2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_CORRUPTED_FREE_BITMAP);\n--\nfs/f2fs/super.c-31-#include \u003clinux/fs_parser.h\u003e\nfs/f2fs/super.c:32:#include \u003clinux/fserror.h\u003e\nfs/f2fs/super.c-33-\n--\nfs/f2fs/super.c=4673=static void f2fs_record_stop_reason(struct f2fs_sb_info *sbi)\n--\nfs/f2fs/super.c-4702-\tif (report_shutdown)\nfs/f2fs/super.c:4703:\t\tfserror_report_shutdown(sbi-\u003esb, GFP_NOFS);\nfs/f2fs/super.c-4704-}\n--\nfs/f2fs/super.c=4706=void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag)\n--\nfs/f2fs/super.c-4717-\nfs/f2fs/super.c:4718:static void f2fs_report_fserror(struct f2fs_sb_info *sbi, unsigned char error)\nfs/f2fs/super.c-4719-{\n--\nfs/f2fs/super.c-4731-\tcase ERROR_INCONSISTENT_NAT:\nfs/f2fs/super.c:4732:\t\tfserror_report_metadata(sbi-\u003esb, -EFSCORRUPTED, GFP_NOFS);\nfs/f2fs/super.c-4733-\t\tbreak;\n--\nfs/f2fs/super.c=4739=void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error)\n--\nfs/f2fs/super.c-4748-\nfs/f2fs/super.c:4749:\tf2fs_report_fserror(sbi, error);\nfs/f2fs/super.c-4750-}\n--\n\n"
} |
| 7/2 | 2026/10/11 16:16 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29467 output: 33 thoughts: 13 Thoughts: Here's a breakdown of my thought process: **Diving Deep into fs/fserror.c** Okay, time to really scrutinize `fs/fserror.c`. I need to get a granular understanding of how this particular module handles error conditions within the file system. What are the key data structures and functions being employed? I'm anticipating this will involve examining the error codes themselves, the mechanisms for reporting them, and perhaps even the strategies for recovering from specific failures. I'll be looking for common patterns, potential bottlenecks, and any areas that might benefit from more robust error handling or more detailed logging. This deep dive should illuminate the overall resilience of the file system and where its weak points may lie. |
| 8/2 | 2026/10/11 16:16 | tool | read-file |
0mArgs:{
"File": "fs/fserror.c",
"FirstLine": 1,
"LineCount": 100
}Results: {
"Contents": " 1:\t// SPDX-License-Identifier: GPL-2.0-or-later\n 2:\t/*\n 3:\t * Copyright (c) 2025 Oracle. All Rights Reserved.\n 4:\t * Author: Darrick J. Wong \u003cdjwong@kernel.org\u003e\n 5:\t */\n 6:\t#include \u003clinux/fs.h\u003e\n 7:\t#include \u003clinux/fsnotify.h\u003e\n 8:\t#include \u003clinux/mempool.h\u003e\n 9:\t#include \u003clinux/fserror.h\u003e\n 10:\t\n 11:\t#define FSERROR_DEFAULT_EVENT_POOL_SIZE\t\t(32)\n 12:\t\n 13:\tstatic struct mempool fserror_events_pool;\n 14:\t\n 15:\tvoid fserror_mount(struct super_block *sb)\n 16:\t{\n 17:\t\t/*\n 18:\t\t * The pending error counter is biased by 1 so that we don't wake_var\n 19:\t\t * until we're actually trying to unmount.\n 20:\t\t */\n 21:\t\trefcount_set(\u0026sb-\u003es_pending_errors, 1);\n 22:\t}\n 23:\t\n 24:\tvoid fserror_unmount(struct super_block *sb)\n 25:\t{\n 26:\t\t/*\n 27:\t\t * If we don't drop the pending error count to zero, then wait for it\n 28:\t\t * to drop below 1, which means that the pending errors cleared and\n 29:\t\t * hopefully we didn't saturate with 1 billion+ concurrent events.\n 30:\t\t */\n 31:\t\tif (!refcount_dec_and_test(\u0026sb-\u003es_pending_errors))\n 32:\t\t\twait_var_event(\u0026sb-\u003es_pending_errors,\n 33:\t\t\t\t refcount_read(\u0026sb-\u003es_pending_errors) \u003c 1);\n 34:\t}\n 35:\t\n 36:\tstatic inline void fserror_pending_dec(struct super_block *sb)\n 37:\t{\n 38:\t\tif (refcount_dec_and_test(\u0026sb-\u003es_pending_errors)) {\n 39:\t\t\t/*\n 40:\t\t\t * refcount_dec_and_test() isn't fully ordered but wake_up_var()\n 41:\t\t\t * needs a full barrier between the store and its waitqueue check.\n 42:\t\t\t * Pairs with the barrier in prepare_to_wait_event().\n 43:\t\t\t */\n 44:\t\t\tsmp_mb();\n 45:\t\t\twake_up_var(\u0026sb-\u003es_pending_errors);\n 46:\t\t}\n 47:\t}\n 48:\t\n 49:\tstatic inline void fserror_free_event(struct fserror_event *event)\n 50:\t{\n 51:\t\tfserror_pending_dec(event-\u003esb);\n 52:\t\tmempool_free(event, \u0026fserror_events_pool);\n 53:\t}\n 54:\t\n 55:\tstatic void fserror_worker(struct work_struct *work)\n 56:\t{\n 57:\t\tstruct fserror_event *event =\n 58:\t\t\t\tcontainer_of(work, struct fserror_event, work);\n 59:\t\tstruct super_block *sb = event-\u003esb;\n 60:\t\n 61:\t\tif (sb-\u003es_flags \u0026 SB_ACTIVE) {\n 62:\t\t\tstruct fs_error_report report = {\n 63:\t\t\t\t/* send positive error number to userspace */\n 64:\t\t\t\t.error = -event-\u003eerror,\n 65:\t\t\t\t.inode = event-\u003einode,\n 66:\t\t\t\t.sb = event-\u003esb,\n 67:\t\t\t};\n 68:\t\n 69:\t\t\tif (sb-\u003es_op-\u003ereport_error)\n 70:\t\t\t\tsb-\u003es_op-\u003ereport_error(event);\n 71:\t\n 72:\t\t\tfsnotify(FS_ERROR, \u0026report, FSNOTIFY_EVENT_ERROR, NULL, NULL,\n 73:\t\t\t\t NULL, 0);\n 74:\t\t}\n 75:\t\n 76:\t\tiput(event-\u003einode);\n 77:\t\tfserror_free_event(event);\n 78:\t}\n 79:\t\n 80:\tstatic inline struct fserror_event *fserror_alloc_event(struct super_block *sb,\n 81:\t\t\t\t\t\t\t\tgfp_t gfp_flags)\n 82:\t{\n 83:\t\tstruct fserror_event *event = NULL;\n 84:\t\n 85:\t\t/*\n 86:\t\t * If pending_errors already reached zero or is no longer active,\n 87:\t\t * the superblock is being deactivated so there's no point in\n 88:\t\t * continuing.\n 89:\t\t *\n 90:\t\t * The order of the check of s_pending_errors and SB_ACTIVE are\n 91:\t\t * mandated by order of accesses in generic_shutdown_super and\n 92:\t\t * fserror_unmount. Barriers are implicitly provided by the refcount\n 93:\t\t * manipulations in this function and fserror_unmount.\n 94:\t\t */\n 95:\t\tif (!refcount_inc_not_zero(\u0026sb-\u003es_pending_errors))\n 96:\t\t\treturn NULL;\n 97:\t\tif (!(sb-\u003es_flags \u0026 SB_ACTIVE))\n 98:\t\t\tgoto out_pending;\n 99:\t\t/*\n 100:\t\t * xfs and f2fs set SB_ACTIVE while filling the superblock. Nobody can\n"
} |
| 9/2 | 2026/10/11 16:16 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31090 output: 35 thoughts: 18 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into `fs/fs_context.c` Around Line 544** Right, let's zero in on `fs/fs_context.c` and specifically, around line 544. That's usually where the core of the `fs_context` structure initialization and setup is handled. I need to refresh my memory on what that section is responsible for. I'm likely looking for the instantiation, initial population, or perhaps the finalization of the context related structures. I'm expecting to find some crucial pieces of the file system mount process happening in that area. Probably looking at how the context is hooked up with the superblock, or handling some of the arguments passed during the mount operation. I'm curious what the context is handling, in this specific mount scenario. I need to be sure that the error handling and initialization are correct, as I'm sure I'll probably be looking for a bug there. |
| 10/2 | 2026/10/11 16:17 | tool | read-file |
0mArgs:{
"File": "fs/fs_context.c",
"FirstLine": 535,
"LineCount": 30
}Results: {
"Contents": " 535:\t * and failing to allocate memory would've put us into a nasty situation.\n 536:\t * So here we only discard the old state and reinitialization is left\n 537:\t * until we actually try to reconfigure.\n 538:\t */\n 539:\tvoid vfs_clean_context(struct fs_context *fc)\n 540:\t{\n 541:\t\tif (fc-\u003eneed_free \u0026\u0026 fc-\u003eops \u0026\u0026 fc-\u003eops-\u003efree)\n 542:\t\t\tfc-\u003eops-\u003efree(fc);\n 543:\t\tfc-\u003eneed_free = false;\n 544:\t\tfc-\u003efs_private = NULL;\n 545:\t\tfc-\u003es_fs_info = NULL;\n 546:\t\tfc-\u003esb_flags = 0;\n 547:\t\tfc-\u003esb_flags_mask = 0;\n 548:\t\tsecurity_free_mnt_opts(\u0026fc-\u003esecurity);\n 549:\t\tkfree(fc-\u003esource);\n 550:\t\tfc-\u003esource = NULL;\n 551:\t\tfc-\u003eexclusive = false;\n 552:\t\n 553:\t\tfc-\u003epurpose = FS_CONTEXT_FOR_RECONFIGURE;\n 554:\t\tfc-\u003ephase = FS_CONTEXT_AWAITING_RECONF;\n 555:\t}\n 556:\t\n 557:\tint finish_clean_context(struct fs_context *fc)\n 558:\t{\n 559:\t\tint error;\n 560:\t\n 561:\t\tif (fc-\u003ephase != FS_CONTEXT_AWAITING_RECONF)\n 562:\t\t\treturn 0;\n 563:\t\n 564:\t\terror = fc-\u003efs_type-\u003einit_fs_context(fc);\n"
} |
| 11/2 | 2026/10/11 16:17 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31826 output: 33 thoughts: 28 Thoughts: Okay, let's dive into this. Here's my thought process as I approach the code: **Analyzing `fs/super.c` for Modifications** Alright, time to get to work. My immediate focus is on `fs/super.c`. I need to zero in on any recent changes made within that file. I'm going to carefully read around the modified lines, or at least, the most recently changed code. The context around the changes is what matters. Why were these parts of the superblock code touched? What was the rationale? What other parts of the codebase might interact with this updated section? Understanding the *why* behind the change is crucial to determining the implications. Let's see what we can find. |
| 12/2 | 2026/10/11 16:17 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 955,
"LineCount": 50
}Results: {
"Contents": " 955:\t}\n 956:\t\n 957:\tstatic void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,\n 958:\t\t\t\t enum super_iter_flags_t flags)\n 959:\t{\n 960:\t\tstruct super_block *sb, *p = NULL;\n 961:\t\n 962:\t\tspin_lock(\u0026sb_lock);\n 963:\t\n 964:\t\tfor (sb = first_super(flags);\n 965:\t\t !list_entry_is_head(sb, \u0026super_blocks, s_list);\n 966:\t\t sb = next_super(sb, flags)) {\n 967:\t\t\tif (super_flags(sb, SB_DYING))\n 968:\t\t\t\tcontinue;\n 969:\t\n 970:\t\t\tif (!refcount_inc_not_zero(\u0026sb-\u003es_passive))\n 971:\t\t\t\tcontinue;\n 972:\t\n 973:\t\t\tspin_unlock(\u0026sb_lock);\n 974:\t\n 975:\t\t\tif (flags \u0026 SUPER_ITER_UNLOCKED) {\n 976:\t\t\t\tf(sb, arg);\n 977:\t\t\t} else if (super_lock_shared(sb)) {\n 978:\t\t\t\tf(sb, arg);\n 979:\t\t\t\tsuper_unlock_shared(sb);\n 980:\t\t\t}\n 981:\t\n 982:\t\t\tif (p)\n 983:\t\t\t\tput_super(p);\n 984:\t\t\tp = sb;\n 985:\t\t\tspin_lock(\u0026sb_lock);\n 986:\t\t}\n 987:\t\tspin_unlock(\u0026sb_lock);\n 988:\t\tif (p)\n 989:\t\t\tput_super(p);\n 990:\t}\n 991:\t\n 992:\tvoid iterate_supers(void (*f)(struct super_block *, void *), void *arg)\n 993:\t{\n 994:\t\t__iterate_supers(f, arg, 0);\n 995:\t}\n 996:\t\n 997:\t/**\n 998:\t *\titerate_supers_type - call function for superblocks of given type\n 999:\t *\t@type: fs type\n1000:\t *\t@f: function to call\n1001:\t *\t@arg: argument to pass to it\n1002:\t *\n1003:\t *\tScans the superblock list and calls given function, passing it\n1004:\t *\tlocked superblock and given argument.\n"
} |
| 13/2 | 2026/10/11 16:17 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32733 output: 35 thoughts: 21 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Analyzing `super.c` for Context** Okay, time to dive in. I need to take a look at `super.c` specifically around lines 1070-1200. This range typically holds a crucial piece of the puzzle I'm investigating. I suspect it's related to [***insert your field of expertise here, e.g., memory management, inter-process communication, a specific data structure*]**. My initial hunch is [***insert your specific hypothesis, e.g., that there's a potential race condition, an inefficient algorithm, a subtle memory leak*]**. This section is likely where [***elaboration of what you are anticipating to find, e.g., the core logic for object instantiation, the handling of shared memory access, the iterative process of parsing input*]** happens. I'm focusing on this range because [***provide your reasoning, e.g., it aligns with recent error reports, it's where related components interface, it's where the most complex interactions occur*]**. I'm going to look for any deviations from expected behavior, potential bottlenecks, or areas that could benefit from optimization based on the latest knowledge about [***relevant concepts, e.g., lock-free programming, cache coherence, compiler optimizations*]**. The goal is to understand the exact mechanics of what's happening and either confirm or refute my current assumptions. |
| 14/2 | 2026/10/11 16:18 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 1070,
"LineCount": 100
}Results: {
"Contents": "1070:\t\tbool remount_rw = false;\n1071:\t\tbool force = fc-\u003esb_flags \u0026 SB_FORCE;\n1072:\t\n1073:\t\tif (fc-\u003esb_flags_mask \u0026 ~MS_RMT_MASK)\n1074:\t\t\treturn -EINVAL;\n1075:\t\tif (sb-\u003es_writers.frozen != SB_UNFROZEN)\n1076:\t\t\treturn -EBUSY;\n1077:\t\n1078:\t\t/*\n1079:\t\t * Filesystems take fc-\u003esb_flags \u0026 SB_RDONLY as the read-only state the\n1080:\t\t * superblock ends up in. If that isn't being changed, e.g., fspick()\n1081:\t\t * without \"ro\" or \"rw\", it's the current one.\n1082:\t\t */\n1083:\t\tif (!(fc-\u003esb_flags_mask \u0026 SB_RDONLY))\n1084:\t\t\tfc-\u003esb_flags = (fc-\u003esb_flags \u0026 ~SB_RDONLY) | (sb-\u003es_flags \u0026 SB_RDONLY);\n1085:\t\n1086:\t\tretval = security_sb_remount(sb, fc-\u003esecurity);\n1087:\t\tif (retval)\n1088:\t\t\treturn retval;\n1089:\t\n1090:\t\tif (fc-\u003esb_flags_mask \u0026 SB_RDONLY) {\n1091:\t#ifdef CONFIG_BLOCK\n1092:\t\t\tif (!(fc-\u003esb_flags \u0026 SB_RDONLY) \u0026\u0026 sb-\u003es_bdev \u0026\u0026\n1093:\t\t\t bdev_read_only(sb-\u003es_bdev))\n1094:\t\t\t\treturn -EACCES;\n1095:\t#endif\n1096:\t\t\tremount_rw = !(fc-\u003esb_flags \u0026 SB_RDONLY) \u0026\u0026 sb_rdonly(sb);\n1097:\t\t\tremount_ro = (fc-\u003esb_flags \u0026 SB_RDONLY) \u0026\u0026 !sb_rdonly(sb);\n1098:\t\t}\n1099:\t\n1100:\t\tif (remount_ro) {\n1101:\t\t\tif (!hlist_empty(\u0026sb-\u003es_pins)) {\n1102:\t\t\t\tsuper_unlock_excl(sb);\n1103:\t\t\t\tgroup_pin_kill(\u0026sb-\u003es_pins);\n1104:\t\t\t\t__super_lock_excl(sb);\n1105:\t\t\t\tif (!sb-\u003es_root)\n1106:\t\t\t\t\treturn 0;\n1107:\t\t\t\tif (sb-\u003es_writers.frozen != SB_UNFROZEN)\n1108:\t\t\t\t\treturn -EBUSY;\n1109:\t\t\t\tremount_ro = !sb_rdonly(sb);\n1110:\t\t\t}\n1111:\t\t}\n1112:\t\tshrink_dcache_sb(sb);\n1113:\t\n1114:\t\t/* If we are reconfiguring to RDONLY and current sb is read/write,\n1115:\t\t * make sure there are no files open for writing.\n1116:\t\t */\n1117:\t\tif (remount_ro) {\n1118:\t\t\tif (force) {\n1119:\t\t\t\tsb_start_ro_state_change(sb);\n1120:\t\t\t} else {\n1121:\t\t\t\tretval = sb_prepare_remount_readonly(sb);\n1122:\t\t\t\tif (retval)\n1123:\t\t\t\t\treturn retval;\n1124:\t\t\t}\n1125:\t\t} else if (remount_rw) {\n1126:\t\t\t/*\n1127:\t\t\t * Protect filesystem's reconfigure code from writes from\n1128:\t\t\t * userspace until reconfigure finishes.\n1129:\t\t\t */\n1130:\t\t\tsb_start_ro_state_change(sb);\n1131:\t\t}\n1132:\t\n1133:\t\tif (fc-\u003eops-\u003ereconfigure) {\n1134:\t\t\tretval = fc-\u003eops-\u003ereconfigure(fc);\n1135:\t\t\tif (retval) {\n1136:\t\t\t\tif (!force)\n1137:\t\t\t\t\tgoto cancel_readonly;\n1138:\t\t\t\t/* If forced remount, go ahead despite any errors */\n1139:\t\t\t\tWARN(1, \"forced remount of a %s fs returned %i\\n\",\n1140:\t\t\t\t sb-\u003es_type-\u003ename, retval);\n1141:\t\t\t}\n1142:\t\t}\n1143:\t\n1144:\t\tWRITE_ONCE(sb-\u003es_flags, ((sb-\u003es_flags \u0026 ~fc-\u003esb_flags_mask) |\n1145:\t\t\t\t\t (fc-\u003esb_flags \u0026 fc-\u003esb_flags_mask)));\n1146:\t\tsb_end_ro_state_change(sb);\n1147:\t\n1148:\t\t/*\n1149:\t\t * Some filesystems modify their metadata via some other path than the\n1150:\t\t * bdev buffer cache (eg. use a private mapping, or directories in\n1151:\t\t * pagecache, etc). Also file data modifications go via their own\n1152:\t\t * mappings. So If we try to mount readonly then copy the filesystem\n1153:\t\t * from bdev, we could get stale data, so invalidate it to give a best\n1154:\t\t * effort at coherency.\n1155:\t\t */\n1156:\t\tif (remount_ro \u0026\u0026 sb-\u003es_bdev)\n1157:\t\t\tinvalidate_bdev(sb-\u003es_bdev);\n1158:\t\treturn 0;\n1159:\t\n1160:\tcancel_readonly:\n1161:\t\tsb_end_ro_state_change(sb);\n1162:\t\treturn retval;\n1163:\t}\n1164:\t\n1165:\tstatic void do_emergency_remount_callback(struct super_block *sb, void *unused)\n1166:\t{\n1167:\t\tstruct fs_context *fc = NULL;\n1168:\t\n1169:\t\tif (!super_lock_excl(sb))\n"
} |
| 15/2 | 2026/10/11 16:18 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34672 output: 35 thoughts: 21 Thoughts: Here's a summary of my thinking, expressed in the first person: **Diving into the Filesystem Superblock Handling** Okay, so I need to zero in on a specific area within the Linux kernel's filesystem code. I'm thinking I need to investigate the `fs/super.c` file, specifically around line numbers 1480 to 1670. That's a pretty targeted range, which means I've likely got a specific hypothesis or problem in mind related to the superblock operations within the virtual filesystem layer. This suggests I need to analyze how the system interacts with the superblock data, perhaps related to mounting, unmounting, or filesystem integrity checks. I'm likely looking for a specific behavior, a potential bug, or perhaps trying to understand the control flow related to some superblock operation I have in mind. I hope this specific region of the codebase will lead me to the answer that I need. |
| 16/2 | 2026/10/11 16:18 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 1490,
"LineCount": 100
}Results: {
"Contents": "1490:\tEXPORT_SYMBOL(sget_dev);\n1491:\t\n1492:\t#ifdef CONFIG_BLOCK\n1493:\tstatic int fs_super_freeze(struct super_block *sb)\n1494:\t{\n1495:\t\tif (sb-\u003es_op-\u003efreeze_super)\n1496:\t\t\treturn sb-\u003es_op-\u003efreeze_super(sb,\n1497:\t\t\t\t\tFREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n1498:\t\treturn freeze_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n1499:\t}\n1500:\t\n1501:\tstatic int fs_super_thaw(struct super_block *sb)\n1502:\t{\n1503:\t\tint error;\n1504:\t\n1505:\t\tif (sb-\u003es_op-\u003ethaw_super) {\n1506:\t\t\terror = sb-\u003es_op-\u003ethaw_super(sb,\n1507:\t\t\t\t\tFREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n1508:\t\t\t/* -EINVAL means the freeze is gone already. */\n1509:\t\t\tif (error == -EINVAL)\n1510:\t\t\t\treturn 0;\n1511:\t\t\treturn error;\n1512:\t\t}\n1513:\t\n1514:\t\t/* The caller holds an active reference. */\n1515:\t\tif (WARN_ON_ONCE(!super_lock_excl(sb)))\n1516:\t\t\treturn 0;\n1517:\t\n1518:\t\t/* FITHAW or an emergency thaw may have dropped the freeze already. */\n1519:\t\tif (sb-\u003es_writers.frozen != SB_FREEZE_COMPLETE ||\n1520:\t\t !sb-\u003es_writers.freeze_ucount) {\n1521:\t\t\tsuper_unlock_excl(sb);\n1522:\t\t\treturn 0;\n1523:\t\t}\n1524:\t\treturn thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE,\n1525:\t\t\t\t\t NULL);\n1526:\t}\n1527:\t\n1528:\tstatic void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)\n1529:\t{\n1530:\t\tstruct super_dev *sb_dev;\n1531:\t\tdev_t dev = bdev-\u003ebd_dev;\n1532:\t\n1533:\t\tmutex_unlock(\u0026bdev-\u003ebd_holder_lock);\n1534:\t\n1535:\t\tfor (sb_dev = super_dev_first(dev); sb_dev; sb_dev = super_dev_next(sb_dev)) {\n1536:\t\t\tstruct super_block *sb = sb_dev-\u003esd_sb;\n1537:\t\n1538:\t\t\tif (!super_lock_shared(sb))\n1539:\t\t\t\tcontinue;\n1540:\t\t\tif (sb-\u003es_root \u0026\u0026 (sb-\u003es_flags \u0026 SB_ACTIVE)) {\n1541:\t\t\t\tif (!sb-\u003es_op-\u003eremove_bdev ||\n1542:\t\t\t\t sb-\u003es_op-\u003eremove_bdev(sb, bdev)) {\n1543:\t\t\t\t\tif (!surprise)\n1544:\t\t\t\t\t\tsync_filesystem(sb);\n1545:\t\t\t\t\tshrink_dcache_sb(sb);\n1546:\t\t\t\t\tevict_inodes(sb);\n1547:\t\t\t\t\tif (sb-\u003es_op-\u003eshutdown)\n1548:\t\t\t\t\t\tsb-\u003es_op-\u003eshutdown(sb);\n1549:\t\t\t\t}\n1550:\t\t\t}\n1551:\t\t\tsuper_unlock_shared(sb);\n1552:\t\t}\n1553:\t}\n1554:\t\n1555:\tstatic void fs_bdev_sync(struct block_device *bdev)\n1556:\t{\n1557:\t\tstruct super_dev *sb_dev;\n1558:\t\tdev_t dev = bdev-\u003ebd_dev;\n1559:\t\n1560:\t\tmutex_unlock(\u0026bdev-\u003ebd_holder_lock);\n1561:\t\n1562:\t\tfor (sb_dev = super_dev_first(dev); sb_dev; sb_dev = super_dev_next(sb_dev)) {\n1563:\t\t\tstruct super_block *sb = sb_dev-\u003esd_sb;\n1564:\t\n1565:\t\t\tif (!super_lock_shared(sb))\n1566:\t\t\t\tcontinue;\n1567:\t\t\tif (sb-\u003es_root \u0026\u0026 (sb-\u003es_flags \u0026 SB_ACTIVE))\n1568:\t\t\t\tsync_filesystem(sb);\n1569:\t\t\tsuper_unlock_shared(sb);\n1570:\t\t}\n1571:\t}\n1572:\t\n1573:\t/**\n1574:\t * fs_bdev_freeze - freeze every superblock using a block device\n1575:\t * @bdev: block device\n1576:\t *\n1577:\t * Freeze each live superblock using @bdev. A superblock owning several block\n1578:\t * devices is frozen once per device and stays frozen until all are thawed; the\n1579:\t * block layer nests these freezes so the count stays balanced.\n1580:\t *\n1581:\t * Return: 0, or the error from the one superblock on a single-fs device. When\n1582:\t * several superblocks share @bdev a per-superblock failure is swallowed\n1583:\t * (see below). A sync_blockdev() failure is only reported if no\n1584:\t * live superblock uses @bdev.\n1585:\t */\n1586:\tstatic int fs_bdev_freeze(struct block_device *bdev)\n1587:\t{\n1588:\t\tdev_t dev = bdev-\u003ebd_dev;\n1589:\t\tstruct super_dev *sb_dev;\n"
} |
| 17/2 | 2026/10/11 16:18 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36498 output: 34 thoughts: 21 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into the Superblock Implementation** Okay, I need to investigate something related to the file system's superblock, specifically around the area of the code where its management and interaction takes place. Let's see... my initial instinct is to focus on `fs/super.c`. That's the logical place to start digging, given the context. And, I'm going to start my exploration within the function calls somewhere between lines 2050 to 2440 in that source file. It is very likely that the issue I am seeing lies within that call stack or related functions, but this gives me a good place to start my investigation. |
| 18/2 | 2026/10/11 16:18 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 2150,
"LineCount": 90
}Results: {
"Contents": "2150:\t\tWARN_ON_ONCE(hweight32(who \u0026 FREEZE_HOLDERS) \u003e 1);\n2151:\t\n2152:\t\tif ((who \u0026 FREEZE_HOLDER_KERNEL) \u0026\u0026 sb-\u003es_writers.freeze_kcount)\n2153:\t\t\t--sb-\u003es_writers.freeze_kcount;\n2154:\t\tif ((who \u0026 FREEZE_HOLDER_USERSPACE) \u0026\u0026 sb-\u003es_writers.freeze_ucount)\n2155:\t\t\t--sb-\u003es_writers.freeze_ucount;\n2156:\t\treturn sb-\u003es_writers.freeze_kcount + sb-\u003es_writers.freeze_ucount;\n2157:\t}\n2158:\t\n2159:\tstatic inline bool may_freeze(struct super_block *sb, enum freeze_holder who,\n2160:\t\t\t\t const void *freeze_owner)\n2161:\t{\n2162:\t\tlockdep_assert_held(\u0026sb-\u003es_umount);\n2163:\t\n2164:\t\tWARN_ON_ONCE((who \u0026 ~FREEZE_FLAGS));\n2165:\t\tWARN_ON_ONCE(hweight32(who \u0026 FREEZE_HOLDERS) \u003e 1);\n2166:\t\n2167:\t\tif (who \u0026 FREEZE_EXCL) {\n2168:\t\t\tif (WARN_ON_ONCE(!(who \u0026 FREEZE_HOLDER_KERNEL)))\n2169:\t\t\t\treturn false;\n2170:\t\t\tif (WARN_ON_ONCE(who \u0026 ~(FREEZE_EXCL | FREEZE_HOLDER_KERNEL)))\n2171:\t\t\t\treturn false;\n2172:\t\t\tif (WARN_ON_ONCE(!freeze_owner))\n2173:\t\t\t\treturn false;\n2174:\t\t\t/* This freeze already has a specific owner. */\n2175:\t\t\tif (sb-\u003es_writers.freeze_owner)\n2176:\t\t\t\treturn false;\n2177:\t\t\t/*\n2178:\t\t\t * This is already frozen multiple times so we're just\n2179:\t\t\t * going to take a reference count and mark the freeze as\n2180:\t\t\t * being owned by the caller.\n2181:\t\t\t */\n2182:\t\t\tif (sb-\u003es_writers.freeze_kcount + sb-\u003es_writers.freeze_ucount)\n2183:\t\t\t\tsb-\u003es_writers.freeze_owner = freeze_owner;\n2184:\t\t\treturn true;\n2185:\t\t}\n2186:\t\n2187:\t\tif (who \u0026 FREEZE_HOLDER_KERNEL)\n2188:\t\t\treturn (who \u0026 FREEZE_MAY_NEST) ||\n2189:\t\t\t sb-\u003es_writers.freeze_kcount == 0;\n2190:\t\tif (who \u0026 FREEZE_HOLDER_USERSPACE)\n2191:\t\t\treturn (who \u0026 FREEZE_MAY_NEST) ||\n2192:\t\t\t sb-\u003es_writers.freeze_ucount == 0;\n2193:\t\treturn false;\n2194:\t}\n2195:\t\n2196:\tstatic inline bool may_unfreeze(struct super_block *sb, enum freeze_holder who,\n2197:\t\t\t\t\tconst void *freeze_owner)\n2198:\t{\n2199:\t\tlockdep_assert_held(\u0026sb-\u003es_umount);\n2200:\t\n2201:\t\tWARN_ON_ONCE((who \u0026 ~FREEZE_FLAGS));\n2202:\t\tWARN_ON_ONCE(hweight32(who \u0026 FREEZE_HOLDERS) \u003e 1);\n2203:\t\n2204:\t\tif (who \u0026 FREEZE_EXCL) {\n2205:\t\t\tif (WARN_ON_ONCE(!(who \u0026 FREEZE_HOLDER_KERNEL)))\n2206:\t\t\t\treturn false;\n2207:\t\t\tif (WARN_ON_ONCE(who \u0026 ~(FREEZE_EXCL | FREEZE_HOLDER_KERNEL)))\n2208:\t\t\t\treturn false;\n2209:\t\t\tif (WARN_ON_ONCE(!freeze_owner))\n2210:\t\t\t\treturn false;\n2211:\t\t\t/* This isn't exclusively frozen. */\n2212:\t\t\tif (!sb-\u003es_writers.freeze_owner)\n2213:\t\t\t\treturn false;\n2214:\t\t\t/* This isn't exclusively frozen by us. */\n2215:\t\t\tif (sb-\u003es_writers.freeze_owner != freeze_owner)\n2216:\t\t\t\treturn false;\n2217:\t\t\t/* An exclusive freeze always holds a kernel reference. */\n2218:\t\t\tif (WARN_ON_ONCE(sb-\u003es_writers.freeze_kcount == 0))\n2219:\t\t\t\treturn false;\n2220:\t\t\t/*\n2221:\t\t\t * This is still frozen multiple times so we're just\n2222:\t\t\t * going to drop our reference count and undo our\n2223:\t\t\t * exclusive freeze.\n2224:\t\t\t */\n2225:\t\t\tif ((sb-\u003es_writers.freeze_kcount + sb-\u003es_writers.freeze_ucount) \u003e 1)\n2226:\t\t\t\tsb-\u003es_writers.freeze_owner = NULL;\n2227:\t\t\treturn true;\n2228:\t\t}\n2229:\t\n2230:\t\tif (who \u0026 FREEZE_HOLDER_KERNEL) {\n2231:\t\t\t/*\n2232:\t\t\t * Someone's trying to steal the reference belonging to\n2233:\t\t\t * @sb-\u003es_writers.freeze_owner.\n2234:\t\t\t */\n2235:\t\t\tif (sb-\u003es_writers.freeze_kcount == 1 \u0026\u0026\n2236:\t\t\t sb-\u003es_writers.freeze_owner)\n2237:\t\t\t\treturn false;\n2238:\t\t\treturn sb-\u003es_writers.freeze_kcount \u003e 0;\n2239:\t\t}\n"
} |
| 19/2 | 2026/10/11 16:18 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38224 output: 35 thoughts: 18 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into quota.c Line 894** Alright, let's zero in on `fs/quota/quota.c`, specifically around line 894. My initial thought process is to understand the context surrounding that specific line and what it's likely responsible for. Given the location within the quota subsystem, I'm expecting to find code that's either: * Dealing with allocation/deallocation of disk space. * Potentially a critical point within an accounting or enforcement mechanism. * Potentially involved with error checking or reporting related to quota limits. * Possibly a piece of code related to quota modifications. I'm mentally preparing to quickly assess the surrounding code. My primary goals will be: * Identify the function/block of code and its purpose. * Understand the data structures involved, especially if there are any that have critical importance or potential concurrency issues. * Assess how the code handles error conditions or edge cases. * Look for potential vulnerabilities, like race conditions, integer overflows, or off-by-one errors, though I'll be more focused on the specific line and its immediate neighborhood. I may also want to identify any security implications related to that section of code. This will all be about quickly building a mental map of this section of code so I can quickly identify any immediate issues. |
| 20/2 | 2026/10/11 16:19 | tool | read-file |
0mArgs:{
"File": "fs/quota/quota.c",
"FirstLine": 880,
"LineCount": 50
}Results: {
"Contents": " 880:\t\n 881:\t\tif (quotactl_cmd_onoff(cmd)) {\n 882:\t\t\texcl = true;\n 883:\t\t\tthawed = true;\n 884:\t\t} else if (quotactl_cmd_write(cmd)) {\n 885:\t\t\tthawed = true;\n 886:\t\t}\n 887:\t\n 888:\tretry:\n 889:\t\tsb = user_get_super(dev, excl);\n 890:\t\tif (!sb)\n 891:\t\t\treturn ERR_PTR(-ENODEV);\n 892:\t\tif (thawed \u0026\u0026 sb-\u003es_writers.frozen != SB_UNFROZEN) {\n 893:\t\t\tif (excl)\n 894:\t\t\t\tup_write(\u0026sb-\u003es_umount);\n 895:\t\t\telse\n 896:\t\t\t\tup_read(\u0026sb-\u003es_umount);\n 897:\t\t\t/*\n 898:\t\t\t * Wait for sb to unfreeze. A read-only superblock is frozen\n 899:\t\t\t * without taking s_writers so sb_start_write() won't wait.\n 900:\t\t\t */\n 901:\t\t\terror = wait_var_event_killable(\u0026sb-\u003es_writers.frozen,\n 902:\t\t\t\t\tREAD_ONCE(sb-\u003es_writers.frozen) == SB_UNFROZEN);\n 903:\t\t\tput_super(sb);\n 904:\t\t\tif (error)\n 905:\t\t\t\treturn ERR_PTR(error);\n 906:\t\t\tgoto retry;\n 907:\t\t}\n 908:\t\treturn sb;\n 909:\t\n 910:\t#else\n 911:\t\treturn ERR_PTR(-ENODEV);\n 912:\t#endif\n 913:\t}\n 914:\t\n 915:\t/*\n 916:\t * This is the system call interface. This communicates with\n 917:\t * the user-level programs. Currently this only supports diskquota\n 918:\t * calls. Maybe we need to add the process quotas etc. in the future,\n 919:\t * but we probably should use rlimits for that.\n 920:\t */\n 921:\tSYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,\n 922:\t\t\tqid_t, id, void __user *, addr)\n 923:\t{\n 924:\t\tuint cmds, type;\n 925:\t\tstruct super_block *sb = NULL;\n 926:\t\tstruct path path, *pathp = NULL;\n 927:\t\tint ret;\n 928:\t\n 929:\t\tcmds = cmd \u003e\u003e SUBCMDSHIFT;\n"
} |
| 21/2 | 2026/10/11 16:19 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39307 output: 28 thoughts: 39 Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts: **Investigating Quota, FSError, fs_context, and Super Configuration in the Kernel** Alright, I need to figure out the Kconfig options that actually *enable* quota, fserror handling, the `fs_context` structure, and the `super` block for this particular build. I'm pretty sure quota's configuration is going to be tucked away somewhere in the filesystem-specific sections, probably under a name like `quotactl` or something similar, and so I should start by looking there. I'll need to locate the relevant Kconfig file(s), likely somewhere under the `fs/quota/` directory, or perhaps in the overall filesystem configurations. This feels like the right path to track down which flags are set, and how the various components are tied together at compile time. |
| 22/2 | 2026/10/11 16:19 | tool | grepper |
0mArgs:{
"Expression": "config QUOTA\\b",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/quota/Kconfig-5-\nfs/quota/Kconfig:6:config QUOTA\nfs/quota/Kconfig-7-\tbool \"Quota support\"\n"
} |
| 23/2 | 2026/10/11 16:19 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39623 output: 32 thoughts: 14 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the Filesystem Quota Configuration** Alright, before I go any further down this path, let's just confirm my assumptions about the configuration. I need to refresh my memory on the specifics of how quotas are handled at the kernel level. Let's start with `fs/quota/Kconfig`. This is where the real meat of the available options and their dependencies will be. I need to quickly scan through it to make sure I haven't forgotten anything critical or overlooked a potential conflict with other filesystem features. This is the bedrock; best to double-check and then proceed. |
| 24/2 | 2026/10/11 16:19 | tool | read-file |
0mArgs:{
"File": "fs/quota/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t#\n 3:\t# Quota configuration\n 4:\t#\n 5:\t\n 6:\tconfig QUOTA\n 7:\t\tbool \"Quota support\"\n 8:\t\tselect QUOTACTL\n 9:\t\thelp\n 10:\t\t If you say Y here, you will be able to set per user limits for disk\n 11:\t\t usage (also called disk quotas). Currently, it works for the\n 12:\t\t ext2, ext3, ext4, f2fs, jfs and ocfs2 file systems. Note that gfs2\n 13:\t\t and xfs use their own quota system. Ext3 and ext4 also support\n 14:\t\t journaled quotas for which you don't need to run quotacheck(8) after\n 15:\t\t an unclean shutdown. For further details, read the Quota mini-HOWTO,\n 16:\t\t available from \u003chttps://www.tldp.org/docs.html#howto\u003e, or the\n 17:\t\t documentation provided with the quota tools. Probably the quota\n 18:\t\t support is only useful for multi user systems. If unsure, say N.\n 19:\t\n 20:\tconfig QUOTA_NETLINK_INTERFACE\n 21:\t\tbool \"Report quota messages through netlink interface\"\n 22:\t\tdepends on QUOTACTL \u0026\u0026 NET\n 23:\t\thelp\n 24:\t\t If you say Y here, quota warnings (about exceeding softlimit, reaching\n 25:\t\t hardlimit, etc.) will be reported through netlink interface. If unsure,\n 26:\t\t say Y.\n 27:\t\n 28:\tconfig QUOTA_DEBUG\n 29:\t\tbool \"Additional quota sanity checks\"\n 30:\t\tdepends on QUOTA\n 31:\t\tdefault n\n 32:\t\thelp\n 33:\t\t If you say Y here, quota subsystem will perform some additional\n 34:\t\t sanity checks of quota internal structures. If unsure, say N.\n 35:\t\n 36:\t# Generic support for tree structured quota files. Selected when needed.\n 37:\tconfig QUOTA_TREE\n 38:\t\t tristate\n 39:\t\n 40:\tconfig QFMT_V1\n"
} |
| 25/2 | 2026/10/11 16:19 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40390 output: 35 thoughts: 190 Thoughts: **Investigating the Conditional Nature of `fserror.o`** Okay, so I need to figure out if `fserror.o` is built based on any specific configuration options. My initial thought is to check `fs/Makefile` where it was defined. Let me pull up that earlier grep result again... Ah, there it is: `fs/Makefile: obj-y := open.o read_write.o file_table.o super.o ... file_attr.o fserror.o nullfs.o failfs.o`. Looks like it's built unconditionally; `obj-y` means always, doesn't it? Good. And confirming the obvious, `super.o` is also unconditionally built. Further more, `fs_context.o` is unconditionally built. Now, out of habit, let me do some quick cross-checking and see if there are any conditional elements surrounding what `fserror.o` may depend on. In `super.c`, I see that the `fs_bdev_freeze` and `fs_super_thaw` functions are inside an `#ifdef CONFIG_BLOCK` block. This is useful, worth noting. Now looking at quota.c, the `quotactl_block` function is under `#if defined(CONFIG_QUOTA) && defined(CONFIG_BLOCK)`. I should verify line 870 in `fs/quota/quota.c` just to be sure... |
| 26/2 | 2026/10/11 16:19 | tool | read-file |
0mArgs:{
"File": "fs/quota/quota.c",
"FirstLine": 860,
"LineCount": 30
}Results: {
"Contents": " 860:\t}\n 861:\t\n 862:\t/*\n 863:\t * look up a superblock on which quota ops will be performed\n 864:\t * - use the name of a block device to find the superblock thereon\n 865:\t */\n 866:\tstatic struct super_block *quotactl_block(const char __user *special, int cmd)\n 867:\t{\n 868:\t#ifdef CONFIG_BLOCK\n 869:\t\tstruct super_block *sb;\n 870:\t\tCLASS(filename, tmp)(special);\n 871:\t\tbool excl = false, thawed = false;\n 872:\t\tint error;\n 873:\t\tdev_t dev;\n 874:\t\n 875:\t\tif (IS_ERR(tmp))\n 876:\t\t\treturn ERR_CAST(tmp);\n 877:\t\terror = lookup_bdev(tmp-\u003ename, \u0026dev);\n 878:\t\tif (error)\n 879:\t\t\treturn ERR_PTR(error);\n 880:\t\n 881:\t\tif (quotactl_cmd_onoff(cmd)) {\n 882:\t\t\texcl = true;\n 883:\t\t\tthawed = true;\n 884:\t\t} else if (quotactl_cmd_write(cmd)) {\n 885:\t\t\tthawed = true;\n 886:\t\t}\n 887:\t\n 888:\tretry:\n 889:\t\tsb = user_get_super(dev, excl);\n"
} |
| 27/2 | 2026/10/11 16:19 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41333 output: 34 thoughts: 206 Thoughts: Okay, let's break this down.
**Analyzing Configuration Dependencies for File System Operations**
Alright, I need to figure out the right configuration options here. First, I see that the `BLOCK` config is crucial; it's required for `fs_bdev_freeze`, `fs_super_thaw`, and `quotactl_block`. That makes sense. Then, I see `QUOTA` is needed for `fs/quota/quota.c`. Good, so both `BLOCK` and `QUOTA` are solid EnableConfigs to consider.
Now, let me analyze the functions that are touched across the relevant files. I'm seeing:
1. `vfs_clean_context` in `fs/fs_context.c`. This is called during mount, fsmount, fspick, and reconfigure – all standard file system operations.
2. `fserror_pending_dec` and `fserror_alloc_event` in `fs/fserror.c`. These are called via `fserror_report_*` and `fserror_worker` so that is fine. Wait, let me check `fserror.c` itself. Are there any functions with wider scope than just static or call sites?
Let me check `fserror_report` in `fs/fserror.c`.
|
| 28/2 | 2026/10/11 16:22 | tool | read-file |
0mArgs:{
"File": "fs/fserror.c",
"FirstLine": 140,
"LineCount": 60
}Results: {
"Contents": " 140:\t * must point to @sb.\n 141:\t *\n 142:\t * Reporting work is deferred to a workqueue to ensure that -\u003ereport_error is\n 143:\t * called from process context without any locks held. An active reference to\n 144:\t * the inode is maintained until event handling is complete, and unmount will\n 145:\t * wait for queued events to drain.\n 146:\t */\n 147:\tvoid fserror_report(struct super_block *sb, struct inode *inode,\n 148:\t\t\t enum fserror_type type, loff_t pos, u64 len, int error,\n 149:\t\t\t gfp_t gfp)\n 150:\t{\n 151:\t\tstruct fserror_event *event;\n 152:\t\n 153:\t\t/* sb and inode must be from the same filesystem */\n 154:\t\tWARN_ON_ONCE(inode \u0026\u0026 inode-\u003ei_sb != sb);\n 155:\t\n 156:\t\t/* error number must be negative */\n 157:\t\tWARN_ON_ONCE(error \u003e= 0);\n 158:\t\n 159:\t\tevent = fserror_alloc_event(sb, gfp);\n 160:\t\tif (!event)\n 161:\t\t\tgoto lost;\n 162:\t\n 163:\t\tevent-\u003etype = type;\n 164:\t\tevent-\u003epos = pos;\n 165:\t\tevent-\u003elen = len;\n 166:\t\tevent-\u003eerror = error;\n 167:\t\n 168:\t\t/*\n 169:\t\t * Can't iput from non-sleeping context, so grabbing another reference\n 170:\t\t * to the inode must be the last thing before submitting the event.\n 171:\t\t */\n 172:\t\tif (inode) {\n 173:\t\t\tevent-\u003einode = igrab(inode);\n 174:\t\t\tif (!event-\u003einode)\n 175:\t\t\t\tgoto lost_event;\n 176:\t\t}\n 177:\t\n 178:\t\t/*\n 179:\t\t * Use schedule_work here even if we're already in process context so\n 180:\t\t * that fsnotify and super_operations::report_error implementations are\n 181:\t\t * guaranteed to run in process context without any locks held. Since\n 182:\t\t * errors are supposed to be rare, the overhead shouldn't kill us any\n 183:\t\t * more than the failing device will.\n 184:\t\t */\n 185:\t\tschedule_work(\u0026event-\u003ework);\n 186:\t\treturn;\n 187:\t\n 188:\tlost_event:\n 189:\t\tfserror_free_event(event);\n 190:\tlost:\n 191:\t\tif (inode)\n 192:\t\t\tpr_err_ratelimited(\n 193:\t \"%s: lost file I/O error report for ino %llu type %u pos 0x%llx len 0x%llx error %d\",\n 194:\t\t\t sb-\u003es_id, inode-\u003ei_ino, type, pos, len, error);\n 195:\t\telse\n 196:\t\t\tpr_err_ratelimited(\n 197:\t \"%s: lost filesystem error report for type %u error %d\",\n 198:\t\t\t sb-\u003es_id, type, error);\n 199:\t}\n"
} |
| 29/2 | 2026/10/11 16:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42763 output: 30 thoughts: 270 Thoughts: **My Analysis of Superblock Freezing/Thawing Functions** Okay, let's dive into this. I need to understand what's been touched regarding superblocks, specifically in relation to freezing and thawing. First, I'm noting functions modified in `fs/super.c`: `__iterate_supers`, `iterate_supers`, `reconfigure_super`, `do_emergency_remount_callback`, `do_emergency_remount`, `fs_super_thaw`, `fs_bdev_freeze`, `fs_bdev_thaw`, `may_unfreeze`, `freeze_super`, `thaw_super_locked`, and `thaw_super`. The distinction between static and non-static is important, as is the presence of inline functions (`may_unfreeze`). It's crucial to see which of these are directly called and how. Then, there's `quotactl_block` in `fs/quota/quota.c`. Interesting. This is called by `__do_sys_quotactl`, and `SYSCALL_DEFINE4(quotactl)`, which means this is a system call function. I wonder if there's any interaction there. Finally, I'm also seeing `vfs_clean_context` in `fs/fs_context.c`. It's non-static, so it's probably exported. The core of my interest, however, remains with the freezing and thawing logic. The next step is to examine the specific implementations of `freeze_super`, `thaw_super`, `thaw_super_locked`, etc. in `fs/super.c`. I need to trace the data flow, dependencies, and synchronization mechanisms. Understanding their interactions will reveal the implications of these changes. |
| 30/2 | 2026/10/11 16:22 | tool | grepper |
0mArgs:{
"Expression": "thaw_super",
"PathPrefixes": [
"fs/super.c"
]
}Results: {
"Output": "fs/super.c-44-\nfs/super.c:45:static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,\nfs/super.c-46-\t\t\t const void *freeze_owner);\n--\nfs/super.c=1221=static void do_thaw_all_callback(struct super_block *sb, void *unused)\n--\nfs/super.c-1231-\tif (super_lock_excl(sb))\nfs/super.c:1232:\t\tthaw_super_locked(sb, FREEZE_HOLDER_USERSPACE, NULL);\nfs/super.c-1233-\tdeactivate_super(sb);\n--\nfs/super.c=1292=static void filesystems_thaw_callback(struct super_block *sb, void *unused)\n--\nfs/super.c-1299-\nfs/super.c:1300:\tif (sb-\u003es_op-\u003ethaw_super)\nfs/super.c:1301:\t\tsb-\u003es_op-\u003ethaw_super(sb, FREEZE_EXCL | FREEZE_HOLDER_KERNEL,\nfs/super.c-1302-\t\t\t\t filesystems_freeze_ptr);\nfs/super.c-1303-\telse\nfs/super.c:1304:\t\tthaw_super(sb, FREEZE_EXCL | FREEZE_HOLDER_KERNEL,\nfs/super.c-1305-\t\t\t filesystems_freeze_ptr);\n--\nfs/super.c=1501=static int fs_super_thaw(struct super_block *sb)\n--\nfs/super.c-1504-\nfs/super.c:1505:\tif (sb-\u003es_op-\u003ethaw_super) {\nfs/super.c:1506:\t\terror = sb-\u003es_op-\u003ethaw_super(sb,\nfs/super.c-1507-\t\t\t\tFREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n--\nfs/super.c-1523-\t}\nfs/super.c:1524:\treturn thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE,\nfs/super.c-1525-\t\t\t\t NULL);\n--\nfs/super.c=1586=static int fs_bdev_freeze(struct block_device *bdev)\n--\nfs/super.c-1609-\t * of them failed to freeze and swallow the error: rolling the rest back\nfs/super.c:1610:\t * via thaw_super() can fail too, so neither is a clear win. A single\nfs/super.c-1611-\t * filesystem (count == 1) still reports its error.\n--\nfs/super.c=2073=static void sb_wait_write(struct super_block *sb, int level)\n--\nfs/super.c-2079- * We are going to return to userspace and forget about these locks, the\nfs/super.c:2080: * ownership goes to the caller of thaw_super() which does unlock().\nfs/super.c-2081- */\n--\nfs/super.c=2303=int freeze_super(struct super_block *sb, enum freeze_holder who, const void *freeze_owner)\n--\nfs/super.c-2381-\t * For debugging purposes so that fs can warn if it sees write activity\nfs/super.c:2382:\t * when frozen is set to SB_FREEZE_COMPLETE, and for thaw_super().\nfs/super.c-2383-\t */\n--\nfs/super.c=2392=EXPORT_SYMBOL(freeze_super);\n--\nfs/super.c-2399- */\nfs/super.c:2400:static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,\nfs/super.c-2401-\t\t\t const void *freeze_owner)\n--\nfs/super.c-2453-/**\nfs/super.c:2454: * thaw_super -- unlock filesystem\nfs/super.c-2455- * @sb: the super to thaw\n--\nfs/super.c-2470- */\nfs/super.c:2471:int thaw_super(struct super_block *sb, enum freeze_holder who,\nfs/super.c-2472-\t const void *freeze_owner)\n--\nfs/super.c-2477-\t}\nfs/super.c:2478:\treturn thaw_super_locked(sb, who, freeze_owner);\nfs/super.c-2479-}\nfs/super.c:2480:EXPORT_SYMBOL(thaw_super);\nfs/super.c-2481-\n"
} |
| 31/2 | 2026/10/11 16:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44666 output: 28 thoughts: 121 Thoughts: **Investigating the `fs_bdev_freeze` and `fs_bdev_thaw` Callers**
Okay, so I need to understand the usage of `fs_bdev_freeze` and `fs_bdev_thaw`. The code indicates that `fs_bdev_freeze` is registered within `fs_holder_ops`. Specifically, the following block of code shows it is part of a `blk_holder_ops` structure:
```c
static const struct blk_holder_ops fs_holder_ops = {
.sync = fs_bdev_sync,
.freeze = fs_bdev_freeze,
.thaw = fs_bdev_thaw,
};
```
That's good, but not enough. Now I need to find where `fs_holder_ops` itself is *used*. That's where the real investigation begins. I need to determine the context in which these freeze/thaw operations are actually being invoked. Knowing how `fs_holder_ops` is used will give me the crucial insight I need.
|
| 32/2 | 2026/10/11 16:23 | tool | grepper |
0mArgs:{
"Expression": "fs_holder_ops",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/super.c=1641=static int fs_bdev_thaw(struct block_device *bdev)\n--\nfs/super.c-1667-\nfs/super.c:1668:static const struct blk_holder_ops fs_holder_ops = {\nfs/super.c-1669-\t.mark_dead\t\t= fs_bdev_mark_dead,\n--\nfs/super.c=1693=static int fs_bdev_register(struct file *bdev_file, struct super_block *sb)\n--\nfs/super.c-1731- * when the device may be shared by several superblocks of that type)\nfs/super.c:1732: * @sb: superblock to drive fs_holder_ops events for\nfs/super.c-1733- *\nfs/super.c:1734: * Open @dev with \u0026fs_holder_ops and register that @sb uses it, so device\nfs/super.c-1735- * removal/sync/freeze/thaw are propagated to @sb (and any other superblock\n--\nfs/super.c=1740=struct file *fs_bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,\n--\nfs/super.c-1745-\nfs/super.c:1746:\tbdev_file = bdev_file_open_by_dev(dev, mode, holder, \u0026fs_holder_ops);\nfs/super.c-1747-\tif (IS_ERR(bdev_file))\n--\nfs/super.c=1757=EXPORT_SYMBOL_GPL(fs_bdev_file_open_by_dev);\n--\nfs/super.c-1764- * when the device may be shared by several superblocks of that type)\nfs/super.c:1765: * @sb: superblock to drive fs_holder_ops events for\nfs/super.c-1766- *\nfs/super.c:1767: * Open the block device at @path with \u0026fs_holder_ops and register that @sb\nfs/super.c-1768- * uses it, so device removal/sync/freeze/thaw are propagated to @sb (and any\n--\nfs/super.c=1774=struct file *fs_bdev_file_open_by_path(const char *path, blk_mode_t mode,\n--\nfs/super.c-1779-\nfs/super.c:1780:\tbdev_file = bdev_file_open_by_path(path, mode, holder, \u0026fs_holder_ops);\nfs/super.c-1781-\tif (IS_ERR(bdev_file))\n"
} |
| 33/2 | 2026/10/11 16:23 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 45759 output: 37 thoughts: 66 Thoughts: Here's my take on the thought process: **Diving into Block Device Freezing/Thawing** Okay, so I see these `fs_bdev_freeze` and `fs_bdev_thaw` functions, and the context tells me they're called from `bdev_freeze` and `bdev_thaw` within `block/bdev.c`. That's a key piece of information. Since I'm working on understanding the block device lifecycle, knowing the connection between the filesystem-specific freeze/thaw mechanisms and the broader block device management is important. My next step is to trace the call paths to those core `bdev_freeze` calls. I need to understand *why* a block device is being frozen in the first place, and that means figuring out the different entry points to `bdev_freeze`. Understanding its usage will help me to understand the whole process! |
| 34/2 | 2026/10/11 16:24 | tool | grepper |
0mArgs:{
"Expression": "bdev_freeze",
"PathPrefixes": [
"block/",
"drivers/",
"fs/"
]
}Results: {
"Output": "block/bdev.c=284=EXPORT_SYMBOL(sync_blockdev_range);\n--\nblock/bdev.c-286-/**\nblock/bdev.c:287: * bdev_freeze - lock a filesystem and force it into a consistent state\nblock/bdev.c-288- * @bdev:\tblockdevice to lock\n--\nblock/bdev.c-293- * unfreeze process can unfreeze the frozen filesystem actually when multiple\nblock/bdev.c:294: * freeze requests arrive simultaneously. It counts up in bdev_freeze() and\nblock/bdev.c-295- * count down in bdev_thaw(). When it becomes 0, thaw_bdev() will unfreeze\n--\nblock/bdev.c-299- */\nblock/bdev.c:300:int bdev_freeze(struct block_device *bdev)\nblock/bdev.c-301-{\n--\nblock/bdev.c-330-}\nblock/bdev.c:331:EXPORT_SYMBOL(bdev_freeze);\nblock/bdev.c-332-\n--\nblock/bdev.c-336- *\nblock/bdev.c:337: * Unlocks the filesystem and marks it writeable again after bdev_freeze().\nblock/bdev.c-338- *\n--\nblock/bdev.c=373=EXPORT_SYMBOL(bdev_thaw);\n--\nblock/bdev.c-378- *\nblock/bdev.c:379: * Reserve @bdev against bdev_freeze() the way deny_write_access() reserves a\nblock/bdev.c-380- * file against writers. bd_fsfreeze_count is sign-encoded: \u003e 0 counts active\nblock/bdev.c-381- * freezes, \u003c 0 counts deniers, so a deny succeeds only while no freeze is in\nblock/bdev.c:382: * progress. While held, bdev_freeze() returns -EBUSY. Pair with\nblock/bdev.c-383- * bdev_allow_freeze().\n--\ndrivers/md/dm.c=2936=static int lock_fs(struct mapped_device *md)\n--\ndrivers/md/dm.c-2941-\ndrivers/md/dm.c:2942:\tr = bdev_freeze(md-\u003edisk-\u003epart0);\ndrivers/md/dm.c-2943-\tif (!r)\n--\nfs/btrfs/volumes.c=2820=static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)\n--\nfs/btrfs/volumes.c-2891- * Open @path for @sb with freezing denied before the holder claim is published,\nfs/btrfs/volumes.c:2892: * so a racing bdev_freeze() can never reach a claim a device add or replace may\nfs/btrfs/volumes.c-2893- * still abort. The deny is taken on a throwaway non-holder probe open, then the\n--\nfs/exfat/super.c=155=int exfat_force_shutdown(struct super_block *sb, u32 flags)\n--\nfs/exfat/super.c-166-\tcase EXFAT_GOING_DOWN_FULLSYNC:\nfs/exfat/super.c:167:\t\tret = bdev_freeze(sb-\u003es_bdev);\nfs/exfat/super.c-168-\t\tif (ret)\n--\nfs/ext4/ioctl.c=810=int ext4_force_shutdown(struct super_block *sb, u32 flags)\n--\nfs/ext4/ioctl.c-825-\tcase EXT4_GOING_FLAGS_DEFAULT:\nfs/ext4/ioctl.c:826:\t\tret = bdev_freeze(sb-\u003es_bdev);\nfs/ext4/ioctl.c-827-\t\tif (ret)\n--\nfs/f2fs/file.c=2535=int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,\n--\nfs/f2fs/file.c-2542-\tcase F2FS_GOING_DOWN_FULLSYNC:\nfs/f2fs/file.c:2543:\t\tret = bdev_freeze(sb-\u003es_bdev);\nfs/f2fs/file.c-2544-\t\tif (ret)\n--\nfs/ntfs/super.c=1820=int ntfs_force_shutdown(struct super_block *sb, u32 flags)\n--\nfs/ntfs/super.c-1830-\tcase FS_SHUTDOWN_FLAGS_LOGFLUSH:\nfs/ntfs/super.c:1831:\t\tret = bdev_freeze(sb-\u003es_bdev);\nfs/ntfs/super.c-1832-\t\tif (ret)\n--\nfs/ntfs3/file.c=197=static int ntfs_force_shutdown(struct super_block *sb, u32 flags)\n--\nfs/ntfs3/file.c-205-\t/* No additional options yet (flags). */\nfs/ntfs3/file.c:206:\terr = bdev_freeze(sb-\u003es_bdev);\nfs/ntfs3/file.c-207-\tif (err)\n--\nfs/super.c=1555=static void fs_bdev_sync(struct block_device *bdev)\n--\nfs/super.c-1573-/**\nfs/super.c:1574: * fs_bdev_freeze - freeze every superblock using a block device\nfs/super.c-1575- * @bdev: block device\n--\nfs/super.c-1585- */\nfs/super.c:1586:static int fs_bdev_freeze(struct block_device *bdev)\nfs/super.c-1587-{\n--\nfs/super.c-1618-\t/*\nfs/super.c:1619:\t * An error tells bdev_freeze() that nothing is frozen and nobody would\nfs/super.c-1620-\t * ever thaw a superblock frozen above. So only report a failed sync if\n--\nfs/super.c-1632- *\nfs/super.c:1633: * The counterpart to fs_bdev_freeze(): thaw each live superblock using @bdev.\nfs/super.c-1634- * A zero return does not imply a superblock is fully unfrozen; it may have been\n--\nfs/super.c-1637- * Return: 0, or the first error on a single-fs device; a shared device swallows\nfs/super.c:1638: * per-superblock errors, as fs_bdev_freeze() does. A superblock that\nfs/super.c-1639- * lost the freeze already, e.g., to FITHAW, counts as thawed.\n--\nfs/super.c=1641=static int fs_bdev_thaw(struct block_device *bdev)\n--\nfs/super.c-1661-\nfs/super.c:1662:\t/* Shared device: swallow per-superblock errors, like fs_bdev_freeze(). */\nfs/super.c-1663-\tif (error \u0026\u0026 count \u003e 1)\n--\nfs/super.c=1668=static const struct blk_holder_ops fs_holder_ops = {\n--\nfs/super.c-1670-\t.sync\t\t\t= fs_bdev_sync,\nfs/super.c:1671:\t.freeze\t\t\t= fs_bdev_freeze,\nfs/super.c-1672-\t.thaw\t\t\t= fs_bdev_thaw,\n--\nfs/super.c=1693=static int fs_bdev_register(struct file *bdev_file, struct super_block *sb)\n--\nfs/super.c-1714-\nfs/super.c:1715:\t/* Publish the entry before reading the count; pairs with bdev_freeze(). */\nfs/super.c-1716-\tsmp_mb();\n--\nfs/super.c=1831=int setup_bdev_super(struct super_block *sb, int sb_flags,\n--\nfs/super.c-1855-\nfs/super.c:1856:\t/* The sget_fc() entry is already published; pairs with bdev_freeze(). */\nfs/super.c-1857-\tsmp_mb();\n--\nfs/xfs/xfs_fsops.c=451=xfs_fs_goingdown(\n--\nfs/xfs/xfs_fsops.c-456-\tcase XFS_FSOP_GOING_FLAGS_DEFAULT: {\nfs/xfs/xfs_fsops.c:457:\t\tif (!bdev_freeze(mp-\u003em_super-\u003es_bdev)) {\nfs/xfs/xfs_fsops.c-458-\t\t\txfs_force_shutdown(mp, SHUTDOWN_FORCE_UMOUNT);\n"
} |
| 35/2 | 2026/10/11 16:24 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48359 output: 34 thoughts: 729 Thoughts: **Analyzing Filesystem Lifecycle and FocusSymbol Compliance**
Okay, here's what's running through my mind as I dig into this. I'm looking at how this patch interacts with the filesystem lifecycle, specifically focusing on the user-space interaction points. I'm seeing a whole slew of syscalls that are relevant here: `dm suspend`, the various filesystem shutdowns triggered by `ioctl` (ext4, xfs, f2fs, ntfs3, exfat), `bdev_freeze`, `FIFREEZE/FITHAW` ioctls, `quotactl`, and the potentially interesting `remount` and "emergency remount" capabilities (using `sysrq`). There's also `fspick reconfigure` which is a critical point of entry. It is clear that we have a wide range of interfaces from userspace to interact with the underlying filesystem components.
My immediate thought is to determine if all of these points are going to present a problem with FocusSymbols. The guidelines are pretty clear: avoid listing generic functions that are called everywhere, and instead target specific feature logic and entry points. Also I need to remember how the static inline functions are handled, because they may not have their own symbol addresses.
Now, I'm checking each function touched by the patch against the FocusSymbols guidelines. I need to identify the exported, non-inline symbols that are used.
1. `vfs_clean_context` seems fine; it's non-static and exported. It's used in `fs/fs_context.c`.
2. `reconfigure_super` looks good, also non-static and in `fs/super.c`.
3. `fserror_report` or `fserror_unmount` (both in `fs/fserror.c`) are non-static and exported. But I should check the static inline functions, such as `fserror_pending_dec` and `fserror_alloc_event`, which are also in `fs/fserror.c` and are called by `fserror_free_event` / `fserror_worker` / `fserror_report` / `fserror_unmount`
It seems that `fserror_report` and `fserror_unmount` are visible symbols, which helps.
4. Then, there's `fs/quota/quota.c`. Here's where it gets interesting: `quotactl_block` is static, which is called by the `__do_sys_quotactl` or `quotactl` syscall. I have to figure out what the actual syscall entry point is: is it `__do_sys_quotactl` or is it `quotactl_block`? I need to check whether `quotactl_block` might be inlined into `__do_sys_quotactl`. I will investigate it and verify that `__do_sys_quotactl` is exported so it can be used.
Overall, I need to check the symbols in `fs/quota/quota.c` and also `fs/super.c`. I have a feeling there might be a few gotchas here, and a careful analysis is required.
|
| 36/2 | 2026/10/11 16:26 | tool | grepper |
0mArgs:{
"Expression": "SYSCALL_DEFINE.*quotactl",
"PathPrefixes": [
"fs/quota/"
]
}Results: {
"Output": "fs/quota/quota.c=866=static struct super_block *quotactl_block(const char __user *special, int cmd)\n--\nfs/quota/quota.c-920- */\nfs/quota/quota.c:921:SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,\nfs/quota/quota.c-922-\t\tqid_t, id, void __user *, addr)\n--\nfs/quota/quota.c-976-\nfs/quota/quota.c:977:SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,\nfs/quota/quota.c-978-\t\tqid_t, id, void __user *, addr)\n"
} |
| 37/2 | 2026/10/11 16:26 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50009 output: 29 thoughts: 121 Thoughts: Okay, let's break this down. **Investigating Potential Emergency Remount Functionality** Right, I need to understand the relationship between the emergency remount feature and the filesystem's freeze/thaw mechanisms. I'll start by taking a look at `fs/super.c`. My initial focus will be on the functions associated with superblocks since those are key to filesystem state. Specifically, I should be looking at `freeze_super`, `thaw_super`, `thaw_super_locked`, and of course `do_emergency_remount`. Beyond those primary functions, I'll also glance at `fs_super_thaw`, `fs_bdev_freeze`, `reconfigure_super`, and `vfs_clean_context`. They might provide additional context around how freezing, thawing, and remounting are handled at the superblock level or related block device interactions. My aim is to see how these functions interplay, particularly if `do_emergency_remount` is actually triggered by the emergency remount logic itself. That's the primary question I'm trying to answer here. |
| 38/2 | 2026/10/11 16:26 | tool | grepper |
0mArgs:{
"Expression": "do_emergency_remount",
"PathPrefixes": [
"fs/"
]
}Results: {
"Output": "fs/super.c=1065=int reconfigure_super(struct fs_context *fc)\n--\nfs/super.c-1164-\nfs/super.c:1165:static void do_emergency_remount_callback(struct super_block *sb, void *unused)\nfs/super.c-1166-{\n--\nfs/super.c-1190-\nfs/super.c:1191:static void do_emergency_remount(struct work_struct *work)\nfs/super.c-1192-{\nfs/super.c:1193:\t__iterate_supers(do_emergency_remount_callback, NULL,\nfs/super.c-1194-\t\t\t SUPER_ITER_UNLOCKED | SUPER_ITER_REVERSE);\n--\nfs/super.c=1199=void emergency_remount(void)\n--\nfs/super.c-1204-\tif (work) {\nfs/super.c:1205:\t\tINIT_WORK(work, do_emergency_remount);\nfs/super.c-1206-\t\tschedule_work(work);\n"
} |
| 39/2 | 2026/10/11 16:26 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50689 output: 275 thoughts: 2408 Thoughts: **Analysis of Potential Fuzzing Targets in the VFS Layer** Alright, let's break this down. My goal is to identify and characterize areas in the kernel that are ripe for fuzzing. I'm focusing on the VFS layer, specifically areas touched by a recent patch that seems to be making significant changes. My initial thought is that `emergency_remount` (and, consequently, `do_emergency_remount`), along with `freeze_super`, `thaw_super`, `reconfigure_super`, and related functions, are of interest. I also need to consider related functions like `vfs_clean_context`, the error reporting functions (`fserror_report`, `fserror_unmount`, and the static inline versions), and anything related to quota management (`quotactl_block`, and associated syscalls). My next thought is that I need to be precise about these symbols. Are they static, inline, or extern? Where are they defined, and how might the compiler optimize them? For example, while `quotactl_block` is static, it could be inlined, impacting coverage analysis. I have to be aware of how syzkaller and other coverage tools might interact with these symbols. I then think about the modified code paths: The function `quotactl_block` could present an interesting starting point, given the changes in locking. Similarly, `freeze_super` and `thaw_super`, and related functions `fs_bdev_freeze` and `fs_super_thaw` seem very important, since they are being changed directly. I'll need to check the callers of these and similar functions to make sure I am comprehensive. I then focus on creating a refined list of functions to consider. So after analyzing a list of functions, the next logical move is to confirm that they are truly key feature-specific functions: `reconfigure_super`, `freeze_super`, `thaw_super`, `vfs_clean_context`, `quotactl_block`, `fs_bdev_freeze`, `fs_super_thaw`, `do_emergency_remount`, `fserror_report`. After reviewing all the changes, I add to that list `fserror_unmount`. A critical aspect of this analysis is determining if these code paths are actually *reachable* in a typical setup. I'm certain that the filesystem mount/unmount/remount operations, `quotactl`, and the block device freeze/thaw mechanisms are standard parts of a standard QEMU environment. This implies that these modifications can be tested under fuzzing. My next step is to examine what configurations are necessary to reach the code. `BLOCK` and `QUOTA` are the primary kernel configuration flags needed to compile and reach the modified code. Then I assess the fuzzing "worthiness" of these changes. The patch modifies core VFS locking, reference counting, synchronization barriers, remount logic, and freeze/thaw state machines. These are fundamental changes. Specifically, I see changes that touch memory barriers and concurrency issues. This, along with the fact that these are user-accessible via system calls, tells me this is prime fuzzing territory. Finally, I’m confirming the symbols one last time. All 10 symbols are confirmed present and directly related to the changed code. So I conclude with a concise summary: This patch introduces modifications in core VFS code across multiple files, touching superblock reconfiguration, filesystem freezing, block-device freeze/thaw synchronization, emergency remount locking, quota control, and memory ordering in error reporting. All the modified code paths are directly accessible from userspace. Concurrency and barrier changes can introduce race conditions, making this very suitable for fuzzing. The result is `WorthFuzzing=true`. |
| 40/2 | 2026/10/11 16:28 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BLOCK",
"QUOTA"
],
"FocusSymbols": [
"reconfigure_super",
"freeze_super",
"thaw_super",
"vfs_clean_context",
"quotactl_block",
"fs_bdev_freeze",
"fs_super_thaw",
"do_emergency_remount",
"fserror_report",
"fserror_unmount"
],
"Reasoning": "The patch series modifies core VFS logic across multiple areas: superblock reconfiguration (reconfigure_super, vfs_clean_context), filesystem and block-device freeze/thaw state handling (freeze_super, thaw_super, fs_bdev_freeze, fs_super_thaw), quota syscall synchronization on frozen filesystems (quotactl_block), emergency remount refcounting/locking (do_emergency_remount), and memory barriers / initialization checks in filesystem error reporting (fserror_pending_dec, fserror_alloc_event). These paths are reachable from userspace in standard virtualized environments via mount, fsopen/fspick/fsconfig, quotactl, and freeze ioctls, making them prime targets for fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BLOCK",
"QUOTA"
],
"FocusSymbols": [
"reconfigure_super",
"freeze_super",
"thaw_super",
"vfs_clean_context",
"quotactl_block",
"fs_bdev_freeze",
"fs_super_thaw",
"do_emergency_remount",
"fserror_report",
"fserror_unmount"
],
"Reasoning": "The patch series modifies core VFS logic across multiple areas: superblock reconfiguration (reconfigure_super, vfs_clean_context), filesystem and block-device freeze/thaw state handling (freeze_super, thaw_super, fs_bdev_freeze, fs_super_thaw), quota syscall synchronization on frozen filesystems (quotactl_block), emergency remount refcounting/locking (do_emergency_remount), and memory barriers / initialization checks in filesystem error reporting (fserror_pending_dec, fserror_alloc_event). These paths are reachable from userspace in standard virtualized environments via mount, fsopen/fspick/fsconfig, quotactl, and freeze ioctls, making them prime targets for fuzzing.",
"WorthFuzzing": true
} |
| 41/1 | 2026/10/11 16:28 | action | If |
8mArgs:{
"WorthFuzzing": true
}Results: null |
| 42/2 | 2026/10/11 16:28 | agent | kmsan-evaluator |
8mModel:core Args: null Results: {
"KMSANReasoning": "The patch series addresses VFS-level filesystem freezing/thawing synchronization, emergency remount locking and lifetime semantics, memory barriers before wait_var wakeups, fserror event allocation checks against SB_BORN, and preserving SB_RDONLY during fs_context reconfiguration.\n\nNone of the changes introduce or modify any kernel-to-user memory copy operations, uninitialized stack/heap allocations, or conditional branches on uninitialized memory. All variables and fields modified are scalar flags, reference counts, or waitqueue primitives. Any potential issues introduced by these changes relate to synchronization, reference counting, or locking, which are well-covered by LOCKDEP and KASAN. Therefore, 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 49cd28e4b9cb8c0a01dbd19cfdcd9b28bf17b398
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Oct 11 16:15:06 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/fs_context.c b/fs/fs_context.c
index a50584df97bea..ba99e673458a8 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -544,6 +544,7 @@ void vfs_clean_context(struct fs_context *fc)
fc->fs_private = NULL;
fc->s_fs_info = NULL;
fc->sb_flags = 0;
+ fc->sb_flags_mask = 0;
security_free_mnt_opts(&fc->security);
kfree(fc->source);
fc->source = NULL;
diff --git a/fs/fserror.c b/fs/fserror.c
index 1e4d11fd9562f..90ce04d585149 100644
--- a/fs/fserror.c
+++ b/fs/fserror.c
@@ -35,8 +35,15 @@ void fserror_unmount(struct super_block *sb)
static inline void fserror_pending_dec(struct super_block *sb)
{
- if (refcount_dec_and_test(&sb->s_pending_errors))
+ if (refcount_dec_and_test(&sb->s_pending_errors)) {
+ /*
+ * refcount_dec_and_test() isn't fully ordered but wake_up_var()
+ * needs a full barrier between the store and its waitqueue check.
+ * Pairs with the barrier in prepare_to_wait_event().
+ */
+ smp_mb();
wake_up_var(&sb->s_pending_errors);
+ }
}
static inline void fserror_free_event(struct fserror_event *event)
@@ -89,6 +96,13 @@ static inline struct fserror_event *fserror_alloc_event(struct super_block *sb,
return NULL;
if (!(sb->s_flags & SB_ACTIVE))
goto out_pending;
+ /*
+ * xfs and f2fs set SB_ACTIVE while filling the superblock. Nobody can
+ * listen before the superblock is born and if the mount fails nothing
+ * waits for the event.
+ */
+ if (!(sb->s_flags & SB_BORN))
+ goto out_pending;
event = mempool_alloc(&fserror_events_pool, gfp_flags);
if (!event)
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 33bacd7075800..d55ef08de833e 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -894,11 +894,15 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)
up_write(&sb->s_umount);
else
up_read(&sb->s_umount);
- /* Wait for sb to unfreeze */
- sb_start_write(sb);
- sb_end_write(sb);
+ /*
+ * Wait for sb to unfreeze. A read-only superblock is frozen
+ * without taking s_writers so sb_start_write() won't wait.
+ */
+ error = wait_var_event_killable(&sb->s_writers.frozen,
+ READ_ONCE(sb->s_writers.frozen) == SB_UNFROZEN);
put_super(sb);
- cond_resched();
+ if (error)
+ return ERR_PTR(error);
goto retry;
}
return sb;
diff --git a/fs/super.c b/fs/super.c
index 1d5ccf540a9bf..657958a1d1352 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -935,9 +935,8 @@ void drop_super_exclusive(struct super_block *sb)
}
enum super_iter_flags_t {
- SUPER_ITER_EXCL = (1U << 0),
- SUPER_ITER_UNLOCKED = (1U << 1),
- SUPER_ITER_REVERSE = (1U << 2),
+ SUPER_ITER_UNLOCKED = (1U << 0),
+ SUPER_ITER_REVERSE = (1U << 1),
};
static inline struct super_block *first_super(enum super_iter_flags_t flags)
@@ -959,7 +958,6 @@ static void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,
enum super_iter_flags_t flags)
{
struct super_block *sb, *p = NULL;
- bool excl = flags & SUPER_ITER_EXCL;
spin_lock(&sb_lock);
@@ -976,9 +974,9 @@ static void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,
if (flags & SUPER_ITER_UNLOCKED) {
f(sb, arg);
- } else if (super_lock(sb, excl)) {
+ } else if (super_lock_shared(sb)) {
f(sb, arg);
- super_unlock(sb, excl);
+ super_unlock_shared(sb);
}
if (p)
@@ -1077,6 +1075,14 @@ int reconfigure_super(struct fs_context *fc)
if (sb->s_writers.frozen != SB_UNFROZEN)
return -EBUSY;
+ /*
+ * Filesystems take fc->sb_flags & SB_RDONLY as the read-only state the
+ * superblock ends up in. If that isn't being changed, e.g., fspick()
+ * without "ro" or "rw", it's the current one.
+ */
+ if (!(fc->sb_flags_mask & SB_RDONLY))
+ fc->sb_flags = (fc->sb_flags & ~SB_RDONLY) | (sb->s_flags & SB_RDONLY);
+
retval = security_sb_remount(sb, fc->security);
if (retval)
return retval;
@@ -1158,23 +1164,34 @@ int reconfigure_super(struct fs_context *fc)
static void do_emergency_remount_callback(struct super_block *sb, void *unused)
{
- if (sb->s_bdev && !sb_rdonly(sb)) {
- struct fs_context *fc;
+ struct fs_context *fc = NULL;
+
+ if (!super_lock_excl(sb))
+ return;
+ /* Make sure no reference put under s_umount is the last one. */
+ atomic_inc(&sb->s_active);
+ if (sb->s_bdev && !sb_rdonly(sb)) {
fc = fs_context_for_reconfigure(sb->s_root,
SB_RDONLY | SB_FORCE, SB_RDONLY);
- if (!IS_ERR(fc)) {
- if (parse_monolithic_mount_data(fc, NULL) == 0)
- (void)reconfigure_super(fc);
- put_fs_context(fc);
- }
+ if (!IS_ERR(fc) && parse_monolithic_mount_data(fc, NULL) == 0)
+ (void)reconfigure_super(fc);
}
+ super_unlock_excl(sb);
+
+ /*
+ * Our active reference may be the last one by now, so only drop it
+ * after s_umount has been released.
+ */
+ if (!IS_ERR_OR_NULL(fc))
+ put_fs_context(fc);
+ deactivate_super(sb);
}
static void do_emergency_remount(struct work_struct *work)
{
__iterate_supers(do_emergency_remount_callback, NULL,
- SUPER_ITER_EXCL | SUPER_ITER_REVERSE);
+ SUPER_ITER_UNLOCKED | SUPER_ITER_REVERSE);
kfree(work);
printk("Emergency Remount complete\n");
}
@@ -1483,10 +1500,29 @@ static int fs_super_freeze(struct super_block *sb)
static int fs_super_thaw(struct super_block *sb)
{
- if (sb->s_op->thaw_super)
- return sb->s_op->thaw_super(sb,
+ int error;
+
+ if (sb->s_op->thaw_super) {
+ error = sb->s_op->thaw_super(sb,
FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);
- return thaw_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);
+ /* -EINVAL means the freeze is gone already. */
+ if (error == -EINVAL)
+ return 0;
+ return error;
+ }
+
+ /* The caller holds an active reference. */
+ if (WARN_ON_ONCE(!super_lock_excl(sb)))
+ return 0;
+
+ /* FITHAW or an emergency thaw may have dropped the freeze already. */
+ if (sb->s_writers.frozen != SB_FREEZE_COMPLETE ||
+ !sb->s_writers.freeze_ucount) {
+ super_unlock_excl(sb);
+ return 0;
+ }
+ return thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE,
+ NULL);
}
static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)
@@ -1544,7 +1580,8 @@ static void fs_bdev_sync(struct block_device *bdev)
*
* Return: 0, or the error from the one superblock on a single-fs device. When
* several superblocks share @bdev a per-superblock failure is swallowed
- * (see below), but a sync_blockdev() failure is always reported.
+ * (see below). A sync_blockdev() failure is only reported if no
+ * live superblock uses @bdev.
*/
static int fs_bdev_freeze(struct block_device *bdev)
{
@@ -1575,8 +1612,17 @@ static int fs_bdev_freeze(struct block_device *bdev)
*/
if (error && count > 1)
error = 0;
- if (!error)
- error = sync_blockdev(bdev);
+ if (error)
+ return error;
+
+ /*
+ * An error tells bdev_freeze() that nothing is frozen and nobody would
+ * ever thaw a superblock frozen above. So only report a failed sync if
+ * no superblock uses the device.
+ */
+ error = sync_blockdev(bdev);
+ if (count)
+ error = 0;
return error;
}
@@ -1589,7 +1635,8 @@ static int fs_bdev_freeze(struct block_device *bdev)
* frozen more than once (by the kernel or via another device).
*
* Return: 0, or the first error on a single-fs device; a shared device swallows
- * per-superblock errors, as fs_bdev_freeze() does.
+ * per-superblock errors, as fs_bdev_freeze() does. A superblock that
+ * lost the freeze already, e.g., to FITHAW, counts as thawed.
*/
static int fs_bdev_thaw(struct block_device *bdev)
{
@@ -2057,6 +2104,13 @@ static void sb_freeze_unlock(struct super_block *sb, int level)
percpu_up_write(sb->s_writers.rw_sem + level);
}
+static inline void sb_freeze_wake(struct super_block *sb)
+{
+ /* wake_up_var() needs a full barrier after storing s_writers.frozen. */
+ smp_mb();
+ wake_up_var(&sb->s_writers.frozen);
+}
+
static int wait_for_partially_frozen(struct super_block *sb)
{
int ret = 0;
@@ -2154,14 +2208,15 @@ static inline bool may_unfreeze(struct super_block *sb, enum freeze_holder who,
return false;
if (WARN_ON_ONCE(!freeze_owner))
return false;
- if (WARN_ON_ONCE(sb->s_writers.freeze_kcount == 0))
- return false;
/* This isn't exclusively frozen. */
if (!sb->s_writers.freeze_owner)
return false;
/* This isn't exclusively frozen by us. */
if (sb->s_writers.freeze_owner != freeze_owner)
return false;
+ /* An exclusive freeze always holds a kernel reference. */
+ if (WARN_ON_ONCE(sb->s_writers.freeze_kcount == 0))
+ return false;
/*
* This is still frozen multiple times so we're just
* going to drop our reference count and undo our
@@ -2281,7 +2336,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
WARN_ON_ONCE(freeze_inc(sb, who) > 1);
sb->s_writers.freeze_owner = freeze_owner;
sb->s_writers.frozen = SB_FREEZE_COMPLETE;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
super_unlock_excl(sb);
return 0;
}
@@ -2301,7 +2356,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
if (ret) {
sb->s_writers.frozen = SB_UNFROZEN;
sb_freeze_unlock(sb, SB_FREEZE_PAGEFAULT);
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
deactivate_locked_super(sb);
return ret;
}
@@ -2317,7 +2372,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
"VFS:Filesystem freeze failed\n");
sb->s_writers.frozen = SB_UNFROZEN;
sb_freeze_unlock(sb, SB_FREEZE_FS);
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
deactivate_locked_super(sb);
return ret;
}
@@ -2329,7 +2384,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who, const void *fre
WARN_ON_ONCE(freeze_inc(sb, who) > 1);
sb->s_writers.freeze_owner = freeze_owner;
sb->s_writers.frozen = SB_FREEZE_COMPLETE;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
lockdep_sb_freeze_release(sb);
super_unlock_excl(sb);
return 0;
@@ -2366,7 +2421,7 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
if (sb_rdonly(sb)) {
sb->s_writers.frozen = SB_UNFROZEN;
sb->s_writers.freeze_owner = NULL;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
goto out_deactivate;
}
@@ -2384,7 +2439,7 @@ static int thaw_super_locked(struct super_block *sb, enum freeze_holder who,
sb->s_writers.frozen = SB_UNFROZEN;
sb->s_writers.freeze_owner = NULL;
- wake_up_var(&sb->s_writers.frozen);
+ sb_freeze_wake(sb);
sb_freeze_unlock(sb, SB_FREEZE_FS);
out_deactivate:
deactivate_locked_super(sb);
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index bc4fdb6f53375..a60778626c8c9 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -38,6 +38,7 @@ TARGETS += filesystems/epoll
TARGETS += filesystems/eventfd
TARGETS += filesystems/failfs
TARGETS += filesystems/fat
+TARGETS += filesystems/freeze
TARGETS += filesystems/openat2
TARGETS += filesystems/open_tree_ns
TARGETS += filesystems/overlayfs
diff --git a/tools/testing/selftests/filesystems/.gitignore b/tools/testing/selftests/filesystems/.gitignore
index 62f7b1c466497..fa2b6f0bb6a4f 100644
--- a/tools/testing/selftests/filesystems/.gitignore
+++ b/tools/testing/selftests/filesystems/.gitignore
@@ -8,3 +8,4 @@ kernfs_test
idmapped_tmpfile
ustat_test
rw_hint_test
+fspick_reconfigure_test
diff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile
index 93e2cc9123b04..ef1b4f6a0f826 100644
--- a/tools/testing/selftests/filesystems/Makefile
+++ b/tools/testing/selftests/filesystems/Makefile
@@ -2,9 +2,11 @@
CFLAGS += $(KHDR_INCLUDES)
TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test
-TEST_GEN_PROGS += idmapped_tmpfile
+TEST_GEN_PROGS += idmapped_tmpfile fspick_reconfigure_test
TEST_GEN_PROGS_EXTENDED := dnotify_test
+LOCAL_HDRS += wrappers.h freeze/loop_util.h
+
include ../lib.mk
$(OUTPUT)/idmapped_tmpfile: LDLIBS += -lcap
diff --git a/tools/testing/selftests/filesystems/freeze/.gitignore b/tools/testing/selftests/filesystems/freeze/.gitignore
new file mode 100644
index 0000000000000..28f1fe73f19b7
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/.gitignore
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+quotactl_test
+bdev_freeze_test
+bdev_thaw_test
diff --git a/tools/testing/selftests/filesystems/freeze/Makefile b/tools/testing/selftests/filesystems/freeze/Makefile
new file mode 100644
index 0000000000000..acd246e1b14bb
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
+LOCAL_HDRS += loop_util.h
+
+TEST_GEN_PROGS := quotactl_test
+TEST_GEN_PROGS += bdev_freeze_test bdev_thaw_test
+
+include ../../lib.mk
diff --git a/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c b/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c
new file mode 100644
index 0000000000000..0a13111a85d35
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/bdev_freeze_test.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * A failed block device freeze must not leave the filesystem frozen.
+ *
+ * bdev_freeze() takes an error from the holder's ->freeze() to mean that
+ * nothing was frozen and drops bd_fsfreeze_count, so its callers (dm's
+ * lock_fs(), the filesystem shutdown ioctls) never call bdev_thaw(). Leave a
+ * writeback error on the block device's page cache and freeze the device
+ * through EXT4_IOC_SHUTDOWN: either the freeze succeeds, or the superblock
+ * must not stay frozen. The filesystem is mounted read-only so that
+ * freeze_super() doesn't sync the device and consume the error itself.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "loop_util.h"
+
+#define IMG_SIZE (64 << 20)
+
+#ifndef EXT4_IOC_SHUTDOWN
+#define EXT4_IOC_SHUTDOWN _IOR('X', 125, uint32_t)
+#endif
+#ifndef EXT4_GOING_FLAGS_DEFAULT
+#define EXT4_GOING_FLAGS_DEFAULT 0x0
+#endif
+
+#define FMR "/sys/kernel/debug/fail_make_request"
+#define FMR_VAL_LEN 32
+
+/* Global fail_make_request settings that fail exactly the next bio. */
+static const struct {
+ const char *name;
+ const char *val;
+} fmr_attrs[] = {
+ { "probability", "100" },
+ { "interval", "1" },
+ { "times", "1" },
+ { "verbose", "0" },
+};
+
+FIXTURE(bdev_freeze) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char dev[32];
+ char fail[64];
+ /* the settings the test found, restored in the teardown */
+ char fmr[ARRAY_SIZE(fmr_attrs)][FMR_VAL_LEN];
+ int nr_fmr;
+ int loop;
+ int mntfd;
+};
+
+static int read_file(const char *path, char *buf, size_t size)
+{
+ ssize_t n;
+ int fd;
+
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+ n = read(fd, buf, size - 1);
+ close(fd);
+ if (n <= 0)
+ return -1;
+ buf[n] = '\0';
+ return 0;
+}
+
+static int write_file(const char *path, const char *val)
+{
+ int fd, ret;
+
+ fd = open(path, O_WRONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+ ret = write(fd, val, strlen(val)) == (ssize_t)strlen(val) ? 0 : -1;
+ close(fd);
+ return ret;
+}
+
+static void bdev_freeze_cleanup(FIXTURE_DATA(bdev_freeze) *self)
+{
+ char path[128];
+
+ if (self->fail[0])
+ write_file(self->fail, "0");
+ for (int i = 0; i < self->nr_fmr; i++) {
+ snprintf(path, sizeof(path), FMR "/%s", fmr_attrs[i].name);
+ write_file(path, self->fmr[i]);
+ }
+ if (self->mntfd >= 0) {
+ /* don't leave a frozen superblock behind if the test failed */
+ ioctl(self->mntfd, FITHAW, 0);
+ close(self->mntfd);
+ umount2(self->mnt, MNT_DETACH);
+ }
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->img);
+ rmdir(self->mnt);
+ rmdir(self->dir);
+}
+
+FIXTURE_SETUP(bdev_freeze)
+{
+ char cmd[160];
+ int fd, ret;
+
+ self->loop = -1;
+ self->mntfd = -1;
+ self->nr_fmr = 0;
+ self->fail[0] = '\0';
+
+ 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");
+ if (access(FMR "/probability", W_OK))
+ SKIP(return, "test requires CONFIG_FAIL_MAKE_REQUEST and debugfs");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/bdev_freeze.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ /* The harness doesn't run the teardown when the setup fails. */
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0)
+ bdev_freeze_cleanup(self);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0)
+ bdev_freeze_cleanup(self);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)
+ bdev_freeze_cleanup(self);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ bdev_freeze_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (loop_missing(self->loop)) {
+ bdev_freeze_cleanup(self);
+ SKIP(return, "test requires loop devices");
+ }
+ ASSERT_GE(self->loop, 0)
+ bdev_freeze_cleanup(self);
+ snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", self->loop);
+ snprintf(self->fail, sizeof(self->fail), "/sys/block/loop%d/make-it-fail", self->loop);
+
+ if (mount(self->dev, self->mnt, "ext4", MS_RDONLY, NULL)) {
+ if (errno == ENODEV) {
+ bdev_freeze_cleanup(self);
+ SKIP(return, "kernel lacks ext4");
+ }
+ ASSERT_EQ(errno, 0)
+ bdev_freeze_cleanup(self);
+ }
+ self->mntfd = open(self->mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(self->mntfd, 0)
+ bdev_freeze_cleanup(self);
+}
+
+FIXTURE_TEARDOWN(bdev_freeze)
+{
+ bdev_freeze_cleanup(self);
+}
+
+TEST_F(bdev_freeze, sync_error_does_not_strand_freeze)
+{
+ uint32_t flags = EXT4_GOING_FLAGS_DEFAULT;
+ off_t off = IMG_SIZE - 4096;
+ char buf[4096], path[128];
+ int fd, ret, err;
+
+ /* Without bdev_allow_write_mounted the mount blocks writers. */
+ fd = open(self->dev, O_RDWR | O_CLOEXEC);
+ if (fd < 0 && errno == EBUSY)
+ SKIP(return, "writes to mounted block devices are blocked");
+ ASSERT_GE(fd, 0);
+
+ for (int i = 0; i < ARRAY_SIZE(fmr_attrs); i++) {
+ snprintf(path, sizeof(path), FMR "/%s", fmr_attrs[i].name);
+ ASSERT_EQ(read_file(path, self->fmr[i], sizeof(self->fmr[i])), 0);
+ self->nr_fmr = i + 1;
+ ASSERT_EQ(write_file(path, fmr_attrs[i].val), 0);
+ }
+
+ memset(buf, 0x5a, sizeof(buf));
+ ASSERT_EQ(pwrite(fd, buf, sizeof(buf), off), sizeof(buf));
+
+ /*
+ * Start writeback of that page and let it fail. Don't wait for it
+ * with an error check: that would consume AS_EIO on the mapping.
+ */
+ ASSERT_EQ(write_file(self->fail, "1"), 0);
+ ASSERT_EQ(sync_file_range(fd, off, sizeof(buf), SYNC_FILE_RANGE_WRITE), 0);
+ ASSERT_EQ(write_file(self->fail, "0"), 0);
+ /* The mount keeps the device open, so this close doesn't flush. */
+ close(fd);
+
+ /* bdev_freeze() -> fs_bdev_freeze() -> sync_blockdev() fails */
+ ret = ioctl(self->mntfd, EXT4_IOC_SHUTDOWN, &flags);
+ err = errno;
+ TH_LOG("EXT4_IOC_SHUTDOWN: %d (%s)", ret, ret ? strerror(err) : "ok");
+
+ /* FITHAW only succeeds on a frozen superblock. */
+ ret = ioctl(self->mntfd, FITHAW, 0);
+ ASSERT_NE(ret, 0)
+ TH_LOG("superblock left frozen after the block device freeze failed");
+ ASSERT_EQ(errno, EINVAL);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c b/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c
new file mode 100644
index 0000000000000..9bb21293093c6
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/bdev_thaw_test.c
@@ -0,0 +1,251 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Thawing a superblock behind the block layer's back.
+ *
+ * A device-mapper suspend freezes the filesystem on the device through
+ * bdev_freeze() with the same userspace holder FIFREEZE uses, so FITHAW can
+ * drop that freeze while the device is still suspended. The resume then
+ * finds nothing left to thaw. Check that it still thaws the device so that
+ * it can be mounted again afterwards. The filesystem is mounted read-only
+ * so the freeze and the thaw don't need to write to the suspended device.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/dm-ioctl.h>
+#include <linux/fs.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "loop_util.h"
+
+#define IMG_SIZE (64 << 20)
+
+FIXTURE(bdev_thaw) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char node[96];
+ char name[32];
+ int loop;
+ int mntfd;
+ bool tmpfs;
+ bool dm;
+ bool suspended;
+ bool mounted;
+};
+
+static int dm_ioctl(unsigned long cmd, const char *name, uint32_t flags, dev_t *dev)
+{
+ struct dm_ioctl dmi = {
+ .version = { DM_VERSION_MAJOR, 0, 0 },
+ .data_size = sizeof(dmi),
+ .data_start = sizeof(dmi),
+ .flags = flags,
+ };
+ int fd, ret = 0;
+
+ strncpy(dmi.name, name, sizeof(dmi.name) - 1);
+ fd = open("/dev/mapper/control", O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ if (ioctl(fd, cmd, &dmi))
+ ret = -errno;
+ else if (dev)
+ *dev = makedev((dmi.dev >> 8) & 0xfff,
+ (dmi.dev & 0xff) | ((dmi.dev >> 12) & 0xfff00));
+ close(fd);
+ return ret;
+}
+
+/* Remove @name now, or on its last close if udev still has it open. */
+static int dm_remove(const char *name)
+{
+ return dm_ioctl(DM_DEV_REMOVE, name, DM_DEFERRED_REMOVE, NULL);
+}
+
+/* Create @name as a linear mapping of all of @backing and make it live. */
+static int dm_create_linear(const char *name, dev_t backing, uint64_t sectors,
+ dev_t *dev)
+{
+ struct {
+ struct dm_ioctl dmi;
+ struct dm_target_spec spec;
+ char params[64];
+ } __attribute__((aligned(8))) t = {};
+ int fd, ret;
+
+ ret = dm_ioctl(DM_DEV_CREATE, name, 0, NULL);
+ if (ret)
+ return ret;
+
+ t.dmi.version[0] = DM_VERSION_MAJOR;
+ t.dmi.data_size = sizeof(t);
+ t.dmi.data_start = sizeof(t.dmi);
+ t.dmi.target_count = 1;
+ strncpy(t.dmi.name, name, sizeof(t.dmi.name) - 1);
+ t.spec.length = sectors;
+ strcpy(t.spec.target_type, "linear");
+ snprintf(t.params, sizeof(t.params), "%u:%u 0", major(backing), minor(backing));
+
+ fd = open("/dev/mapper/control", O_RDWR | O_CLOEXEC);
+ if (fd >= 0) {
+ ret = ioctl(fd, DM_TABLE_LOAD, &t) ? -errno : 0;
+ close(fd);
+ } else {
+ ret = -errno;
+ }
+ /* Resuming makes the loaded table live. */
+ if (!ret)
+ ret = dm_ioctl(DM_DEV_SUSPEND, name, 0, dev);
+ if (ret)
+ dm_remove(name);
+ return ret;
+}
+
+static void bdev_thaw_cleanup(FIXTURE_DATA(bdev_thaw) *self)
+{
+ if (self->suspended)
+ dm_ioctl(DM_DEV_SUSPEND, self->name, 0, NULL);
+ if (self->mntfd >= 0)
+ close(self->mntfd);
+ if (self->mounted)
+ umount2(self->mnt, MNT_DETACH);
+ if (self->dm)
+ dm_remove(self->name);
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->node);
+ unlink(self->img);
+ rmdir(self->mnt);
+ if (self->tmpfs)
+ umount2(self->dir, MNT_DETACH);
+ rmdir(self->dir);
+}
+
+FIXTURE_SETUP(bdev_thaw)
+{
+ char cmd[160], dev[32];
+ struct stat st;
+ dev_t dmdev;
+ int fd, ret;
+
+ self->loop = -1;
+ self->mntfd = -1;
+ self->tmpfs = false;
+ self->dm = false;
+ self->suspended = false;
+ self->mounted = false;
+
+ 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");
+ if (access("/dev/mapper/control", R_OK | W_OK))
+ SKIP(return, "test requires device-mapper");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/bdev_thaw.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ /* /tmp may be mounted nodev, the dm node needs a tmpfs of our own. */
+ ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", MS_NOSUID | MS_NOEXEC, NULL), 0)
+ rmdir(self->dir);
+ self->tmpfs = true;
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ snprintf(self->node, sizeof(self->node), "%s/dm", self->dir);
+ snprintf(self->name, sizeof(self->name), "bdev_thaw_%d", getpid());
+ /* The harness doesn't run the teardown when the setup fails. */
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0)
+ bdev_thaw_cleanup(self);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0)
+ bdev_thaw_cleanup(self);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)
+ bdev_thaw_cleanup(self);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ bdev_thaw_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (loop_missing(self->loop)) {
+ bdev_thaw_cleanup(self);
+ SKIP(return, "test requires loop devices");
+ }
+ ASSERT_GE(self->loop, 0)
+ bdev_thaw_cleanup(self);
+ snprintf(dev, sizeof(dev), "/dev/loop%d", self->loop);
+ ASSERT_EQ(stat(dev, &st), 0)
+ bdev_thaw_cleanup(self);
+
+ ASSERT_EQ(dm_create_linear(self->name, st.st_rdev, IMG_SIZE >> 9, &dmdev), 0)
+ bdev_thaw_cleanup(self);
+ self->dm = true;
+ ASSERT_EQ(mknod(self->node, S_IFBLK | 0600, dmdev), 0)
+ bdev_thaw_cleanup(self);
+
+ if (mount(self->node, self->mnt, "ext4", MS_RDONLY, NULL)) {
+ if (errno == ENODEV) {
+ bdev_thaw_cleanup(self);
+ SKIP(return, "kernel lacks ext4");
+ }
+ ASSERT_EQ(errno, 0)
+ bdev_thaw_cleanup(self);
+ }
+ self->mounted = true;
+ self->mntfd = open(self->mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(self->mntfd, 0)
+ bdev_thaw_cleanup(self);
+}
+
+FIXTURE_TEARDOWN(bdev_thaw)
+{
+ bdev_thaw_cleanup(self);
+}
+
+TEST_F(bdev_thaw, fithaw_during_dm_suspend)
+{
+ /* A suspend with lockfs freezes the filesystem through bdev_freeze(). */
+ ASSERT_EQ(dm_ioctl(DM_DEV_SUSPEND, self->name, DM_SUSPEND_FLAG, NULL), 0);
+ self->suspended = true;
+
+ /* FITHAW drops the freeze the suspend holds. */
+ if (ioctl(self->mntfd, FITHAW, 0)) {
+ ASSERT_EQ(errno, EINVAL);
+ SKIP(return, "FITHAW doesn't drop a device-mapper freeze");
+ }
+
+ /* The resume's bdev_thaw() finds nothing left to thaw. */
+ ASSERT_EQ(dm_ioctl(DM_DEV_SUSPEND, self->name, 0, NULL), 0);
+ self->suspended = false;
+
+ close(self->mntfd);
+ self->mntfd = -1;
+ ASSERT_EQ(umount2(self->mnt, 0), 0);
+ self->mounted = false;
+
+ ASSERT_EQ(mount(self->node, self->mnt, "ext4", MS_RDONLY, NULL), 0)
+ TH_LOG("device still frozen after the resume: %s", strerror(errno));
+ self->mounted = true;
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/freeze/config b/tools/testing/selftests/filesystems/freeze/config
new file mode 100644
index 0000000000000..d03720cda9a98
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/config
@@ -0,0 +1,9 @@
+CONFIG_BLK_DEV_DM=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_DEBUG_FS=y
+CONFIG_EXT4_FS=y
+CONFIG_FAIL_MAKE_REQUEST=y
+CONFIG_FAULT_INJECTION=y
+CONFIG_FAULT_INJECTION_DEBUG_FS=y
+CONFIG_MD=y
+CONFIG_QUOTA=y
diff --git a/tools/testing/selftests/filesystems/freeze/loop_util.h b/tools/testing/selftests/filesystems/freeze/loop_util.h
new file mode 100644
index 0000000000000..fcea5be6030d5
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/loop_util.h
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H
+#define __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H
+
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/loop.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+/* How often to retry when somebody else binds the free device first. */
+#define LOOP_BIND_TRIES 64
+
+/* Bind a free loop device to @fd; its number or -errno. */
+static inline int loop_bind(int fd)
+{
+ for (int i = 0; i < LOOP_BIND_TRIES; i++) {
+ char dev[32];
+ int cfd, lfd, n, err;
+
+ cfd = open("/dev/loop-control", O_RDWR | O_CLOEXEC);
+ if (cfd < 0)
+ return -errno;
+ n = ioctl(cfd, LOOP_CTL_GET_FREE);
+ err = errno;
+ close(cfd);
+ if (n < 0)
+ return -err;
+ snprintf(dev, sizeof(dev), "/dev/loop%d", n);
+ lfd = open(dev, O_RDWR | O_CLOEXEC);
+ if (lfd < 0)
+ return -errno;
+ err = ioctl(lfd, LOOP_SET_FD, fd) ? errno : 0;
+ close(lfd);
+ if (!err)
+ return n;
+ if (err != EBUSY)
+ return -err;
+ }
+ return -EBUSY;
+}
+
+/* Did loop_bind() fail because there are no loop device nodes or no driver? */
+static inline bool loop_missing(int ret)
+{
+ return ret == -ENOENT || ret == -ENODEV;
+}
+
+static inline void loop_clear(int n)
+{
+ char dev[32];
+ int fd;
+
+ snprintf(dev, sizeof(dev), "/dev/loop%d", n);
+ fd = open(dev, O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ return;
+ ioctl(fd, LOOP_CLR_FD, 0);
+ close(fd);
+}
+
+#endif /* __SELFTESTS_FILESYSTEMS_FREEZE_LOOP_UTIL_H */
diff --git a/tools/testing/selftests/filesystems/freeze/quotactl_test.c b/tools/testing/selftests/filesystems/freeze/quotactl_test.c
new file mode 100644
index 0000000000000..24772e531eb4c
--- /dev/null
+++ b/tools/testing/selftests/filesystems/freeze/quotactl_test.c
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * quotactl(2) on a frozen superblock.
+ *
+ * Commands that modify quota wait in quotactl_block() for a frozen
+ * superblock to be thawed. A read-only superblock is frozen without
+ * taking s_writers so that wait can't be built on sb_start_write(). Check
+ * that a caller waiting on a frozen read-only or read-write superblock can
+ * be killed and that it is woken up when the superblock is thawed.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/quota.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "../../kselftest_harness.h"
+#include "loop_util.h"
+
+#define IMG_SIZE (64 << 20)
+#define POLL_MS 10
+/* How long the child gets to block in quotactl() or to go away. */
+#define WAIT_MS 3000
+
+FIXTURE(frozen) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char dev[32];
+ int loop;
+ int mntfd;
+ pid_t pid;
+ bool frozen;
+};
+
+FIXTURE_VARIANT(frozen) {
+ unsigned long flags;
+};
+
+FIXTURE_VARIANT_ADD(frozen, ro) {
+ .flags = MS_RDONLY,
+};
+
+FIXTURE_VARIANT_ADD(frozen, rw) {
+ .flags = 0,
+};
+
+/* Fork a child that calls quotactl(Q_SETQUOTA) on @dev and exits. */
+static pid_t quotactl_child(const char *dev)
+{
+ pid_t pid;
+
+ pid = fork();
+ if (pid == 0) {
+ struct if_dqblk dq = {};
+
+ quotactl(QCMD(Q_SETQUOTA, USRQUOTA), dev, 0, (void *)&dq);
+ _exit(0);
+ }
+ return pid;
+}
+
+/* Reap @pid within @ms milliseconds; true if it went away. */
+static bool reap(pid_t pid, int *status, int ms)
+{
+ struct timespec ts = { .tv_nsec = POLL_MS * 1000 * 1000 };
+
+ for (int i = 0; i < ms / POLL_MS; i++) {
+ pid_t ret = waitpid(pid, status, WNOHANG);
+
+ if (ret == pid)
+ return true;
+ if (ret < 0)
+ return false;
+ nanosleep(&ts, NULL);
+ }
+ return false;
+}
+
+/* Wait up to @ms milliseconds for @pid to sleep in the kernel. */
+static bool blocked(pid_t pid, int ms)
+{
+ struct timespec ts = { .tv_nsec = POLL_MS * 1000 * 1000 };
+ char path[64], buf[512], *p, state;
+
+ snprintf(path, sizeof(path), "/proc/%d/stat", pid);
+ for (int i = 0; i < ms / POLL_MS; i++) {
+ ssize_t n;
+ int fd;
+
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return false;
+ n = read(fd, buf, sizeof(buf) - 1);
+ close(fd);
+ if (n <= 0)
+ return false;
+ buf[n] = '\0';
+ /* "pid (comm) state ..." */
+ p = strrchr(buf, ')');
+ if (p && sscanf(p, ") %c", &state) == 1 &&
+ (state == 'D' || state == 'S'))
+ return true;
+ nanosleep(&ts, NULL);
+ }
+ return false;
+}
+
+static void frozen_cleanup(FIXTURE_DATA(frozen) *self)
+{
+ int status;
+
+ if (self->pid > 0)
+ kill(self->pid, SIGKILL);
+ /* The thaw also lets a waiter go that ignored SIGKILL. */
+ if (self->frozen)
+ ioctl(self->mntfd, FITHAW, 0);
+ if (self->pid > 0)
+ reap(self->pid, &status, WAIT_MS);
+ if (self->mntfd >= 0) {
+ close(self->mntfd);
+ umount2(self->mnt, MNT_DETACH);
+ }
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->img);
+ rmdir(self->mnt);
+ rmdir(self->dir);
+}
+
+FIXTURE_SETUP(frozen)
+{
+ char cmd[160];
+ int fd, ret;
+
+ self->loop = -1;
+ self->mntfd = -1;
+ self->pid = -1;
+ self->frozen = false;
+
+ 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");
+ /* Without a device this fails with ENODEV, or ENOSYS without quotactl(). */
+ if (quotactl(QCMD(Q_GETINFO, USRQUOTA), NULL, 0, NULL) && errno == ENOSYS)
+ SKIP(return, "kernel lacks quotactl()");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/freeze_quotactl.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ /* The harness doesn't run the teardown when the setup fails. */
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0)
+ frozen_cleanup(self);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0)
+ frozen_cleanup(self);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0)
+ frozen_cleanup(self);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ frozen_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (loop_missing(self->loop)) {
+ frozen_cleanup(self);
+ SKIP(return, "test requires loop devices");
+ }
+ ASSERT_GE(self->loop, 0)
+ frozen_cleanup(self);
+ snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", self->loop);
+
+ if (mount(self->dev, self->mnt, "ext4", variant->flags, NULL)) {
+ if (errno == ENODEV) {
+ frozen_cleanup(self);
+ SKIP(return, "kernel lacks ext4");
+ }
+ ASSERT_EQ(errno, 0)
+ frozen_cleanup(self);
+ }
+ self->mntfd = open(self->mnt, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ ASSERT_GE(self->mntfd, 0)
+ frozen_cleanup(self);
+}
+
+FIXTURE_TEARDOWN(frozen)
+{
+ frozen_cleanup(self);
+}
+
+TEST_F(frozen, waiter_is_killable)
+{
+ int status;
+
+ ASSERT_EQ(ioctl(self->mntfd, FIFREEZE, 0), 0);
+ self->frozen = true;
+
+ self->pid = quotactl_child(self->dev);
+ ASSERT_GT(self->pid, 0);
+ ASSERT_TRUE(blocked(self->pid, WAIT_MS))
+ TH_LOG("quotactl() doesn't wait on a frozen superblock");
+
+ ASSERT_EQ(kill(self->pid, SIGKILL), 0);
+ ASSERT_TRUE(reap(self->pid, &status, WAIT_MS))
+ TH_LOG("quotactl() waiter survived SIGKILL on a frozen superblock");
+ self->pid = -1;
+ ASSERT_TRUE(WIFSIGNALED(status));
+ ASSERT_EQ(WTERMSIG(status), SIGKILL);
+}
+
+TEST_F(frozen, waiter_wakes_on_thaw)
+{
+ int status;
+
+ ASSERT_EQ(ioctl(self->mntfd, FIFREEZE, 0), 0);
+ self->frozen = true;
+
+ self->pid = quotactl_child(self->dev);
+ ASSERT_GT(self->pid, 0);
+ ASSERT_TRUE(blocked(self->pid, WAIT_MS))
+ TH_LOG("quotactl() doesn't wait on a frozen superblock");
+
+ ASSERT_EQ(ioctl(self->mntfd, FITHAW, 0), 0);
+ self->frozen = false;
+
+ ASSERT_TRUE(reap(self->pid, &status, WAIT_MS))
+ TH_LOG("quotactl() waiter wasn't woken by the thaw");
+ self->pid = -1;
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+}
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/filesystems/fspick_reconfigure_test.c b/tools/testing/selftests/filesystems/fspick_reconfigure_test.c
new file mode 100644
index 0000000000000..a184a5af06d4d
--- /dev/null
+++ b/tools/testing/selftests/filesystems/fspick_reconfigure_test.c
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Reconfiguring a read-only superblock through fspick().
+ *
+ * fspick() creates a reconfiguration context whose flag mask is empty until
+ * "ro" or "rw" is set. Filesystems decide whether to go read-write from
+ * fc->sb_flags, so a reconfiguration without either must leave a read-only
+ * superblock read-only. Check that writes through a read-write bind mount of
+ * a read-only ext4 superblock are still refused after such a reconfiguration
+ * and that an explicit "rw" still makes the superblock read-write.
+ *
+ * After fsmount() and after each reconfiguration the context can be used for
+ * the next reconfiguration. A "ro" set before must not carry over into it.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "wrappers.h"
+#include "freeze/loop_util.h"
+#include "../kselftest_harness.h"
+
+#define IMG_SIZE (64 << 20)
+
+#ifndef MNT_DETACH
+#define MNT_DETACH 2
+#endif
+
+static inline int sys_fspick(int dfd, const char *path, unsigned int flags)
+{
+ return syscall(__NR_fspick, dfd, path, flags);
+}
+
+static inline int sys_umount2(const char *path, int flags)
+{
+ return syscall(__NR_umount2, path, flags);
+}
+
+FIXTURE(fspick_ro) {
+ char dir[64];
+ char img[96];
+ char mnt[96];
+ char bind[96];
+ int loop;
+ bool mounted;
+ bool bound;
+};
+
+static void fspick_ro_cleanup(FIXTURE_DATA(fspick_ro) *self)
+{
+ if (self->bound)
+ sys_umount2(self->bind, MNT_DETACH);
+ if (self->mounted)
+ sys_umount2(self->mnt, MNT_DETACH);
+ if (self->loop >= 0)
+ loop_clear(self->loop);
+ unlink(self->img);
+ rmdir(self->bind);
+ rmdir(self->mnt);
+ rmdir(self->dir);
+}
+
+/* Mount @dev read-only and add a read-write bind mount of it. */
+static int fspick_ro_mount(FIXTURE_DATA(fspick_ro) *self, const char *dev)
+{
+ if (sys_mount(dev, self->mnt, "ext4", MS_RDONLY, NULL))
+ return -errno;
+ self->mounted = true;
+
+ /* A read-write bind mount only refuses writes if the superblock does. */
+ if (sys_mount(self->mnt, self->bind, NULL, MS_BIND, NULL))
+ return -errno;
+ self->bound = true;
+ if (sys_mount(NULL, self->bind, NULL, MS_REMOUNT | MS_BIND, NULL))
+ return -errno;
+ return 0;
+}
+
+FIXTURE_SETUP(fspick_ro)
+{
+ char cmd[160], dev[32];
+ int fd, ret;
+
+ self->loop = -1;
+ self->mounted = false;
+ self->bound = false;
+
+ if (geteuid() != 0)
+ SKIP(return, "test requires root");
+ if (access("/dev/loop-control", R_OK | W_OK))
+ SKIP(return, "test requires loop devices");
+
+ ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+ ASSERT_EQ(sys_mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+
+ snprintf(self->dir, sizeof(self->dir), "/tmp/fspick_ro.XXXXXX");
+ ASSERT_NE(mkdtemp(self->dir), NULL);
+ snprintf(self->img, sizeof(self->img), "%s/img", self->dir);
+ snprintf(self->mnt, sizeof(self->mnt), "%s/mnt", self->dir);
+ snprintf(self->bind, sizeof(self->bind), "%s/bind", self->dir);
+ ASSERT_EQ(mkdir(self->mnt, 0700), 0);
+ ASSERT_EQ(mkdir(self->bind, 0700), 0);
+
+ fd = open(self->img, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(ftruncate(fd, IMG_SIZE), 0);
+
+ snprintf(cmd, sizeof(cmd), "mkfs.ext4 -q -F %s >/dev/null 2>&1", self->img);
+ ret = system(cmd);
+ if (ret) {
+ close(fd);
+ fspick_ro_cleanup(self);
+ SKIP(return, "mkfs.ext4 failed or is not available");
+ }
+
+ /* The harness skips the teardown if the setup fails, so clean up. */
+ self->loop = loop_bind(fd);
+ close(fd);
+ if (self->loop < 0) {
+ fspick_ro_cleanup(self);
+ ASSERT_GE(self->loop, 0);
+ }
+ snprintf(dev, sizeof(dev), "/dev/loop%d", self->loop);
+
+ ret = fspick_ro_mount(self, dev);
+ if (ret) {
+ fspick_ro_cleanup(self);
+ if (ret == -ENODEV)
+ SKIP(return, "kernel lacks ext4");
+ ASSERT_EQ(ret, 0);
+ }
+}
+
+FIXTURE_TEARDOWN(fspick_ro)
+{
+ fspick_ro_cleanup(self);
+}
+
+static int reconfigure(const char *path, const char *flag)
+{
+ int fd, ret = 0;
+
+ fd = sys_fspick(AT_FDCWD, path, FSPICK_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ if (flag && sys_fsconfig(fd, FSCONFIG_SET_FLAG, flag, NULL, 0))
+ ret = -errno;
+ if (!ret && sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0))
+ ret = -errno;
+ close(fd);
+ return ret;
+}
+
+static int create_file(const char *dir)
+{
+ char path[128];
+ int fd;
+
+ snprintf(path, sizeof(path), "%s/file", dir);
+ fd = open(path, O_RDWR | O_CREAT | O_CLOEXEC, 0600);
+ if (fd < 0)
+ return -errno;
+ close(fd);
+ return 0;
+}
+
+TEST_F(fspick_ro, reconfigure_keeps_ro)
+{
+ ASSERT_EQ(create_file(self->bind), -EROFS);
+
+ ASSERT_EQ(reconfigure(self->mnt, NULL), 0);
+ ASSERT_EQ(create_file(self->bind), -EROFS)
+ TH_LOG("reconfiguration without \"rw\" made the superblock read-write");
+}
+
+TEST_F(fspick_ro, reconfigure_rw)
+{
+ ASSERT_EQ(reconfigure(self->mnt, "rw"), 0);
+ ASSERT_EQ(create_file(self->bind), 0);
+}
+
+TEST_F(fspick_ro, reconfigure_after_fsmount_keeps_ro)
+{
+ char dev[32];
+ int fd, mfd;
+
+ /* Make room for the new mount, the bind mount keeps the superblock. */
+ ASSERT_EQ(sys_umount2(self->mnt, 0), 0);
+ self->mounted = false;
+
+ snprintf(dev, sizeof(dev), "/dev/loop%d", self->loop);
+ fd = sys_fsopen("ext4", FSOPEN_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_STRING, "source", dev, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_FLAG, "ro", NULL, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0);
+ mfd = sys_fsmount(fd, FSMOUNT_CLOEXEC, 0);
+ ASSERT_GE(mfd, 0);
+ ASSERT_EQ(sys_move_mount(mfd, "", AT_FDCWD, self->mnt,
+ MOVE_MOUNT_F_EMPTY_PATH), 0);
+ self->mounted = true;
+ close(mfd);
+
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);
+ close(fd);
+ ASSERT_EQ(create_file(self->bind), -EROFS)
+ TH_LOG("reconfiguration after fsmount() made the superblock read-write");
+}
+
+TEST_F(fspick_ro, reconfigure_twice_keeps_ro)
+{
+ int fd;
+
+ fd = sys_fspick(AT_FDCWD, self->mnt, FSPICK_CLOEXEC);
+ ASSERT_GE(fd, 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_SET_FLAG, "ro", NULL, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);
+ ASSERT_EQ(sys_fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0), 0);
+ close(fd);
+ ASSERT_EQ(create_file(self->bind), -EROFS)
+ TH_LOG("second reconfiguration made the superblock read-write");
+}
+
+TEST_HARNESS_MAIN
|
| 43/3 | 2026/10/11 16:28 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20112 output: 35 thoughts: 1070 Thoughts: **KMSAN Fuzzing Session Justification** Okay, let's break this down. My goal is to determine if this kernel patch warrants spawning a dedicated KMSAN fuzzing session. The patch seems to touch several areas, so I need to analyze each change with KMSAN's purpose in mind: detecting uninitialized memory reads and kernel-to-user information leaks. I know KASAN, LOCKDEP, and other tools catch different bugs, so I don't need KMSAN if they already cover the potential issues. First, I'll quickly look at the diff: 1. `fs/fs_context.c`: Setting `fc->sb_flags_mask = 0` in `vfs_clean_context`. I'll need to figure out what `vfs_clean_context` actually does. I'll need to reference the code. 2. `fs/fserror.c`: Adding `smp_mb()` and a check `!(sb->s_flags & SB_BORN)`. The `smp_mb()` suggests memory barrier concerns, which may interact with uninitialized data indirectly, but it's not a direct KMSAN red flag. The check is interesting and may imply conditional logic. 3. `fs/quota/quota.c`: Waiting for `sb` unfreeze. This seems to be about synchronization, less about initialization. But I will keep an eye on how it handles errors. 4. `fs/super.c`: This is the most complex one. Changes include modifying `enum super_iter_flags_t`, changing locking from `super_lock` to `super_lock_shared` and a handful of other modifications related to super block operations. There's a lot here on freezing and thawing. The emergency remount code is important. These changes are complex, and I need to look closely for data structure modifications or changes in control flow that might expose uninitialized data. Specifically, I'll be looking for changes that might involve new structure initialization or conditional logic that relies on potentially uninitialized data. The modifications to `reconfigure_super` are also worth a careful look. I'll be focused on how `sb_flags` are handled. 5. `tools/testing/selftests/...`: Just selftests. Doesn't directly impact my KMSAN decision, but it's good to know tests are present. Now, let's recap the KMSAN criteria. Does the patch... 1. Involve kernel structures passed to userspace? (copy_to_user, put_user, etc.) 2. Have conditional logic depending on uninitialized variables? 3. Allocate or initialize complex data structures where uninitialized fields could be read later? 4. Modify bounds checks or logic in a way that allows access to uninitialized bytes? And I know to rule out KMSAN if: * The primary risks are out-of-bounds, use-after-free, NULL dereferences, or locking bugs. * All relevant structures are fully zeroed or initialized. * The patch *doesn't* introduce uninitialized memory usage or leaks. I'll start with the first change, examining the definition of `vfs_clean_context` and its usage in `fs/fs_context.c` around line 544. From there I will work through the list, cross referencing any concerns from the diff to the KMSAN rules. |
| 44/3 | 2026/10/11 16:29 | tool | read-file |
0mArgs:{
"File": "fs/fs_context.c",
"FirstLine": 535,
"LineCount": 30
}Results: {
"Contents": " 535:\t * and failing to allocate memory would've put us into a nasty situation.\n 536:\t * So here we only discard the old state and reinitialization is left\n 537:\t * until we actually try to reconfigure.\n 538:\t */\n 539:\tvoid vfs_clean_context(struct fs_context *fc)\n 540:\t{\n 541:\t\tif (fc-\u003eneed_free \u0026\u0026 fc-\u003eops \u0026\u0026 fc-\u003eops-\u003efree)\n 542:\t\t\tfc-\u003eops-\u003efree(fc);\n 543:\t\tfc-\u003eneed_free = false;\n 544:\t\tfc-\u003efs_private = NULL;\n 545:\t\tfc-\u003es_fs_info = NULL;\n 546:\t\tfc-\u003esb_flags = 0;\n 547:\t\tfc-\u003esb_flags_mask = 0;\n 548:\t\tsecurity_free_mnt_opts(\u0026fc-\u003esecurity);\n 549:\t\tkfree(fc-\u003esource);\n 550:\t\tfc-\u003esource = NULL;\n 551:\t\tfc-\u003eexclusive = false;\n 552:\t\n 553:\t\tfc-\u003epurpose = FS_CONTEXT_FOR_RECONFIGURE;\n 554:\t\tfc-\u003ephase = FS_CONTEXT_AWAITING_RECONF;\n 555:\t}\n 556:\t\n 557:\tint finish_clean_context(struct fs_context *fc)\n 558:\t{\n 559:\t\tint error;\n 560:\t\n 561:\t\tif (fc-\u003ephase != FS_CONTEXT_AWAITING_RECONF)\n 562:\t\t\treturn 0;\n 563:\t\n 564:\t\terror = fc-\u003efs_type-\u003einit_fs_context(fc);\n"
} |
| 45/3 | 2026/10/11 16:29 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22416 output: 33 thoughts: 100 Thoughts: Okay, here's my understanding, framed as my internal thought process: **Resetting the Filesystem Context for a Clean Reconfiguration** Alright, let's break this down. `vfs_clean_context` is clearly designed to wipe the slate clean when we're about to reconfigure something. The key part is that it's clearing `sb_flags_mask = 0`. That's the important bit. It's essentially ensuring that any stale flags from *previous* mounts or reconfigurations don't accidentally linger around and pollute the system. It's crucial for idempotency, right? We *absolutely* don't want old baggage influencing a fresh configuration. This cleaning step is essential for correctness. Now, before this fix was implemented, `sb_flags_mask` was holding onto old, potentially irrelevant, values, which is just bad news. So, by clearing it, we guarantee that the *next* reconfigure gets a truly clean starting point, a fresh state. I'm also noting that `fs_context` is initialized using `kzalloc` in `alloc_fs_context`. That's the right choice – memory is zeroed, which is a good baseline and a good way to start. But I need to double-check something. Let me go back and verify exactly *how* `fs_context` is constructed to ensure there aren't any other subtle issues or dependencies lurking. I'll focus on how `alloc_fs_context` is called and what information is passed in. Gotta be rigorous about this, as filesystem context is fundamental. |
| 46/3 | 2026/10/11 16:29 | tool | grepper |
0mArgs:{
"Expression": "alloc_fs_context",
"PathPrefixes": [
"fs/fs_context.c"
]
}Results: {
"Output": "fs/fs_context.c=243=EXPORT_SYMBOL(generic_parse_monolithic);\n--\nfs/fs_context.c-245-/**\nfs/fs_context.c:246: * alloc_fs_context - Create a filesystem context.\nfs/fs_context.c-247- * @fs_type: The filesystem type.\n--\nfs/fs_context.c-257- */\nfs/fs_context.c:258:static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,\nfs/fs_context.c-259-\t\t\t\t struct dentry *reference,\n--\nfs/fs_context.c=306=struct fs_context *fs_context_for_mount(struct file_system_type *fs_type,\n--\nfs/fs_context.c-308-{\nfs/fs_context.c:309:\treturn alloc_fs_context(fs_type, NULL, sb_flags, 0,\nfs/fs_context.c-310-\t\t\t\t\tFS_CONTEXT_FOR_MOUNT);\n--\nfs/fs_context.c=314=struct fs_context *fs_context_for_reconfigure(struct dentry *dentry,\n--\nfs/fs_context.c-321-\nfs/fs_context.c:322:\treturn alloc_fs_context(dentry-\u003ed_sb-\u003es_type, dentry, sb_flags,\nfs/fs_context.c-323-\t\t\t\tsb_flags_mask, FS_CONTEXT_FOR_RECONFIGURE);\n--\nfs/fs_context.c=334=struct fs_context *fs_context_for_submount(struct file_system_type *type,\n--\nfs/fs_context.c-339-\nfs/fs_context.c:340:\tfc = alloc_fs_context(type, reference, 0, 0, FS_CONTEXT_FOR_SUBMOUNT);\nfs/fs_context.c-341-\tif (IS_ERR(fc))\n"
} |
| 47/3 | 2026/10/11 16:29 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23405 output: 35 thoughts: 13 Thoughts: Okay, let's dive into this. Here's how I'd approach summarizing the prompt from an expert's perspective: **Diving into `alloc_fs_context`** Alright, so the task at hand is to understand the implementation of `alloc_fs_context`. My immediate thought is to check the actual code itself. What's the context? What exactly are we allocating? Is it file system specific metadata, a cache structure, some sort of context for a mount operation, or something else entirely? The name itself gives us a pretty good indication, but the devil's in the details. My prior experience tells me there will be some memory allocation and initialization involved, possibly within a `kmalloc` or `vmalloc` framework, depending on its size and alignment requirements. I expect to see error handling, of course; null pointer checks are crucial, as are checks for memory allocation failures. I'll need to look at the surrounding functions it calls, and functions that might call it, to understand its role in a larger context. Does it take any configuration parameters? And how is this allocated context ultimately released or freed? These are the questions I'll be asking myself as I inspect the code. |
| 48/3 | 2026/10/11 16:29 | tool | read-file |
0mArgs:{
"File": "fs/fs_context.c",
"FirstLine": 258,
"LineCount": 35
}Results: {
"Contents": " 258:\tstatic struct fs_context *alloc_fs_context(struct file_system_type *fs_type,\n 259:\t\t\t\t\t struct dentry *reference,\n 260:\t\t\t\t\t unsigned int sb_flags,\n 261:\t\t\t\t\t unsigned int sb_flags_mask,\n 262:\t\t\t\t\t enum fs_context_purpose purpose)\n 263:\t{\n 264:\t\tstruct fs_context *fc;\n 265:\t\tint ret = -ENOMEM;\n 266:\t\n 267:\t\tfc = kzalloc_obj(struct fs_context, GFP_KERNEL_ACCOUNT);\n 268:\t\tif (!fc)\n 269:\t\t\treturn ERR_PTR(-ENOMEM);\n 270:\t\n 271:\t\tfc-\u003epurpose\t= purpose;\n 272:\t\tfc-\u003esb_flags\t= sb_flags;\n 273:\t\tfc-\u003esb_flags_mask = sb_flags_mask;\n 274:\t\tfc-\u003efs_type\t= get_filesystem(fs_type);\n 275:\t\tfc-\u003ecred\t= get_current_cred();\n 276:\t\tfc-\u003enet_ns\t= get_net(current-\u003ensproxy-\u003enet_ns);\n 277:\t\tfc-\u003elog.prefix\t= fs_type-\u003ename;\n 278:\t\n 279:\t\tmutex_init(\u0026fc-\u003euapi_mutex);\n 280:\t\n 281:\t\tswitch (purpose) {\n 282:\t\tcase FS_CONTEXT_FOR_MOUNT:\n 283:\t\t\tfc-\u003euser_ns = get_user_ns(fc-\u003ecred-\u003euser_ns);\n 284:\t\t\tbreak;\n 285:\t\tcase FS_CONTEXT_FOR_SUBMOUNT:\n 286:\t\t\tfc-\u003euser_ns = get_user_ns(reference-\u003ed_sb-\u003es_user_ns);\n 287:\t\t\tbreak;\n 288:\t\tcase FS_CONTEXT_FOR_RECONFIGURE:\n 289:\t\t\tatomic_inc(\u0026reference-\u003ed_sb-\u003es_active);\n 290:\t\t\tfc-\u003euser_ns = get_user_ns(reference-\u003ed_sb-\u003es_user_ns);\n 291:\t\t\tfc-\u003eroot = dget(reference);\n 292:\t\t\tbreak;\n"
} |
| 49/3 | 2026/10/11 16:29 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24303 output: 33 thoughts: 119 Thoughts: Here's my analysis of the provided code snippets: **Debugging the Filesystem Error Handling** Okay, so `alloc_fs_context` relies on `kzalloc_obj`, which is a good starting point as it ensures a clean, zeroed memory allocation. That helps eliminate initial garbage in the allocated structures, a common source of subtle bugs. Now, let's dive into the `fserror.c` file. I see two key areas that warrant inspection. First, in `fserror_pending_dec`, there's `smp_mb()` before `wake_up_var(&sb->s_pending_errors)`. This memory barrier is absolutely crucial for proper synchronization in a multi-processor environment. I need to confirm that this is correctly ensuring visibility of the updates to `sb->s_pending_errors` to other CPUs before they potentially wake up on it. I need to make sure the memory ordering semantics are correct here. Second, in `fserror_alloc_event`, there's a conditional check: `if (!(sb->s_flags & SB_BORN)) goto out_pending;`. This means that if a superblock's `SB_BORN` flag is not set, the process is skipped. I want to understand what the implications are of this test, and what could cause a superblock not to be "born" at the moment we attempt to allocate an error event. Is it related to initialization or a specific lifecycle state? I need to understand the contexts in which this can happen. I'll be paying close attention to the code around line 89 of `fs/fserror.c` for some more context. |
| 50/3 | 2026/10/11 16:29 | tool | read-file |
0mArgs:{
"File": "fs/fserror.c",
"FirstLine": 80,
"LineCount": 40
}Results: {
"Contents": " 80:\tstatic inline struct fserror_event *fserror_alloc_event(struct super_block *sb,\n 81:\t\t\t\t\t\t\t\tgfp_t gfp_flags)\n 82:\t{\n 83:\t\tstruct fserror_event *event = NULL;\n 84:\t\n 85:\t\t/*\n 86:\t\t * If pending_errors already reached zero or is no longer active,\n 87:\t\t * the superblock is being deactivated so there's no point in\n 88:\t\t * continuing.\n 89:\t\t *\n 90:\t\t * The order of the check of s_pending_errors and SB_ACTIVE are\n 91:\t\t * mandated by order of accesses in generic_shutdown_super and\n 92:\t\t * fserror_unmount. Barriers are implicitly provided by the refcount\n 93:\t\t * manipulations in this function and fserror_unmount.\n 94:\t\t */\n 95:\t\tif (!refcount_inc_not_zero(\u0026sb-\u003es_pending_errors))\n 96:\t\t\treturn NULL;\n 97:\t\tif (!(sb-\u003es_flags \u0026 SB_ACTIVE))\n 98:\t\t\tgoto out_pending;\n 99:\t\t/*\n 100:\t\t * xfs and f2fs set SB_ACTIVE while filling the superblock. Nobody can\n 101:\t\t * listen before the superblock is born and if the mount fails nothing\n 102:\t\t * waits for the event.\n 103:\t\t */\n 104:\t\tif (!(sb-\u003es_flags \u0026 SB_BORN))\n 105:\t\t\tgoto out_pending;\n 106:\t\n 107:\t\tevent = mempool_alloc(\u0026fserror_events_pool, gfp_flags);\n 108:\t\tif (!event)\n 109:\t\t\tgoto out_pending;\n 110:\t\n 111:\t\t/* mempool_alloc doesn't support GFP_ZERO */\n 112:\t\tmemset(event, 0, sizeof(*event));\n 113:\t\tevent-\u003esb = sb;\n 114:\t\tINIT_WORK(\u0026event-\u003ework, fserror_worker);\n 115:\t\n 116:\t\treturn event;\n 117:\t\n 118:\tout_pending:\n 119:\t\tfserror_pending_dec(sb);\n"
} |
| 51/3 | 2026/10/11 16:29 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25396 output: 35 thoughts: 287 Thoughts: **Analyzing Potential Error Paths in Filesystem Quota Management** Okay, let's break this down systematically. My initial concern was about potential uninitialized memory, but after reviewing `fserror_alloc_event`, it seems that isn't the problem. The code explicitly zeroes the event structure using `memset`, so that's not where the issue lies. The check `!(sb->s_flags & SB_BORN)` and the subsequent NULL return indicate a graceful handling of the event allocation failure. Now, my attention has shifted to `fs/quota/quota.c`. Specifically, I'm focusing on the superblock unfreeze mechanism. The original code used `sb_start_write` and `sb_end_write`, but that has been replaced with a `wait_var_event_killable` call. The comment explicitly mentions a read-only superblock being frozen without taking `s_writers`, and `sb_start_write` wouldn't wait in that scenario. This is crucial for avoiding deadlocks or hangs. The `wait_var_event_killable` function seems to be the key to ensuring the superblock unfreezes. I need to understand what `error` represents in this context. It's returned by `wait_var_event_killable` and if it is non-zero, it gets returned. I need to look closer at the surrounding code, around line 894, to fully grasp what conditions might lead to a non-zero `error` value, and what implications that has for the quota system. I need to know what those error conditions are and how they are handled. I'm going to follow the logic from the `error` return back to the caller to understand the impact on the overall flow of quota operations. |
| 52/3 | 2026/10/11 16:29 | tool | read-file |
0mArgs:{
"File": "fs/quota/quota.c",
"FirstLine": 870,
"LineCount": 45
}Results: {
"Contents": " 870:\t\tCLASS(filename, tmp)(special);\n 871:\t\tbool excl = false, thawed = false;\n 872:\t\tint error;\n 873:\t\tdev_t dev;\n 874:\t\n 875:\t\tif (IS_ERR(tmp))\n 876:\t\t\treturn ERR_CAST(tmp);\n 877:\t\terror = lookup_bdev(tmp-\u003ename, \u0026dev);\n 878:\t\tif (error)\n 879:\t\t\treturn ERR_PTR(error);\n 880:\t\n 881:\t\tif (quotactl_cmd_onoff(cmd)) {\n 882:\t\t\texcl = true;\n 883:\t\t\tthawed = true;\n 884:\t\t} else if (quotactl_cmd_write(cmd)) {\n 885:\t\t\tthawed = true;\n 886:\t\t}\n 887:\t\n 888:\tretry:\n 889:\t\tsb = user_get_super(dev, excl);\n 890:\t\tif (!sb)\n 891:\t\t\treturn ERR_PTR(-ENODEV);\n 892:\t\tif (thawed \u0026\u0026 sb-\u003es_writers.frozen != SB_UNFROZEN) {\n 893:\t\t\tif (excl)\n 894:\t\t\t\tup_write(\u0026sb-\u003es_umount);\n 895:\t\t\telse\n 896:\t\t\t\tup_read(\u0026sb-\u003es_umount);\n 897:\t\t\t/*\n 898:\t\t\t * Wait for sb to unfreeze. A read-only superblock is frozen\n 899:\t\t\t * without taking s_writers so sb_start_write() won't wait.\n 900:\t\t\t */\n 901:\t\t\terror = wait_var_event_killable(\u0026sb-\u003es_writers.frozen,\n 902:\t\t\t\t\tREAD_ONCE(sb-\u003es_writers.frozen) == SB_UNFROZEN);\n 903:\t\t\tput_super(sb);\n 904:\t\t\tif (error)\n 905:\t\t\t\treturn ERR_PTR(error);\n 906:\t\t\tgoto retry;\n 907:\t\t}\n 908:\t\treturn sb;\n 909:\t\n 910:\t#else\n 911:\t\treturn ERR_PTR(-ENODEV);\n 912:\t#endif\n 913:\t}\n 914:\t\n"
} |
| 53/3 | 2026/10/11 16:29 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26717 output: 33 thoughts: 113 Thoughts: **Analyzing Error Handling and Superblock Iteration** Okay, so I'm looking at this code and trying to understand the error handling within this particular function. It looks like `error` is a local integer variable, which is initialized by `wait_var_event_killable(...)`. The critical bit is that if this `error` variable isn't zero, the function returns `ERR_PTR(error)`. No immediate concerns about uninitialized memory here, which is good. We're getting a value from a well defined origin. Now, I need to check the filesystem's superblock handling in `fs/super.c`. Let's dig into that and look at any of the parts that are touched in `fs/super.c`. I am going to inspect it systematically. I am thinking, that I am not just looking for obvious errors, I am also looking for performance problems, locking issues and resource leaks. Specifically, I'm going to focus on `__iterate_supers`, that seems like the starting point. I'm going to check lines 950-985 of `fs/super.c`. I'm going to extend the scope of the inspection to lines 930-1000 in `fs/super.c` for some context and to get a feel for the broader structure. I am expecting some kind of iteration in that routine. I need to understand this process thoroughly. |
| 54/3 | 2026/10/11 16:30 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 930,
"LineCount": 60
}Results: {
"Contents": " 930:\t\n 931:\tvoid drop_super_exclusive(struct super_block *sb)\n 932:\t{\n 933:\t\tsuper_unlock_excl(sb);\n 934:\t\tput_super(sb);\n 935:\t}\n 936:\t\n 937:\tenum super_iter_flags_t {\n 938:\t\tSUPER_ITER_UNLOCKED\t= (1U \u003c\u003c 0),\n 939:\t\tSUPER_ITER_REVERSE\t= (1U \u003c\u003c 1),\n 940:\t};\n 941:\t\n 942:\tstatic inline struct super_block *first_super(enum super_iter_flags_t flags)\n 943:\t{\n 944:\t\tif (flags \u0026 SUPER_ITER_REVERSE)\n 945:\t\t\treturn list_last_entry(\u0026super_blocks, struct super_block, s_list);\n 946:\t\treturn list_first_entry(\u0026super_blocks, struct super_block, s_list);\n 947:\t}\n 948:\t\n 949:\tstatic inline struct super_block *next_super(struct super_block *sb,\n 950:\t\t\t\t\t\t enum super_iter_flags_t flags)\n 951:\t{\n 952:\t\tif (flags \u0026 SUPER_ITER_REVERSE)\n 953:\t\t\treturn list_prev_entry(sb, s_list);\n 954:\t\treturn list_next_entry(sb, s_list);\n 955:\t}\n 956:\t\n 957:\tstatic void __iterate_supers(void (*f)(struct super_block *, void *), void *arg,\n 958:\t\t\t\t enum super_iter_flags_t flags)\n 959:\t{\n 960:\t\tstruct super_block *sb, *p = NULL;\n 961:\t\n 962:\t\tspin_lock(\u0026sb_lock);\n 963:\t\n 964:\t\tfor (sb = first_super(flags);\n 965:\t\t !list_entry_is_head(sb, \u0026super_blocks, s_list);\n 966:\t\t sb = next_super(sb, flags)) {\n 967:\t\t\tif (super_flags(sb, SB_DYING))\n 968:\t\t\t\tcontinue;\n 969:\t\n 970:\t\t\tif (!refcount_inc_not_zero(\u0026sb-\u003es_passive))\n 971:\t\t\t\tcontinue;\n 972:\t\n 973:\t\t\tspin_unlock(\u0026sb_lock);\n 974:\t\n 975:\t\t\tif (flags \u0026 SUPER_ITER_UNLOCKED) {\n 976:\t\t\t\tf(sb, arg);\n 977:\t\t\t} else if (super_lock_shared(sb)) {\n 978:\t\t\t\tf(sb, arg);\n 979:\t\t\t\tsuper_unlock_shared(sb);\n 980:\t\t\t}\n 981:\t\n 982:\t\t\tif (p)\n 983:\t\t\t\tput_super(p);\n 984:\t\t\tp = sb;\n 985:\t\t\tspin_lock(\u0026sb_lock);\n 986:\t\t}\n 987:\t\tspin_unlock(\u0026sb_lock);\n 988:\t\tif (p)\n 989:\t\t\tput_super(p);\n"
} |
| 55/3 | 2026/10/11 16:30 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28040 output: 34 thoughts: 23 Thoughts: Okay, let's dive into this. I need to get a handle on the `reconfigure_super` function. Specifically, I'm going to focus on lines 1070-1110. This segment is key, and I know it probably relates to how the system adjusts its core configuration; I need to understand the specifics of its operation here. The documentation probably offers some clues, but I'll start with the code itself. |
| 56/3 | 2026/10/11 16:30 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 1070,
"LineCount": 40
}Results: {
"Contents": "1070:\t\tbool remount_rw = false;\n1071:\t\tbool force = fc-\u003esb_flags \u0026 SB_FORCE;\n1072:\t\n1073:\t\tif (fc-\u003esb_flags_mask \u0026 ~MS_RMT_MASK)\n1074:\t\t\treturn -EINVAL;\n1075:\t\tif (sb-\u003es_writers.frozen != SB_UNFROZEN)\n1076:\t\t\treturn -EBUSY;\n1077:\t\n1078:\t\t/*\n1079:\t\t * Filesystems take fc-\u003esb_flags \u0026 SB_RDONLY as the read-only state the\n1080:\t\t * superblock ends up in. If that isn't being changed, e.g., fspick()\n1081:\t\t * without \"ro\" or \"rw\", it's the current one.\n1082:\t\t */\n1083:\t\tif (!(fc-\u003esb_flags_mask \u0026 SB_RDONLY))\n1084:\t\t\tfc-\u003esb_flags = (fc-\u003esb_flags \u0026 ~SB_RDONLY) | (sb-\u003es_flags \u0026 SB_RDONLY);\n1085:\t\n1086:\t\tretval = security_sb_remount(sb, fc-\u003esecurity);\n1087:\t\tif (retval)\n1088:\t\t\treturn retval;\n1089:\t\n1090:\t\tif (fc-\u003esb_flags_mask \u0026 SB_RDONLY) {\n1091:\t#ifdef CONFIG_BLOCK\n1092:\t\t\tif (!(fc-\u003esb_flags \u0026 SB_RDONLY) \u0026\u0026 sb-\u003es_bdev \u0026\u0026\n1093:\t\t\t bdev_read_only(sb-\u003es_bdev))\n1094:\t\t\t\treturn -EACCES;\n1095:\t#endif\n1096:\t\t\tremount_rw = !(fc-\u003esb_flags \u0026 SB_RDONLY) \u0026\u0026 sb_rdonly(sb);\n1097:\t\t\tremount_ro = (fc-\u003esb_flags \u0026 SB_RDONLY) \u0026\u0026 !sb_rdonly(sb);\n1098:\t\t}\n1099:\t\n1100:\t\tif (remount_ro) {\n1101:\t\t\tif (!hlist_empty(\u0026sb-\u003es_pins)) {\n1102:\t\t\t\tsuper_unlock_excl(sb);\n1103:\t\t\t\tgroup_pin_kill(\u0026sb-\u003es_pins);\n1104:\t\t\t\t__super_lock_excl(sb);\n1105:\t\t\t\tif (!sb-\u003es_root)\n1106:\t\t\t\t\treturn 0;\n1107:\t\t\t\tif (sb-\u003es_writers.frozen != SB_UNFROZEN)\n1108:\t\t\t\t\treturn -EBUSY;\n1109:\t\t\t\tremount_ro = !sb_rdonly(sb);\n"
} |
| 57/3 | 2026/10/11 16:30 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28900 output: 34 thoughts: 36 Thoughts: Okay, let's dive into this code. I need to understand the emergency remount logic. Specifically, I should examine the relationship between `do_emergency_remount_callback` and `do_emergency_remount`. I'm assuming one is a callback function and the other performs the actual remount, but I need to confirm that. I'll focus on lines 1158 through 1200. This block should give me a clear picture of how this critical emergency procedure is handled. I need to quickly identify the trigger and the sequence. |
| 58/3 | 2026/10/11 16:30 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 1158,
"LineCount": 45
}Results: {
"Contents": "1158:\t\treturn 0;\n1159:\t\n1160:\tcancel_readonly:\n1161:\t\tsb_end_ro_state_change(sb);\n1162:\t\treturn retval;\n1163:\t}\n1164:\t\n1165:\tstatic void do_emergency_remount_callback(struct super_block *sb, void *unused)\n1166:\t{\n1167:\t\tstruct fs_context *fc = NULL;\n1168:\t\n1169:\t\tif (!super_lock_excl(sb))\n1170:\t\t\treturn;\n1171:\t\n1172:\t\t/* Make sure no reference put under s_umount is the last one. */\n1173:\t\tatomic_inc(\u0026sb-\u003es_active);\n1174:\t\tif (sb-\u003es_bdev \u0026\u0026 !sb_rdonly(sb)) {\n1175:\t\t\tfc = fs_context_for_reconfigure(sb-\u003es_root,\n1176:\t\t\t\t\t\tSB_RDONLY | SB_FORCE, SB_RDONLY);\n1177:\t\t\tif (!IS_ERR(fc) \u0026\u0026 parse_monolithic_mount_data(fc, NULL) == 0)\n1178:\t\t\t\t(void)reconfigure_super(fc);\n1179:\t\t}\n1180:\t\tsuper_unlock_excl(sb);\n1181:\t\n1182:\t\t/*\n1183:\t\t * Our active reference may be the last one by now, so only drop it\n1184:\t\t * after s_umount has been released.\n1185:\t\t */\n1186:\t\tif (!IS_ERR_OR_NULL(fc))\n1187:\t\t\tput_fs_context(fc);\n1188:\t\tdeactivate_super(sb);\n1189:\t}\n1190:\t\n1191:\tstatic void do_emergency_remount(struct work_struct *work)\n1192:\t{\n1193:\t\t__iterate_supers(do_emergency_remount_callback, NULL,\n1194:\t\t\t\t SUPER_ITER_UNLOCKED | SUPER_ITER_REVERSE);\n1195:\t\tkfree(work);\n1196:\t\tprintk(\"Emergency Remount complete\\n\");\n1197:\t}\n1198:\t\n1199:\tvoid emergency_remount(void)\n1200:\t{\n1201:\t\tstruct work_struct *work;\n1202:\t\n"
} |
| 59/3 | 2026/10/11 16:30 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29743 output: 34 thoughts: 25 Thoughts: Okay, let's dive into this. Here's my take on those lines of code, presented as a personal reflection, keeping in mind my expertise: **Diving into `fs_super_thaw` (Lines 1490-1540)** Alright, so we're looking at the `fs_super_thaw` function, specifically lines 1490 through 1540. My immediate thought is, "Okay, this is where we're reconstructing the filesystem superblock from its frozen state." Given my experience, I know this is a critical section – the integrity of the entire filesystem hinges on this process. We're essentially bringing the filesystem back to life after some sort of hibernation, snapshot, or crash-consistent state. I'm expecting to see operations related to: * **Memory allocation and deallocation:** We're likely dealing with dynamic memory here, re-allocating the superblock and potentially other associated data structures that were previously persisted. I need to keep a close eye on the allocation patterns for potential memory leaks or corruption issues, particularly in the error paths. * **Data integrity checks:** We're thawing the superblock, so we MUST be validating the data being read. It's incredibly important to ensure the data is complete and accurate. It is important to know which state we are coming from. Is it a graceful shutdown, or something less organized? * **Metadata restoration:** The most important thing is restoring metadata. Depending on the design, this might involve re-initializing key fields, syncing critical in-memory structures with what's on disk, and potentially rebuilding caches and indexes. I know that if these files are damaged or not written correctly, we will have a lot of problems. * **Error handling:** Obviously, a proper error handling is important here. Errors can lead to complete file-system failure, so the handling code in this section had better be bulletproof. I anticipate we're looking at a series of `read` operations from the persistent storage (disk, SSD, etc.) and a corresponding set of `write` operations to update the in-memory superblock structure. The order of these operations is critical to maintain consistency. Any data dependencies here are something I need to keep in mind, and the locking strategy needs to be flawless. I'll be paying close attention to any uses of atomic operations or memory barriers, especially if this code is designed to support concurrent access or if we're dealing with a multi-processor environment. Any potential race conditions would be an absolute disaster at this stage. In short, this is where the magic happens and the filesystem comes back from the dead. I'm ready to look for any potential bottlenecks and make sure this critical path is as robust and efficient as possible. Time to dig in! |
| 60/3 | 2026/10/11 16:31 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 1490,
"LineCount": 50
}Results: {
"Contents": "1490:\tEXPORT_SYMBOL(sget_dev);\n1491:\t\n1492:\t#ifdef CONFIG_BLOCK\n1493:\tstatic int fs_super_freeze(struct super_block *sb)\n1494:\t{\n1495:\t\tif (sb-\u003es_op-\u003efreeze_super)\n1496:\t\t\treturn sb-\u003es_op-\u003efreeze_super(sb,\n1497:\t\t\t\t\tFREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n1498:\t\treturn freeze_super(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n1499:\t}\n1500:\t\n1501:\tstatic int fs_super_thaw(struct super_block *sb)\n1502:\t{\n1503:\t\tint error;\n1504:\t\n1505:\t\tif (sb-\u003es_op-\u003ethaw_super) {\n1506:\t\t\terror = sb-\u003es_op-\u003ethaw_super(sb,\n1507:\t\t\t\t\tFREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE, NULL);\n1508:\t\t\t/* -EINVAL means the freeze is gone already. */\n1509:\t\t\tif (error == -EINVAL)\n1510:\t\t\t\treturn 0;\n1511:\t\t\treturn error;\n1512:\t\t}\n1513:\t\n1514:\t\t/* The caller holds an active reference. */\n1515:\t\tif (WARN_ON_ONCE(!super_lock_excl(sb)))\n1516:\t\t\treturn 0;\n1517:\t\n1518:\t\t/* FITHAW or an emergency thaw may have dropped the freeze already. */\n1519:\t\tif (sb-\u003es_writers.frozen != SB_FREEZE_COMPLETE ||\n1520:\t\t !sb-\u003es_writers.freeze_ucount) {\n1521:\t\t\tsuper_unlock_excl(sb);\n1522:\t\t\treturn 0;\n1523:\t\t}\n1524:\t\treturn thaw_super_locked(sb, FREEZE_MAY_NEST | FREEZE_HOLDER_USERSPACE,\n1525:\t\t\t\t\t NULL);\n1526:\t}\n1527:\t\n1528:\tstatic void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)\n1529:\t{\n1530:\t\tstruct super_dev *sb_dev;\n1531:\t\tdev_t dev = bdev-\u003ebd_dev;\n1532:\t\n1533:\t\tmutex_unlock(\u0026bdev-\u003ebd_holder_lock);\n1534:\t\n1535:\t\tfor (sb_dev = super_dev_first(dev); sb_dev; sb_dev = super_dev_next(sb_dev)) {\n1536:\t\t\tstruct super_block *sb = sb_dev-\u003esd_sb;\n1537:\t\n1538:\t\t\tif (!super_lock_shared(sb))\n1539:\t\t\t\tcontinue;\n"
} |
| 61/3 | 2026/10/11 16:31 | llm | kmsan-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31183 output: 34 thoughts: 25 Thoughts: Okay, let's dive into this. I need to get a handle on `fs_bdev_freeze`, specifically lines 1570-1625. I need to understand its function and how it relates to the bigger picture. I'm going to carefully read those lines and identify the core logic, its inputs, outputs, and any potential points of interest. My brain will begin to build a mental model of this critical piece of the filesystem component. I'll be looking for nuances; are there any locking primitives used here? What's the error handling like? Any interactions with the block device itself, and the VFS? I need to analyze those lines and extract all the relevant details. |
| 62/3 | 2026/10/11 16:33 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 1570,
"LineCount": 55
}Results: {
"Contents": "1570:\t\t}\n1571:\t}\n1572:\t\n1573:\t/**\n1574:\t * fs_bdev_freeze - freeze every superblock using a block device\n1575:\t * @bdev: block device\n1576:\t *\n1577:\t * Freeze each live superblock using @bdev. A superblock owning several block\n1578:\t * devices is frozen once per device and stays frozen until all are thawed; the\n1579:\t * block layer nests these freezes so the count stays balanced.\n1580:\t *\n1581:\t * Return: 0, or the error from the one superblock on a single-fs device. When\n1582:\t * several superblocks share @bdev a per-superblock failure is swallowed\n1583:\t * (see below). A sync_blockdev() failure is only reported if no\n1584:\t * live superblock uses @bdev.\n1585:\t */\n1586:\tstatic int fs_bdev_freeze(struct block_device *bdev)\n1587:\t{\n1588:\t\tdev_t dev = bdev-\u003ebd_dev;\n1589:\t\tstruct super_dev *sb_dev;\n1590:\t\tunsigned int count = 0;\n1591:\t\tint error = 0, err;\n1592:\t\n1593:\t\tlockdep_assert_held(\u0026bdev-\u003ebd_fsfreeze_mutex);\n1594:\t\n1595:\t\tmutex_unlock(\u0026bdev-\u003ebd_holder_lock);\n1596:\t\n1597:\t\tfor (sb_dev = super_dev_first(dev); sb_dev; sb_dev = super_dev_next(sb_dev)) {\n1598:\t\t\tif (!get_active_super(sb_dev-\u003esd_sb))\n1599:\t\t\t\tcontinue;\n1600:\t\t\terr = fs_super_freeze(sb_dev-\u003esd_sb);\n1601:\t\t\tif (err \u0026\u0026 !error)\n1602:\t\t\t\terror = err;\n1603:\t\t\tdeactivate_super(sb_dev-\u003esd_sb);\n1604:\t\t\tcount++;\n1605:\t\t}\n1606:\t\n1607:\t\t/*\n1608:\t\t * When several superblocks share the device, keep it frozen even if some\n1609:\t\t * of them failed to freeze and swallow the error: rolling the rest back\n1610:\t\t * via thaw_super() can fail too, so neither is a clear win. A single\n1611:\t\t * filesystem (count == 1) still reports its error.\n1612:\t\t */\n1613:\t\tif (error \u0026\u0026 count \u003e 1)\n1614:\t\t\terror = 0;\n1615:\t\tif (error)\n1616:\t\t\treturn error;\n1617:\t\n1618:\t\t/*\n1619:\t\t * An error tells bdev_freeze() that nothing is frozen and nobody would\n1620:\t\t * ever thaw a superblock frozen above. So only report a failed sync if\n1621:\t\t * no superblock uses the device.\n1622:\t\t */\n1623:\t\terror = sync_blockdev(bdev);\n1624:\t\tif (count)\n"
} |
| 63/3 | 2026/10/11 16:33 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32243 output: 34 thoughts: 50 Thoughts: Here's my summary, as though I'm thinking through this process: **Diving into Superblock Freeze/Thaw in `fs/super.c`** Okay, I need to get a handle on the superblock freeze/thaw mechanisms, so I'll start by pinpointing the relevant code. Let's see... lines 2050 through 2390 in `fs/super.c` should be the sweet spot. That's where I'd expect to find the core functions. My instincts are telling me this will be where all the important work happens. I'm especially interested in understanding the interaction of `sb_freeze_wake`, `may_unfreeze`, `freeze_super`, and `thaw_super_locked`. Those function names give me a pretty good idea, but I need to see the details to confirm my assumptions and get a deeper understanding of the implementation. So let's crack open that file and get to work. I anticipate understanding the locking strategies, potential race conditions, and how these functions interact with other parts of the filesystem stack to ensure data integrity during freeze/thaw operations. |
| 64/3 | 2026/10/11 16:33 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 2100,
"LineCount": 60
}Results: {
"Contents": "2100:\t\n2101:\tstatic void sb_freeze_unlock(struct super_block *sb, int level)\n2102:\t{\n2103:\t\tfor (level--; level \u003e= 0; level--)\n2104:\t\t\tpercpu_up_write(sb-\u003es_writers.rw_sem + level);\n2105:\t}\n2106:\t\n2107:\tstatic inline void sb_freeze_wake(struct super_block *sb)\n2108:\t{\n2109:\t\t/* wake_up_var() needs a full barrier after storing s_writers.frozen. */\n2110:\t\tsmp_mb();\n2111:\t\twake_up_var(\u0026sb-\u003es_writers.frozen);\n2112:\t}\n2113:\t\n2114:\tstatic int wait_for_partially_frozen(struct super_block *sb)\n2115:\t{\n2116:\t\tint ret = 0;\n2117:\t\n2118:\t\tdo {\n2119:\t\t\tunsigned short old = sb-\u003es_writers.frozen;\n2120:\t\n2121:\t\t\tup_write(\u0026sb-\u003es_umount);\n2122:\t\t\tret = wait_var_event_killable(\u0026sb-\u003es_writers.frozen,\n2123:\t\t\t\t\t\t sb-\u003es_writers.frozen != old);\n2124:\t\t\tdown_write(\u0026sb-\u003es_umount);\n2125:\t\t} while (ret == 0 \u0026\u0026\n2126:\t\t\t sb-\u003es_writers.frozen != SB_UNFROZEN \u0026\u0026\n2127:\t\t\t sb-\u003es_writers.frozen != SB_FREEZE_COMPLETE);\n2128:\t\n2129:\t\treturn ret;\n2130:\t}\n2131:\t\n2132:\t#define FREEZE_HOLDERS (FREEZE_HOLDER_KERNEL | FREEZE_HOLDER_USERSPACE)\n2133:\t#define FREEZE_FLAGS (FREEZE_HOLDERS | FREEZE_MAY_NEST | FREEZE_EXCL)\n2134:\t\n2135:\tstatic inline int freeze_inc(struct super_block *sb, enum freeze_holder who)\n2136:\t{\n2137:\t\tWARN_ON_ONCE((who \u0026 ~FREEZE_FLAGS));\n2138:\t\tWARN_ON_ONCE(hweight32(who \u0026 FREEZE_HOLDERS) \u003e 1);\n2139:\t\n2140:\t\tif (who \u0026 FREEZE_HOLDER_KERNEL)\n2141:\t\t\t++sb-\u003es_writers.freeze_kcount;\n2142:\t\tif (who \u0026 FREEZE_HOLDER_USERSPACE)\n2143:\t\t\t++sb-\u003es_writers.freeze_ucount;\n2144:\t\treturn sb-\u003es_writers.freeze_kcount + sb-\u003es_writers.freeze_ucount;\n2145:\t}\n2146:\t\n2147:\tstatic inline int freeze_dec(struct super_block *sb, enum freeze_holder who)\n2148:\t{\n2149:\t\tWARN_ON_ONCE((who \u0026 ~FREEZE_FLAGS));\n2150:\t\tWARN_ON_ONCE(hweight32(who \u0026 FREEZE_HOLDERS) \u003e 1);\n2151:\t\n2152:\t\tif ((who \u0026 FREEZE_HOLDER_KERNEL) \u0026\u0026 sb-\u003es_writers.freeze_kcount)\n2153:\t\t\t--sb-\u003es_writers.freeze_kcount;\n2154:\t\tif ((who \u0026 FREEZE_HOLDER_USERSPACE) \u0026\u0026 sb-\u003es_writers.freeze_ucount)\n2155:\t\t\t--sb-\u003es_writers.freeze_ucount;\n2156:\t\treturn sb-\u003es_writers.freeze_kcount + sb-\u003es_writers.freeze_ucount;\n2157:\t}\n2158:\t\n2159:\tstatic inline bool may_freeze(struct super_block *sb, enum freeze_holder who,\n"
} |
| 65/3 | 2026/10/11 16:33 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33602 output: 34 thoughts: 11 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Analyzing the `may_unfreeze` Function** Right, let's take a look at `may_unfreeze`. I need to understand its logic, its potential edge cases, and how it interacts with the rest of the system. I'm already thinking about its dependencies, both upstream and downstream. Specifically, what conditions trigger it, and what consequences result from it returning `True` or `False`? I'm anticipating that I might need to consider several scenarios to have a complete picture. Are there any implicit assumptions baked into this that need to be explicitly addressed? Is it possible to bypass it under certain conditions, and if so, what are the implications of doing so? |
| 66/3 | 2026/10/11 16:33 | tool | read-file |
0mArgs:{
"File": "fs/super.c",
"FirstLine": 2200,
"LineCount": 40
}Results: {
"Contents": "2200:\t\n2201:\t\tWARN_ON_ONCE((who \u0026 ~FREEZE_FLAGS));\n2202:\t\tWARN_ON_ONCE(hweight32(who \u0026 FREEZE_HOLDERS) \u003e 1);\n2203:\t\n2204:\t\tif (who \u0026 FREEZE_EXCL) {\n2205:\t\t\tif (WARN_ON_ONCE(!(who \u0026 FREEZE_HOLDER_KERNEL)))\n2206:\t\t\t\treturn false;\n2207:\t\t\tif (WARN_ON_ONCE(who \u0026 ~(FREEZE_EXCL | FREEZE_HOLDER_KERNEL)))\n2208:\t\t\t\treturn false;\n2209:\t\t\tif (WARN_ON_ONCE(!freeze_owner))\n2210:\t\t\t\treturn false;\n2211:\t\t\t/* This isn't exclusively frozen. */\n2212:\t\t\tif (!sb-\u003es_writers.freeze_owner)\n2213:\t\t\t\treturn false;\n2214:\t\t\t/* This isn't exclusively frozen by us. */\n2215:\t\t\tif (sb-\u003es_writers.freeze_owner != freeze_owner)\n2216:\t\t\t\treturn false;\n2217:\t\t\t/* An exclusive freeze always holds a kernel reference. */\n2218:\t\t\tif (WARN_ON_ONCE(sb-\u003es_writers.freeze_kcount == 0))\n2219:\t\t\t\treturn false;\n2220:\t\t\t/*\n2221:\t\t\t * This is still frozen multiple times so we're just\n2222:\t\t\t * going to drop our reference count and undo our\n2223:\t\t\t * exclusive freeze.\n2224:\t\t\t */\n2225:\t\t\tif ((sb-\u003es_writers.freeze_kcount + sb-\u003es_writers.freeze_ucount) \u003e 1)\n2226:\t\t\t\tsb-\u003es_writers.freeze_owner = NULL;\n2227:\t\t\treturn true;\n2228:\t\t}\n2229:\t\n2230:\t\tif (who \u0026 FREEZE_HOLDER_KERNEL) {\n2231:\t\t\t/*\n2232:\t\t\t * Someone's trying to steal the reference belonging to\n2233:\t\t\t * @sb-\u003es_writers.freeze_owner.\n2234:\t\t\t */\n2235:\t\t\tif (sb-\u003es_writers.freeze_kcount == 1 \u0026\u0026\n2236:\t\t\t sb-\u003es_writers.freeze_owner)\n2237:\t\t\t\treturn false;\n2238:\t\t\treturn sb-\u003es_writers.freeze_kcount \u003e 0;\n2239:\t\t}\n"
} |
| 67/3 | 2026/10/11 16:33 | llm | kmsan-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34472 output: 174 thoughts: 1244 Thoughts: **Analysis of the Patch Series and KMSAN Applicability** Okay, let's break this down. My initial assessment is that this patch series doesn't necessitate `NeedsKMSAN=true`. It seems focused on fixing synchronization, locking, and VFS state-machine issues, which is distinct from the type of memory safety problems KMSAN is designed to catch. I've examined the changes in detail. * `fs/fs_context.c` has a fix for `vfs_clean_context()`, ensuring the superblock flags mask is cleared appropriately. This is about correctness in VFS state management, not uninitialized memory. * `fs/fserror.c` adds a memory barrier to `fserror_pending_dec()` and includes a check for `SB_BORN` in `fserror_alloc_event()`. This is about synchronization and preventing errors before the superblock is ready, so still not relevant to KMSAN. * `fs/quota/quota.c` addresses a deadlock issue in `quotactl_block()` by replacing `sb_start_write` with `wait_var_event_killable`, specifically for read-only superblocks. This is pure concurrency and locking, not introducing uninitialized memory risks. * `fs/super.c` has multiple changes: preserving the `SB_RDONLY` flag, fixing locking and reference counting in emergency remount, handling errors in `fs_super_thaw()`, correcting sync handling in `fs_bdev_freeze()`, adding a memory barrier in `sb_freeze_wake()`, and reordering a WARN_ON check in `may_unfreeze()`. These are all about locking, reference counting, and VFS state transitions. No uninitialized data exposure here. I've carefully considered the conditions for setting `NeedsKMSAN=true`. This patch series doesn't introduce any new structures copied to user space, doesn't have conditional logic based on potentially uninitialized variables, and no allocations that could lead to uninitialized memory being read. All the variables touched are scalar types, flags, or refcounts which don't require KMSAN. The primary risks here are concurrency issues like deadlocks, locking hierarchy problems, potential superblock reference count errors, and race conditions, all of which are caught by LOCKDEP, KASAN, and general testing. The functional behavior will also be tested, but doesn't require KMSAN. My reasoning is straightforward: these changes deal with synchronization primitives, flags, refcounts, and VFS state transitions. KMSAN would be irrelevant because we're not dealing with uninitialized memory leaks to userspace. The potential problems here are related to concurrency and the VFS state machine, which is well covered by existing debuggers. |
| 68/3 | 2026/10/11 16:36 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series addresses VFS-level filesystem freezing/thawing synchronization, emergency remount locking and lifetime semantics, memory barriers before wait_var wakeups, fserror event allocation checks against SB_BORN, and preserving SB_RDONLY during fs_context reconfiguration.\n\nNone of the changes introduce or modify any kernel-to-user memory copy operations, uninitialized stack/heap allocations, or conditional branches on uninitialized memory. All variables and fields modified are scalar flags, reference counts, or waitqueue primitives. Any potential issues introduced by these changes relate to synchronization, reference counting, or locking, which are well-covered by LOCKDEP and KASAN. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series addresses VFS-level filesystem freezing/thawing synchronization, emergency remount locking and lifetime semantics, memory barriers before wait_var wakeups, fserror event allocation checks against SB_BORN, and preserving SB_RDONLY during fs_context reconfiguration.\n\nNone of the changes introduce or modify any kernel-to-user memory copy operations, uninitialized stack/heap allocations, or conditional branches on uninitialized memory. All variables and fields modified are scalar flags, reference counts, or waitqueue primitives. Any potential issues introduced by these changes relate to synchronization, reference counting, or locking, which are well-covered by LOCKDEP and KASAN. Therefore, 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) |
|---|