All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
To: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
	Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org, Artem Bulgakov <artem.bulgakov@virtuozzo.com>
Subject: [Devel] [PATCH hci-8.2] ve/kthreadd: keep the create request of a VE kthread off the stack
Date: Tue, 01 Dec 2026 10:20:13 +0000	[thread overview]
Message-ID: <20261201-ve-kthreadd-stack-v1-1-b4fb15511033@virtuozzo.com> (raw)

__kthread_create_on_node_ve() queues a work item from its stack to the
kthreadd worker of the VE. When a fatal signal ends the wait, the
function returns -EINTR and the item stays in the queue. The worker
then uses a dead stack frame. A SIGKILL to the init of a container
during the write of START to ve.state crashes the node:

  Oops: general protection fault
  RIP: __list_del_entry_valid_or_report
  kthread_worker_fn
  Comm: kthreadd ve: vek5

Put the work item into struct kthread_create_info. As in the kthreadd
of the host, the caller frees this structure, or, if the caller was
killed, the new thread or the worker on a failed kernel_thread().

https://virtuozzo.atlassian.net/browse/VSTOR-158054

Feature: nfs/nfsd: containerization
Fixes: f94e1c28fdd1 ("ve/kthreadd: add per-ve kthreads creation interface")
Reported-by: Artem Bulgakov <artem.bulgakov@virtuozzo.com>
Signed-off-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
---
 kernel/kthread.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index a6738c77b09d..baacee7ab331 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -52,6 +52,11 @@ struct kthread_create_info
 	struct completion *done;
 
 	struct list_head list;
+#ifdef CONFIG_VE
+	/* Queued to the VE kthreadd, may outlive a killed caller */
+	struct kthread_work ve_work;
+	unsigned long ve_flags;
+#endif
 };
 
 struct kthread {
@@ -508,19 +513,16 @@ static void create_kthread(struct kthread_create_info *create)
 }
 
 
-struct kthread_create_work {
-	struct kthread_work work;
-	struct kthread_create_info *info;
-	unsigned long flags;
-};
-
+#ifdef CONFIG_VE
 static void kthread_create_fn(struct kthread_work *w)
 {
-	struct kthread_create_work *work = container_of(w,
-			struct kthread_create_work, work);
+	struct kthread_create_info *create = container_of(w,
+			struct kthread_create_info, ve_work);
 
-	create_kthread_flags(work->info, work->flags);
+	/* @create must not be touched after kernel_thread() succeeds */
+	create_kthread_flags(create, create->ve_flags);
 }
+#endif
 
 static void kthread_create_add(struct kthread_create_info *create)
 {
@@ -540,9 +542,6 @@ struct task_struct *__kthread_create_on_node_ve(struct ve_struct *ve,
 						va_list args)
 {
 	DECLARE_COMPLETION_ONSTACK(done);
-	struct kthread_create_work work = {
-		KTHREAD_WORK_INIT(work.work, kthread_create_fn),
-	};
 	struct task_struct *task;
 	struct kthread_create_info *create = kmalloc(sizeof(*create),
 						     GFP_KERNEL);
@@ -562,9 +561,9 @@ struct task_struct *__kthread_create_on_node_ve(struct ve_struct *ve,
 #ifdef CONFIG_VE
 	if (!ve_is_super(ve))
 	{
-		work.info = create;
-		work.flags = flags;
-		kthread_queue_work(ve->kthreadd_worker, &work.work);
+		kthread_init_work(&create->ve_work, kthread_create_fn);
+		create->ve_flags = flags;
+		kthread_queue_work(ve->kthreadd_worker, &create->ve_work);
 	} else
 #endif
 		kthread_create_add(create);

---
base-commit: beda1840d22b7707e3f8e18f413afbfffef93d25
change-id: 20261201-ve-kthreadd-stack-3c0f59b5b738

-- 
Best regards, Vasileios Almpanis
Software Developer, Virtuozzo.

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

             reply	other threads:[~2026-12-01 10:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 10:20 Vasileios Almpanis [this message]
2026-12-01 10:24 ` no-reply
2026-12-01 10:52 ` Mirian Shilakadze
2026-12-01 15:17 ` Konstantin Khorenko
2026-12-01 15:17 ` Konstantin Khorenko

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=20261201-ve-kthreadd-stack-v1-1-b4fb15511033@virtuozzo.com \
    --to=vasileios.almpanis@virtuozzo.com \
    --cc=artem.bulgakov@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=mirian.shilakadze@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.