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 23C7FA00C3; Thu, 16 Jun 2022 16:38:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CAB9540689; Thu, 16 Jun 2022 16:38:34 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 78C0A40141 for ; Thu, 16 Jun 2022 16:38:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655390313; 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: in-reply-to:in-reply-to:references:references; bh=aEAwGDk+QoNlVKRN4Zw9zKh08Ggeii+5fEKm5CTGyBc=; b=ecO/CADQPZzMzGwYWOzvdbbX60uP2RZaWCiul8naIv3ZNquk7/TSrdbh0Z69XOfgF68L2I fTeNpeFYKOlS34Eg0ZfODa9Lf7lSTUDauTavPCFYDwyJSoGbIVJMILnyCGTYrMpt6R5jPV rczzG4nHeMUiSjZ5NnWrlnBNjRvRt3s= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-513-Pusew-0-OTeP9HzPjsfsig-1; Thu, 16 Jun 2022 10:38:29 -0400 X-MC-Unique: Pusew-0-OTeP9HzPjsfsig-1 Received: by mail-lf1-f71.google.com with SMTP id p36-20020a05651213a400b004779d806c13so874657lfa.10 for ; Thu, 16 Jun 2022 07:38:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aEAwGDk+QoNlVKRN4Zw9zKh08Ggeii+5fEKm5CTGyBc=; b=amTOWwV8Dw4v217ixmRVnpjMoKEsDnoxHFw7kxLw/oHL9vp+GxKu+5QL7Tuy9YCn9E KjxbsMcqP+0MHCtmaXr4+J9D5HOKu2Aqc9tF2swJZJtbfQ79GYg6KHzCriDSt5GIHh5E ATi2C/DOTAxIiiQPr+zr8qQ1PMphiDEYXyIyNUwL/BVZzZoe7452oXnvmmqqgBPcIULe ZCasitFi7rFxBe5/ePEl0GiohY/1LFuz9ge1m+dkrMtlPu6dqQv0BotwsbyDzjETCBij HBt6lAFZW24xGZ/nxx/Tl7fCRo4bepECzTfRS5Vqv5kMh/cDiRzn6/Zyx0irLRrNU1xy 8/Ow== X-Gm-Message-State: AJIora/BQBQiqEKi6StwlSKnPoMn6FCdAhl2KP4cnkUNGwxuKPJidKKf 677cI5so9EIpgRSUM5dQZ6t4ezTYDeOrVVufm6yMinXbRm76UJ+nJhoPRcHm/rrsz+tumVUl9p7 B4OPKEhEDN1NYvs0IlPs= X-Received: by 2002:a05:6512:3130:b0:479:385f:e2ac with SMTP id p16-20020a056512313000b00479385fe2acmr2886209lfd.575.1655390308311; Thu, 16 Jun 2022 07:38:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uLVNw5w3kNgw+qgaamq0QdBnFqgOm/xGcGJo+CtqmKj2fHJu7GUs0KpFvcSq8W6LaxmVWOdJH0i6mbfM14ysI= X-Received: by 2002:a05:6512:3130:b0:479:385f:e2ac with SMTP id p16-20020a056512313000b00479385fe2acmr2886201lfd.575.1655390308094; Thu, 16 Jun 2022 07:38:28 -0700 (PDT) MIME-Version: 1.0 References: <20220407152546.38167-1-xuan.ding@intel.com> <20220516111041.63914-1-xuan.ding@intel.com> <20220516111041.63914-5-xuan.ding@intel.com> In-Reply-To: <20220516111041.63914-5-xuan.ding@intel.com> From: David Marchand Date: Thu, 16 Jun 2022 16:38:17 +0200 Message-ID: Subject: Re: [PATCH v8 4/5] vhost: support async dequeue for split ring To: Xuan Ding Cc: Maxime Coquelin , "Xia, Chenbo" , dev , Jiayu Hu , Cheng Jiang , Sunil Pai G , liangma@liangbit.com, Yuan Wang , "Mcnamara, John" Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" 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 On Mon, May 16, 2022 at 1:16 PM wrote: > +static __rte_always_inline uint16_t > +virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq, > + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count, > + int16_t dma_id, uint16_t vchan_id, bool legacy_ol_flags) > +{ > + static bool allocerr_warned; > + bool dropped = false; > + uint16_t free_entries; > + uint16_t pkt_idx, slot_idx = 0; > + uint16_t nr_done_pkts = 0; > + uint16_t pkt_err = 0; > + uint16_t n_xfer; > + struct vhost_async *async = vq->async; > + struct async_inflight_info *pkts_info = async->pkts_info; > + struct rte_mbuf *pkts_prealloc[MAX_PKT_BURST]; Why do we need this array? Plus, see blow. > + uint16_t pkts_size = count; > + > + /** > + * The ordering between avail index and > + * desc reads needs to be enforced. > + */ > + free_entries = __atomic_load_n(&vq->avail->idx, __ATOMIC_ACQUIRE) - > + vq->last_avail_idx; > + if (free_entries == 0) > + goto out; > + > + rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]); > + > + async_iter_reset(async); > + > + count = RTE_MIN(count, MAX_PKT_BURST); > + count = RTE_MIN(count, free_entries); > + VHOST_LOG_DATA(DEBUG, "(%s) about to dequeue %u buffers\n", > + dev->ifname, count); > + > + if (rte_pktmbuf_alloc_bulk(mbuf_pool, pkts_prealloc, count)) 'count' is provided by the user of the vhost async dequeue public API. There is no check that it is not bigger than MAX_PKT_BURST. Calling rte_pktmbuf_alloc_bulk on a fixed-size array pkts_prealloc, allocated on the stack, it may cause a stack overflow. This code is mostly copy/pasted from the "sync" code. I see a fix on the stats has been sent. I point here another bug. There are probably more... I don't like how async code has been added in the vhost library by Intel. Maxime did a cleanup on the enqueue patch https://patchwork.dpdk.org/project/dpdk/list/?series=20020&state=%2A&archive=both. I see that the recent dequeue path additions have the same method of copying/pasting code and adding some branches in a non systematic way. Please clean this code and stop copy/pasting without a valid reason. -- David Marchand