From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Joe Perches <joe@perches.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v4 7/7] kernel.h: Split out might_sleep() and friends
Date: Wed, 22 Apr 2020 15:52:01 +0300 [thread overview]
Message-ID: <20200422125201.37618-7-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200422125201.37618-1-andriy.shevchenko@linux.intel.com>
kernel.h is being used as a dump for all kinds of stuff for a long time.
Here is the attempt to start cleaning it up by splitting out might_sleep()
and friends.
At the same time convert users in header and crypto folder to use new header.
Though for time being include new header back to kernel.h to avoid twisted
indirected includes for existing users.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v4: rebase on latest kernel and previous patches in the series
crypto/asymmetric_keys/pkcs7_trust.c | 3 +-
include/linux/kernel.h | 67 +------------------------
include/linux/might_sleep.h | 73 ++++++++++++++++++++++++++++
include/linux/percpu-rwsem.h | 1 +
include/linux/sched.h | 1 +
include/linux/wait_bit.h | 1 +
6 files changed, 79 insertions(+), 67 deletions(-)
create mode 100644 include/linux/might_sleep.h
diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c
index 61af3c4d82ccf..9a3f0c3cafa27 100644
--- a/crypto/asymmetric_keys/pkcs7_trust.c
+++ b/crypto/asymmetric_keys/pkcs7_trust.c
@@ -6,8 +6,9 @@
*/
#define pr_fmt(fmt) "PKCS7: "fmt
-#include <linux/kernel.h>
#include <linux/export.h>
+#include <linux/might_sleep.h>
+#include <linux/printk.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/asn1.h>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index cd83a57c1b244..4558a6af90399 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -11,6 +11,7 @@
#include <linux/bitops.h>
#include <linux/log2.h>
#include <linux/math.h>
+#include <linux/might_sleep.h>
#include <linux/minmax.h>
#include <linux/typecheck.h>
#include <linux/panic.h>
@@ -77,72 +78,6 @@
#define lower_32_bits(n) ((u32)(n))
struct completion;
-struct user;
-
-#ifdef CONFIG_PREEMPT_VOLUNTARY
-extern int _cond_resched(void);
-# define might_resched() _cond_resched()
-#else
-# define might_resched() do { } while (0)
-#endif
-
-#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
-extern void ___might_sleep(const char *file, int line, int preempt_offset);
-extern void __might_sleep(const char *file, int line, int preempt_offset);
-extern void __cant_sleep(const char *file, int line, int preempt_offset);
-
-/**
- * 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__, 0); 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)
-/**
- * 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_sleep(const char *file, int line,
- int preempt_offset) { }
- static inline void __might_sleep(const char *file, int line,
- int preempt_offset) { }
-# define might_sleep() do { might_resched(); } while (0)
-# define cant_sleep() 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)
#ifndef CONFIG_PREEMPT_RT
# define cant_migrate() cant_sleep()
diff --git a/include/linux/might_sleep.h b/include/linux/might_sleep.h
new file mode 100644
index 0000000000000..dbf0097113337
--- /dev/null
+++ b/include/linux/might_sleep.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_MIGHT_SLEEP_H
+#define _LINUX_MIGHT_SLEEP_H
+
+#include <asm/bug.h>
+#include <asm/current.h>
+
+#ifdef CONFIG_PREEMPT_VOLUNTARY
+extern int _cond_resched(void);
+# define might_resched() _cond_resched()
+#else
+# define might_resched() do { } while (0)
+#endif
+
+#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
+extern void ___might_sleep(const char *file, int line, int preempt_offset);
+extern void __might_sleep(const char *file, int line, int preempt_offset);
+extern void __cant_sleep(const char *file, int line, int preempt_offset);
+
+/**
+ * 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__, 0); 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)
+/**
+ * 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_sleep(const char *file, int line,
+ int preempt_offset) { }
+ static inline void __might_sleep(const char *file, int line,
+ int preempt_offset) { }
+# define might_sleep() do { might_resched(); } while (0)
+# define cant_sleep() 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)
+
+#endif /* _LINUX_MIGHT_SLEEP_H */
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
index 5e033fe1ff4e9..504cb587cf7ea 100644
--- a/include/linux/percpu-rwsem.h
+++ b/include/linux/percpu-rwsem.h
@@ -3,6 +3,7 @@
#define _LINUX_PERCPU_RWSEM_H
#include <linux/atomic.h>
+#include <linux/might_sleep.h>
#include <linux/percpu.h>
#include <linux/rcuwait.h>
#include <linux/wait.h>
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 36306c7d2afcc..7acc5a2df398e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -15,6 +15,7 @@
#include <linux/sem.h>
#include <linux/shm.h>
#include <linux/kcov.h>
+#include <linux/might_sleep.h>
#include <linux/mutex.h>
#include <linux/plist.h>
#include <linux/hrtimer.h>
diff --git a/include/linux/wait_bit.h b/include/linux/wait_bit.h
index 7dec36aecbd9f..324cdbf5b4a49 100644
--- a/include/linux/wait_bit.h
+++ b/include/linux/wait_bit.h
@@ -5,6 +5,7 @@
/*
* Linux wait-bit related types and methods:
*/
+#include <linux/might_sleep.h>
#include <linux/wait.h>
struct wait_bit_key {
--
2.26.1
next prev parent reply other threads:[~2020-04-22 12:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-22 12:51 [PATCH v4 1/7] drm: shmobile: Reduce include dependencies Andy Shevchenko
2020-04-22 12:51 ` [PATCH v4 2/7] kernel.h: Drop unneeded <linux/kernel.h> inclusion from other headers Andy Shevchenko
2020-04-22 12:51 ` [PATCH v4 3/7] kernel.h: Move oops_in_progress to printk.h Andy Shevchenko
2020-04-22 12:51 ` [PATCH v4 4/7] kernel.h: Split out min()/max() et al helpers Andy Shevchenko
2020-04-22 14:52 ` Joe Perches
2020-04-22 15:44 ` Andy Shevchenko
2020-04-22 15:51 ` Joe Perches
2020-04-23 9:33 ` Rasmus Villemoes
2020-04-22 12:51 ` [PATCH v4 5/7] kernel.h: Split out mathematical helpers Andy Shevchenko
2020-04-22 12:52 ` [PATCH v4 6/7] kernel.h: Split out panic and oops helpers Andy Shevchenko
2020-04-24 17:04 ` kbuild test robot
2020-04-24 17:27 ` kbuild test robot
2020-04-22 12:52 ` Andy Shevchenko [this message]
2020-04-24 15:49 ` [PATCH v4 7/7] kernel.h: Split out might_sleep() and friends kbuild test robot
2020-04-24 17:45 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200422125201.37618-7-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox