Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1461587 > unrolled thread
| Started by | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| First post | 2016-08-13 05:20 +0200 |
| Last post | 2016-08-17 07:00 +0200 |
| Articles | 11 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-13 05:20 +0200
[PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-13 05:20 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Dave Young <dyoung@redhat.com> - 2016-08-18 11:10 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-19 04:10 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Dave Young <dyoung@redhat.com> - 2016-08-22 05:20 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-22 05:30 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Dave Young <dyoung@redhat.com> - 2016-08-22 05:40 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-22 05:50 +0200
Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-23 00:20 +0200
Re: [PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel Dave Young <dyoung@redhat.com> - 2016-08-17 05:00 +0200
Re: [PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> - 2016-08-17 07:00 +0200
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-13 05:20 +0200 |
| Subject | [PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel |
| Message-ID | <s5xEm-2xg-7@gated-at.bofh.it> |
Hello,
This patch series implements a mechanism which allows the kernel to pass
on a buffer to the kernel that will be kexec'd. This buffer is passed
as a segment which is added to the kimage when it is being prepared
by kexec_file_load.
How the second kernel is informed of this buffer is architecture-specific.
On powerpc, this is done via the device tree, by checking
the properties /chosen/linux,kexec-handover-buffer-start and
/chosen/linux,kexec-handover-buffer-end, which is analogous to how the
kernel finds the initrd.
This is needed because the Integrity Measurement Architecture subsystem
needs to preserve its measurement list accross the kexec reboot. The
following patch series for the IMA subsystem uses this feature for that
purpose:
https://lists.infradead.org/pipermail/kexec/2016-August/016745.html
This is so that IMA can implement trusted boot support on the OpenPower
platform, because on such systems an intermediary Linux instance running
as part of the firmware is used to boot the target operating system via
kexec. Using this mechanism, IMA on this intermediary instance can
hand over to the target OS the measurements of the components that were
used to boot it.
Because there could be additional measurement events between the
kexec_file_load call and the actual reboot, IMA needs a way to update the
buffer with those additional events before rebooting. One can minimize
the interval between the kexec_file_load and the reboot syscalls, but as
small as it can be, there is always the possibility that the measurement
list will be out of date at the time of reboot.
To address this issue, this patch series also introduces
kexec_update_segment, which allows a reboot notifier to change the
contents of the image segment during the reboot process.
Patch 5 makes kimage_load_normal_segment and kexec_update_segment share
code. It's not much code that they can share though, so I'm not sure if
the result is actually better.
The last patch is not intended to be merged, it just demonstrates how
this feature can be used.
This series applies on top of v5 of the "kexec_file_load implementation
for PowerPC" patch series (which applies on top of v4.8-rc1):
https://lists.infradead.org/pipermail/kexec/2016-August/016843.html
Changes for v2:
- Rebased on v5 of kexec_file_load implementation for PowerPC patch series.
- Patch "kexec_file: Add buffer hand-over support for the next kernel"
- Changed kexec_add_handover_buffer to receive a struct kexec_buf, as
suggested by Dave Young.
- Patch "powerpc: kexec_file: Add buffer hand-over support for the next kernel"
- Moved setup_handover_buffer from kexec_elf_64.c to machine_kexec_64.c.
- Call setup_handover_buffer from setup_new_fdt instead of elf64_load.
- Changed kexec_get_handover_buffer to read from the expanded device tree
instead of the flattened device tree.
- Patch "kexec_file: Add mechanism to update kexec segments.":
- Removed unnecessary "#include <linux/highmem.h>" in kexec_file.c.
- Round up memsz argument to PAGE_SIZE.
- Check if kexec_image is NULL in kexec_update_segment.
- Patch "IMA: Demonstration code for kexec buffer passing."
- Avoid registering reboot notifier again if kexec_file_load is called
more than once.
Thiago Jung Bauermann (6):
kexec_file: Add buffer hand-over support for the next kernel
powerpc: kexec_file: Add buffer hand-over support for the next kernel
kexec_file: Allow skipping checksum calculation for some segments.
kexec_file: Add mechanism to update kexec segments.
kexec: Share logic to copy segment page contents.
IMA: Demonstration code for kexec buffer passing.
arch/powerpc/include/asm/kexec.h | 12 +-
arch/powerpc/kernel/kexec_elf_64.c | 8 +-
arch/powerpc/kernel/machine_kexec_64.c | 114 ++++++++++++++++-
arch/x86/kernel/crash.c | 4 +-
arch/x86/kernel/kexec-bzimage64.c | 6 +-
include/linux/ima.h | 11 ++
include/linux/kexec.h | 37 +++++-
kernel/kexec_core.c | 216 ++++++++++++++++++++++++++-------
kernel/kexec_file.c | 91 ++++++++++++--
security/integrity/ima/ima.h | 5 +
security/integrity/ima/ima_init.c | 26 ++++
security/integrity/ima/ima_template.c | 85 +++++++++++++
12 files changed, 546 insertions(+), 69 deletions(-)
--
1.9.1
[toc] | [next] | [standalone]
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-13 05:20 +0200 |
| Subject | [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s5xEm-2xg-31@gated-at.bofh.it> |
| In reply to | #1461587 |
Adds checksum argument to kexec_add_buffer specifying whether the given
segment should be part of the checksum calculation.
The next patch will add a way to update segments after a kimage is loaded.
Segments that will be updated in this way should not be checksummed,
otherwise they will cause the purgatory checksum verification to fail
when the machine is rebooted.
As a bonus, we don't need to special-case the purgatory segment anymore
to avoid checksumming it.
Adjust call sites for the new argument.
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
---
arch/powerpc/kernel/kexec_elf_64.c | 6 +++---
arch/x86/kernel/crash.c | 4 ++--
arch/x86/kernel/kexec-bzimage64.c | 6 +++---
include/linux/kexec.h | 10 +++++++---
kernel/kexec_file.c | 23 ++++++++++++-----------
5 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/arch/powerpc/kernel/kexec_elf_64.c b/arch/powerpc/kernel/kexec_elf_64.c
index 22afc7b5ee73..4c528c81b076 100644
--- a/arch/powerpc/kernel/kexec_elf_64.c
+++ b/arch/powerpc/kernel/kexec_elf_64.c
@@ -128,7 +128,7 @@ static int elf_exec_load(struct kimage *image, struct elfhdr *ehdr,
kbuf.memsz = phdr->p_memsz;
kbuf.buf_align = phdr->p_align;
kbuf.buf_min = phdr->p_paddr + base;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
goto out;
load_addr = kbuf.mem;
@@ -188,7 +188,7 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
kbuf.bufsz = kbuf.memsz = initrd_len;
kbuf.buf_align = PAGE_SIZE;
kbuf.top_down = false;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
goto out;
initrd_load_addr = kbuf.mem;
@@ -245,7 +245,7 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
kbuf.bufsz = kbuf.memsz = fdt_size;
kbuf.buf_align = PAGE_SIZE;
kbuf.top_down = true;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
goto out;
fdt_load_addr = kbuf.mem;
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 38a1cdf6aa05..634ab16377b1 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -642,7 +642,7 @@ int crash_load_segments(struct kimage *image)
* copied in purgatory after crash. Just add a zero filled
* segment for now to make sure checksum logic works fine.
*/
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
return ret;
image->arch.backup_load_addr = kbuf.mem;
@@ -661,7 +661,7 @@ int crash_load_segments(struct kimage *image)
kbuf.memsz = kbuf.bufsz;
kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret) {
vfree((void *)image->arch.elf_headers);
return ret;
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 4b3a75329fb6..a46e3fbb0639 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -422,7 +422,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
kbuf.memsz = kbuf.bufsz;
kbuf.buf_align = 16;
kbuf.buf_min = MIN_BOOTPARAM_ADDR;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
goto out_free_params;
bootparam_load_addr = kbuf.mem;
@@ -435,7 +435,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
kbuf.memsz = PAGE_ALIGN(header->init_size);
kbuf.buf_align = header->kernel_alignment;
kbuf.buf_min = MIN_KERNEL_LOAD_ADDR;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
goto out_free_params;
kernel_load_addr = kbuf.mem;
@@ -449,7 +449,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
kbuf.bufsz = kbuf.memsz = initrd_len;
kbuf.buf_align = PAGE_SIZE;
kbuf.buf_min = MIN_INITRD_LOAD_ADDR;
- ret = kexec_add_buffer(&kbuf);
+ ret = kexec_add_buffer(&kbuf, true);
if (ret)
goto out_free_params;
initrd_load_addr = kbuf.mem;
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 4559a1a01b0a..37eea32fdff1 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -100,6 +100,9 @@ struct kexec_segment {
size_t bufsz;
unsigned long mem;
size_t memsz;
+
+ /* Whether this segment is part of the checksum calculation. */
+ bool do_checksum;
};
#ifdef CONFIG_COMPAT
@@ -175,7 +178,7 @@ struct kexec_buf {
int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
int (*func)(u64, u64, void *));
-extern int kexec_add_buffer(struct kexec_buf *kbuf);
+extern int kexec_add_buffer(struct kexec_buf *kbuf, bool checksum);
int kexec_locate_mem_hole(struct kexec_buf *kbuf);
int __weak arch_kexec_verify_buffer(enum kexec_file_type type, const void *buf,
unsigned long size);
@@ -393,7 +396,7 @@ bool __weak kexec_can_hand_over_buffer(void);
int __weak arch_kexec_add_handover_buffer(struct kimage *image,
unsigned long load_addr,
unsigned long size);
-int kexec_add_handover_buffer(struct kexec_buf *kbuf);
+int kexec_add_handover_buffer(struct kexec_buf *kbuf, bool checksum);
int __weak kexec_get_handover_buffer(void **addr, unsigned long *size);
int __weak kexec_free_handover_buffer(void);
#else
@@ -402,7 +405,8 @@ static inline bool kexec_can_hand_over_buffer(void)
return false;
}
-static inline int kexec_add_handover_buffer(struct kexec_buf *kbuf)
+static inline int kexec_add_handover_buffer(struct kexec_buf *kbuf,
+ bool checksum)
{
return -ENOTSUPP;
}
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index c8418d62e2fc..aed51175915f 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -161,6 +161,7 @@ int __weak arch_kexec_add_handover_buffer(struct kimage *image,
/**
* kexec_add_handover_buffer - add buffer to be used by the next kernel
* @kbuf: Buffer contents and memory parameters.
+ * @checksum: Should the segment checksum be verified by the purgatory?
*
* This function assumes that kexec_mutex is held.
* On successful return, @kbuf->mem will have the physical address of
@@ -168,14 +169,14 @@ int __weak arch_kexec_add_handover_buffer(struct kimage *image,
*
* Return: 0 on success, negative errno on error.
*/
-int kexec_add_handover_buffer(struct kexec_buf *kbuf)
+int kexec_add_handover_buffer(struct kexec_buf *kbuf, bool checksum)
{
int ret;
if (!kexec_can_hand_over_buffer())
return -ENOTSUPP;
- ret = kexec_add_buffer(kbuf);
+ ret = kexec_add_buffer(kbuf, checksum);
if (ret)
return ret;
@@ -611,6 +612,7 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)
/**
* kexec_add_buffer - place a buffer in a kexec segment
* @kbuf: Buffer contents and memory parameters.
+ * @checksum: Should the segment checksum be verified by the purgatory?
*
* This function assumes that kexec_mutex is held.
* On successful return, @kbuf->mem will have the physical address of
@@ -618,7 +620,7 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)
*
* Return: 0 on success, negative errno on error.
*/
-int kexec_add_buffer(struct kexec_buf *kbuf)
+int kexec_add_buffer(struct kexec_buf *kbuf, bool checksum)
{
struct kexec_segment *ksegment;
@@ -658,6 +660,7 @@ int kexec_add_buffer(struct kexec_buf *kbuf)
ksegment->bufsz = kbuf->bufsz;
ksegment->mem = kbuf->mem;
ksegment->memsz = kbuf->memsz;
+ ksegment->do_checksum = checksum;
kbuf->image->nr_segments++;
return 0;
}
@@ -672,7 +675,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
char *digest;
void *zero_buf;
struct kexec_sha_region *sha_regions;
- struct purgatory_info *pi = &image->purgatory_info;
zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT);
zero_buf_sz = PAGE_SIZE;
@@ -712,11 +714,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
struct kexec_segment *ksegment;
ksegment = &image->segment[i];
- /*
- * Skip purgatory as it will be modified once we put digest
- * info in purgatory.
- */
- if (ksegment->kbuf == pi->purgatory_buf)
+ if (!ksegment->do_checksum)
continue;
ret = crypto_shash_update(desc, ksegment->kbuf,
@@ -893,8 +891,11 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
if (kbuf.buf_align < bss_align)
kbuf.buf_align = bss_align;
- /* Add buffer to segment list */
- ret = kexec_add_buffer(&kbuf);
+ /*
+ * Add buffer to segment list. Don't checksum the segment as
+ * it will be modified once we put digest info in purgatory.
+ */
+ ret = kexec_add_buffer(&kbuf, false);
if (ret)
goto out;
pi->purgatory_load_addr = kbuf.mem;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Dave Young <dyoung@redhat.com> |
|---|---|
| Date | 2016-08-18 11:10 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s7ruO-66w-41@gated-at.bofh.it> |
| In reply to | #1461588 |
On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote:
> Adds checksum argument to kexec_add_buffer specifying whether the given
> segment should be part of the checksum calculation.
>
Since it is used with add buffer, could it be added to kbuf as a new
field?
Like kbuf.no_checksum, default value is 0 that means checksum is needed
if it is 1 then no need a checksum.
> The next patch will add a way to update segments after a kimage is loaded.
> Segments that will be updated in this way should not be checksummed,
> otherwise they will cause the purgatory checksum verification to fail
> when the machine is rebooted.
>
> As a bonus, we don't need to special-case the purgatory segment anymore
> to avoid checksumming it.
>
> Adjust call sites for the new argument.
>
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
> ---
> arch/powerpc/kernel/kexec_elf_64.c | 6 +++---
> arch/x86/kernel/crash.c | 4 ++--
> arch/x86/kernel/kexec-bzimage64.c | 6 +++---
> include/linux/kexec.h | 10 +++++++---
> kernel/kexec_file.c | 23 ++++++++++++-----------
> 5 files changed, 27 insertions(+), 22 deletions(-)
>
> diff --git a/arch/powerpc/kernel/kexec_elf_64.c b/arch/powerpc/kernel/kexec_elf_64.c
> index 22afc7b5ee73..4c528c81b076 100644
> --- a/arch/powerpc/kernel/kexec_elf_64.c
> +++ b/arch/powerpc/kernel/kexec_elf_64.c
> @@ -128,7 +128,7 @@ static int elf_exec_load(struct kimage *image, struct elfhdr *ehdr,
> kbuf.memsz = phdr->p_memsz;
> kbuf.buf_align = phdr->p_align;
> kbuf.buf_min = phdr->p_paddr + base;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> goto out;
> load_addr = kbuf.mem;
> @@ -188,7 +188,7 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
> kbuf.bufsz = kbuf.memsz = initrd_len;
> kbuf.buf_align = PAGE_SIZE;
> kbuf.top_down = false;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> goto out;
> initrd_load_addr = kbuf.mem;
> @@ -245,7 +245,7 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
> kbuf.bufsz = kbuf.memsz = fdt_size;
> kbuf.buf_align = PAGE_SIZE;
> kbuf.top_down = true;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> goto out;
> fdt_load_addr = kbuf.mem;
> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
> index 38a1cdf6aa05..634ab16377b1 100644
> --- a/arch/x86/kernel/crash.c
> +++ b/arch/x86/kernel/crash.c
> @@ -642,7 +642,7 @@ int crash_load_segments(struct kimage *image)
> * copied in purgatory after crash. Just add a zero filled
> * segment for now to make sure checksum logic works fine.
> */
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> return ret;
> image->arch.backup_load_addr = kbuf.mem;
> @@ -661,7 +661,7 @@ int crash_load_segments(struct kimage *image)
>
> kbuf.memsz = kbuf.bufsz;
> kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret) {
> vfree((void *)image->arch.elf_headers);
> return ret;
> diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
> index 4b3a75329fb6..a46e3fbb0639 100644
> --- a/arch/x86/kernel/kexec-bzimage64.c
> +++ b/arch/x86/kernel/kexec-bzimage64.c
> @@ -422,7 +422,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
> kbuf.memsz = kbuf.bufsz;
> kbuf.buf_align = 16;
> kbuf.buf_min = MIN_BOOTPARAM_ADDR;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> goto out_free_params;
> bootparam_load_addr = kbuf.mem;
> @@ -435,7 +435,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
> kbuf.memsz = PAGE_ALIGN(header->init_size);
> kbuf.buf_align = header->kernel_alignment;
> kbuf.buf_min = MIN_KERNEL_LOAD_ADDR;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> goto out_free_params;
> kernel_load_addr = kbuf.mem;
> @@ -449,7 +449,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
> kbuf.bufsz = kbuf.memsz = initrd_len;
> kbuf.buf_align = PAGE_SIZE;
> kbuf.buf_min = MIN_INITRD_LOAD_ADDR;
> - ret = kexec_add_buffer(&kbuf);
> + ret = kexec_add_buffer(&kbuf, true);
> if (ret)
> goto out_free_params;
> initrd_load_addr = kbuf.mem;
> diff --git a/include/linux/kexec.h b/include/linux/kexec.h
> index 4559a1a01b0a..37eea32fdff1 100644
> --- a/include/linux/kexec.h
> +++ b/include/linux/kexec.h
> @@ -100,6 +100,9 @@ struct kexec_segment {
> size_t bufsz;
> unsigned long mem;
> size_t memsz;
> +
> + /* Whether this segment is part of the checksum calculation. */
> + bool do_checksum;
> };
>
> #ifdef CONFIG_COMPAT
> @@ -175,7 +178,7 @@ struct kexec_buf {
>
> int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
> int (*func)(u64, u64, void *));
> -extern int kexec_add_buffer(struct kexec_buf *kbuf);
> +extern int kexec_add_buffer(struct kexec_buf *kbuf, bool checksum);
> int kexec_locate_mem_hole(struct kexec_buf *kbuf);
> int __weak arch_kexec_verify_buffer(enum kexec_file_type type, const void *buf,
> unsigned long size);
> @@ -393,7 +396,7 @@ bool __weak kexec_can_hand_over_buffer(void);
> int __weak arch_kexec_add_handover_buffer(struct kimage *image,
> unsigned long load_addr,
> unsigned long size);
> -int kexec_add_handover_buffer(struct kexec_buf *kbuf);
> +int kexec_add_handover_buffer(struct kexec_buf *kbuf, bool checksum);
> int __weak kexec_get_handover_buffer(void **addr, unsigned long *size);
> int __weak kexec_free_handover_buffer(void);
> #else
> @@ -402,7 +405,8 @@ static inline bool kexec_can_hand_over_buffer(void)
> return false;
> }
>
> -static inline int kexec_add_handover_buffer(struct kexec_buf *kbuf)
> +static inline int kexec_add_handover_buffer(struct kexec_buf *kbuf,
> + bool checksum)
> {
> return -ENOTSUPP;
> }
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index c8418d62e2fc..aed51175915f 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -161,6 +161,7 @@ int __weak arch_kexec_add_handover_buffer(struct kimage *image,
> /**
> * kexec_add_handover_buffer - add buffer to be used by the next kernel
> * @kbuf: Buffer contents and memory parameters.
> + * @checksum: Should the segment checksum be verified by the purgatory?
> *
> * This function assumes that kexec_mutex is held.
> * On successful return, @kbuf->mem will have the physical address of
> @@ -168,14 +169,14 @@ int __weak arch_kexec_add_handover_buffer(struct kimage *image,
> *
> * Return: 0 on success, negative errno on error.
> */
> -int kexec_add_handover_buffer(struct kexec_buf *kbuf)
> +int kexec_add_handover_buffer(struct kexec_buf *kbuf, bool checksum)
> {
> int ret;
>
> if (!kexec_can_hand_over_buffer())
> return -ENOTSUPP;
>
> - ret = kexec_add_buffer(kbuf);
> + ret = kexec_add_buffer(kbuf, checksum);
> if (ret)
> return ret;
>
> @@ -611,6 +612,7 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)
> /**
> * kexec_add_buffer - place a buffer in a kexec segment
> * @kbuf: Buffer contents and memory parameters.
> + * @checksum: Should the segment checksum be verified by the purgatory?
> *
> * This function assumes that kexec_mutex is held.
> * On successful return, @kbuf->mem will have the physical address of
> @@ -618,7 +620,7 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)
> *
> * Return: 0 on success, negative errno on error.
> */
> -int kexec_add_buffer(struct kexec_buf *kbuf)
> +int kexec_add_buffer(struct kexec_buf *kbuf, bool checksum)
> {
>
> struct kexec_segment *ksegment;
> @@ -658,6 +660,7 @@ int kexec_add_buffer(struct kexec_buf *kbuf)
> ksegment->bufsz = kbuf->bufsz;
> ksegment->mem = kbuf->mem;
> ksegment->memsz = kbuf->memsz;
> + ksegment->do_checksum = checksum;
> kbuf->image->nr_segments++;
> return 0;
> }
> @@ -672,7 +675,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
> char *digest;
> void *zero_buf;
> struct kexec_sha_region *sha_regions;
> - struct purgatory_info *pi = &image->purgatory_info;
>
> zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT);
> zero_buf_sz = PAGE_SIZE;
> @@ -712,11 +714,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
> struct kexec_segment *ksegment;
>
> ksegment = &image->segment[i];
> - /*
> - * Skip purgatory as it will be modified once we put digest
> - * info in purgatory.
> - */
> - if (ksegment->kbuf == pi->purgatory_buf)
> + if (!ksegment->do_checksum)
> continue;
>
> ret = crypto_shash_update(desc, ksegment->kbuf,
> @@ -893,8 +891,11 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
> if (kbuf.buf_align < bss_align)
> kbuf.buf_align = bss_align;
>
> - /* Add buffer to segment list */
> - ret = kexec_add_buffer(&kbuf);
> + /*
> + * Add buffer to segment list. Don't checksum the segment as
> + * it will be modified once we put digest info in purgatory.
> + */
> + ret = kexec_add_buffer(&kbuf, false);
> if (ret)
> goto out;
> pi->purgatory_load_addr = kbuf.mem;
> --
> 1.9.1
>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
[toc] | [prev] | [next] | [standalone]
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-19 04:10 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s7HpU-7RC-33@gated-at.bofh.it> |
| In reply to | #1465027 |
Hello Dave,
Thanks for your review!
[ Trimming down Cc: list a little to try to clear the "too many recipients"
mailing list restriction. ]
Am Donnerstag, 18 August 2016, 17:03:30 schrieb Dave Young:
> On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote:
> > Adds checksum argument to kexec_add_buffer specifying whether the given
> > segment should be part of the checksum calculation.
>
> Since it is used with add buffer, could it be added to kbuf as a new
> field?
I was on the fence about adding it as a new argument to kexec_add_buffer or
as a new field to struct kexec_buf. Both alternatives make sense to me. I
implemented your suggestion in the patch below, what do you think?
> Like kbuf.no_checksum, default value is 0 that means checksum is needed
> if it is 1 then no need a checksum.
It's an interesting idea and I implemented it that way, though in practice
all current users of struct kexec_buf put it on the stack so the field needs
to be initialized explicitly.
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Subject: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for
some segments.
Add skip_checksum member to struct kexec_buf to specify whether the
corresponding segment should be part of the checksum calculation.
The next patch will add a way to update segments after a kimage is loaded.
Segments that will be updated in this way should not be checksummed,
otherwise they will cause the purgatory checksum verification to fail
when the machine is rebooted.
As a bonus, we don't need to special-case the purgatory segment anymore
to avoid checksumming it.
Adjust places using struct kexec_buf to set skip_checksum.
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
---
arch/powerpc/kernel/kexec_elf_64.c | 5 +++--
arch/x86/kernel/crash.c | 3 ++-
arch/x86/kernel/kexec-bzimage64.c | 2 +-
include/linux/kexec.h | 23 ++++++++++++++---------
kernel/kexec_file.c | 15 +++++++--------
5 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/arch/powerpc/kernel/kexec_elf_64.c b/arch/powerpc/kernel/kexec_elf_64.c
index 22afc7b5ee73..d009f5363968 100644
--- a/arch/powerpc/kernel/kexec_elf_64.c
+++ b/arch/powerpc/kernel/kexec_elf_64.c
@@ -107,7 +107,7 @@ static int elf_exec_load(struct kimage *image, struct elfhdr *ehdr,
int ret;
size_t i;
struct kexec_buf kbuf = { .image = image, .buf_max = ppc64_rma_size,
- .top_down = false };
+ .top_down = false, .skip_checksum = false };
/* Read in the PT_LOAD segments. */
for (i = 0; i < ehdr->e_phnum; i++) {
@@ -162,7 +162,8 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
struct elf_info elf_info;
struct fdt_reserve_entry *rsvmap;
struct kexec_buf kbuf = { .image = image, .buf_min = 0,
- .buf_max = ppc64_rma_size };
+ .buf_max = ppc64_rma_size,
+ .skip_checksum = false };
ret = build_elf_exec_info(kernel_buf, kernel_len, &ehdr, &elf_info);
if (ret)
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 38a1cdf6aa05..7b8f62c86651 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -617,7 +617,8 @@ int crash_load_segments(struct kimage *image)
{
int ret;
struct kexec_buf kbuf = { .image = image, .buf_min = 0,
- .buf_max = ULONG_MAX, .top_down = false };
+ .buf_max = ULONG_MAX, .top_down = false,
+ .skip_checksum = false };
/*
* Determine and load a segment for backup area. First 640K RAM
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 4b3a75329fb6..449f433cd225 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -341,7 +341,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
unsigned int setup_hdr_offset = offsetof(struct boot_params, hdr);
unsigned int efi_map_offset, efi_map_sz, efi_setup_data_offset;
struct kexec_buf kbuf = { .image = image, .buf_max = ULONG_MAX,
- .top_down = true };
+ .top_down = true, .skip_checksum = false };
header = (struct setup_header *)(kernel + setup_hdr_offset);
setup_sects = header->setup_sects;
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 4559a1a01b0a..e5b3d99cbe50 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -100,6 +100,9 @@ struct kexec_segment {
size_t bufsz;
unsigned long mem;
size_t memsz;
+
+ /* Whether this segment is ignored in the checksum calculation. */
+ bool skip_checksum;
};
#ifdef CONFIG_COMPAT
@@ -151,15 +154,16 @@ struct kexec_file_ops {
/**
* struct kexec_buf - parameters for finding a place for a buffer in memory
- * @image: kexec image in which memory to search.
- * @buffer: Contents which will be copied to the allocated memory.
- * @bufsz: Size of @buffer.
- * @mem: On return will have address of the buffer in memory.
- * @memsz: Size for the buffer in memory.
- * @buf_align: Minimum alignment needed.
- * @buf_min: The buffer can't be placed below this address.
- * @buf_max: The buffer can't be placed above this address.
- * @top_down: Allocate from top of memory.
+ * @image: kexec image in which memory to search.
+ * @buffer: Contents which will be copied to the allocated memory.
+ * @bufsz: Size of @buffer.
+ * @mem: On return will have address of the buffer in memory.
+ * @memsz: Size for the buffer in memory.
+ * @buf_align: Minimum alignment needed.
+ * @buf_min: The buffer can't be placed below this address.
+ * @buf_max: The buffer can't be placed above this address.
+ * @top_down: Allocate from top of memory.
+ * @skip_checksum: Don't verify checksum for this buffer in purgatory.
*/
struct kexec_buf {
struct kimage *image;
@@ -171,6 +175,7 @@ struct kexec_buf {
unsigned long buf_min;
unsigned long buf_max;
bool top_down;
+ bool skip_checksum;
};
int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index c8418d62e2fc..f6e9958bf578 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -658,6 +658,7 @@ int kexec_add_buffer(struct kexec_buf *kbuf)
ksegment->bufsz = kbuf->bufsz;
ksegment->mem = kbuf->mem;
ksegment->memsz = kbuf->memsz;
+ ksegment->skip_checksum = kbuf->skip_checksum;
kbuf->image->nr_segments++;
return 0;
}
@@ -672,7 +673,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
char *digest;
void *zero_buf;
struct kexec_sha_region *sha_regions;
- struct purgatory_info *pi = &image->purgatory_info;
zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT);
zero_buf_sz = PAGE_SIZE;
@@ -712,11 +712,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
struct kexec_segment *ksegment;
ksegment = &image->segment[i];
- /*
- * Skip purgatory as it will be modified once we put digest
- * info in purgatory.
- */
- if (ksegment->kbuf == pi->purgatory_buf)
+ if (ksegment->skip_checksum)
continue;
ret = crypto_shash_update(desc, ksegment->kbuf,
@@ -788,7 +784,7 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
Elf_Shdr *sechdrs = NULL;
struct kexec_buf kbuf = { .image = image, .bufsz = 0, .buf_align = 1,
.buf_min = min, .buf_max = max,
- .top_down = top_down };
+ .top_down = top_down, .skip_checksum = true };
/*
* sechdrs_c points to section headers in purgatory and are read
@@ -893,7 +889,10 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
if (kbuf.buf_align < bss_align)
kbuf.buf_align = bss_align;
- /* Add buffer to segment list */
+ /*
+ * Add buffer to segment list. Don't checksum the segment as
+ * it will be modified once we put digest info in purgatory.
+ */
ret = kexec_add_buffer(&kbuf);
if (ret)
goto out;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Dave Young <dyoung@redhat.com> |
|---|---|
| Date | 2016-08-22 05:20 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s8NWh-HR-1@gated-at.bofh.it> |
| In reply to | #1465888 |
On 08/18/16 at 06:09pm, Thiago Jung Bauermann wrote:
> Hello Dave,
>
> Thanks for your review!
>
> [ Trimming down Cc: list a little to try to clear the "too many recipients"
> mailing list restriction. ]
I also got "too many recipients".. Thanks for the trimming.
>
> Am Donnerstag, 18 August 2016, 17:03:30 schrieb Dave Young:
> > On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote:
> > > Adds checksum argument to kexec_add_buffer specifying whether the given
> > > segment should be part of the checksum calculation.
> >
> > Since it is used with add buffer, could it be added to kbuf as a new
> > field?
>
> I was on the fence about adding it as a new argument to kexec_add_buffer or
> as a new field to struct kexec_buf. Both alternatives make sense to me. I
> implemented your suggestion in the patch below, what do you think?
>
> > Like kbuf.no_checksum, default value is 0 that means checksum is needed
> > if it is 1 then no need a checksum.
>
> It's an interesting idea and I implemented it that way, though in practice
> all current users of struct kexec_buf put it on the stack so the field needs
> to be initialized explicitly.
>
> --
> []'s
> Thiago Jung Bauermann
> IBM Linux Technology Center
>
>
> Subject: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for
> some segments.
>
> Add skip_checksum member to struct kexec_buf to specify whether the
> corresponding segment should be part of the checksum calculation.
>
> The next patch will add a way to update segments after a kimage is loaded.
> Segments that will be updated in this way should not be checksummed,
> otherwise they will cause the purgatory checksum verification to fail
> when the machine is rebooted.
>
> As a bonus, we don't need to special-case the purgatory segment anymore
> to avoid checksumming it.
>
> Adjust places using struct kexec_buf to set skip_checksum.
>
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
> ---
> arch/powerpc/kernel/kexec_elf_64.c | 5 +++--
> arch/x86/kernel/crash.c | 3 ++-
> arch/x86/kernel/kexec-bzimage64.c | 2 +-
> include/linux/kexec.h | 23 ++++++++++++++---------
> kernel/kexec_file.c | 15 +++++++--------
> 5 files changed, 27 insertions(+), 21 deletions(-)
>
> diff --git a/arch/powerpc/kernel/kexec_elf_64.c b/arch/powerpc/kernel/kexec_elf_64.c
> index 22afc7b5ee73..d009f5363968 100644
> --- a/arch/powerpc/kernel/kexec_elf_64.c
> +++ b/arch/powerpc/kernel/kexec_elf_64.c
> @@ -107,7 +107,7 @@ static int elf_exec_load(struct kimage *image, struct elfhdr *ehdr,
> int ret;
> size_t i;
> struct kexec_buf kbuf = { .image = image, .buf_max = ppc64_rma_size,
> - .top_down = false };
> + .top_down = false, .skip_checksum = false };
No need to set it as false because it will be initialized to 0 by
default?
>
> /* Read in the PT_LOAD segments. */
> for (i = 0; i < ehdr->e_phnum; i++) {
> @@ -162,7 +162,8 @@ void *elf64_load(struct kimage *image, char *kernel_buf,
> struct elf_info elf_info;
> struct fdt_reserve_entry *rsvmap;
> struct kexec_buf kbuf = { .image = image, .buf_min = 0,
> - .buf_max = ppc64_rma_size };
> + .buf_max = ppc64_rma_size,
> + .skip_checksum = false };
>
> ret = build_elf_exec_info(kernel_buf, kernel_len, &ehdr, &elf_info);
> if (ret)
> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
> index 38a1cdf6aa05..7b8f62c86651 100644
> --- a/arch/x86/kernel/crash.c
> +++ b/arch/x86/kernel/crash.c
> @@ -617,7 +617,8 @@ int crash_load_segments(struct kimage *image)
> {
> int ret;
> struct kexec_buf kbuf = { .image = image, .buf_min = 0,
> - .buf_max = ULONG_MAX, .top_down = false };
> + .buf_max = ULONG_MAX, .top_down = false,
> + .skip_checksum = false };
>
> /*
> * Determine and load a segment for backup area. First 640K RAM
> diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
> index 4b3a75329fb6..449f433cd225 100644
> --- a/arch/x86/kernel/kexec-bzimage64.c
> +++ b/arch/x86/kernel/kexec-bzimage64.c
> @@ -341,7 +341,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
> unsigned int setup_hdr_offset = offsetof(struct boot_params, hdr);
> unsigned int efi_map_offset, efi_map_sz, efi_setup_data_offset;
> struct kexec_buf kbuf = { .image = image, .buf_max = ULONG_MAX,
> - .top_down = true };
> + .top_down = true, .skip_checksum = false };
>
> header = (struct setup_header *)(kernel + setup_hdr_offset);
> setup_sects = header->setup_sects;
> diff --git a/include/linux/kexec.h b/include/linux/kexec.h
> index 4559a1a01b0a..e5b3d99cbe50 100644
> --- a/include/linux/kexec.h
> +++ b/include/linux/kexec.h
> @@ -100,6 +100,9 @@ struct kexec_segment {
> size_t bufsz;
> unsigned long mem;
> size_t memsz;
> +
> + /* Whether this segment is ignored in the checksum calculation. */
> + bool skip_checksum;
> };
>
> #ifdef CONFIG_COMPAT
> @@ -151,15 +154,16 @@ struct kexec_file_ops {
>
> /**
> * struct kexec_buf - parameters for finding a place for a buffer in memory
> - * @image: kexec image in which memory to search.
> - * @buffer: Contents which will be copied to the allocated memory.
> - * @bufsz: Size of @buffer.
> - * @mem: On return will have address of the buffer in memory.
> - * @memsz: Size for the buffer in memory.
> - * @buf_align: Minimum alignment needed.
> - * @buf_min: The buffer can't be placed below this address.
> - * @buf_max: The buffer can't be placed above this address.
> - * @top_down: Allocate from top of memory.
> + * @image: kexec image in which memory to search.
> + * @buffer: Contents which will be copied to the allocated memory.
> + * @bufsz: Size of @buffer.
> + * @mem: On return will have address of the buffer in memory.
> + * @memsz: Size for the buffer in memory.
> + * @buf_align: Minimum alignment needed.
> + * @buf_min: The buffer can't be placed below this address.
> + * @buf_max: The buffer can't be placed above this address.
> + * @top_down: Allocate from top of memory.
> + * @skip_checksum: Don't verify checksum for this buffer in purgatory.
> */
> struct kexec_buf {
> struct kimage *image;
> @@ -171,6 +175,7 @@ struct kexec_buf {
> unsigned long buf_min;
> unsigned long buf_max;
> bool top_down;
> + bool skip_checksum;
> };
>
> int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index c8418d62e2fc..f6e9958bf578 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -658,6 +658,7 @@ int kexec_add_buffer(struct kexec_buf *kbuf)
> ksegment->bufsz = kbuf->bufsz;
> ksegment->mem = kbuf->mem;
> ksegment->memsz = kbuf->memsz;
> + ksegment->skip_checksum = kbuf->skip_checksum;
> kbuf->image->nr_segments++;
> return 0;
> }
> @@ -672,7 +673,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
> char *digest;
> void *zero_buf;
> struct kexec_sha_region *sha_regions;
> - struct purgatory_info *pi = &image->purgatory_info;
>
> zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT);
> zero_buf_sz = PAGE_SIZE;
> @@ -712,11 +712,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
> struct kexec_segment *ksegment;
>
> ksegment = &image->segment[i];
> - /*
> - * Skip purgatory as it will be modified once we put digest
> - * info in purgatory.
> - */
> - if (ksegment->kbuf == pi->purgatory_buf)
> + if (ksegment->skip_checksum)
> continue;
>
> ret = crypto_shash_update(desc, ksegment->kbuf,
> @@ -788,7 +784,7 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
> Elf_Shdr *sechdrs = NULL;
> struct kexec_buf kbuf = { .image = image, .bufsz = 0, .buf_align = 1,
> .buf_min = min, .buf_max = max,
> - .top_down = top_down };
> + .top_down = top_down, .skip_checksum = true };
>
> /*
> * sechdrs_c points to section headers in purgatory and are read
> @@ -893,7 +889,10 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
> if (kbuf.buf_align < bss_align)
> kbuf.buf_align = bss_align;
>
> - /* Add buffer to segment list */
> + /*
> + * Add buffer to segment list. Don't checksum the segment as
> + * it will be modified once we put digest info in purgatory.
> + */
> ret = kexec_add_buffer(&kbuf);
> if (ret)
> goto out;
> --
> 1.9.1
>
>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
[toc] | [prev] | [next] | [standalone]
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-22 05:30 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s8O5X-Lh-1@gated-at.bofh.it> |
| In reply to | #1467322 |
Am Montag, 22 August 2016, 11:17:45 schrieb Dave Young: > On 08/18/16 at 06:09pm, Thiago Jung Bauermann wrote: > > Hello Dave, > > > > Thanks for your review! > > > > [ Trimming down Cc: list a little to try to clear the "too many > > recipients"> > > mailing list restriction. ] > > I also got "too many recipients".. Thanks for the trimming. Didn't work though. What is the maximum number of recipients? > > Am Donnerstag, 18 August 2016, 17:03:30 schrieb Dave Young: > > > On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote: > > > > Adds checksum argument to kexec_add_buffer specifying whether the > > > > given > > > > segment should be part of the checksum calculation. > > > > > > Since it is used with add buffer, could it be added to kbuf as a new > > > field? > > > > I was on the fence about adding it as a new argument to kexec_add_buffer > > or as a new field to struct kexec_buf. Both alternatives make sense to > > me. I implemented your suggestion in the patch below, what do you > > think?> > > > Like kbuf.no_checksum, default value is 0 that means checksum is > > > needed > > > if it is 1 then no need a checksum. > > > > It's an interesting idea and I implemented it that way, though in > > practice all current users of struct kexec_buf put it on the stack so > > the field needs to be initialized explicitly. > > No need to set it as false because it will be initialized to 0 by > default? As far as I know, variables on the stack are not initialized. Only global and static variables are. -- []'s Thiago Jung Bauermann IBM Linux Technology Center
[toc] | [prev] | [next] | [standalone]
| From | Dave Young <dyoung@redhat.com> |
|---|---|
| Date | 2016-08-22 05:40 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s8OfE-Ow-21@gated-at.bofh.it> |
| In reply to | #1467323 |
On 08/22/16 at 12:25am, Thiago Jung Bauermann wrote: > Am Montag, 22 August 2016, 11:17:45 schrieb Dave Young: > > On 08/18/16 at 06:09pm, Thiago Jung Bauermann wrote: > > > Hello Dave, > > > > > > Thanks for your review! > > > > > > [ Trimming down Cc: list a little to try to clear the "too many > > > recipients"> > > > mailing list restriction. ] > > > > I also got "too many recipients".. Thanks for the trimming. > > Didn't work though. What is the maximum number of recipients? I have no idea as well.. > > > > Am Donnerstag, 18 August 2016, 17:03:30 schrieb Dave Young: > > > > On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote: > > > > > Adds checksum argument to kexec_add_buffer specifying whether the > > > > > given > > > > > segment should be part of the checksum calculation. > > > > > > > > Since it is used with add buffer, could it be added to kbuf as a new > > > > field? > > > > > > I was on the fence about adding it as a new argument to kexec_add_buffer > > > or as a new field to struct kexec_buf. Both alternatives make sense to > > > me. I implemented your suggestion in the patch below, what do you > > > think?> > > > > Like kbuf.no_checksum, default value is 0 that means checksum is > > > > needed > > > > if it is 1 then no need a checksum. > > > > > > It's an interesting idea and I implemented it that way, though in > > > practice all current users of struct kexec_buf put it on the stack so > > > the field needs to be initialized explicitly. > > > > No need to set it as false because it will be initialized to 0 by > > default? > > As far as I know, variables on the stack are not initialized. Only global > and static variables are. But designated initializers will do it. Thanks Dave
[toc] | [prev] | [next] | [standalone]
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-22 05:50 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s8Opj-SQ-1@gated-at.bofh.it> |
| In reply to | #1467333 |
Am Montag, 22 August 2016, 11:36:43 schrieb Dave Young: > On 08/22/16 at 12:25am, Thiago Jung Bauermann wrote: > > Am Montag, 22 August 2016, 11:17:45 schrieb Dave Young: > > > On 08/18/16 at 06:09pm, Thiago Jung Bauermann wrote: > > > > Hello Dave, > > > > > > > > Thanks for your review! > > > > > > > > [ Trimming down Cc: list a little to try to clear the "too many > > > > recipients"> > > > > > > > > mailing list restriction. ] > > > > > > I also got "too many recipients".. Thanks for the trimming. > > > > Didn't work though. What is the maximum number of recipients? > > I have no idea as well.. > > > > > Am Donnerstag, 18 August 2016, 17:03:30 schrieb Dave Young: > > > > > On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote: > > > > > > Adds checksum argument to kexec_add_buffer specifying whether > > > > > > the > > > > > > given > > > > > > segment should be part of the checksum calculation. > > > > > > > > > > Since it is used with add buffer, could it be added to kbuf as a > > > > > new > > > > > field? > > > > > > > > I was on the fence about adding it as a new argument to > > > > kexec_add_buffer > > > > or as a new field to struct kexec_buf. Both alternatives make sense > > > > to > > > > me. I implemented your suggestion in the patch below, what do you > > > > think?> > > > > > > > > > Like kbuf.no_checksum, default value is 0 that means checksum is > > > > > needed > > > > > if it is 1 then no need a checksum. > > > > > > > > It's an interesting idea and I implemented it that way, though in > > > > practice all current users of struct kexec_buf put it on the stack > > > > so > > > > the field needs to be initialized explicitly. > > > > > > No need to set it as false because it will be initialized to 0 by > > > default? > > > > As far as I know, variables on the stack are not initialized. Only > > global > > and static variables are. > > But designated initializers will do it. Ah, you are right! I'll provide an updated patch then. Thanks for your suggestion. -- []'s Thiago Jung Bauermann IBM Linux Technology Center
[toc] | [prev] | [next] | [standalone]
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-23 00:20 +0200 |
| Subject | Re: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for some segments. |
| Message-ID | <s95Jw-3Lg-31@gated-at.bofh.it> |
| In reply to | #1467333 |
Am Montag, 22 August 2016, 11:36:43 schrieb Dave Young:
> On 08/22/16 at 12:25am, Thiago Jung Bauermann wrote:
> > Am Montag, 22 August 2016, 11:17:45 schrieb Dave Young:
> > > On 08/18/16 at 06:09pm, Thiago Jung Bauermann wrote:
> > > > Am Donnerstag, 18 August 2016, 17:03:30 schrieb Dave Young:
> > > > > On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote:
> > > > > > Adds checksum argument to kexec_add_buffer specifying whether
> > > > > > the
> > > > > > given
> > > > > > segment should be part of the checksum calculation.
> > > > >
> > > > > Since it is used with add buffer, could it be added to kbuf as a
> > > > > new
> > > > > field?
> > > >
> > > > I was on the fence about adding it as a new argument to
> > > > kexec_add_buffer
> > > > or as a new field to struct kexec_buf. Both alternatives make sense
> > > > to
> > > > me. I implemented your suggestion in the patch below, what do you
> > > > think?>
> > > >
> > > > > Like kbuf.no_checksum, default value is 0 that means checksum is
> > > > > needed
> > > > > if it is 1 then no need a checksum.
> > > >
> > > > It's an interesting idea and I implemented it that way, though in
> > > > practice all current users of struct kexec_buf put it on the stack
> > > > so
> > > > the field needs to be initialized explicitly.
> > >
> > > No need to set it as false because it will be initialized to 0 by
> > > default?
> >
> > As far as I know, variables on the stack are not initialized. Only
> > global
> > and static variables are.
>
> But designated initializers will do it.
Here is the new version, relying on the default value for
kexec_buf.skip_checksum. A nice side effect is that I don't have to
cc the x86 maintainers anymore.
What do you think?
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Subject: [PATCH v2 3/6] kexec_file: Allow skipping checksum calculation for
some segments.
Add skip_checksum member to struct kexec_buf to specify whether the
corresponding segment should be part of the checksum calculation.
The next patch will add a way to update segments after a kimage is loaded.
Segments that will be updated in this way should not be checksummed,
otherwise they will cause the purgatory checksum verification to fail
when the machine is rebooted.
As a bonus, we don't need to special-case the purgatory segment anymore
to avoid checksumming it.
Places currently using struct kexec_buf will get false as the default
value for skip_checksum since they all use designated initializers.
Therefore, there will not be any behavior change with this patch and
their buffers will continue being checksummed.
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
---
include/linux/kexec.h | 23 ++++++++++++++---------
kernel/kexec_file.c | 15 +++++++--------
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 4559a1a01b0a..e5b3d99cbe50 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -100,6 +100,9 @@ struct kexec_segment {
size_t bufsz;
unsigned long mem;
size_t memsz;
+
+ /* Whether this segment is ignored in the checksum calculation. */
+ bool skip_checksum;
};
#ifdef CONFIG_COMPAT
@@ -151,15 +154,16 @@ struct kexec_file_ops {
/**
* struct kexec_buf - parameters for finding a place for a buffer in memory
- * @image: kexec image in which memory to search.
- * @buffer: Contents which will be copied to the allocated memory.
- * @bufsz: Size of @buffer.
- * @mem: On return will have address of the buffer in memory.
- * @memsz: Size for the buffer in memory.
- * @buf_align: Minimum alignment needed.
- * @buf_min: The buffer can't be placed below this address.
- * @buf_max: The buffer can't be placed above this address.
- * @top_down: Allocate from top of memory.
+ * @image: kexec image in which memory to search.
+ * @buffer: Contents which will be copied to the allocated memory.
+ * @bufsz: Size of @buffer.
+ * @mem: On return will have address of the buffer in memory.
+ * @memsz: Size for the buffer in memory.
+ * @buf_align: Minimum alignment needed.
+ * @buf_min: The buffer can't be placed below this address.
+ * @buf_max: The buffer can't be placed above this address.
+ * @top_down: Allocate from top of memory.
+ * @skip_checksum: Don't verify checksum for this buffer in purgatory.
*/
struct kexec_buf {
struct kimage *image;
@@ -171,6 +175,7 @@ struct kexec_buf {
unsigned long buf_min;
unsigned long buf_max;
bool top_down;
+ bool skip_checksum;
};
int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index c8418d62e2fc..f6e9958bf578 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -658,6 +658,7 @@ int kexec_add_buffer(struct kexec_buf *kbuf)
ksegment->bufsz = kbuf->bufsz;
ksegment->mem = kbuf->mem;
ksegment->memsz = kbuf->memsz;
+ ksegment->skip_checksum = kbuf->skip_checksum;
kbuf->image->nr_segments++;
return 0;
}
@@ -672,7 +673,6 @@ static int kexec_calculate_store_digests(struct kimage *image)
char *digest;
void *zero_buf;
struct kexec_sha_region *sha_regions;
- struct purgatory_info *pi = &image->purgatory_info;
zero_buf = __va(page_to_pfn(ZERO_PAGE(0)) << PAGE_SHIFT);
zero_buf_sz = PAGE_SIZE;
@@ -712,11 +712,7 @@ static int kexec_calculate_store_digests(struct kimage *image)
struct kexec_segment *ksegment;
ksegment = &image->segment[i];
- /*
- * Skip purgatory as it will be modified once we put digest
- * info in purgatory.
- */
- if (ksegment->kbuf == pi->purgatory_buf)
+ if (ksegment->skip_checksum)
continue;
ret = crypto_shash_update(desc, ksegment->kbuf,
@@ -788,7 +784,7 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
Elf_Shdr *sechdrs = NULL;
struct kexec_buf kbuf = { .image = image, .bufsz = 0, .buf_align = 1,
.buf_min = min, .buf_max = max,
- .top_down = top_down };
+ .top_down = top_down, .skip_checksum = true };
/*
* sechdrs_c points to section headers in purgatory and are read
@@ -893,7 +889,10 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
if (kbuf.buf_align < bss_align)
kbuf.buf_align = bss_align;
- /* Add buffer to segment list */
+ /*
+ * Add buffer to segment list. Don't checksum the segment as
+ * it will be modified once we put digest info in purgatory.
+ */
ret = kexec_add_buffer(&kbuf);
if (ret)
goto out;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Dave Young <dyoung@redhat.com> |
|---|---|
| Date | 2016-08-17 05:00 +0200 |
| Subject | Re: [PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel |
| Message-ID | <s6Zfb-3kj-1@gated-at.bofh.it> |
| In reply to | #1461587 |
On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote: > Hello, > > This patch series implements a mechanism which allows the kernel to pass > on a buffer to the kernel that will be kexec'd. This buffer is passed > as a segment which is added to the kimage when it is being prepared > by kexec_file_load. > > How the second kernel is informed of this buffer is architecture-specific. > On powerpc, this is done via the device tree, by checking > the properties /chosen/linux,kexec-handover-buffer-start and > /chosen/linux,kexec-handover-buffer-end, which is analogous to how the > kernel finds the initrd. > > This is needed because the Integrity Measurement Architecture subsystem > needs to preserve its measurement list accross the kexec reboot. The > following patch series for the IMA subsystem uses this feature for that > purpose: > > https://lists.infradead.org/pipermail/kexec/2016-August/016745.html > > This is so that IMA can implement trusted boot support on the OpenPower > platform, because on such systems an intermediary Linux instance running > as part of the firmware is used to boot the target operating system via > kexec. Using this mechanism, IMA on this intermediary instance can > hand over to the target OS the measurements of the components that were > used to boot it. > > Because there could be additional measurement events between the > kexec_file_load call and the actual reboot, IMA needs a way to update the > buffer with those additional events before rebooting. One can minimize > the interval between the kexec_file_load and the reboot syscalls, but as > small as it can be, there is always the possibility that the measurement > list will be out of date at the time of reboot. > > To address this issue, this patch series also introduces > kexec_update_segment, which allows a reboot notifier to change the > contents of the image segment during the reboot process. > > Patch 5 makes kimage_load_normal_segment and kexec_update_segment share > code. It's not much code that they can share though, so I'm not sure if > the result is actually better. > > The last patch is not intended to be merged, it just demonstrates how > this feature can be used. > > This series applies on top of v5 of the "kexec_file_load implementation > for PowerPC" patch series (which applies on top of v4.8-rc1): > > https://lists.infradead.org/pipermail/kexec/2016-August/016843.html I'm trying to review your patches, but seems I can not apply them cleanly to mainline kernel or v4.8-rc1 Apply the kexec_file_load series failed as below on v4.8-rc1: Applying: kexec_file: Allow arch-specific memory walking for kexec_add_buffer error: patch failed: include/linux/kexec.h:149 error: include/linux/kexec.h: patch does not apply Patch failed at 0001 kexec_file: Allow arch-specific memory walking for kexec_add_buffer The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". What is the order of your patch series of the three patchset? [PATCH v2 0/2] extend kexec_file_load system call [PATCH v5 00/13] kexec_file_load implementation for PowerPC [PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel Do they depend on other patches? Thanks Dave
[toc] | [prev] | [next] | [standalone]
| From | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> |
|---|---|
| Date | 2016-08-17 07:00 +0200 |
| Message-ID | <s717j-4AG-1@gated-at.bofh.it> |
| In reply to | #1464292 |
Hello Dave, Am Mittwoch, 17 August 2016, 10:52:26 schrieb Dave Young: > On 08/13/16 at 12:18am, Thiago Jung Bauermann wrote: > > This series applies on top of v5 of the "kexec_file_load implementation > > for PowerPC" patch series (which applies on top of v4.8-rc1): > > > > https://lists.infradead.org/pipermail/kexec/2016-August/016843.html > > I'm trying to review your patches, but seems I can not apply them > cleanly to mainline kernel or v4.8-rc1 Strange, I just did a test using the patches I received via the kexec mailing list, and git am applied them cleanly on v4.8-rc1. > Apply the kexec_file_load series failed as below on v4.8-rc1: > > Applying: kexec_file: Allow arch-specific memory walking for > kexec_add_buffer > error: patch failed: include/linux/kexec.h:149 > error: include/linux/kexec.h: patch does not apply > Patch failed at 0001 kexec_file: Allow arch-specific memory walking for > kexec_add_buffer > The copy of the patch that failed is found in: .git/rebase-apply/patch > When you have resolved this problem, run "git am --continue". > If you prefer to skip this patch, run "git am --skip" instead. > To restore the original branch and stop patching, run "git am --abort". > > What is the order of your patch series of the three patchset? > > [PATCH v2 0/2] extend kexec_file_load system call > [PATCH v5 00/13] kexec_file_load implementation for PowerPC > [PATCH v2 0/6] kexec_file: Add buffer hand-over for the next kernel Yes, that is correct. > Do they depend on other patches? No, they apply directly on v4.8-rc1. I just published a branch with the patches, if you want you can use that instead. The branch is called kexec-patches and is at the repo git@github.com:bauermann/linux -- []'s Thiago Jung Bauermann IBM Linux Technology Center
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web