From patchwork Mon Mar 20 20:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Jiahao X-Patchwork-Id: 72139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1196058wrt; Mon, 20 Mar 2023 05:50:42 -0700 (PDT) X-Google-Smtp-Source: AK7set8j1tSWxFU16opdk52vpflqO8JtvAo5FsSUIAOSuaP9fFQiYwgyZOmWCWSod3aqRw6cPgJ6 X-Received: by 2002:a05:6a20:7f8c:b0:d0:e4b:29b3 with SMTP id d12-20020a056a207f8c00b000d00e4b29b3mr20303007pzj.27.1679316641864; Mon, 20 Mar 2023 05:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679316641; cv=none; d=google.com; s=arc-20160816; b=b7EZ174aTZo/iwxGigCjOJW4MuMA4z+xkmE5w2jgX9O6QWkqSatkV5Fr6vGtnxHw6K JMNCsMCW0BR8HGfXJQ1F2F9wqMimNzM87B/XwkiWe/+6+RnHuxbzGXoMrVkKvYF9imlG agouHhA6M11NahyzCtI/zoGZBtFppJt0wI9S7yoevPPfJBGacXGUtPIKy/75HzxyxgFH SOUeJxekf/SZYhXd7fnbnGoDLsHD0DvW7wrWrFl76Sq8MZy/pyPQU8YJv1ypUbYlfOoi sikWjo+uZGsMgeObaPOxSrRQtxNAvwtPgr6dc2jR1Nc64+nnbHgvzbzXyhbrmTvSG5Gt ck0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=GLVG8gegDKjYaFZi6ZZvdixy3sQnTI+iHAcVui14gQw=; b=reTLy28qNRVXpPbi6S2MCM9ucfmko8TW0GEq8P8UpIwBE09hr9PSaBl1bU5Bw3Ym1+ hNN3kUPOdv1mC6MK1a7HnIePoALs7TR0kgusJ0mr8T+i1IKqSpHwFYXvo0p9cY8xRELh ou3QRRI7mr/7a2odpF2/cpl793zNsUbH+P6dm6tfF+fexWtNT7czbQgASDAfCC352KhL 5imnVCAKTODW6MXYOXQ/D6ZvjFndU7LUvORHD6Gikk522hvnGYyKq5cZ0NhqsLviQkLu /VVva300SvWZF765Kj86Ey09iDl1CXT8dkCHysGKjnVojy+83RpOIAuwM7r/pS18wJJo NrjQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 34-20020a630d62000000b00509461bbf1csi10634196pgn.79.2023.03.20.05.50.27; Mon, 20 Mar 2023 05:50:41 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231473AbjCTMqa (ORCPT + 99 others); Mon, 20 Mar 2023 08:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbjCTMqZ (ORCPT ); Mon, 20 Mar 2023 08:46:25 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66D8F2134; Mon, 20 Mar 2023 05:46:02 -0700 (PDT) Received: from dggpemm500016.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PgDss1SYdz17MgS; Mon, 20 Mar 2023 20:42:57 +0800 (CST) Received: from huawei.com (10.67.174.205) by dggpemm500016.china.huawei.com (7.185.36.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 20:46:00 +0800 From: Chen Jiahao To: , , , , , , , , , , CC: , , , Subject: [PATCH -next 1/2] riscv: kdump: Implement crashkernel=X,[high,low] Date: Tue, 21 Mar 2023 04:42:43 +0800 Message-ID: <20230320204244.1637821-2-chenjiahao16@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230320204244.1637821-1-chenjiahao16@huawei.com> References: <20230320204244.1637821-1-chenjiahao16@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.205] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500016.china.huawei.com (7.185.36.25) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760891127191997751?= X-GMAIL-MSGID: =?utf-8?q?1760891127191997751?= On riscv, the current crash kernel allocation logic is trying to allocate within 32bit addressible memory region by default, if failed, try to allocate without 4G restriction. In need of saving DMA zone memory while allocating a relatively large crash kernel region, allocating the reserved memory top down in high memory, without overlapping the DMA zone, is a mature solution. Here introduce the parameter option crashkernel=X,[high,low]. We can reserve the crash kernel from high memory above DMA zone range by explicitly passing "crashkernel=X,high"; or reserve a memory range below 4G with "crashkernel=X,low". Signed-off-by: Chen Jiahao Reviewed-by: Simon Horman --- arch/riscv/kernel/setup.c | 5 ++++ arch/riscv/mm/init.c | 56 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 376d2827e736..d867b1535da4 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -176,6 +176,11 @@ static void __init init_resources(void) if (ret < 0) goto error; } + if (crashk_low_res.start != crashk_low_res.end) { + ret = add_resource(&iomem_resource, &crashk_low_res); + if (ret < 0) + goto error; + } #endif #ifdef CONFIG_CRASH_DUMP diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 478d6763a01a..5def2174b243 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1152,6 +1152,28 @@ static inline void setup_vm_final(void) } #endif /* CONFIG_MMU */ +/* Reserve 128M low memory by default for swiotlb buffer */ +#define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) + +static int __init reserve_crashkernel_low(unsigned long long low_size) +{ + unsigned long long low_base; + + low_base = memblock_phys_alloc_range(low_size, PMD_SIZE, 0, dma32_phys_limit); + if (!low_base) { + pr_err("cannot allocate crashkernel low memory (size:0x%llx).\n", low_size); + return -ENOMEM; + } + + pr_info("crashkernel low memory reserved: 0x%08llx - 0x%08llx (%lld MB)\n", + low_base, low_base + low_size, low_size >> 20); + + crashk_low_res.start = low_base; + crashk_low_res.end = low_base + low_size - 1; + + return 0; +} + /* * reserve_crashkernel() - reserves memory for crash kernel * @@ -1163,6 +1185,7 @@ static void __init reserve_crashkernel(void) { unsigned long long crash_base = 0; unsigned long long crash_size = 0; + unsigned long long crash_low_size = 0; unsigned long search_start = memblock_start_of_DRAM(); unsigned long search_end = memblock_end_of_DRAM(); @@ -1182,8 +1205,26 @@ static void __init reserve_crashkernel(void) ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); - if (ret || !crash_size) + if (ret == -ENOENT) { + ret = parse_crashkernel_high(boot_command_line, 0, &crash_size, &crash_base); + if (ret || !crash_size) + return; + + /* + * crashkernel=Y,low can be specified or not, but invalid value + * is not allowed. + */ + ret = parse_crashkernel_low(boot_command_line, 0, &crash_low_size, &crash_base); + if (ret == -ENOENT) + crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; + else if (ret) + return; + + search_start = dma32_phys_limit; + } else if (ret || !crash_size) { + /* Invalid argument value specified */ return; + } crash_size = PAGE_ALIGN(crash_size); @@ -1201,16 +1242,25 @@ static void __init reserve_crashkernel(void) */ crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE, search_start, - min(search_end, (unsigned long) SZ_4G)); + min(search_end, (unsigned long) dma32_phys_limit)); if (crash_base == 0) { /* Try again without restricting region to 32bit addressible memory */ crash_base = memblock_phys_alloc_range(crash_size, PMD_SIZE, - search_start, search_end); + search_start, search_end); if (crash_base == 0) { pr_warn("crashkernel: couldn't allocate %lldKB\n", crash_size >> 10); return; } + + if (!crash_low_size) + crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE; + } + + if ((crash_base > dma32_phys_limit - crash_low_size) && + crash_low_size && reserve_crashkernel_low(crash_low_size)) { + memblock_phys_free(crash_base, crash_size); + return; } pr_info("crashkernel: reserved 0x%016llx - 0x%016llx (%lld MB)\n", From patchwork Mon Mar 20 20:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Jiahao X-Patchwork-Id: 72143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1200892wrt; Mon, 20 Mar 2023 06:01:14 -0700 (PDT) X-Google-Smtp-Source: AK7set/1gmPm3PFrSTpWy9gas53oD+3BsatfOvpXGopnw7UQgjZyfqzzudUSsTAHtEqq+uemjP5Y X-Received: by 2002:a17:90a:195a:b0:23f:2d2c:abcc with SMTP id 26-20020a17090a195a00b0023f2d2cabccmr17138344pjh.9.1679317274571; Mon, 20 Mar 2023 06:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679317274; cv=none; d=google.com; s=arc-20160816; b=TC8UYcJO1887nboyRmGbfYOK3rXtwIWWVfUViVMa3F2pDp5Foi8cba+gFyQHtvO6c0 AeG31mvy8E13rFvxmtMOlsGjDTCkjfieQp2SGgQjjThfn76caHcpy72JQ9CD7mw/TPdR G5G57yR387kftf6jSNuFIkvatXEAeljYNTYUx/D7EA6p4YWFoJPIXHWtPn6T5NGB1bxd LPjTZDVGrs0+fxTieg1JStswrmPe0YcOBsLYv3okWS9sRWimxc6h0WeTzPRVAjDivZCL XVd1e9vVItR32rysazTqmJASYmPMNBlq9Z3oFuyAf+TLxuRyHWSnrQQa7NOwLRY56mtq I8eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cNx/5/6/s7VKRwf2cOZ1ArscVjs2Q8sZEiR3EttKWPk=; b=VClCTMlykOm95nRF9w4OA2VonRH/mF7En6S3l7Gyb9hFc4P7IUPlG/xkQnYMsVfQPG ds3iLnoIr66ijzDBN5ewEH58xxWLaVC4saVP7BDVn5zfvE1qu1OygrFMrQeB4lKJj+JP UL1EGKoaixBrqRmUHjjHZ68GQmX7tViroz9bpdK7DD7l06faC9h/zhJPC85lspvgeTG4 PTCuBAu7a9sAZzcXy68vWzC1isLw+KeoeCkKzIKRJV8l3iUarSVdR5R8f4AKnJgUTwVF V7nYxIYjkoqfX91OV6+sLAbJD9RnnN4SpOINl4EAXiZlbuDFPkZ5bzoq3vxKnljFXPch N7Gw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v20-20020a17090a899400b0023ef9514233si10085219pjn.116.2023.03.20.06.00.44; Mon, 20 Mar 2023 06:01:14 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231459AbjCTMqd (ORCPT + 99 others); Mon, 20 Mar 2023 08:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231436AbjCTMq0 (ORCPT ); Mon, 20 Mar 2023 08:46:26 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69CF812CCA; Mon, 20 Mar 2023 05:46:03 -0700 (PDT) Received: from dggpemm500016.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PgDsV5NqxzSkMC; Mon, 20 Mar 2023 20:42:38 +0800 (CST) Received: from huawei.com (10.67.174.205) by dggpemm500016.china.huawei.com (7.185.36.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 20:46:01 +0800 From: Chen Jiahao To: , , , , , , , , , , CC: , , , Subject: [PATCH -next 2/2] docs: kdump: Update the crashkernel description for riscv Date: Tue, 21 Mar 2023 04:42:44 +0800 Message-ID: <20230320204244.1637821-3-chenjiahao16@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230320204244.1637821-1-chenjiahao16@huawei.com> References: <20230320204244.1637821-1-chenjiahao16@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.205] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500016.china.huawei.com (7.185.36.25) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_MED,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760891790421925267?= X-GMAIL-MSGID: =?utf-8?q?1760891790421925267?= Now "crashkernel=" parameter on riscv has been updated to support crashkernel=X,[high,low]. Through which we can reserve memory region above/within 32bit addressible DMA zone. Here update the parameter description accordingly. Signed-off-by: Chen Jiahao Reviewed-by: Simon Horman Reviewed-by: Zhen Lei --- Documentation/admin-guide/kernel-parameters.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 6221a1d057dd..89e26a4864f8 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -843,7 +843,7 @@ memory region [offset, offset + size] for that kernel image. If '@offset' is omitted, then a suitable offset is selected automatically. - [KNL, X86-64, ARM64] Select a region under 4G first, and + [KNL, X86-64, ARM64, RISCV] Select a region under 4G first, and fall back to reserve region above 4G when '@offset' hasn't been specified. See Documentation/admin-guide/kdump/kdump.rst for further details. @@ -856,14 +856,14 @@ Documentation/admin-guide/kdump/kdump.rst for an example. crashkernel=size[KMG],high - [KNL, X86-64, ARM64] range could be above 4G. Allow kernel - to allocate physical memory region from top, so could - be above 4G if system have more than 4G ram installed. - Otherwise memory region will be allocated below 4G, if - available. + [KNL, X86-64, ARM64, RISCV] range could be above 4G. + Allow kernel to allocate physical memory region from top, + so could be above 4G if system have more than 4G ram + installed. Otherwise memory region will be allocated + below 4G, if available. It will be ignored if crashkernel=X is specified. crashkernel=size[KMG],low - [KNL, X86-64, ARM64] range under 4G. When crashkernel=X,high + [KNL, X86-64, ARM64, RISCV] range under 4G. When crashkernel=X,high is passed, kernel could allocate physical memory region above 4G, that cause second kernel crash on system that require some amount of low memory, e.g. swiotlb @@ -874,6 +874,7 @@ size is platform dependent. --> x86: max(swiotlb_size_or_default() + 8MiB, 256MiB) --> arm64: 128MiB + --> riscv: 128MiB This one lets the user specify own low range under 4G for second kernel instead. 0: to disable low allocation.