Skip to content

Commit

Permalink
cache: enforce cache groups
Browse files Browse the repository at this point in the history
Set up build time warnings to safeguard against future header changes of
organized structs.

Warning includes:

1) whether all variables are still in the same cache group
2) whether all the cache groups have the sum of the members size (in the
   maximum condition, including all members defined in configs)

The __cache_group* variables are ignored in kernel-doc check in the
various header files they appear in to enforce the cache groups.

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Coco Li <lixiaoyan@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Coco Li authored and David S. Miller committed Dec 2, 2023
1 parent 14006f1 commit aeb9ce0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/linux/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@
#define cache_line_size() L1_CACHE_BYTES
#endif

#ifndef __cacheline_group_begin
#define __cacheline_group_begin(GROUP) \
__u8 __cacheline_group_begin__##GROUP[0]
#endif

#ifndef __cacheline_group_end
#define __cacheline_group_end(GROUP) \
__u8 __cacheline_group_end__##GROUP[0]
#endif

#ifndef CACHELINE_ASSERT_GROUP_MEMBER
#define CACHELINE_ASSERT_GROUP_MEMBER(TYPE, GROUP, MEMBER) \
BUILD_BUG_ON(!(offsetof(TYPE, MEMBER) >= \
offsetofend(TYPE, __cacheline_group_begin__##GROUP) && \
offsetofend(TYPE, MEMBER) <= \
offsetof(TYPE, __cacheline_group_end__##GROUP)))
#endif

#ifndef CACHELINE_ASSERT_GROUP_SIZE
#define CACHELINE_ASSERT_GROUP_SIZE(TYPE, GROUP, SIZE) \
BUILD_BUG_ON(offsetof(TYPE, __cacheline_group_end__##GROUP) - \
offsetofend(TYPE, __cacheline_group_begin__##GROUP) > \
SIZE)
#endif

/*
* Helper to add padding within a struct to ensure data fall into separate
* cachelines.
Expand Down
5 changes: 5 additions & 0 deletions scripts/kernel-doc
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,11 @@ sub push_parameter($$$$$) {
$parameterdescs{$param} = "anonymous\n";
$anon_struct_union = 1;
}
elsif ($param =~ "__cacheline_group" )
# handle cache group enforcing variables: they do not need be described in header files
{
return; # ignore __cacheline_group_begin and __cacheline_group_end
}

# warn if parameter has no description
# (but ignore ones starting with # as these are not parameters
Expand Down

0 comments on commit aeb9ce0

Please sign in to comment.