mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <sgruszka@redhat.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
	Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
	Peter Zijlstra <peterz@infradead.org>,
	stable@kernel.org,
	Michael Chapman <redhat-bugzilla@very.puzzling.org>,
	Ciriaco Garcia de Celis <sysman@etherpilot.com>
Subject: [PATCH v2] sched: fix user time incorrectly accounted as system time on 32 bit
Date: Tue, 14 Sep 2010 16:35:14 +0200	[thread overview]
Message-ID: <20100914143513.GB8415@redhat.com> (raw)

We have 32 bit variable overflow possibility when multiply in
task_times() and thread_group_times() functions. If overflow happens
calculated scaled utime value become wrongly small and scaled stime
wrongly big.

Reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=633037
https://bugzilla.kernel.org/show_bug.cgi?id=16559

Reported-by: Michael Chapman <redhat-bugzilla@very.puzzling.org>
Reported-by: Ciriaco Garcia de Celis <sysman@etherpilot.com>
Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: <stable@kernel.org>  # 2.6.32.19+ (partially) and 2.6.33+
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
v1 -> v2
Fix mail recipients.

 kernel/sched.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 09b574e..eee9470 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3507,9 +3507,9 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
 	rtime = nsecs_to_cputime(p->se.sum_exec_runtime);
 
 	if (total) {
-		u64 temp;
+		u64 temp = rtime;
 
-		temp = (u64)(rtime * utime);
+		temp *= utime;
 		do_div(temp, total);
 		utime = (cputime_t)temp;
 	} else
@@ -3540,9 +3540,9 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
 	rtime = nsecs_to_cputime(cputime.sum_exec_runtime);
 
 	if (total) {
-		u64 temp;
+		u64 temp = rtime;
 
-		temp = (u64)(rtime * cputime.utime);
+		temp *= cputime.utime;
 		do_div(temp, total);
 		utime = (cputime_t)temp;
 	} else
-- 
1.7.1


             reply	other threads:[~2010-09-14 14:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-14 14:35 Stanislaw Gruszka [this message]
2010-09-14 14:37 ` Peter Zijlstra
2010-09-15 10:01 ` [tip:sched/urgent] sched: Fix user time incorrectly accounted as system time on 32-bit tip-bot for Stanislaw Gruszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100914143513.GB8415@redhat.com \
    --to=sgruszka@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=redhat-bugzilla@very.puzzling.org \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    --cc=stable@kernel.org \
    --cc=sysman@etherpilot.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome