[PATCH] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start()

11 views
Skip to first unread message

Camila Alvarez

unread,
May 15, 2024, 9:53:34 PMMay 15
to syzbot+10b936...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, Camila Alvarez
#syz test
Values were left as the next possible sequence number when there were no
entries.

The fix involves updating the last_seq initial value and
setting last_empty_seq to cur_seq - 1.

Signed-off-by: Camila Alvarez <cam.al...@gmail.com>
---
fs/bcachefs/journal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index adec8e1ea73e..3835c458eec9 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -1196,7 +1196,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
struct journal_replay *i, **_i;
struct genradix_iter iter;
bool had_entries = false;
- u64 last_seq = cur_seq, nr, seq;
+ u64 last_seq = cur_seq - 1, nr, seq;

genradix_for_each_reverse(&c->journal_entries, iter, _i) {
i = *_i;
@@ -1256,7 +1256,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
}

if (!had_entries)
- j->last_empty_seq = cur_seq;
+ j->last_empty_seq = cur_seq - 1;

spin_lock(&j->lock);

--
2.34.1

syzbot

unread,
May 15, 2024, 11:15:08 PMMay 15
to cam.al...@gmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+10b936...@syzkaller.appspotmail.com

Tested on:

commit: 82d92a9a Add linux-next specific files for 20240515
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=11c02034980000
kernel config: https://syzkaller.appspot.com/x/.config?x=a6e710494e484d15
dashboard link: https://syzkaller.appspot.com/bug?extid=10b936c5eaee2819b49b
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=128d04f4980000

Note: testing is done by a robot and is best-effort only.

Camila Alvarez

unread,
May 19, 2024, 10:34:04 PMMay 19
to syzbot+10b936...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, Camila Alvarez
#syz test
Values were left as the next possible sequence number when there were no
entries.

The fix involves updating the last_seq initial value and
setting last_empty_seq to cur_seq - 1.

Signed-off-by: Camila Alvarez <cam.al...@gmail.com>
---
fs/bcachefs/journal.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index adec8e1ea73e..99fc32f0382d 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -1195,8 +1195,8 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
struct journal_entry_pin_list *p;
struct journal_replay *i, **_i;
struct genradix_iter iter;
- bool had_entries = false;
- u64 last_seq = cur_seq, nr, seq;
+ bool had_entries = false;
+ u64 last_written_seq = cur_seq - 1, last_seq = cur_seq - 1, nr, seq;

genradix_for_each_reverse(&c->journal_entries, iter, _i) {
i = *_i;
@@ -1204,11 +1204,11 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
if (journal_replay_ignore(i))
continue;

- last_seq = le64_to_cpu(i->j.last_seq);
+ last_written_seq = le64_to_cpu(i->j.last_seq);
break;
}

- nr = cur_seq - last_seq;
+ nr = cur_seq - last_written_seq;

if (nr + 1 > j->pin.size) {
free_fifo(&j->pin);
@@ -1219,14 +1219,14 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
}
}

- j->replay_journal_seq = last_seq;
+ j->replay_journal_seq = last_written_seq;
j->replay_journal_seq_end = cur_seq;
- j->last_seq_ondisk = last_seq;
- j->flushed_seq_ondisk = cur_seq - 1;
- j->seq_ondisk = cur_seq - 1;
- j->pin.front = last_seq;
+ j->last_seq_ondisk = last_written_seq;
+ j->flushed_seq_ondisk = last_seq;
+ j->seq_ondisk = last_seq;
+ j->pin.front = last_written_seq;
j->pin.back = cur_seq;
- atomic64_set(&j->seq, cur_seq - 1);
+ atomic64_set(&j->seq, last_seq);

fifo_for_each_entry_ptr(p, &j->pin, seq)
journal_pin_list_init(p, 1);
@@ -1256,7 +1256,7 @@ int bch2_fs_journal_start(struct journal *j, u64 cur_seq)
}

if (!had_entries)
- j->last_empty_seq = cur_seq;
+ j->last_empty_seq = last_seq;

spin_lock(&j->lock);

--
2.34.1

syzbot

unread,
May 19, 2024, 11:09:04 PMMay 19
to cam.al...@gmail.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+10b936...@syzkaller.appspotmail.com

Tested on:

commit: c7596217 Add linux-next specific files for 20240517
git tree: linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=10a2eedc980000
kernel config: https://syzkaller.appspot.com/x/.config?x=fba88766130220e8
dashboard link: https://syzkaller.appspot.com/bug?extid=10b936c5eaee2819b49b
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=110469e0980000
Reply all
Reply to author
Forward
0 new messages