@@ -612,6 +612,109 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec)
612
612
return widen_string (buf , len , end , spec );
613
613
}
614
614
615
+ static noinline_for_stack
616
+ char * pointer_string (char * buf , char * end , const void * ptr ,
617
+ struct printf_spec spec )
618
+ {
619
+ spec .base = 16 ;
620
+ spec .flags |= SMALL ;
621
+ if (spec .field_width == -1 ) {
622
+ spec .field_width = 2 * sizeof (ptr );
623
+ spec .flags |= ZEROPAD ;
624
+ }
625
+
626
+ return number (buf , end , (unsigned long int )ptr , spec );
627
+ }
628
+
629
+ /* Make pointers available for printing early in the boot sequence. */
630
+ static int debug_boot_weak_hash __ro_after_init ;
631
+
632
+ static int __init debug_boot_weak_hash_enable (char * str )
633
+ {
634
+ debug_boot_weak_hash = 1 ;
635
+ pr_info ("debug_boot_weak_hash enabled\n" );
636
+ return 0 ;
637
+ }
638
+ early_param ("debug_boot_weak_hash" , debug_boot_weak_hash_enable );
639
+
640
+ static DEFINE_STATIC_KEY_TRUE (not_filled_random_ptr_key );
641
+ static siphash_key_t ptr_key __read_mostly ;
642
+
643
+ static void enable_ptr_key_workfn (struct work_struct * work )
644
+ {
645
+ get_random_bytes (& ptr_key , sizeof (ptr_key ));
646
+ /* Needs to run from preemptible context */
647
+ static_branch_disable (& not_filled_random_ptr_key );
648
+ }
649
+
650
+ static DECLARE_WORK (enable_ptr_key_work , enable_ptr_key_workfn ) ;
651
+
652
+ static void fill_random_ptr_key (struct random_ready_callback * unused )
653
+ {
654
+ /* This may be in an interrupt handler. */
655
+ queue_work (system_unbound_wq , & enable_ptr_key_work );
656
+ }
657
+
658
+ static struct random_ready_callback random_ready = {
659
+ .func = fill_random_ptr_key
660
+ };
661
+
662
+ static int __init initialize_ptr_random (void )
663
+ {
664
+ int key_size = sizeof (ptr_key );
665
+ int ret ;
666
+
667
+ /* Use hw RNG if available. */
668
+ if (get_random_bytes_arch (& ptr_key , key_size ) == key_size ) {
669
+ static_branch_disable (& not_filled_random_ptr_key );
670
+ return 0 ;
671
+ }
672
+
673
+ ret = add_random_ready_callback (& random_ready );
674
+ if (!ret ) {
675
+ return 0 ;
676
+ } else if (ret == - EALREADY ) {
677
+ /* This is in preemptible context */
678
+ enable_ptr_key_workfn (& enable_ptr_key_work );
679
+ return 0 ;
680
+ }
681
+
682
+ return ret ;
683
+ }
684
+ early_initcall (initialize_ptr_random );
685
+
686
+ /* Maps a pointer to a 32 bit unique identifier. */
687
+ static char * ptr_to_id (char * buf , char * end , const void * ptr ,
688
+ struct printf_spec spec )
689
+ {
690
+ const char * str = sizeof (ptr ) == 8 ? "(____ptrval____)" : "(ptrval)" ;
691
+ unsigned long hashval ;
692
+
693
+ /* When debugging early boot use non-cryptographically secure hash. */
694
+ if (unlikely (debug_boot_weak_hash )) {
695
+ hashval = hash_long ((unsigned long )ptr , 32 );
696
+ return pointer_string (buf , end , (const void * )hashval , spec );
697
+ }
698
+
699
+ if (static_branch_unlikely (& not_filled_random_ptr_key )) {
700
+ spec .field_width = 2 * sizeof (ptr );
701
+ /* string length must be less than default_width */
702
+ return string (buf , end , str , spec );
703
+ }
704
+
705
+ #ifdef CONFIG_64BIT
706
+ hashval = (unsigned long )siphash_1u64 ((u64 )ptr , & ptr_key );
707
+ /*
708
+ * Mask off the first 32 bits, this makes explicit that we have
709
+ * modified the address (and 32 bits is plenty for a unique ID).
710
+ */
711
+ hashval = hashval & 0xffffffff ;
712
+ #else
713
+ hashval = (unsigned long )siphash_1u32 ((u32 )ptr , & ptr_key );
714
+ #endif
715
+ return pointer_string (buf , end , (const void * )hashval , spec );
716
+ }
717
+
615
718
static noinline_for_stack
616
719
char * dentry_name (char * buf , char * end , const struct dentry * d , struct printf_spec spec ,
617
720
const char * fmt )
@@ -1357,20 +1460,6 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
1357
1460
return string (buf , end , uuid , spec );
1358
1461
}
1359
1462
1360
- static noinline_for_stack
1361
- char * pointer_string (char * buf , char * end , const void * ptr ,
1362
- struct printf_spec spec )
1363
- {
1364
- spec .base = 16 ;
1365
- spec .flags |= SMALL ;
1366
- if (spec .field_width == -1 ) {
1367
- spec .field_width = 2 * sizeof (ptr );
1368
- spec .flags |= ZEROPAD ;
1369
- }
1370
-
1371
- return number (buf , end , (unsigned long int )ptr , spec );
1372
- }
1373
-
1374
1463
int kptr_restrict __read_mostly ;
1375
1464
1376
1465
static noinline_for_stack
@@ -1421,7 +1510,8 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,
1421
1510
}
1422
1511
1423
1512
static noinline_for_stack
1424
- char * netdev_bits (char * buf , char * end , const void * addr , const char * fmt )
1513
+ char * netdev_bits (char * buf , char * end , const void * addr ,
1514
+ struct printf_spec spec , const char * fmt )
1425
1515
{
1426
1516
unsigned long long num ;
1427
1517
int size ;
@@ -1432,9 +1522,7 @@ char *netdev_bits(char *buf, char *end, const void *addr, const char *fmt)
1432
1522
size = sizeof (netdev_features_t );
1433
1523
break ;
1434
1524
default :
1435
- num = (unsigned long )addr ;
1436
- size = sizeof (unsigned long );
1437
- break ;
1525
+ return ptr_to_id (buf , end , addr , spec );
1438
1526
}
1439
1527
1440
1528
return special_hex_number (buf , end , num , size );
@@ -1474,7 +1562,7 @@ char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
1474
1562
#ifdef CONFIG_COMMON_CLK
1475
1563
return string (buf , end , __clk_get_name (clk ), spec );
1476
1564
#else
1477
- return special_hex_number (buf , end , ( unsigned long ) clk , sizeof ( unsigned long ) );
1565
+ return ptr_to_id (buf , end , clk , spec );
1478
1566
#endif
1479
1567
}
1480
1568
}
@@ -1651,94 +1739,6 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
1651
1739
return widen_string (buf , buf - buf_start , end , spec );
1652
1740
}
1653
1741
1654
- /* Make pointers available for printing early in the boot sequence. */
1655
- static int debug_boot_weak_hash __ro_after_init ;
1656
-
1657
- static int __init debug_boot_weak_hash_enable (char * str )
1658
- {
1659
- debug_boot_weak_hash = 1 ;
1660
- pr_info ("debug_boot_weak_hash enabled\n" );
1661
- return 0 ;
1662
- }
1663
- early_param ("debug_boot_weak_hash" , debug_boot_weak_hash_enable );
1664
-
1665
- static DEFINE_STATIC_KEY_TRUE (not_filled_random_ptr_key );
1666
- static siphash_key_t ptr_key __read_mostly ;
1667
-
1668
- static void enable_ptr_key_workfn (struct work_struct * work )
1669
- {
1670
- get_random_bytes (& ptr_key , sizeof (ptr_key ));
1671
- /* Needs to run from preemptible context */
1672
- static_branch_disable (& not_filled_random_ptr_key );
1673
- }
1674
-
1675
- static DECLARE_WORK (enable_ptr_key_work , enable_ptr_key_workfn ) ;
1676
-
1677
- static void fill_random_ptr_key (struct random_ready_callback * unused )
1678
- {
1679
- /* This may be in an interrupt handler. */
1680
- queue_work (system_unbound_wq , & enable_ptr_key_work );
1681
- }
1682
-
1683
- static struct random_ready_callback random_ready = {
1684
- .func = fill_random_ptr_key
1685
- };
1686
-
1687
- static int __init initialize_ptr_random (void )
1688
- {
1689
- int key_size = sizeof (ptr_key );
1690
- int ret ;
1691
-
1692
- /* Use hw RNG if available. */
1693
- if (get_random_bytes_arch (& ptr_key , key_size ) == key_size ) {
1694
- static_branch_disable (& not_filled_random_ptr_key );
1695
- return 0 ;
1696
- }
1697
-
1698
- ret = add_random_ready_callback (& random_ready );
1699
- if (!ret ) {
1700
- return 0 ;
1701
- } else if (ret == - EALREADY ) {
1702
- /* This is in preemptible context */
1703
- enable_ptr_key_workfn (& enable_ptr_key_work );
1704
- return 0 ;
1705
- }
1706
-
1707
- return ret ;
1708
- }
1709
- early_initcall (initialize_ptr_random );
1710
-
1711
- /* Maps a pointer to a 32 bit unique identifier. */
1712
- static char * ptr_to_id (char * buf , char * end , void * ptr , struct printf_spec spec )
1713
- {
1714
- const char * str = sizeof (ptr ) == 8 ? "(____ptrval____)" : "(ptrval)" ;
1715
- unsigned long hashval ;
1716
-
1717
- /* When debugging early boot use non-cryptographically secure hash. */
1718
- if (unlikely (debug_boot_weak_hash )) {
1719
- hashval = hash_long ((unsigned long )ptr , 32 );
1720
- return pointer_string (buf , end , (const void * )hashval , spec );
1721
- }
1722
-
1723
- if (static_branch_unlikely (& not_filled_random_ptr_key )) {
1724
- spec .field_width = 2 * sizeof (ptr );
1725
- /* string length must be less than default_width */
1726
- return string (buf , end , str , spec );
1727
- }
1728
-
1729
- #ifdef CONFIG_64BIT
1730
- hashval = (unsigned long )siphash_1u64 ((u64 )ptr , & ptr_key );
1731
- /*
1732
- * Mask off the first 32 bits, this makes explicit that we have
1733
- * modified the address (and 32 bits is plenty for a unique ID).
1734
- */
1735
- hashval = hashval & 0xffffffff ;
1736
- #else
1737
- hashval = (unsigned long )siphash_1u32 ((u32 )ptr , & ptr_key );
1738
- #endif
1739
- return pointer_string (buf , end , (const void * )hashval , spec );
1740
- }
1741
-
1742
1742
/*
1743
1743
* Show a '%p' thing. A kernel extension is that the '%p' is followed
1744
1744
* by an extra set of alphanumeric characters that are extended format
@@ -1944,7 +1944,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1944
1944
break ;
1945
1945
return restricted_pointer (buf , end , ptr , spec );
1946
1946
case 'N' :
1947
- return netdev_bits (buf , end , ptr , fmt );
1947
+ return netdev_bits (buf , end , ptr , spec , fmt );
1948
1948
case 'a' :
1949
1949
return address_val (buf , end , ptr , fmt );
1950
1950
case 'd' :
0 commit comments