All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: obey guest PAT
@ 2017-10-26  7:13 Paolo Bonzini
  2017-10-26  8:17 ` David Hildenbrand
  2017-11-10 21:27 ` Radim Krčmář
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2017-10-26  7:13 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: stable

For many years some users of assigned devices have reported worse
performance on AMD processors with NPT than on AMD without NPT,
Intel or bare metal.

The reason turned out to be that SVM is discarding the guest PAT
setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-,
PA3=UC).  The guest might be using a different setting, and
especially might want write combining but isn't getting it
(instead getting slow UC or UC- accesses).

Thanks a lot to geoff@hostfission.com for noticing the relation
to the g_pat setting.  The patch has been tested also by a bunch
of people on VFIO users forums.

Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464
Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/svm.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index af256b786a70..af09baa3d736 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3626,6 +3626,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 	u32 ecx = msr->index;
 	u64 data = msr->data;
 	switch (ecx) {
+	case MSR_IA32_CR_PAT:
+		if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
+			return 1;
+		vcpu->arch.pat = data;
+		svm->vmcb->save.g_pat = data;
+		mark_dirty(svm->vmcb, VMCB_NPT);
+		break;
 	case MSR_IA32_TSC:
 		kvm_write_tsc(vcpu, msr);
 		break;
-- 
2.14.2

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

* Re: [PATCH] KVM: SVM: obey guest PAT
  2017-10-26  7:13 [PATCH] KVM: SVM: obey guest PAT Paolo Bonzini
@ 2017-10-26  8:17 ` David Hildenbrand
  2017-10-26 15:00   ` Nick Sarnie
  2017-11-10 21:27 ` Radim Krčmář
  1 sibling, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2017-10-26  8:17 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm; +Cc: stable

On 26.10.2017 09:13, Paolo Bonzini wrote:
> For many years some users of assigned devices have reported worse
> performance on AMD processors with NPT than on AMD without NPT,
> Intel or bare metal.
> 
> The reason turned out to be that SVM is discarding the guest PAT
> setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-,
> PA3=UC).  The guest might be using a different setting, and
> especially might want write combining but isn't getting it
> (instead getting slow UC or UC- accesses).
> 
> Thanks a lot to geoff@hostfission.com for noticing the relation
> to the g_pat setting.  The patch has been tested also by a bunch
> of people on VFIO users forums.
> 
> Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464
> Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409
> Cc: stable@vger.kernel.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index af256b786a70..af09baa3d736 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -3626,6 +3626,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
>  	u32 ecx = msr->index;
>  	u64 data = msr->data;
>  	switch (ecx) {
> +	case MSR_IA32_CR_PAT:
> +		if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
> +			return 1;
> +		vcpu->arch.pat = data;
> +		svm->vmcb->save.g_pat = data;
> +		mark_dirty(svm->vmcb, VMCB_NPT);
> +		break;
>  	case MSR_IA32_TSC:
>  		kvm_write_tsc(vcpu, msr);
>  		break;
> 

Although no SVM expert, looking at the way it is handled on VMX, this
looks good to me.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David

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

* Re: [PATCH] KVM: SVM: obey guest PAT
  2017-10-26  8:17 ` David Hildenbrand
@ 2017-10-26 15:00   ` Nick Sarnie
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Sarnie @ 2017-10-26 15:00 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: Paolo Bonzini, linux-kernel, kvm, stable

On Thu, Oct 26, 2017 at 4:17 AM, David Hildenbrand <david@redhat.com> wrote:
> On 26.10.2017 09:13, Paolo Bonzini wrote:
>> For many years some users of assigned devices have reported worse
>> performance on AMD processors with NPT than on AMD without NPT,
>> Intel or bare metal.
>>
>> The reason turned out to be that SVM is discarding the guest PAT
>> setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-,
>> PA3=UC).  The guest might be using a different setting, and
>> especially might want write combining but isn't getting it
>> (instead getting slow UC or UC- accesses).
>>
>> Thanks a lot to geoff@hostfission.com for noticing the relation
>> to the g_pat setting.  The patch has been tested also by a bunch
>> of people on VFIO users forums.
>>
>> Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464
>> Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  arch/x86/kvm/svm.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index af256b786a70..af09baa3d736 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -3626,6 +3626,13 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
>>       u32 ecx = msr->index;
>>       u64 data = msr->data;
>>       switch (ecx) {
>> +     case MSR_IA32_CR_PAT:
>> +             if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
>> +                     return 1;
>> +             vcpu->arch.pat = data;
>> +             svm->vmcb->save.g_pat = data;
>> +             mark_dirty(svm->vmcb, VMCB_NPT);
>> +             break;
>>       case MSR_IA32_TSC:
>>               kvm_write_tsc(vcpu, msr);
>>               break;
>>
>
> Although no SVM expert, looking at the way it is handled on VMX, this
> looks good to me.
>
> Reviewed-by: David Hildenbrand <david@redhat.com>
>
> --
>
> Thanks,
>
> David

Tested-by: Nick Sarnie <commendsarnex@gmail.com>

You're a legend.

Thanks,
Sarnex

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

* Re: [PATCH] KVM: SVM: obey guest PAT
  2017-10-26  7:13 [PATCH] KVM: SVM: obey guest PAT Paolo Bonzini
  2017-10-26  8:17 ` David Hildenbrand
@ 2017-11-10 21:27 ` Radim Krčmář
  1 sibling, 0 replies; 4+ messages in thread
From: Radim Krčmář @ 2017-11-10 21:27 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm, stable

2017-10-26 09:13+0200, Paolo Bonzini:
> For many years some users of assigned devices have reported worse
> performance on AMD processors with NPT than on AMD without NPT,
> Intel or bare metal.
> 
> The reason turned out to be that SVM is discarding the guest PAT
> setting and uses the default (PA0=PA4=WB, PA1=PA5=WT, PA2=PA6=UC-,
> PA3=UC).  The guest might be using a different setting, and
> especially might want write combining but isn't getting it
> (instead getting slow UC or UC- accesses).
> 
> Thanks a lot to geoff@hostfission.com for noticing the relation
> to the g_pat setting.  The patch has been tested also by a bunch
> of people on VFIO users forums.
> 
> Fixes: 709ddebf81cb40e3c36c6109a7892e8b93a09464
> Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=196409
> Cc: stable@vger.kernel.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Applied, thanks.

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

end of thread, other threads:[~2017-11-10 21:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-26  7:13 [PATCH] KVM: SVM: obey guest PAT Paolo Bonzini
2017-10-26  8:17 ` David Hildenbrand
2017-10-26 15:00   ` Nick Sarnie
2017-11-10 21:27 ` Radim Krčmář

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.