Blame SOURCES/librdmacm-add-support-for-extended-join-mc.patch

6698ac
commit 3c1d25b8170b0c30d723b2bf89c390293dc4477c
6698ac
Author: Jason Gunthorpe <jgg@mellanox.com>
6698ac
Date:   Fri Nov 17 11:59:13 2017 -0700
6698ac
6698ac
    librdmacm: Add support for extended join multicast API
6698ac
    
6698ac
    Add support for specifying MC join flags.  The following multicast join
6698ac
    flags will now be supported by librdmacm (as already defined in the join
6698ac
    flags in rdma_user_cm.h through the UAPI of the kernel).
6698ac
    
6698ac
    -Full Member:
6698ac
     The initiator creates the Multicast group (MCG) if it wasn't previously
6698ac
     created, can send Multicast messages to the group and receive messages
6698ac
     from the MCG.
6698ac
    
6698ac
    -Send Only Full Member:
6698ac
     The initiator creates the Multicast group (MCG) if it wasn't previously
6698ac
     created, can send Multicast messages but doesn't receive any messages
6698ac
     from the MCG (send-only).
6698ac
    
6698ac
    Tested-by: Christoph Lameter <cl@linux.com>
6698ac
    Reviewed by: Hal Rosenstock <hal@mellanox.com>
6698ac
    Signed-off-by: Alex Vesker <valex@mellanox.com>
6698ac
    Signed-off-by: Christoph Lameter <cl@linux.com>
6698ac
    Reviewed-by: Jason Gunthorpe <jgg@ziepe.ca>
6698ac
    Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
6698ac
6698ac
Index: rdma-core-15/debian/librdmacm-dev.install
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/debian/librdmacm-dev.install
6698ac
+++ rdma-core-15/debian/librdmacm-dev.install
6698ac
@@ -33,6 +33,7 @@ usr/share/man/man3/rdma_get_send_comp.3
6698ac
 usr/share/man/man3/rdma_get_src_port.3
6698ac
 usr/share/man/man3/rdma_getaddrinfo.3
6698ac
 usr/share/man/man3/rdma_join_multicast.3
6698ac
+usr/share/man/man3/rdma_join_multicast_ex.3
6698ac
 usr/share/man/man3/rdma_leave_multicast.3
6698ac
 usr/share/man/man3/rdma_listen.3
6698ac
 usr/share/man/man3/rdma_migrate_id.3
6698ac
Index: rdma-core-15/debian/librdmacm1.symbols
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/debian/librdmacm1.symbols
6698ac
+++ rdma-core-15/debian/librdmacm1.symbols
6698ac
@@ -1,5 +1,6 @@
6698ac
 librdmacm.so.1 librdmacm1 #MINVER#
6698ac
  RDMACM_1.0@RDMACM_1.0 1.0.15
6698ac
+ RDMACM_1.1@RDMACM_1.1 16
6698ac
  raccept@RDMACM_1.0 1.0.16
6698ac
  rbind@RDMACM_1.0 1.0.16
6698ac
  rclose@RDMACM_1.0 1.0.16
6698ac
@@ -31,6 +32,7 @@ librdmacm.so.1 librdmacm1 #MINVER#
6698ac
  rdma_get_src_port@RDMACM_1.0 1.0.19
6698ac
  rdma_getaddrinfo@RDMACM_1.0 1.0.15
6698ac
  rdma_join_multicast@RDMACM_1.0 1.0.15
6698ac
+ rdma_join_multicast_ex@RDMACM_1.1 16
6698ac
  rdma_leave_multicast@RDMACM_1.0 1.0.15
6698ac
  rdma_listen@RDMACM_1.0 1.0.15
6698ac
  rdma_migrate_id@RDMACM_1.0 1.0.15
6698ac
Index: rdma-core-15/librdmacm/CMakeLists.txt
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/librdmacm/CMakeLists.txt
6698ac
+++ rdma-core-15/librdmacm/CMakeLists.txt
6698ac
@@ -10,7 +10,7 @@ publish_headers(infiniband
6698ac
 
6698ac
 rdma_library(rdmacm librdmacm.map
6698ac
   # See Documentation/versioning.md
6698ac
-  1 1.0.${PACKAGE_VERSION}
6698ac
+  1 1.1.${PACKAGE_VERSION}
6698ac
   acm.c
6698ac
   addrinfo.c
6698ac
   cma.c
6698ac
Index: rdma-core-15/librdmacm/cma.c
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/librdmacm/cma.c
6698ac
+++ rdma-core-15/librdmacm/cma.c
6698ac
@@ -114,6 +114,7 @@ struct cma_multicast {
6698ac
 	uint32_t	handle;
6698ac
 	union ibv_gid	mgid;
6698ac
 	uint16_t	mlid;
6698ac
+	uint16_t	join_flags;
6698ac
 	struct sockaddr_storage addr;
6698ac
 };
6698ac
 
6698ac
@@ -1713,7 +1714,8 @@ int rdma_disconnect(struct rdma_cm_id *i
6698ac
 }
6698ac
 
6698ac
 static int rdma_join_multicast2(struct rdma_cm_id *id, struct sockaddr *addr,
6698ac
-				socklen_t addrlen, void *context)
6698ac
+				socklen_t addrlen, uint16_t join_flags,
6698ac
+				void *context)
6698ac
 {
6698ac
 	struct ucma_abi_create_id_resp resp;
6698ac
 	struct cma_id_private *id_priv;
6698ac
@@ -1727,6 +1729,7 @@ static int rdma_join_multicast2(struct r
6698ac
 
6698ac
 	mc->context = context;
6698ac
 	mc->id_priv = id_priv;
6698ac
+	mc->join_flags = join_flags;
6698ac
 	memcpy(&mc->addr, addr, addrlen);
6698ac
 	if (pthread_cond_init(&mc->cond, NULL)) {
6698ac
 		ret = -1;
6698ac
@@ -1746,7 +1749,7 @@ static int rdma_join_multicast2(struct r
6698ac
 		memcpy(&cmd.addr, addr, addrlen);
6698ac
 		cmd.addr_size = addrlen;
6698ac
 		cmd.uid = (uintptr_t) mc;
6698ac
-		cmd.reserved = 0;
6698ac
+		cmd.join_flags = join_flags;
6698ac
 
6698ac
 		ret = write(id->channel->fd, &cmd, sizeof cmd);
6698ac
 		if (ret != sizeof cmd) {
6698ac
@@ -1784,6 +1787,30 @@ err1:
6698ac
 	return ret;
6698ac
 }
6698ac
 
6698ac
+int rdma_join_multicast_ex(struct rdma_cm_id *id,
6698ac
+			   struct rdma_cm_join_mc_attr_ex *mc_join_attr,
6698ac
+			   void *context)
6698ac
+{
6698ac
+	int addrlen;
6698ac
+
6698ac
+	if (mc_join_attr->comp_mask >= RDMA_CM_JOIN_MC_ATTR_RESERVED)
6698ac
+		return ERR(ENOTSUP);
6698ac
+
6698ac
+	if (!(mc_join_attr->comp_mask & RDMA_CM_JOIN_MC_ATTR_ADDRESS))
6698ac
+		return ERR(EINVAL);
6698ac
+
6698ac
+	if (!(mc_join_attr->comp_mask & RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS) ||
6698ac
+	    (mc_join_attr->join_flags >= RDMA_MC_JOIN_FLAG_RESERVED))
6698ac
+		return ERR(EINVAL);
6698ac
+
6698ac
+	addrlen = ucma_addrlen(mc_join_attr->addr);
6698ac
+	if (!addrlen)
6698ac
+		return ERR(EINVAL);
6698ac
+
6698ac
+	return rdma_join_multicast2(id, mc_join_attr->addr, addrlen,
6698ac
+				    mc_join_attr->join_flags, context);
6698ac
+}
6698ac
+
6698ac
 int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
6698ac
 			void *context)
6698ac
 {
6698ac
@@ -1793,7 +1820,8 @@ int rdma_join_multicast(struct rdma_cm_i
6698ac
 	if (!addrlen)
6698ac
 		return ERR(EINVAL);
6698ac
 
6698ac
-	return rdma_join_multicast2(id, addr, addrlen, context);
6698ac
+	return rdma_join_multicast2(id, addr, addrlen,
6698ac
+				    RDMA_MC_JOIN_FLAG_FULLMEMBER, context);
6698ac
 }
6698ac
 
6698ac
 int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
6698ac
@@ -1821,7 +1849,7 @@ int rdma_leave_multicast(struct rdma_cm_
6698ac
 	if (!mc)
6698ac
 		return ERR(EADDRNOTAVAIL);
6698ac
 
6698ac
-	if (id->qp)
6698ac
+	if (id->qp && (mc->join_flags != RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER))
6698ac
 		ibv_detach_mcast(id->qp, &mc->mgid, mc->mlid);
6698ac
 	
6698ac
 	CMA_INIT_CMD_RESP(&cmd, sizeof cmd, LEAVE_MCAST, &resp, sizeof resp);
6698ac
@@ -2009,6 +2037,10 @@ static int ucma_process_join(struct cma_
6698ac
 	if (!evt->id_priv->id.qp)
6698ac
 		return 0;
6698ac
 
6698ac
+	/* Don't attach QP to multicast if joined as send only full member */
6698ac
+	if (evt->mc->join_flags == RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER)
6698ac
+		return 0;
6698ac
+
6698ac
 	return rdma_seterrno(ibv_attach_mcast(evt->id_priv->id.qp,
6698ac
 					      &evt->mc->mgid, evt->mc->mlid));
6698ac
 }
6698ac
Index: rdma-core-15/librdmacm/librdmacm.map
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/librdmacm/librdmacm.map
6698ac
+++ rdma-core-15/librdmacm/librdmacm.map
6698ac
@@ -71,3 +71,8 @@ RDMACM_1.0 {
6698ac
 		rdma_create_qp_ex;
6698ac
 	local: *;
6698ac
 };
6698ac
+
6698ac
+RDMACM_1.1 {
6698ac
+	global:
6698ac
+		rdma_join_multicast_ex;
6698ac
+} RDMACM_1.0;
6698ac
Index: rdma-core-15/librdmacm/man/CMakeLists.txt
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/librdmacm/man/CMakeLists.txt
6698ac
+++ rdma-core-15/librdmacm/man/CMakeLists.txt
6698ac
@@ -33,6 +33,7 @@ rdma_man_pages(
6698ac
   rdma_get_src_port.3
6698ac
   rdma_getaddrinfo.3
6698ac
   rdma_join_multicast.3
6698ac
+  rdma_join_multicast_ex.3
6698ac
   rdma_leave_multicast.3
6698ac
   rdma_listen.3
6698ac
   rdma_migrate_id.3
6698ac
Index: rdma-core-15/librdmacm/man/rdma_join_multicast_ex.3
6698ac
===================================================================
6698ac
--- /dev/null
6698ac
+++ rdma-core-15/librdmacm/man/rdma_join_multicast_ex.3
6698ac
@@ -0,0 +1,66 @@
6698ac
+.TH "RDMA_JOIN_MULTICAST_EX" 3 "2017-11-17" "librdmacm" "Librdmacm Programmer's Manual" librdmacm
6698ac
+.SH NAME
6698ac
+rdma_join_multicast_ex \- Joins a multicast group with extended options.
6698ac
+.SH SYNOPSIS
6698ac
+.B "#include <rdma/rdma_cma.h>"
6698ac
+.P
6698ac
+.B "int" rdma_join_multicast_ex
6698ac
+.BI "(struct rdma_cm_id *" id ","
6698ac
+.BI "struct rdma_cm_join_mc_attr_ex *" mc_join_attr ","
6698ac
+.BI "void *" context ");"
6698ac
+.SH ARGUMENTS
6698ac
+.IP "id" 20
6698ac
+Communication identifier associated with the request.
6698ac
+.IP "mc_join_attr" 20
6698ac
+Is an rdma_cm_join_mc_attr_ex struct, as defined in <rdma/rdma_cma.h>.
6698ac
+.IP "context" 20
6698ac
+User-defined context associated with the join request.
6698ac
+.SH "DESCRIPTION"
6698ac
+Joins a multicast group (MCG) with extended options.
6698ac
+Currently supporting MC join with a specified join flag.
6698ac
+.P
6698ac
+.nf
6698ac
+struct rdma_cm_join_mc_attr_ex {
6698ac
+.in +8
6698ac
+uint32_t                comp_mask;      /* Bitwise OR between "rdma_cm_join_mc_attr_mask" enum */
6698ac
+uint32_t                join_flags;     /* Use a single flag from "rdma_cm_mc_join_flags" enum */
6698ac
+struct sockaddr         *addr;          /* Multicast address identifying the group to join */
6698ac
+.in -8
6698ac
+};
6698ac
+.fi
6698ac
+.P
6698ac
+The supported join flags are:
6698ac
+.P
6698ac
+.B RDMA_MC_JOIN_FLAG_FULLMEMBER
6698ac
+- Create multicast group, Send multicast messages to MCG, Receive multicast messages from MCG.
6698ac
+.P
6698ac
+.B RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER
6698ac
+- Create multicast group, Send multicast messages to MCG, Don't receive multicast messages from MCG (send-only).
6698ac
+.P
6698ac
+Initiating a MC join as "Send Only Full Member" on InfiniBand requires SM support, otherwise joining will fail.
6698ac
+.P
6698ac
+Initiating a MC join as "Send Only Full Member" on RoCEv2/ETH will not send any IGMP messages unlike a Full Member MC join.
6698ac
+When "Send Only Full Member" is used the QP will not be attached to the MCG.
6698ac
+.P
6698ac
+.SH "RETURN VALUE"
6698ac
+Returns 0 on success, or -1 on error.  If an error occurs, errno will be
6698ac
+set to indicate the failure reason.
6698ac
+.SH "NOTES"
6698ac
+Before joining a multicast group, the rdma_cm_id must be bound to
6698ac
+an RDMA device by calling rdma_bind_addr or rdma_resolve_addr.  Use of
6698ac
+rdma_resolve_addr requires the local routing tables to resolve the
6698ac
+multicast address to an RDMA device, unless a specific source address
6698ac
+is provided.  The user must call rdma_leave_multicast to leave the
6698ac
+multicast group and release any multicast resources.  After the join
6698ac
+operation completes, if a QP is associated with the rdma_cm_id,
6698ac
+it is automatically attached to the multicast group when the multicast
6698ac
+event is retrieved by the user.  Otherwise, the user is responsible
6698ac
+for calling ibv_attach_mcast to bind the QP to the multicast group.
6698ac
+The join context is returned to the user through the private_data
6698ac
+field in the rdma_cm_event.
6698ac
+.SH "SEE ALSO"
6698ac
+rdma_join_multicast(3), rdma_leave_multicast(3), rdma_bind_addr(3), rdma_resolve_addr(3), rdma_create_qp(3),
6698ac
+rdma_get_cm_event(3)
6698ac
+.SH "AUTHORS"
6698ac
+.TP
6698ac
+Alex Vesker <valex@mellanox.com>
6698ac
Index: rdma-core-15/librdmacm/rdma_cma.h
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/librdmacm/rdma_cma.h
6698ac
+++ rdma-core-15/librdmacm/rdma_cma.h
6698ac
@@ -197,6 +197,29 @@ struct rdma_addrinfo {
6698ac
 	struct rdma_addrinfo	*ai_next;
6698ac
 };
6698ac
 
6698ac
+/* Multicast join compatibility mask attributes */
6698ac
+enum rdma_cm_join_mc_attr_mask {
6698ac
+	RDMA_CM_JOIN_MC_ATTR_ADDRESS	= 1 << 0,
6698ac
+	RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS	= 1 << 1,
6698ac
+	RDMA_CM_JOIN_MC_ATTR_RESERVED	= 1 << 2,
6698ac
+};
6698ac
+
6698ac
+/* Multicast join flags */
6698ac
+enum rdma_cm_mc_join_flags {
6698ac
+	RDMA_MC_JOIN_FLAG_FULLMEMBER,
6698ac
+	RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER,
6698ac
+	RDMA_MC_JOIN_FLAG_RESERVED,
6698ac
+};
6698ac
+
6698ac
+struct rdma_cm_join_mc_attr_ex {
6698ac
+	/* Bitwise OR between "rdma_cm_join_mc_attr_mask" enum */
6698ac
+	uint32_t comp_mask;
6698ac
+	/* Use a flag from "rdma_cm_mc_join_flags" enum */
6698ac
+	uint32_t join_flags;
6698ac
+	/* Multicast address identifying the group to join */
6698ac
+	struct sockaddr *addr;
6698ac
+};
6698ac
+
6698ac
 /**
6698ac
  * rdma_create_event_channel - Open a channel used to report communication events.
6698ac
  * Description:
6698ac
@@ -555,6 +578,30 @@ int rdma_join_multicast(struct rdma_cm_i
6698ac
 int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr);
6698ac
 
6698ac
 /**
6698ac
+ * rdma_multicast_ex - Joins a multicast group with options.
6698ac
+ * @id: Communication identifier associated with the request.
6698ac
+ * @mc_join_attr: Extensive struct containing multicast join parameters.
6698ac
+ * @context: User-defined context associated with the join request.
6698ac
+ * Description:
6698ac
+ *  Joins a multicast group with options. Currently supporting MC join flags.
6698ac
+ *  The QP will be attached based on the given join flag.
6698ac
+ *  Join message will be sent according to the join flag.
6698ac
+ * Notes:
6698ac
+ *  Before joining a multicast group, the rdma_cm_id must be bound to
6698ac
+ *  an RDMA device by calling rdma_bind_addr or rdma_resolve_addr.  Use of
6698ac
+ *  rdma_resolve_addr requires the local routing tables to resolve the
6698ac
+ *  multicast address to an RDMA device.  The user must call
6698ac
+ *  rdma_leave_multicast to leave the multicast group and release any
6698ac
+ *  multicast resources.  The context is returned to the user through
6698ac
+ *  the private_data field in the rdma_cm_event.
6698ac
+ * See also:
6698ac
+ *  rdma_leave_multicast, rdma_bind_addr, rdma_resolve_addr, rdma_create_qp
6698ac
+ */
6698ac
+int rdma_join_multicast_ex(struct rdma_cm_id *id,
6698ac
+			   struct rdma_cm_join_mc_attr_ex *mc_join_attr,
6698ac
+			   void *context);
6698ac
+
6698ac
+/**
6698ac
  * rdma_get_cm_event - Retrieves the next pending communication event.
6698ac
  * @channel: Event channel to check for events.
6698ac
  * @event: Allocated information about the next communication event.
6698ac
Index: rdma-core-15/librdmacm/rdma_cma_abi.h
6698ac
===================================================================
6698ac
--- rdma-core-15.orig/librdmacm/rdma_cma_abi.h
6698ac
+++ rdma-core-15/librdmacm/rdma_cma_abi.h
6698ac
@@ -302,7 +302,7 @@ struct ucma_abi_join_mcast {
6698ac
 	__u64 uid;
6698ac
 	__u32 id;
6698ac
 	__u16 addr_size;
6698ac
-	__u16 reserved;
6698ac
+	__u16 join_flags;
6698ac
 	struct sockaddr_storage addr;
6698ac
 };
6698ac