1 From 66a5c40f60f5d88ad8d47ba6a4ba05892853fa1f Mon Sep 17 00:00:00 2001
2 From: Tanzir Hasan <tanzirh@google.com>
3 Date: Tue, 26 Dec 2023 18:00:00 +0000
4 Subject: [PATCH] kernel.h: removed REPEAT_BYTE from kernel.h
6 This patch creates wordpart.h and includes it in asm/word-at-a-time.h
7 for all architectures. WORD_AT_A_TIME_CONSTANTS depends on kernel.h
8 because of REPEAT_BYTE. Moving this to another header and including it
9 where necessary allows us to not include the bloated kernel.h. Making
10 this implicit dependency on REPEAT_BYTE explicit allows for later
11 improvements in the lib/string.c inclusion list.
13 Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
14 Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
15 Signed-off-by: Tanzir Hasan <tanzirh@google.com>
16 Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
17 Link: https://lore.kernel.org/r/20231226-libstringheader-v6-1-80aa08c7652c@google.com
18 Signed-off-by: Kees Cook <keescook@chromium.org>
20 arch/arm/include/asm/word-at-a-time.h | 3 ++-
21 arch/arm64/include/asm/word-at-a-time.h | 3 ++-
22 arch/powerpc/include/asm/word-at-a-time.h | 4 ++--
23 arch/riscv/include/asm/word-at-a-time.h | 3 ++-
24 arch/s390/include/asm/word-at-a-time.h | 3 ++-
25 arch/sh/include/asm/word-at-a-time.h | 2 ++
26 arch/x86/include/asm/word-at-a-time.h | 3 ++-
27 arch/x86/kvm/mmu/mmu.c | 1 +
29 include/asm-generic/word-at-a-time.h | 3 ++-
30 include/linux/kernel.h | 8 --------
31 include/linux/wordpart.h | 13 +++++++++++++
32 12 files changed, 31 insertions(+), 17 deletions(-)
33 create mode 100644 include/linux/wordpart.h
35 --- a/arch/arm/include/asm/word-at-a-time.h
36 +++ b/arch/arm/include/asm/word-at-a-time.h
38 * Little-endian word-at-a-time zero byte handling.
39 * Heavily based on the x86 algorithm.
41 -#include <linux/kernel.h>
42 +#include <linux/bitops.h>
43 +#include <linux/wordpart.h>
45 struct word_at_a_time {
46 const unsigned long one_bits, high_bits;
47 --- a/arch/arm64/include/asm/word-at-a-time.h
48 +++ b/arch/arm64/include/asm/word-at-a-time.h
53 -#include <linux/kernel.h>
54 +#include <linux/bitops.h>
55 +#include <linux/wordpart.h>
57 struct word_at_a_time {
58 const unsigned long one_bits, high_bits;
59 --- a/arch/powerpc/include/asm/word-at-a-time.h
60 +++ b/arch/powerpc/include/asm/word-at-a-time.h
63 * Word-at-a-time interfaces for PowerPC.
66 -#include <linux/kernel.h>
67 +#include <linux/bitops.h>
68 +#include <linux/wordpart.h>
69 #include <asm/asm-compat.h>
70 #include <asm/extable.h>
72 --- a/arch/sh/include/asm/word-at-a-time.h
73 +++ b/arch/sh/include/asm/word-at-a-time.h
75 #ifdef CONFIG_CPU_BIG_ENDIAN
76 # include <asm-generic/word-at-a-time.h>
78 +#include <linux/bitops.h>
79 +#include <linux/wordpart.h>
81 * Little-endian version cribbed from x86.
83 --- a/arch/x86/include/asm/word-at-a-time.h
84 +++ b/arch/x86/include/asm/word-at-a-time.h
86 #ifndef _ASM_WORD_AT_A_TIME_H
87 #define _ASM_WORD_AT_A_TIME_H
89 -#include <linux/kernel.h>
90 +#include <linux/bitops.h>
91 +#include <linux/wordpart.h>
94 * This is largely generic for little-endian machines, but the
95 --- a/arch/x86/kvm/mmu/mmu.c
96 +++ b/arch/x86/kvm/mmu/mmu.c
98 #include <linux/kern_levels.h>
99 #include <linux/kstrtox.h>
100 #include <linux/kthread.h>
101 +#include <linux/wordpart.h>
103 #include <asm/page.h>
104 #include <asm/memtype.h>
109 #include <linux/init.h>
110 #include <linux/export.h>
111 -#include <linux/kernel.h>
112 #include <linux/slab.h>
113 +#include <linux/wordpart.h>
114 #include <linux/fs.h>
115 #include <linux/filelock.h>
116 #include <linux/namei.h>
117 --- a/include/asm-generic/word-at-a-time.h
118 +++ b/include/asm-generic/word-at-a-time.h
120 #ifndef _ASM_WORD_AT_A_TIME_H
121 #define _ASM_WORD_AT_A_TIME_H
123 -#include <linux/kernel.h>
124 +#include <linux/bitops.h>
125 +#include <linux/wordpart.h>
126 #include <asm/byteorder.h>
129 --- a/include/linux/kernel.h
130 +++ b/include/linux/kernel.h
133 #define STACK_MAGIC 0xdeadbeef
136 - * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
137 - * @x: value to repeat
139 - * NOTE: @x is not checked for > 0xff; larger values produce odd results.
141 -#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
143 /* generic data direction definitions */
147 +++ b/include/linux/wordpart.h
149 +/* SPDX-License-Identifier: GPL-2.0 */
151 +#ifndef _LINUX_WORDPART_H
152 +#define _LINUX_WORDPART_H
154 + * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
155 + * @x: value to repeat
157 + * NOTE: @x is not checked for > 0xff; larger values produce odd results.
159 +#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
161 +#endif // _LINUX_WORDPART_H