From 0787bdf576a8c9be24f2e1d2f460d67f50d6c45e Mon Sep 17 00:00:00 2001 From: David Stevens Date: Wed, 22 Jan 2020 15:02:33 +0900 Subject: [PATCH] FROMLIST: dma-buf: add support for virtio exported objects This change adds a new dma-buf operation that allows dma-bufs to be used by virtio drivers to share exported objects. The new operation allows the importing driver to query the exporting driver for the UUID which identifies the underlying exported object. Signed-off-by: David Stevens BUG=b:136269340 TEST=boot ARCVM and launch play store Signed-off-by: Keiichi Watanabe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2059086 Reviewed-by: Sean Paul Reviewed-by: Gurchetan Singh Tested-by: David Stevens Commit-Queue: David Stevens Bug: 153580313 Link: https://lore.kernel.org/lkml/20200311112004.47138-2-stevensd@chromium.org/ Change-Id: Ifb429e36ebbba9feead6fd1792fbefa9ca097f0c Signed-off-by: Lingfeng Yang --- drivers/dma-buf/dma-buf.c | 12 ++++++++++++ include/linux/dma-buf.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 23217e3603f2..9d755c1ca9e6 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1304,6 +1304,18 @@ int dma_buf_get_flags(struct dma_buf *dmabuf, unsigned long *flags) } EXPORT_SYMBOL_GPL(dma_buf_get_flags); +int dma_buf_get_uuid(struct dma_buf *dmabuf, uuid_t *uuid) +{ + if (WARN_ON(!dmabuf) || !uuid) + return -EINVAL; + + if (!dmabuf->ops->get_uuid) + return -ENODEV; + + return dmabuf->ops->get_uuid(dmabuf, uuid); +} +EXPORT_SYMBOL_GPL(dma_buf_get_uuid); + #ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show(struct seq_file *s, void *unused) { diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index e765b31f0a28..4aade87553e9 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -325,6 +325,21 @@ struct dma_buf_ops { void *(*vmap)(struct dma_buf *); void (*vunmap)(struct dma_buf *, void *vaddr); + /** + * @get_uuid + * + * This is called by dma_buf_get_uuid to get the UUID which identifies + * the buffer to virtio devices. + * + * This callback is optional. + * + * Returns: + * + * 0 on success or a negative error code on failure. On success uuid + * will be populated with the buffer's UUID. + */ + int (*get_uuid)(struct dma_buf *dmabuf, uuid_t *uuid); + /** * @get_flags: *