public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, linux-arch@vger.kernel.org,
	rostedt@goodmis.org, pbonzini@redhat.com, tglx@linutronix.de,
	mingo@redhat.com, hpa@zytor.com, x86@kernel.org, arnd@arndb.de,
	rusty@rustcorp.com.au, "Radim Krčmář" <rkrcmar@redhat.com>
Subject: [PATCH v2 2/5] static_key: cancel rate limit timer on rmmod
Date: Sat,  7 Dec 2013 01:40:03 +0100	[thread overview]
Message-ID: <1386376806-924-3-git-send-email-rkrcmar@redhat.com> (raw)
In-Reply-To: <1386376806-924-1-git-send-email-rkrcmar@redhat.com>

Fix a bug when we free module's memory while a timer is pending by
canceling all deferred timers from the unloaded module.

static_key_rate_limit() still can't be called more than once.

Reproducer: (host crasher)
  modprobe kvm_intel
  (sleep 1; echo quit) \
    | qemu-kvm -kernel /dev/null -monitor stdio &
  sleep 0.5
  until modprobe -rv kvm_intel 2>/dev/null; do :; done

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
I decided not to post a patch that uses __deferred_key in kernel/module init,
so these three functions might seem like an overkill.

 kernel/jump_label.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 9019f15..02d610a 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -125,6 +125,27 @@ void jump_label_rate_limit(struct static_key_deferred *key,
 }
 EXPORT_SYMBOL_GPL(jump_label_rate_limit);
 
+/* could (should?) be abstracted more */
+static void with_deferred_keys(struct static_key_deferred *entry,
+                               struct static_key_deferred *stop,
+                               void (*op)(struct static_key_deferred *))
+{
+	struct static_key_deferred *iter;
+
+	for (iter = entry; iter < stop; iter++)
+		op(iter);
+}
+
+#define with_module_deferred_keys(mod, op) \
+	with_deferred_keys(mod->deferred_keys, \
+	                   mod->deferred_keys + mod->num_deferred_keys, \
+	                   op)
+
+static void deferred_key_cancel_work(struct static_key_deferred *dkey)
+{
+	cancel_delayed_work_sync(&dkey->work);
+}
+
 static int addr_conflict(struct jump_entry *entry, void *start, void *end)
 {
 	if (entry->code <= (unsigned long)end &&
@@ -385,6 +406,7 @@ jump_label_module_notify(struct notifier_block *self, unsigned long val,
 		jump_label_unlock();
 		break;
 	case MODULE_STATE_GOING:
+		with_module_deferred_keys(mod, deferred_key_cancel_work);
 		jump_label_lock();
 		jump_label_del_module(mod);
 		jump_label_unlock();
-- 
1.8.4.2

  parent reply	other threads:[~2013-12-07  0:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-07  0:40 [PATCH v2 0/5] static_key: deferred key fixes and improvements Radim Krčmář
2013-12-07  0:40 ` Radim Krčmář
2013-12-07  0:40 ` [PATCH v2 1/5] static_key: add a section for deferred keys Radim Krčmář
2013-12-07  0:40   ` Radim Krčmář
2013-12-07  0:40 ` Radim Krčmář [this message]
2013-12-07  0:40   ` [PATCH v2 2/5] static_key: cancel rate limit timer on rmmod Radim Krčmář
2013-12-07  0:40 ` [PATCH v2 3/5] static_key: add static_key_slow_inc_deferred() Radim Krčmář
2013-12-07  0:40   ` Radim Krčmář
2013-12-07  0:40 ` [PATCH v2 4/5] static_key: keep deferred enabled counter debt Radim Krčmář
2013-12-07  0:40   ` Radim Krčmář
2013-12-07  0:40 ` [PATCH v2 5/5] static_key: improve deferred inc behavior Radim Krčmář

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=1386376806-924-3-git-send-email-rkrcmar@redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=arnd@arndb.de \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --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