From: Greg Kroah-Hartman Date: Mon, 25 Apr 2022 13:26:02 +0000 (+0200) Subject: 5.10-stable patches X-Git-Tag: v4.9.312~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b320d698f7ae2a81cd2fa7eb52fb108dac2adcd0;p=thirdparty%2Fkernel%2Fstable-queue.git 5.10-stable patches added patches: jbd2-fix-a-potential-race-while-discarding-reserved-buffers-after-an-abort.patch spi-atmel-quadspi-fix-the-buswidth-adjustment-between-spi-mem-and-controller.patch --- diff --git a/queue-5.10/jbd2-fix-a-potential-race-while-discarding-reserved-buffers-after-an-abort.patch b/queue-5.10/jbd2-fix-a-potential-race-while-discarding-reserved-buffers-after-an-abort.patch new file mode 100644 index 00000000000..f190b2a1500 --- /dev/null +++ b/queue-5.10/jbd2-fix-a-potential-race-while-discarding-reserved-buffers-after-an-abort.patch @@ -0,0 +1,116 @@ +From 23e3d7f7061f8682c751c46512718f47580ad8f0 Mon Sep 17 00:00:00 2001 +From: Ye Bin +Date: Thu, 17 Mar 2022 22:21:37 +0800 +Subject: jbd2: fix a potential race while discarding reserved buffers after an abort + +From: Ye Bin + +commit 23e3d7f7061f8682c751c46512718f47580ad8f0 upstream. + +we got issue as follows: +[ 72.796117] EXT4-fs error (device sda): ext4_journal_check_start:83: comm fallocate: Detected aborted journal +[ 72.826847] EXT4-fs (sda): Remounting filesystem read-only +fallocate: fallocate failed: Read-only file system +[ 74.791830] jbd2_journal_commit_transaction: jh=0xffff9cfefe725d90 bh=0x0000000000000000 end delay +[ 74.793597] ------------[ cut here ]------------ +[ 74.794203] kernel BUG at fs/jbd2/transaction.c:2063! +[ 74.794886] invalid opcode: 0000 [#1] PREEMPT SMP PTI +[ 74.795533] CPU: 4 PID: 2260 Comm: jbd2/sda-8 Not tainted 5.17.0-rc8-next-20220315-dirty #150 +[ 74.798327] RIP: 0010:__jbd2_journal_unfile_buffer+0x3e/0x60 +[ 74.801971] RSP: 0018:ffffa828c24a3cb8 EFLAGS: 00010202 +[ 74.802694] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000 +[ 74.803601] RDX: 0000000000000001 RSI: ffff9cfefe725d90 RDI: ffff9cfefe725d90 +[ 74.804554] RBP: ffff9cfefe725d90 R08: 0000000000000000 R09: ffffa828c24a3b20 +[ 74.805471] R10: 0000000000000001 R11: 0000000000000001 R12: ffff9cfefe725d90 +[ 74.806385] R13: ffff9cfefe725d98 R14: 0000000000000000 R15: ffff9cfe833a4d00 +[ 74.807301] FS: 0000000000000000(0000) GS:ffff9d01afb00000(0000) knlGS:0000000000000000 +[ 74.808338] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +[ 74.809084] CR2: 00007f2b81bf4000 CR3: 0000000100056000 CR4: 00000000000006e0 +[ 74.810047] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 +[ 74.810981] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 +[ 74.811897] Call Trace: +[ 74.812241] +[ 74.812566] __jbd2_journal_refile_buffer+0x12f/0x180 +[ 74.813246] jbd2_journal_refile_buffer+0x4c/0xa0 +[ 74.813869] jbd2_journal_commit_transaction.cold+0xa1/0x148 +[ 74.817550] kjournald2+0xf8/0x3e0 +[ 74.819056] kthread+0x153/0x1c0 +[ 74.819963] ret_from_fork+0x22/0x30 + +Above issue may happen as follows: + write truncate kjournald2 +generic_perform_write + ext4_write_begin + ext4_walk_page_buffers + do_journal_get_write_access ->add BJ_Reserved list + ext4_journalled_write_end + ext4_walk_page_buffers + write_end_fn + ext4_handle_dirty_metadata + ***************JBD2 ABORT************** + jbd2_journal_dirty_metadata + -> return -EROFS, jh in reserved_list + jbd2_journal_commit_transaction + while (commit_transaction->t_reserved_list) + jh = commit_transaction->t_reserved_list; + truncate_pagecache_range + do_invalidatepage + ext4_journalled_invalidatepage + jbd2_journal_invalidatepage + journal_unmap_buffer + __dispose_buffer + __jbd2_journal_unfile_buffer + jbd2_journal_put_journal_head ->put last ref_count + __journal_remove_journal_head + bh->b_private = NULL; + jh->b_bh = NULL; + jbd2_journal_refile_buffer(journal, jh); + bh = jh2bh(jh); + ->bh is NULL, later will trigger null-ptr-deref + journal_free_journal_head(jh); + +After commit 96f1e0974575, we no longer hold the j_state_lock while +iterating over the list of reserved handles in +jbd2_journal_commit_transaction(). This potentially allows the +journal_head to be freed by journal_unmap_buffer while the commit +codepath is also trying to free the BJ_Reserved buffers. Keeping +j_state_lock held while trying extends hold time of the lock +minimally, and solves this issue. + +Fixes: 96f1e0974575("jbd2: avoid long hold times of j_state_lock while committing a transaction") +Signed-off-by: Ye Bin +Reviewed-by: Jan Kara +Link: https://lore.kernel.org/r/20220317142137.1821590-1-yebin10@huawei.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +--- + fs/jbd2/commit.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +--- a/fs/jbd2/commit.c ++++ b/fs/jbd2/commit.c +@@ -501,7 +501,6 @@ void jbd2_journal_commit_transaction(jou + } + spin_unlock(&commit_transaction->t_handle_lock); + commit_transaction->t_state = T_SWITCH; +- write_unlock(&journal->j_state_lock); + + J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <= + journal->j_max_transaction_buffers); +@@ -521,6 +520,8 @@ void jbd2_journal_commit_transaction(jou + * has reserved. This is consistent with the existing behaviour + * that multiple jbd2_journal_get_write_access() calls to the same + * buffer are perfectly permissible. ++ * We use journal->j_state_lock here to serialize processing of ++ * t_reserved_list with eviction of buffers from journal_unmap_buffer(). + */ + while (commit_transaction->t_reserved_list) { + jh = commit_transaction->t_reserved_list; +@@ -540,6 +541,7 @@ void jbd2_journal_commit_transaction(jou + jbd2_journal_refile_buffer(journal, jh); + } + ++ write_unlock(&journal->j_state_lock); + /* + * Now try to drop any written-back buffers from the journal's + * checkpoint lists. We do this *before* commit because it potentially diff --git a/queue-5.10/series b/queue-5.10/series index 43d2d819bbd..4147022e355 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -79,3 +79,5 @@ ext4-doc-fix-incorrect-h_reserved-size.patch ext4-fix-overhead-calculation-to-account-for-the-reserved-gdt-blocks.patch ext4-force-overhead-calculation-if-the-s_overhead_cluster-makes-no-sense.patch can-isotp-stop-timeout-monitoring-when-no-first-frame-was-sent.patch +jbd2-fix-a-potential-race-while-discarding-reserved-buffers-after-an-abort.patch +spi-atmel-quadspi-fix-the-buswidth-adjustment-between-spi-mem-and-controller.patch diff --git a/queue-5.10/spi-atmel-quadspi-fix-the-buswidth-adjustment-between-spi-mem-and-controller.patch b/queue-5.10/spi-atmel-quadspi-fix-the-buswidth-adjustment-between-spi-mem-and-controller.patch new file mode 100644 index 00000000000..4df3f04e930 --- /dev/null +++ b/queue-5.10/spi-atmel-quadspi-fix-the-buswidth-adjustment-between-spi-mem-and-controller.patch @@ -0,0 +1,34 @@ +From 8c235cc25087495c4288d94f547e9d3061004991 Mon Sep 17 00:00:00 2001 +From: Tudor Ambarus +Date: Wed, 6 Apr 2022 16:36:03 +0300 +Subject: spi: atmel-quadspi: Fix the buswidth adjustment between spi-mem and controller + +From: Tudor Ambarus + +commit 8c235cc25087495c4288d94f547e9d3061004991 upstream. + +Use the spi_mem_default_supports_op() core helper in order to take into +account the buswidth specified by the user in device tree. + +Cc: +Fixes: 0e6aae08e9ae ("spi: Add QuadSPI driver for Atmel SAMA5D2") +Signed-off-by: Tudor Ambarus +Link: https://lore.kernel.org/r/20220406133604.455356-1-tudor.ambarus@microchip.com +Signed-off-by: Mark Brown +Signed-off-by: Greg Kroah-Hartman +--- + drivers/spi/atmel-quadspi.c | 3 +++ + 1 file changed, 3 insertions(+) + +--- a/drivers/spi/atmel-quadspi.c ++++ b/drivers/spi/atmel-quadspi.c +@@ -277,6 +277,9 @@ static int atmel_qspi_find_mode(const st + static bool atmel_qspi_supports_op(struct spi_mem *mem, + const struct spi_mem_op *op) + { ++ if (!spi_mem_default_supports_op(mem, op)) ++ return false; ++ + if (atmel_qspi_find_mode(op) < 0) + return false; +