@@ -355,41 +355,6 @@ enum log_flags {
355
355
LOG_CONT = 8 , /* text is a fragment of a continuation line */
356
356
};
357
357
358
- /*
359
- * The logbuf_lock protects kmsg buffer, indices, counters. This can be taken
360
- * within the scheduler's rq lock. It must be released before calling
361
- * console_unlock() or anything else that might wake up a process.
362
- */
363
- DEFINE_RAW_SPINLOCK (logbuf_lock );
364
-
365
- /*
366
- * Helper macros to lock/unlock logbuf_lock and switch between
367
- * printk-safe/unsafe modes.
368
- */
369
- #define logbuf_lock_irq () \
370
- do { \
371
- printk_safe_enter_irq(); \
372
- raw_spin_lock(&logbuf_lock); \
373
- } while (0)
374
-
375
- #define logbuf_unlock_irq () \
376
- do { \
377
- raw_spin_unlock(&logbuf_lock); \
378
- printk_safe_exit_irq(); \
379
- } while (0)
380
-
381
- #define logbuf_lock_irqsave (flags ) \
382
- do { \
383
- printk_safe_enter_irqsave(flags); \
384
- raw_spin_lock(&logbuf_lock); \
385
- } while (0)
386
-
387
- #define logbuf_unlock_irqrestore (flags ) \
388
- do { \
389
- raw_spin_unlock(&logbuf_lock); \
390
- printk_safe_exit_irqrestore(flags); \
391
- } while (0)
392
-
393
358
/* syslog_lock protects syslog_* variables and write access to clear_seq. */
394
359
static DEFINE_RAW_SPINLOCK (syslog_lock );
395
360
@@ -401,6 +366,7 @@ static u64 syslog_seq;
401
366
static size_t syslog_partial ;
402
367
static bool syslog_time ;
403
368
369
+ /* All 3 protected by @console_sem. */
404
370
/* the next printk record to write to the console */
405
371
static u64 console_seq ;
406
372
static u64 exclusive_console_stop_seq ;
@@ -766,27 +732,27 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
766
732
if (ret )
767
733
return ret ;
768
734
769
- logbuf_lock_irq ();
735
+ printk_safe_enter_irq ();
770
736
if (!prb_read_valid (prb , atomic64_read (& user -> seq ), r )) {
771
737
if (file -> f_flags & O_NONBLOCK ) {
772
738
ret = - EAGAIN ;
773
- logbuf_unlock_irq ();
739
+ printk_safe_exit_irq ();
774
740
goto out ;
775
741
}
776
742
777
- logbuf_unlock_irq ();
743
+ printk_safe_exit_irq ();
778
744
ret = wait_event_interruptible (log_wait ,
779
745
prb_read_valid (prb , atomic64_read (& user -> seq ), r ));
780
746
if (ret )
781
747
goto out ;
782
- logbuf_lock_irq ();
748
+ printk_safe_enter_irq ();
783
749
}
784
750
785
751
if (r -> info -> seq != atomic64_read (& user -> seq )) {
786
752
/* our last seen message is gone, return error and reset */
787
753
atomic64_set (& user -> seq , r -> info -> seq );
788
754
ret = - EPIPE ;
789
- logbuf_unlock_irq ();
755
+ printk_safe_exit_irq ();
790
756
goto out ;
791
757
}
792
758
@@ -796,7 +762,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
796
762
& r -> info -> dev_info );
797
763
798
764
atomic64_set (& user -> seq , r -> info -> seq + 1 );
799
- logbuf_unlock_irq ();
765
+ printk_safe_exit_irq ();
800
766
801
767
if (len > count ) {
802
768
ret = - EINVAL ;
@@ -831,7 +797,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
831
797
if (offset )
832
798
return - ESPIPE ;
833
799
834
- logbuf_lock_irq ();
800
+ printk_safe_enter_irq ();
835
801
switch (whence ) {
836
802
case SEEK_SET :
837
803
/* the first record */
@@ -852,7 +818,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
852
818
default :
853
819
ret = - EINVAL ;
854
820
}
855
- logbuf_unlock_irq ();
821
+ printk_safe_exit_irq ();
856
822
return ret ;
857
823
}
858
824
@@ -867,15 +833,15 @@ static __poll_t devkmsg_poll(struct file *file, poll_table *wait)
867
833
868
834
poll_wait (file , & log_wait , wait );
869
835
870
- logbuf_lock_irq ();
836
+ printk_safe_enter_irq ();
871
837
if (prb_read_valid_info (prb , atomic64_read (& user -> seq ), & info , NULL )) {
872
838
/* return error when data has vanished underneath us */
873
839
if (info .seq != atomic64_read (& user -> seq ))
874
840
ret = EPOLLIN |EPOLLRDNORM |EPOLLERR |EPOLLPRI ;
875
841
else
876
842
ret = EPOLLIN |EPOLLRDNORM ;
877
843
}
878
- logbuf_unlock_irq ();
844
+ printk_safe_exit_irq ();
879
845
880
846
return ret ;
881
847
}
@@ -908,9 +874,9 @@ static int devkmsg_open(struct inode *inode, struct file *file)
908
874
prb_rec_init_rd (& user -> record , & user -> info ,
909
875
& user -> text_buf [0 ], sizeof (user -> text_buf ));
910
876
911
- logbuf_lock_irq ();
877
+ printk_safe_enter_irq ();
912
878
atomic64_set (& user -> seq , prb_first_valid_seq (prb ));
913
- logbuf_unlock_irq ();
879
+ printk_safe_exit_irq ();
914
880
915
881
file -> private_data = user ;
916
882
return 0 ;
@@ -1532,11 +1498,11 @@ static int syslog_print(char __user *buf, int size)
1532
1498
size_t n ;
1533
1499
size_t skip ;
1534
1500
1535
- logbuf_lock_irq ();
1501
+ printk_safe_enter_irq ();
1536
1502
raw_spin_lock (& syslog_lock );
1537
1503
if (!prb_read_valid (prb , syslog_seq , & r )) {
1538
1504
raw_spin_unlock (& syslog_lock );
1539
- logbuf_unlock_irq ();
1505
+ printk_safe_exit_irq ();
1540
1506
break ;
1541
1507
}
1542
1508
if (r .info -> seq != syslog_seq ) {
@@ -1566,7 +1532,7 @@ static int syslog_print(char __user *buf, int size)
1566
1532
} else
1567
1533
n = 0 ;
1568
1534
raw_spin_unlock (& syslog_lock );
1569
- logbuf_unlock_irq ();
1535
+ printk_safe_exit_irq ();
1570
1536
1571
1537
if (!n )
1572
1538
break ;
@@ -1600,7 +1566,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
1600
1566
return - ENOMEM ;
1601
1567
1602
1568
time = printk_time ;
1603
- logbuf_lock_irq ();
1569
+ printk_safe_enter_irq ();
1604
1570
/*
1605
1571
* Find first record that fits, including all following records,
1606
1572
* into the user-provided buffer for this dump.
@@ -1621,12 +1587,12 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
1621
1587
break ;
1622
1588
}
1623
1589
1624
- logbuf_unlock_irq ();
1590
+ printk_safe_exit_irq ();
1625
1591
if (copy_to_user (buf + len , text , textlen ))
1626
1592
len = - EFAULT ;
1627
1593
else
1628
1594
len += textlen ;
1629
- logbuf_lock_irq ();
1595
+ printk_safe_enter_irq ();
1630
1596
1631
1597
if (len < 0 )
1632
1598
break ;
@@ -1637,19 +1603,19 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
1637
1603
latched_seq_write (& clear_seq , seq );
1638
1604
raw_spin_unlock (& syslog_lock );
1639
1605
}
1640
- logbuf_unlock_irq ();
1606
+ printk_safe_exit_irq ();
1641
1607
1642
1608
kfree (text );
1643
1609
return len ;
1644
1610
}
1645
1611
1646
1612
static void syslog_clear (void )
1647
1613
{
1648
- logbuf_lock_irq ();
1614
+ printk_safe_enter_irq ();
1649
1615
raw_spin_lock (& syslog_lock );
1650
1616
latched_seq_write (& clear_seq , prb_next_seq (prb ));
1651
1617
raw_spin_unlock (& syslog_lock );
1652
- logbuf_unlock_irq ();
1618
+ printk_safe_exit_irq ();
1653
1619
}
1654
1620
1655
1621
/* Return a consistent copy of @syslog_seq. */
@@ -1737,12 +1703,12 @@ int do_syslog(int type, char __user *buf, int len, int source)
1737
1703
break ;
1738
1704
/* Number of chars in the log buffer */
1739
1705
case SYSLOG_ACTION_SIZE_UNREAD :
1740
- logbuf_lock_irq ();
1706
+ printk_safe_enter_irq ();
1741
1707
raw_spin_lock (& syslog_lock );
1742
1708
if (!prb_read_valid_info (prb , syslog_seq , & info , NULL )) {
1743
1709
/* No unread messages. */
1744
1710
raw_spin_unlock (& syslog_lock );
1745
- logbuf_unlock_irq ();
1711
+ printk_safe_exit_irq ();
1746
1712
return 0 ;
1747
1713
}
1748
1714
if (info .seq != syslog_seq ) {
@@ -1771,7 +1737,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
1771
1737
error -= syslog_partial ;
1772
1738
}
1773
1739
raw_spin_unlock (& syslog_lock );
1774
- logbuf_unlock_irq ();
1740
+ printk_safe_exit_irq ();
1775
1741
break ;
1776
1742
/* Size of the log buffer */
1777
1743
case SYSLOG_ACTION_SIZE_BUFFER :
@@ -2627,7 +2593,6 @@ void console_unlock(void)
2627
2593
size_t len ;
2628
2594
2629
2595
printk_safe_enter_irqsave (flags );
2630
- raw_spin_lock (& logbuf_lock );
2631
2596
skip :
2632
2597
if (!prb_read_valid (prb , console_seq , & r ))
2633
2598
break ;
@@ -2671,7 +2636,6 @@ void console_unlock(void)
2671
2636
console_msg_format & MSG_FORMAT_SYSLOG ,
2672
2637
printk_time );
2673
2638
console_seq ++ ;
2674
- raw_spin_unlock (& logbuf_lock );
2675
2639
2676
2640
/*
2677
2641
* While actively printing out messages, if another printk()
@@ -2698,8 +2662,6 @@ void console_unlock(void)
2698
2662
2699
2663
console_locked = 0 ;
2700
2664
2701
- raw_spin_unlock (& logbuf_lock );
2702
-
2703
2665
up_console_sem ();
2704
2666
2705
2667
/*
@@ -2708,9 +2670,7 @@ void console_unlock(void)
2708
2670
* there's a new owner and the console_unlock() from them will do the
2709
2671
* flush, no worries.
2710
2672
*/
2711
- raw_spin_lock (& logbuf_lock );
2712
2673
retry = prb_read_valid (prb , console_seq , NULL );
2713
- raw_spin_unlock (& logbuf_lock );
2714
2674
printk_safe_exit_irqrestore (flags );
2715
2675
2716
2676
if (retry && console_trylock ())
@@ -2777,9 +2737,9 @@ void console_flush_on_panic(enum con_flush_mode mode)
2777
2737
if (mode == CONSOLE_REPLAY_ALL ) {
2778
2738
unsigned long flags ;
2779
2739
2780
- logbuf_lock_irqsave (flags );
2740
+ printk_safe_enter_irqsave (flags );
2781
2741
console_seq = prb_first_valid_seq (prb );
2782
- logbuf_unlock_irqrestore (flags );
2742
+ printk_safe_exit_irqrestore (flags );
2783
2743
}
2784
2744
console_unlock ();
2785
2745
}
@@ -3008,7 +2968,7 @@ void register_console(struct console *newcon)
3008
2968
* console_unlock(); will print out the buffered messages
3009
2969
* for us.
3010
2970
*/
3011
- logbuf_lock_irqsave (flags );
2971
+ printk_safe_enter_irqsave (flags );
3012
2972
/*
3013
2973
* We're about to replay the log buffer. Only do this to the
3014
2974
* just-registered console to avoid excessive message spam to
@@ -3026,7 +2986,7 @@ void register_console(struct console *newcon)
3026
2986
console_seq = syslog_seq ;
3027
2987
raw_spin_unlock (& syslog_lock );
3028
2988
3029
- logbuf_unlock_irqrestore (flags );
2989
+ printk_safe_exit_irqrestore (flags );
3030
2990
}
3031
2991
console_unlock ();
3032
2992
console_sysfs_notify ();
@@ -3492,9 +3452,9 @@ bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
3492
3452
unsigned long flags ;
3493
3453
bool ret ;
3494
3454
3495
- logbuf_lock_irqsave (flags );
3455
+ printk_safe_enter_irqsave (flags );
3496
3456
ret = kmsg_dump_get_line_nolock (iter , syslog , line , size , len );
3497
- logbuf_unlock_irqrestore (flags );
3457
+ printk_safe_exit_irqrestore (flags );
3498
3458
3499
3459
return ret ;
3500
3460
}
@@ -3538,7 +3498,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
3538
3498
if (iter -> cur_seq < min_seq )
3539
3499
iter -> cur_seq = min_seq ;
3540
3500
3541
- logbuf_lock_irqsave (flags );
3501
+ printk_safe_enter_irqsave (flags );
3542
3502
if (prb_read_valid_info (prb , iter -> cur_seq , & info , NULL )) {
3543
3503
if (info .seq != iter -> cur_seq ) {
3544
3504
/* messages are gone, move to first available one */
@@ -3548,7 +3508,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
3548
3508
3549
3509
/* last entry */
3550
3510
if (iter -> cur_seq >= iter -> next_seq ) {
3551
- logbuf_unlock_irqrestore (flags );
3511
+ printk_safe_exit_irqrestore (flags );
3552
3512
goto out ;
3553
3513
}
3554
3514
@@ -3582,7 +3542,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
3582
3542
3583
3543
iter -> next_seq = next_seq ;
3584
3544
ret = true;
3585
- logbuf_unlock_irqrestore (flags );
3545
+ printk_safe_exit_irqrestore (flags );
3586
3546
out :
3587
3547
if (len_out )
3588
3548
* len_out = len ;
@@ -3618,9 +3578,9 @@ void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
3618
3578
{
3619
3579
unsigned long flags ;
3620
3580
3621
- logbuf_lock_irqsave (flags );
3581
+ printk_safe_enter_irqsave (flags );
3622
3582
kmsg_dump_rewind_nolock (iter );
3623
- logbuf_unlock_irqrestore (flags );
3583
+ printk_safe_exit_irqrestore (flags );
3624
3584
}
3625
3585
EXPORT_SYMBOL_GPL (kmsg_dump_rewind );
3626
3586
0 commit comments