public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: linux-kernel@vger.kernel.org, kexec@lists.infradead.org
Cc: ebiederm@xmission.com, hpa@zytor.com, mjg59@srcf.ucam.org,
	greg@kroah.com, bp@alien8.de, dyoung@redhat.com,
	chaowang@redhat.com, bhe@redhat.com, akpm@linux-foundation.org
Subject: [PATCH 16/15] kexec: Fix freeing up for image loader data loading
Date: Fri, 27 Jun 2014 12:34:23 -0400	[thread overview]
Message-ID: <20140627163423.GG13337@redhat.com> (raw)
In-Reply-To: <1403814824-7587-1-git-send-email-vgoyal@redhat.com>


During testing I noticed a crash. Which in turn showed that there are
problems with how I am freeing up image->image_loader_data.

In one case I am freeing up kimage->image_loader_data first and then
calling up arch to free up which might have been contained in that
structure. That's wrong.

I have done little cleanup and this should fix the issues around
freeing up of loader data.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
---
 arch/x86/kernel/kexec-bzimage64.c  |    4 ++--
 arch/x86/kernel/machine_kexec_64.c |    2 +-
 include/linux/kexec.h              |    2 +-
 kernel/kexec.c                     |   11 ++++++++---
 4 files changed, 12 insertions(+), 7 deletions(-)

Index: linux-2.6/arch/x86/kernel/machine_kexec_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/machine_kexec_64.c	2014-06-27 09:55:41.824755401 -0400
+++ linux-2.6/arch/x86/kernel/machine_kexec_64.c	2014-06-27 11:02:02.607548946 -0400
@@ -369,7 +369,7 @@ int arch_kimage_file_post_load_cleanup(s
 	if (!image->fops || !image->fops->cleanup)
 		return 0;
 
-	return image->fops->cleanup(image);
+	return image->fops->cleanup(image->image_loader_data);
 }
 
 /*
Index: linux-2.6/include/linux/kexec.h
===================================================================
--- linux-2.6.orig/include/linux/kexec.h	2014-06-27 09:55:41.695754029 -0400
+++ linux-2.6/include/linux/kexec.h	2014-06-27 11:04:28.467151813 -0400
@@ -190,7 +190,7 @@ typedef void *(kexec_load_t)(struct kima
 			     unsigned long kernel_len, char *initrd,
 			     unsigned long initrd_len, char *cmdline,
 			     unsigned long cmdline_len);
-typedef int (kexec_cleanup_t)(struct kimage *image);
+typedef int (kexec_cleanup_t)(void *loader_data);
 
 struct kexec_file_ops {
 	kexec_probe_t *probe;
Index: linux-2.6/arch/x86/kernel/kexec-bzimage64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/kexec-bzimage64.c	2014-06-27 09:55:41.872755912 -0400
+++ linux-2.6/arch/x86/kernel/kexec-bzimage64.c	2014-06-27 11:05:42.151963710 -0400
@@ -512,9 +512,9 @@ out_free_params:
 }
 
 /* This cleanup function is called after various segments have been loaded */
-int bzImage64_cleanup(struct kimage *image)
+int bzImage64_cleanup(void *loader_data)
 {
-	struct bzimage64_data *ldata = image->image_loader_data;
+	struct bzimage64_data *ldata = loader_data;
 
 	if (!ldata)
 		return 0;
Index: linux-2.6/kernel/kexec.c
===================================================================
--- linux-2.6.orig/kernel/kexec.c	2014-06-27 10:04:23.409024171 -0400
+++ linux-2.6/kernel/kexec.c	2014-06-27 11:45:14.684874978 -0400
@@ -459,6 +459,14 @@ static void kimage_file_post_load_cleanu
 
 	/* See if architecture has anything to cleanup post load */
 	arch_kimage_file_post_load_cleanup(image);
+
+	/*
+	 * Above call should have called into bootloader to free up
+	 * any data stored in kimage->image_loader_data. It should
+	 * be ok now to free it up.
+	 */
+	kfree(image->image_loader_data);
+	image->image_loader_data = NULL;
 }
 
 /*
@@ -584,7 +592,6 @@ out_free_control_pages:
 	kimage_free_page_list(&image->control_pages);
 out_free_post_load_bufs:
 	kimage_file_post_load_cleanup(image);
-	kfree(image->image_loader_data);
 out_free_image:
 	kfree(image);
 	return ret;
@@ -908,8 +915,6 @@ static void kimage_free(struct kimage *i
 	/* Free the kexec control pages... */
 	kimage_free_page_list(&image->control_pages);
 
-	kfree(image->image_loader_data);
-
 	/*
 	 * Free up any temporary buffers allocated. This might hit if
 	 * error occurred much later after buffer allocation.

      parent reply	other threads:[~2014-06-27 18:01 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26 20:33 [PATCH 00/15][V4] kexec: A new system call to allow in kernel loading Vivek Goyal
2014-06-26 20:33 ` [PATCH 01/15] bin2c: Move bin2c in scripts/basic Vivek Goyal
2014-06-26 20:33 ` [PATCH 02/15] kernel: Build bin2c based on config option CONFIG_BUILD_BIN2C Vivek Goyal
2014-06-26 20:33 ` [PATCH 03/15] kexec: rename unusebale_pages to unusable_pages Vivek Goyal
2014-06-26 20:33 ` [PATCH 04/15] kexec: Move segment verification code in a separate function Vivek Goyal
2014-06-26 20:33 ` [PATCH 05/15] kexec: Use common function for kimage_normal_alloc() and kimage_crash_alloc() Vivek Goyal
2014-06-26 20:33 ` [PATCH 06/15] resource: Provide new functions to walk through resources Vivek Goyal
2014-06-26 20:33 ` [PATCH 07/15] kexec: Make kexec_segment user buffer pointer a union Vivek Goyal
2014-06-26 20:33 ` [PATCH 08/15] kexec: New syscall kexec_file_load() declaration Vivek Goyal
2014-06-26 20:43   ` Vivek Goyal
2014-06-26 21:03     ` Andy Lutomirski
2014-06-27 11:50       ` Vivek Goyal
2014-06-27 12:20         ` Michael Kerrisk (man-pages)
2014-06-26 20:33 ` [PATCH 09/15] kexec: Implementation of new syscall kexec_file_load Vivek Goyal
2014-06-26 20:58   ` Andrew Morton
2014-06-27 16:31     ` Vivek Goyal
2014-07-01 20:25       ` Vivek Goyal
2014-06-26 20:33 ` [PATCH 10/15] purgatory/sha256: Provide implementation of sha256 in purgaotory context Vivek Goyal
2014-06-26 20:33 ` [PATCH 11/15] purgatory: Core purgatory functionality Vivek Goyal
2014-08-11 17:40   ` Shaun Ruffell
2014-08-11 17:51     ` H. Peter Anvin
2014-08-11 18:02       ` Vivek Goyal
2014-08-11 18:08         ` H. Peter Anvin
2014-08-11 18:15           ` Vivek Goyal
2014-08-11 20:23           ` Vivek Goyal
2014-06-26 20:33 ` [PATCH 12/15] kexec: Load and Relocate purgatory at kernel load time Vivek Goyal
2014-06-26 20:33 ` [PATCH 13/15] kexec-bzImage64: Support for loading bzImage using 64bit entry Vivek Goyal
2014-06-26 20:33 ` [PATCH 14/15] kexec: Support for kexec on panic using new system call Vivek Goyal
2014-06-26 20:33 ` [PATCH 15/15] kexec: Support kexec/kdump on EFI systems Vivek Goyal
2014-07-01 19:46   ` Matt Fleming
2014-07-01 20:14     ` Andrew Morton
2014-07-01 20:21       ` Vivek Goyal
2014-07-01 21:23       ` Matt Fleming
2014-07-01 20:09   ` [PATCH 17/15] kexec-bzimage: Change EFI helper function names Vivek Goyal
2014-06-26 20:39 ` [PATCH 00/15][V4] kexec: A new system call to allow in kernel loading Vivek Goyal
2014-06-26 20:58 ` Andrew Morton
2014-06-26 21:21   ` Borislav Petkov
2014-06-27 11:33   ` Vivek Goyal
2014-06-27 16:34 ` Vivek Goyal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140627163423.GG13337@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=chaowang@redhat.com \
    --cc=dyoung@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=greg@kroah.com \
    --cc=hpa@zytor.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjg59@srcf.ucam.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox