linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: "Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Rik van Riel" <riel@redhat.com>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Denys Vlasenko" <vda.linux@googlemail.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Kees Cook" <keescook@chromium.org>,
	"Brian Gerst" <brgerst@gmail.com>,
	paulmck@linux.vnet.ibm.com, "Andy Lutomirski" <luto@kernel.org>
Subject: [PATCH v2 02/14] context_tracking: Add ct_state and CT_WARN_ON
Date: Thu, 18 Jun 2015 12:08:34 -0700	[thread overview]
Message-ID: <30a8c36bb4a5cba8947780ebe99e8ea3d3fb995f.1434654252.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1434654252.git.luto@kernel.org>
In-Reply-To: <cover.1434654252.git.luto@kernel.org>

This will let us sprinkle sanity checks around the kernel without
making too much of a mess.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 include/linux/context_tracking.h       | 15 +++++++++++++++
 include/linux/context_tracking_state.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index 2821838256b4..3f5ac9b86f69 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -57,6 +57,19 @@ static inline void context_tracking_task_switch(struct task_struct *prev,
 	if (context_tracking_is_enabled())
 		__context_tracking_task_switch(prev, next);
 }
+
+/**
+ * ct_state() - return the current context tracking state if known
+ *
+ * Returns the current cpu's context tracking state if context tracking
+ * is enabled.  If context tracking is disabled, returns
+ * CONTEXT_DISABLED.  This should be used primarily for debugging.
+ */
+static inline enum ctx_state ct_state(void)
+{
+	return context_tracking_is_enabled() ?
+		this_cpu_read(context_tracking.state) : CONTEXT_DISABLED;
+}
 #else
 static inline void user_enter(void) { }
 static inline void user_exit(void) { }
@@ -64,8 +77,10 @@ static inline enum ctx_state exception_enter(void) { return 0; }
 static inline void exception_exit(enum ctx_state prev_ctx) { }
 static inline void context_tracking_task_switch(struct task_struct *prev,
 						struct task_struct *next) { }
+static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; }
 #endif /* !CONFIG_CONTEXT_TRACKING */
 
+#define CT_WARN_ON(cond) WARN_ON(context_tracking_is_enabled() && (cond))
 
 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
 extern void context_tracking_init(void);
diff --git a/include/linux/context_tracking_state.h b/include/linux/context_tracking_state.h
index 6b7b96a32b75..d4aec2805849 100644
--- a/include/linux/context_tracking_state.h
+++ b/include/linux/context_tracking_state.h
@@ -13,6 +13,7 @@ struct context_tracking {
 	 */
 	bool active;
 	enum ctx_state {
+		CONTEXT_DISABLED = -1,	/* returned by ct_state() if unknown */
 		CONTEXT_KERNEL = 0,
 		CONTEXT_USER,
 		CONTEXT_GUEST,
-- 
2.4.3


  parent reply	other threads:[~2015-06-18 19:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-18 19:08 [PATCH v2 00/14] x86: Rewrite exit-to-userspace code Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 01/14] uml: Fix do_signal() prototype Andy Lutomirski
2015-06-18 19:08 ` Andy Lutomirski [this message]
2015-06-18 19:08 ` [PATCH v2 03/14] notifiers: Assert that RCU is watching in notify_die Andy Lutomirski
2015-06-22 11:36   ` Borislav Petkov
2015-06-22 16:26     ` Andy Lutomirski
2015-06-22 16:33       ` Borislav Petkov
2015-06-22 17:03         ` Andy Lutomirski
2015-06-22 17:24           ` Borislav Petkov
2015-06-22 17:37             ` Andy Lutomirski
2015-06-22 18:15               ` Borislav Petkov
2015-06-22 19:48                 ` Andy Lutomirski
2015-06-23  8:56         ` Ingo Molnar
2015-06-23 11:08           ` Borislav Petkov
2015-06-18 19:08 ` [PATCH v2 04/14] x86: Move C entry and exit code to arch/x86/entry/common.c Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 05/14] x86/traps: Assert that we're in CONTEXT_KERNEL in exception entries Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 06/14] x86/entry: Add enter_from_user_mode and use it in syscalls Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 07/14] x86/entry: Add new, comprehensible entry and exit hooks Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 08/14] x86/entry/64: Really create an error-entry-from-usermode code path Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 09/14] x86/entry/64: Migrate 64-bit and compat syscalls to new exit hooks Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 10/14] x86/asm/entry/64: Save all regs on interrupt entry Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 11/14] x86/asm/entry/64: Simplify irq stack pt_regs handling Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 12/14] x86/asm/entry/64: Migrate error and interrupt exit work to C Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 13/14] x86/entry: Remove exception_enter from trap handlers Andy Lutomirski
2015-06-18 19:08 ` [PATCH v2 14/14] x86/entry: Remove SCHEDULE_USER and asm/context-tracking.h Andy Lutomirski
2015-06-22 19:50 ` [PATCH v2 00/14] x86: Rewrite exit-to-userspace code Andy Lutomirski
2015-06-23  5:32   ` Andy Lutomirski

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=30a8c36bb4a5cba8947780ebe99e8ea3d3fb995f.1434654252.git.luto@kernel.org \
    --to=luto@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=riel@redhat.com \
    --cc=vda.linux@googlemail.com \
    --cc=x86@kernel.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;
as well as URLs for NNTP newsgroup(s).