Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp811150ybk; Wed, 13 May 2020 13:49:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnfPEv2vfdfhLAKVMFqs+yyndRNOnzGmowq9Sc1MCuCxdaE5Ds866AoIW2jhVSP32qytsG X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr777464ejb.119.1589402944131; Wed, 13 May 2020 13:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589402944; cv=none; d=google.com; s=arc-20160816; b=u+fPwZLSvcygF4uiRQ0zWb2vrpaPsHG9tVtMRPLBaxlEbsaNXSAPv/0OsZj5c06FL1 5+3tHBlYM+lWxdAuWsSmbU2OTjJgWcqnsFm6NBGa4iVgI23aXclS5xudGkVeI/H18PfN p4Uk4rEgn880saIvLCIA8hY6qKSDt4jzdv8VKLLCXJBcAlg9NkieSM8j+5FC5d8lRO7Y bNh/Q11FxBw8ry/hmY9x8K3L0q3FT3RszixRuHhl56VyZwTmQvomtlKu40yxONe5k4mF pwdrFnQKsDP9Js3u4bAZgkIEYJRlpB0dSHR/j0DODaI6v8oNt8sBn9MuPrYfYiQ5CqIj Hu7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Mei1LatTmGdj+EOMqNvHhmuC380OhE62eU0mPCj4HIU=; b=LfUZ7yX94X1ly4cLXDZvq1NpnBWscld4e/DHuq9W4YQbsKygWrx0obOj0OuTNmIl7Z ts4ex/6agNK7V1E4qamdQ6z0n2BafQrhI5zkIbCgOqJr+S5hJJ3ogS7BEPOV2S5KKMd5 b8EmA8XMLrVf8CWS8IAmpaxOE8UDrBCzkFyXyh26B7QuIi//2VqfeO7XsA6GXT9CLQ0d kW/JGcmHv0IxL0netEXuyH8WV4Su/KF54HudYZaxM27yb0UH133QEkK7my5HyLBXmY4v E4aU3aPdzDjMSSpSroHuyRMBGSpZBuuixkxWAdJw7kcILo8GnTP5fjrre2kXtt5c1rod plCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=TIT8H80m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l19si550509ejq.122.2020.05.13.13.48.41; Wed, 13 May 2020 13:49:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=TIT8H80m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730575AbgEMPpO (ORCPT + 99 others); Wed, 13 May 2020 11:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbgEMPpN (ORCPT ); Wed, 13 May 2020 11:45:13 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D936C061A0E for ; Wed, 13 May 2020 08:45:12 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id 19so21808371oiy.8 for ; Wed, 13 May 2020 08:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Mei1LatTmGdj+EOMqNvHhmuC380OhE62eU0mPCj4HIU=; b=TIT8H80mk+o//K+Djr3m9ymdXjqeJJh7T1O0QGR3OB+cw9gH6v6k/2XsLqv7s+oaGI UWDF28wRCnpwGYavm+XRQfy+8o2ez7RJBPSI+LHD5tVHIt5p1Sr7uwpr2rlisGEov6IA 64dCFZ8mHEj3yDnfE1IkxFdtbSA94SYqY5inY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Mei1LatTmGdj+EOMqNvHhmuC380OhE62eU0mPCj4HIU=; b=g4IG+BXIEwni6FoVSKScfw8JnnPwc30Ma+/4nikMLbl3sPeHJBTketCcHEEZgyZYN5 s3h5XeOMChuRdOtCzkaqnhcWG7sGJrsPws2aiXXWGpfeBokZgR8N/J5GFtzwFc6+g8qq DBnnHHmvEiU2aPxTdPtm/+E/8O24bhDpUS8MHZF4gMfGD5LUIoFO+C/6p6tjHJ8p8xlv ygsNewA/F84R/vzxLOTMzq+6bxcfIobdupAL5jzkND24Xzmntd0nHPiSO3QkGRyK/J7F 9j8rIYUBgJ/4COkUFjgDBSud9sQtLsTCu7TZyzWtoTyDovzYKswtKeNzj4RHH/vSjOnH VZ9g== X-Gm-Message-State: AGi0Puazn8fMZh+PWf7e2m8k5dfxZJG4Kz4ldThHhbRmjJy3laH42ey0 Pb/ivCLObuzxwelRYzCOPUt4yu+Zsk6Zzv9CSDRb9w== X-Received: by 2002:aca:3b41:: with SMTP id i62mr9169611oia.101.1589384711122; Wed, 13 May 2020 08:45:11 -0700 (PDT) MIME-Version: 1.0 References: <20200311112004.47138-1-stevensd@chromium.org> <20200311112004.47138-2-stevensd@chromium.org> In-Reply-To: <20200311112004.47138-2-stevensd@chromium.org> From: Daniel Vetter Date: Wed, 13 May 2020 17:45:00 +0200 Message-ID: Subject: Re: [PATCH v3 1/4] dma-buf: add support for virtio exported objects To: David Stevens , Tomasz Figa Cc: Gerd Hoffmann , David Airlie , "Michael S . Tsirkin" , Jason Wang , Sumit Semwal , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Linux Kernel Mailing List , dri-devel , "open list:VIRTIO CORE, NET..." , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" , virtio-dev@lists.oasis-open.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 11, 2020 at 12:20 PM David Stevens wrote: > > 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 Adding Tomasz Figa, I've discussed this with him at elce last year I think. Just to make sure. Bunch of things: - obviously we need the users of this in a few drivers, can't really review anything stand-alone - adding very specific ops to the generic interface is rather awkward, eventually everyone wants that and we end up in a mess. I think the best solution here would be if we create a struct virtio_dma_buf which subclasses dma-buf, add a (hopefully safe) runtime upcasting functions, and then a virtio_dma_buf_get_uuid() function. Just storing the uuid should be doable (assuming this doesn't change during the lifetime of the buffer), so no need for a callback. - for the runtime upcasting the usual approach is to check the ->ops pointer. Which means that would need to be the same for all virtio dma_bufs, which might get a bit awkward. But I'd really prefer we not add allocator specific stuff like this to dma-buf. -Daniel > --- > drivers/dma-buf/dma-buf.c | 12 ++++++++++++ > include/linux/dma-buf.h | 18 ++++++++++++++++++ > 2 files changed, 30 insertions(+) > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c > index d4097856c86b..fa5210ba6aaa 100644 > --- a/drivers/dma-buf/dma-buf.c > +++ b/drivers/dma-buf/dma-buf.c > @@ -1158,6 +1158,18 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) > } > EXPORT_SYMBOL_GPL(dma_buf_vunmap); > > +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 abf5459a5b9d..00758523597d 100644 > --- a/include/linux/dma-buf.h > +++ b/include/linux/dma-buf.h > @@ -251,6 +251,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); > }; > > /** > @@ -444,4 +459,7 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, > unsigned long); > void *dma_buf_vmap(struct dma_buf *); > void dma_buf_vunmap(struct dma_buf *, void *vaddr); > + > +int dma_buf_get_uuid(struct dma_buf *dmabuf, uuid_t *uuid); > + > #endif /* __DMA_BUF_H__ */ > -- > 2.25.1.481.gfbce0eb801-goog > -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch