Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 212B41B0412 for ; Mon, 30 Dec 2024 12:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562714; cv=none; b=bwJ4Pe8/KuBSbvv8+6uuP33Br+QXRdK8vEAp0KvkrGk4KxYmI+9DcDfjoIiy4c8u0E32MST/cAfNalJZeoDqmTC2DJ7sUq7AX0rJPRsPP7AgLaRjv7Myp6Qv4HlbEcV6bGZ6J/UWpA89AiRZBQllPj6r36pXBGqFD/gssuubyd0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562714; c=relaxed/simple; bh=zJ7gQ1kSqCdMUp9Tx832EuPhAuNPPcp41jJMW9X3QaE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aT2Dj8SVup8iK4sWUp59ht15WJ/YIkF522J/XStqw01hhx6b6wP/AHJELrfRY4uOcdQTqsMY1UGd53DTGjT+TRZg6ac533am3IAS3h2O4prO3P0nDNITexgOHRrZnA0/Pz3vZEDnfst8ClnQV+M9f2aeJbEb6UMwiyoRu8mL1oY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Kcq/cY5Z; arc=none smtp.client-ip=140.211.166.133 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Kcq/cY5Z" Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id A0BDD40B27 for ; Mon, 30 Dec 2024 12:45:12 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -5.793 X-Spam-Level: Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id dK0Lo_qlAHHN for ; Mon, 30 Dec 2024 12:45:12 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=lulu@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org BC45D400D0 Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org BC45D400D0 Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Kcq/cY5Z Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id BC45D400D0 for ; Mon, 30 Dec 2024 12:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562710; 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=QDGpQBYYbqEvdCGufJQtc26EbONqPNkQa5s9LCtzmcU=; b=Kcq/cY5Z6C7Eo6gFYmIjApNpHuzR9e8ge/I+UcwF4shLVL+2KVbsjunZ2k1jC56CLizPXF jVH9TTT1hMsD/IuMJpRxPbQm7RpoLf4psxwfxdDEoUqMT7zgSp7basondwPDIQgtFqmtAf UZDmvq3NxZgdkvPuu6qMdIUlt6L1XSs= 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-594-_PZL29MePRm7ojIGFhQoiQ-1; Mon, 30 Dec 2024 07:45:09 -0500 X-MC-Unique: _PZL29MePRm7ojIGFhQoiQ-1 X-Mimecast-MFC-AGG-ID: _PZL29MePRm7ojIGFhQoiQ 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2CE7319560BE; Mon, 30 Dec 2024 12:45:08 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 46C361956053; Mon, 30 Dec 2024 12:45:03 +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 v5 2/6] vhost: Add the vhost_worker to support kthread Date: Mon, 30 Dec 2024 20:43:49 +0800 Message-ID: <20241230124445.1850997-3-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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 changed to support tasks in commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads") and to support multiple workers per device using 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 eaddbd39c29b..1feba29abf95 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -388,6 +388,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; -- 2.45.0