[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86: cap address bits CPUID output



commit a24edf49f5195fc3ec54584e42a6cdef6d248221
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed May 11 09:46:43 2016 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed May 11 09:46:43 2016 +0200

    x86: cap address bits CPUID output
    
    Don't use more or report more to guests than we are capable of
    handling.
    
    At once
    - correct the involved extended CPUID level checks,
    - simplify the code in hvm_cpuid() and mtrr_top_of_ram().
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Release-acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/cpu/common.c       | 11 ++++++++++-
 xen/arch/x86/e820.c             |  9 +++++----
 xen/arch/x86/hvm/hvm.c          | 12 ++++++------
 xen/arch/x86/traps.c            |  1 +
 xen/include/asm-x86/processor.h |  6 ++++--
 5 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index f664341..4b56061 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -46,6 +46,7 @@ const struct cpu_dev *__read_mostly cpu_devs[X86_VENDOR_NUM] 
= {};
 
 unsigned int paddr_bits __read_mostly = 36;
 unsigned int hap_paddr_bits __read_mostly = 36;
+unsigned int vaddr_bits __read_mostly = VADDR_BITS;
 
 /*
  * Default host IA32_CR_PAT value to cover all memory types.
@@ -237,10 +238,18 @@ static void __init early_cpu_detect(void)
        c->x86_capability[cpufeat_word(X86_FEATURE_FPU)] = edx;
        c->x86_capability[cpufeat_word(X86_FEATURE_SSE3)] = ecx;
 
-       if ( cpuid_eax(0x80000000) >= 0x80000008 ) {
+       eax = cpuid_eax(0x80000000);
+       if ((eax >> 16) == 0x8000 && eax >= 0x80000008) {
                eax = cpuid_eax(0x80000008);
                paddr_bits = eax & 0xff;
+               if (paddr_bits > PADDR_BITS)
+                       paddr_bits = PADDR_BITS;
+               vaddr_bits = (eax >> 8) & 0xff;
+               if (vaddr_bits > VADDR_BITS)
+                       vaddr_bits = VADDR_BITS;
                hap_paddr_bits = ((eax >> 16) & 0xff) ?: paddr_bits;
+               if (hap_paddr_bits > PADDR_BITS)
+                       hap_paddr_bits = PADDR_BITS;
        }
 }
 
diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c
index 3c64f19..ef077a5 100644
--- a/xen/arch/x86/e820.c
+++ b/xen/arch/x86/e820.c
@@ -451,11 +451,12 @@ static uint64_t __init mtrr_top_of_ram(void)
          return 0;
 
     /* Find the physical address size for this CPU. */
-    cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
-    if ( eax >= 0x80000008 )
+    eax = cpuid_eax(0x80000000);
+    if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 )
     {
-        cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
-        phys_bits = (uint8_t)eax;
+        phys_bits = (uint8_t)cpuid_eax(0x80000008);
+        if ( phys_bits > PADDR_BITS )
+            phys_bits = PADDR_BITS;
     }
     addr_mask = ((1ull << phys_bits) - 1) & ~((1ull << 12) - 1);
 
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 863d134..917db56 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3513,19 +3513,19 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, 
unsigned int *ebx,
         break;
 
     case 0x80000008:
+        *eax &= 0xff;
         count = d->arch.paging.gfn_bits + PAGE_SHIFT;
-        if ( (*eax & 0xff) > count )
-            *eax = (*eax & ~0xff) | count;
+        if ( *eax > count )
+            *eax = count;
 
         hvm_cpuid(1, NULL, NULL, NULL, &_edx);
         count = _edx & (cpufeat_mask(X86_FEATURE_PAE) |
                         cpufeat_mask(X86_FEATURE_PSE36)) ? 36 : 32;
-        if ( (*eax & 0xff) < count )
-            *eax = (*eax & ~0xff) | count;
+        if ( *eax < count )
+            *eax = count;
 
         hvm_cpuid(0x80000001, NULL, NULL, NULL, &_edx);
-        *eax = (*eax & ~0xffff00) | (_edx & cpufeat_mask(X86_FEATURE_LM)
-                                     ? 0x3000 : 0x2000);
+        *eax |= (_edx & cpufeat_mask(X86_FEATURE_LM) ? vaddr_bits : 32) << 8;
 
         *ebx &= hvm_featureset[FEATURESET_e8b];
         break;
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 0895441..0052ab8 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -1146,6 +1146,7 @@ void pv_cpuid(struct cpu_user_regs *regs)
         break;
 
     case 0x80000008:
+        a = paddr_bits | (vaddr_bits << 8);
         b &= pv_featureset[FEATURESET_e8b];
         break;
 
diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h
index 37ac9e4..a69d720 100644
--- a/xen/include/asm-x86/processor.h
+++ b/xen/include/asm-x86/processor.h
@@ -216,10 +216,12 @@ extern bool_t opt_cpu_info;
 extern u32 cpuid_ext_features;
 extern u64 trampoline_misc_enable_off;
 
-/* Maximum width of physical addresses supported by the hardware */
+/* Maximum width of physical addresses supported by the hardware. */
 extern unsigned int paddr_bits;
-/* Max physical address width supported within HAP guests */
+/* Max physical address width supported within HAP guests. */
 extern unsigned int hap_paddr_bits;
+/* Maximum width of virtual addresses supported by the hardware. */
+extern unsigned int vaddr_bits;
 
 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id table[]);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.