From patchwork Tue Sep 6 02:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Changpeng" X-Patchwork-Id: 115944 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 228F5A054A; Tue, 6 Sep 2022 04:22:49 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C62AE400D6; Tue, 6 Sep 2022 04:22:48 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 05F5540041 for ; Tue, 6 Sep 2022 04:22:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662430967; x=1693966967; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+MC175JMkeyyKNqVlyzerf/VhCRTb00T53eGcWgygZ0=; b=TW2QxgVntpx/tS1rJBK94whNEwlAXA46aiDwiB2BarihlhV1SDGuWTJr 5QLby+gmgspt9qIZ6IIY5EKezsYSqHrJABMkVfAUHi0biA8CyObJjab9f mtGB88Vba48cx4jmg+4zQJ2deOD4Ums5fdf4vmGYzKpFaXaZFNbU9Biz4 G/Ixi+2CTUJ87tZoKRaSewIedVvtyt8x+Dfkd4UXXnoYNskhWb0JTHcD0 s5aAh80S6nSk/7f3asKoHXIShR7QeheBhfP6xB5+klTwPHM5BoUlxEj3D PBMlqAQBu5ROCXyWWc+GyeU37/Hz5Q9RHKS5E4CCJEZ/Jg2doFMbZrtl+ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10461"; a="382780216" X-IronPort-AV: E=Sophos;i="5.93,292,1654585200"; d="scan'208";a="382780216" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 19:22:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,292,1654585200"; d="scan'208";a="675479632" Received: from waikikibeach52.sh.intel.com ([10.67.111.175]) by fmsmga008.fm.intel.com with ESMTP; 05 Sep 2022 19:22:45 -0700 From: Changpeng Liu To: dev@dpdk.org Cc: Changpeng Liu , Maxime Coquelin , Chenbo Xia Subject: [PATCH] vhost: use try_lock in rte_vhost_vring_call Date: Tue, 6 Sep 2022 10:22:25 +0800 Message-Id: <20220906022225.17215-1-changpeng.liu@intel.com> X-Mailer: git-send-email 2.21.3 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 Note that this function is in data path, so the thread context may not same as socket messages processing context, by using try_lock here, users can have another try in case of VQ's access lock is held by `vhost-events` thread. Signed-off-by: Changpeng Liu --- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 60cb05a0ff..072d2acb7b 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1329,7 +1329,11 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx) if (!vq) return -1; - rte_spinlock_lock(&vq->access_lock); + if (!rte_spinlock_trylock(&vq->access_lock)) { + VHOST_LOG_CONFIG(dev->ifname, DEBUG, + "failed to kick guest, virtqueue busy.\n"); + return -1; + } if (vq_is_packed(dev)) vhost_vring_call_packed(dev, vq);