Received: by 10.192.165.148 with SMTP id m20csp919869imm; Thu, 10 May 2018 02:50:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp5KYRHuDtR7pwbiO1GoSkxQ1sQpkia21EPYusM+nJvYFDXKmg3JAbm9XDbmaHNjGkh1UTP X-Received: by 2002:a63:6142:: with SMTP id v63-v6mr581747pgb.432.1525945832502; Thu, 10 May 2018 02:50:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525945832; cv=none; d=google.com; s=arc-20160816; b=zdVToULmMNcSFzFgTfWMDiUDdKo0R1umoASCTbTozEtplxCiPO5bfx2cFlm1d6WMlZ miC1W27RiL/P0In//XqZuiiCoOuMs3yXI7QQ9TBSgswB0o1ZbiwOjCpFMlalToNviG6Q q8lckYTokl4FplI+xLwzqBN3CprAwSbpbJnr6euvOCimB6tSfLPaUa3/rLr6+P6ej9xR 4K2i0kO2E3ymHyRew+WnrggjoC4Ypyh0ksZxoo6+uJAJYVZ2j0IgHAHm7swHvVtOXExN +EntNNdq9Gc6CRyP/S2QHz8ws5LzaX6/atj8VTNW0ADIEpqWU40xOsHzRWjn+p0y/19h BWPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=KyuLc9onPE9Ezg7Nf3fzt7Hfri3ITb3wsXLv6mgzWwI=; b=QmHSvrAoc6qjO/kypObluWplF/QasnZaPzDS30rhwR0a5iwfTM1VYiajZFxzamt1tv 2W1FNWMIgFFQyo0z3G3ayhWMeUov59uTPXwrQAS77IKT/O566iOBd37A3e/kXXrxWxl6 prmosxGPLUs4oIpTBUlyLFQeJnZyglH8efJ/lItiziYWAxy91yQSkmFNysdWU6/bxUrg /YSSjXRxWmEtIsXIS7axTvSMPjuvlpghpGHp4o819j7+TefID68jv/EbWUN8+oehbZAT o7tY0Yw8wJEuMZHHQbuEsbSV6PYWtgH2Wow/z3DmF1OVdxOUHpF18JxuJF6k21naEMTL Mj2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b70-v6si429962pfe.265.2018.05.10.02.50.16; Thu, 10 May 2018 02:50:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757046AbeEJJt3 (ORCPT + 99 others); Thu, 10 May 2018 05:49:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34744 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756697AbeEJJt1 (ORCPT ); Thu, 10 May 2018 05:49:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0826C818A6AD; Thu, 10 May 2018 09:49:27 +0000 (UTC) Received: from [10.72.12.103] (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A5162141200; Thu, 10 May 2018 09:49:23 +0000 (UTC) Subject: Re: [RFC v3 3/5] virtio_ring: add packed ring support To: Tiwei Bie Cc: mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, wexu@redhat.com References: <20180425051550.24342-1-tiwei.bie@intel.com> <20180425051550.24342-4-tiwei.bie@intel.com> <927f4478-5a81-31d4-ac69-f9ec26248591@redhat.com> <5885acac-e9e3-3abf-b6a2-7347f4d55be2@redhat.com> <20180510085601.6mpxf3yvwxnqnk5q@debian> From: Jason Wang Message-ID: <2fc35cd5-9dbd-7743-497f-b6637d92f528@redhat.com> Date: Thu, 10 May 2018 17:49:20 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180510085601.6mpxf3yvwxnqnk5q@debian> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 10 May 2018 09:49:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 10 May 2018 09:49:27 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018年05月10日 16:56, Tiwei Bie wrote: > On Thu, May 10, 2018 at 03:34:50PM +0800, Jason Wang wrote: >> On 2018年05月10日 15:32, Jason Wang wrote: >>> On 2018年04月25日 13:15, Tiwei Bie wrote: >>>> +    /* We're using some buffers from the free list. */ >>>> +    vq->vq.num_free -= descs_used; >>>> + >>>> +    /* Update free pointer */ >>>> +    if (indirect) { >>>> +        n = head + 1; >>>> +        if (n >= vq->vring_packed.num) { >>>> +            n = 0; >>>> +            vq->wrap_counter ^= 1; >>>> +        } >>>> +        vq->next_avail_idx = n; >>>> +    } else >>>> +        vq->next_avail_idx = i; >>> During testing zerocopy (out of order completion), I found driver may >>> submit two identical buffer id to vhost. So the above code may not work >>> well. >>> >>> Consider the case that driver adds 3 buffer and virtqueue size is 8. >>> >>> a) id = 0,count = 2,next_avail = 2 >>> >>> b) id = 2,count = 4,next_avail = 2 >> next_avail should be 6 here. >> >>> c) id = 4,count = 2,next_avail = 0 >>> >> id should be 6 here. >> >> Thanks >> >>> if packet b is done before packet a, driver may think buffer id 0 is >>> available and try to use it if even if the real buffer 0 was not done. >>> >>> Thanks > Nice catch! Thanks a lot! > I'll implement an ID allocator. > > Best regards, > Tiwei Bie Sounds good. Another similar issue is detac_buf_packed(). It did:         for (j = 0; j < vq->desc_state[head].num; j++) {                 desc = &vq->vring_packed.desc[i];                 vring_unmap_one_packed(vq, desc);                 i++;                 if (i >= vq->vring_packed.num)                         i = 0;         } This probably won't work for out of order too and according to the spec: """ Driver needs to keep track of the size of the list corresponding to each buffer ID, to be able to skip to where the next used descriptor is written by the device. """ Looks like we should not depend on the descriptor ring. Thanks