Skip to contentSkip to conversation

jump_label: mark __start/stop___jump_table const

PATCH In review Michael S. Tsirkin 2 participants 3 messages Feb 9, 2017 – Feb 10, 2017 Static branch/call

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jump_label: mark __start/stop___jump_table const

Attempts to assign values through these pointers would fail. Mark them const to make sure the failure is compile time.

Cc Jason Baron <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 include/linux/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
index a0547c5..48ed83f 100644
@@ -132,8 +132,8 @@ static __always_inline bool static_key_true(struct static_key *key)
 	return !arch_static_branch(key, true);
 }
 
-extern struct jump_entry __start___jump_table[];
-extern struct jump_entry __stop___jump_table[];
+extern const struct jump_entry __start___jump_table[];
+extern const struct jump_entry __stop___jump_table[];
 
 extern void jump_label_init(void);
 extern void jump_label_lock(void);
Signature · 1 line
MST
#1 lore raw
Quoted 13 lines · Michael S. Tsirkin

Attempts to assign values through these pointers would fail. Mark them const to make sure the failure is compile time.

Cc Jason Baron <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Ingo Molnar <[email protected]>

Hmm this produces a bunch of warnings that I managed to somehow miss. Self-Nack. Pls disregard.

Quoted 21 lines
---
 include/linux/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
index a0547c5..48ed83f 100644
@@ -132,8 +132,8 @@ static __always_inline bool static_key_true(struct static_key *key)
 	return !arch_static_branch(key, true);
 }
 
-extern struct jump_entry __start___jump_table[];
-extern struct jump_entry __stop___jump_table[];
+extern const struct jump_entry __start___jump_table[];
+extern const struct jump_entry __stop___jump_table[];
 
 extern void jump_label_init(void);
 extern void jump_label_lock(void);
Signature · 1 line
MST
#2 lore raw
In reply to Michael S. Tsirkin
url: https://github.com/0day-ci/linux/commits/Michael-S-Tsirkin/jump_label-mark-__start-stop___jump_table-const/20170210-104623 config: x86_64-rhel (attached as .config) compiler: gcc-6 (Debian…

Hi Michael,

[auto build test WARNING on linus/master]
[also build test WARNING on v4.10-rc7 next-20170209]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Michael-S-Tsirkin/jump_label-mark-__start-stop___jump_table-const/20170210-104623
config: x86_64-rhel (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

kernel/jump_label.c: In function 'jump_label_init':

>> kernel/jump_label.c:284:34: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     struct jump_entry *iter_start = __start___jump_table;
                                     ^~~~~~~~~~~~~~~~~~~~
   kernel/jump_label.c:285:33: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     struct jump_entry *iter_stop = __stop___jump_table;
                                    ^~~~~~~~~~~~~~~~~~~
   kernel/jump_label.c: In function 'jump_label_text_reserved':
>> kernel/jump_label.c:549:39: warning: passing argument 1 of '__jump_label_text_reserved' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     int ret = __jump_label_text_reserved(__start___jump_table,
                                          ^~~~~~~~~~~~~~~~~~~~
   kernel/jump_label.c:210:12: note: expected 'struct jump_entry *' but argument is of type 'const struct jump_entry *'
    static int __jump_label_text_reserved(struct jump_entry *iter_start,
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/jump_label.c:550:4: warning: passing argument 2 of '__jump_label_text_reserved' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
       __stop___jump_table, start, end);
       ^~~~~~~~~~~~~~~~~~~
   kernel/jump_label.c:210:12: note: expected 'struct jump_entry *' but argument is of type 'const struct jump_entry *'
    static int __jump_label_text_reserved(struct jump_entry *iter_start,
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/jump_label.c: In function 'jump_label_update':
   kernel/jump_label.c:563:28: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     struct jump_entry *stop = __stop___jump_table;
                               ^~~~~~~~~~~~~~~~~~~

vim +/const +284 kernel/jump_label.c

706249c22 Peter Zijlstra      2015-07-24  268  				struct jump_entry *entry,
706249c22 Peter Zijlstra      2015-07-24  269  				struct jump_entry *stop)
706249c22 Peter Zijlstra      2015-07-24  270  {
706249c22 Peter Zijlstra      2015-07-24  271  	for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) {
706249c22 Peter Zijlstra      2015-07-24  272  		/*
706249c22 Peter Zijlstra      2015-07-24  273  		 * entry->code set to 0 invalidates module init text sections
706249c22 Peter Zijlstra      2015-07-24  274  		 * kernel_text_address() verifies we are not in core kernel
706249c22 Peter Zijlstra      2015-07-24  275  		 * init code, see jump_label_invalidate_module_init().
706249c22 Peter Zijlstra      2015-07-24  276  		 */
706249c22 Peter Zijlstra      2015-07-24  277  		if (entry->code && kernel_text_address(entry->code))
706249c22 Peter Zijlstra      2015-07-24  278  			arch_jump_label_transform(entry, jump_label_type(entry));
706249c22 Peter Zijlstra      2015-07-24  279  	}
706249c22 Peter Zijlstra      2015-07-24  280  }
706249c22 Peter Zijlstra      2015-07-24  281  
97ce2c88f Jeremy Fitzhardinge 2011-10-12  282  void __init jump_label_init(void)
bf5438fca Jason Baron         2010-09-17  283  {
bf5438fca Jason Baron         2010-09-17 @284  	struct jump_entry *iter_start = __start___jump_table;
bf5438fca Jason Baron         2010-09-17  285  	struct jump_entry *iter_stop = __stop___jump_table;
c5905afb0 Ingo Molnar         2012-02-24  286  	struct static_key *key = NULL;
bf5438fca Jason Baron         2010-09-17  287  	struct jump_entry *iter;
bf5438fca Jason Baron         2010-09-17  288  
1f69bf9c6 Jason Baron         2016-08-03  289  	/*
1f69bf9c6 Jason Baron         2016-08-03  290  	 * Since we are initializing the static_key.enabled field with
1f69bf9c6 Jason Baron         2016-08-03  291  	 * with the 'raw' int values (to avoid pulling in atomic.h) in
1f69bf9c6 Jason Baron         2016-08-03  292  	 * jump_label.h, let's make sure that is safe. There are only two

:::::: The code at line 284 was first introduced by commit
:::::: bf5438fca2950b03c21ad868090cc1a8fcd49536 jump label: Base patch for jump label

:::::: TO: Jason Baron <[email protected]> :::::: CC: Steven Rostedt <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation