Skip to contentSkip to conversation

RDMA/mlx5: Change check for cacheable user mkeys

PATCH Michael Guralnik 2 participants 5 messages Jan 31, 2024 1 message not in the archive InfiniBand

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 9 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky

From: Or Har-Toov <[email protected]>

In the dereg flow, UMEM is not a good enough indication whether an MR is from userspace since in mlx5_ib_rereg_user_mr there are some cases when a new MR is created and the UMEM of the old MR is set to NULL.

Why is this a problem though? The only thing the umem has to do is to trigger the UMR optimization. If UMR is not triggered then the mkey is destroyed and it shouldn't be part of the cache at all.

The problem is that it doesn't trigger the UMR on mkeys that are dereged from the rereg flow.
Optimally, we'd want them to return to the cache, if possible.

We can keep relying on the UMEM to decide whether we want to try to return them to cache, as you suggested in the revoke_mr() below, but that way those mkeys will not return to the cache and we have to deal with the in_use in the revoke flow.

Quoted 11 lines

Review int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct · line 1918

Quoted 8 lines
(quoted diff) +3 -1
@@ -1914,7 +1913,9 @@ int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct 
 ib_udata *udata)
 ib_umem_stop_invalidation_notifier(mr->umem);
 }
- if (!mr->mmkey.cache_ent) {
+ /* Stop DMA */
+ if (!is_cacheable_mkey(&mr->mmkey) || mlx5r_umr_revoke_mr(mr) ||
+ cache_ent_find_and_store(dev, mr)) {

And now the mlx5r_umr_can_load_pas() can been lost, that isn't good. A non-umr-able object should never be placed in the cache. If the mkey's size is too big it has to be freed normally.

mlx5r_can_load_pas() will not get lost since mkeys that are not-umr-able will not have rb_key or cache_ent set so is_cacheable_mkey is always false for them.

Quoted 36 lines

Review int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct · line 1921

Quoted 3 lines
(quoted diff) +0 -0
 rc = destroy_mkey(to_mdev(mr->ibmr.device), mr);
 if (rc)
 return rc;

I'm not sure it is right to re-order this? The revokation of a mkey should be a single operation, which ever path we choose to take..

Regardless the upstream code doesn't have this ordering so it should all be one sequence of revoking the mkey and synchronizing the cache.

I suggest to put the revoke sequence into one function:

static int mlx5_revoke_mr(struct mlx5_ib_mr *mr) {
struct mlx5_ib_dev *dev = to_mdev(mr->ibmr.device);

if (mr->umem && mlx5r_umr_can_load_pas(dev, mr->umem->length)) { if (mlx5r_umr_revoke_mr(mr))
goto destroy;

if (cache_ent_find_and_store(dev, mr))
goto destroy;
return 0;
}

destroy:
if (mr->mmkey.cache_ent) { spin_lock_irq(&mr->mmkey.cache_ent->mkeys_queue.lock); mr->mmkey.cache_ent->in_use--; mr->mmkey.cache_ent = NULL; spin_unlock_irq(&mr->mmkey.cache_ent->mkeys_queue.lock); }
return destroy_mkey(dev, mr);
}

(notice we probably shouldn't set cache_ent to null without adjusting in_use) Jason

maintainer
#2 lore raw
Quoted 7 lines · Michael Guralnik
Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky

From: Or Har-Toov <[email protected]>

In the dereg flow, UMEM is not a good enough indication whether an MR is from userspace since in mlx5_ib_rereg_user_mr there are some cases when a new MR is created and the UMEM of the old MR is set to NULL.

Quoted 7 lines
Quoted 3 lines

Why is this a problem though? The only thing the umem has to do is to trigger the UMR optimization. If UMR is not triggered then the mkey is destroyed and it shouldn't be part of the cache at all.

The problem is that it doesn't trigger the UMR on mkeys that are dereged from the rereg flow.
Optimally, we'd want them to return to the cache, if possible.

Right, so you suggest changing the umem and umr_can_load into is_cacheable_mkey() and carefully ensuring the rb_key.ndescs is zero for non-umrable?

Quoted 4 lines

We can keep relying on the UMEM to decide whether we want to try to return them to cache, as you suggested in the revoke_mr() below, but that way those mkeys will not return to the cache and we have to deal with the in_use in the revoke flow.

I don't know what this in_use means? in_use should be only an issue if the cache_ent is set? Are we really having in_use be set and cache_ent bet NULL? That seems like a different bug that should be fixed by keeping cache_ent and in_use consistent.

Jason

#3 lore raw
Quoted 11 lines · Jason Gunthorpe
Quoted 10 lines · Michael Guralnik
Quoted 9 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky

From: Or Har-Toov <[email protected]>

In the dereg flow, UMEM is not a good enough indication whether an MR is from userspace since in mlx5_ib_rereg_user_mr there are some cases when a new MR is created and the UMEM of the old MR is set to NULL.

Why is this a problem though? The only thing the umem has to do is to trigger the UMR optimization. If UMR is not triggered then the mkey is destroyed and it shouldn't be part of the cache at all.

Quoted 6 lines
Quoted 3 lines

The problem is that it doesn't trigger the UMR on mkeys that are dereged from the rereg flow.
Optimally, we'd want them to return to the cache, if possible.

Right, so you suggest changing the umem and umr_can_load into is_cacheable_mkey() and carefully ensuring the rb_key.ndescs is zero for non-umrable?

Yes. The code is already written trying to ensure this and we've rephrased a comment in the previous patch to describe this more accurately.

Quoted 8 lines
Quoted 4 lines

We can keep relying on the UMEM to decide whether we want to try to return them to cache, as you suggested in the revoke_mr() below, but that way those mkeys will not return to the cache and we have to deal with the in_use in the revoke flow.

I don't know what this in_use means? in_use should be only an issue if the cache_ent is set? Are we really having in_use be set and cache_ent bet NULL? That seems like a different bug that should be fixed by keeping cache_ent and in_use consistent.

in_use should be handled only if mkey has a cache_ent.

I take back what I wrote previously, in_use should be handled in revoke_mr no matter how we choose to implement this, since we're not guaranteed to succeed in UMR and might end up dereging mkeys from the cache.

maintainer
#4 lore raw
Quoted 16 lines · Michael Guralnik
Quoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Michael Guralnik
Quoted 9 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky

From: Or Har-Toov <[email protected]>

In the dereg flow, UMEM is not a good enough indication whether an MR is from userspace since in mlx5_ib_rereg_user_mr there are some cases when a new MR is created and the UMEM of the old MR is set to NULL.

Why is this a problem though? The only thing the umem has to do is to trigger the UMR optimization. If UMR is not triggered then the mkey is destroyed and it shouldn't be part of the cache at all.

The problem is that it doesn't trigger the UMR on mkeys that are dereged from the rereg flow.
Optimally, we'd want them to return to the cache, if possible.

Quoted 6 lines
Quoted 3 lines

Right, so you suggest changing the umem and umr_can_load into is_cacheable_mkey() and carefully ensuring the rb_key.ndescs is zero for non-umrable?

Yes. The code is already written trying to ensure this and we've rephrased a comment in the previous patch to describe this more accurately.

But then I wonder why does cache_ent become NULL but the rb_key.ndesc is set? That seems pretty confusing.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

We can keep relying on the UMEM to decide whether we want to try to return them to cache, as you suggested in the revoke_mr() below, but that way those mkeys will not return to the cache and we have to deal with the in_use in the revoke flow.

I don't know what this in_use means? in_use should be only an issue if the cache_ent is set? Are we really having in_use be set and cache_ent bet NULL? That seems like a different bug that should be fixed by keeping cache_ent and in_use consistent.

Quoted 5 lines

in_use should be handled only if mkey has a cache_ent.

I take back what I wrote previously, in_use should be handled in revoke_mr no matter how we choose to implement this, since we're not guaranteed to succeed in UMR and might end up dereging mkeys from the cache.

That makes the most sense, yes.

Jason

#5 lore raw
Quoted 16 lines · Jason Gunthorpe
Quoted 15 lines · Michael Guralnik
Quoted 14 lines · Jason Gunthorpe
Quoted 13 lines · Michael Guralnik
Quoted 9 lines · Jason Gunthorpe
Quoted 5 lines · Leon Romanovsky

From: Or Har-Toov <[email protected]>

In the dereg flow, UMEM is not a good enough indication whether an MR is from userspace since in mlx5_ib_rereg_user_mr there are some cases when a new MR is created and the UMEM of the old MR is set to NULL.

Why is this a problem though? The only thing the umem has to do is to trigger the UMR optimization. If UMR is not triggered then the mkey is destroyed and it shouldn't be part of the cache at all.

The problem is that it doesn't trigger the UMR on mkeys that are dereged from the rereg flow.
Optimally, we'd want them to return to the cache, if possible.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Right, so you suggest changing the umem and umr_can_load into is_cacheable_mkey() and carefully ensuring the rb_key.ndescs is zero for non-umrable?

Yes. The code is already written trying to ensure this and we've rephrased a comment in the previous patch to describe this more accurately.

But then I wonder why does cache_ent become NULL but the rb_key.ndesc is set? That seems pretty confusing.

I think we did it only in the flow where we destroy the mkey to mark mkeys that were not returned to the cache.

Do you think it'll be better if we switch to marking this explicitly? Add a flag to the mkey that marks it as a cachable mkey and we'll make this decision per mkey creation.
Then we can stop relying on the value of other variables to decide what goes back to cache.

Michael