All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86: perf: fix incorrect use of do_div() in nmi warning
@ 2013-07-08 21:44 Dave Hansen
  2013-07-12 12:08 ` Ingo Molnar
  2013-07-12 13:30 ` [tip:perf/urgent] perf/x86: Fix incorrect use of do_div() in NMI warning tip-bot for Dave Hansen
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Hansen @ 2013-07-08 21:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Dave Hansen


From: Dave Hansen <dave.hansen@linux.intel.com>

This fixes a bug present in 3.10 and introduced here:

commit 2ab00456ea8a0d79acb1390659b98416111880b2
Author: Dave Hansen <dave.hansen@linux.intel.com>
Date:   Fri Jun 21 08:51:35 2013 -0700

    x86: Warn when NMI handlers take large amounts of time

I completely botched understanding the calling conventions of
do_div().  I assumed that do_div() returned the result instead
of realizing that it modifies its argument and returns a
remainder.  The side-effect from this would be bogus numbers
for the "msecs" value in the warning messages:

	INFO: NMI handler (perf_event_nmi_handler) took too long to run: 0.114 msecs

Note, there was a second fix posted by Stephane Eranian for
a separate patch which I also botched:

	http://lkml.kernel.org/r/20130704223010.GA30625@quad

Both of these fixes need to get pulled in to Linus's tree and
the 3.10 stable tree.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: stable@vger.kernel.org
Cc: x86@kernel.org
---

 linux.git-davehans/arch/x86/kernel/nmi.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff -puN arch/x86/kernel/nmi.c~dave-is-stupid-do_div arch/x86/kernel/nmi.c
--- linux.git/arch/x86/kernel/nmi.c~dave-is-stupid-do_div	2013-07-08 13:10:55.498656504 -0700
+++ linux.git-davehans/arch/x86/kernel/nmi.c	2013-07-08 13:10:55.501656637 -0700
@@ -111,7 +111,7 @@ static int __kprobes nmi_handle(unsigned
 	 */
 	list_for_each_entry_rcu(a, &desc->head, list) {
 		u64 before, delta, whole_msecs;
-		int decimal_msecs, thishandled;
+		int remainder_ns, decimal_msecs, thishandled;
 
 		before = local_clock();
 		thishandled = a->handler(type, regs);
@@ -123,8 +123,9 @@ static int __kprobes nmi_handle(unsigned
 			continue;
 
 		nmi_longest_ns = delta;
-		whole_msecs = do_div(delta, (1000 * 1000));
-		decimal_msecs = do_div(delta, 1000) % 1000;
+		whole_msecs = delta;
+		remainder_ns = do_div(whole_msecs, (1000 * 1000));
+		decimal_msecs = remainder_ns / 1000;
 		printk_ratelimited(KERN_INFO
 			"INFO: NMI handler (%ps) took too long to run: "
 			"%lld.%03d msecs\n", a->handler, whole_msecs,
_

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: perf: fix incorrect use of do_div() in nmi warning
  2013-07-08 21:44 [PATCH] x86: perf: fix incorrect use of do_div() in nmi warning Dave Hansen
@ 2013-07-12 12:08 ` Ingo Molnar
  2013-07-12 16:28   ` Dave Hansen
  2013-07-12 13:30 ` [tip:perf/urgent] perf/x86: Fix incorrect use of do_div() in NMI warning tip-bot for Dave Hansen
  1 sibling, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2013-07-12 12:08 UTC (permalink / raw)
  To: Dave Hansen; +Cc: linux-kernel, x86, Peter Zijlstra


* Dave Hansen <dave@sr71.net> wrote:

> 
> From: Dave Hansen <dave.hansen@linux.intel.com>
> 
> This fixes a bug present in 3.10 and introduced here:
> 
> commit 2ab00456ea8a0d79acb1390659b98416111880b2
> Author: Dave Hansen <dave.hansen@linux.intel.com>
> Date:   Fri Jun 21 08:51:35 2013 -0700
> 
>     x86: Warn when NMI handlers take large amounts of time
> 
> I completely botched understanding the calling conventions of
> do_div().  I assumed that do_div() returned the result instead
> of realizing that it modifies its argument and returns a
> remainder.  The side-effect from this would be bogus numbers
> for the "msecs" value in the warning messages:
> 
> 	INFO: NMI handler (perf_event_nmi_handler) took too long to run: 0.114 msecs
> 
> Note, there was a second fix posted by Stephane Eranian for
> a separate patch which I also botched:
> 
> 	http://lkml.kernel.org/r/20130704223010.GA30625@quad
> 
> Both of these fixes need to get pulled in to Linus's tree and
> the 3.10 stable tree.

This is a brand new v3.11 commit.

It should not be included in any -stable tree, is it?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:perf/urgent] perf/x86: Fix incorrect use of do_div() in NMI warning
  2013-07-08 21:44 [PATCH] x86: perf: fix incorrect use of do_div() in nmi warning Dave Hansen
  2013-07-12 12:08 ` Ingo Molnar
@ 2013-07-12 13:30 ` tip-bot for Dave Hansen
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Dave Hansen @ 2013-07-12 13:30 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, dave.hansen, tglx, dave

Commit-ID:  baf64b85445546a38b44052d71782dfe7531e350
Gitweb:     http://git.kernel.org/tip/baf64b85445546a38b44052d71782dfe7531e350
Author:     Dave Hansen <dave.hansen@linux.intel.com>
AuthorDate: Mon, 8 Jul 2013 14:44:04 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 12 Jul 2013 14:13:04 +0200

perf/x86: Fix incorrect use of do_div() in NMI warning

I completely botched understanding the calling conventions of
do_div().  I assumed that do_div() returned the result instead
of realizing that it modifies its argument and returns a
remainder.  The side-effect from this would be bogus numbers
for the "msecs" value in the warning messages:

	INFO: NMI handler (perf_event_nmi_handler) took too long to run: 0.114 msecs

Note, there was a second fix posted by Stephane Eranian for
a separate patch which I also botched:

	http://lkml.kernel.org/r/20130704223010.GA30625@quad

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dave Hansen <dave@sr71.net>
Link: http://lkml.kernel.org/r/20130708214404.B0B6EA66@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/nmi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 0920212..ba77ebc 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -111,7 +111,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
 	 */
 	list_for_each_entry_rcu(a, &desc->head, list) {
 		u64 before, delta, whole_msecs;
-		int decimal_msecs, thishandled;
+		int remainder_ns, decimal_msecs, thishandled;
 
 		before = local_clock();
 		thishandled = a->handler(type, regs);
@@ -123,8 +123,9 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
 			continue;
 
 		nmi_longest_ns = delta;
-		whole_msecs = do_div(delta, (1000 * 1000));
-		decimal_msecs = do_div(delta, 1000) % 1000;
+		whole_msecs = delta;
+		remainder_ns = do_div(whole_msecs, (1000 * 1000));
+		decimal_msecs = remainder_ns / 1000;
 		printk_ratelimited(KERN_INFO
 			"INFO: NMI handler (%ps) took too long to run: "
 			"%lld.%03d msecs\n", a->handler, whole_msecs,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86: perf: fix incorrect use of do_div() in nmi warning
  2013-07-12 12:08 ` Ingo Molnar
@ 2013-07-12 16:28   ` Dave Hansen
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Hansen @ 2013-07-12 16:28 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel, x86, Peter Zijlstra

On 07/12/2013 05:08 AM, Ingo Molnar wrote:
>> > Note, there was a second fix posted by Stephane Eranian for
>> > a separate patch which I also botched:
>> > 
>> > 	http://lkml.kernel.org/r/20130704223010.GA30625@quad
>> > 
>> > Both of these fixes need to get pulled in to Linus's tree and
>> > the 3.10 stable tree.
> This is a brand new v3.11 commit.
> 
> It should not be included in any -stable tree, is it?

Ingo, you are correct.  The commit only appeared in Linus's tree
post-3.10.  It does not need to be in any stable trees.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-12 16:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-08 21:44 [PATCH] x86: perf: fix incorrect use of do_div() in nmi warning Dave Hansen
2013-07-12 12:08 ` Ingo Molnar
2013-07-12 16:28   ` Dave Hansen
2013-07-12 13:30 ` [tip:perf/urgent] perf/x86: Fix incorrect use of do_div() in NMI warning tip-bot for Dave Hansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.