From patchwork Thu Mar 16 22:21:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 70998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp26847wrt; Thu, 16 Mar 2023 15:26:44 -0700 (PDT) X-Google-Smtp-Source: AK7set9CDdIgTfGTs4nmWFdMVynHIH/0Rnz4XrnElAKrpdyO9cPLmIXADaSU3jS1a/1KUF8VQmgw X-Received: by 2002:a17:90a:192:b0:23d:4188:ad86 with SMTP id 18-20020a17090a019200b0023d4188ad86mr5471522pjc.18.1679005604645; Thu, 16 Mar 2023 15:26:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679005604; cv=none; d=google.com; s=arc-20160816; b=Tga7jqcdeD4Bhv13VLXeBDQ+gHC/d3KoCvYudBGLzlZOPaNq08+ItojP/c66NQkdYF 4zK1o1yEPmLC/hncB8U3B5KC/1gQV0dSbDvN9R92FG29eixBN7J133Za0aTv7OxCv6nI GawC9ykEnrZ4juf+3hsVXVrwduoabov/Ag/8YwLfK4WxD3/J1ihgBPQuyWrMVNdn6mqE JNMvxwR4wShhSh+YuuRQOtdcQhy+afGfd1esGw+7pkkFuUs2ipgRtEJ6UkSKX96wWfow d8MjQ2fKUvAKiWdZCIrcugl5qzJaYXRbri5RtlJ+scyvs+hM7/ZTqNgIgNNJaScVl5LQ 6/Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FULGw2JzzQsOYOrWK/IeWDfn0l3ZyQtosjohoUs52UM=; b=rdPAIMcbL8zt04zIAAEjBVsjeQCWGZpwv8LvjM68JR3aVh+Za00NH/L2NXM/h2LdBw MF63jtxrr4xbaw44LoJwfCL/dU9N40SGbztK8Ks0TtyunCqfteDr0MWE9wtGARbsVtUo PdGnMAwV3t/zK0+XSwXyvf7RXqxsq1/W1TAS4hTkt6ybbzPDgGKknnsUGaa/bosD9zgr KN4lLhNzOn1CtzTPftzDRZv26lNCUUz4xPn4MD71pKbklLdAy3YAeuJVw+0MyCi/d6yB h5irmDeeCqNROsIgvvRL5RIYB423IFkx4j/R7ckHiYdRTvmvTnhUCsFRLEJLm1sqhv3A laOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=XJkZiiYe; 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=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk2-20020a17090b4a0200b0022c83e223desi6802583pjb.58.2023.03.16.15.26.29; Thu, 16 Mar 2023 15:26:44 -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=@bytedance.com header.s=google header.b=XJkZiiYe; 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=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjCPWWB (ORCPT + 99 others); Thu, 16 Mar 2023 18:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjCPWVo (ORCPT ); Thu, 16 Mar 2023 18:21:44 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32135B2558 for ; Thu, 16 Mar 2023 15:21:21 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id h17so2862894wrt.8 for ; Thu, 16 Mar 2023 15:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1679005279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FULGw2JzzQsOYOrWK/IeWDfn0l3ZyQtosjohoUs52UM=; b=XJkZiiYe6qukEyVX/ujwP5etOZk592Q68jftwrVXpL4JMdoU251Sic4GKKxqoURB75 gfXMd+jOXjW5LK3dYpkUe8S2pEZcRggenTmD9+KE8eZgb7yDzwQ3EMBwGdAl5IPg5Svn 1adM4NXK26p396oaoPI2OcwyTLd5TOZ1YG6WQ6WmrT6yfgHUpju2g8gPjeQRxBtKMwN6 f/t0MCNQSMV0DnRW6aFDulqBtXy3RiaUMqnmpi5FlWc+3X8EyGqzmzqkqNLeFBvPnhqe IFrtkO2JXGZY1L74uXsj4Kv61nAuvl270HxBVyJPFpasxMgN+NUXU8heKCaGYPurMp14 C9jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679005279; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FULGw2JzzQsOYOrWK/IeWDfn0l3ZyQtosjohoUs52UM=; b=riWkjyuVe9lEt2215+k1De30jJaQH0mcyw4lTCjpXFRvVS3jrENWv/+yFCY6xcK9nk e4tSPbfTrQFMNdKkGU4KIC0XYgGsUvY2Oub4qcMtnJUq9yESZWnnL/dbCoeCg60eAyiA 4CS3noF2kLyMYnGBqACiwYsyebt/EtojqfMrHI0nN3OIopgFss5q7C+3Aylh9A2h9snb H5NnzlAUbvYV6fQB86cIPKFgR3ymVN1/Ly9Zkc8rm4eQXcwAegTxruKcTw/cpw+QaXzE uQbbKn7OvCALXxSk6q60CMdI+GYLIQLAFfgFeJCZTM4iUjqszqXNRLo3oGtTtdTmCblH z38g== X-Gm-Message-State: AO0yUKXr/aK7vuau0wJx+C7ukOsln7ELGm/2AtwjmysWhAO54w7csub8 l5Xx+L0PPqIJSvnbAdSgAv5fLA== X-Received: by 2002:adf:dc0f:0:b0:2cf:f0c3:79ba with SMTP id t15-20020adfdc0f000000b002cff0c379bamr5429317wri.67.1679005279217; Thu, 16 Mar 2023 15:21:19 -0700 (PDT) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6a:b566:0:4b87:78c3:3abe:7b0d]) by smtp.gmail.com with ESMTPSA id f9-20020adff989000000b002cea392f000sm439256wrr.69.2023.03.16.15.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 15:21:18 -0700 (PDT) From: Usama Arif To: dwmw2@infradead.org, tglx@linutronix.de, kim.phillips@amd.com, brgerst@gmail.com Cc: piotrgorski@cachyos.org, oleksandr@natalenko.name, arjan@linux.intel.com, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, paulmck@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, rcu@vger.kernel.org, mimoja@mimoja.de, hewenliang4@huawei.com, thomas.lendacky@amd.com, seanjc@google.com, pmenzel@molgen.mpg.de, fam.zheng@bytedance.com, punit.agrawal@bytedance.com, simon.evans@bytedance.com, liangma@liangbit.com, gpiccoli@igalia.com, David Woodhouse , Usama Arif Subject: [PATCH v15 08/12] x86/smpboot: Remove initial_gs Date: Thu, 16 Mar 2023 22:21:05 +0000 Message-Id: <20230316222109.1940300-9-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230316222109.1940300-1-usama.arif@bytedance.com> References: <20230316222109.1940300-1-usama.arif@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760564980697133778?= X-GMAIL-MSGID: =?utf-8?q?1760564980697133778?= From: Brian Gerst Given its CPU#, each CPU can find its own per-cpu offset, and directly set GSBASE accordingly. The global variable can be eliminated. Signed-off-by: Brian Gerst Reviewed-by: David Woodhouse Signed-off-by: David Woodhouse Tested-by: Usama Arif Signed-off-by: Usama Arif Tested-by: Guilherme G. Piccoli --- arch/x86/include/asm/realmode.h | 1 - arch/x86/kernel/acpi/sleep.c | 1 - arch/x86/kernel/head_64.S | 22 ++++++++-------------- arch/x86/kernel/smpboot.c | 2 -- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h index a336feef0af1..f6a1737c77be 100644 --- a/arch/x86/include/asm/realmode.h +++ b/arch/x86/include/asm/realmode.h @@ -59,7 +59,6 @@ extern struct real_mode_header *real_mode_header; extern unsigned char real_mode_blob_end[]; extern unsigned long initial_code; -extern unsigned long initial_gs; extern unsigned long initial_stack; #ifdef CONFIG_AMD_MEM_ENCRYPT extern unsigned long initial_vc_handler; diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c index de89bb4719d0..1328c221af30 100644 --- a/arch/x86/kernel/acpi/sleep.c +++ b/arch/x86/kernel/acpi/sleep.c @@ -127,7 +127,6 @@ int x86_acpi_suspend_lowlevel(void) * value is in the actual %rsp register. */ current->thread.sp = (unsigned long)temp_stack + sizeof(temp_stack); - initial_gs = per_cpu_offset(smp_processor_id()); smpboot_control = smp_processor_id(); #endif initial_code = (unsigned long)wakeup_long64; diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index a5b46c2fba05..6a8238702eab 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -66,18 +66,10 @@ SYM_CODE_START_NOALIGN(startup_64) leaq _text(%rip), %rdi - /* - * initial_gs points to initial fixed_percpu_data struct with storage for - * the stack protector canary. Global pointer fixups are needed at this - * stage, so apply them as is done in fixup_pointer(), and initialize %gs - * such that the canary can be accessed at %gs:40 for subsequent C calls. - */ + /* Setup GSBASE to allow stack canary access for C code */ movl $MSR_GS_BASE, %ecx - movq initial_gs(%rip), %rax - movq $_text, %rdx - subq %rdx, %rax - addq %rdi, %rax - movq %rax, %rdx + leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx + movl %edx, %eax shrq $32, %rdx wrmsr @@ -294,8 +286,11 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) * the per cpu areas are set up. */ movl $MSR_GS_BASE,%ecx - movl initial_gs(%rip),%eax - movl initial_gs+4(%rip),%edx +#ifndef CONFIG_SMP + leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx +#endif + movl %edx, %eax + shrq $32, %rdx wrmsr /* Setup and Load IDT */ @@ -437,7 +432,6 @@ SYM_CODE_END(vc_boot_ghcb) __REFDATA .balign 8 SYM_DATA(initial_code, .quad x86_64_start_kernel) -SYM_DATA(initial_gs, .quad INIT_PER_CPU_VAR(fixed_percpu_data)) #ifdef CONFIG_AMD_MEM_ENCRYPT SYM_DATA(initial_vc_handler, .quad handle_vc_boot_ghcb) #endif diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 67224e61310c..28d1643eee99 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1084,8 +1084,6 @@ int common_cpu_up(unsigned int cpu, struct task_struct *idle) #ifdef CONFIG_X86_32 /* Stack for startup_32 can be just as for start_secondary onwards */ per_cpu(pcpu_hot.top_of_stack, cpu) = task_top_of_stack(idle); -#else - initial_gs = per_cpu_offset(cpu); #endif return 0; }