[PATCH v5] alpha: Clean-up the panic notifier code

Guilherme G. Piccoli posted 1 patch 2 years, 3 months ago
There is a newer version of this series
arch/alpha/kernel/setup.c | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)
[PATCH v5] alpha: Clean-up the panic notifier code
Posted by Guilherme G. Piccoli 2 years, 3 months ago
The alpha panic notifier has some code issues, not following
the conventions of other notifiers. Also, it might halt the
machine but still it is set to run as early as possible, which
doesn't seem to be a good idea.

So, let's clean the code and set the notifier to run as the
latest, following the same approach other architectures are
doing - also, remove the unnecessary include of a header already
included indirectly.

Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---

V5: rebased against v6.5, build-tested using defconfig.

V4: https://lore.kernel.org/lkml/20230220212245.153554-1-gpiccoli@igalia.com/

Hi Matt, apologies for the annoyance. Seems that this one was never picked-up;
let me know if there's anything missing.

Thanks in advance,

Guilherme


 arch/alpha/kernel/setup.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
index 3d7473531ab1..07afd2bf18d7 100644
--- a/arch/alpha/kernel/setup.c
+++ b/arch/alpha/kernel/setup.c
@@ -41,19 +41,11 @@
 #include <linux/sysrq.h>
 #include <linux/reboot.h>
 #endif
-#include <linux/notifier.h>
 #include <asm/setup.h>
 #include <asm/io.h>
 #include <linux/log2.h>
 #include <linux/export.h>
 
-static int alpha_panic_event(struct notifier_block *, unsigned long, void *);
-static struct notifier_block alpha_panic_block = {
-	alpha_panic_event,
-        NULL,
-        INT_MAX /* try to do it first */
-};
-
 #include <linux/uaccess.h>
 #include <asm/hwrpb.h>
 #include <asm/dma.h>
@@ -434,6 +426,21 @@ static const struct sysrq_key_op srm_sysrq_reboot_op = {
 };
 #endif
 
+static int alpha_panic_event(struct notifier_block *this,
+			     unsigned long event, void *ptr)
+{
+	/* If we are using SRM and serial console, just hard halt here. */
+	if (alpha_using_srm && srmcons_output)
+		__halt();
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block alpha_panic_block = {
+	.notifier_call = alpha_panic_event,
+	.priority = INT_MIN, /* may not return, do it last */
+};
+
 void __init
 setup_arch(char **cmdline_p)
 {
@@ -1426,19 +1433,6 @@ const struct seq_operations cpuinfo_op = {
 	.show	= show_cpuinfo,
 };
 
-
-static int
-alpha_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
-{
-#if 1
-	/* FIXME FIXME FIXME */
-	/* If we are using SRM and serial console, just hard halt here. */
-	if (alpha_using_srm && srmcons_output)
-		__halt();
-#endif
-        return NOTIFY_DONE;
-}
-
 static __init int add_pcspkr(void)
 {
 	struct platform_device *pd;
-- 
2.41.0
Re: [PATCH v5] alpha: Clean-up the panic notifier code
Posted by Maciej W. Rozycki 2 years, 2 months ago
On Sat, 2 Sep 2023, Guilherme G. Piccoli wrote:

> So, let's clean the code and set the notifier to run as the
> latest, following the same approach other architectures are
> doing - also, remove the unnecessary include of a header already
> included indirectly.

 FWIW my understanding is our current policy is not to rely on indirect 
inclusions and if a given source relies on declarations or definitions 
provided by a header, then it is supposed to pull it explicitly.

 And in any case such an unrelated self-contained change is expected to be 
sent as a separate patch, in a series if there's a mechanical dependency.

  Maciej
Re: [PATCH v5] alpha: Clean-up the panic notifier code
Posted by Guilherme G. Piccoli 2 years, 2 months ago
On 10/10/2023 02:16, Maciej W. Rozycki wrote:
> On Sat, 2 Sep 2023, Guilherme G. Piccoli wrote:
> 
>> So, let's clean the code and set the notifier to run as the
>> latest, following the same approach other architectures are
>> doing - also, remove the unnecessary include of a header already
>> included indirectly.
> 
>  FWIW my understanding is our current policy is not to rely on indirect 
> inclusions and if a given source relies on declarations or definitions 
> provided by a header, then it is supposed to pull it explicitly.
> 
>  And in any case such an unrelated self-contained change is expected to be 
> sent as a separate patch, in a series if there's a mechanical dependency.
> 
>   Maciej
> 

Hi Maciej, thanks for your review!

I'm not sure how the indirect inclusion is happening here. The only
notifier present in this file is a panic notifier, and for this one, we
have the "panic_notifier.h" header. It's like this for many others (if
not all) panic notifiers in the kernel.

Usually the indirect inclusion would happen if some other notifier block
was used for any other reason, and we dropped the "notifier.h" include,
which then would indirectly rely on "panic_notifier.h". In case I'm
talking silly things, let me know! I might not have understood properly
your point (and if so, apologies).

Regarding split in another patch, it can easily be done, but I think
it's quite self-contained now, a simple patch that cleans-up the alpha
notifier. I've done that for other notifiers so far, but I'm OK either
way, as long maintainers are happy and community agrees =)

Cheers,


Guilherme
Re: [PATCH v5] alpha: Clean-up the panic notifier code
Posted by Petr Mladek 2 years, 1 month ago
On Sun 2023-10-15 15:54:49, Guilherme G. Piccoli wrote:
> On 10/10/2023 02:16, Maciej W. Rozycki wrote:
> > On Sat, 2 Sep 2023, Guilherme G. Piccoli wrote:
> > 
> >> So, let's clean the code and set the notifier to run as the
> >> latest, following the same approach other architectures are
> >> doing - also, remove the unnecessary include of a header already
> >> included indirectly.
> > 
> >  FWIW my understanding is our current policy is not to rely on indirect 
> > inclusions and if a given source relies on declarations or definitions 
> > provided by a header, then it is supposed to pull it explicitly.
> > 
> >  And in any case such an unrelated self-contained change is expected to be 
> > sent as a separate patch, in a series if there's a mechanical dependency.
> > 
> >   Maciej
> > 
> 
> Hi Maciej, thanks for your review!
> 
> I'm not sure how the indirect inclusion is happening here. The only
> notifier present in this file is a panic notifier, and for this one, we
> have the "panic_notifier.h" header. It's like this for many others (if
> not all) panic notifiers in the kernel.

IMHO, including linux/panic_notifier.h should be enough. It is includes
linux/notifier.h by definition.

Well, it is not a big deal to keep the include. Let's not block the
change because of this.

> Regarding split in another patch, it can easily be done, but I think
> it's quite self-contained now, a simple patch that cleans-up the alpha
> notifier. I've done that for other notifiers so far, but I'm OK either
> way, as long maintainers are happy and community agrees =)

If I was the maintainer, I would prefer the split as well ;-)
I mean to move the code in one patch and do the changes in
a followup patch.

It is much easier for review. It is more clear what are the real
changes and that there are only wanted changes.

Even removal of the include might be in a separate patch. It helps
to find regressions by bisecting. The eventual revert is easier.
Also it does not block the other changes ;-)

Best Regards,
Petr
Re: [PATCH v5] alpha: Clean-up the panic notifier code
Posted by Guilherme G. Piccoli 2 years, 1 month ago
On 20/10/2023 09:53, Petr Mladek wrote:
> [...]

OK, thanks folks! I'll resubmit without the includes change =)

Cheers!