From patchwork Tue Sep 7 22:00:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD44CC433F5 for ; Tue, 7 Sep 2021 22:00:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5FC6661151 for ; Tue, 7 Sep 2021 22:00:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5FC6661151 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E8C516B0075; Tue, 7 Sep 2021 18:00:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D74EB6B0078; Tue, 7 Sep 2021 18:00:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEEA36B007B; Tue, 7 Sep 2021 18:00:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id A68556B0075 for ; Tue, 7 Sep 2021 18:00:48 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5ADCB181E997F for ; Tue, 7 Sep 2021 22:00:48 +0000 (UTC) X-FDA: 78562147776.12.8928E8F Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf02.hostedemail.com (Postfix) with ESMTP id 0ACB87001737 for ; Tue, 7 Sep 2021 22:00:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 0C8923F30863; Tue, 7 Sep 2021 15:00:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 5Y4i2-aqxt-e; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id E77263F30865; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id CED761E60122; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 1/7] ARM: Pass cpu number to secondary_start_kernel Date: Tue, 7 Sep 2021 15:00:32 -0700 Message-Id: <20210907220038.91021-2-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine) X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0ACB87001737 X-Stat-Signature: p9nnyey9hdk5mxx5bs55atuxbjjeqm6g X-Rspam: Yes X-HE-Tag: 1631052047-541402 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Instead of pulling the CPU value out of the thread_info struct, pass it as an argument. When first initializing secondary processors, this is done by stashing the value in the secondary_data struct. When restarting idle processors, the previous CPU value is passed. Because the cpu is now known at the top of secondary_start_kernel, the per_cpu_offset value can now be set at this point, instead of in cpu_init where it was also incorrectly setting the per_cpu_offset for the boot processor before that value had been computed. Signed-off-by: Keith Packard Reviewed-by: Ard Biesheuvel --- arch/arm/include/asm/smp.h | 3 ++- arch/arm/kernel/head-nommu.S | 1 + arch/arm/kernel/head.S | 1 + arch/arm/kernel/setup.c | 6 ------ arch/arm/kernel/smp.c | 14 +++++++++----- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index 5d508f5d56c4..86a7fd721556 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -48,7 +48,7 @@ extern void set_smp_ipi_range(int ipi_base, int nr_ipi); * Called from platform specific assembly code, this is the * secondary CPU entry point. */ -asmlinkage void secondary_start_kernel(void); +asmlinkage void secondary_start_kernel(unsigned int cpu); /* @@ -61,6 +61,7 @@ struct secondary_data { }; unsigned long swapper_pg_dir; void *stack; + unsigned int cpu; }; extern struct secondary_data secondary_data; extern void secondary_startup(void); diff --git a/arch/arm/kernel/head-nommu.S b/arch/arm/kernel/head-nommu.S index 0fc814bbc34b..5aa8ef42717f 100644 --- a/arch/arm/kernel/head-nommu.S +++ b/arch/arm/kernel/head-nommu.S @@ -114,6 +114,7 @@ ENTRY(secondary_startup) add r12, r12, r10 ret r12 1: bl __after_proc_init + ldr r0, [r7, #16] @ set up cpu number ldr sp, [r7, #12] @ set up the stack pointer mov fp, #0 b secondary_start_kernel diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S index 7f62c5eccdf3..0e541af738e2 100644 --- a/arch/arm/kernel/head.S +++ b/arch/arm/kernel/head.S @@ -394,6 +394,7 @@ ENDPROC(secondary_startup_arm) ENTRY(__secondary_switched) ldr_l r7, secondary_data + 12 @ get secondary_data.stack + ldr_l r0, secondary_data + 16 @ get secondary_data.cpu mov sp, r7 mov fp, #0 b secondary_start_kernel diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 73ca7797b92f..ca0201635fac 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -532,12 +532,6 @@ void notrace cpu_init(void) BUG(); } - /* - * This only works on resume and secondary cores. For booting on the - * boot cpu, smp_prepare_boot_cpu is called after percpu area setup. - */ - set_my_cpu_offset(per_cpu_offset(cpu)); - cpu_proc_init(); /* diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 74679240a9d8..55cb1689a4b3 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -153,6 +153,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) secondary_data.pgdir = virt_to_phys(idmap_pgd); secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir); #endif + secondary_data.cpu = cpu; sync_cache_w(&secondary_data); /* @@ -373,11 +374,14 @@ void arch_cpu_idle_dead(void) * cpu initialisation. There's some initialisation which needs * to be repeated to undo the effects of taking the CPU offline. */ - __asm__("mov sp, %0\n" + __asm__("mov r0, %1\n" + " mov sp, %0\n" " mov fp, #0\n" " b secondary_start_kernel" : - : "r" (task_stack_page(current) + THREAD_SIZE - 8)); + : "r" (task_stack_page(current) + THREAD_SIZE - 8), + "r" (cpu) + : "r0"); } #endif /* CONFIG_HOTPLUG_CPU */ @@ -400,10 +404,11 @@ static void smp_store_cpu_info(unsigned int cpuid) * This is the secondary CPU boot entry. We're using this CPUs * idle thread stack, but a set of temporary page tables. */ -asmlinkage void secondary_start_kernel(void) +asmlinkage void secondary_start_kernel(unsigned int cpu) { struct mm_struct *mm = &init_mm; - unsigned int cpu; + + set_my_cpu_offset(per_cpu_offset(cpu)); secondary_biglittle_init(); @@ -420,7 +425,6 @@ asmlinkage void secondary_start_kernel(void) * All kernel threads share the same mm context; grab a * reference and switch to it. */ - cpu = smp_processor_id(); mmgrab(mm); current->active_mm = mm; cpumask_set_cpu(cpu, mm_cpumask(mm)); From patchwork Tue Sep 7 22:00:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EB86C433FE for ; Tue, 7 Sep 2021 22:01:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D27F961103 for ; Tue, 7 Sep 2021 22:01:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D27F961103 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3148F6B0081; Tue, 7 Sep 2021 18:01:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C4E16B0082; Tue, 7 Sep 2021 18:01:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 116996B0083; Tue, 7 Sep 2021 18:01:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 02D6D6B0081 for ; Tue, 7 Sep 2021 18:01:48 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 99954181DF768 for ; Tue, 7 Sep 2021 22:01:47 +0000 (UTC) X-FDA: 78562150254.18.2D66C00 Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf27.hostedemail.com (Postfix) with ESMTP id 3BDCD70009D5 for ; Tue, 7 Sep 2021 22:00:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 9617C3F3086C; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id A33anUDGjTNA; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id C09633F30863; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id D229D1E6012A; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 2/7] ARM: Pass task to secondary_start_kernel Date: Tue, 7 Sep 2021 15:00:33 -0700 Message-Id: <20210907220038.91021-3-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine) X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3BDCD70009D5 X-Stat-Signature: u5s3j9npj5y6hbix15abbqbhbtgukb1u X-Rspam: Yes X-HE-Tag: 1631052047-309612 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This avoids needing to compute the task pointer in this function, allowing it to be used as the source of identification in the future. Signed-off-by: Keith Packard --- arch/arm/include/asm/smp.h | 3 ++- arch/arm/kernel/head-nommu.S | 1 + arch/arm/kernel/head.S | 1 + arch/arm/kernel/smp.c | 8 +++++--- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index 86a7fd721556..d43b64635d77 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -48,7 +48,7 @@ extern void set_smp_ipi_range(int ipi_base, int nr_ipi); * Called from platform specific assembly code, this is the * secondary CPU entry point. */ -asmlinkage void secondary_start_kernel(unsigned int cpu); +asmlinkage void secondary_start_kernel(unsigned int cpu, struct task_struct *task); /* @@ -62,6 +62,7 @@ struct secondary_data { unsigned long swapper_pg_dir; void *stack; unsigned int cpu; + struct task_struct *task; }; extern struct secondary_data secondary_data; extern void secondary_startup(void); diff --git a/arch/arm/kernel/head-nommu.S b/arch/arm/kernel/head-nommu.S index 5aa8ef42717f..218715c135ed 100644 --- a/arch/arm/kernel/head-nommu.S +++ b/arch/arm/kernel/head-nommu.S @@ -115,6 +115,7 @@ ENTRY(secondary_startup) ret r12 1: bl __after_proc_init ldr r0, [r7, #16] @ set up cpu number + ldr r1, [r7, #20] @ set up task pointer ldr sp, [r7, #12] @ set up the stack pointer mov fp, #0 b secondary_start_kernel diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S index 0e541af738e2..4a6cb0b0808b 100644 --- a/arch/arm/kernel/head.S +++ b/arch/arm/kernel/head.S @@ -395,6 +395,7 @@ ENDPROC(secondary_startup_arm) ENTRY(__secondary_switched) ldr_l r7, secondary_data + 12 @ get secondary_data.stack ldr_l r0, secondary_data + 16 @ get secondary_data.cpu + ldr_l r1, secondary_data + 20 @ get secondary_data.task mov sp, r7 mov fp, #0 b secondary_start_kernel diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 55cb1689a4b3..5e999f1f1aea 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -154,6 +154,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir); #endif secondary_data.cpu = cpu; + secondary_data.task = idle; sync_cache_w(&secondary_data); /* @@ -375,13 +376,14 @@ void arch_cpu_idle_dead(void) * to be repeated to undo the effects of taking the CPU offline. */ __asm__("mov r0, %1\n" + " mov r1, %2\n" " mov sp, %0\n" " mov fp, #0\n" " b secondary_start_kernel" : : "r" (task_stack_page(current) + THREAD_SIZE - 8), - "r" (cpu) - : "r0"); + "r" (cpu), "r" (current) + : "r0", "r1"); } #endif /* CONFIG_HOTPLUG_CPU */ @@ -404,7 +406,7 @@ static void smp_store_cpu_info(unsigned int cpuid) * This is the secondary CPU boot entry. We're using this CPUs * idle thread stack, but a set of temporary page tables. */ -asmlinkage void secondary_start_kernel(unsigned int cpu) +asmlinkage void secondary_start_kernel(unsigned int cpu, struct task_struct *task) { struct mm_struct *mm = &init_mm; From patchwork Tue Sep 7 22:00:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D580C433F5 for ; Tue, 7 Sep 2021 22:00:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 323C561108 for ; Tue, 7 Sep 2021 22:00:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 323C561108 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6981F6B0071; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 646F96B0072; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 535BE6B0073; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3F0DF6B0071 for ; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F1B9D2BA87 for ; Tue, 7 Sep 2021 22:00:44 +0000 (UTC) X-FDA: 78562147608.19.05EEB83 Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf26.hostedemail.com (Postfix) with ESMTP id 6BC2220019C6 for ; Tue, 7 Sep 2021 22:00:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 0A85D3F30866; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id BrT72QuO-XSn; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id B2A033F30862; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id D53551E60132; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 3/7] ARM: Use smp_processor_id() in vfp_pm_suspend instead of ti->cpu Date: Tue, 7 Sep 2021 15:00:34 -0700 Message-Id: <20210907220038.91021-4-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6BC2220019C6 Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine); spf=pass (imf26.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com X-Rspamd-Server: rspam01 X-Stat-Signature: a7arnn3ubxibg3qbck4rm4hwsrqjuwgu X-Rspam: Yes X-HE-Tag: 1631052044-372601 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: These are equivalent when thread_info contains the CPU value, but when THREAD_INFO_IN_TASK is enabled, cpu moves to task_struct. Using the macro allows either. Signed-off-by: Keith Packard --- arch/arm/vfp/vfpmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 2cb355c1b5b7..d7a3818da671 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -458,16 +458,16 @@ static int vfp_pm_suspend(void) /* disable, just in case */ fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_EN); - } else if (vfp_current_hw_state[ti->cpu]) { + } else if (vfp_current_hw_state[smp_processor_id()]) { #ifndef CONFIG_SMP fmxr(FPEXC, fpexc | FPEXC_EN); - vfp_save_state(vfp_current_hw_state[ti->cpu], fpexc); + vfp_save_state(vfp_current_hw_state[smp_processor_id()], fpexc); fmxr(FPEXC, fpexc); #endif } /* clear any information we had about last context state */ - vfp_current_hw_state[ti->cpu] = NULL; + vfp_current_hw_state[smp_processor_id()] = NULL; return 0; } From patchwork Tue Sep 7 22:00:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70EE0C43217 for ; Tue, 7 Sep 2021 22:00:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1C83D61103 for ; Tue, 7 Sep 2021 22:00:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1C83D61103 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B53EE6B0072; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2A3A6B0073; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C8456B0074; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 7FCDC6B0073 for ; Tue, 7 Sep 2021 18:00:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2F11C181DF776 for ; Tue, 7 Sep 2021 22:00:45 +0000 (UTC) X-FDA: 78562147650.17.0512A2F Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf08.hostedemail.com (Postfix) with ESMTP id D04DF30000B6 for ; Tue, 7 Sep 2021 22:00:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 136533F30867; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id LYoWbEmDiZX3; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id A3F673F30861; Tue, 7 Sep 2021 15:00:18 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id D854B1E6013A; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 4/7] ARM: Use hack from powerpc to get current cpu number Date: Tue, 7 Sep 2021 15:00:35 -0700 Message-Id: <20210907220038.91021-5-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine); spf=pass (imf08.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com X-Stat-Signature: ubwgighwg1s1u4bnhpeirs8o1cxmu1np X-Rspamd-Queue-Id: D04DF30000B6 X-Rspamd-Server: rspam04 X-Rspam: Yes X-HE-Tag: 1631052044-178941 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When we enable THREAD_INFO_IN_TASK, the cpu number will disappear from thread_info and reappear in task_struct. As we cannot include linux/sched.h in asm/smp.h, there's no way to use that struct type in the raw_smp_processor_id macro. Instead, a hack from the powerpc code is used. This pulls the TI_CPU offset out of asm-offsets.h and uses that to find the cpu value. Signed-off-by: Keith Packard --- arch/arm/Makefile | 8 ++++++++ arch/arm/include/asm/smp.h | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 415c3514573a..6752995d2914 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -284,6 +284,14 @@ stack_protector_prepare: prepare0 $(eval GCC_PLUGINS_CFLAGS += $(SSP_PLUGIN_CFLAGS)) endif +ifdef CONFIG_SMP +prepare: task_cpu_prepare + +PHONY += task_cpu_prepare +task_cpu_prepare: prepare0 + $(eval KBUILD_CFLAGS += -D_TI_CPU=$(shell awk '{if ($$2 == "TI_CPU") print $$3;}' include/generated/asm-offsets.h)) +endif + all: $(notdir $(KBUILD_IMAGE)) diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index d43b64635d77..f77ba3753bc4 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -15,7 +15,23 @@ # error " included in non-SMP build" #endif -#define raw_smp_processor_id() (current_thread_info()->cpu) +/* + * This is particularly ugly: it appears we can't actually get the + * definition of task_struct here, but we need access to the CPU this + * task is running on, which is stored in task_struct when + * THREAD_INFO_IN_TASK is set. Instead of using task_struct we're + * using TI_CPU which is extracted from asm-offsets.h by kbuild to get + * the current processor ID. + * + * This also needs to be safeguarded when building asm-offsets.s + * because at that time TI_CPU is not defined yet. + */ +#ifndef _TI_CPU +#define raw_smp_processor_id() (0) +#else +#define raw_smp_processor_id() \ + (*(unsigned int *)((void *)current_thread_info() + _TI_CPU)) +#endif struct seq_file; From patchwork Tue Sep 7 22:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A1BFC433FE for ; Tue, 7 Sep 2021 22:01:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 003F760EE6 for ; Tue, 7 Sep 2021 22:01:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 003F760EE6 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0F51B6B0087; Tue, 7 Sep 2021 18:01:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07D5E6B0088; Tue, 7 Sep 2021 18:01:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E859D900002; Tue, 7 Sep 2021 18:01:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id D2FAB6B0087 for ; Tue, 7 Sep 2021 18:01:51 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 85ED030C7D for ; Tue, 7 Sep 2021 22:01:51 +0000 (UTC) X-FDA: 78562150422.13.A332C22 Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf16.hostedemail.com (Postfix) with ESMTP id 29B81F000AE8 for ; Tue, 7 Sep 2021 22:00:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 977CB3F30865; Tue, 7 Sep 2021 15:00:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8zM7JNQ355Md; Tue, 7 Sep 2021 15:00:20 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id 7AF273F30868; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id DB4811E6013B; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 5/7] ARM: Stop using TPIDRPRW to hold per_cpu_offset Date: Tue, 7 Sep 2021 15:00:36 -0700 Message-Id: <20210907220038.91021-6-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine); spf=pass (imf16.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 29B81F000AE8 X-Stat-Signature: zfg57gofnt44j8nawgkq5ba5buejtubx X-Rspam: Yes X-HE-Tag: 1631052051-885683 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We're going to store TPIDRPRW here instead Signed-off-by: Keith Packard --- arch/arm/include/asm/percpu.h | 31 ------------------------------- arch/arm/kernel/setup.c | 7 ------- arch/arm/kernel/smp.c | 3 --- 3 files changed, 41 deletions(-) diff --git a/arch/arm/include/asm/percpu.h b/arch/arm/include/asm/percpu.h index e2fcb3cfd3de..eeafcd6a3e01 100644 --- a/arch/arm/include/asm/percpu.h +++ b/arch/arm/include/asm/percpu.h @@ -7,37 +7,6 @@ register unsigned long current_stack_pointer asm ("sp"); -/* - * Same as asm-generic/percpu.h, except that we store the per cpu offset - * in the TPIDRPRW. TPIDRPRW only exists on V6K and V7 - */ -#if defined(CONFIG_SMP) && !defined(CONFIG_CPU_V6) -static inline void set_my_cpu_offset(unsigned long off) -{ - /* Set TPIDRPRW */ - asm volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (off) : "memory"); -} - -static inline unsigned long __my_cpu_offset(void) -{ - unsigned long off; - - /* - * Read TPIDRPRW. - * We want to allow caching the value, so avoid using volatile and - * instead use a fake stack read to hazard against barrier(). - */ - asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) - : "Q" (*(const unsigned long *)current_stack_pointer)); - - return off; -} -#define __my_cpu_offset __my_cpu_offset() -#else -#define set_my_cpu_offset(x) do {} while(0) - -#endif /* CONFIG_SMP */ - #include #endif /* _ASM_ARM_PERCPU_H_ */ diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index ca0201635fac..d0dc60afe54f 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -590,13 +590,6 @@ void __init smp_setup_processor_id(void) for (i = 1; i < nr_cpu_ids; ++i) cpu_logical_map(i) = i == cpu ? 0 : i; - /* - * clear __my_cpu_offset on boot CPU to avoid hang caused by - * using percpu variable early, for example, lockdep will - * access percpu variable inside lock_release - */ - set_my_cpu_offset(0); - pr_info("Booting Linux on physical CPU 0x%x\n", mpidr); } diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 5e999f1f1aea..8ccf10b34f08 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -410,8 +410,6 @@ asmlinkage void secondary_start_kernel(unsigned int cpu, struct task_struct *tas { struct mm_struct *mm = &init_mm; - set_my_cpu_offset(per_cpu_offset(cpu)); - secondary_biglittle_init(); /* @@ -495,7 +493,6 @@ void __init smp_cpus_done(unsigned int max_cpus) void __init smp_prepare_boot_cpu(void) { - set_my_cpu_offset(per_cpu_offset(smp_processor_id())); } void __init smp_prepare_cpus(unsigned int max_cpus) From patchwork Tue Sep 7 22:00:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4C8BC433F5 for ; Tue, 7 Sep 2021 22:01:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5747F610A3 for ; Tue, 7 Sep 2021 22:01:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5747F610A3 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DEB9A6B0083; Tue, 7 Sep 2021 18:01:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D25816B0085; Tue, 7 Sep 2021 18:01:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BED7B900002; Tue, 7 Sep 2021 18:01:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id AFFFA6B0083 for ; Tue, 7 Sep 2021 18:01:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 06B8E2D38D for ; Tue, 7 Sep 2021 22:01:50 +0000 (UTC) X-FDA: 78562150380.18.E5FF1A4 Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf12.hostedemail.com (Postfix) with ESMTP id 900F110003D1 for ; Tue, 7 Sep 2021 22:00:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 263123F30864; Tue, 7 Sep 2021 15:00:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id uccwbHGFUJ_y; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id 655EA3F30861; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id DED9A1E6013C; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 6/7] ARM: Use TPIDRPRW for current Date: Tue, 7 Sep 2021 15:00:37 -0700 Message-Id: <20210907220038.91021-7-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine); spf=pass (imf12.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 900F110003D1 X-Stat-Signature: zq5nrueo64ghnhab1zq9zrb3girabnuf X-Rspam: Yes X-HE-Tag: 1631052049-615106 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Store current task pointer in CPU thread ID register TPIDRPRW so that accessing it doesn't depend on being able to locate thread_info off of the kernel stack pointer. Signed-off-by: Keith Packard --- arch/arm/Kconfig | 4 +++ arch/arm/include/asm/assembler.h | 8 +++++ arch/arm/include/asm/current.h | 52 ++++++++++++++++++++++++++++++++ arch/arm/kernel/entry-armv.S | 4 +++ arch/arm/kernel/setup.c | 1 + arch/arm/kernel/smp.c | 1 + 6 files changed, 70 insertions(+) create mode 100644 arch/arm/include/asm/current.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 24804f11302d..414fe23fd5ac 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1172,6 +1172,10 @@ config SMP_ON_UP If you don't know what to do here, say Y. +config CURRENT_POINTER_IN_TPIDRPRW + def_bool y + depends on (CPU_V6K || CPU_V7) && !CPU_V6 + config ARM_CPU_TOPOLOGY bool "Support cpu topology definition" depends on SMP && CPU_V7 diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index e2b1fd558bf3..ea12fe3bb589 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -209,6 +209,14 @@ mov \rd, \rd, lsl #THREAD_SIZE_ORDER + PAGE_SHIFT .endm +/* + * Set current task_info + * @src: Source register containing task_struct pointer + */ + .macro set_current src : req + mcr p15, 0, \src, c13, c0, 4 + .endm + /* * Increment/decrement the preempt count. */ diff --git a/arch/arm/include/asm/current.h b/arch/arm/include/asm/current.h new file mode 100644 index 000000000000..153a2ea18747 --- /dev/null +++ b/arch/arm/include/asm/current.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright © 2021 Keith Packard + */ + +#ifndef _ASM_ARM_CURRENT_H_ +#define _ASM_ARM_CURRENT_H_ + +#ifndef __ASSEMBLY__ + +register unsigned long current_stack_pointer asm ("sp"); + +/* + * Same as asm-generic/current.h, except that we store current + * in TPIDRPRW. TPIDRPRW only exists on V6K and V7 + */ +#ifdef CONFIG_CURRENT_POINTER_IN_TPIDRPRW + +struct task_struct; + +static inline void set_current(struct task_struct *tsk) +{ + /* Set TPIDRPRW */ + asm volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (tsk) : "memory"); +} + +static __always_inline struct task_struct *get_current(void) +{ + struct task_struct *tsk; + + /* + * Read TPIDRPRW. + * We want to allow caching the value, so avoid using volatile and + * instead use a fake stack read to hazard against barrier(). + */ + asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (tsk) + : "Q" (*(const unsigned long *)current_stack_pointer)); + + return tsk; +} +#define current get_current() +#else + +#define set_current(tsk) do {} while (0) + +#include + +#endif /* CONFIG_SMP */ + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_ARM_CURRENT_H_ */ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 0ea8529a4872..db3947ee9c3e 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -761,6 +761,10 @@ ENTRY(__switch_to) ldr r6, [r2, #TI_CPU_DOMAIN] #endif switch_tls r1, r4, r5, r3, r7 +#ifdef CONFIG_CURRENT_POINTER_IN_TPIDRPRW + ldr r7, [r2, #TI_TASK] + set_current r7 +#endif #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) ldr r7, [r2, #TI_TASK] ldr r8, =__stack_chk_guard diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index d0dc60afe54f..2fdf8c31d6c9 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -586,6 +586,7 @@ void __init smp_setup_processor_id(void) u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0; u32 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); + set_current(&init_task); cpu_logical_map(0) = cpu; for (i = 1; i < nr_cpu_ids; ++i) cpu_logical_map(i) = i == cpu ? 0 : i; diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 8ccf10b34f08..09771916442a 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -410,6 +410,7 @@ asmlinkage void secondary_start_kernel(unsigned int cpu, struct task_struct *tas { struct mm_struct *mm = &init_mm; + set_current(task); secondary_biglittle_init(); /* From patchwork Tue Sep 7 22:00:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 12479433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_ADSP_ALL, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8888C433F5 for ; Tue, 7 Sep 2021 22:00:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6165261106 for ; Tue, 7 Sep 2021 22:00:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6165261106 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E3F5A6B007B; Tue, 7 Sep 2021 18:00:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE8FD6B007D; Tue, 7 Sep 2021 18:00:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7B8F6B007E; Tue, 7 Sep 2021 18:00:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id A27E26B007B for ; Tue, 7 Sep 2021 18:00:50 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6045C181EBA4E for ; Tue, 7 Sep 2021 22:00:50 +0000 (UTC) X-FDA: 78562147860.32.248EC41 Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by imf26.hostedemail.com (Postfix) with ESMTP id 1100220019CF for ; Tue, 7 Sep 2021 22:00:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 9155B3F30861; Tue, 7 Sep 2021 15:00:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id cyWcFQXC8t4y; Tue, 7 Sep 2021 15:00:20 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id 71C3F3F30862; Tue, 7 Sep 2021 15:00:19 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id E25F31E6013D; Tue, 7 Sep 2021 15:00:40 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Andrew Morton , Andrey Ryabinin , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Christoph Lameter , Dennis Zhou , Geert Uytterhoeven , Jens Axboe , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nick Desaulniers , Nicolas Pitre , Russell King , Tejun Heo , Thomas Gleixner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu Subject: [PATCH 7/7] ARM: Move thread_info into task_struct (v7 only) Date: Tue, 7 Sep 2021 15:00:38 -0700 Message-Id: <20210907220038.91021-8-keithpac@amazon.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210907220038.91021-1-keithpac@amazon.com> References: <20210904060908.1310204-1-keithp@keithp.com> <20210907220038.91021-1-keithpac@amazon.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1100220019CF Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=amazon.com (policy=quarantine); spf=pass (imf26.hostedemail.com: domain of keithp@keithp.com designates 63.227.221.253 as permitted sender) smtp.mailfrom=keithp@keithp.com X-Rspamd-Server: rspam01 X-Stat-Signature: brs5ku9fh7spq3ej6f943ots3zoxja6o X-Rspam: Yes X-HE-Tag: 1631052049-503475 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This avoids many stack overflow attacks which modified the thread_info structure by moving that into the task_struct as is done is almost all other architectures. This depends on having 'current' stored in the TPIDRPRW register as that allows us to find thread_info and task_struct once the thread_info cannot be located using the kernel stack pointer. Signed-off-by: Keith Packard --- arch/arm/Kconfig | 1 + arch/arm/include/asm/assembler.h | 4 ++++ arch/arm/include/asm/thread_info.h | 12 +++++++++++- arch/arm/kernel/asm-offsets.c | 4 ++++ arch/arm/kernel/entry-armv.S | 4 ++++ arch/arm/vfp/vfpmodule.c | 9 +++++++++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 414fe23fd5ac..5846b4f5444b 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -128,6 +128,7 @@ config ARM select RTC_LIB select SET_FS select SYS_SUPPORTS_APM_EMULATION + select THREAD_INFO_IN_TASK if CURRENT_POINTER_IN_TPIDRPRW # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index ea12fe3bb589..b23d2b87184a 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -203,10 +203,14 @@ * Get current thread_info. */ .macro get_thread_info, rd +#ifdef CONFIG_THREAD_INFO_IN_TASK + mrc p15, 0, \rd, c13, c0, 4 +#else ARM( mov \rd, sp, lsr #THREAD_SIZE_ORDER + PAGE_SHIFT ) THUMB( mov \rd, sp ) THUMB( lsr \rd, \rd, #THREAD_SIZE_ORDER + PAGE_SHIFT ) mov \rd, \rd, lsl #THREAD_SIZE_ORDER + PAGE_SHIFT +#endif .endm /* diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index 70d4cbc49ae1..6b67703ca16a 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -55,8 +55,10 @@ struct thread_info { unsigned long flags; /* low level flags */ int preempt_count; /* 0 => preemptable, <0 => bug */ mm_segment_t addr_limit; /* address limit */ +#ifndef CONFIG_THREAD_INFO_IN_TASK struct task_struct *task; /* main task structure */ __u32 cpu; /* cpu */ +#endif __u32 cpu_domain; /* cpu domain */ #ifdef CONFIG_STACKPROTECTOR_PER_TASK unsigned long stack_canary; @@ -75,14 +77,21 @@ struct thread_info { #endif }; +#ifdef CONFIG_THREAD_INFO_IN_TASK +#define INIT_THREAD_INFO_TASK(tsk) +#else +#define INIT_THREAD_INFO_TASK(tsk) .task = &tsk, +#endif + #define INIT_THREAD_INFO(tsk) \ { \ - .task = &tsk, \ + INIT_THREAD_INFO_TASK(tsk) \ .flags = 0, \ .preempt_count = INIT_PREEMPT_COUNT, \ .addr_limit = KERNEL_DS, \ } +#ifndef CONFIG_THREAD_INFO_IN_TASK /* * how to get the thread information struct from C */ @@ -93,6 +102,7 @@ static inline struct thread_info *current_thread_info(void) return (struct thread_info *) (current_stack_pointer & ~(THREAD_SIZE - 1)); } +#endif #define thread_saved_pc(tsk) \ ((unsigned long)(task_thread_info(tsk)->cpu_context.pc)) diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index 70993af22d80..2a6745f7423e 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -44,8 +44,12 @@ int main(void) DEFINE(TI_FLAGS, offsetof(struct thread_info, flags)); DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count)); DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit)); +#ifdef CONFIG_THREAD_INFO_IN_TASK + DEFINE(TI_CPU, offsetof(struct task_struct, cpu)); +#else DEFINE(TI_TASK, offsetof(struct thread_info, task)); DEFINE(TI_CPU, offsetof(struct thread_info, cpu)); +#endif DEFINE(TI_CPU_DOMAIN, offsetof(struct thread_info, cpu_domain)); DEFINE(TI_CPU_SAVE, offsetof(struct thread_info, cpu_context)); DEFINE(TI_USED_CP, offsetof(struct thread_info, used_cp)); diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index db3947ee9c3e..5ae687c8c7b8 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -762,9 +762,13 @@ ENTRY(__switch_to) #endif switch_tls r1, r4, r5, r3, r7 #ifdef CONFIG_CURRENT_POINTER_IN_TPIDRPRW +#ifdef CONFIG_THREAD_INFO_IN_TASK + set_current r2 +#else ldr r7, [r2, #TI_TASK] set_current r7 #endif +#endif #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP) ldr r7, [r2, #TI_TASK] ldr r8, =__stack_chk_guard diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index d7a3818da671..84a691da59fa 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -158,7 +158,12 @@ static void vfp_thread_copy(struct thread_info *thread) */ static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) { +#ifdef CONFIG_THREAD_INFO_IN_TASK + struct task_struct *tsk = v; + struct thread_info *thread = &tsk->thread_info; +#else struct thread_info *thread = v; +#endif u32 fpexc; #ifdef CONFIG_SMP unsigned int cpu; @@ -169,7 +174,11 @@ static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) fpexc = fmrx(FPEXC); #ifdef CONFIG_SMP +#ifdef CONFIG_THREAD_INFO_IN_TASK + cpu = tsk->cpu; +#else cpu = thread->cpu; +#endif /* * On SMP, if VFP is enabled, save the old state in