Patchwork cpu: msr: GPF avoidance on BOCHs QEMU systems (LP: #925001)

login
register
mail settings
Submitter Colin King
Date Feb. 2, 2012, 10:46 a.m.
Message ID <1328179586-30547-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/139115/
State Accepted
Headers show

Comments

Colin King - Feb. 2, 2012, 10:46 a.m.
From: Colin Ian King <colin.king@canonical.com>

Bochs firmware based QEMU systems on some configurations get
General Protection Faults when running the MSR tests.  Since this
isn't real hardware that we care about we can just kludge around
this by not allowing the MSR tests in Bochs based systems.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/msr/msr.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
Alex Hung - Feb. 2, 2012, 11:13 a.m.
On 02/02/2012 06:46 PM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Bochs firmware based QEMU systems on some configurations get
> General Protection Faults when running the MSR tests.  Since this
> isn't real hardware that we care about we can just kludge around
> this by not allowing the MSR tests in Bochs based systems.
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/cpu/msr/msr.c |   19 +++++++++++++++++++
>   1 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/src/cpu/msr/msr.c b/src/cpu/msr/msr.c
> index d6aa00e..5de27a7 100644
> --- a/src/cpu/msr/msr.c
> +++ b/src/cpu/msr/msr.c
> @@ -30,6 +30,8 @@ static fwts_cpuinfo_x86 *cpuinfo;
>
>   static int msr_init(fwts_framework *fw)
>   {
> +	char *bios_vendor;
> +
>   	if ((cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>   		fwts_log_error(fw, "Cannot get CPU info");
>   		return FWTS_ERROR;
> @@ -45,6 +47,23 @@ static int msr_init(fwts_framework *fw)
>   		fwts_log_error(fw, "Cannot detect the number of CPUs on this machine.");
>   		return FWTS_ABORTED;
>   	}
> +
> +	/*
> +	 * Running MSR tests inside virtual machines such as QEMU with some kernel/kvm
> +	 * combinations have been observed to cause GPFs.  We kludge around this by
> +	 * avoiding MSR tests for a Bochs BIOS based QEMU virtual machine.
> +	 */
> +	if ((bios_vendor = fwts_get("/sys/class/dmi/id/bios_vendor")) != NULL) {
> +		if (strstr(bios_vendor, "Bochs")) {
> +			fwts_log_error(fw,
> +				"MSR test being avoiding inside a virtual machine as "
> +				"this is known to cause General Protection Faults on "
> +				"some configurations.");
> +			free(bios_vendor);
> +			return FWTS_SKIP;
> +		}
> +		free(bios_vendor);
> +	}
>   	return FWTS_OK;
>   }
>
Ack'ed by Alex Hung <alex.hung@canonical.com>
Chris Van Hoof - Feb. 4, 2012, 6:37 a.m.
On 02/02/2012 05:46 AM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Bochs firmware based QEMU systems on some configurations get
> General Protection Faults when running the MSR tests.  Since this
> isn't real hardware that we care about we can just kludge around
> this by not allowing the MSR tests in Bochs based systems.
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/cpu/msr/msr.c |   19 +++++++++++++++++++
>   1 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/src/cpu/msr/msr.c b/src/cpu/msr/msr.c
> index d6aa00e..5de27a7 100644
> --- a/src/cpu/msr/msr.c
> +++ b/src/cpu/msr/msr.c
> @@ -30,6 +30,8 @@ static fwts_cpuinfo_x86 *cpuinfo;
>
>   static int msr_init(fwts_framework *fw)
>   {
> +	char *bios_vendor;
> +
>   	if ((cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>   		fwts_log_error(fw, "Cannot get CPU info");
>   		return FWTS_ERROR;
> @@ -45,6 +47,23 @@ static int msr_init(fwts_framework *fw)
>   		fwts_log_error(fw, "Cannot detect the number of CPUs on this machine.");
>   		return FWTS_ABORTED;
>   	}
> +
> +	/*
> +	 * Running MSR tests inside virtual machines such as QEMU with some kernel/kvm
> +	 * combinations have been observed to cause GPFs.  We kludge around this by
> +	 * avoiding MSR tests for a Bochs BIOS based QEMU virtual machine.
> +	 */
> +	if ((bios_vendor = fwts_get("/sys/class/dmi/id/bios_vendor")) != NULL) {
> +		if (strstr(bios_vendor, "Bochs")) {
> +			fwts_log_error(fw,
> +				"MSR test being avoiding inside a virtual machine as "
> +				"this is known to cause General Protection Faults on "
> +				"some configurations.");
> +			free(bios_vendor);
> +			return FWTS_SKIP;
> +		}
> +		free(bios_vendor);
> +	}
>   	return FWTS_OK;
>   }
>

Put together a test build[0] of fwts-live based with kernel 3.2.0-14.23 
+ fwts version 0.24.17 + this patch patch[1]:

  * [0] -- 
http://hwe.ubuntu.com/fwts-live/test_images/fwts-live-oneiric-amd64-experimental-usb-hdd-20120204-0.img
  * [1] -- 
http://kernel.ubuntu.com/git?p=vanhoof/fwts.git;a=shortlog;h=refs/heads/kvm-msr-test
  * [1] -- https://launchpad.net/~vanhoof/+archive/fwts-sandbox/+packages

"""
$ sudo kvm -m 512 -hda 
fwts-live-oneiric-amd64-experimental-usb-hdd-20120204-0.img --vga vmware

[ while in kvm instance ]

$ dmesg | grep BOCHS
ACPI: RSDP 00000000000fd9a0 00014 (v00 BOCHS )

$ dpkg -l fwts
[...]
ii  fwts	0.24.17ubuntu1 Firmware Test Suite

$ sudo fwts msr
Running 1 tests. results appended to results.log
Test: MSR register tests
  Test skipped..
"""

Everything looks good on my end and the rest of the --batch tests 
continue as expected.  Thanks Colin!

--chris

Tested-by: Chris Van Hoof <vanhoof@canonical.com>
Keng-Yu Lin - Feb. 7, 2012, 9:07 a.m.
On Thu, Feb 2, 2012 at 7:13 PM, Alex Hung <alex.hung@canonical.com> wrote:
> On 02/02/2012 06:46 PM, Colin King wrote:
>>
>> From: Colin Ian King<colin.king@canonical.com>
>>
>> Bochs firmware based QEMU systems on some configurations get
>> General Protection Faults when running the MSR tests.  Since this
>> isn't real hardware that we care about we can just kludge around
>> this by not allowing the MSR tests in Bochs based systems.
>>
>> Signed-off-by: Colin Ian King<colin.king@canonical.com>
>> ---
>>  src/cpu/msr/msr.c |   19 +++++++++++++++++++
>>  1 files changed, 19 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/cpu/msr/msr.c b/src/cpu/msr/msr.c
>> index d6aa00e..5de27a7 100644
>> --- a/src/cpu/msr/msr.c
>> +++ b/src/cpu/msr/msr.c
>> @@ -30,6 +30,8 @@ static fwts_cpuinfo_x86 *cpuinfo;
>>
>>  static int msr_init(fwts_framework *fw)
>>  {
>> +       char *bios_vendor;
>> +
>>        if ((cpuinfo = fwts_cpu_get_info(0)) == NULL) {
>>                fwts_log_error(fw, "Cannot get CPU info");
>>                return FWTS_ERROR;
>> @@ -45,6 +47,23 @@ static int msr_init(fwts_framework *fw)
>>                fwts_log_error(fw, "Cannot detect the number of CPUs on
>> this machine.");
>>                return FWTS_ABORTED;
>>        }
>> +
>> +       /*
>> +        * Running MSR tests inside virtual machines such as QEMU with
>> some kernel/kvm
>> +        * combinations have been observed to cause GPFs.  We kludge
>> around this by
>> +        * avoiding MSR tests for a Bochs BIOS based QEMU virtual machine.
>> +        */
>> +       if ((bios_vendor = fwts_get("/sys/class/dmi/id/bios_vendor")) !=
>> NULL) {
>> +               if (strstr(bios_vendor, "Bochs")) {
>> +                       fwts_log_error(fw,
>> +                               "MSR test being avoiding inside a virtual
>> machine as "
>> +                               "this is known to cause General Protection
>> Faults on "
>> +                               "some configurations.");
>> +                       free(bios_vendor);
>> +                       return FWTS_SKIP;
>> +               }
>> +               free(bios_vendor);
>> +       }
>>        return FWTS_OK;
>>  }
>>
> Ack'ed by Alex Hung <alex.hung@canonical.com>

Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/cpu/msr/msr.c b/src/cpu/msr/msr.c
index d6aa00e..5de27a7 100644
--- a/src/cpu/msr/msr.c
+++ b/src/cpu/msr/msr.c
@@ -30,6 +30,8 @@  static fwts_cpuinfo_x86 *cpuinfo;
 
 static int msr_init(fwts_framework *fw)
 {
+	char *bios_vendor;
+
 	if ((cpuinfo = fwts_cpu_get_info(0)) == NULL) {
 		fwts_log_error(fw, "Cannot get CPU info");
 		return FWTS_ERROR;
@@ -45,6 +47,23 @@  static int msr_init(fwts_framework *fw)
 		fwts_log_error(fw, "Cannot detect the number of CPUs on this machine.");
 		return FWTS_ABORTED;
 	}
+
+	/*
+	 * Running MSR tests inside virtual machines such as QEMU with some kernel/kvm
+	 * combinations have been observed to cause GPFs.  We kludge around this by
+	 * avoiding MSR tests for a Bochs BIOS based QEMU virtual machine.
+	 */
+	if ((bios_vendor = fwts_get("/sys/class/dmi/id/bios_vendor")) != NULL) {
+		if (strstr(bios_vendor, "Bochs")) {
+			fwts_log_error(fw,
+				"MSR test being avoiding inside a virtual machine as "
+				"this is known to cause General Protection Faults on "
+				"some configurations.");
+			free(bios_vendor);
+			return FWTS_SKIP;
+		}
+		free(bios_vendor);
+	}
 	return FWTS_OK;
 }