From patchwork Wed Nov 27 19:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 846210 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 8EC58200B95; Wed, 27 Nov 2024 19:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732735251; cv=none; b=kIvABfJdRYRHd2w9ZyJcXnkWumpfSyKwcJ59QJfBFH33cm8+UZK0rwzxi+mYblUxWjpepK8rA3g12xiZU7tBy4ut6I7jANs4HwndBvT5dckloBUZyyP0EZ2t57LE1ynSQpWheWchqQsGd8ZbsyLQdMY3i1urHJv136u9nhjvZDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732735251; c=relaxed/simple; bh=KtwbEqFpnwCczek16OOedUheaLXyXVIfozidQrI0uUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FzuCGfN2S2Ow3ukQmvuNYe/gEJrYG49WdqLS7wfs/3LjPLaWqANCw78IBbHEXO6zJdkoSU8buVFP5kfgERwK/nuPw+CHQx6AI27eYm92yLcGCWNucRIMWhBy9Ai3US1qGX4bS1ajUxddkeN5SePrfZrqIzJUvWfq19IB26q+ZxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=jFMJYZsw; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="jFMJYZsw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1732735246; bh=KtwbEqFpnwCczek16OOedUheaLXyXVIfozidQrI0uUw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jFMJYZswpV72PsYnBLk9fA0ivlsvcxSLmKiej9qOQ9tbfsnNAmgryDG60B9Ed42Qp H6jkH4PnoIBpYN6VlX9h1KzmmX6ktBYiCrxjmE9N9Rxs0ZDlS5U46uujAUnqhGY8Y5 qT6Hb4SRVe+kP/PvifyXuUC3r7kB41qOeXD/9YwM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 27 Nov 2024 20:15:24 +0100 Subject: [PATCH bpf-next 5/9] bpf: Allow registration of const cfi_stubs Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241127-bpf-const-ops-v1-5-a698b8d58680@weissschuh.net> References: <20241127-bpf-const-ops-v1-0-a698b8d58680@weissschuh.net> In-Reply-To: <20241127-bpf-const-ops-v1-0-a698b8d58680@weissschuh.net> To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Martin KaFai Lau , Kui-Feng Lee , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jiri Kosina , Benjamin Tissoires , Tejun Heo , David Vernet , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-input@vger.kernel.org, =?utf-8?q?Thomas_Wei?= =?utf-8?q?=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732735245; l=1514; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=KtwbEqFpnwCczek16OOedUheaLXyXVIfozidQrI0uUw=; b=KpuXC0mLiHk4BoFEt+TSl42FiwTEq/ap2yVY3heLEigxFb2I0wUKPZJZkINMI1AopeGtO6wnI 2Oev6Ufy0VwDveY03Cs721MrPZ83t+7IyUUQv9ly1zWAYM/J1rBehAB X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The BPF core does not need to modify the cfi_stubs. Reflect this in the API so users can move their structures into read-only memory. Signed-off-by: Thomas Weißschuh --- include/linux/bpf.h | 2 +- kernel/bpf/bpf_struct_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index a9267af9671b2bc8961cde24d2f79f473ab227d7..fbe5ae7c2b380fdb624ea1f04fdf56e4f6710f14 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1795,7 +1795,7 @@ struct bpf_struct_ops { void (*unreg)(void *kdata, struct bpf_link *link); int (*update)(void *kdata, void *old_kdata, struct bpf_link *link); int (*validate)(void *kdata); - void *cfi_stubs; + const void *cfi_stubs; struct module *owner; const char *name; }; diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index 967f0914d473fcde4a6ce3bb6ac976345daf8e88..2a9b9c39f1e7c2c22dc83ad68766b522117f3979 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -778,7 +778,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, trampoline_start = image_off; err = bpf_struct_ops_prepare_trampoline(tlinks, link, &st_ops_desc->func_models[i], - *(void **)(st_ops->cfi_stubs + moff), + *(void *const *)(st_ops->cfi_stubs + moff), &image, &image_off, st_map->image_pages_cnt < MAX_TRAMP_IMAGE_PAGES); if (err)