Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1041559pxb; Thu, 28 Jan 2021 06:48:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6x1EkF+b0oNDefjbupg4rAbyI6700paO2Aj3j5L1xpsu+zRprsISacTK89WdpLvPmDgpA X-Received: by 2002:aa7:c3d9:: with SMTP id l25mr15174277edr.188.1611845307397; Thu, 28 Jan 2021 06:48:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611845307; cv=none; d=google.com; s=arc-20160816; b=gFtEevUnd9JgEpkiTMpMCaANG4xFTf0Z69UsqG7gzHqKbjnrIAk86DtxbcEH8ZI1Wq 7+6D/cxdZvh1jcvbWpjbTD5msIYUNRzGjoM15mwmX8Y68O3IoWIQqux9ipyFIPROm2zX AotEgPTpZzfG6KOpkkYDtyvKU90DDT4NibtjENbSyiuLDdNRyyS1rtOUSvjFUTI5WJQN y/w7537EKw85v7t2ls4E6O+DCFFu49GL7BET6R+zQ+hcyKku+r0fhCVz+rEw4gv0lZYV HsokoTYdqAD0fhvfVxcPOrn81PMvp2miveuZehz2kdiAKNNubztsGtdEozbDtQuIDXo+ F9Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dMfBbPjDPZ4dIyXQtS0tJU0Oae1keECk1ejt9iIRqJg=; b=J/wbbLKzgbARX9b95eNGItmhbamp2hHbql4wiI6cQZa5DdPF5Ee6Nljb+wWOSJTzrO NsVs7wIt+rWlnWR4DR7gPdww1mYGgRypO6B7l8vzOpSjbAhiKr776+hZ4zqkEUJ+5AK4 fV6GPphv60DCoJK+3kTI/p/dXlU8S9aBsy3dALsrAA1QDZUeYQBnKs+7WJa8hsrbsh14 mzsC7oosZr0cFfIrtJnC9vTVwSuS3mJgQ2qj6n08s1zQ2a3WACYr5kQ8NSGiVlQjUg3y LFiL9x6oRsYnV87FJ69FNnKjrBUIXbLIJGR5JWynKpcGWTCHf9q8hTB3orW0LQdWK0Aw MmYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="U/7lAwf5"; 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 cs9si2329208ejc.113.2021.01.28.06.48.02; Thu, 28 Jan 2021 06:48:27 -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="U/7lAwf5"; 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 S231907AbhA1OoI (ORCPT + 99 others); Thu, 28 Jan 2021 09:44:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52276 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231537AbhA1Onx (ORCPT ); Thu, 28 Jan 2021 09:43:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611844946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dMfBbPjDPZ4dIyXQtS0tJU0Oae1keECk1ejt9iIRqJg=; b=U/7lAwf5Hx6ghL0gZW9GJv+d4/iOvzNp4sLtd6436+BNTwD7Yxgzu2fjKriBL0IjeVbNV2 tGLHcVkHc8n35ERuZcvxiJgbE9yQwwE8lmLH1Pt8ZpjiZOi6er6TJSA+hO8TcO5qisNYrB z2iYpps3TdnDpghD24iFVoqXGf4x448= 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-524-UzL0ZiMJPbiRkiCf77zeAA-1; Thu, 28 Jan 2021 09:42:25 -0500 X-MC-Unique: UzL0ZiMJPbiRkiCf77zeAA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA868801B2E; Thu, 28 Jan 2021 14:42:23 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-113-219.ams2.redhat.com [10.36.113.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0F9E19443; Thu, 28 Jan 2021 14:42:05 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Xie Yongji , "Michael S. Tsirkin" , Stefano Garzarella , Laurent Vivier , Stefan Hajnoczi , linux-kernel@vger.kernel.org, Max Gurtovoy , Jason Wang , kvm@vger.kernel.org Subject: [PATCH RFC v2 04/10] vringh: implement vringh_kiov_advance() Date: Thu, 28 Jan 2021 15:41:21 +0100 Message-Id: <20210128144127.113245-5-sgarzare@redhat.com> In-Reply-To: <20210128144127.113245-1-sgarzare@redhat.com> References: <20210128144127.113245-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some cases, it may be useful to provide a way to skip a number of bytes in a vringh_kiov. Let's implement vringh_kiov_advance() for this purpose, reusing the code from vringh_iov_xfer(). We replace that code calling the new vringh_kiov_advance(). Signed-off-by: Stefano Garzarella --- include/linux/vringh.h | 2 ++ drivers/vhost/vringh.c | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/linux/vringh.h b/include/linux/vringh.h index 9c077863c8f6..755211ebd195 100644 --- a/include/linux/vringh.h +++ b/include/linux/vringh.h @@ -199,6 +199,8 @@ static inline void vringh_kiov_cleanup(struct vringh_kiov *kiov) kiov->iov = NULL; } +void vringh_kiov_advance(struct vringh_kiov *kiov, size_t len); + int vringh_getdesc_kern(struct vringh *vrh, struct vringh_kiov *riov, struct vringh_kiov *wiov, diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index bee63d68201a..4d800e4f31ca 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -75,6 +75,34 @@ static inline int __vringh_get_head(const struct vringh *vrh, return head; } +/** + * vringh_kiov_advance - skip bytes from vring_kiov + * @iov: an iov passed to vringh_getdesc_*() (updated as we consume) + * @len: the maximum length to advance + */ +void vringh_kiov_advance(struct vringh_kiov *iov, size_t len) +{ + while (len && iov->i < iov->used) { + size_t partlen = min(iov->iov[iov->i].iov_len, len); + + iov->consumed += partlen; + iov->iov[iov->i].iov_len -= partlen; + iov->iov[iov->i].iov_base += partlen; + + if (!iov->iov[iov->i].iov_len) { + /* Fix up old iov element then increment. */ + iov->iov[iov->i].iov_len = iov->consumed; + iov->iov[iov->i].iov_base -= iov->consumed; + + iov->consumed = 0; + iov->i++; + } + + len -= partlen; + } +} +EXPORT_SYMBOL(vringh_kiov_advance); + /* Copy some bytes to/from the iovec. Returns num copied. */ static inline ssize_t vringh_iov_xfer(struct vringh *vrh, struct vringh_kiov *iov, @@ -95,19 +123,8 @@ static inline ssize_t vringh_iov_xfer(struct vringh *vrh, done += partlen; len -= partlen; ptr += partlen; - iov->consumed += partlen; - iov->iov[iov->i].iov_len -= partlen; - iov->iov[iov->i].iov_base += partlen; - if (!iov->iov[iov->i].iov_len) { - /* Fix up old iov element then increment. */ - iov->iov[iov->i].iov_len = iov->consumed; - iov->iov[iov->i].iov_base -= iov->consumed; - - - iov->consumed = 0; - iov->i++; - } + vringh_kiov_advance(iov, partlen); } return done; } -- 2.29.2