From patchwork Wed Dec 9 11:18:39 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: 340864 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=-15.8 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 E76DCC2BB40 for ; Wed, 9 Dec 2020 11:21:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC883233A1 for ; Wed, 9 Dec 2020 11:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730671AbgLILVS (ORCPT ); Wed, 9 Dec 2020 06:21:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58567 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730323AbgLILUO (ORCPT ); Wed, 9 Dec 2020 06:20:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512726; 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=ICznRmJm5dVUGmr9DiortfE3N0uQK/Rp9N47GmwoLqA=; b=M58TPkBS21hyA83y5kVHePibD8+ofrJUtA7kmLQUMaPvosvG4r1w8nqWmbCWl99glXFqlv 40mgHk05FfXHDPThBfX46OninFJigSF39M/lT2+jNj3aZom0W1Icye7M6y5qCjBvsGr/K4 xNuJv+DoPyyQaL3NpEvbt+fGw/if/S0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-UGzjFxmhOSqK72Y0TndP4g-1; Wed, 09 Dec 2020 06:18:43 -0500 X-MC-Unique: UGzjFxmhOSqK72Y0TndP4g-1 Received: by mail-wr1-f71.google.com with SMTP id r11so521544wrs.23 for ; Wed, 09 Dec 2020 03:18:42 -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=ICznRmJm5dVUGmr9DiortfE3N0uQK/Rp9N47GmwoLqA=; b=QCEwMgKwhMV4d0TJT4xJL+FmnuiHdol/s3H1mh07pk/tYKz87IhImKiH48WgNrO7IH CFKZayI+4UA+7dpcNN8qv5TzvYtBobZnYTs5sNYIXbrc2NLGRe2Lc0mUjJJ8601fVveV /IK4isAUvo7jaSJHmrNRF/eI7GJpd5HdDtnN8xVQX8e6mer2RLTWSLu9lQ4zjTHxl184 4mFRXW1/NMtSRrkJAaBEBlaMkakFhlT4NWqOWOvrIHdddrG+WYcaSCtEm/6VUJIiJ2O/ kEWJuvSesE+aGA8UZfy2/BN4/lgCsdUMf1ROSg4c3splv7Bp1VZVBFTtcC9CtmxFCDqk 0SFw== X-Gm-Message-State: AOAM531LC/uDG+Zp6sq6lrt1NI2JeiSA1NGzzqVlCfsV1Pu4HTYGG+Xd JEBfmW0Ne3fihfEY1DC9yNe5GDpgxmWxOc1Aboo0lWe30kuRuRiitbXgFRaOGA77oHuhPrVAkh0 VbXittxedAg3zVXrL X-Received: by 2002:a1c:46c5:: with SMTP id t188mr2244429wma.3.1607512721547; Wed, 09 Dec 2020 03:18:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsjN8rtB0x2Qe/UzkwKnGOYovEgAud1os2UtZyiOyp7h6thRolybgYwGlOHZ8V21PuGhd/pg== X-Received: by 2002:a1c:46c5:: with SMTP id t188mr2244346wma.3.1607512720752; Wed, 09 Dec 2020 03:18:40 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id g192sm2711608wme.48.2020.12.09.03.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:18:39 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 2D136180004; Wed, 9 Dec 2020 12:18:39 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:39 +0100 Message-ID: <160751271909.104774.6106391152070643541.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs in net_device") 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 Wed Dec 9 11:18:40 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: 341753 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=-15.8 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 A2FA8C433FE for ; Wed, 9 Dec 2020 11:22:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CA2E2343F for ; Wed, 9 Dec 2020 11:22:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730693AbgLILVw (ORCPT ); Wed, 9 Dec 2020 06:21:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30211 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730161AbgLILUK (ORCPT ); Wed, 9 Dec 2020 06:20:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512724; 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=s8DLLPviF9h72fPL9/Hm3sEntx53yIBaT2WZkb5ZEsg=; b=jKoOkqandHWLIxwUNUHx7uBwbWKXF5lcVO6GBtYbgaNZgOARf+St3NtvjSJjX6AXwztAdW Isj8naeoY5suk+dccVjjiMpCceiM46zoRkJteTeo8nRJXX2309q1tI0amRa+Ua2cv/iO+m PfiY9+x2pX+fohuEPXvvl+HWPwRa4yg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-149-HwSqYjuWOYaPLSuIq364wQ-1; Wed, 09 Dec 2020 06:18:42 -0500 X-MC-Unique: HwSqYjuWOYaPLSuIq364wQ-1 Received: by mail-wm1-f70.google.com with SMTP id q17so257040wmc.1 for ; Wed, 09 Dec 2020 03:18:42 -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=s8DLLPviF9h72fPL9/Hm3sEntx53yIBaT2WZkb5ZEsg=; b=aPMm5Qw/ZdQnvmIvM19orjDkUQyeKMcn+FcxIgsal3CQK7AWNHsiSFk8JI9XsKi3JJ HcKqlD548x8URmiKvXxWhiHwmqr2eWYGPTLYF0zuebr3CibPG90GZnMfTBrff/2pLeSq TD0rNM4lMucAqaNWYjE6ULeZTju/2VHvMQNQr4FBlh4ltMCZrpnchkc5D2MW+3ig/GjD 8V54LRunrNFD2ak7bB6W8pvU1TdnahPX7LJvtO5DRoaNhtfpHSzcYxz8hwCrxlUnDvVd uy3sWx0z3Om+XXWX+c+6y7eo21IVzq/r7O78TVy45f8cg5CUt49quL5L87tZITr9ja3S eH8g== X-Gm-Message-State: AOAM530JvoFYjBh4kILeg0lquR8i2J7sh0xeyOYzDSZ4P3VN/8nsCBIe ZzajFDHFc/hOUhxU+xMTIc4O6UoUHkZ3jUKKmWCD1tPrE4Mc8B2hXijtEldPMj8ZJBCfcjhOUx8 /ZCLbOkMR4jt12gqd X-Received: by 2002:adf:f08a:: with SMTP id n10mr2125744wro.142.1607512721744; Wed, 09 Dec 2020 03:18:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0+3pof9UTo3XYyH121XixbuW1FBW+oG2DWZ/KmUgwij6v8Q7tM4hPPFxpP2i3YuHZGgj9yQ== X-Received: by 2002:adf:f08a:: with SMTP id n10mr2125719wro.142.1607512721573; Wed, 09 Dec 2020 03:18:41 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id l7sm2721839wme.4.2020.12.09.03.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:18:41 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 4074A180068; Wed, 9 Dec 2020 12:18:40 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:40 +0100 Message-ID: <160751272018.104774.8600625429164016287.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs in net_device") 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 Wed Dec 9 11:18:41 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: 340863 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=-15.8 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=ham 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 7E6F7C4361B for ; Wed, 9 Dec 2020 11:22:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34BDF233A1 for ; Wed, 9 Dec 2020 11:22:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730359AbgLILVo (ORCPT ); Wed, 9 Dec 2020 06:21:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28412 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730328AbgLILUO (ORCPT ); Wed, 9 Dec 2020 06:20:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512727; 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=rs0UkbehwBsDPQ8obfGEfwu5WvgJdipXIe4g7gP7tw8=; b=IU4e68LV5r57PTlmeHz9OW3ggdMZ8W/YA86gnKzrDqnIead6NVtwWmKPg+GIpSqLJiO3vF WhK9UlEO8R/ed0Go5TfBzKntnnHjN6QktkIUjFlRwZ06hJCZXtUPgqZh8ueAto4eHAyk2K andaOL+czplNVrcFfhFzmy1I9RveG64= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-374-BWV9XXlAP1W-4yzCCc7U3w-1; Wed, 09 Dec 2020 06:18:45 -0500 X-MC-Unique: BWV9XXlAP1W-4yzCCc7U3w-1 Received: by mail-wm1-f72.google.com with SMTP id f187so434288wme.3 for ; Wed, 09 Dec 2020 03:18:45 -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=rs0UkbehwBsDPQ8obfGEfwu5WvgJdipXIe4g7gP7tw8=; b=O2qiVCX1fGlTQ7RzEqVAzDEexHKV4IWZ3PKNN+siW4MJ/d9rrwsnVDkI8Mjk8IOlIe AtNGArQI999F6ajawhPcbVX6UHIFC0Fhn7O02PCbbnTDD6v3kbi80o+xuhq/mx9r6YBC ABAh3JTjv+pRJPLSAZ3D7rZW+GqvZD6lBPz7ZhM60qhtzdvnTKNfzmLwhvB8ABJ30Mwx ZdyeKaOdeEuQrb6ySJz55fonZjXv3OBM99Z84keMhfnUp2IbxM5R8gw5VtLrcJ3o9KRw 5lb4TBHs8Rt0gvu7uQ4MjHfKYsxqq4EUQR1mo57vqhUdQIGWoJv9UeQKDZsYXTjz8h9U JSTQ== X-Gm-Message-State: AOAM533o8FwKtQ6+aXD7uWMj3VK/Puem1VofJcg6BFjBcHP9/I8y6KkK hyOMrU1GpFyL2xFtnFA56hMJXO/JP1T8THT3VRRuwes8AIydGRIuP5VXq7EeF0B4kpdFUpZWOoF 7v19MZmEQovXHIcXU X-Received: by 2002:a5d:510d:: with SMTP id s13mr2170607wrt.380.1607512724564; Wed, 09 Dec 2020 03:18:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUFTLJxM7MK6E7FYWlZphsYY3r5n+tLpJNDziNUu+XqdM68+jgoEImmuHFsl38M0dCcQR5CA== X-Received: by 2002:a5d:510d:: with SMTP id s13mr2170585wrt.380.1607512724413; Wed, 09 Dec 2020 03:18:44 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id w17sm2785271wmk.12.2020.12.09.03.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:18:41 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 56A98180003; Wed, 9 Dec 2020 12:18:41 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:41 +0100 Message-ID: <160751272126.104774.9977428866761146011.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: 6f8a57ccf85 ("bpf: Make verifier log more relevant by default") 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 Wed Dec 9 11:18:42 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: 341754 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=-15.8 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 DD2DDC4361B for ; Wed, 9 Dec 2020 11:21:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B28AC2343F for ; Wed, 9 Dec 2020 11:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730514AbgLILVb (ORCPT ); Wed, 9 Dec 2020 06:21:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49506 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730359AbgLILUO (ORCPT ); Wed, 9 Dec 2020 06:20:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512728; 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=vHtRZEbZli1h982vP/LiKLhTpQ4S7yCfLA6svbBiHq8=; b=ihcgPzyeDjXEJNdIEsYIUpZCEh+KM3yj5P14vF+GnVt3GgoQHWEzrbkoTPsmwMdnHq/NeH eWjxqL9LENWV+nI9WuREbN1RWngGvOJ9QbHWX7cPADfpJFGQvUNfvr6RT0fd2waDgq2cIa zTopSukcrpn5VQnCFxian8gLDtTatFU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-570-DU_sVVaiPt25_pUz1V3mBQ-1; Wed, 09 Dec 2020 06:18:47 -0500 X-MC-Unique: DU_sVVaiPt25_pUz1V3mBQ-1 Received: by mail-wm1-f69.google.com with SMTP id v5so440248wmj.0 for ; Wed, 09 Dec 2020 03:18:46 -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=vHtRZEbZli1h982vP/LiKLhTpQ4S7yCfLA6svbBiHq8=; b=scT58tV28cRUNW/MqmEcDbIemu+hOZpPdeKyfgSrpqTpwLvDdkrHnmBgYn3AdPn9sj TNDudXJHYXc//0d7CVlovxhfRz7Ub5g1fw/qF/FOUrnzpTCw6nyapMVrhGmN+9n8G2m3 RNK30NrKMm3HEKkKpugOYw1NerjMHE1eH7o+iCgorwozliVcSa/Od8prj0mhYYfQQM3u CzmSse4sY1ncyzPnzKKLlv6hjesvY+IpeiDvhBsTdF/oaHip0xoL9i2u3M83yad7Te5P Ggr7odVTawizSFTs1hwNjCMsKqHmb2b/bgaXluX0fE+xZT1S/7kxUV6g7KAsIicEP/ft gMWw== X-Gm-Message-State: AOAM53282cMbQks/6yHwmcb8SIg6ziseVOnXVsOcolZRxlhy2IbYsJr6 0iWYgBgzjCSJC3bykYpiuN987G3R1wQVXgE09xCVrF1PZ/zvxOfpMDL9DDalX6rwrVm2UUNBCQ7 aJ8IUpIkWkaK7nadm X-Received: by 2002:a5d:6105:: with SMTP id v5mr2065760wrt.178.1607512725293; Wed, 09 Dec 2020 03:18:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxB6RTggDKWVmluBFuFp8fDNooX99A3rM0VufkhCcyMx9n9rSn9l50zgZfXiRLkF1cVaFOU/Q== X-Received: by 2002:a5d:6105:: with SMTP id v5mr2065727wrt.178.1607512724896; Wed, 09 Dec 2020 03:18:44 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id w12sm3172176wre.57.2020.12.09.03.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:18:44 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 6B110180004; Wed, 9 Dec 2020 12:18:42 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:42 +0100 Message-ID: <160751272235.104774.3114776457666871889.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: 6f8a57ccf85 ("bpf: Make verifier log more relevant by default") 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 Wed Dec 9 11:18:43 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: 341750 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=-15.8 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=ham 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 C3DA2C433FE for ; Wed, 9 Dec 2020 11:28:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99C8523B85 for ; Wed, 9 Dec 2020 11:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730654AbgLIL2c (ORCPT ); Wed, 9 Dec 2020 06:28:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26959 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727970AbgLIL2c (ORCPT ); Wed, 9 Dec 2020 06:28:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607513224; 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=MU7CQgT+A+S9BhvCz6Q80+yj2qZjKz+oqKrOC0MV6ss=; b=Sl9KjYciaI2OhboUZCNLlBuEdWGblawvU7OVs//rm2BJlykSGsDn7iFvwUjxb9bxTvQk2r uwEhJ8rT86HaYYaHyYAV1LyG7av4MTL+/7T3DYntvKI1caJyc5Hokp+2aYQo9O6pc1Ugns yDDiSuiKfWfPjr0JlrDSa6/SM/BBWCk= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-450-LHNck6E-OV-QBeTvgpHvdw-1; Wed, 09 Dec 2020 06:27:03 -0500 X-MC-Unique: LHNck6E-OV-QBeTvgpHvdw-1 Received: by mail-wm1-f71.google.com with SMTP id k23so447629wmj.1 for ; Wed, 09 Dec 2020 03:27:03 -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=MU7CQgT+A+S9BhvCz6Q80+yj2qZjKz+oqKrOC0MV6ss=; b=F2Uyy0A23xqXeZklUh1SAuQsJs1i1ycQvvMX+N1/GzSP88vrcuQIVED5sYc0Dccv0S KTjseS6d5yfU/qCHI5Fp3wCt3ExfjOGZu3brMG2AdaP5CQ+MvgtUpyXN8HArkYfrbUHn rb8uBNLqZZj5M1hsf5mK0DPxu3oxIJq0/9gVBLiWDjYKIwBdVEpRSFf+QIztFPNCrLSo d4iAJ05i3LF4wCXxeo26AB3ov+XFP3OQR22V464OyKgQTv7/JRtxL7Q3OBaA20zdkZCm cQLRiddIGOlhmOrqo42jJjbFGUCmR6TtnPIltQ0E48NPiTaSrBRlPsl5LJNnTvQE++I0 BXvw== X-Gm-Message-State: AOAM532HvSEmSHQxgKTobH9sNG4Y8lDCZMnIJFUcA4TQpIkUhfmq0GFS wb29mn5ynuuUmXI+72VU0coqT42Fv8IOERGlFQkXCixi96ZewBt0+hW0WE3XIFC+JftOGpBdG4J gJ5Tra+I4PiaaQXxq X-Received: by 2002:a05:6000:11c1:: with SMTP id i1mr2205358wrx.16.1607513222224; Wed, 09 Dec 2020 03:27:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4kEQwZHME/Wlz6Nd9XqGg5QzCY9JlMn7Oho4DCv+zv0U6Ck0N79UYtSLkLkEsPaoBsptJ/g== X-Received: by 2002:a05:6000:11c1:: with SMTP id i1mr2205334wrx.16.1607513222022; Wed, 09 Dec 2020 03:27:02 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id m21sm2751701wml.13.2020.12.09.03.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:27:01 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 82C04180068; Wed, 9 Dec 2020 12:18:43 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:43 +0100 Message-ID: <160751272344.104774.16243874919103350259.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs in net_device") 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 Wed Dec 9 11:18:44 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: 341755 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=-15.8 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=ham 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 42A42C4361B for ; Wed, 9 Dec 2020 11:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06AE3233A1 for ; Wed, 9 Dec 2020 11:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730379AbgLILUb (ORCPT ); Wed, 9 Dec 2020 06:20:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39048 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730484AbgLILUR (ORCPT ); Wed, 9 Dec 2020 06:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512730; 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=paX/7UAlKmbp58QFD0gyJzQyU0HAfzMzkzakh+VAmUM=; b=Ut2DG7fg1pAhVZlbcjfgf9bg2WexlR5jAuFY5+gr201Bov6tKKkI3e6GCtO3to+wCKIc7G fM+5JOXY5iTBfXEp9iqXD3TTzw7mZ0k0n7pKaJ8GW3Iw2mf96wNuhWvAd90lVJRkDHt+si eMtScq1n+Kq/kCYfJk37lq8zflA1L4Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-yd6YqGwPODO1RTNB5tEuug-1; Wed, 09 Dec 2020 06:18:48 -0500 X-MC-Unique: yd6YqGwPODO1RTNB5tEuug-1 Received: by mail-wm1-f71.google.com with SMTP id f12so430405wmf.6 for ; Wed, 09 Dec 2020 03:18:48 -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=paX/7UAlKmbp58QFD0gyJzQyU0HAfzMzkzakh+VAmUM=; b=CmDQcZGWE8rTAfOYLpUXjrXVLuO/7j155JVgElLjUbrhO6UC2EeYd0fuFnj61CrPGI ijfv5DXlSyjCDlzAmz7cniP2BS/Q2JxOc1haxQw/TKeMdxzA8bPjUCB/LHHk6JPyk9g+ 5B7A27pvRXQYsb2bJmlC1W4N+ceN3Vs9Q19+KgzhrX4eOMQF61ShAVYRKul9t8DSSWBe 10MiTH/Jz87pD+vAtboUZbBSuJ/bJ9eoZdYJQ/4yrcHUMkZrhIyJmj0ur2+XWdUcpbIl 2i4GBMModSvWEcnBDaNHMZ7OdkeVbg41Vey7zHOh7WXKaH9fBv/cGhpdJwfpfSIWeAQC wbQg== X-Gm-Message-State: AOAM531Ro8704f1UPOVjEcR1+79RLTf2DvwWkP8jB6piQyvKygonkYnG Q7NmOayITZX9CGTUE2N77T6g0WHPm7HrSEQK2ymJ41G35Ix/rkxRyAXU4WOhH2r3cIH1dDpIYbv 9UU0Jqnoh/9qJBEvp X-Received: by 2002:a7b:c24b:: with SMTP id b11mr2243675wmj.168.1607512727667; Wed, 09 Dec 2020 03:18:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIQXSKeI1KTNfWKjLVO4BGjQ+RlzPjAi6h6dYdW2N/q7Mg8WugtYj7pqH+1ymMCaAkwmoJxQ== X-Received: by 2002:a7b:c24b:: with SMTP id b11mr2243632wmj.168.1607512727350; Wed, 09 Dec 2020 03:18:47 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id m8sm2867185wmc.27.2020.12.09.03.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:18:46 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 96E5E18006E; Wed, 9 Dec 2020 12:18:44 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:44 +0100 Message-ID: <160751272453.104774.14088086677950503174.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: 417ec26477a5 ("selftests/bpf: add offload test based on netdevsim") 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 Wed Dec 9 11:18:45 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: 340865 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=-15.8 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=ham 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 42C66C1B0D8 for ; Wed, 9 Dec 2020 11:20:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13A8C233A1 for ; Wed, 9 Dec 2020 11:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730600AbgLILUT (ORCPT ); Wed, 9 Dec 2020 06:20:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30487 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730591AbgLILUS (ORCPT ); Wed, 9 Dec 2020 06:20:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512731; 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=rdg7j0aoyv9xFKjTcy/3BS13uPnBUVbkHjhjaK6AxE0=; b=S2108bF0cDW7RKHlAK5M0foap1uuDcDBnqQAqkeL227qJqN/RpEan2nhYYIL9B83aKfmNn GOVgTw8bT3qtfCjygcy2hV1p99VuRASoZAB/+HLfpBSR8gpSr3q3ZCevcpV4G+yrG7fdFx 2w2915SF3YL0WrG0hT3AZv56pRXxspU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-Rz1yVDkDP--TKVMHwE4HJQ-1; Wed, 09 Dec 2020 06:18:50 -0500 X-MC-Unique: Rz1yVDkDP--TKVMHwE4HJQ-1 Received: by mail-wm1-f72.google.com with SMTP id v5so440314wmj.0 for ; Wed, 09 Dec 2020 03:18:49 -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=rdg7j0aoyv9xFKjTcy/3BS13uPnBUVbkHjhjaK6AxE0=; b=Pr2O7/UHcHv9ckVZ3Qps6FjoCCGjRS+TA2pbaBSgQS8UHr/4y4dzTzhz/NrJrJvHeu P0dFzyAfT7FbGdVjsi3mqYbo+TELKDyGu9WKhH0edWkmf57vjdEkrkFEHcixvnKVNdpK 9C0Vo9jLVuAOwC27yixBj72NbmNofD7+Dyvoz9OtEb74fLAEgQeNhDEkSXSzGZKl+BRn aa+h8xKOWk+S9AYmjM7HMsY5pv3PUBH3ltxPhaUWS/c9UQbZ66RIqmQfRWB+49dQUByl H54JiRkWqhPJ8CbwrA4QhF44tl0kupRnxR5l9/+7DVUxAFGBkQGH52QuilWINekFxyrV uCgw== X-Gm-Message-State: AOAM530zaDGOJMh8wxa/dLhwSid3LZf6gHpiABXbdpczlInTciyYFE0q tFe977FDoIGF0QRa5/1P51s3bJKa1mEFNJLtwtyV61QXL/KbrawHi4bdMH+c8oHAADwiXVTuOAR /pbOrYRg0SP1GBAkg X-Received: by 2002:adf:94c7:: with SMTP id 65mr2051409wrr.423.1607512728449; Wed, 09 Dec 2020 03:18:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzByUzK4whQvOkVhb3u3QIf2WOJnMrhMKCWhHgegG+om0p+KZUQ0AX0otTOa/8uQfiNtIENbA== X-Received: by 2002:adf:94c7:: with SMTP id 65mr2051355wrr.423.1607512728038; Wed, 09 Dec 2020 03:18:48 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id y2sm2663184wma.6.2020.12.09.03.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 03:18:47 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id AF47A180004; Wed, 9 Dec 2020 12:18:45 +0100 (CET) Subject: [PATCH bpf v3 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: Wed, 09 Dec 2020 12:18:45 +0100 Message-ID: <160751272562.104774.12715774646876868194.stgit@toke.dk> In-Reply-To: <160751271801.104774.5575431902172553440.stgit@toke.dk> References: <160751271801.104774.5575431902172553440.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. Fixes: d53dee3fe013 ("tools/bpftool: Show info for processes holding BPF map/prog/link/btf FDs") 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)