[patch 2/5] x86/kvm: Handle task_work on VMENTER/EXIT
From: Thomas Gleixner
Date: Thu Aug 01 2019 - 10:38:31 EST
TIF_NOTITY_RESUME is evaluated on return to user space along with other TIF
flags.
>From the kernels point of view a VMENTER is more or less equivalent to
return to user space which means that at least a subset of TIF flags needs
to be evaluated and handled.
Currently KVM handles only TIF_SIGPENDING and TIF_NEED_RESCHED, but
TIF_NOTIFY_RESUME is ignored. So pending task_work etc, is completely
ignored until the vCPU thread actually goes all the way back into
userspace/qemu.
Use the newly provided notify_resume_pending() and
tracehook_handle_notify_resume() to solve this similar to the existing
handling of SIGPENDING.
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: kvm@xxxxxxxxxxxxxxx
Cc: Radim Krcmar <rkrcmar@xxxxxxxxxx>
Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/x86/kvm/x86.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -52,6 +52,7 @@
#include <linux/irqbypass.h>
#include <linux/sched/stat.h>
#include <linux/sched/isolation.h>
+#include <linux/tracehook.h>
#include <linux/mem_encrypt.h>
#include <trace/events/kvm.h>
@@ -7972,7 +7973,8 @@ static int vcpu_enter_guest(struct kvm_v
kvm_x86_ops->sync_pir_to_irr(vcpu);
if (vcpu->mode == EXITING_GUEST_MODE || kvm_request_pending(vcpu)
- || need_resched() || signal_pending(current)) {
+ || need_resched() || signal_pending(current)
+ || notify_resume_pending()) {
vcpu->mode = OUTSIDE_GUEST_MODE;
smp_wmb();
local_irq_enable();
@@ -8172,6 +8174,10 @@ static int vcpu_run(struct kvm_vcpu *vcp
++vcpu->stat.signal_exits;
break;
}
+
+ if (notify_resume_pending())
+ tracehook_handle_notify_resume();
+
if (need_resched()) {
srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
cond_resched();