Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3045542imm; Mon, 28 May 2018 23:17:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqAvVPXHj2yVa7/ACSh37A4S+7d2+LLohtHgTzdKZBOG1F6aLWz6qbhyz0Alw9nPLY3rwo8 X-Received: by 2002:a17:902:b58e:: with SMTP id a14-v6mr16434955pls.261.1527574633300; Mon, 28 May 2018 23:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527574633; cv=none; d=google.com; s=arc-20160816; b=XyPZoxKg4B/8rAta8SmDWUiAjJAU0FENX91oi1H2yWpy1XEyFUboCm56j5OUvYOa3G gqUxsS//2b1IOJmURp5UzCkBIhKDF8oeQUesdfnnZEMPb3DZPwlVB9+ry5w4E4jrDdzM +f7R5gvgsCGmtbuWW2rgv/6fWWa5yi8Tasz2qHQ8fAJ4l5gEKl9VJtNFFf+I9xMwRL// jdC+Nk5H6sQSPJaYlIwDQlBOP+03SfNiYfltxr9EByuYQDysqcUcCuQXRtYeocu/0scp 7u2Sfg2v9YrtRj5MacdFjXTSsbn0xW4QuZGEGKwjLCbyEbphWnQmrI5Ndi1sqc3+f7D+ 5dkQ== 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=FrR7vCGRm+IeLuSQxbdOifRAxF2lxHrO48OgPCTUSzw=; b=YNybMZ1RGF+9g+ZTifZqHrCDHoFPOd92PRWj8EehgnCKEQOeiISNJ+T2bAMP2k8/o7 sY1KFeAylPuRHCQI0qtxpioCWSSQXuSIzPn6L1SQ90S58qzZfaY98/9N34+5Bn6AzZ5M YuVfIncIHdWC6WYC5OFFvu0p5ltyBVIg9kMP13YhKkpbXULkS1IPdFw4qtZRDJkLYHuc xgfD/3ZuIkWwOh7bou1R8FQotwZW+w42SOJcpn2XdAvk6R2ySmsxScn129C3C2rHDPtx I2TNZ2Dz9F348Ke1CHoXWPesKcM8W8WWasFSTBJ1v/bJgHdh2vUm6XZ93gpfX1sXbmez P0tw== 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 l70-v6si32419687pfk.129.2018.05.28.23.16.59; Mon, 28 May 2018 23:17: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 S1754591AbeE2GQK (ORCPT + 99 others); Tue, 29 May 2018 02:16:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35504 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754501AbeE2GQI (ORCPT ); Tue, 29 May 2018 02:16:08 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1947C80401A8; Tue, 29 May 2018 06:16:08 +0000 (UTC) Received: from [10.72.12.86] (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F01502026609; Tue, 29 May 2018 06:16:04 +0000 (UTC) Subject: Re: [RFC v5 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, jfreimann@redhat.com References: <20180522081648.14768-1-tiwei.bie@intel.com> <20180522081648.14768-4-tiwei.bie@intel.com> <30bd7505-0ded-8584-e9ab-152756a667d6@redhat.com> <20180529051125.GA2976@debian> From: Jason Wang Message-ID: Date: Tue, 29 May 2018 14:16:01 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180529051125.GA2976@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.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 29 May 2018 06:16:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 29 May 2018 06:16:08 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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月29日 13:11, Tiwei Bie wrote: > On Tue, May 29, 2018 at 11:18:57AM +0800, Jason Wang wrote: >> On 2018年05月22日 16:16, Tiwei Bie wrote: > [...] >>> +static void detach_buf_packed(struct vring_virtqueue *vq, >>> + unsigned int id, void **ctx) >>> +{ >>> + struct vring_desc_state_packed *state; >>> + struct vring_packed_desc *desc; >>> + unsigned int i; >>> + int *next; >>> + >>> + /* Clear data ptr. */ >>> + vq->desc_state_packed[id].data = NULL; >>> + >>> + next = &id; >>> + for (i = 0; i < vq->desc_state_packed[id].num; i++) { >>> + state = &vq->desc_state_packed[*next]; >>> + vring_unmap_state_packed(vq, state); >>> + next = &vq->desc_state_packed[*next].next; >> Have a short discussion with Michael. It looks like the only thing we care >> is DMA address and length here. > The length tracked by desc_state_packed[] is also necessary > when INDIRECT is used and the buffers are writable. > >> So a thought is to avoid using desc_state_packed() is vring_use_dma_api() is >> false? Probably need another id allocator or just use desc_state_packed for >> free id list. > I think it's a good suggestion. Thanks! > > I won't track the addr/len/flags for non-indirect descs > when vring_use_dma_api() returns false. > >>> + } >>> + >>> + vq->vq.num_free += vq->desc_state_packed[id].num; >>> + *next = vq->free_head; >> Using pointer seems not elegant and unnecessary here. You can just track >> next in integer I think? > It's possible to use integer, but will need one more var > to track `prev` (desc_state_packed[prev].next == next in > this case). Yes, please do this. > >>> + vq->free_head = id; >>> + >>> + if (vq->indirect) { >>> + u32 len; >>> + >>> + /* Free the indirect table, if any, now that it's unmapped. */ >>> + desc = vq->desc_state_packed[id].indir_desc; >>> + if (!desc) >>> + return; >>> + >>> + len = vq->desc_state_packed[id].len; >>> + for (i = 0; i < len / sizeof(struct vring_packed_desc); i++) >>> + vring_unmap_desc_packed(vq, &desc[i]); >>> + >>> + kfree(desc); >>> + vq->desc_state_packed[id].indir_desc = NULL; >>> + } else if (ctx) { >>> + *ctx = vq->desc_state_packed[id].indir_desc; >>> + } >>> } >>> static inline bool more_used_packed(const struct vring_virtqueue *vq) >>> { >>> - return false; >>> + u16 last_used, flags; >>> + u8 avail, used; >>> + >>> + 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 && used == vq->used_wrap_counter; >> Spec does not check avail == used? So there's probably a bug in either of >> the two places. >> >> In what condition that avail != used but used == vq_used_wrap_counter? A >> buggy device or device set the two bits in two writes? > Currently, spec doesn't forbid devices to set the status > bits as: avail != used but used == vq_used_wrap_counter. > So I think driver cannot assume this won't happen. Right, but I could not find a situation that device need to something like this. We should either forbid this in the spec or change the example code in the spec. Let's see how Michael think about this. Thanks