diff mbox series

[v8,net-next,2/5] cache: enforce cache groups

Message ID 20231129072756.3684495-3-lixiaoyan@google.com (mailing list archive)
State Accepted
Commit aeb9ce058d7c6193dc41e06b3a5b29d22c446b14
Delegated to: Netdev Maintainers
Headers show
Series Analyze and Reorganize core Networking Structs to optimize cacheline consumption | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/codegen success Generated files up to date
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 15951 this patch: 15951
netdev/cc_maintainers warning 3 maintainers not CCed: linux-doc@vger.kernel.org catalin.marinas@arm.com akpm@linux-foundation.org
netdev/build_clang success Errors and warnings before: 3559 this patch: 3559
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 17143 this patch: 17143
netdev/checkpatch warning CHECK: Macro argument 'SIZE' may be better as '(SIZE)' to avoid precedence issues
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Coco Li Nov. 29, 2023, 7:27 a.m. UTC
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>
---
 include/linux/cache.h | 25 +++++++++++++++++++++++++
 scripts/kernel-doc    |  5 +++++
 2 files changed, 30 insertions(+)

Comments

Eric Dumazet Nov. 30, 2023, 10:40 a.m. UTC | #1
On Wed, Nov 29, 2023 at 8:28 AM Coco Li <lixiaoyan@google.com> wrote:
>
> 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>
> ---
>  include/linux/cache.h | 25 +++++++++++++++++++++++++
>  scripts/kernel-doc    |  5 +++++
>  2 files changed, 30 insertions(+)
>

Reviewed-by: Eric Dumazet <edumazet@google.com>
Jakub Kicinski Dec. 2, 2023, 4:20 a.m. UTC | #2
On Wed, 29 Nov 2023 07:27:53 +0000 Coco Li wrote:
> diff --git a/scripts/kernel-doc b/scripts/kernel-doc
> index 08a3e603db192..0a890fe4d22b1 100755
> --- a/scripts/kernel-doc
> +++ b/scripts/kernel-doc
> @@ -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

Hi Jon, would you be okay with this chunk going into net-next?
Shakeel Butt Dec. 2, 2023, 8:08 p.m. UTC | #3
On Wed, Nov 29, 2023 at 07:27:53AM +0000, Coco Li wrote:
> 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: Shakeel Butt <shakeelb@google.com>
diff mbox series

Patch

diff --git a/include/linux/cache.h b/include/linux/cache.h
index 9900d20b76c28..0ecb17bb68837 100644
--- a/include/linux/cache.h
+++ b/include/linux/cache.h
@@ -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.
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 08a3e603db192..0a890fe4d22b1 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -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