@@ -170,6 +170,11 @@ extern void __printk_safe_exit(void);
170170#define printk_deferred_enter __printk_safe_enter
171171#define printk_deferred_exit __printk_safe_exit
172172
173+ extern void printk_prefer_direct_enter (void );
174+ extern void printk_prefer_direct_exit (void );
175+
176+ extern bool pr_flush (int timeout_ms , bool reset_on_progress );
177+
173178/*
174179 * Please don't use printk_ratelimit(), because it shares ratelimiting state
175180 * with all other unrelated printk_ratelimit() callsites. Instead use
@@ -220,6 +225,19 @@ static inline void printk_deferred_exit(void)
220225{
221226}
222227
228+ static inline void printk_prefer_direct_enter (void )
229+ {
230+ }
231+
232+ static inline void printk_prefer_direct_exit (void )
233+ {
234+ }
235+
236+ static inline bool pr_flush (int timeout_ms , bool reset_on_progress )
237+ {
238+ return true;
239+ }
240+
223241static inline int printk_ratelimit (void )
224242{
225243 return 0 ;
@@ -277,45 +295,57 @@ static inline void printk_trigger_flush(void)
277295#endif
278296
279297#ifdef CONFIG_SMP
280- extern int __printk_cpu_trylock (void );
281- extern void __printk_wait_on_cpu_lock (void );
282- extern void __printk_cpu_unlock (void );
298+ extern int __printk_cpu_sync_try_get (void );
299+ extern void __printk_cpu_sync_wait (void );
300+ extern void __printk_cpu_sync_put (void );
301+
302+ #else
303+
304+ #define __printk_cpu_sync_try_get () true
305+ #define __printk_cpu_sync_wait ()
306+ #define __printk_cpu_sync_put ()
307+ #endif /* CONFIG_SMP */
283308
284309/**
285- * printk_cpu_lock_irqsave () - Acquire the printk cpu-reentrant spinning
286- * lock and disable interrupts .
310+ * printk_cpu_sync_get_irqsave () - Disable interrupts and acquire the printk
311+ * cpu-reentrant spinning lock .
287312 * @flags: Stack-allocated storage for saving local interrupt state,
288- * to be passed to printk_cpu_unlock_irqrestore ().
313+ * to be passed to printk_cpu_sync_put_irqrestore ().
289314 *
290315 * If the lock is owned by another CPU, spin until it becomes available.
291316 * Interrupts are restored while spinning.
317+ *
318+ * CAUTION: This function must be used carefully. It does not behave like a
319+ * typical lock. Here are important things to watch out for...
320+ *
321+ * * This function is reentrant on the same CPU. Therefore the calling
322+ * code must not assume exclusive access to data if code accessing the
323+ * data can run reentrant or within NMI context on the same CPU.
324+ *
325+ * * If there exists usage of this function from NMI context, it becomes
326+ * unsafe to perform any type of locking or spinning to wait for other
327+ * CPUs after calling this function from any context. This includes
328+ * using spinlocks or any other busy-waiting synchronization methods.
292329 */
293- #define printk_cpu_lock_irqsave (flags ) \
294- for (;;) { \
295- local_irq_save(flags); \
296- if (__printk_cpu_trylock ()) \
297- break; \
298- local_irq_restore(flags); \
299- __printk_wait_on_cpu_lock (); \
330+ #define printk_cpu_sync_get_irqsave (flags ) \
331+ for (;;) { \
332+ local_irq_save(flags); \
333+ if (__printk_cpu_sync_try_get ()) \
334+ break; \
335+ local_irq_restore(flags); \
336+ __printk_cpu_sync_wait (); \
300337 }
301338
302339/**
303- * printk_cpu_unlock_irqrestore () - Release the printk cpu-reentrant spinning
304- * lock and restore interrupts.
305- * @flags: Caller's saved interrupt state, from printk_cpu_lock_irqsave ().
340+ * printk_cpu_sync_put_irqrestore () - Release the printk cpu-reentrant spinning
341+ * lock and restore interrupts.
342+ * @flags: Caller's saved interrupt state, from printk_cpu_sync_get_irqsave ().
306343 */
307- #define printk_cpu_unlock_irqrestore (flags ) \
344+ #define printk_cpu_sync_put_irqrestore (flags ) \
308345 do { \
309- __printk_cpu_unlock (); \
346+ __printk_cpu_sync_put (); \
310347 local_irq_restore(flags); \
311- } while (0) \
312-
313- #else
314-
315- #define printk_cpu_lock_irqsave (flags ) ((void)flags)
316- #define printk_cpu_unlock_irqrestore (flags ) ((void)flags)
317-
318- #endif /* CONFIG_SMP */
348+ } while (0)
319349
320350extern int kptr_restrict ;
321351
0 commit comments