linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org,
	linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Carsten Emde <C.Emde@osadl.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	John Kacur <jkacur@redhat.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	Rik van Riel <riel@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH RT 06/20] kvm, rt: change async pagefault code locking for PREEMPT_RT
Date: Tue, 12 Jul 2016 10:24:11 -0400	[thread overview]
Message-ID: <20160712142418.343296848@goodmis.org> (raw)
In-Reply-To: 20160712142405.634544943@goodmis.org

[-- Attachment #1: 0006-kvm-rt-change-async-pagefault-code-locking-for-PREEM.patch --]
[-- Type: text/plain, Size: 4517 bytes --]

4.1.27-rt31-rc1 stable review patch.
If anyone has any objections, please let me know.

------------------

From: Rik van Riel <riel@redhat.com>

The async pagefault wake code can run from the idle task in exception
context, so everything here needs to be made non-preemptible.

Conversion to a simple wait queue and raw spinlock does the trick.

Signed-off-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 arch/x86/kernel/kvm.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 9435620062df..ba97b5b45879 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -36,6 +36,7 @@
 #include <linux/kprobes.h>
 #include <linux/debugfs.h>
 #include <linux/nmi.h>
+#include <linux/wait-simple.h>
 #include <asm/timer.h>
 #include <asm/cpu.h>
 #include <asm/traps.h>
@@ -91,14 +92,14 @@ static void kvm_io_delay(void)
 
 struct kvm_task_sleep_node {
 	struct hlist_node link;
-	wait_queue_head_t wq;
+	struct swait_head wq;
 	u32 token;
 	int cpu;
 	bool halted;
 };
 
 static struct kvm_task_sleep_head {
-	spinlock_t lock;
+	raw_spinlock_t lock;
 	struct hlist_head list;
 } async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE];
 
@@ -122,17 +123,17 @@ void kvm_async_pf_task_wait(u32 token)
 	u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
 	struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
 	struct kvm_task_sleep_node n, *e;
-	DEFINE_WAIT(wait);
+	DEFINE_SWAITER(wait);
 
 	rcu_irq_enter();
 
-	spin_lock(&b->lock);
+	raw_spin_lock(&b->lock);
 	e = _find_apf_task(b, token);
 	if (e) {
 		/* dummy entry exist -> wake up was delivered ahead of PF */
 		hlist_del(&e->link);
 		kfree(e);
-		spin_unlock(&b->lock);
+		raw_spin_unlock(&b->lock);
 
 		rcu_irq_exit();
 		return;
@@ -141,13 +142,13 @@ void kvm_async_pf_task_wait(u32 token)
 	n.token = token;
 	n.cpu = smp_processor_id();
 	n.halted = is_idle_task(current) || preempt_count() > 1;
-	init_waitqueue_head(&n.wq);
+	init_swait_head(&n.wq);
 	hlist_add_head(&n.link, &b->list);
-	spin_unlock(&b->lock);
+	raw_spin_unlock(&b->lock);
 
 	for (;;) {
 		if (!n.halted)
-			prepare_to_wait(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
+			swait_prepare(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
 		if (hlist_unhashed(&n.link))
 			break;
 
@@ -166,7 +167,7 @@ void kvm_async_pf_task_wait(u32 token)
 		}
 	}
 	if (!n.halted)
-		finish_wait(&n.wq, &wait);
+		swait_finish(&n.wq, &wait);
 
 	rcu_irq_exit();
 	return;
@@ -178,8 +179,8 @@ static void apf_task_wake_one(struct kvm_task_sleep_node *n)
 	hlist_del_init(&n->link);
 	if (n->halted)
 		smp_send_reschedule(n->cpu);
-	else if (waitqueue_active(&n->wq))
-		wake_up(&n->wq);
+	else if (swaitqueue_active(&n->wq))
+		swait_wake(&n->wq);
 }
 
 static void apf_task_wake_all(void)
@@ -189,14 +190,14 @@ static void apf_task_wake_all(void)
 	for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) {
 		struct hlist_node *p, *next;
 		struct kvm_task_sleep_head *b = &async_pf_sleepers[i];
-		spin_lock(&b->lock);
+		raw_spin_lock(&b->lock);
 		hlist_for_each_safe(p, next, &b->list) {
 			struct kvm_task_sleep_node *n =
 				hlist_entry(p, typeof(*n), link);
 			if (n->cpu == smp_processor_id())
 				apf_task_wake_one(n);
 		}
-		spin_unlock(&b->lock);
+		raw_spin_unlock(&b->lock);
 	}
 }
 
@@ -212,7 +213,7 @@ void kvm_async_pf_task_wake(u32 token)
 	}
 
 again:
-	spin_lock(&b->lock);
+	raw_spin_lock(&b->lock);
 	n = _find_apf_task(b, token);
 	if (!n) {
 		/*
@@ -225,17 +226,17 @@ again:
 			 * Allocation failed! Busy wait while other cpu
 			 * handles async PF.
 			 */
-			spin_unlock(&b->lock);
+			raw_spin_unlock(&b->lock);
 			cpu_relax();
 			goto again;
 		}
 		n->token = token;
 		n->cpu = smp_processor_id();
-		init_waitqueue_head(&n->wq);
+		init_swait_head(&n->wq);
 		hlist_add_head(&n->link, &b->list);
 	} else
 		apf_task_wake_one(n);
-	spin_unlock(&b->lock);
+	raw_spin_unlock(&b->lock);
 	return;
 }
 EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);
@@ -486,7 +487,7 @@ void __init kvm_guest_init(void)
 	paravirt_ops_setup();
 	register_reboot_notifier(&kvm_pv_reboot_nb);
 	for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
-		spin_lock_init(&async_pf_sleepers[i].lock);
+		raw_spin_lock_init(&async_pf_sleepers[i].lock);
 	if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
 		x86_init.irqs.trap_init = kvm_apf_trap_init;
 
-- 
2.8.1

  parent reply	other threads:[~2016-07-12 14:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-12 14:24 [PATCH RT 00/20] Linux 4.1.27-rt31-rc1 Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 01/20] ARM: at91: pm: simply call at91_pm_init Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 02/20] ARM: at91: pm: find and remap the pmc Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 03/20] ARM: at91: pm: move idle functions to pm.c Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 04/20] ARM: at91: remove useless includes and function prototypes Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 05/20] usb: gadget: atmel: access the PMC using regmap Steven Rostedt
2016-07-12 14:24 ` Steven Rostedt [this message]
2016-07-12 14:24 ` [PATCH RT 07/20] mm/zsmalloc: Use get/put_cpu_light in zs_map_object()/zs_unmap_object() Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 08/20] net: dev: always take qdiscs busylock in __dev_xmit_skb() Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 09/20] drivers/block/zram: Replace bit spinlocks with rtmutex for -rt Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 10/20] list_bl: fixup bogus lockdep warning Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 11/20] ARM: imx: always use TWD on IMX6Q Steven Rostedt
2016-07-12 20:04   ` Sebastian Andrzej Siewior
2016-07-12 20:25     ` Steven Rostedt
2016-07-18 17:18     ` Grygorii Strashko
2016-07-12 14:24 ` [PATCH RT 12/20] drivers/block/zram: fixup compile for !RT Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 13/20] perf/x86/intel/rapl: Make PMU lock raw Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 14/20] sched,preempt: Fix preempt_count manipulations Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 15/20] kernel/printk: Dont try to print from IRQ/NMI region Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 16/20] arm: lazy preempt: correct resched condition Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 17/20] locallock: add local_lock_on() Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 18/20] mm: perform lru_add_drain_all() remotely Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 19/20] trace: correct off by one while recording the trace-event Steven Rostedt
2016-07-12 14:24 ` [PATCH RT 20/20] Linux 4.1.27-rt31-rc1 Steven Rostedt
2016-07-12 23:18 ` Linux 4.1.27-rt31-rc2 Steven Rostedt

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=20160712142418.343296848@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=C.Emde@osadl.org \
    --cc=bigeasy@linutronix.de \
    --cc=jkacur@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=pbonzini@redhat.com \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    /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).