Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4144404ybl; Sat, 21 Dec 2019 00:33:34 -0800 (PST) X-Google-Smtp-Source: APXvYqyqyr8xunzBBw/5Ijv4i+1bDkwL9U1EowKn+hK6FRVyaxEES0t1mPp8mRfUmxeYgZANVnyM X-Received: by 2002:a05:6830:1cd3:: with SMTP id p19mr17497238otg.118.1576917214277; Sat, 21 Dec 2019 00:33:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576917214; cv=none; d=google.com; s=arc-20160816; b=Bf2s53WHzjoUtkl2Ijyset52SR91yvpz1Y1Z+0ng4nzuB0MIq24+KuI9wAP3zcDU9F IM2fNix5h6Q/LEsSCS+5tXrYZG+eZ+FQ/uoMcnpI9kyTwa3CsMYl9/8m28VjVHg1K/9Q +CPKmP9aEUnnzgsYHz+RAXNrSWx7K5G6IzeRSM71hNIeqbSIEup+CnqWtIDKEyWFckRF NZp6pg2vVQMLkIk1Oytodjp+1x07oTDn47j2qJpKDFsjRKq/vaU/B3VaQOk8ENQpNI10 q3C0/bOqSCGzNFz23f8lgmVLt9p3cONhRb2KORVQj8LmfCYxLM2Lfk2jACFxyKHLCC8/ S6sg== 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=DQVyB9m2SFlXQ/6NdPBYridG2vEVSsZ5fiPCfT1jDYA=; b=LHoV5XcyJCI/KJM2tYNlubKs5QBT9AzPTogPhopqkaKvXLnnm9UAAtxK4qk56WvA4q 1/5gGNqPKyq+0g7N0uR46gNnl8R+sQlJwhVqJt+MaNzoDIjlvJHeQ87c508uZRSWgeId 8ieBARtNdWbSwNwxhDb9OV/ZxTfPAMY7Cy0w6BW9fBWuiKVYFnZdNJ+cd8KmwEwE+drG Kk7/EiAtnirhsLfOjXjPMTgMdIGrlycjIwTiFBrhHv/Ps3uZucEOiaC4HnssJ1EZQfjh IDNNjbT/RqPikcExucPLjovGSPuYzxOUAEddjL8wVvhlt7uS52cSgQi1YfLLpgGU7EvQ 0LAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=GH8QhU59; 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 z2si6059732oix.100.2019.12.21.00.33.22; Sat, 21 Dec 2019 00:33:34 -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=GH8QhU59; 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 S1725944AbfLUIcf (ORCPT + 99 others); Sat, 21 Dec 2019 03:32:35 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:45061 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726633AbfLUIca (ORCPT ); Sat, 21 Dec 2019 03:32:30 -0500 Received: from localhost (mailhub1-ext [192.168.12.233]) by localhost (Postfix) with ESMTP id 47fzPm1XnZz9vBn0; Sat, 21 Dec 2019 09:32:28 +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=GH8QhU59; 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 V64sKJAt0eTT; Sat, 21 Dec 2019 09:32:28 +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 47fzPm0WYVz9vBmv; Sat, 21 Dec 2019 09:32:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1576917148; bh=DQVyB9m2SFlXQ/6NdPBYridG2vEVSsZ5fiPCfT1jDYA=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=GH8QhU596ao3qVRmQVoLd675JOn2TS4f+p6EHnZkDe/e6LfII1+kAgKJwB+KOLIKT x73Dj1CLkhuIdFe/d3aWQyJeDkB5XSRrzWpos2Z0Z6XPDDQeI7T9dvCSBXocjcLlNe hwy0Ws1Q2SWp/PjOiNpJ32cLhUnKKSI5bz1+pVcg= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 083708B77C; Sat, 21 Dec 2019 09:32:29 +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 aeRrlaLRdQ6v; Sat, 21 Dec 2019 09:32:28 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BFC7A8B752; Sat, 21 Dec 2019 09:32:28 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id 88DD0637B6; Sat, 21 Dec 2019 08:32:28 +0000 (UTC) Message-Id: <60e9ae86b7d2cdcf21468787076d345663648f46.1576916812.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v5 07/17] powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , dja@axtens.net Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Date: Sat, 21 Dec 2019 08:32:28 +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 8834220036a5..b4c89a1acebb 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -323,7 +323,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