@@ -5988,14 +5988,60 @@ ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
5988
5988
return __tracing_resize_ring_buffer (tr , size , cpu_id );
5989
5989
}
5990
5990
5991
+ struct trace_mod_entry {
5992
+ unsigned long mod_addr ;
5993
+ char mod_name [MODULE_NAME_LEN ];
5994
+ };
5995
+
5991
5996
struct trace_scratch {
5992
5997
unsigned long kaslr_addr ;
5998
+ unsigned long nr_entries ;
5999
+ struct trace_mod_entry entries [];
5993
6000
};
5994
6001
6002
+ static int save_mod (struct module * mod , void * data )
6003
+ {
6004
+ struct trace_array * tr = data ;
6005
+ struct trace_scratch * tscratch ;
6006
+ struct trace_mod_entry * entry ;
6007
+ unsigned int size ;
6008
+
6009
+ tscratch = tr -> scratch ;
6010
+ if (!tscratch )
6011
+ return -1 ;
6012
+ size = tr -> scratch_size ;
6013
+
6014
+ if (struct_size (tscratch , entries , tscratch -> nr_entries + 1 ) > size )
6015
+ return -1 ;
6016
+
6017
+ entry = & tscratch -> entries [tscratch -> nr_entries ];
6018
+
6019
+ tscratch -> nr_entries ++ ;
6020
+
6021
+ entry -> mod_addr = (unsigned long )mod -> mem [MOD_TEXT ].base ;
6022
+ strscpy (entry -> mod_name , mod -> name );
6023
+
6024
+ return 0 ;
6025
+ }
6026
+
5995
6027
static void update_last_data (struct trace_array * tr )
5996
6028
{
5997
6029
struct trace_scratch * tscratch ;
5998
6030
6031
+ if (!(tr -> flags & TRACE_ARRAY_FL_BOOT ))
6032
+ return ;
6033
+
6034
+ /* Reset the module list and reload them */
6035
+ if (tr -> scratch ) {
6036
+ struct trace_scratch * tscratch = tr -> scratch ;
6037
+
6038
+ memset (tscratch -> entries , 0 ,
6039
+ flex_array_size (tscratch , entries , tscratch -> nr_entries ));
6040
+ tscratch -> nr_entries = 0 ;
6041
+
6042
+ module_for_each_mod (save_mod , tr );
6043
+ }
6044
+
5999
6045
if (!(tr -> flags & TRACE_ARRAY_FL_LAST_BOOT ))
6000
6046
return ;
6001
6047
@@ -9224,6 +9270,46 @@ static struct dentry *trace_instance_dir;
9224
9270
static void
9225
9271
init_tracer_tracefs (struct trace_array * tr , struct dentry * d_tracer );
9226
9272
9273
+ static void setup_trace_scratch (struct trace_array * tr ,
9274
+ struct trace_scratch * tscratch , unsigned int size )
9275
+ {
9276
+ struct trace_mod_entry * entry ;
9277
+
9278
+ if (!tscratch )
9279
+ return ;
9280
+
9281
+ tr -> scratch = tscratch ;
9282
+ tr -> scratch_size = size ;
9283
+
9284
+ #ifdef CONFIG_RANDOMIZE_BASE
9285
+ if (tscratch -> kaslr_addr )
9286
+ tr -> text_delta = kaslr_offset () - tscratch -> kaslr_addr ;
9287
+ #endif
9288
+
9289
+ if (struct_size (tscratch , entries , tscratch -> nr_entries ) > size )
9290
+ goto reset ;
9291
+
9292
+ /* Check if each module name is a valid string */
9293
+ for (int i = 0 ; i < tscratch -> nr_entries ; i ++ ) {
9294
+ int n ;
9295
+
9296
+ entry = & tscratch -> entries [i ];
9297
+
9298
+ for (n = 0 ; n < MODULE_NAME_LEN ; n ++ ) {
9299
+ if (entry -> mod_name [n ] == '\0' )
9300
+ break ;
9301
+ if (!isprint (entry -> mod_name [n ]))
9302
+ goto reset ;
9303
+ }
9304
+ if (n == MODULE_NAME_LEN )
9305
+ goto reset ;
9306
+ }
9307
+ return ;
9308
+ reset :
9309
+ /* Invalid trace modules */
9310
+ memset (tscratch , 0 , size );
9311
+ }
9312
+
9227
9313
static int
9228
9314
allocate_trace_buffer (struct trace_array * tr , struct array_buffer * buf , int size )
9229
9315
{
@@ -9236,21 +9322,15 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size
9236
9322
buf -> tr = tr ;
9237
9323
9238
9324
if (tr -> range_addr_start && tr -> range_addr_size ) {
9325
+ /* Add scratch buffer to handle 128 modules */
9239
9326
buf -> buffer = ring_buffer_alloc_range (size , rb_flags , 0 ,
9240
9327
tr -> range_addr_start ,
9241
9328
tr -> range_addr_size ,
9242
- sizeof ( * tscratch ));
9329
+ struct_size ( tscratch , entries , 128 ));
9243
9330
9244
9331
tscratch = ring_buffer_meta_scratch (buf -> buffer , & scratch_size );
9245
- if (tscratch ) {
9246
- tr -> scratch = tscratch ;
9247
- tr -> scratch_size = scratch_size ;
9332
+ setup_trace_scratch (tr , tscratch , scratch_size );
9248
9333
9249
- #ifdef CONFIG_RANDOMIZE_BASE
9250
- if (tscratch -> kaslr_addr )
9251
- tr -> text_delta = kaslr_offset () - tscratch -> kaslr_addr ;
9252
- #endif
9253
- }
9254
9334
/*
9255
9335
* This is basically the same as a mapped buffer,
9256
9336
* with the same restrictions.
0 commit comments