Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1411674rdh; Fri, 24 Nov 2023 11:58:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtRXVXJc8wVmJH/wp4pXJ3LGkSv0tKrd3qvQYDo9GOROzP0oALlMo2t7kh2lgKuUZLvjlE X-Received: by 2002:a17:90b:1b03:b0:285:9d5b:eed7 with SMTP id nu3-20020a17090b1b0300b002859d5beed7mr1323775pjb.10.1700855904208; Fri, 24 Nov 2023 11:58:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700855904; cv=none; d=google.com; s=arc-20160816; b=EB9kogfsxJAY5kpiduutJWNV4OqWcMalJ8xTxslxk/H+Bu1cXIw8sMx5V+VtFWblPR qvzqqumx40qfHwJb/d52MhDZmFOYU2CxTSTgWg4ql3g/3ZkuAmHPuu6cQ4Xjq9gH3b3c EgitZP4ya79qElxxZEeuwZeotFAESRs55Tklh7ew8G2Ydc2EKmxjZWJdPE05puaGAtFm e06iV49dlNNlBfW9VxhFWE5FKtfE0SYTA/JW5z5gk3y7o+DSv5EgrPUcd45ZDL8zDJ3O BfNrog+CbrEA8/00B0zi7F8car2f7cYaQbdfbB6f9UcZhMwbTC/3ip5zkJKA4HWoqfTU PzbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature:dkim-signature; bh=rL7u06+WD+aE2+8equGsGoE7y/tVOqmNf5x3nllorEI=; fh=N9iTC4ETbLLv8Qag9but96wYdeum3ovJpDOsbUrbTQg=; b=UNiIqQeU93D7094ub8/SbCwArtma22bi7/DE+jQs/u8vRu7uj+go58mgcjvdZZZh0g 1XcOvqrxdVJT/2UTZP7jVas6JBPhNgx4MJ7Fkqd3piUKjuOSRmrYlOXcwqn/4oBVuLh6 hel9mMPmyw8A43stvaa6vHCbwIdUOIJrR0ImvQPU9y8D1F9/Cg7C1odIAlL/rZvLxUs7 ihvYWS07E8T27XL9os3MPcaGP+djQnERomUSg37PEpmNPa6wwJbv3cXy7/BbedxFT90H OOEQrhBJCt5YPpTX4viHOCfBTQv265TTdWeRbZH0O0gIZ931SO4Ni3LR9MEyzFxrv3F2 TGHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=KjB4L2sX; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Cw40MhUy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id d9-20020a170902cec900b001ca35cb0dbfsi4052642plg.613.2023.11.24.11.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 11:58:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=KjB4L2sX; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=Cw40MhUy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6DD3A81FD9D7; Fri, 24 Nov 2023 11:58:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbjKXT6A (ORCPT + 99 others); Fri, 24 Nov 2023 14:58:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231847AbjKXT55 (ORCPT ); Fri, 24 Nov 2023 14:57:57 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF8E1987 for ; Fri, 24 Nov 2023 11:58:04 -0800 (PST) Received: from relay2.suse.de (unknown [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id CF9B21FE90; Fri, 24 Nov 2023 19:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1700855882; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=rL7u06+WD+aE2+8equGsGoE7y/tVOqmNf5x3nllorEI=; b=KjB4L2sXfNur0f/FabkZEkw3kNGcXvWSv11EpyAEscgbnt7t+V11Up9d4mybmigCfOdWmZ jzcbAdjYNx62MzhKVTCJo/ms7tY0yuWDSJcCC4wPEbZEJ3D2+o8UqSNWyZvzEghXELnb20 cl4eUyNKIuxgFdHPU0spXJtUiaGD128= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1700855882; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=rL7u06+WD+aE2+8equGsGoE7y/tVOqmNf5x3nllorEI=; b=Cw40MhUyvssBlKCwj8rHAwDqF5hVptjseRaftR9uOGzG+83CzXWkyqoVKylaTxMxO0BzjZ vSPKUofr9NpUDxCQ== Received: from localhost (dwarf.suse.cz [10.100.12.32]) by relay2.suse.de (Postfix) with ESMTP id 103522C145; Fri, 24 Nov 2023 19:58:01 +0000 (UTC) Date: Fri, 24 Nov 2023 20:58:00 +0100 From: Jiri Bohac To: Baoquan He , Vivek Goyal , Dave Young , kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, mhocko@suse.cz Subject: [PATCH 2/4] kdump: implement reserve_crashkernel_cma Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spamd-Bar: +++++++++++++ X-Spam-Score: 13.49 X-Rspamd-Server: rspamd1 X-Rspamd-Queue-Id: CF9B21FE90 Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=none; spf=pass (smtp-out2.suse.de: domain of jbohac@suse.cz designates 149.44.160.134 as permitted sender) smtp.mailfrom=jbohac@suse.cz X-Spamd-Result: default: False [13.49 / 50.00]; RDNS_NONE(1.00)[]; SPAMHAUS_XBL(0.00)[149.44.160.134:from]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:149.44.0.0/16:c]; RWL_MAILSPIKE_GOOD(-1.00)[149.44.160.134:from]; HFILTER_HELO_IP_A(1.00)[relay2.suse.de]; HFILTER_HELO_NORES_A_OR_MX(0.30)[relay2.suse.de]; RCPT_COUNT_FIVE(0.00)[6]; MID_RHS_MATCH_FROMTLD(0.00)[]; MX_GOOD(-0.01)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RDNS_DNSFAIL(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(1.20)[suse.cz]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_SPAM_LONG(3.50)[1.000]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; HFILTER_HOSTNAME_UNKNOWN(2.50)[] X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 24 Nov 2023 11:58:21 -0800 (PST) reserve_crashkernel_cma() reserves CMA ranges for the crash kernel. If allocating the requested size fails, try to reserve in smaller pieces. Store the reserved ranges in the crashk_cma_ranges array and the number of ranges in crashk_cma_cnt. Signed-off-by: Jiri Bohac --- include/linux/crash_core.h | 9 +++++++ kernel/crash_core.c | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index f1edefcf7377..5afe3866d35a 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -14,6 +14,13 @@ extern struct resource crashk_res; extern struct resource crashk_low_res; +extern struct range crashk_cma_ranges[]; +#ifdef CONFIG_CMA +extern int crashk_cma_cnt; +#else +#define crashk_cma_cnt 0 +#endif + #define CRASH_CORE_NOTE_NAME "CORE" #define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4) #define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4) @@ -98,6 +105,8 @@ int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, unsigned long long *low_size, unsigned long long *cma_size, bool *high); +void __init reserve_crashkernel_cma(unsigned long long cma_size); + #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION #ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 1e952d2e451b..d71ecd59f16b 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -475,6 +476,57 @@ void __init reserve_crashkernel_generic(char *cmdline, } #endif +#ifdef CONFIG_CMA +#define CRASHKERNEL_CMA_RANGES_MAX 4 + +struct range crashk_cma_ranges[CRASHKERNEL_CMA_RANGES_MAX]; +int crashk_cma_cnt = 0; + +void __init reserve_crashkernel_cma(unsigned long long cma_size) +{ + unsigned long long request_size = roundup(cma_size, PAGE_SIZE); + unsigned long long reserved_size = 0; + + while (cma_size > reserved_size && + crashk_cma_cnt < CRASHKERNEL_CMA_RANGES_MAX) { + + struct cma *res; + + if (cma_declare_contiguous(0, request_size, 0, 0, 0, false, + "crashkernel", &res)) { + /* reservation failed, try half-sized blocks */ + if (request_size <= PAGE_SIZE) + break; + + request_size = roundup(request_size / 2, PAGE_SIZE); + continue; + } + + crashk_cma_ranges[crashk_cma_cnt].start = cma_get_base(res); + crashk_cma_ranges[crashk_cma_cnt].end = + crashk_cma_ranges[crashk_cma_cnt].start + + cma_get_size(res) - 1; + ++crashk_cma_cnt; + reserved_size += request_size; + } + + if (cma_size > reserved_size) + pr_warn("crashkernel CMA reservation failed: %lld MB requested, %lld MB reserved in %d ranges\n", + cma_size >> 20, reserved_size >> 20, crashk_cma_cnt); + else + pr_info("crashkernel CMA reserved: %lld MB in %d ranges\n", + reserved_size >> 20, crashk_cma_cnt); +} + +#else /* CONFIG_CMA */ +struct range crashk_cma_ranges[0]; +void __init reserve_crashkernel_cma(unsigned long long cma_size) +{ + if (cma_size) + pr_warn("crashkernel CMA reservation failed: CMA disabled\n"); +} +#endif + int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, void **addr, unsigned long *sz) { -- Jiri Bohac SUSE Labs, Prague, Czechia