public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]: Fake MSR_K7 performance counters
@ 2008-04-28 16:45 Chris Lalancette
  2008-05-01 14:23 ` Chris Lalancette
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Lalancette @ 2008-04-28 16:45 UTC (permalink / raw)
  To: kvm-devel

[-- Attachment #1: Type: text/plain, Size: 701 bytes --]

Attached is a patch that fixes a guest crash when booting older Linux kernels.
The problem stems from the fact that we are currently emulating
MSR_K7_EVNTSEL[0-3], but not emulating MSR_K7_PERFCTR[0-3].  Because of this,
setup_k7_watchdog() in the Linux kernel receives a GPF when it attempts to write
into MSR_K7_PERFCTR, which causes an OOPs.

The patch fixes it by just "fake" emulating the appropriate MSRs, throwing away
the data in the process.  This causes the NMI watchdog to not actually work, but
it's not such a big deal in a virtualized environment.

Tested by myself on a RHEL-4 guest, and Joerg Roedel on a Windows XP 64-bit guest.

Signed-off-by: Chris Lalancette <clalance@redhat.com>

[-- Attachment #2: kvm-66-fix-k7-msr.patch --]
[-- Type: text/x-patch, Size: 848 bytes --]

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 89e0be2..6130704 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1284,16 +1284,18 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
 	case MSR_K7_EVNTSEL1:
 	case MSR_K7_EVNTSEL2:
 	case MSR_K7_EVNTSEL3:
+	case MSR_K7_PERFCTR0:
+	case MSR_K7_PERFCTR1:
+	case MSR_K7_PERFCTR2:
+	case MSR_K7_PERFCTR3:
 		/*
-		 * only support writing 0 to the performance counters for now
-		 * to make Windows happy. Should be replaced by a real
-		 * performance counter emulation later.
+		 * Just discard all writes to the performance counters; this
+		 * should keep both older linux and windows 64-bit guests
+		 * happy
 		 */
-		if (data != 0)
-			goto unhandled;
+
 		break;
 	default:
-	unhandled:
 		return kvm_set_msr_common(vcpu, ecx, data);
 	}
 	return 0;

[-- Attachment #3: Type: text/plain, Size: 320 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* Re: [PATCH]: Fake MSR_K7 performance counters
  2008-04-28 16:45 [PATCH]: Fake MSR_K7 performance counters Chris Lalancette
@ 2008-05-01 14:23 ` Chris Lalancette
  2008-05-02 10:00   ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Lalancette @ 2008-05-01 14:23 UTC (permalink / raw)
  To: kvm-devel

Chris Lalancette wrote:
> Attached is a patch that fixes a guest crash when booting older Linux kernels.
> The problem stems from the fact that we are currently emulating
> MSR_K7_EVNTSEL[0-3], but not emulating MSR_K7_PERFCTR[0-3].  Because of this,
> setup_k7_watchdog() in the Linux kernel receives a GPF when it attempts to write
> into MSR_K7_PERFCTR, which causes an OOPs.
> 
> The patch fixes it by just "fake" emulating the appropriate MSRs, throwing away
> the data in the process.  This causes the NMI watchdog to not actually work, but
> it's not such a big deal in a virtualized environment.
> 
> Tested by myself on a RHEL-4 guest, and Joerg Roedel on a Windows XP 64-bit guest.

Avi,
     Do you mind applying this patch for me (unless you see something wrong with
it, of course)?

Thanks,
Chris Lalancette

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

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

* Re: [PATCH]: Fake MSR_K7 performance counters
  2008-05-01 14:23 ` Chris Lalancette
@ 2008-05-02 10:00   ` Avi Kivity
  0 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2008-05-02 10:00 UTC (permalink / raw)
  To: Chris Lalancette; +Cc: kvm-devel

Chris Lalancette wrote:
> Chris Lalancette wrote:
>   
>> Attached is a patch that fixes a guest crash when booting older Linux kernels.
>> The problem stems from the fact that we are currently emulating
>> MSR_K7_EVNTSEL[0-3], but not emulating MSR_K7_PERFCTR[0-3].  Because of this,
>> setup_k7_watchdog() in the Linux kernel receives a GPF when it attempts to write
>> into MSR_K7_PERFCTR, which causes an OOPs.
>>
>> The patch fixes it by just "fake" emulating the appropriate MSRs, throwing away
>> the data in the process.  This causes the NMI watchdog to not actually work, but
>> it's not such a big deal in a virtualized environment.
>>
>> Tested by myself on a RHEL-4 guest, and Joerg Roedel on a Windows XP 64-bit guest.
>>     
>
> Avi,
>      Do you mind applying this patch for me (unless you see something wrong with
> it, of course)?
>
>   

Sorry, was behind on my email. Please add a ratelimited printk() if 
nonzero data is written, so that we know that the guest is using 
partially virtualized features.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

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

* [PATCH]: Fake MSR_K7 performance counters
@ 2008-05-05 17:05 Chris Lalancette
  2008-05-06 11:28 ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Lalancette @ 2008-05-05 17:05 UTC (permalink / raw)
  To: kvm-devel

[-- Attachment #1: Type: text/plain, Size: 914 bytes --]

Attached is a patch that fixes a guest crash when booting older Linux kernels.
The problem stems from the fact that we are currently emulating
MSR_K7_EVNTSEL[0-3], but not emulating MSR_K7_PERFCTR[0-3].  Because of this,
setup_k7_watchdog() in the Linux kernel receives a GPF when it attempts to write
into MSR_K7_PERFCTR, which causes an OOPs.

The patch fixes it by just "fake" emulating the appropriate MSRs, throwing away
the data in the process.  This causes the NMI watchdog to not actually work, but
it's not such a big deal in a virtualized environment.

When we get a write to one of these counters, we printk_ratelimit() a warning.
I decided to print it out for all writes, even if the data is 0; it doesn't seem
to make sense to me to special case when data == 0.

Tested by myself on a RHEL-4 guest, and Joerg Roedel on a Windows XP 64-bit guest.

Signed-off-by: Chris Lalancette <clalance@redhat.com>

[-- Attachment #2: kvm-66-fix-k7-msr2.patch --]
[-- Type: text/x-patch, Size: 930 bytes --]

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 5528121..dc91b09 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1312,16 +1312,19 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
 	case MSR_K7_EVNTSEL1:
 	case MSR_K7_EVNTSEL2:
 	case MSR_K7_EVNTSEL3:
+	case MSR_K7_PERFCTR0:
+	case MSR_K7_PERFCTR1:
+	case MSR_K7_PERFCTR2:
+	case MSR_K7_PERFCTR3:
 		/*
-		 * only support writing 0 to the performance counters for now
-		 * to make Windows happy. Should be replaced by a real
-		 * performance counter emulation later.
+		 * Just discard all writes to the performance counters; this
+		 * should keep both older linux and windows 64-bit guests
+		 * happy
 		 */
-		if (data != 0)
-			goto unhandled;
+		pr_unimpl(vcpu, "unimplemented perfctr wrmsr: 0x%x data 0x%llx\n", ecx, data);
+
 		break;
 	default:
-	unhandled:
 		return kvm_set_msr_common(vcpu, ecx, data);
 	}
 	return 0;

[-- Attachment #3: Type: text/plain, Size: 320 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* Re: [PATCH]: Fake MSR_K7 performance counters
  2008-05-05 17:05 Chris Lalancette
@ 2008-05-06 11:28 ` Avi Kivity
  0 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2008-05-06 11:28 UTC (permalink / raw)
  To: Chris Lalancette; +Cc: kvm-devel

Chris Lalancette wrote:
> Attached is a patch that fixes a guest crash when booting older Linux kernels.
> The problem stems from the fact that we are currently emulating
> MSR_K7_EVNTSEL[0-3], but not emulating MSR_K7_PERFCTR[0-3].  Because of this,
> setup_k7_watchdog() in the Linux kernel receives a GPF when it attempts to write
> into MSR_K7_PERFCTR, which causes an OOPs.
>
> The patch fixes it by just "fake" emulating the appropriate MSRs, throwing away
> the data in the process.  This causes the NMI watchdog to not actually work, but
> it's not such a big deal in a virtualized environment.
>
> When we get a write to one of these counters, we printk_ratelimit() a warning.
> I decided to print it out for all writes, even if the data is 0; it doesn't seem
> to make sense to me to special case when data == 0.
>
> Tested by myself on a RHEL-4 guest, and Joerg Roedel on a Windows XP 64-bit guest.
>   

Applied, thanks.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

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

end of thread, other threads:[~2008-05-06 11:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-28 16:45 [PATCH]: Fake MSR_K7 performance counters Chris Lalancette
2008-05-01 14:23 ` Chris Lalancette
2008-05-02 10:00   ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2008-05-05 17:05 Chris Lalancette
2008-05-06 11:28 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox