Netdev List
 help / color / mirror / Atom feed
From: Karl Mehltretter <kmehltretter@gmail.com>
To: Alistair Popple <apopple@nvidia.com>
Cc: "Christian König" <christian.koenig@amd.com>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Simona Vetter" <simona.vetter@ffwll.ch>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Vivek Kasireddy" <vivek.kasireddy@intel.com>,
	"Dongwon Kim" <dongwon.kim@intel.com>,
	"Kevin Tian" <kevin.tian@intel.com>,
	"Xu Yilun" <yilun.xu@linux.intel.com>,
	"Baolu Lu" <baolu.lu@linux.intel.com>,
	"Felix Kuehling" <felix.kuehling@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, linux-media@vger.kernel.org,
	linaro-mm-sig@lists.linaro.org, linux-rdma@vger.kernel.org,
	iommu@lists.linux.dev, "Keith Busch" <kbusch@kernel.org>,
	"Jens Axboe" <axboe@kernel.dk>, "Christoph Hellwig" <hch@lst.de>,
	"Sagi Grimberg" <sagi@grimberg.me>,
	linux-nvme@lists.infradead.org,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Mina Almasry" <almasrymina@google.com>,
	netdev@vger.kernel.org, "Alexey Kardashevskiy" <aik@amd.com>,
	zhipingz@meta.com, treding@nvidia.com, jhubbard@nvidia.com,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>
Subject: Re: [PATCH v2 06/23] dma-buf: Let the exporter select mapping type at pin/map
Date: Sat, 7 Nov 2026 09:57:22 +0100	[thread overview]
Message-ID: <au7mBMbRC8q6NILj@gmail.com> (raw)
In-Reply-To: <20261105-dma_mapping_type_v4-v2-6-78b8dc9ae80a@nvidia.com>

On Thu, Nov 05, 2026 at 05:40:41PM +0100, Alistair Popple wrote:
> + * A pin or map that fails after dma_buf_mapping_select() may reopen the
> + * choice only if it was the one that made it. A selection that predates the
> + * call belongs to a live pin or mapping and must survive, otherwise the next
> + * pin or map would reselect under it without an invalidate.
> + */
> +void dma_buf_mapping_unselect(struct dma_buf_attachment *attach,
> +			      bool was_selected)
> +{
> +	dma_resv_assert_held(attach->dmabuf->resv);
> +
> +	if (was_selected)
> +		return;
> +
> +	attach->selected = false;
> +	attach->selected_idx = 0;
> +}
> +

After dma_buf_invalidate_mappings(), attach->selected is false while
attach->selected_idx still holds that mapping's entry for a pending
unmap. 

If a pin/map fails before that unmap runs, was_selected is false and
dma_buf_mapping_unselect() resets attach->selected_idx to 0.

A subsequent dma_buf_unmap_sgt() then uses matches[0].

>  int dma_buf_pin(struct dma_buf_attachment *attach)
>  {
>  	struct dma_buf *dmabuf = attach->dmabuf;
> +	bool selected = attach->selected;
>  	int ret = 0;
>  
>  	WARN_ON(!attach->importer_ops);
>  
>  	dma_resv_assert_held(dmabuf->resv);
>  
> -	if (dmabuf->ops->pin)
> +	ret = dma_buf_mapping_select(attach);
> +	if (ret)
> +		return ret;
> +
> +	if (dmabuf->ops->pin) {
>  		ret = dmabuf->ops->pin(attach);
> +		if (ret)
> +			dma_buf_mapping_unselect(attach, selected);
> +	}

dma_buf_mapping_select() sets attach->selected = true before ops->pin()
and the map callbacks run.

In patches 14/15, xe/amdgpu migrate a VRAM buffer to system memory
during pin and map when the attachment does not accept P2P.

That migration calls dma_buf_invalidate_mappings() and clears
attach->selected on every attachment, also the one being pinned/mapped. 

When the callback succeeds, the attachment stays pinned or mapped with
attach->selected == false.

A later map/pin on the same attachment can then reselect without an
invalidation.

Thanks,
Karl

  reply	other threads:[~2026-11-07  8:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  6:40 [PATCH v2 00/23] DMA-buf mapping types Alistair Popple
2026-11-05  6:40 ` [PATCH v2 01/23] treewide: Rename dma_buf_(un)map_attachment() to dma_buf_(un)map_sgt() Alistair Popple
2026-11-05  9:55   ` Christian König
2026-11-05  6:40 ` [PATCH v2 02/23] dma-buf: Introduce DMA-buf mapping types Alistair Popple
2026-11-05  6:40 ` [PATCH v2 03/23] dma-buf: Add the SGT DMA mapping type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 04/23] dma-buf: Negotiate the mapping type in dma_buf_dynamic_attach() Alistair Popple
2026-11-05  6:40 ` [PATCH v2 05/23] dma-buf: Route SGT related actions through the attachment's mapping type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 06/23] dma-buf: Let the exporter select mapping type at pin/map Alistair Popple
2026-11-07  8:57   ` Karl Mehltretter [this message]
2026-11-09  2:58     ` Alistair Popple
2026-11-09 10:59       ` Christian König
2026-11-05  6:40 ` [PATCH v2 07/23] dma-buf: Add match set queries for exporter placement decisions Alistair Popple
2026-11-05  6:40 ` [PATCH v2 08/23] dma-buf: Add dma_buf_mapping_map() returning a type-tagged mapping Alistair Popple
2026-11-05  6:40 ` [PATCH v2 09/23] dma-buf: Allow single exporter drivers to avoid the match_mapping function Alistair Popple
2026-11-05  6:40 ` [PATCH v2 10/23] drm: Check the SGT ops for drm_gem_map_dma_buf() Alistair Popple
2026-11-05  6:40 ` [PATCH v2 11/23] dma-buf: Convert all the simple exporters to use SGT mapping type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 12/23] drm/vmwgfx: Use match_mapping instead of dummy calls Alistair Popple
2026-11-05  6:40 ` [PATCH v2 13/23] accel/habanalabs: Use the SGT_P2P mapping type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 14/23] drm/xe/dma-buf: Use the SGT " Alistair Popple
2026-11-05  6:40 ` [PATCH v2 15/23] drm/amdgpu: " Alistair Popple
2026-11-05  6:40 ` [PATCH v2 16/23] vfio/pci: Change the DMA-buf exporter to use mapping_type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 17/23] RDMA/uverbs: Use the SGT_P2P mapping type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 18/23] dma-buf: Update dma_buf_phys_vec_to_sgt() to use the SGT " Alistair Popple
2026-11-05  6:40 ` [PATCH v2 19/23] iio: buffer: convert " Alistair Popple
2026-11-05  6:40 ` [PATCH v2 20/23] functionfs: " Alistair Popple
2026-11-05  6:40 ` [PATCH v2 21/23] dma-buf: Remove unused SGT stuff from the common structures Alistair Popple
2026-11-05  6:40 ` [PATCH v2 22/23] dma-buf: Add kunit tests for mapping type Alistair Popple
2026-11-05  6:40 ` [PATCH v2 23/23] dma-buf: Add kunit tests for mapping type selection Alistair Popple
2026-11-05 16:18 ` [PATCH v2 00/23] DMA-buf mapping types Maarten Lankhorst

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=au7mBMbRC8q6NILj@gmail.com \
    --to=kmehltretter@gmail.com \
    --cc=aik@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=almasrymina@google.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=apopple@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=baolu.lu@linux.intel.com \
    --cc=christian.koenig@amd.com \
    --cc=davem@davemloft.net \
    --cc=dongwon.kim@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edumazet@kernel.org \
    --cc=felix.kuehling@amd.com \
    --cc=hch@lst.de \
    --cc=horms@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=kbusch@kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sagi@grimberg.me \
    --cc=simona.vetter@ffwll.ch \
    --cc=sumit.semwal@linaro.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=treding@nvidia.com \
    --cc=vivek.kasireddy@intel.com \
    --cc=yilun.xu@linux.intel.com \
    --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