From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54A2E36B93B for ; Mon, 31 Aug 2026 16:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788194559; cv=none; b=FzWc/yZWQIAXY04FJhji6z+oWyrs918czwu04ynGMRifppDk2gDJgfGCK/7oLwhH3Jh/qJsTZvUSP8Dn7PnzNkwpjY8ftFBy7URfaHK245oddh8DbPG+iMFnvZZPEPd9elWVRUyaIJ4LstksW7VG/YJpxxKQIpSW/IRuePIR3H4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788194559; c=relaxed/simple; bh=6WOlm8OsLfGwDK5bh1FMwvRz+Ma8FdcYnNlpQc+pLac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bu9xai1PaFpqMWR4vZjL5dciXzP7F6UTPDpBaTmMrMHUZbrNrKKVBahJ3vDf/+VjVyjJBo+SVg4rcUyX0JNt/BfXLdpzg5m3WnUF40JBqNPdSzGOX9TLXvwlnFglFKJHZ5NIf0AVmW9uudNJIoDqoaj3dQkDjdur95m1S2dc8zc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oYZv35nA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oYZv35nA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71BED1F00A3E; Mon, 31 Aug 2026 16:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788194558; bh=DZdZmUDadWTvWRxsdPghLt45GwWahNScFZu1PpwuF14=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oYZv35nAq2gNjgsPKF36hNzc4UVZC/mc0csQzyquca9pKjxAOzl8VrqoIC/z3tKkF Lkgw1oanPOuSLovTL3sMqRRUASxQdRigv8Sb2++jj5zbUf4IhGjJwbuWH1/jFEayty ggMrFMbGHZ6SYIiZ3x9vg31LdBX/Ry9O54BGtv8xSslg7/Jvq/3YFN/b9gd0PMeK5J 0eHCe3vYYhIS7FlcViIOvMJI2x0VNe97V+lxjt+OiZQxVV2AO+eyEt7hJhtAOx0Cq/ 5lDgBT0DclUaadOl+JSO1944DIvdL9gE2EaUR1xvmjE2ZWmnGngASxSy7ZIeJ3PRmk 3CEYJ/IjOmDMQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Breno Leitao , Mathias Nyman , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.12.y 4/4] usb: xhci: bail out of setup if the controller is inaccessible Date: Mon, 31 Aug 2026 12:42:33 -0400 Message-ID: <20260831164233.269066-4-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260831164233.269066-1-sashal@kernel.org> References: <2026083120-autism-gerbil-efbb@gregkh> <20260831164233.269066-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Breno Leitao [ Upstream commit 78203d5b54a40f0e36196ebf31c9c7a380fc8811 ] xhci_gen_setup() locates the operational registers using the capability length read from the very first register: xhci->op_regs = hcd->regs + HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); If the controller is dead or has dropped off the bus, that read returns ~0, HC_LENGTH() truncates it to 0xff, and op_regs ends up 0xff bytes past the page-aligned MMIO base, i.e. unaligned. The first access through it, xhci_halt() -> xhci_handshake() reading op_regs->status, is then an unaligned readl() on device memory. arm64 faults on unaligned device accesses, so instead of xhci_handshake() catching the all-ones value and returning -ENODEV, setup oopses: xhci-pci-renesas 0005:08:00.0: Unable to change power state from D3cold to D0, device inaccessible xhci-pci-renesas 0005:08:00.0: xHCI Host Controller xhci-pci-renesas 0005:08:00.0: new USB bus registered, assigned bus number 1 Unable to handle kernel paging request at virtual address ffff80030a770103 ESR = 0x0000000096000021 FSC = 0x21: alignment fault Internal error: Oops: 0000000096000021 [#1] SMP pc : xhci_halt [xhci_hcd] Call trace: xhci_halt xhci_gen_setup xhci_pci_setup usb_add_hcd usb_hcd_pci_probe xhci_pci_common_probe xhci_pci_renesas_probe This was hit with a Renesas uPD720201 that failed to power up ("Unable to change power state from D3cold to D0, device inaccessible") yet still reached the HCD probe path. Read the capability register once, and if it reads back the all-ones value (as xhci_handshake() and xhci_reset() already test for), abort setup with -ENODEV before op_regs is derived from it. Reading it once also avoids re-reading a register that may change under a concurrent hot-removal. Fixes: 66d4eadd8d06 ("USB: xhci: BIOS handoff and HW initialization.") Cc: stable@vger.kernel.org Signed-off-by: Breno Leitao Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20260806142113.2436238-11-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 1c414b89b099c..ac80a0e363ee6 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5225,6 +5225,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) struct device *dev = hcd->self.sysdev; int retval; u32 hcs_params1; + u32 hc_capbase; /* Accept arbitrarily long scatter-gather lists */ hcd->self.sg_tablesize = ~0; @@ -5245,15 +5246,19 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) mutex_init(&xhci->mutex); xhci->main_hcd = hcd; xhci->cap_regs = hcd->regs; - xhci->op_regs = hcd->regs + - HC_LENGTH(readl(&xhci->cap_regs->hc_capbase)); + hc_capbase = readl(&xhci->cap_regs->hc_capbase); + if (hc_capbase == U32_MAX) { + xhci_warn(xhci, "Host controller not accessible, removed?\n"); + return -ENODEV; + } + xhci->op_regs = hcd->regs + HC_LENGTH(hc_capbase); xhci->run_regs = hcd->regs + (readl(&xhci->cap_regs->run_regs_off) & RTSOFF_MASK); /* Cache read-only capability registers */ hcs_params1 = readl(&xhci->cap_regs->hcs_params1); xhci->hcs_params2 = readl(&xhci->cap_regs->hcs_params2); xhci->hcs_params3 = readl(&xhci->cap_regs->hcs_params3); - xhci->hci_version = HC_VERSION(readl(&xhci->cap_regs->hc_capbase)); + xhci->hci_version = HC_VERSION(hc_capbase); xhci->hcc_params = readl(&xhci->cap_regs->hcc_params); if (xhci->hci_version > 0x100) xhci->hcc_params2 = readl(&xhci->cap_regs->hcc_params2); -- 2.53.0