Received: by 10.223.185.116 with SMTP id b49csp549666wrg; Wed, 14 Feb 2018 03:19:22 -0800 (PST) X-Google-Smtp-Source: AH8x227+UXTq/n0079yO9cuyweNvPC27x1tPP6XsJgom8n3M5PVCQVFDkP4GK5JMVboGOd0NN45H X-Received: by 10.99.174.7 with SMTP id q7mr3640890pgf.170.1518607161983; Wed, 14 Feb 2018 03:19:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518607161; cv=none; d=google.com; s=arc-20160816; b=fwXrKRV6JwtwsYv1VzoMS8FYt7oZw14MhFM5kSKEInfq/SmSBmdzViqi6JAT0FII0/ 3uDlbyoPGEPuL1U4Hfpwm6tRIFj8TrhHdDYnc9pikaR7LTWa7SPqEYolkZ9UZ6XBeAby +LsDutuPEE6TUMDrK4pXA1b9RarbjSRQE07kavZ6Dl6vNw9nH3hXyEJEq54r0cjaV+SZ DfndP+Hp98NvRn5b3cVRfJWvf3qDeV/lxTjNI+dbPdPskGaOejf48bqtyKiBRzyJ1HJ2 LbrfPlafPnJ2sv2Gv26w609gbFKwcJUWMIamZyJA60t8s6CNvAbSq6zbgF4msFHOMn3M y9nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=/Oo9y3HdkKovFIe2AzzJNOxxptxluOHWr9nMo1sr5Xc=; b=K8P3xlVmxscy3DbHs/BYa2HIN0ssBVVFbT+t8dGpYeXPlVyyX/TbRu8OGvNFWpFJ5S VnhGPF9ic2M/Q/pEdcxjYhEtg3cDxHL741vZZeGZdqQ0pVZu7554wcw0R4kLw1k3aAZz qh3azqZWPwl/Vg70SJTROqjPF8/hlD0gbrttQjq+93CDOEAOMj+LSBGVqP9oIcaKDKR3 18v/apMhAP/ZeWwAScrtyIHtX4A+GWC1vibe10Q8UkIQZKsZdgE98yEB/vf9ZuXFmkE9 cgB/Jv+oyuT/lB+J8cHa4Y5UulvhpsWAEjC0VlahLHyVCxL+FkT9zyRQOTzmvJY6RjVN B8wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3-v6si829360pld.135.2018.02.14.03.19.07; Wed, 14 Feb 2018 03:19:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967442AbeBNLRh (ORCPT + 99 others); Wed, 14 Feb 2018 06:17:37 -0500 Received: from mga02.intel.com ([134.134.136.20]:5270 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967414AbeBNLRQ (ORCPT ); Wed, 14 Feb 2018 06:17:16 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2018 03:17:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,512,1511856000"; d="scan'208";a="34604565" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 14 Feb 2018 03:17:13 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id B016D325; Wed, 14 Feb 2018 13:17:08 +0200 (EET) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" Cc: Linus Torvalds , Andy Lutomirski , Borislav Petkov , Andi Kleen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 7/9] x86/mm: Make MAX_PHYSADDR_BITS and MAX_PHYSMEM_BITS dynamic Date: Wed, 14 Feb 2018 14:16:54 +0300 Message-Id: <20180214111656.88514-8-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180214111656.88514-1-kirill.shutemov@linux.intel.com> References: <20180214111656.88514-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For boot-time switching between paging modes, we need to be able to adjust size of physical address space at runtime. As part of making physical address space size variable, we have to make X86_5LEVEL dependent on SPARSEMEM_VMEMMAP. !SPARSEMEM_VMEMMAP configuration doesn't build with variable MAX_PHYSMEM_BITS. For !SPARSEMEM_VMEMMAP SECTIONS_WIDTH depends on MAX_PHYSMEM_BITS: SECTIONS_WIDTH SECTIONS_SHIFT MAX_PHYSMEM_BITS And SECTIONS_WIDTH is used on pre-processor stage, it doesn't work if it's dyncamic. See include/linux/page-flags-layout.h. Affect on kernel image size: text data bss dec hex filename 8628393 4734340 1368064 14730797 e0c62d vmlinux.before 8628892 4734340 1368064 14731296 e0c820 vmlinux.after Signed-off-by: Kirill A. Shutemov --- arch/x86/Kconfig | 1 + arch/x86/include/asm/pgtable_64_types.h | 2 +- arch/x86/include/asm/sparsemem.h | 9 ++------- arch/x86/kernel/setup.c | 5 ++--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f925274ddf79..0d780a3ee924 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1472,6 +1472,7 @@ config X86_PAE config X86_5LEVEL bool "Enable 5-level page tables support" select DYNAMIC_MEMORY_LAYOUT + select SPARSEMEM_VMEMMAP depends on X86_64 ---help--- 5-level paging enables access to larger address space: diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h index 0c48d80e11d4..59d971c85de5 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -95,7 +95,7 @@ extern unsigned int ptrs_per_p4d; * range must not overlap with anything except the KASAN shadow area, which * is correct as KASAN disables KASLR. */ -#define MAXMEM _AC(__AC(1, UL) << MAX_PHYSMEM_BITS, UL) +#define MAXMEM (1UL << MAX_PHYSMEM_BITS) #define LDT_PGD_ENTRY_L4 -3UL #define LDT_PGD_ENTRY_L5 -112UL diff --git a/arch/x86/include/asm/sparsemem.h b/arch/x86/include/asm/sparsemem.h index 4fc1e9d3c43e..4617a2bf123c 100644 --- a/arch/x86/include/asm/sparsemem.h +++ b/arch/x86/include/asm/sparsemem.h @@ -27,13 +27,8 @@ # endif #else /* CONFIG_X86_32 */ # define SECTION_SIZE_BITS 27 /* matt - 128 is convenient right now */ -# ifdef CONFIG_X86_5LEVEL -# define MAX_PHYSADDR_BITS 52 -# define MAX_PHYSMEM_BITS 52 -# else -# define MAX_PHYSADDR_BITS 44 -# define MAX_PHYSMEM_BITS 46 -# endif +# define MAX_PHYSADDR_BITS (pgtable_l5_enabled ? 52 : 44) +# define MAX_PHYSMEM_BITS (pgtable_l5_enabled ? 52 : 46) #endif #endif /* CONFIG_SPARSEMEM */ diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 1ae67e982af7..399d0f7fa8f1 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -189,9 +189,7 @@ struct ist_info ist_info; #endif #else -struct cpuinfo_x86 boot_cpu_data __read_mostly = { - .x86_phys_bits = MAX_PHYSMEM_BITS, -}; +struct cpuinfo_x86 boot_cpu_data __read_mostly; EXPORT_SYMBOL(boot_cpu_data); #endif @@ -851,6 +849,7 @@ void __init setup_arch(char **cmdline_p) __flush_tlb_all(); #else printk(KERN_INFO "Command line: %s\n", boot_command_line); + boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; #endif /* -- 2.15.1