Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8DADFF34C47 for ; Mon, 13 Apr 2026 11:54:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Type:Content-Transfer-Encoding:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:References:To:MIME-Version:Date: Message-ID:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yLUkvNyUZD5GA1kRG7GYXv1rZi+RlaXGp42ppL+OujU=; b=Z9CbVWLWHJGuB1e3WZZhFXpFOJ UMoWGhdyVrRBHmyksbJYjj5vTZK6kzhsIhFo9CdXsx4EYAQtBo5e6H0kS/I8FtactH1pRRyNhzjL+ SJ3g+16X6R8sJwAqa7Vzfat89HE/jJkuZ1m9wp8eQCx3X6i97cGBortInWUDMJcnSElI=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wCFsA-0007Nv-TQ; Mon, 13 Apr 2026 11:54:34 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wCFs9-0007Np-D4 for linux-f2fs-devel@lists.sourceforge.net; Mon, 13 Apr 2026 11:54:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:To:Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fl6r2Px2FE57kecv4pilGff2O5FFtZl7aLNqsSpgVa4=; b=HdVW3U27B4i2kQo7uX8M+1cyaZ CDyJpEbh0Ott1r66G8f1zsIKLYKeHjiZk47QrKShowX2GYTIV4eIrymeKsof1LSspxcDToQ3SzVfl 2RgLyZNeHvtUHCFVroC6WLRhBzsUwimkosGPu/KajANJNbbtVczVfVcErQVkxB8w5lHA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:To: Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fl6r2Px2FE57kecv4pilGff2O5FFtZl7aLNqsSpgVa4=; b=ZcWkK/BW2UP5cKb3m8Uu/XS7IG gJzs5/QANvJKfZDC/U4ujvIaexBPfm+0EQ9exefoOq0xlkRm7sPFavJ5ozkNRpWTUbkdKDvpZhldl x5di/stqHwwtwRtccqLxkVqm1lpFPv6OYJ3ew+IcQl96q7lhqKYSrAjX6uw88opGgYkU=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wCFs8-0004rn-G1 for linux-f2fs-devel@lists.sourceforge.net; Mon, 13 Apr 2026 11:54:33 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id DAFF660180; Mon, 13 Apr 2026 11:54:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5DFAC116C6; Mon, 13 Apr 2026 11:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776081266; bh=7rzEirGAaiibBl9sqteOnX5vt/DO959nElOqrV0o52M=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=C7Qan1bb6H8XAQqzqQxh59DuBfJ5XozKp94RVvu+WY5jIIi4Grkgh8Zbbz0H+vh6R CUypwbkRCX9JwsiR8WdsNfJsYFW3tWT4F5MuNtwDh4ZHDJ3zxawoRay29PQ5DgvihM tQ/LcwO1bOHau3Ze7nnL6sldQVZmb4IkAYJfdpCErky8f8vnjQlEQGB3Dm78h00aZl qskWixZU9ztdqzCSyafQuqtHsEGPGPwG4e7gUjUigqUffkrGsoLA0nf45QyNlTm/yS d7pmkNwCVPER//wxGexZLqv1K0mYtrqGtO7SrIYfObrCO6xVVYzxYWn8bAp2G8o1mc l6c5p+F2OarsQ== Message-ID: Date: Mon, 13 Apr 2026 19:54:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Xiaosen He , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <20260410105311.3260515-1-xiaosen.he@oss.qualcomm.com> <20260410105311.3260515-2-xiaosen.he@oss.qualcomm.com> Content-Language: en-US In-Reply-To: <20260410105311.3260515-2-xiaosen.he@oss.qualcomm.com> X-Headers-End: 1wCFs8-0004rn-G1 Subject: Re: [f2fs-dev] [PATCH v3 1/1] f2fs: fix deadlock in serializing io X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Chao Yu via Linux-f2fs-devel Reply-To: Chao Yu Cc: can.guo@oss.qualcomm.com Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 4/10/2026 6:53 PM, Xiaosen He wrote: > kworker/u32:7(f2fs writeback thread) was trying to acquire > sbi->writepages, the mutex was already acquired by emulated;0. > kworker/u32:7 tried to flush plugged IO before sleep, during > flushing plug list, kworker/u32:7 got preempted in RCU read-side > critical section and got scheduled out waiting to be woken up by > the release of mutex. emulated;0 was blocked on blk_mq_get_tag > as there was no available tag and expected the previous IO > requests to be handled by UFS host to release tags, but UFS host > was blocked on synchronize_rcu waiting for ending of RCU grace > period. the deadlock was caused by writeback thread was stuck in > RCU critical section waiting for mutex. call blk_flush_plug() if > mutex_trylock(&sbi->writepages) failed, so that the plug list is > empty when blk_flush_plug() is called in sched_submit_work to > fix the deadlock. IMO, look more like a common bug? otherwise, sounds like we can not grab mutex lock w/ mutex_lock directly during writeback in .writepages? > > Task name: kworker/u32:7 [affinity: 0xff] pid: 233 tgid: 233 cpu: 6 prio: 98 start: 0xffffff8099390040 > state: 0x2[D] exit_state: 0x0 stack base: 0xffffffc083c48000 > Last_enqueued_ts: 390.169395877 Last_sleep_ts: 389.756639574 > Stack: > [] __switch_to+0x214 > [] __schedule+0xa30 > [] preempt_schedule_notrace+0x68 > [] rcu_is_watching[jt]+0x5c > [] lock_acquire+0x68 > [] rcu_lock_acquire+0x34 > [] percpu_ref_put_many+0x20 > [] blk_mq_dispatch_list+0x570 > [] blk_mq_flush_plug_list+0x13c > [] __blk_flush_plug+0x11c It tries to flush plug list inside mutex_lock() and then be blocked. Will it cause the same issue w/ your below implementation: if (!mutex_trylock(&sbi->writepages)) blk_flush_plug(((struct task_struct *)current)->plug, true); <--- here ... mutex_lock(&sbi->writepages); Let me know if I'm missing anything. Thanks, > [] sched_submit_work+0x78 > [] schedule+0x38 > [] schedule_preempt_disabled+0x18 > [] __mutex_lock_common+0xab8 > [] mutex_lock_nested+0x2c > [] f2fs_write_data_pages+0xd64 > [] do_writepages+0xd4 > [] __writeback_single_inode+0x78 > [] writeback_sb_inodes+0x2b8 > [] __writeback_inodes_wb+0xa0 > [] wb_writeback+0x188 > [] wb_workfn[jt]+0x438 > [] process_one_work+0x27c > [] worker_thread+0x358 > [] kthread+0x150 > [] ret_from_fork+0x10 > > Task name: kworker/u32:2 [affinity: 0xff] pid: 90 tgid: 90 cpu: 1 prio: 120 start: 0xffffff80adae8040 > state: 0x2[D] exit_state: 0x0 stack base: 0xffffffc080a18000 > Last_enqueued_ts: 389.899608637 Last_sleep_ts: 389.899665303 > Stack: > [] __switch_to+0x214 > [] __schedule+0xa30 > [] schedule+0x48 > [] synchronize_rcu_expedited+0x928 > [] synchronize_rcu[jt]+0x234 > [] blk_mq_quiesce_tagset[jt]+0xa8 > [] ufshcd_devfreq_scale+0x90 > [] ufshcd_devfreq_target+0x204 > [] devfreq_set_target+0xb8 > [] devfreq_update_target[jt]+0xd8 > [] devfreq_monitor+0x38 > [] process_one_work+0x27c > [] worker_thread+0x358 > [] kthread+0x150 > [] ret_from_fork+0x10 > > Task name: emulated;0 [affinity: 0xff] pid: 5245 tgid: 4922 cpu: 6 prio: 120 start: 0xffffff89e2e60040 > state: 0x2[D] exit_state: 0x0 stack base: 0xffffffc0d42f8000 > Last_enqueued_ts: 390.169395877 Last_sleep_ts: 390.178459731 > Stack: > [] __switch_to+0x214 > [] __schedule+0xa30 > [] schedule+0x48 > [] io_schedule+0x38 > [] blk_mq_get_tag+0x1a4 > [] __blk_mq_alloc_requests+0x358 > [] blk_mq_submit_bio+0x50c > [] __submit_bio[jt]+0x164 > [] submit_bio_noacct_nocheck+0x14c > [] submit_bio_noacct+0x330 > [] submit_bio+0x1f4 > [] f2fs_submit_write_bio+0x88 > [] __submit_merged_bio[jt]+0xbc > [] f2fs_submit_page_write+0x400 > [] do_write_page+0x180 > [] f2fs_outplace_write_data+0x78 > [] f2fs_do_write_data_page+0x390 > [] f2fs_write_single_data_page+0x1e0 > [] f2fs_write_data_pages+0x8c0 > [] do_writepages+0xd4 > [] __filemap_fdatawrite_range+0x94 > [] generic_fadvise+0x1d8 > [] f2fs_file_fadvise+0x124 > [] __arm64_sys_fadvise64_64+0x70 > [] invoke_syscall+0x58 > [] el0_svc_common[jt]+0xb8 > [] do_el0_svc+0x1c > [] el0_svc+0x40 > [] el0t_64_sync_handler[jt]+0xd0 > [] ret_to_user[jt]+0x0 > > Signed-off-by: Xiaosen He > --- > fs/f2fs/data.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index 338df7a2aea6..c8e81f63fe73 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -3585,7 +3585,13 @@ static int __f2fs_write_data_pages(struct address_space *mapping, > } > > if (__should_serialize_io(inode, wbc)) { > + if (!mutex_trylock(&sbi->writepages)) > + blk_flush_plug(((struct task_struct *)current)->plug, true); > + else > + goto set_locked; > + > mutex_lock(&sbi->writepages); > +set_locked: > locked = true; > } > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel