From: Al Viro <viro@zeniv.linux.org.uk>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC][PATCH] getname_maybe_null() - the third variant of pathname copy-in
Date: Fri, 18 Oct 2024 17:51:58 +0100 [thread overview]
Message-ID: <20241018165158.GA1172273@ZenIV> (raw)
In-Reply-To: <20241018-stadien-einweichen-32632029871a@brauner>
On Fri, Oct 18, 2024 at 01:06:12PM +0200, Christian Brauner wrote:
> > Look: all it takes is the following trick
> > * add const char *pathname to struct nameidata
> > * in __set_nameidata() add
> > p->pathname = likely(name) ? name->name : "";
> > * in path_init() replace
> > const char *s = nd->name->name;
> > with
> > const char *s = nd->pathname;
> > and we are done. Oh, and teach putname() to treat NULL as no-op.
>
> I know, that's what I suggested to Linus initially but he NAKed it
> because he didn't want the extra cycles.
Extra cycles where? If anything, I'd expect a too-small-to-measure
speedup due to dereference shifted from path_init() to __set_nameidata().
Below is literally all it takes to make filename_lookup() treat NULL
as empty-string name.
NOTE: I'm not talking about forcing the pure by-descriptor case through
the dfd+pathname codepath; not without serious profiling. But treating
AT_FDCWD + NULL by the delta below and passing NULL struct filename to
filename_lookup()? Where do you expect to have the lost cycles on that?
diff --git a/fs/namei.c b/fs/namei.c
index 4a4a22a08ac2..fc2053877e5c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -264,7 +264,7 @@ EXPORT_SYMBOL(getname_kernel);
void putname(struct filename *name)
{
- if (IS_ERR(name))
+ if (IS_ERR_OR_NULL(name))
return;
if (WARN_ON_ONCE(!atomic_read(&name->refcnt)))
@@ -588,6 +588,7 @@ struct nameidata {
unsigned seq;
} *stack, internal[EMBEDDED_LEVELS];
struct filename *name;
+ const char *pathname;
struct nameidata *saved;
unsigned root_seq;
int dfd;
@@ -606,6 +607,7 @@ static void __set_nameidata(struct nameidata *p, int dfd, struct filename *name)
p->depth = 0;
p->dfd = dfd;
p->name = name;
+ p->pathname = likely(name) ? name->name : "";
p->path.mnt = NULL;
p->path.dentry = NULL;
p->total_link_count = old ? old->total_link_count : 0;
@@ -2439,7 +2441,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
static const char *path_init(struct nameidata *nd, unsigned flags)
{
int error;
- const char *s = nd->name->name;
+ const char *s = nd->pathname;
/* LOOKUP_CACHED requires RCU, ask caller to retry */
if ((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED)
next prev parent reply other threads:[~2024-10-18 16:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 4:03 [RFC][PATCH] getname_maybe_null() - the third variant of pathname copy-in Al Viro
2024-10-15 14:05 ` Christian Brauner
2024-10-16 5:09 ` Al Viro
2024-10-16 8:32 ` Christian Brauner
2024-10-16 14:00 ` Al Viro
2024-10-16 14:49 ` Christian Brauner
2024-10-17 23:54 ` Al Viro
2024-10-18 11:06 ` Christian Brauner
2024-10-18 16:51 ` Al Viro [this message]
2024-10-18 19:38 ` Al Viro
2024-10-19 5:03 ` Al Viro
2024-10-19 16:15 ` Linus Torvalds
2024-10-19 17:11 ` Al Viro
2024-10-19 17:27 ` Linus Torvalds
2024-10-21 12:38 ` Christian Brauner
2024-10-21 12:39 ` Christian Brauner
2024-10-21 17:09 ` Al Viro
2024-10-21 22:43 ` Al Viro
2024-10-22 8:49 ` Christian Brauner
2024-10-30 6:37 ` Al Viro
2024-10-21 12:47 ` Christian Brauner
2024-10-21 17:05 ` Al Viro
2024-10-21 12:36 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241018165158.GA1172273@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).