Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chengwen Feng" <fengchengwen@huawei.com>
Cc: kvm@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v20 12/16] vfio/pci: Add basic NO-ST TPH VFIO device feature support
Date: Tue, 14 Jul 2026 11:10:58 +0000	[thread overview]
Message-ID: <20260714111059.032C91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714104325.54444-13-fengchengwen@huawei.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditional release of the DMA reservation lock in `vfio_pci_get_dmabuf_tph()` when acquisition fails.
- [Medium] Missing validation for the reserved field `rsv` in `struct vfio_device_feature_tph_resolve`.
--

--- Patch [12]: [PATCH v20 12/16] vfio/pci: Add basic NO-ST TPH VFIO device feature support ---
commit e2b4dfe99fe4b36b6dce86a257a0fa1605e500b6
Author: Chengwen Feng <fengchengwen@huawei.com>

vfio/pci: Add basic NO-ST TPH VFIO device feature support

Implement basic PCIe TPH support in NO-ST mode, adding VFIO_DEVICE_FEATURE_TPH
and VFIO_DEVICE_FEATURE_TPH_RESOLVE to allow TPH operations after opt-in.

> diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
> index 4e5e34a77b76d..82582c8ef69da 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
[ ... ]
> @@ -1607,6 +1611,123 @@ static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,
[ ... ]
> +static int vfio_pci_get_dmabuf_tph(int fd, bool extended, u16 *st, u8 *ph)
> +{
> +	struct dma_buf *dmabuf;
> +	int ret;
> +
> +	dmabuf = dma_buf_get(fd);
> +	if (IS_ERR(dmabuf))
> +		return PTR_ERR(dmabuf);
> +
> +	ret = dma_resv_lock_interruptible(dmabuf->resv, NULL);
> +	if (ret == 0)
> +		ret = dma_buf_get_pci_tph(dmabuf, extended, st, ph);
> +	dma_resv_unlock(dmabuf->resv);

[Severity: High]
Does this code unconditionally unlock the DMA reservation lock even if the
lock acquisition fails? 

If a signal interrupts dma_resv_lock_interruptible(), it will return -EINTR,
skipping the read but still calling dma_resv_unlock(). Can this underflow the
WW mutex state and lead to a panic?

> +
> +	dma_buf_put(dmabuf);
> +	return ret;
> +}
> +
> +static int vfio_pci_core_feature_tph_resolve(struct vfio_pci_core_device *vdev,
> +			u32 flags,
> +			struct vfio_device_feature_tph_resolve __user *arg,
> +			size_t argsz)
> +{
> +	struct vfio_device_feature_tph_resolve resolve;
> +	u32 user_flags, allow_src;
> +	bool extended;
> +	u16 tag = 0;
> +	u8 ph = 0;
> +	int ret;
> +
> +	if (!vdev->tph_opt_in)
> +		return -EOPNOTSUPP;
> +
> +	ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET,
> +				 sizeof(resolve));
> +	if (ret != 1)
> +		return ret;
> +
> +	if (copy_from_user(&resolve, arg, sizeof(resolve)))
> +		return -EFAULT;
> +
> +	user_flags = resolve.flags;

[Severity: Medium]
Does this code need to validate that the reserved field resolve.rsv is zero?

Without checking it here, userspace could pass garbage data, which might
prevent safely extending this UAPI structure in the future without breaking
existing applications.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714104325.54444-1-fengchengwen@huawei.com?part=12

  reply	other threads:[~2026-07-14 11:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 10:43 [PATCH v20 00/16] vfio/pci: Add PCIe TPH support Chengwen Feng
2026-07-14 10:43 ` [PATCH v20 01/16] PCI/TPH: Add requester/completer type helpers Chengwen Feng
2026-07-14 10:54   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 02/16] dma-buf: add optional get_pci_tph() callback Chengwen Feng
2026-07-14 10:50   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 03/16] vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature Chengwen Feng
2026-07-14 10:50   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 04/16] PCI/TPH: Fix pcie_tph_get_st_table_loc() field extraction Chengwen Feng
2026-07-14 10:54   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 05/16] PCI/TPH: Fix tph_enabled concurrent update race by bitfield packing Chengwen Feng
2026-07-14 11:00   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 06/16] PCI/TPH: Cache negotiated max requester type at probe time Chengwen Feng
2026-07-14 10:57   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 07/16] PCI/TPH: Refactor pcie_enable_tph and add requester variant Chengwen Feng
2026-07-14 10:58   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 08/16] PCI/TPH: Refactor pcie_tph_get_cpu_st & " Chengwen Feng
2026-07-14 11:00   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 09/16] PCI/TPH: Add macros to check standard and extended TPH support Chengwen Feng
2026-07-14 11:07   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 10/16] PCI/TPH: Add pcie_tph_set_st_entries() batch ST entry programming helper Chengwen Feng
2026-07-14 11:11   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 11/16] PCI/TPH: Add pci_tph_dsm_supported() helper to detect device TPH ST _DSM Chengwen Feng
2026-07-14 11:27   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 12/16] vfio/pci: Add basic NO-ST TPH VFIO device feature support Chengwen Feng
2026-07-14 11:10   ` sashiko-bot [this message]
2026-07-14 10:43 ` [PATCH v20 13/16] vfio/pci: Add IV-ST TPH policy and VFIO TPH_ST batch programming support Chengwen Feng
2026-07-14 11:14   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 14/16] vfio/pci: Add DS-ST TPH policy and extend TPH_RESOLVE capabilities Chengwen Feng
2026-07-14 11:12   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 15/16] vfio/pci: Sync core PCI TPH software state across device lifecycle and resets Chengwen Feng
2026-07-14 11:28   ` sashiko-bot
2026-07-14 10:43 ` [PATCH v20 16/16] vfio/pci: Expose per-device TPH state via debugfs Chengwen Feng
2026-07-14 11:17   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260714111059.032C91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fengchengwen@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox