All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Ying <ying.huang@intel.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: nigel@nigel.suspend2.net,
	Kexec Mailing List <kexec@lists.infradead.org>,
	linux-kernel@vger.kernel.org, "Rafael J. Wysocki" <rjw@sisk.pl>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Pavel Machek <pavel@ucw.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-pm@lists.linux-foundation.org
Subject: Re: [PATCH -mm 1/2] kexec jump -v12: kexec jump
Date: Wed, 09 Jul 2008 09:09:23 +0800	[thread overview]
Message-ID: <1215565763.16450.4.camel@caritas-dev.intel.com> (raw)
In-Reply-To: <20080708145051.GA14745@redhat.com>

On Tue, 2008-07-08 at 10:50 -0400, Vivek Goyal wrote:
> On Mon, Jul 07, 2008 at 11:25:22AM +0800, Huang Ying wrote:
> > This patch provides an enhancement to kexec/kdump. It implements
> > the following features:
> > 
> > - Backup/restore memory used by the original kernel before/after
> >   kexec.
> > 
> > - Save/restore CPU state before/after kexec.
> > 
> 
> Hi Huang,
> 
> In general this patch set looks good enough to live in -mm and
> get some testing going.
> 
> To me, adding capability to return back to original kernel looks
> like a logical extension to kexec functionality.
> 
> Acked-by: Vivek Goyal <vgoyal@redhat.com>
> 
> Few minor comments inline.

Thank you very much!

> [..]
> > --- a/arch/x86/kernel/machine_kexec_32.c
> > +++ b/arch/x86/kernel/machine_kexec_32.c
> > @@ -22,6 +22,7 @@
> >  #include <asm/cpufeature.h>
> >  #include <asm/desc.h>
> >  #include <asm/system.h>
> > +#include <asm/cacheflush.h>
> >  
> >  #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
> >  static u32 kexec_pgd[1024] PAGE_ALIGNED;
> > @@ -85,10 +86,12 @@ static void load_segments(void)
> >   * reboot code buffer to allow us to avoid allocations
> >   * later.
> >   *
> > - * Currently nothing.
> > + * Make control page executable.
> >   */
> >  int machine_kexec_prepare(struct kimage *image)
> >  {
> > +	if (nx_enabled)
> > +		set_pages_x(image->control_code_page, 1);
> >  	return 0;
> >  }
> >  
> > @@ -98,16 +101,24 @@ int machine_kexec_prepare(struct kimage 
> >   */
> >  void machine_kexec_cleanup(struct kimage *image)
> >  {
> > +	if (nx_enabled)
> > +		set_pages_nx(image->control_code_page, 1);
> >  }
> >  
> >  /*
> >   * Do not allocate memory (or fail in any way) in machine_kexec().
> >   * We are past the point of no return, committed to rebooting now.
> >   */
> > -NORET_TYPE void machine_kexec(struct kimage *image)
> > +void machine_kexec(struct kimage *image)
> >  {
> >  	unsigned long page_list[PAGES_NR];
> >  	void *control_page;
> > +	asmlinkage unsigned long
> > +		(*relocate_kernel_ptr)(unsigned long indirection_page,
> > +				       unsigned long control_page,
> > +				       unsigned long start_address,
> > +				       unsigned int has_pae,
> > +				       unsigned int preserve_context);
> >  
> >  	tracer_disable();
> >  
> > @@ -115,10 +126,11 @@ NORET_TYPE void machine_kexec(struct kim
> >  	local_irq_disable();
> >  
> >  	control_page = page_address(image->control_code_page);
> > -	memcpy(control_page, relocate_kernel, PAGE_SIZE);
> > +	memcpy(control_page, relocate_kernel, PAGE_SIZE/2);
> >  
> 
> Is it possible to add either a compile time or run time check
> somewhere to make sure code in relocate_kernel.S does not exceed
> PAGE_SIZE/2.

OK, I will add it.

> [..]
> > --- a/kernel/kexec.c
> > +++ b/kernel/kexec.c
> > @@ -24,6 +24,8 @@
> >  #include <linux/utsrelease.h>
> >  #include <linux/utsname.h>
> >  #include <linux/numa.h>
> > +#include <linux/suspend.h>
> > +#include <linux/device.h>
> >  
> >  #include <asm/page.h>
> >  #include <asm/uaccess.h>
> > @@ -242,6 +244,12 @@ static int kimage_normal_alloc(struct ki
> >  		goto out;
> >  	}
> >  
> > +	image->swap_page = kimage_alloc_control_pages(image, 0);
> > +	if (!image->swap_page) {
> > +		printk(KERN_ERR "Could not allocate swap buffer\n");
> > +		goto out;
> > +	}
> > +
> >  	result = 0;
> >   out:
> >  	if (result == 0)
> > @@ -986,6 +994,8 @@ asmlinkage long sys_kexec_load(unsigned 
> >  		if (result)
> >  			goto out;
> >  
> > +		if (flags & KEXEC_PRESERVE_CONTEXT)
> > +			image->preserve_context = 1;
> >  		result = machine_kexec_prepare(image);
> >  		if (result)
> >  			goto out;
> > @@ -1411,3 +1421,50 @@ static int __init crash_save_vmcoreinfo_
> >  }
> >  
> >  module_init(crash_save_vmcoreinfo_init)
> > +
> > +/**
> > + *	kernel_kexec - reboot the system
> > + *
> > + *	Move into place and start executing a preloaded standalone
> > + *	executable.  If nothing was preloaded return an error.
> > + */
> > +int kernel_kexec(void)
> > +{
> > +	int error = 0;
> > +
> > +	if (xchg(&kexec_lock, 1))
> > +		return -EBUSY;
> > +	if (!kexec_image) {
> > +		error = -EINVAL;
> > +		goto Unlock;
> > +	}
> > +
> > +	if (kexec_image->preserve_context) {
> > +#ifdef CONFIG_KEXEC_JUMP
> > +		local_irq_disable();
> > +		save_processor_state();
> > +#endif
> > +	} else {
> > +		blocking_notifier_call_chain(&reboot_notifier_list,
> > +					     SYS_RESTART, NULL);
> > +		system_state = SYSTEM_RESTART;
> > +		device_shutdown();
> > +		sysdev_shutdown();
> > +		printk(KERN_EMERG "Starting new kernel\n");
> > +		machine_shutdown();
> 
> All the above code was part of kernel_restart_prepare(), can't we just
> make that function non-static and use that?

OK, I will do that.

> [..]
> > --- a/arch/x86/kernel/relocate_kernel_32.S
> > +++ b/arch/x86/kernel/relocate_kernel_32.S
> > @@ -20,11 +20,44 @@
> >  #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
> >  #define PAE_PGD_ATTR (_PAGE_PRESENT)
> >  
> > +/* control_page + PAGE_SIZE/2 ~ control_page + PAGE_SIZE * 3/4 are
> > + * used to save some data for jumping back
> > + */
> > +#define DATA(offset)		(PAGE_SIZE/2+(offset))
> > +
> > +/* Minimal CPU state */
> > +#define ESP			DATA(0x0)
> > +#define CR0			DATA(0x4)
> > +#define CR3			DATA(0x8)
> > +#define CR4			DATA(0xc)
> > +
> > +/* other data */
> > +#define CP_VA_CONTROL_PAGE	DATA(0x10)
> > +#define CP_PA_PGD		DATA(0x14)
> > +#define CP_PA_SWAP_PAGE		DATA(0x18)
> > +#define CP_PA_BACKUP_PAGES_MAP	DATA(0x1c)
> > +
> 
> In general, this assembly piece of code is getting bigger and its
> difficult to read it now. I think we should at-least pull out the page
> table setup code into C. Somebody had posted a patch to do that. Don't
> know what happened to that. Anyway, this is a separate issue and is on
> wish list.

In fact, that patch was posted by me. I will re-post that patch.

Best Regards,
Huang Ying



_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

WARNING: multiple messages have this Message-ID (diff)
From: Huang Ying <ying.huang@intel.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Pavel Machek <pavel@ucw.cz>,
	nigel@nigel.suspend2.net, "Rafael J. Wysocki" <rjw@sisk.pl>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	linux-pm@lists.linux-foundation.org,
	Kexec Mailing List <kexec@lists.infradead.org>
Subject: Re: [PATCH -mm 1/2] kexec jump -v12: kexec jump
Date: Wed, 09 Jul 2008 09:09:23 +0800	[thread overview]
Message-ID: <1215565763.16450.4.camel@caritas-dev.intel.com> (raw)
In-Reply-To: <20080708145051.GA14745@redhat.com>

On Tue, 2008-07-08 at 10:50 -0400, Vivek Goyal wrote:
> On Mon, Jul 07, 2008 at 11:25:22AM +0800, Huang Ying wrote:
> > This patch provides an enhancement to kexec/kdump. It implements
> > the following features:
> > 
> > - Backup/restore memory used by the original kernel before/after
> >   kexec.
> > 
> > - Save/restore CPU state before/after kexec.
> > 
> 
> Hi Huang,
> 
> In general this patch set looks good enough to live in -mm and
> get some testing going.
> 
> To me, adding capability to return back to original kernel looks
> like a logical extension to kexec functionality.
> 
> Acked-by: Vivek Goyal <vgoyal@redhat.com>
> 
> Few minor comments inline.

Thank you very much!

> [..]
> > --- a/arch/x86/kernel/machine_kexec_32.c
> > +++ b/arch/x86/kernel/machine_kexec_32.c
> > @@ -22,6 +22,7 @@
> >  #include <asm/cpufeature.h>
> >  #include <asm/desc.h>
> >  #include <asm/system.h>
> > +#include <asm/cacheflush.h>
> >  
> >  #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
> >  static u32 kexec_pgd[1024] PAGE_ALIGNED;
> > @@ -85,10 +86,12 @@ static void load_segments(void)
> >   * reboot code buffer to allow us to avoid allocations
> >   * later.
> >   *
> > - * Currently nothing.
> > + * Make control page executable.
> >   */
> >  int machine_kexec_prepare(struct kimage *image)
> >  {
> > +	if (nx_enabled)
> > +		set_pages_x(image->control_code_page, 1);
> >  	return 0;
> >  }
> >  
> > @@ -98,16 +101,24 @@ int machine_kexec_prepare(struct kimage 
> >   */
> >  void machine_kexec_cleanup(struct kimage *image)
> >  {
> > +	if (nx_enabled)
> > +		set_pages_nx(image->control_code_page, 1);
> >  }
> >  
> >  /*
> >   * Do not allocate memory (or fail in any way) in machine_kexec().
> >   * We are past the point of no return, committed to rebooting now.
> >   */
> > -NORET_TYPE void machine_kexec(struct kimage *image)
> > +void machine_kexec(struct kimage *image)
> >  {
> >  	unsigned long page_list[PAGES_NR];
> >  	void *control_page;
> > +	asmlinkage unsigned long
> > +		(*relocate_kernel_ptr)(unsigned long indirection_page,
> > +				       unsigned long control_page,
> > +				       unsigned long start_address,
> > +				       unsigned int has_pae,
> > +				       unsigned int preserve_context);
> >  
> >  	tracer_disable();
> >  
> > @@ -115,10 +126,11 @@ NORET_TYPE void machine_kexec(struct kim
> >  	local_irq_disable();
> >  
> >  	control_page = page_address(image->control_code_page);
> > -	memcpy(control_page, relocate_kernel, PAGE_SIZE);
> > +	memcpy(control_page, relocate_kernel, PAGE_SIZE/2);
> >  
> 
> Is it possible to add either a compile time or run time check
> somewhere to make sure code in relocate_kernel.S does not exceed
> PAGE_SIZE/2.

OK, I will add it.

> [..]
> > --- a/kernel/kexec.c
> > +++ b/kernel/kexec.c
> > @@ -24,6 +24,8 @@
> >  #include <linux/utsrelease.h>
> >  #include <linux/utsname.h>
> >  #include <linux/numa.h>
> > +#include <linux/suspend.h>
> > +#include <linux/device.h>
> >  
> >  #include <asm/page.h>
> >  #include <asm/uaccess.h>
> > @@ -242,6 +244,12 @@ static int kimage_normal_alloc(struct ki
> >  		goto out;
> >  	}
> >  
> > +	image->swap_page = kimage_alloc_control_pages(image, 0);
> > +	if (!image->swap_page) {
> > +		printk(KERN_ERR "Could not allocate swap buffer\n");
> > +		goto out;
> > +	}
> > +
> >  	result = 0;
> >   out:
> >  	if (result == 0)
> > @@ -986,6 +994,8 @@ asmlinkage long sys_kexec_load(unsigned 
> >  		if (result)
> >  			goto out;
> >  
> > +		if (flags & KEXEC_PRESERVE_CONTEXT)
> > +			image->preserve_context = 1;
> >  		result = machine_kexec_prepare(image);
> >  		if (result)
> >  			goto out;
> > @@ -1411,3 +1421,50 @@ static int __init crash_save_vmcoreinfo_
> >  }
> >  
> >  module_init(crash_save_vmcoreinfo_init)
> > +
> > +/**
> > + *	kernel_kexec - reboot the system
> > + *
> > + *	Move into place and start executing a preloaded standalone
> > + *	executable.  If nothing was preloaded return an error.
> > + */
> > +int kernel_kexec(void)
> > +{
> > +	int error = 0;
> > +
> > +	if (xchg(&kexec_lock, 1))
> > +		return -EBUSY;
> > +	if (!kexec_image) {
> > +		error = -EINVAL;
> > +		goto Unlock;
> > +	}
> > +
> > +	if (kexec_image->preserve_context) {
> > +#ifdef CONFIG_KEXEC_JUMP
> > +		local_irq_disable();
> > +		save_processor_state();
> > +#endif
> > +	} else {
> > +		blocking_notifier_call_chain(&reboot_notifier_list,
> > +					     SYS_RESTART, NULL);
> > +		system_state = SYSTEM_RESTART;
> > +		device_shutdown();
> > +		sysdev_shutdown();
> > +		printk(KERN_EMERG "Starting new kernel\n");
> > +		machine_shutdown();
> 
> All the above code was part of kernel_restart_prepare(), can't we just
> make that function non-static and use that?

OK, I will do that.

> [..]
> > --- a/arch/x86/kernel/relocate_kernel_32.S
> > +++ b/arch/x86/kernel/relocate_kernel_32.S
> > @@ -20,11 +20,44 @@
> >  #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
> >  #define PAE_PGD_ATTR (_PAGE_PRESENT)
> >  
> > +/* control_page + PAGE_SIZE/2 ~ control_page + PAGE_SIZE * 3/4 are
> > + * used to save some data for jumping back
> > + */
> > +#define DATA(offset)		(PAGE_SIZE/2+(offset))
> > +
> > +/* Minimal CPU state */
> > +#define ESP			DATA(0x0)
> > +#define CR0			DATA(0x4)
> > +#define CR3			DATA(0x8)
> > +#define CR4			DATA(0xc)
> > +
> > +/* other data */
> > +#define CP_VA_CONTROL_PAGE	DATA(0x10)
> > +#define CP_PA_PGD		DATA(0x14)
> > +#define CP_PA_SWAP_PAGE		DATA(0x18)
> > +#define CP_PA_BACKUP_PAGES_MAP	DATA(0x1c)
> > +
> 
> In general, this assembly piece of code is getting bigger and its
> difficult to read it now. I think we should at-least pull out the page
> table setup code into C. Somebody had posted a patch to do that. Don't
> know what happened to that. Anyway, this is a separate issue and is on
> wish list.

In fact, that patch was posted by me. I will re-post that patch.

Best Regards,
Huang Ying



  parent reply	other threads:[~2008-07-09  1:04 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-07  3:25 [PATCH -mm 1/2] kexec jump -v12: kexec jump Huang Ying
2008-07-07  3:25 ` Huang Ying
2008-07-07 12:50 ` Pavel Machek
2008-07-07 12:50   ` Pavel Machek
2008-07-08  9:10   ` Huang Ying
2008-07-08  9:10   ` Huang Ying
2008-07-08  9:10     ` Huang Ying
2008-07-08 10:40     ` Pavel Machek
2008-07-08 10:40       ` Pavel Machek
2008-07-09  1:12       ` Huang Ying
2008-07-09  1:12       ` Huang Ying
2008-07-09  1:12         ` Huang Ying
2008-07-08 10:40     ` Pavel Machek
2008-07-07 12:50 ` Pavel Machek
2008-07-08 14:50 ` Vivek Goyal
2008-07-08 14:50 ` Vivek Goyal
2008-07-08 14:50   ` Vivek Goyal
2008-07-09  1:09   ` Huang Ying
2008-07-09  1:09   ` Huang Ying [this message]
2008-07-09  1:09     ` Huang Ying
2008-07-11 19:21   ` Andrew Morton
2008-07-11 19:21   ` Andrew Morton
2008-07-11 19:21     ` Andrew Morton
2008-07-11 20:11     ` Vivek Goyal
2008-07-11 20:11       ` Vivek Goyal
2008-07-12  1:02       ` Nigel Cunningham
2008-07-12  1:02         ` Nigel Cunningham
2008-07-14  5:46         ` Pavel Machek
2008-07-14  5:46         ` Pavel Machek
2008-07-14  5:46           ` Pavel Machek
2008-07-14 13:32           ` Vivek Goyal
2008-07-14 13:32             ` Vivek Goyal
2008-08-04 11:01             ` Pavel Machek
2008-08-04 11:01             ` Pavel Machek
2008-08-04 11:01               ` Pavel Machek
2008-07-14 13:32           ` Vivek Goyal
2008-07-14 13:09         ` Vivek Goyal
2008-07-14 13:09           ` Vivek Goyal
2008-07-14 13:09         ` Vivek Goyal
2008-07-12  1:02       ` Nigel Cunningham
2008-07-11 20:11     ` Vivek Goyal
2008-07-11 20:24     ` Pavel Machek
2008-07-11 20:24       ` Pavel Machek
2008-07-11 20:40       ` Rafael J. Wysocki
2008-07-11 20:40       ` Rafael J. Wysocki
2008-07-11 20:40         ` Rafael J. Wysocki
2008-07-12  2:23         ` Eric W. Biederman
2008-07-12  2:23           ` Eric W. Biederman
2008-07-12  3:04           ` [linux-pm] " Alan Stern
2008-07-12  3:04             ` Alan Stern
2008-07-12  3:50             ` Eric W. Biederman
2008-07-12  3:50             ` [linux-pm] " Eric W. Biederman
2008-07-12  3:50               ` Eric W. Biederman
2008-07-12 18:52               ` Rafael J. Wysocki
2008-07-12 18:52                 ` Rafael J. Wysocki
2008-07-12 18:52               ` Rafael J. Wysocki
2008-07-12 19:55               ` Alan Stern
2008-07-12 19:55               ` [linux-pm] " Alan Stern
2008-07-12 19:55                 ` Alan Stern
2008-07-12  3:04           ` Alan Stern
2008-07-12  2:23         ` Eric W. Biederman
2008-07-11 20:24     ` Pavel Machek
2008-07-14 13:30     ` huang ying
2008-07-14 13:30     ` huang ying
2008-07-14 13:30       ` huang ying
2008-07-14 13:30     ` huang ying
  -- strict thread matches above, loose matches on Subject: below --
2008-07-07  3:25 Huang Ying

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=1215565763.16450.4.camel@caritas-dev.intel.com \
    --to=ying.huang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=nigel@nigel.suspend2.net \
    --cc=pavel@ucw.cz \
    --cc=rjw@sisk.pl \
    --cc=vgoyal@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.