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: 11961135 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 BEEC4C4361B for ; Wed, 9 Dec 2020 11:21:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76F402343F for ; Wed, 9 Dec 2020 11:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730680AbgLILVS (ORCPT ); Wed, 9 Dec 2020 06:21:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38012 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730277AbgLILUM (ORCPT ); Wed, 9 Dec 2020 06:20:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607512725; 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=io/y1SY8pb8fEGtcAgjrbeoKAla9xxEW+UwwjggL/YAhnOBOT0/h6eVjn8rgG2awB9yRQV rrOA5tLQh+E2kNP1uIooWZbF31yYxDOu8mGt4FK/AO6U/PQ4C5z2XGa/qAm2J299ns4YSN C5m2VtCjnibnKRVyVCxqiWb2J31VkVY= 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-269-kSpqneWCOY6ro7BCz_kibw-1; Wed, 09 Dec 2020 06:18:43 -0500 X-MC-Unique: kSpqneWCOY6ro7BCz_kibw-1 Received: by mail-wm1-f72.google.com with SMTP id k126so257233wmb.0 for ; Wed, 09 Dec 2020 03:18:43 -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=oODmYXPKTXWGkiiVQBOamvAJZ91lw/wiuROlUP+KM/yvtr7bbeMRzrxQ4XOygy4BvP 1IDk8LIq8T3MTm1OAbC0fYw40YOZL0Z20pLWHYeKmfAgF14pqyyRP82ezwOH+StPuLMF 6fnk3qFCXT6Ldn58N8Ni6s+WCRdqHr/HiBQA/XpiXk6wu6g+28MFR7Nq1ON69CxXgF/j Ub3WFbUQ0+b+rAQkaMLtxN2oCgmY2ajJR7VhK51MlFgKlfR2Hs3+iZ828csCpFv+ZSZw 41TnY1h7MKU2gmS0cyWUp3BI/B253Lbumxjfy5uVQrS376QrhBPpUhIJGRB+5lahagnh 2YxA== X-Gm-Message-State: AOAM533rNJgwy1eCfGGAdMG0n+b93XrtQcGxntfiI+rO8obCoBElgmgp q6mZk4A8n51LemxfzJhZVl+fzIEeFbqb/3LT/GTBaKmz/Av8N7ivtNhPe1ckOS/T4Lw0/mw8H++ 3974dw+vfTKUGZcZLHUKXTw== X-Received: by 2002:a1c:46c5:: with SMTP id t188mr2244423wma.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: linux-omap@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: 11961137 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 147BDC4167B for ; Wed, 9 Dec 2020 11:22:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D612223609 for ; Wed, 9 Dec 2020 11:22:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730674AbgLILVS (ORCPT ); Wed, 9 Dec 2020 06:21:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41429 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730244AbgLILUL (ORCPT ); Wed, 9 Dec 2020 06:20:11 -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-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-235-t9R6d6GINAeuzjWNjZHJ3g-1; Wed, 09 Dec 2020 06:18:42 -0500 X-MC-Unique: t9R6d6GINAeuzjWNjZHJ3g-1 Received: by mail-wm1-f69.google.com with SMTP id z12so423501wmf.9 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=BhxmFIV3dW7qvqkbpqUTQMLXl7n0b3BdrktUPpW1cAparuGbmsm8tNGYyEYGGyfek5 wqJIBws3YZO8kwhPwxjhu0YpNsfHTnE//+sOaaLrrxW2OA8vGhReWxIVCSKH9FHUlds6 PMLeeJ2Z6zNipxBtG0Wrv2YVOHLxhb4mBG5sgWkCkfbgURDR9MW6O1Y40qbev5fGZZEo MdhEakcp0DzsUd3UugCXBqjniUlzlb7KfLkf5MtN/ptIG6c1yRIMQ3QTBTb/yFuyIJNt gE8GRwaMXErrbiCc/3S32NuMauaHIf+mT+WJvDUigdmmI4+C60V6FTKQC8GInu34C+4X 6lIA== X-Gm-Message-State: AOAM533+IRCv2YvZvv0iiRaRNQnk4UKiUpZyIg8dZBJFNb+7rOpTfTBM q6YSJ3xTqOBz3rXawlCw8QZqgaj33Ynz674SmsBuuHxIUbIp8Mo/4vucTwr3TyHb0pmLxSSn9h8 1QRHFOnOEKKUm6/Ww6Cyrhw== X-Received: by 2002:adf:f08a:: with SMTP id n10mr2125745wro.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: linux-omap@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: 11961139 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 A35D1C19425 for ; Wed, 9 Dec 2020 11:23:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6579E233A1 for ; Wed, 9 Dec 2020 11:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730385AbgLILVR (ORCPT ); Wed, 9 Dec 2020 06:21:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55370 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730345AbgLILUO (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-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-OMfo7WNgNnmeY8udfhV79g-1; Wed, 09 Dec 2020 06:18:46 -0500 X-MC-Unique: OMfo7WNgNnmeY8udfhV79g-1 Received: by mail-wm1-f71.google.com with SMTP id k128so427464wme.7 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=FrbbzyuajwLDYJaodh+IMxwIFRgA9V/4BQcP5nvgn95yPtbrOTJKg7XyhsbQp+oWOF MC/oj5i/h4lGgmWCyrR5pToTZ7r6HeELayEf0ltbcuMYY/SFtuVUAQ4oYnq4riYZiF1G 36mAxCGm3ZN2/OGIYWOtWQyLJFfW9m7vwENS89YRQFoTUU9Snk2s4Mr3dF0zvb3VHBX4 CpsuUo3KYVpGJD4hmZnOxmiVD3/TvuC3fOO8CNtizuOV5ruiSXyFV7Vh18urVobtDWj2 rqVC7S4xoWca+eMHh30We62Ho4plLHkayJ+eofAy3AAa6jQ87rfHFkdsczUk5kkEajc0 fywg== X-Gm-Message-State: AOAM533V7FSUb5P3Hdb6f/mAEowEUm0wmT8/Kz1+9U7X91/Z8IccCP/0 txook3Syqj0WlPFWAg6ygymsfesNKoRcVkiZEhJN3+euGC7TZ20iMpOr6CeLZu/u9cJpMkxHJPD M1ITo8rdv1OJ4V2bAyT222w== X-Received: by 2002:a5d:510d:: with SMTP id s13mr2170600wrt.380.1607512724563; 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: linux-omap@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: 11961119 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 2DD08C4167B 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 D395823433 for ; Wed, 9 Dec 2020 11:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730595AbgLILUT (ORCPT ); Wed, 9 Dec 2020 06:20:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52974 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730354AbgLILUP (ORCPT ); Wed, 9 Dec 2020 06:20:15 -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-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-5WR-ydJTPyeHIIkTi90dNA-1; Wed, 09 Dec 2020 06:18:46 -0500 X-MC-Unique: 5WR-ydJTPyeHIIkTi90dNA-1 Received: by mail-wm1-f72.google.com with SMTP id f12so430359wmf.6 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=pCpnWNfqZ4rbm0/y6w2KinADbSDsR4o9jLpkdBLpgPm2qsvi1kKY5NjJOXlrYpXJwZ j/hrlSJgxRTskUp9U7xII/SfstUI7VVc5Azsdzsz430EO7PAweI4CADhieh+Bu5MurPO l9eGQBcuZ3FHQ+RY1Q/JhPGl877m8NeT+ObNXIhXZ2s9x2HfaDzaNsIqhjwzYWgs7QAq xVWbpmVd91yBnjGKoHzZRu/B9mzHpQV+BNOesbiK2P6ziItGn3rdTj02iPwYfTNIXr/1 q1h+WLETqSZ6PPrJD5mOlSiA5v7D8MCRNmSYSgkGtQCZtPUv8W0L4rlfAxbroDlFZmu9 KC+Q== X-Gm-Message-State: AOAM5307PZKAxG12a0L2fSj6D+SFbNIvYknWcsynOKzAsmgkvM91JwXY e+jr7J4DeSyP6/FTInaQcbwAp3RAJ7BHXTLln2RDaDgoSqN7ytFEkq+AZsInaKMnnHnliDMmzpT 5v0s/xWVrMU3pYYtwh40KYA== X-Received: by 2002:a5d:6105:: with SMTP id v5mr2065766wrt.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: linux-omap@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: 11961151 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 ADC0FC4361B 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 8294023B7B for ; Wed, 9 Dec 2020 11:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730664AbgLIL2c (ORCPT ); Wed, 9 Dec 2020 06:28:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54527 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730633AbgLIL2c (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=1607513225; 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=Rsgik8NyiOdJ+bU1wHPrYt17GP69RQYhSR1gWklejo/zJWhEZf42c54dxhdzoZvArwth1x a7S2L1QzBv8AlrR5UhzXUioZO1g3In8LtarAt01S/qnNDpyXyimLLORjBaaCwgttWuFewz skJHZd3zCyzh9x14bwgD6u6O7VuKvYc= 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-284-W5nLK4SLO22HzQe8CLdaAQ-1; Wed, 09 Dec 2020 06:27:03 -0500 X-MC-Unique: W5nLK4SLO22HzQe8CLdaAQ-1 Received: by mail-wm1-f69.google.com with SMTP id k128so435960wme.7 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=mJIhV1ZxG1UVk9D9YnZY+bOgxCrY5XCaLAPAdeYzfe/RY8g1XY0sf2tO3ETu0gDh3d YyGBUPk+pd/X3T2FEIx57+cPbwLHjyF/IZ3XCX8jgJ+vjxQuPdftMCEkO/A5jnGtgzfs eS4v13RSsiPeVwueGQS0Sg+TGg5/fP+oDtNbjm9YKTUksI8AbY6/5oI/6Gk7MEXoHfyd TxDeGLfITHr9hRyzrE10OkTKdbmEAKHN4BDBgizACRi4IGuLIH0H9aulK7Mjz/2NCuCy rPBRQiCes1NWMa5dzJkQyut+0+xkwbqdiK11F9jJJsAI0DKKRYwrrO52PZOIb1BdHUFo MvPg== X-Gm-Message-State: AOAM533VIUWsKvPCLIKwaCh9JdUHdNhGFiQXi+qtVNrpRL4s0Cc4zleC CybpeOYT/cBc3ImbAemSRFLApF2nKEOpJsOCaW+vgNq6bzmy43IyzTsYDSF7UfW4gkcOX1Z1WmZ U71Sptnv/bfd6+Pkd6oBPBw== X-Received: by 2002:a05:6000:11c1:: with SMTP id i1mr2205357wrx.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: linux-omap@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: 11961123 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 7A0CCC4167B 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 304D423407 for ; Wed, 9 Dec 2020 11:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730657AbgLILVR (ORCPT ); Wed, 9 Dec 2020 06:21:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36849 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730521AbgLILUR (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-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-jGmUhyn6OjGqmgEcsfYzjQ-1; Wed, 09 Dec 2020 06:18:49 -0500 X-MC-Unique: jGmUhyn6OjGqmgEcsfYzjQ-1 Received: by mail-wr1-f70.google.com with SMTP id d26so328986wrb.1 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=V0GDytAikYVqX0evrkDMtbxJ64et7a4/B2xp9x0VLMSuQQJKOtZaERZVBFm7V163g+ b78UkDqEGK9rfEK+sf49+gk9pBdtsm4BqNTVz++aZXihvSktRDWIEk+JUM1gXVe/CoLk +868HZNMF4dnV13AYp05utGjsmTurM9hN1XCcn4zDQ3FF3DJm011E71Ok+KC6b8bsI/O p9fNP783adte1L7RBU6qv/+XbBQZDCqjsrjtIW6w7NeukP5AUk8DxaSo+oA3XRST4VUh c9q1FnjFQHmJDGu8/s0BTO38zXBZxts6VDCf7dFgexC/HN29ns5S56G9y6esUwzWDXjR EQKg== X-Gm-Message-State: AOAM530elNqipY3EuaIl0NJag1wOFfczHbVH3W7M3TXx9I0r0i0DO1lO CAbOQCPlAz4SGldAhH2WzAjCIZcaZa2d/OazgB6moZ3A9yfHGX4x0ea5O4r1Dqyy8k2VsyulbUX I9sEbbbik2c43eBqzuSqzZw== X-Received: by 2002:a7b:c24b:: with SMTP id b11mr2243678wmj.168.1607512727668; 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: linux-omap@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: 11961121 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 8804FC433FE for ; Wed, 9 Dec 2020 11:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5215F23407 for ; Wed, 9 Dec 2020 11:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730358AbgLILUT (ORCPT ); Wed, 9 Dec 2020 06:20:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45445 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbgLILUS (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-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-ojNM6W_KOeaOdd8ElDKIeg-1; Wed, 09 Dec 2020 06:18:49 -0500 X-MC-Unique: ojNM6W_KOeaOdd8ElDKIeg-1 Received: by mail-wr1-f72.google.com with SMTP id o4so523187wrw.19 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=ggeOzlf+UXgazIjgxjewk5PjCZoY/c+npkn6yxHzsejv3OmUppR36fEEADbAuVHYB0 mqXqrEUvzI5A4omIoBRDvkBlS5EkObX+V7RlSmOwxWnzr/01YiOV4WdIeSoqbvA72qeY DMorDZ+IifT6Yj2PbDIsfWNzjC4JTXvL7vYJeNCCshMDQvUJ+Kl/qqh6vVgk1MDDBTau 5wUQZ6Yfv90PtdtJi64Z7H4rUklk3HEFgurXHKBv9vt5PLJ/leFRzi9vFH+UZb8WVEZl VgdzSAuStqD4qrDjIVUe0WXXOxWXkKg/6XQL2r40uyFmtDHFUPywMELCNZTNy6Wq1I9f coxA== X-Gm-Message-State: AOAM533JIwNnUu1eu/+tG5cP31Nw7CmwG297IySH641bz36PUeOE2U2h 4mRj+CpK+U+7askteah6cEADAeAqWjeyPra7IRBZBna88/ImlHJuaBh8SCMuwqRIQ3Yufqo3Joi Y4fZbxQ8OeASQI/bkdQuRkg== X-Received: by 2002:adf:94c7:: with SMTP id 65mr2051397wrr.423.1607512728445; 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: linux-omap@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)