From patchwork Fri Mar 26 12:24:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166495 X-Patchwork-Delegate: bpf@iogearbox.net 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=-16.0 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=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 D9C37C433DB for ; Fri, 26 Mar 2021 12:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 999ED61971 for ; Fri, 26 Mar 2021 12:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbhCZMZM (ORCPT ); Fri, 26 Mar 2021 08:25:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57498 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbhCZMYo (ORCPT ); Fri, 26 Mar 2021 08:24:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616761483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SAwTQ0VaCubvF8+lJjw41zWb458iCBIQT7bnPFJm/IU=; b=RutPa1h09NfJ5JXDHYUrNFYAQ7rLdYbZXMochfm+JIpH1b4wENdFTGZ217AesIzqH37683 xiYuywy8lcMi+3W6aGYYllZNJMsVeA50PKK6Z8RIBGaYWAu1qFC8gBzrlczcgmX3QLhY1m 5q5zY1AIujGGFHFdfw2SVReZ2+YH3wE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-135-f6zYn7x7M46R9ZbR8bhPuA-1; Fri, 26 Mar 2021 08:24:41 -0400 X-MC-Unique: f6zYn7x7M46R9ZbR8bhPuA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D387294DCA; Fri, 26 Mar 2021 12:24:40 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-130.ams2.redhat.com [10.36.114.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E1935D9E3; Fri, 26 Mar 2021 12:24:39 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH v2 1/4] selftests/bpf: test_progs/sockopt_sk: Convert to use BPF skeleton Date: Fri, 26 Mar 2021 14:24:35 +0200 Message-Id: <20210326122438.211242-1-yauheni.kaliuta@redhat.com> In-Reply-To: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> References: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Switch the test to use BPF skeleton to save some boilerplate and make it easy to access bpf program bss segment. The latter will be used to pass PAGE_SIZE from userspace since there is no convenient way for bpf program to get it from inside of the kernel. Signed-off-by: Yauheni Kaliuta Acked-by: Andrii Nakryiko --- .../selftests/bpf/prog_tests/sockopt_sk.c | 72 ++++++------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c index d5b44b135c00..114c1a622ffa 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c @@ -3,6 +3,7 @@ #include "cgroup_helpers.h" #include +#include "sockopt_sk.skel.h" #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP @@ -191,60 +192,33 @@ static int getsetsockopt(void) return -1; } -static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title) -{ - enum bpf_attach_type attach_type; - enum bpf_prog_type prog_type; - struct bpf_program *prog; - int err; - - err = libbpf_prog_type_by_name(title, &prog_type, &attach_type); - if (err) { - log_err("Failed to deduct types for %s BPF program", title); - return -1; - } - - prog = bpf_object__find_program_by_title(obj, title); - if (!prog) { - log_err("Failed to find %s BPF program", title); - return -1; - } - - err = bpf_prog_attach(bpf_program__fd(prog), cgroup_fd, - attach_type, 0); - if (err) { - log_err("Failed to attach %s BPF program", title); - return -1; - } - - return 0; -} - static void run_test(int cgroup_fd) { - struct bpf_prog_load_attr attr = { - .file = "./sockopt_sk.o", - }; - struct bpf_object *obj; - int ignored; - int err; - - err = bpf_prog_load_xattr(&attr, &obj, &ignored); - if (CHECK_FAIL(err)) - return; - - err = prog_attach(obj, cgroup_fd, "cgroup/getsockopt"); - if (CHECK_FAIL(err)) - goto close_bpf_object; - - err = prog_attach(obj, cgroup_fd, "cgroup/setsockopt"); - if (CHECK_FAIL(err)) - goto close_bpf_object; + struct sockopt_sk *skel; + int duration = 0; + + skel = sockopt_sk__open_and_load(); + if (CHECK(!skel, "skel_load", "sockopt_sk skeleton failed\n")) + goto cleanup; + + skel->links._setsockopt = + bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd); + if (CHECK(IS_ERR(skel->links._setsockopt), + "setsockopt_attach", "err: %ld\n", + PTR_ERR(skel->links._setsockopt))) + goto cleanup; + + skel->links._getsockopt = + bpf_program__attach_cgroup(skel->progs._getsockopt, cgroup_fd); + if (CHECK(IS_ERR(skel->links._getsockopt), + "getsockopt_attach", "err: %ld\n", + PTR_ERR(skel->links._getsockopt))) + goto cleanup; CHECK_FAIL(getsetsockopt()); -close_bpf_object: - bpf_object__close(obj); +cleanup: + sockopt_sk__destroy(skel); } void test_sockopt_sk(void) From patchwork Fri Mar 26 12:24:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166497 X-Patchwork-Delegate: bpf@iogearbox.net 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=-16.0 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=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 C98FDC433C1 for ; Fri, 26 Mar 2021 12:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77A9461953 for ; Fri, 26 Mar 2021 12:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbhCZMZM (ORCPT ); Fri, 26 Mar 2021 08:25:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47950 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbhCZMYp (ORCPT ); Fri, 26 Mar 2021 08:24:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616761485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1PRjoolN/0TRpZdrtFaOMo+fWLdGM5HRHk+d2zU9yXI=; b=cMum0nfR5xU1Q1aO+fQpycfeQF5DDpNtBXNtw9BgzpooctazwpISjEIKQiIzpcIfJHPNxb k8b075yypD7vHvJSOIxNHQCduD3BPkiha0EenFXj9BylN3SuPLHOSNCA+ZKR9Mi54KbTaw /yQ6OwJp7GgGX+2w4hggJm3D1S97SSk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-sXjOyQsNOwqYqSp2Osasgg-1; Fri, 26 Mar 2021 08:24:43 -0400 X-MC-Unique: sXjOyQsNOwqYqSp2Osasgg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3D7A80006E; Fri, 26 Mar 2021 12:24:42 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-130.ams2.redhat.com [10.36.114.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44E565D9E3; Fri, 26 Mar 2021 12:24:41 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH v2 2/4] selftests/bpf: test_progs/sockopt_sk: pass page size from userspace Date: Fri, 26 Mar 2021 14:24:36 +0200 Message-Id: <20210326122438.211242-2-yauheni.kaliuta@redhat.com> In-Reply-To: <20210326122438.211242-1-yauheni.kaliuta@redhat.com> References: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> <20210326122438.211242-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Since there is no convenient way for bpf program to get PAGE_SIZE from inside of the kernel, pass the value from userspace. Signed-off-by: Yauheni Kaliuta Acked-by: Andrii Nakryiko --- tools/testing/selftests/bpf/prog_tests/sockopt_sk.c | 2 ++ tools/testing/selftests/bpf/progs/sockopt_sk.c | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c index 114c1a622ffa..6a7cb5f23db2 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c @@ -201,6 +201,8 @@ static void run_test(int cgroup_fd) if (CHECK(!skel, "skel_load", "sockopt_sk skeleton failed\n")) goto cleanup; + skel->bss->page_size = getpagesize(); + skel->links._setsockopt = bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd); if (CHECK(IS_ERR(skel->links._setsockopt), diff --git a/tools/testing/selftests/bpf/progs/sockopt_sk.c b/tools/testing/selftests/bpf/progs/sockopt_sk.c index d3597f81e6e9..55dfbe53c24e 100644 --- a/tools/testing/selftests/bpf/progs/sockopt_sk.c +++ b/tools/testing/selftests/bpf/progs/sockopt_sk.c @@ -8,9 +8,7 @@ char _license[] SEC("license") = "GPL"; __u32 _version SEC("version") = 1; -#ifndef PAGE_SIZE -#define PAGE_SIZE 4096 -#endif +int page_size; /* userspace should set it */ #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP @@ -90,7 +88,7 @@ int _getsockopt(struct bpf_sockopt *ctx) * program can only see the first PAGE_SIZE * bytes of data. */ - if (optval_end - optval != PAGE_SIZE) + if (optval_end - optval != page_size) return 0; /* EPERM, unexpected data size */ return 1; @@ -161,7 +159,7 @@ int _setsockopt(struct bpf_sockopt *ctx) if (ctx->level == SOL_IP && ctx->optname == IP_FREEBIND) { /* Original optlen is larger than PAGE_SIZE. */ - if (ctx->optlen != PAGE_SIZE * 2) + if (ctx->optlen != page_size * 2) return 0; /* EPERM, unexpected data size */ if (optval + 1 > optval_end) @@ -175,7 +173,7 @@ int _setsockopt(struct bpf_sockopt *ctx) * program can only see the first PAGE_SIZE * bytes of data. */ - if (optval_end - optval != PAGE_SIZE) + if (optval_end - optval != page_size) return 0; /* EPERM, unexpected data size */ return 1; From patchwork Fri Mar 26 12:24:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166493 X-Patchwork-Delegate: bpf@iogearbox.net 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=-16.0 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=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 072D4C433E0 for ; Fri, 26 Mar 2021 12:25:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9E37619AE for ; Fri, 26 Mar 2021 12:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbhCZMZN (ORCPT ); Fri, 26 Mar 2021 08:25:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45897 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229969AbhCZMYr (ORCPT ); Fri, 26 Mar 2021 08:24:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616761487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ONMwwggOPA4PUs4JSBeo1Fh+t/y79K7nhlnXHEaYcI0=; b=df8e3jdGNRGEetYfgbrpCTf3Qdxfn0PawtkMele+7XCLXXZl+RcBDwQEdPyAze7ILKbgBL tphJnN9iq3Kdd4iPTRFZQXzPFDvZK2wdTU2EC2C4lokY/PWJogOFCvChP2juL8gp+zTuCE 2QOm4mPMwvgdYQSiktlPo6d3KgpBAKA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-GtoiApcHMZCHfWdpHtbc9g-1; Fri, 26 Mar 2021 08:24:45 -0400 X-MC-Unique: GtoiApcHMZCHfWdpHtbc9g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5CD0794DC0; Fri, 26 Mar 2021 12:24:44 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-130.ams2.redhat.com [10.36.114.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F6DC5D9E3; Fri, 26 Mar 2021 12:24:42 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH v2 3/4] bpf: selftests: test_progs/sockopt_sk: remove version Date: Fri, 26 Mar 2021 14:24:37 +0200 Message-Id: <20210326122438.211242-3-yauheni.kaliuta@redhat.com> In-Reply-To: <20210326122438.211242-1-yauheni.kaliuta@redhat.com> References: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> <20210326122438.211242-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net As pointed by Andrii Nakryiko, _version is useless now, remove it. Signed-off-by: Yauheni Kaliuta --- tools/testing/selftests/bpf/progs/sockopt_sk.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/bpf/progs/sockopt_sk.c b/tools/testing/selftests/bpf/progs/sockopt_sk.c index 55dfbe53c24e..d6d03f64e2e4 100644 --- a/tools/testing/selftests/bpf/progs/sockopt_sk.c +++ b/tools/testing/selftests/bpf/progs/sockopt_sk.c @@ -6,7 +6,6 @@ #include char _license[] SEC("license") = "GPL"; -__u32 _version SEC("version") = 1; int page_size; /* userspace should set it */ From patchwork Fri Mar 26 12:24:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166499 X-Patchwork-Delegate: bpf@iogearbox.net 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=-16.0 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=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 3524FC433E1 for ; Fri, 26 Mar 2021 12:25:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D76E1619D3 for ; Fri, 26 Mar 2021 12:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbhCZMZN (ORCPT ); Fri, 26 Mar 2021 08:25:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51551 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbhCZMYt (ORCPT ); Fri, 26 Mar 2021 08:24:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616761488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IJVWMxceisDQsF9m4+VnneiUiqpvYHl9MaEFmAKL1r8=; b=gr0gkhPN0cdQYIEuFasfrDn2tBoVCwS9u9KGxHKND2Es/5Kmp/QQcCs9PoT3OzfCddcs2n /mc6imwZFfdQ9QLN4u0lFwF1sVji4Y3JQFolQnFa0tR5Tw0WfA7qifV/v5xb8jqI7EdXeF 8gYFJ/bMiyNiZi41a+DlrgJIazAQqDM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-547-gj9A2EbcNRqMyO_heVsVQQ-1; Fri, 26 Mar 2021 08:24:47 -0400 X-MC-Unique: gj9A2EbcNRqMyO_heVsVQQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42AA683DD20; Fri, 26 Mar 2021 12:24:46 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-130.ams2.redhat.com [10.36.114.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id BACCA5D9E3; Fri, 26 Mar 2021 12:24:44 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH v2 4/4] selftests/bpf: ringbuf, mmap: bump up page size to 64K Date: Fri, 26 Mar 2021 14:24:38 +0200 Message-Id: <20210326122438.211242-4-yauheni.kaliuta@redhat.com> In-Reply-To: <20210326122438.211242-1-yauheni.kaliuta@redhat.com> References: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> <20210326122438.211242-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Both ringbuf and mmap need PAGE_SIZE, but it's not available during bpf program compile time. 4K size was hardcoded (page shift 12 bits) which makes the tests fail on systems, configured for larger pages. Bump it up to 64K which at the first glance look reasonable at the moment for most of the systems. Use define to make it clear. Signed-off-by: Yauheni Kaliuta --- tools/testing/selftests/bpf/prog_tests/ringbuf.c | 9 +++++++-- tools/testing/selftests/bpf/progs/map_ptr_kern.c | 9 +++++++-- tools/testing/selftests/bpf/progs/test_mmap.c | 10 ++++++++-- tools/testing/selftests/bpf/progs/test_ringbuf.c | 8 +++++++- tools/testing/selftests/bpf/progs/test_ringbuf_multi.c | 7 ++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index fddbc5db5d6a..9057654da957 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -15,6 +15,11 @@ #include "test_ringbuf.skel.h" #define EDONE 7777 +#ifdef PAGE_SIZE +#undef PAGE_SIZE +#endif +/* this is not actual page size, but the value used for ringbuf */ +#define PAGE_SIZE 65536 static int duration = 0; @@ -110,9 +115,9 @@ void test_ringbuf(void) CHECK(skel->bss->avail_data != 3 * rec_sz, "err_avail_size", "exp %ld, got %ld\n", 3L * rec_sz, skel->bss->avail_data); - CHECK(skel->bss->ring_size != 4096, + CHECK(skel->bss->ring_size != PAGE_SIZE, "err_ring_size", "exp %ld, got %ld\n", - 4096L, skel->bss->ring_size); + (long)PAGE_SIZE, skel->bss->ring_size); CHECK(skel->bss->cons_pos != 0, "err_cons_pos", "exp %ld, got %ld\n", 0L, skel->bss->cons_pos); diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c index d8850bc6a9f1..c1460f27af78 100644 --- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c +++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c @@ -8,6 +8,11 @@ #define MAX_ENTRIES 8 #define HALF_ENTRIES (MAX_ENTRIES >> 1) +#ifndef PAGE_SIZE +/* use reasonable value for various configurations */ +#define PAGE_SIZE 65536 +#endif + _Static_assert(MAX_ENTRIES < LOOP_BOUND, "MAX_ENTRIES must be < LOOP_BOUND"); enum bpf_map_type g_map_type = BPF_MAP_TYPE_UNSPEC; @@ -635,7 +640,7 @@ struct bpf_ringbuf_map { struct { __uint(type, BPF_MAP_TYPE_RINGBUF); - __uint(max_entries, 1 << 12); + __uint(max_entries, PAGE_SIZE); } m_ringbuf SEC(".maps"); static inline int check_ringbuf(void) @@ -643,7 +648,7 @@ static inline int check_ringbuf(void) struct bpf_ringbuf_map *ringbuf = (struct bpf_ringbuf_map *)&m_ringbuf; struct bpf_map *map = (struct bpf_map *)&m_ringbuf; - VERIFY(check(&ringbuf->map, map, 0, 0, 1 << 12)); + VERIFY(check(&ringbuf->map, map, 0, 0, PAGE_SIZE)); return 1; } diff --git a/tools/testing/selftests/bpf/progs/test_mmap.c b/tools/testing/selftests/bpf/progs/test_mmap.c index 4eb42cff5fe9..c22fcfea0767 100644 --- a/tools/testing/selftests/bpf/progs/test_mmap.c +++ b/tools/testing/selftests/bpf/progs/test_mmap.c @@ -5,11 +5,16 @@ #include #include +#ifndef PAGE_SIZE +/* use reasonable value for various configurations */ +#define PAGE_SIZE 65536 +#endif + char _license[] SEC("license") = "GPL"; struct { __uint(type, BPF_MAP_TYPE_ARRAY); - __uint(max_entries, 4096); + __uint(max_entries, PAGE_SIZE); __uint(map_flags, BPF_F_MMAPABLE | BPF_F_RDONLY_PROG); __type(key, __u32); __type(value, char); @@ -17,7 +22,8 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); - __uint(max_entries, 512 * 4); /* at least 4 pages of data */ + /* at least 4 pages of data */ + __uint(max_entries, 4 * (PAGE_SIZE / sizeof (__u64))); __uint(map_flags, BPF_F_MMAPABLE); __type(key, __u32); __type(value, __u64); diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf.c b/tools/testing/selftests/bpf/progs/test_ringbuf.c index 8ba9959b036b..6e645babdc18 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf.c @@ -4,6 +4,12 @@ #include #include +#ifndef PAGE_SIZE +/* use reasonable value for various configurations */ +#define PAGE_SIZE 65536 +#endif + + char _license[] SEC("license") = "GPL"; struct sample { @@ -15,7 +21,7 @@ struct sample { struct { __uint(type, BPF_MAP_TYPE_RINGBUF); - __uint(max_entries, 1 << 12); + __uint(max_entries, PAGE_SIZE); } ringbuf SEC(".maps"); /* inputs */ diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c index edf3b6953533..13bcf095e06c 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c @@ -4,6 +4,11 @@ #include #include +#ifndef PAGE_SIZE +/* use reasonable value for various configurations */ +#define PAGE_SIZE 65536 +#endif + char _license[] SEC("license") = "GPL"; struct sample { @@ -15,7 +20,7 @@ struct sample { struct ringbuf_map { __uint(type, BPF_MAP_TYPE_RINGBUF); - __uint(max_entries, 1 << 12); + __uint(max_entries, PAGE_SIZE); } ringbuf1 SEC(".maps"), ringbuf2 SEC(".maps");