Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2470046rdh; Wed, 27 Sep 2023 03:48:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvtTwr7Jwp8Hh3yEMCn84t1DUOF+uCHbTTP5cJ2AGki01OhClf/6DfkHG1Q04xSNIS3Whf X-Received: by 2002:a67:ee01:0:b0:452:819b:f7f5 with SMTP id f1-20020a67ee01000000b00452819bf7f5mr1681052vsp.25.1695811730373; Wed, 27 Sep 2023 03:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695811730; cv=none; d=google.com; s=arc-20160816; b=l+0X/n8IaDJUkI8Thd9/3OfPCL3GGUcjwvd2EWPYb8K5qdboDlwcUu7dkbiONA3FA/ 9V9S8brL5yv7HgImyu3Ty82uvGJoef5yP7Xz1rSVKufyHuOGkpe6CC+ioqwgFs2R0IVa hKli0VR8VwRh+smBe5BE2wKftwHp05myt+lImryTHpeNssj2wiVSt8CUOJj3Tm6dQQ8R HEZQ6XhhL+LS6Mo+ShXf54punjH8Of4ByPf1rx+bDq71Cz858hBESkeyMU6y658HCyIc kMh5KluFjmLNt85w1oz3pbyiFAiRr4zBWWHko0rLIsvr4WVKI4GSoTCnQK36FJ3AnG+b Ut5g== 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=ap6jvf8/2CoqbMpAwThp0QoWymIsVaHbvqKSWQ1uNLM=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=bXANeLP2tnH+rIJzEDiE4tOwk61+UHPIuBOG5Abb22psqY3ed54AE9IpAHw2Hh1v2N wSbQtQairW7GiLoiVWU03Xy4LsbSVPCTGaulZTcv5iNZva+mlQs7cJ4xDEQ3thMZx/b1 3nPEKy1U0CctbcVq9u4Zv3Yl8f3R+tRFc77t9aLA+Se3KNcLGXeCeIj6ZaDJvD8zK1UR rskZDMQkXe7X5FTt1ywB66iidl4rb2XLNdoaG0r9GKEL71nYWvmdNWCWjIUpcJddBd8s CCQawnO2kkQp0cbWivA09+ypV3wwIZ7dWLmGKBLEnIkVaDIhHFW8U4PjCCRBOO27y5ER 6Rog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DxqZbid8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ca37-20020a056a0206a500b00578a43e3b0bsi17642800pgb.655.2023.09.27.03.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 03:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DxqZbid8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id E79B680B26BA; Wed, 27 Sep 2023 00:36:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbjI0Hg3 (ORCPT + 99 others); Wed, 27 Sep 2023 03:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjI0HgZ (ORCPT ); Wed, 27 Sep 2023 03:36:25 -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 79F7B193 for ; Wed, 27 Sep 2023 00:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695800137; 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=ap6jvf8/2CoqbMpAwThp0QoWymIsVaHbvqKSWQ1uNLM=; b=DxqZbid8+SG9xtUkotqnGYLLppNEf+Q7lITn0rNcTt4RqNFfk4TQ9tu9PI1fme8nrXa1cA 150h+wGO8tagfGOGSLfqzs74ibdwKMQ1Gsr7g35SwoW9DmMuxQ21G/p+qOuCqFjos5m2HV r3yP+dOxVXMtwNHf5QlnB9E+oBIMxGQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-lUNwBF3GNAWxu1BcJfh43Q-1; Wed, 27 Sep 2023 03:35:36 -0400 X-MC-Unique: lUNwBF3GNAWxu1BcJfh43Q-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-405917470e8so58144465e9.1 for ; Wed, 27 Sep 2023 00:35:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695800135; x=1696404935; 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=ap6jvf8/2CoqbMpAwThp0QoWymIsVaHbvqKSWQ1uNLM=; b=vSI9F1OLRw8wyaaPmcqyzHToO8qnMxbtd3CqGw70OTp3uNAPwkdOKNw169GKBs/zRa jAEO4isZINZY3r/Myn/+5AI0dKTgaUsC4appyKMUX+xczHmqydbidt8qPxstta6cWEWl saJqhTpHp4ThJhXsnb6x8Ac8SsRwGLcL5R2NevPRUWPOGo2QvDuIyZWG1jxIdSZaWe77 JpdUVKEbuIS9D5N8S/GiHh2OQ1BXCmPBB+/btZYdLv6mBlxXgbLUx6q0zcRQ4FljMm/A SLR9tHKjmqHxQNR5b7Si5mJiWnP74CU6t80x4So7UkMQX6rLzagrOLXg1Bk+xrVJVFoG e8Cw== X-Gm-Message-State: AOJu0YxvugDzPS6LfUaaF880IhnYBtNpK6GaRQNbF56b7QvbA+KFOFUL l771lcM0otJJOOZPi/+OlJTNpRhatVMFBT6WW6GzntesCch3qvWmD9bdKda/VRwbsFbn7Bn8BqN 51FPgAkaYtZleO1xBdO2igQNP X-Received: by 2002:a7b:ce94:0:b0:401:c944:a4d6 with SMTP id q20-20020a7bce94000000b00401c944a4d6mr1190418wmj.28.1695800134934; Wed, 27 Sep 2023 00:35:34 -0700 (PDT) X-Received: by 2002:a7b:ce94:0:b0:401:c944:a4d6 with SMTP id q20-20020a7bce94000000b00401c944a4d6mr1190398wmj.28.1695800134503; Wed, 27 Sep 2023 00:35:34 -0700 (PDT) Received: from sgarzare-redhat ([46.222.19.70]) by smtp.gmail.com with ESMTPSA id 19-20020a05600c029300b004060f0a0fdbsm4495926wmk.41.2023.09.27.00.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 00:35:33 -0700 (PDT) Date: Wed, 27 Sep 2023 09:35:31 +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 v1 08/12] vsock: enable setting SO_ZEROCOPY Message-ID: References: <20230922052428.4005676-1-avkrasnov@salutedevices.com> <20230922052428.4005676-9-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 00:36:58 -0700 (PDT) On Tue, Sep 26, 2023 at 10:38:06PM +0300, Arseniy Krasnov wrote: > > >On 26.09.2023 15:56, Stefano Garzarella wrote: >> On Fri, Sep 22, 2023 at 08:24:24AM +0300, Arseniy Krasnov wrote: >>> For AF_VSOCK, zerocopy tx mode depends on transport, so this option must >>> be set in AF_VSOCK implementation where transport is accessible (if >>> transport is not set during setting SO_ZEROCOPY: for example socket is >>> not connected, then SO_ZEROCOPY will be enabled, but once transport will >>> be assigned, support of this type of transmission will be checked). >>> >>> To handle SO_ZEROCOPY, AF_VSOCK implementation uses SOCK_CUSTOM_SOCKOPT >>> bit, thus handling SOL_SOCKET option operations, but all of them except >>> SO_ZEROCOPY will be forwarded to the generic handler by calling >>> 'sock_setsockopt()'. >>> >>> Signed-off-by: Arseniy Krasnov >>> --- >>> Changelog: >>> v5(big patchset) -> v1: >>> ?* Compact 'if' conditions. >>> ?* Rename 'zc_val' to 'zerocopy'. >>> ?* Use 'zerocopy' value directly in 'sock_valbool_flag()', without >>> ?? ?: operator. >>> ?* Set 'SOCK_CUSTOM_SOCKOPT' bit for connectible sockets only, as >>> ?? suggested by Bobby Eshleman . >>> >>> net/vmw_vsock/af_vsock.c | 46 ++++++++++++++++++++++++++++++++++++++-- >>> 1 file changed, 44 insertions(+), 2 deletions(-) >>> >>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >>> index 482300eb88e0..c05a42e02a17 100644 >>> --- a/net/vmw_vsock/af_vsock.c >>> +++ b/net/vmw_vsock/af_vsock.c >>> @@ -1406,8 +1406,16 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr, >>> ??????????? goto out; >>> ??????? } >>> >>> -??????? if (vsock_msgzerocopy_allow(transport)) >>> +??????? if (vsock_msgzerocopy_allow(transport)) { >>> ??????????? set_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); >>> +??????? } else if (sock_flag(sk, SOCK_ZEROCOPY)) { >>> +??????????? /* If this option was set before 'connect()', >>> +???????????? * when transport was unknown, check that this >>> +???????????? * feature is supported here. >>> +???????????? */ >>> +??????????? err = -EOPNOTSUPP; >>> +??????????? goto out; >>> +??????? } >>> >>> ??????? err = vsock_auto_bind(vsk); >>> ??????? if (err) >>> @@ -1643,7 +1651,7 @@ static int vsock_connectible_setsockopt(struct socket *sock, >>> ????const struct vsock_transport *transport; >>> ????u64 val; >>> >>> -??? if (level != AF_VSOCK) >>> +??? if (level != AF_VSOCK && level != SOL_SOCKET) >>> ??????? return -ENOPROTOOPT; >>> >>> #define COPY_IN(_v)?????????????????????????????????????? \ >>> @@ -1666,6 +1674,34 @@ static int vsock_connectible_setsockopt(struct socket *sock, >>> >>> ????transport = vsk->transport; >>> >>> +??? if (level == SOL_SOCKET) { >>> +??????? int zerocopy; >>> + >>> +??????? if (optname != SO_ZEROCOPY) { >>> +??????????? release_sock(sk); >>> +??????????? return sock_setsockopt(sock, level, optname, optval, optlen); >>> +??????? } >>> + >>> +??????? /* Use 'int' type here, because variable to >>> +???????? * set this option usually has this type. >>> +???????? */ >>> +??????? COPY_IN(zerocopy); >>> + >>> +??????? if (zerocopy < 0 || zerocopy > 1) { >>> +??????????? err = -EINVAL; >>> +??????????? goto exit; >>> +??????? } >>> + >>> +??????? if (transport && !vsock_msgzerocopy_allow(transport)) { >>> +??????????? err = -EOPNOTSUPP; >>> +??????????? goto exit; >>> +??????? } >>> + >>> +??????? sock_valbool_flag(sk, SOCK_ZEROCOPY, >>> +????????????????? zerocopy); >> >> it's not necessary to wrap this call. > >Sorry, what do you mean ? I mean that can be on the same line: sock_valbool_flag(sk, SOCK_ZEROCOPY, zerocopy); Stefano