Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mshv: Handle NEED_RESCHED_LAZY before transferring to guest

Check for NEED_RESCHED_LAZY, not just NEED_RESCHED, prior to transferring
control to a guest. Failure to check for lazy resched can unnecessarily
delay rescheduling until the next tick when using a lazy preemption model.

Note, ideally both the checking and processing of TIF bits would be handled
in common code, to avoid having to keep three separate paths synchronized,
but defer such cleanups to the future to keep the fix as standalone as
possible.

Cc: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Cc: Mukesh R <mrathor@linux.microsoft.com>
Fixes: 621191d709b1 ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Sean Christopherson and committed by
Wei Liu
0ebac01a 7ad8c34f

+3 -2
+1 -1
drivers/hv/mshv_common.c
··· 151 151 if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) 152 152 return -EINTR; 153 153 154 - if (th_flags & _TIF_NEED_RESCHED) 154 + if (th_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) 155 155 schedule(); 156 156 157 157 if (th_flags & _TIF_NOTIFY_RESUME)
+2 -1
drivers/hv/mshv_root_main.c
··· 484 484 static int mshv_pre_guest_mode_work(struct mshv_vp *vp) 485 485 { 486 486 const ulong work_flags = _TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING | 487 - _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME; 487 + _TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | 488 + _TIF_NOTIFY_RESUME; 488 489 ulong th_flags; 489 490 490 491 th_flags = read_thread_flags();