kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: svm: remove KVM_QUIRK_CD_NW_CLEARED quirk
@ 2015-07-10 12:01 Paolo Bonzini
  2015-07-10 15:16 ` Joerg Roedel
  2015-07-10 16:04 ` Xiao Guangrong
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2015-07-10 12:01 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: guangrong.xiao, joerg.roedel

We can disable CD unconditionally when there is no assigned device.
KVM now forces guest PAT to all-writeback in that case, so it makes
sense to also force CR0.CD=0.

When there are assigned devices, emulate cache-disabled operation
through the page tables.  This behavior is consistent with VMX,
where CD/NW are not touched by vmentry/vmexit.

Note that buggy firmware that does not clear CD/NW is _seriously_
old: SeaBIOS for example has been doing it since October 2008.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/svm.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index bbc678a66b18..9b1513065a6a 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1173,6 +1173,9 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
 	if (!is_mmio && !kvm_arch_has_assigned_device(vcpu->kvm))
 		return 0;
 
+	if (kvm_read_cr0(vcpu) & X86_CR0_CD)
+		return _PAGE_NOCACHE;
+
 	mtrr = kvm_mtrr_get_guest_memory_type(vcpu, gfn);
 	return mtrr2protval[mtrr];
 }
@@ -1667,13 +1670,10 @@ static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 
 	if (!vcpu->fpu_active)
 		cr0 |= X86_CR0_TS;
-	/*
-	 * re-enable caching here because the QEMU bios
-	 * does not do it - this results in some delay at
-	 * reboot
-	 */
-	if (!(vcpu->kvm->arch.disabled_quirks & KVM_QUIRK_CD_NW_CLEARED))
-		cr0 &= ~(X86_CR0_CD | X86_CR0_NW);
+
+	/* These are emulated via page tables.  */
+	cr0 &= ~(X86_CR0_CD | X86_CR0_NW);
+
 	svm->vmcb->save.cr0 = cr0;
 	mark_dirty(svm->vmcb, VMCB_CR);
 	update_cr0_intercept(svm);
-- 
1.8.3.1

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

* Re: [PATCH] KVM: svm: remove KVM_QUIRK_CD_NW_CLEARED quirk
  2015-07-10 12:01 [PATCH] KVM: svm: remove KVM_QUIRK_CD_NW_CLEARED quirk Paolo Bonzini
@ 2015-07-10 15:16 ` Joerg Roedel
  2015-07-10 16:04 ` Xiao Guangrong
  1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2015-07-10 15:16 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm, guangrong.xiao, joerg.roedel

On Fri, Jul 10, 2015 at 02:01:33PM +0200, Paolo Bonzini wrote:
> We can disable CD unconditionally when there is no assigned device.
> KVM now forces guest PAT to all-writeback in that case, so it makes
> sense to also force CR0.CD=0.
> 
> When there are assigned devices, emulate cache-disabled operation
> through the page tables.  This behavior is consistent with VMX,
> where CD/NW are not touched by vmentry/vmexit.
> 
> Note that buggy firmware that does not clear CD/NW is _seriously_
> old: SeaBIOS for example has been doing it since October 2008.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

Looks good to me.

Reviewed-by: Joerg Roedel <jroedel@suse.de>


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

* Re: [PATCH] KVM: svm: remove KVM_QUIRK_CD_NW_CLEARED quirk
  2015-07-10 12:01 [PATCH] KVM: svm: remove KVM_QUIRK_CD_NW_CLEARED quirk Paolo Bonzini
  2015-07-10 15:16 ` Joerg Roedel
@ 2015-07-10 16:04 ` Xiao Guangrong
  1 sibling, 0 replies; 3+ messages in thread
From: Xiao Guangrong @ 2015-07-10 16:04 UTC (permalink / raw)
  To: Paolo Bonzini, linux-kernel, kvm; +Cc: joerg.roedel



On 07/10/2015 08:01 PM, Paolo Bonzini wrote:
> We can disable CD unconditionally when there is no assigned device.
> KVM now forces guest PAT to all-writeback in that case, so it makes
> sense to also force CR0.CD=0.
>
> When there are assigned devices, emulate cache-disabled operation
> through the page tables.  This behavior is consistent with VMX,
> where CD/NW are not touched by vmentry/vmexit.
>
> Note that buggy firmware that does not clear CD/NW is _seriously_
> old: SeaBIOS for example has been doing it since October 2008.

Reviewed-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>

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

end of thread, other threads:[~2015-07-10 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-10 12:01 [PATCH] KVM: svm: remove KVM_QUIRK_CD_NW_CLEARED quirk Paolo Bonzini
2015-07-10 15:16 ` Joerg Roedel
2015-07-10 16:04 ` Xiao Guangrong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).