Skip to content
Commit 48fa851b authored by Wang Zhaolong's avatar Wang Zhaolong
Browse files

cifs: Fix deadlock in cifs_writepages during reconnect

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAASLU



--------------------------------

When multiple processes or threads write to the same file concurrently,
if a network disruption occurs during the write operation, it may lead
to a deadlock situation as follow:

Process 1 (dd)    Process 2 (cifsd)     Process 3 (cifsiod)
cifs_writepages
 lock_page - [1]
 wait_on_page_writeback - [2] Waiting for writeback, blocked by [4]
  wait_on_page_bit
                  cifs_demultiplex_thread
                  cifs_read_from_socket
                  cifs_readv_from_socket
                  - If another process triggers reconnect at this point
                    cifs_reconnect
                    - mid->mid_state updated to MID_RETRY_NEEDED
                    smb2_writev_callback mid_entry->callback()
                     - mid_state leads to wdata->result = -EAGAIN
                     wdata->result = -EAGAIN
                     queue_work(cifsiod_wq, &wdata->work);
                                     cifs_writev_complete - work function
                                       - Condition satisfied
                                       - wdata->result == -EAGAIN
                                       cifs_writev_requeue
                                         lock_page - [3] Blocked by [1]
                                       end_page_writeback
                                       - [4] Won't execute, blocked by [3]
 unlock_page

Mainline refactoring patch d08089f6 ("cifs: Change the I/O paths to
use an iterator rather than a page list") unlock page while waiting for
the writeback to complete, thus avoiding potential deadlocks caused by
lock ordering issues during reconnection.

Due to the large refactor of the mainline, the patch cannot be backport
directly. Therefore, This patch only uses a part of the idea of the
mainline patch to fix deadlock.

Fixes: c28c89fc ("cifs: add cifs_async_writev")
Signed-off-by: default avatarWang Zhaolong <wangzhaolong1@huawei.com>
parent 8585cfc0
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment