From nobody Mon Dec 23 14:47:51 2024 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 4YH18m1V6Yz5h9mP; Mon, 23 Dec 2024 14:47:52 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YH18m0zdSz4f2l; Mon, 23 Dec 2024 14:47:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734965272; 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=n7AIw521r54ou6rf/MR2nE9BhLWECHVxTEXebH27qdo=; b=OgkI16OVuvvifoHiyVHU4WBdxhqJLxccjJxab8qBG5ZotHKuXCE4crmN/2Sh6pwH9Sf6R0 h+Cos7+JEYYQx3gZ8DnskShb/CatAP+iI/CW5jYKWv5iuxCZJu9c25lXjWTb1AxtBcmQbT uXywokDflkPDP5q3m32FFtcX1Qri5dmJDhKqTfvGaUpMLC+a1r+o9uU+1SDLRA7EXqyAb5 8FGfljv9nb31hQbl3taiA9ifMRO+Qd0EtGe+V5EmgBYd5/NuQTyu4AHJSF8DhimMGm98Jv O4qkHwJ0lD1pUTyDmuQaaKQLuEyv6/UcryZRhZOh4YrfkuZfQofDCxhLCJQJuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734965272; 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=n7AIw521r54ou6rf/MR2nE9BhLWECHVxTEXebH27qdo=; b=ScOuPKUiwvzhLvnKUTODdV02e/cjFjCoQa4h1UIp10lE0SO9r6EvyxIzhwWkkD6hBtEpaP GfUxg/Uf/fHUnRd1W4HDITmy3IJ/+OSFqPru8WXxgR/6but4fExPLKb1ufr6g6mE5kHTVv Og/8fuO/oppi0ySdwsicNsqY1e8NEz4E1ilMcYL1CVCPaQtPzdEWIeB4uQpDxFJkWI7BKK vWXIpoxMVx8llC/DolxxFTmgKSP0uB2QyB1IvzTps20GBe9IJEdyuUBnbU3J0+RLToENpW Mwps4YAR6EhZEu0+TvqdvYKS7iDyA11r+EI9g8r3NAIZsP/YUBe1Y+lc2TNnmQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734965272; a=rsa-sha256; cv=none; b=FwNYAcCXBviosOz7RZ0q1qcueE8mpZe6hVvNqCybVmdUB63elltACXUoFELmTbZN3JVyeY rWhSswhCpj9DUtKh5sgaHvQPg87fKb1WJk+9coi+LP/DWlZX8zWyo2Mq/MbjyCnlgTlH4q rcfMXNQ8xxtEikxmE1HlqUQukXh0icC7yTMC76VT/8L1OFFZsDCpWxjr8BOWbPH0Kp6/Kz Y+bBN8dwvVm2iJg0vufHDpYynCpbYQjeUwpHnsXKn9klQrf2/wh15BMkZ7rrz46Ro9Vs7e IU4hr2NGMfZ9vuV2znTw1Hpns98EnfHH9UMK8FARxOwIQiuHsfGu6crZaxupNA== 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 4YH18m0bhnzy6t; Mon, 23 Dec 2024 14:47:52 +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 4BNElpLr097353; Mon, 23 Dec 2024 14:47:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BNElpeJ097350; Mon, 23 Dec 2024 14:47:51 GMT (envelope-from git) Date: Mon, 23 Dec 2024 14:47:51 GMT Message-Id: <202412231447.4BNElpeJ097350@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 1ccbdf561f41 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 1ccbdf561f417f9fe802131d5b1756ac45fd314d Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=1ccbdf561f417f9fe802131d5b1756ac45fd314d commit 1ccbdf561f417f9fe802131d5b1756ac45fd314d Author: Olivier Certner AuthorDate: 2024-12-06 20:23:59 +0000 Commit: Olivier Certner CommitDate: 2024-12-23 14:46:55 +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 --- 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 58f8720c3f84..52307cc7c7b2 100644 --- a/sys/fs/tmpfs/tmpfs.h +++ b/sys/fs/tmpfs/tmpfs.h @@ -448,11 +448,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 dd48a24dab2f..431893b77bb9 100644 --- a/sys/fs/tmpfs/tmpfs_vfsops.c +++ b/sys/fs/tmpfs/tmpfs_vfsops.c @@ -585,29 +585,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 162977b8abf7..83e43ec7ba13 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -1706,23 +1706,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); }