From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 022E01FA163 for ; Wed, 8 Jan 2025 12:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736338419; cv=none; b=egfvBSy7244F6x9bq9fqwEk9T99mvWi9iKd5RujGTazKKuifruf+UBg0CJ0jGnKMpxCCC2KJP1RXlQFIttxnuuY01kP4qyJC58dUOOabGfz53S1rhlYZeXX6D0TOeh+0QI6w+FFdOELoC/mv7GWoeAHV1XLLRhjt8Nn/tf/Ajm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736338419; c=relaxed/simple; bh=d7f8krLI3sio/JPw5wyDY2mgXVXa4Il9oYZULrgrmls=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: In-Reply-To:Content-Type:Content-Disposition; b=qXSbOKk3+i55mmzxjfTN/7Mm0n1wLakA1mnd3RPRvNZrr3O//nBSjpUcqp7QP8JHbmVsv0xR/IRRxbAq4T06gRudnWesvm5tJ2knj6wTIPyhIcAZhiqsZOwy7ulxqBACuWQiEAnnQKIB8kV9VPydJuwC5H7DPZmWEH7DkdiSgHY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PWEwi+Vx; arc=none smtp.client-ip=140.211.166.138 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PWEwi+Vx" Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9651680F32 for ; Wed, 8 Jan 2025 12:13:37 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -5.792 X-Spam-Level: Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id W9wWISsCkhbu for ; Wed, 8 Jan 2025 12:13:37 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=mst@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org C393F80F05 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org C393F80F05 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PWEwi+Vx Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id C393F80F05 for ; Wed, 8 Jan 2025 12:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736338414; 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=bcqwD+plhNgGAFGqLcZ3Vozdz+RdeOGXJJcR/HY5MSA=; b=PWEwi+VxxuOoYDKI8PZYijW07s4N4pIurywKHpc4UyZoFon+GSpspSHtsMePOztZHi4h6n /30tP5909OMncu350Jvcadh0t5F7oC5Mmb/hAwWktzWHvq791pJlMdHdMye+cOK4+3q3je FvGD8mjH4C7Czm1jUsafTkAnzDuuBPI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-8CY7gBM2PwOtz0XbGbVPvw-1; Wed, 08 Jan 2025 07:13:33 -0500 X-MC-Unique: 8CY7gBM2PwOtz0XbGbVPvw-1 X-Mimecast-MFC-AGG-ID: 8CY7gBM2PwOtz0XbGbVPvw Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-aa68952272bso455668266b.2 for ; Wed, 08 Jan 2025 04:13:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736338412; x=1736943212; 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=bcqwD+plhNgGAFGqLcZ3Vozdz+RdeOGXJJcR/HY5MSA=; b=QLCg/iBh3dmlV5RDWeub/wWgs5SvJuR4YmBWPSbclORMMa30Rqxs9SVcCDu4QEOoOe 4TJZH+QXI4MqAj/xhrk+n7SFMcvA4Egsy7J8n0lsM84KPceAUIQhOOAIEqiy2rBJAfiL 1AjflwpTPd1mEBS8RtXqrnHcHdcgWCzXzeaLrlWPT/bqyap6eTael7ymDqqF1bNr9Vr9 y3aLT09dHEgr1jtGTiTRGOmaATyNMhaOL4nE5e6/GSmgQtoSpwBK5mOqN6Cu4lROu4ZD P1/bd6D2cmJ3P0A6QBvmYlhbBTgRSyKHl4Ky9xRW8O9SQhwXzWz5xisPFE0CYJsMzBAe /oMQ== X-Forwarded-Encrypted: i=1; AJvYcCVUi4nIkLwLTPnlVdbTim71V8ZABhwUlIcXI/27quNAFZ0nIBY4HbY21v7fo/mIgOjYVZmk+B1YzUMfU6uOxw==@lists.linux-foundation.org X-Gm-Message-State: AOJu0Yz6nO1YA1i6HFiRoshUFUHq2BxE9YZRNl+Lwgo70VRtXduG1ZJG T5AD7p5p41AQIfQsS3grriBrCiQfr+lU1n7ifVqdSPE08SHcC8M4WmzPqRT4KUmtx3Svhhu0NJi F5mC76I9Zdqoa+bn0kWs7OZ6jYNNDVnFCBJVP06+ltPmSRFBIffh3XmOJ5gsMT0an5simCEaLKY m8yMs= X-Gm-Gg: ASbGncvUxXFNgyCCs06xA+yQsBXZ9k92ng//Sr2Xkyll2n8VCdP7xQlEtkuwns7igB4 6t0/5Naf5MdWPWXHlg+Rx+yUYJxCQyniMOHgbBp77zYCJWhmprpYA/Ovd3TF6ICz6bMr1onKGUH faCP3Ql5BhtGxVJGAQuLCfvyG3jqFHJ7/08n8NYf9v+TEs0CwskP6exoP8qY/C8v2nb79/mCxy7 DN5qwEa0xvUu0KOzangbRqjVIgD2bj+BE7766ygX0M/pHMKpoE= X-Received: by 2002:a17:906:ef0e:b0:aa6:9e0f:d985 with SMTP id a640c23a62f3a-ab2ab748e6fmr186651366b.35.1736338411967; Wed, 08 Jan 2025 04:13:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1tzHlmToonYU5VRNpZjPrkTmxuXnu7JCDwg2y8QM+1b+3gwVx6kdoXsaFrzdS6+50/P9Meg== X-Received: by 2002:a17:906:ef0e:b0:aa6:9e0f:d985 with SMTP id a640c23a62f3a-ab2ab748e6fmr186649366b.35.1736338411574; Wed, 08 Jan 2025 04:13:31 -0800 (PST) Received: from redhat.com ([2a02:14f:175:d62d:93ef:d7e2:e7da:ed72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f06c654sm2510917266b.185.2025.01.08.04.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 04:13:30 -0800 (PST) Date: Wed, 8 Jan 2025 07:13:27 -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 v4 7/8] vhost: Add new UAPI to support change to task mode Message-ID: <20250108071107-mutt-send-email-mst@kernel.org> References: <20241210164456.925060-1-lulu@redhat.com> <20241210164456.925060-8-lulu@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20241210164456.925060-8-lulu@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: a6XLPj6tJuwGtJwaBHoNfLcP9OeIynTKaDCJ0YN9ZCo_1736338412 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Dec 11, 2024 at 12:41:46AM +0800, Cindy Lu wrote: > 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 Good. I would like to see an option to allow/block this ioctl, to prevent exceeding nproc limits. A Kconfig option is probably sufficient. "allow legacy threading mode" and default to yes? > --- > drivers/vhost/vhost.c | 22 +++++++++++++++++++++- > include/uapi/linux/vhost.h | 18 ++++++++++++++++++ > 2 files changed, 39 insertions(+), 1 deletion(-) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index 3e9cb99da1b5..12c3bf3d1ed4 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -2257,15 +2257,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_SET_INHERIT_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..d7564d62b76d 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_SET_INHERIT_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_SET_INHERIT_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8) > + > #endif > -- > 2.45.0