Skip to contentSkip to conversation

fs: jfs: fix a possible data race in metapage_writepage()

PATCH Superseded Jia-Ju Bai 3 participants 6 messages May 5, 2020 JFS filesystem

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH v2 1/1 fs: jfs: fix a possible data race in metapage_writepage()

The functions metapage_writepage() and lmPostGC() can be concurrently executed in the following call contexts:

Thread1:
metapage_writepage()

Thread2:
lbmIODone()
lmPostGC()

In metapage_writepage():
if (mp->log && !(mp->log->cflag & logGC_PAGEOUT))

In lmPostGC():
spin_lock_irqsave(&log->gclock, flags);
...
log->cflag &= ~logGC_PAGEOUT
...
spin_unlock_irqrestore(&log->gclock, flags);

The memory addresses of mp->log->cflag and log->cflag can be identical, and thus a data race can occur.

This data race is found by our concurrency fuzzer.

Thus use the spin lock "mp->log->gclock" for the assignment of the data structure member "log->cflag" to a local variable in this function implementation.

---
v2:
* Change the description.
Thank Markus Elfring for good advice.

---
 fs/jfs/jfs_metapage.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/jfs/jfs_metapage.c +9 -2
index a2f5338a5ea1..026c11b2572d 100644
@@ -351,6 +351,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
 	unsigned long bio_offset = 0;
 	int offset;
 	int bad_blocks = 0;
+	uint cflag;
 
 	page_start = (sector_t)page->index <<
 		     (PAGE_SHIFT - inode->i_blkbits);
@@ -370,8 +371,14 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
 			 * Make sure this page isn't blocked indefinitely.
 			 * If the journal isn't undergoing I/O, push it
 			 */
-			if (mp->log && !(mp->log->cflag & logGC_PAGEOUT))
-				jfs_flush_journal(mp->log, 0);
+
+			if (mp->log) {
+				spin_lock_irq(&mp->log->gclock);
+				cflag = mp->log->cflag;
+				spin_unlock_irq(&mp->log->gclock);
+				if (!(cflag & logGC_PAGEOUT))
+					jfs_flush_journal(mp->log, 0);
+			}
 			continue;
 		}
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 1 line

This data race is found by our concurrency fuzzer.

* How do you think about to replace the word “is” by “was”?

* Is this analysis tool publicly available?

…

Quoted 2 lines
---
 fs/jfs/jfs_metapage.c | 11 +++++++++--

I suggest to omit the triple dashes before this information.

Regards,
Markus

author
#2 lore raw
Quoted 2 lines · Markus Elfring
Quoted 1 line

This data race is found by our concurrency fuzzer.

* How do you think about to replace the word “is” by “was”?

Okay.

Quoted 1 line

* Is this analysis tool publicly available?

Not yet, because we are still developing this tool...

Quoted 5 lines

…

Quoted 2 lines
---
  fs/jfs/jfs_metapage.c | 11 +++++++++--

I suggest to omit the triple dashes before this information.

Okay, thanks.

Best wishes,
Jia-Ju Bai

#3 lore raw
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

This data race is found by our concurrency fuzzer.

* How do you think about to replace the word “is” by “was”?

Okay.

Can such a positive feedback influence the change descriptions for any of your other patches?

Regards,
Markus

author
#4 lore raw
Quoted 5 lines · Markus Elfring
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

This data race is found by our concurrency fuzzer.

* How do you think about to replace the word “is” by “was”?

Okay.

Can such a positive feedback influence the change descriptions for any of your other patches?

Okay, sure, thanks for the advice.
I will resend my patches for jfs.

Best wishes,
Jia-Ju Bai

#5 lore raw
In reply to Markus Elfring
Quoted 4 lines · Markus Elfring
Quoted 1 line

This data race is found by our concurrency fuzzer.

* How do you think about to replace the word “is” by “was”?

Quoted 8 lines

* Is this analysis tool publicly available?

…

Quoted 2 lines
---
 fs/jfs/jfs_metapage.c | 11 +++++++++--

I suggest to omit the triple dashes before this information.

That's standard. There's no need to the diffstat to persist in the commit message.

Quoted 4 lines

Regards,
Markus