Skip to contentSkip to conversation

x86/nmi: Fix nmi_handle duration miscalculation

PATCH Applied Libing Zhou 2 participants 3 messages Aug 20, 2020 – Oct 1, 2020 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/nmi: Fix nmi_handle duration miscalculation

In nmi_check_duration(), the 'whole_msecs' value get from 'action->max_duration' is wrong.

Fixes 248ed51048c4 ("x86/nmi: Remove irq_work from the long duration NMI handler")

---
v2:
Change solution as [email protected] suggested.

 arch/x86/kernel/nmi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/nmi.c +2 -3
index 4fc9954a9560..47381666d6a5 100644
@@ -102,7 +102,6 @@ fs_initcall(nmi_warning_debugfs);
 
 static void nmi_check_duration(struct nmiaction *action, u64 duration)
 {
-	u64 whole_msecs = READ_ONCE(action->max_duration);
 	int remainder_ns, decimal_msecs;
 
 	if (duration < nmi_longest_ns || duration < action->max_duration)
@@ -110,12 +109,12 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration)
 
 	action->max_duration = duration;
 
-	remainder_ns = do_div(whole_msecs, (1000 * 1000));
+	remainder_ns = do_div(duration, (1000 * 1000));
 	decimal_msecs = remainder_ns / 1000;
 
 	printk_ratelimited(KERN_INFO
 		"INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
-		action->handler, whole_msecs, decimal_msecs);
+		action->handler, duration, decimal_msecs);
 }
 
 static int nmi_handle(unsigned int type, struct pt_regs *regs)
Signature · 1 line
2.22.0
#1 lore raw

Hi,

Any comment on this?

-----Original Message-----
From: Libing Zhou <[email protected]>
Sent: 2020年8月20日 10:57
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Zhou, Libing (NSB - CN/Hangzhou) <[email protected]>; [email protected]
Subject: [PATCH v2] x86/nmi: Fix nmi_handle duration miscalculation

In nmi_check_duration(), the 'whole_msecs' value get from 'action->max_duration' is wrong.

Fixes 248ed51048c4 ("x86/nmi: Remove irq_work from the long duration NMI handler")

---
v2:
Change solution as [email protected] suggested.

 arch/x86/kernel/nmi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/nmi.c +0 -1
@@ -102,7 +102,6 @@ fs_initcall(nmi_warning_debugfs);
 
 static void nmi_check_duration(struct nmiaction *action, u64 duration)  {
-	u64 whole_msecs = READ_ONCE(action->max_duration);
 	int remainder_ns, decimal_msecs;
 
 	if (duration < nmi_longest_ns || duration < action->max_duration) @@ -110,12 +109,12 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration)
 

action->max_duration = duration;

- remainder_ns = do_div(whole_msecs, (1000 * 1000));
+ remainder_ns = do_div(duration, (1000 * 1000));
decimal_msecs = remainder_ns / 1000;

printk_ratelimited(KERN_INFO
"INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
- action->handler, whole_msecs, decimal_msecs);
+ action->handler, duration, decimal_msecs);
}

static int nmi_handle(unsigned int type, struct pt_regs *regs)
--
2.22.0

merge bot Applied
#2 lore raw

[tip: x86/misc] x86/nmi: Fix nmi_handle() duration miscalculation

In reply to Libing Zhou
The following commit has been merged into the x86/misc branch of tip:

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     f94c91f7ba3ba7de2bc8aa31be28e1abb22f849e
Gitweb:        https://git.kernel.org/tip/f94c91f7ba3ba7de2bc8aa31be28e1abb22f849e
Author:        Libing Zhou <[email protected]>
AuthorDate:    Thu, 20 Aug 2020 10:56:41 +08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Thu, 01 Oct 2020 14:42:08 +02:00

x86/nmi: Fix nmi_handle() duration miscalculation

When nmi_check_duration() is checking the time an NMI handler took to execute, the whole_msecs value used should be read from the @duration argument, not from the ->max_duration, the latter being used to store the current maximal duration.

[ bp: Rewrite commit message. ]

Fixes 248ed51048c4 ("x86/nmi: Remove irq_work from the long duration NMI handler")
Cc Changbin Du <[email protected]>
---
 arch/x86/kernel/nmi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/nmi.c +2 -3
index 4fc9954..4738166 100644
@@ -102,7 +102,6 @@ fs_initcall(nmi_warning_debugfs);
 
 static void nmi_check_duration(struct nmiaction *action, u64 duration)
 {
-	u64 whole_msecs = READ_ONCE(action->max_duration);
 	int remainder_ns, decimal_msecs;
 
 	if (duration < nmi_longest_ns || duration < action->max_duration)
@@ -110,12 +109,12 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration)
 
 	action->max_duration = duration;
 
-	remainder_ns = do_div(whole_msecs, (1000 * 1000));
+	remainder_ns = do_div(duration, (1000 * 1000));
 	decimal_msecs = remainder_ns / 1000;
 
 	printk_ratelimited(KERN_INFO
 		"INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
-		action->handler, whole_msecs, decimal_msecs);
+		action->handler, duration, decimal_msecs);
 }
 
 static int nmi_handle(unsigned int type, struct pt_regs *regs)