From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17820C4742C for ; Fri, 13 Nov 2020 13:48:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C68992222F for ; Fri, 13 Nov 2020 13:48:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DzeiBxja" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726859AbgKMNs4 (ORCPT ); Fri, 13 Nov 2020 08:48:56 -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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88F71C4742C for ; Fri, 13 Nov 2020 13:48:53 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BC5E2223F for ; Fri, 13 Nov 2020 13:48:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H7bBtU2i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BC5E2223F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 05397874A6; Fri, 13 Nov 2020 13:48:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jmaw1FiLPUIW; Fri, 13 Nov 2020 13:48:52 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 9149687464; Fri, 13 Nov 2020 13:48:52 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7CE91C0891; Fri, 13 Nov 2020 13:48:52 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 11802C0800 for ; Fri, 13 Nov 2020 13:48:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 07B142E20E for ; Fri, 13 Nov 2020 13:48:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5z6EIGO9LAqn for ; Fri, 13 Nov 2020 13:48:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by silver.osuosl.org (Postfix) with ESMTPS id E63F52E162 for ; Fri, 13 Nov 2020 13:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605275329; 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=H7bBtU2iEqhLeg9AtTjjYBUEZ+3T+y/XlKFOjEI2hgMCg/nqaqMxNuwNuetqatzYdZQC8u 0mHu8+c/pzqltHqoNKlLNL6PodsX/rF5js23xMTt5TSYWW+0y0BRo0r25Rd4FI5vi8bg9C cZliriPBRqa26gNtpZHOdl9D5a6RPGk= 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 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 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Cc: Laurent Vivier , Max Gurtovoy , "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Stefan Hajnoczi , Eli Cohen X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" 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 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization