mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] kvm: x86: final XSAVES bits
@ 2014-12-03 13:40 Paolo Bonzini
  2014-12-03 13:40 ` [PATCH 1/2] KVM: x86: use F() macro throughout cpuid.c Paolo Bonzini
  2014-12-03 13:40 ` [PATCH 2/2] KVM: cpuid: set CPUID(EAX=0xd,ECX=1).EBX correctly Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-12-03 13:40 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: rkrcmar, Wanpeng Li

The final thing to do, besides adding support for XSS != 0, is to set
CPUID(EAX=0xd,ECX=1).EBX to the size of the XSAVES area.

Paolo Bonzini (2):
  KVM: x86: use F() macro throughout cpuid.c
  KVM: x86: set CPUID(EAX=0xd,ECX=1).EBX correctly

 arch/x86/kvm/cpuid.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

-- 
1.8.3.1


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

* [PATCH 1/2] KVM: x86: use F() macro throughout cpuid.c
  2014-12-03 13:40 [PATCH 0/2] kvm: x86: final XSAVES bits Paolo Bonzini
@ 2014-12-03 13:40 ` Paolo Bonzini
  2014-12-03 13:40 ` [PATCH 2/2] KVM: cpuid: set CPUID(EAX=0xd,ECX=1).EBX correctly Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-12-03 13:40 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: rkrcmar, Wanpeng Li

For code that deals with cpuid, this makes things a bit more readable.

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

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index d82204ac555e..2c561dba81c0 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -53,6 +53,8 @@ u64 kvm_supported_xcr0(void)
 	return xcr0;
 }
 
+#define F(x) bit(X86_FEATURE_##x)
+
 int kvm_update_cpuid(struct kvm_vcpu *vcpu)
 {
 	struct kvm_cpuid_entry2 *best;
@@ -64,13 +66,13 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
 
 	/* Update OSXSAVE bit */
 	if (cpu_has_xsave && best->function == 0x1) {
-		best->ecx &= ~(bit(X86_FEATURE_OSXSAVE));
+		best->ecx &= ~F(OSXSAVE);
 		if (kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE))
-			best->ecx |= bit(X86_FEATURE_OSXSAVE);
+			best->ecx |= F(OSXSAVE);
 	}
 
 	if (apic) {
-		if (best->ecx & bit(X86_FEATURE_TSC_DEADLINE_TIMER))
+		if (best->ecx & F(TSC_DEADLINE_TIMER))
 			apic->lapic_timer.timer_mode_mask = 3 << 17;
 		else
 			apic->lapic_timer.timer_mode_mask = 1 << 17;
@@ -122,8 +124,8 @@ static void cpuid_fix_nx_cap(struct kvm_vcpu *vcpu)
 			break;
 		}
 	}
-	if (entry && (entry->edx & bit(X86_FEATURE_NX)) && !is_efer_nx()) {
-		entry->edx &= ~bit(X86_FEATURE_NX);
+	if (entry && (entry->edx & F(NX)) && !is_efer_nx()) {
+		entry->edx &= ~F(NX);
 		printk(KERN_INFO "kvm: guest NX capability removed\n");
 	}
 }
@@ -227,8 +229,6 @@ static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function,
 	entry->flags = 0;
 }
 
-#define F(x) bit(X86_FEATURE_##x)
-
 static int __do_cpuid_ent_emulated(struct kvm_cpuid_entry2 *entry,
 				   u32 func, u32 index, int *nent, int maxnent)
 {
-- 
1.8.3.1



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

* [PATCH 2/2] KVM: cpuid: set CPUID(EAX=0xd,ECX=1).EBX correctly
  2014-12-03 13:40 [PATCH 0/2] kvm: x86: final XSAVES bits Paolo Bonzini
  2014-12-03 13:40 ` [PATCH 1/2] KVM: x86: use F() macro throughout cpuid.c Paolo Bonzini
@ 2014-12-03 13:40 ` Paolo Bonzini
  2014-12-03 14:00   ` Radim Krčmář
  1 sibling, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2014-12-03 13:40 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: rkrcmar, Wanpeng Li

This is the size of the XSAVES area.  This completes guest support
for XSAVES (with no support yet for supervisor states, i.e. XSS == 0
always in guests for now).

Suggested-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/cpuid.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 2c561dba81c0..646e6e830ac3 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -23,7 +23,7 @@
 #include "mmu.h"
 #include "trace.h"
 
-static u32 xstate_required_size(u64 xstate_bv)
+static u32 xstate_required_size(u64 xstate_bv, bool compacted)
 {
 	int feature_bit = 0;
 	u32 ret = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET;
@@ -31,9 +31,10 @@ static u32 xstate_required_size(u64 xstate_bv)
 	xstate_bv &= XSTATE_EXTEND_MASK;
 	while (xstate_bv) {
 		if (xstate_bv & 0x1) {
-		        u32 eax, ebx, ecx, edx;
+		        u32 eax, ebx, ecx, edx, offset;
 		        cpuid_count(0xD, feature_bit, &eax, &ebx, &ecx, &edx);
-			ret = max(ret, eax + ebx);
+			offset = compacted ? ret : ebx;
+			ret = max(ret, offset + eax);
 		}
 
 		xstate_bv >>= 1;
@@ -87,9 +88,13 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
 			(best->eax | ((u64)best->edx << 32)) &
 			kvm_supported_xcr0();
 		vcpu->arch.guest_xstate_size = best->ebx =
-			xstate_required_size(vcpu->arch.xcr0);
+			xstate_required_size(vcpu->arch.xcr0, false);
 	}
 
+	best = kvm_find_cpuid_entry(vcpu, 0xD, 1);
+	if (best && (best->eax & F(XSAVES)))
+		best->ebx = xstate_required_size(vcpu->arch.xcr0, true);
+
 	/*
 	 * The existing code assumes virtual address is 48-bit in the canonical
 	 * address checks; exit if it is ever changed.
-- 
1.8.3.1


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

* Re: [PATCH 2/2] KVM: cpuid: set CPUID(EAX=0xd,ECX=1).EBX correctly
  2014-12-03 13:40 ` [PATCH 2/2] KVM: cpuid: set CPUID(EAX=0xd,ECX=1).EBX correctly Paolo Bonzini
@ 2014-12-03 14:00   ` Radim Krčmář
  0 siblings, 0 replies; 4+ messages in thread
From: Radim Krčmář @ 2014-12-03 14:00 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm, Wanpeng Li

2014-12-03 14:40+0100, Paolo Bonzini:
> This is the size of the XSAVES area.  This completes guest support
> for XSAVES (with no support yet for supervisor states, i.e. XSS == 0
> always in guests for now).
> 
> Suggested-by: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---

Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
(The first one is ok too.)

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

end of thread, other threads:[~2014-12-03 14:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-03 13:40 [PATCH 0/2] kvm: x86: final XSAVES bits Paolo Bonzini
2014-12-03 13:40 ` [PATCH 1/2] KVM: x86: use F() macro throughout cpuid.c Paolo Bonzini
2014-12-03 13:40 ` [PATCH 2/2] KVM: cpuid: set CPUID(EAX=0xd,ECX=1).EBX correctly Paolo Bonzini
2014-12-03 14:00   ` Radim Krčmář

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

all inboxes | Powered by JetHome®