Message ID | 20200714040643.1135876-5-andriin@fb.com |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | BPF XDP link | expand |
Hi Andrii,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Andrii-Nakryiko/BPF-XDP-link/20200714-120909
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: parisc-defconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.3.0
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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
net/core/dev.c:8717:18: error: field 'link' has incomplete type
8717 | struct bpf_link link;
| ^~~~
In file included from include/linux/instrumented.h:10,
from include/linux/uaccess.h:5,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_release':
include/linux/kernel.h:1003:32: error: dereferencing pointer to incomplete type 'struct bpf_link'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~
include/linux/compiler.h:372:9: note: in definition of macro '__compiletime_assert'
372 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
392 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:20: note: in expansion of macro '__same_type'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~
net/core/dev.c:8972:34: note: in expansion of macro 'container_of'
8972 | struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
| ^~~~~~~~~~~~
In file included from arch/parisc/include/asm/atomic.h:10,
from include/linux/atomic.h:7,
from arch/parisc/include/asm/bitops.h:13,
from include/linux/bitops.h:29,
from include/linux/kernel.h:12,
from arch/parisc/include/asm/bug.h:5,
from include/linux/bug.h:5,
from include/linux/thread_info.h:12,
from include/asm-generic/current.h:5,
from ./arch/parisc/include/generated/asm/current.h:1,
from include/linux/sched.h:12,
from include/linux/uaccess.h:6,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_update':
>> arch/parisc/include/asm/cmpxchg.h:50:27: warning: initialization of 'int' from 'struct bpf_prog *' makes integer from pointer without a cast [-Wint-conversion]
50 | __typeof__(*(ptr)) _x_ = (x); \
| ^
net/core/dev.c:9026:13: note: in expansion of macro 'xchg'
9026 | old_prog = xchg(&link->prog, new_prog);
| ^~~~
net/core/dev.c:9026:11: warning: assignment to 'struct bpf_prog *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
9026 | old_prog = xchg(&link->prog, new_prog);
| ^
net/core/dev.c: At top level:
net/core/dev.c:9034:21: error: variable 'bpf_xdp_link_lops' has initializer but incomplete type
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~
net/core/dev.c:9035:3: error: 'const struct bpf_link_ops' has no member named 'release'
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~
net/core/dev.c:9035:13: warning: excess elements in struct initializer
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9035:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9036:3: error: 'const struct bpf_link_ops' has no member named 'dealloc'
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~
net/core/dev.c:9036:13: warning: excess elements in struct initializer
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9036:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9037:3: error: 'const struct bpf_link_ops' has no member named 'update_prog'
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~
net/core/dev.c:9037:17: warning: excess elements in struct initializer
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~~~~~~~~~
net/core/dev.c:9037:17: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c: In function 'bpf_xdp_link_attach':
net/core/dev.c:9043:25: error: storage size of 'link_primer' isn't known
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c:9058:2: error: implicit declaration of function 'bpf_link_init'; did you mean 'bio_list_init'? [-Werror=implicit-function-declaration]
9058 | bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
| ^~~~~~~~~~~~~
| bio_list_init
net/core/dev.c:9062:8: error: implicit declaration of function 'bpf_link_prime' [-Werror=implicit-function-declaration]
9062 | err = bpf_link_prime(&link->link, &link_primer);
| ^~~~~~~~~~~~~~
net/core/dev.c:9073:3: error: implicit declaration of function 'bpf_link_cleanup' [-Werror=implicit-function-declaration]
9073 | bpf_link_cleanup(&link_primer);
| ^~~~~~~~~~~~~~~~
net/core/dev.c:9077:7: error: implicit declaration of function 'bpf_link_settle' [-Werror=implicit-function-declaration]
9077 | fd = bpf_link_settle(&link_primer);
| ^~~~~~~~~~~~~~~
net/core/dev.c:9043:25: warning: unused variable 'link_primer' [-Wunused-variable]
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c: At top level:
net/core/dev.c:9034:34: error: storage size of 'bpf_xdp_link_lops' isn't known
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +50 arch/parisc/include/asm/cmpxchg.h
9e5228ce0b9619 Paul Gortmaker 2012-04-01 37
9e5228ce0b9619 Paul Gortmaker 2012-04-01 38 /*
9e5228ce0b9619 Paul Gortmaker 2012-04-01 39 ** REVISIT - Abandoned use of LDCW in xchg() for now:
9e5228ce0b9619 Paul Gortmaker 2012-04-01 40 ** o need to test sizeof(*ptr) to avoid clearing adjacent bytes
9e5228ce0b9619 Paul Gortmaker 2012-04-01 41 ** o and while we are at it, could CONFIG_64BIT code use LDCD too?
9e5228ce0b9619 Paul Gortmaker 2012-04-01 42 **
9e5228ce0b9619 Paul Gortmaker 2012-04-01 43 ** if (__builtin_constant_p(x) && (x == NULL))
9e5228ce0b9619 Paul Gortmaker 2012-04-01 44 ** if (((unsigned long)p & 0xf) == 0)
9e5228ce0b9619 Paul Gortmaker 2012-04-01 45 ** return __ldcw(p);
9e5228ce0b9619 Paul Gortmaker 2012-04-01 46 */
9e5228ce0b9619 Paul Gortmaker 2012-04-01 47 #define xchg(ptr, x) \
75cf9797006a3a Helge Deller 2019-12-20 48 ({ \
75cf9797006a3a Helge Deller 2019-12-20 49 __typeof__(*(ptr)) __ret; \
75cf9797006a3a Helge Deller 2019-12-20 @50 __typeof__(*(ptr)) _x_ = (x); \
75cf9797006a3a Helge Deller 2019-12-20 51 __ret = (__typeof__(*(ptr))) \
75cf9797006a3a Helge Deller 2019-12-20 52 __xchg((unsigned long)_x_, (ptr), sizeof(*(ptr))); \
75cf9797006a3a Helge Deller 2019-12-20 53 __ret; \
75cf9797006a3a Helge Deller 2019-12-20 54 })
9e5228ce0b9619 Paul Gortmaker 2012-04-01 55
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hi Andrii,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Andrii-Nakryiko/BPF-XDP-link/20200714-120909
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: alpha-defconfig (attached as .config)
compiler: alpha-linux-gcc (GCC) 9.3.0
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
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
net/core/dev.c:8717:18: error: field 'link' has incomplete type
8717 | struct bpf_link link;
| ^~~~
In file included from include/linux/instrumented.h:10,
from include/linux/uaccess.h:5,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_release':
include/linux/kernel.h:1003:32: error: dereferencing pointer to incomplete type 'struct bpf_link'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~
include/linux/compiler.h:372:9: note: in definition of macro '__compiletime_assert'
372 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
392 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~~~~~~
include/linux/kernel.h:1003:20: note: in expansion of macro '__same_type'
1003 | BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
| ^~~~~~~~~~~
net/core/dev.c:8972:34: note: in expansion of macro 'container_of'
8972 | struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
| ^~~~~~~~~~~~
In file included from arch/alpha/include/asm/atomic.h:7,
from include/linux/atomic.h:7,
from include/linux/rcupdate.h:25,
from include/linux/rculist.h:11,
from include/linux/pid.h:5,
from include/linux/sched.h:14,
from include/linux/uaccess.h:6,
from net/core/dev.c:71:
net/core/dev.c: In function 'bpf_xdp_link_update':
>> arch/alpha/include/asm/cmpxchg.h:48:27: warning: initialization of 'int' from 'struct bpf_prog *' makes integer from pointer without a cast [-Wint-conversion]
48 | __typeof__(*(ptr)) _x_ = (x); \
| ^
net/core/dev.c:9026:13: note: in expansion of macro 'xchg'
9026 | old_prog = xchg(&link->prog, new_prog);
| ^~~~
net/core/dev.c:9026:11: warning: assignment to 'struct bpf_prog *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
9026 | old_prog = xchg(&link->prog, new_prog);
| ^
net/core/dev.c: At top level:
net/core/dev.c:9034:21: error: variable 'bpf_xdp_link_lops' has initializer but incomplete type
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~
net/core/dev.c:9035:3: error: 'const struct bpf_link_ops' has no member named 'release'
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~
net/core/dev.c:9035:13: warning: excess elements in struct initializer
9035 | .release = bpf_xdp_link_release,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9035:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9036:3: error: 'const struct bpf_link_ops' has no member named 'dealloc'
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~
net/core/dev.c:9036:13: warning: excess elements in struct initializer
9036 | .dealloc = bpf_xdp_link_dealloc,
| ^~~~~~~~~~~~~~~~~~~~
net/core/dev.c:9036:13: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c:9037:3: error: 'const struct bpf_link_ops' has no member named 'update_prog'
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~
net/core/dev.c:9037:17: warning: excess elements in struct initializer
9037 | .update_prog = bpf_xdp_link_update,
| ^~~~~~~~~~~~~~~~~~~
net/core/dev.c:9037:17: note: (near initialization for 'bpf_xdp_link_lops')
net/core/dev.c: In function 'bpf_xdp_link_attach':
net/core/dev.c:9043:25: error: storage size of 'link_primer' isn't known
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c:9058:2: error: implicit declaration of function 'bpf_link_init'; did you mean 'bio_list_init'? [-Werror=implicit-function-declaration]
9058 | bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
| ^~~~~~~~~~~~~
| bio_list_init
net/core/dev.c:9062:8: error: implicit declaration of function 'bpf_link_prime' [-Werror=implicit-function-declaration]
9062 | err = bpf_link_prime(&link->link, &link_primer);
| ^~~~~~~~~~~~~~
net/core/dev.c:9073:3: error: implicit declaration of function 'bpf_link_cleanup' [-Werror=implicit-function-declaration]
9073 | bpf_link_cleanup(&link_primer);
| ^~~~~~~~~~~~~~~~
net/core/dev.c:9077:7: error: implicit declaration of function 'bpf_link_settle' [-Werror=implicit-function-declaration]
9077 | fd = bpf_link_settle(&link_primer);
| ^~~~~~~~~~~~~~~
net/core/dev.c:9043:25: warning: unused variable 'link_primer' [-Wunused-variable]
9043 | struct bpf_link_primer link_primer;
| ^~~~~~~~~~~
net/core/dev.c: At top level:
net/core/dev.c:9034:34: error: storage size of 'bpf_xdp_link_lops' isn't known
9034 | static const struct bpf_link_ops bpf_xdp_link_lops = {
| ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +48 arch/alpha/include/asm/cmpxchg.h
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 40
fbfcd019917098 Andrea Parri 2018-02-27 41 /*
fbfcd019917098 Andrea Parri 2018-02-27 42 * The leading and the trailing memory barriers guarantee that these
fbfcd019917098 Andrea Parri 2018-02-27 43 * operations are fully ordered.
fbfcd019917098 Andrea Parri 2018-02-27 44 */
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 45 #define xchg(ptr, x) \
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 46 ({ \
fbfcd019917098 Andrea Parri 2018-02-27 47 __typeof__(*(ptr)) __ret; \
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 @48 __typeof__(*(ptr)) _x_ = (x); \
fbfcd019917098 Andrea Parri 2018-02-27 49 smp_mb(); \
fbfcd019917098 Andrea Parri 2018-02-27 50 __ret = (__typeof__(*(ptr))) \
fbfcd019917098 Andrea Parri 2018-02-27 51 __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
fbfcd019917098 Andrea Parri 2018-02-27 52 smp_mb(); \
fbfcd019917098 Andrea Parri 2018-02-27 53 __ret; \
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 54 })
5ba840f9da1ff9 Paul Gortmaker 2012-04-02 55
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff --git a/net/core/dev.c b/net/core/dev.c index 4a9a9d53d844..7c2935d567c4 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8989,9 +8989,52 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link) kfree(xdp_link); } +static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog, + struct bpf_prog *old_prog) +{ + struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link); + enum bpf_xdp_mode mode; + bpf_op_t bpf_op; + int err = 0; + + rtnl_lock(); + + /* link might have been auto-released already, so fail */ + if (!xdp_link->dev) { + err = -ENOLINK; + goto out_unlock; + } + + if (old_prog && link->prog != old_prog) { + err = -EPERM; + goto out_unlock; + } + old_prog = link->prog; + if (old_prog == new_prog) { + /* no-op, don't disturb drivers */ + bpf_prog_put(new_prog); + goto out_unlock; + } + + mode = dev_xdp_mode(xdp_link->flags); + bpf_op = dev_xdp_bpf_op(xdp_link->dev, mode); + err = dev_xdp_install(xdp_link->dev, mode, bpf_op, NULL, + xdp_link->flags, new_prog); + if (err) + goto out_unlock; + + old_prog = xchg(&link->prog, new_prog); + bpf_prog_put(old_prog); + +out_unlock: + rtnl_unlock(); + return err; +} + static const struct bpf_link_ops bpf_xdp_link_lops = { .release = bpf_xdp_link_release, .dealloc = bpf_xdp_link_dealloc, + .update_prog = bpf_xdp_link_update, }; int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
Add support for LINK_UPDATE command for BPF XDP link to enable reliable replacement of underlying BPF program. Signed-off-by: Andrii Nakryiko <andriin@fb.com> --- net/core/dev.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)