[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8A5BDA6D-21F7-40F8-8A28-0B2F57D89D81@akamai.com>
Date: Tue, 28 Oct 2025 07:13:56 +0000
From: "Hudson, Nick" <nhudson@...mai.com>
To: Jason Wang <jasowang@...hat.com>
CC: "Michael S. Tsirkin" <mst@...hat.com>,
Eugenio Pérez
<eperezma@...hat.com>,
"Tottenham, Max" <mtottenh@...mai.com>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"virtualization@...ts.linux.dev"
<virtualization@...ts.linux.dev>,
"netdev@...r.kernel.org"
<netdev@...r.kernel.org>,
"linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] vhost: add a new ioctl VHOST_GET_VRING_WORKER_INFO and
use in net.c
> On 28 Oct 2025, at 00:42, Jason Wang <jasowang@...hat.com> wrote:
>
> !-------------------------------------------------------------------|
> This Message Is From an External Sender
> This message came from outside your organization.
> |-------------------------------------------------------------------!
>
> On Mon, Oct 27, 2025 at 6:27 PM Nick Hudson <nhudson@...mai.com> wrote:
>>
>> The vhost_net (and vhost_sock) drivers create worker tasks to handle
>> the virtual queues. Provide a new ioctl VHOST_GET_VRING_WORKER_INFO that
>> can be used to determine the PID of these tasks so that, for example,
>> they can be pinned to specific CPU(s).
>>
>> Signed-off-by: Nick Hudson <nhudson@...mai.com>
>> Reviewed-by: Max Tottenham <mtottenh@...mai.com>
>> ---
>> drivers/vhost/net.c | 5 +++++
>> drivers/vhost/vhost.c | 16 ++++++++++++++++
>> include/uapi/linux/vhost.h | 3 +++
>> include/uapi/linux/vhost_types.h | 13 +++++++++++++
>> kernel/vhost_task.c | 12 ++++++++++++
>> 5 files changed, 49 insertions(+)
>>
>> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
>> index 35ded4330431..e86bd5d7d202 100644
>> --- a/drivers/vhost/net.c
>> +++ b/drivers/vhost/net.c
>> @@ -1804,6 +1804,11 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
>> return vhost_net_reset_owner(n);
>> case VHOST_SET_OWNER:
>> return vhost_net_set_owner(n);
>> + case VHOST_GET_VRING_WORKER_INFO:
>> + mutex_lock(&n->dev.mutex);
>> + r = vhost_worker_ioctl(&n->dev, ioctl, argp);
>> + mutex_unlock(&n->dev.mutex);
>> + return r;
>> default:
>> mutex_lock(&n->dev.mutex);
>> r = vhost_dev_ioctl(&n->dev, ioctl, argp);
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index 8570fdf2e14a..8b52fd5723c3 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -2399,6 +2399,22 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
>> if (ctx)
>> eventfd_ctx_put(ctx);
>> break;
>> + case VHOST_GET_VRING_WORKER_INFO:
>> + worker = rcu_dereference_check(vq->worker,
>> + lockdep_is_held(&dev->mutex));
>> + if (!worker) {
>> + ret = -EINVAL;
>> + break;
>> + }
>> +
>> + memset(&ring_worker_info, 0, sizeof(ring_worker_info));
>> + ring_worker_info.index = idx;
>> + ring_worker_info.worker_id = worker->id;
>> + ring_worker_info.worker_pid = task_pid_vnr(vhost_get_task(worker->vtsk));
>> +
>> + if (copy_to_user(argp, &ring_worker_info, sizeof(ring_worker_info)))
>> + ret = -EFAULT;
>> + break;
>> default:
>> r = -ENOIOCTLCMD;
>> break;
>> diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
>> index c57674a6aa0d..c32aa8c71952 100644
>> --- a/include/uapi/linux/vhost.h
>> +++ b/include/uapi/linux/vhost.h
>> @@ -101,6 +101,9 @@
>> /* Return the vring worker's ID */
>> #define VHOST_GET_VRING_WORKER _IOWR(VHOST_VIRTIO, 0x16, \
>> struct vhost_vring_worker)
>> +/* Return the vring worker's ID and PID */
>> +#define VHOST_GET_VRING_WORKER_INFO _IOWR(VHOST_VIRTIO, 0x17, \
>> + struct vhost_vring_worker_info)
>>
>> /* The following ioctls use eventfd file descriptors to signal and poll
>> * for events. */
>> diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h
>> index 1c39cc5f5a31..28e00f8ade85 100644
>> --- a/include/uapi/linux/vhost_types.h
>> +++ b/include/uapi/linux/vhost_types.h
>> @@ -63,6 +63,19 @@ struct vhost_vring_worker {
>> unsigned int worker_id;
>> };
>>
>> +/* Per-virtqueue worker mapping entry */
>> +struct vhost_vring_worker_info {
>> + /* vring index */
>> + unsigned int index;
>> + /*
>> + * The id of the vhost_worker returned from VHOST_NEW_WORKER or
>> + * allocated as part of vhost_dev_set_owner.
>> + */
>> + unsigned int worker_id;
>
> I'm not sure the above two are a must and exposing internal workd_id
> seems not like a good idea.
It’s already exposed by VHOST_NEW_WORKER, but happy to drop it if you prefer.
>
>> +
>> + __kernel_pid_t worker_pid; /* PID/TID of worker thread, -1 if none */
>
> Instead of exposing the worker PID, I wonder if it's simple to just
> having a better naming of the worker instead of a simple:
>
> snprintf(name, sizeof(name), "vhost-%d", current->pid);
This is currently the case
drivers/vhost/vhost.c: snprintf(name, sizeof(name), "vhost-%d", current->pid);
I was hoping to add the IOCTL, use in qemu, and expose it via QMP/HMP. I have changes to qemu that do this.
Thanks,
Nick
Download attachment "smime.p7s" of type "application/pkcs7-signature" (3067 bytes)
Powered by blists - more mailing lists