From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2455633E1 for ; Sun, 4 May 2025 05:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746335733; cv=none; b=LgIuYZffaKkO05KPp3Mzx5sVuNTkKiXTjJ/bp7RdBuR4LoVgaEtMGCmlyMeWut3vC7+h5DcjQ6famO0bxcVhtP4tLNp876NSt+IFHzQPdb4eEhvERQeaXH+T+tO1U14kk6gjPwQpPUKAxlGZG6eQ+ziwD6MauZxho6s+w4O1L0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746335733; c=relaxed/simple; bh=xz2MKF9TPFIA9y2eWbHb7Jl4xaDPECWUQF8YwV4mGpA=; h=Date:To:From:Subject:Message-Id; b=GZ7oryhFAAwA5iq2Go0k/KAuFN+havYj9wTPD+lv2gQTYI7M146Uw7UFST30ODM3eEubgqSMlFseRHOmFpzoysSGFu0J60Ty4Euc6K1A8LRtMPep+FY8scI8N2X0YdcXLjyhmI8UaKWaoesai1n9TpnpNvrwTgdJRAjxZTg4NsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=zMdsJsT9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="zMdsJsT9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBE9DC4CEED; Sun, 4 May 2025 05:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1746335733; bh=xz2MKF9TPFIA9y2eWbHb7Jl4xaDPECWUQF8YwV4mGpA=; h=Date:To:From:Subject:From; b=zMdsJsT9erfgmWLjMVC3aj1SF/TvaWLS9hNQMZQYEK+u9gfSFg4A9mudT22T6GPnk kTozrre3U7p9HRERCJXwLMyq+L7kugfdx38VR+p2ppJ76YJsMBOBtrj1baI1xhHmDF eyH9jCEIcgrBU7grE4nkQ83KPQl1lcoFSyx9HRKk= Date: Sat, 03 May 2025 22:15:32 -0700 To: mm-commits@vger.kernel.org,vkuznets@redhat.com,okozina@redhat.com,kernelfans@gmail.com,jpazdziora@redhat.com,gmazyland@gmail.com,dyoung@redhat.com,dave.hansen@intel.com,bhe@redhat.com,berrange@redhat.com,coxu@redhat.com,akpm@linux-foundation.org From: Andrew Morton Subject: + x86-crash-pass-dm-crypt-keys-to-kdump-kernel.patch added to mm-nonmm-unstable branch Message-Id: <20250504051532.EBE9DC4CEED@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: x86/crash: pass dm crypt keys to kdump kernel has been added to the -mm mm-nonmm-unstable branch. Its filename is x86-crash-pass-dm-crypt-keys-to-kdump-kernel.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/x86-crash-pass-dm-crypt-keys-to-kdump-kernel.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Coiby Xu Subject: x86/crash: pass dm crypt keys to kdump kernel Date: Fri, 2 May 2025 09:12:41 +0800 1st kernel will build up the kernel command parameter dmcryptkeys as similar to elfcorehdr to pass the memory address of the stored info of dm crypt key to kdump kernel. Link: https://lkml.kernel.org/r/20250502011246.99238-8-coxu@redhat.com Signed-off-by: Coiby Xu Acked-by: Baoquan He Cc: "Daniel P. Berrange" Cc: Dave Hansen Cc: Dave Young Cc: Jan Pazdziora Cc: Liu Pingfan Cc: Milan Broz Cc: Ondrej Kozina Cc: Vitaly Kuznetsov Signed-off-by: Andrew Morton --- Documentation/admin-guide/kdump/kdump.rst | 4 +-- arch/x86/kernel/crash.c | 26 ++++++++++++++++++-- arch/x86/kernel/kexec-bzimage64.c | 21 ++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) --- a/arch/x86/kernel/crash.c~x86-crash-pass-dm-crypt-keys-to-kdump-kernel +++ a/arch/x86/kernel/crash.c @@ -278,6 +278,7 @@ static int memmap_exclude_ranges(struct unsigned long long mend) { unsigned long start, end; + int ret; cmem->ranges[0].start = mstart; cmem->ranges[0].end = mend; @@ -286,22 +287,43 @@ static int memmap_exclude_ranges(struct /* Exclude elf header region */ start = image->elf_load_addr; end = start + image->elf_headers_sz - 1; - return crash_exclude_mem_range(cmem, start, end); + ret = crash_exclude_mem_range(cmem, start, end); + + if (ret) + return ret; + + /* Exclude dm crypt keys region */ + if (image->dm_crypt_keys_addr) { + start = image->dm_crypt_keys_addr; + end = start + image->dm_crypt_keys_sz - 1; + return crash_exclude_mem_range(cmem, start, end); + } + + return ret; } /* Prepare memory map for crash dump kernel */ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params) { + unsigned int nr_ranges = 0; int i, ret = 0; unsigned long flags; struct e820_entry ei; struct crash_memmap_data cmd; struct crash_mem *cmem; - cmem = vzalloc(struct_size(cmem, ranges, 1)); + /* + * Using random kexec_buf for passing dm crypt keys may cause a range + * split. So use two slots here. + */ + nr_ranges = 2; + cmem = vzalloc(struct_size(cmem, ranges, nr_ranges)); if (!cmem) return -ENOMEM; + cmem->max_nr_ranges = nr_ranges; + cmem->nr_ranges = 0; + memset(&cmd, 0, sizeof(struct crash_memmap_data)); cmd.params = params; --- a/arch/x86/kernel/kexec-bzimage64.c~x86-crash-pass-dm-crypt-keys-to-kdump-kernel +++ a/arch/x86/kernel/kexec-bzimage64.c @@ -27,6 +27,8 @@ #include #define MAX_ELFCOREHDR_STR_LEN 30 /* elfcorehdr=0x<64bit-value> */ +#define MAX_DMCRYPTKEYS_STR_LEN 31 /* dmcryptkeys=0x<64bit-value> */ + /* * Defines lowest physical address for various segments. Not sure where @@ -76,6 +78,10 @@ static int setup_cmdline(struct kimage * if (image->type == KEXEC_TYPE_CRASH) { len = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ", image->elf_load_addr); + + if (image->dm_crypt_keys_addr != 0) + len += sprintf(cmdline_ptr + len, + "dmcryptkeys=0x%lx ", image->dm_crypt_keys_addr); } memcpy(cmdline_ptr + len, cmdline, cmdline_len); cmdline_len += len; @@ -474,6 +480,19 @@ static void *bzImage64_load(struct kimag ret = crash_load_segments(image); if (ret) return ERR_PTR(ret); + ret = crash_load_dm_crypt_keys(image); + if (ret == -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 && + cmdline_len + MAX_ELFCOREHDR_STR_LEN + MAX_DMCRYPTKEYS_STR_LEN > + header->cmdline_size) { + pr_err("Appending dmcryptkeys= to command line exceeds maximum allowed length\n"); + return ERR_PTR(-EINVAL); + } } #endif @@ -501,6 +520,8 @@ static void *bzImage64_load(struct kimag efi_map_sz = efi_get_runtime_map_size(); params_cmdline_sz = sizeof(struct boot_params) + cmdline_len + MAX_ELFCOREHDR_STR_LEN; + if (image->dm_crypt_keys_addr) + params_cmdline_sz += MAX_DMCRYPTKEYS_STR_LEN; params_cmdline_sz = ALIGN(params_cmdline_sz, 16); kbuf.bufsz = params_cmdline_sz + ALIGN(efi_map_sz, 16) + sizeof(struct setup_data) + --- a/Documentation/admin-guide/kdump/kdump.rst~x86-crash-pass-dm-crypt-keys-to-kdump-kernel +++ a/Documentation/admin-guide/kdump/kdump.rst @@ -551,8 +551,8 @@ Write the dump file to encrypted disk vo ============================================ CONFIG_CRASH_DM_CRYPT can be enabled to support saving the dump file to an -encrypted disk volume. User space can interact with -/sys/kernel/config/crash_dm_crypt_keys for setup, +encrypted disk volume (only x86_64 supported for now). User space can interact +with /sys/kernel/config/crash_dm_crypt_keys for setup, 1. Tell the first kernel what logon keys are needed to unlock the disk volumes, # Add key #1 _ Patches currently in -mm which might be from coxu@redhat.com are kexec_file-allow-to-place-kexec_buf-randomly.patch crash_dump-make-dm-crypt-keys-persist-for-the-kdump-kernel.patch crash_dump-store-dm-crypt-keys-in-kdump-reserved-memory.patch crash_dump-reuse-saved-dm-crypt-keys-for-cpu-memory-hot-plugging.patch crash_dump-retrieve-dm-crypt-keys-in-kdump-kernel.patch revert-x86-mm-remove-unused-__set_memory_prot.patch x86-crash-pass-dm-crypt-keys-to-kdump-kernel.patch x86-crash-make-the-page-that-stores-the-dm-crypt-keys-inaccessible.patch