Received: by 10.192.165.148 with SMTP id m20csp3043709imm; Sun, 22 Apr 2018 22:43:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+tI7etDEvJo/z4S+H+2jXMrRz+ptW4YV6pi9cYuzdjsuvExEUqQMzNKB6mgK4T8L+ZJrGt X-Received: by 10.99.109.138 with SMTP id i132mr16226043pgc.314.1524462224730; Sun, 22 Apr 2018 22:43:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524462224; cv=none; d=google.com; s=arc-20160816; b=Qr8U52F/UepYUddTex83wTB8at79kbuwVw8u5pxVZ2J5KfZrGIZrwAMRwz0Y8qgsc1 4MczBHnQJJmjL0rY2bnJt8IJQfcrcPjf/vlH8iJSTTWn0wAfhWAHEZ7sFz551rL1LXM6 2nBsgZEPnIEs9lTF+sN/RW2ck3Ocnzg70pyP9DwWOQ0nSTN+yVHO/0H7FQ+q4HFQ+t/o J3Z30UEGW3dQJTs8iwIqtzS664jGaxPVpY4TRXjlwhpUTQzazpFTYOGO9WWi8Z+8JR/j E0vsUqRdOTpX/6X8n9noVw25Ni+WrgOeXT08GithnXu+T8UQxT0KLAOdOJZqhfKgUMV0 IujQ== 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=L+oDx0vCyIRJsaeO3imNIm7x9EOYLOLPEcQOTPW+ed8=; b=aDTgCmmACQEAMLxFrkJvVu0kCOIEIqzQwuvH7hJJFEOzcTJ71t8HiCtxwN8ca/Qz4v gI4ec9UI+PfCmjUpM6BIFsTqr4YQAnILUQtQhxcmtyjv9K3WateB7Rp7gKqOX37QjnxV EGHdJgi3xqMY59bTM1/lskuHECi1LbpkkYcyvYjKgdxTtrkOKpDeFl4jATE4mcXzgJ2C MtXOvpHMsseHkbKXuXBZBJg89HpZEfAFOibQwTd82fD9bxGSfmePnh4cFUkRJVj5lWbk LLsnXsYPb17PbxNWjpzADb1ejqU95cTcVQpGAtV8F4MKSHL6P3Ubb9yQSELzjeWB3vor dBlA== 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 62si10571392pfw.173.2018.04.22.22.43.29; Sun, 22 Apr 2018 22:43:44 -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 S1751437AbeDWFmW (ORCPT + 99 others); Mon, 23 Apr 2018 01:42:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50718 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751233AbeDWFmV (ORCPT ); Mon, 23 Apr 2018 01:42:21 -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 A8975406C78B; Mon, 23 Apr 2018 05:42:20 +0000 (UTC) Received: from [10.72.12.101] (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58196215CDC8; Mon, 23 Apr 2018 05:42:17 +0000 (UTC) Subject: Re: [RFC v2] virtio: support packed ring To: Tiwei Bie , mst@redhat.com, wexu@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: jfreimann@redhat.com References: <20180401141216.8969-1-tiwei.bie@intel.com> From: Jason Wang Message-ID: <515e635b-bc80-9b8d-72f9-b390ae5103ec@redhat.com> Date: Mon, 23 Apr 2018 13:42:14 +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: <20180401141216.8969-1-tiwei.bie@intel.com> 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.5]); Mon, 23 Apr 2018 05:42:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 05:42:20 +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年04月01日 22:12, Tiwei Bie wrote: > Hello everyone, > > This RFC implements packed ring support for virtio driver. > > The code was tested with DPDK vhost (testpmd/vhost-PMD) implemented > by Jens at http://dpdk.org/ml/archives/dev/2018-January/089417.html > Minor changes are needed for the vhost code, e.g. to kick the guest. > > TODO: > - Refinements and bug fixes; > - Split into small patches; > - Test indirect descriptor support; > - Test/fix event suppression support; > - Test devices other than net; > > RFC v1 -> RFC v2: > - Add indirect descriptor support - compile test only; > - Add event suppression supprt - compile test only; > - Move vring_packed_init() out of uapi (Jason, MST); > - Merge two loops into one in virtqueue_add_packed() (Jason); > - Split vring_unmap_one() for packed ring and split ring (Jason); > - Avoid using '%' operator (Jason); > - Rename free_head -> next_avail_idx (Jason); > - Add comments for virtio_wmb() in virtqueue_add_packed() (Jason); > - Some other refinements and bug fixes; > > Thanks! > > Signed-off-by: Tiwei Bie > --- > drivers/virtio/virtio_ring.c | 1094 +++++++++++++++++++++++++++++------- > include/linux/virtio_ring.h | 8 +- > include/uapi/linux/virtio_config.h | 12 +- > include/uapi/linux/virtio_ring.h | 61 ++ > 4 files changed, 980 insertions(+), 195 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 71458f493cf8..0515dca34d77 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -58,14 +58,15 @@ > [...] > + > + if (vq->indirect) { > + u32 len; > + > + desc = vq->desc_state[head].indir_desc; > + /* Free the indirect table, if any, now that it's unmapped. */ > + if (!desc) > + goto out; > + > + len = virtio32_to_cpu(vq->vq.vdev, > + vq->vring_packed.desc[head].len); > + > + BUG_ON(!(vq->vring_packed.desc[head].flags & > + cpu_to_virtio16(vq->vq.vdev, VRING_DESC_F_INDIRECT))); It looks to me spec does not force to keep VRING_DESC_F_INDIRECT here. So we can safely remove this BUG_ON() here. > + BUG_ON(len == 0 || len % sizeof(struct vring_packed_desc)); Len could be ignored for used descriptor according to the spec, so we need remove this BUG_ON() too. The reason is we don't touch descriptor ring in the case of split, so BUG_ON()s may help there. > + > + for (j = 0; j < len / sizeof(struct vring_packed_desc); j++) > + vring_unmap_one_packed(vq, &desc[j]); > + > + kfree(desc); > + vq->desc_state[head].indir_desc = NULL; > + } else if (ctx) { > + *ctx = vq->desc_state[head].indir_desc; > + } > + > +out: > + return vq->desc_state[head].num; > +} > + > +static inline bool more_used_split(const struct vring_virtqueue *vq) > { > return vq->last_used_idx != virtio16_to_cpu(vq->vq.vdev, vq->vring.used->idx); > } > > +static inline bool more_used_packed(const struct vring_virtqueue *vq) > +{ > + u16 last_used, flags; > + bool avail, used; > + > + if (vq->vq.num_free == vq->vring_packed.num) > + return false; > + > + last_used = vq->last_used_idx; > + flags = virtio16_to_cpu(vq->vq.vdev, > + vq->vring_packed.desc[last_used].flags); > + avail = flags & VRING_DESC_F_AVAIL(1); > + used = flags & VRING_DESC_F_USED(1); > + > + return avail == used; > +} This looks interesting, spec said: " Thus VIRTQ_DESC_F_AVAIL and VIRTQ_DESC_F_USED bits are different for an available descriptor and equal for a used descriptor. Note that this observation is mostly useful for sanity-checking as these are necessary but not sufficient conditions - for example, all descriptors are zero-initialized. To detect used and available descriptors it is possible for drivers and devices to keep track of the last observed value of VIRTQ_DESC_F_USED/VIRTQ_- DESC_F_AVAIL. Other techniques to detect VIRTQ_DESC_F_AVAIL/VIRTQ_DESC_F_USED bit changes might also be possible. " So it looks to me it was not sufficient, looking at the example codes in spec, do we need to track last seen used_wrap_counter here? Thanks