From: "Longpeng (Mike)" <longpeng2@huawei.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Wanpeng Li" <kernellwp@gmail.com>
Cc: kvm <kvm@vger.kernel.org>, "Michael S. Tsirkin" <mst@redhat.com>,
Gonglei <arei.gonglei@huawei.com>
Subject: [ help ] vcpu handle MWAIT different
Date: Fri, 9 Jun 2017 11:47:14 +0800 [thread overview]
Message-ID: <593A1A42.2030601@huawei.com> (raw)
Hi guys,
I wrote a testcase which repeat execute MWAIT insn in kvm-unit-test and I tested
it on different hardware, but got different results.
1) cpu: E5620 (hardware don't support MONITOR/MWAIT)
This works well because I saw the following info in trace:
CPU 0/KVM-7301 [015] .... 1534719.099573: kvm_exit: reason
MWAIT_INSTRUCTION rip 0x400387 info 0 0
CPU 0/KVM-7301 [015] d... 1534719.099573: kvm_entry: vcpu 0
CPU 0/KVM-7301 [015] .... 1534719.099574: kvm_exit: reason
MWAIT_INSTRUCTION rip 0x400387 info 0 0
CPU 0/KVM-7301 [015] d... 1534719.099574: kvm_entry: vcpu 0
2) cpu: E5-2620 v3 and E5-2690 v4 (both hardwares support MONITOR/MWAIT)
This...
CPU 0/KVM-1683 [017] .... 4844125.856164: kvm_exit: reason EXCEPTION_NMI
rip 0x400382 info 0 80000306
CPU 0/KVM-1683 [017] .... 4844125.856166: kvm_emulate_insn: 0:400382:0f
01 c9 (prot64)
CPU 0/KVM-1683 [017] .... 4844125.856166: kvm_inj_exception: #UD (0x0)
CPU 0/KVM-1683 [017] d... 4844125.856167: kvm_entry: vcpu 0
and the kvm-unit-test guest reported:
Unhandled exception 6 #UD at ip 0000000000400387
error_code=0000 rflags=00010002 cs=00000008
rax=0000000000000000 rcx=0000000000000000 rdx=0000000200000000 rbx=0000000000000000
rbp=000000000044db60 rsi=0000000000000001 rdi=0000000000004020
r8=000000000000000a r9=00000000000003f8 r10=000000000044d1e2 r11=000000000044d1e1
r12=0000000000000000 r13=0000000000000000 r14=0000000000000000 r15=0000000000000000
cr0=0000000080010011 cr2=0000000000000000 cr3=0000000007fff000 cr4=0000000000000020
cr8=0000000000000000
STACK: @400387 40028f
0x0000000000400387: mwait at x86/perf_exit.c:17
/* "mwait %eax, %ecx;" */
> asm volatile(".byte 0x0f, 0x01, 0xc9;"
:: "a" (eax), "c" (ecx));
(inlined by) main at x86/perf_exit.c:93
mb();
> mwait(0, 0);
mb();
0x000000000040028e: start64 at x86/cstart64.S:206
lea __argv(%rip), %rsi
> call main
mov %eax, %edi
In result 2, the trace shows that vcpu is in 64bit protect-mode (the testcase
didn't jump to ring3 manually, so it's in ring0), as intel vol2 said the MWAIT
will #UD in this situation when:
#UD If the current privilege level is not 0.
If CPUID.01H:ECX.MONITOR[bit 3] = 0.
I think CPUID.01H:ECX.MONITOR does not matter, so I'm so curious about the
result 2 .
Do you have any idea ? Thanks.
PS: Wanpeng tested this on his laptop (maybe the cpu is Core-i7) and it worked
well as result 1.
kvm version : 4.4.11
host kernel : 3.10
The testcase is:
#include "libcflat.h"
#include "smp.h"
#include "vm.h"
#include "processor.h"
#include "desc.h"
#include "apic.h"
#include "apic-defs.h"
#include "asm/barrier.h"
[...]
static inline void mwait(unsigned long eax, unsigned long ecx)
{
/* "mwait %eax, %ecx;" */
asm volatile(".byte 0x0f, 0x01, 0xc9;"
:: "a" (eax), "c" (ecx));
}
[...]
int main(int argc, char **argv)
{
setup_vm();
smp_init();
while (test_cnt--) {
[...]
mwait(0, 0);
[...]
}
[...]
}
--
Regards,
Longpeng(Mike)
next reply other threads:[~2017-06-09 3:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-09 3:47 Longpeng (Mike) [this message]
2017-06-09 3:52 ` [ help ] vcpu handle MWAIT different Longpeng (Mike)
2017-06-09 4:51 ` Nadav Amit
2017-06-09 5:57 ` Longpeng (Mike)
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=593A1A42.2030601@huawei.com \
--to=longpeng2@huawei.com \
--cc=arei.gonglei@huawei.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.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 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.