Skip to contentSkip to conversation

Possible usage of uninitalized task_ratelimit variable in mm/page-writeback.c

DISCUSSION Witold Baryluk 2 participants 4 messages Nov 7, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

I found a minor issue when compiling kernel today

CC mm/page-writeback.o
mm/page-writeback.c: In function a??balance_dirty_pages_ratelimited_nra??:
include/trace/events/writeback.h:281:1: warning: a??task_ratelimita?? may be used uninitialized in this function [-Wuninitialized] mm/page-writeback.c:1018:16: note: a??task_ratelimita?? was declared here

Indeed in balance_dirty_pages a task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Regards,
Witek

Signature · 9 lines
Witold Baryluk
JID: witold.baryluk // jabster.pl

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 5 lines · Witold Baryluk

Hi,

I found a minor issue when compiling kernel today

Quoted 8 lines

CC mm/page-writeback.o
mm/page-writeback.c: In function ‘balance_dirty_pages_ratelimited_nr’:
include/trace/events/writeback.h:281:1: warning: ‘task_ratelimit’ may be used uninitialized in this function [-Wuninitialized] mm/page-writeback.c:1018:16: note: ‘task_ratelimit’ was declared here

Indeed in balance_dirty_pages a task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Witold, thanks for the report! This patch should fix the bug.

Thanks,
Fengguang
---

writeback: fix uninitialized task_ratelimit

In balance_dirty_pages() task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Fix it by moving the task_ratelimit assignment before goto pause.

---
 mm/page-writeback.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page-writeback.c +4 -4
@@ -1097,13 +1097,13 @@ static void balance_dirty_pages(struct a
 		pos_ratio = bdi_position_ratio(bdi, dirty_thresh,
 					       background_thresh, nr_dirty,
 					       bdi_thresh, bdi_dirty);
-		if (unlikely(pos_ratio == 0)) {
+		task_ratelimit = (u64)dirty_ratelimit *
+					pos_ratio >> RATELIMIT_CALC_SHIFT;
+		if (unlikely(task_ratelimit == 0)) {
 			pause = max_pause;
 			goto pause;
 		}
-		task_ratelimit = (u64)dirty_ratelimit *
-					pos_ratio >> RATELIMIT_CALC_SHIFT;
-		pause = (HZ * pages_dirtied) / (task_ratelimit | 1);
+		pause = (HZ * pages_dirtied) / task_ratelimit;
 		if (unlikely(pause <= 0)) {
 			trace_balance_dirty_pages(bdi,
 						  dirty_thresh,

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 45 lines · Wu Fengguang
Quoted 5 lines · Witold Baryluk

Hi,

I found a minor issue when compiling kernel today

Quoted 8 lines

CC mm/page-writeback.o
mm/page-writeback.c: In function ‘balance_dirty_pages_ratelimited_nr’:
include/trace/events/writeback.h:281:1: warning: ‘task_ratelimit’ may be used uninitialized in this function [-Wuninitialized] mm/page-writeback.c:1018:16: note: ‘task_ratelimit’ was declared here

Indeed in balance_dirty_pages a task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Witold, thanks for the report! This patch should fix the bug.

Thanks,
Fengguang
---

writeback: fix uninitialized task_ratelimit

In balance_dirty_pages() task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Fix it by moving the task_ratelimit assignment before goto pause.

---
 mm/page-writeback.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page-writeback.c +3 -1
@@ -1097,13 +1097,13 @@ static void balance_dirty_pages(struct a
 		pos_ratio = bdi_position_ratio(bdi, dirty_thresh,
 					       background_thresh, nr_dirty,
 					       bdi_thresh, bdi_dirty);
-		if (unlikely(pos_ratio == 0)) {
+		task_ratelimit = (u64)dirty_ratelimit *
+					pos_ratio >> RATELIMIT_CALC_SHIFT;
+		if (unlikely(task_ratelimit == 0)) {

mm/page-writeback.c static void balance_dirty_pages(struct a · line 1109

Quoted 10 lines
mm/page-writeback.c +1 -3
 			pause = max_pause;
 			goto pause;
 		}
-		task_ratelimit = (u64)dirty_ratelimit *
-					pos_ratio >> RATELIMIT_CALC_SHIFT;
-		pause = (HZ * pages_dirtied) / (task_ratelimit | 1);
+		pause = (HZ * pages_dirtied) / task_ratelimit;
 		if (unlikely(pause <= 0)) {
 			trace_balance_dirty_pages(bdi,
 						  dirty_thresh,

Thanks.

This is very nice patch, fixes warning,
and simplifies logic. I have no other objections.

(I do not remember what have bigger priority, * or >>
- i guess * - but additional paranthesis can help. :D )

Regards,
Witek

Signature · 8 lines
Witold Baryluk

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 59 lines · Witold Baryluk
Quoted 45 lines · Wu Fengguang
Quoted 5 lines · Witold Baryluk

Hi,

I found a minor issue when compiling kernel today

Quoted 8 lines

CC mm/page-writeback.o
mm/page-writeback.c: In function ‘balance_dirty_pages_ratelimited_nr’:
include/trace/events/writeback.h:281:1: warning: ‘task_ratelimit’ may be used uninitialized in this function [-Wuninitialized] mm/page-writeback.c:1018:16: note: ‘task_ratelimit’ was declared here

Indeed in balance_dirty_pages a task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Witold, thanks for the report! This patch should fix the bug.

Thanks,
Fengguang
---

writeback: fix uninitialized task_ratelimit

In balance_dirty_pages() task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Fix it by moving the task_ratelimit assignment before goto pause.

---
 mm/page-writeback.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page-writeback.c +3 -1
@@ -1097,13 +1097,13 @@ static void balance_dirty_pages(struct a
 		pos_ratio = bdi_position_ratio(bdi, dirty_thresh,
 					       background_thresh, nr_dirty,
 					       bdi_thresh, bdi_dirty);
-		if (unlikely(pos_ratio == 0)) {
+		task_ratelimit = (u64)dirty_ratelimit *
+					pos_ratio >> RATELIMIT_CALC_SHIFT;
+		if (unlikely(task_ratelimit == 0)) {

mm/page-writeback.c static void balance_dirty_pages(struct a · line 1109

Quoted 10 lines
mm/page-writeback.c +1 -3
 			pause = max_pause;
 			goto pause;
 		}
-		task_ratelimit = (u64)dirty_ratelimit *
-					pos_ratio >> RATELIMIT_CALC_SHIFT;
-		pause = (HZ * pages_dirtied) / (task_ratelimit | 1);
+		pause = (HZ * pages_dirtied) / task_ratelimit;
 		if (unlikely(pause <= 0)) {
 			trace_balance_dirty_pages(bdi,
 						  dirty_thresh,

Thanks.

Quoted 5 lines

This is very nice patch, fixes warning,
and simplifies logic. I have no other objections.

(I do not remember what have bigger priority, * or >>
- i guess * - but additional paranthesis can help. :D )

Good point! Just added/removed parentheses according to your suggestions :)

Thanks,
Fengguang
---
writeback: fix uninitialized task_ratelimit

In balance_dirty_pages() task_ratelimit may be not initialized (initialization skiped by goto pause;), and then used when calling tracing hook.

Fix it by moving the task_ratelimit assignment before goto pause.

---
 mm/page-writeback.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page-writeback.c +4 -4
@@ -1095,13 +1095,13 @@ static void balance_dirty_pages(struct a
 		pos_ratio = bdi_position_ratio(bdi, dirty_thresh,
 					       background_thresh, nr_dirty,
 					       bdi_thresh, bdi_dirty);
-		if (unlikely(pos_ratio == 0)) {
+		task_ratelimit = ((u64)dirty_ratelimit * pos_ratio) >>
+							RATELIMIT_CALC_SHIFT;
+		if (unlikely(task_ratelimit == 0)) {
 			pause = max_pause;
 			goto pause;
 		}
-		task_ratelimit = (u64)dirty_ratelimit *
-					pos_ratio >> RATELIMIT_CALC_SHIFT;
-		pause = (HZ * pages_dirtied) / (task_ratelimit | 1);
+		pause = HZ * pages_dirtied / task_ratelimit;
 		if (unlikely(pause <= 0)) {
 			trace_balance_dirty_pages(bdi,
 						  dirty_thresh,

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html