From patchwork Tue Jul 23 16:21:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13740192 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 324E31581EE; Tue, 23 Jul 2024 16:22:11 +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=1721751732; cv=none; b=a3/zmsT0YggcTGGh5HzpKppNQkcaRSbi38d1KZbAF5T0xm/qTFgzkEtKZC7yvMdHjgd6gIUroRtYM+JDZnjCezhfcBSfGNU14ucnPtRp4dPqt58SgVOwSSxTFmcdR1Lp4RpwdcCQvpbBC+oro4IsvsVBbsBG7addwlermvtMi1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721751732; c=relaxed/simple; bh=w83YxVgebjmRwK2hKe6lEH7ZBsSGFING/dCqjGaSXbk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PxiqYJRB9QlwskXyIvN+4+UcPdQ65WR9m3r5CfHFfD/lWe3XBfrRNdK/yt4n1W39pvjxCNBnKVIBAjS34a4Ihgzqj4l6eJw7rEtK3hB4mGXgjlf5f6Yq6fYTLsPfBtQN+xQVMzHulPVPPwiXVQms4OOB8CVik1qGk+gMY8Eonuk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oj48lKrM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oj48lKrM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D0BEC4AF09; Tue, 23 Jul 2024 16:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721751731; bh=w83YxVgebjmRwK2hKe6lEH7ZBsSGFING/dCqjGaSXbk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oj48lKrMyxJIfMgOLgxvdcYvz9ko48mIBSR2XmtGov6RFVzmfjRsJvVrLGAeBZSlF u1ug4qxaPrrEUu6UrtIzmEq+Jq80snBSi8Y3vxH8X9dNepwFYYAzrq/4cuxMFd/y5H h8TNCdY7ZmKyvrymKDTiGthNzkXkCh4zYm8SpPXkUv2G3Jsbnl6+NKelSvXe6NjRQS anwoLJsvAmgb9Etai21y6O/eMMLg9NnHGmaMcTj/cg2cK6b++9NpTbIu8EWiJIMdY8 0J41/Qwbz/3qpJ4Z/FX8mq3m7+NFCQkal5LeoJ4fHC7AncQ1vVyFOgED2+WHFuTok8 FmJe47JGjoHww== From: Benjamin Tissoires Date: Tue, 23 Jul 2024 18:21:51 +0200 Subject: [PATCH HID 1/4] selftests/hid: fix bpf_wq new API Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240723-fix-6-11-bpf-v1-1-b9d770346784@kernel.org> References: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> In-Reply-To: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1721751728; l=1863; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=w83YxVgebjmRwK2hKe6lEH7ZBsSGFING/dCqjGaSXbk=; b=doRFw8hjh+OkurziZd/FmudQDjyJR2WhorOSi+P/YR87yVYtzz9LI7uShTJHSUpmg7OQAq0Hs feyiQrXg6sxDgrgkapb6OAv55gm4F+jtlm083u6UESvNS5mLtPUwHsY X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Since commit f56f4d541eab ("bpf: helpers: fix bpf_wq_set_callback_impl signature"), the API for bpf_wq changed a bit. We need to update the selftests/hid code to reflect that or the bpf program will not load. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/progs/hid.c | 2 +- tools/testing/selftests/hid/progs/hid_bpf_helpers.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c index ee9bbbcf751b..5ecc845ef792 100644 --- a/tools/testing/selftests/hid/progs/hid.c +++ b/tools/testing/selftests/hid/progs/hid.c @@ -455,7 +455,7 @@ struct { __type(value, struct elem); } hmap SEC(".maps"); -static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work) +static int wq_cb_sleepable(void *map, int *key, void *work) { __u8 buf[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10}; struct hid_bpf_ctx *hid_ctx; diff --git a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h index cfe37f491906..e5db897586bb 100644 --- a/tools/testing/selftests/hid/progs/hid_bpf_helpers.h +++ b/tools/testing/selftests/hid/progs/hid_bpf_helpers.h @@ -114,7 +114,7 @@ extern int hid_bpf_try_input_report(struct hid_bpf_ctx *ctx, extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym; extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, - int (callback_fn)(void *map, int *key, struct bpf_wq *wq), + int (callback_fn)(void *map, int *key, void *wq), unsigned int flags__k, void *aux__ign) __ksym; #define bpf_wq_set_callback(timer, cb, flags) \ bpf_wq_set_callback_impl(timer, cb, flags, NULL) From patchwork Tue Jul 23 16:21:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13740193 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 F404F1586C9; Tue, 23 Jul 2024 16:22:13 +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=1721751734; cv=none; b=UORGZKxuMQZXTYC8nFk5G20SSMOdqTSKQtvV8fPwn9UyG0FqAiYey5J+PoOFHjboAjYYiqllySN0o7l9f2KtxXyxSJRUmeWeX5oDZTlJ+K5hOuBy/xdtmkO0iOfGxjq6+XZiqUst8LvkT55Ldh6B3eM8Z5T+AVszY1IrH/Igw9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721751734; c=relaxed/simple; bh=+8630yexoVuxUvNFbPLwu8abD4gK79XhhzYX4yU2Te4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fu7D/9rhK7KX3iwR9ts8mWXx1wgRt2DzA4cxvS8jyniNAUL5a36Izgb4/hAfEHKZJobmggpVE4cotODCXKqwMej/icqHhsO8FE2VMzVthQc20njgmJfJoCO+YiBqYeA2S8IGPmq1Ehu9h2UvAiBBVISTtZ/sLZGI2CEwbQSeJ6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ShdnN7dd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ShdnN7dd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D684C4AF12; Tue, 23 Jul 2024 16:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721751733; bh=+8630yexoVuxUvNFbPLwu8abD4gK79XhhzYX4yU2Te4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ShdnN7dddNzIP47xK2+MUrTcatdElzfwqFIXEaNuTluYy1h8wgU8XH81GxW34QUyb 4+4dbx3h4SX/7IOpoNv1TeAd5rweSvSDgx3Wrh2K/4VOAvNW8pZNfQUv4/3blqXMPr gd2hCa5eaYNr14vO00grKcM3nGJegNoRJEeXKIYDhhvBr7bwJfHM6HckDXPE42zF3f L2/q6jHYSCrSu32Mi9tA9fdIJ/hx2mXr/WixX4KuUoOh5BpXIwbQ2sAOxDnHdJJx+o EZyQK5x8M1W4XXY175m5mnaVD2n3vyhbdX9q0OOMolFt2BnmmTK5sUD7x9tycPeDlk U+dwGDz3KatYA== From: Benjamin Tissoires Date: Tue, 23 Jul 2024 18:21:52 +0200 Subject: [PATCH HID 2/4] selftests/hid: disable struct_ops auto-attach Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240723-fix-6-11-bpf-v1-2-b9d770346784@kernel.org> References: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> In-Reply-To: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1721751728; l=1526; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=+8630yexoVuxUvNFbPLwu8abD4gK79XhhzYX4yU2Te4=; b=LbvGWq1ut/0R4rvXiqr63QXXewdqVAjgtztnEOLAx7oAMj6mLE0SsRKJKdXSFd8goDeoo2chD CeYhwyBiiAfBvylgJ2bu8w/wSg3jwdadNHin30Ub2l2CAuiNB+Pn0gq X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Since commit 08ac454e258e ("libbpf: Auto-attach struct_ops BPF maps in BPF skeleton"), libbpf automatically calls bpf_map__attach_struct_ops() on every struct_ops it sees in the bpf object. The problem is that our test bpf object has many of them but only one should be manually loaded at a time, or we end up locking the syscall. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c index dc0408a831d0..9c935fd0dffc 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -532,6 +532,7 @@ static void load_programs(const struct test_program programs[], FIXTURE_DATA(hid_bpf) * self, const FIXTURE_VARIANT(hid_bpf) * variant) { + struct bpf_map *iter_map; int err = -EINVAL; ASSERT_LE(progs_count, ARRAY_SIZE(self->hid_links)) @@ -564,6 +565,13 @@ static void load_programs(const struct test_program programs[], *ops_hid_id = self->hid_id; } + /* we disable the auto-attach feature of all maps because we + * only want the tested one to be manually attached in the next + * call to bpf_map__attach_struct_ops() + */ + bpf_object__for_each_map(iter_map, *self->skel->skeleton->obj) + bpf_map__set_autoattach(iter_map, false); + err = hid__load(self->skel); ASSERT_OK(err) TH_LOG("hid_skel_load failed: %d", err); From patchwork Tue Jul 23 16:21:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13740194 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 CC94C15886B; Tue, 23 Jul 2024 16:22:15 +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=1721751735; cv=none; b=hPVfrMM7pF8d78+dfznAHYjU/GZ8FDAj+UPLqf0+MpnrBG4t2l1aiyH3uA2jzkcJ+mSGtaUb2gNPlZOYU2gLPitVnS7X9C9G6ugW+VYIz5/PehF9cQvtM4C2DYR9B/Yg4hhNHE76QqUXbnjzV4kZP55PvnT0JFXGj0h82H+l14M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721751735; c=relaxed/simple; bh=wojTuv6su0uFmhRH2+1K0rFYVgCtGhL1z6RmaNynhg4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YIB7O9A14z7w7Uk6lgPsCLJk9OU9bK8Aew2dH1EJbAU7jCP+8bgEamcoonX9yOwtE5JiRub9cDpVQrd7l+jg0E/dPNHdLRfGXvxmTs0THfaAo9i/i89VIqmSZQbJlSV6QNH72LiFvPaLTb5oXOtC9YSA+uBTXqrDDYNfwnFoxgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DMhz/b0z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DMhz/b0z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D02BC4AF0C; Tue, 23 Jul 2024 16:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721751735; bh=wojTuv6su0uFmhRH2+1K0rFYVgCtGhL1z6RmaNynhg4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DMhz/b0zRh55DJOm8CWSnM5flgLHP7InrJLHCjgxIKnEjLET3ESAonxbZas3aK3Jh H6RrkUm9pD/GZZiMdkoa2Ol4rjK8jhL4MCnC9dqs2moOnzqjyVCkgCKQV3CjwPpYlp /zcHI4U5QJgW0/TIzH3fb/mtrjmfzLnwuyudL0aRbufy2Y6rYo3Yl9AVPK8B2COKiJ FWgKXLXFKc64lyAxQfpnOP6sAfMwBGFJC2a+X7kUU/UuGbEp+sEcq8qoLdR75up2ie Bz1d82HwICygyERZrHWKLyumfnF0q4eIJDcREWK6bfEpL3M/qEFaLYweIV2KvJ5iFc +asHo+76zBjiw== From: Benjamin Tissoires Date: Tue, 23 Jul 2024 18:21:53 +0200 Subject: [PATCH HID 3/4] HID: bpf: prevent the same struct_ops to be attached more than once Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240723-fix-6-11-bpf-v1-3-b9d770346784@kernel.org> References: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> In-Reply-To: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1721751728; l=1075; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=wojTuv6su0uFmhRH2+1K0rFYVgCtGhL1z6RmaNynhg4=; b=zl/ElL/hewvouwVJXiqkag8nfKVjOSgTcXX9gBKLkCqgaUZ6Ok09XqWGd08mn4k/WaJSTHtkp qvIS5KhjlGnCHoyICoTZqey/AG2P4RLq0Cx2gtDsVP1MxmQf+MEuNCF X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= If the struct_ops is already attached, we should bail out or we will end up in various locks and pointer issues while unregistering. Signed-off-by: Benjamin Tissoires --- drivers/hid/bpf/hid_bpf_struct_ops.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c index f59cce6e437f..cd696c59ba0f 100644 --- a/drivers/hid/bpf/hid_bpf_struct_ops.c +++ b/drivers/hid/bpf/hid_bpf_struct_ops.c @@ -183,6 +183,10 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link) struct hid_device *hdev; int count, err = 0; + /* prevent multiple attach of the same struct_ops */ + if (ops->hdev) + return -EINVAL; + hdev = hid_get_device(ops->hid_id); if (IS_ERR(hdev)) return PTR_ERR(hdev); @@ -248,6 +252,7 @@ static void hid_bpf_unreg(void *kdata, struct bpf_link *link) list_del_rcu(&ops->list); synchronize_srcu(&hdev->bpf.srcu); + ops->hdev = NULL; reconnect = hdev->bpf.rdesc_ops == ops; if (reconnect) From patchwork Tue Jul 23 16:21:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 13740195 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 A658E158A1F; Tue, 23 Jul 2024 16:22:17 +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=1721751737; cv=none; b=gkEBpjPAncb06vZ34hYuoEYuVglczlelHVy1zZ4YNGg2TEI/aoZ5+yoKkKTr4Ur1T/QpmohmMuGi7EstAO+uSLBJnSP0jkC5oPM4iG3mxQkEQRMves2L04jXw+mjD4FVURwwEiL9MyW82jC9AvkpqdorUa2gy7ftOa0VxcWtt1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721751737; c=relaxed/simple; bh=rbkwpDTz7JUQx62sDw+oVHWEAHwrQR6OSjMfDq8ibHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qdVYIdQDO1mUzH7Yze7uwz9R/TauPU5j1ZC7lqhWD97HZhuVZOQ/ZpBW0tNt8TWXH+4Dt6IboiWOcfFubBLKMyZ8vOMj9HBZ4O6fqhjRsj8aGHY7OMK0q4pDZh6Eor9PVGaloGjlcYk1Zz3d3gASghjFgtuT4oaWft2niqVSNkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xcnn9IhT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xcnn9IhT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1147C4AF09; Tue, 23 Jul 2024 16:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721751737; bh=rbkwpDTz7JUQx62sDw+oVHWEAHwrQR6OSjMfDq8ibHU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Xcnn9IhTdV53G/ModhKEbQDSMUV3IFkwy/yGYYDE9kTYWzH+NKESUgfHTeSBaF2PA INgnXoXgFauT0VhOjjf44CPcadvYnf/Lf1N/sggNx3nhdTu9MRmi6cjJZHskhVy4y1 MOw36NYA+6zAf7m/YezM6LtoFWkyGvVXVXYpfjC4xWHD5vRpvmfZ75P2fcuAcdVrEg t+J5YvFydLedgEm0E4h51YYtH4Vtg06ESLH2fLsJ3yskl/T0oPutJNWWjg1VNMAm9d tqxONYyWG76pPvQjjcP9eTFpmNvTWuvWaDo0mdbn7CD7ToIrBi+NiSri89kiOeoMdo yR4b1cvsCRB8A== From: Benjamin Tissoires Date: Tue, 23 Jul 2024 18:21:54 +0200 Subject: [PATCH HID 4/4] selftests/hid: add test for attaching multiple time the same struct_ops Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240723-fix-6-11-bpf-v1-4-b9d770346784@kernel.org> References: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> In-Reply-To: <20240723-fix-6-11-bpf-v1-0-b9d770346784@kernel.org> To: Jiri Kosina , Shuah Khan Cc: linux-input@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1721751728; l=1182; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=rbkwpDTz7JUQx62sDw+oVHWEAHwrQR6OSjMfDq8ibHU=; b=o462OkArDDHfVpI/bdKYU9U7nW92WlKzPZgakCpKBG595M3fkFpL0MBDj7Q3DYupX34eM8L0o PnACh9AIlBWA6Af5Rpki97NcuxJx12ghILHimKeeiXmKcCLHndejuh4 X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= Turns out that we would en up in a bad state if we attempt to attach twice the same HID-BPF struct_ops, so have a test for it. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/hid/hid_bpf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c index 9c935fd0dffc..75b7b4ef6cfa 100644 --- a/tools/testing/selftests/hid/hid_bpf.c +++ b/tools/testing/selftests/hid/hid_bpf.c @@ -694,6 +694,24 @@ TEST_F(hid_bpf, subprog_raw_event) ASSERT_EQ(buf[2], 52); } +/* + * Attach hid_first_event to the given uhid device, + * attempt at re-attaching it, we should not lock and + * return an invalid struct bpf_link + */ +TEST_F(hid_bpf, multiple_attach) +{ + const struct test_program progs[] = { + { .name = "hid_first_event" }, + }; + struct bpf_link *link; + + LOAD_PROGRAMS(progs); + + link = bpf_map__attach_struct_ops(self->skel->maps.first_event); + ASSERT_NULL(link) TH_LOG("unexpected return value when re-attaching the struct_ops"); +} + /* * Ensures that we can attach/detach programs */