From: Jason Gunthorpe <[email protected]> Very similar to habana, except the rejection of unsupported pci_p2p_dma_distance() is done inside map not attach via dma_buf_phys_vec_to_sgt().
Convert this directly to a SGT_P2P match which will prevent matching if dma_buf_phys_vec_to_sgt() would fail. Remove the now empty attach function. Signed-off-by: Jason Gunthorpe <[email protected]> [ rebase context change, upstream added MODULE_IMPORT_NS("DMA_BUF") - apopple ] Signed-off-by: Alistair Popple <[email protected]> --- .../infiniband/core/uverbs_std_types_dmabuf.c | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/infiniband/core/uverbs_std_types_dmabuf.c b/drivers/infiniband/core/uverbs_std_types_dmabuf.c index 2411ebee69e2..3c5c3ea2cf55 100644 --- a/drivers/infiniband/core/uverbs_std_types_dmabuf.c +++ b/drivers/infiniband/core/uverbs_std_types_dmabuf.c @@ -12,15 +12,6 @@ MODULE_IMPORT_NS("DMA_BUF"); -static int uverbs_dmabuf_attach(struct dma_buf *dmabuf, - struct dma_buf_attachment *attachment) -{ - if (!attachment->peer2peer) - return -EOPNOTSUPP; - - return 0; -} - static struct sg_table * uverbs_dmabuf_map(struct dma_buf_attachment *attachment, enum dma_data_direction dir) @@ -76,13 +67,30 @@ static void uverbs_dmabuf_release(struct dma_buf *dmabuf) uverbs_uobject_release(&priv->uobj); } -static const struct dma_buf_ops uverbs_dmabuf_ops = { - .attach = uverbs_dmabuf_attach, +static const struct dma_buf_mapping_sgt_exp_ops uverbs_dma_buf_sgt_ops = { .map_dma_buf = uverbs_dmabuf_map, .unmap_dma_buf = uverbs_dmabuf_unmap, +}; + +static int uverbs_dmabuf_match_mapping(struct dma_buf_match_args *args) +{ + struct ib_uverbs_dmabuf_file *priv = args->dmabuf->priv; + struct dma_buf_mapping_match sgt_match[1]; + + if (WARN_ON(!dev_is_pci(priv->provider->owner))) + return -EINVAL; + + sgt_match[0] = DMA_BUF_EMAPPING_SGT_P2P( + &uverbs_dma_buf_sgt_ops, to_pci_dev(priv->provider->owner)); + + return dma_buf_match_mapping(args, sgt_match, ARRAY_SIZE(sgt_match)); +} + +static const struct dma_buf_ops uverbs_dmabuf_ops = { .pin = uverbs_dmabuf_pin, .unpin = uverbs_dmabuf_unpin, .release = uverbs_dmabuf_release, + .match_mapping = uverbs_dmabuf_match_mapping, }; static int UVERBS_HANDLER(UVERBS_METHOD_DMABUF_ALLOC)( -- 2.54.0
