From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECC3A301709 for ; Sun, 16 Aug 2026 20:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786910474; cv=none; b=HeU3JPsrn0oHDNuAvOTjPUjt4aDmkHZCRSmT8lhFUUeY+z1bNniC1+e0DajcXkdDnqel7gE1iqwV8VQSk2wN5NhbH1FvC9DPGOsPvumwlTD8wwoc/xEiMC7lZY0QIYWdegaVpQ+4zukwlhCLehJWNSN2QS6Xehc64SZJ9dsIatk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786910474; c=relaxed/simple; bh=78/nuNzPt4uU4JcK086ubaceGsR5Qkebr1ixbFJAhXw=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pSJfpLfU0W2eIncf66aSgHB/O5tTzSi+21G2jvE5omymmj5A14b2ogRVCtCcVMfsxw15bNOSpnqNPH/IdYSrHxVO11M1b+Dy2ErYetppuQlueuoe3MWVZvTfXRtCOJSpYQxOTNpwm6SHf59H2Sm+klmudfTaApjr3DXAP6sySd0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=phFwyrPN; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="phFwyrPN" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-c15e2dab83eso421644066b.1 for ; Sun, 16 Aug 2026 13:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786910471; x=1787515271; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=HVK0VUvQpxU/PuZtFJZXm6xx2UqmZ44Az9dSUfrFhas=; b=phFwyrPN5i95leUanjsrNN1VFamOh4v/HecdLTFDblDYcBHP4cU1vt1ad/2MZqBb4v uc1Huw4ZdMvAu16XM74a2Lmz50E5oRbQQTvgsfc4dktEzRYISl0WTK1ixMJ0zYjKiX4o cdwX12hWN9YkXuHnDSrFMuYbP+YutZ2xcnoXC++fhZxW6VxqsPsbTVvXY257bmZhbeRP S6D4egKe6DpbwrwtNN1Fueqfo/jk0ED68Jo4l3T5ZWzyHQvXks3WdAwpbZ+ClpijdtSd j3sbVQ+BgTJR6H3LTGBPZVLYgCvPo6bQerjId0ymVSOSfUQ+rmeGYPvsZxiD309Gf1Hq sFcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786910471; x=1787515271; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HVK0VUvQpxU/PuZtFJZXm6xx2UqmZ44Az9dSUfrFhas=; b=KEI3j8b0wU6jIa7X62IcK6JiyR7bwc4DeVpV9tWE8eNZG5xxgGKjF+1ZUZpBL/BIiM SRt13CDr1VYiywyJ0Xf7f7wFm4p1WsU+sucCHGIGAJUQCh1tcZ216hnhKwmbBTO5jBbn x9RfAyRNKIQ1tJCirkGTYjMKzCDWbz/IYEVcIymCkSigA6kXwlr63IZB5I/3dkbS9u1Z Ji/isiLDBKMnXL03hr9cT1cItMHHECWwEmyFCh7K0YwrHQ9DBg3DfsgZ2k0qQ52cviAx Jq93YH7ctqtdErgyJLDYAs6rGMFmqLOvQy5290FiXF3I99Db4Q2tdNqLN5NzgbTjAo8X w6Xg== X-Forwarded-Encrypted: i=1; AHgh+RpQ+6O8CUv+hPC2P+cy6BU+k3OZXr+Bwko3GkIKB4CnBaoOZIa47x/DoL4DKZt3/7bP/vj4+h7VYnMCFcU=@vger.kernel.org X-Gm-Message-State: AOJu0YxgZD740qwNTUJUMv24HJ61Rk3Ep4hYiLnJwaj4q/esnqAwer6l E106SqnJJBEB+EIIdOCVeuvnyXI8aytUXcp70Q1Gsmn13hDYm5jkoH0X0vudWw== X-Gm-Gg: AR+sD122FlnsUqR+e++v5pIozfTyZ36AJ1Vp20RFzITk2jjReWhwEni1yCH3Lp7vE7J QYtSqFdaKICkQ/QwhqB4Oycb5fL627Al1Mo+J2kMEeDKKleE4jDxl6bAS02MFFlno1FzplhoHFL TOtrph0gyJS0RhOJUQBGg1vynIPtaeieSpIVwS/U246astVX+WsJcBHLs9c0sV4x9mIKHVSruRB KWr5mTeou4E+67UeAF4jTLaVD070sqgX/GE1WR63A0aQ3XcH4yMVL4bxAk8u77Uu/q6zWBZVYDT K+h0N+EcrFN98yM9PrKfPP18rtxv4Gw4YaH5zYiGClphv2Pzn2EQ73/VMvA1BqXo6VhoGx6+n8n Gurv2+fAINzIYg+omXZMTbMDGIbnvZuKkSP7oQxyNc7Evirw8QGWQamKMBFdWIxFCq77MIW9pjX CcZZG4krNxVjj5i4wGuJH12t1s3wFww68ja2LXJ7ovuBCFOicomcNDOjvg04bQomUSomg= X-Received: by 2002:a17:906:fe43:b0:c20:88a6:8210 with SMTP id a640c23a62f3a-c2129be1502mr1020404866b.9.1786910470813; Sun, 16 Aug 2026 13:01:10 -0700 (PDT) Received: from foxbook (bfg7.neoplus.adsl.tpnet.pl. [83.28.44.7]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a38d79e437sm3098303a12.31.2026.08.16.13.01.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 16 Aug 2026 13:01:09 -0700 (PDT) Date: Sun, 16 Aug 2026 22:03:06 +0200 From: Michal Pecio To: Mario Limonciello Cc: Rishabh Jain , Mathias Nyman , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] usb: pci-quirks: always assert xHCI OS ownership Message-ID: <20260816220306.64c615f2.michal.pecio@gmail.com> In-Reply-To: <69fdc442-a4f2-42e0-80f6-6b35cbc207bf@kernel.org> References: <20260815014534.77850-1-rishabh.jain1198@gmail.com> <69fdc442-a4f2-42e0-80f6-6b35cbc207bf@kernel.org> 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=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 16 Aug 2026 11:33:56 -0500, Mario Limonciello wrote: > On 8/14/26 20:45, Rishabh Jain wrote: > > The xHCI ownership protocol requires the OS driver to assert the HC > > OS Owned semaphore before using the host controller, then wait for > > HC BIOS Owned to clear if firmware owns it. > > > > quirk_usb_handoff_xhci() currently asserts OS Owned only when BIOS > > Owned is already set. If firmware leaves BIOS Owned clear, Linux > > uses the xHC while both ownership semaphores remain clear. > > > > On an AMD PROM21 xHCI controller (1022:43fc), this caused every S3 > > resume to terminate Controller Restore State with USBSTS 0x401. > > Linux then reset the host controller, both root hubs and the USB > > Bluetooth adapter. Not sure if this has anything to do with PROM21, or if some BIOS is just trying to use the xHC at resume because it's permitted to. Then it makes too many changes for Restore State to still work. Potentially, such bugs may have happened and been left unsolved or "solved" with RESET_ON_RESUME quirks and other hacks. > > The controller entered resume ready and halted with USBSTS 0x1. > > Endpoint state, 100 ms save/restore delays, scratchpads, the DCBAA, > > device contexts and command, event and transfer rings were verified not > > to cause the restore error. > > > > Asserting only HC OS Owned changed USBLEGSUP from 0x00000801 to > > 0x01000801 and eliminated the restore failure across four S3 cycles, > > including a stock-kernel test. Clearing USBLEGCTLSTS was independently > > verified to be unnecessary. > > > > Always assert OS Owned when the xHCI Legacy Support capability is > > present. Use the independently accessible ownership byte so firmware > > can update BIOS Owned without racing a 32-bit read-modify-write. Keep > > the existing BIOS handoff wait and legacy SMI cleanup unchanged. > > > > Fixes: 66d4eadd8d06 ("USB: xhci: BIOS handoff and HW initialization.") > > Tested-by: Rishabh Jain > > Cc: stable@vger.kernel.org > > Signed-off-by: Rishabh Jain > > --- > > Additional context: > > > > * Kernel Bugzilla #216470 documents the same USBSTS 0x401/reinitialize > > behavior and its impact on attached USB devices: > > https://bugzilla.kernel.org/show_bug.cgi?id=216470 > > > > * Commit a7d57abcc8a5 ("xhci: workaround CSS timeout on AMD SNPS 3.0 > > xHC") is related workaround history: it tolerates a distinct AMD CSS > > timeout and resets the controller on resume: > > https://github.com/torvalds/linux/commit/a7d57abcc8a5bdeb53bbf8e87558e8e0a2c2a29d > > > > The external reports do not record their ownership semaphore values but > > are included as corroborating failure signatures that this might fix. > > > > drivers/usb/host/pci-quirks.c | 12 +++++++++--- > > 1 file changed, 9 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c > > index 0404489c2f6a..d76a4791b8f5 100644 > > --- a/drivers/usb/host/pci-quirks.c > > +++ b/drivers/usb/host/pci-quirks.c > > @@ -1185,6 +1185,14 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev) > > dev_warn(&pdev->dev, "xHCI controller failing to respond"); > > goto iounmap; > > } > > + > > + /* > > + * The OS ownership semaphore must be asserted while the OS owns the > > + * xHC, even if firmware did not assert the BIOS ownership semaphore. > > + * Update only the OS ownership byte to avoid racing with firmware. > > + */ > > + writeb(readb(base + ext_cap_offset + 3) | BIT(0), > > + base + ext_cap_offset + 3); > > I'm assuming you are actually meaning XHCI_EXT_CAPS_PM for the 3 here. > Why are you doing all this math? > > We already have the defines XHCI_HC_OS_OWNED, can't you just use that? > > And for that matter it sounds like you are really proposing to just > remove this check but adding more complexity in the process. > > if (val & XHCI_HC_BIOS_OWNED) All explained by the comment above and xHCI 4.22.1. Though curiously, while HW is required to enable doing the sensible thing, the spec doesn't clearly state that SW must actually do it... And BTW, I checked if any of my HCs refuses to honor DWORD writes to this register to protect SW from itself, but none does. > I guess the way I would do this is at least leave a debug breadcrumb Is anyone ever going to look at that pci_debug()? If it works, who cares if it was claimed by the BIOS or not. If it doesn't, you know that it was. And the full register is dumped. > since you're reading the register something like this: > > val = readl(base + ext_cap_offset); > if (val & XHCI_HC_BIOS_OWNED) > pci_debug(pdev, "BIOS owns XHCI HC\n"0; > writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset); > timeout = handshake(...) > if (timeout && (val & XHCI_HC_BIOS_OWNED)) { > dev_warn(...) > writel(val & ~XHCI_HC_BIOS_OWNED, base + ext_cap_offset); > } > > Then you have a single read, no extra writes. > > > val = readl(base + ext_cap_offset); > > > > /* Auto handoff never worked for these devices. Force it and continue */ > > @@ -1195,10 +1203,8 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev) > > writel(val, base + ext_cap_offset); > > } > > > > - /* If the BIOS owns the HC, signal that the OS wants it, and wait */ > > + /* If the BIOS owns the HC, wait for it to hand over control */ > > if (val & XHCI_HC_BIOS_OWNED) { > > - writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset); > > - > > /* Wait for 1 second with 10 microsecond polling interval */ > > timeout = handshake(base + ext_cap_offset, XHCI_HC_BIOS_OWNED, > > 0, 1000000, 10); >