aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <dumbbell@FreeBSD.org>2026-04-11 09:37:05 +0000
committerJean-Sébastien Pédron <dumbbell@FreeBSD.org>2026-04-21 22:18:24 +0000
commitad528a6b174e7090cb06062867e9a146b017205d (patch)
tree271dfe75332209a314efa5e10e8a1e2c626e6353
parentb6dd9d3593f3286d8225b3bd2ae9248dcf92864c (diff)
linuxkpi: Define diagnostic macros like `might_resched()` or `cant_sleep()`
They are no-ops on FreeBSD. While here, move the already defined `might_sleep*()` macros from <linux/wait.h> to <linux/kernel.h> where they belong. The DRM generic code started to use `might_fault()` in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56434
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kernel.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/wait.h7
2 files changed, 33 insertions, 7 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h
index 2430b25c6915..e3ac4a05612c 100644
--- a/sys/compat/linuxkpi/common/include/linux/kernel.h
+++ b/sys/compat/linuxkpi/common/include/linux/kernel.h
@@ -351,4 +351,37 @@ mac_pton(const char *macin, uint8_t *macout)
#define DECLARE_FLEX_ARRAY(_t, _n) \
struct { struct { } __dummy_ ## _n; _t _n[0]; }
+/*
+ * The following functions/macros are debug/diagnostics tools. They default to
+ * no-ops, except `might_sleep()` which uses `WITNESS_WARN()` on FreeBSD.
+ */
+static inline void
+__might_resched(const char *file, int line, unsigned int offsets)
+{
+}
+
+static inline void
+__might_sleep(const char *file, int line)
+{
+}
+
+static inline void
+might_fault(void)
+{
+}
+
+#define might_sleep() \
+ WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "might_sleep()")
+
+#define might_sleep_if(cond) do { \
+ if (cond) { might_sleep(); } \
+} while (0)
+
+#define might_resched() do { } 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 /* _LINUXKPI_LINUX_KERNEL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/wait.h b/sys/compat/linuxkpi/common/include/linux/wait.h
index 03ddce2c06f5..698a1056b713 100644
--- a/sys/compat/linuxkpi/common/include/linux/wait.h
+++ b/sys/compat/linuxkpi/common/include/linux/wait.h
@@ -43,13 +43,6 @@
#define SKIP_SLEEP() (SCHEDULER_STOPPED() || kdb_active)
-#define might_sleep() \
- WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "might_sleep()")
-
-#define might_sleep_if(cond) do { \
- if (cond) { might_sleep(); } \
-} while (0)
-
struct wait_queue;
struct wait_queue_head;