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=1796061679; b=JPjaZwSf3E0+Is6A16v8BEzbH/0m4CQDOlRzGnoFYVm6IihnoxHNaeT/HIfbY8Ch9B9j xzKY5DbGB/UVsylfarrCxDPk258PxCWDVSFBJkeQmri/Vyo/AwbUNQg/Vz78wV2gmIq7s dpbA3/zZTIyWUC3/Ujfz6SBIESU27bk6Qyl2mNCnNtcSjMsQFud7q4JxKARwgKYcF1GW6 JnS9NRusdnELCz//OxvJlVuZZluickjfBWbImLdIhu+xpLVqUpRuCM1oRSpbcfXCRUwcP yw+Udt7u0GLR7C59xiMfvWEPjnR8CHdinfZu6fS8464jHbwVylaaiVayb4NDCf/LbdA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796061679; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Ne11QPUEw90MeuG6YSUlBU4vFvnjJ9h/pZrbx20N/eI=; b=QTv6aglwSXJfeV6Ww485YscLHGdO/hrPPWncwWr6fPElT5R5aQ277bjZ1LZdmpGEd5ZE 8x6pbSPzjKtkIACeSvsAegeZxR76+XpEoaZG6FBJfGNnNE+8N46Ajd1vFuC7UibYq5/px GgSQ7X6M1f8x/ueNtMLv/Pf2ct01jhPflwNBLR4D+pZUn9/c4rlsAjvF4llDrDYlEJYBM mm8UkoLR3Cyc/i5Hg7REFzCb9jbnSWiCytDLDm1sKh1ejsbwyNOPIvsz5OHjrLItkiDhx N0+vgTlsi1E+FtzTwySImpRkUzHl7PlfDglvxn/AEx0Wl4/+HMO1DXwgpVemePwFiuA== 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=Cr6edBEu; 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 504E6606A31C for ; Mon, 30 Nov 2026 18:01:19 +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=Cr6edBEu Received: by smtp.kernel.org (Postfix) with ESMTPSA id B175F1F0089B; Mon, 30 Nov 2026 18:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796061678; bh=Ne11QPUEw90MeuG6YSUlBU4vFvnjJ9h/pZrbx20N/eI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Cr6edBEuS56ddihgpF0N5zvr6idqrGTh8ql2T/gduYaePXu8lCReJCMuPPzCq+i1C 3s6lpLeTNCNeB+gz+rarzrtQlYzfZFR6B/OopytUDOE3W/q6iuc9bQs+x1/Kaftez0 6C831DNHWibyZjHhrbcr5JY5rrvNn5RCwvRCEmqNYR2kV2jFkrBNQrnNU4ae9mAqb4 fJNXW/rEN8h8eB6RV008pp4+uFb8mlTXm3n6apRUq2j+VUfJDW/rKy1o+edIMY6Inw IVf1TPLuUlzdQkulCmjqsIQE9h7Cjh+lXvM3Heh/vPbzQv7ozY//mbSC8riFUiP4eG q7xRC9wuclitw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH RFC 2/2] usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed Reply-To: sashiko-reviews@lists.linux.dev To: "Krishna Kurapati" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261130-dynamic-icc-voting-v1-2-1a05a5320adc@oss.qualcomm.com> References: <20261130-dynamic-icc-voting-v1-0-1a05a5320adc@oss.qualcomm.com> <20261130-dynamic-icc-voting-v1-2-1a05a5320adc@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 18:01:18 +0000 X-Mailing-List: linux-usb@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 5 potential issues to consider: - [High] usb: dwc3: qcom: link failure when CONFIG_USB or CONFIG_USB_XHCI_HCD is disabled - [High] usb: dwc3: qcom: use-after-free of host_nb on dwc3_qcom_probe() error paths - [Medium] usb: dwc3: qcom: USB_DEVICE_REMOVE votes SuperSpeed DDR bw in dwc3_qcom_host_notifier() - [Medium] usb: dwc3: qcom: broken host_nb lifecycle and DDR bw restoration on role switch - [Medium] usb: dwc3: qcom: host_nb teardown race and leak in dwc3_qcom_remove() -- commit ce9731ed7069be9723645845ce1017e310a2280b Author: Krishna Kurapati usb: dwc3: qcom: Vote ICC DDR bandwidth based on connected device speed This commit registers a USB bus notifier in host mode to vote DDR interconnect bandwidth according to whether a SuperSpeed device is connected to the DWC3 root hub. > diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c > index 52ec7a0709ef4..fdec21b304206 100644 > --- a/drivers/usb/dwc3/dwc3-qcom.c > +++ b/drivers/usb/dwc3/dwc3-qcom.c > @@ -21,6 +21,9 @@ > #include > #include "core.h" > #include "glue.h" > +#include "../host/xhci.h" > +#include "../host/xhci-port.h" > +#include "../host/xhci-caps.h" [ ... ] > @@ -597,6 +601,74 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qco= m, struct platform_device *p > return 0; > } > =20 > +static bool dwc3_qcom_is_ss_rhport_connected(struct dwc3_qcom *qcom) > +{ > + struct dwc3 *dwc =3D &qcom->dwc; > + struct xhci_hcd *xhci; > + struct usb_hcd *hcd; > + unsigned int i; > + u32 portsc; > + > + if (!dwc->xhci) > + return false; > + > + hcd =3D platform_get_drvdata(dwc->xhci); > + xhci =3D hcd_to_xhci(hcd); > + > + for (i =3D 0; i < xhci->usb3_rhub.num_ports; i++) { > + portsc =3D xhci_portsc_readl(xhci->usb3_rhub.ports[i]); > + if ((portsc & PORT_CONNECT) && DEV_SUPERSPEED_ANY(portsc)) > + return true; > + } > + > + return false; > +} [Severity: High] Does this break linking when CONFIG_USB or CONFIG_USB_XHCI_HCD is disabled, or when CONFIG_USB_DWC3_QCOM is built-in with modular USB/xHCI? CONFIG_USB_DWC3_QCOM can be built for gadget-only configurations (notice the CONFIG_USB guard in dwc3_qcom_read_usb2_speed()). usb_register_notify(), usb_unregister_notify(), and usb_hcd_is_primary_hcd() (via hcd_to_xhci()) have no stubs when CONFIG_USB is disabled, and xhci_portsc_readl() has no stub when CONFIG_USB_XHCI_HCD is disabled. Also, ../host/xhci-caps.h does not appear to be used in this file. > + > +static int dwc3_qcom_host_notifier(struct notifier_block *nb, > + unsigned long event, void *ptr) > +{ > + struct dwc3_qcom *qcom =3D container_of(nb, struct dwc3_qcom, host_nb); > + struct dwc3 *dwc =3D &qcom->dwc; > + struct usb_device *udev =3D ptr; > + struct usb_bus *ubus =3D ptr; > + > + if (!dwc || !dwc->xhci) > + return NOTIFY_DONE; > + > + if (event =3D=3D USB_DEVICE_ADD || event =3D=3D USB_DEVICE_REMOVE) > + ubus =3D udev->bus; > + > + if (strcmp(dev_name(ubus->sysdev), dev_name(dwc->sysdev)) !=3D 0) > + return NOTIFY_DONE; > + > + if (event !=3D USB_DEVICE_ADD && event !=3D USB_DEVICE_REMOVE) > + return NOTIFY_DONE; > + > + /* > + * For direct-attach devices, new udev is direct child of root hub > + * i.e. dwc -> xhci -> root_hub -> udev > + * root_hub's udev->parent=3D=3DNULL, so traverse struct device hierarc= hy > + */ > + if (udev->parent && !udev->parent->parent && > + udev->dev.parent->parent =3D=3D &dwc->xhci->dev) { > + if (event =3D=3D USB_DEVICE_ADD) { > + if (!dwc3_qcom_is_ss_rhport_connected(qcom)) { > + dwc3_qcom_interconnect_set_ddr_bw(qcom, > + USB_SPEED_HIGH); > + > + } else { > + dwc3_qcom_interconnect_set_ddr_bw(qcom, > + USB_SPEED_SUPER); > + } > + } else { > + dwc3_qcom_interconnect_set_ddr_bw(qcom, > + USB_SPEED_UNKNOWN); > + } > + } > + > + return NOTIFY_DONE; > +} [Severity: Medium] Does passing USB_SPEED_UNKNOWN on USB_DEVICE_REMOVE raise the DDR bandwidth vote back to SuperSpeed instead of dropping it? drivers/usb/dwc3/dwc3-qcom.c:dwc3_qcom_interconnect_set_ddr_bw() { if (max_speed >=3D USB_SPEED_SUPER || max_speed =3D=3D USB_SPEED_UNKNOWN) ret =3D icc_set_bw(qcom->icc_path_ddr, USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); else ret =3D icc_set_bw(qcom->icc_path_ddr, USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); } Unplugging a Full-Speed or High-Speed device therefore votes SuperSpeed DDR bandwidth while the bus is idle, including on controllers restricted to maximum-speed =3D "high-speed" in Devicetree. On multi-port controllers or when a USB 3.x hub disconnects one of its companion root-hub children, this also overwrites the bandwidth vote without checking the remaining root-hub ports. > + > static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role = next_role) > { > struct dwc3_qcom *qcom =3D to_dwc3_qcom(dwc); > @@ -617,6 +689,13 @@ static void dwc3_qcom_set_role_notifier(struct dwc3 = *dwc, enum usb_role next_rol > pm_runtime_mark_last_busy(qcom->dev); > pm_runtime_put_sync(qcom->dev); > =20 > + if (next_role =3D=3D USB_ROLE_HOST) { > + qcom->host_nb.notifier_call =3D dwc3_qcom_host_notifier; > + usb_register_notify(&qcom->host_nb); > + } else if (qcom->current_role =3D=3D USB_ROLE_HOST) { > + usb_unregister_notify(&qcom->host_nb); > + } > + > /* > * Current role changes via usb_role_switch_set_role callback protected > * internally by mutex lock. > @@ -749,8 +828,12 @@ static int dwc3_qcom_probe(struct platform_device *p= dev) [Severity: Medium] When switching out of USB_ROLE_HOST after a Full/High-Speed host session, does unregistering qcom->host_nb here leave the DDR bandwidth vote stuck at USB_SPEED_HIGH for subsequent SuperSpeed device mode? dwc3_qcom_set_role_notifier() runs as the .pre_set_role callback before dwc3_set_mode() queues dwc->drd_work to run dwc3_host_exit(), so qcom->host_nb is already unregistered when the root-hub devices are removed and nothing restores qcom->icc_path_ddr to usb_get_maximum_speed(dwc->dev). In addition, when dwc3_usb_role_switch_set() receives USB_ROLE_NONE with role_switch_default_mode =3D=3D USB_DR_MODE_HOST, it keeps the controller in DWC3_GCTL_PRTCAP_HOST mode but passes USB_ROLE_NONE to dwc3_pre_set_role(), which unregisters qcom->host_nb while still in host mode. Conversely, on extcon OTG controllers booting with a host cable attached, dwc3_qcom_probe() sets qcom->current_role =3D USB_ROLE_DEVICE and dwc3_drd_init() -> dwc3_drd_update() enters host mode without calling dwc3_pre_set_role(), so qcom->host_nb is never registered. > qcom->current_role =3D USB_ROLE_DEVICE; > } > =20 > - qcom->dwc.glue_ops =3D &dwc3_qcom_glue_ops; > + if (qcom->current_role =3D=3D USB_ROLE_HOST) { > + qcom->host_nb.notifier_call =3D dwc3_qcom_host_notifier; > + usb_register_notify(&qcom->host_nb); > + } > =20 > + qcom->dwc.glue_ops =3D &dwc3_qcom_glue_ops; > qcom->dwc.dev =3D dev; > probe_data.dwc =3D &qcom->dwc; > probe_data.res =3D &res; [Severity: High] If dwc3_core_probe() or dwc3_qcom_interconnect_init() fails (for example with -EPROBE_DEFER), does dwc3_qcom_probe() return without unregistering qcom->host_nb? Because qcom is allocated with devm_kzalloc_obj(), probe failure frees qcom while qcom->host_nb remains linked in usb_notifier_list, causing a use-after-free on the next USB bus notification or probe retry. Moreover, registering the notifier before dwc3_qcom_interconnect_init() means any notification during dwc3_core_probe() or its remove_core error unwind can call dwc3_qcom_interconnect_set_ddr_bw() while qcom->icc_path_ddr is NULL, an ERR_PTR, or already released via icc_put(). > @@ -789,6 +872,9 @@ static void dwc3_qcom_remove(struct platform_device *= pdev) > if (pm_runtime_resume_and_get(qcom->dev) < 0) > return; > =20 > + if (qcom->current_role =3D=3D USB_ROLE_HOST) > + usb_unregister_notify(&qcom->host_nb); > + > dwc3_core_remove(&qcom->dwc); > clk_bulk_disable_unprepare(qcom->num_clocks, qcom->clks); > dwc3_qcom_interconnect_exit(qcom); [Severity: Medium] Can qcom->host_nb remain registered in usb_notifier_list after dwc3_qcom_remove() returns? If pm_runtime_resume_and_get() fails, dwc3_qcom_remove() returns early before usb_unregister_notify(&qcom->host_nb), and devm then frees qcom. Even when runtime resume succeeds, dwc->role_sw and dwc->edev are not unregistered until dwc3_core_remove() -> dwc3_core_exit_mode() -> dwc3_drd_exit(), so a concurrent dwc3_qcom_set_role_notifier() can run between usb_unregister_notify() and dwc3_core_remove() (or skip updating qcom->current_role if its own pm_runtime_resume_and_get() fails) and leave qcom->host_nb registered after qcom is freed. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-dynamic-ic= c-voting-v1-0-1a05a5320adc@oss.qualcomm.com?part=3D2