From patchwork Sat Oct 16 12:48:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12563629 X-Patchwork-Delegate: bpf@iogearbox.net 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 572C6C433FE for ; Sat, 16 Oct 2021 12:33:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 436D560EB4 for ; Sat, 16 Oct 2021 12:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240434AbhJPMfV (ORCPT ); Sat, 16 Oct 2021 08:35:21 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:25197 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240423AbhJPMfU (ORCPT ); Sat, 16 Oct 2021 08:35:20 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HWjFF1Jhwz8tZY; Sat, 16 Oct 2021 20:32:01 +0800 (CST) Received: from dggpeml500025.china.huawei.com (7.185.36.35) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Sat, 16 Oct 2021 20:33:11 +0800 Received: from huawei.com (10.175.124.27) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Sat, 16 Oct 2021 20:33:08 +0800 From: Hou Tao To: Alexei Starovoitov CC: Martin KaFai Lau , Yonghong Song , "Daniel Borkmann" , Andrii Nakryiko , , , Subject: [PATCH bpf-next v2 4/5] bpf: hook .test_run for struct_ops program Date: Sat, 16 Oct 2021 20:48:05 +0800 Message-ID: <20211016124806.1547989-5-houtao1@huawei.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20211016124806.1547989-1-houtao1@huawei.com> References: <20211016124806.1547989-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500025.china.huawei.com (7.185.36.35) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net bpf_struct_ops_test_run() will be used to run struct_ops program from bpf_dummy_ops and now its main purpose is to test the handling of return value and multiple arguments. Signed-off-by: Hou Tao --- kernel/bpf/bpf_struct_ops.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index 44be101f2562..ceedc9f0f786 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -11,6 +11,9 @@ #include #include +static int bpf_struct_ops_test_run(struct bpf_prog *prog, + const union bpf_attr *kattr, + union bpf_attr __user *uattr); enum bpf_struct_ops_state { BPF_STRUCT_OPS_STATE_INIT, BPF_STRUCT_OPS_STATE_INUSE, @@ -93,6 +96,7 @@ const struct bpf_verifier_ops bpf_struct_ops_verifier_ops = { }; const struct bpf_prog_ops bpf_struct_ops_prog_ops = { + .test_run = bpf_struct_ops_test_run, }; static const struct btf_type *module_type; @@ -667,3 +671,16 @@ void bpf_struct_ops_put(const void *kdata) call_rcu(&st_map->rcu, bpf_struct_ops_put_rcu); } } + +static int bpf_struct_ops_test_run(struct bpf_prog *prog, + const union bpf_attr *kattr, + union bpf_attr __user *uattr) +{ + const struct bpf_struct_ops *st_ops; + + st_ops = bpf_struct_ops_find(prog->aux->attach_btf_id); + if (st_ops != &bpf_bpf_dummy_ops) + return -EOPNOTSUPP; + + return bpf_dummy_struct_ops_test_run(prog, kattr, uattr); +}