Skip to content

Commit bf4baaa

Browse files
author
Kent Overstreet
committed
bcachefs: Fix lockdep splat in bch2_accounting_read
We can't take sb_lock while holding mark_lock, so split out replicas_entry_validate() and replicas_entry_sb_validate() - replicas_entry_validate() now uses the normal online device interface. 00039 ========= TEST set_option 00039 00039 WATCHDOG 30 00040 bcachefs (vdb): starting version 1.12: rebalance_work_acct_fix opts=errors=panic 00040 bcachefs (vdb): initializing new filesystem 00040 bcachefs (vdb): going read-write 00040 bcachefs (vdb): marking superblocks 00040 bcachefs (vdb): initializing freespace 00040 bcachefs (vdb): done initializing freespace 00040 bcachefs (vdb): reading snapshots table 00040 bcachefs (vdb): reading snapshots done 00040 bcachefs (vdb): done starting filesystem 00040 zstd 00041 bcachefs (vdb): shutting down 00041 bcachefs (vdb): going read-only 00041 bcachefs (vdb): finished waiting for writes to stop 00041 bcachefs (vdb): flushing journal and stopping allocators, journal seq 3 00041 bcachefs (vdb): flushing journal and stopping allocators complete, journal seq 11 00041 bcachefs (vdb): shutdown complete, journal seq 12 00041 bcachefs (vdb): marking filesystem clean 00041 bcachefs (vdb): shutdown complete 00041 Setting option on offline fs 00041 bch2_write_super(): fatal error : attempting to write superblock that wasn't version downgraded (1.12: (unknown version) > 1.10: disk_accounting_v3) 00041 fatal error - emergency read only 00041 bch2_write_super(): fatal error : attempting to write superblock that wasn't version downgraded (1.12: (unknown version) > 1.10: disk_accounting_v3) 00042 bcachefs (vdb): starting version 1.12: rebalance_work_acct_fix opts=errors=panic,compression=zstd 00042 bcachefs (vdb): recovering from clean shutdown, journal seq 12 00042 bcachefs (vdb): accounting_read... 00042 00042 ====================================================== 00042 WARNING: possible circular locking dependency detected 00042 6.12.0-rc1-ktest-g805e938a8502 #6807 Not tainted 00042 ------------------------------------------------------ 00042 mount.bcachefs/665 is trying to acquire lock: 00045 ffffff80cc280908 (&c->sb_lock){+.+.}-{3:3}, at: bch2_replicas_entry_validate (fs/bcachefs/replicas.c:102) 00045 00045 but task is already holding lock: 00048 ffffff80cc284870 (&c->mark_lock){++++}-{0:0}, at: bch2_accounting_read (fs/bcachefs/disk_accounting.c:670 (discriminator 1)) 00048 00048 which lock already depends on the new lock. 00048 00048 00048 the existing dependency chain (in reverse order) is: 00048 00048 -> #1 (&c->mark_lock){++++}-{0:0}: 00049 percpu_down_write (kernel/locking/percpu-rwsem.c:232) 00052 bch2_sb_replicas_to_cpu_replicas (fs/bcachefs/replicas.c:583) 00055 bch2_sb_to_fs (fs/bcachefs/super-io.c:614) 00057 bch2_fs_open (fs/bcachefs/super.c:828 fs/bcachefs/super.c:2050) 00060 bch2_fs_get_tree (fs/bcachefs/fs.c:2067) 00062 vfs_get_tree (fs/super.c:1801) 00064 path_mount (fs/namespace.c:3507 fs/namespace.c:3834) 00066 __arm64_sys_mount (fs/namespace.c:3847 fs/namespace.c:4055 fs/namespace.c:4032 fs/namespace.c:4032) 00067 invoke_syscall.constprop.0 (arch/arm64/include/asm/syscall.h:61 arch/arm64/kernel/syscall.c:54) 00068 do_el0_svc (include/linux/thread_info.h:127 (discriminator 2) arch/arm64/kernel/syscall.c:140 (discriminator 2) arch/arm64/kernel/syscall.c:151 (discriminator 2)) 00069 el0_svc (arch/arm64/include/asm/irqflags.h:82 arch/arm64/include/asm/irqflags.h:123 arch/arm64/include/asm/irqflags.h:136 arch/arm64/kernel/entry-common.c:165 arch/arm64/kernel/entry-common.c:178 arch/arm64/kernel/entry-common.c:713) 00069 ========= FAILED TIMEOUT set_option in 30s Signed-off-by: Kent Overstreet <[email protected]>
1 parent 0f25eb4 commit bf4baaa

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

fs/bcachefs/replicas.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ void bch2_replicas_entry_to_text(struct printbuf *out,
6666
prt_printf(out, "]");
6767
}
6868

69-
static int bch2_replicas_entry_validate_locked(struct bch_replicas_entry_v1 *r,
70-
struct bch_sb *sb,
71-
struct printbuf *err)
69+
static int bch2_replicas_entry_sb_validate(struct bch_replicas_entry_v1 *r,
70+
struct bch_sb *sb,
71+
struct printbuf *err)
7272
{
7373
if (!r->nr_devs) {
7474
prt_printf(err, "no devices in entry ");
@@ -98,10 +98,28 @@ int bch2_replicas_entry_validate(struct bch_replicas_entry_v1 *r,
9898
struct bch_fs *c,
9999
struct printbuf *err)
100100
{
101-
mutex_lock(&c->sb_lock);
102-
int ret = bch2_replicas_entry_validate_locked(r, c->disk_sb.sb, err);
103-
mutex_unlock(&c->sb_lock);
104-
return ret;
101+
if (!r->nr_devs) {
102+
prt_printf(err, "no devices in entry ");
103+
goto bad;
104+
}
105+
106+
if (r->nr_required > 1 &&
107+
r->nr_required >= r->nr_devs) {
108+
prt_printf(err, "bad nr_required in entry ");
109+
goto bad;
110+
}
111+
112+
for (unsigned i = 0; i < r->nr_devs; i++)
113+
if (r->devs[i] != BCH_SB_MEMBER_INVALID &&
114+
!bch2_dev_exists(c, r->devs[i])) {
115+
prt_printf(err, "invalid device %u in entry ", r->devs[i]);
116+
goto bad;
117+
}
118+
119+
return 0;
120+
bad:
121+
bch2_replicas_entry_to_text(err, r);
122+
return -BCH_ERR_invalid_replicas_entry;
105123
}
106124

107125
void bch2_cpu_replicas_to_text(struct printbuf *out,
@@ -686,7 +704,7 @@ static int bch2_cpu_replicas_validate(struct bch_replicas_cpu *cpu_r,
686704
struct bch_replicas_entry_v1 *e =
687705
cpu_replicas_entry(cpu_r, i);
688706

689-
int ret = bch2_replicas_entry_validate_locked(e, sb, err);
707+
int ret = bch2_replicas_entry_sb_validate(e, sb, err);
690708
if (ret)
691709
return ret;
692710

0 commit comments

Comments
 (0)