Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1158150pxb; Fri, 13 Nov 2020 05:52:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+RFv3jt2TT9rXwyLeThHm3D8Yi4wCnqqll5zjd+asKRr4Uxu7nwKiv3lkF8Sm2n9Kf7aF X-Received: by 2002:a50:8a9c:: with SMTP id j28mr2444010edj.254.1605275551693; Fri, 13 Nov 2020 05:52:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605275551; cv=none; d=google.com; s=arc-20160816; b=avk5tWYEWsWggZL7zpVO8oJCZBjxtR+sDn6M6jND0hPBTmj38kr3wIDsJN+jOJMIpW crbk+PPkHqHXq1IO9ooFO4U/Z2TWoF4cj90/T5Po3d9sWsno9XuB8BxykYwVNypEEudT 1Ksa4EZbz1gP9yX9jMkXoyqPwKp5n2EyWH9PuWEJXDXHtNvVAaQWP0lYql9iGzxjrWGW lA3tbReI+Wo51R3BdF6rMLn/LphOU/uCUph0FcxNyH/ui8fGg/CztJ5/09WsWVfXsjsv tDtoOBkCAl10vV7NkdW3vDfEQX2T1y5k9PfOILuvqCIN04PnnnvHdLAi7qytgOK+z2U0 R2aQ== 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=zahLTNS43nRj+vHGeTYURaqz9Ba56dxaMqAEL8MHFEM=; b=slCSQ5N5QrFU4OjdaF0SjtM++sbftP/rmwir1kySz8l5JAM91mwvPg2oQ6nGy+xS9C yP0KrMKd1TWwvWcWHg9sy7Bck43DdXLYkSk/qtAnO/remCfQOF9wsNaztawy/LZgxaql 1U6b1lffQGzcEdPYHujE8VIVhwQ5uOfXjTVY3y7We4vHx9WntnV6NpTTSBDPy2kYJWIo kUSJUC/D4bC9HhBwyl5nH7t3OTypptO3Q7MOA4r7kVsK+RzcL1paNt4i4fOoTkpSNV93 mLsoQXrz9P7p+KvD84JFOjIM+PqV5N6o+enyce9Frh5LbM+yCOOC/j9+3J3zrD2pbCi+ bpMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DzeiBxja; 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 di3si5832048edb.554.2020.11.13.05.52.08; Fri, 13 Nov 2020 05:52:31 -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=DzeiBxja; 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 S1726851AbgKMNsz (ORCPT + 99 others); Fri, 13 Nov 2020 08:48:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27111 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbgKMNsx (ORCPT ); Fri, 13 Nov 2020 08:48:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605275331; 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=zahLTNS43nRj+vHGeTYURaqz9Ba56dxaMqAEL8MHFEM=; b=DzeiBxjaxlza6nV0gTvLiYvLxCPzkGGfbzNLopb1F56mkT7zOpBS0GFv7ojeEXFkUbkZXQ rMSnMZIMpePRl/+6yKmJSBIRxiSWIkqEIRMB5c9mcpzNFqlVCp8flfw8egDwsLUc8WyA3l P7apbGhSN3EAHg4+8zi5kGcpbrZzaJM= 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-284-XNL1iMqPN5OBFqQ7ctti7g-1; Fri, 13 Nov 2020 08:48:48 -0500 X-MC-Unique: XNL1iMqPN5OBFqQ7ctti7g-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 072748030A7; Fri, 13 Nov 2020 13:48:47 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 306005D9F3; Fri, 13 Nov 2020 13:48:45 +0000 (UTC) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Stefan Hajnoczi , Laurent Vivier , linux-kernel@vger.kernel.org, Eli Cohen , Jason Wang , "Michael S. Tsirkin" , Max Gurtovoy Subject: [PATCH RFC 11/12] vringh: allow vringh_iov_xfer() to skip bytes when ptr is NULL Date: Fri, 13 Nov 2020 14:47:11 +0100 Message-Id: <20201113134712.69744-12-sgarzare@redhat.com> In-Reply-To: <20201113134712.69744-1-sgarzare@redhat.com> References: <20201113134712.69744-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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_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? --- 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; -- 2.26.2