public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] Use copy_process in vhost layer
@ 2023-03-10 22:03 Mike Christie
  2023-03-10 22:03 ` [PATCH 01/11] csky: Remove kernel_thread declaration Mike Christie
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: Mike Christie @ 2023-03-10 22:03 UTC (permalink / raw)
  To: hch, stefanha, jasowang, mst, sgarzare, virtualization, brauner,
	ebiederm, torvalds, konrad.wilk, linux-kernel

The following patches were made over Linus's tree and apply over next. They
allow the vhost layer to use copy_process instead of using
workqueue_structs to create worker threads for VM's devices.

Details:
Qemu will create vhost devices in the kernel which perform network or SCSI,
IO and perform management operations from worker threads created with 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.

The patches allow the vhost layer to do a copy_process from the thread that
does the VHOST_SET_OWNER ioctl like how io_uring does a copy_process against
its userspace thread. This allows the vhost layer's worker threads to inherit
cgroups, namespaces, address space, etc. This worker thread will also be
accounted for against that owner/parent process's RLIMIT_NPROC limit which
will prevent malicious users from creating VMs with almost unlimited threads
when these patches are used:

https://lore.kernel.org/all/20211207025117.23551-1-michael.christie@oracle.com/

which allow us to create a worker thread per N virtqueues.

V12:
- Change how new fields were added to kernel_clone_args so they don't
unnecessarily expand the size of the struct.
- Use named bitfields and make kthread and io_thread work similarly as
the new fields.
- Allow copy_process users to pass in the name of the new task and
convert kthreads and vhost_tasks.
V11:
- Rebase.
V10:
- Eric's cleanup patches my vhost flush cleanup patches are merged
upstream, so rebase against Linus's tree which has everything.
V9:
- Rebase against Eric's kthread-cleanups-for-v5.19 branch. Drop patches
no longer needed due to kernel clone arg and pf io worker patches in that
branch.
V8:
- Fix kzalloc GFP use.
- Fix email subject version number.
V7:
- Drop generic user_worker_* helpers and replace with vhost_task specific
  ones.
- Drop autoreap patch. Use kernel_wait4 instead.
- Fix issue where vhost.ko could be removed while the worker function is
  still running.
V6:
- Rename kernel_worker to user_worker and fix prefixes.
- Add better patch descriptions.
V5:
- Handle kbuild errors by building patchset against current kernel that
  has all deps merged. Also add patch to remove create_io_thread code as
  it's not used anymore.
- Rebase patchset against current kernel and handle a new vm PF_IO_WORKER
  case added in 5.16-rc1.
- Add PF_USER_WORKER flag so we can check it later after the initial
  thread creation for the wake up, vm and singal cses.
- Added patch to auto reap the worker thread.
V4:
- Drop NO_SIG patch and replaced with Christian's SIG_IGN patch.
- Merged Christian's kernel_worker_flags_valid helpers into patch 5 that
  added the new kernel worker functions.
- Fixed extra "i" issue.
- Added PF_USER_WORKER flag and added check that kernel_worker_start users
  had that flag set. Also dropped patches that passed worker flags to
  copy_thread and replaced with PF_USER_WORKER check.
V3:
- Add parentheses in p->flag and work_flags check in copy_thread.
- Fix check in arm/arm64 which was doing the reverse of other archs
  where it did likely(!flags) instead of unlikely(flags).
V2:
- Rename kernel_copy_process to kernel_worker.
- Instead of exporting functions, make kernel_worker() a proper
  function/API that does common work for the caller.
- Instead of adding new fields to kernel_clone_args for each option
  make it flag based similar to CLONE_*.
- Drop unused completion struct in vhost.
- Fix compile warnings by merging vhost cgroup cleanup patch and
  vhost conversion patch.




^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-03-12 10:07 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-10 22:03 [PATCH 00/11] Use copy_process in vhost layer Mike Christie
2023-03-10 22:03 ` [PATCH 01/11] csky: Remove kernel_thread declaration Mike Christie
2023-03-10 22:03 ` [PATCH 02/11] kernel: Allow a kernel thread's name to be set in copy_process Mike Christie
2023-03-10 22:03 ` [PATCH 03/11] kthread: Pass in the thread's name during creation Mike Christie
2023-03-11  8:53   ` Christian Brauner
2023-03-11 16:11     ` michael.christie
2023-03-12  1:48       ` Mike Christie
2023-03-10 22:03 ` [PATCH 04/11] kernel: Make io_thread and kthread bit fields Mike Christie
2023-03-10 22:03 ` [PATCH 05/11] fork/vm: Move common PF_IO_WORKER behavior to new flag Mike Christie
2023-03-10 22:03 ` [PATCH 06/11] fork: add kernel_clone_args flag to not dup/clone files Mike Christie
2023-03-10 22:03 ` [PATCH 07/11] fork: Add kernel_clone_args flag to ignore signals Mike Christie
2023-03-10 22:03 ` [PATCH 08/11] fork: allow kernel code to call copy_process Mike Christie
2023-03-10 22:03 ` [PATCH 09/11] vhost_task: Allow vhost layer to use copy_process Mike Christie
2023-03-10 22:03 ` [PATCH 10/11] vhost: move worker thread fields to new struct Mike Christie
2023-03-10 22:03 ` [PATCH 11/11] vhost: use vhost_tasks for worker threads Mike Christie
2023-03-11 17:21 ` [PATCH 00/11] Use copy_process in vhost layer Linus Torvalds
2023-03-11 17:49   ` Mike Christie
2023-03-11 19:15   ` Michael S. Tsirkin
2023-03-12 10:07 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox