mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <ak@linux.intel.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] jump_labels: Add WARN_ON for too early jump label use
Date: Fri, 13 Sep 2013 15:31:59 -0700	[thread overview]
Message-ID: <20130913223159.GA22222@tassilo.jf.intel.com> (raw)

I spent a few hours tracking down a regression in my TSX code,
which turned out that it is not legal anymore to change jump
labels before the jump label code is initialized.

Add a WARN_ON() for this case.

Signed-off-by: Andi Kleen <ak@linux.intel.com>

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 297a924..c6c5290 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -17,6 +17,8 @@
 
 #ifdef HAVE_JUMP_LABEL
 
+static bool jump_label_initialized;
+
 /* mutex to protect coming/going of the the jump_label table */
 static DEFINE_MUTEX(jump_label_mutex);
 
@@ -58,6 +60,8 @@ static void jump_label_update(struct static_key *key, int enable);
 
 void static_key_slow_inc(struct static_key *key)
 {
+	WARN_ON(!jump_label_initialized);
+
 	if (atomic_inc_not_zero(&key->enabled))
 		return;
 
@@ -76,6 +80,7 @@ EXPORT_SYMBOL_GPL(static_key_slow_inc);
 static void __static_key_slow_dec(struct static_key *key,
 		unsigned long rate_limit, struct delayed_work *work)
 {
+	WARN_ON(!jump_label_initialized);
 	if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
 		WARN(atomic_read(&key->enabled) < 0,
 		     "jump label: negative count!\n");
@@ -213,6 +218,7 @@ void __init jump_label_init(void)
 #endif
 	}
 	jump_label_unlock();
+	jump_label_initialized = true;
 }
 
 #ifdef CONFIG_MODULES
-- 
ak@linux.intel.com -- Speaking for myself only

                 reply	other threads:[~2013-09-13 22:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20130913223159.GA22222@tassilo.jf.intel.com \
    --to=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --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

Powered by JetHome