Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3704499pxb; Mon, 1 Feb 2021 02:26:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwK+XMd+uvtiNVJtfQ4tEqKf3rKFYpNUOFu0p3TwCtiXE3IvnRURpopzGhFvgPuFdVZOy+o X-Received: by 2002:aa7:ce87:: with SMTP id y7mr18240390edv.211.1612175182196; Mon, 01 Feb 2021 02:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612175182; cv=none; d=google.com; s=arc-20160816; b=MmjAhs8tVJ32xUinVXMWnhp5vXJ/g2vbFrq8fgYUo4oQ0Kgc8Dj9qTiTf/hVFqjbWj nyxuwCYQGH75lOoxH3PQFe8Z9LYEXC5CGfxQg//7kJbMfsyx/pQSl97HUwrbJhOVRUj7 1VFiS8xHx5rtxMDzsjmyw9ZfXIx9K13RZm5dvPxQcE/deGFug02iO3zEsVvG5Jvqa7td bcQeJhHF85QPYIlmV4EPGcrTsCHMH7r6MsiO4ZyD+Ze3wBRLsywqrSkp6CTZvYMr0kiM jtUvFlYbY+bOKyvJD+yZFRjqhEB9abJhx3JztEH3rLaCtJPa/FKpLd9uZpdOyNJCAsiC rj0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=76s0xuNfIMYw2Zjhat6XiJ6WTlVIEyZzd1HMUW58qTQ=; b=Yp98Ep8AzlzTB7BVF4PUi5P8s4Aaz5tqXJzi9SpYyAwBmR2Rj/+M88FIUr63mTlc7u +2iE0+qwVvwcfSLssMVF9Okzr8+uxgRse3bKWkfK59NSGlmfPjtnjT8DcdaxyrFy6RbX 03CVXPZ4Ret0adPXFEy+mWlM19CO5f60yyFf2o7B9CMsw6fPqaq7n+GhrpADp5fJpzlV YxbpLY6j39MmKsllRdQquDxr+7ZCNbZGEXFZXsn+R8otwL3Y5TZE0QhTljpXPHIwx+ac Q+JZjrsFPQqPcxC8Zsv0Ktt1kEJLQ3HjPyng2CkDzmHbYErTPa17FKYB0y2S0La2otQo PLdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f+JEU8Te; 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 i18si10401078edx.293.2021.02.01.02.25.57; Mon, 01 Feb 2021 02:26:22 -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=f+JEU8Te; 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 S233011AbhBAKWz (ORCPT + 99 others); Mon, 1 Feb 2021 05:22:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38780 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232742AbhBAKWx (ORCPT ); Mon, 1 Feb 2021 05:22:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612174886; 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=76s0xuNfIMYw2Zjhat6XiJ6WTlVIEyZzd1HMUW58qTQ=; b=f+JEU8TezlIsDUfDZabQ3/XDaKYPHzyAqOnzyBMmJEQFkmnb8Lv8bRtvOAyhgfXoAoSH1R rxti3UjtA9+hGh+t5JNIc34pc4Dfz6SZh308NZX4rs0QiTFTnMgskBvRN438dvlwoxUztk mQiNrSQ+NqCArOhsutimPJgMxOqtX4I= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-61-V96rxaLaNMOnFxHZpgbzCg-1; Mon, 01 Feb 2021 05:21:25 -0500 X-MC-Unique: V96rxaLaNMOnFxHZpgbzCg-1 Received: by mail-wm1-f72.google.com with SMTP id l21so4360495wmj.1 for ; Mon, 01 Feb 2021 02:21:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=76s0xuNfIMYw2Zjhat6XiJ6WTlVIEyZzd1HMUW58qTQ=; b=QFPTrfjAuu6ayOwhjs/oHO+eYpzByMaLYpV9XguXoqWWMZFt+rFzSLxGrci+75CdAU kYGphVrYaVq5IA70Ojx1zvMwaR+zyFzfWPH7fvoiuW4egjcMCfl3gpUPVMIHe+BRgyMX D2ZB/+8z33KiOfgF+S8bhgGwkSeEpeIdL0HJIhlmcujKm9C+m07qvSY856eUGVeWCmP0 BT5GZ6fEz5noAZ/Fot9sxrJrRnUKybNajOrUwaM9LUam9JdPvdtQAjKYiZmiNLaaGL7g HsWqQyYCNRMdH3uuKf7prSqb0bOUT05RnxwrOg0wiT42HpD2FTKz/as1Au0h2+pTrqmj l9Jw== X-Gm-Message-State: AOAM530EKEodOz4kMh/yzBDPMI4xlJ+WR+5Zrx9a6/xkvpkzKTA6TPrW 9busygxAqwiwxJny3vSlwwLfbwttPnt0ccTxtSZU+0a+zyLg3LfG1hjsqahcWekHfBejSsxU9SC Orh60Rg6TI7/Pn+XhK82NdpkV X-Received: by 2002:a7b:ce11:: with SMTP id m17mr14042897wmc.158.1612174884000; Mon, 01 Feb 2021 02:21:24 -0800 (PST) X-Received: by 2002:a7b:ce11:: with SMTP id m17mr14042885wmc.158.1612174883799; Mon, 01 Feb 2021 02:21:23 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id e4sm26994287wrw.96.2021.02.01.02.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 02:21:23 -0800 (PST) Date: Mon, 1 Feb 2021 11:21:20 +0100 From: Stefano Garzarella To: Jason Wang 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 Subject: Re: [PATCH RFC v2 03/10] vringh: reset kiov 'consumed' field in __vringh_iov() Message-ID: <20210201102120.kvbpbne3spaqv6yz@steredhat> References: <20210128144127.113245-1-sgarzare@redhat.com> <20210128144127.113245-4-sgarzare@redhat.com> <62bb2e93-4ac3-edf5-2baa-4c2be8257cf0@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <62bb2e93-4ac3-edf5-2baa-4c2be8257cf0@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Maybe I should add a comment in vringh.c to explain this better. 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; >