All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs
@ 2011-05-26  9:08 Josh Triplett
  2011-05-26  9:12 ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Josh Triplett @ 2011-05-26  9:08 UTC (permalink / raw)
  To: qemu-devel

qemu currently returns 0 for rdmsr on invalid MSRs, and ignores wrmsr on
invalid MSRs.  Real x86 processors GPF on invalid MSRs, which allows
software to detect unavailable MSRs.  Emulate this behavior correctly in
qemu.

Bug discovered via the BIOS Implementation Test Suite
<http://biosbits.org/>; fix tested the same way, for both 32-bit and
64-bit x86.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---
 op_helper.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -Naur a/target-i386/op_helper.c b/target-i386/op_helper.c
--- a/target-i386/op_helper.c	2011-02-07 15:13:34.000000000 -0800
+++ b/target-i386/op_helper.c	2011-05-26 00:08:49.608636117 -0700
@@ -3135,7 +3135,7 @@
                 env->mce_banks[offset] = val;
             break;
         }
-        /* XXX: exception ? */
+        raise_exception(EXCP0D_GPF);
         break;
     }
 }
@@ -3266,7 +3266,7 @@
             val = env->mce_banks[offset];
             break;
         }
-        /* XXX: exception ? */
+        raise_exception(EXCP0D_GPF);
         val = 0;
         break;
     }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs
  2011-05-26  9:08 [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs Josh Triplett
@ 2011-05-26  9:12 ` Alexander Graf
  2011-05-27 15:13   ` Josh Triplett
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Graf @ 2011-05-26  9:12 UTC (permalink / raw)
  To: Josh Triplett; +Cc: qemu-devel


On 26.05.2011, at 11:08, Josh Triplett wrote:

> qemu currently returns 0 for rdmsr on invalid MSRs, and ignores wrmsr on
> invalid MSRs.  Real x86 processors GPF on invalid MSRs, which allows
> software to detect unavailable MSRs.  Emulate this behavior correctly in
> qemu.
> 
> Bug discovered via the BIOS Implementation Test Suite
> <http://biosbits.org/>; fix tested the same way, for both 32-bit and
> 64-bit x86.

This would break a _lot_ of guests that work just fine today, as qemu doesn't handle all the necessary MSRs.


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs
  2011-05-26  9:12 ` Alexander Graf
@ 2011-05-27 15:13   ` Josh Triplett
  2011-05-27 15:16     ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Josh Triplett @ 2011-05-27 15:13 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

On Thu, May 26, 2011 at 11:12:12AM +0200, Alexander Graf wrote:
> On 26.05.2011, at 11:08, Josh Triplett wrote:
> > qemu currently returns 0 for rdmsr on invalid MSRs, and ignores wrmsr on
> > invalid MSRs.  Real x86 processors GPF on invalid MSRs, which allows
> > software to detect unavailable MSRs.  Emulate this behavior correctly in
> > qemu.
> > 
> > Bug discovered via the BIOS Implementation Test Suite
> > <http://biosbits.org/>; fix tested the same way, for both 32-bit and
> > 64-bit x86.
> 
> This would break a _lot_ of guests that work just fine today, as qemu doesn't handle all the necessary MSRs.

It also fixes guests that rely on the GPF to indicate the absence of an
MSR, and assume that the lack of GPF means the availability of that MSR.
Silently returning 0 for unknown MSRs means silent breakage.

What (buggy) guests expect to use random model-specific registers
without either handling GPFs or checking the CPU model first?

What MSRs do those guests expect that qemu doesn't currently implement?

If this represents a workaround for buggy guests, then may I add an
option to control this behavior?

- Josh Triplett

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs
  2011-05-27 15:13   ` Josh Triplett
@ 2011-05-27 15:16     ` Alexander Graf
  2011-05-27 15:46       ` Josh Triplett
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Graf @ 2011-05-27 15:16 UTC (permalink / raw)
  To: Josh Triplett; +Cc: qemu-devel


On 27.05.2011, at 17:13, Josh Triplett wrote:

> On Thu, May 26, 2011 at 11:12:12AM +0200, Alexander Graf wrote:
>> On 26.05.2011, at 11:08, Josh Triplett wrote:
>>> qemu currently returns 0 for rdmsr on invalid MSRs, and ignores wrmsr on
>>> invalid MSRs.  Real x86 processors GPF on invalid MSRs, which allows
>>> software to detect unavailable MSRs.  Emulate this behavior correctly in
>>> qemu.
>>> 
>>> Bug discovered via the BIOS Implementation Test Suite
>>> <http://biosbits.org/>; fix tested the same way, for both 32-bit and
>>> 64-bit x86.
>> 
>> This would break a _lot_ of guests that work just fine today, as qemu doesn't handle all the necessary MSRs.
> 
> It also fixes guests that rely on the GPF to indicate the absence of an
> MSR, and assume that the lack of GPF means the availability of that MSR.
> Silently returning 0 for unknown MSRs means silent breakage.

It's not about guests triggereing MSRs that they shouldn't. It's that qemu doesn't implement all MSRs that all the respective CPUs implement.

> 
> What (buggy) guests expect to use random model-specific registers
> without either handling GPFs or checking the CPU model first?

Mac OS X for example :). It even breaks on KVM today due to MSR checks.

> 
> What MSRs do those guests expect that qemu doesn't currently implement?
> 
> If this represents a workaround for buggy guests, then may I add an
> option to control this behavior?

I'm not against this change per-se, but it should definitely have an option to disable/enable it and you need to do very extensive testing to make sure that all MSRs for most OSs are actually handled.


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs
  2011-05-27 15:16     ` Alexander Graf
@ 2011-05-27 15:46       ` Josh Triplett
  0 siblings, 0 replies; 5+ messages in thread
From: Josh Triplett @ 2011-05-27 15:46 UTC (permalink / raw)
  To: Alexander Graf; +Cc: qemu-devel

On Fri, May 27, 2011 at 05:16:56PM +0200, Alexander Graf wrote:
> 
> On 27.05.2011, at 17:13, Josh Triplett wrote:
> 
> > On Thu, May 26, 2011 at 11:12:12AM +0200, Alexander Graf wrote:
> >> On 26.05.2011, at 11:08, Josh Triplett wrote:
> >>> qemu currently returns 0 for rdmsr on invalid MSRs, and ignores wrmsr on
> >>> invalid MSRs.  Real x86 processors GPF on invalid MSRs, which allows
> >>> software to detect unavailable MSRs.  Emulate this behavior correctly in
> >>> qemu.
> >>> 
> >>> Bug discovered via the BIOS Implementation Test Suite
> >>> <http://biosbits.org/>; fix tested the same way, for both 32-bit and
> >>> 64-bit x86.
> >> 
> >> This would break a _lot_ of guests that work just fine today, as qemu doesn't handle all the necessary MSRs.
> > 
> > It also fixes guests that rely on the GPF to indicate the absence of an
> > MSR, and assume that the lack of GPF means the availability of that MSR.
> > Silently returning 0 for unknown MSRs means silent breakage.
> 
> It's not about guests triggereing MSRs that they shouldn't. It's that qemu doesn't implement all MSRs that all the respective CPUs implement.
> 
> > What (buggy) guests expect to use random model-specific registers
> > without either handling GPFs or checking the CPU model first?
> 
> Mac OS X for example :). It even breaks on KVM today due to MSR checks.

Ah, of course, since they only run on their own hardware.  Fair enough.

> > What MSRs do those guests expect that qemu doesn't currently implement?
> > 
> > If this represents a workaround for buggy guests, then may I add an
> > option to control this behavior?
> 
> I'm not against this change per-se, but it should definitely have an option to disable/enable it and you need to do very extensive testing to make sure that all MSRs for most OSs are actually handled.

Fair enough.  Expect PATCHv2 with an option in the near future.

- Josh Triplett

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-05-27 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26  9:08 [Qemu-devel] [PATCH] target-i386: GPF on invalid MSRs Josh Triplett
2011-05-26  9:12 ` Alexander Graf
2011-05-27 15:13   ` Josh Triplett
2011-05-27 15:16     ` Alexander Graf
2011-05-27 15:46       ` Josh Triplett

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.