Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2074291rdb; Tue, 3 Oct 2023 09:24:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7PP09tBtPATsyBD87HM4sZPvEKpxHG1Rj2RcYo0MjiPSDA1L7ARPvO9Bsnm7M67mvqw3d X-Received: by 2002:a05:6808:1823:b0:3ad:9540:5475 with SMTP id bh35-20020a056808182300b003ad95405475mr66087oib.45.1696350287943; Tue, 03 Oct 2023 09:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696350287; cv=none; d=google.com; s=arc-20160816; b=Cx8yczxjjbrWRaM3rJm0ddhro96HJM6kXgJwBvmGiagvZ4VdqMZcy7BCUdPgBjX3w4 sA0WNGt9NWjQ2+T1tbLMe3Lnh4jjX0KbhcdjzN6vEgumWTlSTEaCQRJFSm0HlMDEfDW3 WLzP0MGWq/sLI3gBvKJjIjNgtal7OJgiEkM/2SKw2D8acv087x+ewSYFhfXBEZXlFWrq bo0vFwyBT9ks9YyF6j1EBATCB0uImvEo6hvOW8MAl1+3KRNZi5+48LyBybcaDW5zgFiw Q805JKTPsFIx6u8itygcMnVrh2U4s3c7fGqdIfjSmW7BYGfC5DZcXdSBbyPOXqwD3fNs At3Q== 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=sfMS7si10Em3Ih0ewdIsQWk4sOjmW1agVLON4O4ZHFs=; fh=JEq7ZyqHwnKMAbPjHbEHIOO1u1YxTWxtQlCbJmwG+xw=; b=Ms2ZVIKwAiBnINuaqQVrp7ZZFqx0+9F1fZewLKifOjEATEh+oPfngxJYiPdE+XX4TD sHO9bQ5ZrqZROmxjEC5jZALvNidJ1uI62AaKVYD9pEkMjpIihOYfPzgWKTQGvW1XTM5d 2XjOkVX4MRmfBpQXPU+KdB/PUEwJb+Mkdx4C/Y33M2KdPhSAebZRKlnuC0NT26E1pgck JCS0MU/YXWV+crSEejSNDvqJDQ9YLJ0/bAndr71f2nYMwPMkVImHse9O1u0RWJbnN1um 0vrTVjpGR+11/T22StFzsJh83k2jTH8GT8MYO6Jirt2dYx8ivGTNayAvz5CeiDKtJW5e ESTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="E/EqjKmG"; 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 fr11-20020a17090ae2cb00b0027909685905si1650255pjb.149.2023.10.03.09.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 09:24:47 -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="E/EqjKmG"; 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 72D3D817ABDB; Tue, 3 Oct 2023 09:24:45 -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 S240309AbjJCQY1 (ORCPT + 99 others); Tue, 3 Oct 2023 12:24:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232012AbjJCQYZ (ORCPT ); Tue, 3 Oct 2023 12:24: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 E8170B0 for ; Tue, 3 Oct 2023 09:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696350220; 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=sfMS7si10Em3Ih0ewdIsQWk4sOjmW1agVLON4O4ZHFs=; b=E/EqjKmGORySBA8LC8FLGDNw6gfrvIK1p3+oi4pdVBimFqvU68feQ8NdPANTCtyr3gIRJ7 0u2amggl2ubpmKxQOGegiNfK5NXOl9ek0EF21wn5D7tXZE76zaExDBk6c0E7YfcNDBXRZA ugXIRSE8SrMAO7F1TyMxkqdcmBbS2SQ= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-GVuI3bsuOdyR5ZrdmEnQig-1; Tue, 03 Oct 2023 12:23:38 -0400 X-MC-Unique: GVuI3bsuOdyR5ZrdmEnQig-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4194eb910f5so12709751cf.0 for ; Tue, 03 Oct 2023 09:23:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696350218; x=1696955018; 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=sfMS7si10Em3Ih0ewdIsQWk4sOjmW1agVLON4O4ZHFs=; b=mQycG91Zs6rElyVPJ9naZ3xxMrqe3jissy694G9Gt1MUsC9HJZIXZZajpmk0LI/uew /z78lWJq0H+5RLogXobxnb0CCPTPvGg1tbUQRXKuKfJAasM1rDP6K86lGMYPugwNjR0k qS7tG4fc/W0CJekt89EA6HsY/1IIB+nCdHh6Wluue/Tg6cfwMURJOYM3xTfrWMNdVxm4 DTx9YPnfbC3BHp34Y9PJB9czVcKArlEEamXqTbKAQ+F+MynhIq5yICzqeyTZvJbsYHDr lakPnXZuu7T5E2cFpONswHl5soe40rk0OmvTQMhy5PSumBNsHrV1wgBw5V1jq+1lB6tR lFQQ== X-Gm-Message-State: AOJu0YzVoQpkjWERF/iUrzsr+Sxaigx5p9uNN6Mx6DMNHANEVsnn4xBU RvjcrjRtP9TdXrFOaCvca42LrVm+Ccv0GvyWLueQWAjP9rEyRi+KFaobXrFgm3nq3CV3T/tMArL KUxBnWJ1fgLy+V5LlTXVzjV/5 X-Received: by 2002:ac8:149a:0:b0:419:af26:fc72 with SMTP id l26-20020ac8149a000000b00419af26fc72mr1872205qtj.27.1696350218259; Tue, 03 Oct 2023 09:23:38 -0700 (PDT) X-Received: by 2002:ac8:149a:0:b0:419:af26:fc72 with SMTP id l26-20020ac8149a000000b00419af26fc72mr1872186qtj.27.1696350217966; Tue, 03 Oct 2023 09:23:37 -0700 (PDT) Received: from sgarzare-redhat (host-82-57-51-114.retail.telecomitalia.it. [82.57.51.114]) by smtp.gmail.com with ESMTPSA id d14-20020ac8118e000000b004198d026be6sm552077qtj.35.2023.10.03.09.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 09:23:37 -0700 (PDT) Date: Tue, 3 Oct 2023 18:23:33 +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 v2 08/12] vsock: enable setting SO_ZEROCOPY Message-ID: References: <20230930210308.2394919-1-avkrasnov@salutedevices.com> <20230930210308.2394919-9-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20230930210308.2394919-9-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 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]); Tue, 03 Oct 2023 09:24:45 -0700 (PDT) On Sun, Oct 01, 2023 at 12:03:04AM +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: > v1 -> v2: > * Place 'sock_valbool_flag()' in a single line. > > net/vmw_vsock/af_vsock.c | 45 ++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 43 insertions(+), 2 deletions(-) Reviewed-by: Stefano Garzarella > >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >index ff44bab05191..a84f242466cf 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,33 @@ 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); >+ goto exit; >+ } >+ > switch (optname) { > case SO_VM_SOCKETS_BUFFER_SIZE: > COPY_IN(val); >@@ -2322,6 +2357,12 @@ static int vsock_create(struct net *net, struct socket *sock, > } > } > >+ /* SOCK_DGRAM doesn't have 'setsockopt' callback set in its >+ * proto_ops, so there is no handler for custom logic. >+ */ >+ if (sock_type_connectible(sock->type)) >+ set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags); >+ > vsock_insert_unbound(vsk); > > return 0; >-- >2.25.1 >