From nobody Mon Feb 21 15:13:30 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 EAC0419CFFA6; Mon, 21 Feb 2022 15:13:30 +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 4K2QmV5RN8z4Ty6; Mon, 21 Feb 2022 15:13:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645456410; 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=b82KIi2D1VUDO/xNUFCdo1/5enakMxDwm+znxvfgKa0=; b=Ahk2VnKJSKnSVtjyKdOUGqI3+JgbarXAe7QUSTbxwdK0U/ZVW1G1bRlfMqHp4tjb7CRi2i 3RrosWA6oph25aPg3nWlCf1pN+pYh/DlqQyDLSt8qcq9u7AHJkXHY9nI/iqJsn4XwW3WLt DCuVKsUNcNDn7jxodeXOvzPwl1+DWG1Q+SugIuUcqlb8nNnUetmULFlQXkKrDno5pL7ly5 ijA3blij1RyIk8dy8HnlKwuBU51dm0JzeZY6GMp85dpuPX7mphbvz8DhRzjJ/tXviYBymW p1dbUv8F51XglBavoqHnHRXc4aokf3VU+QylFmVIHZqorKiewZHk+KT+om80Vg== 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 994F01283C; Mon, 21 Feb 2022 15:13:30 +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 21LFDU4G013921; Mon, 21 Feb 2022 15:13:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21LFDUVI013920; Mon, 21 Feb 2022 15:13:30 GMT (envelope-from git) Date: Mon, 21 Feb 2022 15:13:30 GMT Message-Id: <202202211513.21LFDUVI013920@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: b55a7f3422d7 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: b55a7f3422d76a6765716b2b6e78967bd75199c9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645456410; 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=b82KIi2D1VUDO/xNUFCdo1/5enakMxDwm+znxvfgKa0=; b=HYfg4xqWUckaIvMZ7ASuYJiRiekER/nVvbXMIT+Tb2TAwOaSmO4ykeH15A+PbKdHLGozx8 VsauJNjsK8UGuS1IK85wInozTR7pxmDOiVr+8MYAGEkeeAWzq6t3UAE3XE/BIn53V1OSb6 Gjn8xDkeFGsad16UtpU/yway/LY+IaSC+KQ/eTJdh2IMRfxbuvdarloquZhDC4P+gJuCvE ka5HclhfOh2KhGR/TIwU4xFzjKahk33MQukmhIjVcUpe+qe+JJWscxsvUEDXopqvThEHsi fTxsPZtrgjVjgAdodhrrjZQoBK0NAYq2r4m8zeZVsJB154Ko3m7pZgAA5OnJ0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645456410; a=rsa-sha256; cv=none; b=ftsOVj4GFxP7vbfQdbdwXCwBVsOF7sT1MjnrGw15n0Mi5Kk5gWG20DZG58DLNdctTlcsag zTHcyLtUFJgD9xzrGz4gBO6DY7d8nvmBqrl59PZ9Jbeb1MplLFoJMIqC0XzrxBues1ID8/ K1i8aAmEFfukPek7/8ds4eWo5ypaT6tpizak9YqalW4dd2pyu1ROSJ1gkct+jEQz79U89f uebJSCXbbQiR74t4We5dK53vixzD8pOzxmQLGyKXlhyO9w7qQFIVRoQnGvf85kRDlZ0M5a 4AlN199HHFHT41biYNsMnYktX7JSTeDS7JG2795gIT8mhvoRIGRbLV4MlwXnVw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b55a7f3422d76a6765716b2b6e78967bd75199c9 commit b55a7f3422d76a6765716b2b6e78967bd75199c9 Author: Mark Johnston AuthorDate: 2022-01-21 19:54:05 +0000 Commit: Mark Johnston CommitDate: 2022-02-21 14:59:58 +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) --- 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 170e392abe93..54749810d45d 100644 --- a/sys/contrib/openzfs/module/zfs/zfs_vnops.c +++ b/sys/contrib/openzfs/module/zfs/zfs_vnops.c @@ -323,7 +323,7 @@ out: int zfs_write(znode_t *zp, zfs_uio_t *uio, int ioflag, cred_t *cr) { - int error = 0; + int error = 0, error1; ssize_t start_resid = zfs_uio_resid(uio); /* @@ -561,7 +561,11 @@ zfs_write(znode_t *zp, zfs_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; } @@ -645,7 +649,7 @@ zfs_write(znode_t *zp, zfs_uio_t *uio, int ioflag, cred_t *cr) while ((end_size = zp->z_size) < zfs_uio_offset(uio)) { (void) atomic_cas_64(&zp->z_size, end_size, zfs_uio_offset(uio)); - ASSERT(error == 0); + ASSERT(error == 0 || error == EFAULT); } /* * If we are replaying and eof is non zero then force @@ -655,7 +659,10 @@ zfs_write(znode_t *zp, zfs_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);