From patchwork Wed Mar 31 16:44:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175773 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=-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=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 56702C43460 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 359A861041 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233754AbhCaQpq (ORCPT ); Wed, 31 Mar 2021 12:45:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41135 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232406AbhCaQpU (ORCPT ); Wed, 31 Mar 2021 12:45:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209120; 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=lfCtnOOOaH4oxg255il0FTnmQbHOXUryUVB+jsJ/qzk=; b=Y1BfsGSJ+HFd4lU3sMM+z7X/bt3T/d9I4lzmelE7Ij9gLMVJ2dDmnUBEhw4RAK4i9ZbaLA M8S/os/OS0U7QYiQp6d4ibibk6cQUG89iNHPrpPpRQmh2fDjbM8aMgvp70ISlmHAOOWJjM 3YS+dV4AEoJAUtZCYHesnjvAewEQclk= 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-155-ayk3e8yqNXGtqWq8cNZVhg-1; Wed, 31 Mar 2021 12:45:18 -0400 X-MC-Unique: ayk3e8yqNXGtqWq8cNZVhg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 447E61084C8C; Wed, 31 Mar 2021 16:45:17 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31C01A8438; Wed, 31 Mar 2021 16:45:05 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 1/8] selftests/bpf: test_progs/sockopt_sk: remove version Date: Wed, 31 Mar 2021 19:44:57 +0300 Message-Id: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 d3597f81e6e9..978a68005966 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; #ifndef PAGE_SIZE #define PAGE_SIZE 4096 From patchwork Wed Mar 31 16:44:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175769 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=-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=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 4D137C433B4 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B1B26101E for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232406AbhCaQpq (ORCPT ); Wed, 31 Mar 2021 12:45:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52234 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232805AbhCaQpW (ORCPT ); Wed, 31 Mar 2021 12:45:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209121; 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=ue1WJN9VVLFtg4vxqXBhw+4/lkwt4siu2NvJcjrHRVw=; b=SPn0nqp+/5ndQpCLGpafDRGLY3PfQSzHGe+wapNlbYGDnRt1E9Puu214DoLo8Zk1YXFI07 mORbArXYkGjPi6ZhLhjme9TG+AS2n0QqNCK0MNIyQf1PGPmLmpaRlv8hRHkqtoCZkL3z5k 1o+w6M0VROdfQ8BC5bDxn2B+k6tNW84= 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-528-724S6QzSNQi_ZK9sqV5fJQ-1; Wed, 31 Mar 2021 12:45:19 -0400 X-MC-Unique: 724S6QzSNQi_ZK9sqV5fJQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1DA710082EC; Wed, 31 Mar 2021 16:45:18 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id A360516922; Wed, 31 Mar 2021 16:45:17 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 2/8] selftests/bpf: test_progs/sockopt_sk: Convert to use BPF skeleton Date: Wed, 31 Mar 2021 19:44:58 +0300 Message-Id: <20210331164504.320614-2-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 --- .../selftests/bpf/prog_tests/sockopt_sk.c | 65 +++++-------------- 1 file changed, 17 insertions(+), 48 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..7274b12abe17 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,28 @@ 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; + struct sockopt_sk *skel; + + skel = sockopt_sk__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_load")) + goto cleanup; - err = prog_attach(obj, cgroup_fd, "cgroup/getsockopt"); - if (CHECK_FAIL(err)) - goto close_bpf_object; + skel->links._setsockopt = + bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd); + if (!ASSERT_OK_PTR(skel->links._setsockopt, "setsockopt_link")) + goto cleanup; - err = prog_attach(obj, cgroup_fd, "cgroup/setsockopt"); - if (CHECK_FAIL(err)) - goto close_bpf_object; + skel->links._getsockopt = + bpf_program__attach_cgroup(skel->progs._getsockopt, cgroup_fd); + if (!ASSERT_OK_PTR(skel->links._getsockopt, "getsockopt_link")) + goto cleanup; - CHECK_FAIL(getsetsockopt()); + ASSERT_OK(getsetsockopt(), "getsetsockopt"); -close_bpf_object: - bpf_object__close(obj); +cleanup: + sockopt_sk__destroy(skel); } void test_sockopt_sk(void) From patchwork Wed Mar 31 16:44:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175783 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=-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=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 A10B8C4360C for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ADFE61074 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbhCaQps (ORCPT ); Wed, 31 Mar 2021 12:45:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36846 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234206AbhCaQpa (ORCPT ); Wed, 31 Mar 2021 12:45:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209129; 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=AFwiGJ1dIAkQaLWEx4XeDhCLf4sdj3iC0TsPGK9TRT4=; b=Yi6yT63purwpZpl5fyzXDsUpQ3nB1W3CXlTwH7P1sIPnRswSkqmslzqp/fz52SLmCelNOX 93q1cYa3ljxel+/0hHlOppsDjBe9/8s5Sg7gZ5w+araLutVUgfM8w5NcGVDqvon8OPcyQo tpA3frvCBAKXmSQ+K4XtI8ar2AhqXa8= 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-312-3SV314FsMAeAGbtwKyCT5g-1; Wed, 31 Mar 2021 12:45:21 -0400 X-MC-Unique: 3SV314FsMAeAGbtwKyCT5g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 726098189C8; Wed, 31 Mar 2021 16:45:20 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A49D51C40; Wed, 31 Mar 2021 16:45:19 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 3/8] selftests/bpf: pass page size from userspace in sockopt_sk Date: Wed, 31 Mar 2021 19:44:59 +0300 Message-Id: <20210331164504.320614-3-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 --- 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 7274b12abe17..4b937e5dbaca 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_sk.c @@ -200,6 +200,8 @@ static void run_test(int cgroup_fd) if (!ASSERT_OK_PTR(skel, "skel_load")) goto cleanup; + skel->bss->page_size = getpagesize(); + skel->links._setsockopt = bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd); if (!ASSERT_OK_PTR(skel->links._setsockopt, "setsockopt_link")) diff --git a/tools/testing/selftests/bpf/progs/sockopt_sk.c b/tools/testing/selftests/bpf/progs/sockopt_sk.c index 978a68005966..d6d03f64e2e4 100644 --- a/tools/testing/selftests/bpf/progs/sockopt_sk.c +++ b/tools/testing/selftests/bpf/progs/sockopt_sk.c @@ -7,9 +7,7 @@ char _license[] SEC("license") = "GPL"; -#ifndef PAGE_SIZE -#define PAGE_SIZE 4096 -#endif +int page_size; /* userspace should set it */ #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP @@ -89,7 +87,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; @@ -160,7 +158,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) @@ -174,7 +172,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 Wed Mar 31 16:45:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175771 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=-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=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 33940C433ED for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0680F60FEE for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232805AbhCaQpr (ORCPT ); Wed, 31 Mar 2021 12:45:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59102 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbhCaQpZ (ORCPT ); Wed, 31 Mar 2021 12:45:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209125; 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=7xFKRDA7GxWzWD13Ezn+FHhuS3mF6hkJYSoOAJxBcCA=; b=OuhyUJHppK/Z27Z6eIQOTob7e+aTrPm2CgP5hSim81L8whCEyv676An5C/07gNcGHBhjgM BL5GGS7iBOlIxOFWg6ipsl0NzkK9OWmFSBvDMBw8WWxtR6jc1XJJuoDk3RLCiOdPY9kd6W tCZ6LeFp70EjOaejQaV9PlR5XyfPYaU= 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-100-b1x4-XifNyy8bJTHOb1ZFQ-1; Wed, 31 Mar 2021 12:45:23 -0400 X-MC-Unique: b1x4-XifNyy8bJTHOb1ZFQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 27B0A10082EA; Wed, 31 Mar 2021 16:45:22 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id C67EDA8438; Wed, 31 Mar 2021 16:45:20 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 4/8] selftests/bpf: pass page size from userspace in map_ptr Date: Wed, 31 Mar 2021 19:45:00 +0300 Message-Id: <20210331164504.320614-4-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use ASSERT to check result but keep CHECK where format was used to report error. Use bpf_map__set_max_entries() to set map size dynamically from userspace according to page size. Signed-off-by: Yauheni Kaliuta --- tools/testing/selftests/bpf/prog_tests/map_ptr.c | 15 +++++++++++++-- tools/testing/selftests/bpf/progs/map_ptr_kern.c | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/map_ptr.c b/tools/testing/selftests/bpf/prog_tests/map_ptr.c index c230a573c373..4972f92205c7 100644 --- a/tools/testing/selftests/bpf/prog_tests/map_ptr.c +++ b/tools/testing/selftests/bpf/prog_tests/map_ptr.c @@ -12,11 +12,22 @@ void test_map_ptr(void) __u32 duration = 0, retval; char buf[128]; int err; + int page_size = getpagesize(); - skel = map_ptr_kern__open_and_load(); - if (CHECK(!skel, "skel_open_load", "open_load failed\n")) + skel = map_ptr_kern__open(); + if (!ASSERT_OK_PTR(skel, "skel_open")) return; + err = bpf_map__set_max_entries(skel->maps.m_ringbuf, page_size); + if (!ASSERT_OK(err, "bpf_map__set_max_entries")) + goto cleanup; + + err = map_ptr_kern__load(skel); + if (!ASSERT_OK(err, "skel_load")) + goto cleanup; + + skel->bss->page_size = page_size; + err = bpf_prog_test_run(bpf_program__fd(skel->progs.cg_skb), 1, &pkt_v4, sizeof(pkt_v4), buf, NULL, &retval, NULL); diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c index d8850bc6a9f1..0e06789ad4d2 100644 --- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c +++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c @@ -12,6 +12,7 @@ _Static_assert(MAX_ENTRIES < LOOP_BOUND, "MAX_ENTRIES must be < LOOP_BOUND"); enum bpf_map_type g_map_type = BPF_MAP_TYPE_UNSPEC; __u32 g_line = 0; +int page_size; /* userspace should set it */ #define VERIFY_TYPE(type, func) ({ \ g_map_type = type; \ @@ -635,7 +636,6 @@ struct bpf_ringbuf_map { struct { __uint(type, BPF_MAP_TYPE_RINGBUF); - __uint(max_entries, 1 << 12); } m_ringbuf SEC(".maps"); static inline int check_ringbuf(void) @@ -643,7 +643,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; } From patchwork Wed Mar 31 16:45:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175775 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=-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=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 71F9DC43470 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56DD361074 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234003AbhCaQpr (ORCPT ); Wed, 31 Mar 2021 12:45:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52963 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234119AbhCaQp2 (ORCPT ); Wed, 31 Mar 2021 12:45:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209126; 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=vu4HpU4JCTvWj881JzDXxJ0KAgPaUxPS8xJ1LdP5hJ8=; b=KoHz6ZAHZGICcURB82FnvyYACfRJf9eAihGkb9vpv32r3VgSA4I8CUqD562v2Cimj2SMDX FARPWoi3cB11xBj8fsMmkE+72TAkadEjNEE/FQLX9UpSog2QvH8mH1NFDrcev4wl5pwkqD oMwP+z6s3JyoXHq8TrySCELQ22cnk0M= 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-363-Ek7yM-2-MNWGMapokeofLg-1; Wed, 31 Mar 2021 12:45:24 -0400 X-MC-Unique: Ek7yM-2-MNWGMapokeofLg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B92E81B2C985; Wed, 31 Mar 2021 16:45:23 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B31316922; Wed, 31 Mar 2021 16:45:22 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 5/8] selftests/bpf: mmap: use runtime page size Date: Wed, 31 Mar 2021 19:45:01 +0300 Message-Id: <20210331164504.320614-5-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Replace hardcoded 4096 with runtime value in the userspace part of the test and set bpf table sizes dynamically according to the value. Do not switch to ASSERT macros, keep CHECK, for consistency with the rest of the test. Can be a separate cleanup patch. Signed-off-by: Yauheni Kaliuta --- tools/testing/selftests/bpf/prog_tests/mmap.c | 24 +++++++++++++++---- tools/testing/selftests/bpf/progs/test_mmap.c | 2 -- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mmap.c b/tools/testing/selftests/bpf/prog_tests/mmap.c index 9c3c5c0f068f..691b54b1c7cd 100644 --- a/tools/testing/selftests/bpf/prog_tests/mmap.c +++ b/tools/testing/selftests/bpf/prog_tests/mmap.c @@ -29,22 +29,36 @@ void test_mmap(void) struct test_mmap *skel; __u64 val = 0; - skel = test_mmap__open_and_load(); - if (CHECK(!skel, "skel_open_and_load", "skeleton open/load failed\n")) + skel = test_mmap__open(); + if (CHECK(!skel, "skel_open", "skeleton open failed\n")) return; + err = bpf_map__set_max_entries(skel->maps.rdonly_map, page_size); + if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) + goto cleanup; + + /* at least 4 pages of data */ + err = bpf_map__set_max_entries(skel->maps.data_map, + 4 * (page_size / sizeof (u64))); + if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) + goto cleanup; + + err = test_mmap__load(skel); + if (CHECK(err != 0, "skel_load", "skeleton load failed\n")) + goto cleanup; + bss_map = skel->maps.bss; data_map = skel->maps.data_map; data_map_fd = bpf_map__fd(data_map); rdmap_fd = bpf_map__fd(skel->maps.rdonly_map); - tmp1 = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, rdmap_fd, 0); + tmp1 = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, rdmap_fd, 0); if (CHECK(tmp1 != MAP_FAILED, "rdonly_write_mmap", "unexpected success\n")) { - munmap(tmp1, 4096); + munmap(tmp1, page_size); goto cleanup; } /* now double-check if it's mmap()'able at all */ - tmp1 = mmap(NULL, 4096, PROT_READ, MAP_SHARED, rdmap_fd, 0); + tmp1 = mmap(NULL, page_size, PROT_READ, MAP_SHARED, rdmap_fd, 0); if (CHECK(tmp1 == MAP_FAILED, "rdonly_read_mmap", "failed: %d\n", errno)) goto cleanup; diff --git a/tools/testing/selftests/bpf/progs/test_mmap.c b/tools/testing/selftests/bpf/progs/test_mmap.c index 4eb42cff5fe9..5a5cc19a15bf 100644 --- a/tools/testing/selftests/bpf/progs/test_mmap.c +++ b/tools/testing/selftests/bpf/progs/test_mmap.c @@ -9,7 +9,6 @@ char _license[] SEC("license") = "GPL"; struct { __uint(type, BPF_MAP_TYPE_ARRAY); - __uint(max_entries, 4096); __uint(map_flags, BPF_F_MMAPABLE | BPF_F_RDONLY_PROG); __type(key, __u32); __type(value, char); @@ -17,7 +16,6 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); - __uint(max_entries, 512 * 4); /* at least 4 pages of data */ __uint(map_flags, BPF_F_MMAPABLE); __type(key, __u32); __type(value, __u64); From patchwork Wed Mar 31 16:45:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175777 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=-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=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 6B4A8C43461 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44C2B6103D for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234119AbhCaQpr (ORCPT ); Wed, 31 Mar 2021 12:45:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58832 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234182AbhCaQp2 (ORCPT ); Wed, 31 Mar 2021 12:45:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209128; 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=bMdkdegJVqh4WRz92PW5PUU8JBi58ZeBVxY5/fxVB8E=; b=CsX9CNYgYRnDpk/ConukTmeHVvZLHM0WP9TE0kiVSn0zCmld4qiva3RdccKcA2UW16LAmy 4ZD2c+WdI65P7J8eHJxnx9jtpuW9WmDZgcMXpaMCHgUemhRdCwZpER+JK4OM3Azu3jaCaB SlDpKGUeKjKrcMBJpdgfxQtg2GhkfFI= 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-36-qtmhY2S_OIC0OBu7Y7Le-A-1; Wed, 31 Mar 2021 12:45:26 -0400 X-MC-Unique: qtmhY2S_OIC0OBu7Y7Le-A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BDFC50201; Wed, 31 Mar 2021 16:45:25 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DF1816922; Wed, 31 Mar 2021 16:45:23 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 6/8] selftests/bpf: ringbuf: use runtime page size Date: Wed, 31 Mar 2021 19:45:02 +0300 Message-Id: <20210331164504.320614-6-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Replace hardcoded 4096 with runtime value in the userspace part of the test and set bpf table sizes dynamically according to the value. Do not switch to ASSERT macros, keep CHECK, for consistency with the rest of the test. Can be a separate cleanup patch. Signed-off-by: Yauheni Kaliuta --- .../testing/selftests/bpf/prog_tests/ringbuf.c | 17 +++++++++++++---- .../testing/selftests/bpf/progs/test_ringbuf.c | 1 - 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index fddbc5db5d6a..8c9f71a816f6 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -87,11 +87,20 @@ void test_ringbuf(void) pthread_t thread; long bg_ret = -1; int err, cnt; + int page_size = getpagesize(); - skel = test_ringbuf__open_and_load(); - if (CHECK(!skel, "skel_open_load", "skeleton open&load failed\n")) + skel = test_ringbuf__open(); + if (CHECK(!skel, "skel_open", "skeleton open failed\n")) return; + err = bpf_map__set_max_entries(skel->maps.ringbuf, page_size); + if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) + goto cleanup; + + err = test_ringbuf__load(skel); + if (CHECK(err != 0, "skel_load", "skeleton load failed\n")) + goto cleanup; + /* only trigger BPF program for current process */ skel->bss->pid = getpid(); @@ -110,9 +119,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/test_ringbuf.c b/tools/testing/selftests/bpf/progs/test_ringbuf.c index 8ba9959b036b..6b3f288b7c63 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf.c @@ -15,7 +15,6 @@ struct sample { struct { __uint(type, BPF_MAP_TYPE_RINGBUF); - __uint(max_entries, 1 << 12); } ringbuf SEC(".maps"); /* inputs */ From patchwork Wed Mar 31 16:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175781 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=-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=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 91687C43462 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A52C6101E for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234206AbhCaQps (ORCPT ); Wed, 31 Mar 2021 12:45:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41916 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234219AbhCaQpc (ORCPT ); Wed, 31 Mar 2021 12:45:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209132; 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=NtMayp7ncJkMyGFQcP4hnkKMYWqzepowrLmra6TJ3Mw=; b=OQt2+fSkoWel2uI74s7SKQU3gf+5u9KKcQZsbNYRLwiUZT5+4Zps2Irm/tYntsbeLxDXtB Rc5jq2NiqOJwM5X22Euue+CHm2ZcCiEJSOjgW93df9eQPaEMHNDDnkkvkTkFV3rQBe6Rhq BG6rZQqv7vBrWZKNhn0+UU0KQkCEY2s= 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-401-JBrJlljPMvyEhapjsAr2wg-1; Wed, 31 Mar 2021 12:45:27 -0400 X-MC-Unique: JBrJlljPMvyEhapjsAr2wg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C24BA8189D8; Wed, 31 Mar 2021 16:45:26 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F2FD16922; Wed, 31 Mar 2021 16:45:25 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 7/8] libbpf: add bpf_map__inner_map API Date: Wed, 31 Mar 2021 19:45:03 +0300 Message-Id: <20210331164504.320614-7-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Andrii Nakryiko The API gives access to inner map for map in map types (array or hash of map). It will be used to dynamically set max_entries in it. Signed-off-by: Yauheni Kaliuta --- tools/lib/bpf/libbpf.c | 10 ++++++++++ tools/lib/bpf/libbpf.h | 1 + tools/lib/bpf/libbpf.map | 1 + 3 files changed, 12 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7aad78dbb4b4..b48dc380059d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2194,6 +2194,7 @@ static int parse_btf_map_def(struct bpf_object *obj, map->inner_map = calloc(1, sizeof(*map->inner_map)); if (!map->inner_map) return -ENOMEM; + map->inner_map->fd = -1; map->inner_map->sec_idx = obj->efile.btf_maps_shndx; map->inner_map->name = malloc(strlen(map->name) + sizeof(".inner") + 1); @@ -3845,6 +3846,14 @@ __u32 bpf_map__max_entries(const struct bpf_map *map) return map->def.max_entries; } +struct bpf_map *bpf_map__inner_map(struct bpf_map *map) +{ + if (!bpf_map_type__is_map_in_map(map->def.type)) + return NULL; + + return map->inner_map; +} + int bpf_map__set_max_entries(struct bpf_map *map, __u32 max_entries) { if (map->fd >= 0) @@ -9476,6 +9485,7 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd) pr_warn("error: inner_map_fd already specified\n"); return -EINVAL; } + zfree(&map->inner_map); map->inner_map_fd = fd; return 0; } diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index f500621d28e5..bec4e6a6e31d 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -480,6 +480,7 @@ LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path); LIBBPF_API int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd); +LIBBPF_API struct bpf_map *bpf_map__inner_map(struct bpf_map *map); LIBBPF_API long libbpf_get_error(const void *ptr); diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index f5990f7208ce..eeb6d5ebd1cc 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -360,4 +360,5 @@ LIBBPF_0.4.0 { bpf_linker__free; bpf_linker__new; bpf_object__set_kversion; + bpf_map__inner_map; } LIBBPF_0.3.0; From patchwork Wed Mar 31 16:45:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12175779 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=-13.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, UNWANTED_LANGUAGE_BODY 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 875E4C43600 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6460C61041 for ; Wed, 31 Mar 2021 16:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234217AbhCaQps (ORCPT ); Wed, 31 Mar 2021 12:45:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56859 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbhCaQpe (ORCPT ); Wed, 31 Mar 2021 12:45:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617209133; 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=Nwj7au0bVAHGitRo2xZXQfk6qVnKwbNoNpFW+kN8KBM=; b=KbwmTe9fiFFo17h+DcKd1F3ljm9ufQ7PeZe5Y3RPXjM89sJpcmDXJ90LIdlG2cHybwamXG 5JXQ3dSdBmhy0+W1aUO3cckgZSuXVPqAF6YvWUWI2PZAa3KC28B3CFvSKo6YJ9WDMtYIWL IPzxTmHEuT6ErUsO9ITxPoieAKlG94k= 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-518-SzsGfUP8Ppelr8wVbp-twQ-1; Wed, 31 Mar 2021 12:45:29 -0400 X-MC-Unique: SzsGfUP8Ppelr8wVbp-twQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 674BE1084C95; Wed, 31 Mar 2021 16:45:28 +0000 (UTC) Received: from astarta.redhat.com (ovpn-114-48.ams2.redhat.com [10.36.114.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3210316922; Wed, 31 Mar 2021 16:45:26 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH bpf-next v3 8/8] selftests/bpf: ringbuf_multi: use runtime page size Date: Wed, 31 Mar 2021 19:45:04 +0300 Message-Id: <20210331164504.320614-8-yauheni.kaliuta@redhat.com> In-Reply-To: <20210331164504.320614-1-yauheni.kaliuta@redhat.com> References: <20210331164433.320534-1-yauheni.kaliuta@redhat.com> <20210331164504.320614-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Set bpf table sizes dynamically according to the runtime page size value. Do not switch to ASSERT macros, keep CHECK, for consistency with the rest of the test. Can be a separate cleanup patch. Signed-off-by: Yauheni Kaliuta --- .../selftests/bpf/prog_tests/ringbuf_multi.c | 23 ++++++++++++++++--- .../selftests/bpf/progs/test_ringbuf_multi.c | 1 - 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c index d37161e59bb2..159de99621c7 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c @@ -41,13 +41,30 @@ static int process_sample(void *ctx, void *data, size_t len) void test_ringbuf_multi(void) { struct test_ringbuf_multi *skel; - struct ring_buffer *ringbuf; + struct ring_buffer *ringbuf = NULL; int err; + int page_size = getpagesize(); - skel = test_ringbuf_multi__open_and_load(); - if (CHECK(!skel, "skel_open_load", "skeleton open&load failed\n")) + skel = test_ringbuf_multi__open(); + if (CHECK(!skel, "skel_open", "skeleton open failed\n")) return; + err = bpf_map__set_max_entries(skel->maps.ringbuf1, page_size); + if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) + goto cleanup; + + err = bpf_map__set_max_entries(skel->maps.ringbuf2, page_size); + if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) + goto cleanup; + + err = bpf_map__set_max_entries(bpf_map__inner_map(skel->maps.ringbuf_arr), page_size); + if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n")) + goto cleanup; + + err = test_ringbuf_multi__load(skel); + if (CHECK(err != 0, "skel_load", "skeleton load failed\n")) + goto cleanup; + /* only trigger BPF program for current process */ skel->bss->pid = getpid(); diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c index edf3b6953533..055c10b2ff80 100644 --- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c +++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c @@ -15,7 +15,6 @@ struct sample { struct ringbuf_map { __uint(type, BPF_MAP_TYPE_RINGBUF); - __uint(max_entries, 1 << 12); } ringbuf1 SEC(".maps"), ringbuf2 SEC(".maps");