2022-05-07 16:53:50

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] percpu: improve percpu_alloc_percpu event trace

Hi Vasily,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on hnaz-mm/master v5.18-rc5]
[cannot apply to dennis-percpu/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/intel-lab-lkp/linux/commits/Vasily-Averin/percpu-improve-percpu_alloc_percpu-event-trace/20220506-124742
base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next
config: i386-randconfig-s001 (https://download.01.org/0day-ci/archive/20220507/[email protected]/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/intel-lab-lkp/linux/commit/dee6876db0a7a4715516e673f9edaca2ba40677c
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vasily-Averin/percpu-improve-percpu_alloc_percpu-event-trace/20220506-124742
git checkout dee6876db0a7a4715516e673f9edaca2ba40677c
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)
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 from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> include/trace/events/percpu.h:11:1: sparse: sparse: cast from restricted gfp_t
>> 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

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 )
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;
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

--
0-DAY CI Kernel Test Service
https://01.org/lkp


2022-05-09 04:48:48

by Vasily Averin

[permalink] [raw]
Subject: Re: [PATCH] percpu: improve percpu_alloc_percpu event trace

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

2022-05-09 21:56:12

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] percpu: improve percpu_alloc_percpu event trace

On Sat, 7 May 2022 17:51:16 +0300
Vasily Averin <[email protected]> wrote:

> 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'm curious as to where the gfp_t to unsigned long is happening in the
macros?

-- Steve

2022-05-10 07:32:46

by Vasily Averin

[permalink] [raw]
Subject: Re: [PATCH] percpu: improve percpu_alloc_percpu event trace

On 5/10/22 00:06, Steven Rostedt wrote:
> I'm curious as to where the gfp_t to unsigned long is happening in the
> macros?

original ___GFP_* flags are usual defines

/* Plain integer GFP bitmasks. Do not use this directly. */
#define ___GFP_DMA 0x01u
#define ___GFP_HIGHMEM 0x02u
#define ___GFP_DMA32 0x04u

... but __GFP_* flags used elsewhere are declared as 'forced to gfp_t'

#define __GFP_DMA ((__force gfp_t)___GFP_DMA)
#define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM)
#define __GFP_DMA32 ((__force gfp_t)___GFP_DMA32)
...
#define GFP_DMA __GFP_DMA
#define GFP_DMA32 __GFP_DMA32

... and when __def_gfpflag_names() traslates them to unsigned long

{(unsigned long)GFP_DMA, "GFP_DMA"}, \
{(unsigned long)__GFP_HIGHMEM, "__GFP_HIGHMEM"}, \
{(unsigned long)GFP_DMA32, "GFP_DMA32"}, \

... it leads to sparse warnings bacuse type gfp_t was declared as 'bitwise'
From mas sparse

-Wbitwise
Warn about unsupported operations or type mismatches with
restricted integer types.

Sparse supports an extended attribute,
__attribute__((bitwise)), which creates a new restricted
integer type from a base integer type, distinct from the
base integer type and from any other restricted integer
type not declared in the same declaration or typedef.

__bitwise is for *unique types* that cannot be mixed with
other types, and that you'd never want to just use as a
random integer (the integer 0 is special, though, and gets
silently accepted iirc - it's kind of like "NULL" for
pointers). So "gfp_t" or the "safe endianness" types would
be __bitwise: you can only operate on them by doing
specific operations that know about *that* particular
type.

Sparse issues these warnings by default.

Thank you,
Vasily Averin

2022-05-10 19:48:43

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] percpu: improve percpu_alloc_percpu event trace

On Tue, 10 May 2022 07:22:02 +0300
Vasily Averin <[email protected]> wrote:

> ... and when __def_gfpflag_names() traslates them to unsigned long
>
> {(unsigned long)GFP_DMA, "GFP_DMA"}, \
> {(unsigned long)__GFP_HIGHMEM, "__GFP_HIGHMEM"}, \
> {(unsigned long)GFP_DMA32, "GFP_DMA32"}, \
>
> ... it leads to sparse warnings bacuse type gfp_t was declared as 'bitwise'

Ah' it's the printing of the flag bits. Got it.

-- Steve