From patchwork Fri Mar 26 11:47:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166421 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 25BB2C433C1 for ; Fri, 26 Mar 2021 11:48:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0064F61A4D for ; Fri, 26 Mar 2021 11:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbhCZLrj (ORCPT ); Fri, 26 Mar 2021 07:47:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60807 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbhCZLra (ORCPT ); Fri, 26 Mar 2021 07:47:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616759250; 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=gc1W+g7+Qqj0wdFeGGKfaKUM9cWERShWx2Lfq2g33rGahpUZRH6fvxpu7OfVsqRPBaSACs siWxNCBNqVyAmznjxmJGZw027M5zBlYXUSo0jcHOrCvde9ILE8tL5UAiAhMzPzUwYe7ETX cEUHD1oCs1E6vmOn5Xht5nYYd8kGzTU= 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-578-IIM9zxEKNL2edDbp7N_LSg-1; Fri, 26 Mar 2021 07:47:28 -0400 X-MC-Unique: IIM9zxEKNL2edDbp7N_LSg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BDDD51005D4F; Fri, 26 Mar 2021 11:47:27 +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 3DC186060F; Fri, 26 Mar 2021 11:47:23 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH 1/3] selftests/bpf: test_progs/sockopt_sk: pass page size from userspace Date: Fri, 26 Mar 2021 13:47:20 +0200 Message-Id: <20210326114722.210109-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.13 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 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 11:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166425 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 5E11BC433E1 for ; Fri, 26 Mar 2021 11:48:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EA0061A50 for ; Fri, 26 Mar 2021 11:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbhCZLrj (ORCPT ); Fri, 26 Mar 2021 07:47:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54669 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbhCZLrf (ORCPT ); Fri, 26 Mar 2021 07:47:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616759254; 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=WrrjktyImPOZVJXY89TbmXtd76vrkdHgc1EL0BLZ8KWKsuH/uhxmkDNCBbV1KnCZowBsbh J+P6kVLmzXHIjB7y9ba93t9ub5ClMI7dvcqv5b0rcwJIU0E8R2zUuZSiJyXGTRcNCiNA/V FWr3NjxRfT5MGmMw0nJ0LlObgtiDrLE= 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-513--Nn0T8xnNJ-NWOsOX4OI2A-1; Fri, 26 Mar 2021 07:47:30 -0400 X-MC-Unique: -Nn0T8xnNJ-NWOsOX4OI2A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9732010866A4; Fri, 26 Mar 2021 11:47:29 +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 2B5A860CE9; Fri, 26 Mar 2021 11:47:27 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH 2/3] bpf: selftests: test_progs/sockopt_sk: remove version Date: Fri, 26 Mar 2021 13:47:21 +0200 Message-Id: <20210326114722.210109-2-yauheni.kaliuta@redhat.com> In-Reply-To: <20210326114722.210109-1-yauheni.kaliuta@redhat.com> References: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> <20210326114722.210109-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 11:47:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 12166423 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 16AF4C433DB for ; Fri, 26 Mar 2021 11:48:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC7EE61601 for ; Fri, 26 Mar 2021 11:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbhCZLrj (ORCPT ); Fri, 26 Mar 2021 07:47:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52181 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbhCZLre (ORCPT ); Fri, 26 Mar 2021 07:47:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616759254; 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=fuqGUGaDjkvAMb+uHHikjkaHBZnZDqliCbi4eew0GyFAw+a6GR9svBBiqxIEGOOkzLF5A2 Bvk0qEL3XBhnfM43qNxA8WaVc6bskp5UQdhCxOhIcomlaD1czq5PpAceqfIKmRkFj3bnGF jCnwTF9RqaR93Adigbz8AGAjH/0vRRw= 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-445-F_Gc0CvBNcKt03qrS7ZgtA-1; Fri, 26 Mar 2021 07:47:32 -0400 X-MC-Unique: F_Gc0CvBNcKt03qrS7ZgtA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EAC487A83C; Fri, 26 Mar 2021 11:47:31 +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 F402D6060F; Fri, 26 Mar 2021 11:47:29 +0000 (UTC) From: Yauheni Kaliuta To: bpf@vger.kernel.org Cc: andrii@kernel.org, jolsa@redhat.com, Yauheni Kaliuta Subject: [PATCH 3/3] selftests/bpf: ringbuf, mmap: bump up page size to 64K Date: Fri, 26 Mar 2021 13:47:22 +0200 Message-Id: <20210326114722.210109-3-yauheni.kaliuta@redhat.com> In-Reply-To: <20210326114722.210109-1-yauheni.kaliuta@redhat.com> References: <20210326114658.210034-1-yauheni.kaliuta@redhat.com> <20210326114722.210109-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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");