2021-04-07 07:13:27

by Jan Kara

[permalink] [raw]
Subject: [PATCH 1/2] ext4: Annotate data race in start_this_handle()

Access to journal->j_running_transaction is not protected by appropriate
lock and thus is racy. We are well aware of that and the code handles
the race properly. Just add a comment and data_race() annotation.

Reported-by: [email protected]
Signed-off-by: Jan Kara <[email protected]>
---
fs/jbd2/transaction.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 9396666b7314..398d1d9209e2 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -349,7 +349,12 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
}

alloc_transaction:
- if (!journal->j_running_transaction) {
+ /*
+ * This check is racy but it is just an optimization of allocating new
+ * transaction early if there are high chances we'll need it. If we
+ * guess wrong, we'll retry or free unused transaction.
+ */
+ if (!data_race(journal->j_running_transaction)) {
/*
* If __GFP_FS is not present, then we may be being called from
* inside the fs writeback layer, so we MUST NOT fail.
--
2.26.2


2021-04-10 01:24:53

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 1/2] ext4: Annotate data race in start_this_handle()

On Tue, Apr 06, 2021 at 06:17:59PM +0200, Jan Kara wrote:
> Access to journal->j_running_transaction is not protected by appropriate
> lock and thus is racy. We are well aware of that and the code handles
> the race properly. Just add a comment and data_race() annotation.
>
> Reported-by: [email protected]
> Signed-off-by: Jan Kara <[email protected]>

Thanks, applied.

- Ted