Skip to content

Commit 72c3c0f

Browse files
committed
x86/kvm: Use generic xfer to guest work function
Use the generic infrastructure to check for and handle pending work before transitioning into guest mode. This now handles TIF_NOTIFY_RESUME as well which was ignored so far. Handling it is important as this covers task work and task work will be used to offload the heavy lifting of POSIX CPU timers to thread context. Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a27a0a5 commit 72c3c0f

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ config KVM
4242
select HAVE_KVM_MSI
4343
select HAVE_KVM_CPU_RELAX_INTERCEPT
4444
select HAVE_KVM_NO_POLL
45+
select KVM_XFER_TO_GUEST_WORK
4546
select KVM_GENERIC_DIRTYLOG_READ_PROTECT
4647
select KVM_VFIO
4748
select SRCU

arch/x86/kvm/vmx/vmx.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/slab.h>
2828
#include <linux/tboot.h>
2929
#include <linux/trace_events.h>
30+
#include <linux/entry-kvm.h>
3031

3132
#include <asm/apic.h>
3233
#include <asm/asm.h>
@@ -5373,14 +5374,12 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
53735374
}
53745375

53755376
/*
5376-
* Note, return 1 and not 0, vcpu_run() is responsible for
5377-
* morphing the pending signal into the proper return code.
5377+
* Note, return 1 and not 0, vcpu_run() will invoke
5378+
* xfer_to_guest_mode() which will create a proper return
5379+
* code.
53785380
*/
5379-
if (signal_pending(current))
5381+
if (__xfer_to_guest_mode_work_pending())
53805382
return 1;
5381-
5382-
if (need_resched())
5383-
schedule();
53845383
}
53855384

53865385
return 1;

arch/x86/kvm/x86.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <linux/sched/stat.h>
5757
#include <linux/sched/isolation.h>
5858
#include <linux/mem_encrypt.h>
59+
#include <linux/entry-kvm.h>
5960

6061
#include <trace/events/kvm.h>
6162

@@ -1587,7 +1588,7 @@ EXPORT_SYMBOL_GPL(kvm_emulate_wrmsr);
15871588
bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu)
15881589
{
15891590
return vcpu->mode == EXITING_GUEST_MODE || kvm_request_pending(vcpu) ||
1590-
need_resched() || signal_pending(current);
1591+
xfer_to_guest_mode_work_pending();
15911592
}
15921593
EXPORT_SYMBOL_GPL(kvm_vcpu_exit_request);
15931594

@@ -8681,15 +8682,11 @@ static int vcpu_run(struct kvm_vcpu *vcpu)
86818682
break;
86828683
}
86838684

8684-
if (signal_pending(current)) {
8685-
r = -EINTR;
8686-
vcpu->run->exit_reason = KVM_EXIT_INTR;
8687-
++vcpu->stat.signal_exits;
8688-
break;
8689-
}
8690-
if (need_resched()) {
8685+
if (xfer_to_guest_mode_work_pending()) {
86918686
srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
8692-
cond_resched();
8687+
r = xfer_to_guest_mode_handle_work(vcpu);
8688+
if (r)
8689+
return r;
86938690
vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
86948691
}
86958692
}

0 commit comments

Comments
 (0)