[ipoib] Fix referencing the lists without locks.
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sat, 1 Nov 2008 18:03:56 +0000 (18:03 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sat, 1 Nov 2008 18:03:56 +0000 (18:03 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1717 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/ipoib/kernel/ipoib_port.c
ulp/ipoib/kernel/ipoib_port.h

index 7713149..e6a5391 100644 (file)
@@ -495,8 +495,6 @@ inline void ipoib_port_ref( ipoib_port_t * p_port, int type )
 \r
 inline void ipoib_port_deref(ipoib_port_t * p_port, int type)\r
 {\r
-       cl_obj_deref( &p_port->obj );\r
-\r
 #if DBG\r
        cl_atomic_dec( &p_port->ref[type % ref_mask] );\r
        IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_OBJ,\r
@@ -504,6 +502,8 @@ inline void ipoib_port_deref(ipoib_port_t * p_port, int type)
 #else\r
        UNREFERENCED_PARAMETER(type);\r
 #endif\r
+       cl_obj_deref( &p_port->obj );\r
+\r
 }\r
 \r
 /* function returns pointer to payload that is going after IP header.\r
@@ -3954,15 +3954,15 @@ __build_send_desc(
        \r
        p_desc->wr.ds_array = p_desc->local_ds;\r
 \r
-       p_desc->wr.dgrm.ud.remote_qp = p_desc->p_endpt->qpn;\r
+       p_desc->wr.dgrm.ud.remote_qp = p_desc->p_endpt1->qpn;\r
        p_desc->wr.dgrm.ud.remote_qkey = p_port->ib_mgr.bcast_rec.qkey;\r
-       p_desc->wr.dgrm.ud.h_av = p_desc->p_endpt->h_av;\r
+       p_desc->wr.dgrm.ud.h_av = p_desc->p_endpt1->h_av;\r
        p_desc->wr.dgrm.ud.pkey_index = p_port->pkey_index;\r
        p_desc->wr.dgrm.ud.rsvd = NULL;\r
 \r
        /* Store context in our reserved area of the packet. */\r
        IPOIB_PORT_FROM_PACKET( p_desc->p_pkt ) = p_port;\r
-       IPOIB_ENDPT_FROM_PACKET( p_desc->p_pkt ) = p_desc->p_endpt;\r
+       IPOIB_ENDPT_FROM_PACKET( p_desc->p_pkt ) = p_desc->p_endpt1;\r
        IPOIB_SEND_FROM_PACKET( p_desc->p_pkt ) = p_desc->p_buf;\r
 \r
        IPOIB_EXIT( IPOIB_DBG_SEND );\r
@@ -3983,8 +3983,8 @@ __process_failed_send(
                p_desc->p_pkt, status );\r
        ipoib_inc_send_stat( p_port->p_adapter, IP_STAT_ERROR, 0 );\r
        /* Deref the endpoint. */\r
-       if( p_desc->p_endpt )\r
-               ipoib_endpt_deref( p_desc->p_endpt );\r
+       if( p_desc->p_endpt1 )\r
+               ipoib_endpt_deref( p_desc->p_endpt1 );\r
 \r
        if( p_desc->p_buf )\r
        {\r
@@ -4044,7 +4044,7 @@ ipoib_port_send(
        for( i = 0; i < num_packets; i++ )\r
        {\r
                desc.p_pkt = p_packet_array[i];\r
-               desc.p_endpt = NULL;\r
+               desc.p_endpt1 = NULL;\r
                desc.p_buf = NULL;\r
 \r
                /* Get the ethernet header so we can find the endpoint. */\r
@@ -4107,7 +4107,7 @@ ipoib_port_send(
                        p_eth_hdr->dst.addr[3] = ((unsigned char*)&p_ip_hdr->dst_ip)[1];\r
                }\r
 h_end:\r
-               status = __send_mgr_queue( p_port, p_eth_hdr, &desc.p_endpt );\r
+               status = __send_mgr_queue( p_port, p_eth_hdr, &desc.p_endpt1 );\r
                cl_perf_stop( &p_port->p_adapter->perf, SendMgrQueue );\r
                if( status == NDIS_STATUS_PENDING )\r
                {\r
@@ -4216,7 +4216,7 @@ ipoib_port_resume(
 \r
                desc.p_pkt = IPOIB_PACKET_FROM_LIST_ITEM(\r
                        cl_qlist_remove_head( &p_port->send_mgr.pending_list ) );\r
-               desc.p_endpt = NULL;\r
+               desc.p_endpt1 = NULL;\r
                desc.p_buf = NULL;\r
 \r
                /* Get the ethernet header so we can find the endpoint. */\r
@@ -4231,10 +4231,11 @@ ipoib_port_resume(
                }\r
 \r
                cl_perf_start( GetEndpt );\r
-               status = __endpt_mgr_ref( p_port, p_eth_hdr->dst, &desc.p_endpt );\r
+               status = __endpt_mgr_ref( p_port, p_eth_hdr->dst, &desc.p_endpt1 );\r
                cl_perf_stop( &p_port->p_adapter->perf, GetEndpt );\r
                if( status == NDIS_STATUS_PENDING )\r
                {\r
+                       CL_ASSERT(desc.p_endpt1 == NULL);\r
                        cl_qlist_insert_head( &p_port->send_mgr.pending_list,\r
                                IPOIB_LIST_ITEM_FROM_PACKET( desc.p_pkt ) );\r
                        break;\r
@@ -4242,6 +4243,7 @@ ipoib_port_resume(
                else if( status != NDIS_STATUS_SUCCESS )\r
                {\r
                        ASSERT( status == NDIS_STATUS_NO_ROUTE_TO_DESTINATION );\r
+                       CL_ASSERT(desc.p_endpt1 == NULL);\r
 \r
                        if( ETH_IS_MULTICAST( p_eth_hdr->dst.addr ) )\r
                        {\r
@@ -4549,10 +4551,10 @@ __endpt_mgr_reset_all(
 \r
        if( p_port->p_local_endpt )\r
        {\r
-               cl_qmap_remove_item( &p_port->endpt_mgr.mac_endpts,\r
-                       &p_port->p_local_endpt->mac_item );\r
                cl_fmap_remove_item( &p_port->endpt_mgr.gid_endpts,\r
                        &p_port->p_local_endpt->gid_item );\r
+               cl_qmap_remove_item( &p_port->endpt_mgr.mac_endpts,\r
+                       &p_port->p_local_endpt->mac_item );\r
                cl_qmap_remove_item( &p_port->endpt_mgr.lid_endpts,\r
                        &p_port->p_local_endpt->lid_item );\r
                \r
@@ -4618,8 +4620,10 @@ __endpt_mgr_reset_all(
        /* Destroy all multicast endpoints now that we have released the lock. */\r
        while( cl_qlist_count( &mc_list ) )\r
        {\r
-               cl_obj_destroy( &PARENT_STRUCT( cl_qlist_remove_head( &mc_list ),\r
-                       ipoib_endpt_t, mac_item.pool_item.list_item )->obj );\r
+               cl_list_item_t  *p_item;\r
+               p_item = cl_qlist_remove_head( &mc_list );\r
+               p_endpt = PARENT_STRUCT(p_item, ipoib_endpt_t, mac_item.pool_item.list_item);\r
+               cl_obj_destroy( &p_endpt->obj);\r
        }\r
 \r
        IPOIB_EXIT( IPOIB_DBG_ENDPT );\r
@@ -4639,8 +4643,11 @@ __endpt_mgr_remove(
 {\r
        IPOIB_ENTER( IPOIB_DBG_ENDPT );\r
 \r
+       /* This function must be called from the recieve path */\r
+       CL_ASSERT(p_port->endpt_rdr > 0);\r
+\r
        cl_obj_lock( &p_port->obj );\r
-       /* Wait for all readers to complete. */\r
+       /* Wait for all readers to complete. */    \r
        while( p_port->endpt_rdr > 1 )\r
                ;\r
 \r
@@ -5709,14 +5716,21 @@ __bcast_cb(
                IPOIB_EXIT( IPOIB_DBG_INIT );\r
                return;\r
        }\r
-       cl_obj_unlock( &p_port->obj );\r
        p_port->bc_join_retry_cnt = 0;\r
+\r
+       while( p_port->endpt_rdr )\r
+       {\r
+               cl_obj_unlock( &p_port->obj );\r
+               cl_obj_lock( &p_port->obj );\r
+       }\r
+\r
        if(! p_port->p_local_endpt)\r
        {\r
                ib_port_info_t  port_info;\r
                cl_memclr(&port_info, sizeof(port_info));\r
                port_info.base_lid = p_port->base_lid;\r
                status = __endpt_mgr_add_local( p_port, &port_info );\r
+               cl_obj_unlock( &p_port->obj );\r
                if( status != IB_SUCCESS )\r
                {\r
                        IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
@@ -5725,6 +5739,9 @@ __bcast_cb(
                        goto err;\r
                }\r
        }\r
+\r
+       cl_obj_unlock( &p_port->obj );\r
+\r
        status = __endpt_mgr_add_bcast( p_port, p_mcast_rec );\r
        if( status != IB_SUCCESS )\r
        {\r
@@ -5991,6 +6008,11 @@ __mcast_cb(
        p_port = (ipoib_port_t*)p_mcast_rec->mcast_context;\r
 \r
        cl_obj_lock( &p_port->obj );\r
+       while( p_port->endpt_rdr )\r
+       {\r
+               cl_obj_unlock( &p_port->obj );\r
+               cl_obj_lock( &p_port->obj );\r
+       }\r
        if( p_port->state != IB_QPS_RTS )\r
        {\r
                cl_obj_unlock( &p_port->obj );\r
@@ -6005,10 +6027,10 @@ __mcast_cb(
                        ("Invalid state - Aborting.\n") );\r
                return;\r
        }\r
-       cl_obj_unlock( &p_port->obj );\r
 \r
        if( p_mcast_rec->status != IB_SUCCESS )\r
        {\r
+               cl_obj_unlock( &p_port->obj );\r
                IPOIB_PRINT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
                        ("Multicast join request failed with status %s.\n",\r
                        p_port->p_adapter->p_ifc->get_err_str( p_mcast_rec->status )) );\r
@@ -6019,7 +6041,6 @@ __mcast_cb(
                return;\r
        }\r
 \r
-       cl_obj_lock( &p_port->obj );\r
        p_item = cl_fmap_get(\r
                &p_port->endpt_mgr.gid_endpts, &p_mcast_rec->p_member_rec->mgid );\r
        if( p_item == cl_fmap_end( &p_port->endpt_mgr.gid_endpts ) )\r
@@ -6065,6 +6086,9 @@ __mcast_cb(
         */\r
        if( p_endpt->dlid )\r
        {\r
+               while( p_port->endpt_rdr )\r
+                       ;\r
+    \r
                p_qitem = cl_qmap_insert(\r
                        &p_port->endpt_mgr.lid_endpts, p_endpt->dlid, &p_endpt->lid_item );\r
                CL_ASSERT( p_qitem == &p_endpt->lid_item );\r
@@ -6294,6 +6318,12 @@ static void __port_do_mcast_garbage(ipoib_port_t* const  p_port)
        cl_qlist_init( &destroy_mc_list );\r
 \r
        cl_obj_lock( &p_port->obj );\r
+       /* Wait for all readers to finish */\r
+       while( p_port->endpt_rdr )\r
+       {\r
+               cl_obj_unlock( &p_port->obj );\r
+               cl_obj_lock( &p_port->obj );\r
+       }\r
        cnt = 0;\r
        p_item = cl_qmap_head( &p_port->endpt_mgr.mac_endpts );\r
        while( (p_item != cl_qmap_end( &p_port->endpt_mgr.mac_endpts )) && (cnt < GC_MAX_LEAVE_NUM))\r
@@ -6332,7 +6362,7 @@ static void __port_do_mcast_garbage(ipoib_port_t* const   p_port)
        /* Destroy all multicast endpoints now that we have released the lock. */\r
        while( cl_qlist_count( &destroy_mc_list ) )\r
        {\r
-               p_endpt = PARENT_STRUCT( cl_qlist_head( &destroy_mc_list ),\r
+               p_endpt = PARENT_STRUCT( cl_qlist_remove_head( &destroy_mc_list ),\r
                                                                 ipoib_endpt_t, mac_item.pool_item.list_item );\r
                IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_ENDPT,\r
                        ("mcast garbage collector: destroying endpoint %02x:%02x:%02x:%02x:%02x:%02x \n", \r
@@ -6342,9 +6372,7 @@ static void __port_do_mcast_garbage(ipoib_port_t* const   p_port)
                                 p_endpt->mac.addr[3],\r
                                 p_endpt->mac.addr[4],\r
                                 p_endpt->mac.addr[5]) );\r
-\r
-               cl_obj_destroy( &PARENT_STRUCT( cl_qlist_remove_head( &destroy_mc_list ),\r
-                       ipoib_endpt_t, mac_item.pool_item.list_item )->obj );\r
+               cl_obj_destroy( &p_endpt->obj );\r
        }\r
 }\r
 \r
index a1b6b5e..1b708b2 100644 (file)
@@ -378,7 +378,7 @@ typedef struct _ipoib_recv_desc
 typedef struct _ipoib_send_desc\r
 {\r
        NDIS_PACKET                     *p_pkt;\r
-       ipoib_endpt_t           *p_endpt;\r
+       ipoib_endpt_t           *p_endpt1;\r
        send_buf_t                      *p_buf;\r
        ib_send_wr_t            wr;\r
        ipoib_hdr_t                     pkt_hdr;\r