Skip to content

Commit 9b132fb

Browse files
Li ZhongGleb Natapov
authored andcommitted
Add rcu user eqs exception hooks for async page fault
This patch adds user eqs exception hooks for async page fault page not present code path, to exit the user eqs and re-enter it as necessary. Async page fault is different from other exceptions that it may be triggered from idle process, so we still need rcu_irq_enter() and rcu_irq_exit() to exit cpu idle eqs when needed, to protect the code that needs use rcu. As Frederic pointed out it would be safest and simplest to protect the whole kvm_async_pf_task_wait(). Otherwise, "we need to check all the code there deeply for potential RCU uses and ensure it will never be extended later to use RCU.". However, We'd better re-enter the cpu idle eqs if we get the exception in cpu idle eqs, by calling rcu_irq_exit() before native_safe_halt(). So the patch does what Frederic suggested for rcu_irq_*() API usage here, except that I moved the rcu_irq_*() pair originally in do_async_page_fault() into kvm_async_pf_task_wait(). That's because, I think it's better to have rcu_irq_*() pairs to be in one function ( rcu_irq_exit() after rcu_irq_enter() ), especially here, kvm_async_pf_task_wait() has other callers, which might cause rcu_irq_exit() be called without a matching rcu_irq_enter() before it, which is illegal if the cpu happens to be in rcu idle state. Signed-off-by: Li Zhong <[email protected]> Signed-off-by: Gleb Natapov <[email protected]>
1 parent 66cdd0c commit 9b132fb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/x86/kernel/kvm.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <asm/apicdef.h>
4444
#include <asm/hypervisor.h>
4545
#include <asm/kvm_guest.h>
46+
#include <asm/context_tracking.h>
4647

4748
static int kvmapf = 1;
4849

@@ -121,13 +122,17 @@ void kvm_async_pf_task_wait(u32 token)
121122
struct kvm_task_sleep_node n, *e;
122123
DEFINE_WAIT(wait);
123124

125+
rcu_irq_enter();
126+
124127
spin_lock(&b->lock);
125128
e = _find_apf_task(b, token);
126129
if (e) {
127130
/* dummy entry exist -> wake up was delivered ahead of PF */
128131
hlist_del(&e->link);
129132
kfree(e);
130133
spin_unlock(&b->lock);
134+
135+
rcu_irq_exit();
131136
return;
132137
}
133138

@@ -152,13 +157,16 @@ void kvm_async_pf_task_wait(u32 token)
152157
/*
153158
* We cannot reschedule. So halt.
154159
*/
160+
rcu_irq_exit();
155161
native_safe_halt();
162+
rcu_irq_enter();
156163
local_irq_disable();
157164
}
158165
}
159166
if (!n.halted)
160167
finish_wait(&n.wq, &wait);
161168

169+
rcu_irq_exit();
162170
return;
163171
}
164172
EXPORT_SYMBOL_GPL(kvm_async_pf_task_wait);
@@ -252,10 +260,10 @@ do_async_page_fault(struct pt_regs *regs, unsigned long error_code)
252260
break;
253261
case KVM_PV_REASON_PAGE_NOT_PRESENT:
254262
/* page is swapped out by the host. */
255-
rcu_irq_enter();
263+
exception_enter(regs);
256264
exit_idle();
257265
kvm_async_pf_task_wait((u32)read_cr2());
258-
rcu_irq_exit();
266+
exception_exit(regs);
259267
break;
260268
case KVM_PV_REASON_PAGE_READY:
261269
rcu_irq_enter();

0 commit comments

Comments
 (0)