File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -141,6 +141,34 @@ struct kpatch_post_unpatch_callback {
141141 printk(_fmt, ## __VA_ARGS__); \
142142})
143143
144+
145+ /*
146+ * KPATCH_PRINTK_DEFERRED macro
147+ *
148+ * Use this instead of calling printk_deferred to avoid unwanted compiler optimizations
149+ * which cause kpatch-build errors.
150+ *
151+ * The printk function is annotated with the __cold attribute, which tells gcc
152+ * that the function is unlikely to be called. A side effect of this is that
153+ * code paths containing calls to printk might also be marked cold, leading to
154+ * other functions called in those code paths getting moved into .text.unlikely
155+ * or being uninlined.
156+ *
157+ * And yet, printk may cause dead lock in the context in kernel because when printing
158+ * warning in console, it will call schedule_work which will take the rq_lock.
159+ * If queue_work put this task into current queue, it will cause dead lock when
160+ * try_to_weak_up try to take the rq_lock either. However, printk_deferred will
161+ * call irq_work_queue which can avoid this situation.
162+ *
163+ * This macro places printk_deferred in its own code path so as not to make the
164+ * surrounding code path cold.
165+ */
166+ #define KPATCH_PRINTK_DEFERRED (_fmt , ...) \
167+ ({ \
168+ if (jiffies) \
169+ printk_deferred(_fmt, ## __VA_ARGS__); \
170+ })
171+
144172/*
145173 * KPATCH_STATIC_CALL macro
146174 *
You can’t perform that action at this time.
0 commit comments