Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4436830rwo; Tue, 25 Jul 2023 06:12:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9HQ7UBFhshGUVsLnjrnmG7dXFMz8t5ppAeWebJBsDKTjR+paAiLXKEl6O1n9H97uCtJbJ X-Received: by 2002:a17:90b:3711:b0:268:13c4:b800 with SMTP id mg17-20020a17090b371100b0026813c4b800mr6105801pjb.21.1690290755103; Tue, 25 Jul 2023 06:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690290755; cv=none; d=google.com; s=arc-20160816; b=OanmPUuUuJa5tkjBqoZC7OH6PIMoBVovDeeINf2IiXcLMKMfErp54Up8+oYBY4O4LS 55xjJm2f2r8KcPHPduGjMIjsLvbCviYJkEgZN3eR6lJt6v++fYs2PJJh6IYddcHBrV/M OrwpKFhzwjsieARwI5/NAR5c5MeCIEWctvuKZjac+IoQ0Olwi/2M8NSQ3peSiod4p3z7 dW56YW5bOVAJCAsDns1fVKdrn5J0o5yDVx8WEK7iHZDJHN8Qmf5uTkq9gdVCZDQ7ZBvc b8y/XA+DHOCDw3S8lHzqYGLewlqrCOm8MvCF/dVPKQGlxUDcVEjFV674cOUJiLC0icEw fchg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=C0L81qzAix0/zgzaASRrrWq5Ht6GiafQqJmF+ctDLSM=; fh=wFsl3cT6DsQMyR+H2KX6t6nEqo7wpup75aoI52fSo4M=; b=vXbRVwJxzD2W0ZfKJCqjGx5qA0wEG7SNoPd8Z6lF31NglxNcnP6lHyNaTOuRHqevf0 QN336CJekudOQbEMORaJGnO003xOUCcreosgt9hiZ9tM04ftYXO97OXdTHbSlTuNTLV8 +NEhgRbFQLrxpYMtIKEv0I+C5ExHVg/b6GS1uyJj67UhsUZcpkEj6vz2cwg7PXomASDt BZDu5d4prPKkOoFq4IfziIWSvEusY8kst85YkamDxLTzsH4FrjTH0EMIlnAzP7ur/JIT FXzYZkIeNUOf0CERCrN3GM1hmT4gU1r0+Wh+mOtISAsx9aRpIVQBl69ZJmA8viMCmzJH SXFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DOKiICql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t184-20020a6381c1000000b0055bc30dbcd0si11217754pgd.742.2023.07.25.06.12.21; Tue, 25 Jul 2023 06:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DOKiICql; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232767AbjGYMkN (ORCPT + 99 others); Tue, 25 Jul 2023 08:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbjGYMkL (ORCPT ); Tue, 25 Jul 2023 08:40:11 -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 5BAC7BD for ; Tue, 25 Jul 2023 05:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690288766; 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=C0L81qzAix0/zgzaASRrrWq5Ht6GiafQqJmF+ctDLSM=; b=DOKiICqlnTJJewQwRSx22N9RzwfA0yw6TeJqWyT0XIJVHHixOPrgzvBTYCk3OOG3U57IPY HF69RdTdk0XcpolRGcb9w/zR5lN1Aezaokqpdb7EaHZl3cAsQ0dJU9DON6NgMvWMdXT+C+ LQ5nFkn24UJM40qmY8T7Qk/fkevfhsM= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-67-0DmwnUf_NYyAjTelHrrG3g-1; Tue, 25 Jul 2023 08:39:24 -0400 X-MC-Unique: 0DmwnUf_NYyAjTelHrrG3g-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-51bef8bb689so7949994a12.1 for ; Tue, 25 Jul 2023 05:39:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690288763; x=1690893563; h=in-reply-to:content-transfer-encoding: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=C0L81qzAix0/zgzaASRrrWq5Ht6GiafQqJmF+ctDLSM=; b=TQZuGr7bOXOpNMDvMT8weKdQrg606weWLADi0B1zaj62Qrn2NRsKiPqxcVX1NEkx/z tm0TnzeTibEqBU4tWS7+1nE0fLrl/aAmrLoR30Ga/Clz4Aj2Xbyn99TiX42Fy4lOfUmX yVYRB75aLgijaJ3wQ+IwOlavy8fFHjAGXEvSCvT5tps93D1SczY2P6VZk6/d2jzzmN+L fok/uohj7irfr09tMWjiS8yqWigvoc/DB90p1EFDX6CY7mkIMXViwX9J4JzP9rT//QD5 bmj3Ot8ctViCZiNF8nJssK9UyoKmyredAydrlJYLOrKCNAjrs71LTondFtabJh+rTP9c +bgg== X-Gm-Message-State: ABy/qLbjLyJi0xZidg8oJfnxCGDU9lIk6zP/gObeRvGm9cKkwxlKvRDL n3w7g50oLubSBiXK6f3hWuwi7MNaYI6I/RtPJHaLKQos5YztsiJnF50Oh7dwyl0Y8J82gUaQ6eY cOy9PnGaSHO3KvvJM+1aEBjtA X-Received: by 2002:a05:6402:7da:b0:521:d2ab:e4df with SMTP id u26-20020a05640207da00b00521d2abe4dfmr2242338edy.19.1690288763016; Tue, 25 Jul 2023 05:39:23 -0700 (PDT) X-Received: by 2002:a05:6402:7da:b0:521:d2ab:e4df with SMTP id u26-20020a05640207da00b00521d2abe4dfmr2242326edy.19.1690288762712; Tue, 25 Jul 2023 05:39:22 -0700 (PDT) Received: from redhat.com ([2.55.164.187]) by smtp.gmail.com with ESMTPSA id kg13-20020a17090776ed00b009929ab17be0sm8168056ejc.162.2023.07.25.05.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 05:39:22 -0700 (PDT) Date: Tue, 25 Jul 2023 08:39:17 -0400 From: "Michael S. Tsirkin" To: Stefano Garzarella Cc: Arseniy Krasnov , Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 v3 4/4] vsock/virtio: MSG_ZEROCOPY flag support Message-ID: <20230725083823-mutt-send-email-mst@kernel.org> References: <20230720214245.457298-1-AVKrasnov@sberdevices.ru> <20230720214245.457298-5-AVKrasnov@sberdevices.ru> <091c067b-43a0-da7f-265f-30c8c7e62977@sberdevices.ru> <2k3cbz762ua3fmlben5vcm7rs624sktaltbz3ldeevwiguwk2w@klggxj5e3ueu> <51022d5f-5b50-b943-ad92-b06f60bef433@sberdevices.ru> <3d1d76c9-2fdb-3dfe-222a-b2184cf17708@sberdevices.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 25, 2023 at 02:28:02PM +0200, Stefano Garzarella wrote: > On Tue, Jul 25, 2023 at 12:16:11PM +0300, Arseniy Krasnov wrote: > > > > > > On 25.07.2023 11:46, Arseniy Krasnov wrote: > > > > > > > > > On 25.07.2023 11:43, Stefano Garzarella wrote: > > > > On Fri, Jul 21, 2023 at 08:09:03AM +0300, Arseniy Krasnov wrote: > > > > > > > > > > > > > > > On 21.07.2023 00:42, Arseniy Krasnov wrote: > > > > > > This adds handling of MSG_ZEROCOPY flag on transmission path: 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()'. Second thing that > > > > > > this patch does is replace type of skb owning: instead of calling > > > > > > '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()'. > > > > > > > > > > > > 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. > > > > > > > > > > > > ?include/net/af_vsock.h????????????????? |?? 3 + > > > > > > ?net/vmw_vsock/virtio_transport.c??????? |? 39 ++++ > > > > > > ?net/vmw_vsock/virtio_transport_common.c | 257 ++++++++++++++++++------ > > > > > > ?3 files changed, 241 insertions(+), 58 deletions(-) > > > > > > > > > > > > diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h > > > > > > index 0e7504a42925..a6b346eeeb8e 100644 > > > > > > --- a/include/net/af_vsock.h > > > > > > +++ b/include/net/af_vsock.h > > > > > > @@ -177,6 +177,9 @@ struct vsock_transport { > > > > > > > > > > > > ???? /* Read a single skb */ > > > > > > ???? int (*read_skb)(struct vsock_sock *, skb_read_actor_t); > > > > > > + > > > > > > +??? /* Zero-copy. */ > > > > > > +??? bool (*msgzerocopy_check_iov)(const struct iov_iter *); > > > > > > ?}; > > > > > > > > > > > > ?/**** CORE ****/ > > > > > > diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c > > > > > > index 7bbcc8093e51..23cb8ed638c4 100644 > > > > > > --- a/net/vmw_vsock/virtio_transport.c > > > > > > +++ b/net/vmw_vsock/virtio_transport.c > > > > > > @@ -442,6 +442,43 @@ static void virtio_vsock_rx_done(struct virtqueue *vq) > > > > > > ???? queue_work(virtio_vsock_workqueue, &vsock->rx_work); > > > > > > ?} > > > > > > > > > > > > +static bool > > > > > > virtio_transport_msgzerocopy_check_iov(const struct > > > > > > iov_iter *iov) > > > > > > +{ > > > > > > +??? struct virtio_vsock *vsock; > > > > > > +??? bool res = false; > > > > > > + > > > > > > +??? rcu_read_lock(); > > > > > > + > > > > > > +??? vsock = rcu_dereference(the_virtio_vsock); > > > > > > +??? if (vsock) { > > Just noted, what about the following to reduce the indentation? > > if (!vsock) { > goto out; > } no {} pls > ... > ... > out: > rcu_read_unlock(); > return res; indentation is quite modest here. Not sure goto is worth it.