From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796163039; b=xrcjBwhm9oZd7hzGf8HTPtabFd48Wb/HieLB2wwOopytkE2WR/4VNfo7Rb/8ZRq+Qz9v 25qwN3XOjXB8mPE1OxzoxCSfvY6kJgYKAP8cfBhtQX4KsQc7k9eWyCZyfMiITCm24BhqS fhWhEzmoVn9w5jWyFIZcAtJEbbcbAehAcPvPgSoTlRfqnQK0O++/EkenMAF9X7/l4+DIp ortpaH7pOugQuZ9V8MGkvT9K7XwbeY030Th8xxcxy1HHJ8cAGZAkZuPpW6eNib+gOKqyS jZwjm1LwN8lmkx8ypskZNthnfHPApUecgQfEL3i7tt4JbqNy3J6TXd+eg+7BKMFgVWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796163039; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=b9Fu4j6A48KdRdm4YVk4to9wbs8nsvuLry6T+lINWLc=; b=haZ3n/LQN75NHSSAzTNegpOCsUhxWwCMd/VNGGPFLIzfDE6YQaI0gxvfPSFUmLrAelMb 85XHKVfm26G3jI9B5poTD//W7C403jLCjxEDXFdaQp5C/kmd8dQhomr3olaHFWxJRumhJ i+3hVzBIyDBLEEXaAQm1hQ5I48UDIvyxyEk5x8Vdvyin35syKpJ+HqgJj8fsDUys3ObnL FYxMO3JQz4JCqvsYve4MbJrGg86lFzUINT6B/Z+yL89oN5SqY/dpCRX/bYnfLBnZUMXro /HRLxqBRMGlE518+HVK5axpDabtOBOdhXhmGZ3fv421+lWCHwEXMN0W9qO62+VpRlZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mMqHBetB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52A8F606A320 for ; Tue, 1 Dec 2026 22:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mMqHBetB Received: by smtp.kernel.org (Postfix) with ESMTPSA id E743A1F000C1; Tue, 1 Dec 2026 22:10:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796163039; bh=b9Fu4j6A48KdRdm4YVk4to9wbs8nsvuLry6T+lINWLc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=mMqHBetB6FNSlRH953YADNIrGbbr1jl/vq3WxBhJEHgIz5b0Cagtti3wztfAwQroq tDAw/mezn8UZTk6TuJgRNEFV/2RVaa8retQSXizIT7G/JR2KMxVCrmkfKgW4goGopA 9UBnQ8avCvbj89IQtXyL2PNySjvZag2t9TlzZ5zOq/ilyosKBFa0S7ezKHm4P2NOeh Zx4ggrVBtgtDPdc4Fs8Bg0BGryw1oGd+fm/CSGVu7ox4jRzx2LcU+SXETzHjDK/v3w gj+dqppJfpCW5JKOQ+dPFFZow6lRC+SBsiQqA90vy2WWM/WW5YF3u8eTTMIJYulzlv XrpQFsHuUn4kw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 1/3] cxgb4: support the enable_rdma devlink param in runtime cmode Reply-To: sashiko-reviews@lists.linux.dev To: "Stefan Metzmacher" Cc: linux-rdma@vger.kernel.org In-Reply-To: <2532e7d175c698b77b7a733641608eed83d07f90.1796076486.git.metze@samba.org> References: <2532e7d175c698b77b7a733641608eed83d07f90.1796076486.git.metze@samba.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 22:10:38 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] cxgb4: implicit declaration of module_refcount() when !CONFIG_MODULE_UNLOAD - [Medium] cxgb4: race with c4iw_exit_module() in cxgb4_uld_set_rdma() without module pin - [Medium] cxgb4: NULL uld_info.owner when built-in bypasses cxgb4_uld_set_rdma() check - [Medium] cxgb4: struct uld_ctx memory leak across cxgb4_uld_set_rdma() toggle cycles It also noticed 1 related pre-existing issue this patch does not introduce: - [Critical] cxgb4: resource leak in setup_sge_queues_uld() [1] -- commit 5d2fd6080d0c69d62f374ea901aaa5147340d6f5 Author: Stefan Metzmacher cxgb4: support the enable_rdma devlink param in runtime cmode This commit registers a devlink instance for offload-capable cxgb4 adapters and implements the generic enable_rdma parameter in runtime mode to attach = or detach the iw_cxgb4 RDMA upper layer driver per adapter. > diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c b/drivers/net= /ethernet/chelsio/cxgb4/cxgb4_uld.c > index 23244cdfc1bc6..f66899b4f9322 100644 > --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c > +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c > @@ -732,6 +732,8 @@ static void cxgb4_uld_alloc_resources(struct adapter = *adap, > return; > if (type =3D=3D CXGB4_ULD_ISCSIT && is_t4(adap->params.chip)) > return; > + if (type =3D=3D CXGB4_ULD_RDMA && adap->rdma_disabled) > + return; > ret =3D cfg_queues_uld(adap, type, p); > if (ret) > goto out; [Severity: Critical] This problem wasn't introduced by this patch, but in cxgb4_uld_alloc_resources() [1], when setup_sge_queues_uld() fails it jumps to free_queues instead of free_rxq: drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c:setup_sge_queues_uld() { ... ret =3D alloc_uld_rxqs(adap, rxq_info, lro); if (ret) return ret; /* Tell uP to route control queue completions to rdma rspq */ if (adap->flags & CXGB4_FULL_INIT_DONE && uld_type =3D=3D CXGB4_ULD_RDMA) { ... for_each_port(adap, i) { ... ret =3D t4_set_params(adap, adap->mbox, adap->pf, 0, 1, ¶m, &cmplqid); } } return ret; } If t4_set_params() fails after alloc_uld_rxqs() has allocated the hardware RX queues, jumping to free_queues skips free_sge_queues_uld() and frees only the software structures via free_queues_uld(), leaking the ULD RX queues and leaving active hardware DMA rings pointing to freed memory. > @@ -771,6 +773,78 @@ static void cxgb4_uld_alloc_resources(struct adapter= *adap, > "ULD registration failed for uld type %d\n", type); > } > =20 > +/** > + * cxgb4_uld_set_rdma - detach or attach the RDMA ULD of an adapter > + * @adap: the adapter > + * @enable: attach (true) or detach (false) the RDMA ULD > + * > + * Detaching has the same effect as unloading iw_cxgb4, but only for > + * this adapter, the netdevs stay. While detached, loading iw_cxgb4 > + * doesn't attach it to this adapter. If iw_cxgb4 isn't loaded, > + * attaching only allows it to attach once it's loaded. Used for the > + * enable_rdma devlink param. > + * > + * iw_cxgb4 doesn't support disassociating user contexts, so detaching > + * waits in ib_unregister_device() until all user space applications > + * closed the RDMA device, while holding uld_mutex. So detaching is > + * refused with -EBUSY while iw_cxgb4 is in use, like unloading it. The > + * module refcount covers the RDMA devices of all adapters, so an > + * application using the RDMA device of another adapter also makes > + * detaching fail. An application opening the device right after that > + * check still makes detaching wait until it's closed. > + */ > +int cxgb4_uld_set_rdma(struct adapter *adap, bool enable) > +{ > + struct cxgb4_uld_list *uld_entry; > + int ret =3D 0; > + > + if (!is_offload(adap)) > + return -EOPNOTSUPP; > + > + mutex_lock(&uld_mutex); > + if (adap->flags & CXGB4_SHUTTING_DOWN) { > + ret =3D -ESHUTDOWN; > + goto out; > + } > + if (adap->rdma_disabled =3D=3D !enable) > + goto out; > + > + if (!enable && adap->uld[CXGB4_ULD_RDMA].handle) { > + list_for_each_entry(uld_entry, &uld_list, list_node) { > + struct module *owner =3D uld_entry->uld_info.owner; > + > + if (uld_entry->uld_type =3D=3D CXGB4_ULD_RDMA && > + owner && module_refcount(owner) > 0) { > + ret =3D -EBUSY; > + goto out; > + } > + } > + } [Severity: High] Does calling module_refcount() here break the build when CONFIG_MODULE_UNLOAD is disabled? In include/linux/module.h, module_refcount() is only declared under CONFIG_MODULE_UNLOAD, with no stub for !CONFIG_MODULE_UNLOAD or !CONFIG_MODULES, and CONFIG_CHELSIO_T4 does not depend on MODULE_UNLOAD. [Severity: Medium] What happens when CONFIG_INFINIBAND_CXGB4=3Dy is built into the kernel? When iw_cxgb4 is built-in, THIS_MODULE is NULL, so owner is NULL and this check is skipped. Disabling enable_rdma while user-space RDMA contexts are open then proceeds into state_change(CXGB4_STATE_DETACH) -> c4iw_remove() -> ib_unregister_device() and blocks until all applications close the device while holding uld_mutex and the devlink instance lock. [Severity: Medium] Can cxgb4_uld_set_rdma() race with c4iw_exit_module() during iw_cxgb4 module unload because owner is never pinned with try_module_get()? drivers/infiniband/hw/cxgb4/device.c:c4iw_exit_module() { mutex_lock(&dev_mutex); list_for_each_entry_safe(ctx, tmp, &uld_ctx_list, entry) { if (ctx->dev) c4iw_remove(ctx); kfree(ctx); } mutex_unlock(&dev_mutex); destroy_workqueue(reg_workq); cxgb4_unregister_uld(CXGB4_ULD_RDMA); } During delete_module(), try_stop_module() decrements the module refcount so module_refcount(owner) becomes -1 before c4iw_exit_module() runs, and c4iw_exit_module() tears down all uld_ctx entries and reg_workq before cxgb4_unregister_uld() acquires uld_mutex: CPU0 CPU1 delete_module() try_stop_module() /* module_refcount() is now -1 */ c4iw_exit_module() mutex_lock(&dev_mutex) cxgb4_uld_set_rdma(adap, false) mutex_lock(&uld_mutex) module_refcount(owner) > 0 /* false */ state_change(ctx, CXGB4_STATE_DETACH) c4iw_remove(ctx) c4iw_remove(ctx) kfree(ctx) <-- concurrent c4iw_remove() and use-after-free Similarly, on the enable path, if cxgb4_uld_set_rdma(adap, true) runs after c4iw_exit_module() has destroyed reg_workq but before cxgb4_unregister_uld() acquires uld_mutex, uld_attach() allocates a new ctx and queues reg_work onto the destroyed workqueue. Taking a module reference with try_module_get(owner) under uld_mutex (and releasing it with module_put() after detaching or attaching) would prevent c4iw_exit_module() from running concurrently. > + adap->rdma_disabled =3D !enable; > + > + if (!enable) { > + if (adap->uld[CXGB4_ULD_RDMA].handle) > + adap->uld[CXGB4_ULD_RDMA].state_change(adap->uld[CXGB4_ULD_RDMA].hand= le, > + CXGB4_STATE_DETACH); > + cxgb4_shutdown_uld_adapter(adap, CXGB4_ULD_RDMA); > + goto out; > + } > + > + list_for_each_entry(uld_entry, &uld_list, list_node) { > + if (uld_entry->uld_type !=3D CXGB4_ULD_RDMA) > + continue; > + cxgb4_uld_alloc_resources(adap, CXGB4_ULD_RDMA, > + &uld_entry->uld_info); > + if (!adap->uld[CXGB4_ULD_RDMA].handle) { > + adap->rdma_disabled =3D true; > + ret =3D -EIO; > + } > + } [Severity: Medium] Does toggling enable_rdma off and back on leak a struct uld_ctx on every cycle? On disable, c4iw_uld_state_change(CXGB4_STATE_DETACH) destroys ctx->dev via c4iw_remove(ctx) but leaves ctx allocated on uld_ctx_list, while cxgb4_shutdown_uld_adapter() frees rxq_info->rspq_id (leaving ctx->lldi.rxq_ids and ciq_ids dangling) and clears adap->uld[CXGB4_ULD_RDMA].handle. On re-enable, cxgb4_uld_alloc_resources() -> uld_attach() -> c4iw_uld_add() allocates and links a new struct uld_ctx onto uld_ctx_list without freeing or reusing the detached one. As noted in the commit message, avoiding this leak requires the companion iw_cxgb4 change; since this commit already touches drivers/infiniband/hw/cxgb4/devic= e.c, should that fix be included before or together with this change so bisection and trees without the separate patch do not leak memory on each toggle? [1] https://sashiko.dev/#/bug/linux-000bf912-26b7-4dd2-95b7-a98a4da8e793 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796076486.gi= t.metze@samba.org?part=3D1