Re: [PATCH] percpu: improve percpu_alloc_percpu event trace

From: Vasily Averin
Date: Sat May 07 2022 - 10:51:25 EST


On 5/6/22 23:38, kernel test robot wrote:
>>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>>> include/trace/events/percpu.h:11:1: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected unsigned long flags @@ got restricted gfp_t [usertype] gfp_flags @@
> include/trace/events/percpu.h:11:1: sparse: expected unsigned long flags
> include/trace/events/percpu.h:11:1: sparse: got restricted gfp_t [usertype] gfp_flags
> mm/percpu.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, include/trace/events/percpu.h):
>>> include/trace/events/percpu.h:11:1: sparse: sparse: cast to restricted gfp_t
>>> include/trace/events/percpu.h:11:1: sparse: sparse: cast to restricted gfp_t
>>> include/trace/events/percpu.h:11:1: sparse: sparse: restricted gfp_t degrades to integer
>>> include/trace/events/percpu.h:11:1: sparse: sparse: restricted gfp_t degrades to integer
> mm/percpu.c:2012:24: sparse: sparse: context imbalance in 'pcpu_balance_free' - unexpected unlock

The same messages are generated for any other gfp_t argument in trace events.
As far as I understand it is not a bug per se,
but trace macros lacks __force attribute in 'gfp_t'-> 'unsigned long' casts.
The same thing happens with mode_t and with some other places using __print_flags()
for __bitwise marked types.

I can make sparse happy, here and elsewhere but it requires a lot of __force attributes.
Is anyone interested in such patches, or can we silently ignore these messages?

Need to add __force attribute to all entries in __def_gfpflag_names array
and add few changes into trace description, below is an example.

> vim +11 include/trace/events/percpu.h
>
> df95e795a72289 Dennis Zhou 2017-06-19 10
> df95e795a72289 Dennis Zhou 2017-06-19 @11 TRACE_EVENT(percpu_alloc_percpu,
> df95e795a72289 Dennis Zhou 2017-06-19 12
> df95e795a72289 Dennis Zhou 2017-06-19 13 TP_PROTO(bool reserved, bool is_atomic, size_t size,
> dee6876db0a7a4 Vasily Averin 2022-05-06 14 size_t align, void *base_addr, int off,
> dee6876db0a7a4 Vasily Averin 2022-05-06 15 void __percpu *ptr, size_t bytes_alloc, gfp_t gfp_flags),
> df95e795a72289 Dennis Zhou 2017-06-19 16
> dee6876db0a7a4 Vasily Averin 2022-05-06 17 TP_ARGS(reserved, is_atomic, size, align, base_addr, off, ptr,
> dee6876db0a7a4 Vasily Averin 2022-05-06 18 bytes_alloc, gfp_flags),
> df95e795a72289 Dennis Zhou 2017-06-19 19
> df95e795a72289 Dennis Zhou 2017-06-19 20 TP_STRUCT__entry(
> df95e795a72289 Dennis Zhou 2017-06-19 21 __field( bool, reserved )
> df95e795a72289 Dennis Zhou 2017-06-19 22 __field( bool, is_atomic )
> df95e795a72289 Dennis Zhou 2017-06-19 23 __field( size_t, size )
> df95e795a72289 Dennis Zhou 2017-06-19 24 __field( size_t, align )
> df95e795a72289 Dennis Zhou 2017-06-19 25 __field( void *, base_addr )
> df95e795a72289 Dennis Zhou 2017-06-19 26 __field( int, off )
> df95e795a72289 Dennis Zhou 2017-06-19 27 __field( void __percpu *, ptr )
> dee6876db0a7a4 Vasily Averin 2022-05-06 28 __field( size_t, bytes_alloc )
> dee6876db0a7a4 Vasily Averin 2022-05-06 29 __field( gfp_t, gfp_flags )
VvS: need to replace gfp_t to unsigned long ...

> df95e795a72289 Dennis Zhou 2017-06-19 30 ),
> df95e795a72289 Dennis Zhou 2017-06-19 31 TP_fast_assign(
> df95e795a72289 Dennis Zhou 2017-06-19 32 __entry->reserved = reserved;
> df95e795a72289 Dennis Zhou 2017-06-19 33 __entry->is_atomic = is_atomic;
> df95e795a72289 Dennis Zhou 2017-06-19 34 __entry->size = size;
> df95e795a72289 Dennis Zhou 2017-06-19 35 __entry->align = align;
> df95e795a72289 Dennis Zhou 2017-06-19 36 __entry->base_addr = base_addr;
> df95e795a72289 Dennis Zhou 2017-06-19 37 __entry->off = off;
> df95e795a72289 Dennis Zhou 2017-06-19 38 __entry->ptr = ptr;
> dee6876db0a7a4 Vasily Averin 2022-05-06 39 __entry->bytes_alloc = bytes_alloc;
> dee6876db0a7a4 Vasily Averin 2022-05-06 40 __entry->gfp_flags = gfp_flags;
VvS: ... and use here (__force unsigned long)

> df95e795a72289 Dennis Zhou 2017-06-19 41 ),
> df95e795a72289 Dennis Zhou 2017-06-19 42
> dee6876db0a7a4 Vasily Averin 2022-05-06 43 TP_printk("reserved=%d is_atomic=%d size=%zu align=%zu base_addr=%p off=%d ptr=%p bytes_alloc=%zu gfp_flags=%s",
> df95e795a72289 Dennis Zhou 2017-06-19 44 __entry->reserved, __entry->is_atomic,
> df95e795a72289 Dennis Zhou 2017-06-19 45 __entry->size, __entry->align,
> dee6876db0a7a4 Vasily Averin 2022-05-06 46 __entry->base_addr, __entry->off, __entry->ptr,
> dee6876db0a7a4 Vasily Averin 2022-05-06 47 __entry->bytes_alloc, show_gfp_flags(__entry->gfp_flags))
> df95e795a72289 Dennis Zhou 2017-06-19 48 );
> df95e795a72289 Dennis Zhou 2017-06-19 49
Thank you,
Vasily Averin