From patchwork Mon May 9 13:15:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9046641 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 42BC19F30C for ; Mon, 9 May 2016 13:18:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E29EE20145 for ; Mon, 9 May 2016 13:17:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6B7D200F3 for ; Mon, 9 May 2016 13:17:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1azl2S-0006Pa-NT; Mon, 09 May 2016 13:15:56 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1azl2R-0006O4-MH for xen-devel@lists.xenproject.org; Mon, 09 May 2016 13:15:55 +0000 Received: from [193.109.254.147] by server-2.bemta-14.messagelabs.com id 1A/55-03279-A8D80375; Mon, 09 May 2016 13:15:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsXS6fjDS7ez1yD cYOdKHYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPP/PmsBd/cKvpX7mNpYFxj0cXIySEkkCex 7N1uFhCbV8BOYs6XtWC2hIChxL75q9hAbBYBVYkZC86wgthsAuoSbc+2A9kcHCICBhLnjiaBh JkFAiVu3Z/BCGILC5hJPDndyQ5SwisgKPF3hzBEiZ3Ejea7rBMYuWYhZGYhyUDYWhIPf91igb C1JZYtfM0MUs4sIC2x/B8HhGkp0bI7FFUFiO0i0dp+n3UBI8cqRo3i1KKy1CJdQxO9pKLM9Iy S3MTMHF1DIDc3tbg4MT01JzGpWC85P3cTIzD06hkYGHcwfj/teYhRkoNJSZTXlVEvXIgvKT+l MiOxOCO+qDQntfgQowwHh5IE74Nug3AhwaLU9NSKtMwcYBTApCU4eJREeH+ApHmLCxJzizPTI VKnGBWlxHmfgiQEQBIZpXlwbbDIu8QoKyXMy8jAwCDEU5BalJtZgir/ilGcg1FJmFetB2gKT2 ZeCdz0V0CLmYAWy7HpgywuSURISTUwWmp+PSrgHP/gqQpz+GZrxZCn0mkvz31bZM43OdDmQuQ f07dldl+2zWhlyedelVE4/XZnYLXGpiOazPknNFkCXu1/orLT/D3f1vSjr5/NU7Jf3SXI9CeD JWxZ4TVGWeV1O85ObX95nyOqqqr/uJ3iy7UCCy/66fxcMHfts7dBIbvPTHY/WMU+UYmlOCPRU Iu5qDgRAFx81GG3AgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1462799751!40072305!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3578 invoked from network); 9 May 2016 13:15:53 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 9 May 2016 13:15:53 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Mon, 09 May 2016 07:15:50 -0600 Message-Id: <5730A9A302000078000E98B5@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Mon, 09 May 2016 07:15:47 -0600 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Cc: Andrew Cooper , Wei Liu Subject: [Xen-devel] [PATCH v2] x86: cap address bits CPUID output X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Andrew Cooper , with perhaps one --- v2: Also correct extended CPUID level range checks. 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 --- v2: Also correct extended CPUID level range checks. --- 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_ 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; } } --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -451,11 +451,12 @@ static uint64_t __init mtrr_top_of_ram(v 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); --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3504,19 +3504,19 @@ void hvm_cpuid(unsigned int input, unsig 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 << 8 : 0x2000; *ebx &= hvm_featureset[FEATURESET_e8b]; break; --- 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; --- 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[]); --- 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_ 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; } } --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -451,11 +451,12 @@ static uint64_t __init mtrr_top_of_ram(v 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); --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3504,19 +3504,19 @@ void hvm_cpuid(unsigned int input, unsig 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 << 8 : 0x2000; *ebx &= hvm_featureset[FEATURESET_e8b]; break; --- 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; --- 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[]);