From nobody Wed Dec 17 05:45:42 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB92A20C022 for ; Sun, 23 Feb 2025 15:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740325308; cv=none; b=Y6tUOIFxlTYjpRdNBUnSVaVYtONKlm+PDcA6wz+znBXDFtpojRvOM2fQQFB0PI/3KbckPPVX4WAp2SqVjF+M1TrSW1Cwv0y2whNqGN897PEjmFYjK2OqBv5gI9yTPCZi56L1BYhmvvduthuY4sPwnNkuQrVwvBNAZGBmMmNvBx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740325308; c=relaxed/simple; bh=kQKVmVQmSmL+adQEArOg/LOerBpbDGXBClSP3y4DEC8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kpD8NO/U6l6itYhQvSoWGocNTASnP9TTDwug2wdzMkf8uJ0Nul+JJyMXDXQD5YSU/fEpqpcnrSJ040XAZ6EgdaPAH+Bd0v7DTBGEZJ1bZp2G9/eEkOUc2mCwFcom5u0xYpScDEadxEceg6or0y+i3wdjwxfmYwR6fIki0gijzhU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Xij+vN3G; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xij+vN3G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740325305; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rjvawlWkTytaHXnsqhHLk8h5P4QoG4NsfjDx6jEZ3uw=; b=Xij+vN3GYEB2cCwvb18B3vfk4ocjx7XXPVP1mIjQyN7UkBqUzu0Utn16bSXzQBeZyXosNl SVMGzQ6N4Cbl1Q/ixjjSfMAfjuJoCeEJdgq5dYF+dOSyCcJb/iRMXLRecVq6MSXU67yxUf h9ifdNMbRoEur2Ruf4t6Bmg059Sj5ZM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-96eYb0OwOgKQKyG8SfbhvA-1; Sun, 23 Feb 2025 10:41:40 -0500 X-MC-Unique: 96eYb0OwOgKQKyG8SfbhvA-1 X-Mimecast-MFC-AGG-ID: 96eYb0OwOgKQKyG8SfbhvA_1740325299 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4901C1800374; Sun, 23 Feb 2025 15:41:39 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.28]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E2D3180035F; Sun, 23 Feb 2025 15:41:34 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v6 5/6] vhost: Add new UAPI to support change to task mode Date: Sun, 23 Feb 2025 23:36:20 +0800 Message-ID: <20250223154042.556001-6-lulu@redhat.com> In-Reply-To: <20250223154042.556001-1-lulu@redhat.com> References: <20250223154042.556001-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add a new UAPI to enable setting the vhost device to task mode. The userspace application can use VHOST_SET_INHERIT_FROM_OWNER to configure the 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 --- drivers/vhost/vhost.c | 24 ++++++++++++++++++++++-- include/uapi/linux/vhost.h | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index d8c0ea118bb1..45d8f5c5bca9 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -1133,7 +1133,7 @@ void vhost_dev_reset_owner(struct vhost_dev *dev, str= uct vhost_iotlb *umem) int i; =20 vhost_dev_cleanup(dev); - + dev->inherit_owner =3D true; dev->umem =3D umem; /* We don't need VQ locks below since vhost_dev_cleanup makes sure * VQs aren't running. @@ -2278,15 +2278,35 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned = int ioctl, void __user *argp) { struct eventfd_ctx *ctx; u64 p; - long r; + long r =3D 0; int i, fd; + u8 inherit_owner; =20 /* If you are not the owner, you can become one */ if (ioctl =3D=3D VHOST_SET_OWNER) { r =3D vhost_dev_set_owner(d); goto done; } + if (ioctl =3D=3D VHOST_FORK_FROM_OWNER) { + /*inherit_owner can only be modified before owner is set*/ + if (vhost_dev_has_owner(d)) { + r =3D -EBUSY; + goto done; + } + if (copy_from_user(&inherit_owner, argp, sizeof(u8))) { + r =3D -EFAULT; + goto done; + } + /* Validate the inherit_owner value, ensuring it is either 0 or 1 */ + if (inherit_owner > 1) { + r =3D -EINVAL; + goto done; + } + + d->inherit_owner =3D (bool)inherit_owner; =20 + goto done; + } /* You must be the owner to do anything else */ r =3D vhost_dev_check_owner(d); if (r) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index b95dd84eef2d..8f558b433536 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -235,4 +235,22 @@ */ #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 + * + * @param inherit_owner: An 8-bit value that determines the vhost thread m= ode + * + * When inherit_owner is set to 1: + * - The VHOST worker threads inherit its values/checks from + * the thread that owns the VHOST device, The vhost threads will + * be counted in the nproc rlimits. + * + * When inherit_owner is set to 0: + * - The VHOST worker threads will use the traditional kernel thread (kt= hread) + * implementation, which may be preferred by older userspace applicati= ons that + * do not utilize the newer vhost_task concept. + */ +#define VHOST_FORK_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8) + #endif --=20 2.45.0