In commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads"),
the vhost now uses vhost_task and operates as a child of the
owner thread. This aligns with containerization principles.
However, this change has caused confusion for some legacy
userspace applications. Therefore, we are reintroducing
support for the kthread API.
In this series, a new UAPI is implemented to allow
userspace applications to configure their thread mode.
Changelog v2:
1. Change the module_param's name to enforce_inherit_owner, and the default value is true.
2. Change the UAPI's name to VHOST_SET_INHERIT_FROM_OWNER.
Changelog v3:
1. Change the module_param's name to inherit_owner_default, and the default value is true.
2. Add a structure for task function; the worker will select a different mode based on the value inherit_owner.
3. device will have their own inherit_owner in struct vhost_dev
4. Address other comments
Changelog v4:
1. remove the module_param, only keep the UAPI
2. remove the structure for task function; change to use the function pointer in vhost_worker
3. fix the issue in vhost_worker_create and vhost_dev_ioctl
4. Address other comments
Changelog v5:
1. Change wakeup and stop function pointers in struct vhost_worker to void.
2. merging patches 4, 5, 6 in a single patch
3. Fix spelling issues and address other comments.
Changelog v6:
1. move the check of VHOST_NEW_WORKER from vhost_scsi to vhost
2. Change the ioctl name VHOST_SET_INHERIT_FROM_OWNER to VHOST_FORK_FROM_OWNER
3. reuse the function __vhost_worker_flush
4. use a ops sturct to support worker relates function
5. reset the value of inherit_owner in vhost_dev_reset_owner s.
Changelog v7:
1. add a KConfig knob to disable legacy app support
2. Split the changes into two patches to separately introduce the ops and add kthread support.
3. Utilized INX_MAX to avoid modifications in __vhost_worker_flush
4. Rebased on the latest kernel
5. Address other comments
Tested with QEMU with kthread mode/task mode/kthread+task mode
Cindy Lu (8):
vhost: Add a new parameter in vhost_dev to allow user select kthread
vhost: Reintroduce vhost_worker to support kthread
vhost: Add the cgroup related function
vhost: Introduce vhost_worker_ops in vhost_worker
vhost: Reintroduce kthread mode support in vhost
vhost: uapi to control task mode (owner vs kthread)
vhost: Add check for inherit_owner status
vhost: Add a KConfig knob to enable IOCTL VHOST_FORK_FROM_OWNER
drivers/vhost/Kconfig | 15 +++
drivers/vhost/vhost.c | 227 +++++++++++++++++++++++++++++++++----
drivers/vhost/vhost.h | 21 ++++
include/uapi/linux/vhost.h | 15 +++
4 files changed, 259 insertions(+), 19 deletions(-)
--
2.45.0
The vhost now uses vhost_task and workers as a child of the owner thread.
While this aligns with containerization principles,it confuses some legacy
userspace app, Therefore, we are reintroducing kthread API support.
Introduce a new parameter to enable users to choose between
kthread and task mode.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 1 +
drivers/vhost/vhost.h | 9 +++++++++
2 files changed, 10 insertions(+)
Add back the previously removed cgroup function to support the kthread
The biggest change for this part is in vhost_attach_cgroups() and
vhost_attach_task_to_cgroups().
The old function was remove in
commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads")
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
@@ -620,6 +621,46 @@ long vhost_dev_check_owner(struct vhost_dev *dev)}EXPORT_SYMBOL_GPL(vhost_dev_check_owner);+structvhost_attach_cgroups_struct{+structvhost_workwork;+structtask_struct*owner;+intret;+};++staticvoidvhost_attach_cgroups_work(structvhost_work*work)+{+structvhost_attach_cgroups_struct*s;++s=container_of(work,structvhost_attach_cgroups_struct,work);+s->ret=cgroup_attach_task_all(s->owner,current);+}++staticintvhost_attach_task_to_cgroups(structvhost_worker*worker)+{+structvhost_attach_cgroups_structattach;+intsaved_cnt;++attach.owner=current;++vhost_work_init(&attach.work,vhost_attach_cgroups_work);+vhost_worker_queue(worker,&attach.work);++mutex_lock(&worker->mutex);++/*+*Bypassattachment_cntcheckin__vhost_worker_flush:+*TemporarilychangeittoINT_MAXtobypassthecheck+*/+saved_cnt=worker->attachment_cnt;+worker->attachment_cnt=INT_MAX;+__vhost_worker_flush(worker);+worker->attachment_cnt=saved_cnt;++mutex_unlock(&worker->mutex);++returnattach.ret;+}+/* Caller should have device mutex */boolvhost_dev_has_owner(structvhost_dev*dev){
Add the previously removed function vhost_worker() back
to support the kthread and rename it to vhost_run_work_kthread_list.
The old function vhost_worker was change to support task in
commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads")
change to xarray in
commit 1cdaafa1b8b4 ("vhost: replace single worker pointer with xarray")
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
@@ -388,6 +388,44 @@ static void vhost_vq_reset(struct vhost_dev *dev,__vhost_vq_meta_reset(vq);}+staticintvhost_run_work_kthread_list(void*data)+{+structvhost_worker*worker=data;+structvhost_work*work,*work_next;+structvhost_dev*dev=worker->dev;+structllist_node*node;++kthread_use_mm(dev->mm);++for(;;){+/* mb paired w/ kthread_stop */+set_current_state(TASK_INTERRUPTIBLE);++if(kthread_should_stop()){+__set_current_state(TASK_RUNNING);+break;+}+node=llist_del_all(&worker->work_list);+if(!node)+schedule();++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);+__set_current_state(TASK_RUNNING);+kcov_remote_start_common(worker->kcov_handle);+work->fn(work);+kcov_remote_stop();+cond_resched();+}+}+kthread_unuse_mm(dev->mm);++return0;+}+staticboolvhost_run_work_list(void*data){structvhost_worker*worker=data;
The VHOST_NEW_WORKER requires the inherit_owner
setting to be true. So we need to add a check for this.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 7 +++++++
1 file changed, 7 insertions(+)
This commit restores the previously removed functions kthread
wake/stop/create, and use ops structure vhost_worker_ops to
manage worker wakeup, stop and creation. The function
vhost_worker_create initializes these ops pointers based on
the value of inherit_owner
The old function was remove in
commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads")
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 48 ++++++++++++++++++++++++++++++++++++++++++-
drivers/vhost/vhost.h | 1 +
2 files changed, 48 insertions(+), 1 deletion(-)
Add a new UAPI to configure the vhost device to use the kthread mode
The userspace application can use IOCTL VHOST_FORK_FROM_OWNER
to choose between owner and kthread mode if necessary
This setting must be applied before VHOST_SET_OWNER, as the worker
will be created in the VHOST_SET_OWNER function
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 22 ++++++++++++++++++++--
include/uapi/linux/vhost.h | 15 +++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
@@ -1134,7 +1134,7 @@ void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_iotlb *umem)inti;vhost_dev_cleanup(dev);-+dev->inherit_owner=true;dev->umem=umem;/* We don't need VQ locks below since vhost_dev_cleanup makes sure*VQsaren'trunning.
@@ -2287,7 +2287,25 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}-+if(ioctl==VHOST_FORK_FROM_OWNER){+u8inherit_owner;+/*inherit_owner can only be modified before owner is set*/+if(vhost_dev_has_owner(d)){+r=-EBUSY;+gotodone;+}+if(copy_from_user(&inherit_owner,argp,sizeof(u8))){+r=-EFAULT;+gotodone;+}+if(inherit_owner>1){+r=-EINVAL;+gotodone;+}+d->inherit_owner=(bool)inherit_owner;+r=0;+gotodone;+}/* You must be the owner to do anything else */r=vhost_dev_check_owner(d);if(r)
On Sun, Mar 02, 2025 at 10:32:08PM +0800, Cindy Lu wrote:
quoted hunk
Add a new UAPI to configure the vhost device to use the kthread mode
The userspace application can use IOCTL VHOST_FORK_FROM_OWNER
to choose between owner and kthread mode if necessary
This setting must be applied before VHOST_SET_OWNER, as the worker
will be created in the VHOST_SET_OWNER function
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 22 ++++++++++++++++++++--
include/uapi/linux/vhost.h | 15 +++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
int i;
vhost_dev_cleanup(dev);
-
+ dev->inherit_owner = true;
dev->umem = umem;
/* We don't need VQ locks below since vhost_dev_cleanup makes sure
* VQs aren't running.
@@ -2287,7 +2287,25 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
r = vhost_dev_set_owner(d);
goto done;
}
-
+ if (ioctl == VHOST_FORK_FROM_OWNER) {
+ u8 inherit_owner;
+ /*inherit_owner can only be modified before owner is set*/
+ if (vhost_dev_has_owner(d)) {
+ r = -EBUSY;
+ goto done;
+ }
+ if (copy_from_user(&inherit_owner, argp, sizeof(u8))) {
+ r = -EFAULT;
+ goto done;
+ }
+ if (inherit_owner > 1) {
+ r = -EINVAL;
+ goto done;
+ }
+ d->inherit_owner = (bool)inherit_owner;
+ r = 0;
+ goto done;
+ }
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
#define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \
struct vhost_vring_state)
+
+/**
+ * VHOST_FORK_FROM_OWNER - Set the inherit_owner flag for the vhost device
Should we mention that this IOCTL must be called before VHOST_SET_OWNER?
+ *
+ * @param inherit_owner: An 8-bit value that determines the vhost thread mode
+ *
+ * When inherit_owner is set to 1(default value):
+ * - Vhost will create tasks similar to processes forked from the owner,
+ * inheriting all of the owner's attributes..
^
nit: there 2 points here
+ *
+ * When inherit_owner is set to 0:
+ * - Vhost will create tasks as kernel thread
+ */
+#define VHOST_FORK_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8)
+
#endif
--
2.45.0
On Mon, Mar 3, 2025 at 4:58 PM Stefano Garzarella [off-list ref] wrote:
On Sun, Mar 02, 2025 at 10:32:08PM +0800, Cindy Lu wrote:
quoted
Add a new UAPI to configure the vhost device to use the kthread mode
The userspace application can use IOCTL VHOST_FORK_FROM_OWNER
to choose between owner and kthread mode if necessary
This setting must be applied before VHOST_SET_OWNER, as the worker
will be created in the VHOST_SET_OWNER function
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/vhost.c | 22 ++++++++++++++++++++--
include/uapi/linux/vhost.h | 15 +++++++++++++++
2 files changed, 35 insertions(+), 2 deletions(-)
@@ -1134,7 +1134,7 @@ void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_iotlb *umem)inti;vhost_dev_cleanup(dev);-+dev->inherit_owner=true;dev->umem=umem;/* We don't need VQ locks below since vhost_dev_cleanup makes sure*VQsaren'trunning.
@@ -2287,7 +2287,25 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}-+if(ioctl==VHOST_FORK_FROM_OWNER){+u8inherit_owner;+/*inherit_owner can only be modified before owner is set*/+if(vhost_dev_has_owner(d)){+r=-EBUSY;+gotodone;+}+if(copy_from_user(&inherit_owner,argp,sizeof(u8))){+r=-EFAULT;+gotodone;+}+if(inherit_owner>1){+r=-EINVAL;+gotodone;+}+d->inherit_owner=(bool)inherit_owner;+r=0;+gotodone;+}/* You must be the owner to do anything else */r=vhost_dev_check_owner(d);if(r)
#define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \
struct vhost_vring_state)
+
+/**
+ * VHOST_FORK_FROM_OWNER - Set the inherit_owner flag for the vhost device
Should we mention that this IOCTL must be called before VHOST_SET_OWNER?
quoted
+ *
+ * @param inherit_owner: An 8-bit value that determines the vhost thread mode
+ *
+ * When inherit_owner is set to 1(default value):
+ * - Vhost will create tasks similar to processes forked from the owner,
+ * inheriting all of the owner's attributes..
^
nit: there 2 points here
Thanks Stefano, I will change this
Thanks
cindy
quoted
+ *
+ * When inherit_owner is set to 0:
+ * - Vhost will create tasks as kernel thread
+ */
+#define VHOST_FORK_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8)
+
#endif
--
2.45.0
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}+#endif+/* You must be the owner to do anything else */r=vhost_dev_check_owner(d);if(r)
From: Jason Wang <hidden> Date: 2025-03-03 05:52:35
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted hunk
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}+#endif+/* You must be the owner to do anything else */r=vhost_dev_check_owner(d);if(r)--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
Other patches look good to me.
Thanks
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}+
nit: this empyt line is not needed
quoted
+#else
+ if (ioctl == VHOST_FORK_FROM_OWNER) {
+ /* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */
+ r = -ENOTTY;
+ goto done;
+ }
+#endif
+
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
I'm not sure about this honestly, the user space has no way to figure
out the default value and still has to do the IOCTL.
So IMHO better to have a default value that is independent of the kernel
configuration and consistent with the current behavior.
Thanks,
Stefano
On Mon, Mar 3, 2025 at 5:12 PM Stefano Garzarella [off-list ref] wrote:
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
quoted
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}+
nit: this empyt line is not needed
sure , will fix this
Thanks
Cindy
quoted
quoted
+#else
+ if (ioctl == VHOST_FORK_FROM_OWNER) {
+ /* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */
+ r = -ENOTTY;
+ goto done;
+ }
+#endif
+
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
I'm not sure about this honestly, the user space has no way to figure
out the default value and still has to do the IOCTL.
So IMHO better to have a default value that is independent of the kernel
configuration and consistent with the current behavior.
Thanks,
Stefano
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2025-03-03 17:33:18
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}
why do we need this? won't it fail as any other unsupported ioctl?
quoted
+#endif
+
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
I feel it is best to keep the default consistent.
All the kconfig should do, is block the ioctl.
From: Jason Wang <hidden> Date: 2025-03-10 04:54:41
On Tue, Mar 4, 2025 at 1:33 AM Michael S. Tsirkin [off-list ref] wrote:
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
quoted
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}
why do we need this? won't it fail as any other unsupported ioctl?
quoted
quoted
+#endif
+
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
I feel it is best to keep the default consistent.
Just want to make sure we are on the same page.
For "default", did you mean inherit_owner = false which is consistent
with behaviour without the vhost task?
Or inherit_onwer = true, then the new ioctl to make it false is
useless. And if legacy applications want kthread behaviour it needs to
be patched which seems self-contradictory.
Ping :)
On Mon, Mar 10, 2025 at 12:54 PM Jason Wang [off-list ref] wrote:
On Tue, Mar 4, 2025 at 1:33 AM Michael S. Tsirkin [off-list ref] wrote:
quoted
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
quoted
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}
why do we need this? won't it fail as any other unsupported ioctl?
quoted
quoted
+#endif
+
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
I feel it is best to keep the default consistent.
Just want to make sure we are on the same page.
For "default", did you mean inherit_owner = false which is consistent
with behaviour without the vhost task?
Or inherit_onwer = true, then the new ioctl to make it false is
useless. And if legacy applications want kthread behaviour it needs to
be patched which seems self-contradictory.
On Tue, Mar 4, 2025 at 1:33 AM Michael S. Tsirkin [off-list ref] wrote:
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
quoted
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}
why do we need this? won't it fail as any other unsupported ioctl?
Sure, will remove this
thanks
cindy
quoted
quoted
+#endif
+
/* You must be the owner to do anything else */
r = vhost_dev_check_owner(d);
if (r)
--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
I feel it is best to keep the default consistent.
All the kconfig should do, is block the ioctl.
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2025-03-21 19:39:39
On Mon, Mar 03, 2025 at 01:52:06PM +0800, Jason Wang wrote:
On Sun, Mar 2, 2025 at 10:34 PM Cindy Lu [off-list ref] wrote:
quoted
Introduce a new config knob `CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL`,
to control the availability of the `VHOST_FORK_FROM_OWNER` ioctl.
When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is set to n, the ioctl
is disabled, and any attempt to use it will result in failure.
Signed-off-by: Cindy Lu <redacted>
---
drivers/vhost/Kconfig | 15 +++++++++++++++
drivers/vhost/vhost.c | 11 +++++++++++
2 files changed, 26 insertions(+)
@@ -2294,6 +2294,8 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=vhost_dev_set_owner(d);gotodone;}++#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTLif(ioctl==VHOST_FORK_FROM_OWNER){u8inherit_owner;/*inherit_owner can only be modified before owner is set*/
@@ -2313,6 +2315,15 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)r=0;gotodone;}++#else+if(ioctl==VHOST_FORK_FROM_OWNER){+/* When CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL is 'n', return error */+r=-ENOTTY;+gotodone;+}+#endif+/* You must be the owner to do anything else */r=vhost_dev_check_owner(d);if(r)--
2.45.0
Do we need to change the default value of the inhert_owner? For example:
#ifdef CONFIG_VHOST_ENABLE_FORK_OWNER_IOCTL
inherit_owner = false;
#else
inherit_onwer = true;
#endif
?
Other patches look good to me.
Thanks
I think I agree with Cindy. kconfig just tells us whether the
ioctl is allowed. should not affect the default, if we want
a kconfig for default, it should be separate, but I doubt it.
QE tested this series of patches with virtio-net regression tests,
everything works fine.
Tested-by: Lei Yang <redacted>
On Sun, Mar 2, 2025 at 10:33 PM Cindy Lu [off-list ref] wrote:
In commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads"),
the vhost now uses vhost_task and operates as a child of the
owner thread. This aligns with containerization principles.
However, this change has caused confusion for some legacy
userspace applications. Therefore, we are reintroducing
support for the kthread API.
In this series, a new UAPI is implemented to allow
userspace applications to configure their thread mode.
Changelog v2:
1. Change the module_param's name to enforce_inherit_owner, and the default value is true.
2. Change the UAPI's name to VHOST_SET_INHERIT_FROM_OWNER.
Changelog v3:
1. Change the module_param's name to inherit_owner_default, and the default value is true.
2. Add a structure for task function; the worker will select a different mode based on the value inherit_owner.
3. device will have their own inherit_owner in struct vhost_dev
4. Address other comments
Changelog v4:
1. remove the module_param, only keep the UAPI
2. remove the structure for task function; change to use the function pointer in vhost_worker
3. fix the issue in vhost_worker_create and vhost_dev_ioctl
4. Address other comments
Changelog v5:
1. Change wakeup and stop function pointers in struct vhost_worker to void.
2. merging patches 4, 5, 6 in a single patch
3. Fix spelling issues and address other comments.
Changelog v6:
1. move the check of VHOST_NEW_WORKER from vhost_scsi to vhost
2. Change the ioctl name VHOST_SET_INHERIT_FROM_OWNER to VHOST_FORK_FROM_OWNER
3. reuse the function __vhost_worker_flush
4. use a ops sturct to support worker relates function
5. reset the value of inherit_owner in vhost_dev_reset_owner s.
Changelog v7:
1. add a KConfig knob to disable legacy app support
2. Split the changes into two patches to separately introduce the ops and add kthread support.
3. Utilized INX_MAX to avoid modifications in __vhost_worker_flush
4. Rebased on the latest kernel
5. Address other comments
Tested with QEMU with kthread mode/task mode/kthread+task mode
Cindy Lu (8):
vhost: Add a new parameter in vhost_dev to allow user select kthread
vhost: Reintroduce vhost_worker to support kthread
vhost: Add the cgroup related function
vhost: Introduce vhost_worker_ops in vhost_worker
vhost: Reintroduce kthread mode support in vhost
vhost: uapi to control task mode (owner vs kthread)
vhost: Add check for inherit_owner status
vhost: Add a KConfig knob to enable IOCTL VHOST_FORK_FROM_OWNER
drivers/vhost/Kconfig | 15 +++
drivers/vhost/vhost.c | 227 +++++++++++++++++++++++++++++++++----
drivers/vhost/vhost.h | 21 ++++
include/uapi/linux/vhost.h | 15 +++
4 files changed, 259 insertions(+), 19 deletions(-)
--
2.45.0
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2025-03-21 19:37:08
On Sun, Mar 02, 2025 at 10:32:02PM +0800, Cindy Lu wrote:
In commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads"),
the vhost now uses vhost_task and operates as a child of the
owner thread. This aligns with containerization principles.
However, this change has caused confusion for some legacy
userspace applications. Therefore, we are reintroducing
support for the kthread API.
In this series, a new UAPI is implemented to allow
userspace applications to configure their thread mode.
This seems to be on top of an old tree.
Can you rebase pls?
Changelog v2:
1. Change the module_param's name to enforce_inherit_owner, and the default value is true.
2. Change the UAPI's name to VHOST_SET_INHERIT_FROM_OWNER.
Changelog v3:
1. Change the module_param's name to inherit_owner_default, and the default value is true.
2. Add a structure for task function; the worker will select a different mode based on the value inherit_owner.
3. device will have their own inherit_owner in struct vhost_dev
4. Address other comments
Changelog v4:
1. remove the module_param, only keep the UAPI
2. remove the structure for task function; change to use the function pointer in vhost_worker
3. fix the issue in vhost_worker_create and vhost_dev_ioctl
4. Address other comments
Changelog v5:
1. Change wakeup and stop function pointers in struct vhost_worker to void.
2. merging patches 4, 5, 6 in a single patch
3. Fix spelling issues and address other comments.
Changelog v6:
1. move the check of VHOST_NEW_WORKER from vhost_scsi to vhost
2. Change the ioctl name VHOST_SET_INHERIT_FROM_OWNER to VHOST_FORK_FROM_OWNER
3. reuse the function __vhost_worker_flush
4. use a ops sturct to support worker relates function
5. reset the value of inherit_owner in vhost_dev_reset_owner s.
Changelog v7:
1. add a KConfig knob to disable legacy app support
2. Split the changes into two patches to separately introduce the ops and add kthread support.
3. Utilized INX_MAX to avoid modifications in __vhost_worker_flush
4. Rebased on the latest kernel
5. Address other comments
Tested with QEMU with kthread mode/task mode/kthread+task mode
Cindy Lu (8):
vhost: Add a new parameter in vhost_dev to allow user select kthread
vhost: Reintroduce vhost_worker to support kthread
vhost: Add the cgroup related function
vhost: Introduce vhost_worker_ops in vhost_worker
vhost: Reintroduce kthread mode support in vhost
vhost: uapi to control task mode (owner vs kthread)
vhost: Add check for inherit_owner status
vhost: Add a KConfig knob to enable IOCTL VHOST_FORK_FROM_OWNER
drivers/vhost/Kconfig | 15 +++
drivers/vhost/vhost.c | 227 +++++++++++++++++++++++++++++++++----
drivers/vhost/vhost.h | 21 ++++
include/uapi/linux/vhost.h | 15 +++
4 files changed, 259 insertions(+), 19 deletions(-)
--
2.45.0
On Sat, Mar 22, 2025 at 3:37 AM Michael S. Tsirkin [off-list ref] wrote:
On Sun, Mar 02, 2025 at 10:32:02PM +0800, Cindy Lu wrote:
quoted
In commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads"),
the vhost now uses vhost_task and operates as a child of the
owner thread. This aligns with containerization principles.
However, this change has caused confusion for some legacy
userspace applications. Therefore, we are reintroducing
support for the kthread API.
In this series, a new UAPI is implemented to allow
userspace applications to configure their thread mode.
This seems to be on top of an old tree.
Can you rebase pls?
sure, I will rebase this
Thanks
Cindy
quoted
Changelog v2:
1. Change the module_param's name to enforce_inherit_owner, and the default value is true.
2. Change the UAPI's name to VHOST_SET_INHERIT_FROM_OWNER.
Changelog v3:
1. Change the module_param's name to inherit_owner_default, and the default value is true.
2. Add a structure for task function; the worker will select a different mode based on the value inherit_owner.
3. device will have their own inherit_owner in struct vhost_dev
4. Address other comments
Changelog v4:
1. remove the module_param, only keep the UAPI
2. remove the structure for task function; change to use the function pointer in vhost_worker
3. fix the issue in vhost_worker_create and vhost_dev_ioctl
4. Address other comments
Changelog v5:
1. Change wakeup and stop function pointers in struct vhost_worker to void.
2. merging patches 4, 5, 6 in a single patch
3. Fix spelling issues and address other comments.
Changelog v6:
1. move the check of VHOST_NEW_WORKER from vhost_scsi to vhost
2. Change the ioctl name VHOST_SET_INHERIT_FROM_OWNER to VHOST_FORK_FROM_OWNER
3. reuse the function __vhost_worker_flush
4. use a ops sturct to support worker relates function
5. reset the value of inherit_owner in vhost_dev_reset_owner s.
Changelog v7:
1. add a KConfig knob to disable legacy app support
2. Split the changes into two patches to separately introduce the ops and add kthread support.
3. Utilized INX_MAX to avoid modifications in __vhost_worker_flush
4. Rebased on the latest kernel
5. Address other comments
Tested with QEMU with kthread mode/task mode/kthread+task mode
Cindy Lu (8):
vhost: Add a new parameter in vhost_dev to allow user select kthread
vhost: Reintroduce vhost_worker to support kthread
vhost: Add the cgroup related function
vhost: Introduce vhost_worker_ops in vhost_worker
vhost: Reintroduce kthread mode support in vhost
vhost: uapi to control task mode (owner vs kthread)
vhost: Add check for inherit_owner status
vhost: Add a KConfig knob to enable IOCTL VHOST_FORK_FROM_OWNER
drivers/vhost/Kconfig | 15 +++
drivers/vhost/vhost.c | 227 +++++++++++++++++++++++++++++++++----
drivers/vhost/vhost.h | 21 ++++
include/uapi/linux/vhost.h | 15 +++
4 files changed, 259 insertions(+), 19 deletions(-)
--
2.45.0