ib/mad: Add ability for user space applications to control RMPP directly
cover ib/mad: Add ability for user space applications to control RMPP directly
My apologies if anyone receives duplicates of these emails. Apparently the series did not make it to linux-rdma the first time.
The first 3 patches update the umad and mad modules to use pr_* style print messages in preparation for adding pr_notice messages to the existing and new registration functions.
The final 2 patches add a new registration mechanism which allows for flags to be specified at ib_mad registration time. The first such flag is to allow user control of RMPP transactions.
Existing registration and RMPP transactions are unaffected by this change.
[PATCH 1/5] ib/umad: update module to pr_* style print messages [PATCH 2/5] ib/mad: update module to pr_* style print messages [PATCH 3/5] ib/mad: Add pr_notice messages for various umad/mad [PATCH 4/5] ib/mad: add new ioctl to user space to support new [PATCH 5/5] ib/mad: Add user space RMPP support
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/5 ib/umad: update module to pr_* style print messages
In reply to a message not in the archiveFrom: Ira Weiny <[email protected]>
Also combine previously line broken user-visible strings as per Documentation/CodingStyle
"However, never break user-visible strings such as printk messages, because that breaks the ability to grep for them."
--- drivers/infiniband/core/user_mad.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/infiniband/core/user_mad.c +10 -9
@@ -33,6 +33,8 @@* SOFTWARE. */ +#define pr_fmt (fmt) "user_mad: " fmt +#include <linux/module.h> #include <linux/init.h> #include <linux/device.h>
@@ -669,10 +671,9 @@ found:if (!file->already_used) { file->already_used =1 ;if (!file->use_pkey_index) { -printk (KERN_WARNING "user_mad: process %s did not enable " -"P_Key index support.\n" , current->comm); -printk (KERN_WARNING "user_mad: Documentation/infiniband/user_mad.txt " -"has info on the new ABI.\n" ); +pr_warn ("process %s did not enable P_Key index support.\n" , + current->comm); +pr_warn (" Documentation/infiniband/user_mad.txt has info on the new ABI.\n" ); } }
@@ -982,7 +983,7 @@ static int find_overflow_devnum(void) ret =alloc_chrdev_region (&overflow_maj,0 ,IB_UMAD_MAX_PORTS *2 ,"infiniband_mad" );if (ret) { -printk (KERN_ERR "user_mad: couldn't register dynamic device number\n" ); +pr_err ("couldn't register dynamic device number\n" );return ret; } }
@@ -1187,14 +1188,14 @@ static int __init ib_umad_init(void) ret =register_chrdev_region (base_dev,IB_UMAD_MAX_PORTS *2 ,"infiniband_mad" );if (ret) { -printk (KERN_ERR "user_mad: couldn't register device number\n" ); +pr_err ("couldn't register device number\n" ); goto out; } umad_class =class_create (THIS_MODULE ,"infiniband_mad" );if (IS_ERR (umad_class)) { ret =PTR_ERR (umad_class); -printk (KERN_ERR "user_mad: couldn't create class infiniband_mad\n" ); +pr_err ("couldn't create class infiniband_mad\n" ); goto out_chrdev; }
@@ -1202,13 +1203,13 @@ static int __init ib_umad_init(void) ret =class_create_file (umad_class, &class_attr_abi_version.attr);if (ret) { -printk (KERN_ERR "user_mad: couldn't create abi_version attribute\n" ); +pr_err ("couldn't create abi_version attribute\n" ); goto out_class; } ret =ib_register_client (&umad_client);if (ret) { -printk (KERN_ERR "user_mad: couldn't register ib_umad client\n" ); +pr_err ("couldn't register ib_umad client\n" ); goto out_class; }
Signature · 6 lines
1.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/5 ib/mad: update module to pr_* style print messages
In reply to a message not in the archiveFrom: Ira Weiny <[email protected]>
Also combine previously line broken user-visible strings as per Documentation/CodingStyle
"However, never break user-visible strings such as printk messages, because that breaks the ability to grep for them."
--- drivers/infiniband/core/agent.c | 14 +++--- drivers/infiniband/core/mad.c | 109 +++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 64 deletions(-)
drivers/infiniband/core/agent.c +8 -6
@@ -36,6 +36,8 @@* */ +#define pr_fmt (fmt) SPFX fmt +#include <linux/slab.h> #include <linux/string.h>
@@ -94,14 +96,14 @@ void agent_send_response(struct ib_mad *mad, struct ib_grh *grh, port_priv =ib_get_agent_port (device, port_num);if (!port_priv) { - printk(KERN_ERR SPFX "Unable to find port agent\n"); +pr_err ("Unable to find port agent\n" );return ; } agent = port_priv->agent[qpn]; ah =ib_create_ah_from_wc (agent->qp->pd, wc, grh, port_num);if (IS_ERR (ah)) { - printk(KERN_ERR SPFX "ib_create_ah_from_wc error %ld\n", +pr_err ("ib_create_ah_from_wc error %ld\n" ,PTR_ERR (ah));return ; }
@@ -110,7 +112,7 @@ void agent_send_response(struct ib_mad *mad, struct ib_grh *grh,IB_MGMT_MAD_HDR ,IB_MGMT_MAD_DATA , GFP_KERNEL);if (IS_ERR (send_buf)) { - printk(KERN_ERR SPFX "ib_create_send_mad error\n"); +pr_err ("ib_create_send_mad error\n" ); goto err1; }
@@ -125,7 +127,7 @@ void agent_send_response(struct ib_mad *mad, struct ib_grh *grh, }if (ib_post_send_mad (send_buf,NULL )) { - printk(KERN_ERR SPFX "ib_post_send_mad error\n"); +pr_err ("ib_post_send_mad error\n" ); goto err2; }return ;
@@ -151,7 +153,7 @@ int ib_agent_port_open(struct ib_device *device, int port_num)/* Create new device info */ port_priv =kzalloc (sizeof *port_priv,GFP_KERNEL );if (!port_priv) { - printk(KERN_ERR SPFX "No memory for ib_agent_port_private\n"); +pr_err ("No memory for ib_agent_port_private\n" ); ret = -ENOMEM ; goto error1; }
@@ -202,7 +204,7 @@ int ib_agent_port_close(struct ib_device *device, int port_num) port_priv =__ib_get_agent_port (device, port_num);if (port_priv ==NULL ) {spin_unlock_irqrestore (&ib_agent_port_list_lock, flags); - printk(KERN_ERR SPFX "Port %d not found\n", port_num); +pr_err ("Port %d not found\n" , port_num);return -ENODEV ; }list_del (&port_priv->port_list);
drivers/infiniband/core/mad.c +51 -58
357 lines not on this page · raw message
Signature · 6 lines
1.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/5 ib/mad: Add pr_notice messages for various umad/mad registration failures
In reply to a message not in the archiveFrom: Ira Weiny <[email protected]>
--- drivers/infiniband/core/mad.c | 47 ++++++++++++++++++++++++++++++-------- drivers/infiniband/core/user_mad.c | 5 ++++ 2 files changed, 43 insertions(+), 9 deletions(-)
drivers/infiniband/core/mad.c +38 -9
@@ -214,58 +214,85 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,/* Validate parameters */ qpn =get_spl_qp_index (qp_type); -if (qpn ==-1 ) +if (qpn ==-1 ) { +pr_notice ("ib_register_mad_agent: invalid QP Type %d\n" , + qp_type); goto error1; + } -if (rmpp_version && rmpp_version !=IB_MGMT_RMPP_VERSION ) +if (rmpp_version && rmpp_version !=IB_MGMT_RMPP_VERSION ) { +pr_notice ("ib_register_mad_agent: invalid RMPP Version %u\n" , + rmpp_version); goto error1; + }/* Validate MAD registration request if supplied */ if (mad_reg_req) { -if (mad_reg_req->mgmt_class_version >=MAX_MGMT_VERSION ) +if (mad_reg_req->mgmt_class_version >=MAX_MGMT_VERSION ) { +pr_notice ("ib_register_mad_agent: invalid Class Version %u\n" , + mad_reg_req->mgmt_class_version); goto error1; -if (!recv_handler) + } +if (!recv_handler) { +pr_notice ("ib_register_mad_agent: no recv_handler\n" ); goto error1; + }if (mad_reg_req->mgmt_class >=MAX_MGMT_CLASS ) {/* * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE is the only * one in this range currently allowed */ if (mad_reg_req->mgmt_class != -IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ) +IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ) { +pr_notice ("ib_register_mad_agent: Invalid Mgmt Class 0x%x\n" , + mad_reg_req->mgmt_class); goto error1; + } }else if (mad_reg_req->mgmt_class ==0 ) {/* * Class 0 is reserved in IBA and is used for * aliasing of IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE */ +pr_notice ("ib_register_mad_agent: Invalid Mgmt Class 0\n" ); goto error1; }else if (is_vendor_class (mad_reg_req->mgmt_class)) {/* * If class is in "new" vendor range, * ensure supplied OUI is not zero */ -if (!is_vendor_oui (mad_reg_req->oui)) +if (!is_vendor_oui (mad_reg_req->oui)) { +pr_notice ("ib_register_mad_agent: No OUI specified for class 0x%x\n" , + mad_reg_req->mgmt_class); goto error1; + } }/* Make sure class supplied is consistent with RMPP */ if (!ib_is_mad_class_rmpp (mad_reg_req->mgmt_class)) { -if (rmpp_version) +if (rmpp_version) { +pr_notice ("ib_register_mad_agent: RMPP version for non-RMPP class 0x%x\n" , + mad_reg_req->mgmt_class); goto error1; + } }/* Make sure class supplied is consistent with QP type */ if (qp_type ==IB_QPT_SMI ) {if ((mad_reg_req->mgmt_class !=IB_MGMT_CLASS_SUBN_LID_ROUTED ) && (mad_reg_req->mgmt_class != -IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE )) +IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE )) { +pr_notice ("ib_register_mad_agent: Invalid SM QP type: class 0x%x\n" , + mad_reg_req->mgmt_class); goto error1; + } }else {if ((mad_reg_req->mgmt_class ==IB_MGMT_CLASS_SUBN_LID_ROUTED ) || (mad_reg_req->mgmt_class == -IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE )) +IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE )) { +pr_notice ("ib_register_mad_agent: Invalid GS QP type: class 0x%x\n" , + mad_reg_req->mgmt_class); goto error1; + } } }else {/* No registration request supplied */
@@ -276,6 +303,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,/* Validate device and port */ port_priv =ib_get_mad_port (device, port_num);if (!port_priv) { +pr_notice ("ib_register_mad_agent: Invalid port\n" ); ret =ERR_PTR (-ENODEV ); goto error1; }
@@ -283,6 +311,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,/* Verify the QP requested is supported. For example, Ethernet devices * will not have QP0 */ if (!port_priv->qp_info[qpn].qp) { +pr_notice ("ib_register_mad_agent: QP %d not supported\n" , qpn); ret =ERR_PTR (-EPROTONOSUPPORT ); goto error1; }
drivers/infiniband/core/user_mad.c +5 -0
@@ -612,6 +612,7 @@ static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg,mutex_lock (&file->mutex);if (!file->port->ib_dev) { +pr_notice ("ib_umad_reg_agent: invalid device\n" ); ret = -EPIPE ; goto out; }
@@ -622,6 +623,8 @@ static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, }if (ureq.qpn !=0 && ureq.qpn !=1 ) { +pr_notice ("ib_umad_reg_agent: invalid QPN %d specified\n" , + ureq.qpn); ret = -EINVAL ; goto out; }
@@ -630,6 +633,8 @@ static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg,if (!__get_agent (file, agent_id)) goto found; +pr_notice ("ib_umad_reg_agent: Max Agents (%u) reached\n" , +IB_UMAD_MAX_AGENTS ); ret = -ENOMEM ; goto out;
Signature · 6 lines
1.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/5 ib/mad: add new ioctl to user space to support new registration options
In reply to a message not in the archiveFrom: Ira Weiny <[email protected]>
Registrations options are specified through flags. Definitions of flags will be in subsequent patches.
--- Documentation/infiniband/user_mad.txt | 13 ++-- drivers/infiniband/core/agent.c | 4 +- drivers/infiniband/core/cm.c | 5 +- drivers/infiniband/core/mad.c | 4 +- drivers/infiniband/core/sa_query.c | 2 +- drivers/infiniband/core/user_mad.c | 107 +++++++++++++++++++++++++++++++- drivers/infiniband/hw/mlx4/mad.c | 2 +- drivers/infiniband/hw/mthca/mthca_mad.c | 2 +- drivers/infiniband/hw/qib/qib_mad.c | 2 +- drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +- include/rdma/ib_mad.h | 7 ++- include/uapi/rdma/ib_user_mad.h | 38 ++++++++++++ 12 files changed, 172 insertions(+), 16 deletions(-)
Documentation/infiniband/user_mad.txt +9 -4
@@ -26,6 +26,11 @@ Creating MAD agents ioctl. Also, all agents registered through a file descriptor will be unregistered when the descriptor is closed. + 2013 -- a new registration ioctl is now provided which allows additional + fields to be provided during registration. + Users of this registration call are implicitly setting the use of + pkey_index (see below). + Receiving MADs MADs are received using read(). The receive side now supports
@@ -104,10 +109,10 @@ P_Key Index Handling The old ib_umad interface did not allow setting the P_Key index for MADs that are sent and did not provide a way for obtaining the P_Key index of received MADs. A new layout for struct ib_user_mad_hdr - with a pkey_index member has been defined; however, to preserve - binary compatibility with older applications, this new layout will - not be used unless the IB_USER_MAD_ENABLE_PKEY ioctl is called - before a file descriptor is used for anything else. + with a pkey_index member has been defined; however, to preserve binary + compatibility with older applications, this new layout will not be used + unless one of IB_USER_MAD_ENABLE_PKEY or IB_USER_MAD_REGISTER_AGENT2 ioctl's + are called before a file descriptor is used for anything else. In September 2008, the IB_USER_MAD_ABI_VERSION will be incremented to 6, the new layout of struct ib_user_mad_hdr will be used by
drivers/infiniband/core/agent.c +2 -2
@@ -163,7 +163,7 @@ int ib_agent_port_open(struct ib_device *device, int port_num) port_priv->agent[0 ] =ib_register_mad_agent (device, port_num,IB_QPT_SMI ,NULL ,0 , &agent_send_handler, -NULL ,NULL ); +NULL ,NULL ,0 );if (IS_ERR (port_priv->agent[0 ])) { ret =PTR_ERR (port_priv->agent[0 ]); goto error2;
@@ -174,7 +174,7 @@ int ib_agent_port_open(struct ib_device *device, int port_num) port_priv->agent[1 ] =ib_register_mad_agent (device, port_num,IB_QPT_GSI ,NULL ,0 , &agent_send_handler, -NULL ,NULL ); +NULL ,NULL ,0 );if (IS_ERR (port_priv->agent[1 ])) { ret =PTR_ERR (port_priv->agent[1 ]); goto error3;
drivers/infiniband/core/cm.c +3 -2
@@ -3753,7 +3753,7 @@ static void cm_add_one(struct ib_device *ib_device)struct cm_port *port;struct ib_mad_reg_req reg_req = { .mgmt_class =IB_MGMT_CLASS_CM , - .mgmt_class_version =IB_CM_CLASS_VERSION + .mgmt_class_version =IB_CM_CLASS_VERSION , };struct ib_port_modify port_modify = { .set_port_cap_mask =IB_PORT_CM_SUP
@@ -3801,7 +3801,8 @@ static void cm_add_one(struct ib_device *ib_device)0 , cm_send_handler, cm_recv_handler, - port); + port, + 0);if (IS_ERR (port->mad_agent)) goto error2;
drivers/infiniband/core/mad.c +3 -1
@@ -198,7 +198,8 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,u8 rmpp_version, ib_mad_send_handler send_handler, ib_mad_recv_handler recv_handler, - void *context) + void *context, + u32 registration_flags) { struct ib_mad_port_private *port_priv;struct ib_mad_agent *ret =ERR_PTR (-EINVAL );
@@ -348,6 +349,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, mad_agent_priv->agent.context = context; mad_agent_priv->agent.qp = port_priv->qp_info[qpn].qp; mad_agent_priv->agent.port_num = port_num; + mad_agent_priv->agent.flags = registration_flags;spin_lock_init (&mad_agent_priv->lock);INIT_LIST_HEAD (&mad_agent_priv->send_list);INIT_LIST_HEAD (&mad_agent_priv->wait_list);
drivers/infiniband/core/sa_query.c +1 -1
@@ -1184,7 +1184,7 @@ static void ib_sa_add_one(struct ib_device *device) sa_dev->port[i].agent =ib_register_mad_agent (device, i + s,IB_QPT_GSI ,NULL ,0 , send_handler, - recv_handler, sa_dev); + recv_handler, sa_dev,0 );if (IS_ERR (sa_dev->port[i].agent)) goto err;
drivers/infiniband/core/user_mad.c +106 -1
137 lines not on this page · raw message
drivers/infiniband/hw/mlx4/mad.c +1 -1
@@ -880,7 +880,7 @@ int mlx4_ib_mad_init(struct mlx4_ib_dev *dev) agent =ib_register_mad_agent (&dev->ib_dev, p +1 , q ?IB_QPT_GSI :IB_QPT_SMI ,NULL ,0 , send_handler, -NULL ,NULL ); +NULL ,NULL ,0 );if (IS_ERR (agent)) { ret =PTR_ERR (agent); goto err;
drivers/infiniband/hw/mthca/mthca_mad.c +1 -1
@@ -294,7 +294,7 @@ int mthca_create_agents(struct mthca_dev *dev) agent =ib_register_mad_agent (&dev->ib_dev, p +1 , q ?IB_QPT_GSI :IB_QPT_SMI ,NULL ,0 , send_handler, -NULL ,NULL ); +NULL ,NULL ,0 );if (IS_ERR (agent)) { ret =PTR_ERR (agent); goto err;
drivers/infiniband/hw/qib/qib_mad.c +1 -1
@@ -2476,7 +2476,7 @@ int qib_create_agents(struct qib_ibdev *dev) ibp = &dd->pport[p].ibport_data; agent =ib_register_mad_agent (&dev->ibdev, p +1 ,IB_QPT_SMI ,NULL ,0 , send_handler, -NULL ,NULL ); +NULL ,NULL ,0 );if (IS_ERR (agent)) { ret =PTR_ERR (agent); goto err;
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
@@ -563,7 +563,7 @@ static int srpt_refresh_port(struct srpt_port *sport) ®_req,0 , srpt_mad_send_handler, srpt_mad_recv_handler, - sport); + sport, 0);if (IS_ERR (sport->mad_agent)) { ret =PTR_ERR (sport->mad_agent); sport->mad_agent =NULL ;
include/rdma/ib_mad.h +6 -1
@@ -355,6 +355,7 @@ typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,* @hi_tid: Access layer assigned transaction ID for this client. * Unsolicited MADs sent by this client will have the upper 32-bits * of their TID set to this value. +* @flags: registration flags * @port_num: Port number on which QP is registered * @rmpp_version: If set, indicates the RMPP version used by this agent. */
@@ -367,6 +368,7 @@ struct ib_mad_agent {ib_mad_snoop_handler snoop_handler;void *context;u32 hi_tid; +u32 flags;u8 port_num;u8 rmpp_version; };
@@ -426,6 +428,7 @@ struct ib_mad_recv_wc {* in the range from 0x30 to 0x4f. Otherwise not used. * @method_mask: The caller will receive unsolicited MADs for any method * where @method_mask = 1. +* */ struct ib_mad_reg_req {u8 mgmt_class;
@@ -451,6 +454,7 @@ struct ib_mad_reg_req {* @recv_handler: The completion callback routine invoked for a received * MAD. * @context: User specified context associated with the registration. +* @registration_flags: Registration flags to set for this agent */ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, u8 port_num,
@@ -459,7 +463,8 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,u8 rmpp_version, ib_mad_send_handler send_handler, ib_mad_recv_handler recv_handler, - void *context); + void *context, + u32 registration_flags);enum ib_mad_snoop_flags {/*IB_MAD_SNOOP_POSTED_SENDS = 1,*/
include/uapi/rdma/ib_user_mad.h +38 -0
@@ -191,6 +191,41 @@ struct ib_user_mad_reg_req {__u8 rmpp_version; }; +/** +* ib_user_mad_reg_req2 - MAD registration request +* +* @id - Set by the _kernel_; used by userspace to identify the +* registered agent in future requests. +* @qpn - Queue pair number; must be 0 or 1. +* @mgmt_class - Indicates which management class of MADs should be +* receive by the caller. This field is only required if +* the user wishes to receive unsolicited MADs, otherwise +* it should be 0. +* @mgmt_class_version - Indicates which version of MADs for the given +* management class to receive. +* @res - Ignored. +* @flags - additional registration flags; Must be in the set of +* flags defined in IB_USER_MAD_REG_FLAGS_CAP +* @method_mask - The caller wishes to receive unsolicited MADs for the +* methods whose bit(s) is(are) set. +* @oui - Indicates IEEE OUI to use when mgmt_class is a vendor +* class in the range from 0x30 to 0x4f. Otherwise not +* used. +* @rmpp_version - If set, indicates the RMPP version to use. +*/ +#define IB_USER_MAD_REG_FLAGS_CAP (0) +struct ib_user_mad_reg_req2 { +__u32 id; +__u32 qpn; +__u8 mgmt_class; +__u8 mgmt_class_version; +__u16 res; +__u32 flags; +__u64 method_mask[2 ]; +__u8 oui[3 ];/* network order */ +__u8 rmpp_version; +}; +#define IB_IOCTL_MAGIC 0x1b#define IB_USER_MAD_REGISTER_AGENT _IOWR(IB_IOCTL_MAGIC, 1, \
@@ -200,4 +235,7 @@ struct ib_user_mad_reg_req {#define IB_USER_MAD_ENABLE_PKEY _IO(IB_IOCTL_MAGIC, 3) +#define IB_USER_MAD_REGISTER_AGENT2 _IOWR(IB_IOCTL_MAGIC, 4, \ + struct ib_user_mad_reg_req2) +#endif /* IB_USER_MAD_H */
Signature · 6 lines
1.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/5 ib/mad: Add user space RMPP support
In reply to a message not in the archiveFrom: Ira Weiny <[email protected]>
Using the new registration mechanism define a flag which indicates the user wishes to process RMPP messages in user space rather than have the kernel process them.
--- drivers/infiniband/core/mad.c | 74 ++++++++++++++++++++++++++------------ drivers/infiniband/core/user_mad.c | 34 +++++++++++------- include/rdma/ib_mad.h | 11 ++++++ include/uapi/rdma/ib_user_mad.h | 5 ++- 4 files changed, 88 insertions(+), 36 deletions(-)
drivers/infiniband/core/mad.c +51 -23
@@ -275,6 +275,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, goto error1; } } +/* Make sure class supplied is consistent with QP type */ if (qp_type ==IB_QPT_SMI ) { if ((mad_reg_req->mgmt_class !=
@@ -299,6 +300,8 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,/* No registration request supplied */ if (!send_handler) goto error1; +if (registration_flags &IB_MAD_USER_RMPP ) + goto error1; }/* Validate device and port */
@@ -895,6 +898,12 @@ static int alloc_send_rmpp_list(struct ib_mad_send_wr_private *send_wr,return 0 ; } +int ib_mad_kernel_rmpp_agent (struct ib_mad_agent *agent) +{ +return agent->rmpp_version && !(agent->flags &IB_MAD_USER_RMPP ); +} +EXPORT_SYMBOL (ib_mad_kernel_rmpp_agent); + struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, u32 remote_qpn, u16 pkey_index, int rmpp_active,
@@ -911,10 +920,12 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, pad =get_pad_size (hdr_len, data_len); message_size = hdr_len + data_len + pad; -if ((!mad_agent->rmpp_version && - (rmpp_active || message_size >sizeof (struct ib_mad ))) || - (!rmpp_active && message_size >sizeof (struct ib_mad ))) -return ERR_PTR (-EINVAL ); +if (ib_mad_kernel_rmpp_agent (mad_agent)) { +if (!rmpp_active && message_size >sizeof (struct ib_mad )) +return ERR_PTR (-EINVAL ); + }else +if (rmpp_active || message_size >sizeof (struct ib_mad )) +return ERR_PTR (-EINVAL ); size = rmpp_active ? hdr_len :sizeof (struct ib_mad ); buf =kzalloc (sizeof *mad_send_wr + size, gfp_mask);
@@ -1168,7 +1179,7 @@ int ib_post_send_mad(struct ib_mad_send_buf *send_buf, &mad_agent_priv->send_list);spin_unlock_irqrestore (&mad_agent_priv->lock, flags); -if (mad_agent_priv->agent.rmpp_version) { +if (ib_mad_kernel_rmpp_agent (&mad_agent_priv->agent)) { ret =ib_send_rmpp_mad (mad_send_wr);if (ret >=0 && ret !=IB_RMPP_RESULT_CONSUMED ) ret =ib_send_mad (mad_send_wr);
@@ -1713,6 +1724,7 @@ static int is_data_mad(struct ib_mad_agent_private *mad_agent_priv, rmpp_mad = (struct ib_rmpp_mad *)mad_hdr;return !mad_agent_priv->agent.rmpp_version || + !ib_mad_kernel_rmpp_agent (&mad_agent_priv->agent) || !(ib_get_rmpp_flags (&rmpp_mad->rmpp_hdr) &IB_MGMT_RMPP_FLAG_ACTIVE ) || (rmpp_mad->rmpp_hdr.rmpp_type ==IB_MGMT_RMPP_TYPE_DATA );
@@ -1840,7 +1852,7 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,INIT_LIST_HEAD (&mad_recv_wc->rmpp_list);list_add (&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list); -if (mad_agent_priv->agent.rmpp_version) { +if (ib_mad_kernel_rmpp_agent (&mad_agent_priv->agent)) { mad_recv_wc =ib_process_rmpp_recv_wc (mad_agent_priv, mad_recv_wc);if (!mad_recv_wc) {
@@ -1855,23 +1867,39 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv, mad_send_wr =ib_find_send_mad (mad_agent_priv, mad_recv_wc);if (!mad_send_wr) {spin_unlock_irqrestore (&mad_agent_priv->lock, flags); -ib_free_recv_mad (mad_recv_wc); -deref_mad_agent (mad_agent_priv); -return ; - } -ib_mark_mad_done (mad_send_wr); -spin_unlock_irqrestore (&mad_agent_priv->lock, flags); +if (!ib_mad_kernel_rmpp_agent (&mad_agent_priv->agent) + &&ib_is_mad_class_rmpp (mad_recv_wc->recv_buf.mad->mad_hdr.mgmt_class) + && (ib_get_rmpp_flags (&((struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad)->rmpp_hdr) + &IB_MGMT_RMPP_FLAG_ACTIVE )) { +/* user rmpp is in effect +* and this is an active RMPP MAD +*/ + mad_recv_wc->wc->wr_id =0 ; + mad_agent_priv->agent.recv_handler (&mad_agent_priv->agent, + mad_recv_wc); +atomic_dec (&mad_agent_priv->refcount); + }else { +/* not user rmpp, revert to normal behavior and +* drop the mad */ +ib_free_recv_mad (mad_recv_wc); +deref_mad_agent (mad_agent_priv); +return ; + } + }else { +ib_mark_mad_done (mad_send_wr); +spin_unlock_irqrestore (&mad_agent_priv->lock, flags); -/* Defined behavior is to complete response before request */ - mad_recv_wc->wc->wr_id = (unsigned long ) &mad_send_wr->send_buf; - mad_agent_priv->agent.recv_handler (&mad_agent_priv->agent, - mad_recv_wc); -atomic_dec (&mad_agent_priv->refcount); +/* Defined behavior is to complete response before request */ + mad_recv_wc->wc->wr_id = (unsigned long ) &mad_send_wr->send_buf; + mad_agent_priv->agent.recv_handler (&mad_agent_priv->agent, + mad_recv_wc); +atomic_dec (&mad_agent_priv->refcount); - mad_send_wc.status =IB_WC_SUCCESS ; - mad_send_wc.vendor_err =0 ; - mad_send_wc.send_buf = &mad_send_wr->send_buf; -ib_mad_complete_send_wr (mad_send_wr, &mad_send_wc); + mad_send_wc.status =IB_WC_SUCCESS ; + mad_send_wc.vendor_err =0 ; + mad_send_wc.send_buf = &mad_send_wr->send_buf; +ib_mad_complete_send_wr (mad_send_wr, &mad_send_wc); + } }else { mad_agent_priv->agent.recv_handler (&mad_agent_priv->agent, mad_recv_wc);
@@ -2110,7 +2138,7 @@ void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr, mad_agent_priv = mad_send_wr->mad_agent_priv;spin_lock_irqsave (&mad_agent_priv->lock, flags); -if (mad_agent_priv->agent.rmpp_version) { +if (ib_mad_kernel_rmpp_agent (&mad_agent_priv->agent)) { ret =ib_process_rmpp_send_wc (mad_send_wr, mad_send_wc);if (ret ==IB_RMPP_RESULT_CONSUMED ) goto done;
@@ -2503,7 +2531,7 @@ static int retry_send(struct ib_mad_send_wr_private *mad_send_wr) mad_send_wr->timeout =msecs_to_jiffies (mad_send_wr->send_buf.timeout_ms); -if (mad_send_wr->mad_agent_priv->agent.rmpp_version) { +if (ib_mad_kernel_rmpp_agent (&mad_send_wr->mad_agent_priv->agent)) { ret =ib_retry_rmpp (mad_send_wr);switch (ret) {case IB_RMPP_RESULT_UNHANDLED :
drivers/infiniband/core/user_mad.c +22 -12
@@ -502,13 +502,15 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf, rmpp_mad = (struct ib_rmpp_mad *) packet->mad.data; hdr_len =ib_get_mad_data_offset (rmpp_mad->mad_hdr.mgmt_class); -if (!ib_is_mad_class_rmpp (rmpp_mad->mad_hdr.mgmt_class)) { - copy_offset =IB_MGMT_MAD_HDR ; - rmpp_active =0 ; - }else { + +if (ib_is_mad_class_rmpp (rmpp_mad->mad_hdr.mgmt_class) + &&ib_mad_kernel_rmpp_agent (agent)) { copy_offset =IB_MGMT_RMPP_HDR ; rmpp_active =ib_get_rmpp_flags (&rmpp_mad->rmpp_hdr) & -IB_MGMT_RMPP_FLAG_ACTIVE ; +IB_MGMT_RMPP_FLAG_ACTIVE ; + }else { + copy_offset =IB_MGMT_MAD_HDR ; + rmpp_active =0 ; } data_len = count -hdr_size (file) - hdr_len;
@@ -554,14 +556,22 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf, rmpp_mad->mad_hdr.tid = *tid; } -spin_lock_irq (&file->send_lock); - ret =is_duplicate (file, packet); -if (!ret) +if (!ib_mad_kernel_rmpp_agent (agent) + &&ib_is_mad_class_rmpp (rmpp_mad->mad_hdr.mgmt_class) + && (ib_get_rmpp_flags (&rmpp_mad->rmpp_hdr) &IB_MGMT_RMPP_FLAG_ACTIVE )) { +spin_lock_irq (&file->send_lock);list_add_tail (&packet->list, &file->send_list); -spin_unlock_irq (&file->send_lock); -if (ret) { - ret = -EINVAL ; - goto err_msg; +spin_unlock_irq (&file->send_lock); + }else { +spin_lock_irq (&file->send_lock); + ret =is_duplicate (file, packet); +if (!ret) +list_add_tail (&packet->list, &file->send_list); +spin_unlock_irq (&file->send_lock); +if (ret) { + ret = -EINVAL ; + goto err_msg; + } } ret =ib_post_send_mad (packet->msg,NULL );
include/rdma/ib_mad.h +11 -0
@@ -40,6 +40,7 @@#include <linux/list.h> #include <rdma/ib_verbs.h> +#include <uapi/rdma/ib_user_mad.h> /* Management base version */ #define IB_MGMT_BASE_VERSION 1
@@ -359,6 +360,9 @@ typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,* @port_num: Port number on which QP is registered * @rmpp_version: If set, indicates the RMPP version used by this agent. */ +enum { +IB_MAD_USER_RMPP =IB_USER_MAD_USER_RMPP , +};struct ib_mad_agent {struct ib_device *device;struct ib_qp *qp;
@@ -666,4 +670,11 @@ void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num);*/ void ib_free_send_mad (struct ib_mad_send_buf *send_buf); +/** +* ib_mad_kernel_rmpp_agent - Returns if the agent is performing RMPP. +* @agent: the agent in question +* @return: true if agent is performing rmpp, false otherwise. +*/ +int ib_mad_kernel_rmpp_agent (struct ib_mad_agent *agent); +#endif /* IB_MAD_H */
include/uapi/rdma/ib_user_mad.h +4 -1
@@ -213,7 +213,10 @@ struct ib_user_mad_reg_req {* used. * @rmpp_version - If set, indicates the RMPP version to use. */ -#define IB_USER_MAD_REG_FLAGS_CAP (0) +enum { +IB_USER_MAD_USER_RMPP = (1 <<0 ), +}; +#define IB_USER_MAD_REG_FLAGS_CAP (IB_USER_MAD_USER_RMPP)struct ib_user_mad_reg_req2 {__u32 id;__u32 qpn;
Signature · 6 lines
1.8.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/5] ib/mad: update module to pr_* style print messages
In reply to a message not in the archiveQuoted 4 lines · On Mon, May 05, 2014 at 09:44:47PM -0400…
From: Ira Weiny <[email protected]>
Also combine previously line broken user-visible strings as per
Documentation/CodingStyle
These seem like nice cleanups, however it would be much nicer to use the dev_* versions when a struct device is available, I think many of these cases can reach the /dev/umadX struct device..
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/5] ib/mad: Add pr_notice messages for various umad/mad registration failures
In reply to a message not in the archiveQuoted 1 line · On Mon, May 05, 2014 at 09:44:48PM -0400…
From: Ira Weiny <[email protected]>
An empty commit message is not good enough for the mainline kernel, please describe motivation at least.
I am worried about log DOS potential here, it looks like many of these messages could be triggered by userspace? Have you thought about this?
Generally moving this stuff to a pr_debug might be more appropriate, it is very unusual to have logging like this for malformed syscall arguments.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/5] ib/mad: add new ioctl to user space to support new registration options
In reply to a message not in the archiveinclude/uapi/rdma/ib_user_mad.h struct ib_user_mad_reg_req { · line 227
Quoted 11 lines · On Mon, May 05, 2014 at 09:44:49PM -0400…
include/uapi/rdma/ib_user_mad.h +11
-0+struct ib_user_mad_reg_req2 { +__u32 id; +__u32 qpn; +__u8 mgmt_class; +__u8 mgmt_class_version; +__u16 res; +__u32 flags; +__u64 method_mask[2 ]; +__u8 oui[3 ];/* network order */ +__u8 rmpp_version; +};
Please make the padding on 64 bit explicit so we don't have weird problems mixing 32 and 64 bit code.
Similar comment as for userspace using a host order uint for the oui.
It would also be good to verify that a 32 bit binary can successfully execute the ioctl on a 64 bit kernel.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 2/5] ib/mad: update module to pr_* style print messages
In reply to a message not in the archiveQuoted 10 lines · On Mon, May 05, 2014 at 09:44:47PM -0400…
Quoted 4 lines
From: Ira Weiny <[email protected]>
Also combine previously line broken user-visible strings as per
Documentation/CodingStyleThese seem like nice cleanups, however it would be much nicer to use the dev_* versions when a struct device is available, I think many of these cases can reach the
/dev/umadXstruct device..
Ok, this works nice for ib_umad:
infiniband_mad umad1: ib_umad_reg_agent2 failed: invalid registration flags specified 0x2; supported 0x1 vs.user_mad: ib_umad_reg_agent2 failed: invalid registration flags specified 0x2; supported 0x1
However in ib_mad I'm not so sure. The error now implies it is the driver which is flagging the error, _not_ ib_mad.
For example here is what you get when you change pr_notice to dev_notice in ib_mad.
ib_qib 0000:01:00.0: ib_register_mad_agent: invalid RMPP Version 2
OR (There are 2 "struct device" in the struct ib_device passed to the register function: dma_device vs dev)
infiniband qib0: ib_register_mad_agent: invalid RMPP Version 2
vs.
ib_mad: ib_register_mad_agent: invalid RMPP Version 2
Either message implies it is the HCA driver which is flagging the error. Which I think is misleading but maybe this is more correct and is the "kernel way"?
Ira
Quoted 2 lines
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 3/5] ib/mad: Add pr_notice messages for various umad/mad registration failures
In reply to a message not in the archiveQuoted 6 lines · On Mon, May 05, 2014 at 09:44:48PM -0400…
Quoted 1 line
From: Ira Weiny <[email protected]>
An empty commit message is not good enough for the mainline kernel, please describe motivation at least.
Will do.
Quoted 3 lines
I am worried about log DOS potential here, it looks like many of these messages could be triggered by userspace? Have you thought about this?
Yes I did think about it, see below.
Quoted 3 lines
Generally moving this stuff to a
pr_debugmight be more appropriate, it is very unusual to have logging like this for malformed syscall arguments.
I debated using debug. The problem with debug is that it requires a kernel recompile. This may not be acceptable for some users. Ib_umad devices should only be accessible from a privileged user which I felt was sufficient protection against a DOS attack. But if it would be more acceptable I can change to [pr|dev]_debug.
Ira
Quoted 2 lines
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 4/5] ib/mad: add new ioctl to user space to support new registration options
In reply to a message not in the archiveQuoted 17 lines · On Mon, May 05, 2014 at 09:44:49PM -0400…
include/uapi/rdma/ib_user_mad.h struct ib_user_mad_reg_req { · line 227
Quoted 12 lines
include/uapi/rdma/ib_user_mad.h +11
-0+struct ib_user_mad_reg_req2 { +__u32 id; +__u32 qpn; +__u8 mgmt_class; +__u8 mgmt_class_version; +__u16 res; +__u32 flags; +__u64 method_mask[2 ]; +__u8 oui[3 ];/* network order */ +__u8 rmpp_version; +};Please make the padding on 64 bit explicit so we don't have weird problems mixing 32 and 64 bit code.
Just to be clear you mean to add a __u32 reserved field to the end of this struct?
Quoted 2 lines
Similar comment as for userspace using a host order uint for the oui.
Ok would you prefer changing this to __u32 and specifying in host order? Then adjust the padding, like this:
__u32 oui;_u8 rmpp_version;_u8 res[3];
To complete the changes?
Quoted 3 lines
It would also be good to verify that a 32 bit binary can successfully execute the ioctl on a 64 bit kernel.
I'll try to do this once we agree to the above changes.
Thanks,
Ira
Quoted 2 lines
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/5] ib/mad: add new ioctl to user space to support new registration options
In reply to a message not in the archiveQuoted 17 lines · Ira
Quoted 16 lines · On Mon, May 05, 2014 at 09:44:49PM -0400…
include/uapi/rdma/ib_user_mad.h struct ib_user_mad_reg_req { · line 227
Quoted 12 lines
include/uapi/rdma/ib_user_mad.h +11
-0+struct ib_user_mad_reg_req2 { +__u32 id; +__u32 qpn; +__u8 mgmt_class; +__u8 mgmt_class_version; +__u16 res; +__u32 flags; +__u64 method_mask[2 ]; +__u8 oui[3 ];/* network order */ +__u8 rmpp_version; +};Please make the padding on 64 bit explicit so we don't have weird problems mixing 32 and 64 bit code.
Quoted 1 line
Just to be clear you mean to add a
__u32reserved field to the end of this struct?
I think that is enough, yes. Yann has been using pahole to investigate these issues.
Quoted 9 lines
Quoted 1 line
Similar comment as for userspace using a host order uint for the oui.
Ok would you prefer changing this to
__u32and specifying in host order? Then adjust the padding, like this:
__u32oui;_u8rmpp_version;_u8res[3];To complete the changes?
s/res/reserved/
Sure, that seems simpler for all involved.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/5] ib/mad: update module to pr_* style print messages
In reply to a message not in the archiveQuoted 11 lines · Ira
Quoted 10 lines · On Mon, May 05, 2014 at 09:44:47PM -0400…
Quoted 4 lines
From: Ira Weiny <[email protected]>
Also combine previously line broken user-visible strings as per
Documentation/CodingStyleThese seem like nice cleanups, however it would be much nicer to use the dev_* versions when a struct device is available, I think many of these cases can reach the
/dev/umadXstruct device..
Quoted 5 lines
Ok, this works nice for
ib_umad:
infiniband_madumad1:ib_umad_reg_agent2failed: invalid registration flags specified0x2; supported0x1vs.user_mad:ib_umad_reg_agent2failed: invalid registration flags specified0x2; supported0x1
Right..
Quoted 2 lines
However in
ib_madI'm not so sure. The error now implies it is the driver which is flagging the error, _not_ib_mad.
Does it matter? ib_mad is a kernel implementation detail, and a kernel consumer could trigger the debugging print as well. The function name is a big enough clue that the problem is ib_mad related, IMHO.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html