summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuzanne Candanedo <suzanne.candanedo@arm.com>2022-09-27 18:31:54 +0100
committerGuus Sliepen <gsliepen@google.com>2022-11-08 12:10:51 +0000
commit0881702b67f32a50845ebe042c5e593afa29bf9a (patch)
tree7d6ec83c199b931522923e20f2af804c591d556f
parent65820c20e66e2c801445d7c37c67a86707ce0b13 (diff)
downloadgpu-0881702b67f32a50845ebe042c5e593afa29bf9a.tar.gz
mali_kbase: MIDCET-4220 Patch for GPUSWERRATA-1360
This patch is fix for SW errata 2637762 fixing possible out of bounds array access. Bug: 251397485 Provenance: https://code.ipdelivery.arm.com/c/GPU/mali-ddk/+/4580 Change-Id: I1597418f91390de7afc0c520d11fdfb739c1e69c Signed-off-by: Jesse Hall <jessehall@google.com> (cherry picked from commit 825d564553db3985e94a2e69e6168d596e58ec00)
-rw-r--r--common/include/uapi/gpu/arm/midgard/jm/mali_base_jm_kernel.h3
-rw-r--r--mali_kbase/jm/mali_kbase_jm_js.h38
-rw-r--r--mali_kbase/mali_kbase_js.c19
3 files changed, 41 insertions, 19 deletions
diff --git a/common/include/uapi/gpu/arm/midgard/jm/mali_base_jm_kernel.h b/common/include/uapi/gpu/arm/midgard/jm/mali_base_jm_kernel.h
index 94f4dc7..b63575e 100644
--- a/common/include/uapi/gpu/arm/midgard/jm/mali_base_jm_kernel.h
+++ b/common/include/uapi/gpu/arm/midgard/jm/mali_base_jm_kernel.h
@@ -770,6 +770,9 @@ typedef __u8 base_jd_prio;
*/
#define BASE_JD_PRIO_REALTIME ((base_jd_prio)3)
+/* Invalid atom priority (max uint8_t value) */
+#define BASE_JD_PRIO_INVALID ((base_jd_prio)255)
+
/* Count of the number of priority levels. This itself is not a valid
* base_jd_prio setting
*/
diff --git a/mali_kbase/jm/mali_kbase_jm_js.h b/mali_kbase/jm/mali_kbase_jm_js.h
index f01e8bb..74d02f5 100644
--- a/mali_kbase/jm/mali_kbase_jm_js.h
+++ b/mali_kbase/jm/mali_kbase_jm_js.h
@@ -950,8 +950,8 @@ extern const base_jd_prio
kbasep_js_relative_priority_to_atom[KBASE_JS_ATOM_SCHED_PRIO_COUNT];
/**
- * kbasep_js_atom_prio_to_sched_prio(): - Convert atom priority (base_jd_prio)
- * to relative ordering
+ * kbasep_js_atom_prio_to_sched_prio - Convert atom priority (base_jd_prio)
+ * to relative ordering.
* @atom_prio: Priority ID to translate.
*
* Atom priority values for @ref base_jd_prio cannot be compared directly to
@@ -980,16 +980,32 @@ static inline int kbasep_js_atom_prio_to_sched_prio(base_jd_prio atom_prio)
return kbasep_js_atom_priority_to_relative[atom_prio];
}
-static inline base_jd_prio kbasep_js_sched_prio_to_atom_prio(int sched_prio)
+/**
+ * kbasep_js_sched_prio_to_atom_prio - Convert relative scheduler priority
+ * to atom priority (base_jd_prio).
+ *
+ * @sched_prio: Relative scheduler priority to translate.
+ *
+ * This function will convert relative scheduler priority back into base_jd_prio
+ * values. It takes values which priorities are monotonically increasing
+ * and converts them to the corresponding base_jd_prio values. If an invalid number is
+ * passed in (i.e. not within the expected range) an error code is returned instead.
+ *
+ * The mapping is 1:1 and the size of the valid input range is the same as the
+ * size of the valid output range, i.e.
+ * KBASE_JS_ATOM_SCHED_PRIO_COUNT == BASE_JD_NR_PRIO_LEVELS
+ *
+ * Return: On success: a value in the inclusive range
+ * 0..BASE_JD_NR_PRIO_LEVELS-1. On failure: BASE_JD_PRIO_INVALID.
+ */
+static inline base_jd_prio kbasep_js_sched_prio_to_atom_prio(struct kbase_device *kbdev,
+ int sched_prio)
{
- unsigned int prio_idx;
-
- KBASE_DEBUG_ASSERT(sched_prio >= 0 &&
- sched_prio < KBASE_JS_ATOM_SCHED_PRIO_COUNT);
-
- prio_idx = (unsigned int)sched_prio;
-
- return kbasep_js_relative_priority_to_atom[prio_idx];
+ if (likely(sched_prio >= 0 && sched_prio < KBASE_JS_ATOM_SCHED_PRIO_COUNT))
+ return kbasep_js_relative_priority_to_atom[sched_prio];
+ /* Invalid priority value if reached here */
+ dev_warn(kbdev->dev, "Unknown JS scheduling priority %d", sched_prio);
+ return BASE_JD_PRIO_INVALID;
}
/**
diff --git a/mali_kbase/mali_kbase_js.c b/mali_kbase/mali_kbase_js.c
index 33af2da..df729f5 100644
--- a/mali_kbase/mali_kbase_js.c
+++ b/mali_kbase/mali_kbase_js.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/*
*
- * (C) COPYRIGHT 2011-2021 ARM Limited. All rights reserved.
+ * (C) COPYRIGHT 2011-2022 ARM Limited. All rights reserved.
*
* This program is free software and is provided to you under the terms of the
* GNU General Public License version 2 as published by the Free Software
@@ -4094,13 +4094,16 @@ base_jd_prio kbase_js_priority_check(struct kbase_device *kbdev, base_jd_prio pr
{
struct priority_control_manager_device *pcm_device = kbdev->pcm_dev;
int req_priority, out_priority;
- base_jd_prio out_jd_priority = priority;
- if (pcm_device) {
- req_priority = kbasep_js_atom_prio_to_sched_prio(priority);
- out_priority = pcm_device->ops.pcm_scheduler_priority_check(pcm_device, current, req_priority);
- out_jd_priority = kbasep_js_sched_prio_to_atom_prio(out_priority);
- }
- return out_jd_priority;
+ req_priority = kbasep_js_atom_prio_to_sched_prio(priority);
+ out_priority = req_priority;
+ /* Does not use pcm defined priority check if PCM not defined or if
+ * kbasep_js_atom_prio_to_sched_prio returns an error
+ * (KBASE_JS_ATOM_SCHED_PRIO_INVALID).
+ */
+ if (pcm_device && (req_priority != KBASE_JS_ATOM_SCHED_PRIO_INVALID))
+ out_priority = pcm_device->ops.pcm_scheduler_priority_check(pcm_device, current,
+ req_priority);
+ return kbasep_js_sched_prio_to_atom_prio(kbdev, out_priority);
}