All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kdb: Avoid array subscript warnings on non-SMP builds
@ 2019-10-21 10:10 Daniel Thompson
  2019-10-21 17:01 ` Doug Anderson
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Thompson @ 2019-10-21 10:10 UTC (permalink / raw)
  To: Douglas Anderson, Jason Wessel
  Cc: Daniel Thompson, kgdb-bugreport, linux-kernel, patches,
	kbuild test robot

Recent versions of gcc (reported on gcc-7.4) issue array subscript
warnings for builds where SMP is not enabled.

kernel/debug/debug_core.c: In function 'kdb_dump_stack_on_cpu':
kernel/debug/debug_core.c:452:17: warning: array subscript is outside array
+bounds [-Warray-bounds]
     if (!(kgdb_info[cpu].exception_state & DCPU_IS_SLAVE)) {
           ~~~~~~~~~^~~~~
   kernel/debug/debug_core.c:469:33: warning: array subscript is outside array
+bounds [-Warray-bounds]
     kgdb_info[cpu].exception_state |= DCPU_WANT_BT;
   kernel/debug/debug_core.c:470:18: warning: array subscript is outside array
+bounds [-Warray-bounds]
     while (kgdb_info[cpu].exception_state & DCPU_WANT_BT)

There is no bug here but there is scope to improve the code
generation for non-SMP systems (whilst also silencing the warning).

Reported-by: kbuild test robot <lkp@intel.com>
Fixes: 2277b492582d ("kdb: Fix stack crawling on 'running' CPUs that aren't the master")
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
---

Notes:
    Changes in v2:
    
     - Moved the IS_ENABLED(CONFIG_SMP) test to the first (slightly easier
       to read the code, improves code generation a little)
     - Sent out as a proper patch e-mail ;-)

 kernel/debug/debug_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 70e86b4b4932..2b7c9b67931d 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -444,7 +444,7 @@ int dbg_remove_all_break(void)
 #ifdef CONFIG_KGDB_KDB
 void kdb_dump_stack_on_cpu(int cpu)
 {
-	if (cpu == raw_smp_processor_id()) {
+	if (cpu == raw_smp_processor_id() || !IS_ENABLED(CONFIG_SMP)) {
 		dump_stack();
 		return;
 	}
--
2.21.0


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

* Re: [PATCH v2] kdb: Avoid array subscript warnings on non-SMP builds
  2019-10-21 10:10 [PATCH v2] kdb: Avoid array subscript warnings on non-SMP builds Daniel Thompson
@ 2019-10-21 17:01 ` Doug Anderson
  0 siblings, 0 replies; 2+ messages in thread
From: Doug Anderson @ 2019-10-21 17:01 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: Jason Wessel, kgdb-bugreport, LKML, Patch Tracking, kbuild test robot

Hi,

On Mon, Oct 21, 2019 at 3:11 AM Daniel Thompson
<daniel.thompson@linaro.org> wrote:
>
> Recent versions of gcc (reported on gcc-7.4) issue array subscript
> warnings for builds where SMP is not enabled.
>
> kernel/debug/debug_core.c: In function 'kdb_dump_stack_on_cpu':
> kernel/debug/debug_core.c:452:17: warning: array subscript is outside array
> +bounds [-Warray-bounds]
>      if (!(kgdb_info[cpu].exception_state & DCPU_IS_SLAVE)) {
>            ~~~~~~~~~^~~~~
>    kernel/debug/debug_core.c:469:33: warning: array subscript is outside array
> +bounds [-Warray-bounds]
>      kgdb_info[cpu].exception_state |= DCPU_WANT_BT;
>    kernel/debug/debug_core.c:470:18: warning: array subscript is outside array
> +bounds [-Warray-bounds]
>      while (kgdb_info[cpu].exception_state & DCPU_WANT_BT)
>
> There is no bug here but there is scope to improve the code
> generation for non-SMP systems (whilst also silencing the warning).
>
> Reported-by: kbuild test robot <lkp@intel.com>
> Fixes: 2277b492582d ("kdb: Fix stack crawling on 'running' CPUs that aren't the master")
> Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
> ---
>
> Notes:
>     Changes in v2:
>
>      - Moved the IS_ENABLED(CONFIG_SMP) test to the first (slightly easier
>        to read the code, improves code generation a little)
>      - Sent out as a proper patch e-mail ;-)
>
>  kernel/debug/debug_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
> index 70e86b4b4932..2b7c9b67931d 100644
> --- a/kernel/debug/debug_core.c
> +++ b/kernel/debug/debug_core.c
> @@ -444,7 +444,7 @@ int dbg_remove_all_break(void)
>  #ifdef CONFIG_KGDB_KDB
>  void kdb_dump_stack_on_cpu(int cpu)
>  {
> -       if (cpu == raw_smp_processor_id()) {
> +       if (cpu == raw_smp_processor_id() || !IS_ENABLED(CONFIG_SMP)) {

At first I thought maybe your code would be less efficient than:

  if (!IS_ENABLED(CONFIG_SMP) || cpu == raw_smp_processor_id())

...since the compiler would be still be required to "call"
raw_smp_processor_id() in the non-SMP case.  ...but then I realized
that seems to be a macro in the non-SMP case and just resolves to 0.
...so while the compiler would still be "required" to execute the
first part of the if test, it should be able to realize that it's a
no-op.

Reviewed-by: Douglas Anderson <dianders@chromium.org>

-Doug




>                 dump_stack();
>                 return;
>         }
> --
> 2.21.0
>

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

end of thread, other threads:[~2019-10-21 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 10:10 [PATCH v2] kdb: Avoid array subscript warnings on non-SMP builds Daniel Thompson
2019-10-21 17:01 ` Doug Anderson

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.