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.129.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 0CCEE1E1DE8 for ; Wed, 26 Feb 2025 08:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740559857; cv=none; b=uBTanL5b0Cv9mFuLX9bqpBUmEGVipM3rETTffR8TCN6/+ogdETlSXez0/JYONgKPG2Lh+pFDKoVLKrEFcgOZ0LYqQ/zqIMhiK1h5imSw0LzXex0snraynRB7w/rDGUr5ZeC7o1HCNcmTrjHuTABIG2Pf0YrQoB2d9J8mBXEViQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740559857; c=relaxed/simple; bh=TlqIDV8RqYlxPo/b6yGAe9zWBggL5/w9qEsziGhHGZ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MhQtz/jK0p8QbYYQMV/tf5LPgLhAd9jTRTVhJK5znwPxwvRI8GT7NeNWweXOD4Fw0IREIcYioBv1t98mhF3mi0AiyXdWPVLoYLimvTFYyjodIqr5aUhddxXGqEVT/xajxwenl3BE39M4X106lnpwsi0vyJId7zTcsWYMjt1T8HM= 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=BxqWzA6B; arc=none smtp.client-ip=170.10.129.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="BxqWzA6B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740559853; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W569uJXR/VXEzmXeXl4vPfAutQmoCsakKrgYooeW6j8=; b=BxqWzA6BEAa3Fgkd7mINLnBTi92ZepZPFf0huM2qEmHB15Vfb9RJaO8mh9PAuWaVb2TuTm tUgYN3ugpoB3yiDem7NePyhlIrcT7xsoBpv+ddAcP6ArHk4lEHRTs8xhFRZnHot1uYx9/t Tpi78dAbtxMmF/ZxhgsIKB0n+M6S4VQ= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-3WwMwYbvP2SDeAnK7qewIg-1; Wed, 26 Feb 2025 03:50:52 -0500 X-MC-Unique: 3WwMwYbvP2SDeAnK7qewIg-1 X-Mimecast-MFC-AGG-ID: 3WwMwYbvP2SDeAnK7qewIg_1740559851 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4394c747c72so27749645e9.1 for ; Wed, 26 Feb 2025 00:50:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740559851; x=1741164651; h=in-reply-to:content-transfer-encoding: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=W569uJXR/VXEzmXeXl4vPfAutQmoCsakKrgYooeW6j8=; b=v6Z9feR6aYGLGhofxigEtJU06Ary34hnNy+dLKSdJmPYKiCGy3FubcGJT8e6vQ2BtE Cy5K4o4ExOvHknF0wuwz6OLkSWzPHvoFGQ8acuQJgDFPdispbwgbGIg+BvY49GSZ48yJ DIhTzlhuCC1KzuodQSe7oI8yjXvlhkR+8+lzZUbtbd4IB8yW7HpZ939x31WNEbnoeqIf 7e4LqIVR5SAolhfRt5ZAdBvP5KNnIRddlRXDefqJiyXVg33M9YfLsC3ITdFXuWavAnzR Eb5xIHLZgzr9d8oLQ/k1u8L3eSN5kqv3WaMJ8J0UCzc7uhvTi6jjNd1Da/u76Vmfj6PD egCg== X-Forwarded-Encrypted: i=1; AJvYcCXIAKryGg5Zzre11Y13x9SfdXDZpbJ+UaPnYDqSobkTbXN9dra0Z5Uv9vLpmDjT4uhYc/dNP9NyyPEuTPs=@vger.kernel.org X-Gm-Message-State: AOJu0YzhtTTf+v2W80ngspRv8dwY13vx0WOtVt0xS4qKXd91y2MdwVyd AIC/5oLlmOuYSPwaHgNXKG4RyaW32UQugoKkYc75XczZt2PqkKX/asZstOahbvtdSzcIlvZkx2h OhPH/TDTrSYnuXfjk6IJQo0HSxZnaniUwx4erwNpitDfUOniNZTJm1O9SYDIvpg== X-Gm-Gg: ASbGncvp8KnBs+QPLQxq2g/r2Weyijbj7+95TTV1qopXfKppbYtpiFCgSEprD0ia/f4 4CNksj6HlB67epTcZFN62OiRz/6XLgZQng32be1FUZIqRuAUkz2rdoc2jjJ20WEXCQoIj/XOTP0 7UhBgqOZJsBNTzfZRagZVQOPSxFQeAFsHpc/KWnJBCuz5IEzOvf+EOHjtFisbjSxRKr0Pnn+66k L4r4hFin01321GQkm7uCaj4KjQZp7tclMYgGHvVuOTRW6tM+j9bPJ2LTcGWEr5hVorKjuuCd7XK ltyWFdbPsw== X-Received: by 2002:a05:600c:4f93:b0:439:9c0e:3692 with SMTP id 5b1f17b1804b1-439b75b6417mr141340505e9.28.1740559851183; Wed, 26 Feb 2025 00:50:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbMJ5mkQfjiSQborGir/O3+YljBsy/esutoUmpA27ZFyuTcn1+Xvu16xwWUH6sOldzPwK0qQ== X-Received: by 2002:a05:600c:4f93:b0:439:9c0e:3692 with SMTP id 5b1f17b1804b1-439b75b6417mr141340255e9.28.1740559850795; Wed, 26 Feb 2025 00:50:50 -0800 (PST) Received: from redhat.com ([2a02:14f:1eb:e270:8595:184c:7546:3597]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43aba4c437asm14054485e9.0.2025.02.26.00.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 00:50:50 -0800 (PST) Date: Wed, 26 Feb 2025 03:50:46 -0500 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: Cindy Lu , jasowang@redhat.com, michael.christie@oracle.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: <20250226035030-mutt-send-email-mst@kernel.org> References: <20250223154042.556001-1-lulu@redhat.com> <20250223154042.556001-6-lulu@redhat.com> <6vadeadshznfijaugusnwqprssqirxjtbtpprvokdk6yvvo6br@5ngvuz7peqoz> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Feb 26, 2025 at 09:46:06AM +0100, Stefano Garzarella wrote: > Hi Cindy, > > On Wed, 26 Feb 2025 at 07:14, Cindy Lu wrote: > > > > On Tue, Feb 25, 2025 at 7:31 PM Stefano Garzarella wrote: > > > > > > 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. > > > >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, 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) > > > > > > I don't think we really care of the size of the parameter, so can we > > > just use `bool` or `unsigned int` or `int` for this IOCTL? > > > > > > As we did for other IOCTLs where we had to enable/disable something (e.g > > > VHOST_VSOCK_SET_RUNNING, VHOST_VDPA_SET_VRING_ENABLE). > > > > > hi Stefano > > I initially used it as a boolean, but during the code review, the > > maintainers considered it was unsuitable for the bool use as the > > I see, indeed I found only 1 case of bool: > > include/uapi/misc/xilinx_sdfec.h:#define XSDFEC_SET_BYPASS > _IOW(XSDFEC_MAGIC, 9, bool) > > > interface in ioctl (I think in version 3 ?). So I changed it to u8, > > then will check if this is 1/0 in ioctl and the u8 should be > > sufficient for us to use > > Okay, if Michael and Jason are happy with it, it's fine. > It just seemed strange to me that for other IOCTLs we use int or > unsigned int when we need a boolean instead of a sized type. I only found VHOST_VSOCK_SET_RUNNING. which other ioctls? > Thanks for looking at it, > Stefano