<div dir="auto"><div>Hello Guangming, Christian,<div dir="auto"><br></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 12 Oct 2021, 14:09 , <<a href="mailto:guangming.cao@mediatek.com" rel="noreferrer noreferrer noreferrer" target="_blank">guangming.cao@mediatek.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Guangming Cao <<a href="mailto:Guangming.Cao@mediatek.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">Guangming.Cao@mediatek.com</a>><br>
<br>
> Am 09.10.21 um 07:55 schrieb <a href="mailto:guangming.cao@mediatek.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">guangming.cao@mediatek.com</a>:<br>
> From: Guangming Cao <<a href="mailto:Guangming.Cao@mediatek.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">Guangming.Cao@mediatek.com</a>><br>
> ><br>
> > If dma-buf don't want userspace users to touch the dmabuf buffer,<br>
> > it seems we should add this restriction into dma_buf_ops.mmap,<br>
> > not in this IOCTL:DMA_BUF_SET_NAME.<br>
> ><br>
> > With this restriction, we can only know the kernel users of the dmabuf<br>
> > by attachments.<br>
> > However, for many userspace users, such as userpsace users of dma_heap,<br>
> > they also need to mark the usage of dma-buf, and they don't care about<br>
> > who attached to this dmabuf, and seems it's no meaning to be waiting for<br>
> > IOCTL:DMA_BUF_SET_NAME rather than mmap.<br>
> <br>
> Sounds valid to me, but I have no idea why this restriction was added in <br>
> the first place.<br>
> <br>
> Can you double check the git history and maybe identify when that was <br>
> added? Mentioning this change in the commit message then might make <br>
> things a bit easier to understand.<br>
> <br>
> Thanks,<br>
> Christian.<br>
It was add in this patch: <a href="https://patchwork.freedesktop.org/patch/310349/" rel="noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://patchwork.freedesktop.org/patch/310349/</a>.<br>
However, there is no illustration about it.<br>
I guess it wants users to set_name when no attachments on the dmabuf,<br>
for case with attachments, we can find owner by device in attachments.<br>
But just I said in commit message, this is might not a good idea.<br>
<br>
Do you have any idea?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">For the original series, the idea was that allowing name change mid-use could confuse the users about the dma-buf. However, the rest of the series also makes sure each dma-buf have a unique inode, and any accounting should probably use that, without relying on the name as much.</div><div dir="auto">So I don't have an objection to this change.</div><div dir="auto"><br></div><div dir="auto">Best,</div><div dir="auto">Sumit.</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> <br>
> ><br>
> > Signed-off-by: Guangming Cao <<a href="mailto:Guangming.Cao@mediatek.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">Guangming.Cao@mediatek.com</a>><br>
> > ---<br>
> >   drivers/dma-buf/dma-buf.c | 14 ++------------<br>
> >   1 file changed, 2 insertions(+), 12 deletions(-)<br>
> ><br>
> > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c<br>
> > index 511fe0d217a0..db2f4efdec32 100644<br>
> > --- a/drivers/dma-buf/dma-buf.c<br>
> > +++ b/drivers/dma-buf/dma-buf.c<br>
> > @@ -325,10 +325,8 @@ static __poll_t dma_buf_poll(struct file *file, poll_table *poll)<br>
> >   <br>
> >   /**<br>
> >    * dma_buf_set_name - Set a name to a specific dma_buf to track the usage.<br>
> > - * The name of the dma-buf buffer can only be set when the dma-buf is not<br>
> > - * attached to any devices. It could theoritically support changing the<br>
> > - * name of the dma-buf if the same piece of memory is used for multiple<br>
> > - * purpose between different devices.<br>
> > + * It could theoretically support changing the name of the dma-buf if the same<br>
> > + * piece of memory is used for multiple purpose between different devices.<br>
> >    *<br>
> >    * @dmabuf: [in]     dmabuf buffer that will be renamed.<br>
> >    * @buf:    [in]     A piece of userspace memory that contains the name of<br>
> > @@ -346,19 +344,11 @@ static long dma_buf_set_name(struct dma_buf *dmabuf, const char __user *buf)<br>
> >     if (IS_ERR(name))<br>
> >             return PTR_ERR(name);<br>
> >   <br>
> > -   dma_resv_lock(dmabuf->resv, NULL);<br>
> > -   if (!list_empty(&dmabuf->attachments)) {<br>
> > -           ret = -EBUSY;<br>
> > -           kfree(name);<br>
> > -           goto out_unlock;<br>
> > -   }<br>
> >     spin_lock(&dmabuf->name_lock);<br>
> >     kfree(dmabuf->name);<br>
> >     dmabuf->name = name;<br>
> >     spin_unlock(&dmabuf->name_lock);<br>
> >   <br>
> > -out_unlock:<br>
> > -   dma_resv_unlock(dmabuf->resv);<br>
> >     return ret;<br>
> >   }<br>
> >   <br>
</blockquote></div></div></div>