Skip to contentSkip to conversation

sched/cpupri: fix cpupri_find() for high priority tasks

PATCH In review Mike Galbraith 3 participants 4 messages Apr 9, 2014 – May 8, 2014 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/cpupri: fix cpupri_find() for high priority tasks

Hi Steven,

Seems c92211d9b7727 introduced a buglet.

--snip--

Bail on task_pri >= MAX_RT_PRIO excludes userspace prio 98 and 99 tasks, which map to 100 and 101 respectively.

A user reported that given two SCHED_RR tasks, one hog, one light, the light task may be stacked on top of the hog iff prio >= 98, latency hit follows.

Fixes c92211d9b7727 sched/cpupri: Remove the vec->lock
---
 kernel/sched/cpupri.c |    3 ---
 1 file changed, 3 deletions(-)
kernel/sched/cpupri.c +0 -3
@@ -70,9 +70,6 @@ int cpupri_find(struct cpupri *cp, struc
 	int idx = 0;
 	int task_pri = convert_prio(p->prio);
 
-	if (task_pri >= MAX_RT_PRIO)
-		return 0;
-
 	for (idx = 0; idx < task_pri; idx++) {
 		struct cpupri_vec *vec  = &cp->pri_to_cpu[idx];
 		int skip = 0;
#1 lore raw
Quoted 22 lines · On Wed, 09 Apr 2014 05:50:10 +0200 Mike Galbraith <[email protected]>…

Hi Steven,

Seems c92211d9b7727 introduced a buglet.

--snip--

Bail on task_pri >= MAX_RT_PRIO excludes userspace prio 98 and 99 tasks, which map to 100 and 101 respectively.

A user reported that given two SCHED_RR tasks, one hog, one light, the light task may be stacked on top of the hog iff prio >= 98, latency hit follows.

Fixes c92211d9b7727 sched/cpupri: Remove the vec->lock
---
 kernel/sched/cpupri.c |    3 ---
 1 file changed, 3 deletions(-)

kernel/sched/cpupri.c int cpupri_find(struct cpupri *cp, struc · line 74

Quoted 5 lines
kernel/sched/cpupri.c +0 -2
@@ -70,9 +70,6 @@ int cpupri_find(struct cpupri *cp, struc
 	int idx = 0;
 	int task_pri = convert_prio(p->prio);
 
-	if (task_pri >= MAX_RT_PRIO)
-		return 0;

task_pri is used as an index into pri_to_cpu. Although I don't see how this can be called for a non RT task, the safer solution is below.

-- Steve

Quoted 7 lines
kernel/sched/cpupri.c +0 -1
-
 	for (idx = 0; idx < task_pri; idx++) {
 		struct cpupri_vec *vec  = &cp->pri_to_cpu[idx];
 		int skip = 0;

From 606aa467c9a51c09ce4efa320db45eee59a9bd06 Mon Sep 17 00:00:00 2001

From: "Steven Rostedt (Red Hat)" <[email protected]>
Date: Sun, 13 Apr 2014 09:34:53 -0400
Subject: [PATCH] sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in
cpupri check

The check at the beginning of cpupri_find() makes sure that the task_pri variable does not exceed the cp->pri_to_cpu array length. But that length is CPUPRI_NR_PRIORITIES not MAX_RT_PRIO, where it will miss the last two priorities in that array.

---
 kernel/sched/cpupri.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cpupri.c +1 -1
index 8b836b3..557356a 100644
@@ -70,7 +70,7 @@ int cpupri_find(struct cpupri *cp, struct task_struct *p,
 	int idx = 0;
 	int task_pri = convert_prio(p->prio);
 
-	if (task_pri >= MAX_RT_PRIO)
+	if (task_pri >= CPUPRI_NR_PRIORITIES)
 		return 0;
 
 	for (idx = 0; idx < task_pri; idx++) {
Signature · 1 line
1.8.1.4
#2 lore raw

Actually, since task_pri is calculated from convert_prio() that check should never be hit. But, I'm paranoid, and instead of dropping the check, we can do the same as what cpupri_set() does. Which is to BUG.

-- Steve

Quoted 1 line

From aac271901d6ef5ad19c52f166bf130ad27515b5f Mon Sep 17 00:00:00 2001

From: "Steven Rostedt (Red Hat)" <[email protected]>
Date: Sun, 13 Apr 2014 09:34:53 -0400
Subject: [PATCH] sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in
cpupri check

The check at the beginning of cpupri_find() makes sure that the task_pri variable does not exceed the cp->pri_to_cpu array length. But that length is CPUPRI_NR_PRIORITIES not MAX_RT_PRIO, where it will miss the last two priorities in that array.

As task_pri is computed from convert_prio() which should never be bigger than CPUPRI_NR_PRIORITIES, if the check should cause a panic if it is hit.

---
 kernel/sched/cpupri.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/cpupri.c +1 -2
index 8b836b3..3031bac 100644
@@ -70,8 +70,7 @@ int cpupri_find(struct cpupri *cp, struct task_struct *p,
 	int idx = 0;
 	int task_pri = convert_prio(p->prio);
 
-	if (task_pri >= MAX_RT_PRIO)
-		return 0;
+	BUG_ON(task_pri >= CPUPRI_NR_PRIORITIES);
 
 	for (idx = 0; idx < task_pri; idx++) {
 		struct cpupri_vec *vec  = &cp->pri_to_cpu[idx];
Signature · 1 line
1.8.1.4
#3 lore raw

[tip:sched/core] sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in cpupri check

In reply to Mike Galbraith
sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in cpupri check
Commit-ID:  6227cb00cc120f9a43ce8313bb0475ddabcb7d01
Gitweb:     http://git.kernel.org/tip/6227cb00cc120f9a43ce8313bb0475ddabcb7d01
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Sun, 13 Apr 2014 09:34:53 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 7 May 2014 11:51:33 +0200

sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in cpupri check

The check at the beginning of cpupri_find() makes sure that the task_pri variable does not exceed the cp->pri_to_cpu array length. But that length is CPUPRI_NR_PRIORITIES not MAX_RT_PRIO, where it will miss the last two priorities in that array.

As task_pri is computed from convert_prio() which should never be bigger than CPUPRI_NR_PRIORITIES, if the check should cause a panic if it is hit.

---
 kernel/sched/cpupri.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/cpupri.c +1 -2
index 8b836b3..3031bac 100644
@@ -70,8 +70,7 @@ int cpupri_find(struct cpupri *cp, struct task_struct *p,
 	int idx = 0;
 	int task_pri = convert_prio(p->prio);
 
-	if (task_pri >= MAX_RT_PRIO)
-		return 0;
+	BUG_ON(task_pri >= CPUPRI_NR_PRIORITIES);
 
 	for (idx = 0; idx < task_pri; idx++) {
 		struct cpupri_vec *vec  = &cp->pri_to_cpu[idx];