:::::: 
:::::: Manual check reason: "low confidence static check first_new_problem: 
mm/kfence/core.c:675:47: warning: Parameter 's' can be declared with const 
[constParameter]"
:::::: 

CC: [email protected]
BCC: [email protected]
CC: [email protected]
TO: Sven Schnelle <[email protected]>
CC: Heiko Carstens <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   7a68065eb9cd194cf03f135c9211eeb2d5c4c0a0
commit: e41ba1115a351dd037c21ac75660638219d51485 s390: add support for KFENCE
date:   11 months ago
:::::: branch date: 13 hours ago
:::::: commit date: 11 months ago
compiler: s390-linux-gcc (GCC) 11.3.0
reproduce (cppcheck warning):
        # apt-get install cppcheck
        git checkout e41ba1115a351dd037c21ac75660638219d51485
        cppcheck --quiet --enable=style,performance,portability --template=gcc 
FILE

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>


cppcheck possible warnings: (new ones prefixed by >>, may not real problems)

>> mm/kfence/core.c:675:47: warning: Parameter 's' can be declared with const 
>> [constParameter]
   void kfence_shutdown_cache(struct kmem_cache *s)
                                                 ^
>> net/netfilter/nf_tables_offload.c:598:27: warning: Parameter 'dev' can be 
>> declared with const [constParameter]
          struct net_device *dev)
                             ^
--
>> net/ipv4/inet_hashtables.c:305:35: warning: Parameter 'hashinfo' can be 
>> declared with const [constParameter]
               struct inet_hashinfo *hashinfo,
                                     ^

vim +/s +675 mm/kfence/core.c

0ce20dd840897b1 Alexander Potapenko 2021-02-25  674  
0ce20dd840897b1 Alexander Potapenko 2021-02-25 @675  void 
kfence_shutdown_cache(struct kmem_cache *s)
0ce20dd840897b1 Alexander Potapenko 2021-02-25  676  {
0ce20dd840897b1 Alexander Potapenko 2021-02-25  677     unsigned long flags;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  678     struct kfence_metadata 
*meta;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  679     int i;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  680  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  681     for (i = 0; i < 
CONFIG_KFENCE_NUM_OBJECTS; i++) {
0ce20dd840897b1 Alexander Potapenko 2021-02-25  682             bool in_use;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  683  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  684             meta = 
&kfence_metadata[i];
0ce20dd840897b1 Alexander Potapenko 2021-02-25  685  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  686             /*
0ce20dd840897b1 Alexander Potapenko 2021-02-25  687              * If we 
observe some inconsistent cache and state pair where we
0ce20dd840897b1 Alexander Potapenko 2021-02-25  688              * should have 
returned false here, cache destruction is racing
0ce20dd840897b1 Alexander Potapenko 2021-02-25  689              * with either 
kmem_cache_alloc() or kmem_cache_free(). Taking
0ce20dd840897b1 Alexander Potapenko 2021-02-25  690              * the lock 
will not help, as different critical section
0ce20dd840897b1 Alexander Potapenko 2021-02-25  691              * 
serialization will have the same outcome.
0ce20dd840897b1 Alexander Potapenko 2021-02-25  692              */
0ce20dd840897b1 Alexander Potapenko 2021-02-25  693             if 
(READ_ONCE(meta->cache) != s ||
0ce20dd840897b1 Alexander Potapenko 2021-02-25  694                 
READ_ONCE(meta->state) != KFENCE_OBJECT_ALLOCATED)
0ce20dd840897b1 Alexander Potapenko 2021-02-25  695                     
continue;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  696  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  697             
raw_spin_lock_irqsave(&meta->lock, flags);
0ce20dd840897b1 Alexander Potapenko 2021-02-25  698             in_use = 
meta->cache == s && meta->state == KFENCE_OBJECT_ALLOCATED;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  699             
raw_spin_unlock_irqrestore(&meta->lock, flags);
0ce20dd840897b1 Alexander Potapenko 2021-02-25  700  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  701             if (in_use) {
0ce20dd840897b1 Alexander Potapenko 2021-02-25  702                     /*
0ce20dd840897b1 Alexander Potapenko 2021-02-25  703                      * This 
cache still has allocations, and we should not
0ce20dd840897b1 Alexander Potapenko 2021-02-25  704                      * 
release them back into the freelist so they can still
0ce20dd840897b1 Alexander Potapenko 2021-02-25  705                      * 
safely be used and retain the kernel's default
0ce20dd840897b1 Alexander Potapenko 2021-02-25  706                      * 
behaviour of keeping the allocations alive (leak the
0ce20dd840897b1 Alexander Potapenko 2021-02-25  707                      * 
cache); however, they effectively become "zombie
0ce20dd840897b1 Alexander Potapenko 2021-02-25  708                      * 
allocations" as the KFENCE objects are the only ones
0ce20dd840897b1 Alexander Potapenko 2021-02-25  709                      * 
still in use and the owning cache is being destroyed.
0ce20dd840897b1 Alexander Potapenko 2021-02-25  710                      *
0ce20dd840897b1 Alexander Potapenko 2021-02-25  711                      * We 
mark them freed, so that any subsequent use shows
0ce20dd840897b1 Alexander Potapenko 2021-02-25  712                      * more 
useful error messages that will include stack
0ce20dd840897b1 Alexander Potapenko 2021-02-25  713                      * 
traces of the user of the object, the original
0ce20dd840897b1 Alexander Potapenko 2021-02-25  714                      * 
allocation, and caller to shutdown_cache().
0ce20dd840897b1 Alexander Potapenko 2021-02-25  715                      */
0ce20dd840897b1 Alexander Potapenko 2021-02-25  716                     
kfence_guarded_free((void *)meta->addr, meta, /*zombie=*/true);
0ce20dd840897b1 Alexander Potapenko 2021-02-25  717             }
0ce20dd840897b1 Alexander Potapenko 2021-02-25  718     }
0ce20dd840897b1 Alexander Potapenko 2021-02-25  719  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  720     for (i = 0; i < 
CONFIG_KFENCE_NUM_OBJECTS; i++) {
0ce20dd840897b1 Alexander Potapenko 2021-02-25  721             meta = 
&kfence_metadata[i];
0ce20dd840897b1 Alexander Potapenko 2021-02-25  722  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  723             /* See above. */
0ce20dd840897b1 Alexander Potapenko 2021-02-25  724             if 
(READ_ONCE(meta->cache) != s || READ_ONCE(meta->state) != KFENCE_OBJECT_FREED)
0ce20dd840897b1 Alexander Potapenko 2021-02-25  725                     
continue;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  726  
0ce20dd840897b1 Alexander Potapenko 2021-02-25  727             
raw_spin_lock_irqsave(&meta->lock, flags);
0ce20dd840897b1 Alexander Potapenko 2021-02-25  728             if (meta->cache 
== s && meta->state == KFENCE_OBJECT_FREED)
0ce20dd840897b1 Alexander Potapenko 2021-02-25  729                     
meta->cache = NULL;
0ce20dd840897b1 Alexander Potapenko 2021-02-25  730             
raw_spin_unlock_irqrestore(&meta->lock, flags);
0ce20dd840897b1 Alexander Potapenko 2021-02-25  731     }
0ce20dd840897b1 Alexander Potapenko 2021-02-25  732  }
0ce20dd840897b1 Alexander Potapenko 2021-02-25  733  

:::::: The code at line 675 was first introduced by commit
:::::: 0ce20dd840897b12ae70869c69f1ba34d6d16965 mm: add Kernel Electric-Fence 
infrastructure

:::::: TO: Alexander Potapenko <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp
_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to