Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2840842pxb; Sun, 15 Nov 2020 20:39:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlMrl9onK14pkeAKfZqvLRD5oXWx8EmxtQggxme06KcTfI6aedjzYRcVIJqSYdiK/GBg4u X-Received: by 2002:a05:6402:88d:: with SMTP id e13mr14366163edy.366.1605501586906; Sun, 15 Nov 2020 20:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605501586; cv=none; d=google.com; s=arc-20160816; b=HcwpVcylI+/AkJf6TCTVBmddQI8606oVVUracxI+jgk+0gRASiNzP026s0bpNg0Sg9 AARJ8sBBI5SQyzXovJXrOD/V7Q+WLLaqeLBYLNxpP/cmX+oFfNwp0mbLyFnymZtmaR+i l2PyqCDds14HXAS53zfDavnaBwD38yv3pktDK+iMD495Zqtq51Di90anBvlfrfKRd64M uHASeK6shxuszE3u7TUBtKeBOyANz6MNnNy8Ve9H+UChcZFtjaBGE6558R0yVAvDi7m/ aMyBPVsAb2yACCqqMP33/u7eUhsrqdfNAyDrowjoF8fnr89uh9ogVZOyjDjYoycjgqj0 KrpA== 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=rWwwHi+vPJ8ujzj6hxsvoqxeQ6ueO5UlgElf6+sCWok=; b=r0vNB+Yc/32voFQdvFf8kGExEtTn9vJoPvOLNLgbhiVDwL44rh6ngM4R/9+CofP+AZ teo7LIn5OegfcPkCWTFrVLFoI23Fz9Ff2UIJKvsjjizGZG2aUTy5SDSSzRqO5JDis7TJ 2nort5rco0xYOylRfOkDOwE8ckFCpFN1AvRbhp6/XplNbm1sNytyEaQYr/d47c9WHQ8K V3rYkh91xYtqHziZrjn7YojVzoLwy/RlCDQb8KxlmWHP7Mdymosq3SNX3IIEap0oV8iK VQbUW0Y8TL8C5hQWMO5rSlOJ0vqVMIHFiuMcZfYsmjRMoSrvxZOppw8KjBylAlwemMFj P3Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eMNvgmBP; 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 a1si10507716ejt.206.2020.11.15.20.39.24; Sun, 15 Nov 2020 20:39:46 -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=eMNvgmBP; 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 S1726867AbgKPEcS (ORCPT + 99 others); Sun, 15 Nov 2020 23:32:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32006 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726136AbgKPEcR (ORCPT ); Sun, 15 Nov 2020 23:32:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605501136; 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=rWwwHi+vPJ8ujzj6hxsvoqxeQ6ueO5UlgElf6+sCWok=; b=eMNvgmBPjOTE/KG/ahvFKdvYCigf5BJBVzzSRDr+2BxUMfhmIirVeTew50FoR/S/xlH30f uXZ6Y9I7iz76rzGyGCeIQfqXLGVbbK2BMjFsz7MJNX+2Qvq99FHUljWHtLPLWPbXlJR1Ck 1Srlb2lxQi/Q9qefHsZHwBYXhQvIGu4= 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-92-EPvhdJzgOy60UuEuZ9rE2A-1; Sun, 15 Nov 2020 23:32:15 -0500 X-MC-Unique: EPvhdJzgOy60UuEuZ9rE2A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 186831007474; Mon, 16 Nov 2020 04:32:14 +0000 (UTC) Received: from [10.72.13.126] (ovpn-13-126.pek2.redhat.com [10.72.13.126]) by smtp.corp.redhat.com (Postfix) with ESMTP id 535C15B4C5; Mon, 16 Nov 2020 04:32:04 +0000 (UTC) Subject: Re: [PATCH RFC 11/12] vringh: allow vringh_iov_xfer() to skip bytes when ptr is NULL To: Stefano Garzarella , virtualization@lists.linux-foundation.org Cc: Stefan Hajnoczi , Laurent Vivier , linux-kernel@vger.kernel.org, Eli Cohen , "Michael S. Tsirkin" , Max Gurtovoy References: <20201113134712.69744-1-sgarzare@redhat.com> <20201113134712.69744-12-sgarzare@redhat.com> From: Jason Wang Message-ID: Date: Mon, 16 Nov 2020 12:32:02 +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: <20201113134712.69744-12-sgarzare@redhat.com> 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.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/11/13 下午9:47, Stefano Garzarella wrote: > In some cases, it may be useful to provide a way to skip a number > of bytes in a vringh_iov. > > In order to keep vringh_iov consistent, let's reuse vringh_iov_xfer() > logic and skip bytes when the ptr is NULL. > > Signed-off-by: Stefano Garzarella > --- > > I'm not sure if this is the best option, maybe we can add a new > function vringh_iov_skip(). > > Suggestions? I might be worth to check whether we can convert vringh_iov to use iov iterator then we can use iov_iterator_advance() here. Thanks > --- > drivers/vhost/vringh.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c > index 8bd8b403f087..ed3290946ad7 100644 > --- a/drivers/vhost/vringh.c > +++ b/drivers/vhost/vringh.c > @@ -75,7 +75,9 @@ static inline int __vringh_get_head(const struct vringh *vrh, > return head; > } > > -/* Copy some bytes to/from the iovec. Returns num copied. */ > +/* Copy some bytes to/from the iovec. Returns num copied. > + * If ptr is NULL, skips at most len bytes. > + */ > static inline ssize_t vringh_iov_xfer(struct vringh *vrh, > struct vringh_kiov *iov, > void *ptr, size_t len, > @@ -89,12 +91,16 @@ static inline ssize_t vringh_iov_xfer(struct vringh *vrh, > size_t partlen; > > partlen = min(iov->iov[iov->i].iov_len, len); > - err = xfer(vrh, iov->iov[iov->i].iov_base, ptr, partlen); > - if (err) > - return err; > + > + if (ptr) { > + err = xfer(vrh, iov->iov[iov->i].iov_base, ptr, partlen); > + if (err) > + return err; > + ptr += partlen; > + } > + > done += partlen; > len -= partlen; > - ptr += partlen; > iov->consumed += partlen; > iov->iov[iov->i].iov_len -= partlen; > iov->iov[iov->i].iov_base += partlen;