Re: ia32_sysenter_target does not preserve EFLAGS

From: Ingo Molnar
Date: Sat Mar 28 2015 - 05:31:01 EST



* Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst <brgerst@xxxxxxxxx> wrote:
> >> <-- IRQ. Boom
> >
> > The sti will delay interrupts for one instruction, and that should include NMIs.
>
> Nope. Intel explicitly documents the NMI case only for mov->ss and popss.

Interestingly, I still see a STI 'NMI shadow' even on Intel CPUs.

Try something like this as root on a system with Intel CPUs (running
recent tools/perf), with high-freq NMI sampling:

perf top -F 10000

execute a tight syscall loop on all CPUs (getppid() loop for example),
and you'll see something like this in the profile:

Samples: 1M of event 'cycles', Event count (approx.): 377899840545
Overhead Shared Object Symbol â
27.67% libc-2.19.so [.] __GI___getppid â
21.34% [kernel] [k] system_call â
17.42% [kernel] [k] system_call_after_swapgs â
12.00% [kernel] [k] pid_vnr â
7.49% [kernel] [k] sys_getppid â
5.49% [kernel] [k] sysret_check â
5.34% loop-getppid [.] main â
1.56% [kernel] [k] system_call_fastpath â
0.36% loop-getppid [.] getppid@plt â

Note the very high sample count (due to sampling at 10 KHz).

Now if you hit '<Enter>' twice to annotate system_call_after_swapgs
you should see something like this (the live kernel image disassembly,
annotated):

system_call_after_swapgs /proc/kcore
â
â
â
â Disassembly of section load0:
â
â ffffffff8178b3f3 <load0>:
9.72 âffffffff8178b3f3: mov %rsp,%gs:0xb040
44.24 âffffffff8178b3fc: mov %gs:0xb888,%rsp
0.02 âffffffff8178b405: sti
âffffffff8178b406: nopl 0x0(%rax)
16.04 âffffffff8178b40d: sub $0x50,%rsp
âffffffff8178b411: mov %rdi,0x40(%rsp)
6.51 âffffffff8178b416: mov %rsi,0x38(%rsp)
5.81 âffffffff8178b41b: mov %rdx,0x30(%rsp)
2.22 âffffffff8178b420: mov %rax,0x20(%rsp)
2.16 âffffffff8178b425: mov %r8,0x18(%rsp)
0.93 âffffffff8178b42a: mov %r9,0x10(%rsp)
1.57 âffffffff8178b42f: mov %r10,0x8(%rsp)
3.70 âffffffff8178b434: mov %r11,(%rsp)
2.27 âffffffff8178b438: mov %rax,0x48(%rsp)

Note how the 7-byte NOP after the STI did not get a single profiler
hit.

This is with the default '-e cycles', not '-e cycles:pp', so what we
see as profiler hits should be the raw NMI entry RIPs.

Arguably this could be just the decoder hiding the NOP efficiently,
I'll try to run some more experiments ...

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/