1
0
mirror of https://github.com/dynup/kpatch synced 2025-03-25 04:16:39 +00:00

macros: add KPATCH_PRINTK macro

Use this instead of calling printk to avoid unwanted compiler
optimizations which cause kpatch-build errors.

The printk function is annotated with the __cold attribute, which tells
gcc that the function is unlikely to be called.  A side effect of this
is that code paths containing calls to printk might also be marked cold,
leading to other functions called in those code paths getting moved into
.text.unlikely or being uninlined.

This macro places printk in its own code path so as not to make the
surrounding code path cold.

I have a related integration test to add, but right now it's broken
because we don't yet properly support the __verbose special section.
That'll be another PR.

Fixes .
This commit is contained in:
Josh Poimboeuf 2014-07-31 13:54:51 -05:00
parent 4e0ec591e3
commit a8a037271d

View File

@ -2,6 +2,7 @@
#define __KPATCH_MACROS_H_
#include <linux/compiler.h>
#include <linux/jiffies.h>
typedef void (*kpatch_loadcall_t)(void);
typedef void (*kpatch_unloadcall_t)(void);
@ -93,4 +94,25 @@ struct kpatch_unload {
#define KPATCH_FORCE_UNSAFE(_fn) \
void *__kpatch_force_func_##_fn __section(.kpatch.force) = _fn;
/*
* KPATCH_PRINTK macro
*
* Use this instead of calling printk to avoid unwanted compiler optimizations
* which cause kpatch-build errors.
*
* The printk function is annotated with the __cold attribute, which tells gcc
* that the function is unlikely to be called. A side effect of this is that
* code paths containing calls to printk might also be marked cold, leading to
* other functions called in those code paths getting moved into .text.unlikely
* or being uninlined.
*
* This macro places printk in its own code path so as not to make the
* surrounding code path cold.
*/
#define KPATCH_PRINTK(_fmt, ...) \
({ \
if (jiffies) \
printk(_fmt, ## __VA_ARGS__); \
})
#endif /* __KPATCH_MACROS_H_ */