From: Christian Brauner brauner@kernel.org
mainline inclusion from mainline-v6.12-rc1 commit c65d41c5a5279738fc07f99c0e912b28a691c46f category: performance bugzilla: https://gitee.com/src-openeuler/kernel/issues/IB1S01
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
During O_CREAT we unconditionally audit the parent inode. This makes it difficult to support a fastpath for O_CREAT when the file already exists because we have to drop out of RCU lookup needlessly.
We worked around this by checking whether audit was actually active but that's also suboptimal. Instead, move the audit of the parent inode down into lookup_open() at a point where it's mostly certain that the file needs to be created.
This also reduced the inconsistency that currently exists: while audit on the parent is done independent of whether or no the file already existed an audit on the file is only performed if it has been created.
By moving the audit down a bit we emit the audit a little later but it will allow us to simplify the fastpath for O_CREAT significantly.
Signed-off-by: Christian Brauner brauner@kernel.org Signed-off-by: Jinjie Ruan ruanjinjie@huawei.com --- fs/namei.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/namei.c b/fs/namei.c index 7863f457f2e8..fbbcec1cbb46 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3433,6 +3433,9 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, return dentry; }
+ if (open_flag & O_CREAT) + audit_inode(nd->name, dir, AUDIT_INODE_PARENT); + /* * Checking write permission is tricky, bacuse we don't know if we are * going to actually need it: O_CREAT opens should work as long as the @@ -3588,7 +3591,6 @@ static const char *open_last_lookups(struct nameidata *nd, if (!unlazied) return ERR_PTR(-ECHILD); } - audit_inode(nd->name, dir, AUDIT_INODE_PARENT); if (trailing_slashes(nd)) { dput(dentry); return ERR_PTR(-EISDIR);