net/smc: handle unregistered buffers
authorKarsten Graul <kgraul@linux.ibm.com>
Thu, 3 May 2018 15:57:38 +0000 (17:57 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 3 May 2018 18:47:31 +0000 (14:47 -0400)
When smc_wr_reg_send() fails then tag (regerr) the affected buffer and
free it in smc_buf_unuse().

Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: Ursula Braun <ubraun@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/smc/af_smc.c
net/smc/smc_core.c
net/smc/smc_core.h

index fdb2976117bd796128a8db41abac61ced9766b70..d03b8d29ffc05896ecc0beff941f97263e5c35a9 100644 (file)
@@ -296,8 +296,10 @@ static void smc_copy_sock_settings_to_smc(struct smc_sock *smc)
 static int smc_reg_rmb(struct smc_link *link, struct smc_buf_desc *rmb_desc)
 {
        /* register memory region for new rmb */
-       if (smc_wr_reg_send(link, rmb_desc->mr_rx[SMC_SINGLE_LINK]))
+       if (smc_wr_reg_send(link, rmb_desc->mr_rx[SMC_SINGLE_LINK])) {
+               rmb_desc->regerr = 1;
                return -EFAULT;
+       }
        return 0;
 }
 
index f44f6803f7ff2c8585caf555b7b4aea4168b680b..d4bd01bb44e1738dd7ea1a562b8f4be3295a324b 100644 (file)
@@ -32,6 +32,9 @@
 
 static u32 smc_lgr_num;                        /* unique link group number */
 
+static void smc_buf_free(struct smc_buf_desc *buf_desc, struct smc_link *lnk,
+                        bool is_rmb);
+
 static void smc_lgr_schedule_free_work(struct smc_link_group *lgr)
 {
        /* client link group creation always follows the server link group
@@ -234,9 +237,22 @@ static void smc_buf_unuse(struct smc_connection *conn)
                conn->sndbuf_size = 0;
        }
        if (conn->rmb_desc) {
-               conn->rmb_desc->reused = true;
-               conn->rmb_desc->used = 0;
-               conn->rmbe_size = 0;
+               if (!conn->rmb_desc->regerr) {
+                       conn->rmb_desc->reused = 1;
+                       conn->rmb_desc->used = 0;
+                       conn->rmbe_size = 0;
+               } else {
+                       /* buf registration failed, reuse not possible */
+                       struct smc_link_group *lgr = conn->lgr;
+                       struct smc_link *lnk;
+
+                       write_lock_bh(&lgr->rmbs_lock);
+                       list_del(&conn->rmb_desc->list);
+                       write_unlock_bh(&lgr->rmbs_lock);
+
+                       lnk = &lgr->lnk[SMC_SINGLE_LINK];
+                       smc_buf_free(conn->rmb_desc, lnk, true);
+               }
        }
 }
 
index 07e2a393e6d98b672d4160ff1486c0bd6e43df4b..5dfcb15d529f89c0d5bc9d9f28366c6539a072aa 100644 (file)
@@ -123,7 +123,8 @@ struct smc_buf_desc {
                                                 */
        u32                     order;          /* allocation order */
        u32                     used;           /* currently used / unused */
-       bool                    reused;         /* new created / reused */
+       u8                      reused  : 1;    /* new created / reused */
+       u8                      regerr  : 1;    /* err during registration */
 };
 
 struct smc_rtoken {                            /* address/key of remote RMB */