From patchwork Fri Dec 7 22:34:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 10718989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFB4E14E2 for ; Fri, 7 Dec 2018 22:35:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C83C2B479 for ; Fri, 7 Dec 2018 22:35:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A33A2B8E5; Fri, 7 Dec 2018 22:35:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF5442B479 for ; Fri, 7 Dec 2018 22:35:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCAC08E0033; Fri, 7 Dec 2018 17:35:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B796C8E0004; Fri, 7 Dec 2018 17:35:01 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1A988E0033; Fri, 7 Dec 2018 17:35:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by kanga.kvack.org (Postfix) with ESMTP id 784BB8E0004 for ; Fri, 7 Dec 2018 17:35:01 -0500 (EST) Received: by mail-qt1-f198.google.com with SMTP id b16so5134426qtc.22 for ; Fri, 07 Dec 2018 14:35:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=QDHetqdY6gL2ut6w5hBOClKGYYflCOmIf2piJSnwVCA=; b=OTQ5t2B9XsrBlAnWEx3oNOkfTwY4JR8ntiazqqzR00fv1+4gu9EE+JJCvTfyOdkA9r 8XFgf2hpLFbSDWowIMYFxqWLN6c5E8F6o1lCRmoHrAXhZe0X4ofmK12rLzzqdz0UH5n9 3BPpVTRqnf7RGjOtHhUd6V5V2FoenHOJo0zDahfCch4SqAaPhY53ZmLrcDD7WepiT34u hKXbwQnFR7ftHbUVgdwA3Aj4YOUMKVT6abqtxaVnsaFSLB+EKXgc1K4LufWHyKJt/HWk iD3YSGieiEXXZSocg2M4o7dqJbdc06uHHHvyJIZE0YJvdRVzkvSXd9AU4+wOs/feHKTf /Qaw== X-Gm-Message-State: AA+aEWZXTQxaeRJgaafCOCeg/FQed9hRGCaMPc0fmzTmx9uWqfn/Uwrf RKCV8wixFUFm0HOlS5GCLx/mk8JGomakhPc0PYtAZ90cFdXIMVNemfBqBEs9e6mSVA9pYQ53CDN 0ZQgPkN5Gk3sYBE431JSNJjqG55QlgyMoUDj/8xVOFmP3RxXDCkSgyxh9+BQbkrxJk4UC5/xXaU Z1R7fohMJQe0Qr/4MvVz8704St1uZd0E8pQ3xBl7fY3A2KcvIDYaSzUkpduHoFJqYot/VCuAIYk IEdD3JThm8oG1AJxM+TGr0Awc60GmrQB5IwV/XT/7mmc2cCUhz+WomLxGU4D1GCc+4OXV96yV4a gh3SGPfFQWCBXHzLIxgWEj1nz0PKC6FSBCpDvcfW+S17uI7iWWcskhwG7slFuHTvuggOaPy9x8m Y X-Received: by 2002:a0c:aca7:: with SMTP id m36mr3645912qvc.237.1544222101226; Fri, 07 Dec 2018 14:35:01 -0800 (PST) X-Received: by 2002:a0c:aca7:: with SMTP id m36mr3645887qvc.237.1544222100404; Fri, 07 Dec 2018 14:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544222100; cv=none; d=google.com; s=arc-20160816; b=sXWu4xHdaEIZOMRSRQ/KJSSXB2HPPy57dLiRQ5G/vm0Jvt501cBtpBQfceTCSK8+aV OtPYly0mQZuchAPEjxHBe5N4BP3SwH4Oq3tKZ1fEFWD4cQqSd0617bSqBntU8nj9rB6S 9OQPt4sY+DQIOcR/s9fhADzpr6NG5PQxv1YJ1crdqZtSn2GtGZ4sJs7Prqbrt4pxDC5d DGiHT4ATVpP9A4TCpZbDK+wRPsWbdA4mdWJRmgC0qtZZFTC6MEG2Ln8xCXwn/YQvZJcT 8bTA3W2KAEKrlAqkPD9dGBKn+JRk9jCq6yvoqLq3PCdl1Y0EorsP5yivzTq+blA9qJOV Qkow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QDHetqdY6gL2ut6w5hBOClKGYYflCOmIf2piJSnwVCA=; b=a4h8/9rVJXbrop2eln1jxIJ8IQZL0sUzDBIbAT4c/9hQj46pRW0KnbxmpSfjiSudKD QrdrbZQfTQwcOkhP0j5ebL0rrfylzkbFn/7GPmCHzdomxHy6XzC3+DWPbtUO5Fhvgnv5 gJh5lic/BjyJ9XnmEqm7u1BDla9fqC7S+6vfK1VBrAPmpr7ccrsZbXJkb71vZwPXhsM1 YlbAxp+PdTCycDwxKEGGnnIEpTmD6y8B4kVZBGGKTplbZbGlvupCrIPYKTZmceedieNb nvPLPHCfW7WTNEjwJX9b0ut5ybSujNpgttg0qEC9jtSXYCqWC9QDF6u4ybV0rzlv6Nwl Xqnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=XlewbJ5l; spf=pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) smtp.mailfrom=cai@lca.pw Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v54sor5889826qta.59.2018.12.07.14.35.00 for (Google Transport Security); Fri, 07 Dec 2018 14:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=XlewbJ5l; spf=pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) smtp.mailfrom=cai@lca.pw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QDHetqdY6gL2ut6w5hBOClKGYYflCOmIf2piJSnwVCA=; b=XlewbJ5l6u5F0/A8cWX4s+3SHkW1ez1LG4mNrfLVy1fLIciasfhYhYb+jAjQVRhXy+ eTwKcOqjxK3Jd1pWNMbVzm7nPJmxgmHxMKdrHrUxRN0ap1pyEx7Xnwy6PghZ/smAFkMn zmasFudqR6QRtvtH0S6XTo4OBlk5q3zkSKlLFmIVU17NCV4E2eIMGk5ibnJEDrcYZ3rh q++WnLXNmvIT9MTh9IuGjoxW0qAuFRDzyULrh6UJzsCQZWgywE4dfUpmPzrapsYVjyFQ ZqQZhetQ3QYEq22E8aWN9PE0t3JLgoPTogBGoNqOvM/SuMbl90dj+X1EhzX2z8Ur5rVs USxQ== X-Google-Smtp-Source: AFSGD/WejKshiv7QsC3sfvDuJ4bXWRhcUsf+w02H/MBeBw9vTcjUTcFmTufFIMhbdN/iZ/cqlDZs1Q== X-Received: by 2002:ac8:280f:: with SMTP id 15mr3909192qtq.31.1544222100055; Fri, 07 Dec 2018 14:35:00 -0800 (PST) Received: from ovpn-121-90.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id v53sm2968757qtb.6.2018.12.07.14.34.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 14:34:59 -0800 (PST) From: Qian Cai To: catalin.marinas@arm.com, will.deacon@arm.com Cc: aryabinin@virtuozzo.com, glider@google.com, dvyukov@google.com, arnd@arndb.de, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH] arm64: increase stack size for KASAN_EXTRA Date: Fri, 7 Dec 2018 17:34:49 -0500 Message-Id: <20181207223449.38808-1-cai@lca.pw> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <721E7B42-2D55-4866-9C1A-3E8D64F33F9C@gmx.us> References: <721E7B42-2D55-4866-9C1A-3E8D64F33F9C@gmx.us> 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: X-Virus-Scanned: ClamAV using ClamSMTP If the kernel is configured with KASAN_EXTRA, the stack size is increasted significantly due to enable this option will set -fstack-reuse to "none" in GCC [1]. As the results, it could trigger stack overrun quite often with 32k stack size compiled using GCC 8. For example, this reproducer https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/\ syscalls/madvise/madvise06.c could trigger a "corrupted stack end detected inside scheduler" very reliably with CONFIG_SCHED_STACK_END_CHECK enabled. Also, See other bug reports, https://lore.kernel.org/lkml/1542144497.12945.29.camel@gmx.us/ https://lore.kernel.org/lkml/721E7B42-2D55-4866-9C1A-3E8D64F33F9C@gmx.us/ There are just too many functions that could have a large stack with KASAN_EXTRA due to large local variables that have been called over and over again without being able to reuse the stacks. Some noticiable ones are, size 7536 shrink_inactive_list 7440 shrink_page_list 6560 fscache_stats_show 3920 jbd2_journal_commit_transaction 3216 try_to_unmap_one 3072 migrate_page_move_mapping 3584 migrate_misplaced_transhuge_page 3920 ip_vs_lblcr_schedule 4304 lpfc_nvme_info_show 3888 lpfc_debugfs_nvmestat_data.constprop There are other 49 functions are over 2k in size while compiling kernel with "-Wframe-larger-than=" on this machine. Hence, it is too much work to change Makefiles for each object to compile without -fsanitize-address-use-after-scope individually. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715#c23 Signed-off-by: Qian Cai --- arch/arm64/include/asm/memory.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index b96442960aea..56562ff01076 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -76,12 +76,17 @@ /* * KASAN requires 1/8th of the kernel virtual address space for the shadow * region. KASAN can bloat the stack significantly, so double the (minimum) - * stack size when KASAN is in use. + * stack size when KASAN is in use, and then double it again if KASAN_EXTRA is + * on. */ #ifdef CONFIG_KASAN #define KASAN_SHADOW_SCALE_SHIFT 3 #define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) +#ifdef CONFIG_KASAN_EXTRA +#define KASAN_THREAD_SHIFT 2 +#else #define KASAN_THREAD_SHIFT 1 +#endif /* CONFIG_KASAN_EXTRA */ #else #define KASAN_SHADOW_SIZE (0) #define KASAN_THREAD_SHIFT 0