* [PATCH v2 1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit()
2024-07-24 16:11 [PATCH v2 0/4] ext4: fix incorrect tid assumptions Luis Henriques (SUSE)
@ 2024-07-24 16:11 ` Luis Henriques (SUSE)
2024-07-24 16:30 ` Jan Kara
2024-07-24 16:11 ` [PATCH v2 2/4] ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space() Luis Henriques (SUSE)
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-07-24 16:11 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Jan Kara, Harshad Shirwadkar
Cc: linux-ext4, linux-kernel, Luis Henriques (SUSE)
Function ext4_wait_for_tail_page_commit() assumes that '0' is not a valid
value for transaction IDs, which is incorrect. Don't assume that and invoke
jbd2_log_wait_commit() if the journal had a committing transaction instead.
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
---
fs/ext4/inode.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 941c1c0d5c6e..a0fa5192db8e 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5279,8 +5279,9 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
{
unsigned offset;
journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
- tid_t commit_tid = 0;
+ tid_t commit_tid;
int ret;
+ bool has_transaction;
offset = inode->i_size & (PAGE_SIZE - 1);
/*
@@ -5305,12 +5306,14 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
folio_put(folio);
if (ret != -EBUSY)
return;
- commit_tid = 0;
+ has_transaction = false;
read_lock(&journal->j_state_lock);
- if (journal->j_committing_transaction)
+ if (journal->j_committing_transaction) {
commit_tid = journal->j_committing_transaction->t_tid;
+ has_transaction = true;
+ }
read_unlock(&journal->j_state_lock);
- if (commit_tid)
+ if (has_transaction)
jbd2_log_wait_commit(journal, commit_tid);
}
}
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit()
2024-07-24 16:11 ` [PATCH v2 1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit() Luis Henriques (SUSE)
@ 2024-07-24 16:30 ` Jan Kara
0 siblings, 0 replies; 8+ messages in thread
From: Jan Kara @ 2024-07-24 16:30 UTC (permalink / raw)
To: Luis Henriques (SUSE)
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Harshad Shirwadkar,
linux-ext4, linux-kernel
On Wed 24-07-24 17:11:15, Luis Henriques (SUSE) wrote:
> Function ext4_wait_for_tail_page_commit() assumes that '0' is not a valid
> value for transaction IDs, which is incorrect. Don't assume that and invoke
> jbd2_log_wait_commit() if the journal had a committing transaction instead.
>
> Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/inode.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 941c1c0d5c6e..a0fa5192db8e 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5279,8 +5279,9 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
> {
> unsigned offset;
> journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
> - tid_t commit_tid = 0;
> + tid_t commit_tid;
> int ret;
> + bool has_transaction;
>
> offset = inode->i_size & (PAGE_SIZE - 1);
> /*
> @@ -5305,12 +5306,14 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
> folio_put(folio);
> if (ret != -EBUSY)
> return;
> - commit_tid = 0;
> + has_transaction = false;
> read_lock(&journal->j_state_lock);
> - if (journal->j_committing_transaction)
> + if (journal->j_committing_transaction) {
> commit_tid = journal->j_committing_transaction->t_tid;
> + has_transaction = true;
> + }
> read_unlock(&journal->j_state_lock);
> - if (commit_tid)
> + if (has_transaction)
> jbd2_log_wait_commit(journal, commit_tid);
> }
> }
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space()
2024-07-24 16:11 [PATCH v2 0/4] ext4: fix incorrect tid assumptions Luis Henriques (SUSE)
2024-07-24 16:11 ` [PATCH v2 1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit() Luis Henriques (SUSE)
@ 2024-07-24 16:11 ` Luis Henriques (SUSE)
2024-07-24 16:11 ` [PATCH v2 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list() Luis Henriques (SUSE)
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-07-24 16:11 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Jan Kara, Harshad Shirwadkar
Cc: linux-ext4, linux-kernel, Luis Henriques (SUSE)
Function __jbd2_log_wait_for_space() assumes that '0' is not a valid value
for transaction IDs, which is incorrect. Don't assume that and invoke
jbd2_log_wait_commit() if the journal had a committing transaction instead.
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/jbd2/checkpoint.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 951f78634adf..77bc522e6821 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -79,9 +79,12 @@ __releases(&journal->j_state_lock)
if (space_left < nblocks) {
int chkpt = journal->j_checkpoint_transactions != NULL;
tid_t tid = 0;
+ bool has_transaction = false;
- if (journal->j_committing_transaction)
+ if (journal->j_committing_transaction) {
tid = journal->j_committing_transaction->t_tid;
+ has_transaction = true;
+ }
spin_unlock(&journal->j_list_lock);
write_unlock(&journal->j_state_lock);
if (chkpt) {
@@ -89,7 +92,7 @@ __releases(&journal->j_state_lock)
} else if (jbd2_cleanup_journal_tail(journal) == 0) {
/* We were able to recover space; yay! */
;
- } else if (tid) {
+ } else if (has_transaction) {
/*
* jbd2_journal_commit_transaction() may want
* to take the checkpoint_mutex if JBD2_FLUSHED
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v2 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list()
2024-07-24 16:11 [PATCH v2 0/4] ext4: fix incorrect tid assumptions Luis Henriques (SUSE)
2024-07-24 16:11 ` [PATCH v2 1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit() Luis Henriques (SUSE)
2024-07-24 16:11 ` [PATCH v2 2/4] ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space() Luis Henriques (SUSE)
@ 2024-07-24 16:11 ` Luis Henriques (SUSE)
2024-07-24 16:31 ` Jan Kara
2024-07-24 16:11 ` [PATCH v2 4/4] ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible() Luis Henriques (SUSE)
2024-08-27 12:47 ` [PATCH v2 0/4] ext4: fix incorrect tid assumptions Theodore Ts'o
4 siblings, 1 reply; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-07-24 16:11 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Jan Kara, Harshad Shirwadkar
Cc: linux-ext4, linux-kernel, Luis Henriques (SUSE)
Function jbd2_journal_shrink_checkpoint_list() assumes that '0' is not a
valid value for transaction IDs, which is incorrect. Don't assume that and
use two extra boolean variables to control the loop iterations and keep
track of the first and last tid.
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
---
fs/jbd2/checkpoint.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 77bc522e6821..98a0b2eb84f5 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -410,6 +410,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
tid_t tid = 0;
unsigned long nr_freed = 0;
unsigned long freed;
+ bool first_set = false;
again:
spin_lock(&journal->j_list_lock);
@@ -429,8 +430,10 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
else
transaction = journal->j_checkpoint_transactions;
- if (!first_tid)
+ if (!first_set) {
first_tid = transaction->t_tid;
+ first_set = true;
+ }
last_transaction = journal->j_checkpoint_transactions->t_cpprev;
next_transaction = transaction;
last_tid = last_transaction->t_tid;
@@ -460,7 +463,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
spin_unlock(&journal->j_list_lock);
cond_resched();
- if (*nr_to_scan && next_tid)
+ if (*nr_to_scan && journal->j_shrink_transaction)
goto again;
out:
trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list()
2024-07-24 16:11 ` [PATCH v2 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list() Luis Henriques (SUSE)
@ 2024-07-24 16:31 ` Jan Kara
0 siblings, 0 replies; 8+ messages in thread
From: Jan Kara @ 2024-07-24 16:31 UTC (permalink / raw)
To: Luis Henriques (SUSE)
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Harshad Shirwadkar,
linux-ext4, linux-kernel
On Wed 24-07-24 17:11:17, Luis Henriques (SUSE) wrote:
> Function jbd2_journal_shrink_checkpoint_list() assumes that '0' is not a
> valid value for transaction IDs, which is incorrect. Don't assume that and
> use two extra boolean variables to control the loop iterations and keep
> track of the first and last tid.
>
> Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/checkpoint.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
> index 77bc522e6821..98a0b2eb84f5 100644
> --- a/fs/jbd2/checkpoint.c
> +++ b/fs/jbd2/checkpoint.c
> @@ -410,6 +410,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
> tid_t tid = 0;
> unsigned long nr_freed = 0;
> unsigned long freed;
> + bool first_set = false;
>
> again:
> spin_lock(&journal->j_list_lock);
> @@ -429,8 +430,10 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
> else
> transaction = journal->j_checkpoint_transactions;
>
> - if (!first_tid)
> + if (!first_set) {
> first_tid = transaction->t_tid;
> + first_set = true;
> + }
> last_transaction = journal->j_checkpoint_transactions->t_cpprev;
> next_transaction = transaction;
> last_tid = last_transaction->t_tid;
> @@ -460,7 +463,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journal_t *journal,
> spin_unlock(&journal->j_list_lock);
> cond_resched();
>
> - if (*nr_to_scan && next_tid)
> + if (*nr_to_scan && journal->j_shrink_transaction)
> goto again;
> out:
> trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 4/4] ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible()
2024-07-24 16:11 [PATCH v2 0/4] ext4: fix incorrect tid assumptions Luis Henriques (SUSE)
` (2 preceding siblings ...)
2024-07-24 16:11 ` [PATCH v2 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list() Luis Henriques (SUSE)
@ 2024-07-24 16:11 ` Luis Henriques (SUSE)
2024-08-27 12:47 ` [PATCH v2 0/4] ext4: fix incorrect tid assumptions Theodore Ts'o
4 siblings, 0 replies; 8+ messages in thread
From: Luis Henriques (SUSE) @ 2024-07-24 16:11 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger, Jan Kara, Harshad Shirwadkar
Cc: linux-ext4, linux-kernel, Luis Henriques (SUSE)
Function jbd2_journal_shrink_checkpoint_list() assumes that '0' is not a
valid value for transaction IDs, which is incorrect.
Furthermore, the sbi->s_fc_ineligible_tid handling also makes the same
assumption by being initialised to '0'. Fortunately, the sb flag
EXT4_MF_FC_INELIGIBLE can be used to check whether sbi->s_fc_ineligible_tid
has been previously set instead of comparing it with '0'.
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Reviewed-by: Jan Kara <jack@suse.cz>
---
fs/ext4/fast_commit.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 3926a05eceee..6f4c97bdb2d8 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -339,22 +339,29 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
{
struct ext4_sb_info *sbi = EXT4_SB(sb);
tid_t tid;
+ bool has_transaction = true;
+ bool is_ineligible;
if (ext4_fc_disabled(sb))
return;
- ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
if (handle && !IS_ERR(handle))
tid = handle->h_transaction->t_tid;
else {
read_lock(&sbi->s_journal->j_state_lock);
- tid = sbi->s_journal->j_running_transaction ?
- sbi->s_journal->j_running_transaction->t_tid : 0;
+ if (sbi->s_journal->j_running_transaction)
+ tid = sbi->s_journal->j_running_transaction->t_tid;
+ else
+ has_transaction = false;
read_unlock(&sbi->s_journal->j_state_lock);
}
spin_lock(&sbi->s_fc_lock);
- if (tid_gt(tid, sbi->s_fc_ineligible_tid))
+ is_ineligible = ext4_test_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
+ if (has_transaction &&
+ (!is_ineligible ||
+ (is_ineligible && tid_gt(tid, sbi->s_fc_ineligible_tid))))
sbi->s_fc_ineligible_tid = tid;
+ ext4_set_mount_flag(sb, EXT4_MF_FC_INELIGIBLE);
spin_unlock(&sbi->s_fc_lock);
WARN_ON(reason >= EXT4_FC_REASON_MAX);
sbi->s_fc_stats.fc_ineligible_reason_count[reason]++;
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 0/4] ext4: fix incorrect tid assumptions
2024-07-24 16:11 [PATCH v2 0/4] ext4: fix incorrect tid assumptions Luis Henriques (SUSE)
` (3 preceding siblings ...)
2024-07-24 16:11 ` [PATCH v2 4/4] ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible() Luis Henriques (SUSE)
@ 2024-08-27 12:47 ` Theodore Ts'o
4 siblings, 0 replies; 8+ messages in thread
From: Theodore Ts'o @ 2024-08-27 12:47 UTC (permalink / raw)
To: Andreas Dilger, Jan Kara, Harshad Shirwadkar,
Luis Henriques (SUSE)
Cc: Theodore Ts'o, linux-ext4, linux-kernel
On Wed, 24 Jul 2024 17:11:14 +0100, Luis Henriques (SUSE) wrote:
> As discussed here [1], there are a few places in ext4 and jbd2 code where it
> is assumed that a tid of '0' is not valid. Which isn't true.
>
> This small patchset tries to fix (hopefully!) all these places. Jan Kara
> had already identified the functions that needed to be fixed. I believe
> that the only other issue is the handling of sbi->s_fc_ineligible_tid.
>
> [...]
Applied, thanks!
[1/4] ext4: fix incorrect tid assumption in ext4_wait_for_tail_page_commit()
commit: dd589b0f1445e1ea1085b98edca6e4d5dedb98d0
[2/4] ext4: fix incorrect tid assumption in __jbd2_log_wait_for_space()
commit: 972090651ee15e51abfb2160e986fa050cfc7a40
[3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list()
commit: 7a6443e1dad70281f99f0bd394d7fd342481a632
[4/4] ext4: fix incorrect tid assumption in ext4_fc_mark_ineligible()
commit: ebc4b2c1ac92fc0f8bf3f5a9c285a871d5084a6b
Best regards,
--
Theodore Ts'o <tytso@mit.edu>
^ permalink raw reply [flat|nested] 8+ messages in thread