Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhiping Zhang" <zhipingz@meta.com>
Cc: kvm@vger.kernel.org, linux-pci@vger.kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v10 3/4] vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature
Date: Tue, 30 Jun 2026 23:08:41 +0000	[thread overview]
Message-ID: <20260630230841.7E4C51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630224328.3218796-4-zhipingz@meta.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Lockless plain load of `priv->vdev` races with concurrent modification in cleanup path.
- [Low] Missing `WRITE_ONCE()` for `priv->revoked` leads to data race with `READ_ONCE()`.
--

commit d524eab36e9482385fe1c1a6c6280e667bf56a9c
Author: Zhiping Zhang <zhipingz@meta.com>
Subject: vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature

This commit implements dma-buf get_pci_tph for vfio-pci exported
dma-bufs and adds VFIO_DEVICE_FEATURE_DMA_BUF_TPH. This allows
userspace to publish TPH metadata for a VFIO-owned device.

> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
> index c16f460c01d68..8de72f9e75024 100644
> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
> @@ -30,7 +38,7 @@ static int vfio_pci_dma_buf_attach(struct dma_buf *dmabuf,
>  	if (!attachment->peer2peer)
>  		return -EOPNOTSUPP;
>  
> -	if (priv->revoked)
> +	if (READ_ONCE(priv->revoked))

[Severity: Low]
Since this updates the read of priv->revoked to use READ_ONCE(), should the
corresponding writers in vfio_pci_dma_buf_move() also be updated to use
WRITE_ONCE()?

For example, when a concurrent state change like a device reset writes to
this field:

vfio_pci_dma_buf_move() {
        ...
        priv->revoked = true;
        ...
}

Will the lack of WRITE_ONCE() here trigger KCSAN data race warnings when
evaluated concurrently by the new READ_ONCE() check?

>  		return -ENODEV;
>  
>  	if (!dma_buf_attach_revocable(attachment))

[ ... ]

> @@ -333,6 +362,72 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
>  	return ret;
>  }
>  
> +int vfio_pci_core_feature_dma_buf_tph(struct vfio_pci_core_device *vdev,
> +				      u32 flags,
> +				      struct vfio_device_feature_dma_buf_tph __user *arg,
> +				      size_t argsz)
> +{

[ ... ]

> +	dmabuf = dma_buf_get(set_tph.dmabuf_fd);
> +	if (IS_ERR(dmabuf))
> +		return PTR_ERR(dmabuf);
> +
> +	if (dmabuf->ops != &vfio_pci_dmabuf_ops) {
> +		ret = -EINVAL;
> +		goto out_put;
> +	}
> +
> +	priv = dmabuf->priv;
> +	if (priv->vdev != vdev) {

[Severity: Low]
Can this lockless read of priv->vdev race with concurrent modifications in
the cleanup path?

If userspace calls the VFIO_DEVICE_FEATURE_DMA_BUF_TPH ioctl on device A,
passing a dmabuf_fd belonging to device B, while device B is concurrently
being closed, could this race with vfio_pci_dma_buf_cleanup()?

vfio_pci_dma_buf_cleanup() {
        ...
        priv->vdev = NULL;
        ...
}

Will this concurrent plain store trigger KCSAN warnings during the pointer
equality check?

> +		ret = -EINVAL;
> +		goto out_put;
> +	}
> +
> +	ret = dma_resv_lock_interruptible(dmabuf->resv, NULL);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260630224328.3218796-1-zhipingz@meta.com?part=3

  reply	other threads:[~2026-06-30 23:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 22:42 [PATCH v10 0/4] vfio/dma-buf: add TPH support for peer-to-peer access Zhiping Zhang
2026-06-30 22:42 ` [PATCH v10 1/4] PCI/TPH: Add requester/completer type helpers Zhiping Zhang
2026-06-30 23:07   ` sashiko-bot
2026-06-30 22:42 ` [PATCH v10 2/4] dma-buf: add optional get_pci_tph() callback Zhiping Zhang
2026-06-30 23:01   ` sashiko-bot
2026-07-01  8:25   ` Christian König
2026-07-01 17:53     ` Zhiping Zhang
2026-07-02  7:06       ` Christian König
2026-06-30 22:42 ` [PATCH v10 3/4] vfio/pci: implement get_pci_tph and DMA_BUF_TPH feature Zhiping Zhang
2026-06-30 23:08   ` sashiko-bot [this message]
2026-07-01 18:07   ` Alex Williamson
2026-07-01 21:07     ` Zhiping Zhang
2026-06-30 22:42 ` [PATCH v10 4/4] RDMA/mlx5: get tph for p2p access when registering dma-buf mr Zhiping Zhang
2026-06-30 23:11   ` 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=20260630230841.7E4C51F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhipingz@meta.com \
    /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