Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Aug 2014 18:39:18 -0700
From:      Neel Natu <neelnatu@gmail.com>
To:        Martin Steegmanns <martin@unix-users.de>
Cc:        "freebsd-virtualization@freebsd.org" <freebsd-virtualization@freebsd.org>
Subject:   Re: Problem with vmexit on mtrap
Message-ID:  <CAFgRE9GEXfXbiUjW-dJB7u5Bdqp7sE7k4L1fKmrT8n8OJt19oQ@mail.gmail.com>
In-Reply-To: <20140812092407.GC11403@mail.demonism.de>
References:  <20140812092407.GC11403@mail.demonism.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Martin,

On Tue, Aug 12, 2014 at 2:24 AM, Martin Steegmanns <martin@unix-users.de> wrote:
> Hello list!
> I modified bhyve to toggle the MTF bit on an UD2 instruction.
> In a guest system, a program does:
> __asm__ __volatile__(
>     "UD2"
>     "NOP"
>     "xor %rax,%rax"
>     "NOP"
>     "UD2"
> );
>
> On the first UD2, MTF bit is correctly set, but the second
> UD2 is never reached (waited some hours).
> If I manually reset the MTF bit via bhyvectl --setcap,
> guest executione reaches the second UD2 instruction.
>
> A diff of my modifications is attached to this mail.
>
> Am I missing something on vmenter that makes the guest loop forever?
>

The VM-exit instruction length field is valid only for a subset of VM
exits. See section 27.2.4 "Information for VM exits due to instruction
execution" in the Intel SDM.

In particular, the instruction length is not guaranteed to be valid if
the VM-exit is due to a hardware exception. Therefore it cannot be
used to "skip over" the UD2 instruction.

On my machine the VM-exit instruction length field was set to '2' for
the first UD2 and '5' for the second UD2.

For this specific test, you can either hardcode the instruction length
to '2' if the VM exit is due to a UD2 or use an instruction like "OUT"
to a specific I/O port to trigger the monitor-trap-flag on and off. A
VM-exit due to "OUT" will have the correct value in the VM-exit
instruction length field.

best
Neel

> Regards,
> Martin
>
> <snippet of ktr dump>
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1074 vm vm1[0]: unhandled mtf vmexit at 0xffffffff804dde70
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1063 vm vm1[0]: Resume execution at 0xffffffff804dde41
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:2652 vm vm1[0]: returning from vmx_run: exitcode 6
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1074 vm vm1[0]: unhandled mtf vmexit at 0xffffffff804dde41
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1063 vm vm1[0]: Resume execution at 0xffffffff804dde39
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:2652 vm vm1[0]: returning from vmx_run: exitcode 6
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1074 vm vm1[0]: unhandled mtf vmexit at 0xffffffff804dde39
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1063 vm vm1[0]: Resume execution at 0xffffffff804dde30
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:2652 vm vm1[0]: returning from vmx_run: exitcode 6
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1074 vm vm1[0]: unhandled mtf vmexit at 0xffffffff804dde30
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1063 vm vm1[0]: Resume execution at 0xffffffff804dde27
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:2652 vm vm1[0]: returning from vmx_run: exitcode 6
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1074 vm vm1[0]: unhandled mtf vmexit at 0xffffffff804dde27
> /usr/src/sys/modules/vmm/../../amd64/vmm/intel/vmx.c:1063 vm vm1[0]: Resume execution at 0xffffffff804dde1f
> </snippet>
>
> _______________________________________________
> freebsd-virtualization@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization
> To unsubscribe, send any mail to "freebsd-virtualization-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFgRE9GEXfXbiUjW-dJB7u5Bdqp7sE7k4L1fKmrT8n8OJt19oQ>