From patchwork Tue Nov 9 02:16:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609363 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 2E538C433EF for ; Tue, 9 Nov 2021 02:16:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8E30611C5 for ; Tue, 9 Nov 2021 02:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238818AbhKICTV (ORCPT ); Mon, 8 Nov 2021 21:19:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234245AbhKICTU (ORCPT ); Mon, 8 Nov 2021 21:19:20 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACCCAC061570 for ; Mon, 8 Nov 2021 18:16:35 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id z2-20020a254c02000000b005b68ef4fe24so28182635yba.11 for ; Mon, 08 Nov 2021 18:16:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Xui5NGx6xZn80XKPeiu19bYnbiMY+6CPwqtc3BJKfHI=; b=g5bIU6Iy8gqCP1bazuL6Ub1KtLhDPFLL+Pupkz8fK2pLy78esO2SkpCqM3HBnPFerE Z6Gnqsnj51wKk0NbNkzf2ZWBwRMK2SqqyK4MNewQ+uPGJB+XUd1cn3E4h6Py6fJPv/bl qa8N2NM5oKkERPIX4uJNjjq7TexjCpBABagd0/XU7hk9nV0M7TEUe2vJBjdJh93aM6d/ gMbMpzTNJHCWW/KCa5yKmCICUuQKzbzV/gdHthd0k0LrSnWg4XMBbZSjIwFcqiSe5dWB d84ITyxVatMTqcMtlZfplm+noDQ0Glo5eMd064+/+rIkt3yerj+un5RydeWtuRUttMkb 0naQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Xui5NGx6xZn80XKPeiu19bYnbiMY+6CPwqtc3BJKfHI=; b=pRuWPBu8HMGn2JPjVOWUHKtTrXgcPRdSCz+JzdkdO+JEha7kCBkGgrqGAblTBbu3Gk B9EHx98YDr/nUYiPOvPlMjtqAtTUu9oSyvu4njOFbOdrnhD1ha+mFDWE6t1/K63ieUvv LMvB4SsQjMgk5MV6ywD3zanVFlg2xFy1ok4s3H56WMqcUxSHksh1d4y3fcuF170QL6fJ 5GquOLm2JKmVA9ew0//KxxA1c2rwt0WAkjNTxitLkITufSaNhHUELj9BtvHXjuIER/zZ s3nJj4lVFw6cG0CiMDNRrOsO0HW6uRiXWxU2u+a2a3qLo9WnmUrPNz7i9Skjkn7e3yqS WOww== X-Gm-Message-State: AOAM530g2mwKoDezRUXe11i5/R9nb6kaW4HfYCgOhZtemi9EsZxavQmF WMasJ5JahFcgBrLbfctOr9XG/v8hwMo= X-Google-Smtp-Source: ABdhPJwNHpysoocGpL915610yEPa7xlHyOkNWUM3D4qrryw2LKkNS9C+b8Pz5Fw2r/+2G8enRDSzLHBRUHs= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a25:5402:: with SMTP id i2mr4515093ybb.312.1636424194951; Mon, 08 Nov 2021 18:16:34 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:17 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-3-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 2/9] bpf: Remove ARG_PTR_TO_MAP_VALUE_OR_NULL From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Remove ARG_PTR_TO_MAP_VALUE_OR_NULL and use flag to mark that the argument may be null. Signed-off-by: Hao Luo --- include/linux/bpf.h | 6 +++++- kernel/bpf/bpf_inode_storage.c | 5 ++++- kernel/bpf/bpf_task_storage.c | 5 ++++- kernel/bpf/verifier.c | 11 +++++------ net/core/bpf_sk_storage.c | 15 ++++++++++++--- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 287d819e73f8..d8de8f00e40d 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -297,6 +297,9 @@ bool bpf_map_meta_equal(const struct bpf_map *meta0, extern const struct bpf_map_ops bpf_map_offload_ops; +/* argument may be null or zero */ +#define ARG_FLAG_MAYBE_NULL 1 + /* function argument constraints */ struct bpf_arg_type { enum { @@ -309,7 +312,6 @@ struct bpf_arg_type { ARG_PTR_TO_MAP_KEY, /* pointer to stack used as map key */ ARG_PTR_TO_MAP_VALUE, /* pointer to stack used as map value */ ARG_PTR_TO_UNINIT_MAP_VALUE, /* pointer to valid memory used to store a map value */ - ARG_PTR_TO_MAP_VALUE_OR_NULL, /* pointer to stack used as map value or NULL */ /* the following constraints used to prototype bpf_memcmp() and other * functions that access data on eBPF program stack @@ -345,6 +347,8 @@ struct bpf_arg_type { ARG_PTR_TO_TIMER, /* pointer to bpf_timer */ __BPF_ARG_TYPE_MAX, } type; + + u8 flag; }; /* type of values returned from helper functions */ diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c index 091352613225..acb566a3b37f 100644 --- a/kernel/bpf/bpf_inode_storage.c +++ b/kernel/bpf/bpf_inode_storage.c @@ -265,7 +265,10 @@ const struct bpf_func_proto bpf_inode_storage_get_proto = { .arg1 = { .type = ARG_CONST_MAP_PTR, } .arg2 = { .type = ARG_PTR_TO_BTF_ID, } .arg2_btf_id = &bpf_inode_storage_btf_ids[0], - .arg3 = { .type = ARG_PTR_TO_MAP_VALUE_OR_NULL, } + .arg3 = { + .type = ARG_PTR_TO_MAP_VALUE, + .flag = ARG_FLAG_MAYBE_NULL, + } .arg4_type = { .type = ARG_ANYTHING, } }; diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c index 04bb681edc78..bdc0925c2fd3 100644 --- a/kernel/bpf/bpf_task_storage.c +++ b/kernel/bpf/bpf_task_storage.c @@ -324,7 +324,10 @@ const struct bpf_func_proto bpf_task_storage_get_proto = { .arg1 = { .type = ARG_CONST_MAP_PTR }, .arg2 = { .type = ARG_PTR_TO_BTF_ID }, .arg2_btf_id = &btf_task_struct_ids[0], - .arg3 = { .type = ARG_PTR_TO_MAP_VALUE_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MAP_VALUE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1f2aaa2214d9..f55967f92d22 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -480,7 +480,7 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { - return arg.type == ARG_PTR_TO_MAP_VALUE_OR_NULL || + return arg.flag & ARG_FLAG_MAYBE_NULL || arg.type == ARG_PTR_TO_MEM_OR_NULL || arg.type == ARG_PTR_TO_CTX_OR_NULL || arg.type == ARG_PTR_TO_SOCKET_OR_NULL || @@ -5089,7 +5089,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_MAP_KEY] = &map_key_value_types, [ARG_PTR_TO_MAP_VALUE] = &map_key_value_types, [ARG_PTR_TO_UNINIT_MAP_VALUE] = &map_key_value_types, - [ARG_PTR_TO_MAP_VALUE_OR_NULL] = &map_key_value_types, [ARG_CONST_SIZE] = &scalar_types, [ARG_CONST_SIZE_OR_ZERO] = &scalar_types, [ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types, @@ -5209,8 +5208,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg_num, } if (arg.type == ARG_PTR_TO_MAP_VALUE || - arg.type == ARG_PTR_TO_UNINIT_MAP_VALUE || - arg.type == ARG_PTR_TO_MAP_VALUE_OR_NULL) { + arg.type == ARG_PTR_TO_UNINIT_MAP_VALUE) { err = resolve_map_arg_type(env, meta, &arg); if (err) return err; @@ -5286,9 +5284,10 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg_num, meta->map_ptr->key_size, false, NULL); } else if (arg.type == ARG_PTR_TO_MAP_VALUE || - (arg.type == ARG_PTR_TO_MAP_VALUE_OR_NULL && - !register_is_null(reg)) || arg.type == ARG_PTR_TO_UNINIT_MAP_VALUE) { + if ((arg.flag & ARG_FLAG_MAYBE_NULL) && register_is_null(reg)) + return err; + /* bpf_map_xxx(..., map_ptr, ..., value) call: * check [value, value + map->value_size) validity */ diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c index 81f8529c0169..22fdbe3d68e3 100644 --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -357,7 +357,10 @@ const struct bpf_func_proto bpf_sk_storage_get_proto = { .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1 = { .type = ARG_CONST_MAP_PTR }, .arg2 = { .type = ARG_PTR_TO_BTF_ID_SOCK_COMMON }, - .arg3 = { .type = ARG_PTR_TO_MAP_VALUE_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MAP_VALUE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -367,7 +370,10 @@ const struct bpf_func_proto bpf_sk_storage_get_cg_sock_proto = { .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .arg1 = { .type = ARG_CONST_MAP_PTR }, .arg2 = { .type = ARG_PTR_TO_CTX }, /* context is 'struct sock' */ - .arg3 = { .type = ARG_PTR_TO_MAP_VALUE_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MAP_VALUE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -438,7 +444,10 @@ const struct bpf_func_proto bpf_sk_storage_get_tracing_proto = { .arg1 = { .type = ARG_CONST_MAP_PTR }, .arg2 = { .type = ARG_PTR_TO_BTF_ID }, .arg2_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], - .arg3 = { .type = ARG_PTR_TO_MAP_VALUE_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MAP_VALUE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, .allowed = bpf_sk_storage_tracing_allowed, }; From patchwork Tue Nov 9 02:16:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609365 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 D14C6C433EF for ; Tue, 9 Nov 2021 02:16:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADE2661207 for ; Tue, 9 Nov 2021 02:16:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238856AbhKICTY (ORCPT ); Mon, 8 Nov 2021 21:19:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234245AbhKICTW (ORCPT ); Mon, 8 Nov 2021 21:19:22 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F728C061570 for ; Mon, 8 Nov 2021 18:16:37 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id m5-20020a170902bb8500b0013a2b785187so7653461pls.11 for ; Mon, 08 Nov 2021 18:16:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=tnpzuiBMM4gtcGLMa6Ad04JIjQCqqdttngTqZ/oQlBU=; b=Lr0sTc4BzgNHQoFDmUOpz6TSWbW7XeGpFoEJX8HVnfhDJKGUi+Dc6KRe68yZIyyfvf z0ThnVOa5mUwyt9XENlG63oE2pwgxMJMz5RQMLMBMtBvWuNgs6TwwxdPpo2zhwJAOSOe biEqpwKvJrMUgxLPMkj3gCgvF691Q6N9ERdCwAPs6ezP0b7SrD2wRyIQdxt2UkDs18nx l+GOq0Bc0rzUb6ONBuNeJZCDfcfMrxqFcjTzdFh6yOGmCAA0/hhD7rNJMuHIQcnqgVZT 4sOLn4ZV1HfIDIDeSD+M1pv/qRFTgm5tBPaPa4GGAn0u1s1tBL+zaaCIdJy45y7oiQV3 5pDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=tnpzuiBMM4gtcGLMa6Ad04JIjQCqqdttngTqZ/oQlBU=; b=fiZJNyrPYaI8GM3RNPacMvbvCImzk5KByHmJMDrvmkTnnDf5wbTrNbXQ0zm5sdRJxh QTnIIaPnC0ecJ1EmHW7AlK/FJzOcRt7pzKkTJ7BRz8umBEDC6cGcMKllvmNJdPsLj1NS BPfHzeNC5nFawpznP7N+2tT8Abr0OgnOJVZ3CqgofoG8KwyqEYdjYcjq82UMJFoKgLbn J3y3Fdc+soZInb7Gs0Np0hdhc10djLJ5Mg708jLElmvtzuFwKyvIN1oJzyZvX/FZM8Ga uvNsOdtDGSiJnFaNdzFMftnmmsrzIja3ew7W8ElZljThvu7hWclDI8LmytlYmtsW+geu Hqrw== X-Gm-Message-State: AOAM530NJeINs+EFvQCE7fUZHfHr6u13NpcUJUw6i1Yd00Odur3LG7/e MguVs2wLyUwdHQy+gmzCvaHbA3X+qY8= X-Google-Smtp-Source: ABdhPJwEfzF0lhvGE0Jz+tQeWYY3K3nRvXJFUp82JRnFO7mLtKw3yHKPtjvycN4F4/Yg48VPi0jHkMkfRGU= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a17:902:c404:b0:142:28c5:5416 with SMTP id k4-20020a170902c40400b0014228c55416mr4016439plk.62.1636424196965; Mon, 08 Nov 2021 18:16:36 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:18 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-4-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 3/9] bpf: Remove ARG_PTR_TO_MEM_OR_NULL From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Remove ARG_PTR_TO_MEM_OR_NULL and use flag to mark that the argument may be null. Signed-off-by: Hao Luo --- include/linux/bpf.h | 1 - kernel/bpf/helpers.c | 10 ++++++++-- kernel/bpf/verifier.c | 3 --- kernel/trace/bpf_trace.c | 15 ++++++++++++--- net/core/filter.c | 15 ++++++++++++--- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index d8de8f00e40d..dd92418814b5 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -317,7 +317,6 @@ struct bpf_arg_type { * functions that access data on eBPF program stack */ ARG_PTR_TO_MEM, /* pointer to valid memory (stack, packet, map value) */ - ARG_PTR_TO_MEM_OR_NULL, /* pointer to valid memory or NULL */ ARG_PTR_TO_UNINIT_MEM, /* pointer to memory does not need to be initialized, * helper function must fill all bytes or clear * them in error case. diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index d68c70f4b4b6..cd792777afb2 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -1008,10 +1008,16 @@ const struct bpf_func_proto bpf_snprintf_proto = { .func = bpf_snprintf, .gpl_only = true, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg3 = { .type = ARG_PTR_TO_CONST_STR }, - .arg4 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg4 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, }; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f55967f92d22..eb69b8bddee5 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -481,7 +481,6 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { return arg.flag & ARG_FLAG_MAYBE_NULL || - arg.type == ARG_PTR_TO_MEM_OR_NULL || arg.type == ARG_PTR_TO_CTX_OR_NULL || arg.type == ARG_PTR_TO_SOCKET_OR_NULL || arg.type == ARG_PTR_TO_ALLOC_MEM_OR_NULL || @@ -4951,7 +4950,6 @@ static int process_timer_func(struct bpf_verifier_env *env, int regno, static bool arg_type_is_mem_ptr(struct bpf_arg_type arg) { return arg.type == ARG_PTR_TO_MEM || - arg.type == ARG_PTR_TO_MEM_OR_NULL || arg.type == ARG_PTR_TO_UNINIT_MEM; } @@ -5104,7 +5102,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_BTF_ID] = &btf_ptr_types, [ARG_PTR_TO_SPIN_LOCK] = &spin_lock_types, [ARG_PTR_TO_MEM] = &mem_types, - [ARG_PTR_TO_MEM_OR_NULL] = &mem_types, [ARG_PTR_TO_UNINIT_MEM] = &mem_types, [ARG_PTR_TO_ALLOC_MEM] = &alloc_mem_types, [ARG_PTR_TO_ALLOC_MEM_OR_NULL] = &alloc_mem_types, diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 6e0b17637787..086889a29ca7 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -452,7 +452,10 @@ static const struct bpf_func_proto bpf_trace_vprintk_proto = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_MEM }, .arg2 = { .type = ARG_CONST_SIZE }, - .arg3 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_CONST_SIZE_OR_ZERO }, }; @@ -494,7 +497,10 @@ static const struct bpf_func_proto bpf_seq_printf_proto = { .arg1_btf_id = &btf_seq_file_ids[0], .arg2 = { .type = ARG_PTR_TO_MEM }, .arg3 = { .type = ARG_CONST_SIZE }, - .arg4 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg4 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, }; @@ -1435,7 +1441,10 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, - .arg2 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg2 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/net/core/filter.c b/net/core/filter.c index 90fa7f67f3c2..81c6638ffc2a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2018,9 +2018,15 @@ static const struct bpf_func_proto bpf_csum_diff_proto = { .gpl_only = false, .pkt_access = true, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, - .arg3 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg5 = { .type = ARG_ANYTHING }, }; @@ -2541,7 +2547,10 @@ static const struct bpf_func_proto bpf_redirect_neigh_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_ANYTHING }, - .arg2 = { .type = ARG_PTR_TO_MEM_OR_NULL }, + .arg2 = { + .type = ARG_PTR_TO_MEM, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, .arg4 = { .type = ARG_ANYTHING }, }; From patchwork Tue Nov 9 02:16:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609367 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 AD80FC433F5 for ; Tue, 9 Nov 2021 02:16:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BDC061207 for ; Tue, 9 Nov 2021 02:16:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234245AbhKICTY (ORCPT ); Mon, 8 Nov 2021 21:19:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbhKICTY (ORCPT ); Mon, 8 Nov 2021 21:19:24 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F7E6C061570 for ; Mon, 8 Nov 2021 18:16:39 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id x9-20020a056a00188900b0049fd22b9a27so3048954pfh.18 for ; Mon, 08 Nov 2021 18:16:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XmP2B7rbxa18um0t1mESk3xyMBid0PlfcDFl48NO3Hs=; b=G4jT392X2evxt6bwGFo9jMcHOafmFhfvPtmRoHlkGqplw8RsvHVN1Z5QhhyY2rq5nH plPezqSui/j4XptkcxLzW3gNuJXgvRSxoJ+lxze7GkFg44HXa3nb8TGmNEil4UvrXrE3 vcW2K/dvLu9U+CgcIUYcO2lOrZCEuvN3uMszJ50ejGQwKkSjBkEBFZ1X4mi0xQk4C+xw G9xFApURHQDznntbDMMT9O9/+TKNyuDTypaDIWPiLiq66rgVFtjc+p02Kh06JWPuEaof vc+upqx+pfLhT5UcOaBT5Mb71GpnX/WyDI2Oe6XOoSrKxp5NNxdRYqlhRtnNw373fvxk t6vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XmP2B7rbxa18um0t1mESk3xyMBid0PlfcDFl48NO3Hs=; b=lMaWm7MZ81l2aj9xKzX7chQceext4qzdgRr8PFVYY622AYToAAEAsxhlpzFno+Uz/k G415SncopKWxrIKKZavmoHMndy19ESixJaocArA5vhAAMs3yAEx7WM+NYHhpHEmXF4Jp AnBZo1VyRjgTdDiIFbsrWNJftRcEQez8/f+EgAUWDOZm0ZkJDDC4TWpqlIy0A+OpCY1t PmyD46jWKuekebQtzPXdRSKjets2IgKtVRhYZc0bKoEQeZjEDcigXD+Z8d0HzFsYekXg jnBkH4T0unYhQWcK3863f1x50Pf+advxP4HOZfaR66JcPt7ZpWjkXmWhqruOkoYwdcXk lK9Q== X-Gm-Message-State: AOAM531u396ojz1CAU9vdaFaG7GJlqS7zwDzXVfJqB0RyrOMpSyit2Lo bTSMDLdau5zLcMAe66Xn6qYRYRZl8pY= X-Google-Smtp-Source: ABdhPJwiL2LC8fHRn8PHoeolHTFt2pF+7fEYTnLmtxSEDjhTTRuvJ8/2BKSXDTkt7n5d1m17BIdkd73hH9w= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:aa7:914f:0:b0:44d:6f5e:f11a with SMTP id 15-20020aa7914f000000b0044d6f5ef11amr3941883pfi.10.1636424199017; Mon, 08 Nov 2021 18:16:39 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:19 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-5-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 4/9] bpf: Remove ARG_CONST_SIZE_OR_ZERO From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Remove ARG_CONST_SIZE_OR_ZERO and use flag to mark that the argument may be zero. Signed-off-by: Hao Luo --- include/linux/bpf.h | 2 - kernel/bpf/helpers.c | 20 +++++++-- kernel/bpf/ringbuf.c | 5 ++- kernel/bpf/stackmap.c | 15 +++++-- kernel/bpf/verifier.c | 8 ++-- kernel/trace/bpf_trace.c | 90 ++++++++++++++++++++++++++++++++-------- net/core/filter.c | 35 ++++++++++++---- 7 files changed, 135 insertions(+), 40 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index dd92418814b5..27f81989f992 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -323,8 +323,6 @@ struct bpf_arg_type { */ ARG_CONST_SIZE, /* number of bytes accessed from memory */ - ARG_CONST_SIZE_OR_ZERO, /* number of bytes accessed from memory or 0 */ - ARG_PTR_TO_CTX, /* pointer to context */ ARG_PTR_TO_CTX_OR_NULL, /* pointer to context or NULL */ ARG_ANYTHING, /* any (initialized) argument is ok */ diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index cd792777afb2..082a8620f666 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -631,7 +631,10 @@ const struct bpf_func_proto bpf_event_output_data_proto = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_3(bpf_copy_from_user, void *, dst, u32, size, @@ -652,7 +655,10 @@ const struct bpf_func_proto bpf_copy_from_user_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; @@ -1012,13 +1018,19 @@ const struct bpf_func_proto bpf_snprintf_proto = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_PTR_TO_CONST_STR }, .arg4 = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; /* BPF map elements can contain 'struct bpf_timer'. diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c index bf29de9c4a2d..a8af9c7c6423 100644 --- a/kernel/bpf/ringbuf.c +++ b/kernel/bpf/ringbuf.c @@ -445,7 +445,10 @@ const struct bpf_func_proto bpf_ringbuf_output_proto = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_CONST_MAP_PTR }, .arg2 = { .type = ARG_PTR_TO_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index ae7bfc278443..496baa1b8def 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -464,7 +464,10 @@ const struct bpf_func_proto bpf_get_stack_proto = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, .arg2 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -491,7 +494,10 @@ const struct bpf_func_proto bpf_get_task_stack_proto = { .arg1 = { .type = ARG_PTR_TO_BTF_ID }, .arg1_btf_id = &btf_task_struct_ids[0], .arg2 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -554,7 +560,10 @@ const struct bpf_func_proto bpf_get_stack_proto_pe = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, .arg2 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index eb69b8bddee5..1a4830ad2be2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2493,7 +2493,7 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, * r5 += 1 * ... * call bpf_perf_event_output#25 - * where .arg5 = ARG_CONST_SIZE_OR_ZERO + * where .arg5 = ARG_CONST_SIZE * * and this case: * r6 = 1 @@ -4955,8 +4955,7 @@ static bool arg_type_is_mem_ptr(struct bpf_arg_type arg) static bool arg_type_is_mem_size(struct bpf_arg_type arg) { - return arg.type == ARG_CONST_SIZE || - arg.type == ARG_CONST_SIZE_OR_ZERO; + return arg.type == ARG_CONST_SIZE; } static bool arg_type_is_alloc_size(struct bpf_arg_type arg) @@ -5088,7 +5087,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_MAP_VALUE] = &map_key_value_types, [ARG_PTR_TO_UNINIT_MAP_VALUE] = &map_key_value_types, [ARG_CONST_SIZE] = &scalar_types, - [ARG_CONST_SIZE_OR_ZERO] = &scalar_types, [ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types, [ARG_CONST_MAP_PTR] = &const_map_ptr_types, [ARG_PTR_TO_CTX] = &context_types, @@ -5326,7 +5324,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg_num, */ meta->raw_mode = (arg.type == ARG_PTR_TO_UNINIT_MEM); } else if (arg_type_is_mem_size(arg)) { - bool zero_size_allowed = (arg.type == ARG_CONST_SIZE_OR_ZERO); + bool zero_size_allowed = (arg.flag & ARG_FLAG_MAYBE_NULL); /* This is used to refine r0 return value bounds for helpers * that enforce this value as an upper bound on return values. diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 086889a29ca7..7d6b51ed3292 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -171,7 +171,10 @@ const struct bpf_func_proto bpf_probe_read_user_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; @@ -208,7 +211,10 @@ const struct bpf_func_proto bpf_probe_read_user_str_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; @@ -234,7 +240,10 @@ const struct bpf_func_proto bpf_probe_read_kernel_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; @@ -269,7 +278,10 @@ const struct bpf_func_proto bpf_probe_read_kernel_str_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; @@ -289,7 +301,10 @@ static const struct bpf_func_proto bpf_probe_read_compat_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; @@ -308,7 +323,10 @@ static const struct bpf_func_proto bpf_probe_read_compat_str_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; #endif /* CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE */ @@ -456,7 +474,10 @@ static const struct bpf_func_proto bpf_trace_vprintk_proto = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg4 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg4 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; const struct bpf_func_proto *bpf_get_trace_vprintk_proto(void) @@ -501,7 +522,10 @@ static const struct bpf_func_proto bpf_seq_printf_proto = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_3(bpf_seq_write, struct seq_file *, m, const void *, data, u32, len) @@ -516,7 +540,10 @@ static const struct bpf_func_proto bpf_seq_write_proto = { .arg1 = { .type = ARG_PTR_TO_BTF_ID }, .arg1_btf_id = &btf_seq_file_ids[0], .arg2 = { .type = ARG_PTR_TO_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_4(bpf_seq_printf_btf, struct seq_file *, m, struct btf_ptr *, ptr, @@ -540,7 +567,10 @@ static const struct bpf_func_proto bpf_seq_printf_btf_proto = { .arg1 = { .type = ARG_PTR_TO_BTF_ID }, .arg1_btf_id = &btf_seq_file_ids[0], .arg2 = { .type = ARG_PTR_TO_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -701,7 +731,10 @@ static const struct bpf_func_proto bpf_perf_event_output_proto = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; static DEFINE_PER_CPU(int, bpf_event_output_nest_level); @@ -952,7 +985,10 @@ static const struct bpf_func_proto bpf_d_path_proto = { .arg1 = { .type = ARG_PTR_TO_BTF_ID }, .arg1_btf_id = &bpf_d_path_btf_ids[0], .arg2 = { .type = ARG_PTR_TO_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .allowed = bpf_d_path_allowed, }; @@ -1094,7 +1130,10 @@ static const struct bpf_func_proto bpf_get_branch_snapshot_proto = { .gpl_only = true, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; static const struct bpf_func_proto * @@ -1296,7 +1335,10 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_tp = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_3(bpf_get_stackid_tp, void *, tp_buff, struct bpf_map *, map, @@ -1337,7 +1379,10 @@ static const struct bpf_func_proto bpf_get_stack_proto_tp = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, .arg2 = { .type = ARG_PTR_TO_UNINIT_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -1445,7 +1490,10 @@ static const struct bpf_func_proto bpf_read_branch_records_proto = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -1525,7 +1573,10 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_raw_tp = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; extern const struct bpf_func_proto bpf_skb_output_proto; @@ -1579,7 +1630,10 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, .arg2 = { .type = ARG_PTR_TO_MEM }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/net/core/filter.c b/net/core/filter.c index 81c6638ffc2a..5e0f726a9bcd 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2022,12 +2022,18 @@ static const struct bpf_func_proto bpf_csum_diff_proto = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg2 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg4 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg4 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg5 = { .type = ARG_ANYTHING }, }; @@ -2551,7 +2557,10 @@ static const struct bpf_func_proto bpf_redirect_neigh_proto = { .type = ARG_PTR_TO_MEM, .flag = ARG_FLAG_MAYBE_NULL, }, - .arg3 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg3 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; @@ -4184,7 +4193,10 @@ static const struct bpf_func_proto bpf_skb_event_output_proto = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BTF_ID_LIST_SINGLE(bpf_skb_output_btf_ids, struct, sk_buff) @@ -4198,7 +4210,10 @@ const struct bpf_func_proto bpf_skb_output_proto = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; static unsigned short bpf_tunnel_key_af(u64 flags) @@ -4577,7 +4592,10 @@ static const struct bpf_func_proto bpf_xdp_event_output_proto = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BTF_ID_LIST_SINGLE(bpf_xdp_output_btf_ids, struct, xdp_buff) @@ -4591,7 +4609,10 @@ const struct bpf_func_proto bpf_xdp_output_proto = { .arg2 = { .type = ARG_CONST_MAP_PTR }, .arg3 = { .type = ARG_ANYTHING }, .arg4 = { .type = ARG_PTR_TO_MEM }, - .arg5 = { .type = ARG_CONST_SIZE_OR_ZERO }, + .arg5 = { + .type = ARG_CONST_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_1(bpf_get_socket_cookie, struct sk_buff *, skb) From patchwork Tue Nov 9 02:16:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609369 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 ACF79C433FE for ; Tue, 9 Nov 2021 02:16:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FE71611C4 for ; Tue, 9 Nov 2021 02:16:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230190AbhKICT1 (ORCPT ); Mon, 8 Nov 2021 21:19:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbhKICT0 (ORCPT ); Mon, 8 Nov 2021 21:19:26 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ADDCC061570 for ; Mon, 8 Nov 2021 18:16:41 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id v18-20020a170902e8d200b00141df2da949so7653660plg.10 for ; Mon, 08 Nov 2021 18:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Hr+wzLJaJv9mNlYaiZKEYC36LQnuHRG9zrvQaabYIiY=; b=YDr1IZGokEZecCjrwDWZw+2m3b25mWyGGhXrrfqoza+vxrzmxY3wm34+nqrKzKrBr5 aVrS1J0SCRF6IKxIDjlHXcGQhsyHOhIVW9CfAKTjw8zMkSaIPUYu7m+HYawOHBOx7UTh 8t619nWd9ajsvxm3bN5XXpOLOzM7kH/IIMPbJw+vhX+sFd7+D8w1haFfjc8jn+roaHh/ giz9DikKMW+/iWAdZ+paA2Ea6SsZTKwByLFks19RQs/SOS0lmqzlWZfw3HGzeFJi5rTp COMw5rv2Xn+6yr5qWRccCheMuwPo+B7XTKpa7Y6bcFrAr+aZ7sgMWk074yHYD47gQ5E/ 7WpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Hr+wzLJaJv9mNlYaiZKEYC36LQnuHRG9zrvQaabYIiY=; b=Xl+5OYKtX1qJHnV46yIfb1yQeV0ZW0mfOTiiRkh9217lfg/XC59RzvMQ8km0AbDbcl bsgCMlXnnNlx5Fc2oAgSf4J0kMwVFY3Hd10Qh468mHJsOgEH2Ys3OdlBFtKNA+nQVU5h z2C1VBvkRAOqtDbYffFGG5Yg0ASFg18unPTiNz24O/BjUzpGySm9PZfhQYv01F22c3IB qfc3QCTWL8IiwGW79iQP3dDBMmFIFhlB/agNyw/ydEu9WizAysYht6oRij9dYG3G0W8s JuO1k8QuzwkgRQqrvyFomv7SU9MaNZAzhZxmsbkDwC8eaAT+k7BFyrYe8q9pDPN+IgfM d+mg== X-Gm-Message-State: AOAM532xnKePceoglpfosxUdABxLCBcwZ0fqOGY/GmeHuzmtD4G56Jit KSO8W2LihW5cnV8XAOEacYtWBrEG5S4= X-Google-Smtp-Source: ABdhPJynUr4JU3K8qUJHaeqs+BuC8QZ4GD0ZI8/h0CN8Fd/cRhO422Eg0V0h5GERuXcl4MsyGg27AaxNVE0= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a62:8f93:0:b0:49f:ed44:54ac with SMTP id n141-20020a628f93000000b0049fed4454acmr4217402pfd.72.1636424201127; Mon, 08 Nov 2021 18:16:41 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:20 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-6-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 5/9] bpf: Remove ARG_PTR_TO_CTX_OR_NULL From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Remove ARG_PTR_TO_CTX_OR_NULL and use flag to mark that the argument may be null. Signed-off-by: Hao Luo --- include/linux/bpf.h | 1 - kernel/bpf/cgroup.c | 5 ++++- kernel/bpf/verifier.c | 2 -- net/core/filter.c | 20 ++++++++++++++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 27f81989f992..27bf974ea6b5 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -324,7 +324,6 @@ struct bpf_arg_type { ARG_CONST_SIZE, /* number of bytes accessed from memory */ ARG_PTR_TO_CTX, /* pointer to context */ - ARG_PTR_TO_CTX_OR_NULL, /* pointer to context or NULL */ ARG_ANYTHING, /* any (initialized) argument is ok */ ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */ ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */ diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index ce4de222605f..a0b431be46f8 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1888,7 +1888,10 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sockopt_proto = { .func = bpf_get_netns_cookie_sockopt, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_CTX_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_CTX, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; #endif diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1a4830ad2be2..07b93bfd3518 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -481,7 +481,6 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { return arg.flag & ARG_FLAG_MAYBE_NULL || - arg.type == ARG_PTR_TO_CTX_OR_NULL || arg.type == ARG_PTR_TO_SOCKET_OR_NULL || arg.type == ARG_PTR_TO_ALLOC_MEM_OR_NULL || arg.type == ARG_PTR_TO_STACK_OR_NULL; @@ -5090,7 +5089,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types, [ARG_CONST_MAP_PTR] = &const_map_ptr_types, [ARG_PTR_TO_CTX] = &context_types, - [ARG_PTR_TO_CTX_OR_NULL] = &context_types, [ARG_PTR_TO_SOCK_COMMON] = &sock_types, #ifdef CONFIG_NET [ARG_PTR_TO_BTF_ID_SOCK_COMMON] = &btf_id_sock_common_types, diff --git a/net/core/filter.c b/net/core/filter.c index 5e0f726a9bcd..2575460c054f 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4691,7 +4691,10 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_proto = { .func = bpf_get_netns_cookie_sock, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_CTX_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_CTX, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_1(bpf_get_netns_cookie_sock_addr, struct bpf_sock_addr_kern *, ctx) @@ -4703,7 +4706,10 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = { .func = bpf_get_netns_cookie_sock_addr, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_CTX_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_CTX, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx) @@ -4715,7 +4721,10 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_ops_proto = { .func = bpf_get_netns_cookie_sock_ops, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_CTX_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_CTX, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_1(bpf_get_netns_cookie_sk_msg, struct sk_msg *, ctx) @@ -4727,7 +4736,10 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sk_msg_proto = { .func = bpf_get_netns_cookie_sk_msg, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1 = { .type = ARG_PTR_TO_CTX_OR_NULL }, + .arg1 = { + .type = ARG_PTR_TO_CTX, + .flag = ARG_FLAG_MAYBE_NULL, + }, }; BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb) From patchwork Tue Nov 9 02:16:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609371 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 258F6C433F5 for ; Tue, 9 Nov 2021 02:16:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0972261207 for ; Tue, 9 Nov 2021 02:16:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238877AbhKICT3 (ORCPT ); Mon, 8 Nov 2021 21:19:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238894AbhKICT2 (ORCPT ); Mon, 8 Nov 2021 21:19:28 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B233BC061570 for ; Mon, 8 Nov 2021 18:16:43 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id h35-20020a63f923000000b002d5262fdfc4so7405206pgi.2 for ; Mon, 08 Nov 2021 18:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bA52GRwUI+wYtAbCTfElgrva8CaHE3Bel6vGjs3Uixg=; b=MR2GsHswQ4r4QxDjn17VnwuU1YcQ614lpydSJ8/qpOUZ9Gb0Uw3UuNzpBwBgM4m1u4 EocTapztjD4cWYL9ERjsEP5f3F3IR2+OP394YsSPgiSZXEEVYDChMga8alUqnWJCPZo9 KkQ3BHiv78m7g6Z5uD9YOfGO4jI3PLo4swjVtQfPa8Uqu+yfzgAkGJIL6J44MvBt7j1w ZDmJkF6ZDiwD02C86ZuYM/tRl0JhiPNOBA8WN4U33HzDzBPMGCnWs5Q2QtDhQfftvBdN 8X8fSxDFGAiMnW18DirTjqcU3MNSPIzE1G/3k42WNvYhG7QyStad937YQ5g1jOCt+rj4 MGPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bA52GRwUI+wYtAbCTfElgrva8CaHE3Bel6vGjs3Uixg=; b=xMwV8hBXHNFflN/hMu7/5g3X0D43EMOTzqqKhL5Pr7yUB/qWJ2DxBnNotmpC1Dwwsa l+7DRaq95psg6Z/n0U5ucP6y69Tng093BJQFzwQqiHzCwrj2ScqhEW4H9pPxmQT+EmLB laU6RDjt1TNPGD6kQpfG59n3CEfqPGzQVwsZwmq7+lIKDhe+MNmg0JYwLz8dSqbNgvdd cjZbmYqF3gqxpi7PozmwVWjEcIY+X1GG7tR4ddEbq+5FWfifXqFe9Jfos8P1MStuRYr5 9rpQifvFGzCjkGfxBBnZIoSLgeOuakC8oSBs0Ik6I09U1NcWzZto+JxR29Kuj3tSttEY 5QjA== X-Gm-Message-State: AOAM531RvL4inxG8ULsmDaI9u+jDOiB0ejTkFs8+oJo0OkyVzXrLqfI4 CTv9jUyz3jJdBltDVLVKU6XNVbK88no= X-Google-Smtp-Source: ABdhPJxq1pybk0XVx6EWD5pru5rOF1pxj0qqhgv86hxogv+lK0Fa7z8v+84m+is4I8l34R9L79rizrloR7w= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a63:6a05:: with SMTP id f5mr3202355pgc.97.1636424203193; Mon, 08 Nov 2021 18:16:43 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:21 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-7-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 6/9] bpf: Remove ARG_PTR_TO_SOCKET_OR_NULL From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Remove ARG_PTR_TO_SOCKET_OR_NULL and use flag to mark that the argument may be null. Signed-off-by: Hao Luo --- include/linux/bpf.h | 1 - kernel/bpf/verifier.c | 2 -- net/core/filter.c | 5 ++++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 27bf974ea6b5..94eb776c925a 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -330,7 +330,6 @@ struct bpf_arg_type { ARG_PTR_TO_INT, /* pointer to int */ ARG_PTR_TO_LONG, /* pointer to long */ ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */ - ARG_PTR_TO_SOCKET_OR_NULL, /* pointer to bpf_sock (fullsock) or NULL */ ARG_PTR_TO_BTF_ID, /* pointer to in-kernel struct */ ARG_PTR_TO_ALLOC_MEM, /* pointer to dynamically allocated memory */ ARG_PTR_TO_ALLOC_MEM_OR_NULL, /* pointer to dynamically allocated memory or NULL */ diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 07b93bfd3518..f89cf2a59c82 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -481,7 +481,6 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { return arg.flag & ARG_FLAG_MAYBE_NULL || - arg.type == ARG_PTR_TO_SOCKET_OR_NULL || arg.type == ARG_PTR_TO_ALLOC_MEM_OR_NULL || arg.type == ARG_PTR_TO_STACK_OR_NULL; } @@ -5094,7 +5093,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_BTF_ID_SOCK_COMMON] = &btf_id_sock_common_types, #endif [ARG_PTR_TO_SOCKET] = &fullsock_types, - [ARG_PTR_TO_SOCKET_OR_NULL] = &fullsock_types, [ARG_PTR_TO_BTF_ID] = &btf_ptr_types, [ARG_PTR_TO_SPIN_LOCK] = &spin_lock_types, [ARG_PTR_TO_MEM] = &mem_types, diff --git a/net/core/filter.c b/net/core/filter.c index 2575460c054f..3ad3595a191e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10489,7 +10489,10 @@ static const struct bpf_func_proto bpf_sk_lookup_assign_proto = { .gpl_only = false, .ret_type = RET_INTEGER, .arg1 = { .type = ARG_PTR_TO_CTX }, - .arg2 = { .type = ARG_PTR_TO_SOCKET_OR_NULL }, + .arg2 = { + .type = ARG_PTR_TO_SOCKET, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; From patchwork Tue Nov 9 02:16:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609373 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 0F18CC433EF for ; Tue, 9 Nov 2021 02:16:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9FED611C4 for ; Tue, 9 Nov 2021 02:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238894AbhKICTb (ORCPT ); Mon, 8 Nov 2021 21:19:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbhKICTa (ORCPT ); Mon, 8 Nov 2021 21:19:30 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E10C061570 for ; Mon, 8 Nov 2021 18:16:45 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id 3-20020a620403000000b0044dbf310032so11959064pfe.0 for ; Mon, 08 Nov 2021 18:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=i2mVI49Mw6eAeYTaGKXIl+4Jv4Eq99aU4biyZahIpKg=; b=rH9AFygmOS38Ee2GkpWGYBsT0PSY/kG+xFuaveBKbmSH81bpl8xEpbyVDiqhrvoeHO pnI5cX5T4ApiatbYInUMU9ctZ9M8vMTkpborGwvJcW2Wuts3Q1IZm2tmBKaHJeNUBma9 +gbxeaYqFHP/FIwutdort256X0MDyrKpQMK70/vJvlnyC8EnI105siNuRP2N1t067SGt OyZVhVuT7lzS0KwYIYQ3qD0qdNcROMCJNfXTqxSYRW95nXZQVnzzcFJ4TZ5SUpg1uuVo wWL/fwBYzQFPtMfgn+v32+ELsuZ/SU02GuJoizhdEtTKzkcwGOJXROvDknguPe7MLjPb kzpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=i2mVI49Mw6eAeYTaGKXIl+4Jv4Eq99aU4biyZahIpKg=; b=LjscicriXCS34fndlpOInlHnoDD/XJRsKrX2HVp8aERDjC0DADQTT22gs2KM7EPUQO JGIFimvKCDoY52zSQk/ccIZm//940DyvE2hf3ra2s12MHuLIWlTuPgXvud0q25VlCvgt nt2naEcBxjsDuah+4/3QHu5Myw+ga0DGqd4Ag6tfTLd40i3vE/LQCRz/e/o0sC6u88oG 56/isDQKCz3NspNTOuf9oTAPv1IeDefT2/F4zFri0yuY+BP2hA0USB9zIsgocNFTARNc 2HaUcefBBI+pmN4Ej19HhgNcRpeItvDcvGSyZu1KzZJdj+vPV1vOSaaiaQmb98gFvt/H /xxg== X-Gm-Message-State: AOAM532MLKg6kPEIO/WeXKA6z5YsnRmH+GkOnSfS4MyH8YbveaPBzznk QcFqQ3AsUicAxp8UCTTOjOuTah9RVxg= X-Google-Smtp-Source: ABdhPJx9ltK18YtS55shOGG6jtX0Vmyx8q1JzJepvucExB4DfiC6JmjcsIVIMUZBVIPawSGAepLiMtVEX+4= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a63:6c87:: with SMTP id h129mr3157580pgc.73.1636424205256; Mon, 08 Nov 2021 18:16:45 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:22 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-8-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 7/9] bpf: Remove ARG_PTR_TO_ALLOC_MEM_OR_NULL From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Remove ARG_PTR_TO_ALLOC_MEM_OR_NULL and use flag to mark that the argument may be null. This ARG type doesn't seem to be used anywhere. Signed-off-by: Hao Luo --- include/linux/bpf.h | 1 - kernel/bpf/verifier.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 94eb776c925a..3313ba544758 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -332,7 +332,6 @@ struct bpf_arg_type { ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */ ARG_PTR_TO_BTF_ID, /* pointer to in-kernel struct */ ARG_PTR_TO_ALLOC_MEM, /* pointer to dynamically allocated memory */ - ARG_PTR_TO_ALLOC_MEM_OR_NULL, /* pointer to dynamically allocated memory or NULL */ ARG_CONST_ALLOC_SIZE_OR_ZERO, /* number of allocated bytes requested */ ARG_PTR_TO_BTF_ID_SOCK_COMMON, /* pointer to in-kernel sock_common or bpf-mirrored bpf_sock */ ARG_PTR_TO_PERCPU_BTF_ID, /* pointer to in-kernel percpu type */ diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f89cf2a59c82..2e53605a051a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -481,7 +481,6 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { return arg.flag & ARG_FLAG_MAYBE_NULL || - arg.type == ARG_PTR_TO_ALLOC_MEM_OR_NULL || arg.type == ARG_PTR_TO_STACK_OR_NULL; } @@ -5098,7 +5097,6 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_MEM] = &mem_types, [ARG_PTR_TO_UNINIT_MEM] = &mem_types, [ARG_PTR_TO_ALLOC_MEM] = &alloc_mem_types, - [ARG_PTR_TO_ALLOC_MEM_OR_NULL] = &alloc_mem_types, [ARG_PTR_TO_INT] = &int_ptr_types, [ARG_PTR_TO_LONG] = &int_ptr_types, [ARG_PTR_TO_PERCPU_BTF_ID] = &percpu_btf_ptr_types, From patchwork Tue Nov 9 02:16:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609375 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 09926C433EF for ; Tue, 9 Nov 2021 02:16:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2AF0611C5 for ; Tue, 9 Nov 2021 02:16:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239078AbhKICTd (ORCPT ); Mon, 8 Nov 2021 21:19:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbhKICTc (ORCPT ); Mon, 8 Nov 2021 21:19:32 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C870DC061570 for ; Mon, 8 Nov 2021 18:16:47 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id 184-20020a6217c1000000b0049f9aad0040so7230949pfx.21 for ; Mon, 08 Nov 2021 18:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=EqJ8jwWGMzPbV8luoAMIHUo4M8MJvCBXrIbCycCKrxI=; b=eUJ9y29r1B9HHkxOB9sAszkdBTHJnDsDLF8B4KLty2D/iLb1SDvHpCh5AmBsGV2XVU EqL1lRHlLlyM0A/U50wa02R1MLA3E5lTXt5lRltlaY6CN/7WkYTFj9+37trimtXv+5lo XMiG/KqGTOe0H4Bmcnb9feJe8Ovs8Px2K7bm6uvghSaa4ZzOhdCe2GruEpxKyMoFLkI6 mpQ0o9WN1D0cEi63A8+WqZ1amWm33FEuvktRiciDEaRi1qcyVOE/lhAUqzCG2vJwSNa+ Z1zwNDMThjuh3j9wVRHyoblWn6V+uS6t0gVGQU1NoZJLr7K3WsV3AJKMHOUS6bFaqRaO dMkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EqJ8jwWGMzPbV8luoAMIHUo4M8MJvCBXrIbCycCKrxI=; b=XFwrVGIl4CjwsKWm2ByxBuLZD0npskq/NsuHcTFOQthccQ0V9Qq8EIoAQFuFiZvjlM h7L08tpm3SJZfAojeeLT0IlvypIJ2BwY/7DgNpHD/Ye8u6X6j8BRFKepTIqHaSLs6BhK sLeorxr9ZCeIujaoxh5EhCooezZ6pPwJcRtl5Dl9nnAUeSJDPIxz3YquQu0+w9eVC1Nm zWplnkx4R4Vm8gLWyYgHBA1p8obrW0HUlilmdAp9xVIm/Y7xLggyWgm6k9YEn0Bfy9He A32uBfiK0xD/+5jfO7FpblJFg1sqTMlhcGoBnZM43qX7gGFCuo2j6np7KLROvPs0gT4g s36w== X-Gm-Message-State: AOAM532u0uzb6+8RXkmclsHQHaHm/03LTaggtG8l6+keDimjAUMHxMJP QbRpWe76kbSg1JiEcWnUzrcXd/XCmd4= X-Google-Smtp-Source: ABdhPJz1aopnmiVigurHtgl6eNuahNoSo/i72v39z4w9pY9oGRp2Q5X34eHOoW1Nu66+QFZm2+U7yYUwamI= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a63:6b03:: with SMTP id g3mr3194800pgc.123.1636424207320; Mon, 08 Nov 2021 18:16:47 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:23 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-9-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 8/9] bpf: Rename ARG_CONST_ALLOC_SIZE_OR_ZERO From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Rename ARG_CONST_ALLOC_SIZE_OR_ZERO to ARG_CONST_ALLOC_SIZE and use flag to mark that the argument may be zero. Signed-off-by: Hao Luo --- include/linux/bpf.h | 2 +- kernel/bpf/ringbuf.c | 5 ++++- kernel/bpf/verifier.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 3313ba544758..a6dd5e85113d 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -332,7 +332,7 @@ struct bpf_arg_type { ARG_PTR_TO_SOCKET, /* pointer to bpf_sock (fullsock) */ ARG_PTR_TO_BTF_ID, /* pointer to in-kernel struct */ ARG_PTR_TO_ALLOC_MEM, /* pointer to dynamically allocated memory */ - ARG_CONST_ALLOC_SIZE_OR_ZERO, /* number of allocated bytes requested */ + ARG_CONST_ALLOC_SIZE, /* number of allocated bytes requested */ ARG_PTR_TO_BTF_ID_SOCK_COMMON, /* pointer to in-kernel sock_common or bpf-mirrored bpf_sock */ ARG_PTR_TO_PERCPU_BTF_ID, /* pointer to in-kernel percpu type */ ARG_PTR_TO_FUNC, /* pointer to a bpf program function */ diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c index a8af9c7c6423..132e03617881 100644 --- a/kernel/bpf/ringbuf.c +++ b/kernel/bpf/ringbuf.c @@ -363,7 +363,10 @@ const struct bpf_func_proto bpf_ringbuf_reserve_proto = { .func = bpf_ringbuf_reserve, .ret_type = RET_PTR_TO_ALLOC_MEM_OR_NULL, .arg1 = { .type = ARG_CONST_MAP_PTR }, - .arg2 = { .type = ARG_CONST_ALLOC_SIZE_OR_ZERO }, + .arg2 = { + .type = ARG_CONST_ALLOC_SIZE, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg3 = { .type = ARG_ANYTHING }, }; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 2e53605a051a..9c4a8df25ef2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -4957,7 +4957,7 @@ static bool arg_type_is_mem_size(struct bpf_arg_type arg) static bool arg_type_is_alloc_size(struct bpf_arg_type arg) { - return arg.type == ARG_CONST_ALLOC_SIZE_OR_ZERO; + return arg.type == ARG_CONST_ALLOC_SIZE; } static bool arg_type_is_int_ptr(struct bpf_arg_type arg) @@ -5084,7 +5084,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_MAP_VALUE] = &map_key_value_types, [ARG_PTR_TO_UNINIT_MAP_VALUE] = &map_key_value_types, [ARG_CONST_SIZE] = &scalar_types, - [ARG_CONST_ALLOC_SIZE_OR_ZERO] = &scalar_types, + [ARG_CONST_ALLOC_SIZE] = &scalar_types, [ARG_CONST_MAP_PTR] = &const_map_ptr_types, [ARG_PTR_TO_CTX] = &context_types, [ARG_PTR_TO_SOCK_COMMON] = &sock_types, From patchwork Tue Nov 9 02:16:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Luo X-Patchwork-Id: 12609377 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 EED50C433EF for ; Tue, 9 Nov 2021 02:16:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D17E8611C4 for ; Tue, 9 Nov 2021 02:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238905AbhKICTf (ORCPT ); Mon, 8 Nov 2021 21:19:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238836AbhKICTe (ORCPT ); Mon, 8 Nov 2021 21:19:34 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 999DFC061570 for ; Mon, 8 Nov 2021 18:16:49 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id u10-20020a170902e80a00b001421d86afc4so7246507plg.9 for ; Mon, 08 Nov 2021 18:16:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ow/bQhJ5ayiiUZXllV41DC1Xq3tIA+rpjyEckAEfFb0=; b=Ol46RKgIm961Ys4mFFcuf7Uacjeo05BLEdNccYkZTjX20rMnPt1EQ95hsyIoNdbobE FJ/rNHrmvySzdh0oxfHkMJMBPdn/XoZiCXLcBKm/sNS9D6835UhiCsk5HvDcZEsZApqj qFhsifEO37GRRKja/JOtOQpHzXimV2cLK+QIBWzUDLXf716vDQrEIPUCTdtl0FQW6KMo 2Ve3Eaps3hskOrZ2Q3AccdE/xy4S85KkBFu+BQoK783suW/WjuoTLTmBrmMBJ2uVddMB EUVQMTJ+RsbZzL7+mOQeRo5YB2ZKUiX3FIvLISOtCgrc8peAA88xeZm8Ukm37rLcnV2u VZVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ow/bQhJ5ayiiUZXllV41DC1Xq3tIA+rpjyEckAEfFb0=; b=zfQIJ+Z/8+LgeC25N3t7CHqEz54kfjnOSh6fn5q5dTRDN+5gjf7AWyU/VgfMa5IWUF bX05/hICXk7RQ3TQlFHB2z2aqvGi7UmNVKGexx+VfkdDOjfEr5/UrtQhcC1rWiMYTK5L g2FoAzIknV+otOz48Ga3UR5Wl5vkLhXXGa8sYiaGPhoT83HSJLvE7qyXxNAs0OYVxzgt GZnYcd9g/RXaDv477UodN+FAKW74W13AEsin80+1iz0CeY5zO87WclXWB7Gq7kXlv+mD LlNT1Ir9tZMRVj9ftcQC+3H+WmtxRukVn+pI5Mmvc69Bt+b1uRiidMlGDJXLayl0gxFZ EHvA== X-Gm-Message-State: AOAM531VLBIxg1/Mm3xk0kQNURJNwatybpfKksfuz9tdJvUZR9FzjhOx 383OlO91NeLNAgY1T6fLQ7bObXso2fc= X-Google-Smtp-Source: ABdhPJy3Cb5kzc9a5RxO/VEBuTOIXhOQO8ibQg5j8ZPayd/v34LTFrOx+AXwYano+A1tIuTV1T2+XpCFXyM= X-Received: from haoluo.svl.corp.google.com ([2620:15c:2cd:202:4c6:4bbe:e4c5:ff76]) (user=haoluo job=sendgmr) by 2002:a17:903:2283:b0:141:f858:f9af with SMTP id b3-20020a170903228300b00141f858f9afmr3497273plh.80.1636424209120; Mon, 08 Nov 2021 18:16:49 -0800 (PST) Date: Mon, 8 Nov 2021 18:16:24 -0800 In-Reply-To: <20211109021624.1140446-1-haoluo@google.com> Message-Id: <20211109021624.1140446-10-haoluo@google.com> Mime-Version: 1.0 References: <20211109021624.1140446-1-haoluo@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [RFC PATCH bpf-next 9/9] bpf: Rename ARG_PTR_TO_STACK_OR_NULL From: Hao Luo To: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , bpf@vger.kernel.org, Hao Luo Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Rename ARG_PTR_TO_STACK_OR_NULL to ARG_PTR_TO_STACK and use flag to mark that the argument may be null. Signed-off-by: Hao Luo --- include/linux/bpf.h | 2 +- kernel/bpf/bpf_iter.c | 5 ++++- kernel/bpf/task_iter.c | 5 ++++- kernel/bpf/verifier.c | 5 ++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index a6dd5e85113d..da4fa15127d6 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -336,7 +336,7 @@ struct bpf_arg_type { ARG_PTR_TO_BTF_ID_SOCK_COMMON, /* pointer to in-kernel sock_common or bpf-mirrored bpf_sock */ ARG_PTR_TO_PERCPU_BTF_ID, /* pointer to in-kernel percpu type */ ARG_PTR_TO_FUNC, /* pointer to a bpf program function */ - ARG_PTR_TO_STACK_OR_NULL, /* pointer to stack or NULL */ + ARG_PTR_TO_STACK, /* pointer to stack */ ARG_PTR_TO_CONST_STR, /* pointer to a null terminated read-only string */ ARG_PTR_TO_TIMER, /* pointer to bpf_timer */ __BPF_ARG_TYPE_MAX, diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c index 4fdf225c01f9..d3bded3e05d3 100644 --- a/kernel/bpf/bpf_iter.c +++ b/kernel/bpf/bpf_iter.c @@ -711,6 +711,9 @@ const struct bpf_func_proto bpf_for_each_map_elem_proto = { .ret_type = RET_INTEGER, .arg1 = { .type = ARG_CONST_MAP_PTR }, .arg2 = { .type = ARG_PTR_TO_FUNC }, - .arg3 = { .type = ARG_PTR_TO_STACK_OR_NULL }, + .arg3 = { + .type = ARG_PTR_TO_STACK, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg4 = { .type = ARG_ANYTHING }, }; diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index 0a5e3cf593b5..fc72701ae6b6 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -625,7 +625,10 @@ const struct bpf_func_proto bpf_find_vma_proto = { .arg1_btf_id = &btf_task_struct_ids[0], .arg2 = { .type = ARG_ANYTHING }, .arg3 = { .type = ARG_PTR_TO_FUNC }, - .arg4 = { .type = ARG_PTR_TO_STACK_OR_NULL }, + .arg4 = { + .type = ARG_PTR_TO_STACK, + .flag = ARG_FLAG_MAYBE_NULL, + }, .arg5 = { .type = ARG_ANYTHING }, }; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9c4a8df25ef2..9c68b664f4f4 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -480,8 +480,7 @@ static bool arg_type_may_be_refcounted(struct bpf_arg_type arg) static bool arg_type_may_be_null(struct bpf_arg_type arg) { - return arg.flag & ARG_FLAG_MAYBE_NULL || - arg.type == ARG_PTR_TO_STACK_OR_NULL; + return arg.flag & ARG_FLAG_MAYBE_NULL; } /* Determine whether the function releases some resources allocated by another @@ -5101,7 +5100,7 @@ static const struct bpf_reg_types *compatible_reg_types[__BPF_ARG_TYPE_MAX] = { [ARG_PTR_TO_LONG] = &int_ptr_types, [ARG_PTR_TO_PERCPU_BTF_ID] = &percpu_btf_ptr_types, [ARG_PTR_TO_FUNC] = &func_ptr_types, - [ARG_PTR_TO_STACK_OR_NULL] = &stack_ptr_types, + [ARG_PTR_TO_STACK] = &stack_ptr_types, [ARG_PTR_TO_CONST_STR] = &const_str_ptr_types, [ARG_PTR_TO_TIMER] = &timer_types, };