[PATCH 1/2] x86/nmi: Optimize the check for being in the repeat_nmi code

From: Steven Rostedt
Date: Thu Mar 09 2017 - 17:45:16 EST


From: "Steven Rostedt (Red Hat)" <rostedt@xxxxxxxxxxx>

Linus mentioned that doing two compares can be replaced by a single
compare. That is, instead of:

movq $repeat_nmi, %rdx
cmpq 8(%rsp), %rdx
ja not_in_region
movq $end_repeat_nmi, %rdx
cmpq 8(%rsp), %rdx
ja in_region

we can replace that with:

movq 8(%rsp), %rdx
subq $repeat_nmi, %rdx
cmpq $end_repeat_nmi-repeat_nmi, %rdx
jb in_region

Inspired-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
---
arch/x86/entry/entry_64.S | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 044d18ebc43c..3aad759aace2 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1330,13 +1330,10 @@ ENTRY(nmi)
* resume the outer NMI.
*/

- movq $repeat_nmi, %rdx
- cmpq 8(%rsp), %rdx
- ja 1f
- movq $end_repeat_nmi, %rdx
- cmpq 8(%rsp), %rdx
- ja nested_nmi_out
-1:
+ movq 8(%rsp), %rdx
+ subq $repeat_nmi, %rdx
+ cmpq $end_repeat_nmi-repeat_nmi, %rdx
+ jb nested_nmi_out

/*
* Now check "NMI executing". If it's set, then we're nested.
--
2.10.2