/**
  * setattr_should_drop_sgid - determine whether the setgid bit needs to be
  *                            removed
- * @mnt_userns:        user namespace of the mount @inode was found from
+ * @idmap:     idmap of the mount @inode was found from
  * @inode:     inode to check
  *
  * This function determines whether the setgid bit needs to be removed.
  *
  * Return: ATTR_KILL_SGID if setgid bit needs to be removed, 0 otherwise.
  */
-int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
+int setattr_should_drop_sgid(struct mnt_idmap *idmap,
                             const struct inode *inode)
 {
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        umode_t mode = inode->i_mode;
 
        if (!(mode & S_ISGID))
                return 0;
        if (mode & S_IXGRP)
                return ATTR_KILL_SGID;
-       if (!in_group_or_capable(mnt_userns, inode,
+       if (!in_group_or_capable(idmap, inode,
                                 i_gid_into_vfsgid(mnt_userns, inode)))
                return ATTR_KILL_SGID;
        return 0;
 /**
  * setattr_should_drop_suidgid - determine whether the set{g,u}id bit needs to
  *                               be dropped
- * @mnt_userns:        user namespace of the mount @inode was found from
+ * @idmap:     idmap of the mount @inode was found from
  * @inode:     inode to check
  *
  * This function determines whether the set{g,u}id bits need to be removed.
  * Return: A mask of ATTR_KILL_S{G,U}ID indicating which - if any - setid bits
  * to remove, 0 otherwise.
  */
-int setattr_should_drop_suidgid(struct user_namespace *mnt_userns,
+int setattr_should_drop_suidgid(struct mnt_idmap *idmap,
                                struct inode *inode)
 {
        umode_t mode = inode->i_mode;
        if (unlikely(mode & S_ISUID))
                kill = ATTR_KILL_SUID;
 
-       kill |= setattr_should_drop_sgid(mnt_userns, inode);
+       kill |= setattr_should_drop_sgid(idmap, inode);
 
        if (unlikely(kill && !capable(CAP_FSETID) && S_ISREG(mode)))
                return kill;
 
 /**
  * chown_ok - verify permissions to chown inode
- * @mnt_userns:        user namespace of the mount @inode was found from
+ * @idmap:     idmap of the mount @inode was found from
  * @inode:     inode to check permissions on
  * @ia_vfsuid: uid to chown @inode to
  *
- * If the inode has been found through an idmapped mount the user namespace of
- * the vfsmount must be passed through @mnt_userns. This function will then
- * take care to map the inode according to @mnt_userns before checking
+ * If the inode has been found through an idmapped mount the idmap of
+ * the vfsmount must be passed through @idmap. This function will then
+ * take care to map the inode according to @idmap before checking
  * permissions. On non-idmapped mounts or if permission checking is to be
- * performed on the raw inode simply passs init_user_ns.
+ * performed on the raw inode simply pass @nop_mnt_idmap.
  */
-static bool chown_ok(struct user_namespace *mnt_userns,
+static bool chown_ok(struct mnt_idmap *idmap,
                     const struct inode *inode, vfsuid_t ia_vfsuid)
 {
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
+
        vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
        if (vfsuid_eq_kuid(vfsuid, current_fsuid()) &&
            vfsuid_eq(ia_vfsuid, vfsuid))
                return true;
-       if (capable_wrt_inode_uidgid(mnt_userns, inode, CAP_CHOWN))
+       if (capable_wrt_inode_uidgid(idmap, inode, CAP_CHOWN))
                return true;
        if (!vfsuid_valid(vfsuid) &&
            ns_capable(inode->i_sb->s_user_ns, CAP_CHOWN))
 
 /**
  * chgrp_ok - verify permissions to chgrp inode
- * @mnt_userns:        user namespace of the mount @inode was found from
+ * @idmap:     idmap of the mount @inode was found from
  * @inode:     inode to check permissions on
  * @ia_vfsgid: gid to chown @inode to
  *
- * If the inode has been found through an idmapped mount the user namespace of
- * the vfsmount must be passed through @mnt_userns. This function will then
- * take care to map the inode according to @mnt_userns before checking
+ * If the inode has been found through an idmapped mount the idmap of
+ * the vfsmount must be passed through @idmap. This function will then
+ * take care to map the inode according to @idmap before checking
  * permissions. On non-idmapped mounts or if permission checking is to be
- * performed on the raw inode simply passs init_user_ns.
+ * performed on the raw inode simply pass @nop_mnt_idmap.
  */
-static bool chgrp_ok(struct user_namespace *mnt_userns,
+static bool chgrp_ok(struct mnt_idmap *idmap,
                     const struct inode *inode, vfsgid_t ia_vfsgid)
 {
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
+
        vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
        vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
        if (vfsuid_eq_kuid(vfsuid, current_fsuid())) {
                if (vfsgid_in_group_p(ia_vfsgid))
                        return true;
        }
-       if (capable_wrt_inode_uidgid(mnt_userns, inode, CAP_CHOWN))
+       if (capable_wrt_inode_uidgid(idmap, inode, CAP_CHOWN))
                return true;
        if (!vfsgid_valid(vfsgid) &&
            ns_capable(inode->i_sb->s_user_ns, CAP_CHOWN))
 
        /* Make sure a caller can chown. */
        if ((ia_valid & ATTR_UID) &&
-           !chown_ok(mnt_userns, inode, attr->ia_vfsuid))
+           !chown_ok(idmap, inode, attr->ia_vfsuid))
                return -EPERM;
 
        /* Make sure caller can chgrp. */
        if ((ia_valid & ATTR_GID) &&
-           !chgrp_ok(mnt_userns, inode, attr->ia_vfsgid))
+           !chgrp_ok(idmap, inode, attr->ia_vfsgid))
                return -EPERM;
 
        /* Make sure a caller can chmod. */
                        vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
 
                /* Also check the setgid bit! */
-               if (!in_group_or_capable(mnt_userns, inode, vfsgid))
+               if (!in_group_or_capable(idmap, inode, vfsgid))
                        attr->ia_mode &= ~S_ISGID;
        }
 
                inode->i_ctime = attr->ia_ctime;
        if (ia_valid & ATTR_MODE) {
                umode_t mode = attr->ia_mode;
-               if (!in_group_or_capable(mnt_userns, inode,
+               if (!in_group_or_capable(idmap, inode,
                                         i_gid_into_vfsgid(mnt_userns, inode)))
                        mode &= ~S_ISGID;
                inode->i_mode = mode;
 
                            struct inode *dir, struct dentry *victim, int isdir)
 {
        int error;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (d_really_is_negative(victim))
                return -ENOENT;
                return error;
        if (IS_APPEND(dir))
                return -EPERM;
-       if (check_sticky(mnt_userns, dir, d_inode(victim)) ||
+       if (check_sticky(idmap, dir, d_inode(victim)) ||
            IS_APPEND(d_inode(victim)) || IS_IMMUTABLE(d_inode(victim)) ||
            IS_SWAPFILE(d_inode(victim)))
                return -EPERM;
 
 {
        struct inode *inode = file_inode(file);
        struct mnt_idmap *idmap = file_mnt_idmap(file);
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        if (inode_permission(idmap, inode, MAY_READ) < 0) {
                struct user_namespace *old, *user_ns;
                bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
                /* Ensure mm->user_ns contains the executable */
                user_ns = old = bprm->mm->user_ns;
                while ((user_ns != &init_user_ns) &&
-                      !privileged_wrt_inode_uidgid(user_ns, mnt_userns, inode))
+                      !privileged_wrt_inode_uidgid(user_ns, idmap, inode))
                        user_ns = user_ns->parent;
 
                if (old != user_ns) {
 
        return __f2fs_get_acl(inode, type, NULL);
 }
 
-static int f2fs_acl_update_mode(struct user_namespace *mnt_userns,
+static int f2fs_acl_update_mode(struct mnt_idmap *idmap,
                                struct inode *inode, umode_t *mode_p,
                                struct posix_acl **acl)
 {
        umode_t mode = inode->i_mode;
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        int error;
 
        if (is_inode_flag_set(inode, FI_ACL_MODE))
        if (error == 0)
                *acl = NULL;
        if (!vfsgid_in_group_p(i_gid_into_vfsgid(mnt_userns, inode)) &&
-           !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
+           !capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
                mode &= ~S_ISGID;
        *mode_p = mode;
        return 0;
 }
 
-static int __f2fs_set_acl(struct user_namespace *mnt_userns,
+static int __f2fs_set_acl(struct mnt_idmap *idmap,
                        struct inode *inode, int type,
                        struct posix_acl *acl, struct page *ipage)
 {
        case ACL_TYPE_ACCESS:
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
                if (acl && !ipage) {
-                       error = f2fs_acl_update_mode(mnt_userns, inode,
+                       error = f2fs_acl_update_mode(idmap, inode,
                                                                &mode, &acl);
                        if (error)
                                return error;
 int f2fs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
                 struct posix_acl *acl, int type)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct inode *inode = d_inode(dentry);
 
        if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
                return -EIO;
 
-       return __f2fs_set_acl(mnt_userns, inode, type, acl, NULL);
+       return __f2fs_set_acl(idmap, inode, type, acl, NULL);
 }
 
 /*
 
                vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
 
                if (!vfsgid_in_group_p(vfsgid) &&
-                   !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
+                   !capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
                        mode &= ~S_ISGID;
                set_acl_inode(inode, mode);
        }
 
                }
 
                if (!vfsgid_in_group_p(i_gid_into_vfsgid(&init_user_ns, inode)) &&
-                   !capable_wrt_inode_uidgid(&init_user_ns, inode, CAP_FSETID))
+                   !capable_wrt_inode_uidgid(&nop_mnt_idmap, inode, CAP_FSETID))
                        extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
 
                ret = fuse_setxattr(inode, name, value, size, 0, extra_flags);
 
                        return err;
 
                if (fc->handle_killpriv_v2 &&
-                   setattr_should_drop_suidgid(&init_user_ns, file_inode(file))) {
+                   setattr_should_drop_suidgid(&nop_mnt_idmap,
+                                               file_inode(file))) {
                        goto writethrough;
                }
 
 
  * response to write or truncate. Return 0 if nothing has to be changed.
  * Negative value on error (change should be denied).
  */
-int dentry_needs_remove_privs(struct user_namespace *mnt_userns,
+int dentry_needs_remove_privs(struct mnt_idmap *idmap,
                              struct dentry *dentry)
 {
        struct inode *inode = d_inode(dentry);
        if (IS_NOSEC(inode))
                return 0;
 
-       mask = setattr_should_drop_suidgid(mnt_userns, inode);
+       mask = setattr_should_drop_suidgid(idmap, inode);
        ret = security_inode_need_killpriv(dentry);
        if (ret < 0)
                return ret;
        if (IS_NOSEC(inode) || !S_ISREG(inode->i_mode))
                return 0;
 
-       kill = dentry_needs_remove_privs(file_mnt_user_ns(file), dentry);
+       kill = dentry_needs_remove_privs(file_mnt_idmap(file), dentry);
        if (kill < 0)
                return kill;
 
 
 /**
  * in_group_or_capable - check whether caller is CAP_FSETID privileged
- * @mnt_userns: user namespace of the mount @inode was found from
+ * @idmap:     idmap of the mount @inode was found from
  * @inode:     inode to check
  * @vfsgid:    the new/current vfsgid of @inode
  *
  *
  * Return: true if the caller is sufficiently privileged, false if not.
  */
-bool in_group_or_capable(struct user_namespace *mnt_userns,
+bool in_group_or_capable(struct mnt_idmap *idmap,
                         const struct inode *inode, vfsgid_t vfsgid)
 {
        if (vfsgid_in_group_p(vfsgid))
                return true;
-       if (capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
+       if (capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
                return true;
        return false;
 }
 
 /**
  * mode_strip_sgid - handle the sgid bit for non-directories
- * @mnt_userns: User namespace of the mount the inode was created from
+ * @idmap: idmap of the mount the inode was created from
  * @dir: parent directory inode
  * @mode: mode of the file to be created in @dir
  *
  *
  * Return: the new mode to use for the file
  */
-umode_t mode_strip_sgid(struct user_namespace *mnt_userns,
+umode_t mode_strip_sgid(struct mnt_idmap *idmap,
                        const struct inode *dir, umode_t mode)
 {
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
+
        if ((mode & (S_ISGID | S_IXGRP)) != (S_ISGID | S_IXGRP))
                return mode;
        if (S_ISDIR(mode) || !dir || !(dir->i_mode & S_ISGID))
                return mode;
-       if (in_group_or_capable(mnt_userns, dir,
+       if (in_group_or_capable(idmap, dir,
                                i_gid_into_vfsgid(mnt_userns, dir)))
                return mode;
        return mode & ~S_ISGID;
 
  * inode.c
  */
 extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
-int dentry_needs_remove_privs(struct user_namespace *, struct dentry *dentry);
-bool in_group_or_capable(struct user_namespace *mnt_userns,
+int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry);
+bool in_group_or_capable(struct mnt_idmap *idmap,
                         const struct inode *inode, vfsgid_t vfsgid);
 
 /*
 /*
  * fs/attr.c
  */
-int setattr_should_drop_sgid(struct user_namespace *mnt_userns,
+int setattr_should_drop_sgid(struct mnt_idmap *idmap,
                             const struct inode *inode);
 
                       int mask)
 {
        int ret;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        /*
         * Do the basic permission checks.
        if (S_ISDIR(inode->i_mode)) {
                /* DACs are overridable for directories */
                if (!(mask & MAY_WRITE))
-                       if (capable_wrt_inode_uidgid(mnt_userns, inode,
+                       if (capable_wrt_inode_uidgid(idmap, inode,
                                                     CAP_DAC_READ_SEARCH))
                                return 0;
-               if (capable_wrt_inode_uidgid(mnt_userns, inode,
+               if (capable_wrt_inode_uidgid(idmap, inode,
                                             CAP_DAC_OVERRIDE))
                        return 0;
                return -EACCES;
         */
        mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
        if (mask == MAY_READ)
-               if (capable_wrt_inode_uidgid(mnt_userns, inode,
+               if (capable_wrt_inode_uidgid(idmap, inode,
                                             CAP_DAC_READ_SEARCH))
                        return 0;
        /*
         * at least one exec bit set.
         */
        if (!(mask & MAY_EXEC) || (inode->i_mode & S_IXUGO))
-               if (capable_wrt_inode_uidgid(mnt_userns, inode,
+               if (capable_wrt_inode_uidgid(idmap, inode,
                                             CAP_DAC_OVERRIDE))
                        return 0;
 
 }
 EXPORT_SYMBOL(user_path_at_empty);
 
-int __check_sticky(struct user_namespace *mnt_userns, struct inode *dir,
+int __check_sticky(struct mnt_idmap *idmap, struct inode *dir,
                   struct inode *inode)
 {
        kuid_t fsuid = current_fsuid();
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), fsuid))
                return 0;
        if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, dir), fsuid))
                return 0;
-       return !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FOWNER);
+       return !capable_wrt_inode_uidgid(idmap, inode, CAP_FOWNER);
 }
 EXPORT_SYMBOL(__check_sticky);
 
        if (IS_APPEND(dir))
                return -EPERM;
 
-       if (check_sticky(mnt_userns, dir, inode) || IS_APPEND(inode) ||
+       if (check_sticky(idmap, dir, inode) || IS_APPEND(inode) ||
            IS_IMMUTABLE(inode) || IS_SWAPFILE(inode) ||
            HAS_UNMAPPED_ID(idmap, inode))
                return -EPERM;
 
 /**
  * vfs_prepare_mode - prepare the mode to be used for a new inode
- * @mnt_userns:                user namespace of the mount the inode was found from
+ * @idmap:     idmap of the mount the inode was found from
  * @dir:       parent directory of the new inode
  * @mode:      mode of the new inode
  * @mask_perms:        allowed permission by the vfs
  *
  * Returns: mode to be passed to the filesystem
  */
-static inline umode_t vfs_prepare_mode(struct user_namespace *mnt_userns,
+static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap,
                                       const struct inode *dir, umode_t mode,
                                       umode_t mask_perms, umode_t type)
 {
-       mode = mode_strip_sgid(mnt_userns, dir, mode);
+       mode = mode_strip_sgid(idmap, dir, mode);
        mode = mode_strip_umask(dir, mode);
 
        /*
 int vfs_create(struct mnt_idmap *idmap, struct inode *dir,
               struct dentry *dentry, umode_t mode, bool want_excl)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        int error;
 
        error = may_create(idmap, dir, dentry);
        if (!dir->i_op->create)
                return -EACCES; /* shouldn't it be ENOSYS? */
 
-       mode = vfs_prepare_mode(mnt_userns, dir, mode, S_IALLUGO, S_IFREG);
+       mode = vfs_prepare_mode(idmap, dir, mode, S_IALLUGO, S_IFREG);
        error = security_inode_create(dir, dentry, mode);
        if (error)
                return error;
                                  bool got_write)
 {
        struct mnt_idmap *idmap;
-       struct user_namespace *mnt_userns;
        struct dentry *dir = nd->path.dentry;
        struct inode *dir_inode = dir->d_inode;
        int open_flag = op->open_flag;
        if (unlikely(!got_write))
                open_flag &= ~O_TRUNC;
        idmap = mnt_idmap(nd->path.mnt);
-       mnt_userns = mnt_idmap_owner(idmap);
        if (open_flag & O_CREAT) {
                if (open_flag & O_EXCL)
                        open_flag &= ~O_TRUNC;
-               mode = vfs_prepare_mode(mnt_userns, dir->d_inode, mode, mode, mode);
+               mode = vfs_prepare_mode(idmap, dir->d_inode, mode, mode, mode);
                if (likely(got_write))
                        create_error = may_o_create(idmap, &nd->path,
                                                    dentry, mode);
                       const struct path *parentpath,
                       struct file *file, umode_t mode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct dentry *child;
        struct inode *dir = d_inode(parentpath->dentry);
        struct inode *inode;
                return -ENOMEM;
        file->f_path.mnt = parentpath->mnt;
        file->f_path.dentry = child;
-       mode = vfs_prepare_mode(mnt_userns, dir, mode, mode, mode);
+       mode = vfs_prepare_mode(idmap, dir, mode, mode, mode);
        error = dir->i_op->tmpfile(idmap, dir, file, mode);
        dput(child);
        if (error)
 int vfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
              struct dentry *dentry, umode_t mode, dev_t dev)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        bool is_whiteout = S_ISCHR(mode) && dev == WHITEOUT_DEV;
        int error = may_create(idmap, dir, dentry);
 
        if (!dir->i_op->mknod)
                return -EPERM;
 
-       mode = vfs_prepare_mode(mnt_userns, dir, mode, mode, mode);
+       mode = vfs_prepare_mode(idmap, dir, mode, mode, mode);
        error = devcgroup_inode_mknod(mode, dev);
        if (error)
                return error;
 int vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
              struct dentry *dentry, umode_t mode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        int error;
        unsigned max_links = dir->i_sb->s_max_links;
 
        if (!dir->i_op->mkdir)
                return -EPERM;
 
-       mode = vfs_prepare_mode(mnt_userns, dir, mode, S_IRWXUGO | S_ISVTX, 0);
+       mode = vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, 0);
        error = security_inode_mkdir(dir, dentry, mode);
        if (error)
                return error;
 
                }
        }
 
-       if (file && setattr_should_drop_suidgid(&init_user_ns, file_inode(file))) {
+       if (file && setattr_should_drop_suidgid(&nop_mnt_idmap, file_inode(file))) {
                ret = __ocfs2_write_remove_suid(inode, di_bh);
                if (ret) {
                        mlog_errno(ret);
                 * inode. There's also the dinode i_size state which
                 * can be lost via setattr during extending writes (we
                 * set inode->i_size at the end of a write. */
-               if (setattr_should_drop_suidgid(&init_user_ns, inode)) {
+               if (setattr_should_drop_suidgid(&nop_mnt_idmap, inode)) {
                        if (meta_level == 0) {
                                ocfs2_inode_unlock_for_extent_tree(inode,
                                                                   &di_bh,
 
         * callers. */
        if (S_ISDIR(mode))
                set_nlink(inode, 2);
-       mode = mode_strip_sgid(&init_user_ns, dir, mode);
+       mode = mode_strip_sgid(&nop_mnt_idmap, dir, mode);
        inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
        status = dquot_initialize(inode);
        if (status)
 
 int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
                loff_t length, unsigned int time_attrs, struct file *filp)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        int ret;
        struct iattr newattrs;
 
        }
 
        /* Remove suid, sgid, and file capabilities on truncate too */
-       ret = dentry_needs_remove_privs(mnt_userns, dentry);
+       ret = dentry_needs_remove_privs(idmap, dentry);
        if (ret < 0)
                return ret;
        if (ret)
        inode_lock(inode);
        if (!S_ISDIR(inode->i_mode))
                newattrs.ia_valid |= ATTR_KILL_SUID | ATTR_KILL_PRIV |
-                                    setattr_should_drop_sgid(mnt_userns, inode);
+                                    setattr_should_drop_sgid(idmap, inode);
        /* Continue to send actual fs values, not the mount values. */
        error = security_path_chown(
                path,
 
         */
        if (unlikely(inode->i_mode & S_ISGID) && type == ACL_TYPE_ACCESS &&
            !in_group_p(inode->i_gid) &&
-           !capable_wrt_inode_uidgid(&init_user_ns, inode, CAP_FSETID)) {
+           !capable_wrt_inode_uidgid(&nop_mnt_idmap, inode, CAP_FSETID)) {
                struct iattr iattr = { .ia_valid = ATTR_KILL_SGID };
 
                err = ovl_setattr(&nop_mnt_idmap, dentry, &iattr);
 
        if (error == 0)
                *acl = NULL;
        if (!vfsgid_in_group_p(i_gid_into_vfsgid(mnt_userns, inode)) &&
-           !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
+           !capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
                mode &= ~S_ISGID;
        *mode_p = mode;
        return 0;
 
        struct dentry           *dentry,
        struct fileattr         *fa)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct xfs_inode        *ip = XFS_I(d_inode(dentry));
        struct xfs_mount        *mp = ip->i_mount;
        struct xfs_trans        *tp;
         */
 
        if ((VFS_I(ip)->i_mode & (S_ISUID|S_ISGID)) &&
-           !capable_wrt_inode_uidgid(mnt_userns, VFS_I(ip), CAP_FSETID))
+           !capable_wrt_inode_uidgid(idmap, VFS_I(ip), CAP_FSETID))
                VFS_I(ip)->i_mode &= ~(S_ISUID|S_ISGID);
 
        /* Change the ownerships and register project quota modifications */
 
 }
 #endif /* CONFIG_MULTIUSER */
 bool privileged_wrt_inode_uidgid(struct user_namespace *ns,
-                                struct user_namespace *mnt_userns,
+                                struct mnt_idmap *idmap,
                                 const struct inode *inode);
-bool capable_wrt_inode_uidgid(struct user_namespace *mnt_userns,
+bool capable_wrt_inode_uidgid(struct mnt_idmap *idmap,
                              const struct inode *inode, int cap);
 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
 extern bool ptracer_capable(struct task_struct *tsk, struct user_namespace *ns);
 
 void inode_init_owner(struct mnt_idmap *idmap, struct inode *inode,
                      const struct inode *dir, umode_t mode);
 extern bool may_open_dev(const struct path *path);
-umode_t mode_strip_sgid(struct user_namespace *mnt_userns,
+umode_t mode_strip_sgid(struct mnt_idmap *idmap,
                        const struct inode *dir, umode_t mode);
 
 /*
        return inode_permission(mnt_idmap(path->mnt),
                                d_inode(path->dentry), mask);
 }
-int __check_sticky(struct user_namespace *mnt_userns, struct inode *dir,
+int __check_sticky(struct mnt_idmap *idmap, struct inode *dir,
                   struct inode *inode);
 
 static inline bool execute_ok(struct inode *inode)
 extern struct inode *new_inode_pseudo(struct super_block *sb);
 extern struct inode *new_inode(struct super_block *sb);
 extern void free_inode_nonrcu(struct inode *inode);
-extern int setattr_should_drop_suidgid(struct user_namespace *, struct inode *);
+extern int setattr_should_drop_suidgid(struct mnt_idmap *, struct inode *);
 extern int file_remove_privs(struct file *);
 
 /*
        return mode & (S_ISUID | S_ISGID);
 }
 
-static inline int check_sticky(struct user_namespace *mnt_userns,
+static inline int check_sticky(struct mnt_idmap *idmap,
                               struct inode *dir, struct inode *inode)
 {
        if (!(dir->i_mode & S_ISVTX))
                return 0;
 
-       return __check_sticky(mnt_userns, dir, inode);
+       return __check_sticky(idmap, dir, inode);
 }
 
 static inline void inode_has_no_xattr(struct inode *inode)
 
  * Return true if the inode uid and gid are within the namespace.
  */
 bool privileged_wrt_inode_uidgid(struct user_namespace *ns,
-                                struct user_namespace *mnt_userns,
+                                struct mnt_idmap *idmap,
                                 const struct inode *inode)
 {
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
+
        return vfsuid_has_mapping(ns, i_uid_into_vfsuid(mnt_userns, inode)) &&
               vfsgid_has_mapping(ns, i_gid_into_vfsgid(mnt_userns, inode));
 }
  * its own user namespace and that the given inode's uid and gid are
  * mapped into the current user namespace.
  */
-bool capable_wrt_inode_uidgid(struct user_namespace *mnt_userns,
+bool capable_wrt_inode_uidgid(struct mnt_idmap *idmap,
                              const struct inode *inode, int cap)
 {
        struct user_namespace *ns = current_user_ns();
 
        return ns_capable(ns, cap) &&
-              privileged_wrt_inode_uidgid(ns, mnt_userns, inode);
+              privileged_wrt_inode_uidgid(ns, idmap, inode);
 }
 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
 
 
                return -EINVAL;
        if (!validheader(size, cap))
                return -EINVAL;
-       if (!capable_wrt_inode_uidgid(mnt_userns, inode, CAP_SETFCAP))
+       if (!capable_wrt_inode_uidgid(idmap, inode, CAP_SETFCAP))
                return -EPERM;
        if (size == XATTR_CAPS_SZ_2 && (idmap == &nop_mnt_idmap))
                if (ns_capable(inode->i_sb->s_user_ns, CAP_SETFCAP))
                          struct dentry *dentry, const char *name)
 {
        struct user_namespace *user_ns = dentry->d_sb->s_user_ns;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        /* Ignore non-security xattrs */
        if (strncmp(name, XATTR_SECURITY_PREFIX,
                struct inode *inode = d_backing_inode(dentry);
                if (!inode)
                        return -EINVAL;
-               if (!capable_wrt_inode_uidgid(mnt_userns, inode, CAP_SETFCAP))
+               if (!capable_wrt_inode_uidgid(idmap, inode, CAP_SETFCAP))
                        return -EPERM;
                return 0;
        }