From patchwork Mon Mar 28 17:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 12794076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26C50C4167B for ; Mon, 28 Mar 2022 17:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245066AbiC1R4b (ORCPT ); Mon, 28 Mar 2022 13:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244903AbiC1R4I (ORCPT ); Mon, 28 Mar 2022 13:56:08 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC8BE2251A; Mon, 28 Mar 2022 10:53:45 -0700 (PDT) Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4KS0d44bNNz67Lnh; Tue, 29 Mar 2022 01:51:52 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.63.22) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 28 Mar 2022 19:53:41 +0200 From: Roberto Sassu To: , , , , , , , , , CC: , , , , , , , , , , Roberto Sassu Subject: [PATCH 10/18] bpf-preload: Generate bpf_preload_ops Date: Mon, 28 Mar 2022 19:50:25 +0200 Message-ID: <20220328175033.2437312-11-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220328175033.2437312-1-roberto.sassu@huawei.com> References: <20220328175033.2437312-1-roberto.sassu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.204.63.22] X-ClientProxiedBy: lhreml754-chm.china.huawei.com (10.201.108.204) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Generate a bpf_preload_ops structure, to specify the kernel module and the preload method. Signed-off-by: Roberto Sassu --- kernel/bpf/preload/bpf_preload_kern.c | 5 ----- kernel/bpf/preload/iterators/iterators.lskel.h | 5 +++++ tools/bpf/bpftool/gen.c | 13 +++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/preload/bpf_preload_kern.c b/kernel/bpf/preload/bpf_preload_kern.c index 35e9abd1a668..3839af367200 100644 --- a/kernel/bpf/preload/bpf_preload_kern.c +++ b/kernel/bpf/preload/bpf_preload_kern.c @@ -5,11 +5,6 @@ #include #include "iterators/iterators.lskel.h" -static struct bpf_preload_ops ops = { - .preload = preload, - .owner = THIS_MODULE, -}; - static int __init load(void) { int err; diff --git a/kernel/bpf/preload/iterators/iterators.lskel.h b/kernel/bpf/preload/iterators/iterators.lskel.h index 6faf3708be01..7595fc283a65 100644 --- a/kernel/bpf/preload/iterators/iterators.lskel.h +++ b/kernel/bpf/preload/iterators/iterators.lskel.h @@ -474,6 +474,11 @@ static int preload(struct dentry *parent) return err; } +static struct bpf_preload_ops ops = { + .preload = preload, + .owner = THIS_MODULE, +}; + static int load_skel(void) { int err; diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index 28b1fe718248..5593cbee1846 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -841,6 +841,18 @@ static void codegen_preload(struct bpf_object *obj, const char *obj_name) "); } +static void codegen_preload_ops(void) +{ + codegen("\ + \n\ + \n\ + static struct bpf_preload_ops ops = { \n\ + .preload = preload, \n\ + .owner = THIS_MODULE, \n\ + }; \n\ + "); +} + static void codegen_preload_load(struct bpf_object *obj, const char *obj_name) { struct bpf_program *prog; @@ -1076,6 +1088,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h codegen_preload_vars(obj, obj_name); codegen_preload_free(obj, obj_name); codegen_preload(obj, obj_name); + codegen_preload_ops(); codegen_preload_load(obj, obj_name); }