Hi Udo, 

Thanks for your reply.  When I run my test cases on real physical hardware I can run it through properly and also run in unrestricted guest mode. Looks like Nested VT on Qemu_KVM environment is buggy. Anyway thanks for looking into this problem and giving nice thought.

Regards
Avinash.



On Mon, Nov 11, 2013 at 5:27 PM, Udo Steinberg <udo@...121...> wrote:
On Fri, 8 Nov 2013 12:30:10 +0530 avinash singh (AS) wrote:

AS> However, I also modified my test program to delegate IO ports upfront
AS> before launching vcpu.  But I still get vcpu_ioaccess_handler invoked.
AS> Please see below,

In line 347, there is the following piece of code:

bool success = utcb_main->append_item(Io_crd(0, ORDER_64k), HOTSPOT, MAP_FROM_KERNEL, false);

I added "false" at the end to make the difference explicit. When running
that piece of code I'm getting the following output:

NOVA Microhypervisor v6-d5b54fa (x86_32): Sep  5 2013 16:18:28 [gcc 4.9.0]

[ 0] CORE:0:0:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 3] CORE:0:3:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 1] CORE:0:1:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 7] CORE:0:3:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 5] CORE:0:1:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 4] CORE:0:0:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 6] CORE:0:2:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 2] CORE:0:2:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
 Hello world
All Portal created!
runcpuid addr 0x02001000
eip is initialized
0x00001000
cs 0x02000000
npt fault handler ..
 host_adddr 0x01001000
got cpuid intercept!
IOACCES invoked
IP 0x00001007
dx 0x000003f8
IOACCES invoked
IP 0x00001007
dx 0x000003f8
IOACCESS: Duplicate Request...
[ 0] Killed EC:0xc0011a00 SC:0xc0013500 V:0xd CS:0x1b EIP:0x1001717 CR2:0x0 ERR:0x0 (PT not found)
[ 0] Killed EC:0xc0011b00 SC:0xc0013500 V:0x1e CR0:0x10031 CR3:0x0 CR4:0x0 (IPC Abort)


As expected, I/O accesses cause VM exits because the G-bit has not been set.

So then I've changed line 347 as follows:

bool success = utcb_main->append_item(Io_crd(0, ORDER_64k), HOTSPOT, MAP_FROM_KERNEL, true);

and I'm getting the following output:

NOVA Microhypervisor v6-d5b54fa (x86_32): Sep  5 2013 16:18:28 [gcc 4.9.0]

[ 0] CORE:0:0:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 4] CORE:0:0:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 2] CORE:0:2:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 6] CORE:0:2:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 3] CORE:0:3:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 5] CORE:0:1:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 7] CORE:0:3:1 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
[ 1] CORE:0:1:0 6:3c:3:1 [10] Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
 Hello world
All Portal created!
runcpuid addr 0x02001000
eip is initialized
0x00001000
cs 0x02000000
npt fault handler ..
 host_adddr 0x01001000
got cpuid intercept!
Egot cpuid intercept!
[ 0] Killed EC:0xc0012b00 SC:0xc0014500 V:0xc CR0:0x10031 CR3:0x0 CR4:0x0 (PT not found)

The EC is killed due to an unhandled HLT VM exit, which is expected. As you
can see, there are no I/O exits and everything works as expected. Also note
that the 'E' from startup.s line 46 is being printed to serial line in front
of the CPUID output.

AS> I am not sure what is wrong here. Because same logic works for AMD process.
AS> Please could you just see main.cc if something is I am doing wrong there.
AS> Goal is to run cpuid ad oubt instruction in guest mode with paging disabled
AS> and protected mode bit on.

I believe the problem is that you run NOVA as a nested hypervisor under KVM
and if KVM is not virtualizing VMX correctly, then you get these kind of
problems. Can you try running your tests on bare hardware (as I did) to see
if they work correctly there?

AS> > AS> My question is, does NOVA kernel supports to run intel cpu in
AS> > AS> unrestricted guest mode? or is there any trick to do that so. Please
AS> > AS> help me if I am missing something.
AS> >
AS> > NOVA automatically enables unrestricted guest if the CPU supports it. The
AS> > feature is supported on processors based on the Westmere or newer
AS> > microarchitectures. Unrestricted guest will be disabled, if the user
AS>
AS> [ 0] VMCS:0x017ef000 REV:0x11e57ed0 EPT:0 URG:0 VNMI:1 VPID:0
AS> [ 0] CORE:0:0:0 6:f:b:0 [1] Intel(R) Core(TM)2 Duo CPU     T7700  @ 2.40GHz

First of all, the VMCS revision identifier looks really odd. Secondly, the
virtual CPU claims not to support EPT or unrestricted guest, as you can see
from the EPT and URG fields both showing a 0. This means KVM is not
emulating EPT/URG support and thus NOVA cannot enable it. Again, running the
test on bare hardware may be a better idea, because you rule out KVM as a
potential source of bugs.

Let me know what else you find out.

Cheers,
Udo



--
Avinash Singh
Gurgaon, Mob: 7838884449