Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3618909imw; Mon, 18 Jul 2022 11:17:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sj17InPkIk6dy8PIiY1LbnCXu39iJ6aB2dBvqaU+GU2wQcKbV3uB/630KieUmDolU7mold X-Received: by 2002:a63:8ac3:0:b0:419:c3bb:7d99 with SMTP id y186-20020a638ac3000000b00419c3bb7d99mr19753722pgd.57.1658168258470; Mon, 18 Jul 2022 11:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658168258; cv=none; d=google.com; s=arc-20160816; b=wj5+/TkJ/LKL66c4pfkKW5rdh2Mtj6+r/TNkKxldSDT0J/AOP247sWwpxkg11KUP53 S7/SgrfYkQYahdnhecg3zFVSwu5Aap0sDxIrGZSL7nVQOhPOflvOqEbfATMR4ZXggrAg 0ywx9EOqi13XSZdkpga6tOKRU+dgbvArPfPNfjTo80XCfwQ9prZzqihRo2VeVKQRTg+3 D/Bn/yxw2ypIsR8fRTPaqYRRSsiFVlSnFSqLUPP4xEFXGYzbNc3akVcr9uVICIemZcrq AbpPfZcFA9br3m3DmTDUs+D8WhCBzz45RpYFf71Zfe413mepPxN1qBXcQd1I4z9VvBPB Qy4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :2message-id:dkim-signature:dkim-signature:message-id; bh=KrrFulS1b+TRk+Ir+OgNMh3CyYA86JKp9Z084M+JkBQ=; b=t48Ezl1JAXfVTRpLhoUbn1lMuIJNbZgFb4zzhN73F+/AseJGj6Bc2g9hbavsAqo+et aXkZFd+koo5yh+TZtg7c0CAVSW+gvKLT02VzSsvjihBE4ZYDgUj8RbPoH7ibaesptn4V hMFZ9SvG+cqn64OdO5PqXVSW+KnWW+RwPFuqI2sc1Km9gPHW4Tg0Uh/I/PYfyXr5iRpg u9sh5K81l27B3SnCoL+SkjlHCjLXmfa51SP51x2rK6ihyY/eUbF+Y1zFcnBom+P19Vu7 WhmrzQxEIe2HPPEtXjaqxb2kOlqemjERQYeAYFVZFI6xqfSWjPIv0OIrd6znPS4bi2f7 rMag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zi2nidXU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a17090a1a1300b001e6820f720esi10445936pjk.125.2022.07.18.11.17.18; Mon, 18 Jul 2022 11:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=zi2nidXU; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233897AbiGRRwR (ORCPT + 99 others); Mon, 18 Jul 2022 13:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233552AbiGRRwN (ORCPT ); Mon, 18 Jul 2022 13:52:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA7D2D1D0 for ; Mon, 18 Jul 2022 10:52:12 -0700 (PDT) Message-ID: <20220718173923.951305696@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658166731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=KrrFulS1b+TRk+Ir+OgNMh3CyYA86JKp9Z084M+JkBQ=; b=zi2nidXUDEzobjRZcbJT0RFqPgEoTGbEfLVtFMnXRGBT+3qt4kBQhSEEEDmzeA/kg/AmLg HNb+rrgYrJzBhPD9PAPv+Rz0jUTCr4BQm0nLbZSpgUL/hEhJAsfB4ISTwq2bJ0PJ8mQBhm rvz8eoclb/OvyIKh9UzCoEFyrN6xA0nenWKP/EPBX/fK+gSxp1QnFjZQEmpno74zhvSLqe UwCPQxt+q5jYmog7EO2wTSBracfFoBetC5OwA4BBUzRFcwAHiP/RCghO8msODr+1VzfH9A dmq85fZP05BNu9BxVz6V7Lyj3K+Lv8UE2bUdn8nkHHiTyOvP3uYuEsDP6rJ58A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658166731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=KrrFulS1b+TRk+Ir+OgNMh3CyYA86JKp9Z084M+JkBQ=; b=yYGiepyyxCJiWuj3M7Gexb9o05hj5kTDaiTxAH/FVcvxOiopFgzGEqN1wNpEx72CsqJKZS b+4WtYrXpLoye0AQ== 2Message-ID: <20220718173814.731702240@linutronix.de> From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Tim Chen , Josh Poimboeuf , Andrew Cooper , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , Juergen Gross , "Peter Zijlstra (Intel)" , Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann Subject: [patch 2/3] x86/cpu: Get rid of redundant switch_to_new_gdt() invocations References: <20220716230952.787452088@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 18 Jul 2022 19:52:11 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The only place where switch_to_new_gdt() is required is early boot to switch from the early GDT to the direct GDT. Any other invocation is completely redundant because it does not change anything. Secondary CPUs come out of the ASM code with GDT and GSBASE correctly set up. The same is true for XEN_PV. Remove all the voodoo invocations which are left overs from the ancient past, rename the function to switch_to_direct_gdt() and mark it init. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 2 +- arch/x86/kernel/cpu/common.c | 14 ++------------ arch/x86/kernel/setup_percpu.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++++- arch/x86/xen/enlighten_pv.c | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -670,7 +670,7 @@ extern int sysenter_setup(void); /* Defined in head.S */ extern struct desc_ptr early_gdt_descr; -extern void switch_to_new_gdt(int); +extern void switch_to_direct_gdt(int); extern void load_direct_gdt(int); extern void load_fixmap_gdt(int); extern void cpu_init(void); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -729,14 +729,14 @@ void load_fixmap_gdt(int cpu) EXPORT_SYMBOL_GPL(load_fixmap_gdt); /** - * switch_to_new_gdt - Switch form early GDT to the direct one + * switch_to_direct_gdt - Switch form early GDT to the direct one * @cpu: The CPU number for which this is invoked * * Invoked during early boot to switch from early GDT and early per CPU * (%fs on 32bit, GS_BASE on 64bit) to the direct GDT and the runtime per * CPU area. */ -void switch_to_new_gdt(int cpu) +void __init switch_to_direct_gdt(int cpu) { load_direct_gdt(cpu); @@ -751,10 +751,6 @@ void switch_to_new_gdt(int cpu) * wrmsrl() happens the early mapping is still valid. That means * the GSBASE update will lose any prior per CPU data which was * not copied over in setup_per_cpu_areas(). - * - * For secondary CPUs this is not a problem because they start - * already with the direct GDT and the real GSBASE. This invocation - * is pointless and will be removed in a subsequent step. */ if (IS_ENABLED(CONFIG_X86_64)) wrmsrl(MSR_GS_BASE, cpu_kernelmode_gs_base(cpu)); @@ -2238,12 +2234,6 @@ void cpu_init(void) boot_cpu_has(X86_FEATURE_TSC) || boot_cpu_has(X86_FEATURE_DE)) cr4_clear_bits(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); - /* - * Initialize the per-CPU GDT with the boot GDT, - * and set up the GDT descriptor: - */ - switch_to_new_gdt(cpu); - if (IS_ENABLED(CONFIG_X86_64)) { loadsegment(fs, 0); memset(cur->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8); --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c @@ -211,7 +211,7 @@ void __init setup_per_cpu_areas(void) * area. Reload any changed state for the boot CPU. */ if (!cpu) - switch_to_new_gdt(cpu); + switch_to_direct_gdt(cpu); } /* indicate the early static arrays will soon be gone */ --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1457,7 +1457,11 @@ void arch_thaw_secondary_cpus_end(void) void __init native_smp_prepare_boot_cpu(void) { int me = smp_processor_id(); - switch_to_new_gdt(me); + + /* SMP invokes this from setup_per_cpu_areas() */ + if (!IS_ENABLED(CONFIG_SMP)) + switch_to_direct_gdt(me); + /* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu(me, cpu_callout_mask); cpu_set_state_online(me); --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1164,7 +1164,7 @@ static void __init xen_setup_gdt(int cpu pv_ops.cpu.write_gdt_entry = xen_write_gdt_entry_boot; pv_ops.cpu.load_gdt = xen_load_gdt_boot; - switch_to_new_gdt(cpu); + switch_to_direct_gdt(cpu); pv_ops.cpu.write_gdt_entry = xen_write_gdt_entry; pv_ops.cpu.load_gdt = xen_load_gdt;