[{"id":3687042,"web_url":"http://patchwork.ozlabs.org/comment/3687042/","msgid":"<20260506123907.E2928C2BCB8@smtp.kernel.org>","list_archive_url":null,"date":"2026-05-06T12:39:07","subject":"Re: [PATCH v6 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for\n external use","submitter":{"id":93311,"url":"http://patchwork.ozlabs.org/api/people/93311/","name":null,"email":"sashiko-bot@kernel.org"},"content":"Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:\n- [Medium] Missing error handling for pci_read_config_dword() in the newly exported pcie_tph_get_st_modes() leads to falsely reporting all TPH modes as supported when a device is disconnected.\n- [Low] The !CONFIG_PCI_TPH stub for pcie_tph_get_st_table_loc() returns an inconsistent out-of-bounds value (0x7FF) instead of PCI_TPH_LOC_NONE.\n--\n\ncommit d23fc69219a490dd1458be7c3d6f50ae929f70cd\nAuthor: Chengwen Feng <fengchengwen@huawei.com>\n\nPCI/TPH: Export pcie_tph_get_st_modes() for external use\n\nThis commit exports the pcie_tph_get_st_modes() helper so drivers like VFIO\ncan query supported PCIe TPH steering tag modes. It also adds stub functions\nfor when !CONFIG_PCI_TPH and tph_cap validation.\n\n> diff --git a/drivers/pci/tph.c b/drivers/pci/tph.c\n> index f17b74b5fb1e3..ba31b010f67ad 100644\n> --- a/drivers/pci/tph.c\n> +++ b/drivers/pci/tph.c\n[ ... ]\n> @@ -145,15 +145,27 @@ static void set_ctrl_reg_req_en(struct pci_dev *pdev, u8 req_type)\n> -static u8 get_st_modes(struct pci_dev *pdev)\n> +/**\n> + * pcie_tph_get_st_modes - Get supported Steering Tag modes\n> + * @pdev: PCI device to query\n> + *\n> + * Return:\n> + *  Bitmask of supported ST modes (PCI_TPH_CAP_ST_NS, PCI_TPH_CAP_ST_IV,\n> + *                                 PCI_TPH_CAP_ST_DS)\n> + */\n> +u8 pcie_tph_get_st_modes(struct pci_dev *pdev)\n>  {\n>  \tu32 reg;\n>  \n> +\tif (!pdev->tph_cap)\n> +\t\treturn 0;\n> +\n>  \tpci_read_config_dword(pdev, pdev->tph_cap + PCI_TPH_CAP, &reg);\n\nIf pci_read_config_dword() fails (e.g., when a device is disconnected), it\npopulates the output variable with an error response (~0 or 0xFFFFFFFF).\n\nSince the return value is ignored here, will this masking operation:\n\n>  \treg &= PCI_TPH_CAP_ST_NS | PCI_TPH_CAP_ST_IV | PCI_TPH_CAP_ST_DS;\n\nevaluate to 0x07 and incorrectly report all three Steering Tag modes as\nsupported during a device disconnection?\n\n>  \n>  \treturn reg;\n>  }\n> +EXPORT_SYMBOL(pcie_tph_get_st_modes);\n\n[ ... ]\n\n> diff --git a/include/linux/pci-tph.h b/include/linux/pci-tph.h\n> index be68cd17f2f83..586c75b19e019 100644\n> --- a/include/linux/pci-tph.h\n> +++ b/include/linux/pci-tph.h\n[ ... ]\n> @@ -41,6 +42,12 @@ static inline int pcie_tph_get_cpu_st(struct pci_dev *dev,\n>  static inline void pcie_disable_tph(struct pci_dev *pdev) { }\n>  static inline int pcie_enable_tph(struct pci_dev *pdev, int mode)\n>  { return -EINVAL; }\n> +static inline u16 pcie_tph_get_st_table_size(struct pci_dev *pdev)\n> +{ return 0; }\n> +static inline u32 pcie_tph_get_st_table_loc(struct pci_dev *pdev)\n> +{ return 0x7FF; /* Values that do not appear in normal case */ }\n\nWhen TPH is enabled but a device lacks TPH capabilities, the live function\nsafely returns PCI_TPH_LOC_NONE.\n\nDoes returning 0x7FF in this stub introduce an inconsistency in the API that\nforces callers to handle arbitrary magic numbers instead of relying on\nPCI_TPH_LOC_NONE?","headers":{"Return-Path":"\n <linux-pci+bounces-53857-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=q0T8HVhu;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-53857-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"q0T8HVhu\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9Zlg2cVGz1yJV\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 22:42:23 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id B5BF13015A4F\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 12:39:09 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A4062280CF6;\n\tWed,  6 May 2026 12:39:08 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F84343D517\n\tfor <linux-pci@vger.kernel.org>; Wed,  6 May 2026 12:39:08 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id E2928C2BCB8;\n\tWed,  6 May 2026 12:39:07 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778071148; cv=none;\n b=slxmgb29llMTBEvesXO6WyhoV1blJWK/QwB/Xj3ka70RyNqXiPR/fR2YGCizWzEMoXe7ldFStEE2WYa/mpu6MBnsQs21SN7+cmkc4auWipDF51CUO67lTivQq6AEqGRDmNxDyfR0y5pW5AcZDqp23IISAdww2w7PIPMmuWDUXFI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778071148; c=relaxed/simple;\n\tbh=9uK3VSzqbg7Ou/qYuZlh2e5GSopEy3iqG6qmAtrsBwA=;\n\th=From:Subject:To:Cc:In-Reply-To:References:Content-Type:Date:\n\t Message-Id;\n b=P6aWZC6X/pt8ITyrjbik3DH4/l7DS6SlWIjiIFRfuppaZR3z39CbTEdzMRGncwqaaOgDLJNJkUEPxcR9rbCD9K62SB8CwzcU1PoBQqIDeMQ08uDWH774xPJ6r/el7yjiPA8EMPWbj6F8/SIhhEsCVI+TTO0yO1847m+7RW9OI6c=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=q0T8HVhu; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1778071148;\n\tbh=9uK3VSzqbg7Ou/qYuZlh2e5GSopEy3iqG6qmAtrsBwA=;\n\th=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date:From;\n\tb=q0T8HVhu9w00JYGsKG4K6Lc7YrnBxXD8RWyu7jpUUanN4O4YBPfJqgxrV6VZ83kcl\n\t IQkeh1B9W9HmggIrfIED/jjH4zSvrBcSgGfqJXw7XHyjnRKaXIV5NRNcPVsSIZr1r8\n\t i1sJxZrZDB+llsxxTzhsx2qHGkFWNdacf8al4Ywrd5OV2HjEgZMVjJRdygKkgAmzpE\n\t o7Y9ogw9pM1X9TtnV3tnKGR+MyceHq/vACSzNh1XhDQKijk1IfNy9HYlAoe3EmYM1T\n\t t0XOjo5geR2g6onoBmLxDu9WVQvxPsL5A9akpvjhO7SbUcrCg0WdmocCu38kF7rpVy\n\t g5ezJH8bqvkNw==","From":"sashiko-bot@kernel.org","Subject":"Re: [PATCH v6 2/6] PCI/TPH: Export pcie_tph_get_st_modes() for\n external use","Reply-To":"sashiko@lists.linux.dev","To":"\"Chengwen Feng\" <fengchengwen@huawei.com>","Cc":"linux-pci@vger.kernel.org","In-Reply-To":"<20260506094623.29327-3-fengchengwen@huawei.com>","References":"<20260506094623.29327-3-fengchengwen@huawei.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","Date":"Wed, 06 May 2026 12:39:07 +0000","Message-Id":"<20260506123907.E2928C2BCB8@smtp.kernel.org>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>"}}]