Detecting Hardware Virtualization support for xVM

Yesterday, the xVM project team integrated the OpenSolaris code to enable using a Hypervisor on Solaris x64. This supports running multiple OS instances on a single box. If you want to run an operating system that has been paravirtualized, such as OpenSolaris or Linux, almost any CPU that supports regular OpenSolaris is good enough.

However to run an Operating System, say one from Microsoft, that hasn't been paravirtualized, you'll need a recent Intel or AMD CPU that contains hardware virtualization support and the BIOS in your system will have to enable (or not disable) that support.

The following Solaris program can be compiled and run to determine if HVM support will work when a system is booted under an xVM dom0. Note that this should be run when the system is not using the hypervisor.

/\*
 \* CDDL HEADER START
 \*
 \* The contents of this file are subject to the terms of the
 \* Common Development and Distribution License (the "License").
 \* You may not use this file except in compliance with the License.
 \*
 \* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 \* or http://www.opensolaris.org/os/licensing.
 \* See the License for the specific language governing permissions
 \* and limitations under the License.
 \*
 \* When distributing Covered Code, include this CDDL HEADER in each
 \* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 \* If applicable, add the following below this CDDL HEADER, with the
 \* fields enclosed by brackets "[]" replaced with your own identifying
 \* information: Portions Copyright [yyyy] [name of copyright owner]
 \*
 \* CDDL HEADER END
 \*/

/\*
 \* Test to see if Intel VT-x or AMD-v is supported according to cpuid.
 \*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>

static const char devname[] = "/dev/cpu/self/cpuid";

#define EAX     0
#define EBX     1
#define ECX     2
#define EDX     3

int
main(int argc, char \*\*argv)
{
        int device;
        uint32_t func;
        uint32_t regs[4];
        uint32_t v;
        int r;
        int bit;
        int nbits;

        /\*
         \* open cpuid device
         \*/
        device = open(devname, O_RDONLY);
        if (device == -1)
                goto fail;

        func = 0x0;
        if (pread(device, regs, sizeof (regs), func) != sizeof (regs))
                goto fail;

        if (regs[EBX] == 0x68747541 &&
            regs[ECX] == 0x444d4163 &&
            regs[EDX] == 0x69746e65) { /\* AuthenticAMD \*/

                func = 0x80000001;
                r = ECX;
                bit = 2;
                nbits = 1;

        } else if (regs[EBX] == 0x756e6547 &&
            regs[ECX] == 0x6c65746e &&
            regs[EDX] == 0x49656e69) { /\* GenuineIntel \*/

                func = 1;
                r = ECX;
                bit = 5;
                nbits = 1;

        } else {
                goto fail;
        }

        if (pread(device, regs, sizeof (regs), func) != sizeof (regs))
                goto fail;

        v = regs[r] >> bit;
        if (nbits < 32 && nbits > 0)
                v &= (1 << nbits) - 1;

        if (v)
                printf("yes\\n");
        else
                printf("no\\n");

        (void) close(device);
        exit(0);

fail:
        printf("no\\n");
        (void) close(device);
        exit(1);
}

Comments:

[Trackback] Wer heute OpenSolaris und Xen / xVM benutzen m&#246;chte kann sich ein auf Nevada build 66 basiertes, f&#252;r XEN gepatchtes DVD-Image herunterladen. F&#252;r neuere builds gibt es auch M&#246;glichkeiten, einige Fachkenntnis vorausgesetzt. Das Gebast...

Posted by Otmanix Blog on September 19, 2007 at 08:26 AM PDT #

Awesome! Thanks.

I got a "yes" on my Sony VAIO SZ-330P.

Posted by Tim Kennedy on October 03, 2007 at 12:30 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

JoeBonasera

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News

No bookmarks in folder

Blogroll

No bookmarks in folder