Hi, I''m trying to detect if I''m running as a guest in XEN hypervisor using a simple hypercall like __HYPERVISOR_xen_version with the XENVER_extraversion option. I cannot use any of the API functions for this so I''m trying to setup the required registers and call int 82 myself. This is what I do and unfortunately, it generates an exception 0xd when executing INT 82. Reading the source, I think I''ve figured out that I should put my arguments in a hypercall struct shown below. I might be wrong then. Thanks in advance David --- char buffer[256]; HYPERCALL hypercall; PHYPERCALL phypercall = &hypercall; hypercall.op = 17; // xen_version hypercall.arg[0] = (unsigned long) 1; // xen_extra_version hypercall.arg[1] = (unsigned long) Buffer; memset(Buffer, 0, sizeof(Buffer)); _asm { PUSH EDI; PUSH ESI; PUSH EDX; PUSH ECX; PUSH EBX; PUSH EAX; MOV EAX, phypercall; INT 82; POP EAX; POP EBX; POP ECX POP EDX; POP ESI; POP EDI; } BufferA[255] = ''\0''; Cprintf("Buf: %s\r\n", Buffer); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On 16/12/2008 08:39, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote:> I''m trying to detect if I''m running as a guest in XEN hypervisor using a > simple hypercall like __HYPERVISOR_xen_version with the XENVER_extraversion > option. > I cannot use any of the API functions for this so I''m trying to setup the > required registers and call int 82 myself. > This is what I do and unfortunately, it generates an exception 0xd when > executing INT 82. > > Reading the source, I think I''ve figured out that I should put my arguments in > a hypercall struct shown below. I might be wrong then.See tools/misc/xen-detect.c for a nice approach that even works from user space. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
hnrkssn hnrkssn
2008-Dec-16 10:33 UTC
Re: [Xen-devel] Native hypercall basics using int 82
I have already tried the CPUID approach used in xen-detect.c When I read the info from leaf 0x40000001, it says "Microsoft Hv" when I run it on Citrix XenServer Express Edition. I thought "Microsoft Hv" was supposed to identify Hyper-V? So I have to try another method. Can anybody give me some hints on my assembler example in the initial post for making a hypercall? --- char buffer[256]; HYPERCALL hypercall; PHYPERCALL phypercall = &hypercall; hypercall.op = 17; // xen_version hypercall.arg[0] = (unsigned long) 1; // xen_extra_version hypercall.arg[1] = (unsigned long) Buffer; memset(Buffer, 0, sizeof(Buffer)); _asm { MOV EAX, phypercall; INT 82; } Buffer[255] = ''\0''; Cprintf("Buf: %s\r\n", Buffer); Best Regards, David On Tue, Dec 16, 2008 at 9:47 AM, Keir Fraser <keir.fraser@eu.citrix.com>wrote:> On 16/12/2008 08:39, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote: > > > I''m trying to detect if I''m running as a guest in XEN hypervisor using a > > simple hypercall like __HYPERVISOR_xen_version with the > XENVER_extraversion > > option. > > I cannot use any of the API functions for this so I''m trying to setup the > > required registers and call int 82 myself. > > This is what I do and unfortunately, it generates an exception 0xd when > > executing INT 82. > > > > Reading the source, I think I''ve figured out that I should put my > arguments in > > a hypercall struct shown below. I might be wrong then. > > See tools/misc/xen-detect.c for a nice approach that even works from user > space. > > -- Keir > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Tue, Dec 16, 2008 at 4:39 PM, hnrkssn hnrkssn <hnrkssn@gmail.com> wrote:> MOV EAX, phypercall; > INT 82;You should have used "INT 0x82" ?? -- Paul S. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
We relocate the Xen CPUID info when we emulate Hyper-V. You need to scan for the Xen signature starting at 0x40000000 and then every 0x100 up to 0x40001000. If you find the signature then you have found the contiguous range of Xen CPUID leaves. I should fix xen-detect.c to do this scan. -- Keir On 16/12/2008 10:33, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote:> I have already tried the CPUID approach used in xen-detect.c > When I read the info from leaf 0x40000001, it says "Microsoft Hv" when I run > it on Citrix XenServer Express Edition. > I thought "Microsoft Hv" was supposed to identify Hyper-V? > > So I have to try another method. > Can anybody give me some hints on my assembler example in the initial post for > making a hypercall? > > --- > char buffer[256]; > HYPERCALL hypercall; > PHYPERCALL phypercall = &hypercall; > > hypercall.op = 17; // xen_version > hypercall.arg[0] = (unsigned long) 1; // xen_extra_version > hypercall.arg[1] = (unsigned long) Buffer; > > memset(Buffer, 0, sizeof(Buffer)); > > _asm > { > MOV EAX, phypercall; > INT 82; > } > > Buffer[255] = ''\0''; > > Cprintf("Buf: %s\r\n", Buffer); > > > > Best Regards, > David > > On Tue, Dec 16, 2008 at 9:47 AM, Keir Fraser <keir.fraser@eu.citrix.com> > wrote: >> On 16/12/2008 08:39, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote: >> >>> > I''m trying to detect if I''m running as a guest in XEN hypervisor using a >>> > simple hypercall like __HYPERVISOR_xen_version with the >>> XENVER_extraversion >>> > option. >>> > I cannot use any of the API functions for this so I''m trying to setup the >>> > required registers and call int 82 myself. >>> > This is what I do and unfortunately, it generates an exception 0xd when >>> > executing INT 82. >>> > >>> > Reading the source, I think I''ve figured out that I should put my >>> arguments in >>> > a hypercall struct shown below. I might be wrong then. >> >> See tools/misc/xen-detect.c for a nice approach that even works from user >> space. >> >> -- Keir >> >> > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
hnrkssn hnrkssn
2008-Dec-16 15:04 UTC
Re: [Xen-devel] Native hypercall basics using int 82
Thanks, It''s working like a charm. A background question, why does it "emulate Hyper-V"? Is it configurable? Regards David On Tue, Dec 16, 2008 at 11:59 AM, Keir Fraser <keir.fraser@eu.citrix.com>wrote:> We relocate the Xen CPUID info when we emulate Hyper-V. You need to scan > for the Xen signature — starting at 0x40000000 and then every 0x100 up to > 0x40001000. If you find the signature then you have found the contiguous > range of Xen CPUID leaves. I should fix xen-detect.c to do this scan. > > -- Keir > > > On 16/12/2008 10:33, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote: > > I have already tried the CPUID approach used in xen-detect.c > When I read the info from leaf 0x40000001, it says "Microsoft Hv" when I > run it on Citrix XenServer Express Edition. > I thought "Microsoft Hv" was supposed to identify Hyper-V? > > So I have to try another method. > Can anybody give me some hints on my assembler example in the initial post > for making a hypercall? > > --- > char buffer[256]; > HYPERCALL hypercall; > PHYPERCALL phypercall = &hypercall; > > hypercall.op = 17; // xen_version > hypercall.arg[0] = (unsigned long) 1; // xen_extra_version > hypercall.arg[1] = (unsigned long) Buffer; > > memset(Buffer, 0, sizeof(Buffer)); > > _asm > { > MOV EAX, phypercall; > INT 82; > } > > Buffer[255] = ''\0''; > > Cprintf("Buf: %s\r\n", Buffer); > > > > Best Regards, > David > > On Tue, Dec 16, 2008 at 9:47 AM, Keir Fraser <keir.fraser@eu.citrix.com> > wrote: > > On 16/12/2008 08:39, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote: > > > I''m trying to detect if I''m running as a guest in XEN hypervisor using a > > simple hypercall like __HYPERVISOR_xen_version with the > XENVER_extraversion > > option. > > I cannot use any of the API functions for this so I''m trying to setup the > > required registers and call int 82 myself. > > This is what I do and unfortunately, it generates an exception 0xd when > > executing INT 82. > > > > Reading the source, I think I''ve figured out that I should put my > arguments in > > a hypercall struct shown below. I might be wrong then. > > See tools/misc/xen-detect.c for a nice approach that even works from user > space. > > -- Keir > > > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
I don¹t know whether it¹s configurable in Citrix product. It is configurable in the open source tree (and disabled by default). It¹s probably always on since it¹s harmless and will improve performance of certain Windows guests a tiny bit. -- Keir On 16/12/2008 15:04, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote:> Thanks, > It''s working like a charm. > > A background question, why does it "emulate Hyper-V"? Is it configurable?_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Tue, Dec 16, 2008 at 3:08 PM, Keir Fraser <keir.fraser@eu.citrix.com> wrote:> I don''t know whether it''s configurable in Citrix product. It is configurable > in the open source tree (and disabled by default). It''s probably always on > since it''s harmless and will improve performance of certain Windows guests a > tiny bit. > > -- KeirHow is it enabled in the open source edition? I cannot find any documentation. And how does it improve performance?> > On 16/12/2008 15:04, "hnrkssn hnrkssn" <hnrkssn@gmail.com> wrote: > > Thanks, > It''s working like a charm. > > A background question, why does it "emulate Hyper-V"? Is it configurable? > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On 17/12/2008 11:46, "Andrew Lyon" <andrew.lyon@gmail.com> wrote:> How is it enabled in the open source edition? I cannot find any documentation.Add ''viridian=1'' to your domain config file.> And how does it improve performance?APIC accesses are done via emulated MSRs rather than emulated mmio cycles, which is a teeny bit faster. Also we implement spin-wait notofications, so a vcpu can be descheduled rather than spin. There''s others also we could implement but it''s not clear it would be a win for us. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel