* [PATCH v6 0/2] shrink lib/string.i via IWYU
@ 2023-12-26 17:59 Tanzir Hasan
2023-12-26 18:00 ` [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h Tanzir Hasan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tanzir Hasan @ 2023-12-26 17:59 UTC (permalink / raw)
To: Kees Cook, Nick Desaulniers
Cc: Andy Shevchenko, linux-hardening, linux-kernel, Andrew Morton,
Greg KH, llvm, Al Viro, Andy Shevchenko, Tanzir Hasan
This patch series changes the include list of string.c to minimize
the preprocessing size. The patch series intends to remove REPEAT_BYE
from kernel.h and move it into its own header file because
word-at-a-time.h has an implicit dependancy on it but it is declared
in kernel.h which is bloated.
---
---
Changes in v6:
- added linux/bitops.h to wordpart.h
- removed kernel.h from x86
- Link to v5: https://lore.kernel.org/r/20231219-libstringheader-v5-0-206d4afd309a@google.com
Changes in v5:
- Removed bad copyright.
- Link to v4: https://lore.kernel.org/r/20231219-libstringheader-v4-0-aaeb26495d2f@google.com
Changes in v4:
- Fixed personal email client so name appears instead of just email
- Removed kernel.h where not needed.
- Sorted include list in lib/string.c and used linux/limits.h
- Link to v3: https://lore.kernel.org/r/20231218-libstringheader-v3-0-500bd58f0f75@google.com
Changes in v3:
- Moved REPEAT_BYTE out of kernel.h and into wordpart.h.
- Included wordpart.h where REPEAT_BYTE was necessary.
- Link to v2: https://lore.kernel.org/r/20231214-libstringheader-v2-0-0f195dcff204@google.com
Changes in v2:
- Transformed into a patch series
- Changed asm inclusions to linux inclusions
- added a patch to sh
- Link to v1: https://lore.kernel.org/r/20231205-libstringheader-v1-1-7f9c573053a7@gmail.com
---
Tanzir Hasan (2):
kernel.h: removed REPEAT_BYTE from kernel.h
lib/string: shrink lib/string.i via IWYU
arch/arm/include/asm/word-at-a-time.h | 3 ++-
arch/arm64/include/asm/word-at-a-time.h | 3 ++-
arch/powerpc/include/asm/word-at-a-time.h | 4 ++--
arch/riscv/include/asm/word-at-a-time.h | 3 ++-
arch/s390/include/asm/word-at-a-time.h | 3 ++-
arch/sh/include/asm/word-at-a-time.h | 2 ++
arch/x86/include/asm/word-at-a-time.h | 3 ++-
arch/x86/kvm/mmu/mmu.c | 1 +
fs/namei.c | 2 +-
include/asm-generic/word-at-a-time.h | 3 ++-
include/linux/kernel.h | 7 -------
include/linux/wordpart.h | 14 ++++++++++++++
lib/string.c | 17 +++++++++--------
13 files changed, 41 insertions(+), 24 deletions(-)
---
base-commit: ceb6a6f023fd3e8b07761ed900352ef574010bcb
change-id: 20231204-libstringheader-e238e2af5eec
Best regards,
--
Tanzir Hasan <tanzirh@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h
2023-12-26 17:59 [PATCH v6 0/2] shrink lib/string.i via IWYU Tanzir Hasan
@ 2023-12-26 18:00 ` Tanzir Hasan
2023-12-27 16:53 ` Andy Shevchenko
2023-12-26 18:00 ` [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU Tanzir Hasan
2024-02-01 17:52 ` [PATCH v6 0/2] " Kees Cook
2 siblings, 1 reply; 7+ messages in thread
From: Tanzir Hasan @ 2023-12-26 18:00 UTC (permalink / raw)
To: Kees Cook, Nick Desaulniers
Cc: Andy Shevchenko, linux-hardening, linux-kernel, Andrew Morton,
Greg KH, llvm, Al Viro, Andy Shevchenko, Tanzir Hasan
This patch creates wordpart.h and includes it in asm/word-at-a-time.h
for all architectures. WORD_AT_A_TIME_CONSTANTS depends on kernel.h
because of REPEAT_BYTE. Moving this to another header and including it
where necessary allows us to not include the bloated kernel.h. Making
this implicit dependency on REPEAT_BYTE explicit allows for later
improvements in the lib/string.c inclusion list.
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Tanzir Hasan <tanzirh@google.com>
---
| 3 ++-
| 3 ++-
| 4 ++--
| 3 ++-
| 3 ++-
| 2 ++
| 3 ++-
| 1 +
| 2 +-
| 3 ++-
| 7 -------
| 14 ++++++++++++++
12 files changed, 32 insertions(+), 16 deletions(-)
--git a/arch/arm/include/asm/word-at-a-time.h b/arch/arm/include/asm/word-at-a-time.h
index 352ab213520d..f9a3897b06e7 100644
--- a/arch/arm/include/asm/word-at-a-time.h
+++ b/arch/arm/include/asm/word-at-a-time.h
@@ -8,7 +8,8 @@
* Little-endian word-at-a-time zero byte handling.
* Heavily based on the x86 algorithm.
*/
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
struct word_at_a_time {
const unsigned long one_bits, high_bits;
--git a/arch/arm64/include/asm/word-at-a-time.h b/arch/arm64/include/asm/word-at-a-time.h
index f3b151ed0d7a..14251abee23c 100644
--- a/arch/arm64/include/asm/word-at-a-time.h
+++ b/arch/arm64/include/asm/word-at-a-time.h
@@ -9,7 +9,8 @@
#ifndef __AARCH64EB__
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
struct word_at_a_time {
const unsigned long one_bits, high_bits;
--git a/arch/powerpc/include/asm/word-at-a-time.h b/arch/powerpc/include/asm/word-at-a-time.h
index 30a12d208687..54653a863414 100644
--- a/arch/powerpc/include/asm/word-at-a-time.h
+++ b/arch/powerpc/include/asm/word-at-a-time.h
@@ -4,8 +4,8 @@
/*
* Word-at-a-time interfaces for PowerPC.
*/
-
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
#include <asm/asm-compat.h>
#include <asm/extable.h>
--git a/arch/riscv/include/asm/word-at-a-time.h b/arch/riscv/include/asm/word-at-a-time.h
index 7c086ac6ecd4..fae33cc04f8d 100644
--- a/arch/riscv/include/asm/word-at-a-time.h
+++ b/arch/riscv/include/asm/word-at-a-time.h
@@ -9,7 +9,8 @@
#define _ASM_RISCV_WORD_AT_A_TIME_H
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
struct word_at_a_time {
const unsigned long one_bits, high_bits;
--git a/arch/s390/include/asm/word-at-a-time.h b/arch/s390/include/asm/word-at-a-time.h
index 2579f1694b82..203acd6e431b 100644
--- a/arch/s390/include/asm/word-at-a-time.h
+++ b/arch/s390/include/asm/word-at-a-time.h
@@ -2,7 +2,8 @@
#ifndef _ASM_WORD_AT_A_TIME_H
#define _ASM_WORD_AT_A_TIME_H
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
#include <asm/asm-extable.h>
#include <asm/bitsperlong.h>
--git a/arch/sh/include/asm/word-at-a-time.h b/arch/sh/include/asm/word-at-a-time.h
index 4aa398455b94..95100ce128d6 100644
--- a/arch/sh/include/asm/word-at-a-time.h
+++ b/arch/sh/include/asm/word-at-a-time.h
@@ -5,6 +5,8 @@
#ifdef CONFIG_CPU_BIG_ENDIAN
# include <asm-generic/word-at-a-time.h>
#else
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
/*
* Little-endian version cribbed from x86.
*/
--git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
index 46b4f1f7f354..e8d7d4941c4c 100644
--- a/arch/x86/include/asm/word-at-a-time.h
+++ b/arch/x86/include/asm/word-at-a-time.h
@@ -2,7 +2,8 @@
#ifndef _ASM_WORD_AT_A_TIME_H
#define _ASM_WORD_AT_A_TIME_H
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
/*
* This is largely generic for little-endian machines, but the
--git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index c57e181bba21..75d0f6b11a48 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -47,6 +47,7 @@
#include <linux/kern_levels.h>
#include <linux/kstrtox.h>
#include <linux/kthread.h>
+#include <linux/wordpart.h>
#include <asm/page.h>
#include <asm/memtype.h>
--git a/fs/namei.c b/fs/namei.c
index 71c13b2990b4..189ea53ad635 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -17,8 +17,8 @@
#include <linux/init.h>
#include <linux/export.h>
-#include <linux/kernel.h>
#include <linux/slab.h>
+#include <linux/wordpart.h>
#include <linux/fs.h>
#include <linux/filelock.h>
#include <linux/namei.h>
--git a/include/asm-generic/word-at-a-time.h b/include/asm-generic/word-at-a-time.h
index 95a1d214108a..ef3f841c6625 100644
--- a/include/asm-generic/word-at-a-time.h
+++ b/include/asm-generic/word-at-a-time.h
@@ -2,7 +2,8 @@
#ifndef _ASM_WORD_AT_A_TIME_H
#define _ASM_WORD_AT_A_TIME_H
-#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/wordpart.h>
#include <asm/byteorder.h>
#ifdef __BIG_ENDIAN
--git a/include/linux/kernel.h b/include/linux/kernel.h
index d9ad21058eed..162660af5b7d 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -39,13 +39,6 @@
#define STACK_MAGIC 0xdeadbeef
-/**
- * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
- * @x: value to repeat
- *
- * NOTE: @x is not checked for > 0xff; larger values produce odd results.
- */
-#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
/* generic data direction definitions */
#define READ 0
--git a/include/linux/wordpart.h b/include/linux/wordpart.h
new file mode 100644
index 000000000000..43c1a8ae5152
--- /dev/null
+++ b/include/linux/wordpart.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _LINUX_WORDPART_H
+#define _LINUX_WORDPART_H
+/**
+ * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
+ * @x: value to repeat
+ *
+ * NOTE: @x is not checked for > 0xff; larger values produce odd results.
+ */
+#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
+
+#endif // _LINUX_WORDPART_H
+
--
2.43.0.472.g3155946c3a-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU
2023-12-26 17:59 [PATCH v6 0/2] shrink lib/string.i via IWYU Tanzir Hasan
2023-12-26 18:00 ` [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h Tanzir Hasan
@ 2023-12-26 18:00 ` Tanzir Hasan
2023-12-26 18:34 ` Andy Shevchenko
2024-02-01 17:52 ` [PATCH v6 0/2] " Kees Cook
2 siblings, 1 reply; 7+ messages in thread
From: Tanzir Hasan @ 2023-12-26 18:00 UTC (permalink / raw)
To: Kees Cook, Nick Desaulniers
Cc: Andy Shevchenko, linux-hardening, linux-kernel, Andrew Morton,
Greg KH, llvm, Tanzir Hasan
This diff uses an open source tool include-what-you-use (IWYU) to modify
the include list, changing indirect includes to direct includes. IWYU is
implemented using the IWYUScripts github repository which is a tool that
is currently undergoing development. These changes seek to improve build
times.
This change to lib/string.c resulted in a preprocessed size of
lib/string.i from 26371 lines to 5321 lines (-80%) for the x86
defconfig.
Link: https://github.com/ClangBuiltLinux/IWYUScripts
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Tanzir Hasan <tanzirh@google.com>
---
| 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
--git a/lib/string.c b/lib/string.c
index be26623953d2..06d9b46875ef 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -15,19 +15,20 @@
*/
#define __NO_FORTIFY
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/ctype.h>
-#include <linux/kernel.h>
-#include <linux/export.h>
+#include <linux/bits.h>
#include <linux/bug.h>
+#include <linux/ctype.h>
#include <linux/errno.h>
-#include <linux/slab.h>
+#include <linux/limits.h>
+#include <linux/linkage.h>
+#include <linux/stddef.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <asm/page.h>
+#include <asm/rwonce.h>
#include <asm/unaligned.h>
-#include <asm/byteorder.h>
#include <asm/word-at-a-time.h>
-#include <asm/page.h>
#ifndef __HAVE_ARCH_STRNCASECMP
/**
--
2.43.0.472.g3155946c3a-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU
2023-12-26 18:00 ` [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU Tanzir Hasan
@ 2023-12-26 18:34 ` Andy Shevchenko
2023-12-26 18:47 ` Tanzir Hasan
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2023-12-26 18:34 UTC (permalink / raw)
To: Tanzir Hasan
Cc: Kees Cook, Nick Desaulniers, Andy Shevchenko, linux-hardening,
linux-kernel, Andrew Morton, Greg KH, llvm
On Tue, Dec 26, 2023 at 8:00 PM Tanzir Hasan <tanzirh@google.com> wrote:
>
> This diff uses an open source tool include-what-you-use (IWYU) to modify
> the include list, changing indirect includes to direct includes. IWYU is
> implemented using the IWYUScripts github repository which is a tool that
> is currently undergoing development. These changes seek to improve build
> times.
>
> This change to lib/string.c resulted in a preprocessed size of
> lib/string.i from 26371 lines to 5321 lines (-80%) for the x86
> defconfig.
Why did you ignore my tag?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU
2023-12-26 18:34 ` Andy Shevchenko
@ 2023-12-26 18:47 ` Tanzir Hasan
0 siblings, 0 replies; 7+ messages in thread
From: Tanzir Hasan @ 2023-12-26 18:47 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Kees Cook, Nick Desaulniers, Andy Shevchenko, linux-hardening,
linux-kernel, Andrew Morton, Greg KH, llvm
On Tue, Dec 26, 2023 at 10:35 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Tue, Dec 26, 2023 at 8:00 PM Tanzir Hasan <tanzirh@google.com> wrote:
> >
> > This diff uses an open source tool include-what-you-use (IWYU) to modify
> > the include list, changing indirect includes to direct includes. IWYU is
> > implemented using the IWYUScripts github repository which is a tool that
> > is currently undergoing development. These changes seek to improve build
> > times.
> >
> > This change to lib/string.c resulted in a preprocessed size of
> > lib/string.i from 26371 lines to 5321 lines (-80%) for the x86
> > defconfig.
>
> Why did you ignore my tag?
I'm sorry. I forgot you had already reviewed this one. In a future
revision I will include this:
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Best,
Tanzir
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h
2023-12-26 18:00 ` [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h Tanzir Hasan
@ 2023-12-27 16:53 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-12-27 16:53 UTC (permalink / raw)
To: Tanzir Hasan
Cc: Kees Cook, Nick Desaulniers, linux-hardening, linux-kernel,
Andrew Morton, Greg KH, llvm, Al Viro
On Tue, Dec 26, 2023 at 06:00:00PM +0000, Tanzir Hasan wrote:
> This patch creates wordpart.h and includes it in asm/word-at-a-time.h
> for all architectures. WORD_AT_A_TIME_CONSTANTS depends on kernel.h
> because of REPEAT_BYTE. Moving this to another header and including it
> where necessary allows us to not include the bloated kernel.h. Making
> this implicit dependency on REPEAT_BYTE explicit allows for later
> improvements in the lib/string.c inclusion list.
LGTM, and I hope this will not trigger CIs and other build checkers.
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
...
> --- a/arch/powerpc/include/asm/word-at-a-time.h
> +++ b/arch/powerpc/include/asm/word-at-a-time.h
> @@ -4,8 +4,8 @@
> /*
> * Word-at-a-time interfaces for PowerPC.
> */
> -
You can preserve this blank line...
> -#include <linux/kernel.h>
> +#include <linux/bitops.h>
> +#include <linux/wordpart.h>
...here.
> #include <asm/asm-compat.h>
> #include <asm/extable.h>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v6 0/2] shrink lib/string.i via IWYU
2023-12-26 17:59 [PATCH v6 0/2] shrink lib/string.i via IWYU Tanzir Hasan
2023-12-26 18:00 ` [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h Tanzir Hasan
2023-12-26 18:00 ` [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU Tanzir Hasan
@ 2024-02-01 17:52 ` Kees Cook
2 siblings, 0 replies; 7+ messages in thread
From: Kees Cook @ 2024-02-01 17:52 UTC (permalink / raw)
To: Nick Desaulniers, Tanzir Hasan
Cc: Kees Cook, Andy Shevchenko, linux-hardening, linux-kernel,
Andrew Morton, Greg KH, llvm, Al Viro, Andy Shevchenko
On Tue, 26 Dec 2023 17:59:59 +0000, Tanzir Hasan wrote:
> This patch series changes the include list of string.c to minimize
> the preprocessing size. The patch series intends to remove REPEAT_BYE
> from kernel.h and move it into its own header file because
> word-at-a-time.h has an implicit dependancy on it but it is declared
> in kernel.h which is bloated.
>
Applied to for-next/hardening, thanks!
[1/2] kernel.h: removed REPEAT_BYTE from kernel.h
https://git.kernel.org/kees/c/66a5c40f60f5
[2/2] lib/string: shrink lib/string.i via IWYU
https://git.kernel.org/kees/c/38b9baf19469
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-02-01 17:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-26 17:59 [PATCH v6 0/2] shrink lib/string.i via IWYU Tanzir Hasan
2023-12-26 18:00 ` [PATCH v6 1/2] kernel.h: removed REPEAT_BYTE from kernel.h Tanzir Hasan
2023-12-27 16:53 ` Andy Shevchenko
2023-12-26 18:00 ` [PATCH v6 2/2] lib/string: shrink lib/string.i via IWYU Tanzir Hasan
2023-12-26 18:34 ` Andy Shevchenko
2023-12-26 18:47 ` Tanzir Hasan
2024-02-01 17:52 ` [PATCH v6 0/2] " Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).