Carry forward IMA measurement log on kexec on ARM64
Subsystems (7)
PATCH v15 1/10 powerpc: Rename kexec elfcorehdr_addr to elf_headers_mem
In reply to Lakshmi RamasubramanianFrom: 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 · 1 line
2.30.0
PATCH v15 3/10 arm64: Use common of_kexec_setup_new_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_setup_new_fdt() defined in "drivers/of/kexec.c".
Use the common of_kexec_setup_new_fdt() to setup the device tree and update the memory reservation for kexec for arm64.
--- arch/arm64/kernel/machine_kexec_file.c | 123 +------------------------ 1 file changed, 3 insertions(+), 120 deletions(-)
arch/arm64/kernel/machine_kexec_file.c +3 -120
@@ -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,
@@ -50,112 +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.
@@ -185,8 +68,8 @@ static int create_dtb(struct kimage *image,if (ret)return -EINVAL ; - ret =setup_dtb (image, initrd_load_addr, initrd_len, - cmdline, buf); + ret =of_kexec_setup_new_fdt (image, buf, initrd_load_addr, + initrd_len, cmdline);if (ret) {vfree (buf);if (ret == -ENOMEM ) {
Signature · 1 line
2.30.0
PATCH v15 4/10 powerpc: Use common of_kexec_setup_new_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_setup_new_fdt() defined in "drivers/of/kexec.c".
Use the common of_kexec_setup_new_fdt() to setup the device tree and update the memory reservation for kexec for powerpc.
--- arch/powerpc/kexec/file_load.c | 125 ++------------------------------- 1 file changed, 6 insertions(+), 119 deletions(-)
arch/powerpc/kexec/file_load.c +6 -119
@@ -16,6 +16,7 @@#include <linux/slab.h> #include <linux/kexec.h> +#include <linux/of.h> #include <linux/of_fdt.h> #include <linux/libfdt.h> #include <asm/setup.h>
@@ -156,132 +157,18 @@ int setup_new_fdt(const struct kimage *image, void *fdt, unsigned long initrd_load_addr, unsigned long initrd_len, const char *cmdline) { - int ret, chosen_node; -const void *prop; - -/* Remove memory reservation for the current device tree. */ - ret =delete_fdt_mem_rsv (fdt,__pa (initial_boot_params), -fdt_totalsize (initial_boot_params)); -if (ret ==0 ) -pr_debug ("Removed old device tree reservation.\n" ); -else if (ret != -ENOENT ) -return ret; - - 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 ) { -pr_err ("Error creating /chosen.\n" ); -return -EINVAL ; - } - }else if (chosen_node <0 ) { -pr_err ("Malformed device tree: error reading /chosen.\n" ); -return -EINVAL ; - } - -/* Did we boot using an initrd? */ - prop =fdt_getprop (fdt, chosen_node,"linux,initrd-start" ,NULL ); -if (prop) { -uint64_t 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) { -pr_err ("Malformed device tree.\n" ); -return -EINVAL ; - } - 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 =delete_fdt_mem_rsv (fdt, tmp_start, tmp_size); -if (ret == -ENOENT ) - ret =delete_fdt_mem_rsv (fdt, tmp_start, -round_up (tmp_size,PAGE_SIZE )); -if (ret ==0 ) -pr_debug ("Removed old initrd reservation.\n" ); -else if (ret != -ENOENT ) -return ret; - -/* If there's no new initrd, delete the old initrd's info. */ -if (initrd_len ==0 ) { - ret =fdt_delprop (fdt, chosen_node, -"linux,initrd-start" ); -if (ret) { -pr_err ("Error deleting linux,initrd-start.\n" ); -return -EINVAL ; - } - - ret =fdt_delprop (fdt, chosen_node,"linux,initrd-end" ); -if (ret) { -pr_err ("Error deleting linux,initrd-end.\n" ); -return -EINVAL ; - } - } - } - -if (initrd_len) { - ret =fdt_setprop_u64 (fdt, chosen_node, -"linux,initrd-start" , - initrd_load_addr); -if (ret <0 ) - goto err; - -/* initrd-end is the first address after the initrd image. */ - ret =fdt_setprop_u64 (fdt, chosen_node,"linux,initrd-end" , - initrd_load_addr + initrd_len); -if (ret <0 ) - goto err; - - ret =fdt_add_mem_rsv (fdt, initrd_load_addr, initrd_len); -if (ret) { -pr_err ("Error reserving initrd memory: %s\n" , -fdt_strerror (ret)); -return -EINVAL ; - } - } - -if (cmdline !=NULL ) { - ret =fdt_setprop_string (fdt, chosen_node,"bootargs" , cmdline); -if (ret <0 ) - goto err; - }else { - ret =fdt_delprop (fdt, chosen_node,"bootargs" ); -if (ret && ret != -FDT_ERR_NOTFOUND ) { -pr_err ("Error deleting bootargs.\n" ); -return -EINVAL ; - } - } + int ret; -if (image->type ==KEXEC_TYPE_CRASH ) { -/* -* 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) { -pr_err ("Error reserving elfcorehdr memory: %s\n" , -fdt_strerror (ret)); - goto err; - } - } + ret =of_kexec_setup_new_fdt (image, fdt, initrd_load_addr, initrd_len, cmdline); +if (ret) + goto err; - ret =setup_ima_buffer (image, fdt, chosen_node); + 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; } - ret =fdt_setprop (fdt, chosen_node,"linux,booted-from-kexec" ,NULL ,0 ); -if (ret) - goto err; -return 0 ; err:
Signature · 1 line
2.30.0
v15 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 207cdd565dfc ("ima: Don't modify file descriptor mode on the fly") in https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git
"next-integrity" branch.
Changelog:
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):
ima: Move arch_ima_add_kexec_buffer() to ima
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: Call kmalloc() to allocate DTB buffer
arm64: Add IMA log information in kimage used for 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_setup_new_fdt()
powerpc: Use common of_kexec_setup_new_fdt()
arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 + arch/arm64/kernel/machine_kexec_file.c | 135 +------- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/ima.h | 30 -- arch/powerpc/include/asm/kexec.h | 6 +- arch/powerpc/kexec/Makefile | 7 - arch/powerpc/kexec/file_load.c | 184 +---------- arch/powerpc/kexec/file_load_64.c | 8 +- arch/powerpc/kexec/ima.c | 219 ------------- drivers/of/Makefile | 1 + drivers/of/kexec.c | 429 +++++++++++++++++++++++++ include/linux/of.h | 7 + security/integrity/ima/ima.h | 4 - security/integrity/ima/ima_kexec.c | 22 ++ 15 files changed, 484 insertions(+), 576 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 · 1 line
2.30.0
PATCH v15 2/10 of: Add a common kexec FDT setup function
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_setup_new_fdt() and move it to "drivers/of/kexec.c".
--- drivers/of/Makefile | 1 + drivers/of/kexec.c | 236 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 5 + 3 files changed, 242 insertions(+) create mode 100644 drivers/of/kexec.c
drivers/of/Makefile +1 -0
@@ -13,5 +13,6 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +obj-$(CONFIG_KEXEC_FILE) += kexec.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/
drivers/of/kexec.c new file +236 -0
236 lines not on this page · raw message
include/linux/of.h +5 -0
@@ -558,6 +558,11 @@ int of_map_id(struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, struct device_node **target, u32 *id_out); +struct kimage ; +int of_kexec_setup_new_fdt (const struct kimage *image,void *fdt, +unsigned long initrd_load_addr,unsigned long initrd_len, +const char *cmdline); +#else /* CONFIG_OF */ static inline void of_core_init (void )
Signature · 1 line
2.30.0
PATCH v15 6/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 setup_ima_buffer() call into of_kexec_setup_new_fdt() defined in "drivers/of/kexec.c". Call of_kexec_setup_new_fdt() from setup_new_fdt_ppc64() and remove setup_new_fdt() in "arch/powerpc/kexec/file_load.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 in powerpc and in ima.
--- arch/powerpc/Kconfig | 2 +- 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 | 35 ----- arch/powerpc/kexec/file_load_64.c | 4 +- arch/powerpc/kexec/ima.c | 202 ------------------------ drivers/of/kexec.c | 240 +++++++++++++++++++++++++++++ include/linux/of.h | 2 + security/integrity/ima/ima.h | 4 - security/integrity/ima/ima_kexec.c | 1 + 11 files changed, 247 insertions(+), 280 deletions(-) delete mode 100644 arch/powerpc/include/asm/ima.h delete mode 100644 arch/powerpc/kexec/ima.c
arch/powerpc/Kconfig +1 -1
@@ -548,7 +548,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
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
@@ -123,9 +123,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 -35
@@ -20,7 +20,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 */
@@ -141,37 +140,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 =of_kexec_setup_new_fdt (image, fdt, initrd_load_addr, initrd_len, cmdline); -if (ret) - goto err; - - 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; - } - -return 0 ; - -err: -pr_err ("Error setting up the new device tree.\n" ); -return -EINVAL ; -}
arch/powerpc/kexec/file_load_64.c +3 -1
@@ -17,6 +17,7 @@#include <linux/kexec.h> #include <linux/of_fdt.h> #include <linux/libfdt.h> +#include <linux/of.h> #include <linux/of_device.h> #include <linux/memblock.h> #include <linux/slab.h>
@@ -944,7 +945,8 @@ 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); + ret =of_kexec_setup_new_fdt (image, fdt, initrd_load_addr, initrd_len, + cmdline);if (ret) goto out;
arch/powerpc/kexec/ima.c deleted +0 -202
202 lines not on this page · raw message
drivers/of/kexec.c +240 -0
258 lines not on this page · raw message
include/linux/of.h +2 -0
@@ -562,6 +562,8 @@ struct kimage;int of_kexec_setup_new_fdt (const struct kimage *image,void *fdt,unsigned long initrd_load_addr,unsigned long initrd_len,const char *cmdline); +int ima_get_kexec_buffer (void **addr,size_t *size); +int ima_free_kexec_buffer (void );#else /* CONFIG_OF */
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 };
security/integrity/ima/ima_kexec.c +1 -0
@@ -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
Signature · 1 line
2.30.0
PATCH v15 8/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
@@ -123,7 +123,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
@@ -108,35 +108,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 · 1 line
2.30.0
PATCH v15 9/10 arm64: Call kmalloc() to allocate DTB buffer
In reply to Lakshmi Ramasubramaniancreate_dtb() function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which calls kmalloc() for allocating memory for the DTB.
Call kmalloc() to allocate memory for the DTB, and kfree() to free the allocated memory.
--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
arch/arm64/kernel/machine_kexec_file.c +7 -5
@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);
@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );if (!buf)return -ENOMEM ;/* duplicate a device tree blob */ ret =fdt_open_into (initial_boot_params, buf, buf_size); -if (ret) +if (ret) { +kfree (buf);return -EINVAL ; + } ret =of_kexec_setup_new_fdt (image, buf, initrd_load_addr, initrd_len, cmdline);if (ret) { -vfree (buf); +kfree (buf);if (ret == -ENOMEM ) {/* unlikely, but just in case */ buf_size +=DTB_EXTRA_SPACE ;
@@ -217,6 +219,6 @@ int load_other_segments(struct kimage *image,return 0 ; out_err: -vfree (dtb); +kfree (dtb);return ret; }
Signature · 1 line
2.30.0
PATCH v15 10/10 arm64: Add IMA log information in kimage used for kexec
In reply to Lakshmi RamasubramanianAddress and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.
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 ARM64.
--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)
arch/arm64/Kconfig +1 -0
@@ -1094,6 +1094,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
arch/arm64/include/asm/kexec.h +5 -0
@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif };extern const struct kexec_file_ops kexec_image_ops;
Signature · 1 line
2.30.0
PATCH v15 5/10 ima: Move arch_ima_add_kexec_buffer() to ima
In reply to Lakshmi Ramasubramanianarch_ima_add_kexec_buffer() defined in "arch/powerpc/kexec/ima.c" sets up the address and size of the IMA measurement list in the architecture specific fields in kimage struct. This function does not have architecture specific code, but is currently limited to powerpc.
Move arch_ima_add_kexec_buffer() to ima.
--- arch/powerpc/include/asm/ima.h | 3 --- arch/powerpc/kexec/ima.c | 17 ----------------- security/integrity/ima/ima_kexec.c | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 20 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/kexec/ima.c +0 -17
@@ -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 ) {
security/integrity/ima/ima_kexec.c +21 -0
@@ -71,6 +71,27 @@ static int ima_dump_measurement_list(unsigned long *buffer_size, void **buffer,return ret; } +/** +* arch_ima_add_kexec_buffer - do arch-specific steps to add the IMA buffer +* +* @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 +* +* Architectures should use this function to pass on the IMA buffer +* information to the next kernel. +* +* Return: 0 on success, negative errno on error. +*/ +static 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 ; +} +/* * Called during kexec_file_load so that IMA can add a segment to the kexec * image for the measurement list for the next kernel.
Signature · 1 line
2.30.0
PATCH v15 7/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
@@ -210,36 +210,6 @@ int ima_free_kexec_buffer(void) }#ifdef CONFIG_IMA_KEXEC -/** -* 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.
@@ -251,32 +221,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->arch.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->arch.ima_buffer_addr, addr_cells); -if (ret) -return ret; - - ret =write_number (value +4 * addr_cells, image->arch.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->arch.ima_buffer_addr, + image->arch.ima_buffer_size);if (ret <0 )return -EINVAL ;
Signature · 1 line
2.30.0
Mimi Zohar
maintainerRe: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Lakshmi RamasubramanianHi Ard,
Quoted 7 lines · Lakshmi Ramasubramanian
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.
The vmalloc() function description says, "vmalloc - allocate virtually contiguous memory". I'd appreciate your reviewing this patch, in particular, which replaces vmalloc() with kmalloc().
thanks,
Mimi
Quoted 47 lines
Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +6
-4@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );if (!buf)return -ENOMEM ;/* duplicate a device tree blob */ ret =fdt_open_into (initial_boot_params, buf, buf_size); -if (ret) +if (ret) { +kfree (buf);return -EINVAL ; + } ret =of_kexec_setup_new_fdt (image, buf, initrd_load_addr, initrd_len, cmdline);if (ret) { -vfree (buf); +kfree (buf);if (ret == -ENOMEM ) {/* unlikely, but just in case */ buf_size +=DTB_EXTRA_SPACE ;
arch/arm64/kernel/machine_kexec_file.c int load_other_segments(struct kimage *image, · line 224
Quoted 7 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -217,6 +219,6 @@ int load_other_segments(struct kimage *image,return 0 ; out_err: -vfree (dtb); +kfree (dtb);return ret; }
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerRe: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Lakshmi RamasubramanianQuoted 29 lines · Lakshmi Ramasubramanian
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);
arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 62
Quoted 5 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );
Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for kmalloc().
Will
Will Deacon
maintainerRe: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
In reply to Lakshmi RamasubramanianQuoted 36 lines · Lakshmi Ramasubramanian
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 8 lines
arch/arm64/include/asm/kexec.h +5
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif
Why do these need to be in the arch structure instead of 'struct kimage'?
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
On 1/27/21 8:54 AM, Will Deacon wrote:
Hi Will,
Quoted 39 lines · Lakshmi Ramasubramanian
Quoted 38 lines
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;
Quoted 9 lines
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 6 lines
arch/arm64/include/asm/kexec.h +5
-0unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif Why do these need to be in the arch structure instead of 'struct kimage'?
Currently, only powerpc and, with this patch set, arm64 have support for carrying forward IMA measurement list across kexec system call. The above fields are used for tracking IMA measurement list.
Do you see a reason to move these fields to "struct kimage"?
thanks,
-lakshmi
Re: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Will DeaconOn 1/27/21 8:52 AM, Will Deacon wrote:
Hi Will,
Quoted 32 lines · Lakshmi Ramasubramanian
Quoted 31 lines
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;
Quoted 7 lines
arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 62
Quoted 3 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for
kmalloc().
Changing the allocation from vmalloc() to kmalloc() would help us further consolidate the DTB setup code for powerpc and arm64.
thanks,
-lakshmi
Will Deacon
maintainerRe: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
In reply to Lakshmi RamasubramanianQuoted 50 lines · Lakshmi Ramasubramanian
Quoted 39 lines · Will Deacon
Quoted 38 lines · Lakshmi Ramasubramanian
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;Quoted 9 lines
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 6 lines
arch/arm64/include/asm/kexec.h +5
-0unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif Why do these need to be in the arch structure instead of 'struct kimage'?
Quoted 5 lines
Currently, only powerpc and, with this patch set, arm64 have support for carrying forward IMA measurement list across kexec system call. The above fields are used for tracking IMA measurement list.
Do you see a reason to move these fields to "struct kimage"?
If they're gated on CONFIG_IMA_KEXEC, then it seems harmless for them to be added to the shared structure. Or are you saying that there are architectures which have CONFIG_IMA_KEXEC but do not want these fields?
Will
Re: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
Quoted 55 lines · Will Deacon
Quoted 54 lines · Lakshmi Ramasubramanian
Quoted 39 lines · Will Deacon
Quoted 38 lines · Lakshmi Ramasubramanian
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;Quoted 9 lines
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 6 lines
arch/arm64/include/asm/kexec.h +5
-0unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif Why do these need to be in the arch structure instead of 'struct kimage'?
Currently, only powerpc and, with this patch set, arm64 have support for carrying forward IMA measurement list across kexec system call. The above fields are used for tracking IMA measurement list.
Quoted 6 lines
Quoted 1 line
Do you see a reason to move these fields to "struct kimage"?
If they're gated on
CONFIG_IMA_KEXEC, then it seems harmless for them to be added to the shared structure. Or are you saying that there are architectures which haveCONFIG_IMA_KEXECbut do not want these fields?
As far as I know, there are no other architectures that define CONFIG_IMA_KEXEC, but do not use these fields.
Mimi - please correct me if I am wrong.
thanks,
-lakshmi
Mimi Zohar
maintainerRe: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
Quoted 58 lines · Lakshmi Ramasubramanian
Quoted 57 lines · Will Deacon
Quoted 55 lines · Lakshmi Ramasubramanian
Quoted 39 lines · Will Deacon
Quoted 38 lines · Lakshmi Ramasubramanian
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;Quoted 9 lines
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 6 lines
arch/arm64/include/asm/kexec.h +5
-0unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif Why do these need to be in the arch structure instead of 'struct kimage'?
Currently, only powerpc and, with this patch set, arm64 have support for carrying forward IMA measurement list across kexec system call. The above fields are used for tracking IMA measurement list.
Do you see a reason to move these fields to "struct kimage"?
Quoted 7 lines
Quoted 4 lines
If they're gated on
CONFIG_IMA_KEXEC, then it seems harmless for them to be added to the shared structure. Or are you saying that there are architectures which haveCONFIG_IMA_KEXECbut do not want these fields?As far as I know, there are no other architectures that define
CONFIG_IMA_KEXEC, but do not use these fields.
Yes, CONFIG_IMA_KEXEC enables "carrying the IMA measurement list across
a soft boot". The only arch that currently carries the IMA
measurement across kexec is powerpc.
Mimi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerRe: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Lakshmi RamasubramanianQuoted 41 lines · Lakshmi Ramasubramanian
On 1/27/21 8:52 AM, Will Deacon wrote:
Hi Will,
Quoted 28 lines · Lakshmi Ramasubramanian
Quoted 27 lines
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image,Quoted 8 lines
arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 62
Quoted 4 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1+ cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for
kmalloc().
Quoted 2 lines
Changing the allocation from
vmalloc()tokmalloc()would help us further consolidate the DTB setup code for powerpc and arm64.
Ok, but at the risk of allocation failure. Can powerpc use vmalloc() instead?
Will
Will Deacon
maintainerRe: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
In reply to Mimi ZoharQuoted 64 lines · Mimi Zohar
Quoted 63 lines · Lakshmi Ramasubramanian
Quoted 61 lines · Will Deacon
Quoted 50 lines · Lakshmi Ramasubramanian
Quoted 39 lines · Will Deacon
Quoted 38 lines · Lakshmi Ramasubramanian
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;Quoted 9 lines
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 6 lines
arch/arm64/include/asm/kexec.h +5
-0unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif Why do these need to be in the arch structure instead of 'struct kimage'?
Quoted 5 lines
Currently, only powerpc and, with this patch set, arm64 have support for carrying forward IMA measurement list across kexec system call. The above fields are used for tracking IMA measurement list.
Do you see a reason to move these fields to "struct kimage"?
If they're gated on
CONFIG_IMA_KEXEC, then it seems harmless for them to be added to the shared structure. Or are you saying that there are architectures which haveCONFIG_IMA_KEXECbut do not want these fields?
Quoted 6 lines
Quoted 2 lines
As far as I know, there are no other architectures that define
CONFIG_IMA_KEXEC, but do not use these fields.Yes,
CONFIG_IMA_KEXECenables "carrying the IMA measurement list across
a soft boot". The only arch that currently carries the IMA
measurement across kexec is powerpc.
Ok, in which case this sounds like it should be in the shared structure, no?
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Will DeaconQuoted 42 lines · Will Deacon
Quoted 41 lines · Lakshmi Ramasubramanian
On 1/27/21 8:52 AM, Will Deacon wrote:
Hi Will,
Quoted 36 lines · Lakshmi Ramasubramanian
Quoted 27 lines
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 61
Quoted 4 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for
kmalloc().
Quoted 5 lines
Quoted 2 lines
Changing the allocation from
vmalloc()tokmalloc()would help us further consolidate the DTB setup code for powerpc and arm64.Ok, but at the risk of allocation failure. Can powerpc use
vmalloc()instead?
I believe this patch stems from this suggestion by Rob Herring:
Quoted 4 lines
This could be taken a step further and do the allocation of the new FDT. The difference is arm64 uses vmalloc and powerpc uses kmalloc. The arm64 version also retries with a bigger allocation. That seems unnecessary.
in https://lore.kernel.org/linux-integrity/[email protected]/
The problem is that this patch implements only part of the suggestion, which isn't useful in itself. So the patch series should either drop this patch or consolidate the FDT allocation between the arches.
I just tested on powernv and pseries platforms and powerpc can use vmalloc for the FDT buffer.
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
Quoted 58 lines · Thiago Jung Bauermann
Quoted 42 lines · Will Deacon
Quoted 41 lines · Lakshmi Ramasubramanian
On 1/27/21 8:52 AM, Will Deacon wrote:
Hi Will,
Quoted 36 lines · Lakshmi Ramasubramanian
Quoted 27 lines
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 61
Quoted 4 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for
kmalloc().Quoted 5 lines
Quoted 2 lines
Changing the allocation from
vmalloc()tokmalloc()would help us further consolidate the DTB setup code for powerpc and arm64.Ok, but at the risk of allocation failure. Can powerpc use
vmalloc()instead?I believe this patch stems from this suggestion by Rob Herring:
Quoted 4 lines
This could be taken a step further and do the allocation of the new FDT. The difference is arm64 uses vmalloc and powerpc uses kmalloc. The arm64 version also retries with a bigger allocation. That seems unnecessary.
Quoted 9 lines
in https://lore.kernel.org/linux-integrity/[email protected]/
The problem is that this patch implements only part of the suggestion, which isn't useful in itself. So the patch series should either drop this patch or consolidate the FDT allocation between the arches.
I just tested on powernv and pseries platforms and powerpc can use vmalloc for the FDT buffer.
Thanks for verifying on powerpc platform Thiago.
I'll update the patch to do the following:
=> Use vmalloc for FDT buffer allocation on powerpc
=> Keep vmalloc for arm64, but remove the retry on allocation.
=> Also, there was a memory leak of FDT buffer in the error code path on arm64, which I'll fix as well.
Did I miss anything?
thanks,
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v15 10/10] arm64: Add IMA log information in kimage used for kexec
In reply to Will DeaconQuoted 65 lines · Will Deacon
Quoted 64 lines · Mimi Zohar
Quoted 63 lines · Lakshmi Ramasubramanian
Quoted 61 lines · Will Deacon
Quoted 50 lines · Lakshmi Ramasubramanian
Quoted 39 lines · Will Deacon
Quoted 38 lines · Lakshmi Ramasubramanian
Address and size of the buffer containing the IMA measurement log need to be passed from the current kernel to the next kernel on kexec.
Add address and size fields to "struct
kimage_arch" for ARM64 platform to hold the address and size of the IMA measurement log buffer.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]>Reviewed-by Thiago Jung Bauermann <[email protected]>--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/kexec.h | 5 +++++ 2 files changed, 6 insertions(+)arch/arm64/Kconfig +1
-0@@ -1094,6 +1094,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 argumentarch/arm64/include/asm/kexec.h +0
-0@@ -100,6 +100,11 @@ struct kimage_arch {void *elf_headers;unsigned long elf_headers_mem;Quoted 9 lines
arch/arm64/include/asm/kexec.h struct kimage_arch { · line 107
Quoted 6 lines
arch/arm64/include/asm/kexec.h +5
-0unsigned long elf_headers_sz; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif Why do these need to be in the arch structure instead of 'struct kimage'?
Quoted 5 lines
Currently, only powerpc and, with this patch set, arm64 have support for carrying forward IMA measurement list across kexec system call. The above fields are used for tracking IMA measurement list.
Do you see a reason to move these fields to "struct kimage"?
If they're gated on
CONFIG_IMA_KEXEC, then it seems harmless for them to be added to the shared structure. Or are you saying that there are architectures which haveCONFIG_IMA_KEXECbut do not want these fields?
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
As far as I know, there are no other architectures that define
CONFIG_IMA_KEXEC, but do not use these fields.Yes,
CONFIG_IMA_KEXECenables "carrying the IMA measurement list across
a soft boot". The only arch that currently carries the IMA
measurement across kexec is powerpc.Ok, in which case this sounds like it should be in the shared structure, no?
Ok - I'll move the IMA kexec buffer fields from "struct kimage_arch" to "struct kimage" for both powerpc and arm64.
thanks,
-lakshmi
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Lakshmi RamasubramanianQuoted 67 lines · Lakshmi Ramasubramanian
Quoted 55 lines · Thiago Jung Bauermann
Quoted 42 lines · Will Deacon
Quoted 41 lines · Lakshmi Ramasubramanian
On 1/27/21 8:52 AM, Will Deacon wrote:
Hi Will,
Quoted 36 lines · Lakshmi Ramasubramanian
Quoted 27 lines
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 61
Quoted 4 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for
kmalloc().Quoted 5 lines
Quoted 2 lines
Changing the allocation from
vmalloc()tokmalloc()would help us further consolidate the DTB setup code for powerpc and arm64.Ok, but at the risk of allocation failure. Can powerpc use
vmalloc()instead?I believe this patch stems from this suggestion by Rob Herring:
Quoted 4 lines
This could be taken a step further and do the allocation of the new FDT. The difference is arm64 uses vmalloc and powerpc uses kmalloc. The arm64 version also retries with a bigger allocation. That seems unnecessary.
Quoted 8 lines
in
https://lore.kernel.org/linux-integrity/[email protected]/
The problem is that this patch implements only part of the suggestion, which isn't useful in itself. So the patch series should either drop this patch or consolidate the FDT allocation between the arches. I just tested on powernv and pseries platforms and powerpc can use vmalloc for the FDT buffer.Thanks for verifying on powerpc platform Thiago.
Quoted 8 lines
I'll update the patch to do the following:
=> Use vmalloc for FDT buffer allocation on powerpc
=> Keep vmalloc for arm64, but remove the retry on allocation.
=> Also, there was a memory leak of FDT buffer in the error code path on arm64, which I'll fix as well.Did I miss anything?
Yes, you missed the second part of Rob's suggestion I was mentioning, which is factoring out the code which allocates the new FDT from both arm64 and powerpc.
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 v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
Quoted 77 lines · Thiago Jung Bauermann
Quoted 74 lines · Lakshmi Ramasubramanian
Quoted 55 lines · Thiago Jung Bauermann
Quoted 42 lines · Will Deacon
Quoted 41 lines · Lakshmi Ramasubramanian
On 1/27/21 8:52 AM, Will Deacon wrote:
Hi Will,
Quoted 36 lines · Lakshmi Ramasubramanian
Quoted 27 lines
create_dtb()function allocates kernel virtual memory for the device tree blob (DTB). This is not consistent with other architectures, such as powerpc, which callskmalloc()for allocating memory for the DTB.Call
kmalloc()to allocate memory for the DTB, andkfree()to free the allocated memory.Co-developed-by Prakhar Srivastava <[email protected]>Signed-off-by Prakhar Srivastava <[email protected]>Signed-off-by Lakshmi Ramasubramanian <[email protected]>--- arch/arm64/kernel/machine_kexec_file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -29,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); +kfree (image->arch.dtb); image->arch.dtb =NULL ;vfree (image->arch.elf_headers);arch/arm64/kernel/machine_kexec_file.c static int create_dtb(struct kimage *image, · line 61
Quoted 4 lines
arch/arm64/kernel/machine_kexec_file.c +1
-1@@ -59,19 +59,21 @@ static int create_dtb(struct kimage *image, + cmdline_len +DTB_EXTRA_SPACE ;for (;;) { - buf =vmalloc (buf_size); + buf =kmalloc (buf_size,GFP_KERNEL );Is there a functional need for this patch? I build the 'dtbs' target just now and sdm845-db845c.dtb is approaching 100K, which feels quite large for
kmalloc().Quoted 5 lines
Quoted 2 lines
Changing the allocation from
vmalloc()tokmalloc()would help us further consolidate the DTB setup code for powerpc and arm64.Ok, but at the risk of allocation failure. Can powerpc use
vmalloc()instead?I believe this patch stems from this suggestion by Rob Herring:
Quoted 4 lines
This could be taken a step further and do the allocation of the new FDT. The difference is arm64 uses vmalloc and powerpc uses kmalloc. The arm64 version also retries with a bigger allocation. That seems unnecessary.
Quoted 8 lines
in
https://lore.kernel.org/linux-integrity/[email protected]/
The problem is that this patch implements only part of the suggestion, which isn't useful in itself. So the patch series should either drop this patch or consolidate the FDT allocation between the arches. I just tested on powernv and pseries platforms and powerpc can use vmalloc for the FDT buffer.Thanks for verifying on powerpc platform Thiago.
I'll update the patch to do the following:
=> Use vmalloc for FDT buffer allocation on powerpc
=> Keep vmalloc for arm64, but remove the retry on allocation.
=> Also, there was a memory leak of FDT buffer in the error code path on arm64, which I'll fix as well.
Quoted 6 lines
Quoted 1 line
Did I miss anything?
Yes, you missed the second part of Rob's suggestion I was mentioning, which is factoring out the code which allocates the new FDT from both arm64 and powerpc.
Sure - I'll address that.
thanks,
-lakshmi
Re: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
In reply to Thiago Jung BauermannQuoted 6 lines · Thiago Jung Bauermann
The problem is that this patch implements only part of the suggestion, which isn't useful in itself. So the patch series should either drop this patch or consolidate the FDT allocation between the arches.
I just tested on powernv and pseries platforms and powerpc can use vmalloc for the FDT buffer.
Perhaps more sensible to use kvmalloc/kvfree.
Re: [PATCH v15 09/10] arm64: Call kmalloc() to allocate DTB buffer
Quoted 9 lines · Joe Perches
Quoted 6 lines · Thiago Jung Bauermann
The problem is that this patch implements only part of the suggestion, which isn't useful in itself. So the patch series should either drop this patch or consolidate the FDT allocation between the arches.
I just tested on powernv and pseries platforms and powerpc can use vmalloc for the FDT buffer.
Perhaps more sensible to use kvmalloc/kvfree.
That's true. Converting both arm64 to powerpc to kvmalloc/kvfree is a good option. I don't think it's that much better though, because kexec_file_load() is called infrequently and doesn't need to be fast so the vmalloc() overhead isn't important in practice.
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