Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp145645rdb; Mon, 18 Sep 2023 10:29:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVkqreFUpZPP4cbQHUR0IcgK8Vl5JwK0TOf4P9tvE1Rv0r5xKFD+N53y7OKFv51ALyqpDh X-Received: by 2002:a05:6a00:4199:b0:68e:2fd4:288a with SMTP id ca25-20020a056a00419900b0068e2fd4288amr11127752pfb.3.1695058196285; Mon, 18 Sep 2023 10:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695058196; cv=none; d=google.com; s=arc-20160816; b=vqfsbmMjmOq23scg7EGbZF50MCgS3Ng6+msys4wmiQcNlcMlgI3RwUOTw3CX9+/yVF oNXDhI1gItK8HdvUn9SqeTswTXmhv4+qfESKnsP1ixMml+rxsiW0F8/XwLk/QgM8OGMg s9rlcriF7v/iMITMMFhYpiSO2D80e8GFODo3l49tMPTxO+PLEAtVFGvazLloGCPi+Up8 Ot9U1jl26aI9Og3zRVWNPgyOTw67IARSYMDw4Tu8wQD/RodcKDFcTM4Plqk/zcG8pALL 7nE+YY/CsVSWcJviWWtLRC6nAAxXjEAwu6FSeuAJODDS/nN10Mhd2IDBs+pZaYmtuJia eb1Q== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LcTISZgyQz7Bvk45tsdOeOYi0IZTcEbOF6L8io0wv6s=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=bWrNnWfTKx8EJ6J+G68SD6rwpLT9+I9xCsgMOGBXR0KP8i9RznT78PAc6uJLOG0kLH u7WMYfuBeYApAq//uzkLkq6eoVE9qGx0FseksN8chXSTaEzJaYNI+kNjJZMcR5g1cqxC YRHzzvlsbcusm3y5sKkzjLMtMG08PzLb2i4JUk12fCWGq5y2ffjBHSdLErua6H50iif5 Vi4OlyCV6KCP6WKz6ffsmjlEss/kRsGJZth60T4vZ92IwlhOQwFeiu/y3Xb46vjYcLFk q016DvvoEqtsX/zdNbVY0/qJkcD2pV8Ob1SDk0Ad17Bz2BXLtxWcxi/Hnrl+nT4y2GX6 Sp+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cp2Mz3U2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id cm10-20020a056a00338a00b0068fbace5bfcsi8298075pfb.149.2023.09.18.10.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 10:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cp2Mz3U2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2BF8D81DE68D; Mon, 18 Sep 2023 08:25:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbjIRPZS (ORCPT + 99 others); Mon, 18 Sep 2023 11:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbjIRPZR (ORCPT ); Mon, 18 Sep 2023 11:25:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38F101A8 for ; Mon, 18 Sep 2023 08:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695050425; 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: in-reply-to:in-reply-to:references:references; bh=LcTISZgyQz7Bvk45tsdOeOYi0IZTcEbOF6L8io0wv6s=; b=cp2Mz3U24Ggcuo9FNS9C3MJiMzIwDFP/K+wN9PzWveuI5Hem808RtgQKlLRdcnk7jIN0IJ oQJg/+v+YVz01P7+HCZ+DZMoNFBJyMMfWz2ynXll0M024iFuv5bUMpEUrb6B3Xy4dx805r H1d/TVR9z4idxJhM4/6Jr3d6iDCo1MY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-RaLnU6OBOembrNK_UM7Lmw-1; Mon, 18 Sep 2023 10:50:11 -0400 X-MC-Unique: RaLnU6OBOembrNK_UM7Lmw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-31aef28315eso3112600f8f.2 for ; Mon, 18 Sep 2023 07:50:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695048610; x=1695653410; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LcTISZgyQz7Bvk45tsdOeOYi0IZTcEbOF6L8io0wv6s=; b=A+5t1guaU+AjQJ6tx2TUf/UhHwlVCHldOAt/A17MycP6jrNM194DrJzqs5mck/1OqM dDH9oNQeAR8VJ0pTrVJQmDQqDWJwQ9qJmN7y+8lGBLvkba0fRMGwC7MWe+F+y3H+fsF5 kYY2h7lQl7rsEvlmNIKVo8PUwgVhBQaRLYkYf8RZ/BmS3zJ8hz/1ag3YlMhzIDiFBsmI XNheZm8apn8NZGPXueVrSMUtZl2kj51+Dmia66q+GN+ltQWjiRCQMpGXdH4ZUZ8hhbBL 67a6osoqq5d7X42aMtq9f/i/wLHwEaAUXoj8dcR0IkSbHFaIRy2Yc0m/tuht7cadRqvE 104Q== X-Gm-Message-State: AOJu0YwuGr+mVziGaPnNgkkRzEib5yFOZ7k4H4BY3/0scsn5X0584M+A c9YOQZNWjYs612gQMIskD6Jc0rrLu3bZL7DiUADGfvJSD3E5qGE5Tey5TmY78AoCV8hBXAmvkHt xVxsHLip4yqpgOJKxxgVzGsF7 X-Received: by 2002:a5d:4941:0:b0:319:72f8:7249 with SMTP id r1-20020a5d4941000000b0031972f87249mr7183136wrs.66.1695048609813; Mon, 18 Sep 2023 07:50:09 -0700 (PDT) X-Received: by 2002:a5d:4941:0:b0:319:72f8:7249 with SMTP id r1-20020a5d4941000000b0031972f87249mr7183112wrs.66.1695048609417; Mon, 18 Sep 2023 07:50:09 -0700 (PDT) Received: from sgarzare-redhat ([46.222.42.69]) by smtp.gmail.com with ESMTPSA id m6-20020adfe946000000b0031980783d78sm12772049wrn.54.2023.09.18.07.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 07:50:08 -0700 (PDT) Date: Mon, 18 Sep 2023 16:50:05 +0200 From: Stefano Garzarella To: Arseniy Krasnov Cc: Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@sberdevices.ru, oxffffaa@gmail.com Subject: Re: [PATCH net-next v9 4/4] vsock/virtio: MSG_ZEROCOPY flag support Message-ID: References: <20230916130918.4105122-1-avkrasnov@salutedevices.com> <20230916130918.4105122-5-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230916130918.4105122-5-avkrasnov@salutedevices.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 08:25:18 -0700 (PDT) On Sat, Sep 16, 2023 at 04:09:18PM +0300, Arseniy Krasnov wrote: >This adds handling of MSG_ZEROCOPY flag on transmission path: > >1) If this flag is set and zerocopy transmission is possible (enabled > in socket options and transport allows zerocopy), then non-linear > skb will be created and filled with the pages of user's buffer. > Pages of user's buffer are locked in memory by 'get_user_pages()'. >2) Replaces way of skb owning: instead of 'skb_set_owner_sk_safe()' it > calls 'skb_set_owner_w()'. Reason of this change is that > '__zerocopy_sg_from_iter()' increments 'sk_wmem_alloc' of socket, so > to decrease this field correctly, proper skb destructor is needed: > 'sock_wfree()'. This destructor is set by 'skb_set_owner_w()'. >3) Adds new callback to 'struct virtio_transport': 'can_msgzerocopy'. > If this callback is set, then transport needs extra check to be able > to send provided number of buffers in zerocopy mode. Currently, the > only transport that needs this callback set is virtio, because this > transport adds new buffers to the virtio queue and we need to check, > that number of these buffers is less than size of the queue (it is > required by virtio spec). vhost and loopback transports don't need > this check. > >Signed-off-by: Arseniy Krasnov >--- > Changelog: > v5(big patchset) -> v1: > * Refactorings of 'if' conditions. > * Remove extra blank line. > * Remove 'frag_off' field unneeded init. > * Add function 'virtio_transport_fill_skb()' which fills both linear > and non-linear skb with provided data. > v1 -> v2: > * Use original order of last four arguments in 'virtio_transport_alloc_skb()'. > v2 -> v3: > * Add new transport callback: 'msgzerocopy_check_iov'. It checks that > provided 'iov_iter' with data could be sent in a zerocopy mode. > If this callback is not set in transport - transport allows to send > any 'iov_iter' in zerocopy mode. Otherwise - if callback returns 'true' > then zerocopy is allowed. Reason of this callback is that in case of > G2H transmission we insert whole skb to the tx virtio queue and such > skb must fit to the size of the virtio queue to be sent in a single > iteration (may be tx logic in 'virtio_transport.c' could be reworked > as in vhost to support partial send of current skb). This callback > will be enabled only for G2H path. For details pls see comment > 'Check that tx queue...' below. > v3 -> v4: > * 'msgzerocopy_check_iov' moved from 'struct vsock_transport' to > 'struct virtio_transport' as it is virtio specific callback and > never needed in other transports. > v4 -> v5: > * 'msgzerocopy_check_iov' renamed to 'can_msgzerocopy' and now it > uses number of buffers to send as input argument. I think there is > no need to pass iov to this callback (at least today, it is used only > by guest side of virtio transport), because the only thing that this > callback does is comparison of number of buffers to be inserted to > the tx queue and size of this queue. > * Remove any checks for type of current 'iov_iter' with payload (is it > 'iovec' or 'ubuf'). These checks left from the earlier versions where I > didn't use already implemented kernel API which handles every type of > 'iov_iter'. > v5 -> v6: > * Refactor 'virtio_transport_fill_skb()'. > * Add 'WARN_ON_ONCE()' and comment on invalid combination of destination > socket and payload in 'virtio_transport_alloc_skb()'. > v7 -> v8: > * Move '+1' addition from 'can_msgzerocopy' callback body to the caller. > This addition means packet header. > * In 'virtio_transport_can_zcopy()' rename 'max_to_send' argument to > 'pkt_len'. > * Update commit message by adding details about new 'can_msgzerocopy' > callback. > * In 'virtio_transport_init_hdr()' move 'len' argument directly after > 'info'. > * Add comment about processing last skb in tx loop. > * Update comment for 'can_msgzerocopy' callback for more details. > v8 -> v9: > * Return and update comment for 'virtio_transport_alloc_skb()'. > * Pass pointer to transport ops to 'virtio_transport_can_zcopy()', > this allows to use it directly without calling virtio_transport_get_ops()'. > * Remove redundant call for 'msg_data_left()' in 'virtio_transport_fill_skb()'. > * Do not pass 'struct vsock_sock*' to 'virtio_transport_alloc_skb()', > use same pointer from already passed 'struct virtio_vsock_pkt_info*'. > * Fix setting 'end of message' bit for SOCK_SEQPACKET (add call for > 'msg_data_left()' == 0). > * Add 'zcopy' parameter to packet allocation trace event. Thanks for addressing the comments! > > include/linux/virtio_vsock.h | 9 + > .../events/vsock_virtio_transport_common.h | 12 +- > net/vmw_vsock/virtio_transport.c | 32 +++ > net/vmw_vsock/virtio_transport_common.c | 250 ++++++++++++++---- > 4 files changed, 241 insertions(+), 62 deletions(-) LGTM! Reviewed-by: Stefano Garzarella