Skip to contentSkip to conversation

kernel.h: Move upper_*_bits() and lower_*_bits() to wordpath.h

PATCH Applied Andy Shevchenko 4 participants 8 messages Feb 14, 2024 – Feb 15, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel.h: Move upper_*_bits() and lower_*_bits() to wordpath.h

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

This helps to clean up header dependency hell with regard to kernel.h as the latter gathers completely unrelated stuff together and slows down compilation (especially when it's included into other header).

---

Kees, since wordpart.h is now only in your tree, this is supposed to go there as well.

 include/linux/kernel.h   | 30 ++----------------------------
 include/linux/wordpart.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 28 deletions(-)
include/linux/kernel.h +2 -28
index 5f74733391ed..d718fbec72dd 100644
@@ -33,6 +33,8 @@
 #include <linux/sprintf.h>
 #include <linux/static_call_types.h>
 #include <linux/instruction_pointer.h>
+#include <linux/wordpart.h>
+
 #include <asm/byteorder.h>
 
 #include <uapi/linux/kernel.h>
@@ -52,34 +54,6 @@
 }					\
 )
 
-/**
- * upper_32_bits - return bits 32-63 of a number
- * @n: the number we're accessing
- *
- * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
- * the "right shift count >= width of type" warning when that quantity is
- * 32-bits.
- */
-#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
-
-/**
- * lower_32_bits - return bits 0-31 of a number
- * @n: the number we're accessing
- */
-#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
-
-/**
- * upper_16_bits - return bits 16-31 of a number
- * @n: the number we're accessing
- */
-#define upper_16_bits(n) ((u16)((n) >> 16))
-
-/**
- * lower_16_bits - return bits 0-15 of a number
- * @n: the number we're accessing
- */
-#define lower_16_bits(n) ((u16)((n) & 0xffff))
-
 struct completion;
 struct user;
 
include/linux/wordpart.h +29 -0
index c9e6bd773ebd..f6f8f83b15b0 100644
@@ -2,6 +2,35 @@
 
 #ifndef _LINUX_WORDPART_H
 #define _LINUX_WORDPART_H
+
+/**
+ * upper_32_bits - return bits 32-63 of a number
+ * @n: the number we're accessing
+ *
+ * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
+ * the "right shift count >= width of type" warning when that quantity is
+ * 32-bits.
+ */
+#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
+
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
+
+/**
+ * upper_16_bits - return bits 16-31 of a number
+ * @n: the number we're accessing
+ */
+#define upper_16_bits(n) ((u16)((n) >> 16))
+
+/**
+ * lower_16_bits - return bits 0-15 of a number
+ * @n: the number we're accessing
+ */
+#define lower_16_bits(n) ((u16)((n) & 0xffff))
+
 /**
  * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
  * @x: value to repeat
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andy Shevchenko

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

This helps to clean up header dependency hell with regard to kernel.h as the latter gathers completely unrelated stuff together and slows down compilation (especially when it's included into other header).

Quoted 5 lines

---

Kees, since wordpart.h is now only in your tree, this is supposed to go there as well.

after someone corrects the Subject (wordpath -> wordpart).

Quoted 93 lines
 include/linux/kernel.h   | 30 ++----------------------------
 include/linux/wordpart.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 28 deletions(-)
include/linux/kernel.h +2 -28
index 5f74733391ed..d718fbec72dd 100644
@@ -33,6 +33,8 @@
 #include <linux/sprintf.h>
 #include <linux/static_call_types.h>
 #include <linux/instruction_pointer.h>
+#include <linux/wordpart.h>
+
 #include <asm/byteorder.h>
 
 #include <uapi/linux/kernel.h>
@@ -52,34 +54,6 @@
 }					\
 )
 
-/**
- * upper_32_bits - return bits 32-63 of a number
- * @n: the number we're accessing
- *
- * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
- * the "right shift count >= width of type" warning when that quantity is
- * 32-bits.
- */
-#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
-
-/**
- * lower_32_bits - return bits 0-31 of a number
- * @n: the number we're accessing
- */
-#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
-
-/**
- * upper_16_bits - return bits 16-31 of a number
- * @n: the number we're accessing
- */
-#define upper_16_bits(n) ((u16)((n) >> 16))
-
-/**
- * lower_16_bits - return bits 0-15 of a number
- * @n: the number we're accessing
- */
-#define lower_16_bits(n) ((u16)((n) & 0xffff))
-
 struct completion;
 struct user;
 
include/linux/wordpart.h +29 -0
index c9e6bd773ebd..f6f8f83b15b0 100644
@@ -2,6 +2,35 @@
 
 #ifndef _LINUX_WORDPART_H
 #define _LINUX_WORDPART_H
+
+/**
+ * upper_32_bits - return bits 32-63 of a number
+ * @n: the number we're accessing
+ *
+ * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
+ * the "right shift count >= width of type" warning when that quantity is
+ * 32-bits.
+ */
+#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
+
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
+
+/**
+ * upper_16_bits - return bits 16-31 of a number
+ * @n: the number we're accessing
+ */
+#define upper_16_bits(n) ((u16)((n) >> 16))
+
+/**
+ * lower_16_bits - return bits 0-15 of a number
+ * @n: the number we're accessing
+ */
+#define lower_16_bits(n) ((u16)((n) & 0xffff))
+
 /**
  * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value
  * @x: value to repeat
Signature · 1 line
#Randy
#2 lore raw
Quoted 9 lines · Randy Dunlap
Quoted 8 lines · Andy Shevchenko

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

This helps to clean up header dependency hell with regard to kernel.h as the latter gathers completely unrelated stuff together and slows down compilation (especially when it's included into other header).

Quoted 7 lines
Quoted 5 lines

---

Kees, since wordpart.h is now only in your tree, this is supposed to go there as well.

after someone corrects the Subject (wordpath -> wordpart).

Oh, indeed. Thanks for spotting this!
Kees, should I send a v2 or you can amend when applying?

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Randy Dunlap
Quoted 11 lines · Andy Shevchenko

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

This helps to clean up header dependency hell with regard to kernel.h as the latter gathers completely unrelated stuff together and slows down compilation (especially when it's included into other header).

---

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Kees, since wordpart.h is now only in your tree, this is supposed to go there as well.

after someone corrects the Subject (wordpath -> wordpart).

Oh, indeed. Thanks for spotting this!
Kees, should I send a v2 or you can amend when applying?

I've amended it; thanks for the catch Randy!

-Kees

Quoted 10 lines
Quoted 2 lines

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 1 line
Kees Cook
Applied
#4 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

This helps to clean up header dependency hell with regard to kernel.h as the latter gathers completely unrelated stuff together and slows down compilation (especially when it's included into other header).

[...]

Applied to for-next/hardening, thanks!

[1/1] kernel.h: Move upper_*_bits() and lower_*_bits() to wordpart.h

      https://git.kernel.org/kees/c/9aa3bb490404

Take care,

Signature · 1 line
Kees Cook
#6 lore raw
Quoted 8 lines · Max Kellermann
Quoted 3 lines · Andy Shevchenko

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

Sigh. This was actually a copy of my patch which I submitted a week
before yours. https://lore.kernel.org/lkml/[email protected]/

But it was not standalone and the series has issues AFAICS. Nevertheless, I like it!

In any case the wordpart.h is only in Kees' tree, hence can't be applied separately right now, so if you continue with a series it's technically can't be applied before v6.9-rc1.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Max Kellermann
Quoted 3 lines · Andy Shevchenko

The wordpart.h header is collecting APIs related to the handling parts of the word (usually in byte granularity). The upper_*_bits() and lower_*_bits() are good candidates to be moved to there.

Sigh. This was actually a copy of my patch which I submitted a week
before yours. https://lore.kernel.org/lkml/[email protected]/

Quoted 6 lines

But it was not standalone and the series has issues AFAICS. Nevertheless, I like it!

In any case the wordpart.h is only in Kees' tree, hence can't be applied separately right now, so if you continue with a series it's technically can't be applied before v6.9-rc1.

Btw, you need to look to the patches by Ingo, you are repeating some of them.

Signature · 2 lines
With Best Regards,
Andy Shevchenko