Commit Graph

43 Commits

Author SHA1 Message Date
Olav Haugan
b36765960a gpu: ion: Delay unmapping from IOMMU.
Due to limitations in the multimedia architecure
clients might not know when a buffer can be unmapped
from the IOMMU. In addition, the multimedia architecture
causes unnecessary mappings/unmappings for the same buffers
which reduces framerates.

Add logic to delay unmapping from the IOMMU
until buffer memory is freed and unmap any outstanding
mappings to avoid virtual memory address space leak.

Change-Id: Idaeae269d9ba623e25a0cb087a89b4cbb63915af
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-09 09:49:47 -08:00
Olav Haugan
41f8579a79 gpu: ion: Add API to do cache operations
Clients need to be able to do cache operations
on ION buffers in the kernel. Add API to
flush, invalidate, or invalidate and flush the
cache of an ION buffer.

Change-Id: I2b676dbe32372b3c17e4aaf39f51878b105a699c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-02 17:33:19 -08:00
Olav Haugan
79e9ffa55a gpu: ion: Do not allow cached IOMMU mappings.
Cached IOMMU mapping is not supported.

Add check for clients trying to map buffers
into IOMMU as cached and return error.

Change-Id: Ic63a24bf651d613933633cd81143701f66df566c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-03-02 17:33:19 -08:00
Laura Abbott
ec149ff980 gpu: ion: Fix race condition with import
Consider two threads. Thread 1 has an fd linked to an ion buffer
and Thread 2 has a handle to the same buffer. The two came from
the same client

Thread 1                    Thread 2
-----------------------------------------
ion_import_fd
ion_import
mutex_lock(&client->lock)
                            ion_free
                            ion_handle_put
                            ion_handle_destroy
                            mutex_lock(&client->lock) <--- currently locked
ion_handle_lookup
<return reference to same handle>
mutex_unlock(&client->lock)
                            acquire client lock
                            free(handle)

Thread 1 is now holding a reference to an already freed handle.
The issue arises because thread 2 is attempting to destroy the
handle but the handle still exists on the clients list of handles.
This needs to be atomic. Fix this by taking the client lock
around ion_handle_put.

CRs-Fixed: 328348
Change-Id: I3ff5e6c50b5268fd42092bc1f2b99403e5fcd3cd
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2012-01-30 01:04:11 -07:00
Olav Haugan
0fa9b60cc8 gpu: ion: Limit scope of local functions
Several functions that should not be used outside of
the ion.c file does not have static keyword. In
addition two of the functions should not be exported.

Add static keyword to functions that are local to the
translation unit and remove EXPORT_SYMBOL declarations
that are not needed.

Change-Id: Ia1ef54e3670d361c9a6d684f789be2129facb04d
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-28 17:05:16 -08:00
Olav Haugan
bd2b6925de gpu: ion: Add EXPORT_SYMBOL to functions
Several functions in the ion interface is missing
EXPORT_SYMBOL. This is needed to allow clients to
use these functions from kernel modules.

Add EXPORT_SYMBOL to functions that are supposed
to be exposed.

Change-Id: Ieb2810d85205a7492b8fe28536fb20ea090e830f
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-26 09:18:18 -08:00
Olav Haugan
6625c7d1f8 gpu: ion: Replace strncpy with strlcpy
strncpy is unsafe because it does not guarantee
that the resultant string is NULL-terminated.

Replace strncpy with strlcpy and remove explicit
NULL-termination. Also correct allocation of
string buffer.

Change-Id: Id5075ef7b04f80e2bf828f52def329b926e9ec3f
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-24 14:26:04 -08:00
Laura Abbott
e8bc7aaf98 gpu: ion: Increment the ref count in mmap
The refcount increment actually needs to happen in mmap.
Otherwise it doesn't actually happen.

Change-Id: I1043453c2c828b8658a28acea57181759b2b21f0
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2012-01-19 11:06:59 -08:00
Olav Haugan
3d4fe1ac86 gpu: ion: Refactor debugfs printing
Printing to debugfs is done from a centralized location for
all the heaps managed by ion. This architecture is not
sustainable in the long run since different heaps have different
requirements for what should be printed.

Refactor the debugfs printing for ion so that each heap is
responsible for printing its information.

Change-Id: I1dbe13432a4ab07f27ea4756c3be7fa01ad1df92
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:56 -08:00
Olav Haugan
35e2f2f14b gpu: ion: Add error message when allocation fails
Add error message when allocation from ion fails.

Change-Id: If2efa95c563c9f076b85958a70ea66afa3983325
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:47 -08:00
Olav Haugan
63e5f3bc5a gpu: ion: Fix ion client name allocation
The ion client name used for debugging were being
allocated on the stack for user space clients. This
causes the name to be garbled when later printed.

Instead, allocate the name from the heap.

Change-Id: Id299d224192f127197bef2eeb22d881b3a31795c
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:26 -08:00
Olav Haugan
b06ee07711 gpu: ion: Change ION_IOC_ALLOC ioctl return value
ION_IOC_ALLOC may incorrectly return an error pointer
which could be 0 when an allocation fails. The ioctl call from user
space expects that the function succeeded when ioctl returns 0.
Change ION_IOC_ALLOC return value to -ENOMEM when the requested
buffer could not be allocated.

Change-Id: Id9d49ffa0eb8af5defc9635f40b45351b9dd8999
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:31 -08:00
Olav Haugan
e1f5d838d1 gpu: ion: Add more debug info
Add more debug information to ion_debug_heap_show:
-Get number of allocations from heap
-Get number of user space mappings.
-Get number of kernel space mappings.
-Get indicator whether heaps has been secured or not.

Change-Id: I05491b3dd8caccfc3bbe5a9e55642e5e2cd431c4
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:28 -08:00
Olav Haugan
0a85251cd8 gpu: ion: Add support for secure buffers
Secure buffers provides a way to allow premium encrypted
multimedia content to be decrypted in a secured
memory area that does not allow for interception of the
decrypted content.

Add support for heap type that allow heap to be
used for content protection. Introduce new content
protection heap type and id's.

Change-Id: Idd56aa8805b5b74d1b9ab3fe8964aacc218668c1
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-14 22:18:45 -07:00
Laura Abbott
0f2175b51f gpu: ion: Take handle reference in ion_vma_open
When ion_vma_open is called, a reference to the handle in
the vma must be taken. Otherwise, if forking occurs,
ion_vma_close will be called twice which will leave one of
the calls with an invalid reference.

Change-Id: I9ab6e68ab6b1d2ac4bed4f45045b4b2ee39995e8
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-09 14:26:07 -08:00
Laura Abbott
eed86035d5 gpu: ion: Fix debugfs handling of multiple kernel clients
Currently, Ion registers all debugfs entries for clients
via pid. If there are multiple kernel clients, this means
the debugfs entry only gets created for the first one. Fix
this by creating debugfs entries by name always. When
creating user clients, specify the name via the pid.

Change-Id: I00cbb284d1c53b3362bb7be9c0275620a9fac167
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-08 08:39:38 -07:00
Laura Abbott
a683509211 gpu: ion: Add call back for unmapping user mappings
When mmap is called to remove a mapping, the mmap code
takes care of removing all the entries so it isn't
necessary to call unmap versions. However, there may be
cases where heaps need to do other buffer clean up when
a userspace buffer is unmapped. Add an unmap_user function
to the ion heap ops. This callback needs to happen in
vma_close, so move the decrementing of the overall user map
call back as well.

Change-Id: I8e5716774dd973828f76e03ec43e8e8ecf8c7936
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-07 15:07:01 -08:00
Laura Abbott
7716850941 gpu: ion: Incrememnt user refcount during vma_open/vma_close
Ion allows multiple mmaps of the same buffers. This means that
incrementing the usermap count in mmap and decrementing it in
release is not sufficient as release will only ever be called
once. Fix this by only doing the reference count change in the
vma_open and close which are called whenever mmap is called.

Change-Id: I6d17c0f563d0b90481d8e092c1e206f2b33c8e00
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-07 15:07:00 -08:00
Laura Abbott
8c0173668e gpu: ion: Add support for iommus
Add infrastructure to support mapping allocations
into iommus.

Change-Id: Ia5eafebee408e297013bf55284abf67d9eb8d78b
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-05 10:36:11 -08:00
Laura Abbott
e80ea017f1 gpu: ion: Add support for flushing via fd
Userspace clients pass fds around, not handles. Support flushing
via fd.

Change-Id: Ic22d9327e9fa72cb604c3010a2a6f798be8dfdb1
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-11-21 12:27:52 -08:00
Laura Abbott
e1b9ce5c22 gpu: ion: Return negative value from ioctl on allocation failure
If the ion allocation fails, return a negative value to the
ioctl. This is easier for userspace to deal with than
checking if the handle is valid.

Change-Id: I1c785b1b1e71d2bd45c6f7be78ea15e4a08cd6e5
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-11-16 07:22:40 -08:00
Laura Abbott
9fa29e8889 gpu: ion: Prevent deadlock with cache flushing
Cache flushing takes the mmap semaphore to validate the
address range. This can cause a deadlock in the following
scenario with two threads in the same client:

Thread 1			Thread 2
(cache operation)		(mmap)
-----------------------------------------
lock(client_lock)
				down_write(mmap_semaphore)
down_read(mmap_semaphore)
				lock(client_lock)

Fix this by doing the check for the address range before
taking the client lock. This is independent of Ion so there
is no need to have this lock locked.

Change-Id: Ibe372cf232fbad7e031ab2d38cf3a34823f43bf9
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-11-16 07:22:40 -08:00
Laura Abbott
404f824466 gpu: ion: Add scan for leaked userspace fds
The ION_IOC_MAP/ION_IOC_SHARE ioctls take a reference to
an ion buffer. If the fd generated by the ioctl is never
closed, the buffer will never be freed. This is a pain to
track down in userspace. Add a debugfs entry to do a scan
of all the buffers and check which ones have no handle
associated with them. If a buffer has no handle associated
with it, that means the last reference is an fd. There
isn't a good way to directly associate an fd with a buffer,
but this can at least be a starting point for tracking down
leaks.

Change-Id: I64eedd6a30d8298b2aa75532c7fad506542910f6
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-31 22:37:18 -07:00
Laura Abbott
8747bbe3e9 gpu: ion: Print debug information in hex
For consistency sake, print out debug information in hex.

Change-Id: Iccf27eca1b994bff547c812387ed756a07e9cd7b
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-31 22:37:17 -07:00
Laura Abbott
3647ac3c7e gpu: ion: Add debug information for individual heaps
Currently, the debugfs information provides aggregated data
for all carveout heaps. This isn't particularly helpful for
determining allocation problems with individual carveout heaps.
Fix this to give data for individual carveout heaps.

Change-Id: I60a10851052412e20c40f1862d6dcc22093fd982
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-31 22:37:17 -07:00
Laura Abbott
084d6eb418 gpu: ion: Add information about failed fd imports
If an fd import fails because the fd is not an Ion fd,
print out the name of the file. This way, it can be possible
to deduce where the fd came from.

Change-Id: I8464517ac011d62ebbd7e472f3e5734b0faacb0d
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-28 21:40:38 -06:00
Jordan Crouse
a75022c4e8 gpu: ion: Check for NULL pointer in client destroy
Silently check for a null pointer in ion_client_destroy

Change-Id: Ic0dedbada03496faf2eb024c40f9cfaf8d08c98f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2011-10-28 15:27:20 -06:00
Laura Abbott
273dd8e94a gpu: ion: Add API to get the buffer flags
Clients may want to know what the existing flags are on a
handle for mapping, cache flushing or other purposes. Add
an API to get those flags.

Change-Id: I2d8c93194d1fc940042529b8851ebecf35d6e3de
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-28 13:18:34 -07:00
Laura Abbott
d2a8737891 gpu: ion: Add warning during client freeing
Add warning when freeing client with buffers that are currently
mappped.

Change-Id: Ib8e17786daa7c890245c3d3e37143137cae7d078
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-28 07:54:42 -07:00
Laura Abbott
68c8064daf gpu: ion: Add better debugfs information
In debugfs, clients now show individual allocations.
Carveout heaps now give the number of bytes currently
allocated out of total possible bytes. The system heaps
just show the number of bytes currently allocated.

Change-Id: I4acfcdc1089c73c28041e09cb6b5a03b956e936a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-27 11:13:28 -07:00
Laura Abbott
cbaa6687c5 gpu: ion: Do the cache op when the buffer is cached
Only do the cache operation when the buffer is cached.
If the buffer is uncached, just return. Fixes a bug
where the cache was only being flushed when the buffer
was uncached instead of cached.

Change-Id: Ib1fa01168de79d5627b11d07c5313d19b3049145
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-25 10:06:44 -07:00
Laura Abbott
abcb6f740e gpu: ion: Add cache flushing APIs
Add ioctl to support flushing the caches of ion
buffers from userspace.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-11 09:59:30 -07:00
Laura Abbott
4b5d048a1e gpu: ion: Add O_DSYNC flag to generated file
Ion uses the O_DSYNC flag of a file to indicate an uncached mapping.
When generating a file for mmaping, the new file needs to have the
same O_DSYNC flag as the parent (the file of the ioctl open call)
to indicate if the mapping should be cached or uncached.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-04 17:14:25 -07:00
Laura Abbott
894fd58ea8 gpu: ion: Add support for cached and uncached mappings
Add explicit support for cached and uncached mappings. Functions
now describe whether mappings will be cached or uncached.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-03 16:17:38 -07:00
Iliyan Malchev
3fe24366a4 ion: minor clean up
-- init rb nodes in ion_handle_create
-- in ion_handle_destroy, check that a node belongs to a tree before removing
   it (safety check, does not happen right now)
-- mark as static functions used only inside ion.c
-- update comments to ion_share() with a relevant blurb from the implementation
-- other minor updates/typo fixes to comments

Signed-off-by: Iliyan Malchev <malchev@google.com>
2011-08-09 14:49:21 -07:00
Rebecca Schultz Zavin
c72866db6b gpu: ion: Validate handles passed via the kernel api
Before freeing or sharing handles, confirm that they
are valid in the provided client

Change-Id: I06ec599c0b277fcb5417325a12ecbf8b2d248a7b
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-07-08 15:41:32 -07:00
Rebecca Schultz Zavin
6d3b958d70 gpu: ion: Remove redunant code from ion_open
ion_client_create now does a lookup, so this need not
also be done from ion_open

Change-Id: Icb101bbf514bf2e40b4b5d9b320130bf185349aa
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-07-06 18:13:19 -07:00
Rebecca Schultz Zavin
0b7e8ae7e4 gpu: ion: Fix bug in ion client destroy
ion_client_destroy kernel api should only delete the client
if it's refcount has gone to zero.

Change-Id: Iaa662bd82d67279a9807e01f9a24aebe3d21c17d
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-07-06 18:13:17 -07:00
Rebecca Schultz Zavin
83e3dab069 gpu: ion: Fix bug in ion_client_create
If a process already had a client, ion_client_create
would loop forever.

Change-Id: I723207b5872dfc11be04ca27d38a3cf39c4a1426
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-07-01 20:57:27 -07:00
Rebecca Schultz Zavin
0db1fec422 gpu: ion: Remove incorrect error message
The function name is wrong here, and this function may
sometimes be called to see if a value passed from userspace
is an ion handle.  Since it's not really an error when it
fails, remove the log message.

Change-Id: I7bee0e7ffb72b4c4768774a3586f97e306700c21
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-06-30 19:42:36 -07:00
Rebecca Schultz Zavin
f9fb95ebc7 gpu: ion: Fix bug in ion_buffer_add
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-06-30 18:09:38 -07:00
Rebecca Schultz Zavin
e6ee124528 gpu: ion: Several fixes
Fix some cases where locks were not released on error paths
Change heap->prio to heap->id to make meaning clearer
Fix kernel doc to match sources
2011-06-30 15:15:14 -07:00
Rebecca Schultz Zavin
c80005ae9e gpu: ion: Add ION Memory Manager
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
2011-06-29 19:44:29 -07:00