Skip to contentSkip to conversation

PM: QoS: Add check to make sure CPU latency is non-negative

PATCH In review Clive Lin 2 participants 2 messages Jul 31, 2023 – Aug 22, 2023

Subsystems (2)
lore
Share & tools
lore

Clive Lin

author
#0 lore raw

PATCH 1/1 PM: QoS: Add check to make sure CPU latency is non-negative

CPU latency should never be negative, which will be incorrectly high when converted to unsigned data type. Commit 8d36694245f2 ("PM: QoS:
Add check to make sure CPU freq is non-negative") makes sure CPU freq is non-negative to fix incorrect behavior in freq_qos. Adding a check to make sure CPU latency is non-negative can prevent this problem from happening in cpu_latency_qos.

---
 kernel/power/qos.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/power/qos.c +7 -2
index 782d3b41c1f3..4244b069442e 100644
@@ -220,6 +220,11 @@ static struct pm_qos_constraints cpu_latency_constraints = {
 	.type = PM_QOS_MIN,
 };
 
+static inline bool cpu_latency_qos_value_invalid(s32 value)
+{
+	return value < 0 && value != PM_QOS_DEFAULT_VALUE;
+}
+
 /**
  * cpu_latency_qos_limit - Return current system-wide CPU latency QoS limit.
  */
@@ -263,7 +268,7 @@ static void cpu_latency_qos_apply(struct pm_qos_request *req,
  */
 void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value)
 {
-	if (!req)
+	if (!req || cpu_latency_qos_value_invalid(value))
 		return;
 
 	if (cpu_latency_qos_request_active(req)) {
@@ -289,7 +294,7 @@ EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);
  */
 void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value)
 {
-	if (!req)
+	if (!req || cpu_latency_qos_value_invalid(new_value))
 		return;
 
 	if (!cpu_latency_qos_request_active(req)) {
Signature · 1 line
2.18.0
#1 lore raw
Quoted 39 lines · Clive Lin

CPU latency should never be negative, which will be incorrectly high when converted to unsigned data type. Commit 8d36694245f2 ("PM: QoS:
Add check to make sure CPU freq is non-negative") makes sure CPU freq is non-negative to fix incorrect behavior in freq_qos. Adding a check to make sure CPU latency is non-negative can prevent this problem from happening in cpu_latency_qos.

---
 kernel/power/qos.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/power/qos.c +6 -1
index 782d3b41c1f3..4244b069442e 100644
@@ -220,6 +220,11 @@ static struct pm_qos_constraints cpu_latency_constraints = {
        .type = PM_QOS_MIN,
 };
 
+static inline bool cpu_latency_qos_value_invalid(s32 value)
+{
+       return value < 0 && value != PM_QOS_DEFAULT_VALUE;
+}
+
 /**
  * cpu_latency_qos_limit - Return current system-wide CPU latency QoS limit.
  */
@@ -263,7 +268,7 @@ static void cpu_latency_qos_apply(struct pm_qos_request *req,
  */
 void cpu_latency_qos_add_request(struct pm_qos_request *req, s32 value)
 {
-       if (!req)
+       if (!req || cpu_latency_qos_value_invalid(value))
                return;
 
        if (cpu_latency_qos_request_active(req)) {

kernel/power/qos.c EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);

Quoted 9 lines
kernel/power/qos.c +1 -2
@@ -289,7 +294,7 @@ EXPORT_SYMBOL_GPL(cpu_latency_qos_add_request);
  */
 void cpu_latency_qos_update_request(struct pm_qos_request *req, s32 new_value)
 {
-       if (!req)
+       if (!req || cpu_latency_qos_value_invalid(new_value))
                return;
 
        if (!cpu_latency_qos_request_active(req)) {
--

Applied (with some edits in the changelog) as 6.6 material, thanks!