mbox series

[RFC,0/3] mnt_idmapping: avoid pointer chase & inline low-level helpers

Message ID 20250416-work-mnt_idmap-s_user_ns-v1-0-273bef3a61ec@kernel.org (mailing list archive)
Headers show
Series mnt_idmapping: avoid pointer chase & inline low-level helpers | expand

Message

Christian Brauner April 16, 2025, 1:17 p.m. UTC
We currently always chase a pointer inode->i_sb->s_user_ns whenever we
need to map a uid/gid. Linus reported in [1] that this is noticable
during path lookup.

In the majority of cases we don't need to bother with that pointer chase
because the inode won't be located on a filesystem that's mounted in a
user namespace. The user namespace of the superblock cannot ever change
once it's mounted. So introduce and raise IOP_USERNS on all inodes and
check for that flag in i_user_ns() when we retrieve the user namespace.

Additionally, we now inline all low-level idmapping helpers.

[1]: https://lore.kernel.org/CAHk-=whJgRDtxTudTQ9HV8BFw5-bBsu+c8Ouwd_PrPqPB6_KEQ@mail.gmail.com

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
Christian Brauner (3):
      inode: add fastpath for filesystem user namespace retrieval
      mnt_idmapping: add struct mnt_idmap to header
      mnt_idmapping: inline all low-level helpers

 fs/inode.c                     |   6 ++
 fs/mnt_idmapping.c             | 165 ----------------------------------------
 include/linux/fs.h             |   5 +-
 include/linux/mnt_idmapping.h  | 168 +++++++++++++++++++++++++++++++++++++++--
 include/linux/uidgid.h         |  23 +++++-
 include/linux/user_namespace.h |  23 +-----
 kernel/user_namespace.c        |   2 +
 7 files changed, 195 insertions(+), 197 deletions(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250416-work-mnt_idmap-s_user_ns-eb57ee83e1d6