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=1796409628; b=EC5Z9hEKUTbnpzYVcSWL1wy9dt0bJg22auHgU+ytqsoxK+CtJVE7EK4Jw+I5T94i6xnd C/LfYHL19h8RJtCMMYo6maW8/m4mRNOmdR18ViObI918bqKC0hhP0YJx1B68LU0uP5hHC ivoW/s77C/iPSV0P/XIXVkduo/uHrYAbSLAPEgNrEKu6kYKBPIDM/n16qzp1XPskloDEt VPc0vYK3skLSpOQqrK6xHpro8rMAdjdz3JCwf1Ms7J12GmuvRXczCDSx6I8jczqt6Ul++ lGW88Gl92uSq6r12wZznLRdhYjKoOzo1fjelBB/W8KuBsgMp3iih+FPWGtHEF2lJQWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409628; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=c1S9nIEOlNChv+u5HIoZvs4IkwojRtcLLbD3AQQU4+g=; b=Ef3i//FBTpANK1xsJSZfs92w2tNOSHhZkqW102WIbcb5Ogdu8IHbNN2gMOW8eJ+YbbAj 8Tax9RwDZIfm1WxenIrgGJw/SobtzEEeO9smxGfOJmC4j8ixoPz0bQUYJOIZc5JaOVvQO PNTXazoThO2fymHDBUyXy1FPpHMtFglMCmqfEHux4iRNwqsMdVZyf5dk+cJKlEVJ2lpnV J/4B1dH+SkRMgj1yOVAfcnEJaaDJQaewOzt1j+5/dnqTV5ByQptDzE5KXa9SzF8RTLhgk H6WrNfRHI1Odmn8ocdhXMQoT/IVeD8f2AjpJp5rRWPwWe4gOiIg6/7w4oY6ioom1fjA== 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=RgFphdao; 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 DAE1E606A322 for ; Fri, 4 Dec 2026 18:40:28 +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=RgFphdao Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80D1E1F00936; Fri, 4 Dec 2026 18:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409628; bh=c1S9nIEOlNChv+u5HIoZvs4IkwojRtcLLbD3AQQU4+g=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=RgFphdaovc4cTPo1hxxXg5nf1sduPPcVdCUoQPe0EIuqG6O/zwm59Sj2hdReQAG0a TPYKcEIhQExd28xDbLKyUG4vUh+IIbYN8PO5faRSe73bI90Ub1/PgHkakqza5goRwy 4wALmVz9PFHRFm9qGXBgrNfPY9DIoCElwiMEiTpTRZEv3xR/aA1o1kgPOqJ1C7PPvO 5Ez1icGP4/crmy/ARLjbuHipdJ2tpkX1/sBksHiXbQVPQQDmoMDDpSrZqnW9235Bo3 b+vjzMT3T5SYEL9YUkjmAf88o4sGE6uhRDt8MftQfUGWlgR/hjt5dMqWme3k9iak6E 5K3DtSCiVH00g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 4/6] PCI/FLIT: Add support for the Extended Flit Error Counter Reply-To: sashiko-reviews@lists.linux.dev To: "Yazen Ghannam" , linux-pci@vger.kernel.org In-Reply-To: <20261204181556.1418843-5-yazen.ghannam@amd.com> References: <20261204181556.1418843-1-yazen.ghannam@amd.com> <20261204181556.1418843-5-yazen.ghannam@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 18:40:28 +0000 X-Mailing-List: linux-pci@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] PCI/FLIT: extended Flit error counter never cleared via CLEAR bit - [Medium] PCI/FLIT: slot_reset enables CTRL1 before restoring ERR_CNTR_CTRL and CTRL2 - [Medium] PCI/FLIT: missing PCI_POSSIBLE_ERROR() checks in flit_read_cntr_cap() - [Medium] PCI/FLIT: flit_cntr_enable() omits trigger when updating saved state buffer - [Low] PCI/FLIT: pci_flit_init() lacks PCI_POSSIBLE_ERROR() check on ctrl read -- commit d722ed5d293f00a76cfef74bc7d0010083c5e137 Author: Yazen Ghannam PCI/FLIT: Add support for the Extended Flit Error Counter This commit adds support for the Capability Version 2h Extended Flit Error Counter in drivers/pci/pcie/flit.c, selecting it over the base counter when supported and extending register access and save/restore handling to cover the 32-bit control and status registers. > diff --git a/drivers/pci/pcie/flit.c b/drivers/pci/pcie/flit.c > index 00409dd7bb956..97395b6942389 100644 > --- a/drivers/pci/pcie/flit.c > +++ b/drivers/pci/pcie/flit.c [ ... ] > @@ -93,10 +113,46 @@ static bool flit_is_native(struct pci_dev *pdev) > return host->native_flit && host->native_aer; > } > =20 > +static u32 flit_read_cntr_cap(struct pci_dev *pdev) > +{ > + u32 hdr, cap; > + > + pci_read_config_dword(pdev, pdev->flit_cap, &hdr); > + if (PCI_EXT_CAP_VER(hdr) < 2) > + return 0; > + > + pci_read_config_dword(pdev, pdev->flit_cap + PCI_FLIT_ERR_CNTR_CAP, &ca= p); > + > + return cap; > +} > + > +static void flit_select_cntr(struct pci_dev *pdev) > +{ > + struct flit_info *info =3D pdev->flit_info; > + > + info->cntr =3D &flit_base_cntr; > + if (!(info->cntr_cap & PCI_FLIT_ERR_CNTR_CAP_EXT)) > + return; > + > + /* Running both counters, or both interrupts, is undefined */ > + pci_clear_and_set_config_word(pdev, > + pdev->flit_cap + PCI_FLIT_ERR_CNTR_CTRL, > + PCI_FLIT_ERR_CNTR_CTRL_EN | > + PCI_FLIT_ERR_CNTR_CTRL_INTR_EN, 0); > + > + info->cntr =3D &flit_ext_cntr; > +} [Severity: Medium] Should flit_read_cntr_cap() check PCI_POSSIBLE_ERROR() on both hdr and cap? If a config read returns 0xffffffff, PCI_EXT_CAP_VER(hdr) is 0xf, bypassing the version check and returning 0xffffffff so flit_select_cntr() selects flit_ext_cntr. On a Capability Version 1h device, later accesses to offsets 0x40 through 0x48 would then reach past the end of the Flit Logging capability and could corrupt an adjacent extended capability. [ ... ] > @@ -130,17 +192,24 @@ void pci_flit_init(struct pci_dev *pdev) > =20 > pdev->flit_info =3D info; > =20 > + info->cntr_cap =3D flit_read_cntr_cap(pdev); > + > spin_lock_init(&info->lock); > =20 > - info->cntr =3D &flit_base_cntr; > + flit_select_cntr(pdev); > info->enable =3D info->cntr->en | info->cntr->intr_en; > =20 > ctrl =3D flit_cntr_read(pdev, info->cntr->ctrl); > trigger =3D field_get(info->cntr->trigger, ctrl); > info->trigger =3D trigger ? trigger : FLIT_DEFAULT_TRIGGER; [Severity: Low] Does pci_flit_init() need a PCI_POSSIBLE_ERROR(ctrl) check here? On an all-ones error response, field_get() extracts 0xff or 0xffff instead of falling back to FLIT_DEFAULT_TRIGGER, which can never be exceeded and silently disables trigger events. [ ... ] > @@ -181,6 +250,17 @@ void pci_save_flit_state(struct pci_dev *pdev) > pci_read_config_word(pdev, flit + PCI_FLIT_ERR_CNTR_CTRL, &ctrl); > slots[FLIT_SAVE_CNTR_CTRL] =3D ctrl; > =20 > + if (flit_ext(info)) { > + pci_read_config_dword(pdev, flit + PCI_FLIT_EXT_CNTR_CTRL1, > + &ctrl1); > + pci_read_config_dword(pdev, flit + PCI_FLIT_EXT_CNTR_CTRL2, > + &slots[FLIT_SAVE_EXT_CNTR_CTRL2]); > + > + /* Reads as zero, but restoring a one would clear the counter */ > + ctrl1 &=3D ~PCI_FLIT_EXT_CNTR_CTRL1_CLEAR; > + slots[FLIT_SAVE_EXT_CNTR_CTRL1] =3D ctrl1; > + } [Severity: High] Is the Extended Flit Error Counter ever cleared via PCI_FLIT_EXT_CNTR_CTRL1_CLEAR? For the base counter, flit_isr() writes cntr->intr_gen to PCI_FLIT_ERR_CNTR_STA, zeroing the RW 8-bit count along with INTR_GEN. For the extended counter, the 16-bit count in PCI_FLIT_EXT_CNTR_STA is read-only and needs PCI_FLIT_EXT_CNTR_CTRL1_CLEAR. That bit is never set anywhere in flit.c, and decrement rates in PCI_FLIT_EXT_CNTR_CTRL2 are never programmed. After the first trigger, flit_cntr_resume() re-enables the counter while the count still exceeds info->trigger, causing an interrupt storm or lost notifications. Stale counts left by firmware are likewise never cleared in flit_cntr_enable(). [ ... ] > @@ -203,10 +283,21 @@ void pci_restore_flit_state(struct pci_dev *pdev) > if (!slots) > return; > =20 > - /* Event servicing can run during a runtime resume or slot reset */ > + /* > + * Event servicing can run during a runtime resume or slot reset. Write > + * Flit Error Counter Control first so the two counters never overlap, > + * and the decrement rates before the counter they apply to. > + */ > spin_lock_irqsave(&info->lock, flags); > pci_write_config_word(pdev, flit + PCI_FLIT_ERR_CNTR_CTRL, > slots[FLIT_SAVE_CNTR_CTRL]); > + > + if (flit_ext(info)) { > + pci_write_config_dword(pdev, flit + PCI_FLIT_EXT_CNTR_CTRL2, > + slots[FLIT_SAVE_EXT_CNTR_CTRL2]); > + pci_write_config_dword(pdev, flit + PCI_FLIT_EXT_CNTR_CTRL1, > + slots[FLIT_SAVE_EXT_CNTR_CTRL1]); > + } > spin_unlock_irqrestore(&info->lock, flags); > } [Severity: Medium] Can slot_reset violate the restore ordering documented here by enabling PCI_FLIT_EXT_CNTR_CTRL1 before PCI_FLIT_ERR_CNTR_CTRL and PCI_FLIT_EXT_CNTR_CTRL2 are restored? drivers/pci/pcie/portdrv.c:pcie_portdrv_slot_reset() { size_t off =3D offsetof(struct pcie_port_service_driver, slot_reset); device_for_each_child(&dev->dev, &off, pcie_port_device_iter); pci_restore_state(dev); return PCI_ERS_RESULT_RECOVERED; } flit_cntr_restore() calls flit_cntr_enable() first, enabling CTRL1 while CTRL2 still holds post-reset defaults. pci_restore_flit_state() then writes ERR_CNTR_CTRL and CTRL2 without clearing CTRL1 EN first (which also happens on a non-reset resume). In addition, if a Flit interrupt fires between flit_cntr_restore() and pci_restore_flit_state(), restoring slots[FLIT_SAVE_EXT_CNTR_CTRL1] unconditionally writes EN=3D1 and prematurely re-enables a paused counter while flit_ist() is still draining the log. [Severity: Medium] Can pci_restore_flit_state() clobber the programmed trigger threshold back to 0 after a slot reset? drivers/pci/pcie/flit.c:flit_cntr_enable() { ... __flit_cntr_ctrl_update(pdev, cntr->trigger | ctrl, field_prep(cntr->trigger, info->trigger) | info->enable); __flit_save_state_update(pdev, cntr->slot, ctrl, info->enable); ... } If a port boots with a hardware trigger of 0 and pci_save_state() runs before flit_probe() (for example with driver_async_probe=3Dflit), the save buffer captures trigger as 0. Because __flit_save_state_update() omits cntr->trigger, pci_restore_flit_state() during pcie_portdrv_slot_reset() overwrites the programmed trigger with 0 and stops events from firing. Updating cntr->trigger alongside ctrl in __flit_save_state_update() would keep the save buffer consistent. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204181556.1418= 843-1-yazen.ghannam@amd.com?part=3D4