entry/kvm: Exit to user mode when TIF_NOTIFY_SIGNAL is set
Subsystems (3)
PATCH 1/1 entry/kvm: Exit to user mode when TIF_NOTIFY_SIGNAL is set
A livepatch transition may stall indefinitely when a kvm vCPU is heavily loaded. To the host, the vCPU task is a user thread which is spending a very long time in the ioctl(KVM_RUN) syscall. During livepatch transition, set_notify_signal() will be called on such tasks to interrupt the syscall so that the task can be transitioned. This interrupts guest execution, but when xfer_to_guest_mode_work() sees that TIF_NOTIFY_SIGNAL is set but not TIF_SIGPENDING it concludes that an exit to user mode is unnecessary, and guest execution is resumed without transitioning the task for the livepatch.
This handling of TIF_NOTIFY_SIGNAL is incorrect, as set_notify_signal() is expected to break tasks out of interruptible kernel loops and cause them to return to userspace. Change xfer_to_guest_mode_work() to handle TIF_NOTIFY_SIGNAL the same as TIF_SIGPENDING, signaling to the vCPU run loop that an exit to userpsace is needed. Any pending task_work will be run when get_signal() is called from exit_to_user_mode_loop(), so there is no longer any need to run task work from xfer_to_guest_mode_work().
--- kernel/entry/kvm.c | 6 ------ 1 file changed, 6 deletions(-)
kernel/entry/kvm.c +0 -6
@@ -9,12 +9,6 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)int ret;if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { -clear_notify_signal (); -if (task_work_pending (current)) -task_work_run (); - } - -if (ti_work & _TIF_SIGPENDING) {kvm_handle_signal_exit (vcpu);return -EINTR ; }
Signature · 1 line
2.32.0
Quoted 18 lines · Seth Forshee
A livepatch transition may stall indefinitely when a kvm vCPU is heavily loaded. To the host, the vCPU task is a user thread which is spending a very long time in the
ioctl(KVM_RUN)syscall. During livepatch transition,set_notify_signal()will be called on such tasks to interrupt the syscall so that the task can be transitioned. This interrupts guest execution, but whenxfer_to_guest_mode_work()sees thatTIF_NOTIFY_SIGNALis set but notTIF_SIGPENDINGit concludes that an exit to user mode is unnecessary, and guest execution is resumed without transitioning the task for the livepatch.This handling of
TIF_NOTIFY_SIGNALis incorrect, asset_notify_signal()is expected to break tasks out of interruptible kernel loops and cause them to return to userspace. Changexfer_to_guest_mode_work()to handleTIF_NOTIFY_SIGNALthe same asTIF_SIGPENDING, signaling to the vCPU run loop that an exit to userpsace is needed. Any pendingtask_workwill be run whenget_signal()is called fromexit_to_user_mode_loop(), so there is no longer any need to run task work fromxfer_to_guest_mode_work().
Quoted 3 lines
Suggested-by "Eric W. Biederman" <[email protected]>Cc Petr Mladek <[email protected]>Signed-off-by Seth Forshee <[email protected]>
Quoted 21 lines
--- kernel/entry/kvm.c | 6 ------ 1 file changed, 6 deletions(-)kernel/entry/kvm.c +0
-6@@ -9,12 +9,6 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)int ret;if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { -clear_notify_signal (); -if (task_work_pending (current)) -task_work_run (); - } - -if (ti_work & _TIF_SIGPENDING) {kvm_handle_signal_exit (vcpu);return -EINTR ; }
Quoted 10 lines · Seth Forshee
A livepatch transition may stall indefinitely when a kvm vCPU is heavily loaded. To the host, the vCPU task is a user thread which is spending a very long time in the
ioctl(KVM_RUN)syscall. During livepatch transition,set_notify_signal()will be called on such tasks to interrupt the syscall so that the task can be transitioned. This interrupts guest execution, but whenxfer_to_guest_mode_work()sees thatTIF_NOTIFY_SIGNALis set but notTIF_SIGPENDINGit concludes that an exit to user mode is unnecessary, and guest execution is resumed without transitioning the task for the livepatch.
Quoted 7 lines
This handling of
TIF_NOTIFY_SIGNALis incorrect, asset_notify_signal()is expected to break tasks out of interruptible kernel loops and cause them to return to userspace. Changexfer_to_guest_mode_work()to handleTIF_NOTIFY_SIGNALthe same asTIF_SIGPENDING, signaling to the vCPU run loop that an exit to userpsace is needed. Any pendingtask_workwill be run whenget_signal()is called fromexit_to_user_mode_loop(), so there is no longer any need to run task work fromxfer_to_guest_mode_work().
Signature · 1 line
Jens Axboe
Quoted 18 lines · Seth Forshee
A livepatch transition may stall indefinitely when a kvm vCPU is heavily loaded. To the host, the vCPU task is a user thread which is spending a very long time in the
ioctl(KVM_RUN)syscall. During livepatch transition,set_notify_signal()will be called on such tasks to interrupt the syscall so that the task can be transitioned. This interrupts guest execution, but whenxfer_to_guest_mode_work()sees thatTIF_NOTIFY_SIGNALis set but notTIF_SIGPENDINGit concludes that an exit to user mode is unnecessary, and guest execution is resumed without transitioning the task for the livepatch.This handling of
TIF_NOTIFY_SIGNALis incorrect, asset_notify_signal()is expected to break tasks out of interruptible kernel loops and cause them to return to userspace. Changexfer_to_guest_mode_work()to handleTIF_NOTIFY_SIGNALthe same asTIF_SIGPENDING, signaling to the vCPU run loop that an exit to userpsace is needed. Any pendingtask_workwill be run whenget_signal()is called fromexit_to_user_mode_loop(), so there is no longer any need to run task work fromxfer_to_guest_mode_work().
Quoted 3 lines
Suggested-by "Eric W. Biederman" <[email protected]>Cc Petr Mladek <[email protected]>Signed-off-by Seth Forshee <[email protected]>
Thanks Seth for discovering the problem. Thanks everyone who helped to find the right solution.
Best Regards.
Petr
Quoted 18 lines · Seth Forshee
A livepatch transition may stall indefinitely when a kvm vCPU is heavily loaded. To the host, the vCPU task is a user thread which is spending a very long time in the
ioctl(KVM_RUN)syscall. During livepatch transition,set_notify_signal()will be called on such tasks to interrupt the syscall so that the task can be transitioned. This interrupts guest execution, but whenxfer_to_guest_mode_work()sees thatTIF_NOTIFY_SIGNALis set but notTIF_SIGPENDINGit concludes that an exit to user mode is unnecessary, and guest execution is resumed without transitioning the task for the livepatch.This handling of
TIF_NOTIFY_SIGNALis incorrect, asset_notify_signal()is expected to break tasks out of interruptible kernel loops and cause them to return to userspace. Changexfer_to_guest_mode_work()to handleTIF_NOTIFY_SIGNALthe same asTIF_SIGPENDING, signaling to the vCPU run loop that an exit to userpsace is needed. Any pendingtask_workwill be run whenget_signal()is called fromexit_to_user_mode_loop(), so there is no longer any need to run task work fromxfer_to_guest_mode_work().
Quoted 3 lines
Suggested-by "Eric W. Biederman" <[email protected]>Cc Petr Mladek <[email protected]>Signed-off-by Seth Forshee <[email protected]>
Friendly reminder as it seems like this patch may have been forgotten.
Thanks,
Seth
Quoted 24 lines
--- kernel/entry/kvm.c | 6 ------ 1 file changed, 6 deletions(-)kernel/entry/kvm.c +0
-6@@ -9,12 +9,6 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)int ret;if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { -clear_notify_signal (); -if (task_work_pending (current)) -task_work_run (); - } - -if (ti_work & _TIF_SIGPENDING) {kvm_handle_signal_exit (vcpu);return -EINTR ; }Signature · 1 line
2.32.0
Paolo Bonzini
maintainerQuoted 19 lines · Seth Forshee
Quoted 18 lines · Seth Forshee
A livepatch transition may stall indefinitely when a kvm vCPU is heavily loaded. To the host, the vCPU task is a user thread which is spending a very long time in the
ioctl(KVM_RUN)syscall. During livepatch transition,set_notify_signal()will be called on such tasks to interrupt the syscall so that the task can be transitioned. This interrupts guest execution, but whenxfer_to_guest_mode_work()sees thatTIF_NOTIFY_SIGNALis set but notTIF_SIGPENDINGit concludes that an exit to user mode is unnecessary, and guest execution is resumed without transitioning the task for the livepatch.This handling of
TIF_NOTIFY_SIGNALis incorrect, asset_notify_signal()is expected to break tasks out of interruptible kernel loops and cause them to return to userspace. Changexfer_to_guest_mode_work()to handleTIF_NOTIFY_SIGNALthe same asTIF_SIGPENDING, signaling to the vCPU run loop that an exit to userpsace is needed. Any pendingtask_workwill be run whenget_signal()is called fromexit_to_user_mode_loop(), so there is no longer any need to run task work fromxfer_to_guest_mode_work().
Quoted 5 lines
Quoted 3 lines
Suggested-by "Eric W. Biederman" <[email protected]>Cc Petr Mladek <[email protected]>Signed-off-by Seth Forshee <[email protected]>Friendly reminder as it seems like this patch may have been forgotten.
Probably AB-BA maintainer deadlock. I have queued it now.
Paolo
Quoted 28 lines
Thanks,
SethQuoted 24 lines
--- kernel/entry/kvm.c | 6 ------ 1 file changed, 6 deletions(-)kernel/entry/kvm.c +0
-6@@ -9,12 +9,6 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)int ret;if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { -clear_notify_signal (); -if (task_work_pending (current)) -task_work_run (); - } - -if (ti_work & _TIF_SIGPENDING) {kvm_handle_signal_exit (vcpu);return -EINTR ; }Signature · 1 line
2.32.0