From mboxrd@z Thu Jan 1 00:00:00 1970 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 7D7525227 for ; Mon, 24 Feb 2025 21:46:16 +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=1740433578; cv=none; b=BHhalcc+pzdm5M+mZ5JBp8OqiGnx8qmQR5nSNI42vHAB8IpIEnQtyvz7TqDYBzcOWDcGf5mtgyXrNX6YPL4kEpSC2P2aARaYJv7AVkFCFUSemsudyaihSfqcoUPLH3xVdp+x7gR5rjhiC+jPOhBwlObc2cf8hfIYqdyEep6z/kA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740433578; c=relaxed/simple; bh=e+kYByMXNeDUALN2Jm62hIYRxASWL87Qinb3VWV2j40=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zek0ff24X4RawSQlbuZhEEmqAxvdI9WCrDxhVsGlwi9uaMTUgV3BBGxsu7U1Ao61bBT1iXqweNBd6RVZnWrIuJo1EY8Ox85M/MxXBOAubjCxOwXuQgHL0AyXgG2G9rvxu5E+rZlEmZY037Rmta5DGQ2Huy5zDdNyq+57KcrRJzs= 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=iBJfrgcg; 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="iBJfrgcg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740433575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/djJ+PtX4FDl6jsu51ShmCbl9JrXbgv9LkcxGG2wMj8=; b=iBJfrgcghoMt4jVMUZumxVDUhUa1I0Ax8r99o09wcJ8HEBmm1WOrQdyz1NGw41ktqLjbU8 6vPyOrL65yBmFPLJ7A1JwOc7PPKwCrO2djAs8CKevsCq3OwYZxpTx5FUyt67E2jYPOzhDy z1zd2Dtobb4Ij6ulDb18D8EBrK22NOQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-364-FCOE6UKtNbuj3xIeUzYY4A-1; Mon, 24 Feb 2025 16:46:14 -0500 X-MC-Unique: FCOE6UKtNbuj3xIeUzYY4A-1 X-Mimecast-MFC-AGG-ID: FCOE6UKtNbuj3xIeUzYY4A_1740433573 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5e0573b9f60so3162953a12.3 for ; Mon, 24 Feb 2025 13:46:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740433573; x=1741038373; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/djJ+PtX4FDl6jsu51ShmCbl9JrXbgv9LkcxGG2wMj8=; b=GXV3njEknDks1wWZJQU6CS9ZWkOokJppw9U1Oy3I6zQ2dSvSM2yGeLqA2F8tgcRbbl C7M7gxy9NP4bF66yBBD47Pr14NaBHgnLlgBr+cfkqd29eHwE/KksQ5agQa2vWlFjYKoT mVJvkKX4Oze+HzwfQQqopRtMtf0ft3rl7nMH5DieXQGiQEOZYHZh/IPA20ECEZnsAmcq m5R96qs4D+ZwNlqgwS4qBz9AA+WcxxAb3FY2TjHXMBh1xpjKuDew9e3agEuEnbnzZOVk PHbyfh7QAZC0DzKWVwyDBQ6vfNI2470Db+bYXrv1BksXEQDPXibBPTN0+8Pyy8tvgJmg PYzg== X-Forwarded-Encrypted: i=1; AJvYcCV3Fo4cRu5tf+vIvI176FGA7n0AZwA7AxIiqAuEky02GzF1zuuWE4XU2+T3gJ0RqGgucSLZmjSInf2vt+Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzhwRdasCfKm2OBNbUEEKtSmPxJW8aofjUD72UpO+Nbrsfb+uDO JNpvGo893rqtSE/kevyp4BSMU5IeyDlR7aCWkDmJdKeNCb9YnUqNRglWbB07BmTVwziWBeI65G1 nJBt0t7JIRDuFZwiENgTAQXRkSp57Ty8h7DVYEKoKGkAFifz0BbgNR4YDNXDhqA== X-Gm-Gg: ASbGnctr2RHIF2zBZmn7Y99vOrWdpetiILJnfoSDPHFx8juSSepIXzGOoR1PBtQz4OJ IysmssUQTNW7p/5L/AETvZYHZBoiGhQsKBIod0zFvAO83P+IlSJEmAtTmvXsU6TQj8vJnHK9MwD QBXM1GKMPkCBWOxU30feWVmcOYAlNiZ/os828s96Bk+o0WlZl6gCOgacgxMMqCyQQJasLrI13kN qu7ZoNg667FLc7KkdVNK8oitGropMcbMxFZjqzxMPkwL0lvs89YCQQY6pyRb6HmGb+GZI+mG9Em clA8heQ2zA== X-Received: by 2002:a17:906:399b:b0:abe:cb87:9599 with SMTP id a640c23a62f3a-abecb8796b2mr187043666b.44.1740433572896; Mon, 24 Feb 2025 13:46:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7OyvLnm+e7goejV5zHakF8+COjfdjxx8Ny74h+t1TgYk1yctpE21hRJ1pnICAkf/LM9wawg== X-Received: by 2002:a17:906:399b:b0:abe:cb87:9599 with SMTP id a640c23a62f3a-abecb8796b2mr187042466b.44.1740433572546; Mon, 24 Feb 2025 13:46:12 -0800 (PST) Received: from redhat.com ([2a0d:6fc7:441:1929:22c5:4595:d9bc:489e]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abed1cd4c23sm28274366b.11.2025.02.24.13.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 13:46:11 -0800 (PST) Date: Mon, 24 Feb 2025 16:46:08 -0500 From: "Michael S. Tsirkin" To: Cindy Lu Cc: jasowang@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: Re: [PATCH v6 5/6] vhost: Add new UAPI to support change to task mode Message-ID: <20250224164312-mutt-send-email-mst@kernel.org> References: <20250223154042.556001-1-lulu@redhat.com> <20250223154042.556001-6-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250223154042.556001-6-lulu@redhat.com> better subject: vhost: uapi to control task mode (owner vs kthread) On Sun, Feb 23, 2025 at 11:36:20PM +0800, Cindy Lu wrote: > Add a new UAPI to enable setting the vhost device to task mode. better: Add a new UAPI to configure the vhost device to use the kthread mode > The userspace application can use VHOST_SET_INHERIT_FROM_OWNER > to configure the mode ... to either owner or kthread. > 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, struct vhost_iotlb *umem) > 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. > @@ -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 = 0; > int i, fd; > + u8 inherit_owner; > > /* If you are not the owner, you can become one */ > if (ioctl == VHOST_SET_OWNER) { > r = vhost_dev_set_owner(d); > goto done; > } > + if (ioctl == VHOST_FORK_FROM_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; > + } > + /* Validate the inherit_owner value, ensuring it is either 0 or 1 */ > + if (inherit_owner > 1) { > + r = -EINVAL; > + goto done; > + } > + > + d->inherit_owner = (bool)inherit_owner; > > + goto done; > + } > /* You must be the owner to do anything else */ > r = 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 mode > + * > + * 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 (kthread) > + * implementation, which may be preferred by older userspace applications that > + * do not utilize the newer vhost_task concept. > + */ > +#define VHOST_FORK_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8) > + > #endif > -- > 2.45.0