Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4315785pxb; Mon, 1 Feb 2021 19:29:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJybXDXGOHV9HNuosKjy7JcR2L+xYo0HXM3ROUbSta2EK4RH1l5Iy3DxnuqRvT7lAJKZ5h1O X-Received: by 2002:a17:906:9381:: with SMTP id l1mr21534772ejx.433.1612236592264; Mon, 01 Feb 2021 19:29:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612236592; cv=none; d=google.com; s=arc-20160816; b=jUggtySs1R5kkQVZjSbaSDMaqj4L4dStAk+ibqZzKCQ7noOE6QQo/XcXeP0uJwJwYC p/UpbievyLb0SV9clIMatRd+qXMHwH6LB9OlQg3UODE4W4Th9sRMO4O3WSdfPvxenS7q X/KRkEFgWGSqfaNz/Nu8Xk7DN4nxWtg9nhhT3Bl5PACWflwwWKFB5JFV/ElpJp50vlCo vuIH5bMn3JJaFzZXgLUXE4bOmDsyQCvxKQhXj64Dt7hMlPEFPw1FhHjLoCByVETJJF9o 8Oz1R2BQjwlpn4ccVRLmP3SiaKtTLiONi5gUcu+NBDKoliWCvANmViDEsWazt+OzJq02 nONA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=A+0xoBytfYFL452jZI7eq1Xid/1xoGVklSAHoMYfbNM=; b=Q+v29pO5Ecu6krT6H55nFWGBEBroVODfX5gZGaWn810OrswvUhvF9yFHFL4kFJDJ18 bon0hlbjPILY+s5RZ3a78GMVIQK8IHqtXq/gQizRvaLXmH78N3n45wjY1/EjiBPRdWXd nqctza2BYJCK5mFC4t8UcdkhY9vxWb/lQ+7YsL+HbL+WU+ktUgOamh4AGhPLaxmkRCYS oQwjlxqqxcvQFKX8V9dsXD69rFszyfLud4J21KT9MMHdjWULAycTD/lN9UFLfUD3XsMl FpJcSwXW9Xyg39mfIr7u3vVCHWSK2uzI4EWQMma7OL8JjWeJOaJCRWuoRrGhIfQ8VhXE FFiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aYdKwX0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si7187055edc.514.2021.02.01.19.29.27; Mon, 01 Feb 2021 19:29:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aYdKwX0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbhBBD2N (ORCPT + 99 others); Mon, 1 Feb 2021 22:28:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54942 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbhBBD2L (ORCPT ); Mon, 1 Feb 2021 22:28:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612236405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A+0xoBytfYFL452jZI7eq1Xid/1xoGVklSAHoMYfbNM=; b=aYdKwX0K5+LQhpaHi3Ea8dIyR0mSy+ekoTAr1PSehhKxCxmLBjigo5SeCGfSLIaQctMU2U 3hFPs0lb9o0iZOW5wllFxuCoPHCz6Y+E6SxLMDV7gGywni2Wi7Ska/O1SuacJsxjXkJf2l LAedpvdMygasiCN9gj/zHNmwzuWoXGU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-1axtorIiNDm0hWhRTR7PxA-1; Mon, 01 Feb 2021 22:26:44 -0500 X-MC-Unique: 1axtorIiNDm0hWhRTR7PxA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17B6C803623; Tue, 2 Feb 2021 03:26:43 +0000 (UTC) Received: from [10.72.13.250] (ovpn-13-250.pek2.redhat.com [10.72.13.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D8EA5D9CA; Tue, 2 Feb 2021 03:26:32 +0000 (UTC) Subject: Re: [PATCH RFC v2 03/10] vringh: reset kiov 'consumed' field in __vringh_iov() To: Stefano Garzarella Cc: virtualization@lists.linux-foundation.org, Xie Yongji , "Michael S. Tsirkin" , Laurent Vivier , Stefan Hajnoczi , linux-kernel@vger.kernel.org, Max Gurtovoy , kvm@vger.kernel.org References: <20210128144127.113245-1-sgarzare@redhat.com> <20210128144127.113245-4-sgarzare@redhat.com> <62bb2e93-4ac3-edf5-2baa-4c2be8257cf0@redhat.com> <20210201102120.kvbpbne3spaqv6yz@steredhat> From: Jason Wang Message-ID: <55287f2f-0288-ac07-8232-787612c00290@redhat.com> Date: Tue, 2 Feb 2021 11:26:31 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210201102120.kvbpbne3spaqv6yz@steredhat> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/2/1 下午6:21, Stefano Garzarella wrote: > On Mon, Feb 01, 2021 at 01:40:01PM +0800, Jason Wang wrote: >> >> On 2021/1/28 下午10:41, Stefano Garzarella wrote: >>> __vringh_iov() overwrites the contents of riov and wiov, in fact it >>> resets the 'i' and 'used' fields, but also the consumed field should >>> be reset to avoid an inconsistent state. >>> >>> Signed-off-by: Stefano Garzarella >> >> >> I had a question(I remember we had some discussion like this but I >> forget the conclusion): > > Sorry, I forgot to update you. > >> >> I see e.g in vringh_getdesc_kern() it has the following comment: >> >> /* >>  * Note that you may need to clean up riov and wiov, even on error! >>  */ >> >> So it looks to me the correct way is to call vringh_kiov_cleanup() >> before? > > Looking at the code the right pattern should be: > >     vringh_getdesc_*(..., &out_iov, &in_iov, ...); > >     // use out_iov and in_iov > >     vringh_kiov_cleanup(&out_iov); >     vringh_kiov_cleanup(&in_iov); > > This because vringh_getdesc_*() calls __vringh_iov() where > resize_iovec() is called to allocate the iov wrapped by 'struct > vringh_kiov' and vringh_kiov_cleanup() frees that memory. > > Looking better, __vringh_iov() is able to extend a 'vringh_kiov' > pre-allocated, so in order to avoid to allocate and free the iov for > each request we can avoid to call vringh_kiov_cleanup(), but this > patch is needed to avoid an inconsistent state. > > And also patch "vdpa_sim: cleanup kiovs in vdpasim_free()" is required > to free the iov when the device is going away. > > Does that make sense to you? Make sense. > > Maybe I should add a comment in vringh.c to explain this better. Yes, please. Thanks > > Thanks, > Stefano > >> >> Thanks >> >> >>> --- >>>  drivers/vhost/vringh.c | 4 ++-- >>>  1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c >>> index f68122705719..bee63d68201a 100644 >>> --- a/drivers/vhost/vringh.c >>> +++ b/drivers/vhost/vringh.c >>> @@ -290,9 +290,9 @@ __vringh_iov(struct vringh *vrh, u16 i, >>>          return -EINVAL; >>>      if (riov) >>> -        riov->i = riov->used = 0; >>> +        riov->i = riov->used = riov->consumed = 0; >>>      if (wiov) >>> -        wiov->i = wiov->used = 0; >>> +        wiov->i = wiov->used = wiov->consumed = 0; >>>      for (;;) { >>>          void *addr; >> >