Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5886638iob; Tue, 10 May 2022 06:05:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzRH7Sw75UQkaYPkqRDubOccL9AWjUmG09b2qNQxTUw0LofCx8ICY1uyUuNaCdPhuD+yHH X-Received: by 2002:a17:907:97d5:b0:6f5:405:ef01 with SMTP id js21-20020a17090797d500b006f50405ef01mr19131034ejc.551.1652187950428; Tue, 10 May 2022 06:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652187950; cv=none; d=google.com; s=arc-20160816; b=xl6Ww/5qtIC9mCPQxs0Lw9tUaX0wRDqM6X01rkeMdYY0mJlLelMQU5HTisRljp9I8k 9oEtTIhrWgP7uAcNczK/1idyfYiy2kdKlCVo1cAmW1tnPY4UdkR3/BVfbXugWmW4w/5I y0r+rXco7vx1pmyTzaHBB1c+dxpIZ7ouRFJiORO0LL8u2/+mRz0PoTiCvM8mYdivaUYC W4tSGhHItzncwc43k6PhUVs7tV++5TBve9zmXlx1Ptxd8jqsg+Roq5kTW9aMS7CX6r0U BaIBU9rT778xwvCnCez1NYuTDo5lPqDQvA2bo+Xow9y2NsvLN8uw9nR+OcI5+wdIuKW0 pKKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=L879vTuOytFC1BBKCpJazjTgxv9uvQMbOkHnTde3iP0=; b=qMVfI5sw9zzwYUaPZ6LW1ocjxFI4SukdbQPjo2QT/nfsJavyGkcx29C2dx0jmjD53F SM0CdbZySkehOUhDipjpWfhT6XOalIVkZMYFtvGqHm9Kp3Mxf7k/lXPNbqxdP7F18M0Z GJm9bhqE3AeoY9QlEGhtut4mBrh1x97mtEB9iUUX58I1srS+ArmQaU9nM9tMB3vbUffw lyKE6NcYcWWg0AwQkbA8zdBb/caMQhqa4EVsTi2BqHlhmata+n/roD4xkobExRLHAhcE NdokBXfj679w0ybkvPBhI+ut/GwC3t51BB9RNil0aZmiIvVyoe9hwIwqSAYL1X2j6Ut9 fTVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i07ENLqt; 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 nb10-20020a1709071c8a00b006f3e70bb598si20292660ejc.441.2022.05.10.06.05.25; Tue, 10 May 2022 06:05:50 -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=i07ENLqt; 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 S240628AbiEJLJd (ORCPT + 99 others); Tue, 10 May 2022 07:09:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234466AbiEJLJa (ORCPT ); Tue, 10 May 2022 07:09:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E50C92B09C4 for ; Tue, 10 May 2022 04:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652180732; 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=L879vTuOytFC1BBKCpJazjTgxv9uvQMbOkHnTde3iP0=; b=i07ENLqtRaDhxffSwKtXLKGjpaF0zgacDIAz9ZFjAFDKT7dYIhveO9bV/M/sr/hMaMhmeT oD+gWrOC/pjwjZf9Z3ojq/mbIHc4GZaLdtDyYCIDdutumwD2eC/IPRTvmn5BB3RFitwt6K gwrXJPdPA1Ufje5CNmSRCcZHMjTyX80= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-2ZUVdvP-NqGlHet2ZKjnOA-1; Tue, 10 May 2022 07:05:30 -0400 X-MC-Unique: 2ZUVdvP-NqGlHet2ZKjnOA-1 Received: by mail-qv1-f71.google.com with SMTP id d13-20020a05621421cd00b0045a99874ae5so13973735qvh.14 for ; Tue, 10 May 2022 04:05:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=L879vTuOytFC1BBKCpJazjTgxv9uvQMbOkHnTde3iP0=; b=jKTNVO0+QQJtnORwSmucmX+aJjstaZKtsT+LPSw9MWrG67DKEQLdQd50oYW8uR4ibr rAndbWY3IVoCfWB68PX02HXskErHaWWoTDox6X5u3mkEeAp+vzlc39NeTRZ5DzFknNaF PTvCvFOsec4NdZuGVcKzBOwbL0OnCvrGAvrRgPgT6qKVIXbTsW24pjju2GmX9e45etzZ ZHUJ17zF+uhuHDDJ1DhuQiTHjJG5RXiT0waKmodyYEZvazj0I7Q+Ebvjt3FuJnLf+hSD vNt7SBKGzIlhTUIxSPo9Bh1ezyiRCMPpRLMfb6iR2tR8u6ph54C3Hwt2QRxpZd0ZIoV5 m+xQ== X-Gm-Message-State: AOAM530TmK/v65tUwhPaNTknVJN+2jMo9Zl+Th/RbisfldvSCzCJ6Io0 oa3jvo7ymlAsesfhbUR3RRy97thRZUc9aOrtob30mzf/bvhuxqjfSV5m3RVZoVLMv+pWlSAups6 Hg7eU+5Mp/VtqF66zu6SRqjsr X-Received: by 2002:ac8:7f04:0:b0:2f3:d6d6:8406 with SMTP id f4-20020ac87f04000000b002f3d6d68406mr10162347qtk.509.1652180729598; Tue, 10 May 2022 04:05:29 -0700 (PDT) X-Received: by 2002:ac8:7f04:0:b0:2f3:d6d6:8406 with SMTP id f4-20020ac87f04000000b002f3d6d68406mr10162321qtk.509.1652180729321; Tue, 10 May 2022 04:05:29 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-113-89.dyn.eolo.it. [146.241.113.89]) by smtp.gmail.com with ESMTPSA id g12-20020ac842cc000000b002f39b99f678sm9342697qtm.18.2022.05.10.04.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 04:05:27 -0700 (PDT) Message-ID: Subject: Re: [PATCH net 2/2] net/smc: align the connect behaviour with TCP From: Paolo Abeni To: Guangguan Wang , kgraul@linux.ibm.com, davem@davemloft.net, kuba@kernel.org Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 10 May 2022 13:05:24 +0200 In-Reply-To: <20220509115837.94911-3-guangguan.wang@linux.alibaba.com> References: <20220509115837.94911-1-guangguan.wang@linux.alibaba.com> <20220509115837.94911-3-guangguan.wang@linux.alibaba.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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 Mon, 2022-05-09 at 19:58 +0800, Guangguan Wang wrote: > Connect with O_NONBLOCK will not be completed immediately > and returns -EINPROGRESS. It is possible to use selector/poll > for completion by selecting the socket for writing. After select > indicates writability, a second connect function call will return > 0 to indicate connected successfully as TCP does, but smc returns > -EISCONN. Use socket state for smc to indicate connect state, which > can help smc aligning the connect behaviour with TCP. > > Signed-off-by: Guangguan Wang > --- > net/smc/af_smc.c | 53 ++++++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 49 insertions(+), 4 deletions(-) > > diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c > index fce16b9d6e1a..45f9f7c6e776 100644 > --- a/net/smc/af_smc.c > +++ b/net/smc/af_smc.c > @@ -1544,9 +1544,32 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, > goto out_err; > > lock_sock(sk); > + switch (sock->state) { > + default: > + rc = -EINVAL; > + goto out; > + case SS_CONNECTED: > + rc = sk->sk_state == SMC_ACTIVE ? -EISCONN : -EINVAL; > + goto out; > + case SS_CONNECTING: > + if (sk->sk_state == SMC_ACTIVE) { > + sock->state = SS_CONNECTED; > + rc = 0; > + goto out; > + } > + break; > + case SS_UNCONNECTED: > + sock->state = SS_CONNECTING; > + break; > + } > + > switch (sk->sk_state) { > default: > goto out; > + case SMC_CLOSED: > + rc = sock_error(sk) ? : -ECONNABORTED; > + sock->state = SS_UNCONNECTED; > + goto out; > case SMC_ACTIVE: > rc = -EISCONN; > goto out; > @@ -1565,18 +1588,22 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, > goto out; > > sock_hold(&smc->sk); /* sock put in passive closing */ > - if (smc->use_fallback) > + if (smc->use_fallback) { > + sock->state = SS_CONNECTED; > goto out; > + } > if (flags & O_NONBLOCK) { > if (queue_work(smc_hs_wq, &smc->connect_work)) > smc->connect_nonblock = 1; > rc = -EINPROGRESS; > } else { > rc = __smc_connect(smc); > - if (rc < 0) > + if (rc < 0) { > goto out; > - else > + } else { > rc = 0; /* success cases including fallback */ > + sock->state = SS_CONNECTED; 'else' is not needed here, you can keep the above 2 statements dropping an indentation level. > + } > } > You can avoid a little code duplication adding here the following: connected: sock->state = SS_CONNECTED; and using the new label where appropriate. > out: > @@ -1693,6 +1720,7 @@ struct sock *smc_accept_dequeue(struct sock *parent, > } > if (new_sock) { > sock_graft(new_sk, new_sock); > + new_sock->state = SS_CONNECTED; > if (isk->use_fallback) { > smc_sk(new_sk)->clcsock->file = new_sock->file; > isk->clcsock->file->private_data = isk->clcsock; > @@ -2424,7 +2452,7 @@ static int smc_listen(struct socket *sock, int backlog) > > rc = -EINVAL; > if ((sk->sk_state != SMC_INIT && sk->sk_state != SMC_LISTEN) || > - smc->connect_nonblock) > + smc->connect_nonblock || sock->state != SS_UNCONNECTED) > goto out; > > rc = 0; > @@ -2716,6 +2744,17 @@ static int smc_shutdown(struct socket *sock, int how) > > lock_sock(sk); > > + if (sock->state == SS_CONNECTING) { > + if (sk->sk_state == SMC_ACTIVE) > + sock->state = SS_CONNECTED; > + else if (sk->sk_state == SMC_PEERCLOSEWAIT1 || > + sk->sk_state == SMC_PEERCLOSEWAIT2 || > + sk->sk_state == SMC_APPCLOSEWAIT1 || > + sk->sk_state == SMC_APPCLOSEWAIT2 || > + sk->sk_state == SMC_APPFINCLOSEWAIT) > + sock->state = SS_DISCONNECTING; > + } > + > rc = -ENOTCONN; > if ((sk->sk_state != SMC_ACTIVE) && > (sk->sk_state != SMC_PEERCLOSEWAIT1) && > @@ -2729,6 +2768,7 @@ static int smc_shutdown(struct socket *sock, int how) > sk->sk_shutdown = smc->clcsock->sk->sk_shutdown; > if (sk->sk_shutdown == SHUTDOWN_MASK) { > sk->sk_state = SMC_CLOSED; > + sk->sk_socket->state = SS_UNCONNECTED; > sock_put(sk); > } > goto out; > @@ -2754,6 +2794,10 @@ static int smc_shutdown(struct socket *sock, int how) > /* map sock_shutdown_cmd constants to sk_shutdown value range */ > sk->sk_shutdown |= how + 1; > > + if (sk->sk_state == SMC_CLOSED) > + sock->state = SS_UNCONNECTED; > + else > + sock->state = SS_DISCONNECTING; > out: > release_sock(sk); > return rc ? rc : rc1; > @@ -3139,6 +3183,7 @@ static int __smc_create(struct net *net, struct socket *sock, int protocol, > > rc = -ENOBUFS; > sock->ops = &smc_sock_ops; > + sock->state = SS_UNCONNECTED; > sk = smc_sock_alloc(net, sock, protocol); > if (!sk) > goto out;