Commit Graph

64 Commits

Author SHA1 Message Date
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
cb9ad9ead5 gpu: ion: Add decrement of mapping count
Add decrement of mapping count when mapping fails
and corresponding SMI release region call.

Change-Id: I81fb7eeee9973c770a65f02236c5358ce313e3a0
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:15 -08:00
Olav Haugan
9b2d1c2f8c gpu: ion: Clean up logging messages
Remove duplicate logging message for failure to create
a heap. Add logging message with name, base address, and
size of each heap created.

Change-Id: Id3a3706d914ffa72b0ecd84eb98785a678ceda9a
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:41:04 -08:00
Olav Haugan
41cf3e3363 gpu: ion: Fix SCM call message size
The SCM call message size used to protect and
unprotect memory is incorrect. The interface expects
13 bytes but 16 bytes is sent due to padding of the
message struct.

Pack the message structure to force the size of the
structure to 13 bytes.

Change-Id: Iecb7b40aa7e94454620c19cd70c3106392d2d311
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:40:53 -08:00
Olav Haugan
42ebe71efc gpu: ion: Add support for adjacent heaps
ION has to guarantee that two of the heaps are
adjacent to each other. This is due to a limitation
in the hardware. Add code to ensure these heaps
are adjacent.

Change-Id: Icc18437a50e1d872112468d02b61ab47fd70acc9
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-18 16:40:39 -08:00
Olav Haugan
0703dbf608 gpu: ion: Refactor platform data
Refactor platform data to allow for better
expansion in the future. Add void * for
elements unique to each heap type.

Change-Id: I435679819c67ce917b5798009eff7e71047fd2ea
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:35 -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
5e56021d35 gpu: ion: Add missing iommu heap destroy call
When a heap is destroyed a heap type specific
function is called to release memory that the heap
structures used. A case statement handling destroying
the iommu heap is missing. Add missing case statement.

Change-Id: I1aa54209a55db06becc570f65ecf0f740d2e9545
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-15 09:30:25 -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
Olav Haugan
7fba5cf795 gpu: ion: Add missing gen_pool_destroy call
If the carveout heap fails to be created the pool needs to
be destroyed.

Change-Id: I73f768d79a11aacd2161b079db9621264d14d2ad
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2012-01-10 16:45:32 -08:00
Olav Haugan
ee0f780d78 board: 8660: Add callbacks to request_region
Callbacks to request_region, release_region,
setup_region is missing from ION platform data for
SMI heap.

Change-Id: Ida603d4ac7c3246c0deedb9b80dc0c1ea64638eb
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2011-12-21 16:32:08 -08: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
Linux Build Service Account
13605e484b Merge "gpu: ion: Check for release/request functions before calling" into msm-3.0 2011-12-08 14:54:13 -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
b866d75946 gpu: ion: Check for release/request functions before calling
Not all heaps will implement the release/request callbacks. Check those
function pointers are valid before calling.

Change-Id: I848e31495e45c7eaa4497b82be590d291d77980a
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-07 10:48:17 -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
ceee3d25d5 gpu: ion: Map only the vma size given
When mapping carveout buffers into userspace, only map
the size of the vma given, not the full size of the buffer
since clients may map less than the buffer size.

Change-Id: Idf1d1ee5850c0f7045c0f78bfd5841a76db90a34
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-12-03 05:44:33 -07:00
Alex Bird
8a3ede3801 gpu: ion: Add callbacks to enable SMI voting in ION.
This change is part of the move from PMEM to ION. ION needs an SMI
voting interface smiliar to PMEM's.

Change-Id: I18888f46198848694fb7e1e0d2671074bf51d7c9
Signed-off-by: Alex Bird <alexbird@codeaurora.org>
2011-12-01 17:45:22 -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
Olav Haugan
1a304b5ad6 gpu: ion: Make ion heap error handling consistent
If an error occurs during heap creation the behavior is different
depending on the error condition. If memory cannot be allocated
for the heap the rest of the heaps will be created. However, if
the ion heap cannot be created heap creation stops and all the heaps
are destroyed. Make the error handling consistent for both error
conditions by logging an error message and continuing creation
of the rest of the heaps.

General cleanup: Change global variables to be local to this
translation unit.

Change-Id: Ia8d2fb2f3257b91d6423b6722e12e9b3d7792e86
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2011-11-03 10:35:28 -07:00
Jordan Crouse
0a1195ece6 gpu: ion: Add map/unmap DMA ops for carveout heap
Change-Id: Ic0dedbad2a092c6b9dc9778d26f6315054520a63
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2011-11-02 00:50:08 -06: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
d16dd60d32 gpu: ion: Add message about fragmentation
If memory is fragmented, an allocation may fail even if
there is sufficient memory. Detect this state if it occurs
and note it in the logs.

Change-Id: Ia0471ba3f231c8538449f3f842f157a1128ebd38
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-31 22:36:59 -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
5ee3921e4c gpu: ion: Actually return aligned memory
Currently, the ion allocation API takes an alignment
argument. This alignment argument is currently ignored
everywhere. The system heaps cannot support the alignment
argument, but carveout heaps can. Add support for carveout
heaps to give back aligned memory.

Change-Id: Ic4cff37a7de51e1c85e273c2589958f7f13c33c9
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-15 11:59:11 -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
354120303a gpu: ion: Add IS_CACHED macro
Add a proper IS_CACHED macro for detecting whether or not
flags indicated a cached mapping.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-11 09:59:25 -07:00
Laura Abbott
f4c973de77 gpu: ion: Move initialization earlier
Ion needs to be initialized before most other subsystems.
Move the call to be earlier to ensure drivers that need to
allocate memory at bootup can.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-04 17:14:31 -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
e8f280253c gpu: ion: Fix cached and uncached mapping in carveout heap
When the cached flag is set, ioremap_cached should be called.
When the cache flag is not set, ioremap should be called.

Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2011-10-04 17:14:24 -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