]> git.dujemihanovic.xyz Git - linux.git/commit
uidgid: make sure we fit into one cacheline
authorChristian Brauner <brauner@kernel.org>
Tue, 10 Sep 2024 08:16:39 +0000 (10:16 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 12 Sep 2024 10:16:09 +0000 (12:16 +0200)
commit2077006d4725c82c6e9612cec3a6c140921b067f
tree626702ababcf6dbe391cd931e2ea63b798185ea3
parent698e7d1680544ef114203b0cf656faa0c1216ebc
uidgid: make sure we fit into one cacheline

When I expanded uidgid mappings I intended for a struct uid_gid_map to
fit into a single cacheline on x86 as they tend to be pretty
performance sensitive (idmapped mounts etc). But a 4 byte hole was added
that brought it over 64 bytes. Fix that by adding the static extent
array and the extent counter into a substruct. C's type punning for
unions guarantees that we can access ->nr_extents even if the last
written to member wasn't within the same object. This is also what we
rely on in struct_group() and friends. This of course relies on
non-strict aliasing which we don't do.

99) If the member used to read the contents of a union object is not the
    same as the member last used to store a value in the object, the
    appropriate part of the object representation of the value is
    reinterpreted as an object representation in the new type as
    described in 6.2.6 (a process sometimes called "type punning").

Link: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2310.pdf
Link: https://lore.kernel.org/r/20240910-work-uid_gid_map-v1-1-e6bc761363ed@kernel.org
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/user_namespace.h
kernel/user.c