Skip to content

Use copy_process in vhost layer

Mike Christie lkml regressions virtualization 10 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v11 Latest8 patches 44 repliesIn review
  2. v108 patches 3 repliesSuperseded
  3. v98 patches 2 repliesSuperseded
Earlier versions · 7
VersionPostedPatchesRepliesStatus
v88 patches1 replySuperseded
v610 patches18 repliesSuperseded
v510 patches6 repliesSuperseded
v48 patches3 repliesSuperseded
v39 patches7 repliesSuperseded
v29 patches12 repliesSuperseded
v18 patches7 repliesSuperseded

Changes in v11 from the cover letter

- Rebase.

Patches in v11 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8fork: Make IO worker options flag basedinclude/linux/sched/task.h kernel/fork.c+5 -31 reply
2/8fork/vm: Move common PF_IO_WORKER behavior to new flaginclude/linux/sched.h include/linux/sched/task.h kernel/fork.c +1 more+9 -40 replies
3/8fork: add USER_WORKER flag to not dup/clone filesinclude/linux/sched/task.h kernel/fork.c+10 -21 reply
4/8fork: Add USER_WORKER flag to ignore signalsinclude/linux/sched/task.h kernel/fork.c+4 -02 replies
5/8fork: allow kernel code to call copy_processinclude/linux/sched/task.h kernel/fork.c+3 -10 replies
6/8vhost_task: Allow vhost layer to use copy_processMAINTAINERS drivers/vhost/Kconfig include/linux/sched/vhost_task.h +2 more+153 -01 reply
7/8vhost: move worker thread fields to new structdrivers/vhost/vhost.c drivers/vhost/vhost.h+72 -370 replies
8/8vhost: use vhost_tasks for worker threadsdrivers/vhost/vhost.c drivers/vhost/vhost.h+13 -4938 replies

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchChristian BraunerChristoph HellwigMichael S. TsirkinStefan Hajnoczi
1/8A-b R-b A-b
2/8A-b
3/8A-b R-b A-b
4/8R-b A-b
5/8A-b
6/8A-b
7/8R-b A-b R-b
8/8A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v11 thread

Cover letter [PATCH v11 0/8] Use copy_process in vhost layer

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

Eric, the vhost maintainer, Michael Tsirkin has ACK'd the patches, so we are just waiting on you. I haven't got any more comments after several postings, and the last reply from you was a year ago on Jan 8th *2022*. Are you ok with these patches and can we merge them?

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/[email protected]/

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

V11:
- Rebase.
V10:
- Eric's cleanup patches and 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.

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization