Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933843AbdCWJWt (ORCPT ); Thu, 23 Mar 2017 05:22:49 -0400 Received: from terminus.zytor.com ([65.50.211.136]:34227 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932196AbdCWJWr (ORCPT ); Thu, 23 Mar 2017 05:22:47 -0400 Date: Thu, 23 Mar 2017 02:15:44 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, boris.ostrovsky@oracle.com, tglx@linutronix.de, dvlasenk@redhat.com, bp@alien8.de, brgerst@gmail.com, jpoimboe@redhat.com, peterz@infradead.org, hpa@zytor.com, thgarnie@google.com, mingo@kernel.org, jgross@suse.com, luto@kernel.org Reply-To: torvalds@linux-foundation.org, boris.ostrovsky@oracle.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, brgerst@gmail.com, bp@alien8.de, dvlasenk@redhat.com, jpoimboe@redhat.com, peterz@infradead.org, hpa@zytor.com, mingo@kernel.org, thgarnie@google.com, jgross@suse.com, luto@kernel.org In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/xen/gdt: Use X86_FEATURE_XENPV instead of globals for the GDT fixup Git-Commit-ID: b23adb7d3f7d1d7cce03db9704de67a99ceeda38 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3784 Lines: 103 Commit-ID: b23adb7d3f7d1d7cce03db9704de67a99ceeda38 Gitweb: http://git.kernel.org/tip/b23adb7d3f7d1d7cce03db9704de67a99ceeda38 Author: Andy Lutomirski AuthorDate: Wed, 22 Mar 2017 14:32:34 -0700 Committer: Ingo Molnar CommitDate: Thu, 23 Mar 2017 08:25:08 +0100 x86/xen/gdt: Use X86_FEATURE_XENPV instead of globals for the GDT fixup Xen imposes special requirements on the GDT. Rather than using a global variable for the pgprot, just use an explicit special case for Xen -- this makes it clearer what's going on. It also debloats 64-bit kernels very slightly. Signed-off-by: Andy Lutomirski Cc: Boris Ostrovsky Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Garnier Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/e9ea96abbfd6a8c87753849171bb5987ecfeb523.1490218061.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/include/asm/desc.h | 1 - arch/x86/kernel/cpu/common.c | 28 +++++++++++++++++----------- arch/x86/xen/enlighten.c | 3 --- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index 17cb46e..d0a21b1 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -39,7 +39,6 @@ extern struct desc_ptr idt_descr; extern gate_desc idt_table[]; extern const struct desc_ptr debug_idt_descr; extern gate_desc debug_idt_table[]; -extern pgprot_t pg_fixmap_gdt_flags; struct gdt_page { struct desc_struct gdt[GDT_ENTRIES]; diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index f6e20e2..8ee3211 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -448,21 +448,27 @@ void load_percpu_segment(int cpu) load_stack_canary_segment(); } -/* - * On 64-bit the GDT remapping is read-only. - * A global is used for Xen to change the default when required. - */ +/* Setup the fixmap mapping only once per-processor */ +static inline void setup_fixmap_gdt(int cpu) +{ #ifdef CONFIG_X86_64 -pgprot_t pg_fixmap_gdt_flags = PAGE_KERNEL_RO; + /* On 64-bit systems, we use a read-only fixmap GDT. */ + pgprot_t prot = PAGE_KERNEL_RO; #else -pgprot_t pg_fixmap_gdt_flags = PAGE_KERNEL; + /* + * On native 32-bit systems, the GDT cannot be read-only because + * our double fault handler uses a task gate, and entering through + * a task gate needs to change an available TSS to busy. If the GDT + * is read-only, that will triple fault. + * + * On Xen PV, the GDT must be read-only because the hypervisor requires + * it. + */ + pgprot_t prot = boot_cpu_has(X86_FEATURE_XENPV) ? + PAGE_KERNEL_RO : PAGE_KERNEL; #endif -/* Setup the fixmap mapping only once per-processor */ -static inline void setup_fixmap_gdt(int cpu) -{ - __set_fixmap(get_cpu_gdt_ro_index(cpu), get_cpu_gdt_paddr(cpu), - pg_fixmap_gdt_flags); + __set_fixmap(get_cpu_gdt_ro_index(cpu), get_cpu_gdt_paddr(cpu), prot); } /* Load the original GDT from the per-cpu structure */ diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 08faa61..4951fcf 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -1545,9 +1545,6 @@ asmlinkage __visible void __init xen_start_kernel(void) */ xen_initial_gdt = &per_cpu(gdt_page, 0); - /* GDT can only be remapped RO */ - pg_fixmap_gdt_flags = PAGE_KERNEL_RO; - xen_smp_init(); #ifdef CONFIG_ACPI_NUMA