From nobody Thu Jan 16 18:08:41 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 4YYrTP4pxTz5kl5T; Thu, 16 Jan 2025 18:08:41 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YYrTP2R1yz3S7B; Thu, 16 Jan 2025 18:08:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737050921; 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=YAAM3dMnetFM1s2ONpJbXQh4SGgf91L9izquQb291wQ=; b=XFalc3XDlt6XNYcnnXnwBPd1UWz4+sHOw6bhMX5gZRIjqewcGti8olm6LYyHOuSU3C8t95 0AcTmsq80MpeHcejXWvMGqPxhS7QRkpdxGn/pyqCcqpc+LP0WS1HMSkNB7AsbYczL4Bu/Q oIGJa7uZx0IqEh1HyU5LClQDU+ZChZnEgdsv0j4ZW+gunZ72GJ/dB5MmC2pJbsQ7zbmwhf 7DjopfUoPQXZGtO4Jh61kD/koRYKemHshNJnTwL+/jdPD3NS2uKcM93iKlo7A7qtx4v+20 usfmcqrLmOQMLQbboEqbLjaTKNiIu9hRa+LioCGzkkIEJeMK0tFKKhNb587/Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737050921; 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=YAAM3dMnetFM1s2ONpJbXQh4SGgf91L9izquQb291wQ=; b=aAIGqVh155vkYIjFDDZs2zHA/zUTmeds5WGAjPLjc6RWnUOA0IC/Epb7SkV4LPZB3L2YKI RQv0sW1rtSwBRNpXzLG4rUmGsup8lwRvjkIsCjHNTI4MdV1ngyVttHhNpADjii55a+x0yH Xx0KTfH9KGbQCmw6agAhTNK5Fi2IXdxd5sq1UD/eZYw0kpYDnn5fSCuKi94h03jvZo3CvC PnRdOR7aFQnnbpD/tecfoyUeqRywmG9SF9RIfO0Y0AxfhSuDXEuJ0OLgkU2Q3R55nBnEZh 9TH75Z1iGauFjmANLKZcp5J1AnRJ9y+bOjjhpTf+RLcc8sph228trOE+m9mPhA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737050921; a=rsa-sha256; cv=none; b=L/f7Cil94iFOBqYe6QnGyQeJcassCgiNg1kEx/8noRNTZQ1amhBmFiqVnw1kIUTwn2nP3x uhTf3LFHdGAbK4eT/2OuoK/JDZ+hloIJosMBR2o9Q5Gj2KDJHnjmZPnZiNzPyF12vDaICq LB1zlOGYQVifvya8jLbvGN/ezbb/XgebtG1ihxH9CiMzEkSxoLsKyn8+qJjFcz/fB4ynhb kLm8CBC8FmN9Xlc6KeQ00+iFLaXsHE/xxDyqPoV0g8b9FK4Jvp3OFF4XASS1fQ/YKDsbf3 ZScMxqz3XFbjmylt2H9MBquEsTiV6ojnglPrir/JOrMBNf+zqbwxIn+RmOwEUw== 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 4YYrTP1RcdzkKm; Thu, 16 Jan 2025 18:08:41 +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 50GI8fik092957; Thu, 16 Jan 2025 18:08:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50GI8fon092954; Thu, 16 Jan 2025 18:08:41 GMT (envelope-from git) Date: Thu, 16 Jan 2025 18:08:41 GMT Message-Id: <202501161808.50GI8fon092954@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 5e6079209e9b - stable/14 - tmpfs: Rework file handles 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5e6079209e9b6db2bd2980e1b97e7cb4cf8b5364 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=5e6079209e9b6db2bd2980e1b97e7cb4cf8b5364 commit 5e6079209e9b6db2bd2980e1b97e7cb4cf8b5364 Author: Olivier Certner AuthorDate: 2024-12-06 20:23:59 +0000 Commit: Olivier Certner CommitDate: 2025-01-16 18:07:02 +0000 tmpfs: Rework file handles Change 'struct tmpfs_fid_data' to behave consistently with the private structure other FSes use. In a nutshell, make it a full alias of 'struct fid', instead of just using it to fill 'fid_data'. This implies adding a length field at start (aliasing 'fid_len' of 'struct fid'), and filling 'fid_len' with the full size of the aliased structure. To ensure that the new 'struct tmpfs_fid_data' is smaller than 'struct fid', which the compile-time assert introduced in commit 91b5592a1e1af974 ("fs: Add static asserts for the size of fid structures") checks (and thus was not strong enough when added), use '__packed'. A consequence of this change is that copying the 'struct tmpfs_fid_data' into a stack-allocated variable becomes unnecessary, we simply rely on the compiler emitting the proper code on seeing '__packed' (and on the start of 'struct tmpfs_fid_data' being naturally aligned, which is normally guaranteed by kernel's malloc() and/or inclusion in 'struct fhandle'). Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47956 (cherry picked from commit 1ccbdf561f417f9fe802131d5b1756ac45fd314d) --- sys/fs/tmpfs/tmpfs.h | 5 ++--- sys/fs/tmpfs/tmpfs_vfsops.c | 16 ++++++---------- sys/fs/tmpfs/tmpfs_vnops.c | 16 ++++------------ 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h index 7ebdffbec84f..277cb599d78b 100644 --- a/sys/fs/tmpfs/tmpfs.h +++ b/sys/fs/tmpfs/tmpfs.h @@ -439,11 +439,10 @@ struct tmpfs_mount { * NFS code. */ struct tmpfs_fid_data { + unsigned short tfd_len; ino_t tfd_id; unsigned long tfd_gen; -}; -_Static_assert(sizeof(struct tmpfs_fid_data) <= MAXFIDSZ, - "(struct tmpfs_fid_data) is larger than (struct fid).fid_data"); +} __packed; struct tmpfs_dir_cursor { struct tmpfs_dirent *tdc_current; diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c index 65d54b446849..c404eb81a8d2 100644 --- a/sys/fs/tmpfs/tmpfs_vfsops.c +++ b/sys/fs/tmpfs/tmpfs_vfsops.c @@ -586,29 +586,25 @@ static int tmpfs_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp) { - struct tmpfs_fid_data tfd; + struct tmpfs_fid_data *tfd; struct tmpfs_mount *tmp; struct tmpfs_node *node; int error; - if (fhp->fid_len != sizeof(tfd)) + if (fhp->fid_len != sizeof(*tfd)) return (EINVAL); - /* - * Copy from fid_data onto the stack to avoid unaligned pointer use. - * See the comment in sys/mount.h on struct fid for details. - */ - memcpy(&tfd, fhp->fid_data, fhp->fid_len); + tfd = (struct tmpfs_fid_data *)fhp; tmp = VFS_TO_TMPFS(mp); - if (tfd.tfd_id >= tmp->tm_nodes_max) + if (tfd->tfd_id >= tmp->tm_nodes_max) return (EINVAL); TMPFS_LOCK(tmp); LIST_FOREACH(node, &tmp->tm_nodes_used, tn_entries) { - if (node->tn_id == tfd.tfd_id && - node->tn_gen == tfd.tfd_gen) { + if (node->tn_id == tfd->tfd_id && + node->tn_gen == tfd->tfd_gen) { tmpfs_ref_node(node); break; } diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 4571a2855be3..729feb0329a4 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -1684,23 +1684,15 @@ vop_vptofh { }; */ { - struct tmpfs_fid_data tfd; + struct tmpfs_fid_data *const tfd = (struct tmpfs_fid_data *)ap->a_fhp; struct tmpfs_node *node; - struct fid *fhp; _Static_assert(sizeof(struct tmpfs_fid_data) <= sizeof(struct fid), "struct tmpfs_fid_data cannot be larger than struct fid"); node = VP_TO_TMPFS_NODE(ap->a_vp); - fhp = ap->a_fhp; - fhp->fid_len = sizeof(tfd); - - /* - * Copy into fid_data from the stack to avoid unaligned pointer use. - * See the comment in sys/mount.h on struct fid for details. - */ - tfd.tfd_id = node->tn_id; - tfd.tfd_gen = node->tn_gen; - memcpy(fhp->fid_data, &tfd, fhp->fid_len); + tfd->tfd_len = sizeof(*tfd); + tfd->tfd_gen = node->tn_gen; + tfd->tfd_id = node->tn_id; return (0); }