Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1152523pxb; Thu, 28 Jan 2021 09:10:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJycpFrsdivl3LYsQMcsraOWn6tN+TUdPY6ssXQuXAvvMSTVEkm9kyGsFESUyAr2Xzp6sKkM X-Received: by 2002:a05:6402:4242:: with SMTP id g2mr558429edb.103.1611853820231; Thu, 28 Jan 2021 09:10:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611853820; cv=none; d=google.com; s=arc-20160816; b=W4QVB/5B/WnP1og3arq4v/FgGsjZWwjmMVY57Rw1ZaOc+cFfvRPa0LmjOqdlo8bW7k RdlFJcEYQZr/xrxWsnOB1ndXaE4zJsNgX2w+VTBJt4EbUW00rv61t486v24LJdJqVPxP CVvRLDBSJLoazXCrW7wXYlElun/VJYM5AH7P5J7Qc+ZJORUZoGenys5ykt+FoctVobB7 C9Bfbaj7W4A+A9Ez6/G2hpQY5FzsGNY73gGtlLfMLTmIylFsCn2+lTFngQPQueLwHVmx SqEMZ/lLxwhLcB3QREtmOOn9mKg1DFASEFcKAPbdAVck6gj3K0UPXg62x8fEYC4DRQim stoQ== 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=LvcQzCTMhw0EZfzlSb3F515FxbS4cvGqc8hLzWtIraw=; b=AHHjWsa/4Gx1b/yeAFUNyeAkctCXf99f/VJTLW7vesUzwJZC6wW63omSRzGx1u+Bnz zBYvdGV+dnALwvkyP+lsnHUXx9GxytDP9i7NyL2X6nJ2Vp2xKi472PKVu2F12em5Vk+p L5iSCQCRrrYtHramspuraCWFDWpNBsGEtGifsl685og/1qvE/Tbp5WKsW2Bn21yRJZAL +RKnLszs0rMpXw6a3XY3hGeIK75V6sF4319YuKG60kFBmE1AJwEj6i226H3YS1ZabFae SvjdP8CuV+o+4slFXHrUNBqQo+DzHcp+HE/XDUzBTw1/SRQgTSA5WabwZ3WFjOKqLncF a1oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JcDnJh5p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si3583850ede.192.2021.01.28.09.09.54; Thu, 28 Jan 2021 09:10:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JcDnJh5p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232493AbhA1RJQ (ORCPT + 99 others); Thu, 28 Jan 2021 12:09:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37736 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232824AbhA1RGA (ORCPT ); Thu, 28 Jan 2021 12:06:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611853473; 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=LvcQzCTMhw0EZfzlSb3F515FxbS4cvGqc8hLzWtIraw=; b=JcDnJh5pewXv5NoDV+Wsn4MLDtPKTQJHuCf1YH3OcwfNxXwsCoImJLW1YdIKyib2q8nluV a2hg3Pb7mAujnj0zj8AKS6UrscBXebqoLA06j/BJ9LDOVqJQ7WeUwy67X7YcuFrLIfDo97 dld42Mua92RJOIDALSNiLBW9n+aEwgc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-433-pDY4RnDlM7ak02jp2OvygQ-1; Thu, 28 Jan 2021 12:04:31 -0500 X-MC-Unique: pDY4RnDlM7ak02jp2OvygQ-1 Received: by mail-wr1-f69.google.com with SMTP id x12so3434898wrw.21 for ; Thu, 28 Jan 2021 09:04:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LvcQzCTMhw0EZfzlSb3F515FxbS4cvGqc8hLzWtIraw=; b=I45xR4aJ8MVFGxD5LqY2l0pdyDUIQa/x85prPdqCQQSilK9Byx4oD6fzAtCrX0IH6C xhOL+p1xuNzFRQ8WLkkFeE1RgWxt8Ck2U9wQbqg45Gd6ePaAktrkCNmBkevQ4CCrBsUc gSLvwKUlchSe26NqiMkhz8hNZrKRhyntk8XQMnGW3OsMVDMsunRUTregKZcOmEp8DXn2 i0GHuN5l4aCb9Ad3mmIradqefXF7r5xd+gy0kd+YDQwkTaz81PEE4X68T7dm65I48gS1 meK5GFZ31Q2Zlu5frFyUTeFIbu0eHziIXEMlVnfLEQZXrrodUZ4apvS4dlcI59mtkeqU gxLQ== X-Gm-Message-State: AOAM531wVKTHWia8qBcf8ADbAiTzcf63ZxhXV+gSMmNL033DCssCm2F+ kMjytll+/bW1rs/+VXYHvmM/QoViSDIL6FS/nfdD74aGoNKiE6y5S8zJxJng904uEutu1fhv6Ix qxc6ZFLTnCIWDsTYJnabpNJOR X-Received: by 2002:adf:9148:: with SMTP id j66mr47596wrj.28.1611853470441; Thu, 28 Jan 2021 09:04:30 -0800 (PST) X-Received: by 2002:adf:9148:: with SMTP id j66mr47572wrj.28.1611853470215; Thu, 28 Jan 2021 09:04:30 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id v4sm8574382wrw.42.2021.01.28.09.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jan 2021 09:04:29 -0800 (PST) Date: Thu, 28 Jan 2021 18:04:26 +0100 From: Stefano Garzarella To: Arseny Krasnov Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Andra Paraschiv , Colin Ian King , Jeff Vander Stoep , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stsp2@yandex.ru, oxffffaa@gmail.com Subject: Re: [RFC PATCH v3 05/13] af_vsock: rest of SEQPACKET support Message-ID: <20210128170426.522mpkocdd35bt2e@steredhat> References: <20210125110903.597155-1-arseny.krasnov@kaspersky.com> <20210125111321.598653-1-arseny.krasnov@kaspersky.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210125111321.598653-1-arseny.krasnov@kaspersky.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 25, 2021 at 02:13:18PM +0300, Arseny Krasnov wrote: >This does rest of SOCK_SEQPACKET support: >1) Adds socket ops for SEQPACKET type. >2) Allows to create socket with SEQPACKET type. > >Signed-off-by: Arseny Krasnov >--- > net/vmw_vsock/af_vsock.c | 71 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 71 insertions(+) > >diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c >index 4600c1ec3bb3..bbc3c31085aa 100644 >--- a/net/vmw_vsock/af_vsock.c >+++ b/net/vmw_vsock/af_vsock.c >@@ -452,6 +452,7 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) > new_transport = transport_dgram; > break; > case SOCK_STREAM: >+ case SOCK_SEQPACKET: > if (vsock_use_local_transport(remote_cid)) > new_transport = transport_local; > else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g || >@@ -459,6 +460,13 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk) > new_transport = transport_g2h; > else > new_transport = transport_h2g; >+ >+ if (sk->sk_type == SOCK_SEQPACKET) { I think you must also check that new_transport is not NULL. >+ if (!new_transport->seqpacket_seq_send_len || >+ !new_transport->seqpacket_seq_get_len || >+ !new_transport->seqpacket_dequeue) >+ return -ENODEV; I'm not sure about ENODEV is the better choice in this case, since the transport exists, but it doesn't support SOCK_SEQPACKET, so maybe is better ESOCKTNOSUPPORT. >+ } > break; > default: > return -ESOCKTNOSUPPORT; >@@ -684,6 +692,7 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr) > > switch (sk->sk_socket->type) { > case SOCK_STREAM: >+ case SOCK_SEQPACKET: > spin_lock_bh(&vsock_table_lock); > retval = __vsock_bind_connectible(vsk, addr); > spin_unlock_bh(&vsock_table_lock); >@@ -1406,6 +1415,12 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, > return vsock_connect(sock, addr, addr_len, flags); > } > >+static int vsock_seqpacket_connect(struct socket *sock, struct sockaddr *addr, >+ int addr_len, int flags) >+{ >+ return vsock_connect(sock, addr, addr_len, flags); >+} >+ > static int vsock_accept(struct socket *sock, struct socket *newsock, int flags, > bool kern) > { >@@ -1633,6 +1648,16 @@ static int vsock_stream_setsockopt(struct socket *sock, > optlen); > } > >+static int vsock_seqpacket_setsockopt(struct socket *sock, >+ int level, >+ int optname, >+ sockptr_t optval, >+ unsigned int optlen) >+{ >+ return vsock_connectible_setsockopt(sock, level, optname, optval, >+ optlen); >+} >+ > static int vsock_connectible_getsockopt(struct socket *sock, > int level, int optname, > char __user *optval, >@@ -1713,6 +1738,15 @@ static int vsock_stream_getsockopt(struct socket *sock, > optlen); > } > >+static int vsock_seqpacket_getsockopt(struct socket *sock, >+ int level, int optname, >+ char __user *optval, >+ int __user *optlen) >+{ >+ return vsock_connectible_getsockopt(sock, level, optname, optval, >+ optlen); >+} >+ > static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg, > size_t len) > { >@@ -1870,6 +1904,12 @@ static int vsock_stream_sendmsg(struct socket *sock, struct msghdr *msg, > return vsock_connectible_sendmsg(sock, msg, len); > } > >+static int vsock_seqpacket_sendmsg(struct socket *sock, struct msghdr *msg, >+ size_t len) >+{ >+ return vsock_connectible_sendmsg(sock, msg, len); >+} >+ > static int vsock_wait_data(struct sock *sk, struct wait_queue_entry *wait, > long timeout, > struct vsock_transport_recv_notify_data *recv_data, >@@ -2184,6 +2224,13 @@ vsock_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, > return vsock_connectible_recvmsg(sock, msg, len, flags); > } > >+static int >+vsock_seqpacket_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, >+ int flags) >+{ >+ return vsock_connectible_recvmsg(sock, msg, len, flags); >+} >+ As I said, I think you don't need to implement all of this helpers and you can directly assign the vsock_connectible_* functions in the 'vsock_seqpacket_ops'. > static const struct proto_ops vsock_stream_ops = { > .family = PF_VSOCK, > .owner = THIS_MODULE, >@@ -2205,6 +2252,27 @@ static const struct proto_ops vsock_stream_ops = { > .sendpage = sock_no_sendpage, > }; > >+static const struct proto_ops vsock_seqpacket_ops = { >+ .family = PF_VSOCK, >+ .owner = THIS_MODULE, >+ .release = vsock_release, >+ .bind = vsock_bind, >+ .connect = vsock_seqpacket_connect, >+ .socketpair = sock_no_socketpair, >+ .accept = vsock_accept, >+ .getname = vsock_getname, >+ .poll = vsock_poll, >+ .ioctl = sock_no_ioctl, >+ .listen = vsock_listen, >+ .shutdown = vsock_shutdown, >+ .setsockopt = vsock_seqpacket_setsockopt, >+ .getsockopt = vsock_seqpacket_getsockopt, >+ .sendmsg = vsock_seqpacket_sendmsg, >+ .recvmsg = vsock_seqpacket_recvmsg, >+ .mmap = sock_no_mmap, >+ .sendpage = sock_no_sendpage, >+}; >+ > static int vsock_create(struct net *net, struct socket *sock, > int protocol, int kern) > { >@@ -2225,6 +2293,9 @@ static int vsock_create(struct net *net, struct socket *sock, > case SOCK_STREAM: > sock->ops = &vsock_stream_ops; > break; >+ case SOCK_SEQPACKET: >+ sock->ops = &vsock_seqpacket_ops; >+ break; > default: > return -ESOCKTNOSUPPORT; > } >-- >2.25.1 >