From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C9E1ECAAD3 for ; Thu, 1 Sep 2022 13:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+3Wl112tEBHiAxfJ22OW9mEfGTmKcN4z4TP/s7JL7VA=; b=TUXkIxsp20R/e+ ReSJj3eOWxwnbGyy5dG1AhVn9kvmQY937CGkQ3tI7GrWf1fDP+J5AAReNuhdKP2R1KEQ7OfEPf5K1 FMNiWbB9/Aha6BRMp/3bYFsu7+hc7Wh+Cd0sPHmWZCy5f5ooZMpAUFn9JyxE9I7APWPg4X9Bpv9yZ KxtPO5yyjvg6FLVKIwvFGFNzp4Il5k+mHvkR0yGdU15W7DtGbgDbYj1u9mCBKnLsiocwVfnpc2/B3 +ZGlpDvCIEJ/zfvBg4AGQ4OFulIt0hTkboWHWf67LVfTSkNiDB5gZAxBP5h+FO6BPgciH8buVQIrw 7ANE3b0wLxiTj2YJZK6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTkHo-00C3wm-1d; Thu, 01 Sep 2022 13:31:12 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTk8D-00Byde-GA for linux-arm-kernel@lists.infradead.org; Thu, 01 Sep 2022 13:21:19 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B342A61F53 for ; Thu, 1 Sep 2022 13:21:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6861C43144 for ; Thu, 1 Sep 2022 13:21:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662038475; bh=nDXzklRc+sK26N6ixMCfRzyKwyZFZkTPPxwPBTRopmU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dHD4qRVoLYYEzjg5FYo902H7yN0QeV0ggXWmDqWmAEZtzwNAVZfajtjN0zytMYDnp LmEt9s6Fqpzox1D6ar8+KgUJZrabtlHs64u4h/h7eunxqq6+Ib+lpQ3Y4W+FVQc7mk sycikozRjjc+XX/0bT6fTuBzhOsa33SNTBfHhCv8XnSPRIQ0zelzge2Dx33ZiblJC4 TGPUvUXV+968mXG6cxLIIMfwMlNFgc9vZiHHM8986CEEVwjnp1W9t4qqXHyMq/Kd7d NU02FhWeo9/djAw9baANbguBTarHORknHLlFI50dOyiHWbp8C5+xrFiA//eY+VGnEf UA6kyjHeiCRHQ== Received: by mail-vk1-f178.google.com with SMTP id t82so6019377vkb.6 for ; Thu, 01 Sep 2022 06:21:15 -0700 (PDT) X-Gm-Message-State: ACgBeo2M+UiucuKKsqmiBe+JAZNGhLkXAgkZIcu5niytky7ftDlmVsHC Fyh/Y0nZypEUH9aa0uJb9Ee681ikF9REcfbE8w== X-Google-Smtp-Source: AA6agR7LIB/XF3yfBOGSCexMSd6RVkp0XmXs3cv36zfG9f1NFCoHtgShUSmbVhcb88Y3IJlGjbu2TIRcdfY9CAr3MpE= X-Received: by 2002:a05:6122:d86:b0:37d:3fe:df43 with SMTP id bc6-20020a0561220d8600b0037d03fedf43mr8392063vkb.15.1662038474465; Thu, 01 Sep 2022 06:21:14 -0700 (PDT) MIME-Version: 1.0 References: <20220316023356.120595-1-victor@allwinnertech.com> <9a425a51-9460-6c4d-e331-5cd5873f8a43@samsung.com> <6c14e174-cdb6-c1fc-58cc-d579111d2328@allwinnertech.com> In-Reply-To: <6c14e174-cdb6-c1fc-58cc-d579111d2328@allwinnertech.com> From: Rob Herring Date: Thu, 1 Sep 2022 08:21:02 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] ARM: mmu: fix access to illegal address when using earlycon & memblock=debug To: Victor Hassan Cc: Marek Szyprowski , Russell King , Russell King , Linus Walleij , yanfei.xu@windriver.com, Ard Biesheuvel , Thomas Gleixner , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Arnd Bergmann , linux-arm-kernel , "linux-kernel@vger.kernel.org" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220901_062117_659205_B4E3D89E X-CRM114-Status: GOOD ( 38.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 1, 2022 at 7:54 AM Victor Hassan wrote: > > > > On 2022/8/31 20:37, Victor Hassan wrote: > > On 8/31/2022 7:52 PM, Marek Szyprowski wrote: > >> Hi Victor, > >> > >> On 16.03.2022 03:33, Victor Hassan wrote: > >>> earlycon uses fixmap to create a memory map, > >>> So we need to close earlycon before closing fixmap, > >>> otherwise printk will access illegal addresses. How? Due to recent changes in how printk and the consoles work or just because create_mapping() can print? In the latter case, the only variable input is the phys address. I think most if not all prints cannot occur. > >>> After creating a new memory map, we open earlycon again. > >>> > >>> Signed-off-by: Victor Hassan > >> > >> This patch landed in linux next-20220831 as commit a76886d117cb ("ARM: > >> 9223/1: mmu: fix access to illegal address when using earlycon & > >> memblock=debug"). Unfortunately it breaks booting of all my test boards > >> which *do not* use earlycon. It can be easily reproduced even with QEMU. > >> > >> With kernel compiled from multi_v7_defconfig the following setup boots: > >> > >> $ qemu-system-arm -nographic -kernel arch/arm/boot/zImage -append > >> "console=ttyAMA0 earlycon" -M virt -smp 2 -m 512 > >> > >> while this one doesn't: > >> > >> $ qemu-system-arm -nographic -kernel arch/arm/boot/zImage -append > >> "console=ttyAMA0" -M virt -smp 2 -m 512 > >> > >> > >>> --- > >>> arch/arm/mm/mmu.c | 7 +++++++ > >>> 1 file changed, 7 insertions(+) > >>> > >>> diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c > >>> index 274e4f73fd33..f3511f07a7d0 100644 > >>> --- a/arch/arm/mm/mmu.c > >>> +++ b/arch/arm/mm/mmu.c > >>> @@ -14,6 +14,7 @@ > >>> #include > >>> #include > >>> #include > >>> +#include > >>> #include > >>> #include > >>> @@ -1695,6 +1696,9 @@ static void __init early_fixmap_shutdown(void) > >>> pmd_clear(fixmap_pmd(va)); > >>> local_flush_tlb_kernel_page(va); > >>> +#ifdef CONFIG_FIX_EARLYCON_MEM > >>> + console_stop(console_drivers); > >>> +#endif > >>> for (i = 0; i < __end_of_permanent_fixed_addresses; i++) { > >>> pte_t *pte; > >>> struct map_desc map; > >>> @@ -1713,6 +1717,9 @@ static void __init early_fixmap_shutdown(void) > >>> create_mapping(&map); > >>> } > >>> +#ifdef CONFIG_FIX_EARLYCON_MEM > >>> + console_start(console_drivers); > >>> +#endif > >>> } > >>> /* > >> > >> Best regards > > > > Dear Marek, > > Thank you for the notice. I'll figure it out and feed back to you as > > soon as possible. > > > > Regards, > > Victor > > Hi Marek, > > Sorry, didn't take into account that console_drivers is NULL when > earlycon is not used. > > Here is the patch-v2. Please review: > > diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c > index a49f0b9..a240f38 100644 > --- a/arch/arm/mm/mmu.c > +++ b/arch/arm/mm/mmu.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -1730,6 +1731,10 @@ > pmd_clear(fixmap_pmd(va)); > local_flush_tlb_kernel_page(va); > > +#ifdef CONFIG_FIX_EARLYCON_MEM This is always true for CONFIG_MMU and this file is only built for CONFIG_MMU. So you don't need it. > + if (console_drivers) > + console_stop(console_drivers); console_drivers is a list, so you are only stopping the 1st one. Couldn't console_lock() be used here? Also, this should be before pmd_clear(). > +#endif > for (i = 0; i < __end_of_permanent_fixed_addresses; i++) { > pte_t *pte; > struct map_desc map; > @@ -1748,6 +1753,10 @@ > > create_mapping(&map); > } > +#ifdef CONFIG_FIX_EARLYCON_MEM > + if (console_drivers) > + console_start(console_drivers); > +#endif > } > > BTW, should I resend the patch-v2 through the site > (https://www.armlinux.org.uk/developer/patches/add.php), or should I > send the patch-v2 through E-mail to Linux-Mainline? > > Thanks you. > > Regards, > Victor > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel