Skip to content

Commit c39691d

Browse files
D. WytheNipaLocal
D. Wythe
authored and
NipaLocal
committed
net/smc: Introduce IPPROTO_SMC
This patch allows to create smc socket via AF_INET, similar to the following code, /* create v4 smc sock */ v4 = socket(AF_INET, SOCK_STREAM, IPPROTO_SMC); /* create v6 smc sock */ v6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_SMC); There are several reasons why we believe it is appropriate here: 1. For smc sockets, it actually use IPv4 (AF-INET) or IPv6 (AF-INET6) address. There is no AF_SMC address at all. 2. Create smc socket in the AF_INET(6) path, which allows us to reuse the infrastructure of AF_INET(6) path, such as common ebpf hooks. Otherwise, smc have to implement it again in AF_SMC path. Signed-off-by: D. Wythe <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent bd5202d commit c39691d

File tree

5 files changed

+178
-2
lines changed

5 files changed

+178
-2
lines changed

include/uapi/linux/in.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ enum {
8383
#define IPPROTO_RAW IPPROTO_RAW
8484
IPPROTO_MPTCP = 262, /* Multipath TCP connection */
8585
#define IPPROTO_MPTCP IPPROTO_MPTCP
86+
IPPROTO_SMC = 263, /* Shared Memory Communications */
87+
#define IPPROTO_SMC IPPROTO_SMC
8688
IPPROTO_MAX
8789
};
8890
#endif

net/smc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ obj-$(CONFIG_SMC) += smc.o
44
obj-$(CONFIG_SMC_DIAG) += smc_diag.o
55
smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o
66
smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_ism.o smc_netlink.o smc_stats.o
7-
smc-y += smc_tracepoint.o
7+
smc-y += smc_tracepoint.o inet_smc.o
88
smc-$(CONFIG_SYSCTL) += smc_sysctl.o
99
smc-$(CONFIG_SMC_LO) += smc_loopback.o

net/smc/af_smc.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "smc_tracepoint.h"
5555
#include "smc_sysctl.h"
5656
#include "smc_loopback.h"
57+
#include "inet_smc.h"
5758

5859
static DEFINE_MUTEX(smc_server_lgr_pending); /* serialize link group
5960
* creation on server
@@ -3594,9 +3595,30 @@ static int __init smc_init(void)
35943595
goto out_lo;
35953596
}
35963597

3598+
rc = proto_register(&smc_inet_prot, 1);
3599+
if (rc) {
3600+
pr_err("%s: proto_register smc_inet_prot fails with %d\n", __func__, rc);
3601+
goto out_ulp;
3602+
}
3603+
inet_register_protosw(&smc_inet_protosw);
3604+
#if IS_ENABLED(CONFIG_IPV6)
3605+
rc = proto_register(&smc_inet6_prot, 1);
3606+
if (rc) {
3607+
pr_err("%s: proto_register smc_inet6_prot fails with %d\n", __func__, rc);
3608+
goto out_inet_prot;
3609+
}
3610+
inet6_register_protosw(&smc_inet6_protosw);
3611+
#endif
3612+
35973613
static_branch_enable(&tcp_have_smc);
35983614
return 0;
3599-
3615+
#if IS_ENABLED(CONFIG_IPV6)
3616+
out_inet_prot:
3617+
inet_unregister_protosw(&smc_inet_protosw);
3618+
proto_unregister(&smc_inet_prot);
3619+
#endif
3620+
out_ulp:
3621+
tcp_unregister_ulp(&smc_ulp_ops);
36003622
out_lo:
36013623
smc_loopback_exit();
36023624
out_ib:
@@ -3633,6 +3655,10 @@ static int __init smc_init(void)
36333655
static void __exit smc_exit(void)
36343656
{
36353657
static_branch_disable(&tcp_have_smc);
3658+
inet_unregister_protosw(&smc_inet_protosw);
3659+
#if IS_ENABLED(CONFIG_IPV6)
3660+
inet6_unregister_protosw(&smc_inet6_protosw);
3661+
#endif
36363662
tcp_unregister_ulp(&smc_ulp_ops);
36373663
sock_unregister(PF_SMC);
36383664
smc_core_exit();
@@ -3644,6 +3670,10 @@ static void __exit smc_exit(void)
36443670
destroy_workqueue(smc_hs_wq);
36453671
proto_unregister(&smc_proto6);
36463672
proto_unregister(&smc_proto);
3673+
proto_unregister(&smc_inet_prot);
3674+
#if IS_ENABLED(CONFIG_IPV6)
3675+
proto_unregister(&smc_inet6_prot);
3676+
#endif
36473677
smc_pnet_exit();
36483678
smc_nl_exit();
36493679
smc_clc_exit();
@@ -3660,4 +3690,9 @@ MODULE_DESCRIPTION("smc socket address family");
36603690
MODULE_LICENSE("GPL");
36613691
MODULE_ALIAS_NETPROTO(PF_SMC);
36623692
MODULE_ALIAS_TCP_ULP("smc");
3693+
/* 263 for IPPROTO_SMC and 1 for SOCK_STREAM */
3694+
MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET, 263, 1);
3695+
#if IS_ENABLED(CONFIG_IPV6)
3696+
MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_INET6, 263, 1);
3697+
#endif
36633698
MODULE_ALIAS_GENL_FAMILY(SMC_GENL_FAMILY_NAME);

net/smc/inet_smc.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Shared Memory Communications over RDMA (SMC-R) and RoCE
4+
*
5+
* Definitions for the IPPROTO_SMC (socket related)
6+
*
7+
* Copyright IBM Corp. 2016, 2018
8+
*
9+
* Author(s): D. Wythe <[email protected]>
10+
*/
11+
12+
#include "inet_smc.h"
13+
#include "smc.h"
14+
15+
struct proto smc_inet_prot = {
16+
.name = "INET_SMC",
17+
.owner = THIS_MODULE,
18+
.init = smc_inet_init_sock,
19+
.hash = smc_hash_sk,
20+
.unhash = smc_unhash_sk,
21+
.release_cb = smc_release_cb,
22+
.obj_size = sizeof(struct smc_sock),
23+
.h.smc_hash = &smc_v4_hashinfo,
24+
.slab_flags = SLAB_TYPESAFE_BY_RCU,
25+
};
26+
27+
const struct proto_ops smc_inet_stream_ops = {
28+
.family = PF_INET,
29+
.owner = THIS_MODULE,
30+
.release = smc_release,
31+
.bind = smc_bind,
32+
.connect = smc_connect,
33+
.socketpair = sock_no_socketpair,
34+
.accept = smc_accept,
35+
.getname = smc_getname,
36+
.poll = smc_poll,
37+
.ioctl = smc_ioctl,
38+
.listen = smc_listen,
39+
.shutdown = smc_shutdown,
40+
.setsockopt = smc_setsockopt,
41+
.getsockopt = smc_getsockopt,
42+
.sendmsg = smc_sendmsg,
43+
.recvmsg = smc_recvmsg,
44+
.mmap = sock_no_mmap,
45+
.splice_read = smc_splice_read,
46+
};
47+
48+
struct inet_protosw smc_inet_protosw = {
49+
.type = SOCK_STREAM,
50+
.protocol = IPPROTO_SMC,
51+
.prot = &smc_inet_prot,
52+
.ops = &smc_inet_stream_ops,
53+
.flags = INET_PROTOSW_ICSK,
54+
};
55+
56+
#if IS_ENABLED(CONFIG_IPV6)
57+
struct proto smc_inet6_prot = {
58+
.name = "INET6_SMC",
59+
.owner = THIS_MODULE,
60+
.init = smc_inet_init_sock,
61+
.hash = smc_hash_sk,
62+
.unhash = smc_unhash_sk,
63+
.release_cb = smc_release_cb,
64+
.obj_size = sizeof(struct smc_sock),
65+
.h.smc_hash = &smc_v6_hashinfo,
66+
.slab_flags = SLAB_TYPESAFE_BY_RCU,
67+
};
68+
69+
const struct proto_ops smc_inet6_stream_ops = {
70+
.family = PF_INET6,
71+
.owner = THIS_MODULE,
72+
.release = smc_release,
73+
.bind = smc_bind,
74+
.connect = smc_connect,
75+
.socketpair = sock_no_socketpair,
76+
.accept = smc_accept,
77+
.getname = smc_getname,
78+
.poll = smc_poll,
79+
.ioctl = smc_ioctl,
80+
.listen = smc_listen,
81+
.shutdown = smc_shutdown,
82+
.setsockopt = smc_setsockopt,
83+
.getsockopt = smc_getsockopt,
84+
.sendmsg = smc_sendmsg,
85+
.recvmsg = smc_recvmsg,
86+
.mmap = sock_no_mmap,
87+
.splice_read = smc_splice_read,
88+
};
89+
90+
struct inet_protosw smc_inet6_protosw = {
91+
.type = SOCK_STREAM,
92+
.protocol = IPPROTO_SMC,
93+
.prot = &smc_inet6_prot,
94+
.ops = &smc_inet6_stream_ops,
95+
.flags = INET_PROTOSW_ICSK,
96+
};
97+
#endif
98+
99+
int smc_inet_init_sock(struct sock *sk)
100+
{
101+
struct net *net = sock_net(sk);
102+
103+
/* init common smc sock */
104+
smc_sock_init(net, sk, IPPROTO_SMC);
105+
/* create clcsock */
106+
return smc_create_clcsk(net, sk, sk->sk_family);
107+
}

net/smc/inet_smc.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Shared Memory Communications over RDMA (SMC-R) and RoCE
4+
*
5+
* Definitions for the IPPROTO_SMC (socket related)
6+
7+
* Copyright IBM Corp. 2016
8+
*
9+
*/
10+
#ifndef __INET_SMC
11+
#define __INET_SMC
12+
13+
#include <net/protocol.h>
14+
#include <net/sock.h>
15+
#include <net/tcp.h>
16+
17+
extern struct proto smc_inet_prot;
18+
extern const struct proto_ops smc_inet_stream_ops;
19+
extern struct inet_protosw smc_inet_protosw;
20+
21+
#if IS_ENABLED(CONFIG_IPV6)
22+
#include <net/ipv6.h>
23+
/* MUST after net/tcp.h or warning */
24+
#include <net/transp_v6.h>
25+
extern struct proto smc_inet6_prot;
26+
extern const struct proto_ops smc_inet6_stream_ops;
27+
extern struct inet_protosw smc_inet6_protosw;
28+
#endif
29+
30+
int smc_inet_init_sock(struct sock *sk);
31+
32+
#endif /* __INET_SMC */

0 commit comments

Comments
 (0)