jbd2: make sure jh have b_transaction set in refile/unfile_buffer
Subsystems (6)
Sasha Levin
maintainerPATCH 1/6 jbd2: make sure jh have b_transaction set in refile/unfile_buffer
From: Lukas Czerner <[email protected]>
[ Upstream commit 24dc9864914eb5813173cfa53313fcd02e4aea7d ]
Callers of __jbd2_journal_unfile_buffer() and __jbd2_journal_refile_buffer() assume that the b_transaction is set. In fact if it's not, we can end up with journal_head refcounting errors leading to crash much later that might be very hard to track down. Add asserts to make sure that is the case.
We also make sure that b_next_transaction is NULL in __jbd2_journal_unfile_buffer() since the callers expect that as well and we should not get into that stage in this state anyway, leading to problems later on if we do.
Tested with fstests.
--- fs/jbd2/transaction.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/jbd2/transaction.c +10 -0
@@ -1906,6 +1906,9 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)*/ static void __jbd2_journal_unfile_buffer (struct journal_head *jh) { +J_ASSERT_JH (jh, jh->b_transaction !=NULL ); +J_ASSERT_JH (jh, jh->b_next_transaction ==NULL ); +__jbd2_journal_temp_unlink_buffer (jh); jh->b_transaction =NULL ;jbd2_journal_put_journal_head (jh);
@@ -2453,6 +2456,13 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh) was_dirty =test_clear_buffer_jbddirty (bh);__jbd2_journal_temp_unlink_buffer (jh); + +/* +* b_transaction must be set, otherwise the new b_transaction won't +* be holding jh reference +*/ +J_ASSERT_JH (jh, jh->b_transaction !=NULL ); +/* * We set b_transaction here because b_next_transaction will inherit * our jh reference and thus __jbd2_journal_file_buffer() must not
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 2/6 jbd2: abort journal if free a async write error metadata buffer
From: "zhangyi (F)" <[email protected]>
[ Upstream commit c044f3d8360d2ecf831ba2cc9f08cf9fb2c699fb ]
If we free a metadata buffer which has been failed to async write out in the background, the jbd2 checkpoint procedure will not detect this failure in jbd2_log_do_checkpoint(), so it may lead to filesystem inconsistency after cleanup journal tail. This patch abort the journal if free a buffer has write_io_error flag to prevent potential further inconsistency.
--- fs/jbd2/transaction.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/jbd2/transaction.c +16 -0
@@ -2000,6 +2000,7 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, {struct buffer_head *head;struct buffer_head *bh; +bool has_write_io_error = false;int ret =0 ;J_ASSERT (PageLocked (page));
@@ -2024,11 +2025,26 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal,jbd_unlock_bh_state (bh);if (buffer_jbd (bh)) goto busy; + +/* +* If we free a metadata buffer which has been failed to +* write out, the jbd2 checkpoint procedure will not detect +* this failure and may lead to filesystem inconsistency +* after cleanup journal tail. +*/ +if (buffer_write_io_error (bh)) { +pr_err ("JBD2: Error while async write back metadata bh %llu." , + (unsigned long long )bh->b_blocknr); + has_write_io_error = true; + } }while ((bh = bh->b_this_page) != head); ret =try_to_free_buffers (page); busy: +if (has_write_io_error) +jbd2_journal_abort (journal, -EIO ); +return ret; }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 3/6 s390/cio: add cond_resched() in the slow_eval_known_fn() loop
In reply to Sasha LevinFrom: Vineeth Vijayan <[email protected]>
[ Upstream commit 0b8eb2ee9da1e8c9b8082f404f3948aa82a057b2 ]
The scanning through subchannels during the time of an event could take significant amount of time in case of platforms with lots of known subchannels. This might result in higher scheduling latencies for other tasks especially on systems with a single CPU. Add cond_resched() call, as the loop in slow_eval_known_fn() can be executed for a longer duration.
--- drivers/s390/cio/css.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/s390/cio/css.c +5 -0
@@ -529,6 +529,11 @@ static int slow_eval_known_fn(struct subchannel *sch, void *data) rc =css_evaluate_known_subchannel (sch,1 );if (rc == -EAGAIN )css_schedule_eval (sch->schid); +/* +* The loop might take long time for platforms with lots of +* known devices. Allow scheduling here. +*/ +cond_resched (); }return 0 ; }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 4/6 scsi: ufs: Fix possible infinite loop in ufshcd_hold
In reply to Sasha LevinFrom: Stanley Chu <[email protected]>
[ Upstream commit 93b6c5db06028a3b55122bbb74d0715dd8ca4ae0 ]
In ufshcd_suspend(), after clk-gating is suspended and link is set as Hibern8 state, ufshcd_hold() is still possibly invoked before ufshcd_suspend() returns. For example, MediaTek's suspend vops may issue UIC commands which would call ufshcd_hold() during the command issuing flow.
Now if UFSHCD_CAP_HIBERN8_WITH_CLK_GATING capability is enabled, then ufshcd_hold() may enter infinite loops because there is no clk-ungating work scheduled or pending. In this case, ufshcd_hold() shall just bypass, and keep the link as Hibern8 state.
--- drivers/scsi/ufs/ufshcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd.c +4 -1
@@ -575,6 +575,7 @@ static void ufshcd_ungate_work(struct work_struct *work)int ufshcd_hold (struct ufs_hba *hba,bool async) {int rc =0 ; +bool flush_result;unsigned long flags;if (!ufshcd_is_clkgating_allowed (hba))
@@ -601,7 +602,9 @@ int ufshcd_hold(struct ufs_hba *hba, bool async)break ; }spin_unlock_irqrestore (hba->host->host_lock, flags); -flush_work (&hba->clk_gating.ungate_work); + flush_result =flush_work (&hba->clk_gating.ungate_work); +if (hba->clk_gating.is_suspended && !flush_result) + goto out;spin_lock_irqsave (hba->host->host_lock, flags); goto start; }
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 5/6 net: gianfar: Add of_node_put() before goto statement
In reply to Sasha LevinFrom: Sumera Priyadarsini <[email protected]>
[ Upstream commit 989e4da042ca4a56bbaca9223d1a93639ad11e17 ]
Every iteration of for_each_available_child_of_node() decrements reference count of the previous node, however when control is transferred from the middle of the loop, as in the case of a return or break or goto, there is no decrement thus ultimately resulting in a memory leak.
Fix a potential memory leak in gianfar.c by inserting of_node_put() before the goto statement.
Issue found with Coccinelle.
--- drivers/net/ethernet/freescale/gianfar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/freescale/gianfar.c +3 -1
@@ -845,8 +845,10 @@ static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)continue ; err =gfar_parse_group (child, priv, model); -if (err) +if (err) { +of_node_put (child); goto err_grp_init; + } } }else {/* SQ_SG_MODE */ err =gfar_parse_group (np, priv, model);
Signature · 1 line
2.25.1
Sasha Levin
maintainerPATCH 6/6 powerpc/perf: Fix soft lockups due to missed interrupt accounting
In reply to Sasha LevinFrom: Athira Rajeev <[email protected]>
[ Upstream commit 17899eaf88d689529b866371344c8f269ba79b5f ]
Performance monitor interrupt handler checks if any counter has overflown and calls record_and_restart() in core-book3s which invokes perf_event_overflow() to record the sample information. Apart from creating sample, perf_event_overflow() also does the interrupt and period checks via perf_event_account_interrupt().
Currently we record information only if the SIAR (Sampled Instruction Address Register) valid bit is set (using siar_valid() check) and hence the interrupt check.
But it is possible that we do sampling for some events that are not generating valid SIAR, and hence there is no chance to disable the event if interrupts are more than max_samples_per_tick. This leads to soft lockup.
Fix this by adding perf_event_account_interrupt() in the invalid SIAR code path for a sampling event. ie if SIAR is invalid, just do interrupt check and don't record the sample information.
--- arch/powerpc/perf/core-book3s.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/powerpc/perf/core-book3s.c +4 -0
@@ -2040,6 +2040,10 @@ static void record_and_restart(struct perf_event *event, unsigned long val,if (perf_event_overflow (event, &data, regs))power_pmu_stop (event,0 ); + }else if (period) { +/* Account for interrupt in case of invalid SIAR */ +if (perf_event_account_interrupt (event)) +power_pmu_stop (event,0 ); } }
Signature · 1 line
2.25.1