From patchwork Fri Dec 22 19:35:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 182766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1289529dyi; Fri, 22 Dec 2023 11:39:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0OP2cm6jFE+zat4Iplr9NbAGhubS1223aDWOueA3QTULKVbTAwRkqYgBlHOMrF/Axhd2j X-Received: by 2002:a17:902:d547:b0:1d3:5b15:b118 with SMTP id z7-20020a170902d54700b001d35b15b118mr2963609plf.96.1703273974651; Fri, 22 Dec 2023 11:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703273974; cv=none; d=google.com; s=arc-20160816; b=f14fcaL1c6ZMOW7tlXAvbuKTj0WOi/d1sMWJ8FiKb6jw0qqFPO231NXQmsqVX/GUkl BMp8gcIhqTJuIWnJkoQN2ss60RL+AbtS5QG5GaMdVvt2OXEKo5fdWbM0KpgIFHE5uI6Q watHO9rtFRw8x7F8189zfq2ns8KvHDNtqLajEoqaJ1mDgwAPiu56ZkoUby4c8EAG3vkA kcy3iACZlG0SzR7SsYQ2ejtHcMBQGmlM+GsYEDJeNxFAaueCfsYXRqh7CV2muGHZkxOc lcyEjZBqKz7L3g4WZ4oDJqsBj3vPzHoLNcY7A8ZTI0twTy42WSW7Ah+JSHeRzjBAq7Av TnKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4hs41nrvxXplJ/QyH6HSlHLbtIDrbQgqX7R8fKuobQ4=; fh=xprWcyUKTLi4rhte7gFCvduD673j12awuFkCPnYDQVY=; b=PyNPvJJa8GCPxwpa+9J0eyJ4nR8oDNK9omth90Wu8BZKisoTRCKLowGiGYyNIlPYm7 xVg/sUxL7WjIEMYwpRyRVnVtqN2vfjQCi/q//2dly7x/G+rtMujEhiX3Y780UdowBnZJ eAJWmGsDCn7mXaG2tofDN+JKOsTzvHS48oE9raSInvwc9lSYif0mgZncUvHfRl/Z+Cfi LLVZfOaTYS5KSqnmeAQ1DFUu5L0pO6ABbPRpSJ3gedsn1LjwVv1MT3plKYudPx0x0GXX OcjxR+rXv5cSNR97EEA8/umfVPous+o5PMi3Iz0wXNRcNp3ymzDH3pvyG2mlUHLBMhZe yL0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=fb5WtgA9; spf=pass (google.com: domain of linux-kernel+bounces-10023-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10023-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q4-20020a170902dac400b001ce5b8cfe7dsi3722570plx.230.2023.12.22.11.39.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 11:39:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10023-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=fb5WtgA9; spf=pass (google.com: domain of linux-kernel+bounces-10023-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10023-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DA372B2470D for ; Fri, 22 Dec 2023 19:39:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E023730F90; Fri, 22 Dec 2023 19:37:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fb5WtgA9" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE0FE2E85E; Fri, 22 Dec 2023 19:37:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1703273856; x=1734809856; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4hs41nrvxXplJ/QyH6HSlHLbtIDrbQgqX7R8fKuobQ4=; b=fb5WtgA9BIIcTNptuBossX7z09sYwh7fY7jTEocFeMGfXK5odZvvN7Xe V4DqEZ3tuGNUW8ngtsDwNMlk8bkVPuVsoq55g1Qd17jecYbMF1/tFGLI6 CGjd1wMOYZkdbX5NFyza3nw0PRTa/fxnUj/yn7/CH+/xQjW2ziHylbulQ 4=; X-IronPort-AV: E=Sophos;i="6.04,297,1695686400"; d="scan'208";a="318657015" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 19:37:32 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan3.pdx.amazon.com [10.39.38.70]) by email-inbound-relay-pdx-2c-m6i4x-8c5b1df3.us-west-2.amazon.com (Postfix) with ESMTPS id DCC8F40D5B; Fri, 22 Dec 2023 19:37:28 +0000 (UTC) Received: from EX19MTAUWA001.ant.amazon.com [10.0.38.20:1484] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.38.150:2525] with esmtp (Farcaster) id 8eb458e3-6f3d-4684-a6b2-2776439c40d0; Fri, 22 Dec 2023 19:37:28 +0000 (UTC) X-Farcaster-Flow-ID: 8eb458e3-6f3d-4684-a6b2-2776439c40d0 Received: from EX19D020UWC004.ant.amazon.com (10.13.138.149) by EX19MTAUWA001.ant.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 22 Dec 2023 19:37:28 +0000 Received: from dev-dsk-graf-1a-5ce218e4.eu-west-1.amazon.com (10.253.83.51) by EX19D020UWC004.ant.amazon.com (10.13.138.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 22 Dec 2023 19:37:24 +0000 From: Alexander Graf To: CC: , , , , , , , Eric Biederman , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , "Rob Herring" , Steven Rostedt , "Andrew Morton" , Mark Rutland , "Tom Lendacky" , Ashish Kalra , James Gowans , Stanislav Kinsburskii , , , , Anthony Yznaga , Usama Arif , David Woodhouse , Benjamin Herrenschmidt Subject: [PATCH v2 08/17] arm64: Add KHO support Date: Fri, 22 Dec 2023 19:35:58 +0000 Message-ID: <20231222193607.15474-9-graf@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231222193607.15474-1-graf@amazon.com> References: <20231222193607.15474-1-graf@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D037UWB001.ant.amazon.com (10.13.138.123) To EX19D020UWC004.ant.amazon.com (10.13.138.149) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786012211248379851 X-GMAIL-MSGID: 1786012211248379851 We now have all bits in place to support KHO kexecs. This patch adds awareness of KHO in the kexec file as well as boot path for arm64 and adds the respective kconfig option to the architecture so that it can use KHO successfully. Signed-off-by: Alexander Graf --- v1 -> v2: - test bot warning fix - Change kconfig option to ARCH_SUPPORTS_KEXEC_KHO - s/kho_reserve_mem/kho_reserve_previous_mem/g - s/kho_reserve/kho_reserve_scratch/g - Remove / reduce ifdefs for kho fdt code --- arch/arm64/Kconfig | 3 +++ arch/arm64/kernel/setup.c | 2 ++ arch/arm64/mm/init.c | 8 ++++++ drivers/of/fdt.c | 39 ++++++++++++++++++++++++++++ drivers/of/kexec.c | 54 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7b071a00425d..4a2fd3deaa16 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1495,6 +1495,9 @@ config ARCH_SUPPORTS_KEXEC_IMAGE_VERIFY_SIG config ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG def_bool y +config ARCH_SUPPORTS_KEXEC_KHO + def_bool y + config ARCH_SUPPORTS_CRASH_DUMP def_bool y diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 417a8a86b2db..9aa05b84d202 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -346,6 +346,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) paging_init(); + kho_reserve_previous_mem(); + acpi_table_upgrade(); /* Parse the ACPI tables for possible boot-time configuration */ diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 74c1db8ce271..1a8fc91509af 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -358,6 +358,8 @@ void __init bootmem_init(void) */ arch_reserve_crashkernel(); + kho_reserve_scratch(); + memblock_dump_all(); } @@ -386,6 +388,12 @@ void __init mem_init(void) /* this will put all unused low memory onto the freelists */ memblock_free_all(); + /* + * Now that all KHO pages are marked as reserved, let's flip them back + * to normal pages with accurate refcount. + */ + kho_populate_refcount(); + /* * Check boundaries twice: Some fundamental inconsistencies can be * detected at build time already. diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index bf502ba8da95..f9b9a36fb722 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1006,6 +1006,42 @@ void __init early_init_dt_check_for_usable_mem_range(void) memblock_add(rgn[i].base, rgn[i].size); } +/** + * early_init_dt_check_kho - Decode info required for kexec handover from DT + */ +static void __init early_init_dt_check_kho(void) +{ + unsigned long node = chosen_node_offset; + u64 kho_start, scratch_start, scratch_size, mem_start, mem_size; + const __be32 *p; + int l; + + if (!IS_ENABLED(CONFIG_KEXEC_KHO) || (long)node < 0) + return; + + p = of_get_flat_dt_prop(node, "linux,kho-dt", &l); + if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)) + return; + + kho_start = dt_mem_next_cell(dt_root_addr_cells, &p); + + p = of_get_flat_dt_prop(node, "linux,kho-scratch", &l); + if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)) + return; + + scratch_start = dt_mem_next_cell(dt_root_addr_cells, &p); + scratch_size = dt_mem_next_cell(dt_root_addr_cells, &p); + + p = of_get_flat_dt_prop(node, "linux,kho-mem", &l); + if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32)) + return; + + mem_start = dt_mem_next_cell(dt_root_addr_cells, &p); + mem_size = dt_mem_next_cell(dt_root_addr_cells, &p); + + kho_populate(kho_start, scratch_start, scratch_size, mem_start, mem_size); +} + #ifdef CONFIG_SERIAL_EARLYCON int __init early_init_dt_scan_chosen_stdout(void) @@ -1304,6 +1340,9 @@ void __init early_init_dt_scan_nodes(void) /* Handle linux,usable-memory-range property */ early_init_dt_check_for_usable_mem_range(); + + /* Handle kexec handover */ + early_init_dt_check_kho(); } bool __init early_init_dt_scan(void *params) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index 68278340cecf..59070b09ad45 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -264,6 +264,55 @@ static inline int setup_ima_buffer(const struct kimage *image, void *fdt, } #endif /* CONFIG_IMA_KEXEC */ +static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_node) +{ + void *dt = NULL; + phys_addr_t dt_mem = 0; + phys_addr_t dt_len = 0; + phys_addr_t scratch_mem = 0; + phys_addr_t scratch_len = 0; + void *mem_cache = NULL; + phys_addr_t mem_cache_mem = 0; + phys_addr_t mem_cache_len = 0; + int ret = 0; + +#ifdef CONFIG_KEXEC_KHO + dt = image->kho.dt.buffer; + dt_mem = image->kho.dt.mem; + dt_len = image->kho.dt.bufsz; + + scratch_mem = kho_scratch_phys; + scratch_len = kho_scratch_len; + + mem_cache = image->kho.mem_cache.buffer; + mem_cache_mem = image->kho.mem_cache.mem; + mem_cache_len = image->kho.mem_cache.bufsz; +#endif + + if (!dt || !mem_cache) + goto out; + + pr_debug("Adding kho metadata to DT"); + + ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, "linux,kho-dt", + dt_mem, dt_len); + if (ret) + goto out; + + ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, "linux,kho-scratch", + scratch_mem, scratch_len); + if (ret) + goto out; + + ret = fdt_appendprop_addrrange(fdt, 0, chosen_node, "linux,kho-mem", + mem_cache_mem, mem_cache_len); + if (ret) + goto out; + +out: + return ret; +} + /* * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree * @@ -412,6 +461,11 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, } } + /* Add kho metadata if this is a KHO image */ + ret = kho_add_chosen(image, fdt, chosen_node); + if (ret) + goto out; + /* add bootargs */ if (cmdline) { ret = fdt_setprop_string(fdt, chosen_node, "bootargs", cmdline);