From patchwork Fri Dec 4 11:52:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68B52C193FE for ; Fri, 4 Dec 2020 11:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 307DE22AAE for ; Fri, 4 Dec 2020 11:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729980AbgLDLxf (ORCPT ); Fri, 4 Dec 2020 06:53:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57020 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730021AbgLDLxe (ORCPT ); Fri, 4 Dec 2020 06:53:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607082727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o+PrJpjmM4DYTJUyGlvv6TVizorkSjrUkFAhD1cJoAc=; b=b8cjsvKNraXzC9YXHDpN2JCuQrdhC4AwQNwmduBfpcXy64jK/hHOW09jNZZAKAIbZ5eJ8O 0fYqmF8utDCAVYNezTmRkEuNrkXDW5oFGGjBs2JeecH4bYPOtquu9h7SbPywu9v8d8ge0w 8pvIdnrm9FJjIxS/QroGJBVKL4JDKKQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-WxJLOma9MpuWAHQtgd5cfQ-1; Fri, 04 Dec 2020 06:52:05 -0500 X-MC-Unique: WxJLOma9MpuWAHQtgd5cfQ-1 Received: by mail-ed1-f70.google.com with SMTP id bf13so2241873edb.10 for ; Fri, 04 Dec 2020 03:52:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=o+PrJpjmM4DYTJUyGlvv6TVizorkSjrUkFAhD1cJoAc=; b=YQI7gicXFvNP4Ajcvk6cGZEHOLM9YE60wUXj72cOb+wdDpEyma36KBkB+6dmC14TY/ 1ljjIVC39KIiEs43H0Wxl+rabtYqzejK3C1/VmBaL81cQQqN6v+dlgP8qmMNanRE99hp 7zYZ9Xl7BzicTUm2LdUVHDAX/+6ZUEip56+6Cv+XRmhqG6cLQzYQBNLZVFZ43x+dAzmL y71WDeRIgzvWSA++//JPIq01CZXV1cWagIOWoXwyVzFFxU2Xm4rYfKuQSp1D8g7czYLC LRi1D+MGFAzwreWQL44yyUtpGHzqPtAzAeSeojPpukIyStaBED+jTp9jzoc8JN00wVgE dreQ== X-Gm-Message-State: AOAM5320nwn9WDlIjlowZUtOw2dV4iU4aQoFTZ3Xe9cAdPTfya73as9F KmHs0+rwpgYy59g/PxiqeOQw1kTexwTR7amy2KNcQy137GFYH36U3ZzvdMQinw3ec3qEsrtQvgW 6XrQeFRoFeVXOH8J7 X-Received: by 2002:aa7:dc5a:: with SMTP id g26mr7159185edu.35.1607082724403; Fri, 04 Dec 2020 03:52:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSOGnoLZ1XWP7YZkoXojRE2PhgJ6M3W26c1RRj7AYQElgavQeSYr1QsJQbjPGLaZCb2r29tQ== X-Received: by 2002:aa7:dc5a:: with SMTP id g26mr7159164edu.35.1607082724189; Fri, 04 Dec 2020 03:52:04 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id k21sm3299595edq.26.2020.12.04.03.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:52:03 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 580221843EB; Fri, 4 Dec 2020 12:52:03 +0100 (CET) Subject: [PATCH bpf v2 1/7] xdp: remove the xdp_attachment_flags_ok() callback From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:03 +0100 Message-ID: <160708272326.192754.5292019194136947768.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen Since commit 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs in net_device"), the XDP program attachment info is now maintained in the core code. This interacts badly with the xdp_attachment_flags_ok() check that prevents unloading an XDP program with different load flags than it was loaded with. In practice, two kinds of failures are seen: - An XDP program loaded without specifying a mode (and which then ends up in driver mode) cannot be unloaded if the program mode is specified on unload. - The dev_xdp_uninstall() hook always calls the driver callback with the mode set to the type of the program but an empty flags argument, which means the flags_ok() check prevents the program from being removed, leading to bpf prog reference leaks. The original reason this check was added was to avoid ambiguity when multiple programs were loaded. With the way the checks are done in the core now, this is quite simple to enforce in the core code, so let's add a check there and get rid of the xdp_attachment_flags_ok() callback entirely. Signed-off-by: Toke Høiland-Jørgensen --- .../net/ethernet/netronome/nfp/nfp_net_common.c | 6 ----- drivers/net/ethernet/ti/cpsw_priv.c | 3 --- drivers/net/netdevsim/bpf.c | 3 --- include/net/xdp.h | 2 -- net/core/dev.c | 22 ++++++++++++++++++-- net/core/xdp.c | 12 ----------- 6 files changed, 20 insertions(+), 28 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index b150da43adb2..437226866ce8 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -3562,9 +3562,6 @@ static int nfp_net_xdp_setup_drv(struct nfp_net *nn, struct netdev_bpf *bpf) struct nfp_net_dp *dp; int err; - if (!xdp_attachment_flags_ok(&nn->xdp, bpf)) - return -EBUSY; - if (!prog == !nn->dp.xdp_prog) { WRITE_ONCE(nn->dp.xdp_prog, prog); xdp_attachment_setup(&nn->xdp, bpf); @@ -3593,9 +3590,6 @@ static int nfp_net_xdp_setup_hw(struct nfp_net *nn, struct netdev_bpf *bpf) { int err; - if (!xdp_attachment_flags_ok(&nn->xdp_hw, bpf)) - return -EBUSY; - err = nfp_app_xdp_offload(nn->app, nn, bpf->prog, bpf->extack); if (err) return err; diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/cpsw_priv.c index 31c5e36ff706..424e644724e4 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.c +++ b/drivers/net/ethernet/ti/cpsw_priv.c @@ -1265,9 +1265,6 @@ static int cpsw_xdp_prog_setup(struct cpsw_priv *priv, struct netdev_bpf *bpf) if (!priv->xdpi.prog && !prog) return 0; - if (!xdp_attachment_flags_ok(&priv->xdpi, bpf)) - return -EBUSY; - WRITE_ONCE(priv->xdp_prog, prog); xdp_attachment_setup(&priv->xdpi, bpf); diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c index 2e90512f3bbe..85546664bdd5 100644 --- a/drivers/net/netdevsim/bpf.c +++ b/drivers/net/netdevsim/bpf.c @@ -190,9 +190,6 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf, { int err; - if (!xdp_attachment_flags_ok(xdp, bpf)) - return -EBUSY; - if (bpf->command == XDP_SETUP_PROG && !ns->bpf_xdpdrv_accept) { NSIM_EA(bpf->extack, "driver XDP disabled in DebugFS"); return -EOPNOTSUPP; diff --git a/include/net/xdp.h b/include/net/xdp.h index 3814fb631d52..9dab2bc6f187 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -240,8 +240,6 @@ struct xdp_attachment_info { }; struct netdev_bpf; -bool xdp_attachment_flags_ok(struct xdp_attachment_info *info, - struct netdev_bpf *bpf); void xdp_attachment_setup(struct xdp_attachment_info *info, struct netdev_bpf *bpf); diff --git a/net/core/dev.c b/net/core/dev.c index 8588ade790cb..38412e70f761 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8917,6 +8917,17 @@ static struct bpf_prog *dev_xdp_prog(struct net_device *dev, return dev->xdp_state[mode].prog; } +static u8 dev_xdp_prog_count(struct net_device *dev) +{ + u8 count = 0; + int i; + + for (i = 0; i < __MAX_XDP_MODE; i++) + if (dev->xdp_state[i].prog || dev->xdp_state[i].link) + count++; + return count; +} + u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode) { struct bpf_prog *prog = dev_xdp_prog(dev, mode); @@ -9007,6 +9018,7 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack struct bpf_xdp_link *link, struct bpf_prog *new_prog, struct bpf_prog *old_prog, u32 flags) { + unsigned int num_modes = hweight32(flags & XDP_FLAGS_MODES); struct bpf_prog *cur_prog; enum bpf_xdp_mode mode; bpf_op_t bpf_op; @@ -9022,11 +9034,17 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack NL_SET_ERR_MSG(extack, "Invalid XDP flags for BPF link attachment"); return -EINVAL; } - /* just one XDP mode bit should be set, zero defaults to SKB mode */ - if (hweight32(flags & XDP_FLAGS_MODES) > 1) { + /* just one XDP mode bit should be set, zero defaults to drv/skb mode */ + if (num_modes > 1) { NL_SET_ERR_MSG(extack, "Only one XDP mode flag can be set"); return -EINVAL; } + /* avoid ambiguity if offload + drv/skb mode progs are both loaded */ + if (!num_modes && dev_xdp_prog_count(dev) > 1) { + NL_SET_ERR_MSG(extack, + "More than one program loaded, unset mode is ambiguous"); + return -EINVAL; + } /* old_prog != NULL implies XDP_FLAGS_REPLACE is set */ if (old_prog && !(flags & XDP_FLAGS_REPLACE)) { NL_SET_ERR_MSG(extack, "XDP_FLAGS_REPLACE is not specified"); diff --git a/net/core/xdp.c b/net/core/xdp.c index 491ad569a79c..d900cebc0acd 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -403,18 +403,6 @@ void __xdp_release_frame(void *data, struct xdp_mem_info *mem) } EXPORT_SYMBOL_GPL(__xdp_release_frame); -bool xdp_attachment_flags_ok(struct xdp_attachment_info *info, - struct netdev_bpf *bpf) -{ - if (info->prog && (bpf->flags ^ info->flags) & XDP_FLAGS_MODES) { - NL_SET_ERR_MSG(bpf->extack, - "program loaded with different flags"); - return false; - } - return true; -} -EXPORT_SYMBOL_GPL(xdp_attachment_flags_ok); - void xdp_attachment_setup(struct xdp_attachment_info *info, struct netdev_bpf *bpf) { From patchwork Fri Dec 4 11:52:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA1AEC4361B for ; Fri, 4 Dec 2020 12:00:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52F3D2251E for ; Fri, 4 Dec 2020 12:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728300AbgLDMA5 (ORCPT ); Fri, 4 Dec 2020 07:00:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33422 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbgLDMA5 (ORCPT ); Fri, 4 Dec 2020 07:00:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607083170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fo4CkmHc3jtGL0IOPisn+w0CsTqAMCL3b0L5UdSE4ls=; b=biV+3dzoNJavgCvo1zJhHYpTe+Ij59fP+EghJaQAaxx539hcWVJc5GCloIqnkUxsBrd995 ki2+LG3VQLkWAxA5HQnp4lQ5A3Jm/Bf6mzkqdWl1rTIfkFbVMThStNB+dDmy5CuhbO6ycq hLdAZM+QC68VTxcPx5M+L2mELj3Fc1U= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-247-P414ixDUPMC6FO4hGEIYdQ-1; Fri, 04 Dec 2020 06:59:28 -0500 X-MC-Unique: P414ixDUPMC6FO4hGEIYdQ-1 Received: by mail-ej1-f72.google.com with SMTP id n17so1982762eja.23 for ; Fri, 04 Dec 2020 03:59:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=fo4CkmHc3jtGL0IOPisn+w0CsTqAMCL3b0L5UdSE4ls=; b=Np9GLbIWBrkfhbDK+25aciM6rSk1ug6e7EhAFt/6dU0JS0rWHv9SRmziSdD7fOdHc/ hEa0WvLPhMcAb1xxrU4c3w7KXxvnBdDb+Hf/hZx7bCRFl++nslyKoztqxZ6orSvOAg4s ya7Lfw9MNAMxuEpchbmEv1eOpT6ncmf6aAZJXvqa0O5wcSowMitOVeBHhzZOf1C8Hifd 931MgK1qIRZatQ2LDcPsYjeZthiEnDPxisEcFxhnvy1YOYRlBuZzP+cQPyWPeQ6YgJiw uugTVPVXFNtWmxas5arNAv8L9N4YJLg0MVLPJnnedN9Jnj988NjItUmfYs6mYFjtB3UC t1aw== X-Gm-Message-State: AOAM5335Lw1IDgLBatAviInZQ5xeyqmlsjDtHWDfsMXrmiZ1VxnyLu0G y9trYzaYxus2OFCa40HNu6Oe5C8mIoaMoyckFZx/3gffPCAmQfy4rMCv9Q3GaFuD22AOGGH0lHC Adq6UvfDvpfxdnFOV X-Received: by 2002:a17:906:4016:: with SMTP id v22mr6890793ejj.266.1607083166795; Fri, 04 Dec 2020 03:59:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJywrOY+L6uvg7IiDMqj6/eVEC18v1AA+ShmEGuxMXdvUnzdfACpA0kSCLjZwLRBvQn0LMGt5w== X-Received: by 2002:a17:906:4016:: with SMTP id v22mr6890759ejj.266.1607083166302; Fri, 04 Dec 2020 03:59:26 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id gl2sm2878911ejb.29.2020.12.04.03.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:59:25 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 6FF4E182EEA; Fri, 4 Dec 2020 12:52:04 +0100 (CET) Subject: [PATCH bpf v2 2/7] selftests/bpf/test_offload.py: Remove check for program load flags match From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:04 +0100 Message-ID: <160708272436.192754.11519287849839028664.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen Since we just removed the xdp_attachment_flags_ok() callback, also remove the check for it in test_offload.py, and replace it with a test for the new ambiguity-avoid check when multiple programs are loaded. Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/test_offload.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index 43c9cda199b8..becd27b2f4ba 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -716,13 +716,11 @@ def test_multi_prog(simdev, sim, obj, modename, modeid): fail(ret == 0, "Replaced one of programs without -force") check_extack(err, "XDP program already attached.", args) - if modename == "" or modename == "drv": - othermode = "" if modename == "drv" else "drv" - start_test("Test multi-attachment XDP - detach...") - ret, _, err = sim.unset_xdp(othermode, force=True, - fail=False, include_stderr=True) - fail(ret == 0, "Removed program with a bad mode") - check_extack(err, "program loaded with different flags.", args) + start_test("Test multi-attachment XDP - remove without mode...") + ret, _, err = sim.unset_xdp("", force=True, + fail=False, include_stderr=True) + fail(ret == 0, "Removed program without a mode flag") + check_extack(err, "More than one program loaded, unset mode is ambiguous.", args) sim.unset_xdp("offload") xdp = sim.ip_link_show(xdp=True)["xdp"] @@ -1001,16 +999,6 @@ try: check_extack(err, "native and generic XDP can't be active at the same time.", args) - ret, _, err = sim.set_xdp(obj, "", force=True, - fail=False, include_stderr=True) - fail(ret == 0, "Replaced XDP program with a program in different mode") - check_extack(err, "program loaded with different flags.", args) - - start_test("Test XDP prog remove with bad flags...") - ret, _, err = sim.unset_xdp("", force=True, - fail=False, include_stderr=True) - fail(ret == 0, "Removed program with a bad mode") - check_extack(err, "program loaded with different flags.", args) start_test("Test MTU restrictions...") ret, _ = sim.set_mtu(9000, fail=False) From patchwork Fri Dec 4 11:52:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE9A6C1B0D8 for ; Fri, 4 Dec 2020 11:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADF6B22AAF for ; Fri, 4 Dec 2020 11:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730106AbgLDLxi (ORCPT ); Fri, 4 Dec 2020 06:53:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48569 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730111AbgLDLxh (ORCPT ); Fri, 4 Dec 2020 06:53:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607082730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zcUyCpLjDCll9Y1/aRPnij3wIkLUo17xw68D8racrjQ=; b=jD1AwDVFyyYt1H51xp8v9YSB2emkASH+WXcgSRJNSP70gOsUgwQMeSY4AzFAxgWdizz2N2 VS1XfkySghH9U4Qyd5uaxrEfEbqpUl4uK/j5dY06hlGlvxmNY6TDYJuUDjbqheMvg3WLmO /FA0ea6jIpicxgISMHg4amQdukPQdPk= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584-DQefviJPN6mRTvaKlbB51Q-1; Fri, 04 Dec 2020 06:52:09 -0500 X-MC-Unique: DQefviJPN6mRTvaKlbB51Q-1 Received: by mail-ed1-f72.google.com with SMTP id i1so2240670edt.19 for ; Fri, 04 Dec 2020 03:52:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=zcUyCpLjDCll9Y1/aRPnij3wIkLUo17xw68D8racrjQ=; b=dz999vhpiHQ3O+kK21vZpXkYVFOERl3aVDvbm1KcxyrIVbtkzoxdB3FdBu411T3Ogk kCKqDqZnIvXpmJrcbRvcaIm6Qqzeq8ZV2Cb/kF9R38JpXS05S2o/H4erTUaa/yz4so+b CV3IImrqcBzYQ+GykmqtsuAf+NOEUzP46RfHfxJvIjSjtUS4eyxvYPNL+ORCQNdBRYIk n+/PjhKBfgI7aeR2UGGyqIfJbRyWi3RrFaTSulqDK5YW3Br6HLnwig9M6/VBdHs9pSqn rt5uFScGOyaVmIzrUfGm7EfDQaIFVeeZhAzPCl2MLAFSjt5OiBc23zvHl1y0omRmb19I 2ZgQ== X-Gm-Message-State: AOAM532W3OIPvf2kA7Jhpi08iT8Ieu4cNlXPpp/CgpzQ5JoWFPbId4rf ciiU0QTodFsCE3/Z9izigsVkSuLu4h9bpvKqHn6DP75q2vRQtxgEY2Sz3sxjStypbSxK+TY8PK1 EtE5X1st+odi2ONwK X-Received: by 2002:a17:906:c087:: with SMTP id f7mr867467ejz.492.1607082727622; Fri, 04 Dec 2020 03:52:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyEu66EqzxOKKZOgHPeEZHy0BRghOA3Syefi21Q3iNsPa4ViPa5k+lx+HXAso5qKcEfAQ7TQ== X-Received: by 2002:a17:906:c087:: with SMTP id f7mr867421ejz.492.1607082727090; Fri, 04 Dec 2020 03:52:07 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id k18sm3200968edx.18.2020.12.04.03.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:52:06 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 845291843EB; Fri, 4 Dec 2020 12:52:05 +0100 (CET) Subject: [PATCH bpf v2 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:05 +0100 Message-ID: <160708272546.192754.15754148712783914808.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen This adds a new debugfs toggle ('bpf_bind_verifier_accept') that can be used to make netdevsim reject BPF programs from being accepted by the verifier. If this toggle (which defaults to true) is set to false, nsim_bpf_verify_insn() will return EOPNOTSUPP on the last instruction (after outputting the 'Hello from netdevsim' verifier message). This makes it possible to check the verification callback in the driver from test_offload.py in selftests, since the verifier now clears the verifier log on a successful load, hiding the message from the driver. Acked-by: Jakub Kicinski Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/netdevsim/bpf.c | 12 ++++++++++-- drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c index 85546664bdd5..90aafb56f140 100644 --- a/drivers/net/netdevsim/bpf.c +++ b/drivers/net/netdevsim/bpf.c @@ -63,15 +63,20 @@ static int nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn) { struct nsim_bpf_bound_prog *state; + int ret = 0; state = env->prog->aux->offload->dev_priv; if (state->nsim_dev->bpf_bind_verifier_delay && !insn_idx) msleep(state->nsim_dev->bpf_bind_verifier_delay); - if (insn_idx == env->prog->len - 1) + if (insn_idx == env->prog->len - 1) { pr_vlog(env, "Hello from netdevsim!\n"); - return 0; + if (!state->nsim_dev->bpf_bind_verifier_accept) + ret = -EOPNOTSUPP; + } + + return ret; } static int nsim_bpf_finalize(struct bpf_verifier_env *env) @@ -595,6 +600,9 @@ int nsim_bpf_dev_init(struct nsim_dev *nsim_dev) &nsim_dev->bpf_bind_accept); debugfs_create_u32("bpf_bind_verifier_delay", 0600, nsim_dev->ddir, &nsim_dev->bpf_bind_verifier_delay); + nsim_dev->bpf_bind_verifier_accept = true; + debugfs_create_bool("bpf_bind_verifier_accept", 0600, nsim_dev->ddir, + &nsim_dev->bpf_bind_verifier_accept); return 0; } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 827fc80f50a0..c4e7ad2a1964 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -189,6 +189,7 @@ struct nsim_dev { struct dentry *take_snapshot; struct bpf_offload_dev *bpf_dev; bool bpf_bind_accept; + bool bpf_bind_verifier_accept; u32 bpf_bind_verifier_delay; struct dentry *ddir_bpf_bound_progs; u32 prog_id_gen; From patchwork Fri Dec 4 11:52:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F5C5C4167B for ; Fri, 4 Dec 2020 11:54:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BB1C22A85 for ; Fri, 4 Dec 2020 11:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388078AbgLDLxp (ORCPT ); Fri, 4 Dec 2020 06:53:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42380 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730024AbgLDLxh (ORCPT ); Fri, 4 Dec 2020 06:53:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607082730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Iu5eEQc6BVw7sLLw73HclvN8HnJfR2XuNo4UCs27Raw=; b=OpNVUNDgLf234v9qh7WwqbcTx3/eFKspLHm8fbR8D2Cd35nrbMvsh6ZS7L5KnE4V+zZLqd K1SYph/KQRuj94YCyg0UHR8AWpLKOIVHjTWP1KA+Ow6ozOjzM+P5JBPzJGSiZCNcs/JwUo ggBb8tHM7gZYz6PL/qbmYmZPvJ9ybtU= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-255-gOU3B-jzPlCb9D4OJWqehA-1; Fri, 04 Dec 2020 06:52:09 -0500 X-MC-Unique: gOU3B-jzPlCb9D4OJWqehA-1 Received: by mail-ej1-f70.google.com with SMTP id u15so1973287ejg.17 for ; Fri, 04 Dec 2020 03:52:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Iu5eEQc6BVw7sLLw73HclvN8HnJfR2XuNo4UCs27Raw=; b=Qy/hbder4qEVhnvvGSL0acrgm00f5qhCzM1ac4cghmldKOc4vH8HWPkJTn7lbJk6zc uldUqetWLJqiJM39CqetmwSq+oK6B+Ee2Dow2mPjW6cps6iKvvhxuVHpJwKOn87Hi1i7 MEHY6eB8lDXoUNheaZY39zh9HFPTuarOtI4xxhHZ0zWM/fK8ElpIDx956EPsu5zokbj1 ypVkxOy1A35PcKAZi4Cg5lBVd2D6NMBtS2z1x+yqjusMsUoctjx9oUC0DxBI4sUDcXap yOXoG/83hPRYvpQinlI1G/vcEhBqZOE8H7QLHxdMl3tLkq2o/q/22qFXpZ6+nKf3F/i/ XBNA== X-Gm-Message-State: AOAM530p4yXpNJhspAHVqMHjUZ7r0mqZPHXyzNhKVEKV3lJ2ImU7Xatw 5Q10sS8qi3r3/bZKSwE2VJLHtdERcFEjSTubxSdHmFwhiuklQLJ4ThjHGygs7b1wLWhvUxHtTrS q/8PechzAf4Eu+Qq+ X-Received: by 2002:a17:906:caa:: with SMTP id k10mr6536556ejh.204.1607082727934; Fri, 04 Dec 2020 03:52:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyugoXBC4ufUudPvLnR2Mz8lAS3J/eeuYSbtUpzdXzh3Ra4AwosKXY4UlzD5sCZCi55C7YXvA== X-Received: by 2002:a17:906:caa:: with SMTP id k10mr6536537ejh.204.1607082727607; Fri, 04 Dec 2020 03:52:07 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id qp16sm2890378ejb.74.2020.12.04.03.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:52:07 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 9B1E81843EF; Fri, 4 Dec 2020 12:52:06 +0100 (CET) Subject: [PATCH bpf v2 4/7] selftests/bpf/test_offload.py: only check verifier log on verification fails From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:06 +0100 Message-ID: <160708272654.192754.14360138626200913557.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen Since 6f8a57ccf85 ("bpf: Make verifier log more relevant by default"), the verifier discards log messages for successfully-verified programs. This broke test_offload.py which is looking for a verification message from the driver callback. Change test_offload.py to use the toggle in netdevsim to make the verification fail before looking for the verification message. Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/test_offload.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index becd27b2f4ba..61527b43f067 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -911,11 +911,18 @@ try: sim.tc_flush_filters() + start_test("Test TC offloads failure...") + sim.dfs["dev/bpf_bind_verifier_accept"] = 0 + ret, _, err = sim.cls_bpf_add_filter(obj, verbose=True, skip_sw=True, + fail=False, include_stderr=True) + fail(ret == 0, "TC filter did not reject with TC offloads enabled") + check_verifier_log(err, "[netdevsim] Hello from netdevsim!") + sim.dfs["dev/bpf_bind_verifier_accept"] = 1 + start_test("Test TC offloads work...") ret, _, err = sim.cls_bpf_add_filter(obj, verbose=True, skip_sw=True, fail=False, include_stderr=True) fail(ret != 0, "TC filter did not load with TC offloads enabled") - check_verifier_log(err, "[netdevsim] Hello from netdevsim!") start_test("Test TC offload basics...") dfs = simdev.dfs_get_bound_progs(expected=1) @@ -1032,6 +1039,15 @@ try: rm("/sys/fs/bpf/offload") sim.wait_for_flush() + start_test("Test XDP load failure...") + sim.dfs["dev/bpf_bind_verifier_accept"] = 0 + ret, _, err = bpftool_prog_load("sample_ret0.o", "/sys/fs/bpf/offload", + dev=sim['ifname'], fail=False, include_stderr=True) + fail(ret == 0, "verifier should fail on load") + check_verifier_log(err, "[netdevsim] Hello from netdevsim!") + sim.dfs["dev/bpf_bind_verifier_accept"] = 1 + sim.wait_for_flush() + start_test("Test XDP offload...") _, _, err = sim.set_xdp(obj, "offload", verbose=True, include_stderr=True) ipl = sim.ip_link_show(xdp=True) @@ -1039,7 +1055,6 @@ try: progs = bpftool_prog_list(expected=1) prog = progs[0] fail(link_xdp["id"] != prog["id"], "Loaded program has wrong ID") - check_verifier_log(err, "[netdevsim] Hello from netdevsim!") start_test("Test XDP offload is device bound...") dfs = simdev.dfs_get_bound_progs(expected=1) From patchwork Fri Dec 4 11:52:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C1A1C2BB48 for ; Fri, 4 Dec 2020 11:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F93922A99 for ; Fri, 4 Dec 2020 11:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730134AbgLDLxj (ORCPT ); Fri, 4 Dec 2020 06:53:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58441 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730124AbgLDLxi (ORCPT ); Fri, 4 Dec 2020 06:53:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607082731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lUl3YRxLzhPFlWGiTKmymWpaAC8KhJLCEwifVZuc7JU=; b=a2UJscbar5JqjKJHQQbLFS3TVX08BPZisYSNZOCNjgUF/5VG+vBEBdhVs4uNzZje73ygre tJJlP6X/7wetkNePLrk9ShxhdiAu3iRHp2IhXxi0UWqJUEY+6efmmcljs71gWTQYQ6VmXu m/ahlJS1V6VLW2DSa9jC440eR2f861w= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-kCef01ecMjup2-oQIfANog-1; Fri, 04 Dec 2020 06:52:10 -0500 X-MC-Unique: kCef01ecMjup2-oQIfANog-1 Received: by mail-ej1-f69.google.com with SMTP id 3so1268963ejw.13 for ; Fri, 04 Dec 2020 03:52:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=lUl3YRxLzhPFlWGiTKmymWpaAC8KhJLCEwifVZuc7JU=; b=kKtQS8xTAVz4/MUgokrBRsKaBXm8FO7kfmFoRuhTBBCq8/7WT3clZccqJoK+Vjn1sI u+zbNFsZWzgCa/UOKzOvRha/CPb6GY9LetclGMtXBhT4l2X1chKihqSgsA3bfyrbtZ6n fnrNC1AjfzM8uNYGyiejf+5ONo58K5bimOqBfJWQ3NVpqVHXti97UoRqnTJuCcVtfdaK LIUeINJ5y+fXDK+wQBJyB1TyHeSs5XZ63XL1zc/i6upwGgcuEWs15cQEpu9mM85ZZRdZ YnvF8fREMRL8Lbvj8V71phneHhT2GNBJ9zT9V5t07IQFbWXc2C4Lry3FqtCoQzkg7t+9 bUgg== X-Gm-Message-State: AOAM530oTOZXeuFuVSnrRAZOxF60rsDpX5CFdgEY/f2mLNFLoqQZV77F 3H3wxtu8rxrrRPXwv1rYdkVKsQrd9JNSaBQxB/3Z5v07g+LN4OUfJ9ejKIloB4hu2RciuYuC2SY eL8ppZEtl+NABluau X-Received: by 2002:a17:906:fa13:: with SMTP id lo19mr6557281ejb.455.1607082728846; Fri, 04 Dec 2020 03:52:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUwamXPIM/hd9eQ9ABpikH6bLI4zA+3HPcf7B32GCuXGObxGAEHI2EWUJuzvjPjmEKe00wSw== X-Received: by 2002:a17:906:fa13:: with SMTP id lo19mr6557267ejb.455.1607082728644; Fri, 04 Dec 2020 03:52:08 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id h16sm2985869eji.110.2020.12.04.03.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:52:08 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id B28D81843EC; Fri, 4 Dec 2020 12:52:07 +0100 (CET) Subject: [PATCH bpf v2 5/7] selftests/bpf/test_offload.py: fix expected case of extack messages From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:07 +0100 Message-ID: <160708272763.192754.5153087321106504338.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen Commit 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs in net_device") changed the case of some of the extack messages being returned when attaching of XDP programs failed. This broke test_offload.py, so let's fix the test to reflect this. Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/test_offload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index 61527b43f067..51a5e4d939cc 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -1004,7 +1004,7 @@ try: fail=False, include_stderr=True) fail(ret == 0, "Replaced XDP program with a program in different mode") check_extack(err, - "native and generic XDP can't be active at the same time.", + "Native and generic XDP can't be active at the same time.", args) start_test("Test MTU restrictions...") @@ -1035,7 +1035,7 @@ try: offload = bpf_pinned("/sys/fs/bpf/offload") ret, _, err = sim.set_xdp(offload, "drv", fail=False, include_stderr=True) fail(ret == 0, "attached offloaded XDP program to drv") - check_extack(err, "using device-bound program without HW_MODE flag is not supported.", args) + check_extack(err, "Using device-bound program without HW_MODE flag is not supported.", args) rm("/sys/fs/bpf/offload") sim.wait_for_flush() From patchwork Fri Dec 4 11:52:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1D37C2BBCF for ; Fri, 4 Dec 2020 11:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90B3D22A85 for ; Fri, 4 Dec 2020 11:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387909AbgLDLxm (ORCPT ); Fri, 4 Dec 2020 06:53:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32136 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730139AbgLDLxl (ORCPT ); Fri, 4 Dec 2020 06:53:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607082734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IK/QJ/mwWf6qYNme1m53SvUyoc+tECiyzDRKMtRU8jo=; b=Sjlujd57bh8FzQpguB/8lHFDAidt/KIjok2eG5p2vtn4wRmKtomTcciZ0+avcoPvNXukJP l+zXMtSgy6ll+hHlMkXCFOOLRyqf2sb+S6nODUrk+zjsUSs3K4temFmD5LeFvsMUNP4pDG 8dD+jSGMZ8NAJpJgDIzFPufVDLt9RtM= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-Gsq_RZlLPgKrTLvTS0X8_g-1; Fri, 04 Dec 2020 06:52:13 -0500 X-MC-Unique: Gsq_RZlLPgKrTLvTS0X8_g-1 Received: by mail-ed1-f70.google.com with SMTP id ca7so2260925edb.12 for ; Fri, 04 Dec 2020 03:52:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=IK/QJ/mwWf6qYNme1m53SvUyoc+tECiyzDRKMtRU8jo=; b=FOH9wpKnNRhy4lLshM+awH/1tijgbMeNF0Kltz/94Bi6IAAjKhozSZu1gk8PYU7GXh ViRsrFi6KnwX03kvqHWcP29da1EiTJdbnzrrR5HQF4Wi7gryhbgC89X/mv5zFyz/7e/i 3f+BRcaimO3bX5koeDmH5XkGQsnDqeQsF1r6Rqo1CUBkkk/SuAcwUml8PUcxzLK0xbCn p/qIdRXaFDlne0XLvUzwmaYyQSh9w40lqbNWJ5RKhRyFQUV/4v1ZgHmw8/v4xcdgvF7o LBGOpnGW0HsxJ5UYPcUidsRxWg3aNdmKtgyq4tVefQ7qkRAFnvPJOJuOA03iuM5+stfg TB1w== X-Gm-Message-State: AOAM530bAo9vx8RrHohBYL7s8jF3x87QtmUGJ2B7NXtEKdrbz2tznFsW vpLH2d9RQdxf2JOxLvSUIbCAVnqrfBVxTRwvHJ7iewuCHQap4wElnL/4QfMLN4rnh9YPvsxU5Lo VdhZj8VazO8w4CveV X-Received: by 2002:a17:906:e082:: with SMTP id gh2mr6434418ejb.406.1607082731590; Fri, 04 Dec 2020 03:52:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJnmnrQQFUZtCpPBo0okVYdCn+4YqUFrQtfBWBO5pOeK9MIHcNI5YMcL0nBkzararsSM8lqA== X-Received: by 2002:a17:906:e082:: with SMTP id gh2mr6434391ejb.406.1607082731155; Fri, 04 Dec 2020 03:52:11 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id e12sm3344289edm.48.2020.12.04.03.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:52:10 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id C9F751843EC; Fri, 4 Dec 2020 12:52:08 +0100 (CET) Subject: [PATCH bpf v2 6/7] selftests/bpf/test_offload.py: reset ethtool features after failed setting From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:08 +0100 Message-ID: <160708272873.192754.13552481233579004069.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen When setting the ethtool feature flag fails (as expected for the test), the kernel now tracks that the feature was requested to be 'off' and refuses to subsequently disable it again. So reset it back to 'on' so a subsequent disable (that's not supposed to fail) can succeed. Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/test_offload.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index 51a5e4d939cc..2128fbd8414b 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -946,6 +946,7 @@ try: start_test("Test disabling TC offloads is rejected while filters installed...") ret, _ = sim.set_ethtool_tc_offloads(False, fail=False) fail(ret == 0, "Driver should refuse to disable TC offloads with filters installed...") + sim.set_ethtool_tc_offloads(True) start_test("Test qdisc removal frees things...") sim.tc_flush_filters() From patchwork Fri Dec 4 11:52:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 338770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24ECDC4361A for ; Fri, 4 Dec 2020 11:54:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC9532251E for ; Fri, 4 Dec 2020 11:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388021AbgLDLxo (ORCPT ); Fri, 4 Dec 2020 06:53:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20455 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730136AbgLDLxl (ORCPT ); Fri, 4 Dec 2020 06:53:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607082734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4z8KXODqjwtErk41YpHMDb+O7Bt3e78Uq4SI4fcpBVc=; b=ZxfA/AkZA0Re0qKTLXV7NaDJ42+phaX5Ez3YCEZrHTnYqnpy/ZKufX3dJ2abKLgzAkaADa 7ivvogPCRLo5wczW9u+/zAsnBd8wLtJ06d++0HSYnmbvc5oXNBfw/YTiX2wDf1eyUf4unn v03Y5xpkeJf1WPzVZjc3fsxZdENThf0= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-399-w40M6VQIOwikbuju7gPUHA-1; Fri, 04 Dec 2020 06:52:12 -0500 X-MC-Unique: w40M6VQIOwikbuju7gPUHA-1 Received: by mail-ej1-f71.google.com with SMTP id f21so1976364ejf.11 for ; Fri, 04 Dec 2020 03:52:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=4z8KXODqjwtErk41YpHMDb+O7Bt3e78Uq4SI4fcpBVc=; b=H+8o5tYbOF7RvsAdh0Z7f8BUGjFC06t1tXVr8mmjLWUce3iUyh4Z8ZqaG7kpe19AZp L3bfNEK06gBHJPJ9o6tBOxsXJ/+UfYj1J7+2b3IGhMU0f7YL87WmmWOT9phntJ93BEjd v9ifXq8eKckk+kme6qJfRKzKVtLt6JgnRulxE3BDXnTJUO3Gol5WQAE2GSTtqt+kgAUO dYG268xjTnRM3N8gnslms7GfdWK5ZbamtIA9SBhqnq7/xYoPNx1uqeYkby8fqCjenP/J mBxJ0gTQNHPuMhumMMFb4QJsLrYrRuZ4nwJXTQvN2/CVpP/r/xSn+lCjML3PujIFThGk QYRw== X-Gm-Message-State: AOAM530EktAUECVU3/tROQc2SaiUYIY8GgkQXDuz3E1qVxcwfvQcaVMW 2rhaGntlpLs31lNFc0f6XbDEQ3cCs+hotc3mkta+iYlVsDx02CZVCfm+nLH5MKEEBbDGUg9mB/L zQzVVLYHW7p+bKH6f X-Received: by 2002:a17:906:8042:: with SMTP id x2mr7188288ejw.79.1607082731756; Fri, 04 Dec 2020 03:52:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrtWb6FuuLro5ty8zueEEvZOWwhg6p8KPWy4h8kxmLPsduHpi83CLwjqt251LWSV2eebcO4A== X-Received: by 2002:a17:906:8042:: with SMTP id x2mr7188267ejw.79.1607082731598; Fri, 04 Dec 2020 03:52:11 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id n16sm3284713edq.62.2020.12.04.03.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 03:52:10 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id E1EBE1843EF; Fri, 4 Dec 2020 12:52:09 +0100 (CET) Subject: [PATCH bpf v2 7/7] selftests/bpf/test_offload.py: filter bpftool internal map when counting maps From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: Jakub Kicinski Cc: "David S. Miller" , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jesper Dangaard Brouer , "Michael S. Tsirkin" , Romain Perier , Allen Pais , Grygorii Strashko , Simon Horman , "Gustavo A. R. Silva" , Lorenzo Bianconi , Wei Yongjun , Jiri Benc , oss-drivers@netronome.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Date: Fri, 04 Dec 2020 12:52:09 +0100 Message-ID: <160708272983.192754.10060052789845857257.stgit@toke.dk> In-Reply-To: <160708272217.192754.14019805999368221369.stgit@toke.dk> References: <160708272217.192754.14019805999368221369.stgit@toke.dk> User-Agent: StGit/0.23 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Toke Høiland-Jørgensen A few of the tests in test_offload.py expects to see a certain number of maps created, and checks this by counting the number of maps returned by bpftool. There is already a filter that will remove any maps already there at the beginning of the test, but bpftool now creates a map for the PID iterator rodata on each invocation, which makes the map count wrong. Fix this by also filtering the pid_iter.rodata map by name when counting. Signed-off-by: Toke Høiland-Jørgensen --- tools/testing/selftests/bpf/test_offload.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index 2128fbd8414b..b99bb8ed3ed4 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -184,9 +184,7 @@ def bpftool_prog_list(expected=None, ns=""): def bpftool_map_list(expected=None, ns=""): _, maps = bpftool("map show", JSON=True, ns=ns, fail=True) # Remove the base maps - for m in base_maps: - if m in maps: - maps.remove(m) + maps = [m for m in maps if m not in base_maps and m.get('name') not in base_map_names] if expected is not None: if len(maps) != expected: fail(True, "%d BPF maps loaded, expected %d" % @@ -770,6 +768,9 @@ ret, progs = bpftool("prog", fail=False) skip(ret != 0, "bpftool not installed") base_progs = progs _, base_maps = bpftool("map") +base_map_names = [ + 'pid_iter.rodata' # created on each bpftool invocation +] # Check netdevsim ret, out = cmd("modprobe netdevsim", fail=False)