* [PATCH] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start()
@ 2024-05-16 3:19 Camila Alvarez
2024-05-19 18:25 ` Kent Overstreet
0 siblings, 1 reply; 3+ messages in thread
From: Camila Alvarez @ 2024-05-16 3:19 UTC (permalink / raw)
To: Kent Overstreet
Cc: Brian Foster, linux-bcachefs, linux-kernel, Camila Alvarez,
syzbot+10b936c5eaee2819b49b
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.
Reported-by: syzbot+10b936c5eaee2819b49b@syzkaller.appspotmail.com
Signed-off-by: Camila Alvarez <cam.alvarez.i@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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start()
2024-05-16 3:19 [PATCH] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start() Camila Alvarez
@ 2024-05-19 18:25 ` Kent Overstreet
2024-05-20 2:42 ` Camila Alvarez Inostroza
0 siblings, 1 reply; 3+ messages in thread
From: Kent Overstreet @ 2024-05-19 18:25 UTC (permalink / raw)
To: Camila Alvarez
Cc: Brian Foster, linux-bcachefs, linux-kernel, syzbot+10b936c5eaee2819b49b
On Wed, May 15, 2024 at 11:19:20PM -0400, Camila Alvarez wrote:
> 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.
I think this is correct, but we should try to come up with some better
assertions or something to make the code clearer; we don't want off by
ones to lurk so easily.
Could you give it some thought?
>
> Reported-by: syzbot+10b936c5eaee2819b49b@syzkaller.appspotmail.com
> Signed-off-by: Camila Alvarez <cam.alvarez.i@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
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start()
2024-05-19 18:25 ` Kent Overstreet
@ 2024-05-20 2:42 ` Camila Alvarez Inostroza
0 siblings, 0 replies; 3+ messages in thread
From: Camila Alvarez Inostroza @ 2024-05-20 2:42 UTC (permalink / raw)
To: Kent Overstreet
Cc: Camila Alvarez, Brian Foster, linux-bcachefs, linux-kernel,
syzbot+10b936c5eaee2819b49b
On Sun, 19 May 2024, Kent Overstreet wrote:
> On Wed, May 15, 2024 at 11:19:20PM -0400, Camila Alvarez wrote:
>> 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.
>
> I think this is correct, but we should try to come up with some better
> assertions or something to make the code clearer; we don't want off by
> ones to lurk so easily.
>
> Could you give it some thought?
>
You're right. I think the code is written in a confusing way. In
particular it seems that cur_seq - 1 is used all over the place.
I believe we can abstract cur_seq - 1 in an independent variable (since
it represents the actual last sequence number), that should make it
clearer.
I'll share an updated version of the patch.
Thanks for the response!
>>
>> Reported-by: syzbot+10b936c5eaee2819b49b@syzkaller.appspotmail.com
>> Signed-off-by: Camila Alvarez <cam.alvarez.i@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
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-20 2:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-16 3:19 [PATCH] bcachefs: fix last_seq and last_empty_seq in bch2_fs_journal_start() Camila Alvarez
2024-05-19 18:25 ` Kent Overstreet
2024-05-20 2:42 ` Camila Alvarez Inostroza
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®