/* * Copyright (C) 2006, Intel Corporation * Copyright (C) 2007, AMD Inc * * This file is part of the Linux-ready Firmware Developer Kit * * This program file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation;version 2.1 of the License. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program in a file named COPYING; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ /* * This test checks if the VT-setup is done correctly by the BIOS */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned long long readmsr(int cpu, unsigned long offset) { char buffer[PATH_MAX]; FILE *file; int fd; unsigned long long msr_value=0xffffffff; unsigned char *msr_value_buf; int ret; msr_value_buf = (unsigned char *)&msr_value; sprintf(buffer, "/dev/cpu/%i/msr", cpu); file = fopen(buffer, "r"); if (!file) { printf("Error: fopen failed \n"); return -1; } fd = fileno(file); ret = pread(fd, msr_value_buf, 8, offset); fclose(file); if (ret<0) { printf("Error: pread failed %d\n, errno=%d", ret, errno); return -2; } return msr_value; } static int cpu_has_vmx(void) { char line[4096]; int hasit = 0; FILE *file; file = fopen("/proc/cpuinfo", "r"); if (!file) return 0; while (!feof(file)) { memset(line, 0, 4096); fgets(line, 4095, file); if (strstr(line,"flags") && strstr(line," vmx")) hasit = 1; } fclose(file); return hasit; } #define MSR_FEATURE_CONTROL 0x03a static int vt_locked_by_bios(void) { uint64_t msr; msr = readmsr(0, MSR_FEATURE_CONTROL); return (msr & 5) == 1; /* VT capable but locked by bios*/ } int do_virt_check_vmx() { FILE *file; start_test("virt", "VT/VMX Virtualization extensions", "This test checks if VT/VMX is set up correctly"); if (!cpu_has_vmx()) report_result("virt", INFO, "Processor does not support Virtualization extensions", NULL, NULL); else if (vt_locked_by_bios()) report_result("virt", FAIL, "Virtualization extensions supported but disabled by BIOS", NULL, NULL); finish_test("virt"); return EXIT_SUCCESS; }