vhost_task: Allow vhost layer to use copy_process
authorMike Christie <michael.christie@oracle.com>
Fri, 10 Mar 2023 22:03:30 +0000 (16:03 -0600)
committerChristian Brauner <brauner@kernel.org>
Thu, 23 Mar 2023 11:45:36 +0000 (12:45 +0100)
commite297cd54b3f81d652456ae6cb93941fc6b5c6683
tree26c7617cb30e3eeb9d4620d1ee0bde257e40b145
parent89c8e98d8cfb0656dbeb648572df5b13e372247d
vhost_task: Allow vhost layer to use copy_process

Qemu will create vhost devices in the kernel which perform network, SCSI,
etc IO and management operations from worker threads created by the
kthread API. Because the kthread API does a copy_process on the kthreadd
thread, the vhost layer has to use kthread_use_mm to access the Qemu
thread's memory and cgroup_attach_task_all to add itself to the Qemu
thread's cgroups, and it bypasses the RLIMIT_NPROC limit which can result
in VMs creating more threads than the admin expected.

This patch adds a new struct vhost_task which can be used instead of
kthreads. They allow the vhost layer to use copy_process and inherit
the userspace process's mm and cgroups, the task is accounted for
under the userspace's nproc count and can be seen in its process tree,
and other features like namespaces work and are inherited by default.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
MAINTAINERS
drivers/vhost/Kconfig
include/linux/sched/vhost_task.h [new file with mode: 0644]
kernel/Makefile
kernel/vhost_task.c [new file with mode: 0644]