From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03326C07E95 for ; Wed, 7 Jul 2021 10:30:20 +0000 (UTC) Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by mail.kernel.org (Postfix) with ESMTP id 8E08D61CC5 for ; Wed, 7 Jul 2021 10:30:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E08D61CC5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E59BE406FF; Wed, 7 Jul 2021 12:30:18 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 601D3406B4 for ; Wed, 7 Jul 2021 12:30:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625653816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tBlROgn6I1BJYl5QGMgnM0WMUIBspw6EoK3D14BF2BY=; b=jE1P95gPZy0aUrQ332tg2wKRyjFmZWVgsaCBqbUfH7sWQsHChI0p5Ow0vwOVpI1H3XjTLx EhsTLzUqMtX+4CihGuCFQEFrHDqlTnKZT+c57T3jaswshW+v6rweEuPmZUMbsWXDIzqy/0 lHTwvmyHsqldGNcMJNgl9BZiNevhZE4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-SRjXD4nEMxaXF8VPS9aBQg-1; Wed, 07 Jul 2021 06:30:15 -0400 X-MC-Unique: SRjXD4nEMxaXF8VPS9aBQg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D3A5100CCC3; Wed, 7 Jul 2021 10:30:14 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2E3160BD9; Wed, 7 Jul 2021 10:30:06 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, cheng1.jiang@intel.com, chenbo.xia@intel.com Cc: Maxime Coquelin , stable@dpdk.org Date: Wed, 7 Jul 2021 12:30:04 +0200 Message-Id: <20210707103004.317886-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v2] vhost: fix assuming packed ring size is a power of 2 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 Sender: "dev" Unlike split ring, packed ring does not mandate the ring size to be a power of 2. So we have to use a modulo operation when wrapping ring index. Fixes: 873e8dad6f49 ("vhost: support packed ring in async datapath") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- V2: Also fix wrapping in virtio_dev_rx_async_get_info_idx which is used in the packed ring data path. lib/vhost/virtio_net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index b93482587c..0de5231db7 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1470,7 +1470,7 @@ virtio_dev_rx_async_get_info_idx(uint16_t pkts_idx, uint16_t vq_size, uint16_t n_inflight) { return pkts_idx > n_inflight ? (pkts_idx - n_inflight) : - (vq_size - n_inflight + pkts_idx) & (vq_size - 1); + (vq_size - n_inflight + pkts_idx) % vq_size; } static __rte_always_inline void @@ -2131,7 +2131,7 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, if (vq_is_packed(dev)) { for (i = 0; i < n_pkts_put; i++) { - from = (start_idx + i) & (vq_size - 1); + from = (start_idx + i) % vq_size; n_buffers += pkts_info[from].nr_buffers; pkts[i] = pkts_info[from].mbuf; } -- 2.31.1