Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1136479lqt; Sat, 20 Apr 2024 02:12:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJT6Q3shrUVo4dcnEZkiwneouMB0vl/uUnfxUrcG5E7G4s6BLiJF3CbGRxVtcnGnwz/KCjlc3Gpyzw1X6qYlMyG+0HX3xJbyPXZJEa5A== X-Google-Smtp-Source: AGHT+IFV8qEHnTNJ5i9FYOGaF1hrJLcJLoI58c9kdY5UoHHEvK39ibdFWiZ2ygjW4uHsDJ/PO5eu X-Received: by 2002:a05:651c:1a06:b0:2d8:34ec:54e6 with SMTP id by6-20020a05651c1a0600b002d834ec54e6mr3030310ljb.33.1713604361017; Sat, 20 Apr 2024 02:12:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713604360; cv=pass; d=google.com; s=arc-20160816; b=YLnsZ5y+QfxO08q4GkYSHzH0dHt7+N0hmwhi+VFsttEU5MCyMSm47GSx1euavtFBvx A4dmjLLtrR+O5Np2HVLZRbTza3PNkGXY6ZNWBSfiEbNLPGbAFq4GxVJjINMHeEgRVHoj iJYZHUBPrRAzirO1Mi3WClskqL1tmKEkl68Cbq9T98FJucPihfTJl6elP+UNMBXUajHH OUeutow34V2Zh8zvD0OrhOwpfi8jVpAlNB15Sb/OzkqNHVyI2up+ZFAGlAWTl+SFKZnv D+kf5Kiq8LB9eFuGYhJn+tmHMD6JBsWn1vO9MWhrFyt/0AuqRCuD04wPoMMmBx9ATuEK OObw== 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=PJ5F/d9vldFxjBcnr7Nw5FmE7zi84sSNhNqPYFXfOV8=; fh=Cxwo/A+C89tjOzVq8R/o/DH+l+P6Lpt8VwbqwppZI0Y=; b=Ys4jf1TlSD3BBXeZbWfeeSNBfG2sDJixfnLY10Eh4fr6nOGaTwQ0exW9zMFhbW+Z3W XVZbGSs7yDkKa+rKlieev3EyzF15cTMUc6btsTiDIDxRyiQyMoI4joXmtRw3sxAdnMdL S8nTRG9ev622sg3a7X4FFPwarAZsb8JLtumbW/k53j5N8H4Z41bWwQ9kNSQmrPH9mubS NYWfY3f3YQLuYKwmzV5e5uQNDFUyHckEFZjaU+OpFgxST3flQkJmTElHx0JwVURffmTk l4NupHvv2Gn+nTmkdJX1tJPMiYH73Cfgun+kRmPLSYGRL3E7yw7vFjJrnGOEcPiB+Mmk y/uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=anRgPcMi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152195-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152195-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d9-20020aa7d5c9000000b00571b93fb0b3si3164911eds.665.2024.04.20.02.12.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 02:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152195-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=anRgPcMi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152195-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152195-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8DF4F1F22602 for ; Sat, 20 Apr 2024 09:12:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EA804AEC3; Sat, 20 Apr 2024 09:10:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="anRgPcMi" 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 47E704AEF6; Sat, 20 Apr 2024 09:10:08 +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=1713604209; cv=none; b=dcgF6EAxmrxI7CvjUCYRQgpr+qdu5yeDdon8xSkkuyURc8HzXEP/JOW8yHtSFJ5TsZpqOlGGhRDYBieotWsZUAF8RcNOxaInn1+KMU9ZRVry/hJOiEZRXI2Tj891O4a3kToRgPA7XMUk5+Oc1bVRc2pEtXJgAuS1yp+8T91xclU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713604209; c=relaxed/simple; bh=dgl1Ep3U0dFJ7nrTFAsQUO+nU+CafbtbJcO/cfdK8UM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jjo5dWLQmdJk1qsM3SdNNpzEWnnqnPLeryMpYYXUovZaoUC9qm0lqI5P5HuM3JyQPDhYtVlCCJG+pCkUEsDp6JaRE5qIKfadWutT2pNUCncBAC1XJWI8m2Ygra+mkxwXqaYSaZ+0lpE/rlmG5Zx94JvxFFmIjrWkXo3CsYipmWQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=anRgPcMi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 751D8C32781; Sat, 20 Apr 2024 09:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713604208; bh=dgl1Ep3U0dFJ7nrTFAsQUO+nU+CafbtbJcO/cfdK8UM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=anRgPcMivSeAKJK+Ael0fYxCQrX5N4WJE9heInbgEQ+ce6gSDyuyCSHqIGyE4Bmlf HS1HQGAQO9aR+CqbvoIO64tv3ZCieXjf4BhZ4poACvQCEHIJfHCTAsswJ80IgAQ+7z 4Y3wMkOzUBCMdOqGPaEOXBj068c/anjNCiyllDdcAjeew0oi/21CNRtQVcFC9MY3Li 1IrPag5RxyoNFkgNzh2dxfp3i4cTGV/3qRS749NAPAGXdT7jKCx0la9UfPNeXm4kuN bJ83kQcjmIFCuhs2HFeRHW9SykgAO+mWijglsuSD/zCJgrV0SmIFhUolSHO1AXuvC9 NW11IR7t/3VDw== From: Benjamin Tissoires Date: Sat, 20 Apr 2024 11:09:12 +0200 Subject: [PATCH bpf-next v2 12/16] selftests/bpf: wq: add bpf_wq_init() checks 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: <20240420-bpf_wq-v2-12-6c986a5a741f@kernel.org> References: <20240420-bpf_wq-v2-0-6c986a5a741f@kernel.org> In-Reply-To: <20240420-bpf_wq-v2-0-6c986a5a741f@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=1713604159; l=4667; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=dgl1Ep3U0dFJ7nrTFAsQUO+nU+CafbtbJcO/cfdK8UM=; b=JBJF0zs0pMsZXDgS6At1THNlx6u5LvuLPJqnWvwIEx/8DtAXz38sgWbpGBhLgqdOaaKKSkoJ+ w2ldAv7l5n3AW/6D2I+So7fUFGRAK39c2Gobl5GAlvIvTIMSZ1n8kHg X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Allows to test if allocation/free works Signed-off-by: Benjamin Tissoires --- changes in v2: - dropped mark_precise checks --- tools/testing/selftests/bpf/bpf_experimental.h | 1 + tools/testing/selftests/bpf/prog_tests/wq.c | 8 +++ tools/testing/selftests/bpf/progs/wq.c | 10 ++++ tools/testing/selftests/bpf/progs/wq_failures.c | 78 +++++++++++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index 3329ea080865..785b91b629be 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -470,4 +470,5 @@ extern int bpf_iter_css_new(struct bpf_iter_css *it, extern struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *it) __weak __ksym; extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym; +extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; #endif diff --git a/tools/testing/selftests/bpf/prog_tests/wq.c b/tools/testing/selftests/bpf/prog_tests/wq.c index 9a07b8bc2c52..26ab69796103 100644 --- a/tools/testing/selftests/bpf/prog_tests/wq.c +++ b/tools/testing/selftests/bpf/prog_tests/wq.c @@ -2,6 +2,7 @@ /* Copyright (c) 2024 Benjamin Tissoires */ #include #include "wq.skel.h" +#include "wq_failures.skel.h" void serial_test_wq(void) { @@ -9,3 +10,10 @@ void serial_test_wq(void) RUN_TESTS(wq); } + +void serial_test_failures_wq(void) +{ + LIBBPF_OPTS(bpf_test_run_opts, topts); + + RUN_TESTS(wq_failures); +} diff --git a/tools/testing/selftests/bpf/progs/wq.c b/tools/testing/selftests/bpf/progs/wq.c index 8c668ad04059..f92466eb8fb1 100644 --- a/tools/testing/selftests/bpf/progs/wq.c +++ b/tools/testing/selftests/bpf/progs/wq.c @@ -52,6 +52,7 @@ struct { static int test_elem_callback(void *map, int *key) { struct elem init = {}, *val; + struct bpf_wq *wq; if (map == &lru && bpf_map_update_elem(map, key, &init, 0)) @@ -61,12 +62,17 @@ static int test_elem_callback(void *map, int *key) if (!val) return -2; + wq = &val->w; + if (bpf_wq_init(wq, map, 0) != 0) + return -3; + return 0; } static int test_hmap_elem_callback(void *map, int *key) { struct hmap_elem init = {}, *val; + struct bpf_wq *wq; if (bpf_map_update_elem(map, key, &init, 0)) return -1; @@ -75,6 +81,10 @@ static int test_hmap_elem_callback(void *map, int *key) if (!val) return -2; + wq = &val->work; + if (bpf_wq_init(wq, map, 0) != 0) + return -3; + return 0; } diff --git a/tools/testing/selftests/bpf/progs/wq_failures.c b/tools/testing/selftests/bpf/progs/wq_failures.c new file mode 100644 index 000000000000..db7015c7d541 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/wq_failures.c @@ -0,0 +1,78 @@ +// 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 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"); + +SEC("tc") +/* test that bpf_wq_init takes a map as a second argument + */ +__log_level(2) +__flag(BPF_F_TEST_STATE_FREQ) +__failure +__msg(": (85) call bpf_wq_init#") /* anchor message */ +__msg("pointer in R2 isn't map pointer") +long test_wq_init_nomap(void *ctx) +{ + struct bpf_wq *wq; + struct elem *val; + int key = 0; + + val = bpf_map_lookup_elem(&array, &key); + if (!val) + return -1; + + wq = &val->w; + if (bpf_wq_init(wq, &key, 0) != 0) + return -3; + + return 0; +} + +SEC("tc") +/* test that the workqueue is part of the map in bpf_wq_init + */ +__log_level(2) +__flag(BPF_F_TEST_STATE_FREQ) +__failure +__msg(": (85) call bpf_wq_init#") /* anchor message */ +__msg("workqueue pointer in R1 map_uid=0 doesn't match map pointer in R2 map_uid=0") +long test_wq_init_wrong_map(void *ctx) +{ + struct bpf_wq *wq; + struct elem *val; + int key = 0; + + val = bpf_map_lookup_elem(&array, &key); + if (!val) + return -1; + + wq = &val->w; + if (bpf_wq_init(wq, &lru, 0) != 0) + return -3; + + return 0; +} -- 2.44.0