* [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h
@ 2024-02-15 9:36 Max Kellermann
2024-02-15 9:36 ` [PATCH v1 1/8] include/linux/goldfish.h: include linux/wordpart.h instead of linux/kernel.h Max Kellermann
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
This patch set aims to clean up the linux/kernel.h header and reduce
dependencies on it by moving parts out.
(These patches were part of my previous "fast kernel headers" pull
request which was found hard to review due to its huge size. I'm now
trying to resend smaller chunks of it, hoping they are easier to
review.)
Max Kellermann (8):
include/linux/goldfish.h: include linux/wordpart.h instead of
linux/kernel.h
include/drm/drm_fixed.h: include linux/wordpart.h instead of
linux/kernel.h
include linux/wordpart.h in various sources that need it
linux/random.h: reduce dependencies on linux/kernel.h
linux/kernel.h: move might_sleep(), ... to sched/debug_atomic_sleep.h
linux/kernel.h: move READ and WRITE to direction.h
linux/kernel.h: move VERIFY_OCTAL_PERMISSIONS() to octal_permissions.h
linux/kernel.h: move PTR_IF() to ptr_util.h
arch/arc/kernel/perf_event.c | 1 +
arch/arm64/include/asm/syscall.h | 1 +
arch/arm64/kvm/handle_exit.c | 1 +
drivers/bus/uniphier-system-bus.c | 1 +
drivers/edac/thunderx_edac.c | 1 +
drivers/gpio/gpio-sim.c | 1 +
drivers/gpu/drm/i915/i915_driver.c | 1 +
drivers/hwmon/occ/common.c | 1 +
drivers/input/misc/iqs7222.c | 1 +
drivers/irqchip/irq-gic-v3-its.c | 1 +
drivers/media/platform/amphion/vpu_dbg.c | 1 +
drivers/memstick/core/memstick.c | 1 +
drivers/memstick/host/jmb38x_ms.c | 1 +
drivers/memstick/host/r592.c | 1 +
drivers/memstick/host/rtsx_pci_ms.c | 1 +
drivers/memstick/host/rtsx_usb_ms.c | 1 +
drivers/memstick/host/tifm_ms.c | 1 +
drivers/pinctrl/pinctrl-ingenic.c | 1 +
drivers/soc/aspeed/aspeed-uart-routing.c | 1 +
drivers/spi/spi-pci1xxxx.c | 1 +
fs/ext4/super.c | 1 +
fs/hfs/hfs_fs.h | 1 +
fs/hfsplus/hfsplus_fs.h | 1 +
fs/notify/fanotify/fanotify_user.c | 1 +
fs/open.c | 1 +
fs/overlayfs/copy_up.c | 1 +
fs/ufs/util.h | 1 +
fs/xfs/xfs_error.c | 1 +
include/drm/drm_fixed.h | 2 +-
include/linux/clk.h | 1 +
include/linux/direction.h | 9 ++
include/linux/dma-fence.h | 1 +
include/linux/goldfish.h | 2 +-
include/linux/gpio/consumer.h | 2 +-
include/linux/kernel.h | 125 -----------------------
include/linux/mmu_notifier.h | 1 +
include/linux/moduleparam.h | 2 +-
include/linux/nd.h | 1 +
include/linux/octal_permissions.h | 20 ++++
include/linux/pm.h | 1 +
include/linux/ptr_util.h | 7 ++
include/linux/pwm.h | 2 +
include/linux/qed/common_hsi.h | 1 +
include/linux/random.h | 4 +-
include/linux/rcutiny.h | 1 +
include/linux/sched.h | 1 +
include/linux/sched/debug_atomic_sleep.h | 114 +++++++++++++++++++++
include/linux/sched/mm.h | 2 +-
include/linux/sysfs.h | 1 +
include/linux/uaccess.h | 1 +
include/linux/uio.h | 2 +-
include/linux/wait.h | 1 +
include/linux/wait_bit.h | 1 +
include/rdma/uverbs_ioctl.h | 3 +-
include/soc/fsl/bman.h | 2 +
include/soc/fsl/qman.h | 1 +
security/landlock/object.c | 1 +
security/landlock/ruleset.c | 1 +
58 files changed, 207 insertions(+), 134 deletions(-)
create mode 100644 include/linux/direction.h
create mode 100644 include/linux/octal_permissions.h
create mode 100644 include/linux/ptr_util.h
create mode 100644 include/linux/sched/debug_atomic_sleep.h
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 1/8] include/linux/goldfish.h: include linux/wordpart.h instead of linux/kernel.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 2/8] include/drm/drm_fixed.h: " Max Kellermann
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
This header only needs lower_32_bits() and upper_32_bits(), but
nothing else from kernel.h.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
include/linux/goldfish.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/goldfish.h b/include/linux/goldfish.h
index bcc17f95b906..8b2b3046f779 100644
--- a/include/linux/goldfish.h
+++ b/include/linux/goldfish.h
@@ -2,7 +2,7 @@
#ifndef __LINUX_GOLDFISH_H
#define __LINUX_GOLDFISH_H
-#include <linux/kernel.h>
+#include <linux/wordpart.h> // for lower_32_bits(), upper_32_bits()
#include <linux/types.h>
#include <linux/io.h>
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 2/8] include/drm/drm_fixed.h: include linux/wordpart.h instead of linux/kernel.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 1/8] include/linux/goldfish.h: include linux/wordpart.h instead of linux/kernel.h Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 3/8] include linux/wordpart.h in various sources that need it Max Kellermann
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
This header only needs lower_32_bits(), but nothing else from
kernel.h.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
include/drm/drm_fixed.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/drm/drm_fixed.h b/include/drm/drm_fixed.h
index 0c9f917a4d4b..ff9a91fa40b6 100644
--- a/include/drm/drm_fixed.h
+++ b/include/drm/drm_fixed.h
@@ -25,7 +25,7 @@
#ifndef DRM_FIXED_H
#define DRM_FIXED_H
-#include <linux/kernel.h>
+#include <linux/wordpart.h> // for lower_32_bits()
#include <linux/math64.h>
typedef union dfixed {
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 3/8] include linux/wordpart.h in various sources that need it
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 1/8] include/linux/goldfish.h: include linux/wordpart.h instead of linux/kernel.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 2/8] include/drm/drm_fixed.h: " Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 4/8] linux/random.h: reduce dependencies on linux/kernel.h Max Kellermann
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
After commit edf2f6fb51bc ("kernel.h: Move upper_*_bits() and
lower_*_bits() to wordpart.h"), the lower/upper_*_bits functions can
be found in that header, and all sources that use those functions
should include the header that provides it.
This is just the beginning, many more sources are still missing, but a
large patch adding the "#include" everywhere (700+ sources) would be
hard to review.
(Found with "git grep -E '\b(upper|lower)_(16|32)_bits\('")
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
arch/arm64/include/asm/syscall.h | 1 +
arch/arm64/kvm/handle_exit.c | 1 +
drivers/bus/uniphier-system-bus.c | 1 +
drivers/irqchip/irq-gic-v3-its.c | 1 +
drivers/spi/spi-pci1xxxx.c | 1 +
fs/ext4/super.c | 1 +
fs/hfs/hfs_fs.h | 1 +
fs/hfsplus/hfsplus_fs.h | 1 +
fs/notify/fanotify/fanotify_user.c | 1 +
fs/open.c | 1 +
fs/ufs/util.h | 1 +
include/linux/dma-fence.h | 1 +
include/linux/qed/common_hsi.h | 1 +
include/rdma/uverbs_ioctl.h | 2 +-
include/soc/fsl/bman.h | 2 ++
include/soc/fsl/qman.h | 1 +
16 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h
index ab8e14b96f68..e5f462cc1a54 100644
--- a/arch/arm64/include/asm/syscall.h
+++ b/arch/arm64/include/asm/syscall.h
@@ -8,6 +8,7 @@
#include <uapi/linux/audit.h>
#include <linux/compat.h>
#include <linux/err.h>
+#include <linux/wordpart.h> // for lower_32_bits()
typedef long (*syscall_fn_t)(const struct pt_regs *regs);
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index 617ae6dea5d5..91bd5b701acf 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -10,6 +10,7 @@
#include <linux/kvm.h>
#include <linux/kvm_host.h>
+#include <linux/wordpart.h> // for lower_32_bits(), upper_32_bits()
#include <asm/esr.h>
#include <asm/exception.h>
diff --git a/drivers/bus/uniphier-system-bus.c b/drivers/bus/uniphier-system-bus.c
index cb5c89ce7b86..964f31287d3c 100644
--- a/drivers/bus/uniphier-system-bus.c
+++ b/drivers/bus/uniphier-system-bus.c
@@ -10,6 +10,7 @@
#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
+#include <linux/wordpart.h> // for upper_32_bits()
/* System Bus Controller registers */
#define UNIPHIER_SBC_BASE 0x100 /* base address of bank0 space */
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 201055382bd1..94f917352ac6 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -29,6 +29,7 @@
#include <linux/percpu.h>
#include <linux/slab.h>
#include <linux/syscore_ops.h>
+#include <linux/wordpart.h> // for lower_32_bits(), upper_32_bits()
#include <linux/irqchip.h>
#include <linux/irqchip/arm-gic-v3.h>
diff --git a/drivers/spi/spi-pci1xxxx.c b/drivers/spi/spi-pci1xxxx.c
index 969965d7bc98..775673861c79 100644
--- a/drivers/spi/spi-pci1xxxx.c
+++ b/drivers/spi/spi-pci1xxxx.c
@@ -9,6 +9,7 @@
#include <linux/dma-mapping.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
+#include <linux/kernel.h> // for upper_32_bits(), lower_32_bits()
#include <linux/module.h>
#include <linux/msi.h>
#include <linux/pci_regs.h>
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e487623f9456..6a7686343bd0 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -48,6 +48,7 @@
#include <linux/fsnotify.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
+#include <linux/wordpart.h> // for lower_32_bits(), upper_32_bits()
#include "ext4.h"
#include "ext4_extents.h" /* Needed for trace points definition */
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h
index b5a6ad5df357..514d3856aa27 100644
--- a/fs/hfs/hfs_fs.h
+++ b/fs/hfs/hfs_fs.h
@@ -20,6 +20,7 @@
#include <linux/mutex.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
+#include <linux/wordpart.h> // for lower_32_bits()
#include <linux/workqueue.h>
#include <asm/byteorder.h>
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 7ededcb720c1..79cac82d050e 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -21,6 +21,7 @@
#include <linux/mutex.h>
#include <linux/buffer_head.h>
#include <linux/blkdev.h>
+#include <linux/wordpart.h> // for lower_32_bits()
#include "hfsplus_raw.h"
#define DBG_BNODE_REFS 0x00000001
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index fbdc63cc10d9..9ca5adbf39ae 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -20,6 +20,7 @@
#include <linux/memcontrol.h>
#include <linux/statfs.h>
#include <linux/exportfs.h>
+#include <linux/wordpart.h> // for upper_32_bits()
#include <asm/ioctls.h>
diff --git a/fs/open.c b/fs/open.c
index a7d4bb2c725f..b006de16a15a 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -34,6 +34,7 @@
#include <linux/compat.h>
#include <linux/mnt_idmapping.h>
#include <linux/filelock.h>
+#include <linux/wordpart.h> // for upper_32_bits()
#include "internal.h"
diff --git a/fs/ufs/util.h b/fs/ufs/util.h
index 0ecd2ed792f5..0d4b89794cc5 100644
--- a/fs/ufs/util.h
+++ b/fs/ufs/util.h
@@ -9,6 +9,7 @@
#include <linux/buffer_head.h>
#include <linux/fs.h>
+#include <linux/wordpart.h> // for lower_32_bits()
#include "swab.h"
/*
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index e06bad467f55..02ad83247ea8 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -22,6 +22,7 @@
#include <linux/printk.h>
#include <linux/rcupdate.h>
#include <linux/timekeeping.h>
+#include <linux/wordpart.h> // for lower_32_bits()
struct dma_fence;
struct dma_fence_ops;
diff --git a/include/linux/qed/common_hsi.h b/include/linux/qed/common_hsi.h
index 827624840ee2..fa9cc2be077f 100644
--- a/include/linux/qed/common_hsi.h
+++ b/include/linux/qed/common_hsi.h
@@ -11,6 +11,7 @@
#include <asm/byteorder.h>
#include <linux/bitops.h>
#include <linux/slab.h>
+#include <linux/wordpart.h> // for lower_32_bits(), upper_32_bits()
/* dma_addr_t manip */
#define PTR_LO(x) ((u32)(((uintptr_t)(x)) & 0xffffffff))
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index 06287de69cd2..5ed57a660ead 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
-/*
+ /*
* Copyright (c) 2017, Mellanox Technologies inc. All rights reserved.
*/
diff --git a/include/soc/fsl/bman.h b/include/soc/fsl/bman.h
index 173e4049d963..b01d8c0ac204 100644
--- a/include/soc/fsl/bman.h
+++ b/include/soc/fsl/bman.h
@@ -31,6 +31,8 @@
#ifndef __FSL_BMAN_H
#define __FSL_BMAN_H
+#include <linux/wordpart.h> // for upper_32_bits()
+
/* wrapper for 48-bit buffers */
struct bm_buffer {
union {
diff --git a/include/soc/fsl/qman.h b/include/soc/fsl/qman.h
index 0d3d6beb7fdb..c5230a844114 100644
--- a/include/soc/fsl/qman.h
+++ b/include/soc/fsl/qman.h
@@ -33,6 +33,7 @@
#include <linux/bitops.h>
#include <linux/device.h>
+#include <linux/wordpart.h> // for upper_32_bits()
/* Hardware constants */
#define QM_CHANNEL_SWPORTAL0 0
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 4/8] linux/random.h: reduce dependencies on linux/kernel.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
` (2 preceding siblings ...)
2024-02-15 9:36 ` [PATCH v1 3/8] include linux/wordpart.h in various sources that need it Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 5/8] linux/kernel.h: move might_sleep(), ... to sched/debug_atomic_sleep.h Max Kellermann
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
This header doesn't need kernel.h at all, but if we remove it, the
build breaks because kernel.h includes limits.h and log2.h, which
random.h needs.
list.h is also removed because it is not needed at all.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
include/linux/random.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/random.h b/include/linux/random.h
index b0a940af4fff..3183025ddda9 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -4,8 +4,8 @@
#define _LINUX_RANDOM_H
#include <linux/bug.h>
-#include <linux/kernel.h>
-#include <linux/list.h>
+#include <linux/limits.h> // for U32_MAX
+#include <linux/log2.h> // for is_power_of_2()
#include <uapi/linux/random.h>
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 5/8] linux/kernel.h: move might_sleep(), ... to sched/debug_atomic_sleep.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
` (3 preceding siblings ...)
2024-02-15 9:36 ` [PATCH v1 4/8] linux/random.h: reduce dependencies on linux/kernel.h Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 6/8] linux/kernel.h: move READ and WRITE to direction.h Max Kellermann
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
Reducing dependencies on the header linux/kernel.h.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
include/linux/clk.h | 1 +
include/linux/gpio/consumer.h | 2 +-
include/linux/kernel.h | 106 ---------------------
include/linux/mmu_notifier.h | 1 +
include/linux/pwm.h | 2 +
include/linux/rcutiny.h | 1 +
include/linux/sched.h | 1 +
include/linux/sched/debug_atomic_sleep.h | 114 +++++++++++++++++++++++
include/linux/sched/mm.h | 2 +-
include/linux/uaccess.h | 1 +
include/linux/wait.h | 1 +
include/linux/wait_bit.h | 1 +
security/landlock/object.c | 1 +
security/landlock/ruleset.c | 1 +
14 files changed, 127 insertions(+), 108 deletions(-)
create mode 100644 include/linux/sched/debug_atomic_sleep.h
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 06f1b292f8a0..2fcae620703b 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -12,6 +12,7 @@
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/notifier.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
struct device;
struct clk;
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index db2dfbae8edb..a02927330429 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -184,7 +184,7 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
#else /* CONFIG_GPIOLIB */
#include <linux/err.h>
-#include <linux/kernel.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
#include <asm/bug.h>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 86dd8939c2cd..f6a978d51c1d 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -57,112 +57,6 @@
struct completion;
struct user;
-#ifdef CONFIG_PREEMPT_VOLUNTARY_BUILD
-
-extern int __cond_resched(void);
-# define might_resched() __cond_resched()
-
-#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)
-
-extern int __cond_resched(void);
-
-DECLARE_STATIC_CALL(might_resched, __cond_resched);
-
-static __always_inline void might_resched(void)
-{
- static_call_mod(might_resched)();
-}
-
-#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)
-
-extern int dynamic_might_resched(void);
-# define might_resched() dynamic_might_resched()
-
-#else
-
-# define might_resched() do { } while (0)
-
-#endif /* CONFIG_PREEMPT_* */
-
-#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
-extern void __might_resched(const char *file, int line, unsigned int offsets);
-extern void __might_sleep(const char *file, int line);
-extern void __cant_sleep(const char *file, int line, int preempt_offset);
-extern void __cant_migrate(const char *file, int line);
-
-/**
- * might_sleep - annotation for functions that can sleep
- *
- * this macro will print a stack trace if it is executed in an atomic
- * context (spinlock, irq-handler, ...). Additional sections where blocking is
- * not allowed can be annotated with non_block_start() and non_block_end()
- * pairs.
- *
- * This is a useful debugging help to be able to catch problems early and not
- * be bitten later when the calling function happens to sleep when it is not
- * supposed to.
- */
-# define might_sleep() \
- do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0)
-/**
- * cant_sleep - annotation for functions that cannot sleep
- *
- * this macro will print a stack trace if it is executed with preemption enabled
- */
-# define cant_sleep() \
- do { __cant_sleep(__FILE__, __LINE__, 0); } while (0)
-# define sched_annotate_sleep() (current->task_state_change = 0)
-
-/**
- * cant_migrate - annotation for functions that cannot migrate
- *
- * Will print a stack trace if executed in code which is migratable
- */
-# define cant_migrate() \
- do { \
- if (IS_ENABLED(CONFIG_SMP)) \
- __cant_migrate(__FILE__, __LINE__); \
- } while (0)
-
-/**
- * non_block_start - annotate the start of section where sleeping is prohibited
- *
- * This is on behalf of the oom reaper, specifically when it is calling the mmu
- * notifiers. The problem is that if the notifier were to block on, for example,
- * mutex_lock() and if the process which holds that mutex were to perform a
- * sleeping memory allocation, the oom reaper is now blocked on completion of
- * that memory allocation. Other blocking calls like wait_event() pose similar
- * issues.
- */
-# define non_block_start() (current->non_block_count++)
-/**
- * non_block_end - annotate the end of section where sleeping is prohibited
- *
- * Closes a section opened by non_block_start().
- */
-# define non_block_end() WARN_ON(current->non_block_count-- == 0)
-#else
- static inline void __might_resched(const char *file, int line,
- unsigned int offsets) { }
-static inline void __might_sleep(const char *file, int line) { }
-# define might_sleep() do { might_resched(); } while (0)
-# define cant_sleep() do { } while (0)
-# define cant_migrate() do { } while (0)
-# define sched_annotate_sleep() do { } while (0)
-# define non_block_start() do { } while (0)
-# define non_block_end() do { } while (0)
-#endif
-
-#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
-
-#if defined(CONFIG_MMU) && \
- (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP))
-#define might_fault() __might_fault(__FILE__, __LINE__)
-void __might_fault(const char *file, int line);
-#else
-static inline void might_fault(void) { }
-#endif
-
void do_exit(long error_code) __noreturn;
extern int get_option(char **str, int *pint);
diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
index f349e08a9dfe..ac6bca927257 100644
--- a/include/linux/mmu_notifier.h
+++ b/include/linux/mmu_notifier.h
@@ -6,6 +6,7 @@
#include <linux/spinlock.h>
#include <linux/mm_types.h>
#include <linux/mmap_lock.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
#include <linux/srcu.h>
#include <linux/interval_tree.h>
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 8ffe9ae7a23a..334cacfcb74a 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -402,6 +402,8 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
struct fwnode_handle *fwnode,
const char *con_id);
#else
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
+
static inline bool pwm_might_sleep(struct pwm_device *pwm)
{
return true;
diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
index d9ac7b136aea..e7b6acfbf054 100644
--- a/include/linux/rcutiny.h
+++ b/include/linux/rcutiny.h
@@ -12,6 +12,7 @@
#ifndef __LINUX_TINY_H
#define __LINUX_TINY_H
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
#include <asm/param.h> /* for HZ */
struct rcu_gp_oldstate {
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3c2abbc587b4..74167388ca72 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -31,6 +31,7 @@
#include <linux/refcount_types.h>
#include <linux/resource.h>
#include <linux/latencytop.h>
+#include <linux/sched/debug_atomic_sleep.h> // for __might_resched()
#include <linux/sched/prio.h>
#include <linux/sched/types.h>
#include <linux/signal_types.h>
diff --git a/include/linux/sched/debug_atomic_sleep.h b/include/linux/sched/debug_atomic_sleep.h
new file mode 100644
index 000000000000..018d4a421a80
--- /dev/null
+++ b/include/linux/sched/debug_atomic_sleep.h
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_SCHED_DEBUG_ATOMIC_SLEEP_H
+#define _LINUX_SCHED_DEBUG_ATOMIC_SLEEP_H
+
+#ifdef CONFIG_PREEMPT_VOLUNTARY_BUILD
+
+extern int __cond_resched(void);
+# define might_resched() __cond_resched()
+
+#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)
+
+#include <linux/static_call_types.h>
+
+extern int __cond_resched(void);
+
+DECLARE_STATIC_CALL(might_resched, __cond_resched);
+
+static __always_inline void might_resched(void)
+{
+ static_call_mod(might_resched)();
+}
+
+#elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY)
+
+extern int dynamic_might_resched(void);
+# define might_resched() dynamic_might_resched()
+
+#else
+
+# define might_resched() do { } while (0)
+
+#endif /* CONFIG_PREEMPT_* */
+
+#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
+extern void __might_resched(const char *file, int line, unsigned int offsets);
+extern void __might_sleep(const char *file, int line);
+extern void __cant_sleep(const char *file, int line, int preempt_offset);
+extern void __cant_migrate(const char *file, int line);
+
+/**
+ * might_sleep - annotation for functions that can sleep
+ *
+ * this macro will print a stack trace if it is executed in an atomic
+ * context (spinlock, irq-handler, ...). Additional sections where blocking is
+ * not allowed can be annotated with non_block_start() and non_block_end()
+ * pairs.
+ *
+ * This is a useful debugging help to be able to catch problems early and not
+ * be bitten later when the calling function happens to sleep when it is not
+ * supposed to.
+ */
+# define might_sleep() \
+ do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0)
+/**
+ * cant_sleep - annotation for functions that cannot sleep
+ *
+ * this macro will print a stack trace if it is executed with preemption enabled
+ */
+# define cant_sleep() \
+ do { __cant_sleep(__FILE__, __LINE__, 0); } while (0)
+# define sched_annotate_sleep() (current->task_state_change = 0)
+
+/**
+ * cant_migrate - annotation for functions that cannot migrate
+ *
+ * Will print a stack trace if executed in code which is migratable
+ */
+# define cant_migrate() \
+ do { \
+ if (IS_ENABLED(CONFIG_SMP)) \
+ __cant_migrate(__FILE__, __LINE__); \
+ } while (0)
+
+/**
+ * non_block_start - annotate the start of section where sleeping is prohibited
+ *
+ * This is on behalf of the oom reaper, specifically when it is calling the mmu
+ * notifiers. The problem is that if the notifier were to block on, for example,
+ * mutex_lock() and if the process which holds that mutex were to perform a
+ * sleeping memory allocation, the oom reaper is now blocked on completion of
+ * that memory allocation. Other blocking calls like wait_event() pose similar
+ * issues.
+ */
+# define non_block_start() (current->non_block_count++)
+/**
+ * non_block_end - annotate the end of section where sleeping is prohibited
+ *
+ * Closes a section opened by non_block_start().
+ */
+# define non_block_end() WARN_ON(current->non_block_count-- == 0)
+#else
+ static inline void __might_resched(const char *file, int line,
+ unsigned int offsets) { }
+static inline void __might_sleep(const char *file, int line) { }
+# define might_sleep() do { might_resched(); } while (0)
+# define cant_sleep() do { } while (0)
+# define cant_migrate() do { } while (0)
+# define sched_annotate_sleep() do { } while (0)
+# define non_block_start() do { } while (0)
+# define non_block_end() do { } while (0)
+#endif
+
+#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
+
+#if defined(CONFIG_MMU) && \
+ (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP))
+#define might_fault() __might_fault(__FILE__, __LINE__)
+void __might_fault(const char *file, int line);
+#else
+static inline void might_fault(void) { }
+#endif
+
+
+#endif
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index d6eb56934068..62ac412a5dae 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -2,9 +2,9 @@
#ifndef _LINUX_SCHED_MM_H
#define _LINUX_SCHED_MM_H
-#include <linux/kernel.h>
#include <linux/atomic.h>
#include <linux/sched.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep_if()
#include <linux/mm_types.h>
#include <linux/gfp.h>
#include <linux/sync_core.h>
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 3064314f4832..8ea27d05f17e 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -6,6 +6,7 @@
#include <linux/instrumented.h>
#include <linux/minmax.h>
#include <linux/sched.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_faul()
#include <linux/thread_info.h>
#include <asm/uaccess.h>
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 8aa3372f21a0..61e7f0d9f07e 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -5,6 +5,7 @@
* Linux wait queue related types and methods
*/
#include <linux/list.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
#include <linux/stddef.h>
#include <linux/spinlock.h>
diff --git a/include/linux/wait_bit.h b/include/linux/wait_bit.h
index 7725b7579b78..708d3b3534f6 100644
--- a/include/linux/wait_bit.h
+++ b/include/linux/wait_bit.h
@@ -6,6 +6,7 @@
* Linux wait-bit related types and methods:
*/
#include <linux/wait.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
struct wait_bit_key {
void *flags;
diff --git a/security/landlock/object.c b/security/landlock/object.c
index 1f50612f0185..feb2dec3d89a 100644
--- a/security/landlock/object.c
+++ b/security/landlock/object.c
@@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/rcupdate.h>
#include <linux/refcount.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep()
#include <linux/slab.h>
#include <linux/spinlock.h>
diff --git a/security/landlock/ruleset.c b/security/landlock/ruleset.c
index e0a5fbf9201a..36396959a0e9 100644
--- a/security/landlock/ruleset.c
+++ b/security/landlock/ruleset.c
@@ -16,6 +16,7 @@
#include <linux/overflow.h>
#include <linux/rbtree.h>
#include <linux/refcount.h>
+#include <linux/sched/debug_atomic_sleep.h> // for might_sleep_if()
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 6/8] linux/kernel.h: move READ and WRITE to direction.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
` (4 preceding siblings ...)
2024-02-15 9:36 ` [PATCH v1 5/8] linux/kernel.h: move might_sleep(), ... to sched/debug_atomic_sleep.h Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 7/8] linux/kernel.h: move VERIFY_OCTAL_PERMISSIONS() to octal_permissions.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 8/8] linux/kernel.h: move PTR_IF() to ptr_util.h Max Kellermann
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
Reducing dependencies on the header linux/kernel.h.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
drivers/input/misc/iqs7222.c | 1 +
drivers/memstick/core/memstick.c | 1 +
drivers/memstick/host/jmb38x_ms.c | 1 +
drivers/memstick/host/r592.c | 1 +
drivers/memstick/host/rtsx_pci_ms.c | 1 +
drivers/memstick/host/rtsx_usb_ms.c | 1 +
drivers/memstick/host/tifm_ms.c | 1 +
fs/overlayfs/copy_up.c | 1 +
include/linux/direction.h | 9 +++++++++
include/linux/kernel.h | 4 ----
include/linux/nd.h | 1 +
include/linux/uio.h | 2 +-
12 files changed, 19 insertions(+), 5 deletions(-)
create mode 100644 include/linux/direction.h
diff --git a/drivers/input/misc/iqs7222.c b/drivers/input/misc/iqs7222.c
index 36aeeae77611..622cec9bcfe8 100644
--- a/drivers/input/misc/iqs7222.c
+++ b/drivers/input/misc/iqs7222.c
@@ -8,6 +8,7 @@
#include <linux/bits.h>
#include <linux/delay.h>
#include <linux/device.h>
+#include <linux/direction.h>
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 23fea51ecbdd..fcc28853d588 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -12,6 +12,7 @@
#include <linux/idr.h>
#include <linux/fs.h>
#include <linux/delay.h>
+#include <linux/direction.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index e77eb8b0eb12..dc8e4f6a01df 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -6,6 +6,7 @@
*/
#include <linux/spinlock.h>
+#include <linux/direction.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/dma-mapping.h>
diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
index 461f5ffd02bc..9ab3a7a15674 100644
--- a/drivers/memstick/host/r592.c
+++ b/drivers/memstick/host/r592.c
@@ -12,6 +12,7 @@
#include <linux/pci.h>
#include <linux/pci_ids.h>
#include <linux/delay.h>
+#include <linux/direction.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/sched.h>
diff --git a/drivers/memstick/host/rtsx_pci_ms.c b/drivers/memstick/host/rtsx_pci_ms.c
index 15720a4afac2..4bd00d69a9b6 100644
--- a/drivers/memstick/host/rtsx_pci_ms.c
+++ b/drivers/memstick/host/rtsx_pci_ms.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/highmem.h>
#include <linux/delay.h>
+#include <linux/direction.h>
#include <linux/platform_device.h>
#include <linux/memstick.h>
#include <linux/rtsx_pci.h>
diff --git a/drivers/memstick/host/rtsx_usb_ms.c b/drivers/memstick/host/rtsx_usb_ms.c
index 29271ad4728a..eeebdde571e6 100644
--- a/drivers/memstick/host/rtsx_usb_ms.c
+++ b/drivers/memstick/host/rtsx_usb_ms.c
@@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/highmem.h>
#include <linux/delay.h>
+#include <linux/direction.h>
#include <linux/platform_device.h>
#include <linux/workqueue.h>
#include <linux/memstick.h>
diff --git a/drivers/memstick/host/tifm_ms.c b/drivers/memstick/host/tifm_ms.c
index c272453670be..c46b6157aa25 100644
--- a/drivers/memstick/host/tifm_ms.c
+++ b/drivers/memstick/host/tifm_ms.c
@@ -10,6 +10,7 @@
#include <linux/tifm.h>
#include <linux/memstick.h>
+#include <linux/direction.h>
#include <linux/highmem.h>
#include <linux/scatterlist.h>
#include <linux/log2.h>
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 8586e2f5d243..465a7822b5dd 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -15,6 +15,7 @@
#include <linux/uaccess.h>
#include <linux/sched/signal.h>
#include <linux/cred.h>
+#include <linux/direction.h>
#include <linux/namei.h>
#include <linux/fdtable.h>
#include <linux/ratelimit.h>
diff --git a/include/linux/direction.h b/include/linux/direction.h
new file mode 100644
index 000000000000..78d70701579d
--- /dev/null
+++ b/include/linux/direction.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_DIRECTION_H
+#define _LINUX_DIRECTION_H
+
+/* generic data direction definitions */
+#define READ 0
+#define WRITE 1
+
+#endif
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index f6a978d51c1d..55af40e63b92 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -41,10 +41,6 @@
#define STACK_MAGIC 0xdeadbeef
-/* generic data direction definitions */
-#define READ 0
-#define WRITE 1
-
#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
#define u64_to_user_ptr(x) ( \
diff --git a/include/linux/nd.h b/include/linux/nd.h
index b9771ba1ef87..ef344119214b 100644
--- a/include/linux/nd.h
+++ b/include/linux/nd.h
@@ -7,6 +7,7 @@
#include <linux/fs.h>
#include <linux/ndctl.h>
#include <linux/device.h>
+#include <linux/direction.h>
#include <linux/badblocks.h>
#include <linux/perf_event.h>
diff --git a/include/linux/uio.h b/include/linux/uio.h
index bea9c89922d9..77a3e462d8c4 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -5,7 +5,7 @@
#ifndef __LINUX_UIO_H
#define __LINUX_UIO_H
-#include <linux/kernel.h>
+#include <linux/direction.h>
#include <linux/thread_info.h>
#include <linux/mm_types.h>
#include <uapi/linux/uio.h>
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 7/8] linux/kernel.h: move VERIFY_OCTAL_PERMISSIONS() to octal_permissions.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
` (5 preceding siblings ...)
2024-02-15 9:36 ` [PATCH v1 6/8] linux/kernel.h: move READ and WRITE to direction.h Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
2024-02-15 9:36 ` [PATCH v1 8/8] linux/kernel.h: move PTR_IF() to ptr_util.h Max Kellermann
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
Reducing dependencies on the header linux/kernel.h.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
arch/arc/kernel/perf_event.c | 1 +
drivers/edac/thunderx_edac.c | 1 +
drivers/hwmon/occ/common.c | 1 +
drivers/media/platform/amphion/vpu_dbg.c | 1 +
drivers/soc/aspeed/aspeed-uart-routing.c | 1 +
fs/xfs/xfs_error.c | 1 +
include/linux/kernel.h | 13 -------------
include/linux/moduleparam.h | 2 +-
include/linux/octal_permissions.h | 20 ++++++++++++++++++++
include/linux/sysfs.h | 1 +
10 files changed, 28 insertions(+), 14 deletions(-)
create mode 100644 include/linux/octal_permissions.h
diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c
index adff957962da..48bc5c25842e 100644
--- a/arch/arc/kernel/perf_event.c
+++ b/arch/arc/kernel/perf_event.c
@@ -8,6 +8,7 @@
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/octal_permissions.h>
#include <linux/of.h>
#include <linux/perf_event.h>
#include <linux/platform_device.h>
diff --git a/drivers/edac/thunderx_edac.c b/drivers/edac/thunderx_edac.c
index 90d46e5c4ff0..603f71fcdf44 100644
--- a/drivers/edac/thunderx_edac.c
+++ b/drivers/edac/thunderx_edac.c
@@ -20,6 +20,7 @@
#include <linux/atomic.h>
#include <linux/bitfield.h>
#include <linux/circ_buf.h>
+#include <linux/octal_permissions.h>
#include <asm/page.h>
diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
index dd690f700d49..fc328aa417b2 100644
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -10,6 +10,7 @@
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/octal_permissions.h>
#include <linux/property.h>
#include <linux/sysfs.h>
#include <asm/unaligned.h>
diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c
index 940e5bda5fa3..0f64dce90f9d 100644
--- a/drivers/media/platform/amphion/vpu_dbg.c
+++ b/drivers/media/platform/amphion/vpu_dbg.c
@@ -9,6 +9,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/octal_permissions.h>
#include <linux/types.h>
#include <linux/pm_runtime.h>
#include <media/v4l2-device.h>
diff --git a/drivers/soc/aspeed/aspeed-uart-routing.c b/drivers/soc/aspeed/aspeed-uart-routing.c
index a2195f062e01..6b091df7775a 100644
--- a/drivers/soc/aspeed/aspeed-uart-routing.c
+++ b/drivers/soc/aspeed/aspeed-uart-routing.c
@@ -5,6 +5,7 @@
*/
#include <linux/device.h>
#include <linux/module.h>
+#include <linux/octal_permissions.h>
#include <linux/of.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
index 7ad0e92c6b5b..90075bd7dbe3 100644
--- a/fs/xfs/xfs_error.c
+++ b/fs/xfs/xfs_error.c
@@ -14,6 +14,7 @@
#include "xfs_error.h"
#include "xfs_sysfs.h"
#include "xfs_inode.h"
+#include <linux/octal_permissions.h>
#ifdef DEBUG
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 55af40e63b92..01a0cc0a0776 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -29,7 +29,6 @@
#include <linux/typecheck.h>
#include <linux/panic.h>
#include <linux/printk.h>
-#include <linux/build_bug.h>
#include <linux/sprintf.h>
#include <linux/static_call_types.h>
#include <linux/instruction_pointer.h>
@@ -285,16 +284,4 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
# define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
#endif
-/* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
-#define VERIFY_OCTAL_PERMISSIONS(perms) \
- (BUILD_BUG_ON_ZERO((perms) < 0) + \
- BUILD_BUG_ON_ZERO((perms) > 0777) + \
- /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */ \
- BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) + \
- BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) + \
- /* USER_WRITABLE >= GROUP_WRITABLE */ \
- BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) + \
- /* OTHER_WRITABLE? Generally considered a bad idea. */ \
- BUILD_BUG_ON_ZERO((perms) & 2) + \
- (perms))
#endif
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index bfb85fd13e1f..860b0ea1f3b3 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -4,7 +4,7 @@
/* (C) Copyright 2001, 2002 Rusty Russell IBM Corporation */
#include <linux/init.h>
#include <linux/stringify.h>
-#include <linux/kernel.h>
+#include <linux/octal_permissions.h>
/* You can override this manually, but generally this should match the
module name. */
diff --git a/include/linux/octal_permissions.h b/include/linux/octal_permissions.h
new file mode 100644
index 000000000000..57d4d6a5b66d
--- /dev/null
+++ b/include/linux/octal_permissions.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_OCTAL_PERMISSIONS_H
+#define _LINUX_OCTAL_PERMISSIONS_H
+
+#include <linux/build_bug.h>
+
+/* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
+#define VERIFY_OCTAL_PERMISSIONS(perms) \
+ (BUILD_BUG_ON_ZERO((perms) < 0) + \
+ BUILD_BUG_ON_ZERO((perms) > 0777) + \
+ /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */ \
+ BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) + \
+ BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) + \
+ /* USER_WRITABLE >= GROUP_WRITABLE */ \
+ BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) + \
+ /* OTHER_WRITABLE? Generally considered a bad idea. */ \
+ BUILD_BUG_ON_ZERO((perms) & 2) + \
+ (perms))
+
+#endif
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index b717a70219f6..d584184db8c2 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -21,6 +21,7 @@
#include <linux/kobject_ns.h>
#include <linux/stat.h>
#include <linux/atomic.h>
+#include <linux/octal_permissions.h>
struct kobject;
struct module;
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 8/8] linux/kernel.h: move PTR_IF() to ptr_util.h
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
` (6 preceding siblings ...)
2024-02-15 9:36 ` [PATCH v1 7/8] linux/kernel.h: move VERIFY_OCTAL_PERMISSIONS() to octal_permissions.h Max Kellermann
@ 2024-02-15 9:36 ` Max Kellermann
7 siblings, 0 replies; 9+ messages in thread
From: Max Kellermann @ 2024-02-15 9:36 UTC (permalink / raw)
To: linux-kernel; +Cc: Max Kellermann
Reducing dependencies on the header linux/kernel.h.
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
drivers/gpio/gpio-sim.c | 1 +
drivers/gpu/drm/i915/i915_driver.c | 1 +
drivers/pinctrl/pinctrl-ingenic.c | 1 +
include/linux/kernel.h | 2 --
include/linux/pm.h | 1 +
include/linux/ptr_util.h | 7 +++++++
include/rdma/uverbs_ioctl.h | 1 +
7 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 include/linux/ptr_util.h
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index c4106e37e6db..fdf17cc91b4c 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -29,6 +29,7 @@
#include <linux/notifier.h>
#include <linux/platform_device.h>
#include <linux/property.h>
+#include <linux/ptr_util.h> // for PTR_IF()
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/string.h>
diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c
index 9ee902d5b72c..6dd0d8fdd6eb 100644
--- a/drivers/gpu/drm/i915/i915_driver.c
+++ b/drivers/gpu/drm/i915/i915_driver.c
@@ -34,6 +34,7 @@
#include <linux/pci.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
+#include <linux/ptr_util.h> // for PTR_IF()
#include <linux/slab.h>
#include <linux/string_helpers.h>
#include <linux/vga_switcheroo.h>
diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c
index bc6358a686fc..f88d2d3d217c 100644
--- a/drivers/pinctrl/pinctrl-ingenic.c
+++ b/drivers/pinctrl/pinctrl-ingenic.c
@@ -16,6 +16,7 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/property.h>
+#include <linux/ptr_util.h> // for PTR_IF()
#include <linux/regmap.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 01a0cc0a0776..1f1b2ced524f 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -40,8 +40,6 @@
#define STACK_MAGIC 0xdeadbeef
-#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
-
#define u64_to_user_ptr(x) ( \
{ \
typecheck(u64, (x)); \
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 97b0e23363c8..7e593b5fc5f1 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -9,6 +9,7 @@
#define _LINUX_PM_H
#include <linux/export.h>
+#include <linux/ptr_util.h> // for PTR_IF()
#include <linux/list.h>
#include <linux/workqueue.h>
#include <linux/spinlock.h>
diff --git a/include/linux/ptr_util.h b/include/linux/ptr_util.h
new file mode 100644
index 000000000000..7469aff978a9
--- /dev/null
+++ b/include/linux/ptr_util.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PTR_UTIL_H
+#define _LINUX_PTR_UTIL_H
+
+#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
+
+#endif /* _LINUX_PTR_UTIL_H */
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index 5ed57a660ead..c94244e7a77d 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -7,6 +7,7 @@
#define _UVERBS_IOCTL_
#include <rdma/uverbs_types.h>
+#include <linux/ptr_util.h> // for PTR_IF()
#include <linux/uaccess.h>
#include <rdma/rdma_user_ioctl.h>
#include <rdma/ib_user_ioctl_verbs.h>
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-15 9:37 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-15 9:36 [PATCH v1 0/8] Fast kernel headers: split linux/kernel.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 1/8] include/linux/goldfish.h: include linux/wordpart.h instead of linux/kernel.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 2/8] include/drm/drm_fixed.h: " Max Kellermann
2024-02-15 9:36 ` [PATCH v1 3/8] include linux/wordpart.h in various sources that need it Max Kellermann
2024-02-15 9:36 ` [PATCH v1 4/8] linux/random.h: reduce dependencies on linux/kernel.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 5/8] linux/kernel.h: move might_sleep(), ... to sched/debug_atomic_sleep.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 6/8] linux/kernel.h: move READ and WRITE to direction.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 7/8] linux/kernel.h: move VERIFY_OCTAL_PERMISSIONS() to octal_permissions.h Max Kellermann
2024-02-15 9:36 ` [PATCH v1 8/8] linux/kernel.h: move PTR_IF() to ptr_util.h Max Kellermann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox