Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Edward Srouji <edwards@nvidia.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next 02/11] RDMA/mlx5: Rename to_mdev() helpers that return an IB device
Date: Sun, 22 Nov 2026 12:59:21 +0200	[thread overview]
Message-ID: <7edbb19c-d517-41b0-8dc9-3201d07ed0e5@nvidia.com> (raw)
In-Reply-To: <sashiko-outbox-221131@kernel.org>



On 11/18/2026 4:04 PM, sashiko-bot@kernel.org wrote:
> External email: Use caution opening links or attachments
> 
> 
> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 2 related pre-existing issues it does not
> introduce:
> - [High] RDMA/mlx5: memory leak of implicit child MRs in
>    mlx5_ib_free_odp_mr() [1]
> - [High] RDMA/mlx5: NULL pointer dereference in mlx5_ib_wq_event() [2]
> --
> 
> commit 19b81e90add2578f27e3e1241ff81dd5b9fdd061
> Author: Akiva Goldberger <agoldberger@nvidia.com>
> 
> RDMA/mlx5: Rename to_mdev() helpers that return an IB device
> 
> This commit renames to_mdev(), mr_to_mdev(), and mlx5_udata_to_mdev() to
> to_dev(), mr_to_dev(), and udata_to_dev() across the mlx5_ib driver to match
> their struct mlx5_ib_dev return type.
> 
>> diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
>> index 0b1b63d36e4bc..a4318b11cd81b 100644
>> --- a/drivers/infiniband/hw/mlx5/odp.c
>> +++ b/drivers/infiniband/hw/mlx5/odp.c
> 
> [ ... ]
> 
>> @@ -680,10 +680,10 @@ void mlx5_ib_free_odp_mr(struct mlx5_ib_mr *mr)
>>        }
>>
>>        if (mr->null_mmkey.key) {
>> -             xa_erase(&mr_to_mdev(mr)->odp_mkeys,
>> +             xa_erase(&mr_to_dev(mr)->odp_mkeys,
>>                         mlx5_base_mkey(mr->null_mmkey.key));
>>
>> -             mlx5_core_destroy_mkey(mr_to_mdev(mr)->mdev,
>> +             mlx5_core_destroy_mkey(mr_to_dev(mr)->mdev,
>>                                       mr->null_mmkey.key);
>>        }
>>   }
> 
> [Severity: High]
> This problem wasn't introduced by this patch, but can mlx5_ib_free_odp_mr()
> leak implicit child MRs [1] when a page fault races with teardown?
> 
> mlx5_ib_free_odp_mr() drains mr->implicit_children before removing
> mr->null_mmkey.key from dev->odp_mkeys:
> 
> drivers/infiniband/hw/mlx5/odp.c:mlx5_ib_free_odp_mr() {
>          ...
>          xa_for_each(&mr->implicit_children, idx, mtt) {
>                  xa_erase(&mr->implicit_children, idx);
>                  mlx5_ib_dereg_mr(&mtt->ibmr, NULL);
>          }
> 
>          if (mr->null_mmkey.key) {
>                  xa_erase(&mr_to_dev(mr)->odp_mkeys,
>                           mlx5_base_mkey(mr->null_mmkey.key));
>          ...
> }
> 
> Because null_mmkey remains in odp_mkeys while the loop runs, a concurrent
> page fault can still look it up and insert a new child MR after the loop
> finishes:
> 
> CPU0                              CPU1
> mlx5_ib_free_odp_mr()
>    xa_for_each(&mr->implicit_children, ...)
>      xa_erase(...)
>                                    pagefault_single_data_segment()
>                                      find_odp_mkey() -> null_mmkey
>                                      pagefault_implicit_mr()
>                                        implicit_get_child_mr()
>                                          __xa_cmpxchg(&imr->implicit_children, ...)
>    xa_erase(&dev->odp_mkeys, ...)
> 
> The newly inserted child MR and its xarray nodes are then leaked when the
> parent MR is freed.  Erasing null_mmkey from odp_mkeys and waiting for
> in-flight faults to complete before draining implicit_children would avoid
> this.
> 

The race is real. Not going to fix in this pure renaming patch.
We will add it to our fixes queue though.

> [ ... ]
> 
>> diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
>> index e4f18f7567d67..da4e9a52d2f9b 100644
>> --- a/drivers/infiniband/hw/mlx5/qp.c
>> +++ b/drivers/infiniband/hw/mlx5/qp.c
> 
> [ ... ]
> 
>> @@ -5331,7 +5331,7 @@ static void mlx5_ib_wq_event(struct mlx5_core_qp *core_qp, int type)
>>   {
>>        struct mlx5_ib_rwq *rwq = to_mibrwq(core_qp);
>> -     struct mlx5_ib_dev *dev = to_mdev(rwq->ibwq.device);
>> +     struct mlx5_ib_dev *dev = to_dev(rwq->ibwq.device);
>>        struct ib_event event;
>>
>>        if (rwq->ibwq.event_handler) {
> 
> [Severity: High]
> This problem wasn't introduced by this patch, but can an asynchronous WQ
> event trigger a NULL pointer dereference [2] in mlx5_ib_wq_event()
> before the RDMA core finishes initializing rwq->ibwq?
> 
> In UVERBS_HANDLER(UVERBS_METHOD_WQ_CREATE), the core sets wq->device and
> wq->uobject only after ops.create_wq() returns, whereas mlx5_ib_create_wq()
> sets rwq->ibwq.event_handler and activates the hardware RQ before returning:
> 
> CPU0                              CPU1
> UVERBS_HANDLER(UVERBS_METHOD_WQ_CREATE)
>    mlx5_ib_create_wq()
>      create_rq()
>        mlx5_core_create_rq_tracked()
>      rwq->ibwq.event_handler = ...
>      return &rwq->ibwq;
>                                    mlx5_ib_wq_event()
>                                      dev = to_dev(rwq->ibwq.device);
>                                      ib_uverbs_wq_event_handler()
>                                        wq->uobject->uevent  <-- NULL deref
>    wq->device = pd->device;
>    wq->uobject = obj;
> 
> If an event fires in this window, rwq->ibwq.device is still NULL (crashing
> in mlx5_ib_warn() on unexpected events) and ib_uverbs_wq_event_handler()
> dereferences a NULL wq->uobject.
> 

Hm... I'm not sure if this is real. The window is between create_wq() 
returning and the uverbs core setting wq->device. A WQ is created with 
its RQ in RST and is only moved to RDY by the user's modify_wq(), which 
needs the handle that create_wq() has not returned yet. An RQ in RST 
does not process doorbells and has no TIR or RQT referencing it, so 
nothing can raise WQ_CATAS_ERROR before wq->device is set. Only uverbs 
creates WQs (both the write and ioctl paths set wq->device after 
create_wq() returns). ib_create_wq() passes no udata and mlx5 rejects that.


> [1] https://sashiko.dev/#/bug/linux-f9cb6026-426e-45f3-b251-f749672898fb
> [2] https://sashiko.dev/#/bug/linux-63691fc3-b762-467d-89ea-1bf281490cc3
> 
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261117-mlx5-sd-prep-v1-0-8efd124c7895@nvidia.com?part=2


  reply	other threads:[~2026-11-22 11:02 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 14:01 [PATCH rdma-next 00/11] RDMA/mlx5: Preparation for SD support Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 01/11] RDMA/mlx5: Enforce dev/mdev naming for device pointers Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 10:43     ` Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 02/11] RDMA/mlx5: Rename to_mdev() helpers that return an IB device Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 10:59     ` Edward Srouji [this message]
2026-11-17 14:01 ` [PATCH rdma-next 03/11] RDMA/mlx5: Select the PD and SRQ core device through the PD Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-17 14:01 ` [PATCH rdma-next 04/11] RDMA/mlx5: Select the core device through PD for QP commands Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 12:31     ` Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 05/11] RDMA/mlx5: Cache the MR core device and resolve the MW's via its PD Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 12:32     ` Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 06/11] RDMA/mlx5: Select the AH core device through their PD Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-17 14:01 ` [PATCH rdma-next 07/11] RDMA/mlx5: Select the QP core device through its PD Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 12:35     ` Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 08/11] RDMA/mlx5: Resolve core device from ucontext for DEVX resources Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 12:43     ` Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 09/11] RDMA/mlx5: Cache the CQ core device and resolve it via cq_to_mdev() Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 12:41     ` Edward Srouji
2026-11-17 14:01 ` [PATCH rdma-next 10/11] RDMA/mlx5: Resolve the bfreg UAR-index core device from the ucontext Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-17 14:01 ` [PATCH rdma-next 11/11] RDMA/mlx5: Resolve UAR and mmap core devices via " Edward Srouji
2026-11-18 14:04   ` sashiko-bot
2026-11-22 10:32 ` [PATCH rdma-next 00/11] RDMA/mlx5: Preparation for SD support Edward Srouji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7edbb19c-d517-41b0-8dc9-3201d07ed0e5@nvidia.com \
    --to=edwards@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox