From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16F35C433E6 for ; Thu, 25 Feb 2021 07:34:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C25D264ED9 for ; Thu, 25 Feb 2021 07:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232600AbhBYHeB (ORCPT ); Thu, 25 Feb 2021 02:34:01 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:45522 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233396AbhBYHd7 (ORCPT ); Thu, 25 Feb 2021 02:33:59 -0500 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 11P7UZjr005814 for ; Wed, 24 Feb 2021 23:33:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=/FvcrgXA/34ztMeBDTyezRLU0oLe5JyygoIVPrTa08c=; b=SrzAYtk1NlkNtTGaV1DRp9/qle2eaVyt2Eno/wIhnY3upOX6UBwAivIEc4SNRU5BsNt4 NetVkbU+XUn8jmvYEM+Rus4qgZsbF/wH8PiBXBxiMvdQ3JQUw8PAgikAMXr+cdTHDfiv TYbqwJv2UFdBS4m90/K/3O8iy251bKH8SZE= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 36w7j1hne8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 24 Feb 2021 23:33:19 -0800 Received: from intmgw001.25.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 24 Feb 2021 23:33:17 -0800 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id C6DB53705D0E; Wed, 24 Feb 2021 23:33:15 -0800 (PST) From: Yonghong Song To: CC: Alexei Starovoitov , Cong Wang , Daniel Borkmann , Subject: [PATCH bpf-next v3 06/11] bpf: add arraymap support for bpf_for_each_map_elem() helper Date: Wed, 24 Feb 2021 23:33:15 -0800 Message-ID: <20210225073315.4121184-1-yhs@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20210225073309.4119708-1-yhs@fb.com> References: <20210225073309.4119708-1-yhs@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-02-25_04:2021-02-24,2021-02-25 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxlogscore=506 adultscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 impostorscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102250062 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org This patch added support for arraymap and percpu arraymap. Signed-off-by: Yonghong Song --- kernel/bpf/arraymap.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 1f8453343bf2..4077a8ae7089 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -625,6 +625,42 @@ static const struct bpf_iter_seq_info iter_seq_info = =3D { .seq_priv_size =3D sizeof(struct bpf_iter_seq_array_map_info), }; =20 +static int bpf_for_each_array_elem(struct bpf_map *map, void *callback_f= n, + void *callback_ctx, u64 flags) +{ + u32 i, index, num_elems =3D 0; + struct bpf_array *array; + bool is_percpu; + u64 ret =3D 0; + void *val; + + if (flags !=3D 0) + return -EINVAL; + + is_percpu =3D map->map_type =3D=3D BPF_MAP_TYPE_PERCPU_ARRAY; + array =3D container_of(map, struct bpf_array, map); + if (is_percpu) + migrate_disable(); + for (i =3D 0; i < map->max_entries; i++) { + index =3D i & array->index_mask; + if (is_percpu) + val =3D this_cpu_ptr(array->pptrs[i]); + else + val =3D array->value + array->elem_size * i; + num_elems++; + ret =3D BPF_CAST_CALL(callback_fn)((u64)(long)map, + (u64)(long)&index, (u64)(long)val, + (u64)(long)callback_ctx, 0); + /* return value: 0 - continue, 1 - stop and return */ + if (ret) + break; + } + + if (is_percpu) + migrate_enable(); + return num_elems; +} + static int array_map_btf_id; const struct bpf_map_ops array_map_ops =3D { .map_meta_equal =3D array_map_meta_equal, @@ -643,6 +679,8 @@ const struct bpf_map_ops array_map_ops =3D { .map_check_btf =3D array_map_check_btf, .map_lookup_batch =3D generic_map_lookup_batch, .map_update_batch =3D generic_map_update_batch, + .map_set_for_each_callback_args =3D map_set_for_each_callback_args, + .map_for_each_callback =3D bpf_for_each_array_elem, .map_btf_name =3D "bpf_array", .map_btf_id =3D &array_map_btf_id, .iter_seq_info =3D &iter_seq_info, @@ -660,6 +698,8 @@ const struct bpf_map_ops percpu_array_map_ops =3D { .map_delete_elem =3D array_map_delete_elem, .map_seq_show_elem =3D percpu_array_map_seq_show_elem, .map_check_btf =3D array_map_check_btf, + .map_set_for_each_callback_args =3D map_set_for_each_callback_args, + .map_for_each_callback =3D bpf_for_each_array_elem, .map_btf_name =3D "bpf_array", .map_btf_id =3D &percpu_array_map_btf_id, .iter_seq_info =3D &iter_seq_info, --=20 2.24.1