From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5550B3254B2; Sat, 7 Mar 2026 01:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848054; cv=none; b=WZrbRfHAq0LkMLeZ12mqMMWRJEolX/0RuuWy40q368ewtC1HcHNslOtKAwPj6XxbRLmjIQW/9pwbn0iRFnxIdEwdE658bx3151IDGXGi5rdzUa+wI0d1xIeb8w0g/bNkvo8O0kR8ad/xUpJ8jzCV5mwdorpxTCg6j9UCSFZKjNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848054; c=relaxed/simple; bh=G5JUmQnoDfSaDwdB0ooqXdCrFcaPKNLXU+xVMpdoZEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CayPe1Faiq6o8cyFeZrojmEx5UTpXfrSrW8U2NggaiYp5zU1/GRn9fH0RkOQV9NQoIoDgXVusuXji+HRq8yPfEV6bqaZ4E2132eDf2ov2m+Pu35EE6ps+JUYNe60/2IGXW423R3Z+UrCVNywOWwW9SK+ZunDsC9H+luwMPcSf10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 526C620B6F02; Fri, 6 Mar 2026 17:47:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 526C620B6F02 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 1/8] RDMA/mana_ib: Track ucontext per device Date: Fri, 6 Mar 2026 17:47:15 -0800 Message-ID: <20260307014723.556523-2-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add per-device tracking of ucontext objects. Each ucontext is added to the device's ucontext_list on allocation and removed on deallocation. A mutex protects the list and a per-ucontext lock protects resource lists that will be added in subsequent patches. This enables iterating over all active ucontexts during service reset cleanup. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/device.c | 2 ++ drivers/infiniband/hw/mana/main.c | 10 ++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/ma= na/device.c index ccc2279ca63c..149e8d4d5b8e 100644 --- a/drivers/infiniband/hw/mana/device.c +++ b/drivers/infiniband/hw/mana/device.c @@ -132,6 +132,8 @@ static int mana_ib_probe(struct auxiliary_device *adev, dev->ib_dev.dev.parent =3D gc->dev; dev->gdma_dev =3D mdev; xa_init_flags(&dev->qp_table_wq, XA_FLAGS_LOCK_IRQ); + mutex_init(&dev->ucontext_lock); + INIT_LIST_HEAD(&dev->ucontext_list); =20 if (mana_ib_is_rnic(dev)) { dev->ib_dev.phys_port_cnt =3D 1; diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index 8d99cd00f002..fc28bdafcfd6 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -221,6 +221,12 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibconte= xt, =20 ucontext->doorbell =3D doorbell_page; =20 + mutex_init(&ucontext->lock); + + mutex_lock(&mdev->ucontext_lock); + list_add_tail(&ucontext->dev_list, &mdev->ucontext_list); + mutex_unlock(&mdev->ucontext_lock); + return 0; } =20 @@ -236,6 +242,10 @@ void mana_ib_dealloc_ucontext(struct ib_ucontext *ibco= ntext) mdev =3D container_of(ibdev, struct mana_ib_dev, ib_dev); gc =3D mdev_to_gc(mdev); =20 + mutex_lock(&mdev->ucontext_lock); + list_del_init(&mana_ucontext->dev_list); + mutex_unlock(&mdev->ucontext_lock); + ret =3D mana_gd_destroy_doorbell_page(gc, mana_ucontext->doorbell); if (ret) ibdev_dbg(ibdev, "Failed to destroy doorbell page %d\n", ret); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index a7c8c0fd7019..c7e333d3e9d8 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -83,6 +83,9 @@ struct mana_ib_dev { struct dma_pool *av_pool; netdevice_tracker dev_tracker; struct notifier_block nb; + /* Protects ucontext_list */ + struct mutex ucontext_lock; + struct list_head ucontext_list; }; =20 struct mana_ib_wq { @@ -197,6 +200,9 @@ struct mana_ib_qp { struct mana_ib_ucontext { struct ib_ucontext ibucontext; u32 doorbell; + struct list_head dev_list; + /* Protects resource lists below */ + struct mutex lock; }; =20 struct mana_ib_rwq_ind_table { --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 578D6326D5E; Sat, 7 Mar 2026 01:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848055; cv=none; b=s2GeOtIr69e/3yFHbHuSMZT7PwlZAGmOoJeZ1cOFzFD9OB2rRi8kt7lAYyCcFAAgn7c4Ppgdiw+vt7O7XDA+1d6T3h9/dOpVKLYgKkWodYu21V7dLAqlPFfOM5vDrnmF4r49Nhtlf7rSEFmG4kBy74sp83zKZbhzmePLpFGcUSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848055; c=relaxed/simple; bh=aYTEd3CmO8Tw/gVgrDcwvd9TdGAkXQIZw/u3qNWEaW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DG+wHr6H4nsYN9jDIfpG3BaNpI06n8OLr33eeC7nWoEniZ6hS4URoOFtD9K1jiXbEethdVhNPrL3R15ruDAk71MybyBGd+2vnzMjObuERN6rqWEXDscd0+I9OXBGdCsFnGzrIyn/G8ogonCYGwTYnKQeN+L8iDbensn8FkmqsuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 2FB3A20B6F0A; Fri, 6 Mar 2026 17:47:34 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2FB3A20B6F0A From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 2/8] RDMA/mana_ib: Track PD per ucontext Date: Fri, 6 Mar 2026 17:47:16 -0800 Message-ID: <20260307014723.556523-3-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add per-ucontext list tracking for PD objects. Each PD is added to the ucontext's pd_list on creation and removed on destruction. This enables iterating over all PDs belonging to a ucontext, which will be needed for service reset cleanup. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/main.c | 21 +++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index fc28bdafcfd6..62d89ca06ba1 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -72,6 +72,7 @@ int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata = *udata) struct ib_device *ibdev =3D ibpd->device; struct gdma_create_pd_resp resp =3D {}; struct gdma_create_pd_req req =3D {}; + struct mana_ib_ucontext *mana_ucontext; enum gdma_pd_flags flags =3D 0; struct mana_ib_dev *dev; struct gdma_context *gc; @@ -107,6 +108,16 @@ int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_uda= ta *udata) =20 mutex_init(&pd->vport_mutex); pd->vport_use_count =3D 0; + + INIT_LIST_HEAD(&pd->ucontext_list); + if (udata) { + mana_ucontext =3D rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_add_tail(&pd->ucontext_list, &mana_ucontext->pd_list); + mutex_unlock(&mana_ucontext->lock); + } + return 0; } =20 @@ -123,6 +134,15 @@ int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_u= data *udata) dev =3D container_of(ibdev, struct mana_ib_dev, ib_dev); gc =3D mdev_to_gc(dev); =20 + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_del_init(&pd->ucontext_list); + mutex_unlock(&mana_ucontext->lock); + } + mana_gd_init_req_hdr(&req.hdr, GDMA_DESTROY_PD, sizeof(req), sizeof(resp)); =20 @@ -222,6 +242,7 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontex= t, ucontext->doorbell =3D doorbell_page; =20 mutex_init(&ucontext->lock); + INIT_LIST_HEAD(&ucontext->pd_list); =20 mutex_lock(&mdev->ucontext_lock); list_add_tail(&ucontext->dev_list, &mdev->ucontext_list); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index c7e333d3e9d8..6dba08bccc18 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -107,6 +107,7 @@ struct mana_ib_pd { =20 bool tx_shortform_allowed; u32 tx_vp_offset; + struct list_head ucontext_list; }; =20 struct mana_ib_av { @@ -203,6 +204,7 @@ struct mana_ib_ucontext { struct list_head dev_list; /* Protects resource lists below */ struct mutex lock; + struct list_head pd_list; }; =20 struct mana_ib_rwq_ind_table { --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D05CE3290B0; Sat, 7 Mar 2026 01:47:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848056; cv=none; b=gWL8W4XgJkjXJi7F0bMYNla4sJPIIXHfQ0Wltav39XUgS8VSo3FpQG9b4A85xW5GZktuwRvGxGnvUSvu+Yt5cceTt3q/A77gJYImomjA5KWeHoo1euUNjoKV2OtiDy6sFUROhUF5eg/KwW4Lmmr61g3lsRH1sIAfhSbWAUpSReg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848056; c=relaxed/simple; bh=kAYvOIBdnFKV0F/GO32JrSE3ZWQIK08o0IJ+mNwitP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WfG6jndpqOzA+/mezdcRUAWZSzqQT6+U0RabgB/314m4c99zRoPk6QNgw/1qYOp+VCHiyflSRfJ1IPuuZpL84dcVySArED7whr/DIf5ZN3A70zNY/06jHyhRnTFuQSk1r2IY2HAVvPAJoBDj8RUvIfX+DG0Q8LwoJFF+MTxBDxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id C7B1920B6F02; Fri, 6 Mar 2026 17:47:34 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C7B1920B6F02 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 3/8] RDMA/mana_ib: Track CQ per ucontext Date: Fri, 6 Mar 2026 17:47:17 -0800 Message-ID: <20260307014723.556523-4-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add per-ucontext list tracking for CQ objects. Each CQ is added to the ucontext's cq_list on creation and removed on destruction. This enables iterating over all CQs belonging to a ucontext for service reset cleanup. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/cq.c | 19 +++++++++++++++++++ drivers/infiniband/hw/mana/main.c | 1 + drivers/infiniband/hw/mana/mana_ib.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/c= q.c index b2749f971cd0..89cf60987ff5 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -95,6 +95,16 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct i= b_cq_init_attr *attr, INIT_LIST_HEAD(&cq->list_send_qp); INIT_LIST_HEAD(&cq->list_recv_qp); =20 + INIT_LIST_HEAD(&cq->ucontext_list); + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_add_tail(&cq->ucontext_list, &mana_ucontext->cq_list); + mutex_unlock(&mana_ucontext->lock); + } + return 0; =20 err_remove_cq_cb: @@ -115,6 +125,15 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_u= data *udata) =20 mdev =3D container_of(ibdev, struct mana_ib_dev, ib_dev); =20 + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_del_init(&cq->ucontext_list); + mutex_unlock(&mana_ucontext->lock); + } + mana_ib_remove_cq_cb(mdev, cq); =20 /* Ignore return code as there is not much we can do about it. diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index 62d89ca06ba1..214c1d4e1548 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -243,6 +243,7 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontex= t, =20 mutex_init(&ucontext->lock); INIT_LIST_HEAD(&ucontext->pd_list); + INIT_LIST_HEAD(&ucontext->cq_list); =20 mutex_lock(&mdev->ucontext_lock); list_add_tail(&ucontext->dev_list, &mdev->ucontext_list); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index 6dba08bccc18..8d3edf7ba335 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -150,6 +150,7 @@ struct mana_ib_cq { int cqe; u32 comp_vector; mana_handle_t cq_handle; + struct list_head ucontext_list; }; =20 enum mana_rc_queue_type { @@ -205,6 +206,7 @@ struct mana_ib_ucontext { /* Protects resource lists below */ struct mutex lock; struct list_head pd_list; + struct list_head cq_list; }; =20 struct mana_ib_rwq_ind_table { --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80FD43290AD; Sat, 7 Mar 2026 01:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848056; cv=none; b=TsHeFp83YDsKaKUIL2X3DzIPhY+7SNWbP8GGHapRiBZYtt0MZo5ymPnI/sPm6pyu/S6C6zoYn2/QOSpyKSecwquXMibJ+Lareu6HIudi1VND0JcbQIW9gnatdOlS+OAeHlslRhASijqKZ53h2u5MMpI7Ba5DmpPzrBLvZzXdFTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848056; c=relaxed/simple; bh=oTxIDqoEbl50fBrLylQx52l11EfdexSnz/F5QBFSeqY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EKGS3G5xezPsKeJVCKzYO9l2sxeJ5szAgYFj0GpqfX/6cWRd0EpRfT8v3bGmx5ZSf+gVMH2WBWVADJbukucveeIgoUZPadxfkV2c2pXc9Sj40OPHHUt9lYgjDjka3prMnHSP9LHopYbD9YYTUL/Frqxpjvw+ZHw1uh7PF8DlS2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 60EBD20B6F03; Fri, 6 Mar 2026 17:47:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 60EBD20B6F03 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 4/8] RDMA/mana_ib: Track WQ per ucontext Date: Fri, 6 Mar 2026 17:47:18 -0800 Message-ID: <20260307014723.556523-5-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add per-ucontext list tracking for WQ objects. Each WQ is added to the ucontext's wq_list on creation and removed on destruction. This enables iterating over all WQs belonging to a ucontext for service reset cleanup. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/main.c | 1 + drivers/infiniband/hw/mana/mana_ib.h | 2 ++ drivers/infiniband/hw/mana/wq.c | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index 214c1d4e1548..e6da5c8400f4 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -244,6 +244,7 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontex= t, mutex_init(&ucontext->lock); INIT_LIST_HEAD(&ucontext->pd_list); INIT_LIST_HEAD(&ucontext->cq_list); + INIT_LIST_HEAD(&ucontext->wq_list); =20 mutex_lock(&mdev->ucontext_lock); list_add_tail(&ucontext->dev_list, &mdev->ucontext_list); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index 8d3edf7ba335..96b5a13470ae 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -94,6 +94,7 @@ struct mana_ib_wq { int wqe; u32 wq_buf_size; mana_handle_t rx_object; + struct list_head ucontext_list; }; =20 struct mana_ib_pd { @@ -207,6 +208,7 @@ struct mana_ib_ucontext { struct mutex lock; struct list_head pd_list; struct list_head cq_list; + struct list_head wq_list; }; =20 struct mana_ib_rwq_ind_table { diff --git a/drivers/infiniband/hw/mana/wq.c b/drivers/infiniband/hw/mana/w= q.c index 6206244f762e..1af9869933aa 100644 --- a/drivers/infiniband/hw/mana/wq.c +++ b/drivers/infiniband/hw/mana/wq.c @@ -41,6 +41,17 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, wq->wqe =3D init_attr->max_wr; wq->wq_buf_size =3D ucmd.wq_buf_size; wq->rx_object =3D INVALID_MANA_HANDLE; + + INIT_LIST_HEAD(&wq->ucontext_list); + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_add_tail(&wq->ucontext_list, &mana_ucontext->wq_list); + mutex_unlock(&mana_ucontext->lock); + } + return &wq->ibwq; =20 err_free_wq: @@ -64,6 +75,15 @@ int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_uda= ta *udata) =20 mdev =3D container_of(ib_dev, struct mana_ib_dev, ib_dev); =20 + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_del_init(&wq->ucontext_list); + mutex_unlock(&mana_ucontext->lock); + } + mana_ib_destroy_queue(mdev, &wq->queue); =20 kfree(wq); --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECB1D322A3F; Sat, 7 Mar 2026 01:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848057; cv=none; b=Bv316MteF5GAqzX2tDw74+dY9yPoZiDMFjzbAHEQLYcpld0rnjy+dgVn6Cyu1Jveq7tf3/EphgHE+381ddrFVb8yH7Vspsb6ZT1HCa6/t5KeZZDT7f0DAK7hxKOXy5/4krlFCwcsjE552ojmx+fiOH5YKcp68cUxL2WhbDqBK6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848057; c=relaxed/simple; bh=+E6tUNVLg6Z07+L3m8UPDVdE0xwQVknhfinpmyWAJ40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L1Epg0hLW3SnbVCLZXaNhb7wfJeEzS3URzF4Q9H+PUN3KM2jNv5JenDEVN/O9hh2+QWdJYfdn+vZPvODalSoHXX91WJaFCgqrOl3Zq4r/jZd3zwPnU172RrwEwGhpGk6a+ZUWDq/um+MxmKZVkDwxc7nWHwzj0twpkdWofn2tBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id E08DA20B6F07; Fri, 6 Mar 2026 17:47:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E08DA20B6F07 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 5/8] RDMA/mana_ib: Track QP per ucontext Date: Fri, 6 Mar 2026 17:47:19 -0800 Message-ID: <20260307014723.556523-6-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add per-ucontext list tracking for QP objects. Only RAW_PACKET QPs are tracked since they persist across reset events. RC, UD and GSI QPs are removed and re-added during reset by IB core and do not need tracking. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/main.c | 1 + drivers/infiniband/hw/mana/mana_ib.h | 2 ++ drivers/infiniband/hw/mana/qp.c | 47 ++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index e6da5c8400f4..c6a859628ba3 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -244,6 +244,7 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontex= t, mutex_init(&ucontext->lock); INIT_LIST_HEAD(&ucontext->pd_list); INIT_LIST_HEAD(&ucontext->cq_list); + INIT_LIST_HEAD(&ucontext->qp_list); INIT_LIST_HEAD(&ucontext->wq_list); =20 mutex_lock(&mdev->ucontext_lock); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index 96b5a13470ae..9d90fda2c830 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -198,6 +198,7 @@ struct mana_ib_qp { =20 refcount_t refcount; struct completion free; + struct list_head ucontext_list; }; =20 struct mana_ib_ucontext { @@ -208,6 +209,7 @@ struct mana_ib_ucontext { struct mutex lock; struct list_head pd_list; struct list_head cq_list; + struct list_head qp_list; struct list_head wq_list; }; =20 diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/q= p.c index 82f84f7ad37a..315bc54d8ae6 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -700,14 +700,31 @@ static int mana_ib_create_ud_qp(struct ib_qp *ibqp, s= truct ib_pd *ibpd, int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr, struct ib_udata *udata) { + struct mana_ib_qp *qp =3D container_of(ibqp, struct mana_ib_qp, ibqp); + int err; + + INIT_LIST_HEAD(&qp->ucontext_list); + switch (attr->qp_type) { case IB_QPT_RAW_PACKET: /* When rwq_ind_tbl is used, it's for creating WQs for RSS */ if (attr->rwq_ind_tbl) - return mana_ib_create_qp_rss(ibqp, ibqp->pd, attr, - udata); + err =3D mana_ib_create_qp_rss(ibqp, ibqp->pd, attr, + udata); + else + err =3D mana_ib_create_qp_raw(ibqp, ibqp->pd, attr, + udata); + + if (!err && udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_add_tail(&qp->ucontext_list, &mana_ucontext->qp_list); + mutex_unlock(&mana_ucontext->lock); + } =20 - return mana_ib_create_qp_raw(ibqp, ibqp->pd, attr, udata); + return err; case IB_QPT_RC: return mana_ib_create_rc_qp(ibqp, ibqp->pd, attr, udata); case IB_QPT_UD: @@ -716,9 +733,8 @@ int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_= init_attr *attr, default: ibdev_dbg(ibqp->device, "Creating QP type %u not supported\n", attr->qp_type); + return -EINVAL; } - - return -EINVAL; } =20 static int mana_ib_gd_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *att= r, @@ -898,14 +914,26 @@ static int mana_ib_destroy_ud_qp(struct mana_ib_qp *q= p, struct ib_udata *udata) int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) { struct mana_ib_qp *qp =3D container_of(ibqp, struct mana_ib_qp, ibqp); + int ret =3D -ENOENT; =20 switch (ibqp->qp_type) { case IB_QPT_RAW_PACKET: + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_del_init(&qp->ucontext_list); + mutex_unlock(&mana_ucontext->lock); + } + if (ibqp->rwq_ind_tbl) - return mana_ib_destroy_qp_rss(qp, ibqp->rwq_ind_tbl, - udata); + ret =3D mana_ib_destroy_qp_rss(qp, ibqp->rwq_ind_tbl, + udata); + else + ret =3D mana_ib_destroy_qp_raw(qp, udata); =20 - return mana_ib_destroy_qp_raw(qp, udata); + return ret; case IB_QPT_RC: return mana_ib_destroy_rc_qp(qp, udata); case IB_QPT_UD: @@ -914,7 +942,6 @@ int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_ud= ata *udata) default: ibdev_dbg(ibqp->device, "Unexpected QP type %u\n", ibqp->qp_type); + return ret; } - - return -ENOENT; } --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FEEA32ED24; Sat, 7 Mar 2026 01:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848057; cv=none; b=PrhhtwVgewbx1PtPfes8WZlp/lMln5n3oU4E3jMtgzZFRh9eJCV2f0lgHm5FSK65Im6VMvuOp4SCSoMFyyH4kTXv3AENLCGQyZCW0oWNIC9q4INXktSk3NkKwFQdqyDwmBQnLPX77AFNnLbmCFthTTSr7U0SWwbO1kZsprmTNz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848057; c=relaxed/simple; bh=B1kAd7tzvvgelixw6i3I30H8twYG1KH2iOY+Hc+q92c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=op3LgEQ/YPVVY4H5PCV6wT4FcSTpvI5FYycNV3+Ni73ppVw0FSplyfFfcM13AL0ecnEj9yzfJUQ5bIiTj1eEwKRPue/Z0eI3A3iYhESOjVfvFPelfIxssMqZu7dCOLMeryYZV8vNZQsmM6XqKMOnB7nYlMbb7b5YpuGPHbkkgnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 62CDA20B6F02; Fri, 6 Mar 2026 17:47:36 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 62CDA20B6F02 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 6/8] RDMA/mana_ib: Track MR per ucontext Date: Fri, 6 Mar 2026 17:47:20 -0800 Message-ID: <20260307014723.556523-7-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add per-ucontext list tracking for MR objects. Each MR is added to the ucontext's mr_list on creation and removed on destruction. This enables iterating over all MRs belonging to a ucontext for service reset cleanup. Also export mana_ib_gd_destroy_mr() for use by reset cleanup code. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/main.c | 1 + drivers/infiniband/hw/mana/mana_ib.h | 3 +++ drivers/infiniband/hw/mana/mr.c | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index c6a859628ba3..f739e6da5435 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -243,6 +243,7 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontex= t, =20 mutex_init(&ucontext->lock); INIT_LIST_HEAD(&ucontext->pd_list); + INIT_LIST_HEAD(&ucontext->mr_list); INIT_LIST_HEAD(&ucontext->cq_list); INIT_LIST_HEAD(&ucontext->qp_list); INIT_LIST_HEAD(&ucontext->wq_list); diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index 9d90fda2c830..ce5c6c030fb2 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -134,6 +134,7 @@ struct mana_ib_mr { struct ib_mr ibmr; struct ib_umem *umem; mana_handle_t mr_handle; + struct list_head ucontext_list; }; =20 struct mana_ib_dm { @@ -208,6 +209,7 @@ struct mana_ib_ucontext { /* Protects resource lists below */ struct mutex lock; struct list_head pd_list; + struct list_head mr_list; struct list_head cq_list; struct list_head qp_list; struct list_head wq_list; @@ -665,6 +667,7 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64= start, u64 length, struct ib_udata *udata); =20 int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata); +int mana_ib_gd_destroy_mr(struct mana_ib_dev *dev, u64 mr_handle); =20 int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_at= tr, struct ib_udata *udata); diff --git a/drivers/infiniband/hw/mana/mr.c b/drivers/infiniband/hw/mana/m= r.c index 9613b225dad4..559bb4f7c31d 100644 --- a/drivers/infiniband/hw/mana/mr.c +++ b/drivers/infiniband/hw/mana/mr.c @@ -87,7 +87,7 @@ static int mana_ib_gd_create_mr(struct mana_ib_dev *dev, = struct mana_ib_mr *mr, return 0; } =20 -static int mana_ib_gd_destroy_mr(struct mana_ib_dev *dev, u64 mr_handle) +int mana_ib_gd_destroy_mr(struct mana_ib_dev *dev, u64 mr_handle) { struct gdma_destroy_mr_response resp =3D {}; struct gdma_destroy_mr_request req =3D {}; @@ -185,6 +185,16 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, = u64 start, u64 length, * as part of the lifecycle of this MR. */ =20 + INIT_LIST_HEAD(&mr->ucontext_list); + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_add_tail(&mr->ucontext_list, &mana_ucontext->mr_list); + mutex_unlock(&mana_ucontext->lock); + } + return &mr->ibmr; =20 err_dma_region: @@ -313,6 +323,15 @@ int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_uda= ta *udata) =20 dev =3D container_of(ibdev, struct mana_ib_dev, ib_dev); =20 + if (udata) { + struct mana_ib_ucontext *mana_ucontext =3D + rdma_udata_to_drv_context(udata, + struct mana_ib_ucontext, ibucontext); + mutex_lock(&mana_ucontext->lock); + list_del_init(&mr->ucontext_list); + mutex_unlock(&mana_ucontext->lock); + } + err =3D mana_ib_gd_destroy_mr(dev, mr->mr_handle); if (err) return err; --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 020F7331221; Sat, 7 Mar 2026 01:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848059; cv=none; b=pf9EDA8NebGWcNg7x5jzAZxRETc6DhpzIAwkZUzEJZtg8+u+QJCxrevU4Gjev4GNISHWseE+ARI8IDm5VAoFqhSQiR8Cawvn5ps+/Cg3fiDg2dwiBv4K/sMopxBrPhTO9baMu3asnxMI/tazh4mB4mo3PHLCrsihPVmtF6HY220= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848059; c=relaxed/simple; bh=pWYTHJCNKqq1+GiUUCUl5igXga4xOTfXNYFerUaA9k4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ulvOslDfpXPU+MmPZK6hzLTXDJLpB/ftZhkzRa4KtgIVrFZ0+tpaMjoZ98smfdGe+/jfOMaGEEoy3+ceNREwfmRBkOCph4g0IF1EOTIx6PHe1Giq8sEkPauTBy/8p6r7/sfHldAl9aJsLKHTLhkTltQhRQQtcDdzR2ijOo/LO7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id D1B5620B6F05; Fri, 6 Mar 2026 17:47:36 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D1B5620B6F05 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 7/8] RDMA/mana_ib: Notify service reset events to RDMA devices Date: Fri, 6 Mar 2026 17:47:21 -0800 Message-ID: <20260307014723.556523-8-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Register reset_notify and resume_notify callbacks so the RDMA driver is informed when the MANA service undergoes a reset cycle. On reset notification: - Acquire reset_rwsem write lock to serialize with resource creation - Walk every tracked ucontext and invalidate firmware handles for all PD, CQ, WQ, QP, and MR resources (set to INVALID_MANA_HANDLE) - Dispatch IB_EVENT_PORT_ERR to each affected ucontext so userspace (e.g. DPDK) learns about the reset On resume notification: - Release reset_rwsem write lock, unblocking new resource creation Resource creation paths (alloc_pd, create_cq, create_wq, create_qp for RAW_PACKET, reg_user_mr) acquire reset_rwsem read lock to ensure handles are not invalidated while being set up. Signed-off-by: Long Li --- drivers/infiniband/hw/mana/cq.c | 15 ++- drivers/infiniband/hw/mana/device.c | 103 ++++++++++++++++++ drivers/infiniband/hw/mana/main.c | 9 ++ drivers/infiniband/hw/mana/mana_ib.h | 2 + drivers/infiniband/hw/mana/mr.c | 4 + drivers/infiniband/hw/mana/qp.c | 5 + drivers/infiniband/hw/mana/wq.c | 4 + drivers/net/ethernet/microsoft/mana/mana_en.c | 14 ++- include/net/mana/gdma.h | 6 + 9 files changed, 155 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/c= q.c index 89cf60987ff5..b054684b8de7 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -41,13 +41,17 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct = ib_cq_init_attr *attr, ibdev_dbg(ibdev, "CQE %d exceeding limit\n", attr->cqe); return -EINVAL; } + } + + down_read(&mdev->reset_rwsem); =20 + if (udata) { cq->cqe =3D attr->cqe; err =3D mana_ib_create_queue(mdev, ucmd.buf_addr, cq->cqe * COMP_ENTRY_S= IZE, &cq->queue); if (err) { ibdev_dbg(ibdev, "Failed to create queue for create cq, %d\n", err); - return err; + goto err_unlock; } =20 mana_ucontext =3D rdma_udata_to_drv_context(udata, struct mana_ib_uconte= xt, @@ -56,14 +60,15 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct = ib_cq_init_attr *attr, } else { if (attr->cqe > U32_MAX / COMP_ENTRY_SIZE / 2 + 1) { ibdev_dbg(ibdev, "CQE %d exceeding limit\n", attr->cqe); - return -EINVAL; + err =3D -EINVAL; + goto err_unlock; } buf_size =3D MANA_PAGE_ALIGN(roundup_pow_of_two(attr->cqe * COMP_ENTRY_S= IZE)); cq->cqe =3D buf_size / COMP_ENTRY_SIZE; err =3D mana_ib_create_kernel_queue(mdev, buf_size, GDMA_CQ, &cq->queue); if (err) { ibdev_dbg(ibdev, "Failed to create kernel queue for create cq, %d\n", e= rr); - return err; + goto err_unlock; } doorbell =3D mdev->gdma_dev->doorbell; } @@ -105,6 +110,7 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct = ib_cq_init_attr *attr, mutex_unlock(&mana_ucontext->lock); } =20 + up_read(&mdev->reset_rwsem); return 0; =20 err_remove_cq_cb: @@ -113,7 +119,8 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct = ib_cq_init_attr *attr, mana_ib_gd_destroy_cq(mdev, cq); err_destroy_queue: mana_ib_destroy_queue(mdev, &cq->queue); - +err_unlock: + up_read(&mdev->reset_rwsem); return err; } =20 diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/ma= na/device.c index 149e8d4d5b8e..081be31563ca 100644 --- a/drivers/infiniband/hw/mana/device.c +++ b/drivers/infiniband/hw/mana/device.c @@ -103,6 +103,7 @@ static int mana_ib_netdev_event(struct notifier_block *= this, netdev_put(ndev, &dev->dev_tracker); =20 return NOTIFY_OK; + default: return NOTIFY_DONE; } @@ -110,6 +111,93 @@ static int mana_ib_netdev_event(struct notifier_block = *this, return NOTIFY_DONE; } =20 +/* + * Reset cleanup: invalidate firmware handles for all tracked user objects. + * + * Called during service reset BEFORE dispatching IB_EVENT_PORT_ERR to + * user-mode. + * + * Only invalidates FW handles =E2=80=94 does NOT free kernel resources (u= mem, queues) + * or remove objects from lists. The IB core's destroy callbacks handle fu= ll + * resource teardown when user-space closes the uverbs FD or ib_unregister= _device + * is called. The destroy callbacks skip FW commands when the handle is al= ready + * INVALID_MANA_HANDLE. + * + * For CQs, also removes the CQ callback to prevent stale completions. + */ +static void mana_ib_reset_notify(void *ctx) +{ + struct mana_ib_dev *mdev =3D ctx; + struct mana_ib_ucontext *uctx; + struct mana_ib_qp *qp; + struct mana_ib_wq *wq; + struct mana_ib_cq *cq; + struct mana_ib_mr *mr; + struct mana_ib_pd *pd; + struct ib_event ibev; + int i; + + down_write(&mdev->reset_rwsem); + + ibdev_dbg(&mdev->ib_dev, "reset cleanup starting\n"); + + mutex_lock(&mdev->ucontext_lock); + list_for_each_entry(uctx, &mdev->ucontext_list, dev_list) { + mutex_lock(&uctx->lock); + + list_for_each_entry(qp, &uctx->qp_list, ucontext_list) + qp->qp_handle =3D INVALID_MANA_HANDLE; + + list_for_each_entry(wq, &uctx->wq_list, ucontext_list) + wq->rx_object =3D INVALID_MANA_HANDLE; + + list_for_each_entry(cq, &uctx->cq_list, ucontext_list) { + mana_ib_remove_cq_cb(mdev, cq); + cq->cq_handle =3D INVALID_MANA_HANDLE; + } + + list_for_each_entry(mr, &uctx->mr_list, ucontext_list) + mr->mr_handle =3D INVALID_MANA_HANDLE; + + list_for_each_entry(pd, &uctx->pd_list, ucontext_list) + pd->pd_handle =3D INVALID_MANA_HANDLE; + + uctx->doorbell =3D INVALID_DOORBELL; + + mutex_unlock(&uctx->lock); + } + mutex_unlock(&mdev->ucontext_lock); + + up_write(&mdev->reset_rwsem); + + /* Revoke user doorbell mappings so userspace cannot ring + * stale doorbells after firmware handles are invalidated. + */ + rdma_user_mmap_disassociate(&mdev->ib_dev); + + /* Notify userspace (e.g. DPDK) that the port is down */ + for (i =3D 0; i < mdev->ib_dev.phys_port_cnt; i++) { + ibev.device =3D &mdev->ib_dev; + ibev.element.port_num =3D i + 1; + ibev.event =3D IB_EVENT_PORT_ERR; + ib_dispatch_event(&ibev); + } +} + +static void mana_ib_resume_notify(void *ctx) +{ + struct mana_ib_dev *dev =3D ctx; + struct ib_event ibev; + int i; + + for (i =3D 0; i < dev->ib_dev.phys_port_cnt; i++) { + ibev.device =3D &dev->ib_dev; + ibev.element.port_num =3D i + 1; + ibev.event =3D IB_EVENT_PORT_ACTIVE; + ib_dispatch_event(&ibev); + } +} + static int mana_ib_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) { @@ -134,6 +222,7 @@ static int mana_ib_probe(struct auxiliary_device *adev, xa_init_flags(&dev->qp_table_wq, XA_FLAGS_LOCK_IRQ); mutex_init(&dev->ucontext_lock); INIT_LIST_HEAD(&dev->ucontext_list); + init_rwsem(&dev->reset_rwsem); =20 if (mana_ib_is_rnic(dev)) { dev->ib_dev.phys_port_cnt =3D 1; @@ -216,6 +305,15 @@ static int mana_ib_probe(struct auxiliary_device *adev, =20 dev_set_drvdata(&adev->dev, dev); =20 + /* ETH device persists across reset =E2=80=94 use callback for cleanup. + * RNIC device is removed/re-added, so its cleanup happens in remove. + */ + if (!mana_ib_is_rnic(dev)) { + mdev->reset_notify =3D mana_ib_reset_notify; + mdev->resume_notify =3D mana_ib_resume_notify; + mdev->reset_notify_ctx =3D dev; + } + return 0; =20 deallocate_pool: @@ -242,6 +340,11 @@ static void mana_ib_remove(struct auxiliary_device *ad= ev) if (mana_ib_is_rnic(dev)) mana_drain_gsi_sqs(dev); =20 + if (!mana_ib_is_rnic(dev)) { + dev->gdma_dev->reset_notify =3D NULL; + dev->gdma_dev->resume_notify =3D NULL; + dev->gdma_dev->reset_notify_ctx =3D NULL; + } ib_unregister_device(&dev->ib_dev); dma_pool_destroy(dev->av_pool); if (mana_ib_is_rnic(dev)) { diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index f739e6da5435..61ce30aa9cb2 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -81,6 +81,8 @@ int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata = *udata) dev =3D container_of(ibdev, struct mana_ib_dev, ib_dev); gc =3D mdev_to_gc(dev); =20 + down_read(&dev->reset_rwsem); + mana_gd_init_req_hdr(&req.hdr, GDMA_CREATE_PD, sizeof(req), sizeof(resp)); =20 @@ -98,6 +100,7 @@ int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata= *udata) if (!err) err =3D -EPROTO; =20 + up_read(&dev->reset_rwsem); return err; } =20 @@ -118,6 +121,7 @@ int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udat= a *udata) mutex_unlock(&mana_ucontext->lock); } =20 + up_read(&dev->reset_rwsem); return 0; } =20 @@ -230,10 +234,13 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcont= ext, mdev =3D container_of(ibdev, struct mana_ib_dev, ib_dev); gc =3D mdev_to_gc(mdev); =20 + down_read(&mdev->reset_rwsem); + /* Allocate a doorbell page index */ ret =3D mana_gd_allocate_doorbell_page(gc, &doorbell_page); if (ret) { ibdev_dbg(ibdev, "Failed to allocate doorbell page %d\n", ret); + up_read(&mdev->reset_rwsem); return ret; } =20 @@ -252,6 +259,8 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontex= t, list_add_tail(&ucontext->dev_list, &mdev->ucontext_list); mutex_unlock(&mdev->ucontext_lock); =20 + up_read(&mdev->reset_rwsem); + return 0; } =20 diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/m= ana/mana_ib.h index ce5c6c030fb2..29201cf3274c 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -86,6 +86,8 @@ struct mana_ib_dev { /* Protects ucontext_list */ struct mutex ucontext_lock; struct list_head ucontext_list; + /* Serializes resource create callbacks vs reset cleanup */ + struct rw_semaphore reset_rwsem; }; =20 struct mana_ib_wq { diff --git a/drivers/infiniband/hw/mana/mr.c b/drivers/infiniband/hw/mana/m= r.c index 559bb4f7c31d..7189ccd41576 100644 --- a/drivers/infiniband/hw/mana/mr.c +++ b/drivers/infiniband/hw/mana/mr.c @@ -141,6 +141,8 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u= 64 start, u64 length, if (!mr) return ERR_PTR(-ENOMEM); =20 + down_read(&dev->reset_rwsem); + mr->umem =3D ib_umem_get(ibdev, start, length, access_flags); if (IS_ERR(mr->umem)) { err =3D PTR_ERR(mr->umem); @@ -195,6 +197,7 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u= 64 start, u64 length, mutex_unlock(&mana_ucontext->lock); } =20 + up_read(&dev->reset_rwsem); return &mr->ibmr; =20 err_dma_region: @@ -204,6 +207,7 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u= 64 start, u64 length, ib_umem_release(mr->umem); =20 err_free: + up_read(&dev->reset_rwsem); kfree(mr); return ERR_PTR(err); } diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/q= p.c index 315bc54d8ae6..d590aca9b93a 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -701,12 +701,16 @@ int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_q= p_init_attr *attr, struct ib_udata *udata) { struct mana_ib_qp *qp =3D container_of(ibqp, struct mana_ib_qp, ibqp); + struct mana_ib_dev *mdev =3D + container_of(ibqp->device, struct mana_ib_dev, ib_dev); int err; =20 INIT_LIST_HEAD(&qp->ucontext_list); =20 switch (attr->qp_type) { case IB_QPT_RAW_PACKET: + down_read(&mdev->reset_rwsem); + /* When rwq_ind_tbl is used, it's for creating WQs for RSS */ if (attr->rwq_ind_tbl) err =3D mana_ib_create_qp_rss(ibqp, ibqp->pd, attr, @@ -724,6 +728,7 @@ int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_= init_attr *attr, mutex_unlock(&mana_ucontext->lock); } =20 + up_read(&mdev->reset_rwsem); return err; case IB_QPT_RC: return mana_ib_create_rc_qp(ibqp, ibqp->pd, attr, udata); diff --git a/drivers/infiniband/hw/mana/wq.c b/drivers/infiniband/hw/mana/w= q.c index 1af9869933aa..67b757cf30f9 100644 --- a/drivers/infiniband/hw/mana/wq.c +++ b/drivers/infiniband/hw/mana/wq.c @@ -31,6 +31,8 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, =20 ibdev_dbg(&mdev->ib_dev, "ucmd wq_buf_addr 0x%llx\n", ucmd.wq_buf_addr); =20 + down_read(&mdev->reset_rwsem); + err =3D mana_ib_create_queue(mdev, ucmd.wq_buf_addr, ucmd.wq_buf_size, &w= q->queue); if (err) { ibdev_dbg(&mdev->ib_dev, @@ -52,9 +54,11 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, mutex_unlock(&mana_ucontext->lock); } =20 + up_read(&mdev->reset_rwsem); return &wq->ibwq; =20 err_free_wq: + up_read(&mdev->reset_rwsem); kfree(wq); =20 return ERR_PTR(err); diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/et= hernet/microsoft/mana/mana_en.c index ea71de39f996..3493b36426f7 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -3659,15 +3659,19 @@ int mana_probe(struct gdma_dev *gd, bool resuming) } } =20 - err =3D add_adev(gd, "eth"); + if (!resuming) + err =3D add_adev(gd, "eth"); =20 INIT_DELAYED_WORK(&ac->gf_stats_work, mana_gf_stats_work_handler); schedule_delayed_work(&ac->gf_stats_work, MANA_GF_STATS_PERIOD); - out: if (err) { mana_remove(gd, false); } else { + /* Notify IB layer that ports are back up after reset */ + if (resuming && gd->resume_notify) + gd->resume_notify(gd->reset_notify_ctx); + dev_dbg(dev, "gd=3D%p, id=3D%u, num_ports=3D%d, type=3D%u, instance=3D%u= \n", gd, gd->dev_id.as_uint32, ac->num_ports, gd->dev_id.type, gd->dev_id.instance); @@ -3691,9 +3695,13 @@ void mana_remove(struct gdma_dev *gd, bool suspendin= g) cancel_delayed_work_sync(&ac->gf_stats_work); =20 /* adev currently doesn't support suspending, always remove it */ - if (gd->adev) + if (gd->adev && !suspending) remove_adev(gd); =20 + /* Notify IB layer before tearing down net devices during reset */ + if (suspending && gd->reset_notify) + gd->reset_notify(gd->reset_notify_ctx); + for (i =3D 0; i < ac->num_ports; i++) { ndev =3D ac->ports[i]; if (!ndev) { diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index ec17004b10c0..9187c5b4d0d1 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -249,6 +249,12 @@ struct gdma_dev { struct auxiliary_device *adev; bool is_suspended; bool rdma_teardown; + + /* Called by mana_remove() during reset to notify IB layer */ + void (*reset_notify)(void *ctx); + /* Called by mana_probe() during resume to notify IB layer */ + void (*resume_notify)(void *ctx); + void *reset_notify_ctx; }; =20 /* MANA_PAGE_SIZE is the DMA unit */ --=20 2.43.0 From nobody Thu Apr 9 15:39:38 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BE0A332612; Sat, 7 Mar 2026 01:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848059; cv=none; b=RWgLn1RKtmkCIk/9ehKq6BGp4g0UH+vEiCAXxFtQRSzKlUI+ZdLgDyO6rSkHqhpk3Q1dLh1p7v+HEKTDFXsUFzVt9xjhrtSrg/PIHhJ13JVp3sJL2o2TDci+PWAjYU7ZV1myKN0wxolJ8atq5x6tS0a4rbpxldCagZBXAPnsUxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772848059; c=relaxed/simple; bh=xcDte7rRDknX365WIhKJshHQ92tBG5T6BHy4SirFks8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h5LjRD7HdT0C3az84AGlS4Y5uT2gqpoBpYPT/DF10uqwjs/DEWGJpmRPfOh+KRoN/yJC2v0Xh9pYWgfVEmHETijmG8sGD+fFfdawgDfZcmExwHhQRQCRfoiu4voC3l4cL+nqLiGuQSlVs0VFd2lpU3+pfbWsPG51t2Xi9hKtIK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1202) id 7DFE020B6F03; Fri, 6 Mar 2026 17:47:37 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7DFE020B6F03 From: Long Li To: Long Li , Konstantin Taranov , Jakub Kicinski , "David S . Miller" , Paolo Abeni , Eric Dumazet , Andrew Lunn , Jason Gunthorpe , Leon Romanovsky , Haiyang Zhang , "K . Y . Srinivasan" , Wei Liu , Dexuan Cui Cc: Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next 8/8] RDMA/mana_ib: Skip firmware commands for invalidated handles Date: Fri, 6 Mar 2026 17:47:22 -0800 Message-ID: <20260307014723.556523-9-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260307014723.556523-1-longli@microsoft.com> References: <20260307014723.556523-1-longli@microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After a service reset, firmware handles for PD, CQ, WQ, QP, and MR are set to INVALID_MANA_HANDLE by the reset notification path. Check for INVALID_MANA_HANDLE in each destroy callback before issuing firmware destroy commands. When a handle is invalid, skip the firmware call and proceed directly to kernel resource cleanup (umem, queues, memory). This avoids sending stale handles to firmware after reset. Affected callbacks: - mana_ib_dealloc_pd: skip mana_ib_gd_destroy_pd - mana_ib_destroy_cq: skip mana_ib_gd_destroy_cq and queue destroy - mana_ib_destroy_wq: skip mana_ib_destroy_queue - mana_ib_destroy_qp_rss: skip mana_destroy_wq_obj per WQ - mana_ib_destroy_qp_raw: skip mana_destroy_wq_obj - mana_ib_dereg_mr: skip mana_ib_gd_destroy_mr Signed-off-by: Long Li --- drivers/infiniband/hw/mana/cq.c | 10 ++++++---- drivers/infiniband/hw/mana/main.c | 12 +++++++++--- drivers/infiniband/hw/mana/mr.c | 8 +++++--- drivers/infiniband/hw/mana/qp.c | 9 ++++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/c= q.c index b054684b8de7..315301bccb97 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -143,10 +143,12 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_= udata *udata) =20 mana_ib_remove_cq_cb(mdev, cq); =20 - /* Ignore return code as there is not much we can do about it. - * The error message is printed inside. - */ - mana_ib_gd_destroy_cq(mdev, cq); + if (cq->cq_handle !=3D INVALID_MANA_HANDLE) { + /* Ignore return code as there is not much we can do about it. + * The error message is printed inside. + */ + mana_ib_gd_destroy_cq(mdev, cq); + } =20 mana_ib_destroy_queue(mdev, &cq->queue); =20 diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana= /main.c index 61ce30aa9cb2..d60205184dba 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -147,6 +147,9 @@ int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_ud= ata *udata) mutex_unlock(&mana_ucontext->lock); } =20 + if (pd->pd_handle =3D=3D INVALID_MANA_HANDLE) + return 0; + mana_gd_init_req_hdr(&req.hdr, GDMA_DESTROY_PD, sizeof(req), sizeof(resp)); =20 @@ -280,9 +283,12 @@ void mana_ib_dealloc_ucontext(struct ib_ucontext *ibco= ntext) list_del_init(&mana_ucontext->dev_list); mutex_unlock(&mdev->ucontext_lock); =20 - ret =3D mana_gd_destroy_doorbell_page(gc, mana_ucontext->doorbell); - if (ret) - ibdev_dbg(ibdev, "Failed to destroy doorbell page %d\n", ret); + if (mana_ucontext->doorbell !=3D INVALID_DOORBELL) { + ret =3D mana_gd_destroy_doorbell_page(gc, mana_ucontext->doorbell); + if (ret) + ibdev_dbg(ibdev, "Failed to destroy doorbell page %d\n", + ret); + } } =20 int mana_ib_create_kernel_queue(struct mana_ib_dev *mdev, u32 size, enum g= dma_queue_type type, diff --git a/drivers/infiniband/hw/mana/mr.c b/drivers/infiniband/hw/mana/m= r.c index 7189ccd41576..75bc2a9c366a 100644 --- a/drivers/infiniband/hw/mana/mr.c +++ b/drivers/infiniband/hw/mana/mr.c @@ -336,9 +336,11 @@ int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_uda= ta *udata) mutex_unlock(&mana_ucontext->lock); } =20 - err =3D mana_ib_gd_destroy_mr(dev, mr->mr_handle); - if (err) - return err; + if (mr->mr_handle !=3D INVALID_MANA_HANDLE) { + err =3D mana_ib_gd_destroy_mr(dev, mr->mr_handle); + if (err) + return err; + } =20 if (mr->umem) ib_umem_release(mr->umem); diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/q= p.c index d590aca9b93a..76d59addb645 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -846,9 +846,11 @@ static int mana_ib_destroy_qp_rss(struct mana_ib_qp *q= p, for (i =3D 0; i < (1 << ind_tbl->log_ind_tbl_size); i++) { ibwq =3D ind_tbl->ind_tbl[i]; wq =3D container_of(ibwq, struct mana_ib_wq, ibwq); - ibdev_dbg(&mdev->ib_dev, "destroying wq->rx_object %llu\n", + ibdev_dbg(&mdev->ib_dev, + "destroying wq->rx_object %llu\n", wq->rx_object); - mana_destroy_wq_obj(mpc, GDMA_RQ, wq->rx_object); + if (wq->rx_object !=3D INVALID_MANA_HANDLE) + mana_destroy_wq_obj(mpc, GDMA_RQ, wq->rx_object); } =20 return 0; @@ -867,7 +869,8 @@ static int mana_ib_destroy_qp_raw(struct mana_ib_qp *qp= , struct ib_udata *udata) mpc =3D netdev_priv(ndev); pd =3D container_of(ibpd, struct mana_ib_pd, ibpd); =20 - mana_destroy_wq_obj(mpc, GDMA_SQ, qp->qp_handle); + if (qp->qp_handle !=3D INVALID_MANA_HANDLE) + mana_destroy_wq_obj(mpc, GDMA_SQ, qp->qp_handle); =20 mana_ib_destroy_queue(mdev, &qp->raw_sq); =20 --=20 2.43.0