Commit Graph

16 Commits

Author SHA1 Message Date
Orjan Eide
f2bcdb43a7 ANDROID: staging: ion: Skip sync if not mapped
Only sync the sg-list of an Ion dma-buf attachment when the attachment
is actually mapped on the device.

dma-bufs may be synced at any time. It can be reached from user space
via DMA_BUF_IOCTL_SYNC, so there are no guarantees from callers on when
syncs may be attempted, and dma_buf_end_cpu_access() and
dma_buf_begin_cpu_access() may not be paired.

Since the sg_list's dma_address isn't set up until the buffer is used
on the device, and dma_map_sg() is called on it, the dma_address will be
NULL if sync is attempted on the dma-buf before it's mapped on a device.

Before v5.0 (commit 55897af630 ("dma-direct: merge swiotlb_dma_ops
into the dma_direct code")) this was a problem as the dma-api (at least
the swiotlb_dma_ops on arm64) would use the potentially invalid
dma_address. How that failed depended on how the device handled physical
address 0. If 0 was a valid address to physical ram, that page would get
flushed a lot, while the actual pages in the buffer would not get synced
correctly. While if 0 is an invalid address it cause a fault trigger a
crash.

In v5.0 this was incidentally fixed by commit 55897af630 ("dma-direct:
merge swiotlb_dma_ops into the dma_direct code"), as this moved the
dma-api to use the page pointer in the sg_list, and (for Ion buffers at
least) this will always be valid if the sg_list exists at all.

But, this issue is re-introduced in v5.3 with
commit 449fa54d68 ("dma-direct: correct the physical addr in
dma_direct_sync_sg_for_cpu/device") moves the dma-api back to the old
behaviour and picks the dma_address that may be invalid.

dma-buf core doesn't ensure that the buffer is mapped on the device, and
thus have a valid sg_list, before calling the exporter's
begin_cpu_access.

Bug: 155685387

Change-Id: Ie4da5a875957c831ce5b1345b5794357b844c84c
Signed-off-by: Orjan Eide <orjan.eide@arm.com>
Signed-off-by: Anders Pedersen <anders.pedersen@arm.corp-partner.google.com>
(cherry picked from commit 644ae915cd5df31179144c5b949539520a14f39a)
2020-06-09 20:16:59 +00:00
Suren Baghdasaryan
58d1f13b9e ANDROID: staging: android: ion: Expose total heap and pool sizes via sysfs
Add sysfs attributes to track ion total heap and pool memory allocations.
The following sysfs attributes are added:

/sys/kernel/ion/total_heaps_kb
/sys/kernel/ion/total_pools_kb

Bug: 138148041
Bug: 154238995
Test: adb shell cat /sys/kernel/ion/*
Change-Id: If92770dc3389af865c619525f04d3ba0e013b244
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2020-04-21 22:17:30 +00:00
Hyesoo Yu
4e8ed5ad98 ANDROID: staging: ion: move definition of attachment
The ion_dma_buf_attachment definition that is connected
to attachment of ion_buffer is used by dma buf ops.
However this definition should be available for heap's
dma buf ops as well as for built-in dma buf ops.
Therefore we move this definition to the ion header.

Bug: 151780326

Signed-off-by: Hyesoo Yu <hyesoo.yu@samsung.com>
Change-Id: Ib3023e29f48b1e2502f8d750af6645f65f6eea40
(cherry picked from commit 7e27ee5fc8)
Signed-off-by: Hridya Valsaraju <hridya@google.com>
2020-04-06 16:36:26 +00:00
Hridya Valsaraju
0a6517f730 ANDROID: staging: ion: Add an in-kernel interface to request heap info.
Add an API to allow in-kernel clients to request heap ID info.

Test: make
Bug: 149961819

Change-Id: I59d26355115f100a60bcf8ade0e3afa4b89c5d0a
Signed-off-by: Hridya Valsaraju <hridya@google.com>
2020-03-06 00:40:13 +00:00
Lecopzer Chen
524fcca39b staging: android: ion: Remove unused rbtree for ion_buffer
Re-apply commit 3e6998b17f ("staging: android: ion: Remove unused
rbtree for ion_buffer") which has been inadvertently and partly reverted
by merge commit bfa0399bc8
("Merge Linus's 5.4-rc1-prerelease branch into android-mainline").
Later, the following two commits completed the incomplete revert:

commit c8e152bc7d ("ANDROID: staging: ion: Fix missing entry in
kerneldoc header")
commit f9aa2c6071 ("ANDROID: ion: Fix buffer_lock mutex
initialization")

This commit re-applies the original commit, i.e. it removes the unused
rbtree again.

ion_buffer_add() insert ion_buffer into rbtree every time creating
an ion_buffer but never use it after ION reworking.
Also, buffer_lock protects only rbtree operation, remove it together.

Change-Id: I56cc75fbc84d7412fb4d090f577b5d4a6980b879
Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
Cc: YJ Chiang <yj.chiang@mediatek.com>
Cc: Lecopzer Chen <lecopzer.chen@mediatek.com>
Acked-by: Laura Abbott <labbott@redhat.com>
Link: https://lore.kernel.org/r/20190712084717.12441-1-lecopzer.chen@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-18 16:27:22 -08:00
Vincent Donnefort
b2117ae840 ANDROID: ion: flush cache before exporting non-cached buffers
The memory allocated from the page pool might be in the CPU cache, as the
zeroing can have been done through cache. e.g GFP_ZERO, or if the buffer
was used as cached memory previously. To map this memory as non-cached, we
need to flush the CPU cache first, to avoid any memory corruption when the
corresponding dirty cache line gets evicted.

A proper fix would be to flush the cache using the Linux DMA API. The
problem is that the buffer can be used without a device attached, which is
not covered since the introduction of:

  commit 1dccb598df ("arm64: simplify dma_get_ops")

This patch is then a dirty fix, calling directly cache flush function, to
cover the export of non-cached to an ION client. It ensures that the cache
line is actually cleaned before the memory is used as non-cached.

Change-Id: I9179c2f644a29ae71820c4ae63c880195f55e45d
Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com>
2019-12-12 21:23:03 +00:00
Todd Kjos
c8e152bc7d ANDROID: staging: ion: Fix missing entry in kerneldoc header
The kerneldoc header for struct ion_buffer was missing an
entry for @node which does exist in the rebase version of
android-mainline.

Change-Id: I230b90a2a38bbaf9af39ac0c03af55e2bdf2e133
Signed-off-by: Todd Kjos <tkjos@google.com>
2019-10-03 16:15:34 -07:00
Greg Kroah-Hartman
bfa0399bc8 Merge Linus's 5.4-rc1-prerelease branch into android-mainline
This merges Linus's tree as of commit b41dae061b ("Merge tag
'xfs-5.4-merge-7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux")
into android-mainline.

This "early" merge makes it easier to test and handle merge conflicts
instead of having to wait until the "end" of the merge window and handle
all 10000+ commits at once.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I6bebf55e5e2353f814e3c87f5033607b1ae5d812
2019-09-20 16:07:54 -07:00
Sandeep Patil
2b4444ffaf staging: ion: export ion_free() for ion_heaps.
ion_free() is a generic function needed to release
an ion buffer back to the heap. So, export it for the
heap module.

Bug: 140294230
Test: ion-unit-tests

Change-Id: Iaa467ab3df18fa219412dd9f5913cd022a93455d
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-09-10 05:13:51 -07:00
Sandeep Patil
8eb89f277e ANDROID: staging: ion: Remove unnecessary ion heap ops
The heap operations are redundant now that we have default
dma_buf operations. So, remove them.

Bug: 133508579
Bug: 140290587
Test: ion-unit-tests

Change-Id: I8f87c22896e128f48ed222421cabc23ab238ff69
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-09-03 10:36:20 -07:00
Sandeep Patil
296ba13074 ANDROID: staging: ion: Add support for heap-specific dma_buf_ops
All dma_buf ops are registered by ion core. However, if a given heap
provides a specific dmabuf operation, that will be preferred over the
default ion core implementation

Some dma_buf_ops like get_flags, begin_cpu_access_partial etc are
entirely not supported by ion core and will return -EOPNOTSUPP if the
heap implementation doesn't provided the necessary overrides.

Tested with ion unit test with default system heap.

Bug: 133508579
Bug: 140290587
Test: ion-unit-test

Change-Id: Id13c5c280064b6f47de327223733c2c393f1a41a
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-09-03 10:36:20 -07:00
Sandeep Patil
89791c3f3b ANDROID: staging: ion: move uapi/ion.h to uapi/linux/ion.h
Bug: 133508579
Test: builds

Change-Id: I599a78e1acd2eed909f40e5a5b6a62813610990c
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-08-30 10:14:22 -07:00
Sandeep Patil
d872160f11 staging: ion: make system and contig heaps modular
Add symmetric heap add/remove APIs and export symbols from
ion core that are needed to make both heaps modular.

Bug: 133508579
Test: ion-unit-test, rmmod, modprobe

Change-Id: Ic5f40936531936c9bfab48ea147108c019d28e2c
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-08-19 11:20:00 -07:00
Sandeep Patil
91d0bbda91 staging: ion: refactor ion's heap API into linux/ion.h
Now that we know the APIs needed by system and cma heaps,
refactor and move all those into linux/ion.h.

Unfortunately, the UAPI of ion is now split into linux/ion.h
and drivers/staging/android/uapi/ion.h since some of the UAPI
leaks into heap implementation (ion flags). It can all be moved
into linux/ion.h eventually for all android kernels.

Bug: 133508579
Test: ion-unit-tests

Change-Id: I73ea59b410c46a02e23f2da5c6bdc15182a50b32
Co-developed-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-08-19 11:19:49 -07:00
Sandeep Patil
144555039f staging: ion: refactor ion's dmabuf manipulators into a separate file.
This patch is preparatory work for making ion heaps modular. The patch
itself doesn't make any significant changes except for re-organizing the
buffer manipulator functions in a single file. This will be helpful
later when we specifically export some of these functions to be used by
a heap module.

Bug: 133508579
Test: ion-unit-tests

Change-Id: I52ecea78a179c936006a21beb7630009984cb22f
Co-developed-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-08-19 11:19:49 -07:00
Isaac J. Manjarres
389e2406d3 ANDROID: staging: android: ion: Expose ion_alloc() to kernel space
Expose ion_alloc() to kernel space clients. Users of this
function will receive a dma-buf structure for sharing
the ION buffer that was allocated.

Bug: 133508579
Test: ion-unit-tests
Change-Id: I410044127ba92a759a79c65e422b0b75b74e2159
Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Signed-off-by: Sandeep Patil <sspatil@google.com>
2019-08-01 07:18:48 -07:00