Subject: Re: [PATCH rebased] powerpc/fadump: when fadump is supported register the fadump sysfs files.

From: Michal Suchánek <[email-masked]>
Date: Wed, 28 Aug 2019 19:07:21 +0200

On Tue, 27 Aug 2019 17:57:31 +0530
Hari Bathini <[email-masked]> wrote:

> Hi Michal,
> 
> Thanks for the patch. 
> 
> On 20/08/19 11:42 PM, Michal Suchanek wrote:
> > Currently it is not possible to distinguish the case when fadump is
> > supported by firmware and disabled in kernel and completely unsupported
> > using the kernel sysfs interface. User can investigate the devicetree
> > but it is more reasonable to provide sysfs files in case we get some
> > fadumpv2 in the future.
> > 
> > With this patch sysfs files are available whenever fadump is supported
> > by firmware.
> > 
> > Signed-off-by: Michal Suchanek <[email-masked]>
> > ---
> > Rebase on top of http://patchwork.ozlabs.org/patch/1150160/
> > [v5,31/31] powernv/fadump: support holes in kernel boot memory area
> > ---
> >  arch/powerpc/kernel/fadump.c | 33 ++++++++++++++++++---------------
> >  1 file changed, 18 insertions(+), 15 deletions(-)
> > 
> > diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
> > index 4b1bb3c55cf9..7ad424729e9c 100644
> > --- a/arch/powerpc/kernel/fadump.c
> > +++ b/arch/powerpc/kernel/fadump.c
> > @@ -1319,13 +1319,9 @@ static void fadump_init_files(void)
> >   */
> >  int __init setup_fadump(void)
> >  {
> > -	if (!fw_dump.fadump_enabled)
> > -		return 0;
> > -
> > -	if (!fw_dump.fadump_supported) {
> > +	if (!fw_dump.fadump_supported && fw_dump.fadump_enabled) {
> >  		printk(KERN_ERR "Firmware-assisted dump is not supported on"
> >  			" this hardware\n");
> > -		return 0;
> >  	}
> >  
> >  	fadump_show_config();
> > @@ -1333,19 +1329,26 @@ int __init setup_fadump(void)
> >  	 * If dump data is available then see if it is valid and prepare for
> >  	 * saving it to the disk.
> >  	 */
> > -	if (fw_dump.dump_active) {
> > +	if (fw_dump.fadump_enabled) {
> > +		if (fw_dump.dump_active) {
> > +			/*
> > +			 * if dump process fails then invalidate the
> > +			 * registration and release memory before proceeding
> > +			 * for re-registration.
> > +			 */
> > +			if (fw_dump.ops->fadump_process(&fw_dump) < 0)
> > +				fadump_invalidate_release_mem();
> > +		}
> >  		/*
> > -		 * if dump process fails then invalidate the registration
> > -		 * and release memory before proceeding for re-registration.
> > +		 * Initialize the kernel dump memory structure for FAD
> > +		 * registration.
> >  		 */
> > -		if (fw_dump.ops->fadump_process(&fw_dump) < 0)
> > -			fadump_invalidate_release_mem();
> > -	}
> > -	/* Initialize the kernel dump memory structure for FAD registration. */
> > -	else if (fw_dump.reserve_dump_area_size)
> > -		fw_dump.ops->fadump_init_mem_struct(&fw_dump);
> > +		else if (fw_dump.reserve_dump_area_size)
> > +			fw_dump.ops->fadump_init_mem_struct(&fw_dump);
> >  
> > -	fadump_init_files();
> > +	}
> > +	if (fw_dump.fadump_supported)
> > +		fadump_init_files();
> >  
> >  	return 1;
> >  }
> >   
> 
> 
> Could you please move up fadump_init_files() call and return after it instead of
> nesting rest of the function. 

That sounds reasonable.

> Also, get rid of the error message when fadump is
> not supported as it is already taken care of in fadump_reserve_mem() function.

That should not be called in that case, should it?

Anyway, I find the message right next to the message about reserving
memory for kdump. So it really looks helpful in the log.

> I mean:
> 
> diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
> index 2015b1f..0e9b028 100644
> --- a/arch/powerpc/kernel/fadump.c
> +++ b/arch/powerpc/kernel/fadump.c
> @@ -1322,16 +1322,16 @@ static void fadump_init_files(void)
>   */
>  int __init setup_fadump(void)
>  {
> -       if (!fw_dump.fadump_enabled)
> +       if (!fw_dump.fadump_supported)
>                 return 0;
>  
> -       if (!fw_dump.fadump_supported) {
> -               printk(KERN_ERR "Firmware-assisted dump is not supported on"
> -                       " this hardware\n");
> -               return 0;
> -       }
> +       fadump_init_files();
>  
>         fadump_show_config();
> +
> +       if (!fw_dump.fadump_enabled)
> +               return 0;

Should the init function return 0 when it did something that needs to
be undone later (ie registering the sysfs files)? This is probably not
very meaningful for fadump but what is the correct way to not set a bad
example?

Thanks

Michal