Skip to content

Commit d59ebb4

Browse files
committed
RDMA/mlx5: Fix returned type from _mlx5r_umr_zap_mkey()
As Colin reported: "The variable zapped_blocks is a size_t type and is being assigned a int return value from the call to _mlx5r_umr_zap_mkey. Since zapped_blocks is an unsigned type, the error check for zapped_blocks < 0 will never be true." So separate return error and nblocks assignment. Fixes: e73242a ("RDMA/mlx5: Optimize DMABUF mkey page size") Reported-by: Colin King (gmail) <[email protected]> Closes: https://lore.kernel.org/all/[email protected] Link: https://patch.msgid.link/71d8ea208ac7eaa4438af683b9afaed78625e419.1753003467.git.leon@kernel.org Reviewed-by: Zhu Yanjun <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent aee80e6 commit d59ebb4

File tree

1 file changed

+14
-14
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+14
-14
lines changed

drivers/infiniband/hw/mlx5/umr.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ _mlx5r_dmabuf_umr_update_pas(struct mlx5_ib_mr *mr, unsigned int flags,
992992
static int _mlx5r_umr_zap_mkey(struct mlx5_ib_mr *mr,
993993
unsigned int flags,
994994
unsigned int page_shift,
995+
size_t *nblocks,
995996
bool dd)
996997
{
997998
unsigned int old_page_shift = mr->page_shift;
@@ -1000,7 +1001,6 @@ static int _mlx5r_umr_zap_mkey(struct mlx5_ib_mr *mr,
10001001
size_t page_shift_nblocks;
10011002
unsigned int max_log_size;
10021003
int access_mode;
1003-
size_t nblocks;
10041004
int err;
10051005

10061006
access_mode = dd ? MLX5_MKC_ACCESS_MODE_KSM : MLX5_MKC_ACCESS_MODE_MTT;
@@ -1014,26 +1014,26 @@ static int _mlx5r_umr_zap_mkey(struct mlx5_ib_mr *mr,
10141014
* Block size must be aligned to MLX5_UMR_FLEX_ALIGNMENT since it may
10151015
* be used as offset into the XLT later on.
10161016
*/
1017-
nblocks = ib_umem_num_dma_blocks(mr->umem, 1UL << max_page_shift);
1017+
*nblocks = ib_umem_num_dma_blocks(mr->umem, 1UL << max_page_shift);
10181018
if (dd)
1019-
nblocks = ALIGN(nblocks, MLX5_UMR_KSM_NUM_ENTRIES_ALIGNMENT);
1019+
*nblocks = ALIGN(*nblocks, MLX5_UMR_KSM_NUM_ENTRIES_ALIGNMENT);
10201020
else
1021-
nblocks = ALIGN(nblocks, MLX5_UMR_MTT_NUM_ENTRIES_ALIGNMENT);
1021+
*nblocks = ALIGN(*nblocks, MLX5_UMR_MTT_NUM_ENTRIES_ALIGNMENT);
10221022
page_shift_nblocks = ib_umem_num_dma_blocks(mr->umem,
10231023
1UL << page_shift);
10241024
/* If the number of blocks at max possible page shift is greater than
10251025
* the number of blocks at the new page size, we should just go over the
10261026
* whole mkey entries.
10271027
*/
1028-
if (nblocks >= page_shift_nblocks)
1029-
nblocks = 0;
1028+
if (*nblocks >= page_shift_nblocks)
1029+
*nblocks = 0;
10301030

10311031
/* Make the first nblocks entries non-present without changing
10321032
* page size yet.
10331033
*/
1034-
if (nblocks)
1034+
if (*nblocks)
10351035
mr->page_shift = max_page_shift;
1036-
err = _mlx5r_dmabuf_umr_update_pas(mr, flags, 0, nblocks, dd);
1036+
err = _mlx5r_dmabuf_umr_update_pas(mr, flags, 0, *nblocks, dd);
10371037
if (err) {
10381038
mr->page_shift = old_page_shift;
10391039
return err;
@@ -1042,15 +1042,15 @@ static int _mlx5r_umr_zap_mkey(struct mlx5_ib_mr *mr,
10421042
/* Change page size to the max page size now that the MR is completely
10431043
* non-present.
10441044
*/
1045-
if (nblocks) {
1045+
if (*nblocks) {
10461046
err = mlx5r_umr_update_mr_page_shift(mr, max_page_shift, dd);
10471047
if (err) {
10481048
mr->page_shift = old_page_shift;
10491049
return err;
10501050
}
10511051
}
10521052

1053-
return nblocks;
1053+
return 0;
10541054
}
10551055

10561056
/**
@@ -1085,10 +1085,10 @@ int mlx5r_umr_dmabuf_update_pgsz(struct mlx5_ib_mr *mr, u32 xlt_flags,
10851085
size_t total_blocks;
10861086
int err;
10871087

1088-
zapped_blocks = _mlx5r_umr_zap_mkey(mr, xlt_flags, page_shift,
1089-
mr->data_direct);
1090-
if (zapped_blocks < 0)
1091-
return zapped_blocks;
1088+
err = _mlx5r_umr_zap_mkey(mr, xlt_flags, page_shift, &zapped_blocks,
1089+
mr->data_direct);
1090+
if (err)
1091+
return err;
10921092

10931093
/* _mlx5r_umr_zap_mkey already enables the mkey */
10941094
xlt_flags &= ~MLX5_IB_UPD_XLT_ENABLE;

0 commit comments

Comments
 (0)