Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2504897rwb; Mon, 7 Nov 2022 14:13:25 -0800 (PST) X-Google-Smtp-Source: AMsMyM5qHmduEGWXPMq+9PONAO3PrBs/NRJ1GkX71pyH6El61H2T68qkCyjJoZsYJSSGdQYITk8O X-Received: by 2002:a05:6402:3596:b0:462:6b69:873a with SMTP id y22-20020a056402359600b004626b69873amr52984264edc.374.1667859205373; Mon, 07 Nov 2022 14:13:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667859205; cv=none; d=google.com; s=arc-20160816; b=KUJh2fYAS0iRHaNgqzRiSBdlsbJrQqVJsPt3VXEoq2AV+4zCSr1/+agmBXqpHOb06k ju5u0aqrCcxEtEIGcx60RxqvbC31XLltYFhjwLwp7Bu2i1ovAhlnwznasaZ9OBQ9MMRT 2g/E+4hAgAlI/3PaV4fv0P13SP0akjL2wgMcKkQZbWv5q7dTDt8/+7Qi+CfSEgV+iXeE 5DJr+i3sFaBmokzxWkwR+SjS4KtT5TiDtpuqDknKnP9HiAXSUGacwx8d5T8g1QuS3sPF z5l3dhHbMXD0s8Y00UZj6CqhAwIr2jAyZrEZOBVMps5wltSyqVo27fmLGYo+I98Q/55o 3wPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=l0T5u66tn52ZH6FokXOgiBsxLA25RdjqpseCJ76TDtc=; b=LhBh6tz+qijwoXPDtPGZYHBgX9MizAyf9FtxRhC5qJHMZLkGMXQ9xi/767QDzK2khd 3onZrZVlhvlJHBO0LJyNCdgNIwKL6rFKSX+R3cVzd9/E0k54pJG75YxuGNUJBhbOrt6N 8wJRmsdUG2I0s09qPz82uLBa1xPp/zBTEN6OKWBzyOaWjpGqAof59alq2QVjV/gG22YA 76KBG0VZRPjseXbL83Fs6gJRPp5ACxfaxC3MQKUZhyahnm8SGPB0BImMAJZo94Gc9JYA 6fNkgbaWow9Y2a6uxjY34BcS5qzwv+3Vvam/dYMoD5g7oRev7p0oCPCsCwfgOHOJX+0o VDqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yadro.com header.s=mta-01 header.b="SnrTOZE/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yadro.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go35-20020a1709070da300b0078d44c5da0esi11010004ejc.667.2022.11.07.14.13.03; Mon, 07 Nov 2022 14:13:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yadro.com header.s=mta-01 header.b="SnrTOZE/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yadro.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbiKGVka (ORCPT + 92 others); Mon, 7 Nov 2022 16:40:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232308AbiKGVk2 (ORCPT ); Mon, 7 Nov 2022 16:40:28 -0500 Received: from mta-01.yadro.com (mta-02.yadro.com [89.207.88.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B1A327CFD for ; Mon, 7 Nov 2022 13:40:26 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 21C5A41200; Mon, 7 Nov 2022 21:40:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:references:content-language:subject:subject :user-agent:mime-version:date:date:message-id:received:received :received:received; s=mta-01; t=1667857222; x=1669671623; bh=esC ycxrxvZxM5Pm8Ikehw6aoj6hzkD7c5GQWfXbXSNI=; b=SnrTOZE/hAkiqhNhe/8 zC5CBOXk+n5d9doal91SEURgpbzKMZ4f7GzTT1rcOPDqSg2CmhPfN9VWNOKeaw1E qRxvKsA57Ze0ThAJH+KuH/8VltvA4I73AOTYr++3oMJU1chjoar5uhUoR9dSfA4k n96iTB9CnNh4dHcG8n4CNLAo= X-Virus-Scanned: amavisd-new at yadro.com Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n8uoBLs-ZLt2; Tue, 8 Nov 2022 00:40:22 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (T-EXCH-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id 4B5A2411FB; Tue, 8 Nov 2022 00:40:20 +0300 (MSK) Received: from T-EXCH-08.corp.yadro.com (172.17.11.58) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Tue, 8 Nov 2022 00:40:21 +0300 Received: from [10.199.21.212] (10.199.21.212) by T-EXCH-08.corp.yadro.com (172.17.11.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.9; Tue, 8 Nov 2022 00:40:20 +0300 Message-ID: <497c057d-4e7d-0dcb-fd4c-2c7ef6efb573@yadro.com> Date: Tue, 8 Nov 2022 00:40:19 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v1] riscv: fix reserved memory setup Content-Language: en-US To: Conor Dooley , Palmer Dabbelt CC: Paul Walmsley , Albert Ou , Daire McNamara , "Anup Patel" , Atish Patra , "Nick Kossifidis" , , , Valentina Fernandez References: <20221107151524.3941467-1-conor.dooley@microchip.com> From: Evgenii Shatokhin In-Reply-To: <20221107151524.3941467-1-conor.dooley@microchip.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.199.21.212] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-08.corp.yadro.com (172.17.11.58) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 07.11.2022 18:15, Conor Dooley wrote: > «Внимание! Данное письмо от внешнего адресата!» > > Currently, RISC-V sets up reserved memory using the "early" copy of the > device tree. As a result, when trying to get a reserved memory region > using of_reserved_mem_lookup(), the pointer to reserved memory regions > is using the early, pre-virtual-memory address which causes a kernel > panic when trying to use the buffer's name: > > Unable to handle kernel paging request at virtual address 00000000401c31ac > Oops [#1] > Modules linked in: > CPU: 0 PID: 0 Comm: swapper Not tainted 6.0.0-rc1-00001-g0d9d6953d834 #1 > Hardware name: Microchip PolarFire-SoC Icicle Kit (DT) > epc : string+0x4a/0xea > ra : vsnprintf+0x1e4/0x336 > epc : ffffffff80335ea0 ra : ffffffff80338936 sp : ffffffff81203be0 > gp : ffffffff812e0a98 tp : ffffffff8120de40 t0 : 0000000000000000 > t1 : ffffffff81203e28 t2 : 7265736572203a46 s0 : ffffffff81203c20 > s1 : ffffffff81203e28 a0 : ffffffff81203d22 a1 : 0000000000000000 > a2 : ffffffff81203d08 a3 : 0000000081203d21 a4 : ffffffffffffffff > a5 : 00000000401c31ac a6 : ffff0a00ffffff04 a7 : ffffffffffffffff > s2 : ffffffff81203d08 s3 : ffffffff81203d00 s4 : 0000000000000008 > s5 : ffffffff000000ff s6 : 0000000000ffffff s7 : 00000000ffffff00 > s8 : ffffffff80d9821a s9 : ffffffff81203d22 s10: 0000000000000002 > s11: ffffffff80d9821c t3 : ffffffff812f3617 t4 : ffffffff812f3617 > t5 : ffffffff812f3618 t6 : ffffffff81203d08 > status: 0000000200000100 badaddr: 00000000401c31ac cause: 000000000000000d > [] vsnprintf+0x1e4/0x336 > [] vprintk_store+0xf6/0x344 > [] vprintk_emit+0x56/0x192 > [] vprintk_default+0x16/0x1e > [] vprintk+0x72/0x80 > [] _printk+0x36/0x50 > [] print_reserved_mem+0x1c/0x24 > [] paging_init+0x528/0x5bc > [] setup_arch+0xd0/0x592 > [] start_kernel+0x82/0x73c > > early_init_fdt_scan_reserved_mem() takes no arguments as it operates on > initial_boot_params, which is populated by early_init_dt_verify(). On > RISC-V, early_init_dt_verify() is called twice. Once, directly, in > setup_arch() if CONFIG_BUILTIN_DTB is not enabled and once indirectly, > very early in the boot process, by parse_dtb() when it calls > early_init_dt_scan_nodes(). > > This first call uses dtb_early_va to set initial_boot_params, which is > not usable later in the boot process when > early_init_fdt_scan_reserved_mem() is called. On arm64 for example, the > corresponding call to early_init_dt_scan_nodes() uses fixmap addresses > and doesn't suffer the same fate. Thank you for looking into this! As I wrote earlier, I ran into this issue too, while working on a remoteproc driver for our RISC-V-based SoC. The proposed patch fixes the bug for me and seems to have no problematic side-effects. So: Tested-by: Evgenii Shatokhin > > Move early_init_fdt_scan_reserved_mem() further along the boot sequence, > after the direct call to early_init_dt_verify() in setup_arch() so that > the names use the correct virtual memory addresses. The above supposed > that CONFIG_BUILTIN_DTB was not set, but should work equally in the case > where it is - unflatted_and_copy_device_tree() also updates > initial_boot_params. > > Reported-by: Valentina Fernandez > Reported-by: Evgenii Shatokhin > Link: https://lore.kernel.org/linux-riscv/f8e67f82-103d-156c-deb0-d6d6e2756f5e@microchip.com/ > Fixes: 922b0375fc93 ("riscv: Fix memblock reservation for device tree blob") > Signed-off-by: Conor Dooley > --- > arch/riscv/kernel/setup.c | 1 + > arch/riscv/mm/init.c | 1 - > 2 files changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c > index ad76bb59b059..67ec1fadcfe2 100644 > --- a/arch/riscv/kernel/setup.c > +++ b/arch/riscv/kernel/setup.c > @@ -283,6 +283,7 @@ void __init setup_arch(char **cmdline_p) > else > pr_err("No DTB found in kernel mappings\n"); > #endif > + early_init_fdt_scan_reserved_mem(); > misc_mem_init(); > > init_resources(); > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index b56a0a75533f..50a1b6edd491 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -262,7 +262,6 @@ static void __init setup_bootmem(void) > memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va)); > } > > - early_init_fdt_scan_reserved_mem(); > dma_contiguous_reserve(dma32_phys_limit); > if (IS_ENABLED(CONFIG_64BIT)) > hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); > -- > 2.38.0 >