Commit Graph

783 Commits

Author SHA1 Message Date
Sebastiano Barezzi
fcedce48bf Merge remote-tracking branch 'qcom_sm8250/lineage-20' into lineage-22.2
Change-Id: I41d3b2e791439f1ef1d34ced81a40912461bb3b0
2025-04-02 13:37:55 +02:00
Yabin Cui
b3b4b3bcd6 msm: kgsl: introduce CONFIG_CORESIGHT_ADRENO.
We want to build coresight drivers as builtin drivers. But
adreno-coresight.c in msm_adreno.ko calls coresight functions.
To avoid exporting new symbols in vmlinux and breaking the ABI, this
patch separates adreno-coresight.c into CONFIG_CORESIGHT_ADRENO.
CONFIG_CORESIGHT_ADRENO is only enabled when both coresight and adreno
are builtin drivers.

Bug: 167414982
Bug: 170753932
Signed-off-by: Yabin Cui <yabinc@google.com>
Change-Id: I7488293445ade738ba03cc457320e0d74f910886
2025-03-15 11:43:26 +05:45
althafvly
bac62ca790 Merge branch 'lineage-20' of https://github.com/LineageOS/android_kernel_qcom_sm8250 into lineage-22.1
Change-Id: Ib5c234d95e3f41cfa458ac48d666fbab920b0b6e
2025-01-05 09:32:08 +05:30
Rakesh Naidu Bhaviripudi
02a3be4cf2 msm: kgsl: Fix error handling during drawctxt switch
Currently, separate submissions are made for page table
switch and context switch to the ring buffer. However, if
the page table switch succeeds but the context switch fails,
it can lead to use of wrong page table for drawctxt.

To address this issue, submit page table switch and context
switch commands as a single submission to ring buffer.

Also, remove the unnecessary ADRENO_DEVICE_FAULT check and
correctly put the refcount of adreno context during error
cleanup.

Change-Id: I1bb4ee3ebb0ce6ea32f0b6799cfb7fa89c0d09c7
Signed-off-by: Rakesh Naidu Bhaviripudi <quic_rakeshb@quicinc.com>
(cherry picked from commit fe4cb13a78)
2024-07-16 04:23:04 -07:00
qctecmdr
63b678c6fe Merge "msm: kgsl: Fix upper bound check for iommu address" 2024-03-27 02:58:05 -07:00
Sebastiano Barezzi
d444b6a698 Merge remote-tracking branch 'qcom_sm8250/lineage-20' into lineage-20
Change-Id: I9bb5e8c56e01150638996fecd9dfed2bd7c428c6
2024-03-25 15:37:28 +01:00
Sebastiano Barezzi
25975eb79d Merge remote-tracking branch 'qcom_sm8250/lineage-20' into lineage-20
Change-Id: I8d0a8bc8101febe5e93dc2952f736080c5ee54c4
2024-02-19 18:41:48 +01:00
Sebastiano Barezzi
0c13f6583a Merge remote-tracking branch 'qcom_sm8250/lineage-20' into lineage-20
Change-Id: Ic572f479a072cb0252d5682f6cd56c3499fe3286
2024-02-13 00:46:27 +01:00
Lynus Vaz
b209a01620 msm: kgsl: Do not release dma and anon buffers if unmap fails
If iommu unmap fails and leaves dma or anon buffers still mapped in the
iommu, do not free them.

Change-Id: Ice0e1a59c1ac0ee7a9d62d8899966b84fa63d5ca
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
(cherry picked from commit ab27a52cf1)
2024-02-04 17:43:28 -08:00
qctecmdr
17bda50f8a Merge "msm: kgsl: Do not release dma and anon buffers if unmap fails" 2024-02-04 08:59:25 -08:00
Lynus Vaz
ab27a52cf1 msm: kgsl: Do not release dma and anon buffers if unmap fails
If iommu unmap fails and leaves dma or anon buffers still mapped in the
iommu, do not free them.

Change-Id: Ice0e1a59c1ac0ee7a9d62d8899966b84fa63d5ca
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
2024-01-31 11:44:37 +05:30
Lynus Vaz
69df853d40 msm: kgsl: Keep the timeline fence valid for logging
The timeline fence needs to remain valid for logging purposes. Take an
extra refcount on the timeline dma_fence to make sure it doesn't go
away till we're done with it.

Change-Id: I6670ef7add099a72684c1fe20ed009dff85d1f27
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
2024-01-31 11:35:01 +05:30
Pankaj Gupta
f2f1efbbc2 msm: kgsl: Fix upper bound check for iommu address
kgsl_iommu_addr_in_range() incorrectly checks the virtual address range,
fix this by updating upper bound condition.

Change-Id: I7e443c51be723b70b6367c8d9c75480b2762fe1c
Signed-off-by: Pankaj Gupta <quic_gpankaj@quicinc.com>
2024-01-30 22:51:18 +05:30
Kaushal Sanadhya
88bb532b43 msm: kgsl: Do not free sharedmem if it cannot be unmapped
If sharedmem cannot be unmapped from the mmu, it can still be accessed
by the GPU. Therefore it is not safe to free the backing memory. In the
case that unmap fails, do not free it or return it to the system.

Change-Id: Iad3e86d043f129a4d71cf862865d9033d4a315e3
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
Signed-off-by: Kaushal Sanadhya <quic_ksanadhy@quicinc.com>
2023-11-30 00:05:10 +05:30
qctecmdr
89f31c162e Merge "msm: kgsl: Prevent wrap around during user address mapping" 2023-09-29 20:25:07 -07:00
Kaushal Sanadhya
1e46e81dbe msm: kgsl: Limit the syncpoint count for AUX commands
KGSL internally has a limit on the length of the list of syncpoints
submitted in a single AUX command. Enforce this limit so we don't
overwrite memory beyond the structures that track these syncpoints.

Change-Id: I261bfd4f786ff7e4fbe07e8bca9e9b8d8b87c950
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
Signed-off-by: Kaushal Sanadhya <quic_ksanadhy@quicinc.com>
2023-09-28 21:06:27 -07:00
Mohammed Mirza Mandayappurath Manzoor
d66b799c80 msm: kgsl: Prevent wrap around during user address mapping
When setting svm region during the gpuobj import ioctl call for a usermem
address, there is a possibility of a very large input size causing the
region's 64-bit end address to wrap around. This can cause the region
to incorrectly be considered valid, ultimately allowing a use after free
scenario. To prevent this, detect the occurrence of a wrap and reject the
import.

Change-Id: I4a88f56c58b830d4342e47dc1d1f6290c78ab6b4
Signed-off-by: Mohammed Mirza Mandayappurath Manzoor <quic_mmandaya@quicinc.com>
Signed-off-by: Puranam V G Tejaswi <quic_pvgtejas@quicinc.com>
2023-09-28 21:06:21 -07:00
SIVA MULLATI
2bac75def2 msm: kgsl: Defer drawobj_sync_timeline_fence_work() to a workqueue
drawobj_sync_timeline_fence_work() does a cleanup of fence and syncobj
allocations. Doing this cleanup in irq context requires the irq_work
struct to remain valid after the function executes. Avoid this constraint
by deferring this work to the memory workqueue.

Change-Id: Icf648a61686c1ef3fd84467a2376b11a9a4bb803
Signed-off-by: Lynus Vaz <quic_lvaz@quicinc.com>
Signed-off-by: SIVA MULLATI <quic_smullati@quicinc.com>
2023-07-26 23:06:49 +05:30
Sebastiano Barezzi
231d12aa69 Merge remote-tracking branch 'qcom_sm8250/lineage-20' into lineage-20
Change-Id: I6d6e6fa0e8a40b75433926b887253f77da823bb3
2023-05-14 18:23:37 +02:00
Rakesh Naidu Bhaviripudi
6f98a7970d msm: kgsl: Fix buffer overflow while capturing memory entries
We calculate the number of memory entries of a process first
to make sure we have enough memory. When saving the entries,
we use the ID of the entry as an array index. This can result
into array out of bound access as ID can be greater than
the number of memory entries calculated earlier.
Fix this by using the right array index.

Change-Id: I915e565330c21a2604354a05592ae15d62991617
Signed-off-by: Rakesh Naidu Bhaviripudi <quic_rakeshb@quicinc.com>
Signed-off-by: Hemasri Yallanki <quic_hyallank@quicinc.com>
2023-05-09 16:32:47 +05:30
Kamal Agrawal
fbca1995ab msm: kgsl: Do not capture DTCM on gmu boot failure
Accessing DTCM can cause NoC error sometimes if GMU is accessing
any of its TCMs at the same time as host.

Change-Id: I3d7a3169620854dbd659f378c216a7b15435c914
Signed-off-by: Harshdeep Dhatt <hdhatt@codeaurora.org>
Signed-off-by: Kamal Agrawal <quic_kamaagra@quicinc.com>
2023-04-21 12:47:55 +05:30
Akhil P Oommen
8ab46b7b2c msm: kgsl: Keep postamble packets in a privileged buffer
Postamble packets are executed in privileged mode by gpu. So we should keep
them in a privileged scratch buffer to block userspace access. For
targets with APRIV feature support, we can mark the preemption scratch
buffer as privileged too to avoid similar issues in future.

Change-Id: Ifda360dda251083f38dfde80ce1b5dc83daae902
Signed-off-by: Akhil P Oommen <quic_akhilpo@quicinc.com>
Signed-off-by: Kaushal Sanadhya <quic_ksanadhy@quicinc.com>
2023-03-29 12:11:01 +05:30
qctecmdr
ab395d7782 Merge "msm: kgsl: move kgsl shmem pages to unevictable list" 2023-03-07 06:07:59 -08:00
Sebastiano Barezzi
733a275a27 drivers: gpu: msm: Import Xiaomi changes
* From dagu-s-oss

Change-Id: Iae705abbfe166666dd571c4a653dc350bd2ad595
2023-03-01 19:39:28 +01:00
Charan Teja Kalla
6166a0a749 msm: kgsl: move kgsl shmem pages to unevictable list
Kgsl shmem pages are always pinned but still endup in the evictable lru
leading to inteference with the reclaim logic making the later spending
more time in scanning the pages. This time can result into the PSI
events generation leading to oom/lmkd logic to take the wrong
decissions. Move such pages to unevictable LRU thus kept out of the
reclaimable list.

Change-Id: Iee82ce101526f04a8f294a10dce9598356701977
Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
2023-03-01 15:42:51 +05:30
qctecmdr
9e6c9ab4fc Merge "msm: kgsl: Use dma_buf_get() to get dma_buf structure" 2023-02-21 01:15:17 -08:00
Puranam V G Tejaswi
86695e1dd1 msm: kgsl: Use dma_buf_get() to get dma_buf structure
Currently we don't ensure if vma->vm_file is associated with dma_buf. This
can cause issues later when private_data from a non dma_buf file is used as
dma_buf structure. Hence get the fd that is associated with vma->vm_file
and use dma_buf_get() to get pointer to dma_buf structure. dma_buf_get()
ensures that the file from the input fd is associated with dma_buf.

Change-Id: Ib78aef8b16bedca5ca86d3a132278ff9f07dce73
Signed-off-by: Puranam V G Tejaswi <quic_pvgtejas@quicinc.com>
2023-02-17 14:18:42 +05:30
Kamal Agrawal
9968fcdd9d msm: kgsl: Make sure that pool pages don't have any extra references
Before putting a page back in the pool be sure that it doesn't have
any additional references that would be a signal that somebody else
is looking at the page and that it would be a bad idea to keep it
around and run the risk of accidentally handing it to a different
process.

Change-Id: Ic0dedbad0cf2ffb34b76ad23e393c5a911114b82
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Kamal Agrawal <quic_kamaagra@quicinc.com>
2023-02-16 18:24:08 +05:30
Pranav Patel
3d7bc844b2 msm: kgsl: use kvcalloc for ringbuffer submission
kcalloc returns out of memory in low memory conditions even if memory
is available in non-contiguous manner. This results in failure to
submit commands to ringbuffer. Use kvcalloc in place of kcalloc so
that when kcalloc fails in low memory conditions, commands can be
submitted if kvcalloc can provide enough memory.

Change-Id: If6a20e35983982b5c0888e5f7dabecfa8c026bcb
Signed-off-by: Pranav Patel <quic_pranavp@quicinc.com>
2022-08-11 18:45:52 +05:30
Pranav Patel
66e3c113f8 msm: kgsl: Use consolidated power level for thermal limit
Ensure that thermal limits set by devfreq cooling framework,
limits framework and sysfs nodes (like gpu_max_clock) don't
overwrite each other, instead a consolidated (lowest of all)
limit is used as a final thermal limit. If this fails, fall back
to setting thermal_pwrlevel directly.

Change-Id: Ia6ec60e4881176da064c3cd5cf4ffd8e0a8e1046
Signed-off-by: Pranav Patel <quic_pranavp@quicinc.com>
2022-08-09 17:14:58 +05:30
ravnar
a08c2a18fb msm: kgsl: Remove 'fd' dependency to get dma_buf handle
Get the dma_buf handle directly from 'vm_file' after
doing necessary checks on the file.

Change-Id: Id5eec16588d64e4e28483b32bb52d4d3d9b86b99
Signed-off-by: ravnar <quic_ravnar@quicinc.com>
Signed-off-by: Sanjay Yadav <quic_sanjyada@quicinc.com>
Signed-off-by: Kaushal Sanadhya <quic_ksanadhy@quicinc.com>
2022-05-17 11:20:54 +05:30
Rohan Sethi
7d6b043520 msm: kgsl: Use copy_struct_from_user() helper
Timeline semaphore ioctls use local implementation
kgsl_copy_struct_from_user() to validate and copy structs from
user to kernel memory. This can cause problem when user size is
greater than reserved kernel struct size.
Replace this with new kernel implementation of copy_struct_from_user()
helper to ensure correct alignment and access permissions before
proceeding forward.

Change-Id: I5891f355fe515e271c7470543822792572a42f3f
Signed-off-by: Rohan Sethi <quic_rohsethi@quicinc.com>
2022-05-03 09:11:38 -07:00
qctecmdr
ff1d8f6a04 Merge "msm: kgsl: Remove unnecessary NULL checks" 2022-04-25 11:51:33 -07:00
Puranam V G Tejaswi
70dce4b456 msm: kgsl: Assign a default value to the variable ret
Currently there is a chance that the variable ret can be
used uninitialized in kgsl_reclaim_callback. Assign a default
value to ret to avoid this.

Change-Id: I90014370773ee2a6594ee624f890fead955e6f76
Signed-off-by: Puranam V G Tejaswi <quic_pvgtejas@quicinc.com>
2022-04-08 12:39:29 -07:00
Puranam V G Tejaswi
56f6d40f20 msm: kgsl: Remove unnecessary NULL checks
Currently there are a few unnecessary NULL checks for pointers to
kgsl_drawobj_sync_event. The pointers will always be valid at
these points and are moreover already accessed in the same functions
prior to the NULL checks. Hence remove the unnecessary NULL checks.

Change-Id: I65197ea8ad4df7b28445a95165bf4b57f735a6d8
Signed-off-by: Puranam V G Tejaswi <quic_pvgtejas@quicinc.com>
2022-04-09 00:27:23 +05:30
Mohammed Mirza Mandayappurath Manzoor
48274fac0a msm: kgsl: Zap performance counters across context switches
Performance counter values need not be retained across contexts unless
specifically requested for debug. Zap the counters by initialising
perfcounter SRAM with 0's using GPU_RBBM_PERFCTR_SRAM_INIT_CMD.

Add pm4 packets during context switches and add a KMD postamble packet to
clear the counters during preemption. Do not enable perfcounter save and
restore unless requested.

Change-Id: I371779ce659c07a1cc664327f5ecdcf0374201d8
Signed-off-by: Mohammed Mirza Mandayappurath Manzoor <quic_mmandaya@quicinc.com>
Signed-off-by: Harshitha Sai Neelati <quic_hsaineel@quicinc.com>
2022-03-05 04:52:52 -08:00
Mohammed Mirza Mandayappurath Manzoor
4c9d42b9ad msm: kgsl: Add a sysfs node to control performance counter reads
Currently performance counters are global and can be read by anyone. Change
the behaviour to disable reading global counters as default and add a sysfs
node to enable/disable reads.

Change-Id: Ic3785acd9bd7425c2a844ed103d7b870d9f80adf
Signed-off-by: Mohammed Mirza Mandayappurath Manzoor <quic_mmandaya@quicinc.com>
Signed-off-by: Harshitha Sai Neelati <quic_hsaineel@quicinc.com>
2022-03-05 04:52:02 -08:00
Puranam V G Tejaswi
29ff744a77 msm: kgsl: Perform cache flush on the pages obtained using get_user_pages()
Consider a scenario where user allocates anonymous memory but does not
write to it. Here the physical pages are not yet allocated. Now when this
memory is requested to be imported, a list of newly allocated zero pages
is obtained using get_user_pages(). Currently cache flush is not done for
these pages and hence GPU sees stale data. Fix this by performing cache
flush on these pages.

Change-Id: Id1e8aa20e8a9de112761732ed92f30c01088840b
Signed-off-by: Puranam V G Tejaswi <quic_pvgtejas@quicinc.com>
2022-01-18 13:32:07 +05:30
Rohan Sethi
29434905a4 msm: kgsl: Fix gpuaddr_in_range() to check upper bound
Currently gpuaddr_in_range() accepts only the gpuaddr & returns
true if it lies in valid range. But this does not mean that the
entire buffer is within range.
Modify the function to accept size as a parameter and check that
both starting & ending points of buffer lie within mmu range.

Change-Id: I1d722295b9a27e746bfdb6d3bf409ffe722193cb
Signed-off-by: Rohan Sethi <quic_rohsethi@quicinc.com>
2021-12-30 15:55:28 +05:30
Puranam V G Tejaswi
2959ed5eb8 msm: kgsl: Signal fence only if last fence refcount was not put
Currently there is a chance that release for the fence was already called
before we call dma_fence_get during kgsl_timeline_signal and
kgsl_ioctl_timeline_destroy. This can cause use-after-free issue as we can
access fence after release. Fix this by signalling fence only if the last
refcount on the fence was not yet put. This makes sure that release for the
fence will not be called until we are done signalling.

Change-Id: I6bdcefa1f128febb7a0f7aef133757268a3b9ae3
Signed-off-by: Puranam V G Tejaswi <pvgtejas@codeaurora.org>
Signed-off-by: Pranav Patel <quic_pranavp@quicinc.com>
2021-12-01 17:16:54 +05:30
qctecmdr
05b4289870 Merge "msm: kgsl: Update the IFPC power up reglist" 2021-11-05 08:45:46 -07:00
Akhil P Oommen
a7da315c33 msm: kgsl: Update the IFPC power up reglist
Update the IFPC power up reglist to include all the CP Protect
registers.

Change-Id: I1b43420c466b8a228892afac8ecf05b11b5a80e6
Signed-off-by: Akhil P Oommen <akhilpo@codeaurora.org>
2021-10-21 19:23:56 +05:30
Rohan Sethi
3a9c5960d9 msm: kgsl: Add timeline traces
Add some traces to make it easier to debug and track timeline behavior.

Change-Id: Ic0dedbadbfe623c675616a0d2fdd800b49f14705
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rohan Sethi <rohsethi@codeaurora.org>
2021-10-04 12:49:33 +05:30
Jordan Crouse
d01a2bda03 msm: kgsl: Add software timelines
Some graphics APIs want the ability to create and use timelines
with 64 bit sequence numbers to synchronize between threads.

Add support for timelines that can be created, signaled and managed from
user space. Timelines can also be signaled from a draw context command
stream via an auxiliary command and a wait can be added as a sync object
to any GPU command.

Change-Id: Ic0dedbad0ffc99cc309951369eaf85b56727802c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rohan Sethi <rohsethi@codeaurora.org>
2021-10-04 12:48:09 +05:30
Kamal Agrawal
255a99c332 msm: kgsl: Fix out of bound write in adreno_profile_submit_time
Make sure there is enough room in the memory descriptor to store the
entire profiling buffer object.

Change-Id: I1e1c73097bb2bba9645b0a3c66fdbbc71d8ba8fa
Signed-off-by: Kamal Agrawal <kamaagra@codeaurora.org>
2021-09-21 07:11:31 -07:00
qctecmdr
713f0247f0 Merge "msm: kgsl: Keep the context alive until its fences signal" 2021-08-24 11:05:49 -07:00
Lynus Vaz
db3cf7f3f7 msm: kgsl: Keep the context alive until its fences signal
The context is currently kept alive until all its fences are
released. This means that we do not destroy a context until all
the fence fds associated with it are closed by userspace, which may
be a long time. Instead, remove the timeline's refcount on its
context when it is detached. This permits the context to be freed
once all its fences signal.

Change-Id: Ifc5dd55980358ddbb4d3f6220d8b5d9f725aed1b
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
Signed-off-by: Hareesh Gundu <hareeshg@codeaurora.org>
Signed-off-by: Pankaj Gupta <gpankaj@codeaurora.org>
2021-08-24 18:42:58 +05:30
Pankaj Gupta
6450a9e092 msm: kgsl: Use worker to put refcount on mem entry
If refcount on mem entry is the last refcount, we will call
kgsl_mem_entry_destroy and detach it from process list. If
there is no refcount on the process private as well then we
will call kgsl_destroy_process_private to cleanup. During
cleanup, we will try to remove the same sysfs node which is
in use by the current thread and this situation will end up in
a deadlock.
To fix this problem, use a worker to put the refcount on mem
entry.

Change-Id: I69a77c4059489c95de2ca205701571daac4bdc8a
Signed-off-by: Pankaj Gupta <gpankaj@codeaurora.org>
2021-08-18 20:40:05 +05:30
qctecmdr
1303d0a029 Merge "msm: kgsl: Fix memory leak for anonymous buffers" 2021-07-26 02:47:55 -07:00
qctecmdr
120c562bdf Merge "msm: kgsl: Update GMU FW version for A619 GPU" 2021-07-09 05:37:05 -07:00