From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ABD34A0544 for ; Tue, 11 Oct 2022 05:46:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4DC4B42C17; Tue, 11 Oct 2022 05:46:06 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id A5F8D42C10; Tue, 11 Oct 2022 05:46:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665459963; x=1696995963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PK8Z5cVLmH3iZ9nM2Fc4qh46g1r7+nS4iPyvjTgjKmA=; b=DCYTHnXPDwq86QIrzITlq8rG8HgYPdvZUPJW33uKFQdVTXRdfmu4TBjt u0l07Ipul+dmzvdFsF4KIZG8KBYt0Amxu5DcqamidWjN/MakdEcLL2Ipg 7BO0zCM4hRLYEz/h0MaZr4iZgTPYcO56/v1iEIfJwJCJdpka3j2Byg3qE fMLWmOXZlUDDnYvAYSF/LGFpbjfTkjEWsq8AFPFMPMiZG/bqBMoTMpWQT ihf7/OmkmdAYCcV0ARLGTioJpu0DQCg5pGXdxDu690j3d11geyY5BNqpd YhHFtnW2TWkpXoh1scdJYdmA6awlDxMgow2cX4gc9L4od0kFqIv+/Z9iZ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10496"; a="330872925" X-IronPort-AV: E=Sophos;i="5.95,175,1661842800"; d="scan'208";a="330872925" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2022 20:46:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10496"; a="730809843" X-IronPort-AV: E=Sophos;i="5.95,175,1661842800"; d="scan'208";a="730809843" Received: from dpdk_jiangcheng.sh.intel.com ([10.67.118.237]) by fmsmga002.fm.intel.com with ESMTP; 10 Oct 2022 20:46:00 -0700 From: Cheng Jiang To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, xuan.ding@intel.com, wenwux.ma@intel.com, yuanx.wang@intel.com, yvonnex.yang@intel.com, xingguang.he@intel.com, Cheng Jiang , stable@dpdk.org Subject: [PATCH v2 2/2] vhost: fix slot index calculation in async vhost Date: Tue, 11 Oct 2022 03:08:03 +0000 Message-Id: <20221011030803.16746-3-cheng1.jiang@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221011030803.16746-1-cheng1.jiang@intel.com> References: <20220822043126.19340-1-cheng1.jiang@intel.com> <20221011030803.16746-1-cheng1.jiang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org When the packet receiving failure and the DMA ring full occur simultaneously in the asynchronous vhost, the slot_idx needs to be decreased by 1. For packed virtqueue, the slot index should be ring_size - 1, if the slot_idx is currently 0, since the ring size is not necessarily the power of 2. Fixes: 84d5204310d7 ("vhost: support async dequeue for split ring") Fixes: fe8477ebbd94 ("vhost: support async packed ring dequeue") Cc: stable@dpdk.org Signed-off-by: Cheng Jiang --- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 457ac2e92a..efebd063d7 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -3457,6 +3457,7 @@ virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq, allocerr_warned = true; } dropped = true; + slot_idx--; break; } @@ -3647,6 +3648,12 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, if (unlikely(virtio_dev_tx_async_single_packed(dev, vq, mbuf_pool, pkt, slot_idx, legacy_ol_flags))) { rte_pktmbuf_free_bulk(&pkts_prealloc[pkt_idx], count - pkt_idx); + + if (slot_idx == 0) + slot_idx = vq->size - 1; + else + slot_idx--; + break; } @@ -3674,8 +3681,13 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, async->buffer_idx_packed += vq->size - pkt_err; while (pkt_err-- > 0) { - rte_pktmbuf_free(pkts_info[slot_idx % vq->size].mbuf); - slot_idx--; + rte_pktmbuf_free(pkts_info[slot_idx].mbuf); + descs_err += pkts_info[slot_idx].descs; + + if (slot_idx == 0) + slot_idx = vq->size - 1; + else + slot_idx--; } /* recover available ring */ -- 2.35.1