From patchwork Mon Jul 8 21:15:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 11035803 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 30CA917D5 for ; Mon, 8 Jul 2019 21:17:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A5D12837D for ; Mon, 8 Jul 2019 21:17:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B9B4283BB; Mon, 8 Jul 2019 21:17:13 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B4182837D for ; Mon, 8 Jul 2019 21:17:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8WiTBYoGxJWwmxaiNoTbwaKfzxhTeH2uXaPki6mdGYg=; b=rsZpDVaylyH5iR 5+WD9cswApejdfwQk5qYUbA77+FTblmDlnw9U6JeLUAOmu5WTlx2mHWcAY7Q6iCdhbTtmkI282M8X D0+0zqz2eKwaD958gSHf7+jJCe1ljetWb9sgDOuBSZ3szfXjPQjbEAr2RhHUPHel3/knY1fPiMKE5 s74MAQIyzZQ9U0LmPdjDn+brxXYr3el+1fw1QZO0Cfrv5vMWeC/fAK17Wqte/UTxL3gs9K4wwV+gt 2aW6zTCy9VxEhKZZKhAYhBES+j77pmyjF3a5dcIXZhwBEyVM5bDompCNlVPTlXC7c0hzmFR5fSODV a710DyJJ2UT46pvWYM8Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hkb0U-0002gf-5B; Mon, 08 Jul 2019 21:17:06 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hkaz4-0001TJ-Cq for linux-arm-kernel@lists.infradead.org; Mon, 08 Jul 2019 21:15:41 +0000 Received: by mail-qk1-x741.google.com with SMTP id r4so14395379qkm.13 for ; Mon, 08 Jul 2019 14:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=AiVVzsQgxExtlPdXUQO7u3KIlgj9fJXNjXAFaENAUkA=; b=hBOFe5Ugx8wiuHA/gjntnci5gyCoKGx2KeUGJzzIexTkV/nSc9m1wu1T3dPF3WEYlY lwMmi6wk/x1rt0bVkNJWpCL1+QH1ucrG89pfU/Isl/kUcpBebVFOWEvxPALC3iThVuqG ADWFeylsNMjjNctZNfFC/tsxiYCM89r45RVa2JJrS5RMWEiTiWiGUfh2oiNXyupiAH3g cE6WFbGJY3c5kcFPTx0V9QTiI0bipkfLQlrw6OCsuks9o6h6EGGcKxGMbiuZHxlMWMi1 kbLgzBstYWq+jXa6BHc3h9N+ljlc8rZaZy3kFfH+zMMRFV46PunVk3YJusKsL4zZQHKQ hIAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AiVVzsQgxExtlPdXUQO7u3KIlgj9fJXNjXAFaENAUkA=; b=rMtUNj0r+DXCk0A/lTPFBSA3KJGr+UyjU/8agqIFZqF0zdw2HAfyrY0ZiowzmICua6 bIa4hRoaE5x5q9LGmjoqQOMI+YyFcAt8JhGQ1GA1ibZkCd96R1EsjYVa859jfXZA5l53 4qwf++uRU9GiAcihzjXXzuU/Khj7pqB1yhaIAt5DFMyWDIRqDo8LgdjCJYDgK7e6Cg/9 XbfB+Mj2ylF7pENGrNzSTtwRlDJoe9idiHy8Ev7/1m0ylIHNCg/x9RD3s8SKFLjvy8FK IAT1XadbeiUMB1DW+/TswMviosG5bhR6v4aR7bp8I0paxk1KODU35PGIjTVKgnOySoxG qbGA== X-Gm-Message-State: APjAAAUT02MaHR2scG/KNNN0tB7ffXJCCTgdQZRgWc/RKV+LnEkYOCPA clKMKmh4IarcuV9zGepGhacn6g== X-Google-Smtp-Source: APXvYqyHLZkbmfQTKjXh1EEa/IoaB1YEoR8Z3fSF2HU2Rzl8oz3tGEYtOcg6+Dl43IZZhoEp3B/fZg== X-Received: by 2002:a37:be41:: with SMTP id o62mr15906517qkf.356.1562620537487; Mon, 08 Jul 2019 14:15:37 -0700 (PDT) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id b67sm8335620qkd.82.2019.07.08.14.15.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 14:15:36 -0700 (PDT) From: Pavel Tatashin To: pasha.tatashin@soleen.com, jmorris@namei.org, sashal@kernel.org, ebiederm@xmission.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, corbet@lwn.net, catalin.marinas@arm.com, will@kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [v1 5/5] arm64, kexec: reserve kexeckernel region Date: Mon, 8 Jul 2019 17:15:28 -0400 Message-Id: <20190708211528.12392-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708211528.12392-1-pasha.tatashin@soleen.com> References: <20190708211528.12392-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190708_141538_680093_46100379 X-CRM114-Status: GOOD ( 18.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP kexeckernel= is used to reserve memory for normal kexec kernel for faster reboot. Rename reserve_crashkernel() to reserve_crash_or_kexec_kernel(), and generalize it by adding an argument that specifies what is reserved: "crashkernel=" for crash kernel region "kexeckernel=" for normal kexec region Signed-off-by: Pavel Tatashin --- .../admin-guide/kernel-parameters.txt | 10 +-- arch/arm64/kernel/setup.c | 5 ++ arch/arm64/mm/init.c | 83 ++++++++++++------- 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 0f5ce665c7f5..a18222c1fbee 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -740,11 +740,11 @@ or memory reserved is below 4G. kexeckernel=size[KMG][@offset[KMG]] - [KNL] Using kexec, Linux can reboot to a new kernel. - This parameter reserves the physical memory region - [offset, offset + size] for that kernel. If '@offset' is - omitted, then a suitable offset is selected - automatically. + [KNL, ARM64] Using kexec, Linux can reboot to a new + kernel. This parameter reserves the physical memory + region [offset, offset + size] for that kernel. If + '@offset' is omitted, then a suitable offset is + selected automatically. cryptomgr.notests [KNL] Disable crypto self-tests diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 7e541f947b4c..9f308fa103c5 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -235,6 +235,11 @@ static void __init request_standard_resources(void) if (crashk_res.end && crashk_res.start >= res->start && crashk_res.end <= res->end) request_resource(res, &crashk_res); + + /* Userspace will find "Kexec kernel" region in /proc/iomem. */ + if (kexeck_res.end && kexeck_res.start >= res->start && + kexeck_res.end <= res->end) + request_resource(res, &kexeck_res); #endif } } diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index f3c795278def..dfef39f72faf 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -54,61 +54,83 @@ phys_addr_t arm64_dma_phys_limit __ro_after_init; #ifdef CONFIG_KEXEC_CORE /* - * reserve_crashkernel() - reserves memory for crash kernel + * reserve_crash_or_kexec_kernel() - reserves memory for crash kernel or + * for normal kexec kernel. * - * This function reserves memory area given in "crashkernel=" kernel command - * line parameter. The memory reserved is used by dump capture kernel when - * primary kernel is crashing. + * This function reserves memory area given in "crashkernel=" or "kexeckenel=" + * kernel command line parameter. The memory reserved is used by dump capture + * kernel when primary kernel is crashing, or to load new kexec kernel for + * faster reboot without relocation. */ -static void __init reserve_crashkernel(void) +static void __init reserve_crash_or_kexec_kernel(char *cmd) { - unsigned long long crash_base, crash_size; + unsigned long long base, size; + struct resource *res; + char s[16]; 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) + /* cmd must be either: "crashkernel=" or "kexeckernel=" */ + if (!strcmp(cmd, "crashkernel=")) { + res = &crashk_res; + } else if (!strcmp(cmd, "kexeckernel=")) { + res = &kexeck_res; + } else { + pr_err("%s: invalid cmd %s\n", __func__, cmd); + return; + } + + /* remove trailing '=' for a nicer printfs */ + strcpy(s, cmd); + s[strlen(s) - 1] = '\0'; + + ret = parse_crash_or_kexec_kernel(boot_command_line, + memblock_phys_mem_size(), + &size, &base, cmd, NULL); + /* no specified command or invalid value specified */ + if (ret || !size) return; - crash_size = PAGE_ALIGN(crash_size); + size = PAGE_ALIGN(size); - if (crash_base == 0) { + if (base == 0) { /* Current arm64 boot protocol requires 2MB alignment */ - crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT, - crash_size, SZ_2M); - if (crash_base == 0) { - pr_warn("cannot allocate crashkernel (size:0x%llx)\n", - crash_size); + base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT, + size, SZ_2M); + if (base == 0) { + pr_warn("cannot allocate %s (size:0x%llx)\n", + s, size); return; } } else { /* User specifies base address explicitly. */ - if (!memblock_is_region_memory(crash_base, crash_size)) { - pr_warn("cannot reserve crashkernel: region is not memory\n"); + if (!memblock_is_region_memory(base, size)) { + pr_warn("cannot reserve %s: region is not memory\n", + s); return; } - if (memblock_is_region_reserved(crash_base, crash_size)) { - pr_warn("cannot reserve crashkernel: region overlaps reserved memory\n"); + if (memblock_is_region_reserved(base, size)) { + pr_warn("cannot reserve %s: region overlaps reserved memory\n", + s); return; } - if (!IS_ALIGNED(crash_base, SZ_2M)) { - pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n"); + if (!IS_ALIGNED(base, SZ_2M)) { + pr_warn("cannot reserve %s: base address is not 2MB aligned\n", + s); return; } } - memblock_reserve(crash_base, crash_size); + memblock_reserve(base, size); - pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n", - crash_base, crash_base + crash_size, crash_size >> 20); + pr_info("%s reserved: 0x%016llx - 0x%016llx (%lld MB)\n", + s, base, base + size, size >> 20); - crashk_res.start = crash_base; - crashk_res.end = crash_base + crash_size - 1; + res->start = base; + res->end = base + size - 1; } #else -static void __init reserve_crashkernel(void) +static void __init reserve_crash_or_kexec_kernel(char *cmd) { } #endif /* CONFIG_KEXEC_CORE */ @@ -411,7 +433,8 @@ void __init arm64_memblock_init(void) else arm64_dma_phys_limit = PHYS_MASK + 1; - reserve_crashkernel(); + reserve_crash_or_kexec_kernel("crashkernel="); + reserve_crash_or_kexec_kernel("kexeckernel="); reserve_elfcorehdr();