Skip to contentSkip to conversation

net/smc: Introduce BPF injection capability

PATCH In review D. Wythe 3 participants 11 messages Apr 26, 2023 – Apr 27, 2023

Subsystems (8)
lore
Share & tools
lore

D. Wythe

author maintainer
#0 lore raw

cover net/smc: Introduce BPF injection capability

From: "D. Wythe" <[email protected]>

This patches attempt to introduce BPF injection capability for SMC, and add selftest to ensure code stability.

As we all know that the SMC protocol is not suitable for all scenarios, especially for short-lived. However, for most applications, they cannot guarantee that there are no such scenarios at all. Therefore, apps may need some specific strategies to decide shall we need to use SMC or not, for example, apps can limit the scope of the SMC to a specific IP address or port.

Based on the consideration of transparent replacement, we hope that apps can remain transparent even if they need to formulate some specific strategies for SMC using. That is, do not need to recompile their code.

On the other hand, we need to ensure the scalability of strategies implementation. Although it is simple to use socket options or sysctl, it will bring more complexity to subsequent expansion.

Fortunately, BPF can solve these concerns very well, users can write thire own strategies in eBPF to choose whether to use SMC or not. And it's quite easy for them to modify their strategies in the future.

This patches implement injection capability for SMC via struct_ops. In that way, we can add new injection scenarios in the future.

D. Wythe (5):
net/smc: move smc_sock related structure definition net/smc: allow smc to negotiate protocols on policies net/smc: allow set or get smc negotiator by sockopt
bpf: add smc negotiator support in BPF struct_ops bpf/selftests: add selftest for SMC bpf capability

 include/net/smc.h                                | 268 +++++++++++++++++
 include/uapi/linux/smc.h                         |   1 +
 kernel/bpf/bpf_struct_ops_types.h                |   4 +
 net/Makefile                                     |   1 +
 net/smc/Kconfig                                  |  11 +
 net/smc/af_smc.c                                 | 203 ++++++++++---
 net/smc/bpf_smc.c                                | 360 +++++++++++++++++++++++
 net/smc/smc.h                                    | 224 --------------
 tools/testing/selftests/bpf/prog_tests/bpf_smc.c | 107 +++++++
 tools/testing/selftests/bpf/progs/bpf_smc.c      | 265 +++++++++++++++++
 10 files changed, 1185 insertions(+), 259 deletions(-)
 create mode 100644 net/smc/bpf_smc.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_smc.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

PATCH 1/5 net/smc: move smc_sock related structure definition

From: "D. Wythe" <[email protected]>

This patch only try to move the definition of smc_sock and its related structure, from et/smc/smc.h to include/net/smc/smc.h. In that way can ebpf generate the BTF ID corresponding to our structure.

Of course, we can also choose to hide the structure and only to expose an intermediate structure, but it requires an additional transformation. If we need to obtain some information frequently, this may cause some performance problems.

---
 include/net/smc.h | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/smc/smc.h     | 224 -----------------------------------------------------
 2 files changed, 225 insertions(+), 224 deletions(-)
include/net/smc.h +225 -0
index a002552..6d076f5 100644
@@ -11,12 +11,17 @@
 #ifndef _SMC_H
 #define _SMC_H
 
+#include <net/inet_connection_sock.h>
 #include <linux/device.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
 #include <linux/wait.h>
 #include "linux/ism.h"
 
+#ifdef ATOMIC64_INIT
+#define KERNEL_HAS_ATOMIC64
+#endif
+
 struct sock;
 
 #define SMC_MAX_PNETID_LEN	16	/* Max. length of PNET id */
@@ -91,4 +96,224 @@ struct smcd_dev {
 	u8 going_away : 1;
 };
 
+struct smc_wr_rx_hdr {	/* common prefix part of LLC and CDC to demultiplex */
+	union {
+		u8 type;
+#if defined(__BIG_ENDIAN_BITFIELD)
+		struct {
+			u8 llc_version:4,
+			   llc_type:4;
+		};
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+		struct {
+			u8 llc_type:4,
+			   llc_version:4;
+		};
+#endif
+	};
+} __aligned(1);
+
+struct smc_cdc_conn_state_flags {
+#if defined(__BIG_ENDIAN_BITFIELD)
+	u8	peer_done_writing : 1;	/* Sending done indicator */
+	u8	peer_conn_closed : 1;	/* Peer connection closed indicator */
+	u8	peer_conn_abort : 1;	/* Abnormal close indicator */
+	u8	reserved : 5;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	u8	reserved : 5;
+	u8	peer_conn_abort : 1;
+	u8	peer_conn_closed : 1;
+	u8	peer_done_writing : 1;
+#endif
+};
+
+struct smc_cdc_producer_flags {
+#if defined(__BIG_ENDIAN_BITFIELD)
+	u8	write_blocked : 1;	/* Writing Blocked, no rx buf space */
+	u8	urg_data_pending : 1;	/* Urgent Data Pending */
+	u8	urg_data_present : 1;	/* Urgent Data Present */
+	u8	cons_curs_upd_req : 1;	/* cursor update requested */
+	u8	failover_validation : 1;/* message replay due to failover */
+	u8	reserved : 3;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	u8	reserved : 3;
+	u8	failover_validation : 1;
+	u8	cons_curs_upd_req : 1;
+	u8	urg_data_present : 1;
+	u8	urg_data_pending : 1;
+	u8	write_blocked : 1;
+#endif
+};
+
+/* in host byte order */
+union smc_host_cursor {	/* SMC cursor - an offset in an RMBE */
+	struct {
+		u16	reserved;
+		u16	wrap;		/* window wrap sequence number */
+		u32	count;		/* cursor (= offset) part */
+	};
+#ifdef KERNEL_HAS_ATOMIC64
+	atomic64_t		acurs;	/* for atomic processing */
+#else
+	u64			acurs;	/* for atomic processing */
+#endif
+} __aligned(8);
+
+/* in host byte order, except for flag bitfields in network byte order */
+struct smc_host_cdc_msg {		/* Connection Data Control message */
+	struct smc_wr_rx_hdr		common; /* .type = 0xFE */
+	u8				len;	/* length = 44 */
+	u16				seqno;	/* connection seq # */
+	u32				token;	/* alert_token */
+	union smc_host_cursor		prod;		/* producer cursor */
+	union smc_host_cursor		cons;		/* consumer cursor,
+							 * piggy backed "ack"
+							 */
+	struct smc_cdc_producer_flags	prod_flags;	/* conn. tx/rx status */
+	struct smc_cdc_conn_state_flags	conn_state_flags; /* peer conn. status*/
+	u8				reserved[18];
+} __aligned(8);
+
+enum smc_urg_state {
+	SMC_URG_VALID	= 1,			/* data present */
+	SMC_URG_NOTYET	= 2,			/* data pending */
+	SMC_URG_READ	= 3,			/* data was already read */
+};
+
+struct smc_connection {
+	struct rb_node		alert_node;
+	struct smc_link_group	*lgr;		/* link group of connection */
+	struct smc_link		*lnk;		/* assigned SMC-R link */
+	u32			alert_token_local; /* unique conn. id */
+	u8			peer_rmbe_idx;	/* from tcp handshake */
+	int			peer_rmbe_size;	/* size of peer rx buffer */
+	atomic_t		peer_rmbe_space;/* remaining free bytes in peer
+						 * rmbe
+						 */
+	int			rtoken_idx;	/* idx to peer RMB rkey/addr */
+
+	struct smc_buf_desc	*sndbuf_desc;	/* send buffer descriptor */
+	struct smc_buf_desc	*rmb_desc;	/* RMBE descriptor */
+	int			rmbe_size_short;/* compressed notation */
+	int			rmbe_update_limit;
+						/* lower limit for consumer
+						 * cursor update
+						 */
+
+	struct smc_host_cdc_msg	local_tx_ctrl;	/* host byte order staging
+						 * buffer for CDC msg send
+						 * .prod cf. TCP snd_nxt
+						 * .cons cf. TCP sends ack
+						 */
+	union smc_host_cursor	local_tx_ctrl_fin;
+						/* prod crsr - confirmed by peer
+						 */
+	union smc_host_cursor	tx_curs_prep;	/* tx - prepared data
+						 * snd_max..wmem_alloc
+						 */
+	union smc_host_cursor	tx_curs_sent;	/* tx - sent data
+						 * snd_nxt ?
+						 */
+	union smc_host_cursor	tx_curs_fin;	/* tx - confirmed by peer
+						 * snd-wnd-begin ?
+						 */
+	atomic_t		sndbuf_space;	/* remaining space in sndbuf */
+	u16			tx_cdc_seq;	/* sequence # for CDC send */
+	u16			tx_cdc_seq_fin;	/* sequence # - tx completed */
+	spinlock_t		send_lock;	/* protect wr_sends */
+	atomic_t		cdc_pend_tx_wr; /* number of pending tx CDC wqe
+						 * - inc when post wqe,
+						 * - dec on polled tx cqe
+						 */
+	wait_queue_head_t	cdc_pend_tx_wq; /* wakeup on no cdc_pend_tx_wr*/
+	atomic_t		tx_pushing;     /* nr_threads trying tx push */
+	struct delayed_work	tx_work;	/* retry of smc_cdc_msg_send */
+	u32			tx_off;		/* base offset in peer rmb */
+
+	struct smc_host_cdc_msg	local_rx_ctrl;	/* filled during event_handl.
+						 * .prod cf. TCP rcv_nxt
+						 * .cons cf. TCP snd_una
+						 */
+	union smc_host_cursor	rx_curs_confirmed; /* confirmed to peer
+						    * source of snd_una ?
+						    */
+	union smc_host_cursor	urg_curs;	/* points at urgent byte */
+	enum smc_urg_state	urg_state;
+	bool			urg_tx_pend;	/* urgent data staged */
+	bool			urg_rx_skip_pend;
+						/* indicate urgent oob data
+						 * read, but previous regular
+						 * data still pending
+						 */
+	char			urg_rx_byte;	/* urgent byte */
+	bool			tx_in_release_sock;
+						/* flush pending tx data in
+						 * sock release_cb()
+						 */
+	atomic_t		bytes_to_rcv;	/* arrived data,
+						 * not yet received
+						 */
+	atomic_t		splice_pending;	/* number of spliced bytes
+						 * pending processing
+						 */
+#ifndef KERNEL_HAS_ATOMIC64
+	spinlock_t		acurs_lock;	/* protect cursors */
+#endif
+	struct work_struct	close_work;	/* peer sent some closing */
+	struct work_struct	abort_work;	/* abort the connection */
+	struct tasklet_struct	rx_tsklet;	/* Receiver tasklet for SMC-D */
+	u8			rx_off;		/* receive offset:
+						 * 0 for SMC-R, 32 for SMC-D
+						 */
+	u64			peer_token;	/* SMC-D token of peer */
+	u8			killed : 1;	/* abnormal termination */
+	u8			freed : 1;	/* normal termiation */
+	u8			out_of_sync : 1; /* out of sync with peer */
+};
+
+struct smc_sock {				/* smc sock container */
+	struct sock		sk;
+	struct socket		*clcsock;	/* internal tcp socket */
+	void			(*clcsk_state_change)(struct sock *sk);
+						/* original stat_change fct. */
+	void			(*clcsk_data_ready)(struct sock *sk);
+						/* original data_ready fct. */
+	void			(*clcsk_write_space)(struct sock *sk);
+						/* original write_space fct. */
+	void			(*clcsk_error_report)(struct sock *sk);
+						/* original error_report fct. */
+	struct smc_connection	conn;		/* smc connection */
+	struct smc_sock		*listen_smc;	/* listen parent */
+	struct work_struct	connect_work;	/* handle non-blocking connect*/
+	struct work_struct	tcp_listen_work;/* handle tcp socket accepts */
+	struct work_struct	smc_listen_work;/* prepare new accept socket */
+	struct list_head	accept_q;	/* sockets to be accepted */
+	spinlock_t		accept_q_lock;	/* protects accept_q */
+	bool			limit_smc_hs;	/* put constraint on handshake */
+	bool			use_fallback;	/* fallback to tcp */
+	int			fallback_rsn;	/* reason for fallback */
+	u32			peer_diagnosis; /* decline reason from peer */
+	atomic_t                queued_smc_hs;  /* queued smc handshakes */
+	struct inet_connection_sock_af_ops		af_ops;
+	const struct inet_connection_sock_af_ops	*ori_af_ops;
+						/* original af ops */
+	int			sockopt_defer_accept;
+						/* sockopt TCP_DEFER_ACCEPT
+						 * value
+						 */
+	u8			wait_close_tx_prepared : 1;
+						/* shutdown wr or close
+						 * started, waiting for unsent
+						 * data to be sent
+						 */
+	u8			connect_nonblock : 1;
+						/* non-blocking connect in
+						 * flight
+						 */
+	struct mutex            clcsock_release_lock;
+						/* protects clcsock of a listen
+						 * socket
+						 */
+};
+
 #endif	/* _SMC_H */
net/smc/smc.h +0 -224

242 lines not on this page · raw message

Signature · 1 line
1.8.3.1
reviewer
#2 lore raw

Re: [PATCH bpf-next 1/5] net/smc: move smc_sock related structure definition

Quoted 4 lines · D. Wythe

From: "D. Wythe" <[email protected]>

This patch only try to move the definition of smc_sock and its related structure, from et/smc/smc.h to include/net/smc/smc.h.

                         ^^^^^^^^^^^^^

net/smc/smc.h ?

Quoted 509 lines

In that way can ebpf generate the BTF ID corresponding to our structure.

Of course, we can also choose to hide the structure and only to expose an intermediate structure, but it requires an additional transformation. If we need to obtain some information frequently, this may cause some performance problems.

---
  include/net/smc.h | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  net/smc/smc.h     | 224 -----------------------------------------------------
  2 files changed, 225 insertions(+), 224 deletions(-)
include/net/smc.h +225 -0
index a002552..6d076f5 100644
@@ -11,12 +11,17 @@
  #ifndef _SMC_H
  #define _SMC_H
 
+#include <net/inet_connection_sock.h>
  #include <linux/device.h>
  #include <linux/spinlock.h>
  #include <linux/types.h>
  #include <linux/wait.h>
  #include "linux/ism.h"
 
+#ifdef ATOMIC64_INIT
+#define KERNEL_HAS_ATOMIC64
+#endif
+
  struct sock;
 
  #define SMC_MAX_PNETID_LEN	16	/* Max. length of PNET id */
@@ -91,4 +96,224 @@ struct smcd_dev {
  	u8 going_away : 1;
  };
 
+struct smc_wr_rx_hdr {	/* common prefix part of LLC and CDC to demultiplex */
+	union {
+		u8 type;
+#if defined(__BIG_ENDIAN_BITFIELD)
+		struct {
+			u8 llc_version:4,
+			   llc_type:4;
+		};
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+		struct {
+			u8 llc_type:4,
+			   llc_version:4;
+		};
+#endif
+	};
+} __aligned(1);
+
+struct smc_cdc_conn_state_flags {
+#if defined(__BIG_ENDIAN_BITFIELD)
+	u8	peer_done_writing : 1;	/* Sending done indicator */
+	u8	peer_conn_closed : 1;	/* Peer connection closed indicator */
+	u8	peer_conn_abort : 1;	/* Abnormal close indicator */
+	u8	reserved : 5;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	u8	reserved : 5;
+	u8	peer_conn_abort : 1;
+	u8	peer_conn_closed : 1;
+	u8	peer_done_writing : 1;
+#endif
+};
+
+struct smc_cdc_producer_flags {
+#if defined(__BIG_ENDIAN_BITFIELD)
+	u8	write_blocked : 1;	/* Writing Blocked, no rx buf space */
+	u8	urg_data_pending : 1;	/* Urgent Data Pending */
+	u8	urg_data_present : 1;	/* Urgent Data Present */
+	u8	cons_curs_upd_req : 1;	/* cursor update requested */
+	u8	failover_validation : 1;/* message replay due to failover */
+	u8	reserved : 3;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	u8	reserved : 3;
+	u8	failover_validation : 1;
+	u8	cons_curs_upd_req : 1;
+	u8	urg_data_present : 1;
+	u8	urg_data_pending : 1;
+	u8	write_blocked : 1;
+#endif
+};
+
+/* in host byte order */
+union smc_host_cursor {	/* SMC cursor - an offset in an RMBE */
+	struct {
+		u16	reserved;
+		u16	wrap;		/* window wrap sequence number */
+		u32	count;		/* cursor (= offset) part */
+	};
+#ifdef KERNEL_HAS_ATOMIC64
+	atomic64_t		acurs;	/* for atomic processing */
+#else
+	u64			acurs;	/* for atomic processing */
+#endif
+} __aligned(8);
+
+/* in host byte order, except for flag bitfields in network byte order */
+struct smc_host_cdc_msg {		/* Connection Data Control message */
+	struct smc_wr_rx_hdr		common; /* .type = 0xFE */
+	u8				len;	/* length = 44 */
+	u16				seqno;	/* connection seq # */
+	u32				token;	/* alert_token */
+	union smc_host_cursor		prod;		/* producer cursor */
+	union smc_host_cursor		cons;		/* consumer cursor,
+							 * piggy backed "ack"
+							 */
+	struct smc_cdc_producer_flags	prod_flags;	/* conn. tx/rx status */
+	struct smc_cdc_conn_state_flags	conn_state_flags; /* peer conn. status*/
+	u8				reserved[18];
+} __aligned(8);
+
+enum smc_urg_state {
+	SMC_URG_VALID	= 1,			/* data present */
+	SMC_URG_NOTYET	= 2,			/* data pending */
+	SMC_URG_READ	= 3,			/* data was already read */
+};
+
+struct smc_connection {
+	struct rb_node		alert_node;
+	struct smc_link_group	*lgr;		/* link group of connection */
+	struct smc_link		*lnk;		/* assigned SMC-R link */
+	u32			alert_token_local; /* unique conn. id */
+	u8			peer_rmbe_idx;	/* from tcp handshake */
+	int			peer_rmbe_size;	/* size of peer rx buffer */
+	atomic_t		peer_rmbe_space;/* remaining free bytes in peer
+						 * rmbe
+						 */
+	int			rtoken_idx;	/* idx to peer RMB rkey/addr */
+
+	struct smc_buf_desc	*sndbuf_desc;	/* send buffer descriptor */
+	struct smc_buf_desc	*rmb_desc;	/* RMBE descriptor */
+	int			rmbe_size_short;/* compressed notation */
+	int			rmbe_update_limit;
+						/* lower limit for consumer
+						 * cursor update
+						 */
+
+	struct smc_host_cdc_msg	local_tx_ctrl;	/* host byte order staging
+						 * buffer for CDC msg send
+						 * .prod cf. TCP snd_nxt
+						 * .cons cf. TCP sends ack
+						 */
+	union smc_host_cursor	local_tx_ctrl_fin;
+						/* prod crsr - confirmed by peer
+						 */
+	union smc_host_cursor	tx_curs_prep;	/* tx - prepared data
+						 * snd_max..wmem_alloc
+						 */
+	union smc_host_cursor	tx_curs_sent;	/* tx - sent data
+						 * snd_nxt ?
+						 */
+	union smc_host_cursor	tx_curs_fin;	/* tx - confirmed by peer
+						 * snd-wnd-begin ?
+						 */
+	atomic_t		sndbuf_space;	/* remaining space in sndbuf */
+	u16			tx_cdc_seq;	/* sequence # for CDC send */
+	u16			tx_cdc_seq_fin;	/* sequence # - tx completed */
+	spinlock_t		send_lock;	/* protect wr_sends */
+	atomic_t		cdc_pend_tx_wr; /* number of pending tx CDC wqe
+						 * - inc when post wqe,
+						 * - dec on polled tx cqe
+						 */
+	wait_queue_head_t	cdc_pend_tx_wq; /* wakeup on no cdc_pend_tx_wr*/
+	atomic_t		tx_pushing;     /* nr_threads trying tx push */
+	struct delayed_work	tx_work;	/* retry of smc_cdc_msg_send */
+	u32			tx_off;		/* base offset in peer rmb */
+
+	struct smc_host_cdc_msg	local_rx_ctrl;	/* filled during event_handl.
+						 * .prod cf. TCP rcv_nxt
+						 * .cons cf. TCP snd_una
+						 */
+	union smc_host_cursor	rx_curs_confirmed; /* confirmed to peer
+						    * source of snd_una ?
+						    */
+	union smc_host_cursor	urg_curs;	/* points at urgent byte */
+	enum smc_urg_state	urg_state;
+	bool			urg_tx_pend;	/* urgent data staged */
+	bool			urg_rx_skip_pend;
+						/* indicate urgent oob data
+						 * read, but previous regular
+						 * data still pending
+						 */
+	char			urg_rx_byte;	/* urgent byte */
+	bool			tx_in_release_sock;
+						/* flush pending tx data in
+						 * sock release_cb()
+						 */
+	atomic_t		bytes_to_rcv;	/* arrived data,
+						 * not yet received
+						 */
+	atomic_t		splice_pending;	/* number of spliced bytes
+						 * pending processing
+						 */
+#ifndef KERNEL_HAS_ATOMIC64
+	spinlock_t		acurs_lock;	/* protect cursors */
+#endif
+	struct work_struct	close_work;	/* peer sent some closing */
+	struct work_struct	abort_work;	/* abort the connection */
+	struct tasklet_struct	rx_tsklet;	/* Receiver tasklet for SMC-D */
+	u8			rx_off;		/* receive offset:
+						 * 0 for SMC-R, 32 for SMC-D
+						 */
+	u64			peer_token;	/* SMC-D token of peer */
+	u8			killed : 1;	/* abnormal termination */
+	u8			freed : 1;	/* normal termiation */
+	u8			out_of_sync : 1; /* out of sync with peer */
+};
+
+struct smc_sock {				/* smc sock container */
+	struct sock		sk;
+	struct socket		*clcsock;	/* internal tcp socket */
+	void			(*clcsk_state_change)(struct sock *sk);
+						/* original stat_change fct. */
+	void			(*clcsk_data_ready)(struct sock *sk);
+						/* original data_ready fct. */
+	void			(*clcsk_write_space)(struct sock *sk);
+						/* original write_space fct. */
+	void			(*clcsk_error_report)(struct sock *sk);
+						/* original error_report fct. */
+	struct smc_connection	conn;		/* smc connection */
+	struct smc_sock		*listen_smc;	/* listen parent */
+	struct work_struct	connect_work;	/* handle non-blocking connect*/
+	struct work_struct	tcp_listen_work;/* handle tcp socket accepts */
+	struct work_struct	smc_listen_work;/* prepare new accept socket */
+	struct list_head	accept_q;	/* sockets to be accepted */
+	spinlock_t		accept_q_lock;	/* protects accept_q */
+	bool			limit_smc_hs;	/* put constraint on handshake */
+	bool			use_fallback;	/* fallback to tcp */
+	int			fallback_rsn;	/* reason for fallback */
+	u32			peer_diagnosis; /* decline reason from peer */
+	atomic_t                queued_smc_hs;  /* queued smc handshakes */
+	struct inet_connection_sock_af_ops		af_ops;
+	const struct inet_connection_sock_af_ops	*ori_af_ops;
+						/* original af ops */
+	int			sockopt_defer_accept;
+						/* sockopt TCP_DEFER_ACCEPT
+						 * value
+						 */
+	u8			wait_close_tx_prepared : 1;
+						/* shutdown wr or close
+						 * started, waiting for unsent
+						 * data to be sent
+						 */
+	u8			connect_nonblock : 1;
+						/* non-blocking connect in
+						 * flight
+						 */
+	struct mutex            clcsock_release_lock;
+						/* protects clcsock of a listen
+						 * socket
+						 */
+};
+
  #endif	/* _SMC_H */
net/smc/smc.h +0 -224
index 2eeea4c..55ae8883 100644
@@ -34,10 +34,6 @@
  extern struct proto smc_proto;
  extern struct proto smc_proto6;
 
-#ifdef ATOMIC64_INIT
-#define KERNEL_HAS_ATOMIC64
-#endif
-
  enum smc_state {		/* possible states of an SMC socket */
  	SMC_ACTIVE	= 1,
  	SMC_INIT	= 2,
@@ -57,232 +53,12 @@ enum smc_state {		/* possible states of an SMC socket */
 
  struct smc_link_group;
 
-struct smc_wr_rx_hdr {	/* common prefix part of LLC and CDC to demultiplex */
-	union {
-		u8 type;
-#if defined(__BIG_ENDIAN_BITFIELD)
-		struct {
-			u8 llc_version:4,
-			   llc_type:4;
-		};
-#elif defined(__LITTLE_ENDIAN_BITFIELD)
-		struct {
-			u8 llc_type:4,
-			   llc_version:4;
-		};
-#endif
-	};
-} __aligned(1);
-
-struct smc_cdc_conn_state_flags {
-#if defined(__BIG_ENDIAN_BITFIELD)
-	u8	peer_done_writing : 1;	/* Sending done indicator */
-	u8	peer_conn_closed : 1;	/* Peer connection closed indicator */
-	u8	peer_conn_abort : 1;	/* Abnormal close indicator */
-	u8	reserved : 5;
-#elif defined(__LITTLE_ENDIAN_BITFIELD)
-	u8	reserved : 5;
-	u8	peer_conn_abort : 1;
-	u8	peer_conn_closed : 1;
-	u8	peer_done_writing : 1;
-#endif
-};
-
-struct smc_cdc_producer_flags {
-#if defined(__BIG_ENDIAN_BITFIELD)
-	u8	write_blocked : 1;	/* Writing Blocked, no rx buf space */
-	u8	urg_data_pending : 1;	/* Urgent Data Pending */
-	u8	urg_data_present : 1;	/* Urgent Data Present */
-	u8	cons_curs_upd_req : 1;	/* cursor update requested */
-	u8	failover_validation : 1;/* message replay due to failover */
-	u8	reserved : 3;
-#elif defined(__LITTLE_ENDIAN_BITFIELD)
-	u8	reserved : 3;
-	u8	failover_validation : 1;
-	u8	cons_curs_upd_req : 1;
-	u8	urg_data_present : 1;
-	u8	urg_data_pending : 1;
-	u8	write_blocked : 1;
-#endif
-};
-
-/* in host byte order */
-union smc_host_cursor {	/* SMC cursor - an offset in an RMBE */
-	struct {
-		u16	reserved;
-		u16	wrap;		/* window wrap sequence number */
-		u32	count;		/* cursor (= offset) part */
-	};
-#ifdef KERNEL_HAS_ATOMIC64
-	atomic64_t		acurs;	/* for atomic processing */
-#else
-	u64			acurs;	/* for atomic processing */
-#endif
-} __aligned(8);
-
-/* in host byte order, except for flag bitfields in network byte order */
-struct smc_host_cdc_msg {		/* Connection Data Control message */
-	struct smc_wr_rx_hdr		common; /* .type = 0xFE */
-	u8				len;	/* length = 44 */
-	u16				seqno;	/* connection seq # */
-	u32				token;	/* alert_token */
-	union smc_host_cursor		prod;		/* producer cursor */
-	union smc_host_cursor		cons;		/* consumer cursor,
-							 * piggy backed "ack"
-							 */
-	struct smc_cdc_producer_flags	prod_flags;	/* conn. tx/rx status */
-	struct smc_cdc_conn_state_flags	conn_state_flags; /* peer conn. status*/
-	u8				reserved[18];
-} __aligned(8);
-
-enum smc_urg_state {
-	SMC_URG_VALID	= 1,			/* data present */
-	SMC_URG_NOTYET	= 2,			/* data pending */
-	SMC_URG_READ	= 3,			/* data was already read */
-};
-
  struct smc_mark_woken {
  	bool woken;
  	void *key;
  	wait_queue_entry_t wait_entry;
  };
 
-struct smc_connection {
-	struct rb_node		alert_node;
-	struct smc_link_group	*lgr;		/* link group of connection */
-	struct smc_link		*lnk;		/* assigned SMC-R link */
-	u32			alert_token_local; /* unique conn. id */
-	u8			peer_rmbe_idx;	/* from tcp handshake */
-	int			peer_rmbe_size;	/* size of peer rx buffer */
-	atomic_t		peer_rmbe_space;/* remaining free bytes in peer
-						 * rmbe
-						 */
-	int			rtoken_idx;	/* idx to peer RMB rkey/addr */
-
-	struct smc_buf_desc	*sndbuf_desc;	/* send buffer descriptor */
-	struct smc_buf_desc	*rmb_desc;	/* RMBE descriptor */
-	int			rmbe_size_short;/* compressed notation */
-	int			rmbe_update_limit;
-						/* lower limit for consumer
-						 * cursor update
-						 */
-
-	struct smc_host_cdc_msg	local_tx_ctrl;	/* host byte order staging
-						 * buffer for CDC msg send
-						 * .prod cf. TCP snd_nxt
-						 * .cons cf. TCP sends ack
-						 */
-	union smc_host_cursor	local_tx_ctrl_fin;
-						/* prod crsr - confirmed by peer
-						 */
-	union smc_host_cursor	tx_curs_prep;	/* tx - prepared data
-						 * snd_max..wmem_alloc
-						 */
-	union smc_host_cursor	tx_curs_sent;	/* tx - sent data
-						 * snd_nxt ?
-						 */
-	union smc_host_cursor	tx_curs_fin;	/* tx - confirmed by peer
-						 * snd-wnd-begin ?
-						 */
-	atomic_t		sndbuf_space;	/* remaining space in sndbuf */
-	u16			tx_cdc_seq;	/* sequence # for CDC send */
-	u16			tx_cdc_seq_fin;	/* sequence # - tx completed */
-	spinlock_t		send_lock;	/* protect wr_sends */
-	atomic_t		cdc_pend_tx_wr; /* number of pending tx CDC wqe
-						 * - inc when post wqe,
-						 * - dec on polled tx cqe
-						 */
-	wait_queue_head_t	cdc_pend_tx_wq; /* wakeup on no cdc_pend_tx_wr*/
-	atomic_t		tx_pushing;     /* nr_threads trying tx push */
-	struct delayed_work	tx_work;	/* retry of smc_cdc_msg_send */
-	u32			tx_off;		/* base offset in peer rmb */
-
-	struct smc_host_cdc_msg	local_rx_ctrl;	/* filled during event_handl.
-						 * .prod cf. TCP rcv_nxt
-						 * .cons cf. TCP snd_una
-						 */
-	union smc_host_cursor	rx_curs_confirmed; /* confirmed to peer
-						    * source of snd_una ?
-						    */
-	union smc_host_cursor	urg_curs;	/* points at urgent byte */
-	enum smc_urg_state	urg_state;
-	bool			urg_tx_pend;	/* urgent data staged */
-	bool			urg_rx_skip_pend;
-						/* indicate urgent oob data
-						 * read, but previous regular
-						 * data still pending
-						 */
-	char			urg_rx_byte;	/* urgent byte */
-	bool			tx_in_release_sock;
-						/* flush pending tx data in
-						 * sock release_cb()
-						 */
-	atomic_t		bytes_to_rcv;	/* arrived data,
-						 * not yet received
-						 */
-	atomic_t		splice_pending;	/* number of spliced bytes
-						 * pending processing
-						 */
-#ifndef KERNEL_HAS_ATOMIC64
-	spinlock_t		acurs_lock;	/* protect cursors */
-#endif
-	struct work_struct	close_work;	/* peer sent some closing */
-	struct work_struct	abort_work;	/* abort the connection */
-	struct tasklet_struct	rx_tsklet;	/* Receiver tasklet for SMC-D */
-	u8			rx_off;		/* receive offset:
-						 * 0 for SMC-R, 32 for SMC-D
-						 */
-	u64			peer_token;	/* SMC-D token of peer */
-	u8			killed : 1;	/* abnormal termination */
-	u8			freed : 1;	/* normal termiation */
-	u8			out_of_sync : 1; /* out of sync with peer */
-};
-
-struct smc_sock {				/* smc sock container */
-	struct sock		sk;
-	struct socket		*clcsock;	/* internal tcp socket */
-	void			(*clcsk_state_change)(struct sock *sk);
-						/* original stat_change fct. */
-	void			(*clcsk_data_ready)(struct sock *sk);
-						/* original data_ready fct. */
-	void			(*clcsk_write_space)(struct sock *sk);
-						/* original write_space fct. */
-	void			(*clcsk_error_report)(struct sock *sk);
-						/* original error_report fct. */
-	struct smc_connection	conn;		/* smc connection */
-	struct smc_sock		*listen_smc;	/* listen parent */
-	struct work_struct	connect_work;	/* handle non-blocking connect*/
-	struct work_struct	tcp_listen_work;/* handle tcp socket accepts */
-	struct work_struct	smc_listen_work;/* prepare new accept socket */
-	struct list_head	accept_q;	/* sockets to be accepted */
-	spinlock_t		accept_q_lock;	/* protects accept_q */
-	bool			limit_smc_hs;	/* put constraint on handshake */
-	bool			use_fallback;	/* fallback to tcp */
-	int			fallback_rsn;	/* reason for fallback */
-	u32			peer_diagnosis; /* decline reason from peer */
-	atomic_t                queued_smc_hs;  /* queued smc handshakes */
-	struct inet_connection_sock_af_ops		af_ops;
-	const struct inet_connection_sock_af_ops	*ori_af_ops;
-						/* original af ops */
-	int			sockopt_defer_accept;
-						/* sockopt TCP_DEFER_ACCEPT
-						 * value
-						 */
-	u8			wait_close_tx_prepared : 1;
-						/* shutdown wr or close
-						 * started, waiting for unsent
-						 * data to be sent
-						 */
-	u8			connect_nonblock : 1;
-						/* non-blocking connect in
-						 * flight
-						 */
-	struct mutex            clcsock_release_lock;
-						/* protects clcsock of a listen
-						 * socket
-						 * */
-};
-
  #define smc_sk(ptr) container_of_const(ptr, struct smc_sock, sk)
 
  static inline void smc_init_saved_callbacks(struct smc_sock *smc)
author maintainer
#3 lore raw

Re: [PATCH bpf-next 1/5] net/smc: move smc_sock related structure definition

Quoted 9 lines · Wen Gu
Quoted 4 lines · D. Wythe

From: "D. Wythe" <[email protected]>

This patch only try to move the definition of smc_sock and its related structure, from et/smc/smc.h to include/net/smc/smc.h.

                         ^^^^^^^^^^^^^
net/smc/smc.h ?

You are right. My Mistake.

D. Wythe

Quoted 530 lines
Quoted 530 lines

In that way can ebpf generate the BTF ID corresponding to our structure.

Of course, we can also choose to hide the structure and only to expose an intermediate structure, but it requires an additional transformation. If we need to obtain some information frequently, this may cause some performance problems.

---
  include/net/smc.h | 225
++++++++++++++++++++++++++++++++++++++++++++++++++++++
  net/smc/smc.h     | 224
-----------------------------------------------------

  2 files changed, 225 insertions(+), 224 deletions(-)
include/net/smc.h +0 -0
index a002552..6d076f5 100644
@@ -11,12 +11,17 @@
   #ifndef _SMC_H
   #define _SMC_H

  +#include <net/inet_connection_sock.h>
  #include <linux/device.h>
  #include <linux/spinlock.h>
  #include <linux/types.h>
  #include <linux/wait.h>
  #include "linux/ism.h"
  +#ifdef ATOMIC64_INIT

include/net/smc.h +3 -0
+#define KERNEL_HAS_ATOMIC64
+#endif
+

  struct sock;
    #define SMC_MAX_PNETID_LEN    16    /* Max. length of PNET id */

include/net/smc.h +0 -0
@@ -91,4 +96,224 @@ struct smcd_dev {
       u8 going_away : 1;
   };

  +struct smc_wr_rx_hdr {    /* common prefix part of LLC and CDC to demultiplex */ +    union {
+        u8 type;

include/net/smc.h +18 -0
+#if defined(__BIG_ENDIAN_BITFIELD)
+        struct {
+            u8 llc_version:4,
+               llc_type:4;
+        };
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+        struct {
+            u8 llc_type:4,
+               llc_version:4;
+        };
+#endif
+    };
+} __aligned(1);
+
+struct smc_cdc_conn_state_flags {
+#if defined(__BIG_ENDIAN_BITFIELD)
+    u8    peer_done_writing : 1;    /* Sending done indicator */
+    u8    peer_conn_closed : 1;    /* Peer connection closed 

indicator */
+    u8    peer_conn_abort : 1;    /* Abnormal close indicator */ +    u8    reserved : 5;

include/net/smc.h +41 -0
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+    u8    reserved : 5;
+    u8    peer_conn_abort : 1;
+    u8    peer_conn_closed : 1;
+    u8    peer_done_writing : 1;
+#endif
+};
+
+struct smc_cdc_producer_flags {
+#if defined(__BIG_ENDIAN_BITFIELD)
+    u8    write_blocked : 1;    /* Writing Blocked, no rx buf space */
+    u8    urg_data_pending : 1;    /* Urgent Data Pending */
+    u8    urg_data_present : 1;    /* Urgent Data Present */
+    u8    cons_curs_upd_req : 1;    /* cursor update requested */
+    u8    failover_validation : 1;/* message replay due to failover */
+    u8    reserved : 3;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+    u8    reserved : 3;
+    u8    failover_validation : 1;
+    u8    cons_curs_upd_req : 1;
+    u8    urg_data_present : 1;
+    u8    urg_data_pending : 1;
+    u8    write_blocked : 1;
+#endif
+};
+
+/* in host byte order */
+union smc_host_cursor {    /* SMC cursor - an offset in an RMBE */
+    struct {
+        u16    reserved;
+        u16    wrap;        /* window wrap sequence number */
+        u32    count;        /* cursor (= offset) part */
+    };
+#ifdef KERNEL_HAS_ATOMIC64
+    atomic64_t        acurs;    /* for atomic processing */
+#else
+    u64            acurs;    /* for atomic processing */
+#endif
+} __aligned(8);
+
+/* in host byte order, except for flag bitfields in network byte 

order */
+struct smc_host_cdc_msg {        /* Connection Data Control message */ +    struct smc_wr_rx_hdr        common; /* .type = 0xFE */ +    u8                len;    /* length = 44 */
+    u16                seqno;    /* connection seq # */
+    u32                token;    /* alert_token */
+    union smc_host_cursor        prod;        /* producer cursor */ +    union smc_host_cursor        cons;        /* consumer cursor, +                             * piggy backed "ack"
+                             */
+    struct smc_cdc_producer_flags    prod_flags;    /* conn. tx/rx status */
+    struct smc_cdc_conn_state_flags    conn_state_flags; /* peer conn. status*/
+    u8                reserved[18];

include/net/smc.h +11 -0
+} __aligned(8);
+
+enum smc_urg_state {
+    SMC_URG_VALID    = 1,            /* data present */
+    SMC_URG_NOTYET    = 2,            /* data pending */
+    SMC_URG_READ    = 3,            /* data was already read */
+};
+
+struct smc_connection {
+    struct rb_node        alert_node;
+    struct smc_link_group    *lgr;        /* link group of 

connection */
+    struct smc_link        *lnk;        /* assigned SMC-R link */ +    u32            alert_token_local; /* unique conn. id */ +    u8            peer_rmbe_idx;    /* from tcp handshake */ +    int            peer_rmbe_size;    /* size of peer rx buffer */ +    atomic_t        peer_rmbe_space;/* remaining free bytes in peer +                         * rmbe
+                         */
+    int            rtoken_idx;    /* idx to peer RMB rkey/addr */ +
+    struct smc_buf_desc    *sndbuf_desc;    /* send buffer descriptor */
+    struct smc_buf_desc    *rmb_desc;    /* RMBE descriptor */ +    int            rmbe_size_short;/* compressed notation */ +    int            rmbe_update_limit;
+                        /* lower limit for consumer
+                         * cursor update
+                         */
+
+    struct smc_host_cdc_msg    local_tx_ctrl;    /* host byte order staging
+                         * buffer for CDC msg send
+                         * .prod cf. TCP snd_nxt
+                         * .cons cf. TCP sends ack
+                         */
+    union smc_host_cursor    local_tx_ctrl_fin;
+                        /* prod crsr - confirmed by peer
+                         */
+    union smc_host_cursor    tx_curs_prep;    /* tx - prepared data +                         * snd_max..wmem_alloc
+                         */
+    union smc_host_cursor    tx_curs_sent;    /* tx - sent data +                         * snd_nxt ?
+                         */
+    union smc_host_cursor    tx_curs_fin;    /* tx - confirmed by peer +                         * snd-wnd-begin ?
+                         */
+    atomic_t        sndbuf_space;    /* remaining space in sndbuf */ +    u16            tx_cdc_seq;    /* sequence # for CDC send */ +    u16            tx_cdc_seq_fin;    /* sequence # - tx completed */ +    spinlock_t        send_lock;    /* protect wr_sends */ +    atomic_t        cdc_pend_tx_wr; /* number of pending tx CDC wqe +                         * - inc when post wqe,
+                         * - dec on polled tx cqe
+                         */
+    wait_queue_head_t    cdc_pend_tx_wq; /* wakeup on no cdc_pend_tx_wr*/
+    atomic_t        tx_pushing;     /* nr_threads trying tx push */ +    struct delayed_work    tx_work;    /* retry of smc_cdc_msg_send */ +    u32            tx_off;        /* base offset in peer rmb */ +
+    struct smc_host_cdc_msg    local_rx_ctrl;    /* filled during event_handl.
+                         * .prod cf. TCP rcv_nxt
+                         * .cons cf. TCP snd_una
+                         */
+    union smc_host_cursor    rx_curs_confirmed; /* confirmed to peer +                            * source of snd_una ?
+                            */
+    union smc_host_cursor    urg_curs;    /* points at urgent byte */ +    enum smc_urg_state    urg_state;
+    bool            urg_tx_pend;    /* urgent data staged */ +    bool            urg_rx_skip_pend;
+                        /* indicate urgent oob data
+                         * read, but previous regular
+                         * data still pending
+                         */
+    char            urg_rx_byte;    /* urgent byte */
+    bool            tx_in_release_sock;
+                        /* flush pending tx data in
+                         * sock release_cb()
+                         */
+    atomic_t        bytes_to_rcv;    /* arrived data,
+                         * not yet received
+                         */
+    atomic_t        splice_pending;    /* number of spliced bytes +                         * pending processing
+                         */

include/net/smc.h +6 -0
+#ifndef KERNEL_HAS_ATOMIC64
+    spinlock_t        acurs_lock;    /* protect cursors */
+#endif
+    struct work_struct    close_work;    /* peer sent some closing */
+    struct work_struct    abort_work;    /* abort the connection */
+    struct tasklet_struct    rx_tsklet;    /* Receiver tasklet for 

SMC-D */
+    u8            rx_off;        /* receive offset:
+                         * 0 for SMC-R, 32 for SMC-D +                         */
+    u64            peer_token;    /* SMC-D token of peer */ +    u8            killed : 1;    /* abnormal termination */ +    u8            freed : 1;    /* normal termiation */ +    u8            out_of_sync : 1; /* out of sync with peer */

include/net/smc.h +16 -0
+};
+
+struct smc_sock {                /* smc sock container */
+    struct sock        sk;
+    struct socket        *clcsock;    /* internal tcp socket */
+    void            (*clcsk_state_change)(struct sock *sk);
+                        /* original stat_change fct. */
+    void            (*clcsk_data_ready)(struct sock *sk);
+                        /* original data_ready fct. */
+    void            (*clcsk_write_space)(struct sock *sk);
+                        /* original write_space fct. */
+    void            (*clcsk_error_report)(struct sock *sk);
+                        /* original error_report fct. */
+    struct smc_connection    conn;        /* smc connection */
+    struct smc_sock        *listen_smc;    /* listen parent */
+    struct work_struct    connect_work;    /* handle non-blocking 

connect*/
+    struct work_struct    tcp_listen_work;/* handle tcp socket accepts */
+    struct work_struct    smc_listen_work;/* prepare new accept socket */
+    struct list_head    accept_q;    /* sockets to be accepted */ +    spinlock_t        accept_q_lock;    /* protects accept_q */ +    bool            limit_smc_hs;    /* put constraint on handshake */ +    bool            use_fallback;    /* fallback to tcp */ +    int            fallback_rsn;    /* reason for fallback */ +    u32            peer_diagnosis; /* decline reason from peer */ +    atomic_t                queued_smc_hs;  /* queued smc handshakes */ +    struct inet_connection_sock_af_ops        af_ops;
+    const struct inet_connection_sock_af_ops    *ori_af_ops; +                        /* original af ops */
+    int            sockopt_defer_accept;
+                        /* sockopt TCP_DEFER_ACCEPT
+                         * value
+                         */
+    u8            wait_close_tx_prepared : 1;
+                        /* shutdown wr or close
+                         * started, waiting for unsent
+                         * data to be sent
+                         */
+    u8            connect_nonblock : 1;
+                        /* non-blocking connect in
+                         * flight
+                         */
+    struct mutex            clcsock_release_lock;
+                        /* protects clcsock of a listen
+                         * socket
+                         */

include/net/smc.h +2 -0
+};
+

  #endif    /* _SMC_H */

net/smc/smc.h +0 -0
index 2eeea4c..55ae8883 100644
@@ -34,10 +34,6 @@
   extern struct proto smc_proto;
   extern struct proto smc_proto6;

  -#ifdef ATOMIC64_INIT

net/smc/smc.h +0 -3
-#define KERNEL_HAS_ATOMIC64
-#endif
-

  enum smc_state {        /* possible states of an SMC socket */ SMC_ACTIVE    = 1,
      SMC_INIT    = 2,

net/smc/smc.h +0 -0
@@ -57,232 +53,12 @@ enum smc_state {        /* possible states of an 

SMC socket */
    struct smc_link_group;
  -struct smc_wr_rx_hdr {    /* common prefix part of LLC and CDC to demultiplex */ -    union {
-        u8 type;

net/smc/smc.h +0 -18
-#if defined(__BIG_ENDIAN_BITFIELD)
-        struct {
-            u8 llc_version:4,
-               llc_type:4;
-        };
-#elif defined(__LITTLE_ENDIAN_BITFIELD)
-        struct {
-            u8 llc_type:4,
-               llc_version:4;
-        };
-#endif
-    };
-} __aligned(1);
-
-struct smc_cdc_conn_state_flags {
-#if defined(__BIG_ENDIAN_BITFIELD)
-    u8    peer_done_writing : 1;    /* Sending done indicator */
-    u8    peer_conn_closed : 1;    /* Peer connection closed 

indicator */
-    u8    peer_conn_abort : 1;    /* Abnormal close indicator */ -    u8    reserved : 5;

net/smc/smc.h +0 -41
-#elif defined(__LITTLE_ENDIAN_BITFIELD)
-    u8    reserved : 5;
-    u8    peer_conn_abort : 1;
-    u8    peer_conn_closed : 1;
-    u8    peer_done_writing : 1;
-#endif
-};
-
-struct smc_cdc_producer_flags {
-#if defined(__BIG_ENDIAN_BITFIELD)
-    u8    write_blocked : 1;    /* Writing Blocked, no rx buf space */
-    u8    urg_data_pending : 1;    /* Urgent Data Pending */
-    u8    urg_data_present : 1;    /* Urgent Data Present */
-    u8    cons_curs_upd_req : 1;    /* cursor update requested */
-    u8    failover_validation : 1;/* message replay due to failover */
-    u8    reserved : 3;
-#elif defined(__LITTLE_ENDIAN_BITFIELD)
-    u8    reserved : 3;
-    u8    failover_validation : 1;
-    u8    cons_curs_upd_req : 1;
-    u8    urg_data_present : 1;
-    u8    urg_data_pending : 1;
-    u8    write_blocked : 1;
-#endif
-};
-
-/* in host byte order */
-union smc_host_cursor {    /* SMC cursor - an offset in an RMBE */
-    struct {
-        u16    reserved;
-        u16    wrap;        /* window wrap sequence number */
-        u32    count;        /* cursor (= offset) part */
-    };
-#ifdef KERNEL_HAS_ATOMIC64
-    atomic64_t        acurs;    /* for atomic processing */
-#else
-    u64            acurs;    /* for atomic processing */
-#endif
-} __aligned(8);
-
-/* in host byte order, except for flag bitfields in network byte 

order */
-struct smc_host_cdc_msg {        /* Connection Data Control message */ -    struct smc_wr_rx_hdr        common; /* .type = 0xFE */ -    u8                len;    /* length = 44 */
-    u16                seqno;    /* connection seq # */
-    u32                token;    /* alert_token */
-    union smc_host_cursor        prod;        /* producer cursor */ -    union smc_host_cursor        cons;        /* consumer cursor, -                             * piggy backed "ack"
-                             */
-    struct smc_cdc_producer_flags    prod_flags;    /* conn. tx/rx status */
-    struct smc_cdc_conn_state_flags    conn_state_flags; /* peer conn. status*/
-    u8                reserved[18];

net/smc/smc.h +0 -8
-} __aligned(8);
-
-enum smc_urg_state {
-    SMC_URG_VALID    = 1,            /* data present */
-    SMC_URG_NOTYET    = 2,            /* data pending */
-    SMC_URG_READ    = 3,            /* data was already read */
-};
-

  struct smc_mark_woken {
      bool woken;
      void *key;
      wait_queue_entry_t wait_entry;
  };
  -struct smc_connection {
-    struct rb_node        alert_node;
-    struct smc_link_group    *lgr;        /* link group of connection */
-    struct smc_link        *lnk;        /* assigned SMC-R link */ -    u32            alert_token_local; /* unique conn. id */ -    u8            peer_rmbe_idx;    /* from tcp handshake */ -    int            peer_rmbe_size;    /* size of peer rx buffer */ -    atomic_t        peer_rmbe_space;/* remaining free bytes in peer -                         * rmbe
-                         */
-    int            rtoken_idx;    /* idx to peer RMB rkey/addr */ -
-    struct smc_buf_desc    *sndbuf_desc;    /* send buffer descriptor */
-    struct smc_buf_desc    *rmb_desc;    /* RMBE descriptor */ -    int            rmbe_size_short;/* compressed notation */ -    int            rmbe_update_limit;
-                        /* lower limit for consumer
-                         * cursor update
-                         */
-
-    struct smc_host_cdc_msg    local_tx_ctrl;    /* host byte order staging
-                         * buffer for CDC msg send
-                         * .prod cf. TCP snd_nxt
-                         * .cons cf. TCP sends ack
-                         */
-    union smc_host_cursor    local_tx_ctrl_fin;
-                        /* prod crsr - confirmed by peer
-                         */
-    union smc_host_cursor    tx_curs_prep;    /* tx - prepared data -                         * snd_max..wmem_alloc
-                         */
-    union smc_host_cursor    tx_curs_sent;    /* tx - sent data -                         * snd_nxt ?
-                         */
-    union smc_host_cursor    tx_curs_fin;    /* tx - confirmed by peer -                         * snd-wnd-begin ?
-                         */
-    atomic_t        sndbuf_space;    /* remaining space in sndbuf */ -    u16            tx_cdc_seq;    /* sequence # for CDC send */ -    u16            tx_cdc_seq_fin;    /* sequence # - tx completed */ -    spinlock_t        send_lock;    /* protect wr_sends */ -    atomic_t        cdc_pend_tx_wr; /* number of pending tx CDC wqe -                         * - inc when post wqe,
-                         * - dec on polled tx cqe
-                         */
-    wait_queue_head_t    cdc_pend_tx_wq; /* wakeup on no cdc_pend_tx_wr*/
-    atomic_t        tx_pushing;     /* nr_threads trying tx push */ -    struct delayed_work    tx_work;    /* retry of smc_cdc_msg_send */ -    u32            tx_off;        /* base offset in peer rmb */ -
-    struct smc_host_cdc_msg    local_rx_ctrl;    /* filled during event_handl.
-                         * .prod cf. TCP rcv_nxt
-                         * .cons cf. TCP snd_una
-                         */
-    union smc_host_cursor    rx_curs_confirmed; /* confirmed to peer -                            * source of snd_una ?
-                            */
-    union smc_host_cursor    urg_curs;    /* points at urgent byte */ -    enum smc_urg_state    urg_state;
-    bool            urg_tx_pend;    /* urgent data staged */ -    bool            urg_rx_skip_pend;
-                        /* indicate urgent oob data
-                         * read, but previous regular
-                         * data still pending
-                         */
-    char            urg_rx_byte;    /* urgent byte */
-    bool            tx_in_release_sock;
-                        /* flush pending tx data in
-                         * sock release_cb()
-                         */
-    atomic_t        bytes_to_rcv;    /* arrived data,
-                         * not yet received
-                         */
-    atomic_t        splice_pending;    /* number of spliced bytes -                         * pending processing
-                         */

net/smc/smc.h +0 -6
-#ifndef KERNEL_HAS_ATOMIC64
-    spinlock_t        acurs_lock;    /* protect cursors */
-#endif
-    struct work_struct    close_work;    /* peer sent some closing */
-    struct work_struct    abort_work;    /* abort the connection */
-    struct tasklet_struct    rx_tsklet;    /* Receiver tasklet for 

SMC-D */
-    u8            rx_off;        /* receive offset:
-                         * 0 for SMC-R, 32 for SMC-D -                         */
-    u64            peer_token;    /* SMC-D token of peer */ -    u8            killed : 1;    /* abnormal termination */ -    u8            freed : 1;    /* normal termiation */ -    u8            out_of_sync : 1; /* out of sync with peer */

net/smc/smc.h +0 -16
-};
-
-struct smc_sock {                /* smc sock container */
-    struct sock        sk;
-    struct socket        *clcsock;    /* internal tcp socket */
-    void            (*clcsk_state_change)(struct sock *sk);
-                        /* original stat_change fct. */
-    void            (*clcsk_data_ready)(struct sock *sk);
-                        /* original data_ready fct. */
-    void            (*clcsk_write_space)(struct sock *sk);
-                        /* original write_space fct. */
-    void            (*clcsk_error_report)(struct sock *sk);
-                        /* original error_report fct. */
-    struct smc_connection    conn;        /* smc connection */
-    struct smc_sock        *listen_smc;    /* listen parent */
-    struct work_struct    connect_work;    /* handle non-blocking 

connect*/
-    struct work_struct    tcp_listen_work;/* handle tcp socket accepts */
-    struct work_struct    smc_listen_work;/* prepare new accept socket */
-    struct list_head    accept_q;    /* sockets to be accepted */ -    spinlock_t        accept_q_lock;    /* protects accept_q */ -    bool            limit_smc_hs;    /* put constraint on handshake */ -    bool            use_fallback;    /* fallback to tcp */ -    int            fallback_rsn;    /* reason for fallback */ -    u32            peer_diagnosis; /* decline reason from peer */ -    atomic_t                queued_smc_hs;  /* queued smc handshakes */ -    struct inet_connection_sock_af_ops        af_ops;
-    const struct inet_connection_sock_af_ops    *ori_af_ops; -                        /* original af ops */
-    int            sockopt_defer_accept;
-                        /* sockopt TCP_DEFER_ACCEPT
-                         * value
-                         */
-    u8            wait_close_tx_prepared : 1;
-                        /* shutdown wr or close
-                         * started, waiting for unsent
-                         * data to be sent
-                         */
-    u8            connect_nonblock : 1;
-                        /* non-blocking connect in
-                         * flight
-                         */
-    struct mutex            clcsock_release_lock;
-                        /* protects clcsock of a listen
-                         * socket
-                         * */

net/smc/smc.h +0 -2
-};
-

  #define smc_sk(ptr) container_of_const(ptr, struct smc_sock, sk) static inline void smc_init_saved_callbacks(struct smc_sock *smc)

author maintainer
#4 lore raw

PATCH 2/5 net/smc: allow smc to negotiate protocols on policies

In reply to D. Wythe

From: "D. Wythe" <[email protected]>

As we all know, the SMC protocol is not suitable for all scenarios, especially for short-lived. However, for most applications, they cannot guarantee that there are no such scenarios at all. Therefore, apps may need some specific strategies to decide shall we need to use SMC or not.

Just like the congestion control implementation in TCP, this patch provides a generic negotiator implementation. If necessary, we can provide different protocol negotiation strategies for apps based on this implementation.

But most importantly, this patch provides the possibility of eBPF injection, allowing users to implement their own protocol negotiation policy in userspace.

---
 include/net/smc.h |  43 ++++++++++++
 net/Makefile      |   1 +
 net/smc/Kconfig   |  11 +++
 net/smc/af_smc.c  |  68 +++++++++++++++++-
 net/smc/bpf_smc.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 net/smc/bpf_smc.c
include/net/smc.h +43 -0
index 6d076f5..cd701a3 100644
@@ -296,6 +296,8 @@ struct smc_sock {				/* smc sock container */
 	atomic_t                queued_smc_hs;  /* queued smc handshakes */
 	struct inet_connection_sock_af_ops		af_ops;
 	const struct inet_connection_sock_af_ops	*ori_af_ops;
+	/* protocol negotiator ops */
+	const struct smc_sock_negotiator_ops *negotiator_ops;
 						/* original af ops */
 	int			sockopt_defer_accept;
 						/* sockopt TCP_DEFER_ACCEPT
@@ -316,4 +318,45 @@ struct smc_sock {				/* smc sock container */
 						 */
 };
 
+#ifdef CONFIG_SMC_BPF
+
+#define SMC_NEGOTIATOR_NAME_MAX	(16)
+#define SMC_SOCK_CLOSED_TIMING	(0)
+
+/* BPF struct ops for smc protocol negotiator */
+struct smc_sock_negotiator_ops {
+
+	struct list_head	list;
+
+	/* ops name */
+	char		name[16];
+	/* key for name */
+	u32			key;
+
+	/* init with sk */
+	void (*init)(struct sock *sk);
+
+	/* release with sk */
+	void (*release)(struct sock *sk);
+
+	/* advice for negotiate */
+	int (*negotiate)(struct sock *sk);
+
+	/* info gathering timing */
+	void (*collect_info)(struct sock *sk, int timing);
+
+	/* module owner */
+	struct module *owner;
+};
+
+int smc_sock_register_negotiator_ops(struct smc_sock_negotiator_ops *ops);
+int smc_sock_update_negotiator_ops(struct smc_sock_negotiator_ops *ops,
+					  struct smc_sock_negotiator_ops *old_ops);
+void smc_sock_unregister_negotiator_ops(struct smc_sock_negotiator_ops *ops);
+int smc_sock_assign_negotiator_ops(struct smc_sock *smc, const char *name);
+void smc_sock_cleanup_negotiator_ops(struct smc_sock *smc, int in_release);
+void smc_sock_clone_negotiator_ops(struct sock *parent, struct sock *child);
+
+#endif
+
 #endif	/* _SMC_H */
net/Makefile +1 -0
index 8759200..af2f5ea 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_TIPC)		+= tipc/
 obj-$(CONFIG_NETLABEL)		+= netlabel/
 obj-$(CONFIG_IUCV)		+= iucv/
 obj-$(CONFIG_SMC)		+= smc/
+obj-$(CONFIG_SMC_BPF)		+= smc/bpf_smc.o
 obj-$(CONFIG_RFKILL)		+= rfkill/
 obj-$(CONFIG_NET_9P)		+= 9p/
 obj-$(CONFIG_CAIF)		+= caif/
net/smc/Kconfig +11 -0
index 1ab3c5a..bdcc9f1 100644
@@ -19,3 +19,14 @@ config SMC_DIAG
 	  smcss.
 
 	  if unsure, say Y.
+
+config SMC_BPF
+	bool "SMC: support eBPF" if SMC
+	depends on BPF_SYSCALL
+	default n
+	help
+	  Supports eBPF to allows user mode participation in SMC's protocol process
+	  via ebpf programs. Alternatively, obtain information about the SMC socks
+	  through the ebpf program.
+
+	  If unsure, say N.
net/smc/af_smc.c +67 -1

104 lines not on this page · raw message

net/smc/bpf_smc.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

Re: [PATCH bpf-next 2/5] net/smc: allow smc to negotiate protocols on policies

Quoted 8 lines · D. Wythe

From: "D. Wythe" <[email protected]>

net/smc/bpf_smc.c new file +1 -0
new file mode 100644
index 0000000..0c0ec05
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0-only

... cut ...

Quoted 14 lines
net/smc/bpf_smc.c new file +14 -0
+
+/* register ops */
+int smc_sock_register_negotiator_ops(struct smc_sock_negotiator_ops *ops)
+{
+	int ret;
+
+	ret = smc_sock_validate_negotiator_ops(ops);
+	if (ret)
+		return ret;
+
+	/* calt key by name hash */
+	ops->key = jhash(ops->name, sizeof(ops->name), strlen(ops->name));
+
+	spin_lock(&smc_sock_negotiator_list_lock);

net/smc/bpf_smc.c line 74

Quoted 10 lines
net/smc/bpf_smc.c new file +10 -0
+	if (smc_negotiator_ops_get_by_key(ops->key)) {
+		pr_notice("smc: %s negotiator already registered\n", ops->name);
+		ret = -EEXIST;
+	} else {
+		list_add_tail_rcu(&ops->list, &smc_sock_negotiator_list);
+	}
+	spin_unlock(&smc_sock_negotiator_list_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(smc_sock_register_negotiator_ops);

This and following functions are not specific to BPF, right? I found you have more BPF specific code in this file in following patches. But, I feel these function should not in this file since they are not BPF specific because file name "bpf_smc.c" hints.

author maintainer
#6 lore raw

Re: [PATCH bpf-next 2/5] net/smc: allow smc to negotiate protocols on policies

Hi Lee,

Quoted 12 lines · Kui-Feng Lee
Quoted 8 lines · D. Wythe

From: "D. Wythe" <[email protected]>

net/smc/bpf_smc.c new file +1 -0
new file mode 100644
index 0000000..0c0ec05
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0-only

... cut ...

Will fix it, Thanks.

Quoted 23 lines
Quoted 23 lines
net/smc/bpf_smc.c new file +3 -0
+
+/* register ops */
+int smc_sock_register_negotiator_ops(struct smc_sock_negotiator_ops 

*ops)

net/smc/bpf_smc.c new file +13 -0
+{
+    int ret;
+
+    ret = smc_sock_validate_negotiator_ops(ops);
+    if (ret)
+        return ret;
+
+    /* calt key by name hash */
+    ops->key = jhash(ops->name, sizeof(ops->name), strlen(ops->name));
+
+    spin_lock(&smc_sock_negotiator_list_lock);
+    if (smc_negotiator_ops_get_by_key(ops->key)) {
+        pr_notice("smc: %s negotiator already registered\n", 

ops->name);
+        ret = -EEXIST;
+    } else {
+        list_add_tail_rcu(&ops->list, &smc_sock_negotiator_list); +    }
+    spin_unlock(&smc_sock_negotiator_list_lock);

Quoted 8 lines

net/smc/bpf_smc.c

Quoted 3 lines

+    return ret;

net/smc/bpf_smc.c new file +2 -0
+}
+EXPORT_SYMBOL_GPL(smc_sock_register_negotiator_ops);

This and following functions are not specific to BPF, right? I found you have more BPF specific code in this file in following patches.  But, I feel these function should not in this file since they are not BPF specific because file name "bpf_smc.c" hints.

Yes. Logically those functions are not suitable for being placed in "bpf_smc.c". However, since SMC is compiled as modules by default, and currently struct ops needs to be built in, or specific symbols will not be found during linking.

Of course, I can separate those this function in another new file, which can also be built in. I may have to introduce a new KConfig likes SMC_NEGOTIATOR. But this feature is  only effective when eBPF exists, so from the perspective of SMC, it would also be kind of weird.

But whatever, if you do think it's necessary, I can split it into two files.

Besh wishes.
D. Wythe

#7 lore raw

Re: [PATCH bpf-next 2/5] net/smc: allow smc to negotiate protocols on policies

Quoted 52 lines · D. Wythe

Hi Lee,

Quoted 12 lines · Kui-Feng Lee
Quoted 8 lines · D. Wythe

From: "D. Wythe" <[email protected]>

net/smc/bpf_smc.c new file +1 -0
new file mode 100644
index 0000000..0c0ec05
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0-only

... cut ...

Will fix it, Thanks.

Quoted 23 lines
Quoted 23 lines
net/smc/bpf_smc.c new file +3 -0
+
+/* register ops */
+int smc_sock_register_negotiator_ops(struct smc_sock_negotiator_ops 

*ops)

net/smc/bpf_smc.c new file +13 -0
+{
+    int ret;
+
+    ret = smc_sock_validate_negotiator_ops(ops);
+    if (ret)
+        return ret;
+
+    /* calt key by name hash */
+    ops->key = jhash(ops->name, sizeof(ops->name), strlen(ops->name));
+
+    spin_lock(&smc_sock_negotiator_list_lock);
+    if (smc_negotiator_ops_get_by_key(ops->key)) {
+        pr_notice("smc: %s negotiator already registered\n", 

ops->name);
+        ret = -EEXIST;
+    } else {
+        list_add_tail_rcu(&ops->list, &smc_sock_negotiator_list); +    }
+    spin_unlock(&smc_sock_negotiator_list_lock);

Quoted 8 lines

net/smc/bpf_smc.c

Quoted 3 lines

+    return ret;

net/smc/bpf_smc.c new file +2 -0
+}
+EXPORT_SYMBOL_GPL(smc_sock_register_negotiator_ops);

This and following functions are not specific to BPF, right? I found you have more BPF specific code in this file in following patches.  But, I feel these function should not in this file since they are not BPF specific because file name "bpf_smc.c" hints.

Quoted 7 lines

Yes. Logically those functions are not suitable for being placed in "bpf_smc.c". However, since SMC is compiled as modules by default, and currently struct ops needs to be built in, or specific symbols will not be found during linking.

Of course, I can separate those this function in another new file, which can also be built in. I may have to introduce a new KConfig likes SMC_NEGOTIATOR. But this feature is  only effective when eBPF exists, so from the perspective of SMC, it would also be kind of weird.

On the other hand, this feature is only effective when SMC exists. Even without BPF, you still can implement a negotiator in a module. Since you have exported these symbols, I suspect that you expect negotiators in modules or builtin, right? If I am wrong about exports, perhaps you should stop exporting since they are used locally only.

Quoted 8 lines

But whatever, if you do think it's necessary, I can split it into two files.

Besh wishes.
D. Wythe

author maintainer
#8 lore raw

PATCH 3/5 net/smc: allow set or get smc negotiator by sockopt

In reply to D. Wythe

From: "D. Wythe" <[email protected]>

Allow applications to set specific protocol negotiation rules for SMC Socks. Typically, applications need to know the name of the negotiator and then set it through the syscall setsockopt, for examples:

const char name[] = "apps";
setsockopt(fd, SOL_SMC, SMC_NEGOTIATOR, name, sizeof(name) - 1);

Noted that there is no default negotiator in SMC implementation, the application needs to inject the specific implementation through eBPF before setting it up. Although no default negotiator implementation is provided,

Note that SMC does not provide a default negotiator in SMC implementation,
and the application needs to inject the specific implementation through eBPF before setting it up. Although no default negotiator implementation is provided, logically it can be seen as an implementation that always return SK_PASS.

---
 include/uapi/linux/smc.h |   1 +
 net/smc/af_smc.c         | 135 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 102 insertions(+), 34 deletions(-)
include/uapi/linux/smc.h +1 -0
index bb4dacc..1887ed5 100644
@@ -299,5 +299,6 @@ enum {
 
 /* SMC socket options */
 #define SMC_LIMIT_HS 1	/* constraint on smc handshake */
+#define SMC_NEGOTIATOR 2 /* SMC protocol negotiator */
 
 #endif /* _UAPI_LINUX_SMC_H */
net/smc/af_smc.c +101 -34

184 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author maintainer
#9 lore raw

PATCH 4/5 bpf: add smc negotiator support in BPF struct_ops

In reply to D. Wythe

From: "D. Wythe" <[email protected]>

This PATCH attempts to introduce BPF injection capability for SMC. Considering that the SMC protocol is not suitable for all scenarios, especially for short-lived. However, for most applications, they cannot guarantee that there are no such scenarios at all. Therefore, apps may need some specific strategies to decide shall we need to use SMC or not, for example, apps can limit the scope of the SMC to a specific IP address or port.

Based on the consideration of transparent replacement, we hope that apps can remain transparent even if they need to formulate some specific strategies for SMC using. That is, do not need to recompile their code.

On the other hand, we need to ensure the scalability of strategies implementation. Although it is simple to use socket options or sysctl, it will bring more complexity to subsequent expansion.

Fortunately, BPF can solve these concerns very well, users can write thire own strategies in eBPF to choose whether to use SMC or not. And it's quite easy for them to modify their strategies in the future.

This PATCH implement injection capability for SMC via struct_ops. In that way, we can add new injection scenarios in the future.

---
 kernel/bpf/bpf_struct_ops_types.h |   4 +
 net/smc/bpf_smc.c                 | 159 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 163 insertions(+)
kernel/bpf/bpf_struct_ops_types.h +4 -0
index 5678a9d..d952b85 100644
@@ -9,4 +9,8 @@
 #include <net/tcp.h>
 BPF_STRUCT_OPS_TYPE(tcp_congestion_ops)
 #endif
+#if IS_ENABLED(CONFIG_SMC_BPF)
+#include <net/smc.h>
+BPF_STRUCT_OPS_TYPE(smc_sock_negotiator_ops)
+#endif
 #endif
net/smc/bpf_smc.c +159 -0

176 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author maintainer
#10 lore raw

PATCH 5/5 bpf/selftests: add selftest for SMC bpf capability

In reply to D. Wythe

From: "D. Wythe" <[email protected]>

This PATCH adds a tiny selftest for SMC bpf capability, making decisions on whether to use SMC by collecting certain information from kernel smc sock.

Follow the steps below to run this test.

make -C tools/testing/selftests/bpf
cd tools/testing/selftests/bpf
sudo ./test_progs -t smc

Results shows:

18/1    bpf_smc/load:OK
18/2    bpf_smc/update:OK
18/3    bpf_smc/ref:OK
18      bpf_smc:OK

Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED

---
 tools/testing/selftests/bpf/prog_tests/bpf_smc.c | 107 +++++++++
 tools/testing/selftests/bpf/progs/bpf_smc.c      | 265 +++++++++++++++++++++++
 2 files changed, 372 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_smc.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c
tools/testing/selftests/bpf/prog_tests/bpf_smc.c new file +107 -0
new file mode 100644
index 0000000..e668857
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/err.h>
+#include <netinet/tcp.h>
+#include <test_progs.h>
+#include "network_helpers.h"
+#include "bpf_smc.skel.h"
+
+#define SOL_SMC 286
+#define SMC_NEGOTIATOR 2
+static const char name[] = "apps";
+
+void run_smc(void)
+{
+	int fd, err;
+
+	fd = socket(AF_SMC, SOCK_STREAM, 0);
+	ASSERT_GT(fd, 0, "create smc socket");
+
+	err = setsockopt(fd, SOL_SMC, SMC_NEGOTIATOR, name, sizeof(name) / sizeof(char));
+	ASSERT_EQ(err, 0, "setsockopt");
+
+	close(fd);
+}
+
+void test_load(void)
+{
+	struct bpf_smc *smc_skel;
+	struct bpf_link *link;
+
+	smc_skel = bpf_smc__open_and_load();
+	if (!ASSERT_OK_PTR(smc_skel, "skel_open"))
+		return;
+
+	link = bpf_map__attach_struct_ops(smc_skel->maps.ops);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops"))
+		goto error;
+
+	bpf_link__destroy(link);
+error:
+	bpf_smc__destroy(smc_skel);
+}
+
+void test_update(void)
+{
+	struct bpf_smc *smc_skel;
+	struct bpf_link *link;
+	int err;
+
+	smc_skel = bpf_smc__open_and_load();
+	if (!ASSERT_OK_PTR(smc_skel, "skel_open"))
+		return;
+
+	link = bpf_map__attach_struct_ops(smc_skel->maps.accept);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops"))
+		goto error;
+
+	run_smc();
+	ASSERT_EQ(smc_skel->bss->accept_cnt, 1, "accept_cnt");
+
+	err = bpf_link__update_map(link, smc_skel->maps.drop);
+	ASSERT_OK(err, "update_map");
+
+	run_smc();
+	ASSERT_EQ(smc_skel->bss->accept_cnt, 1, "accept_cnt");
+	ASSERT_EQ(smc_skel->bss->drop_cnt, 1, "drop_cnt");
+
+	bpf_link__destroy(link);
+error:
+	bpf_smc__destroy(smc_skel);
+}
+
+void test_ref(void)
+{
+	struct bpf_smc *smc_skel;
+	struct bpf_link *link;
+	int fd = 0, err;
+
+	smc_skel = bpf_smc__open_and_load();
+	if (!ASSERT_OK_PTR(smc_skel, "skel_open"))
+		return;
+
+	link = bpf_map__attach_struct_ops(smc_skel->maps.accept);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops"))
+		goto error;
+
+	fd = socket(AF_SMC, SOCK_STREAM, 0);
+	ASSERT_GT(fd, 0, "create smc socket");
+	err = setsockopt(fd, SOL_SMC, SMC_NEGOTIATOR, name, sizeof(name) / sizeof(char));
+	ASSERT_EQ(err, 0, "setsockopt");
+	bpf_link__destroy(link);
+	if (fd > 0)
+		close(fd);
+	ASSERT_EQ(smc_skel->bss->accept_release_cnt, 1, "accept_release_cnt");
+error:
+	bpf_smc__destroy(smc_skel);
+}
+
+void test_bpf_smc(void)
+{
+	if (test__start_subtest("load"))
+		test_load();
+	if (test__start_subtest("update"))
+		test_update();
+	if (test__start_subtest("ref"))
+		test_ref();
+}
tools/testing/selftests/bpf/progs/bpf_smc.c new file +265 -0

265 lines not on this page · raw message

Signature · 1 line
1.8.3.1