From patchwork Thu Oct 31 10:56:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 11220915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16D1515AB for ; Thu, 31 Oct 2019 10:58:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E644820862 for ; Thu, 31 Oct 2019 10:58:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="ZRtSyvbV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E644820862 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iQ87m-0008AF-Gc; Thu, 31 Oct 2019 10:56:18 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iQ87l-0008AA-A8 for xen-devel@lists.xen.org; Thu, 31 Oct 2019 10:56:17 +0000 X-Inumbo-ID: 0ea03334-fbcd-11e9-953f-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0ea03334-fbcd-11e9-953f-12813bfff9fa; Thu, 31 Oct 2019 10:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1572519375; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WbqMkY73khVsNFDFekH6v2zn10iTBHvbFxhcwutb1+o=; b=ZRtSyvbVPluXXAalhUxzV7LA3KiAsnW9XSymADLArc+7dsJ5kowio0no V3hFrRWfEn/2NYGN1TaSroNFfkx+twi51rVAWp+wVYlubplvJtGBPcYAw nktAACjCBCcgLm9Obp4bMaJF+g2AWvia/So9yDpmrJm8pAXZPmVJUVJfX 4=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=sergey.dyasli@citrix.com; spf=Pass smtp.mailfrom=sergey.dyasli@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of sergey.dyasli@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of sergey.dyasli@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: sbVw4qmjjlrWo1mi+8mvET7aEZBtR6Ph+euXcyuB85/ls0yWGgeBWO24e1GTr9dVrZlTBWmfiz n3fmleFkjQqQfMa0q4tELDjL3LEnpcD8I3TZUI+EU8+snHQjzTMGc9bDCOPNiOYRX0Hhc6Qel0 xuNMNq7HayUeqmt97i3tr3MRUyD2ejff4Pz6wrd1cHJnDJqQU8zDQudhOzefjFJiqinCdXisfj vAcQ9CKuVit3iLyi8CgVtaLKn5F+k6JMA+MzCeY3N2YWiApxcKYyYEm51+SkpG72N2CyJJ7tx8 gwE= X-SBRS: 2.7 X-MesageID: 7996217 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.68,250,1569297600"; d="scan'208";a="7996217" From: Sergey Dyasli To: Date: Thu, 31 Oct 2019 10:56:09 +0000 Message-ID: <20191031105609.21819-1-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 for 4.13] x86/e820: fix 640k - 1M region reservation logic X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Sergey Dyasli , Wei Liu , Andrew Cooper , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Converting a guest from PV to PV-in-PVH makes the guest to have 384k less memory, which may confuse guest's balloon driver. This happens because Xen unconditionally reserves 640k - 1M region in E820 despite the fact that it's really a usable RAM in PVH boot mode. Fix this by skipping region type change in virtualised environments, trusting whatever memory map our hypervisor has provided. Take a refactoring opportunity to introduce early_cpu_has_hypervisor(). Signed-off-by: Sergey Dyasli --- v2 --> v3: - early_cpu_has_hypervisor() is added CC: Jan Beulich CC: Andrew Cooper CC: Wei Liu CC: "Roger Pau Monné" CC: Juergen Gross --- xen/arch/x86/cpu/common.c | 9 +++++++++ xen/arch/x86/e820.c | 6 ++++-- xen/arch/x86/guest/xen.c | 4 ++-- xen/arch/x86/mm.c | 2 +- xen/include/asm-x86/setup.h | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 6c6bd63301..adedb557df 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -274,6 +274,15 @@ static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) return _phys_pkg_id(get_apic_id(), index_msb); } +/* + * Sometimes it's too early to use cpu_has_hypervisor which is available only + * after early_cpu_init(). + */ +bool __init early_cpu_has_hypervisor(void) +{ + return cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR); +} + /* Do minimum CPU detection early. Fields really needed: vendor, cpuid_level, family, model, mask, cache alignment. The others are not touched to avoid unwanted side effects. diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index 8e8a2c4e1b..dbbe6cac0a 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -10,6 +10,7 @@ #include #include #include +#include /* * opt_mem: Limit maximum address of physical RAM. @@ -318,9 +319,10 @@ static int __init copy_e820_map(struct e820entry * biosmap, unsigned int nr_map) /* * Some BIOSes claim RAM in the 640k - 1M region. - * Not right. Fix it up. + * Not right. Fix it up, but only when running on bare metal. */ - if (type == E820_RAM) { + if ( !early_cpu_has_hypervisor() && type == E820_RAM ) + { if (start < 0x100000ULL && end > 0xA0000ULL) { if (start < 0xA0000ULL) add_memory_region(start, 0xA0000ULL-start, type); diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c index 7b7a5badab..48ea3224ea 100644 --- a/xen/arch/x86/guest/xen.c +++ b/xen/arch/x86/guest/xen.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -72,8 +73,7 @@ void __init probe_hypervisor(void) if ( xen_guest ) return; - /* Too early to use cpu_has_hypervisor */ - if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) ) + if ( !early_cpu_has_hypervisor() ) return; find_xen_leaves(); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 99816fc67c..df1641634c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5943,7 +5943,7 @@ const struct platform_bad_page *__init get_platform_badpages(unsigned int *array case 0x000806e0: /* erratum KBL??? */ case 0x000906e0: /* errata KBL??? / KBW114 / CFW103 */ *array_size = (cpuid_eax(0) >= 7 && - !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) && + !early_cpu_has_hypervisor() && (cpuid_count_ebx(7, 0) & cpufeat_mask(X86_FEATURE_HLE))); return &hle_bad_page; } diff --git a/xen/include/asm-x86/setup.h b/xen/include/asm-x86/setup.h index 861d46d6ac..ddd37907f1 100644 --- a/xen/include/asm-x86/setup.h +++ b/xen/include/asm-x86/setup.h @@ -16,6 +16,7 @@ extern unsigned long xenheap_initial_phys_start; void early_cpu_init(void); void early_time_init(void); +bool early_cpu_has_hypervisor(void); void set_nr_cpu_ids(unsigned int max_cpus);