@@ -172,6 +172,8 @@ struct kmemleak_object {
172
172
#define OBJECT_NO_SCAN (1 << 2)
173
173
/* flag set to fully scan the object when scan_area allocation failed */
174
174
#define OBJECT_FULL_SCAN (1 << 3)
175
+ /* flag set for object allocated with physical address */
176
+ #define OBJECT_PHYS (1 << 4)
175
177
176
178
#define HEX_PREFIX " "
177
179
/* number of bytes to print per line; must be 16 or 32 */
@@ -574,8 +576,9 @@ static int __save_stack_trace(unsigned long *trace)
574
576
* Create the metadata (struct kmemleak_object) corresponding to an allocated
575
577
* memory block and add it to the object_list and object_tree_root.
576
578
*/
577
- static struct kmemleak_object * create_object (unsigned long ptr , size_t size ,
578
- int min_count , gfp_t gfp )
579
+ static struct kmemleak_object * __create_object (unsigned long ptr , size_t size ,
580
+ int min_count , gfp_t gfp ,
581
+ bool is_phys )
579
582
{
580
583
unsigned long flags ;
581
584
struct kmemleak_object * object , * parent ;
@@ -595,7 +598,7 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size,
595
598
INIT_HLIST_HEAD (& object -> area_list );
596
599
raw_spin_lock_init (& object -> lock );
597
600
atomic_set (& object -> use_count , 1 );
598
- object -> flags = OBJECT_ALLOCATED ;
601
+ object -> flags = OBJECT_ALLOCATED | ( is_phys ? OBJECT_PHYS : 0 ) ;
599
602
object -> pointer = ptr ;
600
603
object -> size = kfence_ksize ((void * )ptr ) ?: size ;
601
604
object -> excess_ref = 0 ;
@@ -662,6 +665,20 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size,
662
665
return object ;
663
666
}
664
667
668
+ /* Create kmemleak object which allocated with virtual address. */
669
+ static struct kmemleak_object * create_object (unsigned long ptr , size_t size ,
670
+ int min_count , gfp_t gfp )
671
+ {
672
+ return __create_object (ptr , size , min_count , gfp , false);
673
+ }
674
+
675
+ /* Create kmemleak object which allocated with physical address. */
676
+ static struct kmemleak_object * create_object_phys (unsigned long ptr , size_t size ,
677
+ int min_count , gfp_t gfp )
678
+ {
679
+ return __create_object (ptr , size , min_count , gfp , true);
680
+ }
681
+
665
682
/*
666
683
* Mark the object as not allocated and schedule RCU freeing via put_object().
667
684
*/
@@ -728,11 +745,11 @@ static void delete_object_part(unsigned long ptr, size_t size)
728
745
start = object -> pointer ;
729
746
end = object -> pointer + object -> size ;
730
747
if (ptr > start )
731
- create_object (start , ptr - start , object -> min_count ,
732
- GFP_KERNEL );
748
+ __create_object (start , ptr - start , object -> min_count ,
749
+ GFP_KERNEL , object -> flags & OBJECT_PHYS );
733
750
if (ptr + size < end )
734
- create_object (ptr + size , end - ptr - size , object -> min_count ,
735
- GFP_KERNEL );
751
+ __create_object (ptr + size , end - ptr - size , object -> min_count ,
752
+ GFP_KERNEL , object -> flags & OBJECT_PHYS );
736
753
737
754
__delete_object (object );
738
755
}
@@ -1129,9 +1146,14 @@ EXPORT_SYMBOL(kmemleak_no_scan);
1129
1146
*/
1130
1147
void __ref kmemleak_alloc_phys (phys_addr_t phys , size_t size , gfp_t gfp )
1131
1148
{
1149
+ pr_debug ("%s(0x%pa, %zu)\n" , __func__ , & phys , size );
1150
+
1132
1151
if (PHYS_PFN (phys ) >= min_low_pfn && PHYS_PFN (phys ) < max_low_pfn )
1133
- /* assume min_count 0 */
1134
- kmemleak_alloc (__va (phys ), size , 0 , gfp );
1152
+ /*
1153
+ * Create object with OBJECT_PHYS flag and
1154
+ * assume min_count 0.
1155
+ */
1156
+ create_object_phys ((unsigned long )__va (phys ), size , 0 , gfp );
1135
1157
}
1136
1158
EXPORT_SYMBOL (kmemleak_alloc_phys );
1137
1159
0 commit comments