net/smc: keep static copy of system EID
authorKarsten Graul <kgraul@linux.ibm.com>
Tue, 14 Sep 2021 08:35:06 +0000 (10:35 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 14 Sep 2021 11:49:10 +0000 (12:49 +0100)
The system EID is retrieved using an registered ISM device each time
when needed. This adds some unnecessary complexity at all places where
the system EID is needed, but no ISM device is at hand.
Simplify the code and save the system EID in a static variable in
smc_ism.c.

Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
Reviewed-by: Guvenc Gulce <guvenc@linux.ibm.com>
Signed-off-by: Guvenc Gulce <guvenc@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/smc/af_smc.c
net/smc/smc_clc.c
net/smc/smc_core.c
net/smc/smc_ism.c
net/smc/smc_ism.h

index e5d62acbe40166e84efb7ab43803a991272b324a..f69ef3f2019fb126345f5cb52c8b53821707581d 100644 (file)
@@ -1565,7 +1565,7 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
        if (!ini->ism_dev[0])
                goto not_found;
 
-       smc_ism_get_system_eid(ini->ism_dev[0], &eid);
+       smc_ism_get_system_eid(&eid);
        if (!smc_clc_match_eid(ini->negotiated_eid, smc_v2_ext,
                               smcd_v2_ext->system_eid, eid))
                goto not_found;
index a3d99f894f52c65eacea0be4e81b7c1d470940a8..5a5ebf752860679770e24fe35a6e143dc509d00b 100644 (file)
@@ -796,10 +796,7 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
                                offsetofend(struct smc_clnt_opts_area_hdr,
                                            smcd_v2_ext_offset) +
                                v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN);
-               if (ini->ism_dev[0])
-                       smc_ism_get_system_eid(ini->ism_dev[0], &eid);
-               else
-                       smc_ism_get_system_eid(ini->ism_dev[1], &eid);
+               smc_ism_get_system_eid(&eid);
                if (eid && v2_ext->hdr.flag.seid)
                        memcpy(smcd_v2_ext->system_eid, eid, SMC_MAX_EID_LEN);
                plen += sizeof(*v2_ext) + sizeof(*smcd_v2_ext);
index af227b65669eb60bb5c2c87d8c020991d498b21b..4d0fcd8f8eba53ec35e34811e23391e1c9d3e602 100644 (file)
@@ -223,7 +223,6 @@ int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb)
        struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(cb);
        char hostname[SMC_MAX_HOSTNAME_LEN + 1];
        char smc_seid[SMC_MAX_EID_LEN + 1];
-       struct smcd_dev *smcd_dev;
        struct nlattr *attrs;
        u8 *seid = NULL;
        u8 *host = NULL;
@@ -252,13 +251,8 @@ int smc_nl_get_sys_info(struct sk_buff *skb, struct netlink_callback *cb)
                if (nla_put_string(skb, SMC_NLA_SYS_LOCAL_HOST, hostname))
                        goto errattr;
        }
-       mutex_lock(&smcd_dev_list.mutex);
-       smcd_dev = list_first_entry_or_null(&smcd_dev_list.list,
-                                           struct smcd_dev, list);
-       if (smcd_dev)
-               smc_ism_get_system_eid(smcd_dev, &seid);
-       mutex_unlock(&smcd_dev_list.mutex);
-       if (seid && smc_ism_is_v2_capable()) {
+       if (smc_ism_is_v2_capable()) {
+               smc_ism_get_system_eid(&seid);
                memcpy(smc_seid, seid, SMC_MAX_EID_LEN);
                smc_seid[SMC_MAX_EID_LEN] = 0;
                if (nla_put_string(skb, SMC_NLA_SYS_SEID, smc_seid))
index 9cb2df28996364ef297e975cbbe886c691af8d9f..fd28cc498b984b1bc9e7ac4bef313e36dc332243 100644 (file)
@@ -23,6 +23,7 @@ struct smcd_dev_list smcd_dev_list = {
 };
 
 static bool smc_ism_v2_capable;
+static u8 smc_ism_v2_system_eid[SMC_MAX_EID_LEN];
 
 /* Test if an ISM communication is possible - same CPC */
 int smc_ism_cantalk(u64 peer_gid, unsigned short vlan_id, struct smcd_dev *smcd)
@@ -42,9 +43,12 @@ int smc_ism_write(struct smcd_dev *smcd, const struct smc_ism_position *pos,
        return rc < 0 ? rc : 0;
 }
 
-void smc_ism_get_system_eid(struct smcd_dev *smcd, u8 **eid)
+void smc_ism_get_system_eid(u8 **eid)
 {
-       smcd->ops->get_system_eid(smcd, eid);
+       if (!smc_ism_v2_capable)
+               *eid = NULL;
+       else
+               *eid = smc_ism_v2_system_eid;
 }
 
 u16 smc_ism_get_chid(struct smcd_dev *smcd)
@@ -435,9 +439,12 @@ int smcd_register_dev(struct smcd_dev *smcd)
        if (list_empty(&smcd_dev_list.list)) {
                u8 *system_eid = NULL;
 
-               smc_ism_get_system_eid(smcd, &system_eid);
-               if (system_eid[24] != '0' || system_eid[28] != '0')
+               smcd->ops->get_system_eid(smcd, &system_eid);
+               if (system_eid[24] != '0' || system_eid[28] != '0') {
                        smc_ism_v2_capable = true;
+                       memcpy(smc_ism_v2_system_eid, system_eid,
+                              SMC_MAX_EID_LEN);
+               }
        }
        /* sort list: devices without pnetid before devices with pnetid */
        if (smcd->pnetid[0])
@@ -533,4 +540,5 @@ EXPORT_SYMBOL_GPL(smcd_handle_irq);
 void __init smc_ism_init(void)
 {
        smc_ism_v2_capable = false;
+       memset(smc_ism_v2_system_eid, 0, SMC_MAX_EID_LEN);
 }
index 113efc7352ed67b953105a8bf7ee6a95d9313bc8..004b22a13ffadde88cc93deac8295e4d0e1282bc 100644 (file)
@@ -48,7 +48,7 @@ int smc_ism_unregister_dmb(struct smcd_dev *dev, struct smc_buf_desc *dmb_desc);
 int smc_ism_write(struct smcd_dev *dev, const struct smc_ism_position *pos,
                  void *data, size_t len);
 int smc_ism_signal_shutdown(struct smc_link_group *lgr);
-void smc_ism_get_system_eid(struct smcd_dev *dev, u8 **eid);
+void smc_ism_get_system_eid(u8 **eid);
 u16 smc_ism_get_chid(struct smcd_dev *dev);
 bool smc_ism_is_v2_capable(void);
 void smc_ism_init(void);