On 1/21/26 10:14, Leon Romanovsky wrote: > On Wed, Jan 21, 2026 at 09:59:59AM +0100, Christian König wrote: >> On 1/20/26 15:07, Leon Romanovsky wrote: >>> From: Leon Romanovsky <[email protected]> >>> >>> The .invalidate_mapping() callback is documented as optional, yet it >>> effectively became mandatory whenever importer_ops were provided. This >>> led to cases where RDMA non-ODP code had to supply an empty stub just to >>> provide allow_peer2peer. >>> >>> Document this behavior by creating a dedicated export for the >>> dma_buf_unsupported_invalidate_mappings() function. This function is >>> intended solely for the RDMA non-ODP case and must not be used by any >>> other dma-buf importer. >>> >>> This makes it possible to rely on a valid .invalidate_mappings() >>> callback to determine whether an importer supports revocation. >>> >>> Signed-off-by: Leon Romanovsky <[email protected]> >>> --- >>> drivers/dma-buf/dma-buf.c | 14 ++++++++++++++ >>> drivers/infiniband/core/umem_dmabuf.c | 11 +---------- >>> include/linux/dma-buf.h | 4 +++- >>> 3 files changed, 18 insertions(+), 11 deletions(-) >>> >>> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c >>> index cd3b60ce4863..c4fa35034b92 100644 >>> --- a/drivers/dma-buf/dma-buf.c >>> +++ b/drivers/dma-buf/dma-buf.c >>> @@ -1238,6 +1238,20 @@ void dma_buf_unmap_attachment_unlocked(struct >>> dma_buf_attachment *attach, >>> } >>> EXPORT_SYMBOL_NS_GPL(dma_buf_unmap_attachment_unlocked, "DMA_BUF"); >>> >>> +/* >>> + * This function shouldn't be used by anyone except RDMA non-ODP case. >>> + * The reason to it is UAPI mistake where dma-buf was exported to the >>> + * userspace without knowing that .invalidate_mappings() can be called >>> + * for pinned memory too. >>> + * >>> + * This warning shouldn't be seen in real production scenario. >>> + */ >>> +void dma_buf_unsupported_invalidate_mappings(struct dma_buf_attachment >>> *attach) >>> +{ >>> + pr_warn("Invalidate callback should not be called when memory is >>> pinned\n"); >>> +} >>> +EXPORT_SYMBOL_FOR_MODULES(dma_buf_unsupported_invalidate_mappings, >>> "ib_uverbs"); >>> + >> >> Well that is exactly the opposite of what I had in mind. >> >> The RDMA non-ODP case should explicitly not provide an invalidate_mappings >> callback, but only the dma_buf_attach_ops with allow_peer2peer set to true. >> >> This is done to explicitly note that RDMA non-ODP can't do invalidation's. > > We want to achieve two goals: > 1. Provide a meaningful warning to developers, rather than failing later > because dma_buf_move_notify() was called on this problematic imported > dma-buf. > 2. Require all users to supply a valid .invalidate_mapping().
Nope, that is something I would reject. invalidate_mappings must stay optional. > > If I allow empty .invalidate_mapping(), this check will go too: Correct, that is the whole idea. > 932 struct dma_buf_attachment * > 933 dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, > 934 const struct dma_buf_attach_ops *importer_ops, > 935 void *importer_priv) > ... > 943 if (WARN_ON(importer_ops && > !importer_ops->invalidate_mappings)) > 944 return ERR_PTR(-EINVAL); > > And it is important part of dma-buf. No, as far as I can see that is what we try to avoid. The whole idea is to make invalidate_mappings truly optional. Regards, Christian. > > Thanks
