net/smc: Introduce a new conn->lgr validity check helper
authorWen Gu <guwen@linux.alibaba.com>
Thu, 13 Jan 2022 08:36:41 +0000 (16:36 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Jan 2022 13:14:53 +0000 (13:14 +0000)
It is no longer suitable to identify whether a smc connection
is registered in a link group through checking if conn->lgr
is NULL, because conn->lgr won't be reset even the connection
is unregistered from a link group.

So this patch introduces a new helper smc_conn_lgr_valid() and
replaces all the check of conn->lgr in original implementation
with the new helper to judge if conn->lgr is valid to use.

Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/smc/af_smc.c
net/smc/smc_cdc.c
net/smc/smc_clc.c
net/smc/smc_core.c
net/smc/smc_core.h
net/smc/smc_diag.c

index aa3bcaaeabf759e80c370164e4f0bb55f2c84899..961854e56736642cbec3d323296d26fd905aff78 100644 (file)
@@ -634,9 +634,13 @@ static void smc_conn_abort(struct smc_sock *smc, int local_first)
 {
        struct smc_connection *conn = &smc->conn;
        struct smc_link_group *lgr = conn->lgr;
+       bool lgr_valid = false;
+
+       if (smc_conn_lgr_valid(conn))
+               lgr_valid = true;
 
        smc_conn_free(conn);
-       if (local_first)
+       if (local_first && lgr_valid)
                smc_lgr_cleanup_early(lgr);
 }
 
index 84c8a4374fddda312fb244dc654302f97f1e39ac..9d5a971689695d508df2e41fea24bae4805ffea4 100644 (file)
@@ -197,7 +197,8 @@ int smc_cdc_get_slot_and_msg_send(struct smc_connection *conn)
 {
        int rc;
 
-       if (!conn->lgr || (conn->lgr->is_smcd && conn->lgr->peer_shutdown))
+       if (!smc_conn_lgr_valid(conn) ||
+           (conn->lgr->is_smcd && conn->lgr->peer_shutdown))
                return -EPIPE;
 
        if (conn->lgr->is_smcd) {
index 6be95a2a7b2515216eef177b45bb02af8c4fc208..ce27399b38b1ec2dc240a746af93fe86c18dbedf 100644 (file)
@@ -774,7 +774,7 @@ int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version)
        dclc.os_type = version == SMC_V1 ? 0 : SMC_CLC_OS_LINUX;
        dclc.hdr.typev2 = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ?
                                                SMC_FIRST_CONTACT_MASK : 0;
-       if ((!smc->conn.lgr || !smc->conn.lgr->is_smcd) &&
+       if ((!smc_conn_lgr_valid(&smc->conn) || !smc->conn.lgr->is_smcd) &&
            smc_ib_is_valid_local_systemid())
                memcpy(dclc.id_for_peer, local_systemid,
                       sizeof(local_systemid));
index fcb5e15bfa959be1e3384db7e97ccb755679c6c7..2096841d91ef4d4278740a1d4fb5aed774525252 100644 (file)
@@ -211,7 +211,7 @@ static void smc_lgr_unregister_conn(struct smc_connection *conn)
 {
        struct smc_link_group *lgr = conn->lgr;
 
-       if (!lgr)
+       if (!smc_conn_lgr_valid(conn))
                return;
        write_lock_bh(&lgr->conns_lock);
        if (conn->alert_token_local) {
@@ -1139,7 +1139,7 @@ void smc_conn_free(struct smc_connection *conn)
                return;
 
        conn->freed = 1;
-       if (!conn->alert_token_local)
+       if (!smc_conn_lgr_valid(conn))
                /* Connection has already unregistered from
                 * link group.
                 */
@@ -2278,14 +2278,16 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
 
 void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn)
 {
-       if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk))
+       if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd ||
+           !smc_link_active(conn->lnk))
                return;
        smc_ib_sync_sg_for_cpu(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE);
 }
 
 void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn)
 {
-       if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk))
+       if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd ||
+           !smc_link_active(conn->lnk))
                return;
        smc_ib_sync_sg_for_device(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE);
 }
@@ -2294,7 +2296,7 @@ void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn)
 {
        int i;
 
-       if (!conn->lgr || conn->lgr->is_smcd)
+       if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd)
                return;
        for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
                if (!smc_link_active(&conn->lgr->lnk[i]))
@@ -2308,7 +2310,7 @@ void smc_rmb_sync_sg_for_device(struct smc_connection *conn)
 {
        int i;
 
-       if (!conn->lgr || conn->lgr->is_smcd)
+       if (!smc_conn_lgr_valid(conn) || conn->lgr->is_smcd)
                return;
        for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
                if (!smc_link_active(&conn->lgr->lnk[i]))
index f8b5397a9dbe7634b8c8a62b2e350964dc2209eb..599455d00020ebdb95eb086a4e440d91e3e59c7d 100644 (file)
@@ -410,6 +410,11 @@ static inline struct smc_connection *smc_lgr_find_conn(
        return res;
 }
 
+static inline bool smc_conn_lgr_valid(struct smc_connection *conn)
+{
+       return conn->lgr && conn->alert_token_local;
+}
+
 /*
  * Returns true if the specified link is usable.
  *
index 7c8dad28c18df73d966f5c90c59f3a7ded033437..b8898c787d233cc0e18af0caeade68dfb89fefab 100644 (file)
@@ -89,7 +89,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
        r->diag_state = sk->sk_state;
        if (smc->use_fallback)
                r->diag_mode = SMC_DIAG_MODE_FALLBACK_TCP;
-       else if (smc->conn.lgr && smc->conn.lgr->is_smcd)
+       else if (smc_conn_lgr_valid(&smc->conn) && smc->conn.lgr->is_smcd)
                r->diag_mode = SMC_DIAG_MODE_SMCD;
        else
                r->diag_mode = SMC_DIAG_MODE_SMCR;
@@ -142,7 +142,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
                        goto errout;
        }
 
-       if (smc->conn.lgr && !smc->conn.lgr->is_smcd &&
+       if (smc_conn_lgr_valid(&smc->conn) && !smc->conn.lgr->is_smcd &&
            (req->diag_ext & (1 << (SMC_DIAG_LGRINFO - 1))) &&
            !list_empty(&smc->conn.lgr->list)) {
                struct smc_link *link = smc->conn.lnk;
@@ -164,7 +164,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb,
                if (nla_put(skb, SMC_DIAG_LGRINFO, sizeof(linfo), &linfo) < 0)
                        goto errout;
        }
-       if (smc->conn.lgr && smc->conn.lgr->is_smcd &&
+       if (smc_conn_lgr_valid(&smc->conn) && smc->conn.lgr->is_smcd &&
            (req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) &&
            !list_empty(&smc->conn.lgr->list)) {
                struct smc_connection *conn = &smc->conn;