linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [linux-next:master 1570/2472] mm/kasan/init.c:318:9: warning: variable 'pud' set but not used
@ 2020-11-01 23:31 kernel test robot
  2020-11-03  0:17 ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: kernel test robot @ 2020-11-01 23:31 UTC (permalink / raw)
  To: Linus Walleij
  Cc: kbuild-all, Linux Memory Management List, Russell King,
	Ard Biesheuvel, Abbott Liu, Florian Fainelli

[-- Attachment #1: Type: text/plain, Size: 7786 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   4e78c578cb987725eef1cec7d11b6437109e9a49
commit: 421015713b306e47af95d4d61cdfbd96d462e4cb [1570/2472] ARM: 9017/2: Enable KASan for ARM
config: arm-randconfig-r025-20201030 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=421015713b306e47af95d4d61cdfbd96d462e4cb
        git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
        git fetch --no-tags linux-next master
        git checkout 421015713b306e47af95d4d61cdfbd96d462e4cb
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   mm/kasan/init.c: In function 'kasan_free_pud':
>> mm/kasan/init.c:318:9: warning: variable 'pud' set but not used [-Wunused-but-set-variable]
     318 |  pud_t *pud;
         |         ^~~
--
   In file included from include/trace/define_trace.h:103,
                    from include/trace/events/rcu.h:785,
                    from kernel/rcu/rcu.h:13,
                    from kernel/rcu/update.c:49:
   include/trace/events/rcu.h: In function 'perf_trace_rcu_torture_read':
>> include/trace/events/rcu.h:724:3: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
     724 |   strncpy(__entry->rcutorturename, rcutorturename,
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     725 |    RCUTORTURENAME_LEN);
         |    ~~~~~~~~~~~~~~~~~~~
   include/trace/perf.h:66:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
      66 |  { assign; }       \
         |    ^~~~~~
   include/trace/trace_events.h:79:9: note: in expansion of macro 'PARAMS'
      79 |         PARAMS(assign),         \
         |         ^~~~~~
   include/trace/events/rcu.h:11:25: note: in expansion of macro 'TRACE_EVENT'
      11 | #define TRACE_EVENT_RCU TRACE_EVENT
         |                         ^~~~~~~~~~~
   include/trace/events/rcu.h:723:2: note: in expansion of macro 'TP_fast_assign'
     723 |  TP_fast_assign(
         |  ^~~~~~~~~~~~~~
   In file included from include/trace/define_trace.h:102,
                    from include/trace/events/rcu.h:785,
                    from kernel/rcu/rcu.h:13,
                    from kernel/rcu/update.c:49:
   include/trace/events/rcu.h: In function 'trace_event_raw_event_rcu_torture_read':
>> include/trace/events/rcu.h:724:3: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
     724 |   strncpy(__entry->rcutorturename, rcutorturename,
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     725 |    RCUTORTURENAME_LEN);
         |    ~~~~~~~~~~~~~~~~~~~
   include/trace/trace_events.h:695:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     695 |  { assign; }       \
         |    ^~~~~~
   include/trace/trace_events.h:79:9: note: in expansion of macro 'PARAMS'
      79 |         PARAMS(assign),         \
         |         ^~~~~~
   include/trace/events/rcu.h:11:25: note: in expansion of macro 'TRACE_EVENT'
      11 | #define TRACE_EVENT_RCU TRACE_EVENT
         |                         ^~~~~~~~~~~
   include/trace/events/rcu.h:723:2: note: in expansion of macro 'TP_fast_assign'
     723 |  TP_fast_assign(
         |  ^~~~~~~~~~~~~~
--
   In file included from include/trace/define_trace.h:103,
                    from include/trace/events/fscache.h:533,
                    from fs/fscache/internal.h:28,
                    from fs/fscache/main.c:16:
   include/trace/events/fscache.h: In function 'perf_trace_fscache_netfs':
>> include/trace/events/fscache.h:208:7: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
     208 |       strncpy(__entry->name, netfs->name, 8);
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/perf.h:66:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
      66 |  { assign; }       \
         |    ^~~~~~
   include/trace/trace_events.h:79:9: note: in expansion of macro 'PARAMS'
      79 |         PARAMS(assign),         \
         |         ^~~~~~
   include/trace/events/fscache.h:196:1: note: in expansion of macro 'TRACE_EVENT'
     196 | TRACE_EVENT(fscache_netfs,
         | ^~~~~~~~~~~
   include/trace/events/fscache.h:206:6: note: in expansion of macro 'TP_fast_assign'
     206 |      TP_fast_assign(
         |      ^~~~~~~~~~~~~~
   In file included from include/trace/define_trace.h:102,
                    from include/trace/events/fscache.h:533,
                    from fs/fscache/internal.h:28,
                    from fs/fscache/main.c:16:
   include/trace/events/fscache.h: In function 'trace_event_raw_event_fscache_netfs':
>> include/trace/events/fscache.h:208:7: warning: 'strncpy' specified bound 8 equals destination size [-Wstringop-truncation]
     208 |       strncpy(__entry->name, netfs->name, 8);
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/trace_events.h:695:4: note: in definition of macro 'DECLARE_EVENT_CLASS'
     695 |  { assign; }       \
         |    ^~~~~~
   include/trace/trace_events.h:79:9: note: in expansion of macro 'PARAMS'
      79 |         PARAMS(assign),         \
         |         ^~~~~~
   include/trace/events/fscache.h:196:1: note: in expansion of macro 'TRACE_EVENT'
     196 | TRACE_EVENT(fscache_netfs,
         | ^~~~~~~~~~~
   include/trace/events/fscache.h:206:6: note: in expansion of macro 'TP_fast_assign'
     206 |      TP_fast_assign(
         |      ^~~~~~~~~~~~~~

vim +/pud +318 mm/kasan/init.c

0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  315  
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  316  static void kasan_free_pud(pud_t *pud_start, p4d_t *p4d)
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  317  {
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17 @318  	pud_t *pud;
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  319  	int i;
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  320  
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  321  	for (i = 0; i < PTRS_PER_PUD; i++) {
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  322  		pud = pud_start + i;
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  323  		if (!pud_none(*pud))
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  324  			return;
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  325  	}
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  326  
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  327  	pud_free(&init_mm, (pud_t *)page_to_virt(p4d_page(*p4d)));
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  328  	p4d_clear(p4d);
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  329  }
0207df4fa1a8692 mm/kasan/kasan_init.c Andrey Ryabinin 2018-08-17  330  

:::::: The code at line 318 was first introduced by commit
:::::: 0207df4fa1a869281ddbf72db6203dbf036b3e1a kernel/memremap, kasan: make ZONE_DEVICE with work with KASAN

:::::: TO: Andrey Ryabinin <aryabinin@virtuozzo.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 35198 bytes --]

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

* Re: [linux-next:master 1570/2472] mm/kasan/init.c:318:9: warning: variable 'pud' set but not used
  2020-11-01 23:31 [linux-next:master 1570/2472] mm/kasan/init.c:318:9: warning: variable 'pud' set but not used kernel test robot
@ 2020-11-03  0:17 ` Linus Walleij
  2020-11-03  8:22   ` Ard Biesheuvel
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2020-11-03  0:17 UTC (permalink / raw)
  To: kernel test robot
  Cc: kbuild-all, Linux Memory Management List, Russell King,
	Ard Biesheuvel, Abbott Liu, Florian Fainelli, Linux ARM

On Mon, Nov 2, 2020 at 12:32 AM kernel test robot <lkp@intel.com> wrote:

>    mm/kasan/init.c: In function 'kasan_free_pud':
> >> mm/kasan/init.c:318:9: warning: variable 'pud' set but not used [-Wunused-but-set-variable]
>      318 |  pud_t *pud;
>          |         ^~~

So this is because
arch/arm/include/asm/pgtable-2level.h has:
#define pud_none(pud)           (0)
because of the way that PMDs are folded into the PUD.
(See the comment in the file.)

This is not liked by KASan because it looks like the pud
variable is unused.

Any suggestions? Should it be:
#define pud_none(pud)          (!pud_val(pud))
Like most other archs?

I also toyed with just putting __maybe_unused into the kasan init.

Any other ways to solve this?

Yours,
Linus Walleij


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

* Re: [linux-next:master 1570/2472] mm/kasan/init.c:318:9: warning: variable 'pud' set but not used
  2020-11-03  0:17 ` Linus Walleij
@ 2020-11-03  8:22   ` Ard Biesheuvel
  2020-11-06  8:53     ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2020-11-03  8:22 UTC (permalink / raw)
  To: Linus Walleij
  Cc: kernel test robot, kbuild-all, Linux Memory Management List,
	Russell King, Abbott Liu, Florian Fainelli, Linux ARM

On Tue, 3 Nov 2020 at 01:17, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Mon, Nov 2, 2020 at 12:32 AM kernel test robot <lkp@intel.com> wrote:
>
> >    mm/kasan/init.c: In function 'kasan_free_pud':
> > >> mm/kasan/init.c:318:9: warning: variable 'pud' set but not used [-Wunused-but-set-variable]
> >      318 |  pud_t *pud;
> >          |         ^~~
>
> So this is because
> arch/arm/include/asm/pgtable-2level.h has:
> #define pud_none(pud)           (0)
> because of the way that PMDs are folded into the PUD.
> (See the comment in the file.)
>
> This is not liked by KASan because it looks like the pud
> variable is unused.
>
> Any suggestions? Should it be:
> #define pud_none(pud)          (!pud_val(pud))
> Like most other archs?
>
> I also toyed with just putting __maybe_unused into the kasan init.
>
> Any other ways to solve this?
>

What about

diff --git a/mm/kasan/init.c b/mm/kasan/init.c
index fe6be0be1f76..7c3eb1f5a439 100644
--- a/mm/kasan/init.c
+++ b/mm/kasan/init.c
@@ -315,12 +315,10 @@ static void kasan_free_pmd(pmd_t *pmd_start, pud_t *pud)

 static void kasan_free_pud(pud_t *pud_start, p4d_t *p4d)
 {
-       pud_t *pud;
        int i;

        for (i = 0; i < PTRS_PER_PUD; i++) {
-               pud = pud_start + i;
-               if (!pud_none(*pud))
+               if (!pud_none(pud_start[i]))
                        return;
        }


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

* Re: [linux-next:master 1570/2472] mm/kasan/init.c:318:9: warning: variable 'pud' set but not used
  2020-11-03  8:22   ` Ard Biesheuvel
@ 2020-11-06  8:53     ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2020-11-06  8:53 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: kernel test robot, kbuild-all, Linux Memory Management List,
	Russell King, Abbott Liu, Florian Fainelli, Linux ARM

On Tue, Nov 3, 2020 at 9:22 AM Ard Biesheuvel <ardb@kernel.org> wrote:

> What about
>
> diff --git a/mm/kasan/init.c b/mm/kasan/init.c
> index fe6be0be1f76..7c3eb1f5a439 100644
> --- a/mm/kasan/init.c
> +++ b/mm/kasan/init.c
> @@ -315,12 +315,10 @@ static void kasan_free_pmd(pmd_t *pmd_start, pud_t *pud)
>
>  static void kasan_free_pud(pud_t *pud_start, p4d_t *p4d)
>  {
> -       pud_t *pud;
>         int i;
>
>         for (i = 0; i < PTRS_PER_PUD; i++) {
> -               pud = pud_start + i;
> -               if (!pud_none(*pud))
> +               if (!pud_none(pud_start[i]))
>                         return;
>         }

Yeah that is way better, also makes the code a lot easier to read.

I sent a patch rewriting all the kasan_free_p??() calls like this.

Yours,
Linus Walleij


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

end of thread, other threads:[~2020-11-06  8:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-01 23:31 [linux-next:master 1570/2472] mm/kasan/init.c:318:9: warning: variable 'pud' set but not used kernel test robot
2020-11-03  0:17 ` Linus Walleij
2020-11-03  8:22   ` Ard Biesheuvel
2020-11-06  8:53     ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).