From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Kicinski Subject: [PATCH net 05/10] net: xdp: don't allow device-bound programs in driver mode Date: Sun, 19 Nov 2017 20:55:17 -0800 Message-ID: <20171120045522.2188-6-jakub.kicinski@netronome.com> References: <20171120045522.2188-1-jakub.kicinski@netronome.com> Cc: alexei.starovoitov@gmail.com, daniel@iogearbox.net, Jakub Kicinski To: netdev@vger.kernel.org Return-path: Received: from mail-pg0-f66.google.com ([74.125.83.66]:43468 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751176AbdKTE4L (ORCPT ); Sun, 19 Nov 2017 23:56:11 -0500 Received: by mail-pg0-f66.google.com with SMTP id r12so6406242pgu.10 for ; Sun, 19 Nov 2017 20:56:11 -0800 (PST) In-Reply-To: <20171120045522.2188-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org List-ID: Currently device-bound programs are not able to run on the host to save resources (host JIT is not invoked). Don't allow XDP programs to be attached without the HW_MODE flag. In theory if program is already translated for device offload the driver should choose to offload it instead of loading it in the driver. However, offloading translated program may still fail resulting in device-bound program being run on the host. Prevent this by refusing to attach device bound programs if XDP_FLAGS_HW_MODE is not set. Signed-off-by: Jakub Kicinski Reviewed-by: Quentin Monnet Acked-by: Alexei Starovoitov Acked-by: Daniel Borkmann --- net/core/dev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 09525a27319c..21de2d37a0ba 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -7143,6 +7143,13 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, bpf_op == ops->ndo_bpf); if (IS_ERR(prog)) return PTR_ERR(prog); + + if (!(flags & XDP_FLAGS_HW_MODE) && + bpf_prog_is_dev_bound(prog->aux)) { + NL_SET_ERR_MSG_MOD(extack, "using device-bound program without HW_MODE flag not supported"); + bpf_prog_put(prog); + return -EINVAL; + } } err = dev_xdp_install(dev, bpf_op, extack, flags, prog); -- 2.14.1