public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Olof Johansson <olof@lixom•net>
To: Michael Neuling <mikey@neuling•org>
Cc: linuxppc-dev@ozlabs•org, RAISCH@de•ibm.com,
	Paul Mackerras <paulus@samba•org>,
	THEMANN@de•ibm.com
Subject: Re: [PATCH 2/2] kdump shutdown hook support
Date: Wed, 12 Dec 2007 23:12:24 -0600	[thread overview]
Message-ID: <20071213051224.GA22378@lixom.net> (raw)
In-Reply-To: <20071213031618.DBD207038C@localhost.localdomain>

Hi,

On Thu, Dec 13, 2007 at 02:16:18PM +1100, Michael Neuling wrote:

> Index: clone3/arch/powerpc/kernel/crash.c
> ===================================================================
> --- clone3.orig/arch/powerpc/kernel/crash.c
> +++ clone3/arch/powerpc/kernel/crash.c
> @@ -32,6 +32,8 @@
>  #include <asm/lmb.h>
>  #include <asm/firmware.h>
>  #include <asm/smp.h>
> +#include <asm/system.h>
> +#include <asm/setjmp.h>
>  
>  #ifdef DEBUG
>  #include <asm/udbg.h>
> @@ -45,6 +47,11 @@ int crashing_cpu = -1;
>  static cpumask_t cpus_in_crash = CPU_MASK_NONE;
>  cpumask_t cpus_in_sr = CPU_MASK_NONE;
>  
> +#define CRASH_HANDLER_MAX 1
> +/* NULL terminated list of shutdown handles */
> +static crash_shutdown_t crash_shutdown_handles[CRASH_HANDLER_MAX+1];
> +static DEFINE_SPINLOCK(crash_handers_lock);

How about just using 'handlers' instead of 'handers' and 'handles'? :)

>  static atomic_t enter_on_soft_reset = ATOMIC_INIT(0);
>  
> @@ -285,9 +292,72 @@ static inline void crash_kexec_stop_spus
>  }
>  #endif /* CONFIG_SPU_BASE */
>  
> +/*
> + * Register a function to be called on shutdown.  Only use this if you
> + * can't reset your device in the second kernel.
> + */
> +int crash_shutdown_register(crash_shutdown_t handler)
> +{
> +	unsigned int i, rc;
> +
> +	spin_lock(&crash_handers_lock);
> +	for (i = 0 ; i < CRASH_HANDLER_MAX; i++)
> +		if (!crash_shutdown_handles[i]) {
> +			/* Insert handle at first empty entry */
> +			crash_shutdown_handles[i] = handler;
> +			rc = 0;
> +			break;
> +		}
> +
> +	if (i == CRASH_HANDLER_MAX) {
> +		printk(KERN_ERR "Crash shutdown handles full, "
> +		       "not registered.\n");
> +		rc = 1;
> +	}
> +
> +	spin_unlock(&crash_handers_lock);
> +	return rc;
> +}
> +EXPORT_SYMBOL(crash_shutdown_register);
> +
> +int crash_shutdown_unregister(crash_shutdown_t handler)
> +{
> +	unsigned int i, rc;
> +
> +	spin_lock(&crash_handers_lock);
> +	for (i = 0 ; i < CRASH_HANDLER_MAX; i++)
> +		if (crash_shutdown_handles[i] == handler)
> +			break;
> +
> +	if (i == CRASH_HANDLER_MAX) {
> +		printk(KERN_ERR "Crash shutdown handle not found\n");
> +		rc = 1;
> +	} else {
> +		/* Shift handles down */
> +		for (; crash_shutdown_handles[i]; i++)
> +			crash_shutdown_handles[i] =
> +				crash_shutdown_handles[i+1];
> +		rc = 0;
> +	}
> +
> +	spin_unlock(&crash_handers_lock);
> +	return rc;
> +}
> +EXPORT_SYMBOL(crash_shutdown_unregister);
> +
> +static unsigned long crash_shutdown_buf[SETJMP_BUF_LEN];
> +
> +static int handle_fault(struct pt_regs *regs)
> +{
> +	longjmp(crash_shutdown_buf, 1);
> +	return 0;
> +}
> +
>  void default_machine_crash_shutdown(struct pt_regs *regs)
>  {
> -	unsigned int irq;
> +	unsigned int i;
> +	int (*old_handler)(struct pt_regs *regs);
> +
>  
>  	/*
>  	 * This function is only called after the system
> @@ -301,15 +371,37 @@ void default_machine_crash_shutdown(stru
>  	 */
>  	hard_irq_disable();
>  
> -	for_each_irq(irq) {
> -		struct irq_desc *desc = irq_desc + irq;
> +	for_each_irq(i) {
> +		struct irq_desc *desc = irq_desc + i;
>  
>  		if (desc->status & IRQ_INPROGRESS)
> -			desc->chip->eoi(irq);
> +			desc->chip->eoi(i);
>  
>  		if (!(desc->status & IRQ_DISABLED))
> -			desc->chip->disable(irq);
> +			desc->chip->disable(i);
> +	}
> +
> +	/*
> +	 * Call registered shutdown routines savely.  Swap out
> +	 * __debugger_fault_handler, and replace on exit.
> +	 */
> +	old_handler = __debugger_fault_handler;
> +	__debugger_fault_handler = handle_fault;
> +	for (i = 0; crash_shutdown_handles[i]; i++) {
> +		if (setjmp(crash_shutdown_buf) == 0) {
> +			/*
> +			 * Insert syncs and delay to ensure
> +			 * instructions in the dangerous region don't
> +			 * leak away from this protected region.
> +			 */
> +			asm volatile("sync; isync");
> +			/* dangerous region */
> +			crash_shutdown_handles[i]();
> +			asm volatile("sync; isync");
> +			__delay(SETJMP_MACHINE_CHECK_DELAY);

Where is this defined?

> +		}
>  	}
> +	__debugger_fault_handler = old_handler;
>  
>  	/*
>  	 * Make a note of crashing cpu. Will be used in machine_kexec
> Index: clone3/include/asm-powerpc/kexec.h
> ===================================================================
> --- clone3.orig/include/asm-powerpc/kexec.h
> +++ clone3/include/asm-powerpc/kexec.h
> @@ -123,6 +123,9 @@ struct pt_regs;
>  extern void default_machine_kexec(struct kimage *image);
>  extern int default_machine_kexec_prepare(struct kimage *image);
>  extern void default_machine_crash_shutdown(struct pt_regs *regs);
> +typedef void (*crash_shutdown_t)(void);
> +extern int crash_shutdown_register(crash_shutdown_t handler);
> +extern int crash_shutdown_unregister(crash_shutdown_t handler);
>  
>  extern void machine_kexec_simple(struct kimage *image);
>  extern void crash_kexec_secondary(struct pt_regs *regs);
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs•org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev

  reply	other threads:[~2007-12-13  5:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-12  5:45 [PATCH 2/2] kdump shutdown hook support Michael Neuling
2007-12-12  7:01 ` Olof Johansson
2007-12-13  0:53   ` Michael Neuling
2007-12-12 23:07 ` Michael Ellerman
2007-12-13  0:04   ` Michael Neuling
2007-12-13  3:16 ` [PATCH 0/2] Add crashdump shutdown hooks Michael Neuling
2007-12-13  3:16   ` [PATCH 2/2] kdump shutdown hook support Michael Neuling
2007-12-13  5:12     ` Olof Johansson [this message]
2007-12-13  5:13       ` Olof Johansson
2007-12-13  9:59       ` [PATCH 0/2] Add crashdump shutdown hooks Michael Neuling
2007-12-13  9:59         ` [PATCH 2/2] kdump shutdown hook support Michael Neuling
2007-12-13  9:59         ` [PATCH 1/2] Make setjmp/longjmp code generic Michael Neuling
2008-01-17  4:45         ` [PATCH 0/2] Add crashdump shutdown hooks Michael Neuling
2008-01-17  4:45           ` [PATCH 1/2] Make setjmp/longjmp code generic Michael Neuling
2008-01-17  5:38             ` Olof Johansson
2008-01-17  5:36               ` Michael Neuling
2008-01-17  6:36                 ` Stephen Rothwell
2008-01-17 12:45                 ` Josh Boyer
2008-01-17 21:49                   ` Michael Ellerman
2008-01-17 22:16                 ` [PATCH] Add crashdump shutdown hooks Michael Neuling
2008-01-17 22:16                   ` [PATCH] Make setjmp/longjmp code generic Michael Neuling
2008-01-18  4:50                   ` [PATCH 0/2] Add crashdump shutdown hooks Michael Neuling
2008-01-18  4:50                     ` [PATCH 2/2] kdump shutdown hook support Michael Neuling
2008-01-18  4:50                     ` [PATCH 1/2] Make setjmp/longjmp code generic Michael Neuling
2008-01-17  6:39             ` Stephen Rothwell
2008-01-17  4:45           ` [PATCH 2/2] kdump shutdown hook support Michael Neuling
2007-12-13  3:16   ` [PATCH 1/2] Make setjmp/longjmp code generic Michael Neuling

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=20071213051224.GA22378@lixom.net \
    --to=olof@lixom$(echo .)net \
    --cc=RAISCH@de$(echo .)ibm.com \
    --cc=THEMANN@de$(echo .)ibm.com \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    --cc=mikey@neuling$(echo .)org \
    --cc=paulus@samba$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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