Skip to content

Commit 9d2a621

Browse files
mjguzikbrauner
authored andcommitted
fs: tidy up step_into() & friends before inlining
Symlink handling is already marked as unlikely and pushing out some of it into pick_link() reduces register spillage on entry to step_into() with gcc 14.2. The compiler needed additional convincing that handle_mounts() is unlikely to fail. At the same time neither clang nor gcc could be convinced to tail-call into pick_link(). While pick_link() takes an address of stack-based object as an argument (which definitely prevents the optimization), splitting it into separate <dentry, mount> tuple did not help. The issue persists even when compiled without stack protector. As such nothing was done about this for the time being to not grow the diff. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://patch.msgid.link/20251120003803.2979978-1-mjguzik@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 1ed45a4 commit 9d2a621

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

fs/namei.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,13 +1672,15 @@ static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry,
16721672
path->dentry = dentry;
16731673
if (nd->flags & LOOKUP_RCU) {
16741674
unsigned int seq = nd->next_seq;
1675+
if (likely(!d_managed(dentry)))
1676+
return 0;
16751677
if (likely(__follow_mount_rcu(nd, path)))
16761678
return 0;
16771679
// *path and nd->next_seq might've been clobbered
16781680
path->mnt = nd->path.mnt;
16791681
path->dentry = dentry;
16801682
nd->next_seq = seq;
1681-
if (!try_to_unlazy_next(nd, dentry))
1683+
if (unlikely(!try_to_unlazy_next(nd, dentry)))
16821684
return -ECHILD;
16831685
}
16841686
ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags);
@@ -1941,13 +1943,23 @@ static int reserve_stack(struct nameidata *nd, struct path *link)
19411943

19421944
enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4};
19431945

1944-
static const char *pick_link(struct nameidata *nd, struct path *link,
1946+
static noinline const char *pick_link(struct nameidata *nd, struct path *link,
19451947
struct inode *inode, int flags)
19461948
{
19471949
struct saved *last;
19481950
const char *res;
1949-
int error = reserve_stack(nd, link);
1951+
int error;
1952+
1953+
if (nd->flags & LOOKUP_RCU) {
1954+
/* make sure that d_is_symlink from step_into() matches the inode */
1955+
if (read_seqcount_retry(&link->dentry->d_seq, nd->next_seq))
1956+
return ERR_PTR(-ECHILD);
1957+
} else {
1958+
if (link->mnt == nd->path.mnt)
1959+
mntget(link->mnt);
1960+
}
19501961

1962+
error = reserve_stack(nd, link);
19511963
if (unlikely(error)) {
19521964
if (!(nd->flags & LOOKUP_RCU))
19531965
path_put(link);
@@ -2026,9 +2038,10 @@ static const char *step_into(struct nameidata *nd, int flags,
20262038
{
20272039
struct path path;
20282040
struct inode *inode;
2029-
int err = handle_mounts(nd, dentry, &path);
2041+
int err;
20302042

2031-
if (err < 0)
2043+
err = handle_mounts(nd, dentry, &path);
2044+
if (unlikely(err < 0))
20322045
return ERR_PTR(err);
20332046
inode = path.dentry->d_inode;
20342047
if (likely(!d_is_symlink(path.dentry)) ||
@@ -2050,14 +2063,6 @@ static const char *step_into(struct nameidata *nd, int flags,
20502063
nd->seq = nd->next_seq;
20512064
return NULL;
20522065
}
2053-
if (nd->flags & LOOKUP_RCU) {
2054-
/* make sure that d_is_symlink above matches inode */
2055-
if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq))
2056-
return ERR_PTR(-ECHILD);
2057-
} else {
2058-
if (path.mnt == nd->path.mnt)
2059-
mntget(path.mnt);
2060-
}
20612066
return pick_link(nd, &path, inode, flags);
20622067
}
20632068

0 commit comments

Comments
 (0)