From patchwork Fri Mar 8 01:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13586418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6517C54E4A for ; Fri, 8 Mar 2024 01:09:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3696B6B0308; Thu, 7 Mar 2024 20:09:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3167C6B0309; Thu, 7 Mar 2024 20:09:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 191F16B030A; Thu, 7 Mar 2024 20:09:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 053136B0308 for ; Thu, 7 Mar 2024 20:09:02 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D7B3EA1215 for ; Fri, 8 Mar 2024 01:09:01 +0000 (UTC) X-FDA: 81872087682.10.0CFD6FB Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf23.hostedemail.com (Postfix) with ESMTP id 0B0F214000C for ; Fri, 8 Mar 2024 01:08:59 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mvbd5nRG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709860140; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D38ixjnd/0kZdwFwUpxPlsmklHn50Lw3z4sv9DFS4v8=; b=LFSQ5QVivfOV/VY2hMQUQdOpahdncUFG9UOYJTl4Amn/evZ3oExz1ArXAWyub0i/lHJGD6 GCHW6/eR0gY+mxHLCBSsvTebMXniU0c+bmuhtVMGO5ckzaR7Z4MfT2TJhdWQoYFt3oPx1I n09d79OO+gdqAZxXXuPReZ8ZklXRc8k= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mvbd5nRG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709860140; a=rsa-sha256; cv=none; b=KzYLhxGTGK5541jw4eHZJR099U4Qkau0SqbnSHVxSyOlV7NGOkvlEIbc2WVsnXYPJvLRU3 NfyWBUPvpCAmPIvsnCxEotOUqGe/TpCGOC1G6mvO2ycTm56SFx5UhwdVMvMYyqjbltuRwO BbSLEDn41xLRevnv3guHa1hX4aNNjQg= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6e55731af5cso270683b3a.0 for ; Thu, 07 Mar 2024 17:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709860139; x=1710464939; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D38ixjnd/0kZdwFwUpxPlsmklHn50Lw3z4sv9DFS4v8=; b=mvbd5nRGKnxpW9YutXP+wezvRQIvsEkMhVYMGtZ3xfnQWoWpJ5XiNdHvEnn3kto7ON veJ1EKcQGoMk4ZJJiht8b6o0mcG80jELSJuHQUzv1DAkjaaAA9seyNrVXxWqE9RZQorl 5mH9CpA7HLTuLe6OltEO54zr2Buoj52OgrLQUI0g6ubL8uIF44Go7gB856OH4M4c0phu MWDbgiacY0Rb2t+pl2Mgk5RBL3MlecF2TRD6xdGdw6CExyHwkWFumziDOKnOJvP/yFBL jZwLk7HxfTdjV9q8HSMwxGF67UT3hZIOyYJNCnCDx6BnIJKBIzn7z5RiOpNhRQS36f+r B3nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709860139; x=1710464939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D38ixjnd/0kZdwFwUpxPlsmklHn50Lw3z4sv9DFS4v8=; b=ESiJ9JJwUBlEY+gTdj9F1tLH4WNxN3izsHY4aS+PIeWfRXCOV80aHQyCtMf9ugASFR 3sxxHdYAygA5nt3RAHSr6SM9CAFj+1F792sOHiEF/Td1bXYp37C9V+Vua8VYrFvWOGRm o+cSu1JE0u4F/MLf2IuZVD/+eJ81EZzC8YarKlLFY2SZPoUR7moBTepM/lbMYG+LONUT mi2BiJqsh4MafS5HSTRbvPMDnJRyS2g4BZK1BNkhT6Rl89PI/cCKZw62vZEkLMH8y79/ hIKlOB4aCCQzvotKiRF14jKk8rC2siyj6wBYYQxUnKFvJzwqtZRgtvwZT/FIS8zuc8wj qxpA== X-Forwarded-Encrypted: i=1; AJvYcCWyBS9cJfmwznUNETjTbl5Ty+n3BvCF7aYXslsATOWRqY63DhtMmjg/sqiY5rph6a14d33uOV1EgLCxY/HYWX/Xq5A= X-Gm-Message-State: AOJu0YyE7DsrfiIxDAPRRkdq147ii+Nku6F1Zs5AcWMJfhhF/8GJG1Su 5TvYQVOjpHy01xCr6+gVjiEkd9QUXizSXLvsar2sImcULk0YTqF4 X-Google-Smtp-Source: AGHT+IG73izPw3autz1dBVVk7fqkmTAZ0Abws1Y2STNRhHYf/EsHDbWJRVw6+giej666KIus6bbojQ== X-Received: by 2002:aa7:8446:0:b0:6e5:f456:bf0 with SMTP id r6-20020aa78446000000b006e5f4560bf0mr12040285pfn.22.1709860138826; Thu, 07 Mar 2024 17:08:58 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:428c]) by smtp.gmail.com with ESMTPSA id du6-20020a056a002b4600b006e5933a0da9sm13149770pfb.165.2024.03.07.17.08.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 Mar 2024 17:08:58 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH v3 bpf-next 12/14] selftests/bpf: Add unit tests for bpf_arena_alloc/free_pages Date: Thu, 7 Mar 2024 17:08:10 -0800 Message-Id: <20240308010812.89848-13-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240308010812.89848-1-alexei.starovoitov@gmail.com> References: <20240308010812.89848-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0B0F214000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 5ssjcsscnxhg7ydwzc7qky3fkwkmf6gi X-HE-Tag: 1709860139-326054 X-HE-Meta: U2FsdGVkX1+E+Pde4GJJpMxXam5KjpH7EE/dB0N4D5QmWUX62NS6LUhAugcerFiG+m1sRrSBR7zzTvdFEfoGpFK/QojFs5fRuGeeS+DftnIyyGf6xtuIhUcra5Ud8aPNKsa61OZ2T3QM9JpizMQTaFpaWa85MfjJ37Fm4AQAaf3Dty2f+5KdVak31lSFPgRB5jCWtwlNOOhrC+C7Yae8PnQ6/3Ml5VVRD5mukgLKSeXuQ4GF3Aui0W5J89cXMtXom3NoTc3ZqHHWrSxHQaLpZFsLMvij8YJz0YS7P+U8bTLkIHBLFzX3OuBB9mwUkm/ZOtpZ+mE9dmuQGKYM6aeLhyq/wlLkUfqSFzc9sUQZ6MB/MapJgGgFqO+CFqN4bngxgEJzB1GZ9d6CLS9dAzVpjrWhdgCBE6L6ww8inMrrID0jxfo9CfSZlEVqeu1x70exQ9S/n9KiU52CnLUEM1vk5JiZWy8Zc2q9/8urx/6gbG2mPxfBWz4GWswJBYEj7z11X2g2pNkDclUtKFTQfM2JiwOQfcTy95QMny5VNUMv59tOqmW05klUR5r7ufNaLrUSy6qaCMzZK3EF+a7ntZ/oBjopGvCHe+ZauTnhCuor0uDXaGjgoHLlQBXbtzHKqJ9NZMf2hjvrk+bBR/7BJCyBk3DUjUQcNaPM4rL9DCxhhxxd2uKYfk1O/ASn/+u8XVOslbBPv942j8sjKQ+Resieqyaq0z/EkkDTXf5Len0ofX3nl/CRs7HheReVjwDHu7NtXiPxxyXdgI4idNfv7oMLfaYyrgwOqliI191TJFdSIWB0rnM5O3mg1ebs0P9Qg7XSklg5V5X8p1oM05b0eAS8fdTuD9zyy1JHyW6PK8XYJMX+hCarhueChzK8Uc0RBK+7cPomPQNm9EtJE0bAhN2RA3F8BlY7+FEmRQgc62B7/xQnQUe5x7dMra6psWDnzlqzDMEoADaSTD2LmdGZDYa C59lT2BA eQu2ff2XxKT3YnlQ5byPFVS35abNVska6E7YCqbvgHRrQXgXbXoOsQSz8j0OIaboIqEsqc2x0LrMG8ptZGH16A92kzJEmHSO3/BQcEhBfh7Bu186ndXVZdn8WPUPn4YTe304KAt+IlktTcdtSG4FOaFCd0hldNtxQTWxXMs78NCTfSkuOFikoKHAXeOtZi5HIMRgg45oblkmvzyLkpYpMnZAwDAg/nnQj4oSuCHvwjcL7iz9AzwS/tqYyAgu2mhkKuPGK6crb16b/bw379CseXAlWIIjyIlmex1G9zwmJFrHv/CCSRbY0woUI1bh8slJRcj969kuHfPR/Kf6ODDSMOegqWg/mBO6Xg4L4efZxYIx+HxmLT5SsxbYMZmoXeATITajZ3VNsJfrZ3c1zeBkk7OLK61aznYkt3vor/rXiYOLK2TLWlf8EL3p7jSQASvSH9trTryocKmbVzJsX1x4AMUmJ1/N+D98WkM9ENUvJMUCGG4g6tfruvOOpo4ydB6F0D3EWm4pEQxm+j8bLSJMfeiZVypzRwWmvWn0wYfzfdCe3AbwHDgQHpp/M96vfVJsbfx/K X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov Add unit tests for bpf_arena_alloc/free_pages() functionality and bpf_arena_common.h with a set of common helpers and macros that is used in this test and the following patches. Also modify test_loader that didn't support running bpf_prog_type_syscall programs. Signed-off-by: Alexei Starovoitov --- tools/testing/selftests/bpf/DENYLIST.aarch64 | 1 + tools/testing/selftests/bpf/DENYLIST.s390x | 1 + .../testing/selftests/bpf/bpf_arena_common.h | 70 +++++++++ .../selftests/bpf/prog_tests/verifier.c | 2 + .../selftests/bpf/progs/verifier_arena.c | 146 ++++++++++++++++++ tools/testing/selftests/bpf/test_loader.c | 9 +- 6 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/bpf_arena_common.h create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena.c diff --git a/tools/testing/selftests/bpf/DENYLIST.aarch64 b/tools/testing/selftests/bpf/DENYLIST.aarch64 index 0445ac38bc07..f9101651747b 100644 --- a/tools/testing/selftests/bpf/DENYLIST.aarch64 +++ b/tools/testing/selftests/bpf/DENYLIST.aarch64 @@ -10,3 +10,4 @@ fill_link_info/kprobe_multi_link_info # bpf_program__attach_kprobe_mu fill_link_info/kretprobe_multi_link_info # bpf_program__attach_kprobe_multi_opts unexpected error: -95 fill_link_info/kprobe_multi_invalid_ubuff # bpf_program__attach_kprobe_multi_opts unexpected error: -95 missed/kprobe_recursion # missed_kprobe_recursion__attach unexpected error: -95 (errno 95) +verifier_arena # JIT does not support arena diff --git a/tools/testing/selftests/bpf/DENYLIST.s390x b/tools/testing/selftests/bpf/DENYLIST.s390x index cb810a98e78f..aa8a620f3318 100644 --- a/tools/testing/selftests/bpf/DENYLIST.s390x +++ b/tools/testing/selftests/bpf/DENYLIST.s390x @@ -4,3 +4,4 @@ exceptions # JIT does not support calling kfunc bpf_throw (excepti get_stack_raw_tp # user_stack corrupted user stack (no backchain userspace) stacktrace_build_id # compare_map_keys stackid_hmap vs. stackmap err -2 errno 2 (?) verifier_iterating_callbacks +verifier_arena # JIT does not support arena diff --git a/tools/testing/selftests/bpf/bpf_arena_common.h b/tools/testing/selftests/bpf/bpf_arena_common.h new file mode 100644 index 000000000000..bcf195c64a45 --- /dev/null +++ b/tools/testing/selftests/bpf/bpf_arena_common.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ +#pragma once + +#ifndef WRITE_ONCE +#define WRITE_ONCE(x, val) ((*(volatile typeof(x) *) &(x)) = (val)) +#endif + +#ifndef NUMA_NO_NODE +#define NUMA_NO_NODE (-1) +#endif + +#ifndef arena_container_of +#define arena_container_of(ptr, type, member) \ + ({ \ + void __arena *__mptr = (void __arena *)(ptr); \ + ((type *)(__mptr - offsetof(type, member))); \ + }) +#endif + +#ifdef __BPF__ /* when compiled as bpf program */ + +#ifndef PAGE_SIZE +#define PAGE_SIZE __PAGE_SIZE +/* + * for older kernels try sizeof(struct genradix_node) + * or flexible: + * static inline long __bpf_page_size(void) { + * return bpf_core_enum_value(enum page_size_enum___l, __PAGE_SIZE___l) ?: sizeof(struct genradix_node); + * } + * but generated code is not great. + */ +#endif + +#if defined(__BPF_FEATURE_ARENA_CAST) && !defined(BPF_ARENA_FORCE_ASM) +#define __arena __attribute__((address_space(1))) +#define cast_kern(ptr) /* nop for bpf prog. emitted by LLVM */ +#define cast_user(ptr) /* nop for bpf prog. emitted by LLVM */ +#else +#define __arena +#define cast_kern(ptr) bpf_addr_space_cast(ptr, 0, 1) +#define cast_user(ptr) bpf_addr_space_cast(ptr, 1, 0) +#endif + +void __arena* bpf_arena_alloc_pages(void *map, void __arena *addr, __u32 page_cnt, + int node_id, __u64 flags) __ksym __weak; +void bpf_arena_free_pages(void *map, void __arena *ptr, __u32 page_cnt) __ksym __weak; + +#else /* when compiled as user space code */ + +#define __arena +#define __arg_arena +#define cast_kern(ptr) /* nop for user space */ +#define cast_user(ptr) /* nop for user space */ +__weak char arena[1]; + +#ifndef offsetof +#define offsetof(type, member) ((unsigned long)&((type *)0)->member) +#endif + +static inline void __arena* bpf_arena_alloc_pages(void *map, void *addr, __u32 page_cnt, + int node_id, __u64 flags) +{ + return NULL; +} +static inline void bpf_arena_free_pages(void *map, void __arena *ptr, __u32 page_cnt) +{ +} + +#endif diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c index 9c6072a19745..985273832f89 100644 --- a/tools/testing/selftests/bpf/prog_tests/verifier.c +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c @@ -4,6 +4,7 @@ #include "cap_helpers.h" #include "verifier_and.skel.h" +#include "verifier_arena.skel.h" #include "verifier_array_access.skel.h" #include "verifier_basic_stack.skel.h" #include "verifier_bitfield_write.skel.h" @@ -118,6 +119,7 @@ static void run_tests_aux(const char *skel_name, #define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL) void test_verifier_and(void) { RUN(verifier_and); } +void test_verifier_arena(void) { RUN(verifier_arena); } void test_verifier_basic_stack(void) { RUN(verifier_basic_stack); } void test_verifier_bitfield_write(void) { RUN(verifier_bitfield_write); } void test_verifier_bounds(void) { RUN(verifier_bounds); } diff --git a/tools/testing/selftests/bpf/progs/verifier_arena.c b/tools/testing/selftests/bpf/progs/verifier_arena.c new file mode 100644 index 000000000000..5540b05ff9ee --- /dev/null +++ b/tools/testing/selftests/bpf/progs/verifier_arena.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include "bpf_misc.h" +#include "bpf_experimental.h" +#include "bpf_arena_common.h" + +struct { + __uint(type, BPF_MAP_TYPE_ARENA); + __uint(map_flags, BPF_F_MMAPABLE); + __uint(max_entries, 2); /* arena of two pages close to 32-bit boundary*/ + __ulong(map_extra, (1ull << 44) | (~0u - __PAGE_SIZE * 2 + 1)); /* start of mmap() region */ +} arena SEC(".maps"); + +SEC("syscall") +__success __retval(0) +int basic_alloc1(void *ctx) +{ +#if defined(__BPF_FEATURE_ARENA_CAST) + volatile int __arena *page1, *page2, *no_page, *page3; + + page1 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0); + if (!page1) + return 1; + *page1 = 1; + page2 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0); + if (!page2) + return 2; + *page2 = 2; + no_page = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0); + if (no_page) + return 3; + if (*page1 != 1) + return 4; + if (*page2 != 2) + return 5; + bpf_arena_free_pages(&arena, (void __arena *)page2, 1); + if (*page1 != 1) + return 6; + if (*page2 != 0) /* use-after-free should return 0 */ + return 7; + page3 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0); + if (!page3) + return 8; + *page3 = 3; + if (page2 != page3) + return 9; + if (*page1 != 1) + return 10; +#endif + return 0; +} + +SEC("syscall") +__success __retval(0) +int basic_alloc2(void *ctx) +{ +#if defined(__BPF_FEATURE_ARENA_CAST) + volatile char __arena *page1, *page2, *page3, *page4; + + page1 = bpf_arena_alloc_pages(&arena, NULL, 2, NUMA_NO_NODE, 0); + if (!page1) + return 1; + page2 = page1 + __PAGE_SIZE; + page3 = page1 + __PAGE_SIZE * 2; + page4 = page1 - __PAGE_SIZE; + *page1 = 1; + *page2 = 2; + *page3 = 3; + *page4 = 4; + if (*page1 != 1) + return 1; + if (*page2 != 2) + return 2; + if (*page3 != 0) + return 3; + if (*page4 != 0) + return 4; + bpf_arena_free_pages(&arena, (void __arena *)page1, 2); + if (*page1 != 0) + return 5; + if (*page2 != 0) + return 6; + if (*page3 != 0) + return 7; + if (*page4 != 0) + return 8; +#endif + return 0; +} + +struct bpf_arena___l { + struct bpf_map map; +} __attribute__((preserve_access_index)); + +SEC("syscall") +__success __retval(0) __log_level(2) +int basic_alloc3(void *ctx) +{ + struct bpf_arena___l *ar = (struct bpf_arena___l *)&arena; + volatile char __arena *pages; + + pages = bpf_arena_alloc_pages(&ar->map, NULL, ar->map.max_entries, NUMA_NO_NODE, 0); + if (!pages) + return 1; + return 0; +} + +SEC("iter.s/bpf_map") +__success __log_level(2) +int iter_maps1(struct bpf_iter__bpf_map *ctx) +{ + struct bpf_map *map = ctx->map; + + if (!map) + return 0; + bpf_arena_alloc_pages(map, NULL, map->max_entries, 0, 0); + return 0; +} + +SEC("iter.s/bpf_map") +__failure __msg("expected pointer to STRUCT bpf_map") +int iter_maps2(struct bpf_iter__bpf_map *ctx) +{ + struct seq_file *seq = ctx->meta->seq; + + bpf_arena_alloc_pages((void *)seq, NULL, 1, 0, 0); + return 0; +} + +SEC("iter.s/bpf_map") +__failure __msg("untrusted_ptr_bpf_map") +int iter_maps3(struct bpf_iter__bpf_map *ctx) +{ + struct bpf_map *map = ctx->map; + + if (!map) + return 0; + bpf_arena_alloc_pages(map->inner_map_meta, NULL, map->max_entries, 0, 0); + return 0; +} + +char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c index ba57601c2a4d..524c38e9cde4 100644 --- a/tools/testing/selftests/bpf/test_loader.c +++ b/tools/testing/selftests/bpf/test_loader.c @@ -501,7 +501,7 @@ static bool is_unpriv_capable_map(struct bpf_map *map) } } -static int do_prog_test_run(int fd_prog, int *retval) +static int do_prog_test_run(int fd_prog, int *retval, bool empty_opts) { __u8 tmp_out[TEST_DATA_LEN << 2] = {}; __u8 tmp_in[TEST_DATA_LEN] = {}; @@ -514,6 +514,10 @@ static int do_prog_test_run(int fd_prog, int *retval) .repeat = 1, ); + if (empty_opts) { + memset(&topts, 0, sizeof(struct bpf_test_run_opts)); + topts.sz = sizeof(struct bpf_test_run_opts); + } err = bpf_prog_test_run_opts(fd_prog, &topts); saved_errno = errno; @@ -649,7 +653,8 @@ void run_subtest(struct test_loader *tester, } } - do_prog_test_run(bpf_program__fd(tprog), &retval); + do_prog_test_run(bpf_program__fd(tprog), &retval, + bpf_program__type(tprog) == BPF_PROG_TYPE_SYSCALL ? true : false); if (retval != subspec->retval && subspec->retval != POINTER_VALUE) { PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval); goto tobj_cleanup;