All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Support resetting WARN_ONCE for all architectures
@ 2017-10-19 20:46 Andi Kleen
  2017-11-03  9:38 ` Michael Ellerman
  0 siblings, 1 reply; 7+ messages in thread
From: Andi Kleen @ 2017-10-19 20:46 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Andi Kleen, mpe

From: Andi Kleen <ak@linux.intel.com>

Some architectures store the WARN_ONCE state in the flags
field of the bug_entry. Clear that one too when resetting
once state through /sys/kernel/debug/clear_warn_once

Pointed out by Michael Ellerman

Improves the earlier patch that add clear_warn_once.

Cc: mpe@ellerman.id.au
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 include/linux/bug.h |  5 +++++
 kernel/panic.c      |  1 +
 lib/bug.c           | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/include/linux/bug.h b/include/linux/bug.h
index 5d5554c874fd..b8666ee88086 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -42,6 +42,8 @@ enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
 /* These are defined by the architecture */
 int is_valid_bugaddr(unsigned long addr);
 
+void generic_bug_clear_once(void);
+
 #else	/* !CONFIG_GENERIC_BUG */
 
 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
@@ -50,6 +52,9 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr,
 	return BUG_TRAP_TYPE_BUG;
 }
 
+
+static inline void generic_bug_clear_once(void) {}
+
 #endif	/* CONFIG_GENERIC_BUG */
 
 /*
diff --git a/kernel/panic.c b/kernel/panic.c
index 49dbdb231a77..840a98fa4963 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -595,6 +595,7 @@ EXPORT_SYMBOL(warn_slowpath_null);
 
 static int clear_warn_once_set(void *data, u64 val)
 {
+	generic_bug_clear_once();
 	memset(__start_once, 0, __end_once - __start_once);
 	return 0;
 }
diff --git a/lib/bug.c b/lib/bug.c
index a6a1137d06db..7cb2d41845f7 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -195,3 +195,24 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
 
 	return BUG_TRAP_TYPE_BUG;
 }
+
+static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
+{
+	struct bug_entry *bug;
+
+	for (bug = start; bug < end; bug++)
+		bug->flags &= ~BUGFLAG_ONCE;
+}
+
+void generic_bug_clear_once(void)
+{
+	struct module *mod;
+
+	rcu_read_lock_sched();
+	list_for_each_entry_rcu(mod, &module_bug_list, bug_list)
+		clear_once_table(mod->bug_table,
+				 mod->bug_table + mod->num_bugs);
+	rcu_read_unlock_sched();
+
+	clear_once_table(__start___bug_table, __stop___bug_table);
+}
-- 
2.13.6

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Support resetting WARN_ONCE for all architectures
  2017-10-19 20:46 [PATCH] Support resetting WARN_ONCE for all architectures Andi Kleen
@ 2017-11-03  9:38 ` Michael Ellerman
  2017-11-03 17:47   ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Ellerman @ 2017-11-03  9:38 UTC (permalink / raw)
  To: Andi Kleen, akpm; +Cc: linux-kernel, Andi Kleen

Hi Andi,

Thanks for making it work with the flag, but ...

Andi Kleen <andi@firstfloor.org> writes:
> diff --git a/lib/bug.c b/lib/bug.c
> index a6a1137d06db..7cb2d41845f7 100644
> --- a/lib/bug.c
> +++ b/lib/bug.c
> @@ -195,3 +195,24 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
>  
>  	return BUG_TRAP_TYPE_BUG;
>  }
> +
> +static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
> +{
> +	struct bug_entry *bug;
> +
> +	for (bug = start; bug < end; bug++)
> +		bug->flags &= ~BUGFLAG_ONCE;

Clearing BUGFLAG_ONCE removes the once-ness permanently. ie. it becomes
a WARN().

You should be clearing BUGFLAG_DONE, which is the flag that says this
WARN has already triggered.

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Support resetting WARN_ONCE for all architectures
  2017-11-03  9:38 ` Michael Ellerman
@ 2017-11-03 17:47   ` Andrew Morton
  2017-11-06  0:18     ` Michael Ellerman
  2017-11-06 21:36     ` Andi Kleen
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Morton @ 2017-11-03 17:47 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: Andi Kleen, linux-kernel, Andi Kleen

On Fri, 03 Nov 2017 20:38:03 +1100 Michael Ellerman <mpe@ellerman.id.au> wrote:

> Hi Andi,
> 
> Thanks for making it work with the flag, but ...
> 
> Andi Kleen <andi@firstfloor.org> writes:
> > diff --git a/lib/bug.c b/lib/bug.c
> > index a6a1137d06db..7cb2d41845f7 100644
> > --- a/lib/bug.c
> > +++ b/lib/bug.c
> > @@ -195,3 +195,24 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
> >  
> >  	return BUG_TRAP_TYPE_BUG;
> >  }
> > +
> > +static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
> > +{
> > +	struct bug_entry *bug;
> > +
> > +	for (bug = start; bug < end; bug++)
> > +		bug->flags &= ~BUGFLAG_ONCE;
> 
> Clearing BUGFLAG_ONCE removes the once-ness permanently. ie. it becomes
> a WARN().
> 
> You should be clearing BUGFLAG_DONE, which is the flag that says this
> WARN has already triggered.

This?

--- a/lib/bug.c~support-resetting-warn_once-for-all-architectures-v2-fix-fix-fix
+++ a/lib/bug.c
@@ -202,7 +202,7 @@ static void clear_once_table(struct bug_
 	struct bug_entry *bug;
 
 	for (bug = start; bug < end; bug++)
-		bug->flags &= ~BUGFLAG_ONCE;
+		bug->flags &= ~BUGFLAG_DONE;
 }
 
 void generic_bug_clear_once(void)


And this is getting a bit nutty:

support-resetting-warn_once.patch
support-resetting-warn_once-checkpatch-fixes.patch
support-resetting-warn_once-for-all-architectures.patch
support-resetting-warn_once-for-all-architectures-v2.patch
support-resetting-warn_once-for-all-architectures-v2-fix.patch
support-resetting-warn_once-for-all-architectures-v2-fix-fix.patch
support-resetting-warn_once-for-all-architectures-v2-fix-fix-fix.patch

I'll push all this at Stephen later today.  Someone please tell me
whether this code actually works!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Support resetting WARN_ONCE for all architectures
  2017-11-03 17:47   ` Andrew Morton
@ 2017-11-06  0:18     ` Michael Ellerman
  2017-11-06 21:36     ` Andi Kleen
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2017-11-06  0:18 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andi Kleen, linux-kernel, Andi Kleen

Andrew Morton <akpm@linux-foundation.org> writes:
> On Fri, 03 Nov 2017 20:38:03 +1100 Michael Ellerman <mpe@ellerman.id.au> wrote:
>> Andi Kleen <andi@firstfloor.org> writes:
>> > diff --git a/lib/bug.c b/lib/bug.c
>> > index a6a1137d06db..7cb2d41845f7 100644
>> > --- a/lib/bug.c
>> > +++ b/lib/bug.c
>> > @@ -195,3 +195,24 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
>> >  
>> >  	return BUG_TRAP_TYPE_BUG;
>> >  }
>> > +
>> > +static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
>> > +{
>> > +	struct bug_entry *bug;
>> > +
>> > +	for (bug = start; bug < end; bug++)
>> > +		bug->flags &= ~BUGFLAG_ONCE;
>> 
>> Clearing BUGFLAG_ONCE removes the once-ness permanently. ie. it becomes
>> a WARN().
>> 
>> You should be clearing BUGFLAG_DONE, which is the flag that says this
>> WARN has already triggered.
>
> This?

Yes.

> --- a/lib/bug.c~support-resetting-warn_once-for-all-architectures-v2-fix-fix-fix
> +++ a/lib/bug.c
> @@ -202,7 +202,7 @@ static void clear_once_table(struct bug_
>  	struct bug_entry *bug;
>  
>  	for (bug = start; bug < end; bug++)
> -		bug->flags &= ~BUGFLAG_ONCE;
> +		bug->flags &= ~BUGFLAG_DONE;
>  }
>  
>  void generic_bug_clear_once(void)
>
>
> And this is getting a bit nutty:
>
> support-resetting-warn_once.patch
> support-resetting-warn_once-checkpatch-fixes.patch
> support-resetting-warn_once-for-all-architectures.patch
> support-resetting-warn_once-for-all-architectures-v2.patch
> support-resetting-warn_once-for-all-architectures-v2-fix.patch
> support-resetting-warn_once-for-all-architectures-v2-fix-fix.patch
> support-resetting-warn_once-for-all-architectures-v2-fix-fix-fix.patch

Quite. They should probably all just be squashed together.

> I'll push all this at Stephen later today.  Someone please tell me
> whether this code actually works!

I've tested Andi's two patches with the above one-liner and that worked
for me. I'll test again on linux-next once it's in there to confirm.

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Support resetting WARN_ONCE for all architectures
  2017-11-03 17:47   ` Andrew Morton
  2017-11-06  0:18     ` Michael Ellerman
@ 2017-11-06 21:36     ` Andi Kleen
  2017-11-08  9:40       ` Michael Ellerman
  1 sibling, 1 reply; 7+ messages in thread
From: Andi Kleen @ 2017-11-06 21:36 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Michael Ellerman, Andi Kleen, linux-kernel, Andi Kleen

> 
> And this is getting a bit nutty:
> 
> support-resetting-warn_once.patch
> support-resetting-warn_once-checkpatch-fixes.patch
> support-resetting-warn_once-for-all-architectures.patch
> support-resetting-warn_once-for-all-architectures-v2.patch
> support-resetting-warn_once-for-all-architectures-v2-fix.patch
> support-resetting-warn_once-for-all-architectures-v2-fix-fix.patch
> support-resetting-warn_once-for-all-architectures-v2-fix-fix-fix.patch
> 
> I'll push all this at Stephen later today.  Someone please tell me
> whether this code actually works!

Sorry for the trash! Yes this was harder than originally expected.

The original x86 patch was tested. I see Michael now tested
the PPC version too. So everything should be good and hopefully
don't need any more fixes.

Thanks,

-Andi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Support resetting WARN_ONCE for all architectures
  2017-11-06 21:36     ` Andi Kleen
@ 2017-11-08  9:40       ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2017-11-08  9:40 UTC (permalink / raw)
  To: Andi Kleen, Andrew Morton; +Cc: Andi Kleen, linux-kernel, Andi Kleen

Andi Kleen <andi@firstfloor.org> writes:
>> 
>> And this is getting a bit nutty:
>> 
>> support-resetting-warn_once.patch
>> support-resetting-warn_once-checkpatch-fixes.patch
>> support-resetting-warn_once-for-all-architectures.patch
>> support-resetting-warn_once-for-all-architectures-v2.patch
>> support-resetting-warn_once-for-all-architectures-v2-fix.patch
>> support-resetting-warn_once-for-all-architectures-v2-fix-fix.patch
>> support-resetting-warn_once-for-all-architectures-v2-fix-fix-fix.patch
>> 
>> I'll push all this at Stephen later today.  Someone please tell me
>> whether this code actually works!
>
> Sorry for the trash! Yes this was harder than originally expected.
>
> The original x86 patch was tested. I see Michael now tested
> the PPC version too. So everything should be good and hopefully
> don't need any more fixes.

Yep, I tested next-20171107 and that works for me, if you like:

  Tested-by: Michael Ellerman <mpe@ellerman.id.au>

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] Support resetting WARN_ONCE for all architectures
@ 2017-10-20 17:06 Andi Kleen
  0 siblings, 0 replies; 7+ messages in thread
From: Andi Kleen @ 2017-10-20 17:06 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Andi Kleen, mpe

From: Andi Kleen <ak@linux.intel.com>

Some architectures store the WARN_ONCE state in the flags
field of the bug_entry. Clear that one too when resetting
once state through /sys/kernel/debug/clear_warn_once

Pointed out by Michael Ellerman

Improves the earlier patch that add clear_warn_once.

Cc: mpe@ellerman.id.au
v2: Add a missing ifdef CONFIG_MODULES. Thanks 0day!
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 include/linux/bug.h |  5 +++++
 kernel/panic.c      |  1 +
 lib/bug.c           | 23 +++++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/include/linux/bug.h b/include/linux/bug.h
index 5d5554c874fd..b8666ee88086 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -42,6 +42,8 @@ enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs);
 /* These are defined by the architecture */
 int is_valid_bugaddr(unsigned long addr);
 
+void generic_bug_clear_once(void);
+
 #else	/* !CONFIG_GENERIC_BUG */
 
 static inline enum bug_trap_type report_bug(unsigned long bug_addr,
@@ -50,6 +52,9 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr,
 	return BUG_TRAP_TYPE_BUG;
 }
 
+
+static inline void generic_bug_clear_once(void) {}
+
 #endif	/* CONFIG_GENERIC_BUG */
 
 /*
diff --git a/kernel/panic.c b/kernel/panic.c
index 49dbdb231a77..840a98fa4963 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -595,6 +595,7 @@ EXPORT_SYMBOL(warn_slowpath_null);
 
 static int clear_warn_once_set(void *data, u64 val)
 {
+	generic_bug_clear_once();
 	memset(__start_once, 0, __end_once - __start_once);
 	return 0;
 }
diff --git a/lib/bug.c b/lib/bug.c
index a6a1137d06db..2adafcb41d5b 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -195,3 +195,26 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
 
 	return BUG_TRAP_TYPE_BUG;
 }
+
+static void clear_once_table(struct bug_entry *start, struct bug_entry *end)
+{
+	struct bug_entry *bug;
+
+	for (bug = start; bug < end; bug++)
+		bug->flags &= ~BUGFLAG_ONCE;
+}
+
+void generic_bug_clear_once(void)
+{
+	struct module *mod;
+
+#ifdef CONFIG_MODULES
+	rcu_read_lock_sched();
+	list_for_each_entry_rcu(mod, &module_bug_list, bug_list)
+		clear_once_table(mod->bug_table,
+				 mod->bug_table + mod->num_bugs);
+	rcu_read_unlock_sched();
+#endif
+
+	clear_once_table(__start___bug_table, __stop___bug_table);
+}
-- 
2.13.6

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-11-08  9:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19 20:46 [PATCH] Support resetting WARN_ONCE for all architectures Andi Kleen
2017-11-03  9:38 ` Michael Ellerman
2017-11-03 17:47   ` Andrew Morton
2017-11-06  0:18     ` Michael Ellerman
2017-11-06 21:36     ` Andi Kleen
2017-11-08  9:40       ` Michael Ellerman
2017-10-20 17:06 Andi Kleen

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.