From patchwork Mon Oct 17 07:14:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Changpeng" X-Patchwork-Id: 118242 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 676D0A0556; Mon, 17 Oct 2022 09:15:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 00D5B40143; Mon, 17 Oct 2022 09:15:15 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 2872F400D7 for ; Mon, 17 Oct 2022 09:15:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665990913; x=1697526913; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jn2AqdptVTD/lH656vBR4mGhcpvPEGf+Y4o/E8UhmDE=; b=C+H20wdsElSl0vn3ICun7B4h3uC6+m9bRjdEmHYGnLKhtm5EBk5DPzWy Gk4+wKgle8m6sTMlTdeCAHXdDqzP2mm15WRCHbu+C2txjaNKDKPSGTGSq YFDg+FTBPRyk80Xyi4ILu0jxTJKoKA2rvcEAArSfGqjlz4s+ntcg+eTwq u/cvxl8fKr/IOYBQPKTe+AijaZrgQ0/vV1koGxgbwzRcaD2olA+KV/cl6 wbQEyMImDQ03XmHcBjMKyAmcYHiGGJ/iNCdiCRYJ9hJ9Zhcf9DEiEKjG6 6bKQfYcO4KjgrtrvfuhEMGbpQHp9BTpI20dd2KARcZ0ouShzLtRYl/b5N A==; X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="289016484" X-IronPort-AV: E=Sophos;i="5.95,190,1661842800"; d="scan'208";a="289016484" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2022 00:15:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10502"; a="770665128" X-IronPort-AV: E=Sophos;i="5.95,190,1661842800"; d="scan'208";a="770665128" Received: from waikikibeach52.sh.intel.com ([10.67.111.175]) by fmsmga001.fm.intel.com with ESMTP; 17 Oct 2022 00:15:10 -0700 From: Changpeng Liu To: dev@dpdk.org Cc: Changpeng Liu , Maxime Coquelin , Chenbo Xia , David Marchand Subject: [PATCH v3] vhost: add new `rte_vhost_vring_call_nonblock` API Date: Mon, 17 Oct 2022 15:14:57 +0800 Message-Id: <20221017071457.28589-1-changpeng.liu@intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20221012064007.56040-1-changpeng.liu@intel.com> References: <20221012064007.56040-1-changpeng.liu@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Vhost-user library locks all VQ's access lock when processing vring based messages, such as SET_VRING_KICK and SET_VRING_CALL, and the data processing thread may already be started, e.g: SPDK vhost-blk and vhost-scsi will start the data processing thread when one vring is ready, then deadlock may happen when SPDK is posting interrupts to VM. Here, we add a new API which allows caller to try again later for this case. Bugzilla ID: 1015 Fixes: c5736998305d ("vhost: fix missing virtqueue lock protection") Signed-off-by: Changpeng Liu --- doc/guides/prog_guide/vhost_lib.rst | 6 ++++++ doc/guides/rel_notes/release_22_11.rst | 6 ++++++ lib/vhost/rte_vhost.h | 15 +++++++++++++ lib/vhost/version.map | 3 +++ lib/vhost/vhost.c | 30 ++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst index bad4d819e1..52f0589f51 100644 --- a/doc/guides/prog_guide/vhost_lib.rst +++ b/doc/guides/prog_guide/vhost_lib.rst @@ -297,6 +297,12 @@ The following is an overview of some key Vhost API functions: Clear in-flight packets which are submitted to async channel in vhost async data path. Completed packets are returned to applications through ``pkts``. +* ``rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)`` + + Notify the guest that used descriptors have been added to the vring. This function + will return -EAGAIN when vq's access lock is held by other thread, user should try + again later. + * ``rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id, struct rte_vhost_stat_name *names, unsigned int size)`` This function returns the names of the queue statistics. It requires diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst index 2da8bc9661..9b3783ffd8 100644 --- a/doc/guides/rel_notes/release_22_11.rst +++ b/doc/guides/rel_notes/release_22_11.rst @@ -236,6 +236,12 @@ New Features strings $dpdk_binary_or_driver | sed -n 's/^PMD_INFO_STRING= //p' +* **Added non-block notify API to the vhost library.** + + Added API to notify the guest that used descriptors have been added + to the vring in non-block way, user should check the return value of + this API. + Removed Items ------------- diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h index bb7d86a432..d22b25cd4e 100644 --- a/lib/vhost/rte_vhost.h +++ b/lib/vhost/rte_vhost.h @@ -909,6 +909,21 @@ rte_vhost_clr_inflight_desc_packed(int vid, uint16_t vring_idx, */ int rte_vhost_vring_call(int vid, uint16_t vring_idx); +/** + * Notify the guest that used descriptors have been added to the vring. This + * function acts as a memory barrier. This function will return -EAGAIN when + * vq's access lock is held by other thread, user should try again later. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @return + * 0 on success, -1 on failure, -EAGAIN for another retry + */ +__rte_experimental +int rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx); + /** * Get vhost RX queue avail count. * diff --git a/lib/vhost/version.map b/lib/vhost/version.map index 7a00b65740..c8c44b8326 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map @@ -94,6 +94,9 @@ EXPERIMENTAL { rte_vhost_async_try_dequeue_burst; rte_vhost_driver_get_vdpa_dev_type; rte_vhost_clear_queue; + + # added in 22.11 + rte_vhost_vring_call_nonblock; }; INTERNAL { diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 8740aa2788..ed6efb003f 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1317,6 +1317,36 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) return 0; } +int +rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx) +{ + struct virtio_net *dev; + struct vhost_virtqueue *vq; + + dev = get_device(vid); + if (!dev) + return -1; + + if (vring_idx >= VHOST_MAX_VRING) + return -1; + + vq = dev->virtqueue[vring_idx]; + if (!vq) + return -1; + + if (!rte_spinlock_trylock(&vq->access_lock)) + return -EAGAIN; + + if (vq_is_packed(dev)) + vhost_vring_call_packed(dev, vq); + else + vhost_vring_call_split(dev, vq); + + rte_spinlock_unlock(&vq->access_lock); + + return 0; +} + uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) {