From mboxrd@z Thu Jan 1 00:00:00 1970 From: Haggai Eran Subject: Re: [PATCHv6 2/3] IB/core: added support to use rdma cgroup controller Date: Wed, 24 Feb 2016 15:43:16 +0200 Message-ID: <56CDB374.602@mellanox.com> References: <1455966006-13774-1-git-send-email-pandit.parav@gmail.com> <1455966006-13774-3-git-send-email-pandit.parav@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1455966006-13774-3-git-send-email-pandit.parav-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Sender: cgroups-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Parav Pandit , cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org, hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org, dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, liranl-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org, sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org, jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org Cc: corbet-T1hC0tSOHrs@public.gmane.org, james.l.morris-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org, serge-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org, ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org, matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org, raindel-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org, akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org, linux-security-module-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-rdma@vger.kernel.org On 20/02/2016 13:00, Parav Pandit wrote: > +/** > + * ib_device_unregister_rdmacg - unregister with rdma cgroup. > + * @device: device to unregister. > + * > + * Unregister with the rdma cgroup. Should be called after > + * all the resources are deallocated, and after a stage when any > + * other resource allocation of user application cannot be done > + * for this device to avoid any leak in accounting. > + * HCA drivers should clear resource pool ops after ib stack > + * unregisters with rdma cgroup. HCA drivers don't supply their own ops in this version, right? If so, you can update the comment. > + */ > +void ib_device_unregister_rdmacg(struct ib_device *device) > +{ > + rdmacg_unregister_device(&device->cg_device); > +} > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c > index 179e813..c3bd24c 100644 > --- a/drivers/infiniband/core/device.c > +++ b/drivers/infiniband/core/device.c > @@ -352,10 +352,22 @@ int ib_register_device(struct ib_device *device, > goto out; > } > > +#ifdef CONFIG_CGROUP_RDMA > + ret = ib_device_register_rdmacg(device); > + if (ret) { > + printk(KERN_WARNING "Couldn't set up InfiniBand P_Key/GID cache\n"); You should update the error string, and I think checkpatch recommends using pr_warn(). > + ib_cache_cleanup_one(device); > + goto out; > + } > +#endif > + > ret = ib_device_register_sysfs(device, port_callback); > if (ret) { > printk(KERN_WARNING "Couldn't register device %s with driver model\n", > device->name); > +#ifdef CONFIG_CGROUP_RDMA > + ib_device_unregister_rdmacg(device); > +#endif > ib_cache_cleanup_one(device); > goto out; > } > @@ -405,6 +417,10 @@ void ib_unregister_device(struct ib_device *device) > > mutex_unlock(&device_mutex); > > +#ifdef CONFIG_CGROUP_RDMA > + ib_device_unregister_rdmacg(device); > +#endif > + > ib_device_unregister_sysfs(device); > ib_cache_cleanup_one(device); > > diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c > index 1c02dea..7c51e8a 100644 > --- a/drivers/infiniband/core/uverbs_cmd.c > +++ b/drivers/infiniband/core/uverbs_cmd.c > @@ -1777,6 +1851,12 @@ static int create_qp(struct ib_uverbs_file *file, > &qp_lock_class); > down_write(&obj->uevent.uobject.mutex); > > + pd = idr_read_pd(cmd->pd_handle, file->ucontext); > + if (!pd) { > + ret = -EINVAL; > + goto err_put; > + } > + I'm not sure I understand why you need to keep the PD here. Why don't you use the same ib_device that is used to create the QP? The same applies comment also applies to other uverbs commands. > if (cmd->qp_type == IB_QPT_XRC_TGT) { > xrcd = idr_read_xrcd(cmd->pd_handle, file->ucontext, > &xrcd_uobj); > @@ -1811,8 +1891,7 @@ static int create_qp(struct ib_uverbs_file *file, > > scq = idr_read_cq(cmd->send_cq_handle, file->ucontext, !!rcq); > rcq = rcq ?: scq; > - pd = idr_read_pd(cmd->pd_handle, file->ucontext); > - if (!pd || !scq) { > + if (!scq) { > ret = -EINVAL; > goto err_put; > } > @@ -1858,6 +1937,11 @@ static int create_qp(struct ib_uverbs_file *file, > goto err_put; > } > > + ret = ib_rdmacg_try_charge(&obj->uevent.uobject.cg_obj, pd->device, > + RDMA_VERB_RESOURCE_QP, 1); > + if (ret) > + goto err_put; > + > if (cmd->qp_type == IB_QPT_XRC_TGT) > qp = ib_create_qp(pd, &attr); > else > @@ -1865,7 +1949,7 @@ static int create_qp(struct ib_uverbs_file *file, > > if (IS_ERR(qp)) { > ret = PTR_ERR(qp); > - goto err_put; > + goto err_create; > } > > if (cmd->qp_type != IB_QPT_XRC_TGT) { > @@ -1940,6 +2024,10 @@ err_cb: > err_destroy: > ib_destroy_qp(qp); > > +err_create: > + ib_rdmacg_uncharge(&obj->uevent.uobject.cg_obj, device, > + RDMA_VERB_RESOURCE_QP, 1); > + > err_put: > if (xrcd) > put_xrcd_read(xrcd_uobj); > @@ -3323,6 +3441,11 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, > obj->uevent.events_reported = 0; > INIT_LIST_HEAD(&obj->uevent.event_list); > > + ret = ib_rdmacg_try_charge(&obj->uevent.uobject.cg_obj, pd->device, > + RDMA_VERB_RESOURCE_SRQ, 1); > + if (ret) > + goto err_put_cq; > + I think you need a new error label to release the PD IDR but not uncharge. > srq = pd->device->create_srq(pd, &attr, udata); > if (IS_ERR(srq)) { > ret = PTR_ERR(srq); > @@ -3387,6 +3510,8 @@ err_destroy: > ib_destroy_srq(srq); > > err_put: > + ib_rdmacg_uncharge(&obj->uevent.uobject.cg_obj, pd->device, > + RDMA_VERB_RESOURCE_SRQ, 1); > put_pd_read(pd); > > err_put_cq: Regards, Haggai From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932704AbcBXNng (ORCPT ); Wed, 24 Feb 2016 08:43:36 -0500 Received: from mail-am1on0061.outbound.protection.outlook.com ([157.56.112.61]:45531 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753666AbcBXNna (ORCPT ); Wed, 24 Feb 2016 08:43:30 -0500 Authentication-Results: spf=pass (sender IP is 193.47.165.134) smtp.mailfrom=mellanox.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=mellanox.com; Subject: Re: [PATCHv6 2/3] IB/core: added support to use rdma cgroup controller To: Parav Pandit , , , , , , , , , , , References: <1455966006-13774-1-git-send-email-pandit.parav@gmail.com> <1455966006-13774-3-git-send-email-pandit.parav@gmail.com> CC: , , , , , , , From: Haggai Eran Message-ID: <56CDB374.602@mellanox.com> Date: Wed, 24 Feb 2016 15:43:16 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1455966006-13774-3-git-send-email-pandit.parav@gmail.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.0.52.254] X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD025;1:4Ujp6eny8e/Q9kG6hfEWDeP32IAVLa/T86uxGRLs7Ljvnsz4Gd4hD+PyYzkrUkhLdXt17sR5CMNRj+hsEpBMhMjmNaKrkZOkkqY503Lk3xzYEqeLbWJQLaM4jmQY0HyjYMjxHVwrVvNb/e490liKtDZ7PoeiYjrPn2uY7vTOsOd63FIBPPpinMytx4YmltjhFyaF18ygDC2L7pMgguV/p/8yBQYLY0nn9qrXKLD/Ha1DzYNuQi5CUDBx9OSC4qU5az32tauc6alcWOfadiF2cR/0v4EF11BpvgzGLqtjRtiund4Nf7ynSsD4rcDSZBTjw0sT/+YU5NT6rvDWL+gTrGUvgJMzHPWM8j8q5UG43DAk39j1UXuCtsqsA0xprDhpM2Ki9pZ8fnu/NgsviEaGYBfgcS8TmPTk8Hkb9XboHMAExz7XUGuosZOD9ir8LDH+LWz7cU7F/oFtyAMfvTbITA== X-Forefront-Antispam-Report: CIP:193.47.165.134;CTRY:IL;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(199003)(24454002)(479174004)(189002)(586003)(6116002)(3846002)(65956001)(189998001)(1220700001)(5008740100001)(230700001)(5004730100002)(6806005)(1096002)(64126003)(2906002)(2950100001)(4001350100001)(33656002)(92566002)(5001770100001)(4326007)(77096005)(83506001)(50466002)(23746002)(36756003)(2201001)(87936001)(47776003)(106466001)(11100500001)(65806001)(50986999)(76176999)(65816999)(54356999)(86362001)(921003)(3940600001)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB1038;H:mtlcas13.mtl.com;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1038;2:3GvZzFNp2Ga2Kve/8bqig21tSkqTP44tsn37WEEU1t9oYx/iRzX5h+2nQpnWs+T8utbgBiUkeD3VdiP9rgcdV5t3REZof6qLZrLP0rNKZAn9SPvqx4yuRpmAEoVJ9KsjPsp8z4CmmmkDTPucAOBiAg==;3:zkai2vDfWDKrLDpMN/Hb6IqQCW+kr/uomPzVJuPZhYKy2p1tBOfwIIYz69uHZau9QSoAnuQtS2o4bbATEOvwl2h5nZzzIhGEqa9CEO9mMwvBUmeWAuC+RmvX27JRX4PFx9meYiuT17HB0KsCA/LnNTD/GNo2ziLFnuY7lfEdISOyZIcMwgCp/xDTqzunGM1vY3OdINNPE0lNHSXCMBblOEIJZ6JJTo0cfYGzcgLAmpB0jFM7M1cXTDTcSvgsx3A1EU6kBPSGNR52AjygX/Gz1Q==;25:BNTxrL/R9cTWRQwllCeAA4UsU5B87MaNLcDgRE7CmOVnBHCbwbH4HT6ARy7U+mUetZ1oux0L7gYYHdapSnsAr3v/Kn5g460dlcyFvJu8TMNuFyEsIhoJUN5lkQRAoaqSLizN03tK8aYqbWbtjcNdw82D0+eukb6s8+IzitkzQzUebc1+ZuDMcqh9x603XHsqCbVjj2QQcwZ0Lhae/AqDH7OCRx6DYFZa6ySdJEpsguxmMvFL48b636CRuNM/KTSfzxxDCHZC5znJlf6DOmrmjGsGw3uiVqzTbJ+EH1V0/YnKSYANXIlU4D3IY3arioUp55ZvO1cvln3C/lyEtP6vYg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(8251501001);SRVR:VI1PR05MB1038; X-MS-Office365-Filtering-Correlation-Id: a27ba010-6680-484f-45c9-08d33d207811 X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1038;20:9rjXE63760jE44MsbNCdkmJenWB66uDhkqpR3NwNOlyWdHRLkHdp/v2KxZxA7BTPA74pFrWjBjjTXUx23oF5fgNVdmeJx2IVVZY8EEvuucM9qQZVnfK4mbib9RguBnexs8HHWA6XyswxpiSF5A/KcsoKCBP+mFQH/TgR1I47xsj9htAwJUbpWiNQCrfXDPFFd1HShdh/KwXv2/eeCBIB0odttKlQkU6IgfYc5Rf3Ejd70gdDGZtWwNVnzS/dCVWmLuMJG7jaOUdhQBz1kB54CWRR261IpF7CzMc78f4bW5S9SeTZ/OssKl13oQgYBcGlOj/Jb87gu/LND49CUma1EMOWVihUUKzRzBAsf15Z7oaYepQeb76efl2eEdTFE6SGf+Bj4oZShENSkdLnkGPMSpLSjxTzY6QF/OIsUVwAypTEt5M4gxdMZ9S5oNTtK6hfpzhheXZsaysejqv4L4B9MR9yBPOWDrzNj21fHNCpnHMsj4v3OuVbVZDSvDXylkim X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(13018025)(8121501046)(13023025)(13024025)(13015025)(13017025)(3002001)(10201501046);SRVR:VI1PR05MB1038;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1038; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1038;4:4od9pjvNSQrrAaWFNglPMkZg6pH+kxsWb/HPS+Is0QufwEiKkm/R2MNQE0JzQ5C05Pbc8ImDCTP6UtgVVT5zeth5XvH526zlvc/SccnGAq5xvZxV8JSYiMgbwUzWuoxyFBDt2MfjQyM20NngH9/gmlB4mRn14CqQb1UVntg/+uGfkqftyiCig6ZfZvkNGMwjjh8q1gaPpbQx+IBu3vOxbCpbGaj3nvUUxoMIW+qp9ux2eGJbh9BJi/23BX9rBVzZorjlqGhm6PIXudIk08TS8G4L7KjrcJ26Lu3aJ15fBAyjIHX2xVhQ+RkK4CExdz5jNYDSftvyQQeTjP/iq04ToaU67vsBEFGcfTFHSXiwOtB31NSdVHYp0Bs/JpgKzMfC2HErTtneBas6d2QXYgRArBAXalZD0mOuaMLJDECRjWDFVLQ712edukT5MU3VQvDcIjbvZ+vtAxM+medlAuTgxA== X-Forefront-PRVS: 08626BE3A5 X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;VI1PR05MB1038;23:sTXjzJG4XEuTShc2PINWoMHeNdFKfa7L0UE6k?= =?Windows-1252?Q?uVq+LfJim7Yc4vylr+SAnjhCG9eDRQzEGZbfqej2HipXZFxVLHG8O9zh?= =?Windows-1252?Q?jhACvp9/jAn0oCrE4QcZCWnbyM0jq0WamZv1AsxuGAs7WcDArbPT/gxq?= =?Windows-1252?Q?9HG7vGQnzdpWvm3C44ibqFZ6uynzI3xufARGpVnSLf44sheMvPSbaLOU?= =?Windows-1252?Q?4bzBX8Ln4hgaKyYZWOsV2PNAufFFvgbZ45jSnEY+JAkHJR2kQwPxlzuY?= =?Windows-1252?Q?C5rQovrey0Sgik8lTSgr+enTwK/id+QLdm8BxRlHA3phD/LqiiKg765B?= =?Windows-1252?Q?xr5tRfnsJPht4a+C2Zcsnb+vq2po7kTFOXUKtsDqZKAuWyp+2vkmwvMG?= =?Windows-1252?Q?HvUjaCiPCiz/zmPx1vLQ5CJLA5c2ZBc9Px7fqLSGDqVP0INOK686iLAg?= =?Windows-1252?Q?5nYOHsZfbCJdwbySGli8OLfHuMJKL52xqZ0AUXnViIW1iGpwyHhViRUe?= =?Windows-1252?Q?qG1wVYRYb7MZBXgMyP20SPAj1m1vWxln1OojTsrvG22xj8s6Ae0gdVN1?= =?Windows-1252?Q?c9JA0dTx2RvjRES62ttQFkz7g2V9m0+S7WGfY3hzvcxStwcVbi4TeAK9?= =?Windows-1252?Q?2R10LkCVq8DLNmxzIV6xzIQCl+1xvUwHPizp2vU1u5X0Zy/NYuJxiXhu?= =?Windows-1252?Q?hOzV09vw6sTvAnLqo87i51UBpV9316D4S48UAAwgTs57GDbYkN4/l4kd?= =?Windows-1252?Q?wlN4nVKNJOIv1MZ51GAjRPWQF7BF0Qs0S1Upzz+99OP2TaRO2fRKmwbA?= =?Windows-1252?Q?VXyOGpavczZweVGdUUu/IzNq18WgvfhW2gKJCo/rY6sHTxv4eNEsDQ1F?= =?Windows-1252?Q?enF3FxD4GkDHgimLKG+k23/snW2Neiz077rHz6b6YNh9pQipCLcAp4W+?= =?Windows-1252?Q?RZijZCVTSvUBeEk/xJEg5OFKETNIchTEtYJNgiUzSwZjNvY0DeGOae+v?= =?Windows-1252?Q?+85+nM2RegFk9m30W5zWntA13utBpNi1KPSPZNzNZPezcnHLknxs0UBg?= =?Windows-1252?Q?rQtO9vUwrCjsiyA30DWjFmbAiKE7YYI1ODuhf79V7h/wpuyeZesmB7T5?= =?Windows-1252?Q?BsQFtcW2ZbHJbK46cSCOGjF0OK68sEpil//kyq8FfO5duQp4lw+jAWR2?= =?Windows-1252?Q?4TccAOsGJWWrpJv92Am6ENQ5Pr0CghXX+65dSjMUp1eJ8peAoq5r4tH1?= =?Windows-1252?Q?Ln8zR1pa+c56IElWg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1038;5:kBWhT9+blup8nkmhYkZzpTh0HzqmQnT5tvYhKr6Kz4F9ehLTpeMtXmLw0n3s3Waw738llhAy/pHdK6LV8tnT5kd0CVI/py7myfnG5yc9MXN46LhT86A+/+PXrJ7cbYOP80EulsrajU8suzMW9Q+Wrg==;24:y1G5GP2md9PqiyQi+nhi6QJbhOM6J8oHA9s67tw0FjHC1/7/tJZMS6mHeZfWcYUslqZ9J/+zGdYHPiELwihunU24yL+lVr9t8aRHibnJAiY= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2016 13:43:24.9833 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b;Ip=[193.47.165.134];Helo=[mtlcas13.mtl.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1038 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/02/2016 13:00, Parav Pandit wrote: > +/** > + * ib_device_unregister_rdmacg - unregister with rdma cgroup. > + * @device: device to unregister. > + * > + * Unregister with the rdma cgroup. Should be called after > + * all the resources are deallocated, and after a stage when any > + * other resource allocation of user application cannot be done > + * for this device to avoid any leak in accounting. > + * HCA drivers should clear resource pool ops after ib stack > + * unregisters with rdma cgroup. HCA drivers don't supply their own ops in this version, right? If so, you can update the comment. > + */ > +void ib_device_unregister_rdmacg(struct ib_device *device) > +{ > + rdmacg_unregister_device(&device->cg_device); > +} > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c > index 179e813..c3bd24c 100644 > --- a/drivers/infiniband/core/device.c > +++ b/drivers/infiniband/core/device.c > @@ -352,10 +352,22 @@ int ib_register_device(struct ib_device *device, > goto out; > } > > +#ifdef CONFIG_CGROUP_RDMA > + ret = ib_device_register_rdmacg(device); > + if (ret) { > + printk(KERN_WARNING "Couldn't set up InfiniBand P_Key/GID cache\n"); You should update the error string, and I think checkpatch recommends using pr_warn(). > + ib_cache_cleanup_one(device); > + goto out; > + } > +#endif > + > ret = ib_device_register_sysfs(device, port_callback); > if (ret) { > printk(KERN_WARNING "Couldn't register device %s with driver model\n", > device->name); > +#ifdef CONFIG_CGROUP_RDMA > + ib_device_unregister_rdmacg(device); > +#endif > ib_cache_cleanup_one(device); > goto out; > } > @@ -405,6 +417,10 @@ void ib_unregister_device(struct ib_device *device) > > mutex_unlock(&device_mutex); > > +#ifdef CONFIG_CGROUP_RDMA > + ib_device_unregister_rdmacg(device); > +#endif > + > ib_device_unregister_sysfs(device); > ib_cache_cleanup_one(device); > > diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c > index 1c02dea..7c51e8a 100644 > --- a/drivers/infiniband/core/uverbs_cmd.c > +++ b/drivers/infiniband/core/uverbs_cmd.c > @@ -1777,6 +1851,12 @@ static int create_qp(struct ib_uverbs_file *file, > &qp_lock_class); > down_write(&obj->uevent.uobject.mutex); > > + pd = idr_read_pd(cmd->pd_handle, file->ucontext); > + if (!pd) { > + ret = -EINVAL; > + goto err_put; > + } > + I'm not sure I understand why you need to keep the PD here. Why don't you use the same ib_device that is used to create the QP? The same applies comment also applies to other uverbs commands. > if (cmd->qp_type == IB_QPT_XRC_TGT) { > xrcd = idr_read_xrcd(cmd->pd_handle, file->ucontext, > &xrcd_uobj); > @@ -1811,8 +1891,7 @@ static int create_qp(struct ib_uverbs_file *file, > > scq = idr_read_cq(cmd->send_cq_handle, file->ucontext, !!rcq); > rcq = rcq ?: scq; > - pd = idr_read_pd(cmd->pd_handle, file->ucontext); > - if (!pd || !scq) { > + if (!scq) { > ret = -EINVAL; > goto err_put; > } > @@ -1858,6 +1937,11 @@ static int create_qp(struct ib_uverbs_file *file, > goto err_put; > } > > + ret = ib_rdmacg_try_charge(&obj->uevent.uobject.cg_obj, pd->device, > + RDMA_VERB_RESOURCE_QP, 1); > + if (ret) > + goto err_put; > + > if (cmd->qp_type == IB_QPT_XRC_TGT) > qp = ib_create_qp(pd, &attr); > else > @@ -1865,7 +1949,7 @@ static int create_qp(struct ib_uverbs_file *file, > > if (IS_ERR(qp)) { > ret = PTR_ERR(qp); > - goto err_put; > + goto err_create; > } > > if (cmd->qp_type != IB_QPT_XRC_TGT) { > @@ -1940,6 +2024,10 @@ err_cb: > err_destroy: > ib_destroy_qp(qp); > > +err_create: > + ib_rdmacg_uncharge(&obj->uevent.uobject.cg_obj, device, > + RDMA_VERB_RESOURCE_QP, 1); > + > err_put: > if (xrcd) > put_xrcd_read(xrcd_uobj); > @@ -3323,6 +3441,11 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, > obj->uevent.events_reported = 0; > INIT_LIST_HEAD(&obj->uevent.event_list); > > + ret = ib_rdmacg_try_charge(&obj->uevent.uobject.cg_obj, pd->device, > + RDMA_VERB_RESOURCE_SRQ, 1); > + if (ret) > + goto err_put_cq; > + I think you need a new error label to release the PD IDR but not uncharge. > srq = pd->device->create_srq(pd, &attr, udata); > if (IS_ERR(srq)) { > ret = PTR_ERR(srq); > @@ -3387,6 +3510,8 @@ err_destroy: > ib_destroy_srq(srq); > > err_put: > + ib_rdmacg_uncharge(&obj->uevent.uobject.cg_obj, pd->device, > + RDMA_VERB_RESOURCE_SRQ, 1); > put_pd_read(pd); > > err_put_cq: Regards, Haggai