summaryrefslogtreecommitdiff
path: root/mali_kbase
diff options
context:
space:
mode:
authorPixelBot AutoMerger <android-nexus-securitybot@system.gserviceaccount.com>2023-03-26 19:14:06 -0700
committerSecurityBot <android-nexus-securitybot@system.gserviceaccount.com>2023-03-26 19:14:07 -0700
commit3486b00e408d5c8096dc8539c385b6a545085d29 (patch)
tree6553b6bac1cb9ae1e0b8386c75307b53a8f8a1e1 /mali_kbase
parent8141064fa8984d1b2d25b9c4a84b5e5b7916b83b (diff)
parentfa73c81d4bf634ccc50a231e3f2108a9e7c75689 (diff)
downloadgpu-3486b00e408d5c8096dc8539c385b6a545085d29.tar.gz
Merge android13-gs-pixel-5.10-tm-qpr3 into android13-gs-pixel-5.10-udc
SBMerger: 516612970 Change-Id: Ic3745d8ba6e262a0f971a80e3e304ce2cc91cc26 Signed-off-by: SecurityBot <android-nexus-securitybot@system.gserviceaccount.com>
Diffstat (limited to 'mali_kbase')
-rw-r--r--mali_kbase/backend/gpu/mali_kbase_pm_driver.c2
-rw-r--r--mali_kbase/csf/mali_kbase_csf_kcpu.c24
-rw-r--r--mali_kbase/mali_kbase.h13
-rw-r--r--mali_kbase/mali_kbase_mem_linux.c3
-rw-r--r--mali_kbase/mali_kbase_softjobs.c24
5 files changed, 44 insertions, 22 deletions
diff --git a/mali_kbase/backend/gpu/mali_kbase_pm_driver.c b/mali_kbase/backend/gpu/mali_kbase_pm_driver.c
index 2bfc27a..1f66d17 100644
--- a/mali_kbase/backend/gpu/mali_kbase_pm_driver.c
+++ b/mali_kbase/backend/gpu/mali_kbase_pm_driver.c
@@ -1276,9 +1276,9 @@ static int kbase_pm_l2_update_state(struct kbase_device *kbdev)
switch (backend->l2_state) {
case KBASE_L2_OFF:
if (kbase_pm_is_l2_desired(kbdev)) {
+#if MALI_USE_CSF && defined(KBASE_PM_RUNTIME)
// Workaround: give a short pause here before starting L2 transition.
udelay(200);
-#if MALI_USE_CSF && defined(KBASE_PM_RUNTIME)
/* Enable HW timer of IPA control before
* L2 cache is powered-up.
*/
diff --git a/mali_kbase/csf/mali_kbase_csf_kcpu.c b/mali_kbase/csf/mali_kbase_csf_kcpu.c
index 49c128c..6c034f0 100644
--- a/mali_kbase/csf/mali_kbase_csf_kcpu.c
+++ b/mali_kbase/csf/mali_kbase_csf_kcpu.c
@@ -2210,14 +2210,30 @@ int kbase_csf_kcpu_queue_enqueue(struct kbase_context *kctx,
return -EINVAL;
}
+ /* There might be a race between one thread trying to enqueue commands to the queue
+ * and other thread trying to delete the same queue.
+ * This racing could lead to use-after-free problem by enqueuing thread if
+ * resources for the queue has already been freed by deleting thread.
+ *
+ * To prevent the issue, two mutexes are acquired/release asymmetrically as follows.
+ *
+ * Lock A (kctx mutex)
+ * Lock B (queue mutex)
+ * Unlock A
+ * Unlock B
+ *
+ * With the kctx mutex being held, enqueuing thread will check the queue
+ * and will return error code if the queue had already been deleted.
+ */
mutex_lock(&kctx->csf.kcpu_queues.lock);
queue = kctx->csf.kcpu_queues.array[enq->id];
- mutex_unlock(&kctx->csf.kcpu_queues.lock);
-
- if (queue == NULL)
+ if (queue == NULL) {
+ dev_dbg(kctx->kbdev->dev, "Invalid KCPU queue (id:%u)", enq->id);
+ mutex_unlock(&kctx->csf.kcpu_queues.lock);
return -EINVAL;
-
+ }
mutex_lock(&queue->lock);
+ mutex_unlock(&kctx->csf.kcpu_queues.lock);
if (kcpu_queue_get_space(queue) < enq->nr_commands) {
ret = -EBUSY;
diff --git a/mali_kbase/mali_kbase.h b/mali_kbase/mali_kbase.h
index b04cf94..0a8267b 100644
--- a/mali_kbase/mali_kbase.h
+++ b/mali_kbase/mali_kbase.h
@@ -447,19 +447,6 @@ static inline void kbase_free_user_buffer(
}
}
-/**
- * kbase_mem_copy_from_extres() - Copy from external resources.
- *
- * @kctx: kbase context within which the copying is to take place.
- * @buf_data: Pointer to the information about external resources:
- * pages pertaining to the external resource, number of
- * pages to copy.
- *
- * Return: 0 on success, error code otherwise.
- */
-int kbase_mem_copy_from_extres(struct kbase_context *kctx,
- struct kbase_debug_copy_buffer *buf_data);
-
#if !MALI_USE_CSF
int kbase_process_soft_job(struct kbase_jd_atom *katom);
int kbase_prepare_soft_job(struct kbase_jd_atom *katom);
diff --git a/mali_kbase/mali_kbase_mem_linux.c b/mali_kbase/mali_kbase_mem_linux.c
index 2c33df4..000efc7 100644
--- a/mali_kbase/mali_kbase_mem_linux.c
+++ b/mali_kbase/mali_kbase_mem_linux.c
@@ -3167,6 +3167,9 @@ void *kbase_vmap_prot(struct kbase_context *kctx, u64 gpu_addr, size_t size,
if (kbase_is_region_invalid_or_free(reg))
goto out_unlock;
+ if (reg->gpu_alloc->type != KBASE_MEM_TYPE_NATIVE)
+ goto out_unlock;
+
addr = kbase_vmap_reg(kctx, reg, gpu_addr, size, prot_request, map, 0u);
out_unlock:
diff --git a/mali_kbase/mali_kbase_softjobs.c b/mali_kbase/mali_kbase_softjobs.c
index 665bc09..f9de37f 100644
--- a/mali_kbase/mali_kbase_softjobs.c
+++ b/mali_kbase/mali_kbase_softjobs.c
@@ -504,6 +504,7 @@ static void kbasep_soft_event_cancel_job(struct kbase_jd_atom *katom)
kbase_js_sched_all(katom->kctx->kbdev);
}
+#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST
static void kbase_debug_copy_finish(struct kbase_jd_atom *katom)
{
struct kbase_debug_copy_buffer *buffers = katom->softjob_data;
@@ -730,7 +731,6 @@ out_cleanup:
return ret;
}
-#endif /* !MALI_USE_CSF */
#if KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE
static void *dma_buf_kmap_page(struct kbase_mem_phy_alloc *gpu_alloc,
@@ -762,8 +762,18 @@ static void *dma_buf_kmap_page(struct kbase_mem_phy_alloc *gpu_alloc,
}
#endif
-int kbase_mem_copy_from_extres(struct kbase_context *kctx,
- struct kbase_debug_copy_buffer *buf_data)
+/**
+ * kbase_mem_copy_from_extres() - Copy from external resources.
+ *
+ * @kctx: kbase context within which the copying is to take place.
+ * @buf_data: Pointer to the information about external resources:
+ * pages pertaining to the external resource, number of
+ * pages to copy.
+ *
+ * Return: 0 on success, error code otherwise.
+ */
+static int kbase_mem_copy_from_extres(struct kbase_context *kctx,
+ struct kbase_debug_copy_buffer *buf_data)
{
unsigned int i;
unsigned int target_page_nr = 0;
@@ -850,7 +860,6 @@ out_unlock:
return ret;
}
-#if !MALI_USE_CSF
static int kbase_debug_copy(struct kbase_jd_atom *katom)
{
struct kbase_debug_copy_buffer *buffers = katom->softjob_data;
@@ -868,6 +877,7 @@ static int kbase_debug_copy(struct kbase_jd_atom *katom)
return 0;
}
+#endif /* IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST */
#endif /* !MALI_USE_CSF */
#define KBASEP_JIT_ALLOC_GPU_ADDR_ALIGNMENT ((u32)0x7)
@@ -1571,6 +1581,7 @@ int kbase_process_soft_job(struct kbase_jd_atom *katom)
case BASE_JD_REQ_SOFT_EVENT_RESET:
kbasep_soft_event_update_locked(katom, BASE_JD_SOFT_EVENT_RESET);
break;
+#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST
case BASE_JD_REQ_SOFT_DEBUG_COPY:
{
int res = kbase_debug_copy(katom);
@@ -1579,6 +1590,7 @@ int kbase_process_soft_job(struct kbase_jd_atom *katom)
katom->event_code = BASE_JD_EVENT_JOB_INVALID;
break;
}
+#endif /* IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST */
case BASE_JD_REQ_SOFT_JIT_ALLOC:
ret = kbase_jit_allocate_process(katom);
break;
@@ -1704,8 +1716,10 @@ int kbase_prepare_soft_job(struct kbase_jd_atom *katom)
if (katom->jc == 0)
return -EINVAL;
break;
+#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST
case BASE_JD_REQ_SOFT_DEBUG_COPY:
return kbase_debug_copy_prepare(katom);
+#endif /* IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST */
case BASE_JD_REQ_SOFT_EXT_RES_MAP:
return kbase_ext_res_prepare(katom);
case BASE_JD_REQ_SOFT_EXT_RES_UNMAP:
@@ -1737,9 +1751,11 @@ void kbase_finish_soft_job(struct kbase_jd_atom *katom)
kbase_sync_fence_in_remove(katom);
break;
#endif /* CONFIG_SYNC || CONFIG_SYNC_FILE */
+#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST
case BASE_JD_REQ_SOFT_DEBUG_COPY:
kbase_debug_copy_finish(katom);
break;
+#endif /* IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST */
case BASE_JD_REQ_SOFT_JIT_ALLOC:
kbase_jit_allocate_finish(katom);
break;