Carry forward IMA measurement log on kexec on ARM64
Subsystems (8)
v17 cover Carry forward IMA measurement log on kexec on ARM64
On kexec file load Integrity Measurement Architecture (IMA) subsystem may verify the IMA signature of the kernel and initramfs, and measure it. The command line parameters passed to the kernel in the kexec call may also be measured by IMA. A remote attestation service can verify a TPM quote based on the TPM event log, the IMA measurement list, and the TPM PCR data. This can be achieved only if the IMA measurement log is carried over from the current kernel to the next kernel across the kexec call.
powerpc already supports carrying forward the IMA measurement log on kexec. This patch set adds support for carrying forward the IMA measurement log on kexec on ARM64.
This patch set moves the platform independent code defined for powerpc such that it can be reused for other platforms as well. A chosen node "linux,ima-kexec-buffer" is added to the DTB for ARM64 to hold the address and the size of the memory reserved to carry the IMA measurement log.
This patch set has been tested for ARM64 platform using QEMU. I would like help from the community for testing this change on powerpc. Thanks.
This patch set is based on
commit 96acc833dec8 ("ima: Free IMA measurement buffer after kexec syscall") in https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
"next-integrity" branch.
Changelog:
v17
- Renamed of_kexec_setup_new_fdt() to of_kexec_alloc_and_setup_fdt(), and moved memory allocation for the new FDT to this function.
v16
- Defined functions to allocate and free buffer for FDT for powerpc
and arm64.
- Moved ima_buffer_addr and ima_buffer_size fields from "struct kimage_arch" in powerpc to "struct kimage"
v15
- Included Rob's patches in the patch set, and rebased the changes to "next-integrity" branch.
- Allocate memory for DTB, on arm64, using kmalloc() instead of vmalloc() to keep it consistent with powerpc implementation.
- Call of_kexec_setup_new_fdt() from setup_new_fdt_ppc64() and remove setup_new_fdt() in the same patch to keep it bisect safe.
v14
- Select CONFIG_HAVE_IMA_KEXEC for CONFIG_KEXEC_FILE, for powerpc and arm64, if CONFIG_IMA is enabled.
- Use IS_ENABLED() macro instead of "#ifdef" in remove_ima_buffer(), ima_get_kexec_buffer(), and ima_free_kexec_buffer().
- Call of_kexec_setup_new_fdt() from setup_new_fdt_ppc64() and remove setup_new_fdt() in "arch/powerpc/kexec/file_load.c".
v13
- Moved the arch independent functions to drivers/of/kexec.c and then refactored the code.
- Moved arch_ima_add_kexec_buffer() to security/integrity/ima/ima_kexec.c
v12
- Use fdt_appendprop_addrrange() in setup_ima_buffer() to setup the IMA measurement list property in the device tree.
- Moved architecture independent functions from "arch/powerpc/kexec/ima.c" to "drivers/of/kexec."
- Deleted "arch/powerpc/kexec/ima.c" and "arch/powerpc/include/asm/ima.h".
v11
- Rebased the changes on the kexec code refactoring done by Rob Herring in his "dt/kexec" branch
- Removed "extern" keyword in function declarations
- Removed unnecessary header files included in C files
- Updated patch descriptions per Thiago's comments
v10
- Moved delete_fdt_mem_rsv(), remove_ima_buffer(), get_ima_kexec_buffer, and get_root_addr_size_cells() to drivers/of/kexec.c
- Moved arch_ima_add_kexec_buffer() to security/integrity/ima/ima_kexec.c
- Conditionally define IMA buffer fields in struct kimage_arch
v9
- Moved delete_fdt_mem_rsv() to drivers/of/kexec_fdt.c
- Defined a new function get_ima_kexec_buffer() in drivers/of/ima_kexec.c to replace do_get_kexec_buffer()
- Changed remove_ima_kexec_buffer() to the original function name remove_ima_buffer()
- Moved remove_ima_buffer() to drivers/of/ima_kexec.c
- Moved ima_get_kexec_buffer() and ima_free_kexec_buffer() to security/integrity/ima/ima_kexec.c
v8:
- Moved remove_ima_kexec_buffer(), do_get_kexec_buffer(), and delete_fdt_mem_rsv() to drivers/of/fdt.c
- Moved ima_dump_measurement_list() and ima_add_kexec_buffer() back to security/integrity/ima/ima_kexec.c
v7:
- Renamed remove_ima_buffer() to remove_ima_kexec_buffer() and moved this function definition to kernel.
- Moved delete_fdt_mem_rsv() definition to kernel
- Moved ima_dump_measurement_list() and ima_add_kexec_buffer() to a new file namely ima_kexec_fdt.c in IMA
v6:
- Remove any existing FDT_PROP_IMA_KEXEC_BUFFER property in the device tree and also its corresponding memory reservation in the currently running kernel.
- Moved the function remove_ima_buffer() defined for powerpc to IMA and renamed the function to ima_remove_kexec_buffer(). Also, moved delete_fdt_mem_rsv() from powerpc to IMA.
v5:
- Merged get_addr_size_cells() and do_get_kexec_buffer() into a single function when moving the arch independent code from powerpc to IMA
- Reverted the change to use FDT functions in powerpc code and added back the original code in get_addr_size_cells() and do_get_kexec_buffer() for powerpc.
- Added fdt_add_mem_rsv() for ARM64 to reserve the memory for the IMA log buffer during kexec.
- Fixed the warning reported by kernel test bot for ARM64 arch_ima_add_kexec_buffer() - moved this function to a new file namely arch/arm64/kernel/ima_kexec.c
v4:
- Submitting the patch series on behalf of the original author Prakhar Srivastava <[email protected]>
- Moved FDT_PROP_IMA_KEXEC_BUFFER ("linux,ima-kexec-buffer") to libfdt.h so that it can be shared by multiple platforms.
v3:
Breakup patches further into separate patches.
- Refactoring non architecture specific code out of powerpc
- Update powerpc related code to use fdt functions
- Update IMA buffer read related code to use of functions
- Add support to store the memory information of the IMA measurement logs to be carried forward.
- Update the property strings to align with documented nodes
https://github.com/devicetree-org/dt-schema/pull/46
v2:
Break patches into separate patches.
- Powerpc related Refactoring
- Updating the docuemntation for chosen node
- Updating arm64 to support IMA buffer pass
v1:
Refactoring carrying over IMA measuremnet logs over Kexec. This patch
moves the non-architecture specific code out of powerpc and adds to security/ima.(Suggested by Thiago)
Add Documentation regarding the ima-kexec-buffer node in the chosen
node documentation
v0:
Add a layer of abstraction to use the memory reserved by device tree
for ima buffer pass.
Add support for ima buffer pass using reserved memory for arm64 kexec.
Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.
Lakshmi Ramasubramanian (6):
powerpc: Move ima buffer fields to struct kimage
powerpc: Enable passing IMA log to next kernel on kexec
powerpc: Move arch independent ima kexec functions to
drivers/of/kexec.c
kexec: Use fdt_appendprop_addrrange() to add ima buffer to FDT
powerpc: Delete unused function delete_fdt_mem_rsv()
arm64: Enable passing IMA log to next kernel on kexec
Rob Herring (4):
powerpc: Rename kexec elfcorehdr_addr to elf_headers_mem
of: Add a common kexec FDT setup function
arm64: Use common of_kexec_alloc_and_setup_fdt()
powerpc: Use common of_kexec_alloc_and_setup_fdt()
arch/arm64/Kconfig | 1 + arch/arm64/kernel/machine_kexec_file.c | 180 +--------- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/ima.h | 30 -- arch/powerpc/include/asm/kexec.h | 12 +- arch/powerpc/kexec/Makefile | 7 - arch/powerpc/kexec/elf_64.c | 29 +- arch/powerpc/kexec/file_load.c | 183 +--------- arch/powerpc/kexec/file_load_64.c | 11 +- arch/powerpc/kexec/ima.c | 219 ------------ drivers/of/Makefile | 6 + drivers/of/kexec.c | 473 +++++++++++++++++++++++++ include/linux/kexec.h | 3 + include/linux/of.h | 20 ++ security/integrity/ima/ima.h | 4 - security/integrity/ima/ima_kexec.c | 3 +- 16 files changed, 539 insertions(+), 644 deletions(-) delete mode 100644 arch/powerpc/include/asm/ima.h delete mode 100644 arch/powerpc/kexec/ima.c create mode 100644 drivers/of/kexec.c
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 1/10 powerpc: Rename kexec elfcorehdr_addr to elf_headers_mem
From: Rob Herring <[email protected]>
The architecture specific field, elfcorehdr_addr in struct kimage_arch, that holds the address of the buffer in memory for ELF core header for powerpc has a different name than the one used for arm64. This makes it hard to have a common code for setting up the device tree for kexec system call.
Rename elfcorehdr_addr to elf_headers_mem to align with arm64 name so common code can use it.
--- arch/powerpc/include/asm/kexec.h | 2 +- arch/powerpc/kexec/file_load.c | 4 ++-- arch/powerpc/kexec/file_load_64.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/kexec.h +1 -1
@@ -108,7 +108,7 @@ struct kimage_arch {unsigned long backup_start;void *backup_buf; -unsigned long elfcorehdr_addr; +unsigned long elf_headers_mem;unsigned long elf_headers_sz;void *elf_headers;
arch/powerpc/kexec/file_load.c +2 -2
@@ -45,7 +45,7 @@ char *setup_kdump_cmdline(struct kimage *image, char *cmdline,return NULL ; elfcorehdr_strlen =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , - image->arch.elfcorehdr_addr); + image->arch.elf_headers_mem);if (elfcorehdr_strlen + cmdline_len >COMMAND_LINE_SIZE ) {pr_err ("Appending elfcorehdr=<addr> exceeds cmdline size\n" );
@@ -263,7 +263,7 @@ int setup_new_fdt(const struct kimage *image, void *fdt,* Avoid elfcorehdr from being stomped on in kdump kernel by * setting up memory reserve map. */ - ret =fdt_add_mem_rsv (fdt, image->arch.elfcorehdr_addr, + ret =fdt_add_mem_rsv (fdt, image->arch.elf_headers_mem, image->arch.elf_headers_sz);if (ret) { pr_err("Error reserving elfcorehdr memory: %s\n",
arch/powerpc/kexec/file_load_64.c +2 -2
@@ -815,7 +815,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) goto out; } - image->arch.elfcorehdr_addr = kbuf->mem; + image->arch.elf_headers_mem = kbuf->mem; image->arch.elf_headers_sz = headers_sz; image->arch.elf_headers = headers; out:
@@ -851,7 +851,7 @@ int load_crashdump_segments_ppc64(struct kimage *image,return ret; }pr_debug ("Loaded elf core header at 0x%lx, bufsz=0x%lx memsz=0x%lx\n" , - image->arch.elfcorehdr_addr, kbuf->bufsz, kbuf->memsz); + image->arch.elf_headers_mem, kbuf->bufsz, kbuf->memsz);return 0 ; }
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 2/10 of: Add a common kexec FDT setup function
In reply to Lakshmi RamasubramanianFrom: Rob Herring <[email protected]>
Both arm64 and powerpc do essentially the same FDT /chosen setup for kexec. The differences are either omissions that arm64 should have or additional properties that will be ignored. The setup code can be combined and shared by both powerpc and arm64.
The differences relative to the arm64 version:
- If /chosen doesn't exist, it will be created (should never happen).
- Any old dtb and initrd reserved memory will be released.
- The new initrd and elfcorehdr are marked reserved.
- "linux,booted-from-kexec" is set.
The differences relative to the powerpc version:
- "kaslr-seed" and "rng-seed" may be set.
- "linux,elfcorehdr" is set.
- Any existing "linux,usable-memory-range" is removed.
Combine the code for setting up the /chosen node in the FDT and updating the memory reservation for kexec, for powerpc and arm64, in of_kexec_alloc_and_setup_fdt() and move it to "drivers/of/kexec.c".
--- drivers/of/Makefile | 6 ++ drivers/of/kexec.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++ 3 files changed, 277 insertions(+) create mode 100644 drivers/of/kexec.c
drivers/of/Makefile +6 -0
@@ -14,4 +14,10 @@ obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +ifdef CONFIG_KEXEC_FILE +ifdef CONFIG_OF_FLATTREE +obj-y += kexec.o +endif +endif + obj-$(CONFIG_OF_UNITTEST) += unittest-data/
drivers/of/kexec.c new file +258 -0
258 lines not on this page · raw message
include/linux/of.h +13 -0
@@ -560,6 +560,19 @@ int of_map_id(struct device_node *np, u32 id,phys_addr_t of_dma_get_max_cpu_address (struct device_node *np); +/* +* Additional space needed for the buffer to build the new FDT +* so that we can add initrd, bootargs, kaslr-seed, rng-seed, +* userable-memory-range and elfcorehdr. +*/ +#define FDT_EXTRA_SPACE 0x1000 + +struct kimage ; +void *of_kexec_alloc_and_setup_fdt (const struct kimage *image, +unsigned long initrd_load_addr, +unsigned long initrd_len, +const char *cmdline); +#else /* CONFIG_OF */ static inline void of_core_init (void )
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Rob Herring
maintainerRe: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 315 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
Both arm64 and powerpc do essentially the same FDT /chosen setup for kexec. The differences are either omissions that arm64 should have or additional properties that will be ignored. The setup code can be combined and shared by both powerpc and arm64.
The differences relative to the arm64 version:
- If /chosen doesn't exist, it will be created (should never happen).
- Any old dtb and initrd reserved memory will be released.
- The new initrd and elfcorehdr are marked reserved.
- "linux,booted-from-kexec" is set.The differences relative to the powerpc version:
- "kaslr-seed" and "rng-seed" may be set.
- "linux,elfcorehdr" is set.
- Any existing "linux,usable-memory-range" is removed.Combine the code for setting up the /chosen node in the FDT and updating the memory reservation for kexec, for powerpc and arm64, in
of_kexec_alloc_and_setup_fdt()and move it to "drivers/of/kexec.c".Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- drivers/of/Makefile | 6 ++ drivers/of/kexec.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++ 3 files changed, 277 insertions(+) create mode 100644 drivers/of/kexec.cdrivers/of/Makefile +6
-0@@ -14,4 +14,10 @@ obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +ifdef CONFIG_KEXEC_FILE +ifdef CONFIG_OF_FLATTREE +obj-y += kexec.o +endif +endif + obj-$(CONFIG_OF_UNITTEST) += unittest-data/drivers/of/kexec.c new file +258
-0@@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020 Arm Limited +* +* Based on arch/arm64/kernel/machine_kexec_file.c: +* Copyright (C) 2018 Linaro Limited +* +* And arch/powerpc/kexec/file_load.c: +* Copyright (C) 2016 IBM Corporation +*/ + +#include <linux/kernel.h> +#include <linux/kexec.h> +#include <linux/libfdt.h> +#include <linux/of.h> +#include <linux/of_fdt.h> +#include <linux/random.h> +#include <linux/types.h> + +/* relevant device tree properties */ +#define FDT_PROP_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PROP_MEM_RANGE "linux,usable-memory-range" +#define FDT_PROP_INITRD_START "linux,initrd-start" +#define FDT_PROP_INITRD_END "linux,initrd-end" +#define FDT_PROP_BOOTARGS "bootargs" +#define FDT_PROP_KASLR_SEED "kaslr-seed" +#define FDT_PROP_RNG_SEED "rng-seed" +#define RNG_SEED_SIZE 128 + +/** +* fdt_find_and_del_mem_rsv - delete memory reservation with given address and size +* +* @fdt: Flattened device tree for the current kernel. +* @start: Starting address of the reserved memory. +* @size: Size of the reserved memory. +* +* Return: 0 on success, or negative errno on error. +*/ +static int fdt_find_and_del_mem_rsv (void *fdt,unsigned long start,unsigned long size) +{ +int i, ret, num_rsvs =fdt_num_mem_rsv (fdt); + +for (i =0 ; i < num_rsvs; i++) { +u64 rsv_start, rsv_size; + + ret =fdt_get_mem_rsv (fdt, i, &rsv_start, &rsv_size); +if (ret) { +pr_err ("Malformed device tree.\n" ); +return -EINVAL ; + } + +if (rsv_start == start && rsv_size == size) { + ret =fdt_del_mem_rsv (fdt, i); +if (ret) { +pr_err ("Error deleting device tree reservation.\n" ); +return -EINVAL ; + } + +return 0 ; + } + } + +return -ENOENT ; +} + +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt (const struct kimage *image, +unsigned long initrd_load_addr, +unsigned long initrd_len, +const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ; + + fdt =kvmalloc (fdt_size,GFP_KERNEL ); +if (!fdt) +return NULL ; + + ret =fdt_open_into (initial_boot_params, fdt, fdt_size); +if (ret <0 ) { +pr_err ("Error %d setting up the new device tree.\n" , ret); + goto out; + } + +/* Remove memory reservation for the current device tree. */ + ret =fdt_find_and_del_mem_rsv (fdt,__pa (initial_boot_params), +fdt_totalsize (initial_boot_params)); +if (ret == -EINVAL ) { +pr_err ("Error removing memory reservation.\n" ); + goto out; + } + + chosen_node =fdt_path_offset (fdt,"/chosen" ); +if (chosen_node == -FDT_ERR_NOTFOUND ) + chosen_node =fdt_add_subnode (fdt,fdt_path_offset (fdt,"/" ), +"chosen" ); +if (chosen_node <0 ) { + ret = chosen_node; + goto out; + } + + ret =fdt_delprop (fdt, chosen_node,FDT_PROP_KEXEC_ELFHDR ); +if (ret && ret != -FDT_ERR_NOTFOUND ) + goto out; + ret =fdt_delprop (fdt, chosen_node,FDT_PROP_MEM_RANGE ); +if (ret && ret != -FDT_ERR_NOTFOUND ) + goto out; + +/* Did we boot using an initrd? */ + prop =fdt_getprop (fdt, chosen_node,"linux,initrd-start" ,NULL ); +if (prop) { +u64 tmp_start, tmp_end, tmp_size; + + tmp_start =fdt64_to_cpu (*((const fdt64_t *) prop)); + + prop =fdt_getprop (fdt, chosen_node,"linux,initrd-end" ,NULL ); +if (!prop) { + ret = -EINVAL ; + goto out; + } + + tmp_end =fdt64_to_cpu (*((const fdt64_t *) prop)); + +/* +* kexec reserves exact initrd size, while firmware may +* reserve a multiple of PAGE_SIZE, so check for both. +*/ + tmp_size = tmp_end - tmp_start; + ret =fdt_find_and_del_mem_rsv (fdt, tmp_start, tmp_size); +if (ret == -ENOENT ) + ret =fdt_find_and_del_mem_rsv (fdt, tmp_start, +round_up (tmp_size,PAGE_SIZE )); +if (ret == -EINVAL ) + goto out; + } + +/* add initrd-* */ +if (initrd_load_addr) { + ret =fdt_setprop_u64 (fdt, chosen_node,FDT_PROP_INITRD_START , + initrd_load_addr); +if (ret) + goto out; + + ret =fdt_setprop_u64 (fdt, chosen_node,FDT_PROP_INITRD_END , + initrd_load_addr + initrd_len); +if (ret) + goto out; + + ret =fdt_add_mem_rsv (fdt, initrd_load_addr, initrd_len); +if (ret) + goto out; + + }else { + ret =fdt_delprop (fdt, chosen_node,FDT_PROP_INITRD_START ); +if (ret && (ret != -FDT_ERR_NOTFOUND )) + goto out; + + ret =fdt_delprop (fdt, chosen_node,FDT_PROP_INITRD_END ); +if (ret && (ret != -FDT_ERR_NOTFOUND )) + goto out; + } + +if (image->type ==KEXEC_TYPE_CRASH ) { +/* add linux,elfcorehdr */ + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node, +FDT_PROP_KEXEC_ELFHDR , + image->arch.elf_headers_mem, + image->arch.elf_headers_sz); +if (ret) + goto out; + +/* +* Avoid elfcorehdr from being stomped on in kdump kernel by +* setting up memory reserve map. +*/ + ret =fdt_add_mem_rsv (fdt, image->arch.elf_headers_mem, + image->arch.elf_headers_sz); +if (ret) + goto out; + +/* add linux,usable-memory-range */ + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node, +FDT_PROP_MEM_RANGE , + crashk_res.start, + crashk_res.end - crashk_res.start +1 ); +if (ret) + goto out; + } + +/* add bootargs */ +if (cmdline) { + ret =fdt_setprop_string (fdt, chosen_node,FDT_PROP_BOOTARGS , cmdline); +if (ret) + goto out; + }else { + ret =fdt_delprop (fdt, chosen_node,FDT_PROP_BOOTARGS ); +if (ret && (ret != -FDT_ERR_NOTFOUND )) + goto out; + } + +/* add kaslr-seed */ + ret =fdt_delprop (fdt, chosen_node,FDT_PROP_KASLR_SEED ); +if (ret == -FDT_ERR_NOTFOUND ) + ret =0 ; +else if (ret) + goto out; + +if (rng_is_initialized ()) { +u64 seed =get_random_u64 (); + + ret =fdt_setprop_u64 (fdt, chosen_node,FDT_PROP_KASLR_SEED , seed); +if (ret) + goto out; + }else { +pr_notice ("RNG is not initialised: omitting \"%s\" property\n" , +FDT_PROP_KASLR_SEED ); + } + +/* add rng-seed */ +if (rng_is_initialized ()) { +void *rng_seed; + + ret =fdt_setprop_placeholder (fdt, chosen_node,FDT_PROP_RNG_SEED , +RNG_SEED_SIZE , &rng_seed); +if (ret) + goto out; +get_random_bytes (rng_seed,RNG_SEED_SIZE ); + }else { +pr_notice ("RNG is not initialised: omitting \"%s\" property\n" , +FDT_PROP_RNG_SEED ); + } + + ret =fdt_setprop (fdt, chosen_node,"linux,booted-from-kexec" ,NULL ,0 ); + +out: +if (ret) { +kvfree (fdt); + fdt =NULL ; + } + +return fdt; +}include/linux/of.h +0
-0
include/linux/of.h int of_map_id(struct device_node *np, u32 id, · line 568
Quoted 9 lines
include/linux/of.h +6
-0@@ -560,6 +560,19 @@ int of_map_id(struct device_node *np, u32 id,phys_addr_t of_dma_get_max_cpu_address (struct device_node *np); +/* +* Additional space needed for the buffer to build the new FDT +* so that we can add initrd, bootargs, kaslr-seed, rng-seed, +* userable-memory-range and elfcorehdr. +*/ +#define FDT_EXTRA_SPACE 0x1000
No need for this to be public now. Move it to of/kexec.c.
Rob
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 41 lines · Rob Herring
Quoted 40 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
Both arm64 and powerpc do essentially the same FDT /chosen setup for kexec. The differences are either omissions that arm64 should have or additional properties that will be ignored. The setup code can be combined and shared by both powerpc and arm64.
The differences relative to the arm64 version:
- If /chosen doesn't exist, it will be created (should never happen).
- Any old dtb and initrd reserved memory will be released.
- The new initrd and elfcorehdr are marked reserved.
- "linux,booted-from-kexec" is set.The differences relative to the powerpc version:
- "kaslr-seed" and "rng-seed" may be set.
- "linux,elfcorehdr" is set.
- Any existing "linux,usable-memory-range" is removed.Combine the code for setting up the /chosen node in the FDT and updating the memory reservation for kexec, for powerpc and arm64, in
of_kexec_alloc_and_setup_fdt()and move it to "drivers/of/kexec.c".Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- drivers/of/Makefile | 6 ++ drivers/of/kexec.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++ 3 files changed, 277 insertions(+)create mode 100644
drivers/of/kexec.cinclude/linux/of.h +0
-0@@ -560,6 +560,19 @@ int of_map_id(struct device_node *np, u32 id,phys_addr_t of_dma_get_max_cpu_address (struct device_node *np);
Quoted 9 lines
include/linux/of.h int of_map_id(struct device_node *np, u32 id, · line 568
Quoted 6 lines
include/linux/of.h +6
-0+/* +* Additional space needed for the buffer to build the new FDT +* so that we can add initrd, bootargs, kaslr-seed, rng-seed, +* userable-memory-range and elfcorehdr. +*/ +#define FDT_EXTRA_SPACE 0x1000No need for this to be public now. Move it to
of/kexec.c.
Will do.
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
In reply to Lakshmi RamasubramanianQuoted 22 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
Both arm64 and powerpc do essentially the same FDT /chosen setup for kexec. The differences are either omissions that arm64 should have or additional properties that will be ignored. The setup code can be combined and shared by both powerpc and arm64.
The differences relative to the arm64 version:
- If /chosen doesn't exist, it will be created (should never happen).
- Any old dtb and initrd reserved memory will be released.
- The new initrd and elfcorehdr are marked reserved.
- "linux,booted-from-kexec" is set.The differences relative to the powerpc version:
- "kaslr-seed" and "rng-seed" may be set.
- "linux,elfcorehdr" is set.
- Any existing "linux,usable-memory-range" is removed.Combine the code for setting up the /chosen node in the FDT and updating the memory reservation for kexec, for powerpc and arm64, in
of_kexec_alloc_and_setup_fdt()and move it to "drivers/of/kexec.c".
Quoted 8 lines
Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- drivers/of/Makefile | 6 ++ drivers/of/kexec.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++ 3 files changed, 277 insertions(+) create mode 100644 drivers/of/kexec.c
Signature · 7 lines
Thiago Jung Bauermann IBM Linux Technology Center _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
kernel test robot
build botRe: [PATCH v17 02/10] of: Add a common kexec FDT setup function
In reply to Lakshmi RamasubramanianI love your patch! Yet something to improve:
Hi Lakshmi,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity]
[also build test ERROR on v5.11-rc7 next-20210211]
[cannot apply to powerpc/next robh/for-next arm64/for-next/core] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Lakshmi-Ramasubramanian/Carry-forward-IMA-measurement-log-on-kexec-on-ARM64/20210211-071924 base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity config: x86_64-randconfig-m001-20210211 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/12ae86067d115b84092353109e8798693d102f0d git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Lakshmi-Ramasubramanian/Carry-forward-IMA-measurement-log-on-kexec-on-ARM64/20210211-071924 git checkout 12ae86067d115b84092353109e8798693d102f0d # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/of/kexec.c: In function 'of_kexec_alloc_and_setup_fdt':
>> drivers/of/kexec.c:183:17: error: 'const struct kimage_arch' has no member named 'elf_headers_mem'; did you mean 'elf_headers_sz'?
183 | image->arch.elf_headers_mem,
| ^~~~~~~~~~~~~~~
| elf_headers_sz
drivers/of/kexec.c:192:42: error: 'const struct kimage_arch' has no member named 'elf_headers_mem'; did you mean 'elf_headers_sz'?
192 | ret = fdt_add_mem_rsv(fdt, image->arch.elf_headers_mem,
| ^~~~~~~~~~~~~~~
| elf_headers_szvim +183 drivers/of/kexec.c
65
66 /*
67 * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree
68 *
69 * @image: kexec image being loaded.
70 * @initrd_load_addr: Address where the next initrd will be loaded.
71 * @initrd_len: Size of the next initrd, or 0 if there will be none.
72 * @cmdline: Command line for the next kernel, or NULL if there will
73 * be none.
74 *
75 * Return: fdt on success, or NULL errno on error.
76 */
77 void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
78 unsigned long initrd_load_addr,
79 unsigned long initrd_len,
80 const char *cmdline)
81 {
82 void *fdt;
83 int ret, chosen_node;
84 const void *prop;
85 unsigned long fdt_size;
86
87 fdt_size = fdt_totalsize(initial_boot_params) +
88 (cmdline ? strlen(cmdline) : 0) +
89 FDT_EXTRA_SPACE;
90
91 fdt = kvmalloc(fdt_size, GFP_KERNEL);
92 if (!fdt)
93 return NULL;
94
95 ret = fdt_open_into(initial_boot_params, fdt, fdt_size);
96 if (ret < 0) {
97 pr_err("Error %d setting up the new device tree.\n", ret);
98 goto out;
99 }
100
101 /* Remove memory reservation for the current device tree. */
102 ret = fdt_find_and_del_mem_rsv(fdt, __pa(initial_boot_params),
103 fdt_totalsize(initial_boot_params));
104 if (ret == -EINVAL) {
105 pr_err("Error removing memory reservation.\n");
106 goto out;
107 }
108
109 chosen_node = fdt_path_offset(fdt, "/chosen");
110 if (chosen_node == -FDT_ERR_NOTFOUND)
111 chosen_node = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"),
112 "chosen");
113 if (chosen_node < 0) {
114 ret = chosen_node;
115 goto out;
116 }
117
118 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_KEXEC_ELFHDR);
119 if (ret && ret != -FDT_ERR_NOTFOUND)
120 goto out;
121 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_MEM_RANGE);
122 if (ret && ret != -FDT_ERR_NOTFOUND)
123 goto out;
124
125 /* Did we boot using an initrd? */
126 prop = fdt_getprop(fdt, chosen_node, "linux,initrd-start", NULL);
127 if (prop) {
128 u64 tmp_start, tmp_end, tmp_size;
129
130 tmp_start = fdt64_to_cpu(*((const fdt64_t *) prop));
131
132 prop = fdt_getprop(fdt, chosen_node, "linux,initrd-end", NULL);
133 if (!prop) {
134 ret = -EINVAL;
135 goto out;
136 }
137
138 tmp_end = fdt64_to_cpu(*((const fdt64_t *) prop));
139
140 /*
141 * kexec reserves exact initrd size, while firmware may
142 * reserve a multiple of PAGE_SIZE, so check for both.
143 */
144 tmp_size = tmp_end - tmp_start;
145 ret = fdt_find_and_del_mem_rsv(fdt, tmp_start, tmp_size);
146 if (ret == -ENOENT)
147 ret = fdt_find_and_del_mem_rsv(fdt, tmp_start,
148 round_up(tmp_size, PAGE_SIZE));
149 if (ret == -EINVAL)
150 goto out;
151 }
152
153 /* add initrd-* */
154 if (initrd_load_addr) {
155 ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_START,
156 initrd_load_addr);
157 if (ret)
158 goto out;
159
160 ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_END,
161 initrd_load_addr + initrd_len);
162 if (ret)
163 goto out;
164
165 ret = fdt_add_mem_rsv(fdt, initrd_load_addr, initrd_len);
166 if (ret)
167 goto out;
168
169 } else {
170 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_START);
171 if (ret && (ret != -FDT_ERR_NOTFOUND))
172 goto out;
173
174 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_END);
175 if (ret && (ret != -FDT_ERR_NOTFOUND))
176 goto out;
177 }
178
179 if (image->type == KEXEC_TYPE_CRASH) {
180 /* add linux,elfcorehdr */
181 ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
182 FDT_PROP_KEXEC_ELFHDR,
> 183 image->arch.elf_headers_mem,---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Hi Rob,
[PATCH] powerpc: Rename kexec elfcorehdr_addr to elf_headers_mem
This change causes build problem for x86_64 architecture (please see the mail from kernel test bot below) since arch/x86/include/asm/kexec.h uses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".
struct kimage_arch {
...
/* Core ELF header buffer */
void *elf_headers;
unsigned long elf_headers_sz;
unsigned long elf_load_addr;
};I am thinking of limiting of_kexec_alloc_and_setup_fdt() to ARM64 and PPC64 since they are the only ones using this function now.
#if defined(CONFIG_ARM64) && defined(CONFIG_PPC64)
void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
unsigned long initrd_load_addr, unsigned long initrd_len, const char *cmdline)
{
...
}#endif /* defined(CONFIG_ARM64) && defined(CONFIG_PPC64) */
Please let me know if you have any concerns.
thanks,
-lakshmi
-------- Forwarded Message --------
Subject: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Date: Fri, 12 Feb 2021 00:50:20 +0800
From: kernel test robot <[email protected]>
To: Lakshmi Ramasubramanian <[email protected]>
CC: [email protected]
Hi Lakshmi,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity]
[also build test ERROR on v5.11-rc7 next-20210211]
[cannot apply to powerpc/next robh/for-next arm64/for-next/core] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Lakshmi-Ramasubramanian/Carry-forward-IMA-measurement-log-on-kexec-on-ARM64/20210211-071924
base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity
config: x86_64-randconfig-m001-20210211 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
#
https://github.com/0day-ci/linux/commit/12ae86067d115b84092353109e8798693d102f0d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review
Lakshmi-Ramasubramanian/Carry-forward-IMA-measurement-log-on-kexec-on-ARM64/20210211-071924
git checkout 12ae86067d115b84092353109e8798693d102f0d
# save the attached .config to linux build tree
make W=1 ARCH=x86_64If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/of/kexec.c: In function 'of_kexec_alloc_and_setup_fdt':
Quoted 1 line
Quoted 1 line
drivers/of/kexec.c:183:17: error: 'const structkimage_arch' has no member named 'elf_headers_mem'; did you mean 'elf_headers_sz'?
183 | image->arch.elf_headers_mem,
| ^~~~~~~~~~~~~~~
| elf_headers_sz
drivers/of/kexec.c:192:42: error: 'const struct kimage_arch' has no
member named 'elf_headers_mem'; did you mean 'elf_headers_sz'?
192 | ret = fdt_add_mem_rsv(fdt, image->arch.elf_headers_mem,
| ^~~~~~~~~~~~~~~
| elf_headers_szvim +183 drivers/of/kexec.c
65
66 /*
67 * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree
68 *
69 * @image: kexec image being loaded.
70 * @initrd_load_addr: Address where the next initrd will be loaded.
71 * @initrd_len: Size of the next initrd, or 0 if there will be
none.
72 * @cmdline: Command line for the next kernel, or NULL if there
will
73 * be none.
74 *
75 * Return: fdt on success, or NULL errno on error.
76 */
77 void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
78 unsigned long initrd_load_addr,
79 unsigned long initrd_len,
80 const char *cmdline)
81 {
82 void *fdt;
83 int ret, chosen_node;
84 const void *prop;
85 unsigned long fdt_size;
86
87 fdt_size = fdt_totalsize(initial_boot_params) +
88 (cmdline ? strlen(cmdline) : 0) +
89 FDT_EXTRA_SPACE;
90
91 fdt = kvmalloc(fdt_size, GFP_KERNEL);
92 if (!fdt)
93 return NULL;
94
95 ret = fdt_open_into(initial_boot_params, fdt, fdt_size);
96 if (ret < 0) {
97 pr_err("Error %d setting up the new device tree.\n", ret);
98 goto out;
99 } 100
101 /* Remove memory reservation for the current device tree. */
102 ret = fdt_find_and_del_mem_rsv(fdt, __pa(initial_boot_params),
103 fdt_totalsize(initial_boot_params));
104 if (ret == -EINVAL) {
105 pr_err("Error removing memory reservation.\n");
106 goto out;
107 }
108
109 chosen_node = fdt_path_offset(fdt, "/chosen");
110 if (chosen_node == -FDT_ERR_NOTFOUND)
111 chosen_node = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"),
112 "chosen");
113 if (chosen_node < 0) {
114 ret = chosen_node;
115 goto out;
116 }
117
118 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_KEXEC_ELFHDR);
119 if (ret && ret != -FDT_ERR_NOTFOUND)
120 goto out;
121 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_MEM_RANGE);
122 if (ret && ret != -FDT_ERR_NOTFOUND)
123 goto out;
124
125 /* Did we boot using an initrd? */
126 prop = fdt_getprop(fdt, chosen_node, "linux,initrd-start", NULL);
127 if (prop) {
128 u64 tmp_start, tmp_end, tmp_size;
129
130 tmp_start = fdt64_to_cpu(*((const fdt64_t *) prop));
131
132 prop = fdt_getprop(fdt, chosen_node, "linux,initrd-end", NULL);
133 if (!prop) {
134 ret = -EINVAL;
135 goto out;
136 }
137
138 tmp_end = fdt64_to_cpu(*((const fdt64_t *) prop));
139
140 /*
141 * kexec reserves exact initrd size, while firmware may
142 * reserve a multiple of PAGE_SIZE, so check for both.
143 */
144 tmp_size = tmp_end - tmp_start;
145 ret = fdt_find_and_del_mem_rsv(fdt, tmp_start, tmp_size);
146 if (ret == -ENOENT)
147 ret = fdt_find_and_del_mem_rsv(fdt, tmp_start,
148 round_up(tmp_size, PAGE_SIZE));
149 if (ret == -EINVAL)
150 goto out;
151 }
152
153 /* add initrd-* */
154 if (initrd_load_addr) {
155 ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_START,
156 initrd_load_addr);
157 if (ret)
158 goto out;
159
160 ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_END,
161 initrd_load_addr + initrd_len);
162 if (ret)
163 goto out;
164
165 ret = fdt_add_mem_rsv(fdt, initrd_load_addr, initrd_len);
166 if (ret)
167 goto out;
168
169 } else {
170 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_START);
171 if (ret && (ret != -FDT_ERR_NOTFOUND))
172 goto out;
173
174 ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_END);
175 if (ret && (ret != -FDT_ERR_NOTFOUND))
176 goto out;
177 }
178
179 if (image->type == KEXEC_TYPE_CRASH) {
180 /* add linux,elfcorehdr */
181 ret = fdt_appendprop_addrrange(fdt, 0, chosen_node,
182 FDT_PROP_KEXEC_ELFHDR,
Quoted 1 line
183
image->arch.elf_headers_mem,
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 15 lines · Lakshmi Ramasubramanian
Hi Rob,
[PATCH] powerpc: Rename kexec
elfcorehdr_addrtoelf_headers_memThis change causes build problem for
x86_64architecture (please see the mail from kernel test bot below) sincearch/x86/include/asm/kexec.huses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".struct
kimage_arch{
.../* Core ELF header buffer */
void*elf_headers;
unsigned longelf_headers_sz;
unsigned longelf_load_addr;
};
Quoted 3 lines
I am thinking of limiting
of_kexec_alloc_and_setup_fdt()to ARM64 and PPC64 since they are the only ones using this function now.#if
defined(CONFIG_ARM64)&&defined(CONFIG_PPC64)
Sorry - I meant to say
#if defined(CONFIG_ARM64) || defined(CONFIG_PPC64)
Quoted 203 lines
void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
unsigned longinitrd_load_addr, unsigned longinitrd_len,
const char *cmdline)
{
...
}
#endif /*defined(CONFIG_ARM64)&&defined(CONFIG_PPC64)*/Please let me know if you have any concerns.
thanks,
-lakshmi-------- Forwarded Message --------
Subject: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Date: Fri, 12 Feb 2021 00:50:20 +0800
From: kernel test robot <[email protected]>
To: Lakshmi Ramasubramanian <[email protected]>
CC: [email protected]Hi Lakshmi,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity]
[also build test ERROR on v5.11-rc7 next-20210211]
[cannot apply to powerpc/next robh/for-next arm64/for-next/core] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity
config: x86_64-randconfig-m001-20210211 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
#
https://github.com/0day-ci/linux/commit/12ae86067d115b84092353109e8798693d102f0dgit remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review
Lakshmi-Ramasubramanian/Carry-forward-IMA-measurement-log-on-kexec-on-ARM64/20210211-071924git checkout
12ae86067d115b84092353109e8798693d102f0d# save the attached .config to linux build tree make W=1 ARCH=x86_64 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <[email protected]>All errors (new ones prefixed by >>):
drivers/of/kexec.c: In function 'of_kexec_alloc_and_setup_fdt':Quoted 1 line
Quoted 1 line
drivers/of/kexec.c:183:17: error: 'const structkimage_arch' has no member named 'elf_headers_mem'; did you mean 'elf_headers_sz'?183 |
image->arch.elf_headers_mem,
| ^~~~~~~~~~~~~~~
|elf_headers_szdrivers/of/kexec.c:192:42: error: 'const structkimage_arch' has no
member named 'elf_headers_mem'; did you mean 'elf_headers_sz'?
192 | ret = fdt_add_mem_rsv(fdt,image->arch.elf_headers_mem, | ^~~~~~~~~~~~~~~ |elf_headers_szvim +183
drivers/of/kexec.c65
66 /*
67 *of_kexec_alloc_and_setup_fdt- Alloc and setup a new
Flattened Device Tree
68 *
69 * @image: kexec image being loaded.
70 * @initrd_load_addr: Address where the next initrd will
be loaded.
71 * @initrd_len: Size of the next initrd, or 0 if there
will be none.
72 * @cmdline: Command line for the next kernel, or NULL
if there will
73 * be none.
74 *
75 * Return: fdt on success, or NULL errno on error. 76 */
77 void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, 78 unsigned longinitrd_load_addr, 79 unsigned longinitrd_len,
80 const char *cmdline)
81 {
82 void *fdt;
83 int ret,chosen_node;
84 const void *prop;
85 unsigned longfdt_size;
86
87fdt_size=fdt_totalsize(initial_boot_params)+ 88 (cmdline ? strlen(cmdline) : 0) +
89FDT_EXTRA_SPACE;
90
91 fdt =kvmalloc(fdt_size, GFP_KERNEL);
92 if (!fdt)
93 return NULL;
94
95 ret =fdt_open_into(initial_boot_params, fdt, fdt_size); 96 if (ret < 0) {
97 pr_err("Error %d setting up the new device tree.\n",
ret);
98 goto out;
99 }
100
101 /* Remove memory reservation for the current device tree. */ 102 ret = fdt_find_and_del_mem_rsv(fdt,__pa(initial_boot_params),
103fdt_totalsize(initial_boot_params)); 104 if (ret ==-EINVAL) {
105pr_err("Error removing memory reservation.\n"); 106 goto out;
107 }
108
109chosen_node=fdt_path_offset(fdt, "/chosen"); 110 if (chosen_node== -FDT_ERR_NOTFOUND)
111chosen_node= fdt_add_subnode(fdt,fdt_path_offset(fdt, "/"),
112 "chosen");
113 if (chosen_node< 0) {
114 ret =chosen_node;
115 goto out;
116 }
117
118 ret =fdt_delprop(fdt, chosen_node, FDT_PROP_KEXEC_ELFHDR); 119 if (ret && ret != -FDT_ERR_NOTFOUND)
120 goto out;
121 ret =fdt_delprop(fdt, chosen_node, FDT_PROP_MEM_RANGE); 122 if (ret && ret != -FDT_ERR_NOTFOUND)
123 goto out;
124
125 /* Did we boot using an initrd? */
126 prop = fdt_getprop(fdt,chosen_node,
"linux,initrd-start", NULL);
127 if (prop) {
128 u64tmp_start,tmp_end,tmp_size;
129
130tmp_start=fdt64_to_cpu(*((const fdt64_t *) prop)); 131
132 prop = fdt_getprop(fdt,chosen_node,
"linux,initrd-end", NULL);
133 if (!prop) {
134 ret =-EINVAL;
135 goto out;
136 }
137
138tmp_end=fdt64_to_cpu(*((const fdt64_t *) prop)); 139
140 /*
141 * kexec reserves exact initrd size, while firmware may 142 * reserve a multiple ofPAGE_SIZE, so check for both. 143 */
144tmp_size=tmp_end-tmp_start;
145 ret = fdt_find_and_del_mem_rsv(fdt,tmp_start,tmp_size);
146 if (ret ==-ENOENT)
147 ret = fdt_find_and_del_mem_rsv(fdt,tmp_start, 148round_up(tmp_size, PAGE_SIZE)); 149 if (ret ==-EINVAL)
150 goto out;
151 }
152
153 /* add initrd-* */
154 if (initrd_load_addr) {
155 ret = fdt_setprop_u64(fdt,chosen_node,FDT_PROP_INITRD_START,
156initrd_load_addr);
157 if (ret)
158 goto out;
159
160 ret = fdt_setprop_u64(fdt,chosen_node,FDT_PROP_INITRD_END,
161initrd_load_addr+initrd_len); 162 if (ret)
163 goto out;
164
165 ret = fdt_add_mem_rsv(fdt,initrd_load_addr,initrd_len);
166 if (ret)
167 goto out;
168
169 } else {
170 ret = fdt_delprop(fdt,chosen_node,FDT_PROP_INITRD_START);
171 if (ret && (ret != -FDT_ERR_NOTFOUND))
172 goto out;
173
174 ret = fdt_delprop(fdt,chosen_node,FDT_PROP_INITRD_END);
175 if (ret && (ret != -FDT_ERR_NOTFOUND))
176 goto out;
177 }
178
179 if (image->type==KEXEC_TYPE_CRASH) {
180 /* add linux,elfcorehdr */
181 ret = fdt_appendprop_addrrange(fdt, 0,chosen_node, 182FDT_PROP_KEXEC_ELFHDR,
> 183image->arch.elf_headers_mem,
Quoted 4 lines
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 17 lines · Lakshmi Ramasubramanian
Quoted 13 lines · Lakshmi Ramasubramanian
Hi Rob,
[PATCH] powerpc: Rename kexecelfcorehdr_addrtoelf_headers_memThis change causes build problem forx86_64architecture (please see the mail from kernel test bot below) sincearch/x86/include/asm/kexec.huses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".struct kimage_arch { ... /* Core ELF header buffer */ void *elf_headers; unsigned long elf_headers_sz; unsigned long elf_load_addr; };Quoted 3 lines
I am thinking of limiting
of_kexec_alloc_and_setup_fdt()to ARM64 and PPC64 since they are the only ones using this function now. #ifdefined(CONFIG_ARM64)&&defined(CONFIG_PPC64)
Quoted 3 lines
Sorry - I meant to say
#ifdefined(CONFIG_ARM64)||defined(CONFIG_PPC64)
Does it build correctly if you rename elf_headers_mem to elf_load_addr? Or the other way around, renaming x86's elf_load_addr to elf_headers_mem. I don't really have a preference.
That would be better than adding an #if condition.
Quoted 11 lines
Quoted 11 lines
void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
unsigned longinitrd_load_addr, unsigned longinitrd_len,
const char *cmdline){ ... }#endif /*
defined(CONFIG_ARM64)&&defined(CONFIG_PPC64)*/ Please let me know if you have any concerns. thanks,
-lakshmi
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 20 lines · Thiago Jung Bauermann
Quoted 17 lines · Lakshmi Ramasubramanian
Quoted 16 lines · Lakshmi Ramasubramanian
Hi Rob,
[PATCH] powerpc: Rename kexecelfcorehdr_addrtoelf_headers_memThis change causes build problem forx86_64architecture (please see the mail from kernel test bot below) sincearch/x86/include/asm/kexec.huses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".struct kimage_arch { ... /* Core ELF header buffer */ void *elf_headers; unsigned long elf_headers_sz; unsigned long elf_load_addr; };I am thinking of limiting
of_kexec_alloc_and_setup_fdt()to ARM64 and PPC64 since they are the only ones using this function now. #ifdefined(CONFIG_ARM64)&&defined(CONFIG_PPC64)
Quoted 7 lines
Quoted 3 lines
Sorry - I meant to say
#ifdefined(CONFIG_ARM64)||defined(CONFIG_PPC64)Does it build correctly if you rename
elf_headers_memtoelf_load_addr? Or the other way around, renaming x86'self_load_addrtoelf_headers_mem. I don't really have a preference.
Yes - changing arm64 and ppc from "elf_headers_mem" to "elf_load_addr" builds fine.
But I am concerned about a few other architectures that also define "struct kimage_arch" such as "parisc", "arm" which do not have any ELF related fields. They would not build if the config defines CONFIG_KEXEC_FILE and CONFIG_OF_FLATTREE.
Do you think that could be an issue?
thanks,
-lakshmi
Quoted 15 lines
That would be better than adding an #if condition.
Quoted 11 lines
Quoted 11 lines
void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,
unsigned longinitrd_load_addr, unsigned longinitrd_len,
const char *cmdline){ ... }#endif /*
defined(CONFIG_ARM64)&&defined(CONFIG_PPC64)*/ Please let me know if you have any concerns. thanks,
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 30 lines · Lakshmi Ramasubramanian
Quoted 19 lines · Thiago Jung Bauermann
Quoted 17 lines · Lakshmi Ramasubramanian
Quoted 16 lines · Lakshmi Ramasubramanian
Hi Rob,
[PATCH] powerpc: Rename kexecelfcorehdr_addrtoelf_headers_memThis change causes build problem forx86_64architecture (please see the mail from kernel test bot below) sincearch/x86/include/asm/kexec.huses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".struct kimage_arch { ... /* Core ELF header buffer */ void *elf_headers; unsigned long elf_headers_sz; unsigned long elf_load_addr; };I am thinking of limiting
of_kexec_alloc_and_setup_fdt()to ARM64 and PPC64 since they are the only ones using this function now. #ifdefined(CONFIG_ARM64)&&defined(CONFIG_PPC64)Quoted 6 lines
Quoted 3 lines
Sorry - I meant to say
#ifdefined(CONFIG_ARM64)||defined(CONFIG_PPC64)Does it build correctly if you rename
elf_headers_memtoelf_load_addr? Or the other way around, renaming x86'self_load_addrtoelf_headers_mem. I don't really have a preference.Yes - changing arm64 and ppc from "
elf_headers_mem" to "elf_load_addr" builds fine.
Quoted 6 lines
But I am concerned about a few other architectures that also define "struct
kimage_arch" such as "parisc", "arm" which do not have any ELF related fields. They would not build if the config definesCONFIG_KEXEC_FILEandCONFIG_OF_FLATTREE.Do you think that could be an issue?
That's a good point. But in practice, arm doesn't support CONFIG_KEXEC_FILE. And while parisc does support CONFIG_KEXEC_FILE, as far as I could determine it doesn't support CONFIG_OF.
So IMHO we don't need to worry about them. We'll cross that bridge if we get there. If they ever implement KEXEC_FILE or OF_FLATTREE support, then (again, IMHO) the natural solution would be for them to name the ELF header member the same way the other arches do.
And since no other architecture defines struct kimage_arch, those are the only ones we need to consider.
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 44 lines · Thiago Jung Bauermann
Quoted 30 lines · Lakshmi Ramasubramanian
Quoted 19 lines · Thiago Jung Bauermann
Quoted 17 lines · Lakshmi Ramasubramanian
Quoted 16 lines · Lakshmi Ramasubramanian
Hi Rob,
[PATCH] powerpc: Rename kexecelfcorehdr_addrtoelf_headers_memThis change causes build problem forx86_64architecture (please see the mail from kernel test bot below) sincearch/x86/include/asm/kexec.huses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".struct kimage_arch { ... /* Core ELF header buffer */ void *elf_headers; unsigned long elf_headers_sz; unsigned long elf_load_addr; };I am thinking of limiting
of_kexec_alloc_and_setup_fdt()to ARM64 and PPC64 since they are the only ones using this function now. #ifdefined(CONFIG_ARM64)&&defined(CONFIG_PPC64)Quoted 6 lines
Quoted 3 lines
Sorry - I meant to say
#ifdefined(CONFIG_ARM64)||defined(CONFIG_PPC64)Does it build correctly if you rename
elf_headers_memtoelf_load_addr? Or the other way around, renaming x86'self_load_addrtoelf_headers_mem. I don't really have a preference.Yes - changing arm64 and ppc from "
elf_headers_mem" to "elf_load_addr" builds fine.Quoted 6 lines
But I am concerned about a few other architectures that also define "struct
kimage_arch" such as "parisc", "arm" which do not have any ELF related fields. They would not build if the config definesCONFIG_KEXEC_FILEandCONFIG_OF_FLATTREE.Do you think that could be an issue?
That's a good point. But in practice, arm doesn't support
CONFIG_KEXEC_FILE. And while parisc does supportCONFIG_KEXEC_FILE, as far as I could determine it doesn't supportCONFIG_OF.
Quoted 8 lines
So IMHO we don't need to worry about them. We'll cross that bridge if we get there. If they ever implement
KEXEC_FILEorOF_FLATTREEsupport, then (again, IMHO) the natural solution would be for them to name the ELF header member the same way the other arches do.And since no other architecture defines struct
kimage_arch, those are the only ones we need to consider.
Sounds good Thiago.
I'll rename arm64 and ppc kimage_arch ELF address field to match that defined for x86/x64.
Also, will add "fdt_size" param to of_kexec_alloc_and_setup_fdt(). For now, I'll use 2*fdt_totalsize(initial_boot_params) for ppc.
Will send the updated patches shortly.
-lakshmi
Re: Fwd: Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 52 lines · Lakshmi Ramasubramanian
Quoted 38 lines · Thiago Jung Bauermann
Quoted 30 lines · Lakshmi Ramasubramanian
Quoted 19 lines · Thiago Jung Bauermann
Quoted 17 lines · Lakshmi Ramasubramanian
Quoted 16 lines · Lakshmi Ramasubramanian
Hi Rob,
[PATCH] powerpc: Rename kexecelfcorehdr_addrtoelf_headers_memThis change causes build problem forx86_64architecture (please see the mail from kernel test bot below) sincearch/x86/include/asm/kexec.huses "elf_load_addr" for the ELF header buffer address and not "elf_headers_mem".struct kimage_arch { ... /* Core ELF header buffer */ void *elf_headers; unsigned long elf_headers_sz; unsigned long elf_load_addr; };I am thinking of limiting
of_kexec_alloc_and_setup_fdt()to ARM64 and PPC64 since they are the only ones using this function now. #ifdefined(CONFIG_ARM64)&&defined(CONFIG_PPC64)Quoted 6 lines
Quoted 3 lines
Sorry - I meant to say
#ifdefined(CONFIG_ARM64)||defined(CONFIG_PPC64)Does it build correctly if you rename
elf_headers_memtoelf_load_addr? Or the other way around, renaming x86'self_load_addrtoelf_headers_mem. I don't really have a preference.Yes - changing arm64 and ppc from "
elf_headers_mem" to "elf_load_addr" builds fine.Quoted 6 lines
But I am concerned about a few other architectures that also define "struct
kimage_arch" such as "parisc", "arm" which do not have any ELF related fields. They would not build if the config definesCONFIG_KEXEC_FILEandCONFIG_OF_FLATTREE.Do you think that could be an issue?
Quoted 10 lines
That's a good point. But in practice, arm doesn't support
CONFIG_KEXEC_FILE. And while parisc does supportCONFIG_KEXEC_FILE, as far as I could determine it doesn't supportCONFIG_OF.
So IMHO we don't need to worry about them. We'll cross that bridge if we get there. If they ever implementKEXEC_FILEorOF_FLATTREEsupport, then (again, IMHO) the natural solution would be for them to name the ELF header member the same way the other arches do.
And since no other architecture defines structkimage_arch, those are the only ones we need to consider.Sounds good Thiago.
Quoted 7 lines
I'll rename arm64 and ppc
kimage_archELF address field to match that defined for x86/x64.Also, will add "
fdt_size" param toof_kexec_alloc_and_setup_fdt(). For now, I'll use 2*fdt_totalsize(initial_boot_params) for ppc.Will send the updated patches shortly.
Sounds good. There will be a small conflict with powerpc/next because of the patch I mentioned, but it's simple to fix by whoever merges the series.
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
In reply to Lakshmi RamasubramanianThere's actually a complication that I just noticed and needs to be addressed. More below.
Quoted 131 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
Both arm64 and powerpc do essentially the same FDT /chosen setup for kexec. The differences are either omissions that arm64 should have or additional properties that will be ignored. The setup code can be combined and shared by both powerpc and arm64.
The differences relative to the arm64 version:
- If /chosen doesn't exist, it will be created (should never happen).
- Any old dtb and initrd reserved memory will be released.
- The new initrd and elfcorehdr are marked reserved.
- "linux,booted-from-kexec" is set.The differences relative to the powerpc version:
- "kaslr-seed" and "rng-seed" may be set.
- "linux,elfcorehdr" is set.
- Any existing "linux,usable-memory-range" is removed.Combine the code for setting up the /chosen node in the FDT and updating the memory reservation for kexec, for powerpc and arm64, in
of_kexec_alloc_and_setup_fdt()and move it to "drivers/of/kexec.c".Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- drivers/of/Makefile | 6 ++ drivers/of/kexec.c | 258 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 13 +++ 3 files changed, 277 insertions(+) create mode 100644 drivers/of/kexec.cdrivers/of/Makefile +6
-0@@ -14,4 +14,10 @@ obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +ifdef CONFIG_KEXEC_FILE +ifdef CONFIG_OF_FLATTREE +obj-y += kexec.o +endif +endif + obj-$(CONFIG_OF_UNITTEST) += unittest-data/drivers/of/kexec.c new file +79
-0@@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2020 Arm Limited +* +* Based on arch/arm64/kernel/machine_kexec_file.c: +* Copyright (C) 2018 Linaro Limited +* +* And arch/powerpc/kexec/file_load.c: +* Copyright (C) 2016 IBM Corporation +*/ + +#include <linux/kernel.h> +#include <linux/kexec.h> +#include <linux/libfdt.h> +#include <linux/of.h> +#include <linux/of_fdt.h> +#include <linux/random.h> +#include <linux/types.h> + +/* relevant device tree properties */ +#define FDT_PROP_KEXEC_ELFHDR "linux,elfcorehdr" +#define FDT_PROP_MEM_RANGE "linux,usable-memory-range" +#define FDT_PROP_INITRD_START "linux,initrd-start" +#define FDT_PROP_INITRD_END "linux,initrd-end" +#define FDT_PROP_BOOTARGS "bootargs" +#define FDT_PROP_KASLR_SEED "kaslr-seed" +#define FDT_PROP_RNG_SEED "rng-seed" +#define RNG_SEED_SIZE 128 + +/** +* fdt_find_and_del_mem_rsv - delete memory reservation with given address and size +* +* @fdt: Flattened device tree for the current kernel. +* @start: Starting address of the reserved memory. +* @size: Size of the reserved memory. +* +* Return: 0 on success, or negative errno on error. +*/ +static int fdt_find_and_del_mem_rsv (void *fdt,unsigned long start,unsigned long size) +{ +int i, ret, num_rsvs =fdt_num_mem_rsv (fdt); + +for (i =0 ; i < num_rsvs; i++) { +u64 rsv_start, rsv_size; + + ret =fdt_get_mem_rsv (fdt, i, &rsv_start, &rsv_size); +if (ret) { +pr_err ("Malformed device tree.\n" ); +return -EINVAL ; + } + +if (rsv_start == start && rsv_size == size) { + ret =fdt_del_mem_rsv (fdt, i); +if (ret) { +pr_err ("Error deleting device tree reservation.\n" ); +return -EINVAL ; + } + +return 0 ; + } + } + +return -ENOENT ; +} + +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,
drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;
Just adding 4 KB to initial_boot_params won't be enough for crash kernels on ppc64. The current powerpc code doubles the size of initial_boot_params (which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:
https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la arch_kexec_kernel_image_load())?
Then the powerpc specific hook would be the kexec_fdt_totalsize_ppc64() function from the patch I linked above.
Signature · 7 lines
Thiago Jung Bauermann IBM Linux Technology Center _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 4 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 34 lines
Quoted 15 lines
drivers/of/kexec.c new file +15
-0+ +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
Quoted 8 lines
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la
arch_kexec_kernel_image_load())?Then the powerpc specific hook would be the
kexec_fdt_totalsize_ppc64()function from the patch I linked above.
Do you think it'd better to add "fdt_size" parameter to of_kexec_alloc_and_setup_fdt() so that the caller can provide the desired FDT buffer size?
thanks,
-lakshmi
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 46 lines · Lakshmi Ramasubramanian
Quoted 3 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 29 lines
Quoted 15 lines
drivers/of/kexec.c new file +15
-0+ +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a moreQuoted 9 lines
precise (but arch-specific) formula:
https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a laarch_kexec_kernel_image_load())? Then the powerpc specific hook would be thekexec_fdt_totalsize_ppc64()function from the patch I linked above.
Quoted 3 lines
Do you think it'd better to add "
fdt_size" parameter toof_kexec_alloc_and_setup_fdt()so that the caller can provide the desired FDT buffer size?
Yes, that is actually simpler and better than my idea. :-)
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Rob Herring
maintainerRe: [PATCH v17 02/10] of: Add a common kexec FDT setup function
In reply to Lakshmi RamasubramanianQuoted 48 lines · Lakshmi Ramasubramanian
Quoted 4 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 39 lines
Quoted 15 lines
drivers/of/kexec.c new file +15
-0+ +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la
arch_kexec_kernel_image_load())?
Quoted 7 lines
Quoted 3 lines
Then the powerpc specific hook would be the
kexec_fdt_totalsize_ppc64()function from the patch I linked above.Do you think it'd better to add "
fdt_size" parameter toof_kexec_alloc_and_setup_fdt()so that the caller can provide the desired FDT buffer size?
Yes, I guess so. But please define the param as extra size, not total size. The kernel command line size addition can be in the common code.
The above change is also going to conflict, so I think this may have to wait. Or I'll take the common and arm bits and powerpc can be converted next cycle (or after the merge window).
Rob
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 54 lines · Rob Herring
Quoted 52 lines · Lakshmi Ramasubramanian
Quoted 4 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 42 lines
Quoted 15 lines
drivers/of/kexec.c new file +15
-0+ +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la
arch_kexec_kernel_image_load())?Then the powerpc specific hook would be the
kexec_fdt_totalsize_ppc64()function from the patch I linked above.
Quoted 6 lines
Quoted 3 lines
Do you think it'd better to add "
fdt_size" parameter toof_kexec_alloc_and_setup_fdt()so that the caller can provide the desired FDT buffer size?Yes, I guess so. But please define the param as extra size, not total size. The kernel command line size addition can be in the common code.
Will do. Just to clarify -
The common code will do:
fdt_totalsize(initial_boot_params) + strlen(cmdline) + extra_fdt_size
The caller will pass "extra_fdt_size"
ARM64 => 4KB
PPC64 => fdt_totalsize(initial_boot_params) - which will be updated when the patch Thiago had referred to is merged.
Quoted 5 lines
The above change is also going to conflict, so I think this may have to wait. Or I'll take the common and arm bits and powerpc can be converted next cycle (or after the merge window).
thanks.
-lakshmi
Rob Herring
maintainerRe: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 65 lines · Lakshmi Ramasubramanian
Quoted 54 lines · Rob Herring
Quoted 52 lines · Lakshmi Ramasubramanian
Quoted 4 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 42 lines
Quoted 15 lines
drivers/of/kexec.c new file +15
-0+ +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la
arch_kexec_kernel_image_load())?Then the powerpc specific hook would be the
kexec_fdt_totalsize_ppc64()function from the patch I linked above.Quoted 6 lines
Quoted 3 lines
Do you think it'd better to add "
fdt_size" parameter toof_kexec_alloc_and_setup_fdt()so that the caller can provide the desired FDT buffer size?Yes, I guess so. But please define the param as extra size, not total size. The kernel command line size addition can be in the common code.
Will do. Just to clarify -
Quoted 8 lines
The common code will do:
fdt_totalsize(initial_boot_params)+ strlen(cmdline) +extra_fdt_sizeThe caller will pass "
extra_fdt_size"
ARM64 => 4KB
PPC64 =>fdt_totalsize(initial_boot_params)- which will be updated when the patch Thiago had referred to is merged.
Yes, I'd leave the 4KB in there by default and arm64 use 0.
Rob
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 69 lines · Rob Herring
Quoted 67 lines · Lakshmi Ramasubramanian
Quoted 54 lines · Rob Herring
Quoted 52 lines · Lakshmi Ramasubramanian
Quoted 4 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 42 lines
Quoted 15 lines
drivers/of/kexec.c new file +15
-0+ +/* +* of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree +* +* @image: kexec image being loaded. +* @initrd_load_addr: Address where the next initrd will be loaded. +* @initrd_len: Size of the next initrd, or 0 if there will be none. +* @cmdline: Command line for the next kernel, or NULL if there will +* be none. +* +* Return: fdt on success, or NULL errno on error. +*/ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,drivers/of/kexec.c line 89
Quoted 10 lines
drivers/of/kexec.c new file +10
-0+ const char *cmdline) +{ +void *fdt; +int ret, chosen_node; +const void *prop; +unsigned long fdt_size; + + fdt_size =fdt_totalsize (initial_boot_params) + + (cmdline ?strlen (cmdline) :0 ) + +FDT_EXTRA_SPACE ;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la
arch_kexec_kernel_image_load())?Then the powerpc specific hook would be the
kexec_fdt_totalsize_ppc64()function from the patch I linked above.Quoted 6 lines
Quoted 3 lines
Do you think it'd better to add "
fdt_size" parameter toof_kexec_alloc_and_setup_fdt()so that the caller can provide the desired FDT buffer size?Yes, I guess so. But please define the param as extra size, not total size. The kernel command line size addition can be in the common code.
Will do. Just to clarify -
The common code will do:
Quoted 9 lines
Quoted 6 lines
fdt_totalsize(initial_boot_params)+ strlen(cmdline) +extra_fdt_sizeThe caller will pass "
extra_fdt_size"
ARM64 => 4KB
PPC64 =>fdt_totalsize(initial_boot_params)- which will be updated when the patch Thiago had referred to is merged.Yes, I'd leave the 4KB in there by default and arm64 use 0.
Sounds good.
common:fdt_totalsize(initial_boot_params) + strlen(cmdline) + 0x1000 + extra
arm64 => 0 for extra
ppc => fdt_totalsize(initial_boot_params) for extra.
-lakshmi
Re: [PATCH v17 02/10] of: Add a common kexec FDT setup function
Quoted 79 lines · Lakshmi Ramasubramanian
Quoted 69 lines · Rob Herring
Quoted 67 lines · Lakshmi Ramasubramanian
Quoted 54 lines · Rob Herring
Quoted 52 lines · Lakshmi Ramasubramanian
Quoted 4 lines · Thiago Jung Bauermann
There's actually a complication that I just noticed and needs to be addressed. More below.
<...>
Quoted 42 lines
Quoted 15 lines
(quoted diff) +15
-0+ +/* + * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree + * + * @image: kexec image being loaded. + * @initrd_load_addr: Address where the next initrd will be loaded. + * @initrd_len: Size of the next initrd, or 0 if there will be none. + * @cmdline: Command line for the next kernel, or NULL if there will + * be none. + * + * Return: fdt on success, or NULL errno on error. + */ +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, + unsigned long initrd_load_addr, + unsigned long initrd_len,Review
Quoted 10 lines
(quoted diff) +10
-0+ const char *cmdline) +{ + void *fdt; + int ret, chosen_node; + const void *prop; + unsigned long fdt_size; + + fdt_size = fdt_totalsize(initial_boot_params) + + (cmdline ? strlen(cmdline) : 0) + + FDT_EXTRA_SPACE;Just adding 4 KB to
initial_boot_paramswon't be enough for crash kernels on ppc64. The current powerpc code doubles the size ofinitial_boot_params(which is normally larger than 4 KB) and even that isn't enough. A patch was added to powerpc/next today which uses a more precise (but arch-specific) formula:https://lore.kernel.org/linuxppc-dev/161243826811.119001.14083048209224609814.stgit@hbathini/
So I believe we need a hook here where architectures can provide their own specific calculation for the size of the fdt. Perhaps a weakly defined function providing a default implementation which an arch-specific file can override (a la
arch_kexec_kernel_image_load())?Then the powerpc specific hook would be the
kexec_fdt_totalsize_ppc64()function from the patch I linked above.Quoted 6 lines
Quoted 3 lines
Do you think it'd better to add "
fdt_size" parameter toof_kexec_alloc_and_setup_fdt()so that the caller can provide the desired FDT buffer size?Yes, I guess so. But please define the param as extra size, not total size. The kernel command line size addition can be in the common code.
Will do. Just to clarify -
The common code will do:
Quoted 8 lines
Quoted 6 lines
fdt_totalsize(initial_boot_params)+ strlen(cmdline) +extra_fdt_sizeThe caller will pass "
extra_fdt_size"
ARM64 => 4KB
PPC64 =>fdt_totalsize(initial_boot_params)- which will be updated when the patch Thiago had referred to is merged.Yes, I'd leave the 4KB in there by default and arm64 use 0.
Quoted 7 lines
Sounds good.
common:
fdt_totalsize(initial_boot_params)+ strlen(cmdline) +0x1000+ extraarm64 => 0 for extra
ppc =>fdt_totalsize(initial_boot_params)for extra.
Looks good to me.
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
PATCH v17 3/10 arm64: Use common of_kexec_alloc_and_setup_fdt()
In reply to Lakshmi RamasubramanianFrom: Rob Herring <[email protected]>
The code for setting up the /chosen node in the device tree and updating the memory reservation for the next kernel has been moved to of_kexec_alloc_and_setup_fdt() defined in "drivers/of/kexec.c".
Use the common of_kexec_alloc_and_setup_fdt() to setup the device tree and update the memory reservation for kexec for arm64.
--- arch/arm64/kernel/machine_kexec_file.c | 180 ++----------------------- 1 file changed, 8 insertions(+), 172 deletions(-)
arch/arm64/kernel/machine_kexec_file.c +8 -172
@@ -15,23 +15,12 @@#include <linux/kexec.h> #include <linux/libfdt.h> #include <linux/memblock.h> +#include <linux/of.h> #include <linux/of_fdt.h> -#include <linux/random.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/types.h> #include <linux/vmalloc.h> -#include <asm/byteorder.h> - -/* relevant device tree properties */ -#define FDT_PROP_KEXEC_ELFHDR "linux,elfcorehdr" -#define FDT_PROP_MEM_RANGE "linux,usable-memory-range" -#define FDT_PROP_INITRD_START "linux,initrd-start" -#define FDT_PROP_INITRD_END "linux,initrd-end" -#define FDT_PROP_BOOTARGS "bootargs" -#define FDT_PROP_KASLR_SEED "kaslr-seed" -#define FDT_PROP_RNG_SEED "rng-seed" -#define RNG_SEED_SIZE 128const struct kexec_file_ops *const kexec_file_loaders[] = { &kexec_image_ops,
@@ -40,7 +29,7 @@ const struct kexec_file_ops * const kexec_file_loaders[] = {int arch_kimage_file_post_load_cleanup (struct kimage *image) { -vfree (image->arch.dtb); +kvfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);
@@ -50,162 +39,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)return kexec_image_post_load_cleanup_default (image); } -static int setup_dtb (struct kimage *image, -unsigned long initrd_load_addr,unsigned long initrd_len, -char *cmdline,void *dtb) -{ -int off, ret; - - ret =fdt_path_offset (dtb,"/chosen" ); -if (ret <0 ) - goto out; - - off = ret; - - ret =fdt_delprop (dtb, off,FDT_PROP_KEXEC_ELFHDR ); -if (ret && ret != -FDT_ERR_NOTFOUND ) - goto out; - ret =fdt_delprop (dtb, off,FDT_PROP_MEM_RANGE ); -if (ret && ret != -FDT_ERR_NOTFOUND ) - goto out; - -if (image->type ==KEXEC_TYPE_CRASH ) { -/* add linux,elfcorehdr */ - ret =fdt_appendprop_addrrange (dtb,0 , off, -FDT_PROP_KEXEC_ELFHDR , - image->arch.elf_headers_mem, - image->arch.elf_headers_sz); -if (ret) -return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL ); - -/* add linux,usable-memory-range */ - ret =fdt_appendprop_addrrange (dtb,0 , off, -FDT_PROP_MEM_RANGE , - crashk_res.start, - crashk_res.end - crashk_res.start +1 ); -if (ret) -return (ret == -FDT_ERR_NOSPACE ? -ENOMEM : -EINVAL ); - } - -/* add bootargs */ -if (cmdline) { - ret =fdt_setprop_string (dtb, off,FDT_PROP_BOOTARGS , cmdline); -if (ret) - goto out; - }else { - ret =fdt_delprop (dtb, off,FDT_PROP_BOOTARGS ); -if (ret && (ret != -FDT_ERR_NOTFOUND )) - goto out; - } - -/* add initrd-* */ -if (initrd_load_addr) { - ret =fdt_setprop_u64 (dtb, off,FDT_PROP_INITRD_START , - initrd_load_addr); -if (ret) - goto out; - - ret =fdt_setprop_u64 (dtb, off,FDT_PROP_INITRD_END , - initrd_load_addr + initrd_len); -if (ret) - goto out; - }else { - ret =fdt_delprop (dtb, off,FDT_PROP_INITRD_START ); -if (ret && (ret != -FDT_ERR_NOTFOUND )) - goto out; - - ret =fdt_delprop (dtb, off,FDT_PROP_INITRD_END ); -if (ret && (ret != -FDT_ERR_NOTFOUND )) - goto out; - } - -/* add kaslr-seed */ - ret =fdt_delprop (dtb, off,FDT_PROP_KASLR_SEED ); -if (ret == -FDT_ERR_NOTFOUND ) - ret =0 ; -else if (ret) - goto out; - -if (rng_is_initialized ()) { -u64 seed =get_random_u64 (); - ret =fdt_setprop_u64 (dtb, off,FDT_PROP_KASLR_SEED , seed); -if (ret) - goto out; - }else { -pr_notice ("RNG is not initialised: omitting \"%s\" property\n" , -FDT_PROP_KASLR_SEED ); - } - -/* add rng-seed */ -if (rng_is_initialized ()) { -void *rng_seed; - ret =fdt_setprop_placeholder (dtb, off,FDT_PROP_RNG_SEED , -RNG_SEED_SIZE , &rng_seed); -if (ret) - goto out; -get_random_bytes (rng_seed,RNG_SEED_SIZE ); - }else { -pr_notice ("RNG is not initialised: omitting \"%s\" property\n" , -FDT_PROP_RNG_SEED ); - } - -out: -if (ret) -return (ret == -FDT_ERR_NOSPACE ) ? -ENOMEM : -EINVAL ; - -return 0 ; -} - -/* -* More space needed so that we can add initrd, bootargs, kaslr-seed, -* rng-seed, userable-memory-range and elfcorehdr. -*/ -#define DTB_EXTRA_SPACE 0x1000 - -static int create_dtb (struct kimage *image, -unsigned long initrd_load_addr,unsigned long initrd_len, -char *cmdline,void **dtb) -{ -void *buf; -size_t buf_size; -size_t cmdline_len; -int ret; - - cmdline_len = cmdline ?strlen (cmdline) :0 ; - buf_size =fdt_totalsize (initial_boot_params) - + cmdline_len +DTB_EXTRA_SPACE ; - -for (;;) { - buf =vmalloc (buf_size); -if (!buf) -return -ENOMEM ; - -/* duplicate a device tree blob */ - ret =fdt_open_into (initial_boot_params, buf, buf_size); -if (ret) -return -EINVAL ; - - ret =setup_dtb (image, initrd_load_addr, initrd_len, - cmdline, buf); -if (ret) { -vfree (buf); -if (ret == -ENOMEM ) { -/* unlikely, but just in case */ - buf_size +=DTB_EXTRA_SPACE ; -continue ; - }else { -return ret; - } - } - -/* trim it */ -fdt_pack (buf); - *dtb = buf; - -return 0 ; - } -} -static int prepare_elf_headers (void **addr,unsigned long *sz) {struct crash_mem *cmem;
@@ -312,12 +145,15 @@ int load_other_segments(struct kimage *image, }/* load dtb */ - ret =create_dtb (image, initrd_load_addr, initrd_len, cmdline, &dtb); -if (ret) { + dtb =of_kexec_alloc_and_setup_fdt (image, initrd_load_addr, + initrd_len, cmdline); +if (!dtb) {pr_err ("Preparing for new dtb failed\n" ); goto out_err; } +/* trim it */ +fdt_pack (dtb); dtb_len =fdt_totalsize (dtb); kbuf.buffer = dtb; kbuf.bufsz = dtb_len;
@@ -341,6 +177,6 @@ int load_other_segments(struct kimage *image, out_err: image->nr_segments = orig_segments; -vfree (dtb); +kvfree (dtb);return ret; }
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 03/10] arm64: Use common of_kexec_alloc_and_setup_fdt()
Quoted 6 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
The code for setting up the /chosen node in the device tree and updating the memory reservation for the next kernel has been moved to
of_kexec_alloc_and_setup_fdt()defined in "drivers/of/kexec.c".
Quoted 8 lines
Use the common
of_kexec_alloc_and_setup_fdt()to setup the device tree and update the memory reservation for kexec for arm64.Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 180 ++----------------------- 1 file changed, 8 insertions(+), 172 deletions(-)
I mean, of course I'm going to Ack that!
Will
Re: [PATCH v17 03/10] arm64: Use common of_kexec_alloc_and_setup_fdt()
In reply to Lakshmi RamasubramanianQuoted 6 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
The code for setting up the /chosen node in the device tree and updating the memory reservation for the next kernel has been moved to
of_kexec_alloc_and_setup_fdt()defined in "drivers/of/kexec.c".
Quoted 8 lines
Use the common
of_kexec_alloc_and_setup_fdt()to setup the device tree and update the memory reservation for kexec for arm64.Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 180 ++----------------------- 1 file changed, 8 insertions(+), 172 deletions(-)
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
PATCH v17 4/10 powerpc: Use common of_kexec_alloc_and_setup_fdt()
In reply to Lakshmi RamasubramanianFrom: Rob Herring <[email protected]>
The code for setting up the /chosen node in the device tree and updating the memory reservation for the next kernel has been moved to of_kexec_alloc_and_setup_fdt() defined in "drivers/of/kexec.c".
Use the common of_kexec_alloc_and_setup_fdt() to setup the device tree and update the memory reservation for kexec for powerpc.
--- arch/powerpc/include/asm/kexec.h | 1 + arch/powerpc/kexec/elf_64.c | 29 ++++--- arch/powerpc/kexec/file_load.c | 132 +----------------------------- arch/powerpc/kexec/file_load_64.c | 3 + 4 files changed, 25 insertions(+), 140 deletions(-)
arch/powerpc/include/asm/kexec.h +1 -0
@@ -111,6 +111,7 @@ struct kimage_arch {unsigned long elf_headers_mem;unsigned long elf_headers_sz;void *elf_headers; +void *fdt;#ifdef CONFIG_IMA_KEXEC phys_addr_t ima_buffer_addr;
arch/powerpc/kexec/elf_64.c +17 -12
@@ -19,6 +19,7 @@#include <linux/kexec.h> #include <linux/libfdt.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/of_fdt.h> #include <linux/slab.h> #include <linux/types.h>
@@ -29,7 +30,6 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long cmdline_len) {int ret; -unsigned int fdt_size;unsigned long kernel_load_addr;unsigned long initrd_load_addr =0 , fdt_load_addr;void *fdt;
@@ -102,19 +102,13 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,pr_debug ("Loaded initrd at 0x%lx\n" , initrd_load_addr); } - fdt_size =fdt_totalsize (initial_boot_params) *2 ; - fdt =kmalloc (fdt_size,GFP_KERNEL ); + fdt =of_kexec_alloc_and_setup_fdt (image, initrd_load_addr, + initrd_len, cmdline);if (!fdt) {pr_err ("Not enough memory for the device tree.\n" ); ret = -ENOMEM ; goto out; } - ret =fdt_open_into (initial_boot_params, fdt, fdt_size); -if (ret <0 ) { -pr_err ("Error setting up the new device tree.\n" ); - ret = -EINVAL ; - goto out; - } ret =setup_new_fdt_ppc64 (image, fdt, initrd_load_addr, initrd_len, cmdline);
@@ -124,13 +118,17 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,fdt_pack (fdt); kbuf.buffer = fdt; - kbuf.bufsz = kbuf.memsz = fdt_size; + kbuf.bufsz = kbuf.memsz =fdt_totalsize (fdt); kbuf.buf_align =PAGE_SIZE ; kbuf.top_down = true; kbuf.mem =KEXEC_BUF_MEM_UNKNOWN ; ret =kexec_add_buffer (&kbuf);if (ret) goto out; + +/* FDT will be freed in arch_kimage_file_post_load_cleanup */ + image->arch.fdt = fdt; + fdt_load_addr = kbuf.mem;pr_debug ("Loaded device tree at 0x%lx\n" , fdt_load_addr);
@@ -145,8 +143,15 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,kfree (modified_cmdline);kexec_free_elf_info (&elf_info); -/* Make kimage_file_post_load_cleanup free the fdt buffer for us. */ -return ret ?ERR_PTR (ret) : fdt; +/* +* Once FDT buffer has been successfully passed to kexec_add_buffer(), +* the FDT buffer address is saved in image->arch.fdt. In that case, +* the memory cannot be freed here in case of any other error. +*/ +if (ret && !image->arch.fdt) +kvfree (fdt); + +return ret ?ERR_PTR (ret) :NULL ; }const struct kexec_file_ops kexec_elf64_ops = {
arch/powerpc/kexec/file_load.c +4 -128
139 lines not on this page · raw message
arch/powerpc/kexec/file_load_64.c +3 -0
@@ -1111,5 +1111,8 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) image->arch.elf_headers =NULL ; image->arch.elf_headers_sz =0 ; +kvfree (image->arch.fdt); + image->arch.fdt =NULL ; +return kexec_image_post_load_cleanup_default (image); }
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 04/10] powerpc: Use common of_kexec_alloc_and_setup_fdt()
Quoted 51 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
The code for setting up the /chosen node in the device tree and updating the memory reservation for the next kernel has been moved to
of_kexec_alloc_and_setup_fdt()defined in "drivers/of/kexec.c".Use the common
of_kexec_alloc_and_setup_fdt()to setup the device tree and update the memory reservation for kexec for powerpc.Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/powerpc/include/asm/kexec.h | 1 + arch/powerpc/kexec/elf_64.c | 29 ++++--- arch/powerpc/kexec/file_load.c | 132 +----------------------------- arch/powerpc/kexec/file_load_64.c | 3 + 4 files changed, 25 insertions(+), 140 deletions(-)arch/powerpc/include/asm/kexec.h +1
-0@@ -111,6 +111,7 @@ struct kimage_arch {unsigned long elf_headers_mem;unsigned long elf_headers_sz;void *elf_headers; +void *fdt;#ifdef CONFIG_IMA_KEXEC phys_addr_t ima_buffer_addr;arch/powerpc/kexec/elf_64.c +1
-1@@ -19,6 +19,7 @@#include <linux/kexec.h> #include <linux/libfdt.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/of_fdt.h> #include <linux/slab.h> #include <linux/types.h> @@ -29,7 +30,6 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long cmdline_len) {int ret; -unsigned int fdt_size;unsigned long kernel_load_addr;unsigned long initrd_load_addr =0 , fdt_load_addr;void *fdt;
arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 108
Quoted 9 lines
arch/powerpc/kexec/elf_64.c +2
-2@@ -102,19 +102,13 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,pr_debug ("Loaded initrd at 0x%lx\n" , initrd_load_addr); } - fdt_size =fdt_totalsize (initial_boot_params) *2 ; - fdt =kmalloc (fdt_size,GFP_KERNEL ); + fdt =of_kexec_alloc_and_setup_fdt (image, initrd_load_addr, + initrd_len, cmdline);if (!fdt) {pr_err ("Not enough memory for the device tree.\n" );
This error string can be a bit misleading now, since of_kexec_alloc_and_setup_fdt() can fail for reasons other than lack of memory. I suggest changing it to the error string from fdt_open_into() below:
pr_err("Error setting up the new device tree.\n");With this change:
And also:
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v17 04/10] powerpc: Use common of_kexec_alloc_and_setup_fdt()
Quoted 69 lines · Thiago Jung Bauermann
Quoted 51 lines · Lakshmi Ramasubramanian
From: Rob Herring <[email protected]>
The code for setting up the /chosen node in the device tree and updating the memory reservation for the next kernel has been moved to
of_kexec_alloc_and_setup_fdt()defined in "drivers/of/kexec.c".Use the common
of_kexec_alloc_and_setup_fdt()to setup the device tree and update the memory reservation for kexec for powerpc.Signed-off-by Rob Herring <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/powerpc/include/asm/kexec.h | 1 + arch/powerpc/kexec/elf_64.c | 29 ++++--- arch/powerpc/kexec/file_load.c | 132 +----------------------------- arch/powerpc/kexec/file_load_64.c | 3 + 4 files changed, 25 insertions(+), 140 deletions(-)arch/powerpc/include/asm/kexec.h +1
-0@@ -111,6 +111,7 @@ struct kimage_arch {unsigned long elf_headers_mem;unsigned long elf_headers_sz;void *elf_headers; +void *fdt;#ifdef CONFIG_IMA_KEXEC phys_addr_t ima_buffer_addr;arch/powerpc/kexec/elf_64.c +1
-1@@ -19,6 +19,7 @@#include <linux/kexec.h> #include <linux/libfdt.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/of_fdt.h> #include <linux/slab.h> #include <linux/types.h> @@ -29,7 +30,6 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, unsigned long cmdline_len) {int ret; -unsigned int fdt_size;unsigned long kernel_load_addr;unsigned long initrd_load_addr =0 , fdt_load_addr;void *fdt;arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 108
Quoted 9 lines
arch/powerpc/kexec/elf_64.c +2
-2@@ -102,19 +102,13 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,pr_debug ("Loaded initrd at 0x%lx\n" , initrd_load_addr); } - fdt_size =fdt_totalsize (initial_boot_params) *2 ; - fdt =kmalloc (fdt_size,GFP_KERNEL ); + fdt =of_kexec_alloc_and_setup_fdt (image, initrd_load_addr, + initrd_len, cmdline);if (!fdt) {pr_err ("Not enough memory for the device tree.\n" );This error string can be a bit misleading now, since
of_kexec_alloc_and_setup_fdt()can fail for reasons other than lack of memory. I suggest changing it to the error string fromfdt_open_into()below:
Quoted 3 lines
pr_err("Error setting up the new device tree.\n");With this change:
Agreed - I will make this change.
Quoted 7 lines
Reviewed-by Thiago Jung Bauermann <[email protected]>And also:
Thanks a lot for your help Thiago.
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 5/10 powerpc: Move ima buffer fields to struct kimage
In reply to Lakshmi RamasubramanianThe fields ima_buffer_addr and ima_buffer_size in "struct kimage_arch" for powerpc are used to carry forward the IMA measurement list across kexec system call. These fields are not architecture specific, but are currently limited to powerpc.
arch_ima_add_kexec_buffer() defined in "arch/powerpc/kexec/ima.c" sets ima_buffer_addr and ima_buffer_size for the kexec system call. This function does not have architecture specific code, but is currently limited to powerpc.
Move ima_buffer_addr and ima_buffer_size to "struct kimage". Rename arch_ima_add_kexec_buffer() to of_ima_add_kexec_buffer() and move it in drivers/of/kexec.c.
--- arch/powerpc/include/asm/ima.h | 3 --- arch/powerpc/include/asm/kexec.h | 5 ----- arch/powerpc/kexec/ima.c | 29 ++++++----------------------- drivers/of/kexec.c | 23 +++++++++++++++++++++++ include/linux/kexec.h | 3 +++ include/linux/of.h | 5 +++++ security/integrity/ima/ima_kexec.c | 3 ++- 7 files changed, 39 insertions(+), 32 deletions(-)
arch/powerpc/include/asm/ima.h +0 -3
@@ -14,9 +14,6 @@ static inline void remove_ima_buffer(void *fdt, int chosen_node) {}#endif #ifdef CONFIG_IMA_KEXEC -int arch_ima_add_kexec_buffer (struct kimage *image,unsigned long load_addr, -size_t size); -int setup_ima_buffer (const struct kimage *image,void *fdt,int chosen_node);#else static inline int setup_ima_buffer(const struct kimage *image, void *fdt,
arch/powerpc/include/asm/kexec.h +0 -5
@@ -112,11 +112,6 @@ struct kimage_arch {unsigned long elf_headers_sz;void *elf_headers;void *fdt; - -#ifdef CONFIG_IMA_KEXEC -phys_addr_t ima_buffer_addr; -size_t ima_buffer_size; -#endif }; char *setup_kdump_cmdline(struct kimage *image, char *cmdline,
arch/powerpc/kexec/ima.c +6 -23
@@ -128,23 +128,6 @@ void remove_ima_buffer(void *fdt, int chosen_node) }#ifdef CONFIG_IMA_KEXEC -/** -* arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer -* -* Architectures should use this function to pass on the IMA buffer -* information to the next kernel. -* -* Return: 0 on success, negative errno on error. -*/ -int arch_ima_add_kexec_buffer (struct kimage *image,unsigned long load_addr, -size_t size) -{ - image->arch.ima_buffer_addr = load_addr; - image->arch.ima_buffer_size = size; - -return 0 ; -} -static int write_number (void *p,u64 value,int cells) {if (cells ==1 ) {
@@ -180,7 +163,7 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node)u8 value[16 ];remove_ima_buffer (fdt, chosen_node); -if (!image->arch.ima_buffer_size) +if (!image->ima_buffer_size)return 0 ; ret =get_addr_size_cells (&addr_cells, &size_cells);
@@ -192,11 +175,11 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node)if (entry_size >sizeof (value))return -EINVAL ; - ret =write_number (value, image->arch.ima_buffer_addr, addr_cells); + ret =write_number (value, image->ima_buffer_addr, addr_cells);if (ret)return ret; - ret =write_number (value +4 * addr_cells, image->arch.ima_buffer_size, + ret =write_number (value +4 * addr_cells, image->ima_buffer_size, size_cells);if (ret)return ret;
@@ -206,13 +189,13 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node)if (ret <0 )return -EINVAL ; - ret =fdt_add_mem_rsv (fdt, image->arch.ima_buffer_addr, - image->arch.ima_buffer_size); + ret =fdt_add_mem_rsv (fdt, image->ima_buffer_addr, + image->ima_buffer_size);if (ret)return -EINVAL ;pr_debug ("IMA buffer at 0x%llx, size = 0x%zx\n" , - image->arch.ima_buffer_addr, image->arch.ima_buffer_size); + image->ima_buffer_addr, image->ima_buffer_size);return 0 ; }
drivers/of/kexec.c +23 -0
@@ -63,6 +63,29 @@ static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned lonreturn -ENOENT ; } +#ifdef CONFIG_IMA_KEXEC +/** +* of_ima_add_kexec_buffer - Add IMA buffer for next kernel +* +* @image: kimage struct to set IMA buffer data +* @load_addr: Starting address where IMA buffer is loaded at +* @size: Number of bytes in the IMA buffer +* +* Use this function to pass on the IMA buffer information to +* the next kernel across kexec system call. +* +* Return: 0 on success, negative errno on error. +*/ +int of_ima_add_kexec_buffer (struct kimage *image, +unsigned long load_addr,size_t size) +{ + image->ima_buffer_addr = load_addr; + image->ima_buffer_size = size; + +return 0 ; +} +#endif /* CONFIG_IMA_KEXEC */ +/* * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree *
include/linux/kexec.h +3 -0
@@ -304,6 +304,9 @@ struct kimage {#ifdef CONFIG_IMA_KEXEC /* Virtual address of IMA measurement buffer for kexec syscall */ void *ima_buffer; + +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size;#endif };
include/linux/of.h +5 -0
@@ -573,6 +573,11 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image,unsigned long initrd_len, const char *cmdline); +#ifdef CONFIG_IMA_KEXEC +int of_ima_add_kexec_buffer (struct kimage *image, +unsigned long load_addr,size_t size); +#endif /* CONFIG_IMA_KEXEC */ +#else /* CONFIG_OF */ static inline void of_core_init (void )
security/integrity/ima/ima_kexec.c +2 -1
@@ -10,6 +10,7 @@#include <linux/seq_file.h> #include <linux/vmalloc.h> #include <linux/kexec.h> +#include <linux/of.h> #include "ima.h" #ifdef CONFIG_IMA_KEXEC
@@ -123,7 +124,7 @@ void ima_add_kexec_buffer(struct kimage *image)return ; } - ret =arch_ima_add_kexec_buffer (image, kbuf.mem, kexec_segment_size); + ret =of_ima_add_kexec_buffer (image, kbuf.mem, kexec_segment_size);if (ret) {pr_err ("Error passing over kexec measurement buffer.\n" );return ;
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Rob Herring
maintainerRe: [PATCH v17 05/10] powerpc: Move ima buffer fields to struct kimage
Quoted 143 lines · Lakshmi Ramasubramanian
The fields
ima_buffer_addrandima_buffer_sizein "structkimage_arch" for powerpc are used to carry forward the IMA measurement list across kexec system call. These fields are not architecture specific, but are currently limited to powerpc.
arch_ima_add_kexec_buffer()defined in "arch/powerpc/kexec/ima.c" setsima_buffer_addrandima_buffer_sizefor the kexec system call. This function does not have architecture specific code, but is currently limited to powerpc.Move
ima_buffer_addrandima_buffer_sizeto "struct kimage". Renamearch_ima_add_kexec_buffer()toof_ima_add_kexec_buffer()and move it indrivers/of/kexec.c.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>Suggested-by Will Deacon <[email protected]>--- arch/powerpc/include/asm/ima.h | 3 --- arch/powerpc/include/asm/kexec.h | 5 ----- arch/powerpc/kexec/ima.c | 29 ++++++----------------------- drivers/of/kexec.c | 23 +++++++++++++++++++++++ include/linux/kexec.h | 3 +++ include/linux/of.h | 5 +++++ security/integrity/ima/ima_kexec.c | 3 ++- 7 files changed, 39 insertions(+), 32 deletions(-)arch/powerpc/include/asm/ima.h +0
-3@@ -14,9 +14,6 @@ static inline void remove_ima_buffer(void *fdt, int chosen_node) {}#endif #ifdef CONFIG_IMA_KEXEC -int arch_ima_add_kexec_buffer (struct kimage *image,unsigned long load_addr, -size_t size); -int setup_ima_buffer (const struct kimage *image,void *fdt,int chosen_node);#else static inline int setup_ima_buffer(const struct kimage *image, void *fdt,arch/powerpc/include/asm/kexec.h +0
-5@@ -112,11 +112,6 @@ struct kimage_arch {unsigned long elf_headers_sz;void *elf_headers;void *fdt; - -#ifdef CONFIG_IMA_KEXEC -phys_addr_t ima_buffer_addr; -size_t ima_buffer_size; -#endif }; char *setup_kdump_cmdline(struct kimage *image, char *cmdline,arch/powerpc/kexec/ima.c +6
-23@@ -128,23 +128,6 @@ void remove_ima_buffer(void *fdt, int chosen_node) }#ifdef CONFIG_IMA_KEXEC -/** -* arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer -* -* Architectures should use this function to pass on the IMA buffer -* information to the next kernel. -* -* Return: 0 on success, negative errno on error. -*/ -int arch_ima_add_kexec_buffer (struct kimage *image,unsigned long load_addr, -size_t size) -{ - image->arch.ima_buffer_addr = load_addr; - image->arch.ima_buffer_size = size; - -return 0 ; -} -static int write_number (void *p,u64 value,int cells) {if (cells ==1 ) {@@ -180,7 +163,7 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node)u8 value[16 ];remove_ima_buffer (fdt, chosen_node); -if (!image->arch.ima_buffer_size) +if (!image->ima_buffer_size)return 0 ; ret =get_addr_size_cells (&addr_cells, &size_cells);@@ -192,11 +175,11 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node)if (entry_size >sizeof (value))return -EINVAL ; - ret =write_number (value, image->arch.ima_buffer_addr, addr_cells); + ret =write_number (value, image->ima_buffer_addr, addr_cells);if (ret)return ret; - ret =write_number (value +4 * addr_cells, image->arch.ima_buffer_size, + ret =write_number (value +4 * addr_cells, image->ima_buffer_size, size_cells);if (ret)return ret;@@ -206,13 +189,13 @@ int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node)if (ret <0 )return -EINVAL ; - ret =fdt_add_mem_rsv (fdt, image->arch.ima_buffer_addr, - image->arch.ima_buffer_size); + ret =fdt_add_mem_rsv (fdt, image->ima_buffer_addr, + image->ima_buffer_size);if (ret)return -EINVAL ;pr_debug ("IMA buffer at 0x%llx, size = 0x%zx\n" , - image->arch.ima_buffer_addr, image->arch.ima_buffer_size); + image->ima_buffer_addr, image->ima_buffer_size);return 0 ; }drivers/of/kexec.c +9
-0@@ -63,6 +63,29 @@ static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned lonreturn -ENOENT ; } +#ifdef CONFIG_IMA_KEXEC +/** +* of_ima_add_kexec_buffer - Add IMA buffer for next kernel +* +* @image: kimage struct to set IMA buffer data +* @load_addr: Starting address where IMA buffer is loaded at +* @size: Number of bytes in the IMA buffer +* +* Use this function to pass on the IMA buffer information to
drivers/of/kexec.c static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned lon · line 84
Quoted 10 lines
drivers/of/kexec.c +10
-0+* the next kernel across kexec system call. +* +* Return: 0 on success, negative errno on error. +*/ +int of_ima_add_kexec_buffer (struct kimage *image, +unsigned long load_addr,size_t size) +{ + image->ima_buffer_addr = load_addr; + image->ima_buffer_size = size; +
There's nothing DT specific about this function, so this is the wrong place for it. I would just remove it and directly set the members.
Rob
Re: [PATCH v17 05/10] powerpc: Move ima buffer fields to struct kimage
Quoted 51 lines · Rob Herring
Quoted 50 lines · Lakshmi Ramasubramanian
The fields
ima_buffer_addrandima_buffer_sizein "structkimage_arch" for powerpc are used to carry forward the IMA measurement list across kexec system call. These fields are not architecture specific, but are currently limited to powerpc.
arch_ima_add_kexec_buffer()defined in "arch/powerpc/kexec/ima.c" setsima_buffer_addrandima_buffer_sizefor the kexec system call. This function does not have architecture specific code, but is currently limited to powerpc.Move
ima_buffer_addrandima_buffer_sizeto "struct kimage". Renamearch_ima_add_kexec_buffer()toof_ima_add_kexec_buffer()and move it indrivers/of/kexec.c.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>Suggested-by Will Deacon <[email protected]>--- arch/powerpc/include/asm/ima.h | 3 --- arch/powerpc/include/asm/kexec.h | 5 ----- arch/powerpc/kexec/ima.c | 29 ++++++----------------------- drivers/of/kexec.c | 23 +++++++++++++++++++++++ include/linux/kexec.h | 3 +++ include/linux/of.h | 5 +++++ security/integrity/ima/ima_kexec.c | 3 ++- 7 files changed, 39 insertions(+), 32 deletions(-)drivers/of/kexec.c +14
-0@@ -63,6 +63,29 @@ static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned lonreturn -ENOENT ; } +#ifdef CONFIG_IMA_KEXEC +/** +* of_ima_add_kexec_buffer - Add IMA buffer for next kernel +* +* @image: kimage struct to set IMA buffer data +* @load_addr: Starting address where IMA buffer is loaded at +* @size: Number of bytes in the IMA buffer +* +* Use this function to pass on the IMA buffer information to +* the next kernel across kexec system call. +* +* Return: 0 on success, negative errno on error. +*/ +int of_ima_add_kexec_buffer(struct kimage *image,
Quoted 8 lines
drivers/of/kexec.c static int fdt_find_and_del_mem_rsv(void *fdt, unsigned long start, unsigned lon · line 84
Quoted 5 lines
drivers/of/kexec.c +5
-0+ unsigned long load_addr, size_t size) +{ + image->ima_buffer_addr = load_addr; + image->ima_buffer_size = size; +There's nothing DT specific about this function, so this is the wrong place for it. I would just remove it and directly set the members.
Will do.
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 6/10 powerpc: Enable passing IMA log to next kernel on kexec
In reply to Lakshmi RamasubramanianCONFIG_HAVE_IMA_KEXEC is enabled to indicate that the IMA measurement log information is present in the device tree. This should be selected only if CONFIG_IMA is enabled.
Update CONFIG_KEXEC_FILE to select CONFIG_HAVE_IMA_KEXEC, if CONFIG_IMA is enabled, to indicate that the IMA measurement log information is present in the device tree for powerpc.
--- arch/powerpc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/Kconfig +1 -1
@@ -554,7 +554,7 @@ config KEXEC config KEXEC_FILE bool "kexec file based system call" select KEXEC_CORE - select HAVE_IMA_KEXEC + select HAVE_IMA_KEXEC if IMA select BUILD_BIN2C select KEXEC_ELF depends on PPC64
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 06/10] powerpc: Enable passing IMA log to next kernel on kexec
Quoted 8 lines · Lakshmi Ramasubramanian
CONFIG_HAVE_IMA_KEXECis enabled to indicate that the IMA measurement log information is present in the device tree. This should be selected only ifCONFIG_IMAis enabled.Update
CONFIG_KEXEC_FILEto selectCONFIG_HAVE_IMA_KEXEC, ifCONFIG_IMAis enabled, to indicate that the IMA measurement log information is present in the device tree for powerpc.
Quoted 5 lines
Signed-off-by Lakshmi Ramasubramanian <[email protected]>Suggested-by Thiago Jung Bauermann <[email protected]>--- arch/powerpc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 7 lines
Thiago Jung Bauermann IBM Linux Technology Center _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 7/10 powerpc: Move arch independent ima kexec functions to drivers/of/kexec.c
In reply to Lakshmi RamasubramanianThe functions defined in "arch/powerpc/kexec/ima.c" handle setting up and freeing the resources required to carry over the IMA measurement list from the current kernel to the next kernel across kexec system call. These functions do not have architecture specific code, but are currently limited to powerpc.
Move remove_ima_buffer() and setup_ima_buffer() calls into of_kexec_alloc_and_setup_fdt() defined in "drivers/of/kexec.c".
Move the remaining architecture independent functions from "arch/powerpc/kexec/ima.c" to "drivers/of/kexec.c".
Delete "arch/powerpc/kexec/ima.c" and "arch/powerpc/include/asm/ima.h". Remove references to the deleted files and functions in powerpc and in ima.
--- arch/powerpc/include/asm/ima.h | 27 ---- arch/powerpc/include/asm/kexec.h | 3 - arch/powerpc/kexec/Makefile | 7 - arch/powerpc/kexec/file_load.c | 25 ---- arch/powerpc/kexec/file_load_64.c | 4 - arch/powerpc/kexec/ima.c | 202 ------------------------- drivers/of/kexec.c | 239 ++++++++++++++++++++++++++++++ include/linux/of.h | 2 + security/integrity/ima/ima.h | 4 - 9 files changed, 241 insertions(+), 272 deletions(-) delete mode 100644 arch/powerpc/include/asm/ima.h delete mode 100644 arch/powerpc/kexec/ima.c
arch/powerpc/include/asm/ima.h deleted +0 -27
@@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_POWERPC_IMA_H -#define _ASM_POWERPC_IMA_H - -struct kimage ; - -int ima_get_kexec_buffer (void **addr,size_t *size); -int ima_free_kexec_buffer (void ); - -#ifdef CONFIG_IMA -void remove_ima_buffer (void *fdt,int chosen_node); -#else -static inline void remove_ima_buffer (void *fdt,int chosen_node) {} -#endif - -#ifdef CONFIG_IMA_KEXEC -int setup_ima_buffer (const struct kimage *image,void *fdt,int chosen_node); -#else -static inline int setup_ima_buffer (const struct kimage *image,void *fdt, -int chosen_node) -{ -remove_ima_buffer (fdt, chosen_node); -return 0 ; -} -#endif /* CONFIG_IMA_KEXEC */ - -#endif /* _ASM_POWERPC_IMA_H */
arch/powerpc/include/asm/kexec.h +0 -3
@@ -119,9 +119,6 @@ char *setup_kdump_cmdline(struct kimage *image, char *cmdline,int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr); -int setup_new_fdt (const struct kimage *image,void *fdt, -unsigned long initrd_load_addr,unsigned long initrd_len, -const char *cmdline);int delete_fdt_mem_rsv (void *fdt,unsigned long start,unsigned long size);#ifdef CONFIG_PPC64
arch/powerpc/kexec/Makefile +0 -7
@@ -9,13 +9,6 @@ obj-$(CONFIG_PPC32) += relocate_32.o obj-$(CONFIG_KEXEC_FILE) += file_load.o ranges.o file_load_$(BITS).o elf_$(BITS).o -ifdef CONFIG_HAVE_IMA_KEXEC -ifdef CONFIG_IMA -obj-y += ima.o -endif -endif - - # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_core_$(BITS).o := n KCOV_INSTRUMENT_core_$(BITS).o := n
arch/powerpc/kexec/file_load.c +0 -25
@@ -19,7 +19,6 @@#include <linux/of_fdt.h> #include <linux/libfdt.h> #include <asm/setup.h> -#include <asm/ima.h> #define SLAVE_CODE_SIZE 256/* First 0x100 bytes */
@@ -140,27 +139,3 @@ int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size)return -ENOENT ; } - -/* -* setup_new_fdt - modify /chosen and memory reservation for the next kernel -* @image: kexec image being loaded. -* @fdt: Flattened device tree for the next kernel. -* @initrd_load_addr: Address where the next initrd will be loaded. -* @initrd_len: Size of the next initrd, or 0 if there will be none. -* @cmdline: Command line for the next kernel, or NULL if there will -* be none. -* -* Return: 0 on success, or negative errno on error. -*/ -int setup_new_fdt (const struct kimage *image,void *fdt, -unsigned long initrd_load_addr,unsigned long initrd_len, -const char *cmdline) -{ -int ret; - - ret =setup_ima_buffer (image, fdt,fdt_path_offset (fdt,"/chosen" )); -if (ret) -pr_err ("Error setting up the new device tree.\n" ); - -return ret; -}
arch/powerpc/kexec/file_load_64.c +0 -4
@@ -944,10 +944,6 @@ int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,struct crash_mem *umem =NULL , *rmem =NULL ;int i, nr_ranges, ret; - ret =setup_new_fdt (image, fdt, initrd_load_addr, initrd_len, cmdline); -if (ret) - goto out; -/* * Restrict memory usage for kdump kernel by setting up * usable memory ranges and memory reserve map.
arch/powerpc/kexec/ima.c deleted +0 -202
202 lines not on this page · raw message
drivers/of/kexec.c +239 -0
263 lines not on this page · raw message
include/linux/of.h +2 -0
@@ -578,6 +578,8 @@ int of_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr, size_t size);#endif /* CONFIG_IMA_KEXEC */ +int ima_get_kexec_buffer (void **addr,size_t *size); +int ima_free_kexec_buffer (void );#else /* CONFIG_OF */ static inline void of_core_init (void )
security/integrity/ima/ima.h +0 -4
@@ -24,10 +24,6 @@#include "../integrity.h" -#ifdef CONFIG_HAVE_IMA_KEXEC -#include <asm/ima.h> -#endif -enum ima_show_type {IMA_SHOW_BINARY ,IMA_SHOW_BINARY_NO_FIELD_LEN ,IMA_SHOW_BINARY_OLD_STRING_FMT ,IMA_SHOW_ASCII };enum tpm_pcrs {TPM_PCR0 =0 ,TPM_PCR8 =8 ,TPM_PCR10 =10 };
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 07/10] powerpc: Move arch independent ima kexec functions to drivers/of/kexec.c
Quoted 18 lines · Lakshmi Ramasubramanian
The functions defined in "
arch/powerpc/kexec/ima.c" handle setting up and freeing the resources required to carry over the IMA measurement list from the current kernel to the next kernel across kexec system call. These functions do not have architecture specific code, but are currently limited to powerpc.Move
remove_ima_buffer()andsetup_ima_buffer()calls intoof_kexec_alloc_and_setup_fdt()defined in "drivers/of/kexec.c".Move the remaining architecture independent functions from "
arch/powerpc/kexec/ima.c" to "drivers/of/kexec.c".
Delete "arch/powerpc/kexec/ima.c" and "arch/powerpc/include/asm/ima.h". Remove references to the deleted files and functions in powerpc and in ima.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>
Quoted 13 lines
--- arch/powerpc/include/asm/ima.h | 27 ---- arch/powerpc/include/asm/kexec.h | 3 - arch/powerpc/kexec/Makefile | 7 - arch/powerpc/kexec/file_load.c | 25 ---- arch/powerpc/kexec/file_load_64.c | 4 - arch/powerpc/kexec/ima.c | 202 ------------------------- drivers/of/kexec.c | 239 ++++++++++++++++++++++++++++++ include/linux/of.h | 2 + security/integrity/ima/ima.h | 4 - 9 files changed, 241 insertions(+), 272 deletions(-) delete mode 100644 arch/powerpc/include/asm/ima.h delete mode 100644 arch/powerpc/kexec/ima.c
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
PATCH v17 8/10 kexec: Use fdt_appendprop_addrrange() to add ima buffer to FDT
In reply to Lakshmi Ramasubramanianfdt_appendprop_addrrange() function adds a property, with the given name, to the device tree at the given node offset, and also sets the address and size of the property. This function should be used to add "linux,ima-kexec-buffer" property to the device tree and set the address and size of the IMA measurement buffer, instead of using custom function.
Use fdt_appendprop_addrrange() to add "linux,ima-kexec-buffer" property to the device tree. This property holds the address and size of the IMA measurement buffer that needs to be passed from the current kernel to the next kernel across kexec system call.
Remove custom code that is used in setup_ima_buffer() to add "linux,ima-kexec-buffer" property to the device tree.
--- drivers/of/kexec.c | 57 ++++------------------------------------------ 1 file changed, 5 insertions(+), 52 deletions(-)
drivers/of/kexec.c +5 -52
@@ -232,36 +232,6 @@ int of_ima_add_kexec_buffer(struct kimage *image,return 0 ; } -/** -* write_number - Convert number to big-endian format -* -* @p: Buffer to write the number to -* @value: Number to convert -* @cells: Number of cells -* -* Return: 0 on success, or negative errno on error. -*/ -static int write_number (void *p,u64 value,int cells) -{ -if (cells ==1 ) { -u32 tmp; - -if (value >U32_MAX ) -return -EINVAL ; - - tmp =cpu_to_be32 (value); -memcpy (p, &tmp,sizeof (tmp)); - }else if (cells ==2 ) { -u64 tmp; - - tmp =cpu_to_be64 (value); -memcpy (p, &tmp,sizeof (tmp)); - }else -return -EINVAL ; - -return 0 ; -} -/** * setup_ima_buffer - add IMA buffer information to the fdt * @image: kexec image being loaded.
@@ -273,32 +243,15 @@ static int write_number(void *p, u64 value, int cells)static int setup_ima_buffer (const struct kimage *image,void *fdt,int chosen_node) { -int ret, addr_cells, size_cells, entry_size; -u8 value[16 ]; +int ret;if (!image->ima_buffer_size)return 0 ; - ret =get_addr_size_cells (&addr_cells, &size_cells); -if (ret) -return ret; - - entry_size =4 * (addr_cells + size_cells); - -if (entry_size >sizeof (value)) -return -EINVAL ; - - ret =write_number (value, image->ima_buffer_addr, addr_cells); -if (ret) -return ret; - - ret =write_number (value +4 * addr_cells, image->ima_buffer_size, - size_cells); -if (ret) -return ret; - - ret =fdt_setprop (fdt, chosen_node,"linux,ima-kexec-buffer" , value, - entry_size); + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node, +"linux,ima-kexec-buffer" , + image->ima_buffer_addr, + image->ima_buffer_size);if (ret <0 )return -EINVAL ;
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 9/10 powerpc: Delete unused function delete_fdt_mem_rsv()
In reply to Lakshmi Ramasubramaniandelete_fdt_mem_rsv() defined in "arch/powerpc/kexec/file_load.c" has been renamed to fdt_find_and_del_mem_rsv(), and moved to "drivers/of/kexec.c".
Remove delete_fdt_mem_rsv() in "arch/powerpc/kexec/file_load.c".
--- arch/powerpc/include/asm/kexec.h | 1 - arch/powerpc/kexec/file_load.c | 32 -------------------------------- 2 files changed, 33 deletions(-)
arch/powerpc/include/asm/kexec.h +0 -1
@@ -119,7 +119,6 @@ char *setup_kdump_cmdline(struct kimage *image, char *cmdline,int setup_purgatory (struct kimage *image,const void *slave_code,const void *fdt,unsigned long kernel_load_addr,unsigned long fdt_load_addr); -int delete_fdt_mem_rsv (void *fdt,unsigned long start,unsigned long size);#ifdef CONFIG_PPC64 struct kexec_buf ;
arch/powerpc/kexec/file_load.c +0 -32
@@ -107,35 +107,3 @@ int setup_purgatory(struct kimage *image, const void *slave_code,return 0 ; } - -/** -* delete_fdt_mem_rsv - delete memory reservation with given address and size -* -* Return: 0 on success, or negative errno on error. -*/ -int delete_fdt_mem_rsv (void *fdt,unsigned long start,unsigned long size) -{ -int i, ret, num_rsvs =fdt_num_mem_rsv (fdt); - -for (i =0 ; i < num_rsvs; i++) { -uint64_t rsv_start, rsv_size; - - ret =fdt_get_mem_rsv (fdt, i, &rsv_start, &rsv_size); -if (ret) { -pr_err ("Malformed device tree.\n" ); -return -EINVAL ; - } - -if (rsv_start == start && rsv_size == size) { - ret =fdt_del_mem_rsv (fdt, i); -if (ret) { -pr_err ("Error deleting device tree reservation.\n" ); -return -EINVAL ; - } - -return 0 ; - } - } - -return -ENOENT ; -}
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 09/10] powerpc: Delete unused function delete_fdt_mem_rsv()
Quoted 6 lines · Lakshmi Ramasubramanian
delete_fdt_mem_rsv()defined in "arch/powerpc/kexec/file_load.c" has been renamed tofdt_find_and_del_mem_rsv(), and moved to "drivers/of/kexec.c".Remove
delete_fdt_mem_rsv()in "arch/powerpc/kexec/file_load.c".
Quoted 7 lines
Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/powerpc/include/asm/kexec.h | 1 - arch/powerpc/kexec/file_load.c | 32 -------------------------------- 2 files changed, 33 deletions(-)
Signature · 7 lines
Thiago Jung Bauermann IBM Linux Technology Center _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v17 10/10 arm64: Enable passing IMA log to next kernel on kexec
In reply to Lakshmi RamasubramanianUpdate CONFIG_KEXEC_FILE to select CONFIG_HAVE_IMA_KEXEC, if CONFIG_IMA is enabled, to indicate that the IMA measurement log information is present in the device tree for ARM64.
--- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/Kconfig +1 -0
@@ -1093,6 +1093,7 @@ config KEXEC config KEXEC_FILE bool "kexec file based system call" select KEXEC_CORE + select HAVE_IMA_KEXEC if IMA help This is new version of kexec system call. This system call is file based and takes file descriptors as system call argument
Signature · 7 lines
2.30.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v17 10/10] arm64: Enable passing IMA log to next kernel on kexec
Quoted 11 lines · Lakshmi Ramasubramanian
Update
CONFIG_KEXEC_FILEto selectCONFIG_HAVE_IMA_KEXEC, ifCONFIG_IMAis enabled, to indicate that the IMA measurement log information is present in the device tree for ARM64.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>Suggested-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+)
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Rob Herring
maintainerQuoted 19 lines · Lakshmi Ramasubramanian
On kexec file load Integrity Measurement Architecture (IMA) subsystem may verify the IMA signature of the kernel and initramfs, and measure it. The command line parameters passed to the kernel in the kexec call may also be measured by IMA. A remote attestation service can verify a TPM quote based on the TPM event log, the IMA measurement list, and the TPM PCR data. This can be achieved only if the IMA measurement log is carried over from the current kernel to the next kernel across the kexec call.
powerpc already supports carrying forward the IMA measurement log on kexec. This patch set adds support for carrying forward the IMA measurement log on kexec on ARM64.
This patch set moves the platform independent code defined for powerpc such that it can be reused for other platforms as well. A chosen node "linux,ima-kexec-buffer" is added to the DTB for ARM64 to hold the address and the size of the memory reserved to carry the IMA measurement log.
Quoted 8 lines
This patch set has been tested for ARM64 platform using QEMU. I would like help from the community for testing this change on powerpc. Thanks.
This patch set is based on
commit96acc833dec8("ima: Free IMA measurement buffer after kexec syscall") in https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
"next-integrity" branch.
Is that a hard dependency still? Given this is now almost entirely deleting arch code and adding drivers/of/ code, I was going to apply it.
Rob
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 24 lines · Rob Herring
Quoted 23 lines · Lakshmi Ramasubramanian
On kexec file load Integrity Measurement Architecture (IMA) subsystem may verify the IMA signature of the kernel and initramfs, and measure it. The command line parameters passed to the kernel in the kexec call may also be measured by IMA. A remote attestation service can verify a TPM quote based on the TPM event log, the IMA measurement list, and the TPM PCR data. This can be achieved only if the IMA measurement log is carried over from the current kernel to the next kernel across the kexec call.
powerpc already supports carrying forward the IMA measurement log on kexec. This patch set adds support for carrying forward the IMA measurement log on kexec on ARM64.
This patch set moves the platform independent code defined for powerpc such that it can be reused for other platforms as well. A chosen node "linux,ima-kexec-buffer" is added to the DTB for ARM64 to hold the address and the size of the memory reserved to carry the IMA measurement log.
This patch set has been tested for ARM64 platform using QEMU. I would like help from the community for testing this change on powerpc. Thanks.
Quoted 8 lines
Quoted 4 lines
This patch set is based on
commit96acc833dec8("ima: Free IMA measurement buffer after kexec syscall") in https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
"next-integrity" branch.Is that a hard dependency still? Given this is now almost entirely deleting arch code and adding
drivers/of/code, I was going to apply it.
I tried applying the patches in Linus' mainline branch -
PATCH #5 0005-powerpc-Move-ima-buffer-fields-to-struct-kimage.patch doesn't apply.
But if I apply the dependent patch set (link given below), all the patches in this patch set apply fine.
https://patchwork.kernel.org/project/linux-integrity/patch/[email protected]/
thanks,
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Rob Herring
maintainerQuoted 35 lines · Lakshmi Ramasubramanian
Quoted 24 lines · Rob Herring
Quoted 23 lines · Lakshmi Ramasubramanian
On kexec file load Integrity Measurement Architecture (IMA) subsystem may verify the IMA signature of the kernel and initramfs, and measure it. The command line parameters passed to the kernel in the kexec call may also be measured by IMA. A remote attestation service can verify a TPM quote based on the TPM event log, the IMA measurement list, and the TPM PCR data. This can be achieved only if the IMA measurement log is carried over from the current kernel to the next kernel across the kexec call.
powerpc already supports carrying forward the IMA measurement log on kexec. This patch set adds support for carrying forward the IMA measurement log on kexec on ARM64.
This patch set moves the platform independent code defined for powerpc such that it can be reused for other platforms as well. A chosen node "linux,ima-kexec-buffer" is added to the DTB for ARM64 to hold the address and the size of the memory reserved to carry the IMA measurement log.
This patch set has been tested for ARM64 platform using QEMU. I would like help from the community for testing this change on powerpc. Thanks.
Quoted 8 lines
Quoted 4 lines
This patch set is based on
commit96acc833dec8("ima: Free IMA measurement buffer after kexec syscall") in https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
"next-integrity" branch.Is that a hard dependency still? Given this is now almost entirely deleting arch code and adding
drivers/of/code, I was going to apply it.
Quoted 8 lines
I tried applying the patches in Linus' mainline branch - PATCH #5 0005-powerpc-Move-ima-buffer-fields-to-struct-kimage.patch doesn't apply.
But if I apply the dependent patch set (link given below), all the patches in this patch set apply fine.
https://patchwork.kernel.org/project/linux-integrity/patch/[email protected]/
Ideally, we don't apply the same patch in 2 branches. It looks like there's a conflict but no real dependence on the above patch (the ima_buffer part). The conflict seems trivial enough that Linus can resolve it in the merge window.
Or Mimi can take the whole thing if preferred?
Rob
Mimi Zohar
maintainerQuoted 44 lines · Rob Herring
Quoted 42 lines · Lakshmi Ramasubramanian
Quoted 24 lines · Rob Herring
Quoted 23 lines · Lakshmi Ramasubramanian
On kexec file load Integrity Measurement Architecture (IMA) subsystem may verify the IMA signature of the kernel and initramfs, and measure it. The command line parameters passed to the kernel in the kexec call may also be measured by IMA. A remote attestation service can verify a TPM quote based on the TPM event log, the IMA measurement list, and the TPM PCR data. This can be achieved only if the IMA measurement log is carried over from the current kernel to the next kernel across the kexec call.
powerpc already supports carrying forward the IMA measurement log on kexec. This patch set adds support for carrying forward the IMA measurement log on kexec on ARM64.
This patch set moves the platform independent code defined for powerpc such that it can be reused for other platforms as well. A chosen node "linux,ima-kexec-buffer" is added to the DTB for ARM64 to hold the address and the size of the memory reserved to carry the IMA measurement log.
This patch set has been tested for ARM64 platform using QEMU. I would like help from the community for testing this change on powerpc. Thanks.
Quoted 8 lines
Quoted 4 lines
This patch set is based on
commit96acc833dec8("ima: Free IMA measurement buffer after kexec syscall") in https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
"next-integrity" branch.Is that a hard dependency still? Given this is now almost entirely deleting arch code and adding
drivers/of/code, I was going to apply it.I tried applying the patches in Linus' mainline branch - PATCH #5 0005-powerpc-Move-ima-buffer-fields-to-struct-kimage.patch doesn't apply.
But if I apply the dependent patch set (link given below), all the patches in this patch set apply fine.
Quoted 8 lines
Ideally, we don't apply the same patch in 2 branches. It looks like there's a conflict but no real dependence on the above patch (the
ima_bufferpart). The conflict seems trivial enough that Linus can resolve it in the merge window.Or Mimi can take the whole thing if preferred?
How about I create a topic branch with just the two patches, allowing
both of us to merge it? There shouldn't be a problem with re-writing
next-integrity history.
Mimi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mimi Zohar
maintainerQuoted 8 lines · Mimi Zohar
Quoted 7 lines · Rob Herring
On Wed, Feb 10, 2021 at 11:33 AM Lakshmi Ramasubramanian
Ideally, we don't apply the same patch in 2 branches. It looks like there's a conflict but no real dependence on the above patch (the
ima_bufferpart). The conflict seems trivial enough that Linus can resolve it in the merge window.
Quoted 5 lines
Quoted 1 line
Or Mimi can take the whole thing if preferred?
How about I create a topic branch with just the two patches, allowing
both of us to merge it? There shouldn't be a problem with re-writing
next-integrity history.
The 2 patches are now in the ima-kexec-fixes branch.
Mimi
Quoted 9 lines · Mimi Zohar
Quoted 8 lines · Mimi Zohar
Quoted 7 lines · Rob Herring
On Wed, Feb 10, 2021 at 11:33 AM Lakshmi Ramasubramanian
Ideally, we don't apply the same patch in 2 branches. It looks like there's a conflict but no real dependence on the above patch (the
ima_bufferpart). The conflict seems trivial enough that Linus can resolve it in the merge window.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Or Mimi can take the whole thing if preferred?
How about I create a topic branch with just the two patches, allowing
both of us to merge it? There shouldn't be a problem with re-writing
next-integrity history.The 2 patches are now in the ima-kexec-fixes branch.
Thanks a lot Mimi.
Rob - I will address the 2 comments you'd provided today, and build the patches in ima-kexec-fixes branch.
If you have more comments in the v17 patches, please let me know.
thanks,
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel