From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk0-f51.google.com (mail-vk0-f51.google.com [209.85.213.51]) by dpdk.org (Postfix) with ESMTP id 544758E5A for ; Sat, 12 Dec 2015 07:55:49 +0100 (CET) Received: by vkha189 with SMTP id a189so128353096vkh.2 for ; Fri, 11 Dec 2015 22:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bigswitch-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5SdOAT1nEq2FY5twJzxEDgtztuSbQ0ttHq3rm+tGGpw=; b=FTt9Ig/snKUZ8bCWS1GDpuh3evKLsJLF0+zUZikVFtHrkQ16p0oWGDcJKjhomsUEuV 95WhmF7iYHOq7ZgkHpoA9iwnGPjyG7m2JbnFXFM4ogaElANOCrXHcw+bLGyStlg/jkEi k7ZAlNqcRuev/TKir8yhA7c+WvsSgBrtIym23KLwigPBNb9vyASoWq3H5hVn5o0Auw/R +7ogYSo0ZX/JQ5kBWqU9N8OhZBgjFNkaAThMc0sym9EiDrcZOzi9UDY0YQVv8p+a4qb4 BCQMT2Nc3TEGWwf7fDbsrr1WsXi7QUL+rha3Lq7g34RKkkKyqnFljFohADnLYgnrffbs r4ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=5SdOAT1nEq2FY5twJzxEDgtztuSbQ0ttHq3rm+tGGpw=; b=A1Gsci4onbQMh6+F5csvwH5KQKwYErkrq4KxcoUU/KOP2tX3KXPb84W1DewUi1d+Fz i6EmTqHUOFWupKmYg+sAHJsdOMIq4TmCqKqBk8evA8mYlUtPmKjStxC/CZaCU/96lTIi bvlL4RnQw4ACxsVTMHOhX0QfbxV7BWQVCnsth3BPMznSBROUowlCY90T3QG88V12dQRY zBNcFKqsSntl2WdxsnSztQW7yDdkTKBcBy/pJCq9Hc2UNxOBufoAXAH/FsTTiy+G+hJx gg9Etx1tewXgbuWV0lC2LNt5QACmw3EC6msSrczDClyYlJAMjsIFBRCEv5jgz5b8gWsu RUdQ== X-Gm-Message-State: ALoCoQlNUiF2aWsStGNhbc21W2kVWaFviG8X5or8sEJMYAK47IzKYC6hJbzah1DXKy++M7RC0f+/337w/MFEk5PXyuzn2inpIjwZ5rk5/BA2xrhrOEnn2WQ= MIME-Version: 1.0 X-Received: by 10.31.138.20 with SMTP id m20mr17415016vkd.70.1449903348786; Fri, 11 Dec 2015 22:55:48 -0800 (PST) Received: by 10.31.61.12 with HTTP; Fri, 11 Dec 2015 22:55:48 -0800 (PST) In-Reply-To: <1449122773-25510-2-git-send-email-yuanhan.liu@linux.intel.com> References: <1449122773-25510-1-git-send-email-yuanhan.liu@linux.intel.com> <1449122773-25510-2-git-send-email-yuanhan.liu@linux.intel.com> Date: Fri, 11 Dec 2015 22:55:48 -0800 Message-ID: From: Rich Lane To: Yuanhan Liu Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Cc: dev@dpdk.org, Victor Kaplansky , "Michael S. Tsirkin" Subject: Re: [dpdk-dev] [PATCH 1/5] vhost: refactor rte_vhost_dequeue_burst X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Dec 2015 06:55:49 -0000 On Wed, Dec 2, 2015 at 10:06 PM, Yuanhan Liu wrote: > > +static inline struct rte_mbuf * > +copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, > + uint16_t desc_idx, struct rte_mempool *mbuf_pool) > +{ > ... > + > + desc = &vq->desc[desc_idx]; > + desc_addr = gpa_to_vva(dev, desc->addr); > + rte_prefetch0((void *)(uintptr_t)desc_addr); > + > + /* Discard virtio header */ > + desc_avail = desc->len - vq->vhost_hlen; If desc->len is zero (happens all the time when restarting DPDK apps in the guest) then desc_avail will be huge. > + desc_offset = vq->vhost_hlen; > + > + mbuf_avail = 0; > + mbuf_offset = 0; > + while (desc_avail || (desc->flags & VRING_DESC_F_NEXT) != 0) { + /* This desc reachs to its end, get the next one */ > + if (desc_avail == 0) { > + desc = &vq->desc[desc->next]; > Need to check desc->next against vq->size. There should be a limit on the number of descriptors in a chain to prevent an infinite loop. uint16_t > rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, > struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t > count) > { > ... > avail_idx = *((volatile uint16_t *)&vq->avail->idx); > - > - /* If there are no available buffers then return. */ > - if (vq->last_used_idx == avail_idx) > + free_entries = avail_idx - vq->last_used_idx; > + if (free_entries == 0) > return 0; > A common problem is that avail_idx goes backwards when the guest zeroes its virtqueues. This function could check for free_entries > vq->size and reset vq->last_used_idx. + LOG_DEBUG(VHOST_DATA, "(%"PRIu64") about to dequene %u buffers\n", > + dev->device_fh, count); > Typo at "dequene".