Re: [PATCH bpf] bpf: Fix nested bpf_bprintf_prepare with more per-cpu buffers

From: kernel test robot
Date: Mon May 10 2021 - 21:22:03 EST


Hi Florent,

I love your patch! Yet something to improve:

[auto build test ERROR on bpf/master]

url: https://github.com/0day-ci/linux/commits/Florent-Revest/bpf-Fix-nested-bpf_bprintf_prepare-with-more-per-cpu-buffers/20210511-053835
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git master
config: powerpc-randconfig-r021-20210510 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project a0fed635fe1701470062495a6ffee1c608f3f1bc)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/0day-ci/linux/commit/1f5d45d9243d8ca8ece81e778579fc46a1946887
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Florent-Revest/bpf-Fix-nested-bpf_bprintf_prepare-with-more-per-cpu-buffers/20210511-053835
git checkout 1f5d45d9243d8ca8ece81e778579fc46a1946887
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=powerpc

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All errors (new ones prefixed by >>):

>> kernel/bpf/helpers.c:718:23: error: use of undeclared identifier 'bpf_bprintf_buf'; did you mean 'bpf_bprintf_bufs'?
bufs = this_cpu_ptr(&bpf_bprintf_buf);
^~~~~~~~~~~~~~~
bpf_bprintf_bufs
include/linux/percpu-defs.h:265:39: note: expanded from macro 'this_cpu_ptr'
#define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
^
include/linux/percpu-defs.h:264:38: note: expanded from macro 'raw_cpu_ptr'
#define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
^
include/linux/percpu-defs.h:263:65: note: expanded from macro 'per_cpu_ptr'
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR(ptr); })
^
include/linux/percpu-defs.h:259:20: note: expanded from macro 'VERIFY_PERCPU_PTR'
__verify_pcpu_ptr(__p); \
^
include/linux/percpu-defs.h:219:47: note: expanded from macro '__verify_pcpu_ptr'
const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
^
kernel/bpf/helpers.c:703:48: note: 'bpf_bprintf_bufs' declared here
static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
^
>> kernel/bpf/helpers.c:718:9: error: arithmetic on a pointer to an incomplete type 'typeof(struct bpf_bprintf_bufs)' (aka 'struct bpf_bprintf_bufs')
bufs = this_cpu_ptr(&bpf_bprintf_buf);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/percpu-defs.h:265:27: note: expanded from macro 'this_cpu_ptr'
#define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
^~~~~~~~~~~~~~~~
include/linux/percpu-defs.h:264:26: note: expanded from macro 'raw_cpu_ptr'
#define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
^~~~~~~~~~~~~~~~~~~
include/linux/percpu-defs.h:263:47: note: expanded from macro 'per_cpu_ptr'
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR(ptr); })
^~~~~~~~~~~~~~~~~~~~~~
include/linux/percpu-defs.h:259:2: note: expanded from macro 'VERIFY_PERCPU_PTR'
__verify_pcpu_ptr(__p); \
^~~~~~~~~~~~~~~~~~~~~~
include/linux/percpu-defs.h:219:52: note: expanded from macro '__verify_pcpu_ptr'
const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL; \
~~~~~ ^
kernel/bpf/helpers.c:703:30: note: forward declaration of 'struct bpf_bprintf_bufs'
static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
^
>> kernel/bpf/helpers.c:718:23: error: use of undeclared identifier 'bpf_bprintf_buf'; did you mean 'bpf_bprintf_bufs'?
bufs = this_cpu_ptr(&bpf_bprintf_buf);
^~~~~~~~~~~~~~~
bpf_bprintf_bufs
include/linux/percpu-defs.h:265:39: note: expanded from macro 'this_cpu_ptr'
#define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
^
include/linux/percpu-defs.h:264:38: note: expanded from macro 'raw_cpu_ptr'
#define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
^
include/linux/percpu-defs.h:263:65: note: expanded from macro 'per_cpu_ptr'
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR(ptr); })
^
include/linux/percpu-defs.h:260:12: note: expanded from macro 'VERIFY_PERCPU_PTR'
(typeof(*(__p)) __kernel __force *)(__p); \
^
kernel/bpf/helpers.c:703:48: note: 'bpf_bprintf_bufs' declared here
static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
^
>> kernel/bpf/helpers.c:718:23: error: use of undeclared identifier 'bpf_bprintf_buf'; did you mean 'bpf_bprintf_bufs'?
bufs = this_cpu_ptr(&bpf_bprintf_buf);
^~~~~~~~~~~~~~~
bpf_bprintf_bufs
include/linux/percpu-defs.h:265:39: note: expanded from macro 'this_cpu_ptr'
#define this_cpu_ptr(ptr) raw_cpu_ptr(ptr)
^
include/linux/percpu-defs.h:264:38: note: expanded from macro 'raw_cpu_ptr'
#define raw_cpu_ptr(ptr) per_cpu_ptr(ptr, 0)
^
include/linux/percpu-defs.h:263:65: note: expanded from macro 'per_cpu_ptr'
#define per_cpu_ptr(ptr, cpu) ({ (void)(cpu); VERIFY_PERCPU_PTR(ptr); })
^
include/linux/percpu-defs.h:260:38: note: expanded from macro 'VERIFY_PERCPU_PTR'
(typeof(*(__p)) __kernel __force *)(__p); \
^
kernel/bpf/helpers.c:703:48: note: 'bpf_bprintf_bufs' declared here
static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
^
>> kernel/bpf/helpers.c:718:7: error: incompatible pointer types assigning to 'struct bpf_bprintf_buffers *' from 'typeof (*(&bpf_bprintf_bufs)) *' (aka 'struct bpf_bprintf_bufs *') [-Werror,-Wincompatible-pointer-types]
bufs = this_cpu_ptr(&bpf_bprintf_buf);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> kernel/bpf/helpers.c:703:48: error: tentative definition has type 'typeof(struct bpf_bprintf_bufs)' (aka 'struct bpf_bprintf_bufs') that is never completed
static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
^
kernel/bpf/helpers.c:703:30: note: forward declaration of 'struct bpf_bprintf_bufs'
static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
^
6 errors generated.


vim +718 kernel/bpf/helpers.c

698
699 /* Support executing three nested bprintf helper calls on a given CPU */
700 struct bpf_bprintf_buffers {
701 char tmp_bufs[3][MAX_PRINTF_BUF_LEN];
702 };
> 703 static DEFINE_PER_CPU(struct bpf_bprintf_bufs, bpf_bprintf_bufs);
704 static DEFINE_PER_CPU(int, bpf_bprintf_nest_level);
705
706 static int try_get_fmt_tmp_buf(char **tmp_buf)
707 {
708 struct bpf_bprintf_buffers *bufs;
709 int nest_level;
710
711 preempt_disable();
712 nest_level = this_cpu_inc_return(bpf_bprintf_nest_level);
713 if (WARN_ON_ONCE(nest_level > ARRAY_SIZE(bufs->tmp_bufs))) {
714 this_cpu_dec(bpf_bprintf_nest_level);
715 preempt_enable();
716 return -EBUSY;
717 }
> 718 bufs = this_cpu_ptr(&bpf_bprintf_buf);
719 *tmp_buf = bufs->tmp_bufs[nest_level - 1];
720
721 return 0;
722 }
723

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip