From nobody Tue Mar 15 18:14:09 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4E0511A22EA2; Tue, 15 Mar 2022 18:14:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KJ1kn60cMz57GB; Tue, 15 Mar 2022 18:14:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647368049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=b1VeCDJQANRTz7rxlnWj4ZSj2lkrTzkHBsTqygcRwKA=; b=rNhaDGfgTGCvtHN+67XXDnCX/ijj380QFO9XrhlA9r/PjPSuyMpv3wp2z6K5JhMOfZOCKu cBY5KYn/KwZQwtfGw8s3C/UvKes6aIHQASp46FVtvWNgPc3p6yRuUHyVkrfX7JaoMlBnoe +agpQ58rpayl127EwPGrsHYfdT/i/KVVx/gUAxTg+7rF5qEYCmDVOkTsOWdCmXxoZ4QIeK 3u6UZSL2c/tj1RbR/YSCBwdyaDj4bd0rYzxPmUSkxzeU0ageBZg8u4NidqE5pO8C1fmbe8 AFS+GZUBiQXoB7u+day7NqBVMiTnfAWx534oYBFzXzUz5t2w95OsoDWMrFEdHw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 369BB26936; Tue, 15 Mar 2022 18:14:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22FIE915075030; Tue, 15 Mar 2022 18:14:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22FIE9eM075029; Tue, 15 Mar 2022 18:14:09 GMT (envelope-from git) Date: Tue, 15 Mar 2022 18:14:09 GMT Message-Id: <202203151814.22FIE9eM075029@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 9dc74c5a4b3d - releng/13.0 - Fix handling of errors from dmu_write_uio_dbuf() on FreeBSD List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.0 X-Git-Reftype: branch X-Git-Commit: 9dc74c5a4b3d10b20d14ada2db605d73af8a33f0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647368049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=b1VeCDJQANRTz7rxlnWj4ZSj2lkrTzkHBsTqygcRwKA=; b=wVJDPwOKZTqlE++HKM+KmS4aHzTmreMejf2uJytkKyS1foEwcEpRc+wnfyKSXAyhJbZAUl e6HE/TzsFNNrx6OL3ibcdNqvjQ3icXVTKnosB19pQPGYhGCPZAbadb0y+kQLC/QO6Z8uL5 pVQIgDFVNRs4eHMA9GxWB4PF8+fB4t2CW1r/GsgIorFA+kH+HnXkfmLQDwb+KKy5LMz7Kz BAqCX97Kb65Uc/m9thc37nRwUrRRQmKliZwDh5i7rEfMdYgRkTgkWVdCUmt4EnxFVj56iC 5ogprhweC+Ak7t9qWq5lbICggZQPYWWLmNtD2nQbUIXnfG2UqEwL5uxS10B/5w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647368049; a=rsa-sha256; cv=none; b=xtY4syLQvzMKhjA1boHYeK/MfA/dqza7EmRXqJC+Rxw6zmJZB3ygJZ40RgqjbuYshQ2w6U 3N/0w3eswPrrUw+RFj809hH7W8m20xeOktXyh1Q32DzBIgjgYkD9bbOAHYvhb0vAPx2Iz8 Key3CTEc3zLpQmS4cTeYt2SKdQ5pruyocPu442eYQCxMkZXzMxDEvCyOCfs2N4JZN1dLqd 05lTv3QKQWJw1Qmv0nacSuzdPN6o3VUCcEpq+JpbmGPX9bflUA4ZriI7wXpKt6pzxq9qQ+ GXIXlhZQaZDegXO3+7T3xYx8SscvsF3v/AvBEqeDW4i3kHhFLY0Ul4XmX99mPQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9dc74c5a4b3d10b20d14ada2db605d73af8a33f0 commit 9dc74c5a4b3d10b20d14ada2db605d73af8a33f0 Author: Mark Johnston AuthorDate: 2022-01-21 19:54:05 +0000 Commit: Mark Johnston CommitDate: 2022-03-15 18:09:52 +0000 Fix handling of errors from dmu_write_uio_dbuf() on FreeBSD FreeBSD's implementation of zfs_uio_fault_move() returns EFAULT when a page fault occurs while copying data in or out of user buffers. The VFS treats such errors specially and will retry the I/O operation (which may have made some partial progress). When the FreeBSD and Linux implementations of zfs_write() were merged, the handling of errors from dmu_write_uio_dbuf() changed such that EFAULT is not handled as a partial write. For example, when appending to a file, the z_size field of the znode is not updated after a partial write resulting in EFAULT. Restore the old handling of errors from dmu_write_uio_dbuf() to fix this. This should have no impact on Linux, which has special handling for EFAULT already. Reviewed-by: Andriy Gapon Reviewed-by: Ryan Moeller Signed-off-by: Mark Johnston Closes #12964 (cherry picked from commit 063daa8350d4a78f96d1ee6550910363fd3756fb) (cherry picked from commit b55a7f3422d76a6765716b2b6e78967bd75199c9) Approved by: so Security: FreeBSD-EN-22:10.zfs --- sys/contrib/openzfs/module/zfs/zfs_vnops.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/contrib/openzfs/module/zfs/zfs_vnops.c b/sys/contrib/openzfs/module/zfs/zfs_vnops.c index 2dcc231b30b6..79128ed4b89f 100644 --- a/sys/contrib/openzfs/module/zfs/zfs_vnops.c +++ b/sys/contrib/openzfs/module/zfs/zfs_vnops.c @@ -316,7 +316,7 @@ out: int zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr) { - int error = 0; + int error = 0, error1; ssize_t start_resid = uio->uio_resid; /* @@ -551,7 +551,11 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr) continue; } #endif - if (error != 0) { + /* + * On FreeBSD, EFAULT should be propagated back to the + * VFS, which will handle faulting and will retry. + */ + if (error != 0 && error != EFAULT) { dmu_tx_commit(tx); break; } @@ -635,7 +639,7 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr) while ((end_size = zp->z_size) < uio->uio_loffset) { (void) atomic_cas_64(&zp->z_size, end_size, uio->uio_loffset); - ASSERT(error == 0); + ASSERT(error == 0 || error == EFAULT); } /* * If we are replaying and eof is non zero then force @@ -645,7 +649,10 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr) if (zfsvfs->z_replay && zfsvfs->z_replay_eof != 0) zp->z_size = zfsvfs->z_replay_eof; - error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx); + error1 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx); + if (error1 != 0) + /* Avoid clobbering EFAULT. */ + error = error1; zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag, NULL, NULL);