From patchwork Mon Nov 27 18:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13470090 X-Patchwork-Delegate: bpf@iogearbox.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jgqw2zp7" Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 230E019A for ; Mon, 27 Nov 2023 10:20:59 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-6cc08c794d6so3690655b3a.1 for ; Mon, 27 Nov 2023 10:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701109258; x=1701714058; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ydnfnbaZl9nHPWkOGgpx08lDV2EyFsRWeCshoFltBsk=; b=jgqw2zp7PVomoZXT5TJe3T2CHV1TnX1ONNnGUQfLI7zof8V7SZaWWDjFDN594jmbGz fwrCbt/x3zQKP/2O2lsAQ/lw6UjuBorc9zsKM2Cm3fXJXCnE90fMOJShzi6tx42JkTn+ oF1nmQ8UjlvJyqdE+hAYbBag9xMoYI05NQ++23Hlz2822HpuUwS3p2hmjLdajMgFXArU wwjomTzKRynFD7VLYL44FQH5r+Qv9NHHPc3ROlnFFO0Ku9FP42oPkMM8Emx6UoeNpZLb DpAGwyxxJNJ2pvz3Mu4LlbILFDWXgxC3RgvZwJCptWlt35PZ4cmwO0gyQB7lNQTyZqKM B8xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701109258; x=1701714058; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ydnfnbaZl9nHPWkOGgpx08lDV2EyFsRWeCshoFltBsk=; b=jJU4ZxXd/r/uj6RRiNTkqcUl8Wn2ACfZVFlcXmWjXzHe6IXd12Rj4khUYmCAIWR6h0 drBSjJzSVsxGxI5ZLC512zKNjXJMFYWorR9iuJyMTQSF1qib1RyAGAkRWZwn502jY1FA WCDiwl5paFuZsdylG8cUjzCKO0t8kHP5d8V4763AYN/QdHwal5hKJzGF9WyeOPSYDRkw xDbAk5H3tZdbk95w/IW0eEz92rYuwQuOco1kpe80qLWH67FdWwaTQrLCO3fMaA7yvEit g4MzEZkq+RNI4GBcpoePNgPe2sCTaDuqypblRfm4vShT/xH0ZYYHd26YoLwqNxB+8SG+ HrEg== X-Gm-Message-State: AOJu0YzfMX05ypoT+iCX0yl36LVO1SkjFh6LttX4yeVX74corBtOGJyv mD7GlSNTgluvteei8aJXXfTmL5ofDhQZIoqDLuaBhpr1WnIlJ9gJtX0yoHRpvufKkYa/KSz4RxI nO8kxgnUWvIRE3BVcaV6GjJ2Pn6DYPgYwgTUB4/yi7XTQ3Z6Y5Q== X-Google-Smtp-Source: AGHT+IFd+h3OIGKdssuh0l88ywYzoEwmOkvycRbvs1c01oZllUn+hNLFXFkXBPGEh0wjRNXJKDbOx6s= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a05:6a00:3911:b0:6c3:9efc:6833 with SMTP id fh17-20020a056a00391100b006c39efc6833mr3215705pfb.2.1701109258550; Mon, 27 Nov 2023 10:20:58 -0800 (PST) Date: Mon, 27 Nov 2023 10:20:56 -0800 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231127182057.1081138-1-sdf@google.com> Subject: [PATCH bpf-next v3 1/2] bpftool: mark orphaned programs during prog show From: Stanislav Fomichev To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Commit ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD") stopped removing program's id from idr when the offloaded/bound netdev goes away. I was supposed to take a look and check in [0], but apparently I did not. Martin points out it might be useful to keep it that way for observability sake, but we at least need to mark those programs as unusable. Mark those programs as 'orphaned' and keep printing the list when we encounter ENODEV. 0: unspec tag 0000000000000000 xlated 0B not jited memlock 4096B orphaned [0]: https://lore.kernel.org/all/CAKH8qBtyR20ZWAc11z1-6pGb3Hd47AQUTbE_cfoktG59TqaJ7Q@mail.gmail.com/ v3: * use two spaces for " orphaned" (Quentin) Cc: netdev@vger.kernel.org Fixes: ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD") Signed-off-by: Stanislav Fomichev Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/prog.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 7ec4f5671e7a..feb8e305804f 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -442,7 +442,7 @@ static void print_prog_header_json(struct bpf_prog_info *info, int fd) jsonw_uint_field(json_wtr, "recursion_misses", info->recursion_misses); } -static void print_prog_json(struct bpf_prog_info *info, int fd) +static void print_prog_json(struct bpf_prog_info *info, int fd, bool orphaned) { char *memlock; @@ -461,6 +461,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd) jsonw_uint_field(json_wtr, "uid", info->created_by_uid); } + jsonw_bool_field(json_wtr, "orphaned", orphaned); jsonw_uint_field(json_wtr, "bytes_xlated", info->xlated_prog_len); if (info->jited_prog_len) { @@ -527,7 +528,7 @@ static void print_prog_header_plain(struct bpf_prog_info *info, int fd) printf("\n"); } -static void print_prog_plain(struct bpf_prog_info *info, int fd) +static void print_prog_plain(struct bpf_prog_info *info, int fd, bool orphaned) { char *memlock; @@ -554,6 +555,9 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd) printf(" memlock %sB", memlock); free(memlock); + if (orphaned) + printf(" orphaned"); + if (info->nr_map_ids) show_prog_maps(fd, info->nr_map_ids); @@ -581,15 +585,15 @@ static int show_prog(int fd) int err; err = bpf_prog_get_info_by_fd(fd, &info, &len); - if (err) { + if (err && err != -ENODEV) { p_err("can't get prog info: %s", strerror(errno)); return -1; } if (json_output) - print_prog_json(&info, fd); + print_prog_json(&info, fd, err == -ENODEV); else - print_prog_plain(&info, fd); + print_prog_plain(&info, fd, err == -ENODEV); return 0; } From patchwork Mon Nov 27 18:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Fomichev X-Patchwork-Id: 13470091 X-Patchwork-Delegate: bpf@iogearbox.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XSfEGoBz" Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3C4198 for ; Mon, 27 Nov 2023 10:21:01 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5c203dd04a3so4771531a12.3 for ; Mon, 27 Nov 2023 10:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701109260; x=1701714060; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8SXL1ZpHESJB86RDSKmtn6hmopDrol5p5k12MS2Dgak=; b=XSfEGoBzGxoghNBN3b8moa1wagtxu5r+rIPZqVlt6B2KrDNVzWAaUM7Czs0wDev6Uc jP3bEJQ9a7ZC2kCEAVU9iSy7jx+CroVoUTRuJhwz/85eO6yStb3sHEGnNE5UXcmQQjwN yC0RPvBgJfFpfi1k66oBcazcdrIdBarkgrc7v7OKxLlGijXPj6+uRCxbAutBW1e2zZ7l BQA4xqy2rOGwC9hyV8+EROyvviSNLS9U3wrgUcMY4Z/jK8MGgJIcZ7DzCIQe/tbaRm63 /aw5V66KAnxfR/jErfwrkhzlOB+jmGTiB6eKEAuQXr0auSIYycoR5QvU1u/7xBbhP283 pS+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701109260; x=1701714060; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8SXL1ZpHESJB86RDSKmtn6hmopDrol5p5k12MS2Dgak=; b=fbCb7+EY1QirumNLd+uvcqvIkv/BSj3HicQg2yKbgZ2jwVH7J9ubTLDYxi2JU5Vwnk pH0FB1AuqL3EQ9CiZq4aBS2iMSF43PJDLl+oFsOQaoTGf/QhIFrYnqLl5IMojeJHuUr8 z+CujUaNtStzEUrnMjMzeImAEdf2wjFw0IaEge97BxqZ56qdn10ScXCGyl5mWLIa52TZ R7vH5nD5yYPg53QjN/hB+Yf344HWGiNqdV9rmuGFKTASTTpa8Fcq5OhX3MGD96alO2iY z1bbJNJcgtVGC8xbpsoHgDsjIC///fWCgOT5MD7F5eKuHEG8I+HHb0NqGPRgxofLL0k/ epdg== X-Gm-Message-State: AOJu0YxBaO/HOgxpViIwhXu1P9tuX/2Hc1Vu2z+G585rDx7oEYBs7A3B cU0UJ+LPgS04R78+hT/zriwb9jiAbbVLWClSfLsdDvp8Cl/PiOZkEkvJGgaogwveS2k2HPmUCOg j9yKP52GwtiN6nZl5F8hal3VWzs4ykeLcgnXGin0w8Jjx/4qAAA== X-Google-Smtp-Source: AGHT+IFwEEsbWOBcEc19xvpAH7GHsAzGC7dD+huV9ljjOK/1ZcscyzIva8g42aN4YlApSbKxowJ9m3c= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a63:6909:0:b0:5bd:85b1:da18 with SMTP id e9-20020a636909000000b005bd85b1da18mr1900156pgc.11.1701109260470; Mon, 27 Nov 2023 10:21:00 -0800 (PST) Date: Mon, 27 Nov 2023 10:20:57 -0800 In-Reply-To: <20231127182057.1081138-1-sdf@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231127182057.1081138-1-sdf@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231127182057.1081138-2-sdf@google.com> Subject: [PATCH bpf-next v3 2/2] selftests/bpf: update test_offload to use new orphaned property From: Stanislav Fomichev To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net - filter orphaned programs by default - when trying to query orphaned program, don't expect bpftool failure Cc: netdev@vger.kernel.org Signed-off-by: Stanislav Fomichev --- tools/testing/selftests/bpf/test_offload.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index 40cba8d368d9..6157f884d091 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -169,12 +169,14 @@ netns = [] # net namespaces to be removed return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns, fail=fail, include_stderr=include_stderr) -def bpftool_prog_list(expected=None, ns=""): +def bpftool_prog_list(expected=None, ns="", exclude_orphaned=True): _, progs = bpftool("prog show", JSON=True, ns=ns, fail=True) # Remove the base progs for p in base_progs: if p in progs: progs.remove(p) + if exclude_orphaned: + progs = [ p for p in progs if not p['orphaned'] ] if expected is not None: if len(progs) != expected: fail(True, "%d BPF programs loaded, expected %d" % @@ -612,11 +614,9 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None, def check_dev_info_removed(prog_file=None, map_file=None): bpftool_prog_list(expected=0) + bpftool_prog_list(expected=1, exclude_orphaned=False) ret, err = bpftool("prog show pin %s" % (prog_file), fail=False) - fail(ret == 0, "Showing prog with removed device did not fail") - fail(err["error"].find("No such device") == -1, - "Showing prog with removed device expected ENODEV, error is %s" % - (err["error"])) + fail(ret != 0, "failed to show prog with removed device") bpftool_map_list(expected=0) ret, err = bpftool("map show pin %s" % (map_file), fail=False) @@ -1395,10 +1395,7 @@ netns = [] start_test("Test multi-dev ASIC cross-dev destruction - orphaned...") ret, out = bpftool("prog show %s" % (progB), fail=False) - fail(ret == 0, "got information about orphaned program") - fail("error" not in out, "no error reported for get info on orphaned") - fail(out["error"] != "can't get prog info: No such device", - "wrong error for get info on orphaned") + fail(ret != 0, "couldn't get information about orphaned program") print("%s: OK" % (os.path.basename(__file__)))