From 33bff2dd91f01d83210429efe0d9fa71d844400e 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 e8ced9b3c919..1ab943a6cbf9 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1203,6 +1203,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 f26b4a8212d0..c8768297d89a 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -319,6 +319,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: *