@@ -34,6 +34,7 @@ typedef union uct_ib_mlx5_mr {
3434
3535typedef struct uct_ib_mlx5_mem {
3636 uct_ib_mem_t super ;
37+ void * address ;
3738#if HAVE_DEVX
3839 struct mlx5dv_devx_obj * atomic_dvmr ;
3940 struct mlx5dv_devx_obj * indirect_dvmr ;
@@ -51,6 +52,8 @@ uct_ib_mlx5_reg_key(uct_ib_md_t *md, void *address, size_t length,
5152{
5253 uct_ib_mlx5_mem_t * memh = ucs_derived_of (ib_memh , uct_ib_mlx5_mem_t );
5354
55+ memh -> address = address ;
56+
5457 return uct_ib_reg_key_impl (md , address , length , access_flags , dmabuf_fd ,
5558 dmabuf_offset , ib_memh ,
5659 & memh -> mrs [mr_type ].super , mr_type , silent );
@@ -208,12 +211,13 @@ static ucs_status_t uct_ib_mlx5_devx_reg_ksm(uct_ib_mlx5_md_t *md, int atomic,
208211}
209212
210213static ucs_status_t
211- uct_ib_mlx5_devx_reg_ksm_data (uct_ib_mlx5_md_t * md , int atomic ,
214+ uct_ib_mlx5_devx_reg_ksm_data (uct_ib_mlx5_md_t * md , int atomic , void * address ,
212215 uct_ib_mlx5_ksm_data_t * ksm_data ,
213216 size_t length , off_t off ,
214217 struct mlx5dv_devx_obj * * mr_p ,
215218 uint32_t * mkey )
216219{
220+ void * mr_address = address ;
217221 ucs_status_t status ;
218222 char * in ;
219223 void * klm ;
@@ -226,14 +230,15 @@ uct_ib_mlx5_devx_reg_ksm_data(uct_ib_mlx5_md_t *md, int atomic,
226230
227231 klm = UCT_IB_MLX5DV_ADDR_OF (create_mkey_in , in , klm_pas_mtt );
228232 for (i = 0 ; i < ksm_data -> mr_num ; i ++ ) {
229- UCT_IB_MLX5DV_SET64 (klm , klm , address , (intptr_t ) ksm_data -> mrs [ i ] -> addr );
233+ UCT_IB_MLX5DV_SET64 (klm , klm , address , (uintptr_t ) mr_address );
230234 UCT_IB_MLX5DV_SET (klm , klm , byte_count , ksm_data -> mrs [i ]-> length );
231235 UCT_IB_MLX5DV_SET (klm , klm , mkey , ksm_data -> mrs [i ]-> lkey );
232- klm = UCS_PTR_BYTE_OFFSET (klm , UCT_IB_MLX5DV_ST_SZ_BYTES (klm ));
236+ klm = UCS_PTR_BYTE_OFFSET (klm , UCT_IB_MLX5DV_ST_SZ_BYTES (klm ));
237+ mr_address = UCS_PTR_BYTE_OFFSET (mr_address , ksm_data -> mrs [i ]-> length );
233238 }
234239
235240 status = uct_ib_mlx5_devx_reg_ksm (md , atomic ,
236- (intptr_t ) ksm_data -> mrs [ 0 ] -> addr + off ,
241+ (uintptr_t ) address + off ,
237242 length , ksm_data -> mr_num ,
238243 ksm_data -> mrs [0 ]-> length , in , mr_p ,
239244 mkey );
@@ -276,14 +281,15 @@ uct_ib_mlx5_devx_reg_ksm_data_addr(uct_ib_mlx5_md_t *md, struct ibv_mr *mr,
276281static ucs_status_t
277282uct_ib_mlx5_devx_reg_ksm_data_contig (uct_ib_mlx5_md_t * md ,
278283 uct_ib_mlx5_mr_t * mr , off_t off ,
279- int atomic , struct mlx5dv_devx_obj * * mr_p ,
284+ void * address , int atomic ,
285+ struct mlx5dv_devx_obj * * mr_p ,
280286 uint32_t * mkey )
281287{
282- intptr_t addr = (intptr_t )mr -> super . ib -> addr & ~(UCT_IB_MD_MAX_MR_SIZE - 1 );
288+ intptr_t addr = (intptr_t )address & ~(UCT_IB_MD_MAX_MR_SIZE - 1 );
283289 /* FW requires indirect atomic MR addr and length to be aligned
284290 * to max supported atomic argument size */
285291 size_t length = ucs_align_up (mr -> super .ib -> length +
286- (intptr_t )mr -> super . ib -> addr - addr ,
292+ (intptr_t )address - addr ,
287293 md -> super .dev .atomic_align );
288294 /* add off to workaround CREATE_MKEY range check issue */
289295 int list_size = ucs_div_round_up (length + off , UCT_IB_MD_MAX_MR_SIZE );
@@ -445,8 +451,8 @@ static ucs_status_t uct_ib_mlx5_devx_reg_indirect_key(uct_ib_md_t *ibmd,
445451
446452 do {
447453 status = uct_ib_mlx5_devx_reg_ksm_data_contig (
448- md , & memh -> mrs [UCT_IB_MR_DEFAULT ], 0 , 0 , & memh -> indirect_dvmr ,
449- & memh -> super .indirect_rkey );
454+ md , & memh -> mrs [UCT_IB_MR_DEFAULT ], 0 , memh -> address , 0 ,
455+ & memh -> indirect_dvmr , & memh -> super .indirect_rkey );
450456 if (status != UCS_OK ) {
451457 break ;
452458 }
@@ -549,23 +555,24 @@ static ucs_status_t uct_ib_mlx5_devx_reg_atomic_key(uct_ib_md_t *ibmd,
549555 is_atomic = memh -> super .flags & UCT_IB_MEM_ACCESS_REMOTE_ATOMIC ;
550556
551557 if (memh -> super .flags & UCT_IB_MEM_MULTITHREADED ) {
552- return uct_ib_mlx5_devx_reg_ksm_data (md , is_atomic , mr -> ksm_data ,
558+ return uct_ib_mlx5_devx_reg_ksm_data (md , is_atomic , memh -> address ,
559+ mr -> ksm_data ,
553560 mr -> ksm_data -> length ,
554561 uct_ib_md_atomic_offset (mr_id ),
555562 & memh -> atomic_dvmr ,
556563 & memh -> super .atomic_rkey );
557564 }
558565
559566 status = uct_ib_mlx5_devx_reg_ksm_data_contig (
560- md , mr , uct_ib_md_atomic_offset (mr_id ), is_atomic ,
567+ md , mr , uct_ib_md_atomic_offset (mr_id ), memh -> address , is_atomic ,
561568 & memh -> atomic_dvmr , & memh -> super .atomic_rkey );
562569 if (status != UCS_OK ) {
563570 return status ;
564571 }
565572
566573 ucs_debug ("KSM registered memory %p..%p offset 0x%x%s on %s rkey 0x%x" ,
567- mr -> super . ib -> addr ,
568- UCS_PTR_BYTE_OFFSET (mr -> super . ib -> addr , mr -> super .ib -> length ),
574+ memh -> address ,
575+ UCS_PTR_BYTE_OFFSET (memh -> address , mr -> super .ib -> length ),
569576 uct_ib_md_atomic_offset (mr_id ), is_atomic ? " atomic" : "" ,
570577 uct_ib_device_name (& md -> super .dev ), memh -> super .atomic_rkey );
571578 return status ;
@@ -627,8 +634,8 @@ static ucs_status_t uct_ib_mlx5_devx_reg_multithreaded(uct_ib_md_t *ibmd,
627634 goto err ;
628635 }
629636
630- status = uct_ib_mlx5_devx_reg_ksm_data (md , is_atomic , ksm_data , length , 0 ,
631- & ksm_data -> dvmr , & mkey );
637+ status = uct_ib_mlx5_devx_reg_ksm_data (md , is_atomic , address , ksm_data ,
638+ length , 0 , & ksm_data -> dvmr , & mkey );
632639 if (status != UCS_OK ) {
633640 goto err_dereg ;
634641 }
@@ -639,6 +646,8 @@ static ucs_status_t uct_ib_mlx5_devx_reg_multithreaded(uct_ib_md_t *ibmd,
639646 if (mr_type == UCT_IB_MR_DEFAULT ) {
640647 uct_ib_memh_init_keys (ib_memh , mkey , mkey );
641648 }
649+
650+ memh -> address = address ;
642651 return UCS_OK ;
643652
644653err_dereg :
@@ -1225,9 +1234,8 @@ static ucs_status_t uct_ib_mlx5_devx_md_open(struct ibv_device *ibv_device,
12251234 }
12261235
12271236 md -> super .ops = & uct_ib_mlx5_devx_md_ops ;
1228- status = uct_ib_md_open_common (& md -> super , ibv_device , md_config ,
1229- sizeof (uct_ib_mlx5_mem_t ),
1230- sizeof (uct_ib_mlx5_mr_t ));
1237+
1238+ status = uct_ib_md_open_common (& md -> super , ibv_device , md_config );
12311239 if (status != UCS_OK ) {
12321240 goto err_lru_cleanup ;
12331241 }
@@ -1274,7 +1282,14 @@ static ucs_status_t uct_ib_mlx5_devx_md_open(struct ibv_device *ibv_device,
12741282
12751283 /* Enable relaxed order only if we would be able to create an indirect key
12761284 (with offset) for strict order access */
1277- uct_ib_md_parse_relaxed_order (& md -> super , md_config , ksm_atomic );
1285+ uct_ib_md_parse_relaxed_order (& md -> super , md_config , ksm_atomic ,
1286+ sizeof (uct_ib_mlx5_mem_t ),
1287+ sizeof (uct_ib_mlx5_mr_t ));
1288+
1289+ status = uct_ib_md_parse_reg_methods (& md -> super , md_config );
1290+ if (status != UCS_OK ) {
1291+ goto err_dbrec_mpool_cleanup ;
1292+ }
12781293
12791294 uct_ib_mlx5_devx_init_flush_mr (md );
12801295
@@ -1454,18 +1469,18 @@ uct_ib_mlx5_devx_reg_exported_key(uct_ib_md_t *ib_md, uct_ib_mem_t *ib_memh)
14541469 struct mlx5dv_devx_umem_in umem_in ;
14551470 ucs_status_t status ;
14561471 void * access_key ;
1457- void * address , * aligned_address ;
1472+ void * aligned_address ;
14581473 size_t length ;
14591474 void * mkc ;
14601475
1461- address = memh -> mrs [UCT_IB_MR_DEFAULT ].super .ib -> addr ;
14621476 length = memh -> mrs [UCT_IB_MR_DEFAULT ].super .ib -> length ;
14631477
14641478 /* register umem */
1465- umem_in .addr = address ;
1479+ umem_in .addr = memh -> address ;
14661480 umem_in .size = length ;
14671481 umem_in .access = UCT_IB_MLX5_MD_UMEM_ACCESS ;
1468- aligned_address = ucs_align_down_pow2_ptr (address , ucs_get_page_size ());
1482+ aligned_address = ucs_align_down_pow2_ptr (memh -> address ,
1483+ ucs_get_page_size ());
14691484 umem_in .pgsz_bitmap = UCS_MASK (ucs_ffs64 ((uint64_t )aligned_address ) + 1 );
14701485 umem_in .comp_mask = 0 ;
14711486
@@ -1496,7 +1511,7 @@ uct_ib_mlx5_devx_reg_exported_key(uct_ib_md_t *ib_md, uct_ib_mem_t *ib_memh)
14961511 UCT_IB_MLX5DV_SET (mkc , mkc , qpn , 0xffffff );
14971512 UCT_IB_MLX5DV_SET (mkc , mkc , pd , uct_ib_mlx5_devx_md_get_pdn (md ));
14981513 UCT_IB_MLX5DV_SET (mkc , mkc , mkey_7_0 , md -> mkey_tag );
1499- UCT_IB_MLX5DV_SET64 (mkc , mkc , start_addr , (intptr_t )address );
1514+ UCT_IB_MLX5DV_SET64 (mkc , mkc , start_addr , (intptr_t )memh -> address );
15001515 UCT_IB_MLX5DV_SET64 (mkc , mkc , len , length );
15011516
15021517 ucs_assertv (memh -> cross_mr == NULL , "memh %p cross_mr %p" , memh ,
@@ -1775,19 +1790,24 @@ static ucs_status_t uct_ib_mlx5dv_md_open(struct ibv_device *ibv_device,
17751790 md -> super .ops = & uct_ib_mlx5_md_ops ;
17761791 md -> max_rd_atomic_dc = IBV_DEV_ATTR (dev , max_qp_rd_atom );
17771792 status = uct_ib_md_open_common (& md -> super , ibv_device ,
1778- md_config ,
1779- sizeof (uct_ib_mlx5_mem_t ),
1780- sizeof (uct_ib_mlx5_mr_t ));
1793+ md_config );
17811794 if (status != UCS_OK ) {
17821795 goto err_md_free ;
17831796 }
17841797
17851798 dev -> flags |= UCT_IB_DEVICE_FLAG_MLX5_PRM ;
17861799 md -> super .name = UCT_IB_MD_NAME (mlx5 );
17871800
1788- uct_ib_md_parse_relaxed_order (& md -> super , md_config , 0 );
1801+ uct_ib_md_parse_relaxed_order (& md -> super , md_config , 0 ,
1802+ sizeof (uct_ib_mlx5_mem_t ),
1803+ sizeof (uct_ib_mlx5_mr_t ));
17891804 uct_ib_md_ece_check (& md -> super );
17901805
1806+ status = uct_ib_md_parse_reg_methods (& md -> super , md_config );
1807+ if (status != UCS_OK ) {
1808+ goto err_md_free ;
1809+ }
1810+
17911811 md -> super .flush_rkey = uct_ib_mlx5_flush_rkey_make ();
17921812
17931813 /* cppcheck-suppress autoVariables */
0 commit comments