From patchwork Wed Sep 18 14:12:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 13806931 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F4BEF9CB; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; cv=none; b=R6m2ELFGrkKziBwj3Yrr8l5CF9lVqgxd55zo167bRJWlSy+rCRk766USXsDZVhYdrij53zYp4+ldFIpPyZEsRr0hAvkJa3ggZAjhz3DKfMXa2ezjvnyBFqN5POXe7j3r8JZKTY53lWGwES27Ko3z3dDEiOZLbN9X90Hyz1mhjyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; c=relaxed/simple; bh=x1Xc/UFz3grEcF9+MRXVNAJu0t50Wbx7WhznyvSgTrw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Osg7ARpiRyv9HwgdtgTwvV21PBkkiDU6jvvp6TR5w0GA5O1ljvfJzg9tnvlB3AH2dw1fZ0sCarPnFLla5XgnMkJVb20AYgX0lTcDT1OyPH+dIydOAHEU3VNSoelALwxpxdiRWywQPQ5L2g2DKKbDc+vr6tYn7GcKGILAX2AUBkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l7cwxW6A; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l7cwxW6A" Received: by smtp.kernel.org (Postfix) with ESMTPS id EA55EC4CECE; Wed, 18 Sep 2024 14:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726668769; bh=x1Xc/UFz3grEcF9+MRXVNAJu0t50Wbx7WhznyvSgTrw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=l7cwxW6AL3DZFqpx9Zd0fCVWabYJB5ltdgqd9N0MolKldfDncEO1E+LwAg7ayCdtZ 5NVSOa/Rj8XUCn2QpVRvq1YLqP7GVBn9SfP1vVnPrKIULaIUseB1imxSAaQBA1LlIo QvRxOzTEvS3e+9FR2r/8IRtgd6ekkgh4Y92tI+JsI7BlOie5gyp98mR/WlrqhetW7v F3tEQyxkzSvQ3ZGrkhi4MVOQ6KBfaf9R0TsRJBxM3FXxgVVN2PubE9YYAzZPAFpjUQ 3UWcyJl4oc4mv7eeOR5OZjxzsuLYaMnpUD8wLu+/htM8TrzihDXAlIUvuLPHX1ycRU 35hsVE5ERy5cA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA2B2CCD1AB; Wed, 18 Sep 2024 14:12:48 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 18 Sep 2024 22:12:20 +0800 Subject: [PATCH v5.4-v4.19 1/6] fs: implement vfs_stat and vfs_lstat in terms of vfs_fstatat Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240918-statx-stable-linux-5-4-y-v1-1-8a771c9bbe5f@gmail.com> References: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> In-Reply-To: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: Xi Ruoyao , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Miao Wang , Christoph Hellwig X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1917; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=CQCVg6bGtOP7dyIJeUlTzT0EMwWixKIfeNRTX+C5op0=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBm6t/dN6H2v5zhZ+VZu7qHixmznKxNo+3Rk1z6P MeyL1nJkueJAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZurf3QAKCRCwMePKe/7Z bnotEACicVudyiCwiXPeNPSwGr7S4Ztlm5l8+E5WotWOBHH5e0d5rrkI1IelGuDBBfhhyCbYz0t HgmGj3EtwPIuA3KXS5hKhVnncohkyujzu3s7++7GWQBdAAbYZxqnua3ptUx5Nynf13+9Hr2xCbk eRYyvnXqVED+TubKqcC+TrlwDy4t63C+pMC5woVgZEh/voFNabz/iCKwaNy35AmsSds+guma01G qpkwjRtvy8/HKg6TutXvwz8UJKCTtLq1p3JPD8QS+ztW7kvxz6WyqL7HurZGhn0MHjc63ftA4EY OAnTA+fmPsYrX2HzYxduBYuP+1F4ZyRruTilheJFDWjJ+uKNAfFbo3XyRuyYQDHcf098hAdMjkO eRnlTJm5RkHxbu6vdnPlljNKHp2I0/OsqmPwk7KVWgP8/X3ZrDAMg7Sqa+mvJxanGscjujSPphH xYbGXc5Gtcc1zdPWHjvfZH24x+ooNeKMH0Tf9LkRnv2G2BvQEaB4sJp1ECWWuG1GNdwLhf4s0uu SI1phaQB7NwHGc1cBARomx9Rs7NPp/e86l8ajhbCLy6kPMDvbsZxJ0yKvYP7P+sEqnVrI/f9MYL FFJgLw7y403UUtsRbhWPVfTjdsNQJy/tuT+9O6+MAUIAyA17Q7MP4T8EN4vUalmz80yBFRNq8Lc ZfnlJfEosGcs1yg== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang Reply-To: shankerwangmiao@gmail.com From: Christoph Hellwig commit 0b2c669 upstream. Go through vfs_fstatat instead of duplicating the *stat to statx mapping three times. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro Cc: # 4.19.x-5.4.x Signed-off-by: Miao Wang Tested-by: Xi Ruoyao --- include/linux/fs.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index d4f5fcc60744..2db4e5f7d00b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3262,16 +3262,6 @@ extern int iterate_dir(struct file *, struct dir_context *); extern int vfs_statx(int, const char __user *, int, struct kstat *, u32); extern int vfs_statx_fd(unsigned int, struct kstat *, u32, unsigned int); -static inline int vfs_stat(const char __user *filename, struct kstat *stat) -{ - return vfs_statx(AT_FDCWD, filename, AT_NO_AUTOMOUNT, - stat, STATX_BASIC_STATS); -} -static inline int vfs_lstat(const char __user *name, struct kstat *stat) -{ - return vfs_statx(AT_FDCWD, name, AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT, - stat, STATX_BASIC_STATS); -} static inline int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, int flags) { @@ -3283,6 +3273,14 @@ static inline int vfs_fstat(int fd, struct kstat *stat) return vfs_statx_fd(fd, stat, STATX_BASIC_STATS, 0); } +static inline int vfs_stat(const char __user *filename, struct kstat *stat) +{ + return vfs_fstatat(AT_FDCWD, filename, stat, 0); +} +static inline int vfs_lstat(const char __user *name, struct kstat *stat) +{ + return vfs_fstatat(AT_FDCWD, name, stat, AT_SYMLINK_NOFOLLOW); +} extern const char *vfs_get_link(struct dentry *, struct delayed_call *); extern int vfs_readlink(struct dentry *, char __user *, int); From patchwork Wed Sep 18 14:12:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 13806934 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 583FD18B470; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; cv=none; b=kiTZ4RcWXZ+PnXIdsC/HYBR2eZhJMRFJnDjBVtYztdKygKeBloddNKPmWymZsa3hCRHK0S+AplaNm2T+R3WVwpsdCBn1a0ik4wOoIvd0EO7iRuWtThh2hy5AfVWjYcbduUpBW0BD5F4CcBgtbza9bthzpwWFbhC7MNhAcmEcBAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; c=relaxed/simple; bh=8/JtWAjFO16OAT7HzPLupeSOnXwBE9QA6QRe0YA3btw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YnqMyrxOu0eQO/mB94xei5LDbEj83Q27eTNZlPurTyZyZaW93G+UXPS+VrXcsTXK8suZ0XfGYr+IkvTH6xNuJRxhjBmpAaIt8LcwcGlPhMdXXkbiTD2P2yoQVTZtK7Fospr9DwNlGiDYyIjgrs4hr1oKSEP+utAb23xkvUZvHYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YshBiDlJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YshBiDlJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 03845C4CED0; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726668769; bh=8/JtWAjFO16OAT7HzPLupeSOnXwBE9QA6QRe0YA3btw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YshBiDlJBWRcM2Xg4LaZE1YdVQG9RhJub2ctPazP64QAfvzhHwezMV5uAV+wvggab wZ7sPrTsPBEnZPfgoXWhF+pHx/AWyC6N9uLXRce28GqiIiA6fhu/DunbfNwP32MOpp W9QDyD6GIM2DUTI4NwEi/x5qjIPYvZgW0h8pPDr+ajCGCTVJVPpf48EHWYR4onmQMH TeQLEUcrcYEUMhW/FEY/waTHQ/0gok7yDwn4sVVUaGSfdvgq91GrbuIzEy7TrLh0oa CyjzCmh/+jPE8Pt+gnAKoM6N7DiGqp9qkm8jZ/XDGt4wl1qyM822xLg2lzMW6Qj8iR /k+4AXuNvfhDg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E960CCCD1B7; Wed, 18 Sep 2024 14:12:48 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 18 Sep 2024 22:12:21 +0800 Subject: [PATCH v5.4-v4.19 2/6] fs: move vfs_fstatat out of line Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240918-statx-stable-linux-5-4-y-v1-2-8a771c9bbe5f@gmail.com> References: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> In-Reply-To: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: Xi Ruoyao , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Miao Wang , Christoph Hellwig X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2373; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=cAg8g3RAmbShO+C0L2Soe5vWdpoEVWcVWpevQzMAjzM=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBm6t/d3qqZqYy7HcKahGMFY3/BnO547a2jJCq09 UewNTOwimiJAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZurf3QAKCRCwMePKe/7Z bm75EACQv0fUl953s50IWGUBZ54obM/Msu+o0PNBzgKXSOys4Jdoazs4hERyM/YpsSR/A/3CrkI s3dJss1HUMmZjvvgEwEY0zcH6bhlkdyN7Wbde9RY8S+lgRRUmjoy0RD+EzthEdg55JoYBo/iIe5 Bf6q6qAqjcQEty+/KKGnOZ7XQnCLDDeVnth/HRo/Eo+/fb3S3ps2G8e8bvIUt1jLfW90eBkRSrS XnI2zuzBQOR1ibE2GxvlgAZaKfiuirjfCnAmra11d9PQZs6k/M2sPLL5lJhnNGKjk367d/8/Rpc M/R+mI/HGpqLO3vZ5g+35BPrOxEfoxXmTDbPTgvwDPxAKZa2yZshNM3csq+xe076TtWW4U+7prH IP6AnElgntY+a4av17iu+sK8Q10116/doQQ3EIYkZY2z7euw6AqUGMLHTvDDzyxEvjiWIOSXD5m R+tdLzoSDA5V25xb7VUgqVhYqWA2MLespH5ueD9oiuermAJXCtHt/xNy9vOy8KmfqBaZzraI4FC lrDO+o8J92cM61necDwMkbE6FyNIwf1+gMoa7lZ1kI5oSqRpw4a/G6Ow3pFm6RiGNI16Oeyv+x7 +LOBIs+K1pZ7XybbtgwitE3YU1NMnie61Y6mkY8b/yYzdXOz5jYYD1JbLXURXJvfbmGa0m4UqR/ F+MVWfE4JzzcJzg== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang Reply-To: shankerwangmiao@gmail.com From: Christoph Hellwig commit 09f1bde upstream. This allows to keep vfs_statx static in fs/stat.c to prepare for the following changes. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro Cc: # 4.19.x-5.4.x Signed-off-by: Miao Wang Tested-by: Xi Ruoyao --- fs/stat.c | 9 +++++++-- include/linux/fs.h | 10 +++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 268c9eb89656..b09a0e2a6681 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -165,7 +165,7 @@ EXPORT_SYMBOL(vfs_statx_fd); * * 0 will be returned on success, and a -ve error code if unsuccessful. */ -int vfs_statx(int dfd, const char __user *filename, int flags, +static int vfs_statx(int dfd, const char __user *filename, int flags, struct kstat *stat, u32 request_mask) { struct path path; @@ -197,8 +197,13 @@ int vfs_statx(int dfd, const char __user *filename, int flags, out: return error; } -EXPORT_SYMBOL(vfs_statx); +int vfs_fstatat(int dfd, const char __user *filename, + struct kstat *stat, int flags) +{ + return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT, + stat, STATX_BASIC_STATS); +} #ifdef __ARCH_WANT_OLD_STAT diff --git a/include/linux/fs.h b/include/linux/fs.h index 2db4e5f7d00b..952f103be4a0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3259,20 +3259,16 @@ extern const struct inode_operations simple_symlink_inode_operations; extern int iterate_dir(struct file *, struct dir_context *); -extern int vfs_statx(int, const char __user *, int, struct kstat *, u32); extern int vfs_statx_fd(unsigned int, struct kstat *, u32, unsigned int); -static inline int vfs_fstatat(int dfd, const char __user *filename, - struct kstat *stat, int flags) -{ - return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT, - stat, STATX_BASIC_STATS); -} static inline int vfs_fstat(int fd, struct kstat *stat) { return vfs_statx_fd(fd, stat, STATX_BASIC_STATS, 0); } +int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, + int flags); + static inline int vfs_stat(const char __user *filename, struct kstat *stat) { return vfs_fstatat(AT_FDCWD, filename, stat, 0); From patchwork Wed Sep 18 14:12:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 13806936 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5844B18B472; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; cv=none; b=W3n0SukYMmrbGxj5ENFLjbDDa59VR9UuqclTuV9yTWXTwes47V2QjluJ+sb9n1UTaKw3XDicEKODQHJtTeu5BpY3CY+ozoOFaHEbra+LHimZ+jBWsCy/sewaRTJPMhfNZ8bPaRNMTJOr1aio95vA4BSLMoWvEVNcEHSuxno5DWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; c=relaxed/simple; bh=PVnzNCLQ68jsbupEGVL68Tb95X/C81NbWR59p/QEj7s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X2aJyGkp52uqKrfuOGLQz7gTWHBIrNmlllEpvNxR3Afk8HhrOpsjVEF5oQ9sQiq+oGfZvlfRt001aQQV4OntZu0F4K5XXY89yUXf4e4OUYbh1K5ESv2kXv5OWdxAgvT4LncFQEyXkvhNtJxsxcXbMiSk9GuXSgn1oMyz6udi8tk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S1r1mFyY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S1r1mFyY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0B537C4CECF; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726668769; bh=PVnzNCLQ68jsbupEGVL68Tb95X/C81NbWR59p/QEj7s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=S1r1mFyYRot4UMStkYiFI9qjuW3QAiRyYl6MVPMWDgH+I7N/wkbupaqMz8oaEOq+0 48xMdoKwHqNMYaIEGYW5/pKdrbH9Mt7qtjyChKlX5m/3Y3Eg0mz+UpddlEWpRpWWOm KV2agL5QfVuCf398LBWUGRd21I9xGEq5YLS4d3KAJp5MTuCrL0tpyKjyc1PK5OEmcQ EaWFw9H3393UDBfq1B67XRe4xiOs6iNjh/drMe/NNR9h7xAwYsSemiekdSAP2sQBsT 1CrQsDmnYp2Ad0UYwYLf/5xqjKwrSb0MdZhIXZ8FpghnUqywNS7Su7z2ktofg4vVIh JLwCDWyOT9iZg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04525CCD1B9; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 18 Sep 2024 22:12:22 +0800 Subject: [PATCH v5.4-v4.19 3/6] vfs: mostly undo glibc turning 'fstat()' into 'fstatat(AT_EMPTY_PATH)' Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240918-statx-stable-linux-5-4-y-v1-3-8a771c9bbe5f@gmail.com> References: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> In-Reply-To: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: Xi Ruoyao , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Miao Wang , Linus Torvalds , Mateusz Guzik X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2833; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=Ob5pdDkBmzfI4CRiHVry9bYgBpFtcO+hUY8vOastWdQ=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBm6t/dkhe4gnLosFQYQGgAjw7HgtvKBijoVz7Qh jYM5QOhLIaJAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZurf3QAKCRCwMePKe/7Z blK0D/95LpkFK/leLf1q4EmJiRPaQZZeIx0+uHa7VtIXcjbwDjN6DHRFLlJcQ8lnc1HaIf0NpZx Ur7emkfeutwuMrIgf3yDnvN0vhl5+13CbvJZPUnAnDJqqscoqj9InpIoPdbaOQNjiFIQ9fItajH Jj0WcfHkoJWp8X2C/yy7maTuQ2VeRmHaXtzVAfKYwV1ckdl6UkuzNg4r4d7C+uCbvXlDAEghL3R PxAHoGouQsUQvaOT4Ow03TUUrXH+thTXHLItU76UyhwWXSVna0cgimSbYhIUTgCtAaAA9e0Wdu3 s9dimC31fy9B3wsALIeOd7stElIwCtH51ZIaFZsD5N4OA2dPKi3LTv9gzqN0gKwhQO/IZFu43Em 9Y/R3tJJZabuM0UbXLf5MgzB1on76HmDtJEDkCNXGh7Ig7U191NDo4rr4i86tNjqT4oeV+L/XpS MVQExf+jfuFT6oSQZ9qtolVYfF4QAiAJZt9WQRDsGDzXFQcrhxERUIKHgxnBchPx/6qUwHzjdFn Wy/y3gISELKQco8Qzqz2wCj9gzdevgDKkr0FjIHe8xilebFoZyEjiGSb9YccLCK0QMHdfFyfeJl +AUiT9jiBhZL6Dtk4JiqkkF/2yiq2tDNMTBCPZe5V/X1AUiKX2N1oA2qTOqqJl2hQ+4V137EAEk 4ZxCqcwWoPQIzJA== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang Reply-To: shankerwangmiao@gmail.com From: Linus Torvalds commit 9013c51 upstream. Mateusz reports that glibc turns 'fstat()' calls into 'fstatat()', and that seems to have been going on for quite a long time due to glibc having tried to simplify its stat logic into just one point. This turns out to cause completely unnecessary overhead, where we then go off and allocate the kernel side pathname, and actually look up the empty path. Sure, our path lookup is quite optimized, but it still causes a fair bit of allocation overhead and a couple of completely unnecessary rounds of lockref accesses etc. This is all hopefully getting fixed in user space, and there is a patch floating around for just having glibc use the native fstat() system call. But even with the current situation we can at least improve on things by catching the situation and short-circuiting it. Note that this is still measurably slower than just a plain 'fstat()', since just checking that the filename is actually empty is somewhat expensive due to inevitable user space access overhead from the kernel (ie verifying pointers, and SMAP on x86). But it's still quite a bit faster than actually looking up the path for real. To quote numers from Mateusz: "Sapphire Rapids, will-it-scale, ops/s stock fstat 5088199 patched fstat 7625244 (+49%) real fstat 8540383 (+67% / +12%)" where that 'stock fstat' is the glibc translation of fstat into fstatat() with an empty path, the 'patched fstat' is with this short circuiting of the path lookup, and the 'real fstat' is the actual native fstat() system call with none of this overhead. Link: https://lore.kernel.org/lkml/20230903204858.lv7i3kqvw6eamhgz@f/ Reported-by: Mateusz Guzik Signed-off-by: Linus Torvalds Cc: # 4.19.x-5.4.x Signed-off-by: Miao Wang Tested-by: Xi Ruoyao --- fs/stat.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/stat.c b/fs/stat.c index b09a0e2a6681..526fa0801cad 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -201,6 +201,22 @@ static int vfs_statx(int dfd, const char __user *filename, int flags, int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, int flags) { + /* + * Work around glibc turning fstat() into fstatat(AT_EMPTY_PATH) + * + * If AT_EMPTY_PATH is set, we expect the common case to be that + * empty path, and avoid doing all the extra pathname work. + */ + if (dfd >= 0 && flags == AT_EMPTY_PATH) { + char c; + + ret = get_user(c, filename); + if (unlikely(ret)) + return ret; + + if (likely(!c)) + return vfs_fstat(dfd, stat); + } return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT, stat, STATX_BASIC_STATS); } From patchwork Wed Sep 18 14:12:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 13806937 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82CF418C029; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; cv=none; b=SAbPZMXr203WCldLiGMsG5pzrOG8sMdJNQG2qA2g/BPy1AJ0u6dqubuEfrRSErwpAYxlrtNUCLjOXaWOC2n/BRIRcejbEjl3qnL5AepU5VbE/AobN2tJSg9SJq/MKV+j2LT+z8Ct+3o3TArxiKFgTjoiufqv/coUnBbFu2bisVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; c=relaxed/simple; bh=dEreoO87IPzkF5bkVO2hVE7fN0Lx5g86NkFxXF0VqJc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rWyD6gXqMyW/yCKpJA1M2MwVjWg28oM1ilnvk3knVNeFC3trQXdFqvf12rQHZKbIXvIsx8G7UWyTlub2bLae3ID3MW4Mj5HEVeuJfSC2fyFig5jqFXeoAdmSdfmQDC+I18iZdAu4wKyHg17mNF+tQ11ChhbQ6dA/9f2aG4RnmKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CNDqNtCb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CNDqNtCb" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1F388C4CED2; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726668769; bh=dEreoO87IPzkF5bkVO2hVE7fN0Lx5g86NkFxXF0VqJc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CNDqNtCbMrFhikwPSr4duGD/JaPM6lLVD0X+KUz0WdRb/IvT5CTW0mQy5v8sFd+52 PIo2UKa1NjfUjrb4TVr015iemYwACFepMySFO4lWoQ8Ske/ctr8dqvSOhkcQ6iVY5w DdKcQbhz+AzNmk+HqNhEfzCnv5aj+msAsLc60lyp93HKx6gA2LDRartOVCckIYw4/5 wiyUNoMHbfAlgLl8G4D9BXhopMgvjNK5TzgQkv19Xq88zAhnaTt7Dl4Sgvf0XXP4qg IqEdIUDAfj4unHUrGMxVM5suC+3OZh3GO61ileOdXzz/+6eg3HeSd4lGdY/HwZCz7k 0KT7FRlzces0Q== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15C0ACCD1BA; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 18 Sep 2024 22:12:23 +0800 Subject: [PATCH v5.4-v4.19 4/6] fs: new helper vfs_empty_path() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240918-statx-stable-linux-5-4-y-v1-4-8a771c9bbe5f@gmail.com> References: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> In-Reply-To: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: Xi Ruoyao , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Miao Wang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1161; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=EYzTtx4WfUuets9SJVOnFqg05Micjvp+v1D6XppGYQY=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBm6t/da9VVbzSOdM+CPOCM6K9MndKp6pQ7ppFDv SrJFJsLFQ+JAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZurf3QAKCRCwMePKe/7Z bh5QD/9Fx/EnoLO4EloMc7UpLPmUwiStv+abbyt9H8hvmayjroYdsUtm6QwKmdZV6COGzLuhQIR 7z/UX5cfkwadDwS3HTRcW6v+e3+06bWfVHL2IvAbtvS8N7VwVRq4QpTiouuYpWsZ36WUSYQxyLC ybnDWhCIfBbGnnhRzmzfkqL49tjAHeWlIKOSRydPgRyXPl3RHdikWhh2NQFVSiDv/xrJPyIGNo6 NW4ZHdS4QrU1TS88vGAJZlLRDALikj/13voqcme4A/gHC6RquqxPU1wU4neVZ6X2rzhuWCwG8eQ DswVi8ZzDc1fuFjyYr7x/XF4tbeaXD1IdH9vMmjc0otVm2QpNwE4tHI0UQfju8iKpQP6fLVSzST 4mvl3uiikVzjiChkVT5BPTGrY8QxzB9rz3A9oNjo+fF7xhQCdzVCyjL2Nl0BOZS1t3OksNcwVoz 655/H0Q09sAacgZIQQH2vHCZoaNIqMHoH7Iyio4iNZN6eUpKXQkUFITCH+TpWh2R00utdXMhU5w dizCwz/5uwaCcDgvFHS9pdwb2sXLMIbGFpkr9/xDmQR8KxfgUpTXv9/j9aJFrLTM22T26eX+san FmEgQX0AVXExKPNKFHAZpEx2obP6++aA1iluQEwfrBfg/U43oP5m6naHlGvVJp0f/RtEe3ytBEf S4FnwM+yQkLHwIw== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang Reply-To: shankerwangmiao@gmail.com From: Christian Brauner commit 1bc6d44 upstream. Make it possible to quickly check whether AT_EMPTY_PATH is valid. Note, after some discussion we decided to also allow NULL to be passed instead of requiring the empty string. Signed-off-by: Christian Brauner Cc: # 4.19.x-5.4.x Signed-off-by: Miao Wang Tested-by: Xi Ruoyao --- fs/stat.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/stat.c b/fs/stat.c index 526fa0801cad..3ae958308e48 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -150,6 +150,23 @@ int vfs_statx_fd(unsigned int fd, struct kstat *stat, } EXPORT_SYMBOL(vfs_statx_fd); +static inline bool vfs_empty_path(int dfd, const char __user *path) +{ + char c; + + if (dfd < 0) + return false; + + /* We now allow NULL to be used for empty path. */ + if (!path) + return true; + + if (unlikely(get_user(c, path))) + return false; + + return !c; +} + /** * vfs_statx - Get basic and extra attributes by filename * @dfd: A file descriptor representing the base dir for a relative filename From patchwork Wed Sep 18 14:12:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 13806933 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D98018A95D; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; cv=none; b=GwZNWspiwG6Xj524ld9Eua4pWJLs1YnRRMXklVdU83/W44hz6n77g83vUTmqAqU3l84Lw5uSjrCm6OGdUOxaQfE9IJyqGLryOYIrY+g/lXjDNKGLaiBL1xduoGI/bT80ZzLlTD/UvNlYU2WkPzHRPY4iPfDJ3t75quIdlhfgW6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; c=relaxed/simple; bh=v7U4ypH/Ac5Ke2FaytFoW3LPOQ2F1eTkTbZmllFXXB4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Orumdy0SmtNVQSuGOokSpdIzCbxNMd+V9o+aWWjuEVZDZ4PA/5kkHT3jwk7mDl7PVVN6l0JIbNclaWbuRhifsmSA0bxfQwnJJBqSvSRuBk6xhS34IUxelsfKUzUbq81qWZ5dwcxMDrDKRzvf7ADVIki2+qLNu3Ra7EAoobSfFgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tmogwCrs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tmogwCrs" Received: by smtp.kernel.org (Postfix) with ESMTPS id 29C72C4CED5; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726668769; bh=v7U4ypH/Ac5Ke2FaytFoW3LPOQ2F1eTkTbZmllFXXB4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=tmogwCrsFq/nofnU2pu7mgNa2VIfaM3HAd6asmqNJT2EwLwjm1sHbII6fQJFlD4yO HrGHntH/AwxFy/SOMsf912+U2x4K0gB1FJX7eRFFnwHFqaH6INz8q0ihCheWXRQ4qB prh/bkViSmSzgouqscRwaNZJXWjK+8Gr4srhgfCJeByVPiKoBrmIj2p+lN7tvDjQ8R Wb8WSXSCw9W9uK3Lt50vu+s5IbXM126Ofboai2f0dQeEDFS0nqhXlRY3sziJJ9O3U4 dt5Jbzi3yHqjGoBiKq+3mCiAhjGs/qhmPwt0Dql2QIcgcwMAjcuWXbyDFzdgMr1vpu cmEEyxCwtHYUg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23A27CCD1B3; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 18 Sep 2024 22:12:24 +0800 Subject: [PATCH v5.4-v4.19 5/6] stat: use vfs_empty_path() helper Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240918-statx-stable-linux-5-4-y-v1-5-8a771c9bbe5f@gmail.com> References: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> In-Reply-To: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: Xi Ruoyao , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Miao Wang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1081; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=lbbjfwVQwhBMaQKhLfEbF06OhcMU5I+9P48PRWXjV58=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBm6t/duEd97bWZSZWYr+0maaRO+Z57/o0I255hw /Y1wn2K5xyJAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZurf3QAKCRCwMePKe/7Z blEwEAC2CZBFiARpq0BzXdbsmeSaU+++3T5LIlILiPQILqslb3Sd+tbvA8YUxRClYEU2lR1J8bu 9O8+qcWfYXacbT1Lw+n3Vp7/66c65DG1vmPCoATC708HjRZCnn7qjgNIF3VItPEhEPIguAtHi/f UjUtlk/6KWijVnA/XpK9JrgHIFz/9pf1zehNZa+Plu88S84Wd4PUCO3e95ZxB6c7cHQE6HOjTds rUjO7q2MNWAmfc2AwWmxqtg5ZNVHPSp2jWmGTC/M9apZ/KNH7ahbuJn+W91piZW2GvVSuDXM61b NHAMpje2zaB+f2sHmqgsTG7QxFzINMq8cp4wB2W1QRPY/hoEVNoLbX18wzp6EjMAytQtEjsHyWW nLtBO8duQmz1Br0otDUNMJa6YZHHSy3EW51kByUOVWs3JA4kJ0yY7gzBtaQ2MtSn4X0vUCaF05D hou5nPJ5KmDiTtlfweaRVQbr2FA6qlbuW8rFwpHvoY1QTXu6axlMnIUfD45f6gwCLK3Dmcj2P1D 3h/4ui+c+jbw58YgMy+j4d5u5F85XjGMXTXefUMnjunFI6cn2w5llp77i1vOjzSgKaiV9bnouQe 2zbCIBOcG6xxRo2yWx034hPaRxHjtUBWe9/ETB46yjHmjTvy6U22A9EYYNuiUT+07fF4EhlyhOC sMM7S/UMDdINJWw== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang Reply-To: shankerwangmiao@gmail.com From: Christian Brauner commit 27a2d0c upstream. Use the newly added helper for this. Signed-off-by: Christian Brauner Cc: # 4.19.x-5.4.x Signed-off-by: Miao Wang Tested-by: Xi Ruoyao --- fs/stat.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 3ae958308e48..1aaa5d847db8 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -224,16 +224,9 @@ int vfs_fstatat(int dfd, const char __user *filename, * If AT_EMPTY_PATH is set, we expect the common case to be that * empty path, and avoid doing all the extra pathname work. */ - if (dfd >= 0 && flags == AT_EMPTY_PATH) { - char c; + if (flags == AT_EMPTY_PATH && vfs_empty_path(dfd, filename)) + return vfs_fstat(dfd, stat); - ret = get_user(c, filename); - if (unlikely(ret)) - return ret; - - if (likely(!c)) - return vfs_fstat(dfd, stat); - } return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT, stat, STATX_BASIC_STATS); } From patchwork Wed Sep 18 14:12:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 13806935 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 579DE18B464; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; cv=none; b=ZFF0QEjeVnaIO/l2kqdLkeVXmrtBpXHfbO0EpS0O8XCeTLXXlaCfxdiIEWdVh0iGG7gySQXk88KPiZ983pCgbMAEfldd9Q2xcmY4mUFqCC0XJktQZXqnELie3I4txGiiF/66nCv7DdwUR0DSlH9Y89NqIsk5FA+S1l4r23G/AYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668769; c=relaxed/simple; bh=CYL78L9ih/Kr5eLuAqMgq+8E+45km9xjtzZNPt4WYs4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rMB+lpp7MhU/RZBOguioo7DmSPQSUViHcSjzqF9ub2oNuZ8BqD4L3XFfLG7w5s9FhpETwXAdDE1egiZeSnWCB/VGc2dAnoqIRSPHu+TISgeawccvjwDxMIZnVFg4eqM2vq+7E1Px+3v3gyLNRTKuDF8QrTBLfVEo9t85rWFjiQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W5wfDs9l; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W5wfDs9l" Received: by smtp.kernel.org (Postfix) with ESMTPS id 382F1C4CED7; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726668769; bh=CYL78L9ih/Kr5eLuAqMgq+8E+45km9xjtzZNPt4WYs4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=W5wfDs9legPCf7O/PJbjKV7yQaeXHHsrQ7/szrdKXIgzgMpHxcZenTSVatf+Trgjf 69xxRlcFrQtrCpaLcl3D9/K7acaMh7GFgJtWYpzKVjw9F7kHhT3tZyf7fz19Zzlb+M jF2x8eAHiEFzMya1CqVmJ8NqWR8z3ivKXJs0l/T8sOYJY/besq59ZyGheIDSMU7WSS PDS7UlYCuMe77l3181HbJVcMq8bTTXHWexxAjsfgnDeRyBOFLhXwRpwxj0mvgfoTPZ p1Qzv6U/pqR4iFZY+aA//hN0JS+K/MuaUGigu8XxN863fxfMpI/vO9MZ3rUqTQoyzI F3vrTM5j+GOSQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 314B3CCD1AB; Wed, 18 Sep 2024 14:12:49 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 18 Sep 2024 22:12:25 +0800 Subject: [PATCH v5.4-v4.19 6/6] vfs: support statx(..., NULL, AT_EMPTY_PATH, ...) Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240918-statx-stable-linux-5-4-y-v1-6-8a771c9bbe5f@gmail.com> References: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> In-Reply-To: <20240918-statx-stable-linux-5-4-y-v1-0-8a771c9bbe5f@gmail.com> To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: Xi Ruoyao , Christian Brauner , Alexander Viro , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Miao Wang , Mateusz Guzik X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3164; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=Mz70ynn0QmOv4iQYlvx/dmX1Pkma9wGWlUEA7jcK4og=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBm6t/dGuOjI9aYmI1LQfgwrbw0dZPMapB67Fl5U Px5kKe2npWJAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZurf3QAKCRCwMePKe/7Z bh8DD/9HS5BdVsTPeo/HHJUotxCRxYTUhGJighDBkTNcGK0dO63iAVafsGuImCuoSdjKdvUC9rE 3TRGLdB+VaxHyxnCcSfxDuXeIIS+CUBLcvI1oLAOOGgCNIN5r3gRUxLPnIeugyQ+awOZg3qHRko VJNHxjFtvW0AMI2Nj8XcEiC8b/vMFTiouia0Gx3K9hi9vDdgkVmRFKmtBsJDc1tQIw4I/QVXPTj y4hUXpHn6loOlcSBp1bOw40d+8kKWhsskqku3VqwIdMkV7J+QmjfhXaAXvRXWpncOcV7qAqP+cr FImQj89feRMFc+QGThtbz/VYqHgsxjXYIj1T6skMrfByzPVsgSC8B6JDl6HFAGe1p/zWEGBxY4X jf9ZG9Bv8JwBVylB1FxGklA+y71fXJ9tTpeCJMN6Y3/OTyYaytVNHmSBDNprppNrT+m8st8TQCk G6+rfxxkm0+Y2l0WenX+Z2mk1RxmVYmysNwEHvpLPhXbE0VGJXpjWqDbRhacKeyXzB5kBwYWNBk mdv2eqvr12fsi8tDXBgzFl3JxgSJrSxtHAykMiqon9Kee74M/7al1rWzt2oGQyM3Z7XXH31tDNH NBFp0zhz5heTqevgk4qLUifLEe4l+Mw/fK5GILEVdnp4Sst7608jqxzOLTAKHuWap8L/2Sn1udK jkaaUscsYWWbFGA== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang Reply-To: shankerwangmiao@gmail.com From: Mateusz Guzik commit 0ef625b upstream. The newly used helper also checks for empty ("") paths. NULL paths with any flag value other than AT_EMPTY_PATH go the usual route and end up with -EFAULT to retain compatibility (Rust is abusing calls of the sort to detect availability of statx). This avoids path lookup code, lockref management, memory allocation and in case of NULL path userspace memory access (which can be quite expensive with SMAP on x86_64). Benchmarked with statx(..., AT_EMPTY_PATH, ...) running on Sapphire Rapids, with the "" path for the first two cases and NULL for the last one. Results in ops/s: stock: 4231237 pre-check: 5944063 (+40%) NULL path: 6601619 (+11%/+56%) Signed-off-by: Mateusz Guzik Link: https://lore.kernel.org/r/20240625151807.620812-1-mjguzik@gmail.com Tested-by: Xi Ruoyao [brauner: use path_mounted() and other tweaks] Signed-off-by: Christian Brauner Cc: # 4.19.x-5.4.x Signed-off-by: Miao Wang Tested-by: Xi Ruoyao --- fs/stat.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 1aaa5d847db8..111443789ced 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -590,13 +590,14 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) /** * sys_statx - System call to get enhanced stats * @dfd: Base directory to pathwalk from *or* fd to stat. - * @filename: File to stat or "" with AT_EMPTY_PATH + * @filename: File to stat or either NULL or "" with AT_EMPTY_PATH * @flags: AT_* flags to control pathwalk. * @mask: Parts of statx struct actually required. * @buffer: Result buffer. * * Note that fstat() can be emulated by setting dfd to the fd of interest, - * supplying "" as the filename and setting AT_EMPTY_PATH in the flags. + * supplying "" (or preferably NULL) as the filename and setting AT_EMPTY_PATH + * in the flags. */ SYSCALL_DEFINE5(statx, int, dfd, const char __user *, filename, unsigned, flags, @@ -605,13 +606,29 @@ SYSCALL_DEFINE5(statx, { struct kstat stat; int error; + unsigned lflags; if (mask & STATX__RESERVED) return -EINVAL; if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE) return -EINVAL; - error = vfs_statx(dfd, filename, flags, &stat, mask); + /* + * Short-circuit handling of NULL and "" paths. + * + * For a NULL path we require and accept only the AT_EMPTY_PATH flag + * (possibly |'d with AT_STATX flags). + * + * However, glibc on 32-bit architectures implements fstatat as statx + * with the "" pathname and AT_NO_AUTOMOUNT | AT_EMPTY_PATH flags. + * Supporting this results in the uglification below. + */ + lflags = flags & ~(AT_NO_AUTOMOUNT | AT_STATX_SYNC_TYPE); + if (lflags == AT_EMPTY_PATH && vfs_empty_path(dfd, filename)) + error = vfs_statx_fd(dfd, &stat, mask, + flags & ~(AT_NO_AUTOMOUNT | AT_EMPTY_PATH)); + else + error = vfs_statx(dfd, filename, flags, &stat, mask); if (error) return error;