Received: by 10.192.165.156 with SMTP id m28csp13058imm; Tue, 17 Apr 2018 05:50:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx49jNgBXtLXZNxL2o4izFvbdwcSGj/+IMLkOIO2tMzl1d1dSYx67/+9CNJF3pf6PFH126MlE X-Received: by 10.99.119.2 with SMTP id s2mr1662864pgc.399.1523969447900; Tue, 17 Apr 2018 05:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523969447; cv=none; d=google.com; s=arc-20160816; b=X54I2w2r2MVFeKYEWH9c30cfxcVkmWK+rjiVG4OeHX5wp41mhl4F2+Y+h4WWgaJ7Gd rOrWZ2Vi/q81laTLJyDIJ7KRUgz0EcsMy9sbtFFNXG89kpzdQkx5nOvH4vhs9mJ3xYUj Zss3g8t60GWHqJKI5EWPmLKcM18EOXN8Z6W+NY8Xfy1k4Zp0rSv3cIFruIcmNTJmI3D8 VwkDKWn6GF4CjL8/hKnUIWM399JIKhzAhFWAoCse0yHlrhNeN6YGD9Z5dknIMSFyAzOo dGifMU5kLkyteY6dgCPYXXsA1ewdJa7uqCW3WySVH7IRLJ19CVWKAG3+BalEBy3HN4Y3 6G7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=wRDB6k6PLBrRSNJ9Pujr6eFlku3R87r6PX6IS3vAYDM=; b=qUtRCoYtQJPUsukjGely3WKWiSdQekMPJLqwuTlY8Jyf5/nxFWCLhLexznRSlQhT4F 1vs87yowk4YUxbisKeFZkqnQjcMa8YV79nw9Ue/C5s7lPlXbjtArLJsF/uCargCLo7y0 Kh+H8fT3/YBx8Fec76btj57SVkQWfuatuGAp0OT9LuWZMiCHmB/DffR7LVkmZsYj/qYE IwVDxIHwXR9r/N+Wq/SFA8AbCnqbZ7wQ/NtETqxSB3b28BxVGw+irV3H57egYK00JxI3 bJAEkxvX5e8Vl4xQKfGLYZB2bNAatOESc0gM1eGrD/cB5ZXc+ahC2jhaPsFPSKbuPAKy yLwg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si505811plb.503.2018.04.17.05.50.32; Tue, 17 Apr 2018 05:50:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753154AbeDQMtW (ORCPT + 99 others); Tue, 17 Apr 2018 08:49:22 -0400 Received: from mga04.intel.com ([192.55.52.120]:63102 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752655AbeDQMtU (ORCPT ); Tue, 17 Apr 2018 08:49:20 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Apr 2018 05:49:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,463,1517904000"; d="scan'208";a="32608482" Received: from debian.sh.intel.com (HELO debian) ([10.67.104.164]) by fmsmga007.fm.intel.com with ESMTP; 17 Apr 2018 05:49:19 -0700 Date: Tue, 17 Apr 2018 20:47:16 +0800 From: Tiwei Bie To: "Michael S. Tsirkin" Cc: Jason Wang , wexu@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, jfreimann@redhat.com Subject: Re: [RFC v2] virtio: support packed ring Message-ID: <20180417124716.wsypd5zl4n4galrz@debian> References: <20180401141216.8969-1-tiwei.bie@intel.com> <20180413071529.f4esh654dakodf4f@debian> <8dee7d62-ac0b-54ba-6bec-4bc4a6fb34e9@redhat.com> <20180417025133.7t7exmizgolr565z@debian> <20180417151654-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180417151654-mutt-send-email-mst@kernel.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 17, 2018 at 03:17:41PM +0300, Michael S. Tsirkin wrote: > On Tue, Apr 17, 2018 at 10:51:33AM +0800, Tiwei Bie wrote: > > On Tue, Apr 17, 2018 at 10:11:58AM +0800, Jason Wang wrote: > > > On 2018年04月13日 15:15, Tiwei Bie wrote: > > > > On Fri, Apr 13, 2018 at 12:30:24PM +0800, Jason Wang wrote: > > > > > On 2018年04月01日 22:12, Tiwei Bie wrote: > > [...] > > > > > > +static int detach_buf_packed(struct vring_virtqueue *vq, unsigned int head, > > > > > > + void **ctx) > > > > > > +{ > > > > > > + struct vring_packed_desc *desc; > > > > > > + unsigned int i, j; > > > > > > + > > > > > > + /* Clear data ptr. */ > > > > > > + vq->desc_state[head].data = NULL; > > > > > > + > > > > > > + i = head; > > > > > > + > > > > > > + for (j = 0; j < vq->desc_state[head].num; j++) { > > > > > > + desc = &vq->vring_packed.desc[i]; > > > > > > + vring_unmap_one_packed(vq, desc); > > > > > > + desc->flags = 0x0; > > > > > Looks like this is unnecessary. > > > > It's safer to zero it. If we don't zero it, after we > > > > call virtqueue_detach_unused_buf_packed() which calls > > > > this function, the desc is still available to the > > > > device. > > > > > > Well detach_unused_buf_packed() should be called after device is stopped, > > > otherwise even if you try to clear, there will still be a window that device > > > may use it. > > > > This is not about whether the device has been stopped or > > not. We don't have other places to re-initialize the ring > > descriptors and wrap_counter. So they need to be set to > > the correct values when doing detach_unused_buf. > > > > Best regards, > > Tiwei Bie > > find vqs is the time to do it. The .find_vqs() will call .setup_vq() which will eventually call vring_create_virtqueue(). It's a different case. Here we're talking about re-initializing the descs and updating the wrap counter when detaching the unused descs (In this case, split ring just needs to decrease vring.avail->idx). Best regards, Tiwei Bie