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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4184C0015E for ; Tue, 25 Jul 2023 12:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233141AbjGYMkO (ORCPT ); Tue, 25 Jul 2023 08:40:14 -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-Google-Smtp-Source: APBJJlEZbT/9sLf9SJUi2km6xKCfsN6lBnNmF8+myjdUi1f+mFGkC/VPgqG8v9x7Cn7VgrIjISJYxQ== 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: 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.