Received: by 2002:a05:7208:3228:b0:82:47:81bb with SMTP id cb40csp2635809rbb; Tue, 16 Apr 2024 07:25:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKj3JALzzsiiE4zhYagYtTnu6UjIz5Vmob27QYLZ7PlYChzZfW3QYAmvLPhV7SV6kj+hX83+gdgxNo8RjOnntixwGWKaEZJes+WXa36Q== X-Google-Smtp-Source: AGHT+IHH9dCZfk+afN5kkkp+F413EFtwwxSzBLX+4kg6Wg82DWRcb0xfb6PG4eoOP+C5EImYvJRH X-Received: by 2002:a17:90a:ea81:b0:2a4:c2c4:4a84 with SMTP id h1-20020a17090aea8100b002a4c2c44a84mr12502276pjz.43.1713277535931; Tue, 16 Apr 2024 07:25:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713277535; cv=pass; d=google.com; s=arc-20160816; b=eimzBilI3Y/Ym2unnxGZP8qiScXIpq6CBbNZEfmMegkIF8woBBPAc5ViIjWTRMJB+A V6GYhlqRiHtzCLnf8Dyi4roDukrXtXn5EPtyTEIhuw8cIJoMs/Kvgugcn0LA4ssjMTpX n9kXEL7+2VJCXzqik7iwKzt2ikpkG8pjRL5s2BOhm2K17YlJ40stw4yMZIp7GNsjiSJ4 kmr95OfKvVaKgFWu4b164CE3nm5oV09MP9z6zQlmVuABSqg78FzFTC6q7TmsuHxxx75h x/yZXzSdZRAFuj5QnBZNiGtxFOXLf4q4YGjR7FZbl0OLogl+H1nqu+7O+MqvncmSrjFR Jc2A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=8DWeAZYg4nl+9HWiY0/sbfiAfoDbML+XHLiH7jyhkXQ=; fh=Cxwo/A+C89tjOzVq8R/o/DH+l+P6Lpt8VwbqwppZI0Y=; b=WxRvG+NoGKDeIinjnr7kVdUBO7oFg23J/2b1pkg+t9LMvG+2pPSqPCzzHTTeLdAfGH s9E3d2BmYReGwriJp2niOa7vEGAzSywkMCOWFzIV4++WUJuAIEpvQwYFp+J2gWk2sipc nzvRdqArKCgKHfOqhHJm9HA729/niibkkNK/zr1RFVJofFX8Lt01zyP+i6+mAY2M0vGt ZUhr/ASDMON4KUl+LMmorzhK/xa6wwuvcob8vqXK3j91t6HQfxwJIxdXIsHKKqeEAuOk NYGhTxvfMTTra6fdBuso1HuQhHuWgVW9cdVWS1+bAKa8DNSBncY2vIsUina4bBEfQuK8 WNtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ongPUkZu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-146963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146963-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id gf3-20020a17090ac7c300b002a52c195c06si12123427pjb.28.2024.04.16.07.25.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:25:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ongPUkZu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-146963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146963-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 85CCDB2383B for ; Tue, 16 Apr 2024 14:14:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 902AD13280F; Tue, 16 Apr 2024 14:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ongPUkZu" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A37A91327F1; Tue, 16 Apr 2024 14:10:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713276636; cv=none; b=UdxBFjSKynhLJSVz2nJV91/K/SAgfOjbohcWdORxxuYNowMGfiqXqEesVFCEX/DutOhc83IA1w74s1DS2I35JVCurknc4fZFIvZm3VNvf4jm7ZEKECbxbSraa8z5471FM8jlNGFRh03yh48FfRTem1rcn+ditGJeQeV6n1OIWeY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713276636; c=relaxed/simple; bh=roKe6QLjZdl9WIQ9S2oJ9wC/tRJNZ2Mefv37bh3CfbI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cllqX+LU8L4BjFRpHx8GUD4s1ddlCTz//Kbn1JpV2gyOscnj7k0rrIU06QLtRxliovR4y1fz6vM7Tb+osNtHNC7H+6+ZyWPUQhbtXlFZ+wxGf3CZqkNFSAR5RFsYPWO4zrb660gIw9PHCinUkqajgKYhuz5sgpMMCWUy6uxix9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ongPUkZu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E210C4AF15; Tue, 16 Apr 2024 14:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713276636; bh=roKe6QLjZdl9WIQ9S2oJ9wC/tRJNZ2Mefv37bh3CfbI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ongPUkZusfQcK3BlftlK9CngsAvAFUxzWB+ZYyfVBSY1jezJyeSd2PRGtEdgOeJN5 q4FGuRh5m2YNQ3WO78doX1nejPeIq2mK3qhie/5IndJ4H3BooHYCzhsH95fZAEtmoE tzkJexlHdWvOWcARws2+Masnyc5bxqUdrt1VcBBRukDC7QzkclyzpF8rcZ96RCXE4H RavDL1AZZxVnRo03iUjc8J2SpJo0tO98U3xL1i78vF3GweJMtwlMsQ77Aii59Ltobe yQ3FKvUgNJakfZan/oWk9JI5oFaWlkQ5eaStICPrbbW1nTgN801xLYrUWC6S/foq81 paUuy7XFDjK/Q== From: Benjamin Tissoires Date: Tue, 16 Apr 2024 16:08:23 +0200 Subject: [PATCH bpf-next 10/18] selftests/bpf: add bpf_wq tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240416-bpf_wq-v1-10-c9e66092f842@kernel.org> References: <20240416-bpf_wq-v1-0-c9e66092f842@kernel.org> In-Reply-To: <20240416-bpf_wq-v1-0-c9e66092f842@kernel.org> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713276593; l=3772; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=roKe6QLjZdl9WIQ9S2oJ9wC/tRJNZ2Mefv37bh3CfbI=; b=Ey1VwPVfH8tQjTD8L4stnUcwSbR0Jl/+gsak1M1w03LAPb3x4CD1hQYqFwl9tXXmGowCGLZ0U J0SyZi6LmBQD3xbXAR8qrfNuSGr/FoZdGLXYekDcrRwbjKDZKFilOrm X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= We simply try in all supported map types if we can store/load a bpf_wq. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/bpf/prog_tests/wq.c | 11 +++ tools/testing/selftests/bpf/progs/wq.c | 135 ++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/wq.c b/tools/testing/selftests/bpf/prog_tests/wq.c new file mode 100644 index 000000000000..9a07b8bc2c52 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/wq.c @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Benjamin Tissoires */ +#include +#include "wq.skel.h" + +void serial_test_wq(void) +{ + LIBBPF_OPTS(bpf_test_run_opts, topts); + + RUN_TESTS(wq); +} diff --git a/tools/testing/selftests/bpf/progs/wq.c b/tools/testing/selftests/bpf/progs/wq.c new file mode 100644 index 000000000000..8c668ad04059 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/wq.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Benjamin Tissoires + */ + +#include "bpf_experimental.h" +#include +#include "bpf_misc.h" +#include "../bpf_testmod/bpf_testmod_kfunc.h" + +char _license[] SEC("license") = "GPL"; + +struct hmap_elem { + int counter; + struct bpf_timer timer; /* unused */ + struct bpf_spin_lock lock; /* unused */ + struct bpf_wq work; +}; + +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(max_entries, 1000); + __type(key, int); + __type(value, struct hmap_elem); +} hmap SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(map_flags, BPF_F_NO_PREALLOC); + __uint(max_entries, 1000); + __type(key, int); + __type(value, struct hmap_elem); +} hmap_malloc SEC(".maps"); + +struct elem { + struct bpf_wq w; +}; + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 2); + __type(key, int); + __type(value, struct elem); +} array SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_LRU_HASH); + __uint(max_entries, 4); + __type(key, int); + __type(value, struct elem); +} lru SEC(".maps"); + +static int test_elem_callback(void *map, int *key) +{ + struct elem init = {}, *val; + + if (map == &lru && + bpf_map_update_elem(map, key, &init, 0)) + return -1; + + val = bpf_map_lookup_elem(map, key); + if (!val) + return -2; + + return 0; +} + +static int test_hmap_elem_callback(void *map, int *key) +{ + struct hmap_elem init = {}, *val; + + if (bpf_map_update_elem(map, key, &init, 0)) + return -1; + + val = bpf_map_lookup_elem(map, key); + if (!val) + return -2; + + return 0; +} + +SEC("tc") +/* test that workqueues can be used from an array + */ +__retval(0) +long test_call_array_sleepable(void *ctx) +{ + int key = 0; + + return test_elem_callback(&array, &key); +} + +SEC("syscall") +/* Same test than above but from a sleepable context. + */ +__retval(0) +long test_syscall_array_sleepable(void *ctx) +{ + int key = 1; + + return test_elem_callback(&array, &key); +} + +SEC("tc") +/* test that workqueues can be used from a hashmap + */ +__retval(0) +long test_call_hash_sleepable(void *ctx) +{ + int key = 2; + + return test_hmap_elem_callback(&hmap, &key); +} + +SEC("tc") +/* test that workqueues can be used from a hashmap + * with NO_PREALLOC. + */ +__retval(0) +long test_call_hash_malloc_sleepable(void *ctx) +{ + int key = 3; + + return test_hmap_elem_callback(&hmap_malloc, &key); +} + +SEC("tc") +/* test that workqueues can be used from a LRU map + */ +__retval(0) +long test_call_lru_sleepable(void *ctx) +{ + int key = 4; + + return test_elem_callback(&lru, &key); +} -- 2.44.0