From patchwork Fri Jul 5 13:44: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: 13725153 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 B8D6414D2B8; Fri, 5 Jul 2024 13:45:07 +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=1720187107; cv=none; b=Q9sphdWOmTt4AxlKdTZWwX7ZP8hVrZFwJSs5uHvW8DWpSHptNFnN7isf1Sjm0K9ynPjCw3vc6yQeqeqYw32X9aiySOYhruAy4sln8GRcoc/ahOGBoxLJbQU6m8RAzb0x11019SIAdJ0OwaKzLfjKRuuBSgis8areGH566h/r7IA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720187107; c=relaxed/simple; bh=tmlkinceJ217REpu6WVDDhCLWZe8vaBSsNuNDlMyUz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pNV7p1tBfmRuxMVY2+CzGhQvKJmNdrH1De0vGLptA34ObuMRM/0sIuh23A/wpF54cBszDo5jk7y8Xk+uRINcqGENH3SrJdSQUhtaq0fYD+o2hhKfYFbDTpmAg1PAnDFlQm4u020HMArK6C8VutkwMxfpjerXMl1NpjCZSRaAT2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A+jHveHw; 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="A+jHveHw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB69BC4AF11; Fri, 5 Jul 2024 13:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720187107; bh=tmlkinceJ217REpu6WVDDhCLWZe8vaBSsNuNDlMyUz4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A+jHveHwkXY+CiXSr4nEQhDxyZYfXNRYPawIeh3hWq68kBtjRuqgygRzYMfiKB38C zhkkU+XFnw+mQ5HZi+Yh5kFy+7FBgRAdXVbG0DrxbqMOIcKyZ6KOCpoGjdB463+Jrd ouT02icDl36H8wQ8zicD92bGHPP6d1hZgUex5PGQg3E9go3OfftqoXc5qUopMSP9Xd sm7g7n9gDwqjefm2VK+WATzhjt3JIqkbMhBGjF+uF0cHHDWysHIEcjEdD8QX3JulgX /HNYgdTX2I8LXGhEeTk5z7Zy+n/FBGjkfRqquwYuWDHimpdW9NHdeOVhye4CqJNIyt vl/rwRptXPo1A== From: Benjamin Tissoires Date: Fri, 05 Jul 2024 15:44:52 +0200 Subject: [PATCH bpf-next 1/2] bpf: helpers: fix bpf_wq_set_callback_impl signature Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-fix-wq-v1-1-91b4d82cd825@kernel.org> References: <20240705-fix-wq-v1-0-91b4d82cd825@kernel.org> In-Reply-To: <20240705-fix-wq-v1-0-91b4d82cd825@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.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720187099; l=1192; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=tmlkinceJ217REpu6WVDDhCLWZe8vaBSsNuNDlMyUz4=; b=aEuQ8LRz2zkWCf81XAaAcE6Oew8VwVkkUrZWdIV+xJPTbKhBDIUR1z7v4elK0NSLvh++p3qs/ Knb29Frb3ofCcatLJCO/LQfjhot+L+/Aqx0adjheU74FDsYUKRcKalM X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= I realized this while having a map containing both a struct bpf_timer and a struct bpf_wq: the third argument provided to the bpf_wq callback is not the struct bpf_wq pointer itself, but the pointer to the value in the map. Which means that the users need to double cast the provided "value" as this is not a struct bpf_wq *. This is a change of API, but there doesn't seem to be much users of bpf_wq right now, so we should be able to go with this right now. Fixes: 81f1d7a583fa ("bpf: wq: add bpf_wq_set_callback_impl") Signed-off-by: Benjamin Tissoires Reviewed-by: Eduard Zingerman --- kernel/bpf/helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 229396172026..5241ba671c5a 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2734,7 +2734,7 @@ __bpf_kfunc int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) } __bpf_kfunc 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 *value), unsigned int flags, void *aux__ign) { From patchwork Fri Jul 5 13:44: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: 13725154 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 401FF14EC7C; Fri, 5 Jul 2024 13:45: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=1720187111; cv=none; b=cfkLMeUPHDfMV2vYbNPLSGPxadjNomVccM4mAhnWM43Y7Lck/uJieJITQthTMowGuIO8LeJrPQ0ZkZO/nREnVsnF2RUPSjtb4cvtG/CHuMQwjYZAeOmPOWo5xFEZPiPsRNWQJU+4dAfHMCeSQJA35+qT1ZSbqdXGmdbZ4+VlV3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720187111; c=relaxed/simple; bh=0w8gvKjTu4tdLutH6R1DbAV/uEOlEmQguROzVLf15Us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JiR0gWMpDxNmY0e8Vm9TtoA7OfZyTsL59s8Ya06lxp2kX4lYa7+CQ1XRxY5G5wPICg1CMwxpMKy0xJsR/iejggJMY4MEpIOHCUYBfMgRV+cnvNUFo3TIGQ0IihWLD04WS8Giv/hlzRV1UuqmCflND79F38bKRwdjrHkqUnrRo/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=niGFGSvp; 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="niGFGSvp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B039BC116B1; Fri, 5 Jul 2024 13:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720187111; bh=0w8gvKjTu4tdLutH6R1DbAV/uEOlEmQguROzVLf15Us=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=niGFGSvpUROr4Y+0qkweYq6nbGjtzNOQX4itzKYWRN0TJYMDwD6Mj0hK4XZd31PHr ADMjYJz32dgy3g3xCj4TyOiCaB9BbcCCwRIXFbWQAiCK7mc3XAdsamGpCODduW/JtL S6UJWaAuldVUH/P/c/m1zYIjNQwdnLiUa/ihXnX8aqEvizUpoAZleOE59uwsSC+JaZ sDgzEfd9zwzEPi1BcwL2AWFrmq3R8f2581PZsVhmjnay4ijIuC7tsysNnp3bz3cFpY ilGn7TPvrkqBcxq+xDo8BGZ+y2ldZha7i2MZ0Fu+GshGHxid3KxcP6l+N9u9ajaqzw 7AeZP4A0uBckw== From: Benjamin Tissoires Date: Fri, 05 Jul 2024 15:44:53 +0200 Subject: [PATCH bpf-next 2/2] selftests/bpf: amend for wrong bpf_wq_set_callback_impl signature Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-fix-wq-v1-2-91b4d82cd825@kernel.org> References: <20240705-fix-wq-v1-0-91b4d82cd825@kernel.org> In-Reply-To: <20240705-fix-wq-v1-0-91b4d82cd825@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.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720187099; l=3534; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=0w8gvKjTu4tdLutH6R1DbAV/uEOlEmQguROzVLf15Us=; b=lAPZdY5puQJIW7UV/1AUcyD5sKak0ZlKALEl1x3U4dmG+Owm2K/da9Y7ZpDqfeYHnQy4jnwLe gOipma6E+S0Anqp2RYp/Lel36KVkxn5z/wUDuuCTYHh4/9x2s9gUTHi X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= See the previous patch: the API was wrong, we were provided the pointer to the value, not the actual struct bpf_wq *. Signed-off-by: Benjamin Tissoires --- tools/testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/wq.c | 8 ++++---- tools/testing/selftests/bpf/progs/wq_failures.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index eede6fc2ccb4..828556cdc2f0 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -552,7 +552,7 @@ 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; 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 *value), 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) diff --git a/tools/testing/selftests/bpf/progs/wq.c b/tools/testing/selftests/bpf/progs/wq.c index 49e712acbf60..e5ac0df59b86 100644 --- a/tools/testing/selftests/bpf/progs/wq.c +++ b/tools/testing/selftests/bpf/progs/wq.c @@ -53,7 +53,7 @@ __u32 ok; __u32 ok_sleepable; static int test_elem_callback(void *map, int *key, - int (callback_fn)(void *map, int *key, struct bpf_wq *wq)) + int (callback_fn)(void *map, int *key, void *value)) { struct elem init = {}, *val; struct bpf_wq *wq; @@ -84,7 +84,7 @@ static int test_elem_callback(void *map, int *key, } static int test_hmap_elem_callback(void *map, int *key, - int (callback_fn)(void *map, int *key, struct bpf_wq *wq)) + int (callback_fn)(void *map, int *key, void *value)) { struct hmap_elem init = {}, *val; struct bpf_wq *wq; @@ -114,7 +114,7 @@ static int test_hmap_elem_callback(void *map, int *key, } /* callback for non sleepable workqueue */ -static int wq_callback(void *map, int *key, struct bpf_wq *work) +static int wq_callback(void *map, int *key, void *value) { bpf_kfunc_common_test(); ok |= (1 << *key); @@ -122,7 +122,7 @@ static int wq_callback(void *map, int *key, struct bpf_wq *work) } /* callback for sleepable workqueue */ -static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work) +static int wq_cb_sleepable(void *map, int *key, void *value) { bpf_kfunc_call_test_sleepable(); ok_sleepable |= (1 << *key); diff --git a/tools/testing/selftests/bpf/progs/wq_failures.c b/tools/testing/selftests/bpf/progs/wq_failures.c index 4cbdb425f223..25b51a72fe0f 100644 --- a/tools/testing/selftests/bpf/progs/wq_failures.c +++ b/tools/testing/selftests/bpf/progs/wq_failures.c @@ -28,14 +28,14 @@ struct { } lru SEC(".maps"); /* callback for non sleepable workqueue */ -static int wq_callback(void *map, int *key, struct bpf_wq *work) +static int wq_callback(void *map, int *key, void *value) { bpf_kfunc_common_test(); return 0; } /* callback for sleepable workqueue */ -static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work) +static int wq_cb_sleepable(void *map, int *key, void *value) { bpf_kfunc_call_test_sleepable(); return 0;