From: Nadav Amit <namit@cs.technion.ac.il>
To: bp@alien8.de
Cc: mingo@kernel.org, nadav.amit@gmail.com, pbonzini@redhat.com,
hpa@zytor.com, mingo@redhat.com, tglx@linutronix.de,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, a.p.zijlstra@chello.nl,
Nadav Amit <namit@cs.technion.ac.il>
Subject: [RESEND PATCH 3/3] KVM: x86: Using cpuid structs in KVM
Date: Wed, 17 Sep 2014 15:54:14 +0300 [thread overview]
Message-ID: <1410958454-7501-4-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1410958454-7501-1-git-send-email-namit@cs.technion.ac.il>
Using cpuid structs in KVM to eliminate cryptic code with many bit operations.
The code does not introduce functional changes.
Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
arch/x86/kvm/cpuid.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 38a0afe..a7479ab 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -18,6 +18,7 @@
#include <linux/uaccess.h>
#include <asm/user.h>
#include <asm/xsave.h>
+#include <asm/cpuid_def.h>
#include "cpuid.h"
#include "lapic.h"
#include "mmu.h"
@@ -357,16 +358,18 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
}
/* function 4 has additional index. */
case 4: {
- int i, cache_type;
+ int i;
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
/* read more entries until cache_type is zero */
for (i = 1; ; ++i) {
+ union cpuid4_eax eax;
+
if (*nent >= maxnent)
goto out;
- cache_type = entry[i - 1].eax & 0x1f;
- if (!cache_type)
+ eax.full = entry[i - 1].eax;
+ if (!eax.split.cache_type)
break;
do_cpuid_1_ent(&entry[i], function, i);
entry[i].flags |=
@@ -423,16 +426,18 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
}
/* function 0xb has additional index. */
case 0xb: {
- int i, level_type;
+ int i;
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
/* read more entries until level_type is zero */
for (i = 1; ; ++i) {
+ union cpuid11_ecx ecx;
+
if (*nent >= maxnent)
goto out;
- level_type = entry[i - 1].ecx & 0xff00;
- if (!level_type)
+ ecx.full = entry[i - 1].ecx;
+ if (!ecx.split.level_type)
break;
do_cpuid_1_ent(&entry[i], function, i);
entry[i].flags |=
@@ -505,13 +510,13 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
entry->eax = entry->ebx = entry->ecx = 0;
break;
case 0x80000008: {
- unsigned g_phys_as = (entry->eax >> 16) & 0xff;
- unsigned virt_as = max((entry->eax >> 8) & 0xff, 48U);
- unsigned phys_as = entry->eax & 0xff;
+ union cpuid_8_8_eax eax;
- if (!g_phys_as)
- g_phys_as = phys_as;
- entry->eax = g_phys_as | (virt_as << 8);
+ eax.full = entry->eax;
+ eax.split.virt_as = max_t(int, eax.split.virt_as, 48);
+ if (!eax.split.guest_phys_as)
+ eax.split.guest_phys_as = eax.split.phys_as;
+ entry->eax = eax.full;
entry->ebx = entry->edx = 0;
break;
}
@@ -724,13 +729,16 @@ EXPORT_SYMBOL_GPL(kvm_find_cpuid_entry);
int cpuid_maxphyaddr(struct kvm_vcpu *vcpu)
{
struct kvm_cpuid_entry2 *best;
+ union cpuid_8_8_eax eax;
best = kvm_find_cpuid_entry(vcpu, 0x80000000, 0);
if (!best || best->eax < 0x80000008)
goto not_found;
best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
- if (best)
- return best->eax & 0xff;
+ if (best) {
+ eax.full = best->eax;
+ return eax.split.phys_as;
+ }
not_found:
return 36;
}
--
1.9.1
next prev parent reply other threads:[~2014-09-17 12:54 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1410870160-28845-1-git-send-email-namit@cs.technion.ac.il>
2014-09-16 13:22 ` [PATCH 0/3] x86: structs for cpuid info in x86 Ingo Molnar
2014-09-16 20:19 ` Nadav Amit
2014-09-17 12:37 ` Ingo Molnar
2014-09-17 12:45 ` Borislav Petkov
2014-09-17 12:54 ` [RESEND PATCH " Nadav Amit
2014-09-17 12:54 ` [RESEND PATCH 1/3] x86: Adding structs to reflect cpuid fields Nadav Amit
2014-09-17 13:21 ` Borislav Petkov
2014-09-17 13:53 ` Nadav Amit
2014-09-17 14:06 ` Borislav Petkov
2014-09-17 15:04 ` Radim Krčmář
2014-09-17 15:22 ` Borislav Petkov
2014-09-18 0:29 ` Radim Krčmář
2014-09-18 7:19 ` Borislav Petkov
2014-09-18 10:00 ` Radim Krčmář
2014-09-18 13:06 ` Paolo Bonzini
2014-09-18 13:26 ` Borislav Petkov
2014-09-18 13:36 ` Paolo Bonzini
2014-09-19 7:58 ` Borislav Petkov
2014-09-19 8:59 ` Nadav Amit
2014-09-19 10:32 ` Borislav Petkov
2014-09-19 13:40 ` Paolo Bonzini
2014-09-19 14:44 ` Borislav Petkov
2014-09-17 14:10 ` Peter Zijlstra
2014-09-17 12:54 ` [RESEND PATCH 2/3] x86: Use new cpuid structs in cpuid functions Nadav Amit
2014-09-17 12:54 ` Nadav Amit [this message]
2014-09-17 14:12 ` [PATCH 0/3] x86: structs for cpuid info in x86 Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410958454-7501-4-git-send-email-namit@cs.technion.ac.il \
--to=namit@cs.technion.ac.il \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®