Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 157CDC433EF for ; Tue, 21 Dec 2021 11:15:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236977AbhLULPL (ORCPT ); Tue, 21 Dec 2021 06:15:11 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:14779 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236868AbhLULPL (ORCPT ); Tue, 21 Dec 2021 06:15:11 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20211221111509euoutp0110c8875a801c432bdc3f0ddd2325aae4~CwOZSIDsK2480524805euoutp01E for ; Tue, 21 Dec 2021 11:15:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20211221111509euoutp0110c8875a801c432bdc3f0ddd2325aae4~CwOZSIDsK2480524805euoutp01E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1640085309; bh=+CS92uzC2SxR/olzxHlG6VLuOSbgFNu8je3sPSduk1s=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=ZnPSGEA28erILgU+tc+4CBE5gHBLdNpJjIe8q0rC1b1QXhw18soqTbRXyr0ndbJ2F ObrIyn2z5BykiyCSCNfSqJE38Gqv1X8talNjAQzyfyXx95Lge9fjPJ/jrVysat+nQ2 TM9XiwNTKLv1m8RRKCoR7O433fDPp/J87t1W51Vk= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20211221111509eucas1p1e59ca8c6b66519bf1695b58006fe9423~CwOYxe0i11801718017eucas1p1d; Tue, 21 Dec 2021 11:15:09 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id B6.93.10260.D37B1C16; Tue, 21 Dec 2021 11:15:09 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20211221111508eucas1p21c03036d6d53f61c44539a1b260d288d~CwOYZkR850838708387eucas1p2x; Tue, 21 Dec 2021 11:15:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20211221111508eusmtrp11163b6ba1d96302c705d617bf10b5d58~CwOYYkkLo3096430964eusmtrp1j; Tue, 21 Dec 2021 11:15:08 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-e7-61c1b73de186 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 01.2D.09522.C37B1C16; Tue, 21 Dec 2021 11:15:08 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20211221111508eusmtip29ca8da5e70d0bb8e8bdce55993d5a69d~CwOXvT31t2490724907eusmtip2L; Tue, 21 Dec 2021 11:15:08 +0000 (GMT) Message-ID: Date: Tue, 21 Dec 2021 12:15:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v4 7/7] ARM: implement support for vmap'ed stacks Content-Language: en-US To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Russell King , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Tony Lindgren , Krzysztof Kozlowski , Linux Samsung SOC From: Marek Szyprowski In-Reply-To: Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+N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iffXyrBtCrzNusE8o2+L8/vH8jgZuQaZngrrX3PYEW21eK2y9x3om86M5DivNb97a I1q2NOjstpqpW4tmP111Vaz0HXv9zvV35q+48HNVm9kCjqfbF6eFRGy8+iHX3mO/3+X0iTaT ptoXCwdpMB66sbDynRJLcUaioRZzUXEiAHTepfF3AwAA X-CMS-MailID: 20211221111508eucas1p21c03036d6d53f61c44539a1b260d288d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20211221103854eucas1p2592e38fcc84c1c3506fce87f1dab6739 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20211221103854eucas1p2592e38fcc84c1c3506fce87f1dab6739 References: <20211122092816.2865873-1-ardb@kernel.org> <20211122092816.2865873-8-ardb@kernel.org> <0ffc858f-27e7-6789-4be1-c4c5ad61eb9d@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Hi Ard, On 21.12.2021 11:44, Ard Biesheuvel wrote: > On Tue, 21 Dec 2021 at 11:39, Marek Szyprowski wrote: >> On 22.11.2021 10:28, Ard Biesheuvel wrote: >>> Wire up the generic support for managing task stack allocations via vmalloc, >>> and implement the entry code that detects whether we faulted because of a >>> stack overrun (or future stack overrun caused by pushing the pt_regs array) >>> >>> While this adds a fair amount of tricky entry asm code, it should be >>> noted that it only adds a TST + branch to the svc_entry path. The code >>> implementing the non-trivial handling of the overflow stack is emitted >>> out-of-line into the .text section. >>> >>> Since on ARM, we rely on do_translation_fault() to keep PMD level page >>> table entries that cover the vmalloc region up to date, we need to >>> ensure that we don't hit such a stale PMD entry when accessing the >>> stack. So we do a dummy read from the new stack while still running from >>> the old one on the context switch path, and bump the vmalloc_seq counter >>> when PMD level entries in the vmalloc range are modified, so that the MM >>> switch fetches the latest version of the entries. >>> >>> Note that we need to increase the per-mode stack by 1 word, to gain some >>> space to stash a GPR until we know it is safe to touch the stack. >>> However, due to the cacheline alignment of the struct, this does not >>> actually increase the memory footprint of the struct stack array at all. >>> >>> Signed-off-by: Ard Biesheuvel >>> Tested-by: Keith Packard >> This patch landed recently in linux-next 20211220 as commit a1c510d0adc6 >> ("ARM: implement support for vmap'ed stacks"). Sadly it breaks >> suspend/resume operation on all ARM 32bit Exynos SoCs. Probably the >> suspend/resume related code must be updated somehow (it partially works >> on physical addresses and disabled MMU), but I didn't analyze it yet. If >> you have any hints, let me know. >> > Are there any such systems in KernelCI? We caught a suspend/resume > related issue in development, which is why the hunk below was added. I think that some Exynos-based Odroids (U3 and XU3) were some time ago available in KernelCI, but I don't know if they are still there. > In general, any virt-to-phys translation involving and address on the > stack will become problematic. > > Could you please confirm whether the issue persists with the patch > applied but with CONFIG_VMAP_STACK turned off? Just so we know we are > looking in the right place? I've just checked. After disabling CONFIG_VMAP_STACK suspend/resume works fine both on commit a1c510d0adc6 and linux-next 20211220. >> diff --git a/arch/arm/kernel/sleep.S b/arch/arm/kernel/sleep.S >> index 43077e11dafd..803b51e5cba0 100644 >> --- a/arch/arm/kernel/sleep.S >> +++ b/arch/arm/kernel/sleep.S >> @@ -67,6 +67,14 @@ ENTRY(__cpu_suspend) >> ldr r4, =cpu_suspend_size >> #endif >> mov r5, sp @ current virtual SP >> +#ifdef CONFIG_VMAP_STACK >> + @ Run the suspend code from the overflow stack so we don't have to rely >> + @ on vmalloc-to-phys conversions anywhere in the arch suspend code. >> + @ The original SP value captured in R5 will be restored on the way out. >> + mov_l r6, overflow_stack_ptr @ Base pointer >> + mrc p15, 0, r7, c13, c0, 4 @ Get per-CPU offset >> + ldr sp, [r6, r7] @ Address of this CPU's overflow stack >> +#endif >> add r4, r4, #12 @ Space for pgd, virt sp, phys resume fn >> sub sp, sp, r4 @ allocate CPU state on stack >> ldr r3, =sleep_save_sp Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland