Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhiping Zhang" <zhipingz@meta.com>
Cc: kvm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v6 3/5] dma-buf: add optional get_tph() callback
Date: Tue, 09 Jun 2026 19:38:39 +0000	[thread overview]
Message-ID: <20260609193840.4A1CF1F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260608185646.4085127-4-zhipingz@meta.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The `get_tph` callback takes `struct dma_buf *` instead of `struct dma_buf_attachment *`, failing to account for per-attachment mappings and dynamic buffer migrations.
- [High] The new `get_tph` operation lacks a corresponding core API wrapper function in `dma-buf.c` and is omitted from the subsystem locking documentation.
--

commit 4644c9f73b091302efc6ec2a805dcc7affb8aaf6
Author: Zhiping Zhang <zhipingz@meta.com>

dma-buf: add optional get_tph() callback

This commit adds an optional get_tph callback to the dma-buf ops so an
exporter can return PCIe TPH (TLP Processing Hints) metadata to an importer.
The API provides a discoverable negotiation point between exporter and
importer.

> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> index d1203da56fc5f..8437dbe4a83ec 100644
> --- a/include/linux/dma-buf.h
> +++ b/include/linux/dma-buf.h
> @@ -113,6 +113,37 @@ struct dma_buf_ops {
>  	 */
>  	void (*unpin)(struct dma_buf_attachment *attach);
>  
> +	/**
> +	 * @get_tph:
> +	 * @dmabuf: DMA buffer for which to retrieve TPH metadata
> +	 * @extended: false to request the 8-bit ST namespace, true to request
> +	 *            the 16-bit Extended ST namespace
> +	 * @steering_tag: Returns the raw TPH steering tag for the requested
> +	 *                namespace
> +	 * @ph: Returns the TPH processing hint (2-bit value)
> +	 *
> +	 * Return the TPH (TLP Processing Hints) metadata associated with this
> +	 * DMA buffer for the requested steering-tag namespace. 8-bit ST and
> +	 * 16-bit Extended ST are distinct namespaces in the PCIe TPH ST table
> +	 * and may both be present with different values, so the exporter must
> +	 * select the value that matches @extended and must not substitute one
> +	 * for the other.
> +	 *
> +	 * The exporter owns the completing address space for @dmabuf and
> +	 * therefore decides whether it can derive meaningful TPH metadata for
> +	 * that completer. The dma-buf core treats the returned ST/PH tuple as
> +	 * opaque transport metadata; importers that support TPH place it on
> +	 * outbound TLPs, while exporters that cannot derive a useful tuple
> +	 * simply return -EOPNOTSUPP.
> +	 *
> +	 * Return 0 on success, or -EOPNOTSUPP if no metadata is available for
> +	 * the requested namespace.
> +	 *
> +	 * This callback is optional.
> +	 */
> +	int (*get_tph)(struct dma_buf *dmabuf, bool extended,
> +		       u16 *steering_tag, u8 *ph);

[Severity: High]
Does this callback need to take a struct dma_buf_attachment * instead of a
struct dma_buf *?

A dma-buf's physical backing storage is only stable in the context of a mapped
attachment. Exporters might provide device memory to a peer-to-peer capable
importer, but system memory to another importer. Furthermore, dynamic dma-bufs
can migrate their backing storage between VRAM and system memory, which changes
the completer and the correct Steering Tag.

By querying TPH metadata on the global dma_buf object without an attachment
context, the exporter cannot know which importer's mapping is being queried.
Can this prevent the exporter from returning the correct completing address
space's Steering Tag?

[Severity: High]
Should this new operation have a corresponding core API wrapper function exported
in drivers/dma-buf/dma-buf.c and documented in the locking convention block?

In the dma-buf architecture, ops are typically encapsulated behind core wrappers
to enforce cross-subsystem locking, validate inputs, and handle tracing. By
omitting the wrapper, importers are forced to bypass the core API and
dereference the ops structure directly:

drivers/infiniband/hw/mlx5/mr.c:get_tph_mr_dmabuf() {
    ...
    ret = dmabuf->ops->get_tph(dmabuf, extended, &steering_tag, &local_ph);
    ...
}

Does the lack of a wrapper function like dma_buf_get_tph() violate the expected
API encapsulation for dma-buf operations?

>  	/**
>  	 * @map_dma_buf:
>  	 *

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

  parent reply	other threads:[~2026-06-09 19:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260608185646.4085127-1-zhipingz@meta.com>
     [not found] ` <20260608185646.4085127-4-zhipingz@meta.com>
2026-06-09  8:10   ` [PATCH v6 3/5] dma-buf: add optional get_tph() callback Christian König
2026-06-09 14:38     ` Zhiping Zhang
2026-06-09 19:38   ` sashiko-bot [this message]
     [not found] ` <20260608185646.4085127-5-zhipingz@meta.com>
2026-06-09  8:12   ` [PATCH v6 4/5] vfio/pci: implement get_tph and DMA_BUF_TPH feature Christian König
2026-06-09 14:39     ` Zhiping Zhang
2026-06-09 19:38   ` sashiko-bot
2026-06-09 21:46   ` Alex Williamson
2026-06-09 23:48     ` Zhiping Zhang

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=20260609193840.4A1CF1F00898@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