mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 00:28:52 +02:00 
			
		
		
		
	static_call: Align static_call_is_init() patching condition
The intent is to avoid writing init code after init (because the text might have been freed). The code is needlessly different between jump_label and static_call and not obviously correct. The existing code relies on the fact that the module loader clears the init layout, such that within_module_init() always fails, while jump_label relies on the module state which is more obvious and matches the kernel logic. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Jarkko Sakkinen <jarkko@kernel.org> Tested-by: Sumit Garg <sumit.garg@linaro.org> Link: https://lkml.kernel.org/r/20210318113610.636651340@infradead.org
This commit is contained in:
		
							parent
							
								
									68b1eddd42
								
							
						
					
					
						commit
						698bacefe9
					
				
					 1 changed files with 4 additions and 10 deletions
				
			
		|  | @ -149,6 +149,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func) | |||
| 	}; | ||||
| 
 | ||||
| 	for (site_mod = &first; site_mod; site_mod = site_mod->next) { | ||||
| 		bool init = system_state < SYSTEM_RUNNING; | ||||
| 		struct module *mod = site_mod->mod; | ||||
| 
 | ||||
| 		if (!site_mod->sites) { | ||||
|  | @ -168,6 +169,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func) | |||
| 		if (mod) { | ||||
| 			stop = mod->static_call_sites + | ||||
| 			       mod->num_static_call_sites; | ||||
| 			init = mod->state == MODULE_STATE_COMING; | ||||
| 		} | ||||
| #endif | ||||
| 
 | ||||
|  | @ -175,16 +177,8 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func) | |||
| 		     site < stop && static_call_key(site) == key; site++) { | ||||
| 			void *site_addr = static_call_addr(site); | ||||
| 
 | ||||
| 			if (static_call_is_init(site)) { | ||||
| 				/*
 | ||||
| 				 * Don't write to call sites which were in | ||||
| 				 * initmem and have since been freed. | ||||
| 				 */ | ||||
| 				if (!mod && system_state >= SYSTEM_RUNNING) | ||||
| 					continue; | ||||
| 				if (mod && !within_module_init((unsigned long)site_addr, mod)) | ||||
| 					continue; | ||||
| 			} | ||||
| 			if (!init && static_call_is_init(site)) | ||||
| 				continue; | ||||
| 
 | ||||
| 			if (!kernel_text_address((unsigned long)site_addr)) { | ||||
| 				WARN_ONCE(1, "can't patch static call site at %pS", | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Peter Zijlstra
						Peter Zijlstra