mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
deadlock between mm_sem and tx assign in zfs_write() and page fault
The bug time sequence: 1. thread #1, `zfs_write` assign a txg "n". 2. In a same process, thread #2, mmap page fault (which means the `mm_sem` is hold) occurred, `zfs_dirty_inode` open a txg failed, and wait previous txg "n" completed. 3. thread #1 call `uiomove` to write, however page fault is occurred in `uiomove`, which means it need `mm_sem`, but `mm_sem` is hold by thread #2, so it stuck and can't complete, then txg "n" will not complete. So thread #1 and thread #2 are deadlocked. Reviewed-by: Chunwei Chen <tuxoko@gmail.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Signed-off-by: Grady Wong <grady.w@xtaotech.com> Closes #7939
This commit is contained in:
+21
-3
@@ -650,7 +650,10 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
|
||||
xuio = (xuio_t *)uio;
|
||||
else
|
||||
#endif
|
||||
uio_prefaultpages(MIN(n, max_blksz), uio);
|
||||
if (uio_prefaultpages(MIN(n, max_blksz), uio)) {
|
||||
ZFS_EXIT(zfsvfs);
|
||||
return (SET_ERROR(EFAULT));
|
||||
}
|
||||
|
||||
/*
|
||||
* If in append mode, set the io offset pointer to eof.
|
||||
@@ -808,8 +811,19 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
|
||||
ssize_t tx_bytes;
|
||||
if (abuf == NULL) {
|
||||
tx_bytes = uio->uio_resid;
|
||||
uio->uio_fault_disable = B_TRUE;
|
||||
error = dmu_write_uio_dbuf(sa_get_db(zp->z_sa_hdl),
|
||||
uio, nbytes, tx);
|
||||
if (error == EFAULT) {
|
||||
dmu_tx_commit(tx);
|
||||
if (uio_prefaultpages(MIN(n, max_blksz), uio)) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
} else if (error != 0) {
|
||||
dmu_tx_commit(tx);
|
||||
break;
|
||||
}
|
||||
tx_bytes -= uio->uio_resid;
|
||||
} else {
|
||||
tx_bytes = nbytes;
|
||||
@@ -909,8 +923,12 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
|
||||
ASSERT(tx_bytes == nbytes);
|
||||
n -= nbytes;
|
||||
|
||||
if (!xuio && n > 0)
|
||||
uio_prefaultpages(MIN(n, max_blksz), uio);
|
||||
if (!xuio && n > 0) {
|
||||
if (uio_prefaultpages(MIN(n, max_blksz), uio)) {
|
||||
error = EFAULT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zfs_inode_update(zp);
|
||||
|
||||
Reference in New Issue
Block a user