From nobody Mon Oct 20 19:17:59 2025 X-Original-To: dev-commits-src-all@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 4cr4vX2LZvz6CyHZ; Mon, 20 Oct 2025 19:18:00 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cr4vW5c00z487J; Mon, 20 Oct 2025 19:17:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760987879; 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=DpCa7JHbkgx1HyBsiqEp8xlzjz5o0s3Y3pvf+XqU5R4=; b=FTlp3//RO94E6pEGhwuCR3KNdXZNaSs7jatFYTojf9hw7vF0HH379cGO28rzEIPUoOsRud eHGjp4Nv4PC3JddBbyxqbyL4f+2R1JS1QHdFjITfeLMlmqFvXD+xUpqya8aDN2BQkdgj2y cIfVQ62Lu60elpaokt/SIA1ywz2ZSkpvO+cRjzH5Mursv4ZG0jzGVn1dSzA92c28pz+VZp qz8YaapMgPubGG96ReamM6LPNnA6/N/94WqFcn4xXOL9iFyUuNqGG7g1c3i1iGPpoZR01L o8hHhdJWtwOsvRO48lZcGbP6rIxNPzKRpHKPykdX92Lk4EHFWEUCLWQ822bZxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760987879; 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=DpCa7JHbkgx1HyBsiqEp8xlzjz5o0s3Y3pvf+XqU5R4=; b=Fmb7PMRi8mkwCxFE2442s8B4g9wbmUe9yf9VKqm4nnbyyn6Lez+R9ZS/StzjFRVt1T7hgq ewylZRxkD4UJ31zyFA1Sth73qfIVl4a1CWCEsTkgxnSjC26w6UO+Gu89Gm4bDe5EWN2fLI WxA4wsjoJ+mJmJA6ugpEqbaMJCPTU9Uj7PmJ9YqWzmsQypogA29N0RUt4w+k1FMbSHcGXl ig8pLwuegw4kJSFPB/fSfpRcmuOTfOr5SqX+LGRIGqqkmWO8SJWSFoH7s+Z2+xQhNfs2xn KwCaaS0/c79ZFULj9OCS9kXXCuiPpok98npUm+vkfNj4KK3Sn/SFO5FAS+7ROw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1760987879; a=rsa-sha256; cv=none; b=ELDObQwRT/DFbOqyUIiNVIZxVT0dD4lUY5/UoCui0iQeL5SaFhEctojQG9yZUhqfeQEa+9 TB34+DeCbffyjd1O754I1E/v0TI5ie1lTf+VQMveUIwP5R5s+YZVX5X0OfFfEzMICSPU2d YVkHH8K5CnnbY8+usdEf1r1dpZcsfk6AAnjsonoT1kI1ImejLbMuTnkw3dXkBHfwNRbwI8 VwB8SwUezSqianvHcsmnmHpC5WZ0fcuiEkKw+hbmQaYsy/iolGOxyQzFPx0Jh25omEWApF qojF6SvokwCbprB0FqiyglZBmSS4q5bI7tpUyt6Wg19BgX3/upPYDYDgcaflqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cr4vW4r1Sz9nd; Mon, 20 Oct 2025 19:17:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 59KJHxCq084204; Mon, 20 Oct 2025 19:17:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59KJHxup084201; Mon, 20 Oct 2025 19:17:59 GMT (envelope-from git) Date: Mon, 20 Oct 2025 19:17:59 GMT Message-Id: <202510201917.59KJHxup084201@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien?= =?utf-8?Q?P=C3=A9dron?= Subject: git: b596b4496568 - main - zfs: zfs_getpages: Don't zero freshly allocated pages List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b596b4496568c21e1e8f9c21be913cfc5b71bd9b Auto-Submitted: auto-generated The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=b596b4496568c21e1e8f9c21be913cfc5b71bd9b commit b596b4496568c21e1e8f9c21be913cfc5b71bd9b Author: Jean-Sébastien Pédron AuthorDate: 2025-10-16 08:16:18 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2025-10-20 19:16:43 +0000 zfs: zfs_getpages: Don't zero freshly allocated pages Initially, `zfs_getpages()` is provided with an array of busy pages by the vnode pager. It then tries to acquire the range lock, but if there is a concurrent `zfs_write()` running and fails to acquire that range lock, it "unbusies" the pages to avoid a deadlock with `zfs_write()`. After that, it grabs the pages again and retries to acquire the range lock, and so on. Once it got the range lock, it filters out valid pages, then copy DMU data to the remaining invalid pages. The problem is that freshly allocated zero'd pages it grabbed itself are marked as valid. Therefore they are skipped by the second part of the function and DMU data is never copied to these pages. This causes mapped pages to contain zeros instead of the expected file content. This was discovered while working on RabbitMQ on FreeBSD. I could reproduce the problem easily with the following commands: git clone https://github.com/rabbitmq/rabbitmq-server.git cd rabbitmq-server/deps/rabbit gmake distclean-ct RABBITMQ_METADATA_STORE=mnesia \ ct-amqp_client t=cluster_size_3:leader_transfer_stream_send The testsuite fails because there is a sendfile(2) that can happen concurrently to a write(2) on the same file. This leads to sendfile(2) or read(2) (after the sendfile) sending/returning data with zeros, which causes a function to crash. The patch consists of not setting the `VM_ALLOC_ZERO` flag when `zfs_getpages()` grabs pages again. Then, the last page is zero'd if it is invalid, in case it would be partially filled with the end of the file content. Other pages are either valid (and will be skipped) or they will be entirely overwritten by the file content. This patch was submitted to OpenZFS as openzfs/zfs#17851 which was approved. Reviewed by: avg, mav Obtained from: OpenZFS OpenZFS commit: 8a3533a366e6df2ea770ad7d80b7b68a94a81023 MFC after: 3 days Differential revision: https://reviews.freebsd.org/D53219 --- sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c index e5344497f1be..f34a2fd37a77 100644 --- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c @@ -4223,8 +4223,20 @@ zfs_getpages(struct vnode *vp, vm_page_t *ma, int count, int *rbehind, zfs_vmobject_wlock(object); (void) vm_page_grab_pages(object, OFF_TO_IDX(start), - VM_ALLOC_NORMAL | VM_ALLOC_WAITOK | VM_ALLOC_ZERO, + VM_ALLOC_NORMAL | VM_ALLOC_WAITOK, ma, count); + if (!vm_page_all_valid(ma[count - 1])) { + /* + * Later in this function, we copy DMU data to + * invalid pages only. The last page may not be + * entirely filled though, if the file does not + * end on a page boundary. Therefore, we zero + * that last page here to make sure it does not + * contain garbage after the end of file. + */ + ASSERT(vm_page_none_valid(ma[count - 1])); + vm_page_zero_invalid(ma[count - 1], FALSE); + } zfs_vmobject_wunlock(object); } if (blksz == zp->z_blksz)