[patch v12 10/13] KVM: x86: process isolation work from VM-entry code path

Marcelo Tosatti
2022-03-15T19:55:50Z

VM-entry code path is an entry point similar to userspace return
when task isolation is concerned.

Call isolation_exit_to_user_mode before VM-enter.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

---
v12
- Add missing kvm-entry.h change (Frederic)

v11
- Add TIF_TASK_ISOL bit to thread info flags and use it
to decide whether to perform task isolation work on
return to userspace (Frederic W. Weisbecker)

include/linux/entry-kvm.h | 4 +++-
kernel/entry/kvm.c | 18 ++++++++++++++----
2 files changed, 17 insertions(+), 5 deletions(-)

Index: linux-2.6/kernel/entry/kvm.c
===================================================================
--- linux-2.6.orig/kernel/entry/kvm.c
+++ linux-2.6/kernel/entry/kvm.c
@@ -2,6 +2,7 @@

#include <linux/entry-kvm.h>
#include <linux/kvm_host.h>
+#include <linux/task_isolation.h>

static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
{
@@ -22,6 +23,9 @@ static int xfer_to_guest_mode_work(struc
if (ti_work & _TIF_NOTIFY_RESUME)
tracehook_notify_resume(NULL);

+ if (ti_work & _TIF_TASK_ISOL)
+ task_isol_exit_to_user_mode();
+
ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work);
if (ret)
return ret;
Index: linux-2.6/include/linux/entry-kvm.h
===================================================================
--- linux-2.6.orig/include/linux/entry-kvm.h
+++ linux-2.6/include/linux/entry-kvm.h
@@ -18,7 +18,7 @@

#define XFER_TO_GUEST_MODE_WORK \
(_TIF_NEED_RESCHED | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL | \
- _TIF_NOTIFY_RESUME | ARCH_XFER_TO_GUEST_MODE_WORK)
+ _TIF_NOTIFY_RESUME | _TIF_TASK_ISOL | ARCH_XFER_TO_GUEST_MODE_WORK)

struct kvm_vcpu;