[{"id":3687326,"web_url":"http://patchwork.ozlabs.org/comment/3687326/","msgid":"<20260506184841.34EE6C2BCB0@smtp.kernel.org>","list_archive_url":null,"date":"2026-05-06T18:48:40","subject":"Re: [PATCH v6 3/6] vfio/pci: Add PCIe TPH interface with capability\n query","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 1 potential issue(s) to consider:\n- [High] The VFIO_DEVICE_PCI_TPH IOCTL reads PCI configuration space without ensuring the device is runtime resumed, potentially reporting bogus capabilities and causing hardware errors.\n--\n\ncommit c1b7fcc4c0c41ea45b0bcdd16ef1d416fcc244c3\nAuthor: Chengwen Feng <fengchengwen@huawei.com>\n\nvfio/pci: Add PCIe TPH interface with capability query\n\nThis commit adds the VFIO_DEVICE_PCI_TPH IOCTL to allow userspace to query\ndevice TPH capabilities. It also introduces a module parameter to restrict\nunsafe device-specific TPH mode to trusted userspace.\n\n> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c\n> index 3f8d093aacf8a..d98d04bad4a39 100644\n> --- a/drivers/vfio/pci/vfio_pci_core.c\n> +++ b/drivers/vfio/pci/vfio_pci_core.c\n[ ... ]\n> @@ -1461,6 +1463,53 @@ static int vfio_pci_ioctl_ioeventfd(struct vfio_pci_core_device *vdev,\n>  \t\t\t\t  ioeventfd.fd);\n>  }\n>  \n> +static int vfio_pci_tph_get_cap(struct vfio_pci_core_device *vdev,\n> +\t\t\t\tstruct vfio_device_pci_tph_op *op,\n> +\t\t\t\tvoid __user *uarg)\n> +{\n> +\tstruct pci_dev *pdev = vdev->pdev;\n> +\tu8 mode = pcie_tph_get_st_modes(pdev);\n\nDoes this ioctl need to ensure the device is runtime resumed before reading\nits configuration space?\n\nIf the device is in a low-power state (like D3cold), won't the configuration\nreads in pcie_tph_get_st_modes() return 0xFFFFFFFF?\n\nThis could cause the kernel to falsely report that all TPH modes are\nsupported and advertise an incorrect ST table size.\n\nShould this handler (or vfio_pci_ioctl_tph) call\npm_runtime_resume_and_get() before invoking hardware-touching operations,\nand pm_runtime_put() afterward?\n\n> +\tstruct vfio_pci_tph_cap cap = {0};\n> +\n> +\tif (op->argsz < offsetof(struct vfio_device_pci_tph_op, cap) +\n> +\t\t\tsizeof(struct vfio_pci_tph_cap))\n> +\t\treturn -EINVAL;\n> +\n> +\tif (mode == 0 || mode == PCI_TPH_CAP_ST_NS)\n> +\t\treturn -EOPNOTSUPP;\n[ ... ]","headers":{"Return-Path":"\n <linux-pci+bounces-53937-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=IRwyyUTb;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-53937-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=\"IRwyyUTb\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::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 4g9kxy6hjTz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 07 May 2026 04:51:50 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 314C33006B64\n\tfor <incoming@patchwork.ozlabs.org>; Wed,  6 May 2026 18:48:43 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id DA5434963B3;\n\tWed,  6 May 2026 18:48:41 +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 B69AE4418D7\n\tfor <linux-pci@vger.kernel.org>; Wed,  6 May 2026 18:48:41 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 34EE6C2BCB0;\n\tWed,  6 May 2026 18:48:41 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1778093321; cv=none;\n b=LAaPzF35DCwcsMuO//nnQElo7Jaq+9fHadS/JHfjP80n/8/BniBD85zchUgL4OmC9ovlOb3Yc1+w6J25Rk7u5tg0HivHMLWwYLpxQqLdwjXGbHrei3/7cgCYvh428gro7poTB6xBQWn0r9X8FkWdZPjTs2dUkfd44OfYwvTgy/E=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1778093321; c=relaxed/simple;\n\tbh=O+GrmHIW4NYRhO47krqBeROSuG2cozQ17GJZVgHGkYM=;\n\th=From:Subject:To:Cc:In-Reply-To:References:Content-Type:Date:\n\t Message-Id;\n b=AN9vET3bfGixLshSGp4c/IW4xf+TsMJ3ifQemn6dQY2a0uI/EVFlyGUni/syUlMo7YIgOhVmTbm5V6lOVmJn6xchx56EZ/OfzAqFKL3LEMyX/5Z8CWx7qi+imsyO4EbKppLu0Jftt0wlraErQa01LQ9TQgzVnJdqoVa9VCPxySE=","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=IRwyyUTb; 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=1778093321;\n\tbh=O+GrmHIW4NYRhO47krqBeROSuG2cozQ17GJZVgHGkYM=;\n\th=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date:From;\n\tb=IRwyyUTbRyXpXsxBBWVIVWBYRH4zNOqRhYLOhtzzAVO9X9r43wR1R8HovkJ1Pory5\n\t fMM7VbDsx0pilJNuSvlnRtP4AwKaJUQpWRgBHbDwS49ovoxT7VGUMImboHxxRdmCcv\n\t 3Lf5YceEb85uFuS/HwECTQhYd1i2TkDDOd6Dy7d+WBLSl25z3QvEwCigj0BoWi0tIH\n\t 9cXnNZBfFheL3M/FRXg6qiK/pFPckRzT5WygVBYF6ihKU75m7AMDl6fXNJ2HXUych9\n\t vfxo4dXqHwpfP+pLZWVXgszKlH+qkJ2DNYMJwWOtVIwK5EEFtgpBnGuLBzU2f03UNQ\n\t r2rR9hAHugtkg==","From":"sashiko-bot@kernel.org","Subject":"Re: [PATCH v6 3/6] vfio/pci: Add PCIe TPH interface with capability\n query","Reply-To":"sashiko@lists.linux.dev","To":"\"Chengwen Feng\" <fengchengwen@huawei.com>","Cc":"linux-pci@vger.kernel.org","In-Reply-To":"<20260506094623.29327-4-fengchengwen@huawei.com>","References":"<20260506094623.29327-4-fengchengwen@huawei.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","Date":"Wed, 06 May 2026 18:48:40 +0000","Message-Id":"<20260506184841.34EE6C2BCB0@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>"}}]