After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 789952 - fdmemory: need unmap if mapping flags are not subset of previous
fdmemory: need unmap if mapping flags are not subset of previous
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.12.x
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-11-06 07:19 UTC by Haihua Hu
Modified: 2018-11-03 12:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fbmemory: need unmap if mapping flags are not subset of previous (994 bytes, patch)
2017-11-06 07:19 UTC, Haihua Hu
reviewed Details | Review

Description Haihua Hu 2017-11-06 07:19:15 UTC
fbmemory: need unmap if mapping flags are not subset of previous. Suppose the first map is READ, if the second map is write, then map will goto out directly and return NULL.
Comment 1 Haihua Hu 2017-11-06 07:19:47 UTC
Created attachment 363033 [details] [review]
fbmemory: need unmap if mapping flags are not subset of previous
Comment 2 Matthew Waters (ystreet00) 2017-11-06 08:31:08 UTC
Review of attachment 363033 [details] [review]:

What's the exact sequence of events you're attempting to allow?

e.g.
gst_memory_map(READ)
gst_memory_map(WRITE)
gst_memory_unmap(READ)
gst_memory_unmap(WRITE)

or,

gst_memory_map(READ)
gst_memory_unmap(READ)
gst_memory_map(WRITE)
gst_memory_unmap(WRITE)

The first is unsupported and should return NULL.  The second is valid usage though.

::: gst-libs/gst/allocators/gstfdmemory.c
@@ +103,3 @@
+      munmap ((void *) mem->data, gmem->maxsize);
+      mem->data = NULL;
+      mem->mmap_count = 0;;

And how do we know that this is safe?  i.e. another user does not have another mapping?
Comment 3 Haihua Hu 2017-11-06 09:02:14 UTC
(In reply to Matthew Waters (ystreet00) from comment #2)
> Review of attachment 363033 [details] [review] [review]:
> 
> What's the exact sequence of events you're attempting to allow?
> 
> e.g.
> gst_memory_map(READ)
> gst_memory_map(WRITE)
> gst_memory_unmap(READ)
> gst_memory_unmap(WRITE)
> 
> or,
> 
> gst_memory_map(READ)
> gst_memory_unmap(READ)
> gst_memory_map(WRITE)
> gst_memory_unmap(WRITE)
> 
> The first is unsupported and should return NULL.  The second is valid usage
> though.

the second one actually. But dmabuf allocator set the keep mapped flag, so when do gst_memory_unmap(READ) it just return and do nothing. Which will cause the write map fail

> 
> ::: gst-libs/gst/allocators/gstfdmemory.c
> @@ +103,3 @@
> +      munmap ((void *) mem->data, gmem->maxsize);
> +      mem->data = NULL;
> +      mem->mmap_count = 0;;
> 
> And how do we know that this is safe?  i.e. another user does not have
> another mapping?
Comment 4 Nicolas Dufresne (ndufresne) 2017-11-06 16:19:34 UTC
The keep_map flag should be smarter, otherwise it's just a terribly friend. I didn't know this flag was enabled for dmabuf, it's a bit unfortunate, since it a total breakage of DMABuf usage. You must unmap if you don't implement DMA_SYNC. I'm find that patch and revert.
Comment 5 Nicolas Dufresne (ndufresne) 2017-11-06 16:22:03 UTC
I'm sorry, there is nothing to revert upstream, this flag is not set on the DMABuf allocator. Not sure why it is for you.
Comment 6 Haihua Hu 2017-11-07 01:00:52 UTC
(In reply to Nicolas Dufresne (stormer) from comment #5)
> I'm sorry, there is nothing to revert upstream, this flag is not set on the
> DMABuf allocator. Not sure why it is for you.

Sorry for that, there is an internal patch on my side which change dmabuf to keep mapped. But this is really a problem for a subclass of fbmemory which set this flags. The flag is not so smarter as we think
Comment 7 Nicolas Dufresne (ndufresne) 2017-11-07 01:20:30 UTC
Agreed, I thinks this bug report is completely valid. Maybe we could implement some "lazy" remapping when there is a transition from "keep mapped" read to "keep map" write ? We would then upgrade the map from read to readwrite ? Would that make sense ?

For anything DMABuf though, enabling this flag requires to use DMA_BUF_IOCTL_SYNC() READ/WRITE/RW accordingly around the read/write maps. Otherwise, there is a risk of loosing data that might still be on the CPU cache. The API is quite straight forward though, it's basically a 1 to 1 to map operations.
Comment 8 GStreamer system administrator 2018-11-03 12:01:14 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/396.