Received: by 10.192.165.148 with SMTP id m20csp4057624imm; Mon, 23 Apr 2018 18:16:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+grDrAb87wB0HtZaCIYAK4bv3XAbSS8qJrC7534kQ8UxS7flEcAJtiJWGQup22Eqh6hHvP X-Received: by 10.98.15.23 with SMTP id x23mr20543595pfi.3.1524532573920; Mon, 23 Apr 2018 18:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524532573; cv=none; d=google.com; s=arc-20160816; b=MlVqkZsWbocQdj1uIVkh2pq7LnVfKrrYvs9KtYKtoUM+AFGplLxZN1lrv3Osh0iRpD dgVnBIRUBD/LKB7RoTzXj4oKeodwcGg17T2ITcUg3vZSGhhpRhbBodl0jy3bWYI3hhtl 3xYCZr9706JkwuG/ExeFquFgne+/Et7iCcXxueUOXxZSbXBNqKRvUdd8nYToiWAjMmT8 xO2LcpQeVJWcD6hCOGWn9xYYcOnubTPi7LImmL7asZrcLx7+50SlUKQpJB3A+RKTNAAw 6B9WR72jueG0dTUjUR0u66au9SwqCoBtayf0oIjY0cB49KFQdfYdD5QW8isvZn9/sdPA ORag== 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=PvisKEXG2lsaNDnpOBfcVXhPQyvunVaR0hT/s3AIBbA=; b=h27wXoH9FwEDex7hQcVcgLh+asMWOjOSZ7V5debydkt5PvfmJJDMNOQd+GpmmcRns6 NKSpZCZIOky5axRIv9/+2qZu/qEH5SFDb9nJS6u6ZaEmTXuf/yoXymm/4xmbQMhPp63i Fy6p+qsKllbCndnZFe0afDqvBZaEPrH3R4HH/9YqcXyWpy++6Ytq1l9ewgfRobnosRn7 rcpfUFa+W4wGK+q3a2u4Rn4+eQYXUtPN13wxd49CPU+KMdMuELOA/vqTejXcmYArSmxN s9FHXQTPW+QLS7D5FC3VztU1Y+VHwVoyWvDmDvg8Kz0Ryc7JuKjHYD7mROBCI6pk61uO MkjA== 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 f59-v6si11294366plb.106.2018.04.23.18.15.59; Mon, 23 Apr 2018 18:16:13 -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 S932726AbeDXBOs (ORCPT + 99 others); Mon, 23 Apr 2018 21:14:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35506 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932633AbeDXBOr (ORCPT ); Mon, 23 Apr 2018 21:14:47 -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 6A924EC014; Tue, 24 Apr 2018 01:14:46 +0000 (UTC) Received: from [10.72.12.52] (ovpn-12-52.pek2.redhat.com [10.72.12.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41DBD2166BC6; Tue, 24 Apr 2018 01:14:41 +0000 (UTC) Subject: Re: [RFC v2] virtio: support packed ring To: "Michael S. Tsirkin" Cc: Tiwei Bie , wexu@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, jfreimann@redhat.com References: <20180401141216.8969-1-tiwei.bie@intel.com> <515e635b-bc80-9b8d-72f9-b390ae5103ec@redhat.com> <20180423092908.77rii3gi7dcaf7o6@debian> <20180424040258-mutt-send-email-mst@kernel.org> From: Jason Wang Message-ID: <820a9720-0a02-684b-3957-319b5b2a5370@redhat.com> Date: Tue, 24 Apr 2018 09:14:36 +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: <20180424040258-mutt-send-email-mst@kernel.org> 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.1]); Tue, 24 Apr 2018 01:14:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 24 Apr 2018 01:14:46 +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月24日 09:05, Michael S. Tsirkin wrote: >>>>> + 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. >>> Yeah, you're right! The BUG_ON() isn't right. I'll remove it. >>> And I think something related to this in the spec isn't very >>> clear currently. >>> >>> In the spec, there are below words: >>> >>> https://github.com/oasis-tcs/virtio-spec/blob/d4fec517dfcf/packed-ring.tex#L272 >>> """ >>> In descriptors with VIRTQ_DESC_F_INDIRECT set VIRTQ_DESC_F_WRITE >>> is reserved and is ignored by the device. >>> """ >>> >>> So when device writes back an used descriptor in this case, >>> device may not set the VIRTQ_DESC_F_WRITE flag as the flag >>> is reserved and should be ignored. >>> >>> https://github.com/oasis-tcs/virtio-spec/blob/d4fec517dfcf/packed-ring.tex#L170 >>> """ >>> Element Length is reserved for used descriptors without the >>> VIRTQ_DESC_F_WRITE flag, and is ignored by drivers. >>> """ >>> >>> And this is the way how driver ignores the `len` in an used >>> descriptor. >>> >>> https://github.com/oasis-tcs/virtio-spec/blob/d4fec517dfcf/packed-ring.tex#L241 >>> """ >>> To increase ring capacity the driver can store a (read-only >>> by the device) table of indirect descriptors anywhere in memory, >>> and insert a descriptor in the main virtqueue (with \field{Flags} >>> bit VIRTQ_DESC_F_INDIRECT on) that refers to a buffer element >>> containing this indirect descriptor table; >>> """ >>> >>> So the indirect descriptors in the table are read-only by >>> the device. And the only descriptor which is writeable by >>> the device is the descriptor in the main virtqueue (with >>> Flags bit VIRTQ_DESC_F_INDIRECT on). So if we ignore the >>> `len` in this descriptor, we won't be able to get the >>> length of the data written by the device. >>> >>> So I think the `len` in this descriptor will carry the >>> length of the data written by the device (if the buffers >>> are writable to the device) even if the VIRTQ_DESC_F_WRITE >>> isn't set by the device. How do you think? >> Yes I think so. But we'd better need clarification from Michael. > I think if you use a descriptor, and you want to supply len > to guest, you set VIRTQ_DESC_F_WRITE in the used descriptor. > Spec also says you must not set VIRTQ_DESC_F_INDIRECT then. > If that's a problem we could look at relaxing that last requirement - > does driver want INDIRECT in used descriptor to match > the value in the avail descriptor for some reason? > Looks not, so what I get it: - device and set VIRTQ_DESC_F_WRITE flag for used descriptor when needed - there no need to keep INDIRECT flag in used descriptor So for the above case, we can just have a used descriptor with _F_WRITE but without INDIRECT flag. Thanks