Skip to content

Commit 24d693c

Browse files
mikijoyrleon
authored andcommitted
RDMA/mlx5: Fix cache entry update on dereg error
Fix double decrement of 'in_use' counter on push_mkey_locked() failure while deregistering an MR. If we fail to return an mkey to the cache in cache_ent_find_and_store() it'll update the 'in_use' counter. Its caller, revoke_mr(), also updates it, thus having double decrement. Wrong value of 'in_use' counter will be exposed through debugfs and can also cause wrong resizing of the cache when users try to set cache entry size using the 'size' debugfs. To address this issue, the 'in_use' counter is now decremented within mlx5_revoke_mr() also after a successful call to cache_ent_find_and_store() and not within cache_ent_find_and_store(). Other success or failure flows remains unchanged where it was also decremented. Fixes: 8c1185f ("RDMA/mlx5: Change check for cacheable mkeys") Signed-off-by: Michael Guralnik <[email protected]> Reviewed-by: Yishai Hadas <[email protected]> Link: https://patch.msgid.link/97e979dff636f232ff4c83ce709c17c727da1fdb.1741875692.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent a0130ef commit 24d693c

File tree

1 file changed

+3
-1
lines changed
  • drivers/infiniband/hw/mlx5

1 file changed

+3
-1
lines changed

drivers/infiniband/hw/mlx5/mr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,6 @@ static int cache_ent_find_and_store(struct mlx5_ib_dev *dev,
19671967

19681968
if (mr->mmkey.cache_ent) {
19691969
spin_lock_irq(&mr->mmkey.cache_ent->mkeys_queue.lock);
1970-
mr->mmkey.cache_ent->in_use--;
19711970
goto end;
19721971
}
19731972

@@ -2033,6 +2032,7 @@ static int mlx5_revoke_mr(struct mlx5_ib_mr *mr)
20332032
struct mlx5_ib_dev *dev = to_mdev(mr->ibmr.device);
20342033
struct mlx5_cache_ent *ent = mr->mmkey.cache_ent;
20352034
bool is_odp = is_odp_mr(mr);
2035+
bool from_cache = !!ent;
20362036
int ret = 0;
20372037

20382038
if (is_odp)
@@ -2042,6 +2042,8 @@ static int mlx5_revoke_mr(struct mlx5_ib_mr *mr)
20422042
ent = mr->mmkey.cache_ent;
20432043
/* upon storing to a clean temp entry - schedule its cleanup */
20442044
spin_lock_irq(&ent->mkeys_queue.lock);
2045+
if (from_cache)
2046+
ent->in_use--;
20452047
if (ent->is_tmp && !ent->tmp_cleanup_scheduled) {
20462048
mod_delayed_work(ent->dev->cache.wq, &ent->dwork,
20472049
msecs_to_jiffies(30 * 1000));

0 commit comments

Comments
 (0)