mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
	Mike Christie <michael.christie@oracle.com>,
	linux@leemhuis.info, nicolas.dichtel@6wind.com, axboe@kernel.dk,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org, mst@redhat.com,
	sgarzare@redhat.com, jasowang@redhat.com, stefanha@redhat.com,
	brauner@kernel.org
Subject: Re: [PATCH 3/3] fork, vhost: Use CLONE_THREAD to fix freezer/ps regression
Date: Sat, 27 May 2023 04:49:19 -0500	[thread overview]
Message-ID: <87cz2mrtnk.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <CAHk-=wj4DS=2F5mW+K2P7cVqrsuGd3rKE_2k2BqnnPeeYhUCvg@mail.gmail.com> (Linus Torvalds's message of "Thu, 25 May 2023 09:20:19 -0700")

Linus Torvalds <torvalds@linux-foundation.org> writes:

> So I'd really like to finish this. Even if we end up with a hack or
> two in signal handling that we can hopefully fix up later by having
> vhost fix up some of its current assumptions.


The real sticky widget for me is how to handle one of these processes
coredumping.  It really looks like it will result in a reliable hang.

Limiting ourselves to changes that will only affect vhost, all I can
see would be allowing the vhost_worker thread to exit as soon as
get_signal reports the process is exiting.  Then vhost_dev_flush
would need to process the pending work.

Something like this:

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index a92af08e7864..fb5ebc50c553 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -234,14 +234,31 @@ EXPORT_SYMBOL_GPL(vhost_poll_stop);
 void vhost_dev_flush(struct vhost_dev *dev)
 {
 	struct vhost_flush_struct flush;
+	struct vhost_worker *worker = dev->worker;
+	struct llist_node *node, *head;
+
+	if (!worker)
+		return;
+
+	init_completion(&flush.wait_event);
+	vhost_work_init(&flush.work, vhost_flush_work);
 
-	if (dev->worker) {
-		init_completion(&flush.wait_event);
-		vhost_work_init(&flush.work, vhost_flush_work);
+	vhost_work_queue(dev, &flush.work);
 
-		vhost_work_queue(dev, &flush.work);
-		wait_for_completion(&flush.wait_event);
+	/* Either vhost_worker runs the pending work or we do */
+	node = llist_del_all(&worker->work_list);
+	if (node) {
+		node = llist_reverse_order(node);
+		/* make sure flag is seen after deletion */
+		smp_wmb();
+		llist_for_each_entry_safe(work, work_next, node, node) {
+			clear_bit(VHOST_WORK_QUEUED, &work->flags);
+			work->fn(work);
+			cond_resched();
+		}
 	}
+
+	wait_for_completion(&flush.wait_event);
 }
 EXPORT_SYMBOL_GPL(vhost_dev_flush);
 
@@ -338,6 +355,7 @@ static int vhost_worker(void *data)
 	struct vhost_worker *worker = data;
 	struct vhost_work *work, *work_next;
 	struct llist_node *node;
+	struct ksignal ksig;
 
 	for (;;) {
 		/* mb paired w/ kthread_stop */
@@ -348,6 +366,9 @@ static int vhost_worker(void *data)
 			break;
 		}
 
+		if (get_signal(&ksig))
+			break;
+
 		node = llist_del_all(&worker->work_list);
 		if (!node)
 			schedule();
diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c
index b7cbd66f889e..613d52f01c07 100644
--- a/kernel/vhost_task.c
+++ b/kernel/vhost_task.c
@@ -47,6 +47,7 @@ void vhost_task_stop(struct vhost_task *vtsk)
 	 * not exiting then reap the task.
 	 */
 	kernel_wait4(pid, NULL, __WCLONE, NULL);
+	put_task_struct(vtsk->task);
 	kfree(vtsk);
 }
 EXPORT_SYMBOL_GPL(vhost_task_stop);
@@ -101,7 +102,7 @@ struct vhost_task *vhost_task_create(int (*fn)(void *), void *arg,
 		return NULL;
 	}
 
-	vtsk->task = tsk;
+	vtsk->task = get_task_struct(tsk);
 	return vtsk;
 }
 EXPORT_SYMBOL_GPL(vhost_task_create);

Eric


  reply	other threads:[~2023-05-27  9:49 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22  2:51 [PATCH 0/3] vhost: Fix freezer/ps regressions Mike Christie
2023-05-22  2:51 ` [PATCH 1/3] signal: Don't always put SIGKILL in shared_pending Mike Christie
2023-05-23 15:30   ` Eric W. Biederman
2023-05-22  2:51 ` [PATCH 2/3] signal: Don't exit for PF_USER_WORKER tasks Mike Christie
2023-05-22  2:51 ` [PATCH 3/3] fork, vhost: Use CLONE_THREAD to fix freezer/ps regression Mike Christie
2023-05-22 12:30   ` Oleg Nesterov
2023-05-22 17:00     ` Mike Christie
2023-05-22 17:47       ` Oleg Nesterov
2023-05-23 12:15         ` Oleg Nesterov
2023-05-23 15:57           ` Eric W. Biederman
2023-05-24 14:10             ` Oleg Nesterov
2023-05-24 14:44               ` Eric W. Biederman
2023-05-25 11:55                 ` Oleg Nesterov
2023-05-25 15:30                   ` Eric W. Biederman
2023-05-25 16:20                     ` Linus Torvalds
2023-05-27  9:49                       ` Eric W. Biederman [this message]
2023-05-27 16:12                         ` Linus Torvalds
2023-05-28  1:17                           ` Eric W. Biederman
2023-05-28  1:21                             ` Linus Torvalds
2023-05-29 11:19                             ` Oleg Nesterov
2023-05-29 16:09                               ` michael.christie
2023-05-29 17:46                                 ` Oleg Nesterov
2023-05-29 17:54                                   ` Oleg Nesterov
2023-05-29 19:03                                     ` Mike Christie
2023-05-29 19:35                                   ` Mike Christie
2023-05-29 19:46                                     ` michael.christie
2023-05-30  2:48                                       ` Eric W. Biederman
2023-05-30  2:38                                 ` Eric W. Biederman
2023-05-30 15:34                                   ` Mike Christie
2023-05-31  3:30                                   ` Mike Christie
2023-05-29 16:11                               ` michael.christie
2023-05-30 14:15                               ` Christian Brauner
2023-05-30 17:55                                 ` Oleg Nesterov
2023-05-30 15:01                         ` Eric W. Biederman
2023-05-31  5:22             ` Jason Wang
2023-05-24  0:02           ` Mike Christie
2023-05-25 16:15           ` Mike Christie
2023-05-28  1:41             ` Eric W. Biederman
2023-05-28 19:29               ` Mike Christie
2023-05-31  5:22           ` Jason Wang
2023-05-31  7:25             ` Oleg Nesterov
2023-05-31  8:17               ` Jason Wang
2023-05-31  9:14                 ` Oleg Nesterov
2023-06-01  2:44                   ` Jason Wang
2023-06-01  7:43                     ` Oleg Nesterov
2023-06-02  5:03                       ` Jason Wang
2023-06-02 17:58                         ` Oleg Nesterov
2023-06-02 20:07                           ` Linus Torvalds
2023-06-05 14:20                             ` Oleg Nesterov
2023-05-22 19:40   ` Michael S. Tsirkin
2023-05-23 15:39     ` Eric W. Biederman
2023-05-23 15:48     ` Mike Christie

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=87cz2mrtnk.fsf@email.froward.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@leemhuis.info \
    --cc=michael.christie@oracle.com \
    --cc=mst@redhat.com \
    --cc=nicolas.dichtel@6wind.com \
    --cc=oleg@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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

Powered by JetHome