From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH v2 2/3] vhost_task: Allow caller to omit handle_sigkill() callback
Date: Wed, 27 Aug 2025 12:41:06 -0700 [thread overview]
Message-ID: <20250827194107.4142164-3-seanjc@google.com> (raw)
In-Reply-To: <20250827194107.4142164-1-seanjc@google.com>
Now that vhost_task provides an API to safely wake a task without relying
on the caller to react to signals, make handle_sigkill() optional and
WARN if the "unsafe" __vhost_task_wake() is used without hooking sigkill.
Requiring the user to react to sigkill adds no meaningful value, e.g. it
didn't help KVM do the right thing with respect to signals, and adding a
sanity check in __vhost_task_wake() gives developers a hint as to what
needs to be done in response to sigkill.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
kernel/vhost_task.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c
index bd213d0b6da3..01bf7b0e2c5b 100644
--- a/kernel/vhost_task.c
+++ b/kernel/vhost_task.c
@@ -59,7 +59,8 @@ static int vhost_task_fn(void *data)
*/
if (!test_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags)) {
set_bit(VHOST_TASK_FLAGS_KILLED, &vtsk->flags);
- vtsk->handle_sigkill(vtsk->data);
+ if (vtsk->handle_sigkill)
+ vtsk->handle_sigkill(vtsk->data);
}
mutex_unlock(&vtsk->exit_mutex);
complete(&vtsk->exited);
@@ -81,6 +82,13 @@ static void vhost_task_wake_up_process(struct vhost_task *vtsk)
*/
void __vhost_task_wake(struct vhost_task *vtsk)
{
+ /*
+ * Waking the task without taking exit_mutex is safe if and only if the
+ * implementation hooks sigkill, as that's the only way the caller can
+ * know if the task has exited prematurely due to a signal.
+ */
+ WARN_ON_ONCE(!vtsk->handle_sigkill);
+
/*
* Checking VHOST_TASK_FLAGS_KILLED can race with signal delivery, but
* a race can only result in false negatives and this is just a sanity
--
2.51.0.268.g9569e192d0-goog
next prev parent reply other threads:[~2025-08-27 19:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 19:41 [PATCH v2 0/3] vhost_task: Fix a bug where KVM wakes an exited task Sean Christopherson
2025-08-27 19:41 ` [PATCH v2 1/3] vhost_task: Don't wake KVM x86's recovery thread if vhost task was killed Sean Christopherson
2025-08-27 19:41 ` Sean Christopherson [this message]
2025-08-27 19:41 ` [PATCH v2 3/3] KVM: x86/mmu: Don't register a sigkill callback for NX hugepage recovery tasks Sean Christopherson
2025-08-27 20:10 ` [PATCH v2 0/3] vhost_task: Fix a bug where KVM wakes an exited task Sebastian Andrzej Siewior
2025-08-28 0:16 ` Sean Christopherson
2025-08-28 6:48 ` Sebastian Andrzej Siewior
2025-08-28 2:42 ` Lei Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250827194107.4142164-3-seanjc@google.com \
--to=seanjc@google.com \
--cc=bigeasy@linutronix.de \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).