Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1741778ybg; Thu, 4 Jun 2020 18:33:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjWl80RoY7t3Cgdhl5xHcNRbVlMqyx4Dze5Kgl0/NZkc3A40aikgRfospG7HIeiQ7XgnSA X-Received: by 2002:a17:906:cb97:: with SMTP id mf23mr1535082ejb.468.1591320798302; Thu, 04 Jun 2020 18:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591320798; cv=none; d=google.com; s=arc-20160816; b=TntfLREHMOFcsjddTKrMcmB2vZahoAvTUUz4HFbW7dOsZKw1KQhHP9WK0oTkoLhyR7 cEsXOatikD9jMh8e3VXWtprJseNgygANVhxos1SPwpvsLtFE9998BIC3MMUylGGk6sbU qDXNFhJMh6b7/WVXmMg6OVSbvf7SC8PlrrXtOVb6rT2SaX+VL+OHnKJUColLI3kmEVN9 ZWYKO5weU6pQv1Z2V6gHvzEUHRSahzVAvV1INCX7G1/p31aFJXAZDnW0MUEElbrTPhlY whmM1fnQBG7rTVZWrUgna366gxLXR+uH+NsFTQoKOfPtRRh5hTje1j5rGjWnpIOzogq0 uBIA== 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=y/nqmn16Yw0SQZqn88EIVGM4HFQd8IWQBv7BdFGkZBA=; b=rGXNwgDdzS/A9RAzXeWtgY31KNpqFBs1+vIgTtb2xnfPHSGDzfnWLZoDyK8Yfzi4cG Wofx7tKclj/Iesz/Sxn493TSErytaKYbg3OipmJ+wlIlCYdaXic604tOeXlj7AgJxNYr GOCCZSyvRLXtZzSsB8vv9GCfIuk20pa7bzOmhYZ6xmaQpZe+CNSQXVvb+dG1rt6dT6T9 tEksoe3u2SBK8aHv9Xte7BHhO0tCdzFTJfI0d0s3xINYm5YzcRXZjbSLbUIOcKoS7GAp ThKroJawLs9lwYfiJ6IBQ7Y69IQZnSX395JwYpn49l9FcpO/aMJS+7Ie5Wsc70Lq4GGA gdTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Djwuxcxs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si2590387ejc.94.2020.06.04.18.32.55; Thu, 04 Jun 2020 18:33:18 -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=@chromium.org header.s=google header.b=Djwuxcxs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726119AbgFEB2z (ORCPT + 99 others); Thu, 4 Jun 2020 21:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbgFEB2z (ORCPT ); Thu, 4 Jun 2020 21:28:55 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0AF0C08C5C0 for ; Thu, 4 Jun 2020 18:28:53 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id c12so8157024qkk.13 for ; Thu, 04 Jun 2020 18:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=y/nqmn16Yw0SQZqn88EIVGM4HFQd8IWQBv7BdFGkZBA=; b=Djwuxcxs7hMaNuqV5sa0Qt4loVXVD289IkhwAUeoo9toxuTynSobzLXQofFQ/mxxmA chX1YXEbRvziHsS2t9CF+sRs3hitooR08WRDXrroJv4P7KQvweF5vSAapRuCRXxcin75 AMdZf0yCjV6zh6r2M2eGqgwJQzS57I0WUDha8= 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=y/nqmn16Yw0SQZqn88EIVGM4HFQd8IWQBv7BdFGkZBA=; b=sVGtbyZKxrLcNFQWxk8V1AVDtmIB5Ee0qARd4JNi7PAneZ82J28kOLEeXDMBHtjkYW cDfjR4tzuP0B84PmnaQMdG30ZwNlOu09DZ5YQl/qsT/iBLlkIqkTIppSGKT2IoFrSMNk 287q7yoo9yva8P61CeDOucN+A07aA3vNfrzCKgYjSKZdhBSYH8At69sYP6qRXgmnOrq0 TaH4QMBD3PizUCpJIghcPqdwJP/lOfkXWzvbBfyC0XIa4eu4kp6Ij2FnIKVTGKwKgEiA QQOhtxPZ6ODj/wXuSBcIIthHmINxmlb7E7wqz0CNXAMgVaMQhZuGTvM01988rGHQfHah LbdA== X-Gm-Message-State: AOAM531cutiFHJENnBugIQ2yEgJ0cfem8Pi/yAFIOVxR4VczXZ5TZLYC 06KBI3HI9ibgWRdpBjpe2QWri3XcaYIPS3yI4LHvBw== X-Received: by 2002:a05:620a:21cc:: with SMTP id h12mr7527247qka.194.1591320533032; Thu, 04 Jun 2020 18:28:53 -0700 (PDT) MIME-Version: 1.0 References: <20200526105811.30784-1-stevensd@chromium.org> <20200526105811.30784-2-stevensd@chromium.org> <20200604145620-mutt-send-email-mst@kernel.org> In-Reply-To: <20200604145620-mutt-send-email-mst@kernel.org> From: David Stevens Date: Fri, 5 Jun 2020 10:28:42 +0900 Message-ID: Subject: Re: [PATCH v4 1/3] virtio: add dma-buf support for exported objects To: "Michael S. Tsirkin" Cc: Gerd Hoffmann , David Airlie , Daniel Vetter , Sumit Semwal , Jason Wang , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , open list , ML dri-devel , "open list:VIRTIO GPU DRIVER" , Linux Media Mailing List , "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 Fri, Jun 5, 2020 at 4:05 AM Michael S. Tsirkin wrote: > > On Tue, May 26, 2020 at 07:58:09PM +0900, David Stevens wrote: > > This change adds a new flavor of dma-bufs that can be used by virtio > > drivers to share exported objects. A virtio dma-buf can be queried by > > virtio drivers to obtain the UUID which identifies the underlying > > exported object. > > > > Signed-off-by: David Stevens > > Is this just for graphics? If yes I'd rather we put it in the graphics > driver. We can always move it later ... As stated in the cover letter, this will be used by virtio-video. The proposed virtio-video patches: https://markmail.org/thread/p5d3k566srtdtute The patch which imports these dma-bufs (slightly out of data, uses v3 of this patch set): https://markmail.org/thread/j4xlqaaim266qpks > > --- > > drivers/virtio/Makefile | 2 +- > > drivers/virtio/virtio.c | 6 +++ > > drivers/virtio/virtio_dma_buf.c | 89 +++++++++++++++++++++++++++++++++ > > include/linux/virtio.h | 1 + > > include/linux/virtio_dma_buf.h | 58 +++++++++++++++++++++ > > 5 files changed, 155 insertions(+), 1 deletion(-) > > create mode 100644 drivers/virtio/virtio_dma_buf.c > > create mode 100644 include/linux/virtio_dma_buf.h > > > > diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile > > index 29a1386ecc03..ecdae5b596de 100644 > > --- a/drivers/virtio/Makefile > > +++ b/drivers/virtio/Makefile > > @@ -1,5 +1,5 @@ > > # SPDX-License-Identifier: GPL-2.0 > > -obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o > > +obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o virtio_dma_buf.o > > obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o > > obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o > > virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o > > diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c > > index a977e32a88f2..5d46f0ded92d 100644 > > --- a/drivers/virtio/virtio.c > > +++ b/drivers/virtio/virtio.c > > @@ -357,6 +357,12 @@ int register_virtio_device(struct virtio_device *dev) > > } > > EXPORT_SYMBOL_GPL(register_virtio_device); > > > > +bool is_virtio_device(struct device *dev) > > +{ > > + return dev->bus == &virtio_bus; > > +} > > +EXPORT_SYMBOL_GPL(is_virtio_device); > > + > > void unregister_virtio_device(struct virtio_device *dev) > > { > > int index = dev->index; /* save for after device release */ > > diff --git a/drivers/virtio/virtio_dma_buf.c b/drivers/virtio/virtio_dma_buf.c > > new file mode 100644 > > index 000000000000..23e3399b11ed > > --- /dev/null > > +++ b/drivers/virtio/virtio_dma_buf.c > > @@ -0,0 +1,89 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * dma-bufs for virtio exported objects > > + * > > + * Copyright (C) 2020 Google, Inc. > > + */ > > + > > +#include > > + > > +/** > > + * virtio_dma_buf_export - Creates a new dma-buf for a virtio exported object > > + * > > + * This wraps dma_buf_export() to allow virtio drivers to create a dma-buf > > + * for an virtio exported object that can be queried by other virtio drivers > > + * for the object's UUID. > > + */ > > +struct dma_buf *virtio_dma_buf_export( > > + const struct virtio_dma_buf_export_info *virtio_exp_info) > > +{ > > + struct dma_buf_export_info exp_info; > > + > > + if (!virtio_exp_info->ops > > + || virtio_exp_info->ops->ops.attach != &virtio_dma_buf_attach > > + || !virtio_exp_info->ops->get_uuid) { > > + return ERR_PTR(-EINVAL); > > + } > > + > > + exp_info.exp_name = virtio_exp_info->exp_name; > > + exp_info.owner = virtio_exp_info->owner; > > + exp_info.ops = &virtio_exp_info->ops->ops; > > + exp_info.size = virtio_exp_info->size; > > + exp_info.flags = virtio_exp_info->flags; > > + exp_info.resv = virtio_exp_info->resv; > > + exp_info.priv = virtio_exp_info->priv; > > + BUILD_BUG_ON(sizeof(struct virtio_dma_buf_export_info) > > + != sizeof(struct dma_buf_export_info)); > > This is the only part that gives me pause. Why do we need this hack? > What's wrong with just using dma_buf_export_info directly, > and if you want the virtio ops, just using container_off? This approach provides a more explicit type signature and a little more type safety, I think. If others don't think it's a worthwhile tradeoff, I can remove it. -David