linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt
@ 2016-03-18 18:20 Rik van Riel
  2016-03-29 16:13 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 5+ messages in thread
From: Rik van Riel @ 2016-03-18 18:20 UTC (permalink / raw)
  To: linux-rt-users; +Cc: williams, srostedt

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>
---
 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 47190bd399e7..185404175acb 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 @@ void kvm_async_pf_task_wake(u32 token)
 			 * 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;
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt
  2016-03-18 18:20 [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt Rik van Riel
@ 2016-03-29 16:13 ` Sebastian Andrzej Siewior
  2016-03-29 16:18   ` Rik van Riel
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2016-03-29 16:13 UTC (permalink / raw)
  To: Rik van Riel; +Cc: linux-rt-users, williams, srostedt

* Rik van Riel | 2016-03-18 14:20:52 [-0400]:

>--- 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>

This does not work since v4.4.4-rt11:

|arch/x86/kernel/kvm.c:39:31: fatal error: linux/wait-simple.h: No such file or directory

In -rt11 I pulled in the swait queue which was in the -tip tree and is
now part of v4.6-rc1. So if you could please refresh the patch and
resend it then I will be able pick it up for the next -RT release and
the KVM maintainer will be able to pick it up, too. 

Sebastian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt
  2016-03-29 16:13 ` Sebastian Andrzej Siewior
@ 2016-03-29 16:18   ` Rik van Riel
  2016-03-29 16:28     ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Rik van Riel @ 2016-03-29 16:18 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, williams, srostedt, pbonzini

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

On Tue, 2016-03-29 at 18:13 +0200, Sebastian Andrzej Siewior wrote:
> * Rik van Riel | 2016-03-18 14:20:52 [-0400]:
> 
> > 
> > --- 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>
> This does not work since v4.4.4-rt11:
> 
> > 
> > arch/x86/kernel/kvm.c:39:31: fatal error: linux/wait-simple.h: No
> > such file or directory
> In -rt11 I pulled in the swait queue which was in the -tip tree and
> is
> now part of v4.6-rc1. So if you could please refresh the patch and
> resend it then I will be able pick it up for the next -RT release and
> the KVM maintainer will be able to pick it up, too. 

I missed that swait went upstream, but I believe Paulo fixed
up the patch and has it in the KVM tree already.

-- 
All Rights Reversed.


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt
  2016-03-29 16:18   ` Rik van Riel
@ 2016-03-29 16:28     ` Paolo Bonzini
  2016-03-29 16:33       ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2016-03-29 16:28 UTC (permalink / raw)
  To: Rik van Riel, Sebastian Andrzej Siewior
  Cc: linux-rt-users, williams, srostedt


[-- Attachment #1.1: Type: text/plain, Size: 527 bytes --]



On 29/03/2016 18:18, Rik van Riel wrote:
> > In -rt11 I pulled in the swait queue which was in the -tip tree and is
> > now part of v4.6-rc1. So if you could please refresh the patch and
> > resend it then I will be able pick it up for the next -RT release and
> > the KVM maintainer will be able to pick it up, too. 
>
> I missed that swait went upstream, but I believe Paulo fixed
> up the patch and has it in the KVM tree already.

Yes, I did.  You'll get Rik's patch for free from Linus's tree. :)

Paolo


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt
  2016-03-29 16:28     ` Paolo Bonzini
@ 2016-03-29 16:33       ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2016-03-29 16:33 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Rik van Riel, linux-rt-users, williams, srostedt

* Paolo Bonzini | 2016-03-29 18:28:43 [+0200]:

>> I missed that swait went upstream, but I believe Paulo fixed
>> up the patch and has it in the KVM tree already.
>
>Yes, I did.  You'll get Rik's patch for free from Linus's tree. :)

great. I just picked it from his tree.

>Paolo

Sebastian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-03-29 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-18 18:20 [PATCH -rt] kvm,rt: change async pagefault code locking for rt-preempt Rik van Riel
2016-03-29 16:13 ` Sebastian Andrzej Siewior
2016-03-29 16:18   ` Rik van Riel
2016-03-29 16:28     ` Paolo Bonzini
2016-03-29 16:33       ` Sebastian Andrzej Siewior

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).