From patchwork Thu Oct 13 15:18:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Zhadchenko X-Patchwork-Id: 13006110 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1DEFC4332F for ; Thu, 13 Oct 2022 15:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbiJMPTs (ORCPT ); Thu, 13 Oct 2022 11:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbiJMPTq (ORCPT ); Thu, 13 Oct 2022 11:19:46 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C76ADF4A for ; Thu, 13 Oct 2022 08:19:41 -0700 (PDT) Received: from dev006.ch-qa.sw.ru ([172.29.1.11]) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1oizwM-00B3Aa-V5; Thu, 13 Oct 2022 17:18:57 +0200 From: Andrey Zhadchenko To: virtualization@lists.linux-foundation.org Cc: andrey.zhadchenko@virtuozzo.com, mst@redhat.com, jasonwang@redhat.com, kvm@vger.kernel.org, stefanha@redhat.com, sgarzare@redhat.com, den@virtuozzo.com, ptikhomirov@virtuozzo.com Subject: [RFC PATCH v2 08/10] drivers/vhost: add API to queue work at virtqueue's worker Date: Thu, 13 Oct 2022 18:18:37 +0300 Message-Id: <20221013151839.689700-9-andrey.zhadchenko@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221013151839.689700-1-andrey.zhadchenko@virtuozzo.com> References: <20221013151839.689700-1-andrey.zhadchenko@virtuozzo.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add routines to queue works on virtqueue assigned workers Signed-off-by: Andrey Zhadchenko --- drivers/vhost/vhost.c | 22 ++++++++++++++++++++++ drivers/vhost/vhost.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index d80831d21fba..fbf5fae1a6bf 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -272,6 +272,17 @@ static void vhost_worker_flush(struct vhost_worker *w) wait_for_completion(&flush.wait_event); } +void vhost_work_flush_vq(struct vhost_virtqueue *vq) +{ + struct vhost_worker *w = READ_ONCE(vq->worker); + + if (!w) + return; + + vhost_worker_flush(w); +} +EXPORT_SYMBOL_GPL(vhost_work_flush_vq); + void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) { struct vhost_worker *w = &dev->workers[0]; @@ -283,6 +294,17 @@ void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work) } EXPORT_SYMBOL_GPL(vhost_work_queue); +void vhost_work_vqueue(struct vhost_virtqueue *vq, struct vhost_work *work) +{ + struct vhost_worker *w = READ_ONCE(vq->worker); + + if (!w) + return; + + vhost_work_queue_at_worker(w, work); +} +EXPORT_SYMBOL_GPL(vhost_work_vqueue); + /* A lockless hint for busy polling code to exit the loop */ bool vhost_has_work(struct vhost_dev *dev) { diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index b9a10c85b298..bedf8b9d99de 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -141,6 +141,11 @@ struct vhost_virtqueue { struct vhost_worker *worker; }; +/* Queue the work on virtqueue assigned worker */ +void vhost_work_vqueue(struct vhost_virtqueue *vq, struct vhost_work *work); +/* Flush virtqueue assigned worker */ +void vhost_work_flush_vq(struct vhost_virtqueue *vq); + struct vhost_msg_node { union { struct vhost_msg msg;