From nobody Sun Feb 8 05:29:02 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 42501307AC6 for ; Tue, 6 Jan 2026 07:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767685250; cv=none; b=b70PTbcpZnfvcJJcJlexK9wf72Zv2AVqb3BcoMvbpKsKA4gbbRteM2Z3m4qrpKisFr08wXyH80KfT+dQYZFZwzCjGNwGTzo2rn+ZFxPwemEoluaw7868r1Zou0BnBqA4nI6t4YHsXQHriU1NUa9RYnZOo5pooBLYOs9ILFyDR5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767685250; c=relaxed/simple; bh=SZpy3k7bK4607+q7zj6kiCMgI5ofhjMGxIXtTFzhJgI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mEUmmrlSCEa9CKEdO6QY/cpxnLjrt++iUmGmddxecMtSQzBg0aYwNCy3yRKsLfdQXPohKd2ChdlTz3czKII7alZwz7mcUVjogBy9+jynuob2CoeQOpcBdz9JFhYxUPr0Cq6wTosViGUuI9ZFWlTXgVNsE+4CINq53xOsaBXSx+o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TN/TLn89; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rNnOL5jA; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TN/TLn89"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rNnOL5jA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767685247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2K+6XYuDT2faPkgFNRf0MMgXkPW9/hzNvicOemZ75A=; b=TN/TLn89XtOiiiGrcX9lDxlACzxG2XMoSy2SAVqLSVebJdRzv5LikhI2x18MSkcM9+NtgY xoExOry6FtfXkIY7S1Est85QhIrHYuPyJFymBuVQsTdQYSWO9CEIYR3T9mvB9P+y0eL1zy gj1arMRyer04J7wrDjG/OHaaN6x5geM= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-Q4SU4N9FPkGSbyDpel7cmQ-1; Tue, 06 Jan 2026 02:40:45 -0500 X-MC-Unique: Q4SU4N9FPkGSbyDpel7cmQ-1 X-Mimecast-MFC-AGG-ID: Q4SU4N9FPkGSbyDpel7cmQ_1767685244 Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-34cc88eca7eso1982851a91.2 for ; Mon, 05 Jan 2026 23:40:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1767685244; x=1768290044; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T2K+6XYuDT2faPkgFNRf0MMgXkPW9/hzNvicOemZ75A=; b=rNnOL5jASl/n8AmDU0vBhnHKR0vdubdS4dF+7IH1a2airabQ3opPn94UHiG2/z+f1w R5tWp8HU4pWkxBGH4R/cguzMHpkuxSc7J4dDpEkKlaX8h9Yr1nrIfRXbavIK0kQMTtZH Ar883YVzPyZ0VPzW1q8DhbCUR1W5EQGz83hLvWR3mOJF4Zc9a50uc+JSPaW4sXo6XZPl ib52cC7bgIzD/V3N8SvfW48fsKfWn7EexeloZvCUUeXWiRxYijsT5ZheKppGXWIjeqmw 4xV5N3mbvqowYcyWowDfEAdL2SUiNc/VW5427hfbRGjUS0oTGaHFbWigbN6cum/Db72W dzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767685244; x=1768290044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=T2K+6XYuDT2faPkgFNRf0MMgXkPW9/hzNvicOemZ75A=; b=HeG3YDcWTOfcSsRHAmrUB8EahCVM3ydLBRdHqhLAUHkO3jXyHotu2RWbszdVFBXh92 C8KS24ydZyiy366bBr/GbDM+/UPvIpTwLHJB5hyhP77zDZlKoJkYThdE+0r7kzJ2/Jtq yyTJPANLIO2CCPgfCFfrQlt/G9kLLSJ+wSgyyNKqWAR2KruYBYI9P3Y5k4aLv9w61odp 62lwYzRY/aIkaAVB81++0XZI20WCSfAGqGAstf0UXxgHzyi2QLZt07J84uTlLBrjOBQV OuCyH94xUpUcbrbhrQ1uemTewH9SCc8VDcaR2ej/LJ+H5OWyrZJcV0ZeNUidubqSa/UB iXrA== X-Forwarded-Encrypted: i=1; AJvYcCWQ1g/Z7nPHeHk+27lBYqjwQzMlN+G9pUGh0ydq3gsQkdom8dlcRwnkHUQiN70gNZ/aZf0UknSgoCN1eVE=@vger.kernel.org X-Gm-Message-State: AOJu0YyIz0eMLwkF7nLFyER0SClmKxqchOQr7UTIygHpB0a7hcmCgr6c VOfGCzpE0e7EAq+3zgKkVnTOJtazAleDQQz0BI7isibbtTEzicZIOXxv4Apenid/96Ov8HsML2V 0RndZUqu2ywJpxfWlbH9hAckkzHK635tdWTHL+V2zMxwXvJ+O9Cct18R6yREGgAWshQ== X-Gm-Gg: AY/fxX7cnM7XMt1QGaI7wjf7aMciyl3fL8XGhCHbqeLr+uDPVxeT3vvnLcXDsJQEZ09 U48fkPN5Icnm6i2mzmBTQ3aMKCUhzGCsdLAwPMnzQOtUC3YDhLxoRFiZQPNa3nzbS/234p2Mhua qtiGfgK76Wg/QskUX/tfQodHEii3kexyZmHPtCy0dTx4J05PW4QxJEIDs5OQkx9KLQXp8jjubeu SNbWLOqi+QPrEeVkzyKeiHVnwVrfIeNRPNxgYaH1/G/aTrDlrU+DWD7yNUjHvID/XaTCWkNSCai iNpLRRjTJYmqkUohmvjFFuM62TZI1SrSNjzi6NS00IP1lgTnq8QLqg67DflLDv4qjEypcHh9Cgo I X-Received: by 2002:a05:6a21:6d98:b0:35d:c68e:1b07 with SMTP id adf61e73a8af0-389823e5d3fmr1735571637.54.1767685244275; Mon, 05 Jan 2026 23:40:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVUzWKzSkNqbLbBe+L/snCjJ0oavUrUixh1GN3s9rZlQu+O972p1pSFAutekovPq/olCdVFQ== X-Received: by 2002:a05:6a21:6d98:b0:35d:c68e:1b07 with SMTP id adf61e73a8af0-389823e5d3fmr1735547637.54.1767685243733; Mon, 05 Jan 2026 23:40:43 -0800 (PST) Received: from localhost ([209.132.188.88]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3c3a2a3sm13338605ad.13.2026.01.05.23.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 23:40:43 -0800 (PST) From: Coiby Xu To: kexec@lists.infradead.org, linuxppc-dev@lists.ozlabs.org Cc: Thomas Staudt , Arnaud Lefebvre , Baoquan he , Dave Young , Kairui Song , Pingfan Liu , Andrew Morton , Sourabh Jain , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Vivek Goyal , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] powerpc/kdump: pass dm-crypt keys to kdump kernel Date: Tue, 6 Jan 2026 15:40:38 +0800 Message-ID: <20260106074039.564707-1-coxu@redhat.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251226140636.1378505-1-coxu@redhat.com> References: <20251226140636.1378505-1-coxu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CONFIG_CRASH_DM_CRYPT has been introduced to support LUKS-encrypted device dump target by addressing two challenges [1], - Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes - LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump. To also enable this feature for PowerPC, we only need to let 1st kernel build up the kernel command parameter dmcryptkeys as similar to elfcorehdr to pass the memory address of the stored info of dm-crypt keys to the kdump kernel. Note to avoid a building failure [2] caused by undeclared function crash_load_dm_crypt_keys when CONFIG_CRASH_DUMP is not enabled, realign the function declaration with CONFIG_CRASH_DM_CRYPT. [1] https://lore.kernel.org/all/20250502011246.99238-1-coxu@redhat.com/ [2] https://lore.kernel.org/oe-kbuild-all/202512272218.ghBaSjzO-lkp@intel.c= om/ Cc: Thomas Staudt Cc: Arnaud Lefebvre Cc: Baoquan he Cc: Dave Young Cc: Kairui Song Cc: Pingfan Liu Cc: Andrew Morton Cc: Sourabh Jain Signed-off-by: Coiby Xu Acked-by: Sourabh Jain --- v2: - fix double kfree issue [Sourabh] - corretly kfree old modified_cmdline - use imperative mood for commit message - fix a compiling error caught by kernel test robot arch/powerpc/include/asm/kexec.h | 3 ++- arch/powerpc/kexec/elf_64.c | 27 ++++++++++++++++++++++++++- arch/powerpc/kexec/file_load.c | 18 ++++++++++-------- include/linux/crash_core.h | 14 +++++++------- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/ke= xec.h index bd4a6c42a5f3..f3d098d543b4 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -80,7 +80,8 @@ struct kimage_arch { }; =20 char *setup_kdump_cmdline(struct kimage *image, char *cmdline, - unsigned long cmdline_len); + unsigned long cmdline_len, + char *name, unsigned long addr); int setup_purgatory(struct kimage *image, const void *slave_code, const void *fdt, unsigned long kernel_load_addr, unsigned long fdt_load_addr); diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c index 5d6d616404cf..995d7e8e98e1 100644 --- a/arch/powerpc/kexec/elf_64.c +++ b/arch/powerpc/kexec/elf_64.c @@ -81,13 +81,38 @@ static void *elf64_load(struct kimage *image, char *ker= nel_buf, =20 /* Setup cmdline for kdump kernel case */ modified_cmdline =3D setup_kdump_cmdline(image, cmdline, - cmdline_len); + cmdline_len, + "elfcorehdr", + image->elf_load_addr); if (!modified_cmdline) { pr_err("Setting up cmdline for kdump kernel failed\n"); ret =3D -EINVAL; goto out; } cmdline =3D modified_cmdline; + cmdline_len =3D strlen(cmdline) + 1; + + ret =3D crash_load_dm_crypt_keys(image); + if (ret =3D=3D -ENOENT) { + kexec_dprintk("No dm crypt key to load\n"); + } else if (ret) { + pr_err("Failed to load dm crypt keys\n"); + return ERR_PTR(ret); + } + + if (image->dm_crypt_keys_addr !=3D 0) { + modified_cmdline =3D setup_kdump_cmdline(image, cmdline, + cmdline_len, + "dmcryptkeys", + image->dm_crypt_keys_addr); + kfree(cmdline); + if (!modified_cmdline) { + pr_err("Setting up cmdline for kdump kernel failed\n"); + ret =3D -EINVAL; + goto out; + } + cmdline =3D modified_cmdline; + } } =20 if (initrd !=3D NULL) { diff --git a/arch/powerpc/kexec/file_load.c b/arch/powerpc/kexec/file_load.c index 4284f76cbef5..9964c57785f5 100644 --- a/arch/powerpc/kexec/file_load.c +++ b/arch/powerpc/kexec/file_load.c @@ -23,36 +23,38 @@ #define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */ =20 /** - * setup_kdump_cmdline - Prepend "elfcorehdr=3D " to command line + * setup_kdump_cmdline - Prepend "=3D " to command line * of kdump kernel for exporting the core. * @image: Kexec image * @cmdline: Command line parameters to update. * @cmdline_len: Length of the cmdline parameters. + * @name: Name e.g elfcorehdr. + * @addr: Memory address. * * kdump segment must be setup before calling this function. * * Returns new cmdline buffer for kdump kernel on success, NULL otherwise. */ char *setup_kdump_cmdline(struct kimage *image, char *cmdline, - unsigned long cmdline_len) + unsigned long cmdline_len, + char *name, unsigned long addr) { - int elfcorehdr_strlen; + unsigned long parameter_len; char *cmdline_ptr; =20 cmdline_ptr =3D kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL); if (!cmdline_ptr) return NULL; =20 - elfcorehdr_strlen =3D sprintf(cmdline_ptr, "elfcorehdr=3D0x%lx ", - image->elf_load_addr); + parameter_len =3D sprintf(cmdline_ptr, "%s=3D0x%lx ", name, addr); =20 - if (elfcorehdr_strlen + cmdline_len > COMMAND_LINE_SIZE) { - pr_err("Appending elfcorehdr=3D exceeds cmdline size\n"); + if (parameter_len + cmdline_len > COMMAND_LINE_SIZE) { + pr_err("Appending %s=3D exceeds cmdline size\n", name); kfree(cmdline_ptr); return NULL; } =20 - memcpy(cmdline_ptr + elfcorehdr_strlen, cmdline, cmdline_len); + memcpy(cmdline_ptr + parameter_len, cmdline, cmdline_len); // Ensure it's nul terminated cmdline_ptr[COMMAND_LINE_SIZE - 1] =3D '\0'; return cmdline_ptr; diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index d35726d6a415..e128270c703f 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -34,13 +34,6 @@ static inline void arch_kexec_protect_crashkres(void) { } static inline void arch_kexec_unprotect_crashkres(void) { } #endif =20 -#ifdef CONFIG_CRASH_DM_CRYPT -int crash_load_dm_crypt_keys(struct kimage *image); -ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos); -#else -static inline int crash_load_dm_crypt_keys(struct kimage *image) {return 0= ; } -#endif - #ifndef arch_crash_handle_hotplug_event static inline void arch_crash_handle_hotplug_event(struct kimage *image, v= oid *arg) { } #endif @@ -96,4 +89,11 @@ static inline void crash_save_cpu(struct pt_regs *regs, = int cpu) {}; static inline int kimage_crash_copy_vmcoreinfo(struct kimage *image) { ret= urn 0; }; #endif /* CONFIG_CRASH_DUMP*/ =20 +#ifdef CONFIG_CRASH_DM_CRYPT +int crash_load_dm_crypt_keys(struct kimage *image); +ssize_t dm_crypt_keys_read(char *buf, size_t count, u64 *ppos); +#else +static inline int crash_load_dm_crypt_keys(struct kimage *image) { return = 0; } +#endif + #endif /* LINUX_CRASH_CORE_H */ base-commit: 7f98ab9da046865d57c102fd3ca9669a29845f67 --=20 2.52.0