Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4162197ybc; Tue, 26 Nov 2019 04:56:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwL16BDGdZ4/nRxULNdsE+sUpJh9jgaGHULrE0s1Ya5l1bcHYJKhE8MCzTBB/Hm1omMKGQj X-Received: by 2002:a17:906:7f8a:: with SMTP id f10mr44196685ejr.209.1574772972305; Tue, 26 Nov 2019 04:56:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574772972; cv=none; d=google.com; s=arc-20160816; b=RWg3F7MSS2P87ZEcwZ5NQi1mdv5ZjozcLDx2d1bhuHUEwtqdCycjtCnOfkkfCRzf+3 4AiWXINi945lIlYuq0G0kBHljFPLg/MQFkKSr2jtAh/+ijedcNwgRATT4MZi6hcftAKl xxlFSW3bnSqokDqnTEUJaiqUy0LqT9klO8ZbvFzoEIyxqPr47sud4KUrIohnZigOREri Z64kgxV06As5eEntWKmF0tfvOa7DTOyul6Dsm7PrABFbeuA6BAAw/OtnwWIrQIe5rt75 K/d0kBEvli3PSnCghJQ3cpKuuQta6jZOOy2xJ2WeHsHIRN8b+lbxVvjQtYb9JmwMQYof Claw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=gOKxrtnFAgRuj43vPkwpnRsML3n0B7clWBuAh6m562Y=; b=LChX50w0VC4h+m0tBcdvpiSCrjiRjbuR25yG1ZLEXDNxaEsDFKIMB5i9F8ofxlZNAk vA7yVeF64+ifiWyKWOa2Rm6LHErbKNh5K6CKCtdrKvKkdjV/iJdy0vEhNuyNpALAYH3T OC6Yt3ci0Vk1rcu4OzpgjyS8zIrezEjzmV3Bj3pOGmxLOWi2DTFIEPcEUxhgidli0zfj cdwhU3UZ9BI1TItePUZuP2AhO38o4PNmOkNTzJynvH6R4ZTx6DX6fpKoXuf5x+hZFIh4 D/r4nhm2ZtjWwB9dvRlR8vOGLzNRTTrJ5r5YnoG6uPFqYahhUazRVvXRRRfI8XuI+it2 8sIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=PnPyQyQ0; 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 oy25si6839878ejb.291.2019.11.26.04.55.48; Tue, 26 Nov 2019 04:56:12 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=PnPyQyQ0; 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 S1728489AbfKZMgS (ORCPT + 99 others); Tue, 26 Nov 2019 07:36:18 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:25835 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728445AbfKZMgM (ORCPT ); Tue, 26 Nov 2019 07:36:12 -0500 Received: from localhost (mailhub1-ext [192.168.12.233]) by localhost (Postfix) with ESMTP id 47Mk0T6mvNz9v0GC; Tue, 26 Nov 2019 13:36:09 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=PnPyQyQ0; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id PtuDK7RrT_qk; Tue, 26 Nov 2019 13:36:09 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 47Mk0T5lz7z9v0G3; Tue, 26 Nov 2019 13:36:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1574771769; bh=gOKxrtnFAgRuj43vPkwpnRsML3n0B7clWBuAh6m562Y=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=PnPyQyQ04mngmpm+Thv3+/K8x1FG75fVbSBF1KM3i+WrO6Qb9OaPFjP5oNeeyzR9s HcMx3OBvoR20fF6He9obZJQQjOQD7YULSiTqVWnWChzOsoYzs1PDGy8jWocFqUcc6R tVG2d4UEHAC58vv9yBq4sm3lFTpyDvrZBEO0Tfq4= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 099468B7FC; Tue, 26 Nov 2019 13:36:11 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id y-1AHrQMGz9a; Tue, 26 Nov 2019 13:36:10 +0100 (CET) Received: from po16098vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C83918B771; Tue, 26 Nov 2019 13:36:10 +0100 (CET) Received: by po16098vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 94CDE6B76A; Tue, 26 Nov 2019 12:36:10 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v4 07/16] powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Date: Tue, 26 Nov 2019 12:36:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to ease stack overflow detection, align stack to 2 * THREAD_SIZE when using VMAP_STACK. This allows overflow detection using a single bit check. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/thread_info.h | 13 +++++++++++++ arch/powerpc/kernel/setup_32.c | 2 +- arch/powerpc/kernel/setup_64.c | 2 +- arch/powerpc/kernel/vmlinux.lds.S | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h index 488d5c4670ff..a2270749b282 100644 --- a/arch/powerpc/include/asm/thread_info.h +++ b/arch/powerpc/include/asm/thread_info.h @@ -22,6 +22,19 @@ #define THREAD_SIZE (1 << THREAD_SHIFT) +/* + * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by + * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry + * assembly. + */ +#ifdef CONFIG_VMAP_STACK +#define THREAD_ALIGN_SHIFT (THREAD_SHIFT + 1) +#else +#define THREAD_ALIGN_SHIFT THREAD_SHIFT +#endif + +#define THREAD_ALIGN (1 << THREAD_ALIGN_SHIFT) + #ifndef __ASSEMBLY__ #include #include diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c index dcffe927f5b9..f014c4f7a337 100644 --- a/arch/powerpc/kernel/setup_32.c +++ b/arch/powerpc/kernel/setup_32.c @@ -140,7 +140,7 @@ arch_initcall(ppc_init); static void *__init alloc_stack(void) { - void *ptr = memblock_alloc(THREAD_SIZE, THREAD_SIZE); + void *ptr = memblock_alloc(THREAD_SIZE, THREAD_ALIGN); if (!ptr) panic("cannot allocate %d bytes for stack at %pS\n", diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 6104917a282d..e05e6dd67ae6 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -633,7 +633,7 @@ static void *__init alloc_stack(unsigned long limit, int cpu) BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16); - ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE, + ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_ALIGN, MEMBLOCK_LOW_LIMIT, limit, early_cpu_to_node(cpu)); if (!ptr) diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index 060a1acd7c6d..d38335129c06 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -346,7 +346,7 @@ SECTIONS #endif /* The initial task and kernel stack */ - INIT_TASK_DATA_SECTION(THREAD_SIZE) + INIT_TASK_DATA_SECTION(THREAD_ALIGN) .data..page_aligned : AT(ADDR(.data..page_aligned) - LOAD_OFFSET) { PAGE_ALIGNED_DATA(PAGE_SIZE) -- 2.13.3