forked from mirrors/linux
		
	 dbefa1f31a
			
		
	
	
		dbefa1f31a
		
	
	
	
	
		
			
			Commitb1fca27d38("kernel debug: support resetting WARN*_ONCE") added support for clearing the state of once warnings. However, it is not functional when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION or CONFIG_LTO_CLANG is enabled, because .data.once matches the .data.[0-9a-zA-Z_]* pattern in the DATA_MAIN macro. Commitcb87481ee8("kbuild: linker script do not match C names unless LD_DEAD_CODE_DATA_ELIMINATION is configured") was introduced to suppress the issue for the default CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=n case, providing a minimal fix for stable backporting. We were aware this did not address the issue for CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y. The plan was to apply correct fixes and then revertcb87481ee8. [1] Seven years have passed since then, yet the #ifdef workaround remains in place. Meanwhile, commitb1fca27d38introduced the .data.once section, and commitdc5723b02e("kbuild: add support for Clang LTO") extended the #ifdef. Using a ".." separator in the section name fixes the issue for CONFIG_LD_DEAD_CODE_DATA_ELIMINATION and CONFIG_LTO_CLANG. [1]: https://lore.kernel.org/linux-kbuild/CAK7LNASck6BfdLnESxXUeECYL26yUDm0cwRZuM4gmaWUkxjL5g@mail.gmail.com/ Fixes:b1fca27d38("kernel debug: support resetting WARN*_ONCE") Fixes:dc5723b02e("kbuild: add support for Clang LTO") Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
		
			
				
	
	
		
			36 lines
		
	
	
	
		
			926 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
	
		
			926 B
		
	
	
	
		
			C
		
	
	
	
	
	
| /* SPDX-License-Identifier: GPL-2.0 */
 | |
| #ifndef _LINUX_ONCE_LITE_H
 | |
| #define _LINUX_ONCE_LITE_H
 | |
| 
 | |
| #include <linux/types.h>
 | |
| 
 | |
| /* Call a function once. Similar to DO_ONCE(), but does not use jump label
 | |
|  * patching via static keys.
 | |
|  */
 | |
| #define DO_ONCE_LITE(func, ...)						\
 | |
| 	DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__)
 | |
| 
 | |
| #define __ONCE_LITE_IF(condition)					\
 | |
| 	({								\
 | |
| 		static bool __section(".data..once") __already_done;	\
 | |
| 		bool __ret_cond = !!(condition);			\
 | |
| 		bool __ret_once = false;				\
 | |
| 									\
 | |
| 		if (unlikely(__ret_cond && !__already_done)) {		\
 | |
| 			__already_done = true;				\
 | |
| 			__ret_once = true;				\
 | |
| 		}							\
 | |
| 		unlikely(__ret_once);					\
 | |
| 	})
 | |
| 
 | |
| #define DO_ONCE_LITE_IF(condition, func, ...)				\
 | |
| 	({								\
 | |
| 		bool __ret_do_once = !!(condition);			\
 | |
| 									\
 | |
| 		if (__ONCE_LITE_IF(__ret_do_once))			\
 | |
| 			func(__VA_ARGS__);				\
 | |
| 									\
 | |
| 		unlikely(__ret_do_once);				\
 | |
| 	})
 | |
| 
 | |
| #endif /* _LINUX_ONCE_LITE_H */
 |