From patchwork Tue Nov 5 07:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862588 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 81C971FEFA7 for ; Tue, 5 Nov 2024 07:27:10 +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=1730791632; cv=none; b=KBjLEFy5/Rv1dws9nQzBGE8W7GZ2eexvb7PIIrRICS2Rcg+Sj/qShyMxRlgf330eSB1LyTMLcalUMC/NNhN/2RQmM2oa6gjG8FhqCzCyfFyLmrf+RFUdtw0zovQvMFP6gABwGv72VLvFrk7bwNcmf7HAqxt5hpHpRYD+Cwi5tio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791632; c=relaxed/simple; bh=l9RbpjgxGo9MDgdsXYvwzNMY7RifCS985yCLpV8udPU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m3oNDiMuPmoWrgTvRrqnt8wTb3nfhVoiB/+HVsulrR051hKnFCVTrTOXQoCRm8eWdrxLfpeAgUwFFefQ69gS09NK2Pcnq1uKkMzA1t2hE9apxf6KvV7Pn60kpWO6uf/oUG2R+fChyQEX6j1MomK+4CAw83dkbzb++kxfcg3rv3w= 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=EpwHMB11; 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="EpwHMB11" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791629; 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=YrN25r/0W16IYmHHoUR1xxPmflO4UlfZvP9MJNNbpL4=; b=EpwHMB11KkxRHk6uIukao9SD3ezpgr2yQQIxwlwz6W97a9PUwyHK2O7bH0tcMK7Iew9Hag C9VZ41hIH5xSHO+A28wUpX7QTbLFKwAT88zHDvqQufgy1VoE0yDXg/310wQiYNP3TYqGlv hT//Feg+GcVqHk3NA07apq5gm0IoTt4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-jAnLrO4_OO-yjG_WIvM1-g-1; Tue, 05 Nov 2024 02:27:06 -0500 X-MC-Unique: jAnLrO4_OO-yjG_WIvM1-g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCD631956083; Tue, 5 Nov 2024 07:27:05 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BA081955F42; Tue, 5 Nov 2024 07:27:01 +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 v3 1/9] vhost: Add a new parameter to allow user select kthread Date: Tue, 5 Nov 2024 15:25:20 +0800 Message-ID: <20241105072642.898710-2-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 The vhost now uses vhost_task and workers as a child of the owner thread. While this aligns with containerization principles,it confuses some legacy userspace app, Therefore, we are reintroducing kthread API support. Introduce a new parameter to enable users to choose between kthread and task mode. This will be exposed by module_param() later. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 2 ++ drivers/vhost/vhost.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9ac25d08f473..eff6acbbb63b 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -41,6 +41,7 @@ static int max_iotlb_entries = 2048; module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries. (default: 2048)"); +static bool inherit_owner_default = true; enum { VHOST_MEMORY_F_LOG = 0x1, @@ -552,6 +553,7 @@ void vhost_dev_init(struct vhost_dev *dev, dev->byte_weight = byte_weight; dev->use_worker = use_worker; dev->msg_handler = msg_handler; + dev->inherit_owner = inherit_owner_default; init_waitqueue_head(&dev->wait); INIT_LIST_HEAD(&dev->read_list); INIT_LIST_HEAD(&dev->pending_list); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index bb75a292d50c..c650c4506c70 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -176,6 +176,7 @@ struct vhost_dev { int byte_weight; struct xarray worker_xa; bool use_worker; + bool inherit_owner; int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg); }; From patchwork Tue Nov 5 07:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862589 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 77A971FDF9B for ; Tue, 5 Nov 2024 07:27:14 +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=1730791636; cv=none; b=PaBg/Da5EUFkhMTVKP0lD8rwV2eI38Tkmn5oesddASXYi5edyN/mhS4i1w/g44qg5D0+0CLFknznj1xy0lrbTPuMIKcJXiixph9Z2BHyAvvjRhQL07Lelgf4dhVqN06WDixaHL/hKiE+y6JLGTe1JKXZo0RiiSbn4bszht8hmm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791636; c=relaxed/simple; bh=THdCA1jm90rs4duE7RiNf95OSIxka9SsAUBHQ2Ghxko=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G2RmHfn0MO0PGa6VLMXF/YJmu7FxVB7NAe0VNeoPIs28Nug+9PDMQP4przV7NQcL355GHUrRGzMQY6YUKJ7t7PtmZrEijl6PpaPJa4xHux07b4qj8P5vdvNodJZfjuELWAtX0aCUvU66Fqcpq2oBn3gF8E180B1HC4QElLMCk7k= 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=BbH/5zJG; 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="BbH/5zJG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791633; 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=jtnVyGCllOzCsvYTHj412veayAw36T4Mk750trb6Njs=; b=BbH/5zJGi2AoTj1WJXPSVRvnEKll5A5tyj/pA/Ki/J6bFrUkMfxtF/nlFBUxJwDuVg6UZ+ 4KedPwNT3ZmLhifkN/6rVpvaIpTT1oWMt5VDwuKImnb+1/7Tj3jWFKP855jf8hjl8DCzYp 7lMajxLB9cbYEYJTIYaMO4To2jgnf9k= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-HPKtw0OaP6mHrdqRF2XsXA-1; Tue, 05 Nov 2024 02:27:12 -0500 X-MC-Unique: HPKtw0OaP6mHrdqRF2XsXA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8D8D01955F43; Tue, 5 Nov 2024 07:27:11 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90EAA195607C; Tue, 5 Nov 2024 07:27:06 +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 v3 2/9] vhost: Add the vhost_worker to support kthread Date: Tue, 5 Nov 2024 15:25:21 +0800 Message-ID: <20241105072642.898710-3-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Add the previously removed function vhost_worker() back to support the kthread and rename it to vhost_run_work_kthread_list. The old function vhost_worker was change to support task in commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads") change to xarray in commit 1cdaafa1b8b4 ("vhost: replace single worker pointer with xarray") Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index eff6acbbb63b..65fda810b96e 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -389,6 +389,44 @@ static void vhost_vq_reset(struct vhost_dev *dev, __vhost_vq_meta_reset(vq); } +static int vhost_run_work_kthread_list(void *data) +{ + struct vhost_worker *worker = data; + struct vhost_work *work, *work_next; + struct vhost_dev *dev = worker->dev; + struct llist_node *node; + + kthread_use_mm(dev->mm); + + for (;;) { + /* mb paired w/ kthread_stop */ + set_current_state(TASK_INTERRUPTIBLE); + + if (kthread_should_stop()) { + __set_current_state(TASK_RUNNING); + break; + } + node = llist_del_all(&worker->work_list); + if (!node) + schedule(); + + node = llist_reverse_order(node); + /* make sure flag is seen after deletion */ + smp_wmb(); + llist_for_each_entry_safe(work, work_next, node, node) { + clear_bit(VHOST_WORK_QUEUED, &work->flags); + __set_current_state(TASK_RUNNING); + kcov_remote_start_common(worker->kcov_handle); + work->fn(work); + kcov_remote_stop(); + cond_resched(); + } + } + kthread_unuse_mm(dev->mm); + + return 0; +} + static bool vhost_run_work_list(void *data) { struct vhost_worker *worker = data; From patchwork Tue Nov 5 07:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862590 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 149221FF034 for ; Tue, 5 Nov 2024 07:27:19 +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=1730791641; cv=none; b=vB6qVjafsz3mEHtHw0L9lpRfAKAsniiA+EiLmn9mZePsbhSrGoKk8NFZ1IPZ7zum0mJ0/nuX0P8T3Z85KwmUu+OiL9+xp0eB5C2GYEAhgqwyG1s0o602H5/jUNVhEcrmHwKUK/tF9+oZsnHq+UNmtyN2YzBlIPiedA1heV/LM6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791641; c=relaxed/simple; bh=4BZv/MSpj7iSNmvTqGiuUDrWylQi+HmCE3W6Csgy4G4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lxPK7Z4LHPT4IBDDYzaZfcoRJXmgQBXpSXVAz+zKLAUK/p97f6wuUKztmuFQ5TqPcSqt+J7d1ZJnsVRO9ytwtZTn8FjSbgjNM8G+bE7++i7V/uJTpsHNipxJlj7CWAKIHKC6GlhCPt/z5twKVujHZCE4+HtXQXXVITxpfGlDtpo= 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=IqoMF5mg; 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="IqoMF5mg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791638; 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=Er4Ja48W1bnY3o91mhLUdl719OPZOQTArQmrqwY2GbM=; b=IqoMF5mgW9g6jE04jmL8ZBJlFdtEb2bai/KOzHRvgKY03Y2BdiQpPhFbpPX6/60zDKmDRD uy31b5svtdrRsnKdZYxm6kbZjAdPGzYu61BkjOaZEfPe5vXIGw9qQ3A/6FhzkGadOGw/44 thU5pirzSNxrt0c2wb0alYwKb5PzF+o= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81-u8xPnHuIN3K3aXI64mQ62g-1; Tue, 05 Nov 2024 02:27:17 -0500 X-MC-Unique: u8xPnHuIN3K3aXI64mQ62g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5EBC1955EA7; Tue, 5 Nov 2024 07:27:16 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 623591956086; Tue, 5 Nov 2024 07:27:11 +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 v3 3/9] vhost: Add the cgroup related function Date: Tue, 5 Nov 2024 15:25:22 +0800 Message-ID: <20241105072642.898710-4-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Add back the previously removed cgroup function to support the kthread The biggest change for this part is in vhost_attach_cgroups() and vhost_worker_cgroups_kthread(). This is because of the change in struct dev->worker_xa. The old function was remove in commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads") Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 65fda810b96e..e40cef3a1fa5 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -621,6 +622,57 @@ long vhost_dev_check_owner(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_dev_check_owner); +struct vhost_attach_cgroups_struct { + struct vhost_work work; + struct task_struct *owner; + int ret; +}; + +static void vhost_attach_cgroups_work(struct vhost_work *work) +{ + struct vhost_attach_cgroups_struct *s; + + s = container_of(work, struct vhost_attach_cgroups_struct, work); + s->ret = cgroup_attach_task_all(s->owner, current); +} + +static int vhost_worker_cgroups_kthread(struct vhost_worker *worker) +{ + struct vhost_flush_struct flush; + struct vhost_attach_cgroups_struct attach; + + attach.owner = current; + + vhost_work_init(&attach.work, vhost_attach_cgroups_work); + vhost_worker_queue(worker, &attach.work); + + init_completion(&flush.wait_event); + vhost_work_init(&flush.work, vhost_flush_work); + vhost_worker_queue(worker, &flush.work); + wait_for_completion(&flush.wait_event); + + return attach.ret; +} + +static int vhost_attach_cgroups(struct vhost_dev *dev) +{ + struct vhost_worker *worker; + unsigned long i; + int ret; + + /* + * Free the default worker we created and cleanup workers userspace + * created but couldn't clean up (it forgot or crashed). + */ + + xa_for_each(&dev->worker_xa, i, worker) { + ret = vhost_worker_cgroups_kthread(worker); + if (ret) + return ret; + } + return ret; +} + /* Caller should have device mutex */ bool vhost_dev_has_owner(struct vhost_dev *dev) { From patchwork Tue Nov 5 07:25:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862591 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 B6B961FDF95 for ; Tue, 5 Nov 2024 07:27:49 +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=1730791671; cv=none; b=iiq193x72oelrFCpOBi65EdAhbWG0OutpLHoXCuMg7snZdbkp1szPVvdG4VCBybYuJZocDyVO9df4srd523fAHs6lXExZyQply06C91T7I8xLvrv8nq3GWFeVFgL2HDLy3I03C+vFd6a2ly/+5jN6qLKRMiBQb1dVwh52hmT29U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791671; c=relaxed/simple; bh=px/d7GxNDVWjUeXbE2siNdRGmuGHmt+Dj/2C3sOfk6E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hxa0N4zKoJrSjgy++RE98XQJJMfRBvu4r6Yx6FGYc+UH00Yp/WDQbt3TXQnM0rSnXE3QcG7W8HOkaAuJJQ1hMmguiRldnnL3s2H/KbVkV9Nu6WsuN3Wqr+CcRBpM4Ibu1cAznXKEUEjhj4htkhVzdeCbZLOsKDgL70RMxhppAoQ= 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=ghCjANkL; 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="ghCjANkL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791668; 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=SZXrpm6Hjv9R5RedbyYefAVChV5g9ZLlA5EfzIRNc4s=; b=ghCjANkLACDTehsBDtRhB0Me2suBMPtIPw8Mibue6ZMY6Du9Mzw8pz+Oy3SJItf6BD9Gdt X/WlHeSzUBT9fkwmb4fcin8vWPVUXQBPqgjywytcmeQVh969riKYnSajbKDeZcMlsQz0XO pDUMQVkxMYVqmR6SLiyio9jVxGd6i3s= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-irnbstHlPvKijBtIh1Pthg-1; Tue, 05 Nov 2024 02:27:45 -0500 X-MC-Unique: irnbstHlPvKijBtIh1Pthg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 928681956048; Tue, 5 Nov 2024 07:27:44 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DDEEE1956086; Tue, 5 Nov 2024 07:27:39 +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 v3 4/9] vhost: Add kthread support in function vhost_worker_create Date: Tue, 5 Nov 2024 15:25:23 +0800 Message-ID: <20241105072642.898710-5-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Restored the previous functions kthread_wakeup and kthread_stop. Also add a new structure, vhost_task_fn. The function vhost_worker_create Will initializes this structure based on the value of inherit_owner. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 71 ++++++++++++++++++++++++++++++++++++------- drivers/vhost/vhost.h | 6 ++++ 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index e40cef3a1fa5..603b146fccc1 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -741,43 +741,92 @@ static void vhost_workers_free(struct vhost_dev *dev) xa_destroy(&dev->worker_xa); } +static int vhost_task_wakeup_fn(void *vtsk) +{ + vhost_task_wake((struct vhost_task *)vtsk); + return 0; +} +static int vhost_kthread_wakeup_fn(void *p) +{ + return wake_up_process((struct task_struct *)p); +} +static int vhost_task_stop_fn(void *vtsk) +{ + vhost_task_stop((struct vhost_task *)vtsk); + return 0; +} +static int vhost_kthread_stop_fn(void *k) +{ + return kthread_stop((struct task_struct *)k); +} + static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; - struct vhost_task *vtsk; + struct vhost_task *vtsk = NULL; + struct task_struct *task = NULL; char name[TASK_COMM_LEN]; int ret; u32 id; + /* Allocate resources for the worker */ worker = kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); if (!worker) return NULL; + worker->fn = kzalloc(sizeof(struct vhost_task_fn), GFP_KERNEL_ACCOUNT); + if (!worker->fn) { + kfree(worker); + return NULL; + } + worker->dev = dev; snprintf(name, sizeof(name), "vhost-%d", current->pid); - vtsk = vhost_task_create(vhost_run_work_list, vhost_worker_killed, - worker, name); - if (!vtsk) - goto free_worker; - mutex_init(&worker->mutex); init_llist_head(&worker->work_list); worker->kcov_handle = kcov_common_handle(); - worker->vtsk = vtsk; - vhost_task_start(vtsk); + if (dev->inherit_owner) { + /* Create and start a vhost task */ + vtsk = vhost_task_create(vhost_run_work_list, + vhost_worker_killed, worker, name); + if (!vtsk) + goto free_worker; + + worker->vtsk = vtsk; + worker->fn->wakeup = vhost_task_wakeup_fn; + worker->fn->stop = vhost_task_stop_fn; + + vhost_task_start(vtsk); + } else { + /* Create and start a kernel thread */ + task = kthread_create(vhost_run_work_kthread_list, worker, + "vhost-%d", current->pid); + if (IS_ERR(task)) { + ret = PTR_ERR(task); + goto free_worker; + } + worker->task = task; + worker->fn->wakeup = vhost_kthread_wakeup_fn; + worker->fn->stop = vhost_kthread_stop_fn; + + wake_up_process(task); + /* Attach to the vhost cgroup */ + ret = vhost_attach_cgroups(dev); + if (ret) + goto stop_worker; + } ret = xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, GFP_KERNEL); if (ret < 0) goto stop_worker; worker->id = id; - return worker; - stop_worker: - vhost_task_stop(vtsk); + worker->fn->stop(dev->inherit_owner ? (void *)vtsk : (void *)task); free_worker: + kfree(worker->fn); kfree(worker); return NULL; } diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index c650c4506c70..ebababa4e340 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -25,8 +25,13 @@ struct vhost_work { vhost_work_fn_t fn; unsigned long flags; }; +struct vhost_task_fn { + int (*wakeup)(void *task); + int (*stop)(void *task); +}; struct vhost_worker { + struct task_struct *task; struct vhost_task *vtsk; struct vhost_dev *dev; /* Used to serialize device wide flushing with worker swapping. */ @@ -36,6 +41,7 @@ struct vhost_worker { u32 id; int attachment_cnt; bool killed; + struct vhost_task_fn *fn; }; /* Poll a file (eventfd or socket) */ From patchwork Tue Nov 5 07:25:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862592 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 4137D1FEFC9 for ; Tue, 5 Nov 2024 07:27:53 +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=1730791674; cv=none; b=tD1QiPeAbMLeCy6x5N0261vzpBj3h2Qe0t1B9A+zsyShv/yD8cr9RGVbUk0XioY1pb7EqSlQnhr4T5e31G+xWSIAoisAyuzdthleiBq4EY7upHO+PLHtWu7fZXXr2p0WzCHFQxHDR3ieDjfpBTdWC0XVGT/zA3UzibLxQOSDqek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791674; c=relaxed/simple; bh=+38GjQ5iNed2+14XtChEVV9Ul7oBJUOLzQdRTNmOgpQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u4N3oVCKAp4rPItG7p9pLM+naUp4jG63rBagUMT2RWPKZ5MGMj2+OMw5uhLU+pshsAH/v7ilbxcP65ooSB1vvVpXBP/wu4FSHhzAqBhpr3230l0lqdQinVpHd4r+6kDAy7j8hfTwDfavl6rnpkgxofTCXtDEXV6Vi5fMEmgK/J4= 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=GC8ibTWI; 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="GC8ibTWI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791672; 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=pPknO6DVyO1LjLhZHYo5oROtWHiUqkzRt9HMN0ycP2A=; b=GC8ibTWIO5A3lCaIHQ9yp2HgewmiHsg3PrzSz3ADoKzZYd4NR0qxG+//U23tNS7ArTLIYZ CzkTbL+M4ph8hWTRirWIFQSpZpUW1zg+sMfbU90hdfLrpTeM/dokhGUcsfz4795xIGdHsW 6Wqe4c83i3e4asn6Cjf1dvGTP8fbpRc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-17-18RcnFfyPAuvZxSF-A6PBg-1; Tue, 05 Nov 2024 02:27:50 -0500 X-MC-Unique: 18RcnFfyPAuvZxSF-A6PBg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B6BC719560A2; Tue, 5 Nov 2024 07:27:49 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 64CC91956086; Tue, 5 Nov 2024 07:27:44 +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 v3 5/9] vhost: Add kthread support in function vhost_worker_queue() Date: Tue, 5 Nov 2024 15:25:24 +0800 Message-ID: <20241105072642.898710-6-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 The function vhost_worker_queue() uses vhost_task_fn and selects the different mode based on the value of inherit_owner. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 603b146fccc1..8b7ddfb33c61 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -238,13 +238,18 @@ EXPORT_SYMBOL_GPL(vhost_poll_stop); static void vhost_worker_queue(struct vhost_worker *worker, struct vhost_work *work) { + if (!worker && !worker->fn) + return; + if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) { /* We can only add the work to the list after we're * sure it was not in the list. * test_and_set_bit() implies a memory barrier. */ llist_add(&work->node, &worker->work_list); - vhost_task_wake(worker->vtsk); + worker->fn->wakeup(worker->dev->inherit_owner ? + (void *)worker->vtsk : + (void *)worker->task); } } From patchwork Tue Nov 5 07:25:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862593 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 B85BE1FF7C8 for ; Tue, 5 Nov 2024 07:28:00 +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=1730791682; cv=none; b=YFi71q+CoRpqhsClAUeofjolqHk7Ta0SLrSIBk2MApjZ8rK6VgiqdYUZOcLlRKvopRbSoD6naqevD8cBIw5nd2Bhr8mQaoJIhOnUgUe2w+5/bn0o4pbzkXKlfUzcWbDpYgPNrdMqsMoCW+v3l7ZZ6Kl6c3elXcopRWRkvGd3uLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791682; c=relaxed/simple; bh=M49i9Z80LvRN1KH00nCqmQiLAV5d1TcbHzx3zh4khGU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qcv7jA0mijoqyPD1q2GHGzgXyYX4igHTUf0teh0NMslsL6U31zvd6JkleCljp2Mn11Ak8irvJvr/NPQJI4TkUb/OFcokg8VO+SrE+ex+jb9RkKPEEpCu9FTD21Ddm3DCz27IcXio/Ghl1e7k5s3l01GLXONe+tgKTzrveknwC8w= 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=hvEb9Lbu; 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="hvEb9Lbu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791679; 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=1m4NUSQOwh8h3S2yfP06X/nb4pg21Jt9eMtwUyyXqBQ=; b=hvEb9LbuYa6PsyJRfKycrFF43B6eG9+kY9jde3HGDXdvqVB51o3RBPLFSDoDRvFFbXuuZj oHwRYykoFxbA/MuXYYSrgzZA1IceSWV2IiP7D2PELy10C55euWf1XSrzj+KBig2jJ+uPjP DfUZURD75CUiml2QspTQWT+fxEBD+8A= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-p_ZQeHAjNgOwXe-RNXUbxQ-1; Tue, 05 Nov 2024 02:27:56 -0500 X-MC-Unique: p_ZQeHAjNgOwXe-RNXUbxQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DCC5519560AB; Tue, 5 Nov 2024 07:27:54 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B52F1956086; Tue, 5 Nov 2024 07:27:50 +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 v3 6/9] vhost: Add kthread support in function vhost_worker_destroy() Date: Tue, 5 Nov 2024 15:25:25 +0800 Message-ID: <20241105072642.898710-7-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 The function vhost_worker_destroy() will use struct vhost_task_fn and selects the different mode based on the value of inherit_owner. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 8b7ddfb33c61..c17dc01febcc 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -718,12 +718,14 @@ static void vhost_detach_mm(struct vhost_dev *dev) static void vhost_worker_destroy(struct vhost_dev *dev, struct vhost_worker *worker) { - if (!worker) + if (!worker && !worker->fn) return; WARN_ON(!llist_empty(&worker->work_list)); xa_erase(&dev->worker_xa, worker->id); - vhost_task_stop(worker->vtsk); + worker->fn->stop(dev->inherit_owner ? (void *)worker->vtsk : + (void *)worker->task); + kfree(worker->fn); kfree(worker); } From patchwork Tue Nov 5 07:25:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862594 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 396B320011B for ; Tue, 5 Nov 2024 07:28:03 +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=1730791684; cv=none; b=PW6I3YIhCp7dfBTm3fRpPyqsfwgQw/hkcJafgUuQk2K7sQjeAk67R/G3/yZ1LNyqb6xWOXYuEIUnsHExvcAWQXh/ki8L6EIhbofmi1ygj0f9/QPT55450gUypN30Cd0z7uZWTa9BEpe+ZB2phs+3RC/JeKGlg3FnGw92yfwlRzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791684; c=relaxed/simple; bh=0QdkBtKjMzdIS7SqrchG9JRhfPNterDTSKj/TM/P8mg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gIJ0//UQhAAdPqiNW4yCLRPZUw2OfdpCGfVtIRz2zyEyOpXPitSsjb/oV25sXdrc0dN9qID2om9R92BV8qhofJJf+xdth651QIJinCkKDuW8Kc0j5u5oGYq0lmRImM+qlF+ApiZvjEYiCYLPvp3dyiUuoJyhFOwhDCN/P8lqlJE= 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=ecw4q0wg; 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="ecw4q0wg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791682; 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=b9eokZY2fqQ9vuKBZvQW4V7mmsdAb7yocXzqh175Di8=; b=ecw4q0wgA3NbuLTVIZZIAG9/iYItk/6yzKFAJcD+GFYhjM5QDLbUTGWmQIGCkuuTVCaH/U +GvF3sqgi3FK8NX11khoEErrS9nGp1sES8b0gbJ+UJG8KxuOYU5/fHX9ZQ8zi8dO1b4eRW zvUe+69MBpciiNNiNIJb/j0c22G+wM0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-drmJyLkFOAOKSnWYvp1LDA-1; Tue, 05 Nov 2024 02:28:01 -0500 X-MC-Unique: drmJyLkFOAOKSnWYvp1LDA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2C58C1955EE6; Tue, 5 Nov 2024 07:28:00 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B15971956086; Tue, 5 Nov 2024 07:27:55 +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 v3 7/9] vhost: Add new UAPI to support change to task mode Date: Tue, 5 Nov 2024 15:25:26 +0800 Message-ID: <20241105072642.898710-8-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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 | 15 ++++++++++++++- include/uapi/linux/vhost.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c17dc01febcc..70c793b63905 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2274,8 +2274,9 @@ 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; + bool inherit_owner; /* If you are not the owner, you can become one */ if (ioctl == VHOST_SET_OWNER) { @@ -2332,6 +2333,18 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) if (ctx) eventfd_ctx_put(ctx); break; + case VHOST_SET_INHERIT_FROM_OWNER: + /*inherit_owner can only be modified before owner is set*/ + if (vhost_dev_has_owner(d)) + break; + + if (copy_from_user(&inherit_owner, argp, + sizeof(inherit_owner))) { + r = -EFAULT; + break; + } + d->inherit_owner = inherit_owner; + break; default: r = -ENOIOCTLCMD; break; diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index b95dd84eef2d..1e192038633d 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -235,4 +235,6 @@ */ #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ struct vhost_vring_state) + +#define VHOST_SET_INHERIT_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, bool) #endif From patchwork Tue Nov 5 07:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862595 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 B081C1FE10C for ; Tue, 5 Nov 2024 07:28:32 +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=1730791714; cv=none; b=k+8EKPseQjlR+7Kq1w+Xvq0MxOb8/SWDTsi7XvaoW+U7ZETwPsDoC1ALj2m3d1k9pw9Ht+9cSdOhX5Elcm4tUOan9SeeRahco4W2Ufm7DzWxSIpm+vG8bA0/xM5C4m4HiP1AOWvUWlKSElSkPFbAMfMrQ5eIiPsN8h4HXSQT2/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791714; c=relaxed/simple; bh=MX5FZQA4EmsLL2pOoIXNJm9EOZkEs7x6Q7BAjrZW4D4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dHJ6ofPku7JR/sKmBI9QM/RD2HubrJJt93DnLx+g9n+WVBaLwAAWC5tbWCKRNcnC6z8XQdhHkP+/ofLhf16Diup2QqDtiTHgpdDmjek+KNbj3E0yagpFZd8ipukuQfxlWpBD1JUFAgFzei/mHfn9wMzdFQJcRAk9xA2f7ZHhOh0= 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=UW+mkX5g; 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="UW+mkX5g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791711; 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=waOIJYR/uf8lM72gcE+nfFRZp8HYpeFxyDV384TmS5E=; b=UW+mkX5gKp13qtB//km6gwi1pl/sXu8tZITIZ3Pchm5Ctk8+9/rsh5o2/+4bXBveoN+C61 rNKljNknM5GSWbDtWcIpygHBdQVBnusrv4lXF12znJj/neMo1qcxhZl1Ju/hBkv9qkGd1d p9IjsrolyikmSrSvI6LP2vBFc/OaYuc= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-JVDKDcsiOTSUpOOxeo5f5g-1; Tue, 05 Nov 2024 02:28:28 -0500 X-MC-Unique: JVDKDcsiOTSUpOOxeo5f5g-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A897C1955EAA; Tue, 5 Nov 2024 07:28:27 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 00BD119560A3; Tue, 5 Nov 2024 07:28:22 +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 v3 8/9] vhost_scsi: Add check for inherit_owner status Date: Tue, 5 Nov 2024 15:25:27 +0800 Message-ID: <20241105072642.898710-9-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 The vhost_scsi VHOST_NEW_WORKER requires the inherit_owner setting to be true. So we need to implement a check for this. Signed-off-by: Cindy Lu --- drivers/vhost/scsi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 006ffacf1c56..05290298b5ab 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -2083,6 +2083,11 @@ vhost_scsi_ioctl(struct file *f, return -EFAULT; return vhost_scsi_set_features(vs, features); case VHOST_NEW_WORKER: + /*vhost-scsi VHOST_NEW_WORKER requires inherit_owner to be true*/ + if (vs->dev.inherit_owner != true) + return -EFAULT; + + fallthrough; case VHOST_FREE_WORKER: case VHOST_ATTACH_VRING_WORKER: case VHOST_GET_VRING_WORKER: From patchwork Tue Nov 5 07:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13862596 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 DE5672003B3 for ; Tue, 5 Nov 2024 07:28:37 +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=1730791719; cv=none; b=VHo07rG2CQNZ8ZiuI6fTuU9ajYp0IOuL0NeP0nfatLn/PXFXtt/DD+nT7An5r3XCygfwo/k0fl79+Jr2TmqPAEJUQ47mYHAUbv0maB8zZrvtbW91xMjw8xBSIwoNJbgK5Uu+3m4IuuBXzNul2onXRLMT2nHs9lrnTnBZmFiBzhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791719; c=relaxed/simple; bh=vJGsOnLSVbNs9zEE3Y9TV4PsmII2ryUMx1W/w1V1sgo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rSvLDGxrVM9x9Oe6+eoSlBUCnJGPZ4JTZaA09D1LPGtfaTGclxvRZWcNvDMUzlnaMuUV2F/DOSC3DTCCxMYIHiTxcydy/zv8qgwD1ITb92ZQrRbZqhK7H5vlEzAClk4GxEyZ+ENUrm7vqmgxm/D0swBO86mUkhg2D0El5WRNqcY= 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=KroNaPbJ; 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="KroNaPbJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791717; 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=taXN/BByVA3oeUwccMMIwwKlQcWqxPtqO9YY/m4NEgM=; b=KroNaPbJ/0vNf4plqZ2pDVdHFRBzemiEjZBj2NMl1dHq/d/ISd/xjEGAgbGQtT0Yxm5l5C FBsYs2ztAmO2dMej9B5eyHf/RWCdgHs9IdfjyLc0NOiz8v8sa/Gb6txi6BwGdXWkaRZQ0h EfGtJLXUSb47He8MsRjr58oXGjm4DY0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-435-AAOEehLKPrGIGDel1AAU2Q-1; Tue, 05 Nov 2024 02:28:33 -0500 X-MC-Unique: AAOEehLKPrGIGDel1AAU2Q-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C46FB1955EAB; Tue, 5 Nov 2024 07:28:32 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D39019560A3; Tue, 5 Nov 2024 07:28:28 +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 v3 9/9] vhost: Expose the modparam inherit_owner_default Date: Tue, 5 Nov 2024 15:25:28 +0800 Message-ID: <20241105072642.898710-10-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Expose the inherit_owner_default modparam by module_param(). Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 70c793b63905..1a4ccf4f7316 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -43,6 +43,9 @@ module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries. (default: 2048)"); static bool inherit_owner_default = true; +module_param(inherit_owner_default, bool, 0444); +MODULE_PARM_DESC(inherit_owner_default, + "Set vhost_task mode as the default(default: Y)"); enum { VHOST_MEMORY_F_LOG = 0x1,