Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp459320pxb; Wed, 20 Jan 2021 11:09:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYWjGKeiJ9e+p/7C15JJ8P/Hu63vyiXU0bKf3z0FJB8TlhcFJFCsl8JKNkLbRBtqn7CQYQ X-Received: by 2002:a17:906:858f:: with SMTP id v15mr6898390ejx.238.1611169782084; Wed, 20 Jan 2021 11:09:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611169782; cv=none; d=google.com; s=arc-20160816; b=P5CY3ThW9jkAQpdJKT22bCrDOs8iNPCRMjw9kX8GWD+vEBxcf2C6miMonBn+VzkC94 mVubKq4ogECIdm2KPLmeMuLZ9rBgoVI/0SssAIQS1TrOCVOdOicEpynDfrNOq//9fzS4 jstunI2qTGDTyyfbfuy85iXcUM+HdA2dHSasjNpQF2E9B/M+40tsOU8HA6MNh5pwLUG4 F3nJ6FCFlIqOgiiIXqa0YZaT83nKfVx/6uqabtzUTTgAfmxWWU7rc6TxdSksV50ZQFfG 5wHixu2X54zxytx/V7H+JxhU/CAROlI6+9q0ox8GSLarV24Y3MuMvJkU01GKI28ozbac yuKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fm0Hune4dNh4DOhGPxu2dYoVCrCb/uIZAh+4vIDWr2I=; b=X3XPJpHqxxOyejPtZ2o6czuErxQiCHk5Xp+3O79I3QNZcf0YEGyBUYS+gix06mRMlO s9tDuCEbZ6FXJG2bYoMlBC1dcJBeml7O5earlir7hC5Tf9AXd7quGm37grxeRReh/V76 Ltkc/H5a84z5/FcmGANkKW1eM2QPmyexGxd17B8SL77zDWJueKGq74n7yddyQ53v0r8V KUNNuHRE0nHrCDjbLCdCnI98F/GI8SQLRBhcLU8K8nvNI5r95bSm7Q/I/V6z0bkdqbp3 WQdJ40rQzN5OAcVT9l8kJKGVHSIK+eztFhnIT3Of6GK2JWQdkIZyLUgZVdVGT8o0LNOR Cpeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kVr0nUi6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si940370ejr.242.2021.01.20.11.09.17; Wed, 20 Jan 2021 11:09:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kVr0nUi6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392461AbhATTFn (ORCPT + 99 others); Wed, 20 Jan 2021 14:05:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390158AbhATTEo (ORCPT ); Wed, 20 Jan 2021 14:04:44 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 479A3C061757; Wed, 20 Jan 2021 11:04:04 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id q8so3982657lfm.10; Wed, 20 Jan 2021 11:04:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fm0Hune4dNh4DOhGPxu2dYoVCrCb/uIZAh+4vIDWr2I=; b=kVr0nUi6g0Bm5Cg8a06zoKCBxjsWFjviGBrGKpnbU/P+zXo0vucIbqa26agJ7qIWAG gB7VG8ZXr8MzYOPHzFIMSnYEtXR6e8/PTE3IYRcUwHpCmQ8qlr3/mBUoW6SvKMev3hnC R9AeVTXIhEFLFjwjh3Ldon+H3OTITvGBUZjnB3PmLsj6PNz1XzYYMoUrp93qN8tS3fzj dd8Q6+pEIjZEhXk4AoeZEVVgp1fmLbL5yb6HMGX4RHYmLEA5ouCe3e0utz7yf8URouxh NF1qQtzfLSHWCg9Rx3viBvLmnoBgXg76h3TcyQ6xvDiOFac+vkB3/uhrpByNb2LJQoBW JgWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fm0Hune4dNh4DOhGPxu2dYoVCrCb/uIZAh+4vIDWr2I=; b=EAzy2HoRrDNlnGPGL/i8xsDwcNaF6xdMwTP8uDnsClOtUxSzd6OsCecq04REZfE7yE iVBLhcjj2IjFwjVlSg5ph0E9xeCtXj0KS8IcD0cBSfMl/Lia28ULyxgbFBMHHN68d0UL QRYKVteQYjbNOwDOjDeQXYFh7dc3rCfkFYJIVaz7Qq0QHI27e8wncMYKZ9h9J4J6ey22 MRDzTfkuEvj+ugy0Z3bb4LsyV8bKo4+q3qssjpy3lZsF1ZFvZCbrGhCBFyZapYU32d2M Ld1UuEvdyPdoK5k5nqomdKeASxeNAbwsGIHWFvRCbFhvQs9UYe3IgBqq4/yuwAzdFc7+ 7oeg== X-Gm-Message-State: AOAM533FFFvads0WmpDVUdgScHFmYAq4GD+OqPChKGlsHFe69qH9ss3Z 5TCY4vNrmjuiVrhx7zGFO9reSKmQXQ+uVCRjf3c= X-Received: by 2002:ac2:5b1e:: with SMTP id v30mr5218306lfn.540.1611169442795; Wed, 20 Jan 2021 11:04:02 -0800 (PST) MIME-Version: 1.0 References: <20210119155953.803818-1-revest@chromium.org> <20210119155953.803818-4-revest@chromium.org> In-Reply-To: From: Alexei Starovoitov Date: Wed, 20 Jan 2021 11:03:51 -0800 Message-ID: Subject: Re: [PATCH bpf-next v5 4/4] selftests/bpf: Add a selftest for the tracing bpf_get_socket_cookie To: KP Singh Cc: Florent Revest , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Florent Revest , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 9:08 AM KP Singh wrote: > > On Tue, Jan 19, 2021 at 5:00 PM Florent Revest wrote: > > > > This builds up on the existing socket cookie test which checks whether > > the bpf_get_socket_cookie helpers provide the same value in > > cgroup/connect6 and sockops programs for a socket created by the > > userspace part of the test. > > > > Adding a tracing program to the existing objects requires a different > > attachment strategy and different headers. > > > > Signed-off-by: Florent Revest > > Acked-by: KP Singh > > (one minor note, doesn't really need fixing as a part of this though) > > > --- > > .../selftests/bpf/prog_tests/socket_cookie.c | 24 +++++++---- > > .../selftests/bpf/progs/socket_cookie_prog.c | 41 ++++++++++++++++--- > > 2 files changed, 52 insertions(+), 13 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/socket_cookie.c b/tools/testing/selftests/bpf/prog_tests/socket_cookie.c > > index 53d0c44e7907..e5c5e2ea1deb 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/socket_cookie.c > > +++ b/tools/testing/selftests/bpf/prog_tests/socket_cookie.c > > @@ -15,8 +15,8 @@ struct socket_cookie { > > > > void test_socket_cookie(void) > > { > > + struct bpf_link *set_link, *update_sockops_link, *update_tracing_link; > > socklen_t addr_len = sizeof(struct sockaddr_in6); > > - struct bpf_link *set_link, *update_link; > > int server_fd, client_fd, cgroup_fd; > > struct socket_cookie_prog *skel; > > __u32 cookie_expected_value; > > @@ -39,15 +39,21 @@ void test_socket_cookie(void) > > PTR_ERR(set_link))) > > goto close_cgroup_fd; > > > > - update_link = bpf_program__attach_cgroup(skel->progs.update_cookie, > > - cgroup_fd); > > - if (CHECK(IS_ERR(update_link), "update-link-cg-attach", "err %ld\n", > > - PTR_ERR(update_link))) > > + update_sockops_link = bpf_program__attach_cgroup( > > + skel->progs.update_cookie_sockops, cgroup_fd); > > + if (CHECK(IS_ERR(update_sockops_link), "update-sockops-link-cg-attach", > > + "err %ld\n", PTR_ERR(update_sockops_link))) > > goto free_set_link; > > > > + update_tracing_link = bpf_program__attach( > > + skel->progs.update_cookie_tracing); > > + if (CHECK(IS_ERR(update_tracing_link), "update-tracing-link-attach", > > + "err %ld\n", PTR_ERR(update_tracing_link))) > > + goto free_update_sockops_link; > > + > > server_fd = start_server(AF_INET6, SOCK_STREAM, "::1", 0, 0); > > if (CHECK(server_fd < 0, "start_server", "errno %d\n", errno)) > > - goto free_update_link; > > + goto free_update_tracing_link; > > > > client_fd = connect_to_fd(server_fd, 0); > > if (CHECK(client_fd < 0, "connect_to_fd", "errno %d\n", errno)) > > @@ -71,8 +77,10 @@ void test_socket_cookie(void) > > close(client_fd); > > close_server_fd: > > close(server_fd); > > -free_update_link: > > - bpf_link__destroy(update_link); > > +free_update_tracing_link: > > + bpf_link__destroy(update_tracing_link); > > I don't think this need to block submission unless there are other > issues but the > bpf_link__destroy can just be called in a single cleanup label because > it handles null or > erroneous inputs: > > int bpf_link__destroy(struct bpf_link *link) > { > int err = 0; > > if (IS_ERR_OR_NULL(link)) > return 0; > [...] +1 to KP's point. Also Florent, how did you test it? This test fails in CI and in my manual run: ./test_progs -t cook libbpf: load bpf program failed: Permission denied libbpf: -- BEGIN DUMP LOG --- libbpf: ; int update_cookie_sockops(struct bpf_sock_ops *ctx) 0: (bf) r6 = r1 ; if (ctx->family != AF_INET6) 1: (61) r1 = *(u32 *)(r6 +20) ; if (ctx->family != AF_INET6) 2: (56) if w1 != 0xa goto pc+21 R1_w=inv10 R6_w=ctx(id=0,off=0,imm=0) R10=fp0 ; if (ctx->op != BPF_SOCK_OPS_TCP_CONNECT_CB) 3: (61) r1 = *(u32 *)(r6 +0) ; if (ctx->op != BPF_SOCK_OPS_TCP_CONNECT_CB) 4: (56) if w1 != 0x3 goto pc+19 R1_w=inv3 R6_w=ctx(id=0,off=0,imm=0) R10=fp0 ; if (!ctx->sk) 5: (79) r1 = *(u64 *)(r6 +184) ; if (!ctx->sk) 6: (15) if r1 == 0x0 goto pc+17 R1_w=sock(id=0,ref_obj_id=0,off=0,imm=0) R6_w=ctx(id=0,off=0,imm=0) R10=fp0 ; p = bpf_sk_storage_get(&socket_cookies, ctx->sk, 0, 0); 7: (79) r2 = *(u64 *)(r6 +184) ; p = bpf_sk_storage_get(&socket_cookies, ctx->sk, 0, 0); 8: (18) r1 = 0xffff888106e41400 10: (b7) r3 = 0 11: (b7) r4 = 0 12: (85) call bpf_sk_storage_get#107 R2 type=sock_or_null expected=sock_common, sock, tcp_sock, xdp_sock, ptr_ processed 12 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 libbpf: -- END LOG -- libbpf: failed to load program 'update_cookie_sockops' libbpf: failed to load object 'socket_cookie_prog' libbpf: failed to load BPF skeleton 'socket_cookie_prog': -4007 test_socket_cookie:FAIL:socket_cookie_prog__open_and_load skeleton open_and_load failed #95 socket_cookie:FAIL Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED