| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * CLC (connection layer control) handshake over initial TCP socket to |
| 6 | * prepare for RDMA traffic |
| 7 | * |
| 8 | * Copyright IBM Corp. 2016, 2018 |
| 9 | * |
| 10 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/in.h> |
| 14 | #include <linux/inetdevice.h> |
| 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/sched/signal.h> |
| 17 | #include <linux/utsname.h> |
| 18 | #include <linux/ctype.h> |
| 19 | |
| 20 | #include <net/addrconf.h> |
| 21 | #include <net/sock.h> |
| 22 | #include <net/tcp.h> |
| 23 | |
| 24 | #include "smc.h" |
| 25 | #include "smc_core.h" |
| 26 | #include "smc_clc.h" |
| 27 | #include "smc_ib.h" |
| 28 | #include "smc_ism.h" |
| 29 | #include "smc_netlink.h" |
| 30 | |
| 31 | #define SMCR_CLC_ACCEPT_CONFIRM_LEN 68 |
| 32 | #define SMCD_CLC_ACCEPT_CONFIRM_LEN 48 |
| 33 | #define SMCD_CLC_ACCEPT_CONFIRM_LEN_V2 78 |
| 34 | #define SMCR_CLC_ACCEPT_CONFIRM_LEN_V2 108 |
| 35 | #define SMC_CLC_RECV_BUF_LEN 100 |
| 36 | |
| 37 | /* eye catcher "SMCR" EBCDIC for CLC messages */ |
| 38 | static const char SMC_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xd9'}; |
| 39 | /* eye catcher "SMCD" EBCDIC for CLC messages */ |
| 40 | static const char SMCD_EYECATCHER[4] = {'\xe2', '\xd4', '\xc3', '\xc4'}; |
| 41 | |
| 42 | static u8 smc_hostname[SMC_MAX_HOSTNAME_LEN]; |
| 43 | |
| 44 | struct smc_clc_eid_table { |
| 45 | rwlock_t lock; |
| 46 | struct list_head list; |
| 47 | u8 ueid_cnt; |
| 48 | u8 seid_enabled; |
| 49 | }; |
| 50 | |
| 51 | static struct smc_clc_eid_table smc_clc_eid_table; |
| 52 | |
| 53 | struct smc_clc_eid_entry { |
| 54 | struct list_head list; |
| 55 | u8 eid[SMC_MAX_EID_LEN]; |
| 56 | }; |
| 57 | |
| 58 | /* The size of a user EID is 32 characters. |
| 59 | * Valid characters should be (single-byte character set) A-Z, 0-9, '.' and '-'. |
| 60 | * Blanks should only be used to pad to the expected size. |
| 61 | * First character must be alphanumeric. |
| 62 | */ |
| 63 | static bool smc_clc_ueid_valid(char *ueid) |
| 64 | { |
| 65 | char *end = ueid + SMC_MAX_EID_LEN; |
| 66 | |
| 67 | while (--end >= ueid && isspace(*end)) |
| 68 | ; |
| 69 | if (end < ueid) |
| 70 | return false; |
| 71 | if (!isalnum(*ueid) || islower(*ueid)) |
| 72 | return false; |
| 73 | while (ueid <= end) { |
| 74 | if ((!isalnum(*ueid) || islower(*ueid)) && *ueid != '.' && |
| 75 | *ueid != '-') |
| 76 | return false; |
| 77 | ueid++; |
| 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | static int smc_clc_ueid_add(char *ueid) |
| 83 | { |
| 84 | struct smc_clc_eid_entry *new_ueid, *tmp_ueid; |
| 85 | int rc; |
| 86 | |
| 87 | if (!smc_clc_ueid_valid(ueid)) |
| 88 | return -EINVAL; |
| 89 | |
| 90 | /* add a new ueid entry to the ueid table if there isn't one */ |
| 91 | new_ueid = kzalloc(sizeof(*new_ueid), GFP_KERNEL); |
| 92 | if (!new_ueid) |
| 93 | return -ENOMEM; |
| 94 | memcpy(new_ueid->eid, ueid, SMC_MAX_EID_LEN); |
| 95 | |
| 96 | write_lock(&smc_clc_eid_table.lock); |
| 97 | if (smc_clc_eid_table.ueid_cnt >= SMC_MAX_UEID) { |
| 98 | rc = -ERANGE; |
| 99 | goto err_out; |
| 100 | } |
| 101 | list_for_each_entry(tmp_ueid, &smc_clc_eid_table.list, list) { |
| 102 | if (!memcmp(p: tmp_ueid->eid, q: ueid, SMC_MAX_EID_LEN)) { |
| 103 | rc = -EEXIST; |
| 104 | goto err_out; |
| 105 | } |
| 106 | } |
| 107 | list_add_tail(new: &new_ueid->list, head: &smc_clc_eid_table.list); |
| 108 | smc_clc_eid_table.ueid_cnt++; |
| 109 | write_unlock(&smc_clc_eid_table.lock); |
| 110 | return 0; |
| 111 | |
| 112 | err_out: |
| 113 | write_unlock(&smc_clc_eid_table.lock); |
| 114 | kfree(objp: new_ueid); |
| 115 | return rc; |
| 116 | } |
| 117 | |
| 118 | int smc_clc_ueid_count(void) |
| 119 | { |
| 120 | int count; |
| 121 | |
| 122 | read_lock(&smc_clc_eid_table.lock); |
| 123 | count = smc_clc_eid_table.ueid_cnt; |
| 124 | read_unlock(&smc_clc_eid_table.lock); |
| 125 | |
| 126 | return count; |
| 127 | } |
| 128 | |
| 129 | int smc_nl_add_ueid(struct sk_buff *skb, struct genl_info *info) |
| 130 | { |
| 131 | struct nlattr *nla_ueid = info->attrs[SMC_NLA_EID_TABLE_ENTRY]; |
| 132 | char *ueid; |
| 133 | |
| 134 | if (!nla_ueid || nla_len(nla: nla_ueid) != SMC_MAX_EID_LEN + 1) |
| 135 | return -EINVAL; |
| 136 | ueid = (char *)nla_data(nla: nla_ueid); |
| 137 | |
| 138 | return smc_clc_ueid_add(ueid); |
| 139 | } |
| 140 | |
| 141 | /* remove one or all ueid entries from the table */ |
| 142 | static int smc_clc_ueid_remove(char *ueid) |
| 143 | { |
| 144 | struct smc_clc_eid_entry *lst_ueid, *tmp_ueid; |
| 145 | int rc = -ENOENT; |
| 146 | |
| 147 | /* remove table entry */ |
| 148 | write_lock(&smc_clc_eid_table.lock); |
| 149 | list_for_each_entry_safe(lst_ueid, tmp_ueid, &smc_clc_eid_table.list, |
| 150 | list) { |
| 151 | if (!ueid || !memcmp(p: lst_ueid->eid, q: ueid, SMC_MAX_EID_LEN)) { |
| 152 | list_del(entry: &lst_ueid->list); |
| 153 | smc_clc_eid_table.ueid_cnt--; |
| 154 | kfree(objp: lst_ueid); |
| 155 | rc = 0; |
| 156 | } |
| 157 | } |
| 158 | #if IS_ENABLED(CONFIG_S390) |
| 159 | if (!rc && !smc_clc_eid_table.ueid_cnt) { |
| 160 | smc_clc_eid_table.seid_enabled = 1; |
| 161 | rc = -EAGAIN; /* indicate success and enabling of seid */ |
| 162 | } |
| 163 | #endif |
| 164 | write_unlock(&smc_clc_eid_table.lock); |
| 165 | return rc; |
| 166 | } |
| 167 | |
| 168 | int smc_nl_remove_ueid(struct sk_buff *skb, struct genl_info *info) |
| 169 | { |
| 170 | struct nlattr *nla_ueid = info->attrs[SMC_NLA_EID_TABLE_ENTRY]; |
| 171 | char *ueid; |
| 172 | |
| 173 | if (!nla_ueid || nla_len(nla: nla_ueid) != SMC_MAX_EID_LEN + 1) |
| 174 | return -EINVAL; |
| 175 | ueid = (char *)nla_data(nla: nla_ueid); |
| 176 | |
| 177 | return smc_clc_ueid_remove(ueid); |
| 178 | } |
| 179 | |
| 180 | int smc_nl_flush_ueid(struct sk_buff *skb, struct genl_info *info) |
| 181 | { |
| 182 | smc_clc_ueid_remove(NULL); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int smc_nl_ueid_dumpinfo(struct sk_buff *skb, u32 portid, u32 seq, |
| 187 | u32 flags, char *ueid) |
| 188 | { |
| 189 | char ueid_str[SMC_MAX_EID_LEN + 1]; |
| 190 | void *hdr; |
| 191 | |
| 192 | hdr = genlmsg_put(skb, portid, seq, family: &smc_gen_nl_family, |
| 193 | flags, cmd: SMC_NETLINK_DUMP_UEID); |
| 194 | if (!hdr) |
| 195 | return -ENOMEM; |
| 196 | memcpy(ueid_str, ueid, SMC_MAX_EID_LEN); |
| 197 | ueid_str[SMC_MAX_EID_LEN] = 0; |
| 198 | if (nla_put_string(skb, attrtype: SMC_NLA_EID_TABLE_ENTRY, str: ueid_str)) { |
| 199 | genlmsg_cancel(skb, hdr); |
| 200 | return -EMSGSIZE; |
| 201 | } |
| 202 | genlmsg_end(skb, hdr); |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | static int _smc_nl_ueid_dump(struct sk_buff *skb, u32 portid, u32 seq, |
| 207 | int start_idx) |
| 208 | { |
| 209 | struct smc_clc_eid_entry *lst_ueid; |
| 210 | int idx = 0; |
| 211 | |
| 212 | read_lock(&smc_clc_eid_table.lock); |
| 213 | list_for_each_entry(lst_ueid, &smc_clc_eid_table.list, list) { |
| 214 | if (idx++ < start_idx) |
| 215 | continue; |
| 216 | if (smc_nl_ueid_dumpinfo(skb, portid, seq, NLM_F_MULTI, |
| 217 | ueid: lst_ueid->eid)) { |
| 218 | --idx; |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | read_unlock(&smc_clc_eid_table.lock); |
| 223 | return idx; |
| 224 | } |
| 225 | |
| 226 | int smc_nl_dump_ueid(struct sk_buff *skb, struct netlink_callback *cb) |
| 227 | { |
| 228 | struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(c: cb); |
| 229 | int idx; |
| 230 | |
| 231 | idx = _smc_nl_ueid_dump(skb, NETLINK_CB(cb->skb).portid, |
| 232 | seq: cb->nlh->nlmsg_seq, start_idx: cb_ctx->pos[0]); |
| 233 | |
| 234 | cb_ctx->pos[0] = idx; |
| 235 | return skb->len; |
| 236 | } |
| 237 | |
| 238 | int smc_nl_dump_seid(struct sk_buff *skb, struct netlink_callback *cb) |
| 239 | { |
| 240 | struct smc_nl_dmp_ctx *cb_ctx = smc_nl_dmp_ctx(c: cb); |
| 241 | char seid_str[SMC_MAX_EID_LEN + 1]; |
| 242 | u8 seid_enabled; |
| 243 | void *hdr; |
| 244 | u8 *seid; |
| 245 | |
| 246 | if (cb_ctx->pos[0]) |
| 247 | return skb->len; |
| 248 | |
| 249 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, seq: cb->nlh->nlmsg_seq, |
| 250 | family: &smc_gen_nl_family, NLM_F_MULTI, |
| 251 | cmd: SMC_NETLINK_DUMP_SEID); |
| 252 | if (!hdr) |
| 253 | return -ENOMEM; |
| 254 | if (!smc_ism_is_v2_capable()) |
| 255 | goto end; |
| 256 | |
| 257 | smc_ism_get_system_eid(eid: &seid); |
| 258 | memcpy(seid_str, seid, SMC_MAX_EID_LEN); |
| 259 | seid_str[SMC_MAX_EID_LEN] = 0; |
| 260 | if (nla_put_string(skb, attrtype: SMC_NLA_SEID_ENTRY, str: seid_str)) |
| 261 | goto err; |
| 262 | read_lock(&smc_clc_eid_table.lock); |
| 263 | seid_enabled = smc_clc_eid_table.seid_enabled; |
| 264 | read_unlock(&smc_clc_eid_table.lock); |
| 265 | if (nla_put_u8(skb, attrtype: SMC_NLA_SEID_ENABLED, value: seid_enabled)) |
| 266 | goto err; |
| 267 | end: |
| 268 | genlmsg_end(skb, hdr); |
| 269 | cb_ctx->pos[0]++; |
| 270 | return skb->len; |
| 271 | err: |
| 272 | genlmsg_cancel(skb, hdr); |
| 273 | return -EMSGSIZE; |
| 274 | } |
| 275 | |
| 276 | int smc_nl_enable_seid(struct sk_buff *skb, struct genl_info *info) |
| 277 | { |
| 278 | #if IS_ENABLED(CONFIG_S390) |
| 279 | write_lock(&smc_clc_eid_table.lock); |
| 280 | smc_clc_eid_table.seid_enabled = 1; |
| 281 | write_unlock(&smc_clc_eid_table.lock); |
| 282 | return 0; |
| 283 | #else |
| 284 | return -EOPNOTSUPP; |
| 285 | #endif |
| 286 | } |
| 287 | |
| 288 | int smc_nl_disable_seid(struct sk_buff *skb, struct genl_info *info) |
| 289 | { |
| 290 | int rc = 0; |
| 291 | |
| 292 | #if IS_ENABLED(CONFIG_S390) |
| 293 | write_lock(&smc_clc_eid_table.lock); |
| 294 | if (!smc_clc_eid_table.ueid_cnt) |
| 295 | rc = -ENOENT; |
| 296 | else |
| 297 | smc_clc_eid_table.seid_enabled = 0; |
| 298 | write_unlock(&smc_clc_eid_table.lock); |
| 299 | #else |
| 300 | rc = -EOPNOTSUPP; |
| 301 | #endif |
| 302 | return rc; |
| 303 | } |
| 304 | |
| 305 | static bool _smc_clc_match_ueid(u8 *peer_ueid) |
| 306 | { |
| 307 | struct smc_clc_eid_entry *tmp_ueid; |
| 308 | |
| 309 | list_for_each_entry(tmp_ueid, &smc_clc_eid_table.list, list) { |
| 310 | if (!memcmp(p: tmp_ueid->eid, q: peer_ueid, SMC_MAX_EID_LEN)) |
| 311 | return true; |
| 312 | } |
| 313 | return false; |
| 314 | } |
| 315 | |
| 316 | bool smc_clc_match_eid(u8 *negotiated_eid, |
| 317 | struct smc_clc_v2_extension *smc_v2_ext, |
| 318 | u8 *peer_eid, u8 *local_eid) |
| 319 | { |
| 320 | bool match = false; |
| 321 | int i; |
| 322 | |
| 323 | negotiated_eid[0] = 0; |
| 324 | read_lock(&smc_clc_eid_table.lock); |
| 325 | if (peer_eid && local_eid && |
| 326 | smc_clc_eid_table.seid_enabled && |
| 327 | smc_v2_ext->hdr.flag.seid && |
| 328 | !memcmp(p: peer_eid, q: local_eid, SMC_MAX_EID_LEN)) { |
| 329 | memcpy(negotiated_eid, peer_eid, SMC_MAX_EID_LEN); |
| 330 | match = true; |
| 331 | goto out; |
| 332 | } |
| 333 | |
| 334 | for (i = 0; i < smc_v2_ext->hdr.eid_cnt; i++) { |
| 335 | if (_smc_clc_match_ueid(peer_ueid: smc_v2_ext->user_eids[i])) { |
| 336 | memcpy(negotiated_eid, smc_v2_ext->user_eids[i], |
| 337 | SMC_MAX_EID_LEN); |
| 338 | match = true; |
| 339 | goto out; |
| 340 | } |
| 341 | } |
| 342 | out: |
| 343 | read_unlock(&smc_clc_eid_table.lock); |
| 344 | return match; |
| 345 | } |
| 346 | |
| 347 | /* check arriving CLC proposal */ |
| 348 | static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc) |
| 349 | { |
| 350 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 351 | struct smc_clc_smcd_v2_extension *smcd_v2_ext; |
| 352 | struct smc_clc_msg_hdr *hdr = &pclc->hdr; |
| 353 | struct smc_clc_v2_extension *v2_ext; |
| 354 | |
| 355 | pclc_prfx = smc_clc_proposal_get_prefix(pclc); |
| 356 | if (!pclc_prfx || |
| 357 | pclc_prfx->ipv6_prefixes_cnt > SMC_CLC_MAX_V6_PREFIX) |
| 358 | return false; |
| 359 | |
| 360 | if (hdr->version == SMC_V1) { |
| 361 | if (hdr->typev1 == SMC_TYPE_N) |
| 362 | return false; |
| 363 | if (ntohs(hdr->length) != |
| 364 | sizeof(*pclc) + ntohs(pclc->iparea_offset) + |
| 365 | sizeof(*pclc_prfx) + |
| 366 | pclc_prfx->ipv6_prefixes_cnt * |
| 367 | sizeof(struct smc_clc_ipv6_prefix) + |
| 368 | sizeof(struct smc_clc_msg_trail)) |
| 369 | return false; |
| 370 | } else { |
| 371 | v2_ext = smc_get_clc_v2_ext(prop: pclc); |
| 372 | if ((hdr->typev2 != SMC_TYPE_N && |
| 373 | (!v2_ext || v2_ext->hdr.eid_cnt > SMC_CLC_MAX_UEID)) || |
| 374 | (smcd_indicated(smc_type: hdr->typev2) && |
| 375 | v2_ext->hdr.ism_gid_cnt > SMCD_CLC_MAX_V2_GID_ENTRIES)) |
| 376 | return false; |
| 377 | |
| 378 | if (ntohs(hdr->length) != |
| 379 | sizeof(*pclc) + |
| 380 | sizeof(struct smc_clc_msg_smcd) + |
| 381 | (hdr->typev1 != SMC_TYPE_N ? |
| 382 | sizeof(*pclc_prfx) + |
| 383 | pclc_prfx->ipv6_prefixes_cnt * |
| 384 | sizeof(struct smc_clc_ipv6_prefix) : 0) + |
| 385 | (hdr->typev2 != SMC_TYPE_N ? |
| 386 | sizeof(*v2_ext) + |
| 387 | v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN : 0) + |
| 388 | (smcd_indicated(smc_type: hdr->typev2) ? |
| 389 | sizeof(*smcd_v2_ext) + v2_ext->hdr.ism_gid_cnt * |
| 390 | sizeof(struct smc_clc_smcd_gid_chid) : |
| 391 | 0) + |
| 392 | sizeof(struct smc_clc_msg_trail)) |
| 393 | return false; |
| 394 | } |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | /* check arriving CLC accept or confirm */ |
| 399 | static bool |
| 400 | smc_clc_msg_acc_conf_valid(struct smc_clc_msg_accept_confirm *clc) |
| 401 | { |
| 402 | struct smc_clc_msg_hdr *hdr = &clc->hdr; |
| 403 | |
| 404 | if (hdr->typev1 != SMC_TYPE_R && hdr->typev1 != SMC_TYPE_D) |
| 405 | return false; |
| 406 | if (hdr->version == SMC_V1) { |
| 407 | if ((hdr->typev1 == SMC_TYPE_R && |
| 408 | ntohs(hdr->length) != SMCR_CLC_ACCEPT_CONFIRM_LEN) || |
| 409 | (hdr->typev1 == SMC_TYPE_D && |
| 410 | ntohs(hdr->length) != SMCD_CLC_ACCEPT_CONFIRM_LEN)) |
| 411 | return false; |
| 412 | } else { |
| 413 | if (hdr->typev1 == SMC_TYPE_D && |
| 414 | ntohs(hdr->length) < SMCD_CLC_ACCEPT_CONFIRM_LEN_V2) |
| 415 | return false; |
| 416 | if (hdr->typev1 == SMC_TYPE_R && |
| 417 | ntohs(hdr->length) < SMCR_CLC_ACCEPT_CONFIRM_LEN_V2) |
| 418 | return false; |
| 419 | } |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | /* check arriving CLC decline */ |
| 424 | static bool |
| 425 | smc_clc_msg_decl_valid(struct smc_clc_msg_decline *dclc) |
| 426 | { |
| 427 | struct smc_clc_msg_hdr *hdr = &dclc->hdr; |
| 428 | |
| 429 | if (hdr->version == SMC_V1) { |
| 430 | if (ntohs(hdr->length) != sizeof(struct smc_clc_msg_decline)) |
| 431 | return false; |
| 432 | } else { |
| 433 | if (ntohs(hdr->length) != sizeof(struct smc_clc_msg_decline_v2)) |
| 434 | return false; |
| 435 | } |
| 436 | return true; |
| 437 | } |
| 438 | |
| 439 | static int smc_clc_fill_fce_v2x(struct smc_clc_first_contact_ext_v2x *fce_v2x, |
| 440 | struct smc_init_info *ini) |
| 441 | { |
| 442 | int ret = sizeof(*fce_v2x); |
| 443 | |
| 444 | memset(fce_v2x, 0, sizeof(*fce_v2x)); |
| 445 | fce_v2x->fce_v2_base.os_type = SMC_CLC_OS_LINUX; |
| 446 | fce_v2x->fce_v2_base.release = ini->release_nr; |
| 447 | memcpy(fce_v2x->fce_v2_base.hostname, |
| 448 | smc_hostname, sizeof(smc_hostname)); |
| 449 | if (ini->is_smcd && ini->release_nr < SMC_RELEASE_1) { |
| 450 | ret = sizeof(struct smc_clc_first_contact_ext); |
| 451 | goto out; |
| 452 | } |
| 453 | |
| 454 | if (ini->release_nr >= SMC_RELEASE_1) { |
| 455 | if (!ini->is_smcd) { |
| 456 | fce_v2x->max_conns = ini->max_conns; |
| 457 | fce_v2x->max_links = ini->max_links; |
| 458 | } |
| 459 | fce_v2x->feature_mask = htons(ini->feature_mask); |
| 460 | } |
| 461 | |
| 462 | out: |
| 463 | return ret; |
| 464 | } |
| 465 | |
| 466 | /* check if received message has a correct header length and contains valid |
| 467 | * heading and trailing eyecatchers |
| 468 | */ |
| 469 | static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm, bool check_trl) |
| 470 | { |
| 471 | struct smc_clc_msg_accept_confirm *clc; |
| 472 | struct smc_clc_msg_proposal *pclc; |
| 473 | struct smc_clc_msg_decline *dclc; |
| 474 | struct smc_clc_msg_trail *trl; |
| 475 | |
| 476 | if (memcmp(p: clcm->eyecatcher, q: SMC_EYECATCHER, size: sizeof(SMC_EYECATCHER)) && |
| 477 | memcmp(p: clcm->eyecatcher, q: SMCD_EYECATCHER, size: sizeof(SMCD_EYECATCHER))) |
| 478 | return false; |
| 479 | switch (clcm->type) { |
| 480 | case SMC_CLC_PROPOSAL: |
| 481 | pclc = (struct smc_clc_msg_proposal *)clcm; |
| 482 | if (!smc_clc_msg_prop_valid(pclc)) |
| 483 | return false; |
| 484 | trl = (struct smc_clc_msg_trail *) |
| 485 | ((u8 *)pclc + ntohs(pclc->hdr.length) - sizeof(*trl)); |
| 486 | break; |
| 487 | case SMC_CLC_ACCEPT: |
| 488 | case SMC_CLC_CONFIRM: |
| 489 | clc = (struct smc_clc_msg_accept_confirm *)clcm; |
| 490 | if (!smc_clc_msg_acc_conf_valid(clc)) |
| 491 | return false; |
| 492 | trl = (struct smc_clc_msg_trail *) |
| 493 | ((u8 *)clc + ntohs(clc->hdr.length) - sizeof(*trl)); |
| 494 | break; |
| 495 | case SMC_CLC_DECLINE: |
| 496 | dclc = (struct smc_clc_msg_decline *)clcm; |
| 497 | if (!smc_clc_msg_decl_valid(dclc)) |
| 498 | return false; |
| 499 | check_trl = false; |
| 500 | break; |
| 501 | default: |
| 502 | return false; |
| 503 | } |
| 504 | if (check_trl && |
| 505 | memcmp(p: trl->eyecatcher, q: SMC_EYECATCHER, size: sizeof(SMC_EYECATCHER)) && |
| 506 | memcmp(p: trl->eyecatcher, q: SMCD_EYECATCHER, size: sizeof(SMCD_EYECATCHER))) |
| 507 | return false; |
| 508 | return true; |
| 509 | } |
| 510 | |
| 511 | /* find ipv4 addr on device and get the prefix len, fill CLC proposal msg */ |
| 512 | static int smc_clc_prfx_set4_rcu(struct net_device *dev, __be32 ipv4, |
| 513 | struct smc_clc_msg_proposal_prefix *prop) |
| 514 | { |
| 515 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
| 516 | const struct in_ifaddr *ifa; |
| 517 | |
| 518 | if (!in_dev) |
| 519 | return -ENODEV; |
| 520 | |
| 521 | in_dev_for_each_ifa_rcu(ifa, in_dev) { |
| 522 | if (!inet_ifa_match(addr: ipv4, ifa)) |
| 523 | continue; |
| 524 | prop->prefix_len = inet_mask_len(mask: ifa->ifa_mask); |
| 525 | prop->outgoing_subnet = ifa->ifa_address & ifa->ifa_mask; |
| 526 | /* prop->ipv6_prefixes_cnt = 0; already done by memset before */ |
| 527 | return 0; |
| 528 | } |
| 529 | return -ENOENT; |
| 530 | } |
| 531 | |
| 532 | /* fill CLC proposal msg with ipv6 prefixes from device */ |
| 533 | static int smc_clc_prfx_set6_rcu(struct net_device *dev, |
| 534 | struct smc_clc_msg_proposal_prefix *prop, |
| 535 | struct smc_clc_ipv6_prefix *ipv6_prfx) |
| 536 | { |
| 537 | #if IS_ENABLED(CONFIG_IPV6) |
| 538 | struct inet6_dev *in6_dev = __in6_dev_get(dev); |
| 539 | struct inet6_ifaddr *ifa; |
| 540 | int cnt = 0; |
| 541 | |
| 542 | if (!in6_dev) |
| 543 | return -ENODEV; |
| 544 | /* use a maximum of 8 IPv6 prefixes from device */ |
| 545 | list_for_each_entry(ifa, &in6_dev->addr_list, if_list) { |
| 546 | if (ipv6_addr_type(addr: &ifa->addr) & IPV6_ADDR_LINKLOCAL) |
| 547 | continue; |
| 548 | ipv6_addr_prefix(pfx: &ipv6_prfx[cnt].prefix, |
| 549 | addr: &ifa->addr, plen: ifa->prefix_len); |
| 550 | ipv6_prfx[cnt].prefix_len = ifa->prefix_len; |
| 551 | cnt++; |
| 552 | if (cnt == SMC_CLC_MAX_V6_PREFIX) |
| 553 | break; |
| 554 | } |
| 555 | prop->ipv6_prefixes_cnt = cnt; |
| 556 | if (cnt) |
| 557 | return 0; |
| 558 | #endif |
| 559 | return -ENOENT; |
| 560 | } |
| 561 | |
| 562 | /* retrieve and set prefixes in CLC proposal msg */ |
| 563 | static int smc_clc_prfx_set(struct socket *clcsock, |
| 564 | struct smc_clc_msg_proposal_prefix *prop, |
| 565 | struct smc_clc_ipv6_prefix *ipv6_prfx) |
| 566 | { |
| 567 | struct sockaddr_storage addrs; |
| 568 | struct sockaddr_in6 *addr6; |
| 569 | struct sockaddr_in *addr; |
| 570 | struct net_device *dev; |
| 571 | struct dst_entry *dst; |
| 572 | int rc = -ENOENT; |
| 573 | |
| 574 | /* get address to which the internal TCP socket is bound */ |
| 575 | if (kernel_getsockname(sock: clcsock, addr: (struct sockaddr *)&addrs) < 0) |
| 576 | goto out; |
| 577 | |
| 578 | /* analyze IP specific data of net_device belonging to TCP socket */ |
| 579 | addr6 = (struct sockaddr_in6 *)&addrs; |
| 580 | |
| 581 | rcu_read_lock(); |
| 582 | |
| 583 | dst = __sk_dst_get(sk: clcsock->sk); |
| 584 | dev = dst ? dst_dev_rcu(dst) : NULL; |
| 585 | if (!dev) { |
| 586 | rc = -ENODEV; |
| 587 | goto out_unlock; |
| 588 | } |
| 589 | |
| 590 | if (addrs.ss_family == PF_INET) { |
| 591 | /* IPv4 */ |
| 592 | addr = (struct sockaddr_in *)&addrs; |
| 593 | rc = smc_clc_prfx_set4_rcu(dev, ipv4: addr->sin_addr.s_addr, prop); |
| 594 | } else if (ipv6_addr_v4mapped(a: &addr6->sin6_addr)) { |
| 595 | /* mapped IPv4 address - peer is IPv4 only */ |
| 596 | rc = smc_clc_prfx_set4_rcu(dev, ipv4: addr6->sin6_addr.s6_addr32[3], |
| 597 | prop); |
| 598 | } else { |
| 599 | /* IPv6 */ |
| 600 | rc = smc_clc_prfx_set6_rcu(dev, prop, ipv6_prfx); |
| 601 | } |
| 602 | |
| 603 | out_unlock: |
| 604 | rcu_read_unlock(); |
| 605 | out: |
| 606 | return rc; |
| 607 | } |
| 608 | |
| 609 | /* match ipv4 addrs of dev against addr in CLC proposal */ |
| 610 | static int smc_clc_prfx_match4_rcu(struct net_device *dev, |
| 611 | struct smc_clc_msg_proposal_prefix *prop) |
| 612 | { |
| 613 | struct in_device *in_dev = __in_dev_get_rcu(dev); |
| 614 | const struct in_ifaddr *ifa; |
| 615 | |
| 616 | if (!in_dev) |
| 617 | return -ENODEV; |
| 618 | in_dev_for_each_ifa_rcu(ifa, in_dev) { |
| 619 | if (prop->prefix_len == inet_mask_len(mask: ifa->ifa_mask) && |
| 620 | inet_ifa_match(addr: prop->outgoing_subnet, ifa)) |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | return -ENOENT; |
| 625 | } |
| 626 | |
| 627 | /* match ipv6 addrs of dev against addrs in CLC proposal */ |
| 628 | static int smc_clc_prfx_match6_rcu(struct net_device *dev, |
| 629 | struct smc_clc_msg_proposal_prefix *prop) |
| 630 | { |
| 631 | #if IS_ENABLED(CONFIG_IPV6) |
| 632 | struct inet6_dev *in6_dev = __in6_dev_get(dev); |
| 633 | struct smc_clc_ipv6_prefix *ipv6_prfx; |
| 634 | struct inet6_ifaddr *ifa; |
| 635 | int i, max; |
| 636 | |
| 637 | if (!in6_dev) |
| 638 | return -ENODEV; |
| 639 | /* ipv6 prefix list starts behind smc_clc_msg_proposal_prefix */ |
| 640 | ipv6_prfx = (struct smc_clc_ipv6_prefix *)((u8 *)prop + sizeof(*prop)); |
| 641 | max = min_t(u8, prop->ipv6_prefixes_cnt, SMC_CLC_MAX_V6_PREFIX); |
| 642 | list_for_each_entry(ifa, &in6_dev->addr_list, if_list) { |
| 643 | if (ipv6_addr_type(addr: &ifa->addr) & IPV6_ADDR_LINKLOCAL) |
| 644 | continue; |
| 645 | for (i = 0; i < max; i++) { |
| 646 | if (ifa->prefix_len == ipv6_prfx[i].prefix_len && |
| 647 | ipv6_prefix_equal(addr1: &ifa->addr, addr2: &ipv6_prfx[i].prefix, |
| 648 | prefixlen: ifa->prefix_len)) |
| 649 | return 0; |
| 650 | } |
| 651 | } |
| 652 | #endif |
| 653 | return -ENOENT; |
| 654 | } |
| 655 | |
| 656 | /* check if proposed prefixes match one of our device prefixes */ |
| 657 | int smc_clc_prfx_match(struct socket *clcsock, |
| 658 | struct smc_clc_msg_proposal_prefix *prop) |
| 659 | { |
| 660 | struct net_device *dev; |
| 661 | struct dst_entry *dst; |
| 662 | int rc; |
| 663 | |
| 664 | rcu_read_lock(); |
| 665 | |
| 666 | dst = __sk_dst_get(sk: clcsock->sk); |
| 667 | dev = dst ? dst_dev_rcu(dst) : NULL; |
| 668 | if (!dev) { |
| 669 | rc = -ENODEV; |
| 670 | goto out; |
| 671 | } |
| 672 | |
| 673 | if (!prop->ipv6_prefixes_cnt) |
| 674 | rc = smc_clc_prfx_match4_rcu(dev, prop); |
| 675 | else |
| 676 | rc = smc_clc_prfx_match6_rcu(dev, prop); |
| 677 | out: |
| 678 | rcu_read_unlock(); |
| 679 | |
| 680 | return rc; |
| 681 | } |
| 682 | |
| 683 | /* Wait for data on the tcp-socket, analyze received data |
| 684 | * Returns: |
| 685 | * 0 if success and it was not a decline that we received. |
| 686 | * SMC_CLC_DECL_REPLY if decline received for fallback w/o another decl send. |
| 687 | * clcsock error, -EINTR, -ECONNRESET, -EPROTO otherwise. |
| 688 | */ |
| 689 | int smc_clc_wait_msg(struct smc_sock *smc, void *buf, int buflen, |
| 690 | u8 expected_type, unsigned long timeout) |
| 691 | { |
| 692 | long rcvtimeo = READ_ONCE(smc->clcsock->sk->sk_rcvtimeo); |
| 693 | struct sock *clc_sk = smc->clcsock->sk; |
| 694 | struct smc_clc_msg_hdr *clcm = buf; |
| 695 | struct msghdr msg = {NULL, 0}; |
| 696 | int reason_code = 0; |
| 697 | struct kvec vec = {buf, buflen}; |
| 698 | int len, datlen, recvlen; |
| 699 | bool check_trl = true; |
| 700 | int krflags; |
| 701 | |
| 702 | /* peek the first few bytes to determine length of data to receive |
| 703 | * so we don't consume any subsequent CLC message or payload data |
| 704 | * in the TCP byte stream |
| 705 | */ |
| 706 | /* |
| 707 | * Caller must make sure that buflen is no less than |
| 708 | * sizeof(struct smc_clc_msg_hdr) |
| 709 | */ |
| 710 | krflags = MSG_PEEK | MSG_WAITALL; |
| 711 | WRITE_ONCE(clc_sk->sk_rcvtimeo, timeout); |
| 712 | iov_iter_kvec(i: &msg.msg_iter, ITER_DEST, kvec: &vec, nr_segs: 1, |
| 713 | count: sizeof(struct smc_clc_msg_hdr)); |
| 714 | len = sock_recvmsg(sock: smc->clcsock, msg: &msg, flags: krflags); |
| 715 | if (signal_pending(current)) { |
| 716 | reason_code = -EINTR; |
| 717 | clc_sk->sk_err = EINTR; |
| 718 | smc->sk.sk_err = EINTR; |
| 719 | goto out; |
| 720 | } |
| 721 | if (clc_sk->sk_err) { |
| 722 | reason_code = -clc_sk->sk_err; |
| 723 | if (clc_sk->sk_err == EAGAIN && |
| 724 | expected_type == SMC_CLC_DECLINE) |
| 725 | clc_sk->sk_err = 0; /* reset for fallback usage */ |
| 726 | else |
| 727 | smc->sk.sk_err = clc_sk->sk_err; |
| 728 | goto out; |
| 729 | } |
| 730 | if (!len) { /* peer has performed orderly shutdown */ |
| 731 | smc->sk.sk_err = ECONNRESET; |
| 732 | reason_code = -ECONNRESET; |
| 733 | goto out; |
| 734 | } |
| 735 | if (len < 0) { |
| 736 | if (len != -EAGAIN || expected_type != SMC_CLC_DECLINE) |
| 737 | smc->sk.sk_err = -len; |
| 738 | reason_code = len; |
| 739 | goto out; |
| 740 | } |
| 741 | datlen = ntohs(clcm->length); |
| 742 | if ((len < sizeof(struct smc_clc_msg_hdr)) || |
| 743 | (clcm->version < SMC_V1) || |
| 744 | ((clcm->type != SMC_CLC_DECLINE) && |
| 745 | (clcm->type != expected_type))) { |
| 746 | smc->sk.sk_err = EPROTO; |
| 747 | reason_code = -EPROTO; |
| 748 | goto out; |
| 749 | } |
| 750 | |
| 751 | /* receive the complete CLC message */ |
| 752 | memset(&msg, 0, sizeof(struct msghdr)); |
| 753 | if (datlen > buflen) { |
| 754 | check_trl = false; |
| 755 | recvlen = buflen; |
| 756 | } else { |
| 757 | recvlen = datlen; |
| 758 | } |
| 759 | iov_iter_kvec(i: &msg.msg_iter, ITER_DEST, kvec: &vec, nr_segs: 1, count: recvlen); |
| 760 | krflags = MSG_WAITALL; |
| 761 | len = sock_recvmsg(sock: smc->clcsock, msg: &msg, flags: krflags); |
| 762 | if (len < recvlen || !smc_clc_msg_hdr_valid(clcm, check_trl)) { |
| 763 | smc->sk.sk_err = EPROTO; |
| 764 | reason_code = -EPROTO; |
| 765 | goto out; |
| 766 | } |
| 767 | datlen -= len; |
| 768 | while (datlen) { |
| 769 | u8 tmp[SMC_CLC_RECV_BUF_LEN]; |
| 770 | |
| 771 | vec.iov_base = &tmp; |
| 772 | vec.iov_len = SMC_CLC_RECV_BUF_LEN; |
| 773 | /* receive remaining proposal message */ |
| 774 | recvlen = datlen > SMC_CLC_RECV_BUF_LEN ? |
| 775 | SMC_CLC_RECV_BUF_LEN : datlen; |
| 776 | iov_iter_kvec(i: &msg.msg_iter, ITER_DEST, kvec: &vec, nr_segs: 1, count: recvlen); |
| 777 | len = sock_recvmsg(sock: smc->clcsock, msg: &msg, flags: krflags); |
| 778 | if (len < recvlen) { |
| 779 | smc->sk.sk_err = EPROTO; |
| 780 | reason_code = -EPROTO; |
| 781 | goto out; |
| 782 | } |
| 783 | datlen -= len; |
| 784 | } |
| 785 | if (clcm->type == SMC_CLC_DECLINE) { |
| 786 | struct smc_clc_msg_decline *dclc; |
| 787 | |
| 788 | dclc = (struct smc_clc_msg_decline *)clcm; |
| 789 | reason_code = SMC_CLC_DECL_PEERDECL; |
| 790 | smc->peer_diagnosis = ntohl(dclc->peer_diagnosis); |
| 791 | if (((struct smc_clc_msg_decline *)buf)->hdr.typev2 & |
| 792 | SMC_FIRST_CONTACT_MASK) { |
| 793 | smc->conn.lgr->sync_err = 1; |
| 794 | smc_lgr_terminate_sched(lgr: smc->conn.lgr); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | out: |
| 799 | WRITE_ONCE(clc_sk->sk_rcvtimeo, rcvtimeo); |
| 800 | return reason_code; |
| 801 | } |
| 802 | |
| 803 | /* send CLC DECLINE message across internal TCP socket */ |
| 804 | int smc_clc_send_decline(struct smc_sock *smc, u32 peer_diag_info, u8 version) |
| 805 | { |
| 806 | struct smc_clc_msg_decline *dclc_v1; |
| 807 | struct smc_clc_msg_decline_v2 dclc; |
| 808 | struct msghdr msg; |
| 809 | int len, send_len; |
| 810 | struct kvec vec; |
| 811 | |
| 812 | dclc_v1 = (struct smc_clc_msg_decline *)&dclc; |
| 813 | memset(&dclc, 0, sizeof(dclc)); |
| 814 | memcpy(dclc.hdr.eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 815 | dclc.hdr.type = SMC_CLC_DECLINE; |
| 816 | dclc.hdr.version = version; |
| 817 | dclc.os_type = version == SMC_V1 ? 0 : SMC_CLC_OS_LINUX; |
| 818 | dclc.hdr.typev2 = (peer_diag_info == SMC_CLC_DECL_SYNCERR) ? |
| 819 | SMC_FIRST_CONTACT_MASK : 0; |
| 820 | if ((!smc_conn_lgr_valid(conn: &smc->conn) || !smc->conn.lgr->is_smcd) && |
| 821 | smc_ib_is_valid_local_systemid()) |
| 822 | memcpy(dclc.id_for_peer, local_systemid, |
| 823 | sizeof(local_systemid)); |
| 824 | dclc.peer_diagnosis = htonl(peer_diag_info); |
| 825 | if (version == SMC_V1) { |
| 826 | memcpy(dclc_v1->trl.eyecatcher, SMC_EYECATCHER, |
| 827 | sizeof(SMC_EYECATCHER)); |
| 828 | send_len = sizeof(*dclc_v1); |
| 829 | } else { |
| 830 | memcpy(dclc.trl.eyecatcher, SMC_EYECATCHER, |
| 831 | sizeof(SMC_EYECATCHER)); |
| 832 | send_len = sizeof(dclc); |
| 833 | } |
| 834 | dclc.hdr.length = htons(send_len); |
| 835 | |
| 836 | memset(&msg, 0, sizeof(msg)); |
| 837 | vec.iov_base = &dclc; |
| 838 | vec.iov_len = send_len; |
| 839 | len = kernel_sendmsg(sock: smc->clcsock, msg: &msg, vec: &vec, num: 1, len: send_len); |
| 840 | if (len < 0 || len < send_len) |
| 841 | len = -EPROTO; |
| 842 | return len > 0 ? 0 : len; |
| 843 | } |
| 844 | |
| 845 | /* send CLC PROPOSAL message across internal TCP socket */ |
| 846 | int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini) |
| 847 | { |
| 848 | struct smc_clc_smcd_v2_extension *smcd_v2_ext; |
| 849 | struct smc_clc_msg_proposal_prefix *pclc_prfx; |
| 850 | struct smc_clc_msg_proposal *pclc_base; |
| 851 | struct smc_clc_smcd_gid_chid *gidchids; |
| 852 | struct smc_clc_msg_proposal_area *pclc; |
| 853 | struct smc_clc_ipv6_prefix *ipv6_prfx; |
| 854 | struct net *net = sock_net(sk: &smc->sk); |
| 855 | struct smc_clc_v2_extension *v2_ext; |
| 856 | struct smc_clc_msg_smcd *pclc_smcd; |
| 857 | struct smc_clc_msg_trail *trl; |
| 858 | struct smcd_dev *smcd; |
| 859 | int len, i, plen, rc; |
| 860 | int reason_code = 0; |
| 861 | struct kvec vec[8]; |
| 862 | struct msghdr msg; |
| 863 | |
| 864 | pclc = kzalloc(sizeof(*pclc), GFP_KERNEL); |
| 865 | if (!pclc) |
| 866 | return -ENOMEM; |
| 867 | |
| 868 | pclc_base = &pclc->pclc_base; |
| 869 | pclc_smcd = &pclc->pclc_smcd; |
| 870 | pclc_prfx = &pclc->pclc_prfx; |
| 871 | ipv6_prfx = pclc->pclc_prfx_ipv6; |
| 872 | v2_ext = container_of(&pclc->pclc_v2_ext, |
| 873 | struct smc_clc_v2_extension, fixed); |
| 874 | smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext, |
| 875 | struct smc_clc_smcd_v2_extension, fixed); |
| 876 | gidchids = pclc->pclc_gidchids; |
| 877 | trl = &pclc->pclc_trl; |
| 878 | |
| 879 | pclc_base->hdr.version = SMC_V2; |
| 880 | pclc_base->hdr.typev1 = ini->smc_type_v1; |
| 881 | pclc_base->hdr.typev2 = ini->smc_type_v2; |
| 882 | plen = sizeof(*pclc_base) + sizeof(*pclc_smcd) + sizeof(*trl); |
| 883 | |
| 884 | /* retrieve ip prefixes for CLC proposal msg */ |
| 885 | if (ini->smc_type_v1 != SMC_TYPE_N) { |
| 886 | rc = smc_clc_prfx_set(clcsock: smc->clcsock, prop: pclc_prfx, ipv6_prfx); |
| 887 | if (rc) { |
| 888 | if (ini->smc_type_v2 == SMC_TYPE_N) { |
| 889 | kfree(objp: pclc); |
| 890 | return SMC_CLC_DECL_CNFERR; |
| 891 | } |
| 892 | pclc_base->hdr.typev1 = SMC_TYPE_N; |
| 893 | ini->smc_type_v1 = SMC_TYPE_N; |
| 894 | } else { |
| 895 | pclc_base->iparea_offset = htons(sizeof(*pclc_smcd)); |
| 896 | plen += sizeof(*pclc_prfx) + |
| 897 | pclc_prfx->ipv6_prefixes_cnt * |
| 898 | sizeof(ipv6_prfx[0]); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | /* build SMC Proposal CLC message */ |
| 903 | memcpy(pclc_base->hdr.eyecatcher, SMC_EYECATCHER, |
| 904 | sizeof(SMC_EYECATCHER)); |
| 905 | pclc_base->hdr.type = SMC_CLC_PROPOSAL; |
| 906 | if (smcr_indicated(smc_type: ini->smc_type_v1)) { |
| 907 | /* add SMC-R specifics */ |
| 908 | memcpy(pclc_base->lcl.id_for_peer, local_systemid, |
| 909 | sizeof(local_systemid)); |
| 910 | memcpy(pclc_base->lcl.gid, ini->ib_gid, SMC_GID_SIZE); |
| 911 | memcpy(pclc_base->lcl.mac, &ini->ib_dev->mac[ini->ib_port - 1], |
| 912 | ETH_ALEN); |
| 913 | } |
| 914 | if (smcd_indicated(smc_type: ini->smc_type_v1)) { |
| 915 | struct smcd_gid smcd_gid; |
| 916 | |
| 917 | /* add SMC-D specifics */ |
| 918 | if (ini->ism_dev[0]) { |
| 919 | smcd = ini->ism_dev[0]; |
| 920 | copy_to_smcdgid(sgid: &smcd_gid, dibs_gid: &smcd->dibs->gid); |
| 921 | pclc_smcd->ism.gid = htonll(smcd_gid.gid); |
| 922 | pclc_smcd->ism.chid = |
| 923 | htons(smc_ism_get_chid(ini->ism_dev[0])); |
| 924 | } |
| 925 | } |
| 926 | if (ini->smc_type_v2 == SMC_TYPE_N) { |
| 927 | pclc_smcd->v2_ext_offset = 0; |
| 928 | } else { |
| 929 | struct smc_clc_eid_entry *ueident; |
| 930 | u16 v2_ext_offset; |
| 931 | |
| 932 | v2_ext->hdr.flag.release = SMC_RELEASE; |
| 933 | v2_ext_offset = sizeof(*pclc_smcd) - |
| 934 | offsetofend(struct smc_clc_msg_smcd, v2_ext_offset); |
| 935 | if (ini->smc_type_v1 != SMC_TYPE_N) |
| 936 | v2_ext_offset += sizeof(*pclc_prfx) + |
| 937 | pclc_prfx->ipv6_prefixes_cnt * |
| 938 | sizeof(ipv6_prfx[0]); |
| 939 | pclc_smcd->v2_ext_offset = htons(v2_ext_offset); |
| 940 | plen += sizeof(*v2_ext); |
| 941 | |
| 942 | v2_ext->feature_mask = htons(SMC_FEATURE_MASK); |
| 943 | read_lock(&smc_clc_eid_table.lock); |
| 944 | v2_ext->hdr.eid_cnt = smc_clc_eid_table.ueid_cnt; |
| 945 | plen += smc_clc_eid_table.ueid_cnt * SMC_MAX_EID_LEN; |
| 946 | i = 0; |
| 947 | list_for_each_entry(ueident, &smc_clc_eid_table.list, list) { |
| 948 | memcpy(v2_ext->user_eids[i++], ueident->eid, |
| 949 | sizeof(ueident->eid)); |
| 950 | } |
| 951 | read_unlock(&smc_clc_eid_table.lock); |
| 952 | } |
| 953 | if (smcd_indicated(smc_type: ini->smc_type_v2)) { |
| 954 | struct smcd_gid smcd_gid; |
| 955 | u8 *eid = NULL; |
| 956 | int entry = 0; |
| 957 | |
| 958 | v2_ext->hdr.flag.seid = smc_clc_eid_table.seid_enabled; |
| 959 | v2_ext->hdr.smcd_v2_ext_offset = htons(sizeof(*v2_ext) - |
| 960 | offsetofend(struct smc_clnt_opts_area_hdr, |
| 961 | smcd_v2_ext_offset) + |
| 962 | v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN); |
| 963 | smc_ism_get_system_eid(eid: &eid); |
| 964 | if (eid && v2_ext->hdr.flag.seid) |
| 965 | memcpy(smcd_v2_ext->system_eid, eid, SMC_MAX_EID_LEN); |
| 966 | plen += sizeof(*smcd_v2_ext); |
| 967 | if (ini->ism_offered_cnt) { |
| 968 | for (i = 1; i <= ini->ism_offered_cnt; i++) { |
| 969 | smcd = ini->ism_dev[i]; |
| 970 | copy_to_smcdgid(sgid: &smcd_gid, dibs_gid: &smcd->dibs->gid); |
| 971 | gidchids[entry].chid = |
| 972 | htons(smc_ism_get_chid(ini->ism_dev[i])); |
| 973 | gidchids[entry].gid = htonll(smcd_gid.gid); |
| 974 | if (smc_ism_is_emulated(smcd)) { |
| 975 | /* an Emulated-ISM device takes two |
| 976 | * entries. CHID of the second entry |
| 977 | * repeats that of the first entry. |
| 978 | */ |
| 979 | gidchids[entry + 1].chid = |
| 980 | gidchids[entry].chid; |
| 981 | gidchids[entry + 1].gid = |
| 982 | htonll(smcd_gid.gid_ext); |
| 983 | entry++; |
| 984 | } |
| 985 | entry++; |
| 986 | } |
| 987 | plen += entry * sizeof(struct smc_clc_smcd_gid_chid); |
| 988 | } |
| 989 | v2_ext->hdr.ism_gid_cnt = entry; |
| 990 | } |
| 991 | if (smcr_indicated(smc_type: ini->smc_type_v2)) { |
| 992 | memcpy(v2_ext->roce, ini->smcrv2.ib_gid_v2, SMC_GID_SIZE); |
| 993 | v2_ext->max_conns = net->smc.sysctl_max_conns_per_lgr; |
| 994 | v2_ext->max_links = net->smc.sysctl_max_links_per_lgr; |
| 995 | } |
| 996 | |
| 997 | pclc_base->hdr.length = htons(plen); |
| 998 | memcpy(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 999 | |
| 1000 | /* send SMC Proposal CLC message */ |
| 1001 | memset(&msg, 0, sizeof(msg)); |
| 1002 | i = 0; |
| 1003 | vec[i].iov_base = pclc_base; |
| 1004 | vec[i++].iov_len = sizeof(*pclc_base); |
| 1005 | vec[i].iov_base = pclc_smcd; |
| 1006 | vec[i++].iov_len = sizeof(*pclc_smcd); |
| 1007 | if (ini->smc_type_v1 != SMC_TYPE_N) { |
| 1008 | vec[i].iov_base = pclc_prfx; |
| 1009 | vec[i++].iov_len = sizeof(*pclc_prfx); |
| 1010 | if (pclc_prfx->ipv6_prefixes_cnt > 0) { |
| 1011 | vec[i].iov_base = ipv6_prfx; |
| 1012 | vec[i++].iov_len = pclc_prfx->ipv6_prefixes_cnt * |
| 1013 | sizeof(ipv6_prfx[0]); |
| 1014 | } |
| 1015 | } |
| 1016 | if (ini->smc_type_v2 != SMC_TYPE_N) { |
| 1017 | vec[i].iov_base = v2_ext; |
| 1018 | vec[i++].iov_len = sizeof(*v2_ext) + |
| 1019 | (v2_ext->hdr.eid_cnt * SMC_MAX_EID_LEN); |
| 1020 | if (smcd_indicated(smc_type: ini->smc_type_v2)) { |
| 1021 | vec[i].iov_base = smcd_v2_ext; |
| 1022 | vec[i++].iov_len = sizeof(*smcd_v2_ext); |
| 1023 | if (ini->ism_offered_cnt) { |
| 1024 | vec[i].iov_base = gidchids; |
| 1025 | vec[i++].iov_len = v2_ext->hdr.ism_gid_cnt * |
| 1026 | sizeof(struct smc_clc_smcd_gid_chid); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | vec[i].iov_base = trl; |
| 1031 | vec[i++].iov_len = sizeof(*trl); |
| 1032 | /* due to the few bytes needed for clc-handshake this cannot block */ |
| 1033 | len = kernel_sendmsg(sock: smc->clcsock, msg: &msg, vec, num: i, len: plen); |
| 1034 | if (len < 0) { |
| 1035 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 1036 | reason_code = -smc->sk.sk_err; |
| 1037 | } else if (len < ntohs(pclc_base->hdr.length)) { |
| 1038 | reason_code = -ENETUNREACH; |
| 1039 | smc->sk.sk_err = -reason_code; |
| 1040 | } |
| 1041 | |
| 1042 | kfree(objp: pclc); |
| 1043 | return reason_code; |
| 1044 | } |
| 1045 | |
| 1046 | static void |
| 1047 | smcd_clc_prep_confirm_accept(struct smc_connection *conn, |
| 1048 | struct smc_clc_msg_accept_confirm *clc, |
| 1049 | int first_contact, u8 version, |
| 1050 | u8 *eid, struct smc_init_info *ini, |
| 1051 | int *fce_len, |
| 1052 | struct smc_clc_first_contact_ext_v2x *fce_v2x, |
| 1053 | struct smc_clc_msg_trail *trl) |
| 1054 | { |
| 1055 | struct smcd_dev *smcd = conn->lgr->smcd; |
| 1056 | struct smcd_gid smcd_gid; |
| 1057 | u16 chid; |
| 1058 | int len; |
| 1059 | |
| 1060 | /* SMC-D specific settings */ |
| 1061 | memcpy(clc->hdr.eyecatcher, SMCD_EYECATCHER, |
| 1062 | sizeof(SMCD_EYECATCHER)); |
| 1063 | copy_to_smcdgid(sgid: &smcd_gid, dibs_gid: &smcd->dibs->gid); |
| 1064 | clc->hdr.typev1 = SMC_TYPE_D; |
| 1065 | clc->d0.gid = htonll(smcd_gid.gid); |
| 1066 | clc->d0.token = htonll(conn->rmb_desc->token); |
| 1067 | clc->d0.dmbe_size = conn->rmbe_size_comp; |
| 1068 | clc->d0.dmbe_idx = 0; |
| 1069 | memcpy(&clc->d0.linkid, conn->lgr->id, SMC_LGR_ID_SIZE); |
| 1070 | if (version == SMC_V1) { |
| 1071 | clc->hdr.length = htons(SMCD_CLC_ACCEPT_CONFIRM_LEN); |
| 1072 | } else { |
| 1073 | chid = smc_ism_get_chid(dev: smcd); |
| 1074 | clc->d1.chid = htons(chid); |
| 1075 | if (eid && eid[0]) |
| 1076 | memcpy(clc->d1.eid, eid, SMC_MAX_EID_LEN); |
| 1077 | if (__smc_ism_is_emulated(chid)) |
| 1078 | clc->d1.gid_ext = htonll(smcd_gid.gid_ext); |
| 1079 | len = SMCD_CLC_ACCEPT_CONFIRM_LEN_V2; |
| 1080 | if (first_contact) { |
| 1081 | *fce_len = smc_clc_fill_fce_v2x(fce_v2x, ini); |
| 1082 | len += *fce_len; |
| 1083 | } |
| 1084 | clc->hdr.length = htons(len); |
| 1085 | } |
| 1086 | memcpy(trl->eyecatcher, SMCD_EYECATCHER, |
| 1087 | sizeof(SMCD_EYECATCHER)); |
| 1088 | } |
| 1089 | |
| 1090 | static void |
| 1091 | smcr_clc_prep_confirm_accept(struct smc_connection *conn, |
| 1092 | struct smc_clc_msg_accept_confirm *clc, |
| 1093 | int first_contact, u8 version, |
| 1094 | u8 *eid, struct smc_init_info *ini, |
| 1095 | int *fce_len, |
| 1096 | struct smc_clc_first_contact_ext_v2x *fce_v2x, |
| 1097 | struct smc_clc_fce_gid_ext *gle, |
| 1098 | struct smc_clc_msg_trail *trl) |
| 1099 | { |
| 1100 | struct smc_link *link = conn->lnk; |
| 1101 | int len; |
| 1102 | |
| 1103 | /* SMC-R specific settings */ |
| 1104 | memcpy(clc->hdr.eyecatcher, SMC_EYECATCHER, |
| 1105 | sizeof(SMC_EYECATCHER)); |
| 1106 | clc->hdr.typev1 = SMC_TYPE_R; |
| 1107 | memcpy(clc->r0.lcl.id_for_peer, local_systemid, |
| 1108 | sizeof(local_systemid)); |
| 1109 | memcpy(&clc->r0.lcl.gid, link->gid, SMC_GID_SIZE); |
| 1110 | memcpy(&clc->r0.lcl.mac, &link->smcibdev->mac[link->ibport - 1], |
| 1111 | ETH_ALEN); |
| 1112 | hton24(net: clc->r0.qpn, host: link->roce_qp->qp_num); |
| 1113 | clc->r0.rmb_rkey = |
| 1114 | htonl(conn->rmb_desc->mr[link->link_idx]->rkey); |
| 1115 | clc->r0.rmbe_idx = 1; /* for now: 1 RMB = 1 RMBE */ |
| 1116 | clc->r0.rmbe_alert_token = htonl(conn->alert_token_local); |
| 1117 | switch (clc->hdr.type) { |
| 1118 | case SMC_CLC_ACCEPT: |
| 1119 | clc->r0.qp_mtu = link->path_mtu; |
| 1120 | break; |
| 1121 | case SMC_CLC_CONFIRM: |
| 1122 | clc->r0.qp_mtu = min(link->path_mtu, link->peer_mtu); |
| 1123 | break; |
| 1124 | } |
| 1125 | clc->r0.rmbe_size = conn->rmbe_size_comp; |
| 1126 | clc->r0.rmb_dma_addr = conn->rmb_desc->is_vm ? |
| 1127 | cpu_to_be64((uintptr_t)conn->rmb_desc->cpu_addr) : |
| 1128 | cpu_to_be64((u64)sg_dma_address |
| 1129 | (conn->rmb_desc->sgt[link->link_idx].sgl)); |
| 1130 | hton24(net: clc->r0.psn, host: link->psn_initial); |
| 1131 | if (version == SMC_V1) { |
| 1132 | clc->hdr.length = htons(SMCR_CLC_ACCEPT_CONFIRM_LEN); |
| 1133 | } else { |
| 1134 | if (eid && eid[0]) |
| 1135 | memcpy(clc->r1.eid, eid, SMC_MAX_EID_LEN); |
| 1136 | len = SMCR_CLC_ACCEPT_CONFIRM_LEN_V2; |
| 1137 | if (first_contact) { |
| 1138 | *fce_len = smc_clc_fill_fce_v2x(fce_v2x, ini); |
| 1139 | len += *fce_len; |
| 1140 | fce_v2x->fce_v2_base.v2_direct = |
| 1141 | !link->lgr->uses_gateway; |
| 1142 | if (clc->hdr.type == SMC_CLC_CONFIRM) { |
| 1143 | memset(gle, 0, sizeof(*gle)); |
| 1144 | gle->gid_cnt = ini->smcrv2.gidlist.len; |
| 1145 | len += sizeof(*gle); |
| 1146 | len += gle->gid_cnt * sizeof(gle->gid[0]); |
| 1147 | } |
| 1148 | } |
| 1149 | clc->hdr.length = htons(len); |
| 1150 | } |
| 1151 | memcpy(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER)); |
| 1152 | } |
| 1153 | |
| 1154 | /* build and send CLC CONFIRM / ACCEPT message */ |
| 1155 | static int smc_clc_send_confirm_accept(struct smc_sock *smc, |
| 1156 | struct smc_clc_msg_accept_confirm *clc, |
| 1157 | int first_contact, u8 version, |
| 1158 | u8 *eid, struct smc_init_info *ini) |
| 1159 | { |
| 1160 | struct smc_clc_first_contact_ext_v2x fce_v2x; |
| 1161 | struct smc_connection *conn = &smc->conn; |
| 1162 | struct smc_clc_fce_gid_ext gle; |
| 1163 | struct smc_clc_msg_trail trl; |
| 1164 | int i, fce_len; |
| 1165 | struct kvec vec[5]; |
| 1166 | struct msghdr msg; |
| 1167 | |
| 1168 | /* send SMC Confirm CLC msg */ |
| 1169 | clc->hdr.version = version; /* SMC version */ |
| 1170 | if (first_contact) |
| 1171 | clc->hdr.typev2 |= SMC_FIRST_CONTACT_MASK; |
| 1172 | if (conn->lgr->is_smcd) |
| 1173 | smcd_clc_prep_confirm_accept(conn, clc, first_contact, |
| 1174 | version, eid, ini, fce_len: &fce_len, |
| 1175 | fce_v2x: &fce_v2x, trl: &trl); |
| 1176 | else |
| 1177 | smcr_clc_prep_confirm_accept(conn, clc, first_contact, |
| 1178 | version, eid, ini, fce_len: &fce_len, |
| 1179 | fce_v2x: &fce_v2x, gle: &gle, trl: &trl); |
| 1180 | memset(&msg, 0, sizeof(msg)); |
| 1181 | i = 0; |
| 1182 | vec[i].iov_base = clc; |
| 1183 | if (version > SMC_V1) |
| 1184 | vec[i++].iov_len = (clc->hdr.typev1 == SMC_TYPE_D ? |
| 1185 | SMCD_CLC_ACCEPT_CONFIRM_LEN_V2 : |
| 1186 | SMCR_CLC_ACCEPT_CONFIRM_LEN_V2) - |
| 1187 | sizeof(trl); |
| 1188 | else |
| 1189 | vec[i++].iov_len = (clc->hdr.typev1 == SMC_TYPE_D ? |
| 1190 | SMCD_CLC_ACCEPT_CONFIRM_LEN : |
| 1191 | SMCR_CLC_ACCEPT_CONFIRM_LEN) - |
| 1192 | sizeof(trl); |
| 1193 | if (version > SMC_V1 && first_contact) { |
| 1194 | vec[i].iov_base = &fce_v2x; |
| 1195 | vec[i++].iov_len = fce_len; |
| 1196 | if (!conn->lgr->is_smcd) { |
| 1197 | if (clc->hdr.type == SMC_CLC_CONFIRM) { |
| 1198 | vec[i].iov_base = &gle; |
| 1199 | vec[i++].iov_len = sizeof(gle); |
| 1200 | vec[i].iov_base = &ini->smcrv2.gidlist.list; |
| 1201 | vec[i++].iov_len = gle.gid_cnt * |
| 1202 | sizeof(gle.gid[0]); |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | vec[i].iov_base = &trl; |
| 1207 | vec[i++].iov_len = sizeof(trl); |
| 1208 | return kernel_sendmsg(sock: smc->clcsock, msg: &msg, vec, num: 1, |
| 1209 | ntohs(clc->hdr.length)); |
| 1210 | } |
| 1211 | |
| 1212 | /* send CLC CONFIRM message across internal TCP socket */ |
| 1213 | int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact, |
| 1214 | u8 version, u8 *eid, struct smc_init_info *ini) |
| 1215 | { |
| 1216 | struct smc_clc_msg_accept_confirm cclc; |
| 1217 | int reason_code = 0; |
| 1218 | int len; |
| 1219 | |
| 1220 | /* send SMC Confirm CLC msg */ |
| 1221 | memset(&cclc, 0, sizeof(cclc)); |
| 1222 | cclc.hdr.type = SMC_CLC_CONFIRM; |
| 1223 | len = smc_clc_send_confirm_accept(smc, clc: &cclc, first_contact: clnt_first_contact, |
| 1224 | version, eid, ini); |
| 1225 | if (len < ntohs(cclc.hdr.length)) { |
| 1226 | if (len >= 0) { |
| 1227 | reason_code = -ENETUNREACH; |
| 1228 | smc->sk.sk_err = -reason_code; |
| 1229 | } else { |
| 1230 | smc->sk.sk_err = smc->clcsock->sk->sk_err; |
| 1231 | reason_code = -smc->sk.sk_err; |
| 1232 | } |
| 1233 | } |
| 1234 | return reason_code; |
| 1235 | } |
| 1236 | |
| 1237 | /* send CLC ACCEPT message across internal TCP socket */ |
| 1238 | int smc_clc_send_accept(struct smc_sock *new_smc, bool srv_first_contact, |
| 1239 | u8 version, u8 *negotiated_eid, struct smc_init_info *ini) |
| 1240 | { |
| 1241 | struct smc_clc_msg_accept_confirm aclc; |
| 1242 | int len; |
| 1243 | |
| 1244 | memset(&aclc, 0, sizeof(aclc)); |
| 1245 | aclc.hdr.type = SMC_CLC_ACCEPT; |
| 1246 | len = smc_clc_send_confirm_accept(smc: new_smc, clc: &aclc, first_contact: srv_first_contact, |
| 1247 | version, eid: negotiated_eid, ini); |
| 1248 | if (len < ntohs(aclc.hdr.length)) |
| 1249 | len = len >= 0 ? -EPROTO : -new_smc->clcsock->sk->sk_err; |
| 1250 | |
| 1251 | return len > 0 ? 0 : len; |
| 1252 | } |
| 1253 | |
| 1254 | int smc_clc_srv_v2x_features_validate(struct smc_sock *smc, |
| 1255 | struct smc_clc_msg_proposal *pclc, |
| 1256 | struct smc_init_info *ini) |
| 1257 | { |
| 1258 | struct smc_clc_v2_extension *pclc_v2_ext; |
| 1259 | struct net *net = sock_net(sk: &smc->sk); |
| 1260 | |
| 1261 | ini->max_conns = SMC_CONN_PER_LGR_MAX; |
| 1262 | ini->max_links = SMC_LINKS_ADD_LNK_MAX; |
| 1263 | ini->feature_mask = SMC_FEATURE_MASK; |
| 1264 | |
| 1265 | if ((!(ini->smcd_version & SMC_V2) && !(ini->smcr_version & SMC_V2)) || |
| 1266 | ini->release_nr < SMC_RELEASE_1) |
| 1267 | return 0; |
| 1268 | |
| 1269 | pclc_v2_ext = smc_get_clc_v2_ext(prop: pclc); |
| 1270 | if (!pclc_v2_ext) |
| 1271 | return SMC_CLC_DECL_NOV2EXT; |
| 1272 | |
| 1273 | if (ini->smcr_version & SMC_V2) { |
| 1274 | ini->max_conns = min_t(u8, pclc_v2_ext->max_conns, |
| 1275 | net->smc.sysctl_max_conns_per_lgr); |
| 1276 | if (ini->max_conns < SMC_CONN_PER_LGR_MIN) |
| 1277 | return SMC_CLC_DECL_MAXCONNERR; |
| 1278 | |
| 1279 | ini->max_links = min_t(u8, pclc_v2_ext->max_links, |
| 1280 | net->smc.sysctl_max_links_per_lgr); |
| 1281 | if (ini->max_links < SMC_LINKS_ADD_LNK_MIN) |
| 1282 | return SMC_CLC_DECL_MAXLINKERR; |
| 1283 | } |
| 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
| 1288 | int smc_clc_clnt_v2x_features_validate(struct smc_clc_first_contact_ext *fce, |
| 1289 | struct smc_init_info *ini) |
| 1290 | { |
| 1291 | struct smc_clc_first_contact_ext_v2x *fce_v2x = |
| 1292 | (struct smc_clc_first_contact_ext_v2x *)fce; |
| 1293 | |
| 1294 | if (ini->release_nr < SMC_RELEASE_1) |
| 1295 | return 0; |
| 1296 | |
| 1297 | if (!ini->is_smcd) { |
| 1298 | if (fce_v2x->max_conns < SMC_CONN_PER_LGR_MIN) |
| 1299 | return SMC_CLC_DECL_MAXCONNERR; |
| 1300 | ini->max_conns = fce_v2x->max_conns; |
| 1301 | |
| 1302 | if (fce_v2x->max_links > SMC_LINKS_ADD_LNK_MAX || |
| 1303 | fce_v2x->max_links < SMC_LINKS_ADD_LNK_MIN) |
| 1304 | return SMC_CLC_DECL_MAXLINKERR; |
| 1305 | ini->max_links = fce_v2x->max_links; |
| 1306 | } |
| 1307 | /* common supplemental features of server and client */ |
| 1308 | ini->feature_mask = ntohs(fce_v2x->feature_mask) & SMC_FEATURE_MASK; |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
| 1313 | int smc_clc_v2x_features_confirm_check(struct smc_clc_msg_accept_confirm *cclc, |
| 1314 | struct smc_init_info *ini) |
| 1315 | { |
| 1316 | struct smc_clc_first_contact_ext *fce = |
| 1317 | smc_get_clc_first_contact_ext(clc: cclc, is_smcd: ini->is_smcd); |
| 1318 | struct smc_clc_first_contact_ext_v2x *fce_v2x = |
| 1319 | (struct smc_clc_first_contact_ext_v2x *)fce; |
| 1320 | |
| 1321 | if (cclc->hdr.version == SMC_V1 || |
| 1322 | !(cclc->hdr.typev2 & SMC_FIRST_CONTACT_MASK)) |
| 1323 | return 0; |
| 1324 | |
| 1325 | if (ini->release_nr != fce->release) |
| 1326 | return SMC_CLC_DECL_RELEASEERR; |
| 1327 | |
| 1328 | if (fce->release < SMC_RELEASE_1) |
| 1329 | return 0; |
| 1330 | |
| 1331 | if (!ini->is_smcd) { |
| 1332 | if (fce_v2x->max_conns != ini->max_conns) |
| 1333 | return SMC_CLC_DECL_MAXCONNERR; |
| 1334 | if (fce_v2x->max_links != ini->max_links) |
| 1335 | return SMC_CLC_DECL_MAXLINKERR; |
| 1336 | } |
| 1337 | /* common supplemental features returned by client */ |
| 1338 | ini->feature_mask = ntohs(fce_v2x->feature_mask); |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | void smc_clc_get_hostname(u8 **host) |
| 1344 | { |
| 1345 | *host = &smc_hostname[0]; |
| 1346 | } |
| 1347 | |
| 1348 | void __init smc_clc_init(void) |
| 1349 | { |
| 1350 | struct new_utsname *u; |
| 1351 | |
| 1352 | memset(smc_hostname, _S, sizeof(smc_hostname)); /* ASCII blanks */ |
| 1353 | u = utsname(); |
| 1354 | memcpy(smc_hostname, u->nodename, |
| 1355 | min_t(size_t, strlen(u->nodename), sizeof(smc_hostname))); |
| 1356 | |
| 1357 | INIT_LIST_HEAD(list: &smc_clc_eid_table.list); |
| 1358 | rwlock_init(&smc_clc_eid_table.lock); |
| 1359 | smc_clc_eid_table.ueid_cnt = 0; |
| 1360 | #if IS_ENABLED(CONFIG_S390) |
| 1361 | smc_clc_eid_table.seid_enabled = 1; |
| 1362 | #else |
| 1363 | smc_clc_eid_table.seid_enabled = 0; |
| 1364 | #endif |
| 1365 | } |
| 1366 | |
| 1367 | void smc_clc_exit(void) |
| 1368 | { |
| 1369 | smc_clc_ueid_remove(NULL); |
| 1370 | } |
| 1371 | |