From patchwork Mon Apr 15 10:57:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenzhou X-Patchwork-Id: 10900549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CF0317EF for ; Mon, 15 Apr 2019 10:47:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45245287AA for ; Mon, 15 Apr 2019 10:47:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38B52287D3; Mon, 15 Apr 2019 10:47:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77C06287AA for ; Mon, 15 Apr 2019 10:47:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 249ED6B0006; Mon, 15 Apr 2019 06:47:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 222A86B000A; Mon, 15 Apr 2019 06:47:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA7DE6B0006; Mon, 15 Apr 2019 06:47:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id C063B6B0007 for ; Mon, 15 Apr 2019 06:47:05 -0400 (EDT) Received: by mail-ot1-f70.google.com with SMTP id k28so8873252otf.3 for ; Mon, 15 Apr 2019 03:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uq4YXG/fd4i9tMfjG1TF9685MevsjIg/lcHigJ5WLOE=; b=qx8nyjI0m92sk9/dKmi8l0FiHuwwWmDIMbK8SzojMAlqkIYqUx6891Lc7plPHWSWsn qLiU3nihudl5/hw5GQWcjhdrI+js7yZzLQ9BE9GxV/Zf4jRkErxCpacGb5j37zBN5dHv i255g8OeANX42vQeawTLz/XT7HTA5n0w2FMzjA7yOh9L+lR4oDe6qCxlLT0WlbzFCWeO YByJcaFpwVAQ/ixGif1iXE06C+woId/Xasfdjtg37H0Jw5YipQHn13xlcfNQ1wUMCBHn 9kMwsqIEYMEUuxcptNDofivpRKYR4u3iwfDyyvISD3/a2vJhqJzCymw64IoaCNY7aduo h8hg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com X-Gm-Message-State: APjAAAXGDfkvH1tqJ/EdVbGOyuFmoUT6awefusGnljcnCXBXhCzP66rL qnJPY7ug9/rXY/I/a+nAHt60njDd+KPTzTtgdHw2imcVsgH1D6Eklgj0LnWDhwoiuhVZv7mbKz2 bh6uj1ESyeFrMHQDvxcz8O0n/2Tubt26MFrrXLCBVNDnl+27DNE4utGV0LImiZcxbcQ== X-Received: by 2002:a9d:dc4:: with SMTP id 62mr46672720ots.211.1555325225464; Mon, 15 Apr 2019 03:47:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLv4ZsJEveyG74N+iKqEMaW1wrWzaR6rJvEBy7dN03EkKNV+WMEwoIPPidleEhk8gZw0Nq X-Received: by 2002:a9d:dc4:: with SMTP id 62mr46672691ots.211.1555325224469; Mon, 15 Apr 2019 03:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555325224; cv=none; d=google.com; s=arc-20160816; b=Pqrot4lfbghRAbzcM+Uez3/y4za1ElakJx+FF7AUIHNYDKX+hY5B8mhoYOIsbvfTAT y9kZ7KRiuVDadzmKowjzD9H+wVYltyL0lAmRfRUYIGFPo19bPNzkiNhSJwqvH6GXj2ht S6o1hjP7Z1oVGXGct7DRBz/blQaVTCEgKU+wrFGTpEVwLtfFITyQoA3sRn91wpcC2U/q wuKvjc7Twkl1Xb6YKwTId6DeazF+XRxDg7RRHiOQokjf/DgSCEQFunfrQVxilaf3Ts0B aLxbawrNTuI1N3HvLqKyEattp+eeucIdYh0zPIOa7zMeUEL10lgHEpTOByae4Lr5k+0/ ZhIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=uq4YXG/fd4i9tMfjG1TF9685MevsjIg/lcHigJ5WLOE=; b=w4UMTYOCojtcBjj29lS6sDfBo+eFr800VnOefbMbALSDd5aLq8np2jI/12Q9wy3u7o K2lbpRCX4jWyKMyQly2ClHO1m8wm6DcjWlU4UgUQdqeVbFyPFV4m4P+KuqEV73MfEVwo OFq/kbB2etZC/TT+HnOBBXVKLTDdT8XQoeNZCWF3gK4ca+gDFpZhDkoZ+RLVZeLvcU2l NT12s7Z7etJ0Lrelm7nbq6eCHejTe9MREdTVz6YF5e4MKIzlSJLGAl3zdpyaN9hcG/JR rZP110YNNTUyYRRRGsjp36jAQVq6AZX6Wr27BMExtQyKaxcGBVKS1OHfFxAKIv7jhykv 0bRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from huawei.com (szxga06-in.huawei.com. [45.249.212.32]) by mx.google.com with ESMTPS id b13si21792871oti.57.2019.04.15.03.47.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 03:47:04 -0700 (PDT) Received-SPF: pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) client-ip=45.249.212.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 690EA8DA76D87F47CC55; Mon, 15 Apr 2019 18:46:58 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Mon, 15 Apr 2019 18:46:48 +0800 From: Chen Zhou To: , , , , , , , , CC: , , , , , , , Chen Zhou Subject: [PATCH v4 1/5] x86: kdump: move reserve_crashkernel_low() into kexec_core.c Date: Mon, 15 Apr 2019 18:57:21 +0800 Message-ID: <20190415105725.22088-2-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190415105725.22088-1-chenzhou10@huawei.com> References: <20190415105725.22088-1-chenzhou10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In preparation for supporting more than one crash kernel regions in arm64 as x86_64 does, move reserve_crashkernel_low() into kexec/kexec_core.c. Signed-off-by: Chen Zhou --- arch/x86/include/asm/kexec.h | 3 ++ arch/x86/kernel/setup.c | 66 +++++--------------------------------------- include/linux/kexec.h | 5 ++++ kernel/kexec_core.c | 56 +++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 59 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 003f2da..485a514 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -18,6 +18,9 @@ # define KEXEC_CONTROL_CODE_MAX_SIZE 2048 +/* 16M alignment for crash kernel regions */ +#define CRASH_ALIGN (16 << 20) + #ifndef __ASSEMBLY__ #include diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 3773905..4182035 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -447,9 +447,6 @@ static void __init memblock_x86_reserve_range_setup_data(void) #ifdef CONFIG_KEXEC_CORE -/* 16M alignment for crash kernel regions */ -#define CRASH_ALIGN (16 << 20) - /* * Keep the crash kernel below this limit. On 32 bits earlier kernels * would limit the kernel to the low 512 MiB due to mapping restrictions. @@ -463,59 +460,6 @@ static void __init memblock_x86_reserve_range_setup_data(void) # define CRASH_ADDR_HIGH_MAX MAXMEM #endif -static int __init reserve_crashkernel_low(void) -{ -#ifdef CONFIG_X86_64 - unsigned long long base, low_base = 0, low_size = 0; - unsigned long total_low_mem; - int ret; - - total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); - - /* crashkernel=Y,low */ - ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); - if (ret) { - /* - * two parts from lib/swiotlb.c: - * -swiotlb size: user-specified with swiotlb= or default. - * - * -swiotlb overflow buffer: now hardcoded to 32k. We round it - * to 8M for other buffers that may need to stay low too. Also - * make sure we allocate enough extra low memory so that we - * don't run out of DMA buffers for 32-bit devices. - */ - low_size = max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20); - } else { - /* passed with crashkernel=0,low ? */ - if (!low_size) - return 0; - } - - low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); - if (!low_base) { - pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", - (unsigned long)(low_size >> 20)); - return -ENOMEM; - } - - ret = memblock_reserve(low_base, low_size); - if (ret) { - pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); - return ret; - } - - pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", - (unsigned long)(low_size >> 20), - (unsigned long)(low_base >> 20), - (unsigned long)(total_low_mem >> 20)); - - crashk_low_res.start = low_base; - crashk_low_res.end = low_base + low_size - 1; - insert_resource(&iomem_resource, &crashk_low_res); -#endif - return 0; -} - static void __init reserve_crashkernel(void) { unsigned long long crash_size, crash_base, total_mem; @@ -573,9 +517,13 @@ static void __init reserve_crashkernel(void) return; } - if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { - memblock_free(crash_base, crash_size); - return; + if (crash_base >= (1ULL << 32)) { + if (reserve_crashkernel_low()) { + memblock_free(crash_base, crash_size); + return; + } + + insert_resource(&iomem_resource, &crashk_low_res); } pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n", diff --git a/include/linux/kexec.h b/include/linux/kexec.h index b9b1bc5..096ad63 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -63,6 +63,10 @@ #define KEXEC_CORE_NOTE_NAME CRASH_CORE_NOTE_NAME +#ifndef CRASH_ALIGN +#define CRASH_ALIGN SZ_128M +#endif + /* * This structure is used to hold the arguments that are used when loading * kernel binaries. @@ -281,6 +285,7 @@ extern void __crash_kexec(struct pt_regs *); extern void crash_kexec(struct pt_regs *); int kexec_should_crash(struct task_struct *); int kexec_crash_loaded(void); +int __init reserve_crashkernel_low(void); void crash_save_cpu(struct pt_regs *regs, int cpu); extern int kimage_crash_copy_vmcoreinfo(struct kimage *image); diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index d714044..3492abd 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -96,6 +98,60 @@ int kexec_crash_loaded(void) } EXPORT_SYMBOL_GPL(kexec_crash_loaded); +int __init reserve_crashkernel_low(void) +{ + unsigned long long base, low_base = 0, low_size = 0; + unsigned long total_low_mem; + int ret; + + total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); + + /* crashkernel=Y,low */ + ret = parse_crashkernel_low(boot_command_line, total_low_mem, + &low_size, &base); + if (ret) { + /* + * two parts from lib/swiotlb.c: + * -swiotlb size: user-specified with swiotlb= or default. + * + * -swiotlb overflow buffer: now hardcoded to 32k. We round it + * to 8M for other buffers that may need to stay low too. Also + * make sure we allocate enough extra low memory so that we + * don't run out of DMA buffers for 32-bit devices. + */ + low_size = max(swiotlb_size_or_default() + (8UL << 20), + 256UL << 20); + } else { + /* passed with crashkernel=0,low ? */ + if (!low_size) + return 0; + } + + low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); + if (!low_base) { + pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", + (unsigned long)(low_size >> 20)); + return -ENOMEM; + } + + ret = memblock_reserve(low_base, low_size); + if (ret) { + pr_err("%s: Error reserving crashkernel low memblock.\n", + __func__); + return ret; + } + + pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", + (unsigned long)(low_size >> 20), + (unsigned long)(low_base >> 20), + (unsigned long)(total_low_mem >> 20)); + + crashk_low_res.start = low_base; + crashk_low_res.end = low_base + low_size - 1; + + return 0; +} + /* * When kexec transitions to the new kernel there is a one-to-one * mapping between physical and virtual addresses. On processors From patchwork Mon Apr 15 10:57:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenzhou X-Patchwork-Id: 10900547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9F7DA1669 for ; Mon, 15 Apr 2019 10:47:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 855AD287AA for ; Mon, 15 Apr 2019 10:47:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 763C1287D3; Mon, 15 Apr 2019 10:47:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAB79287AA for ; Mon, 15 Apr 2019 10:47:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAEAF6B0007; Mon, 15 Apr 2019 06:47:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E2F326B0008; Mon, 15 Apr 2019 06:47:05 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF68C6B000A; Mon, 15 Apr 2019 06:47:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by kanga.kvack.org (Postfix) with ESMTP id A67136B0006 for ; Mon, 15 Apr 2019 06:47:05 -0400 (EDT) Received: by mail-oi1-f197.google.com with SMTP id i203so7710382oih.16 for ; Mon, 15 Apr 2019 03:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=msW/DfQw6RLXEJV1GdO6xcS+vBgdX+OmDHFBMpqAuDk=; b=RR49gJU1UQeXUY7yKkGxmEPR4zS463B5u5zu/3OAXDFuhCF+uq1xizj0Mw23Dbr/F8 ajXWxUlm8SlgUV4scZowkrQGjhzGQgQIGww+19rn2ijCuufS/tNjJBcktx/L6H4GdA+q v99I8eecQA9lEqkdsJ5yDIgoN71pmgvKYVryrGHlenVTvhWjycKifDrjz0GHSpF+smAV ml5s8l3/44zTH9zeu/VdUnR8YAJJqr5FV2Zb5c6s5nevPYAZEMxS4vHuBLWUUoImaqhg psLWE8pdT+Ks+xxx7C4I8WIFyOnJf4Pnh739hOodu9zkyD70OGV/+QdUVxkNWFFyop/w QW0w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com X-Gm-Message-State: APjAAAUtVPSALorH8qLm7Md1MO2BVEHAXyHlg1e56M62gn4DUhoEVfso vZLrKSnH2VJAS0ViKxcjCzcKtToVwrGb39/3naOMhUIvRHXGkLFF1i0HWFwoNE19EoPKNwRRx2S E1qX3NrDxRahTMj4n/a02AVfPJMqZqmElDa2Blenz1k6LI2EzJpW6PxfR4t3cKcf5ZA== X-Received: by 2002:aca:d614:: with SMTP id n20mr19178922oig.46.1555325225328; Mon, 15 Apr 2019 03:47:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1TR9dtcmRqRHI15xTf/bOnEAzpZOov58dx7UqgwtHovHINB8NXHiY4j5z++IryTmXNg6N X-Received: by 2002:aca:d614:: with SMTP id n20mr19178879oig.46.1555325224038; Mon, 15 Apr 2019 03:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555325224; cv=none; d=google.com; s=arc-20160816; b=tWLeu4ks5SUrX3sKwC2YPBvWmfpHla0Oiv86NMbsMndhkUeY5Sn3yYnw+yLWsYJsbh X/v+aV6JXo4TZwQDQODTIHf9EfrcxBD2aWQGZnilCIoSksUKFBRIDioSIP6FVYdGKeAj ftKj+dNPCxhtO7SBaO+7v808ehR5/9K6/ed238+J6VCPBvzI3pT8yKX2618g5/prkVC9 LCwTEN0SX25j63ZxIgTqcNpR4arN3LS6kxZYwB5x8VQiMJoo+NbJB6rm64xsPzneWzx5 xJPeTKXKPp897kHXxgQc4TNqSETLYlleNDTRjnNVEV61xV0lS4n5TCASDl6Bwe/Wo9t9 FF7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=msW/DfQw6RLXEJV1GdO6xcS+vBgdX+OmDHFBMpqAuDk=; b=NNSk7O+vD5Yhkp62WVrZV64wRqJSJfdLWTHPXHj+CCQMPsOLpA/IaBQRZz598sBoMT Jk6RXM/SeXYyiIHgZ3EEn7quLYWk0FvqUtRACiZv3dJLur4fR8uVTxTzFyHVd+ILNHB3 /chRPkC/55jjP3S/+2Rc9vX/lk0PGFMaQfthFOG+ivWGeHCCFZkTnZkGHYLIjUWqFieO GQsL7mLtRMJ5uUcyTEePTnt1aVFQ+CPLgX3W2MLQ9W77Fxn9Qs8FGXs0nRGH2znkHrbC mt6nY17tt8cY4A+BgWwJ9jzETyd7l5dqpQspEYgwmey5aKFa6+I1ZIXTuR3IxgVkPwJH cCpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from huawei.com (szxga06-in.huawei.com. [45.249.212.32]) by mx.google.com with ESMTPS id w6si22313972oiw.197.2019.04.15.03.47.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 03:47:04 -0700 (PDT) Received-SPF: pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) client-ip=45.249.212.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 727A8A52E617467592BB; Mon, 15 Apr 2019 18:46:58 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Mon, 15 Apr 2019 18:46:50 +0800 From: Chen Zhou To: , , , , , , , , CC: , , , , , , , Chen Zhou Subject: [PATCH v4 2/5] arm64: kdump: support reserving crashkernel above 4G Date: Mon, 15 Apr 2019 18:57:22 +0800 Message-ID: <20190415105725.22088-3-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190415105725.22088-1-chenzhou10@huawei.com> References: <20190415105725.22088-1-chenzhou10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When crashkernel is reserved above 4G in memory, kernel should reserve some amount of low memory for swiotlb and some DMA buffers. Kernel would try to allocate at least 256M below 4G automatically as x86_64 if crashkernel is above 4G. Meanwhile, support crashkernel=X,[high,low] in arm64. Signed-off-by: Chen Zhou --- arch/arm64/include/asm/kexec.h | 3 +++ arch/arm64/kernel/setup.c | 3 +++ arch/arm64/mm/init.c | 25 ++++++++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 67e4cb7..32949bf 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -28,6 +28,9 @@ #define KEXEC_ARCH KEXEC_ARCH_AARCH64 +/* 2M alignment for crash kernel regions */ +#define CRASH_ALIGN SZ_2M + #ifndef __ASSEMBLY__ /** diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 413d566..82cd9a0 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -243,6 +243,9 @@ static void __init request_standard_resources(void) request_resource(res, &kernel_data); #ifdef CONFIG_KEXEC_CORE /* Userspace will find "Crash kernel" region in /proc/iomem. */ + if (crashk_low_res.end && crashk_low_res.start >= res->start && + crashk_low_res.end <= res->end) + request_resource(res, &crashk_low_res); if (crashk_res.end && crashk_res.start >= res->start && crashk_res.end <= res->end) request_resource(res, &crashk_res); diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 972bf43..f5dde73 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -74,20 +74,30 @@ phys_addr_t arm64_dma_phys_limit __ro_after_init; static void __init reserve_crashkernel(void) { unsigned long long crash_base, crash_size; + bool high = false; int ret; ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); /* no crashkernel= or invalid value specified */ - if (ret || !crash_size) - return; + if (ret || !crash_size) { + /* crashkernel=X,high */ + ret = parse_crashkernel_high(boot_command_line, + memblock_phys_mem_size(), + &crash_size, &crash_base); + if (ret || !crash_size) + return; + high = true; + } crash_size = PAGE_ALIGN(crash_size); if (crash_base == 0) { /* Current arm64 boot protocol requires 2MB alignment */ - crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT, - crash_size, SZ_2M); + crash_base = memblock_find_in_range(0, + high ? memblock_end_of_DRAM() + : ARCH_LOW_ADDRESS_LIMIT, + crash_size, CRASH_ALIGN); if (crash_base == 0) { pr_warn("cannot allocate crashkernel (size:0x%llx)\n", crash_size); @@ -105,13 +115,18 @@ static void __init reserve_crashkernel(void) return; } - if (!IS_ALIGNED(crash_base, SZ_2M)) { + if (!IS_ALIGNED(crash_base, CRASH_ALIGN)) { pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n"); return; } } memblock_reserve(crash_base, crash_size); + if (crash_base >= SZ_4G && reserve_crashkernel_low()) { + memblock_free(crash_base, crash_size); + return; + } + pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n", crash_base, crash_base + crash_size, crash_size >> 20); From patchwork Mon Apr 15 10:57:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenzhou X-Patchwork-Id: 10900551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0A4517EF for ; Mon, 15 Apr 2019 10:47:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9E01287AA for ; Mon, 15 Apr 2019 10:47:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCE23287D3; Mon, 15 Apr 2019 10:47:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 221E2287AA for ; Mon, 15 Apr 2019 10:47:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 647716B0008; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 580C36B000A; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 494D76B000C; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id 21E856B0008 for ; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) Received: by mail-oi1-f200.google.com with SMTP id w10so7734396oie.1 for ; Mon, 15 Apr 2019 03:47:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xXTptsneB+kP0gcjLWhElHF2YJCjnVugAtGJoCyGJpk=; b=PZVfrKuOO+bzzGp1sPTvv3aPAtQ1EXX5FmHqeYQAdeIwWeLR/+wBFDmvAH3ZJd9BRy HBaK6EakDhSqsB2sONgWI/CGcZjx79ol7LB3OSYTydc9QEEYNlr4C1vpLQM4vtryANxL yTz783AOP+M4YEG9A7bm6M3sJ4YTAb7qqS7uHeAo3FMFFOyae7F987DB1rInYcsEbPN4 1+1E8n06E6Md3vBxOz2+JkY6dTQrPhGpiuXLfJY/1LcyIlMSlP4nPSEB32usi1XsDPVx tBREfkkmLNPD01QZokkdZgHIvrx5KVgtLVrqSANzZ+754fN0pLfpZSsO730URH46NLcY EUKA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com X-Gm-Message-State: APjAAAUjCd+yDakZVkEVWH2i8qO+cVpoJSSz5hs6FC6qwRHXcx6IFu8a cssy/UcHyRDwfRhFdxcIVxsoBsfMG3cvZwSL6grhF5RJSK14K1LxiIsq7HsiWSJa7lG7jaNrunu ZJh+GI/e43gsjpP2ebP7Mibk3ZJt6xzjj2lgMOi2AQ02cOnoCbJrEim1y5gIYrAPHcA== X-Received: by 2002:aca:5842:: with SMTP id m63mr19791607oib.10.1555325229802; Mon, 15 Apr 2019 03:47:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqybcYWBEcZFJbNWrGqUHxbeobWuM1IjEhz2pHhr/OGMjIXegvxvFJN4iOFL7rv5RaF2RF8J X-Received: by 2002:aca:5842:: with SMTP id m63mr19791576oib.10.1555325228949; Mon, 15 Apr 2019 03:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555325228; cv=none; d=google.com; s=arc-20160816; b=oBK5k1ct24LwdaOLvu6nzTHQt9h9lg4ujvEb5/ACeLLWDpSGuQ7OJYDBAHHylgKLex HbQW0JOp8a/sjqoezy/bTvjdTlSnwDdPsC2KUGSRJpivFR59GPeROmaEscpeMQpaZqPB g+iFr3GEiftN/dLeTDZu9utNO2CW68qEuO0ZVlbVSLUPnHonQ1GBV1CJlX2GyZOS3Agv P6WHL8Sb7u7+CSde0DDpHfBFqAOo7inWDa7nQLfbKjLHGwFxxpT7HUCuGjccN5HxJDkw dmlTYiN4lObBSb4cGheagbW0hv0hZORjCOuEuMxItwg98jirlZIo2W97oR0+A3hHBbyR bopA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=xXTptsneB+kP0gcjLWhElHF2YJCjnVugAtGJoCyGJpk=; b=kijTT6YYm1Am7xDebV4W2Jis8VEuuxw9Bm32k90G6nlH5PM0lrKDbKqQTvMhqNlQu0 8kx9Kxreez4WkvbWcQ8dqwnnaC4JnjzA59lBJ9uA8manKH1DHwzKA7ZtKizNVptA4Jx2 0mqCm/vj95e7S2UcyQcb9tOZl+U0IpY4SfuuXacMyHFfpMEq3UOIyWlExIFaaTIUF+mc WIl3h6FmT8TPKx+TawG/gnrj98xAUcEUFfwZVKUaBx2SdqQ/rspM31mzDKhTocK6JfKY vvlvD/L1drQ0AYGceLESlErbePt1jffSIhCmm8mKqzLhk7zojJS9TwE/LrqdFesGKOKV xW4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from huawei.com (szxga04-in.huawei.com. [45.249.212.190]) by mx.google.com with ESMTPS id z6si22469128oto.251.2019.04.15.03.47.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 03:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) client-ip=45.249.212.190; Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 75C8BB19C81F804D5FBC; Mon, 15 Apr 2019 18:47:03 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Mon, 15 Apr 2019 18:46:53 +0800 From: Chen Zhou To: , , , , , , , , CC: , , , , , , , Chen Zhou Subject: [PATCH v4 3/5] memblock: add memblock_cap_memory_ranges for multiple ranges Date: Mon, 15 Apr 2019 18:57:23 +0800 Message-ID: <20190415105725.22088-4-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190415105725.22088-1-chenzhou10@huawei.com> References: <20190415105725.22088-1-chenzhou10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The memblock_cap_memory_range() removes all the memory except the range passed to it. Extend this function to receive memblock_type with the regions that should be kept. Enable this function in arm64 for reservation of multiple regions for the crash kernel. Signed-off-by: Chen Zhou Signed-off-by: Mike Rapoport Signed-off-by: Mike Rapoport --- include/linux/memblock.h | 1 + mm/memblock.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 47e3c06..180877c 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -446,6 +446,7 @@ phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); +void memblock_cap_memory_ranges(struct memblock_type *regions_to_keep); void memblock_mem_limit_remove_map(phys_addr_t limit); bool memblock_is_memory(phys_addr_t addr); bool memblock_is_map_memory(phys_addr_t addr); diff --git a/mm/memblock.c b/mm/memblock.c index f315eca..9661807 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1697,6 +1697,51 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) base + size, PHYS_ADDR_MAX); } +void __init memblock_cap_memory_ranges(struct memblock_type *regions_to_keep) +{ + int start_rgn[INIT_MEMBLOCK_REGIONS], end_rgn[INIT_MEMBLOCK_REGIONS]; + int i, j, ret, nr = 0; + struct memblock_region *regs = regions_to_keep->regions; + + for (i = 0; i < regions_to_keep->cnt; i++) { + ret = memblock_isolate_range(&memblock.memory, regs[i].base, + regs[i].size, &start_rgn[i], &end_rgn[i]); + if (ret) + break; + nr++; + } + if (!nr) + return; + + /* remove all the MAP regions */ + for (i = memblock.memory.cnt - 1; i >= end_rgn[nr - 1]; i--) + if (!memblock_is_nomap(&memblock.memory.regions[i])) + memblock_remove_region(&memblock.memory, i); + + for (i = nr - 1; i > 0; i--) + for (j = start_rgn[i] - 1; j >= end_rgn[i - 1]; j--) + if (!memblock_is_nomap(&memblock.memory.regions[j])) + memblock_remove_region(&memblock.memory, j); + + for (i = start_rgn[0] - 1; i >= 0; i--) + if (!memblock_is_nomap(&memblock.memory.regions[i])) + memblock_remove_region(&memblock.memory, i); + + /* truncate the reserved regions */ + memblock_remove_range(&memblock.reserved, 0, regs[0].base); + + for (i = nr - 1; i > 0; i--) { + phys_addr_t remove_base = regs[i - 1].base + regs[i - 1].size; + phys_addr_t remove_size = regs[i].base - remove_base; + + memblock_remove_range(&memblock.reserved, remove_base, + remove_size); + } + + memblock_remove_range(&memblock.reserved, + regs[nr - 1].base + regs[nr - 1].size, PHYS_ADDR_MAX); +} + void __init memblock_mem_limit_remove_map(phys_addr_t limit) { phys_addr_t max_addr; From patchwork Mon Apr 15 10:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenzhou X-Patchwork-Id: 10900553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AA671669 for ; Mon, 15 Apr 2019 10:47:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1392C287AA for ; Mon, 15 Apr 2019 10:47:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0661E287D3; Mon, 15 Apr 2019 10:47:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6461E287AA for ; Mon, 15 Apr 2019 10:47:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E83BC6B000A; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DE0436B000C; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CABE86B000D; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id A1A446B000A for ; Mon, 15 Apr 2019 06:47:10 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id q25so8831083otf.6 for ; Mon, 15 Apr 2019 03:47:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=2HfS5mdi6OnZ8KWKOdyFVgV0F97qjf8nFM8nzbKXexw=; b=gwS2zp6RkyJQ0gcCgWxMeRgRE6KQYXonwMCKcavgo5jf+T4oQORo4iRxxpjlFEQ59o ub/slyv1xV0hM9oeLcvDFH6wxsjoSR1NiqvLCXXl4X+3CdtTc8Fl3HezxN9pSki9Xstn oLnpWaBqSee8xczDtao4kEChUUGQd87t1Qs1sa4FCETFXuaqdU9UULlt9BPF7O+UjLWN u+rgU1rSmPJ70v7a2ILUzAUTZP2k13uVfyjKXVCcZXtI95n7J4sJpQht1y8HM0PFikFq ANfEdPESnKMhpc9kDNZF2YEleESZOwSIaifcLg/U7ht/Rs0pp7uLfV3Vv0dRjgIK8yxC Gv5g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com X-Gm-Message-State: APjAAAW5nZ3PN/hT7g908SUnnhksR4U4GifQs9dJDLqn/QBj646aXA0b dLBbyVDboPr6KBGeKFR41cqBvEjRDGXt2bmvg1a9neT8SHvtrz9N4Rlx20vxSkNqcdBMa/IZy8N oQaToRS+9vHvngHk/oY4de8GDJUr4poEweAwPWboTuO1iUq3rNgxIDgfT28dP478uvA== X-Received: by 2002:a9d:6d05:: with SMTP id o5mr13951344otp.175.1555325230294; Mon, 15 Apr 2019 03:47:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTp6ZI+MrjcpruX1aZsKVlI8EwAeAUXw538rEENqNsGjiJRBrtR3Ec3/vC3/h4sA0hbMSt X-Received: by 2002:a9d:6d05:: with SMTP id o5mr13951287otp.175.1555325229011; Mon, 15 Apr 2019 03:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555325229; cv=none; d=google.com; s=arc-20160816; b=FB2QGNcw8mB8yCTPxwzZQrAtbH5g/7vJxcLvS5jPtVyDHRLccOTFgL3VKdpI1QxrHf nRVs0v00OBtfLk3zWg8aoNZ8obWDD0EFNfDAZzl7/dKbSev3YbW+2JOhIZIWDlQPp9mM /mOilFqCMnxCwcSI4G6phTROd851Rf/3A/F36HyAaO6vxfK3SyPptM1b7fUjGRl2ebKg D+87IvLTdYKyQj5rc0xjmXrI7Pxhyzbl2PAZvmIMcK9uoP2DLGPurIac+/XilUmoRLHv 4uDEVm1p5PgGRyaY0ILlIpw+GgqDWix7DZ3jT8PjqTDNDj5A3ZOYgynSFTOLcvLEiNrJ wEkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=2HfS5mdi6OnZ8KWKOdyFVgV0F97qjf8nFM8nzbKXexw=; b=1Iv/z6mrsBMLXt1rtbl6vb1uYejnuyCHv1SEUD3Vx+LQSZZhWwMCkjqP2EPKiizIVw p1G1MGmgIBT6qKbVZrpu8Fky3xZ4T4+tB5aZr2qrnzA87nFzhg7Jsv2RxPrxeRwWwUDR j/pe6axKs/1HtuwQEDCQ3Yo+Je54zs6RkVnVrwcqJxRkL3AulL2BiVC+qe/rk/hT0e6F HcN1aJ+R4t5JclFSzVmSa9vaDqqH9AfOR7CpdOoAtrpX/EGvdEcDiwlHpn0NWEkKC+dn 8YVXW8HFfXz4MxoA+igR/Mgd40tdBC3kkgmGGepc8yxgnjd3Eong5oU+634ugzEswGdy NJYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from huawei.com (szxga04-in.huawei.com. [45.249.212.190]) by mx.google.com with ESMTPS id t145si23361876oih.106.2019.04.15.03.47.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 03:47:09 -0700 (PDT) Received-SPF: pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) client-ip=45.249.212.190; Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8035E95E669BD9B289C4; Mon, 15 Apr 2019 18:47:03 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Mon, 15 Apr 2019 18:46:55 +0800 From: Chen Zhou To: , , , , , , , , CC: , , , , , , , Chen Zhou Subject: [PATCH v4 4/5] arm64: kdump: support more than one crash kernel regions Date: Mon, 15 Apr 2019 18:57:24 +0800 Message-ID: <20190415105725.22088-5-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190415105725.22088-1-chenzhou10@huawei.com> References: <20190415105725.22088-1-chenzhou10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP After commit (arm64: kdump: support reserving crashkernel above 4G), there may be two crash kernel regions, one is below 4G, the other is above 4G. Use memblock_cap_memory_ranges() to support multiple crash kernel regions. Crash dump kernel reads more than one crash kernel regions via a dtb property under node /chosen, linux,usable-memory-range = . Besides, replace memblock_cap_memory_range() with memblock_cap_memory_ranges(). Signed-off-by: Chen Zhou Signed-off-by: Mike Rapoport --- arch/arm64/mm/init.c | 34 ++++++++++++++++++++++++---------- include/linux/memblock.h | 1 - mm/memblock.c | 41 ++++++++++++----------------------------- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index f5dde73..921953d 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -52,6 +52,9 @@ #include #include +/* at most two crash kernel regions, low_region and high_region */ +#define CRASH_MAX_USABLE_RANGES 2 + /* * We need to be able to catch inadvertent references to memstart_addr * that occur (potentially in generic code) before arm64_memblock_init() @@ -295,9 +298,9 @@ early_param("mem", early_mem); static int __init early_init_dt_scan_usablemem(unsigned long node, const char *uname, int depth, void *data) { - struct memblock_region *usablemem = data; - const __be32 *reg; - int len; + struct memblock_type *usablemem = data; + const __be32 *reg, *endp; + int len, nr = 0; if (depth != 1 || strcmp(uname, "chosen") != 0) return 0; @@ -306,22 +309,33 @@ static int __init early_init_dt_scan_usablemem(unsigned long node, if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells))) return 1; - usablemem->base = dt_mem_next_cell(dt_root_addr_cells, ®); - usablemem->size = dt_mem_next_cell(dt_root_size_cells, ®); + endp = reg + (len / sizeof(__be32)); + while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { + unsigned long base = dt_mem_next_cell(dt_root_addr_cells, ®); + unsigned long size = dt_mem_next_cell(dt_root_size_cells, ®); + + if (memblock_add_range(usablemem, base, size, NUMA_NO_NODE, + MEMBLOCK_NONE)) + return 0; + if (++nr >= CRASH_MAX_USABLE_RANGES) + break; + } return 1; } static void __init fdt_enforce_memory_region(void) { - struct memblock_region reg = { - .size = 0, + struct memblock_region usable_regions[CRASH_MAX_USABLE_RANGES]; + struct memblock_type usablemem = { + .max = CRASH_MAX_USABLE_RANGES, + .regions = usable_regions, }; - of_scan_flat_dt(early_init_dt_scan_usablemem, ®); + of_scan_flat_dt(early_init_dt_scan_usablemem, &usablemem); - if (reg.size) - memblock_cap_memory_range(reg.base, reg.size); + if (usablemem.cnt) + memblock_cap_memory_ranges(&usablemem); } void __init arm64_memblock_init(void) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 180877c..f04dfc1 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -445,7 +445,6 @@ phys_addr_t memblock_mem_size(unsigned long limit_pfn); phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); -void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); void memblock_cap_memory_ranges(struct memblock_type *regions_to_keep); void memblock_mem_limit_remove_map(phys_addr_t limit); bool memblock_is_memory(phys_addr_t addr); diff --git a/mm/memblock.c b/mm/memblock.c index 9661807..9b5cef4 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1669,34 +1669,6 @@ void __init memblock_enforce_memory_limit(phys_addr_t limit) PHYS_ADDR_MAX); } -void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) -{ - int start_rgn, end_rgn; - int i, ret; - - if (!size) - return; - - ret = memblock_isolate_range(&memblock.memory, base, size, - &start_rgn, &end_rgn); - if (ret) - return; - - /* remove all the MAP regions */ - for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) - if (!memblock_is_nomap(&memblock.memory.regions[i])) - memblock_remove_region(&memblock.memory, i); - - for (i = start_rgn - 1; i >= 0; i--) - if (!memblock_is_nomap(&memblock.memory.regions[i])) - memblock_remove_region(&memblock.memory, i); - - /* truncate the reserved regions */ - memblock_remove_range(&memblock.reserved, 0, base); - memblock_remove_range(&memblock.reserved, - base + size, PHYS_ADDR_MAX); -} - void __init memblock_cap_memory_ranges(struct memblock_type *regions_to_keep) { int start_rgn[INIT_MEMBLOCK_REGIONS], end_rgn[INIT_MEMBLOCK_REGIONS]; @@ -1744,6 +1716,16 @@ void __init memblock_cap_memory_ranges(struct memblock_type *regions_to_keep) void __init memblock_mem_limit_remove_map(phys_addr_t limit) { + struct memblock_region rgn = { + .base = 0, + }; + + struct memblock_type region_to_keep = { + .cnt = 1, + .max = 1, + .regions = &rgn, + }; + phys_addr_t max_addr; if (!limit) @@ -1755,7 +1737,8 @@ void __init memblock_mem_limit_remove_map(phys_addr_t limit) if (max_addr == PHYS_ADDR_MAX) return; - memblock_cap_memory_range(0, max_addr); + region_to_keep.regions[0].size = max_addr; + memblock_cap_memory_ranges(®ion_to_keep); } static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr) From patchwork Mon Apr 15 10:57:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenzhou X-Patchwork-Id: 10900555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E46C17EF for ; Mon, 15 Apr 2019 10:47:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB9D4287AA for ; Mon, 15 Apr 2019 10:47:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF725287D3; Mon, 15 Apr 2019 10:47:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56754287AA for ; Mon, 15 Apr 2019 10:47:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C386A6B000C; Mon, 15 Apr 2019 06:47:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BBE656B000D; Mon, 15 Apr 2019 06:47:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFB906B000E; Mon, 15 Apr 2019 06:47:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 850136B000C for ; Mon, 15 Apr 2019 06:47:15 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id 64so8801954ota.18 for ; Mon, 15 Apr 2019 03:47:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=s3cqLnZ8ikaGliCL7mUmXmKsHQTifOzyfKPhb+L5V7k=; b=uHQ2SbMW02xpWhVeh+MWbPrNRsaAQ6EW0Gg8x7r8ELM9kZpkAagGhmwPCDs0ZX0AAe WeeY7wM5oXWU4To46ImwJIlsCiFsnysfSNDk6eu/+C1+u9CVhs/Bbm2qTzuFV9zqvdBB 5asGOdu1v492IGRUSOO9nPKGK5LmP0KeRFTpQRkIHVuXUIZNtVGQLZkY/+QXSOpk6svZ KbXM3iH+BjpAOYPPC3WvQWi/X2r/RASy1oOp45YkXAmv2YfaOMBfTTS2ChsRve2UiQcN aamyjJiY94Pys+o+spgR/A3ALZucmqRGWw+5BDNh6Zj6v54aU6vub/JUZ8hTRKT18wP1 ekiQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com X-Gm-Message-State: APjAAAUhmU6Afvh++PIy/zWtIrJHG7EKt2mh+4FqlZB0RCyGv2JYTiXv SRYp0MLsPuo7NDOpgwQu+MLHJ26cM2mHZTmCpR/iOlJqEQuWD9Mnb9oQonxODwRPClntT08JBsb XJcTDBFWGgo3fTUHeI3/KJPxFflvDUQS6J5sBooQ2nsimuW9uxNyOrFRtlWs5NJC6rA== X-Received: by 2002:a9d:51ca:: with SMTP id d10mr44928854oth.83.1555325235260; Mon, 15 Apr 2019 03:47:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqynVOnSHOY3IsWYoRTt6DWO45/Cw6ZcT5NunAg3BqWyQlOqtOVG0qSqkc3xtwG7gzVPPKkf X-Received: by 2002:a9d:51ca:: with SMTP id d10mr44928801oth.83.1555325233975; Mon, 15 Apr 2019 03:47:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555325233; cv=none; d=google.com; s=arc-20160816; b=uXY29TbqZFZdDmjpPHDVpIecLyoS0GD0IV0Hnng+yphlXDRTPMv9SjwOjJzGFCQZ4b LyhXKxY41rz+RgoW6W1egdBOQHWl3kuLiEtHBXZj9k74PUpdALuNND12NDib6DzcXeXf rVPmHcjz4kbg80wWByDhwTPVoIHSRHCmbBMCahXxwKuL0uqTELpSjAXGxWAvEZwdAOz1 LWWTrV/a5GgnWgtxmDNSGbcYIrJkqT4JOisxjVaCb2sgf12qgUQlPiN+oK2u13ws2cco LJMZZd8+7fRYkUaypORbbIJeo9zePTAJAiySkW8eaxJQmM9jEdYW+jFnG+AH5uH4OnCw rrVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=s3cqLnZ8ikaGliCL7mUmXmKsHQTifOzyfKPhb+L5V7k=; b=o1PucjRUrrRbJ8qenui1/SXZvhXuvnEUrghYCq5Hg2eQruUsIfORxUHfOT3akdOQ++ l+nNuucWYLc7P7SP5BKi2lpT1KBY8l2qgzM2KoN2zchBV8YDK3SxfoT3elzzMyOh0BUQ F8U10atiXU+Es6FN6D6zONba87EB5NA60R0NiffH2HgDe2BtI8nVZsgHsDncviyFHNCG TyfYYy/4AYvLEzy158TtKWnPRbkXED+3sYc7KmH0G4n/KYAO3A/uJw6U6J4q33vUaiyG 4Wx7OZQMfI4keI09i+c+JtnxJHABCvd65OfjGivoWE3xrTdY9KJvQTNMrfad3D5x5BBV CD/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from huawei.com (szxga05-in.huawei.com. [45.249.212.191]) by mx.google.com with ESMTPS id j185si22999546oia.117.2019.04.15.03.47.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 03:47:13 -0700 (PDT) Received-SPF: pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.191 as permitted sender) client-ip=45.249.212.191; Authentication-Results: mx.google.com; spf=pass (google.com: domain of chenzhou10@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=chenzhou10@huawei.com Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8810C6B0925E761BECE1; Mon, 15 Apr 2019 18:47:08 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Mon, 15 Apr 2019 18:46:58 +0800 From: Chen Zhou To: , , , , , , , , CC: , , , , , , , Chen Zhou Subject: [PATCH v4 5/5] kdump: update Documentation about crashkernel on arm64 Date: Mon, 15 Apr 2019 18:57:25 +0800 Message-ID: <20190415105725.22088-6-chenzhou10@huawei.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190415105725.22088-1-chenzhou10@huawei.com> References: <20190415105725.22088-1-chenzhou10@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Now we support crashkernel=X,[high,low] on arm64, update the Documentation. Signed-off-by: Chen Zhou --- Documentation/admin-guide/kernel-parameters.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 308af3b..a055983 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -715,14 +715,14 @@ Documentation/kdump/kdump.txt for an example. crashkernel=size[KMG],high - [KNL, x86_64] range could be above 4G. Allow kernel + [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. It will be ignored if crashkernel=X is specified. crashkernel=size[KMG],low - [KNL, x86_64] range under 4G. When crashkernel=X,high + [KNL, x86_64, arm64] 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