Hello Kent Overstreet,
The patch 93a640e2570b: "bcachefs: GFP_NOIO -> GFP_NOFS" from May 28,
2023 (linux-next), leads to the following Smatch static checker
warning:
fs/bcachefs/journal_io.c:1461 journal_buf_realloc() warn: sleeping in atomic
context
fs/bcachefs/journal_io.c:1662 bch2_journal_entries_postprocess() warn: sleeping
in atomic context
fs/bcachefs/journal_io.c:1764 bch2_journal_write() warn: sleeping in atomic
context
fs/bcachefs/journal_io.c:788 jset_validate() warn: sleeping in atomic context
fs/bcachefs/replicas.c:439 bch2_mark_replicas() warn: sleeping in atomic context
All this sleeping in atomic warnings start in journal_write_done()
where it takes spin_lock(&j->lock) so preempt is disabled.
The call tree for the first warning is:
journal_write_done() <- disables preempt
-> bch2_journal_write()
-> journal_buf_realloc()
fs/bcachefs/journal_io.c
1452 static void journal_buf_realloc(struct journal *j, struct journal_buf
*buf)
1453 {
1454 /* we aren't holding j->lock: */
1455 unsigned new_size = READ_ONCE(j->buf_size_want);
1456 void *new_buf;
1457
1458 if (buf->buf_size >= new_size)
1459 return;
1460
--> 1461 new_buf = kvpmalloc(new_size, GFP_NOFS|__GFP_NOWARN);
This sleeps. GFP_NOWAIT and GFP_ATOMIC don't sleep. But kvpmalloc() is
always going to have to be treated as a sleeping function because it
allocates giant amounts of memory.
1462 if (!new_buf)
1463 return;
1464
1465 memcpy(new_buf, buf->data, buf->buf_size);
1466
1467 spin_lock(&j->lock);
1468 swap(buf->data, new_buf);
1469 swap(buf->buf_size, new_size);
1470 spin_unlock(&j->lock);
1471
1472 kvpfree(new_buf, new_size);
1473 }
regards,
dan carpenter