From patchwork Wed Jun 17 20:43:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Ignatov X-Patchwork-Id: 1311510 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=fb.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.a=rsa-sha256 header.s=facebook header.b=A9qnOG/X; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49nHB13Cshz9sT9 for ; Thu, 18 Jun 2020 06:44:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726984AbgFQUol (ORCPT ); Wed, 17 Jun 2020 16:44:41 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:38506 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbgFQUok (ORCPT ); Wed, 17 Jun 2020 16:44:40 -0400 Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05HKZhFW024268 for ; Wed, 17 Jun 2020 13:44:39 -0700 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=vyKWXHfNkpJBknpAg0rWdI9c4pvECRYKMHHXxlwHqSI=; b=A9qnOG/XYFr1qk+k2jxhuQGHWq9SwYzy6X6BdVn9AvdHBhLr6SseU64f3vwJaJDfKt/B M9qirC84Ck56uaxsmckEbbBJ8TQmn53AEzDeMknKcHSHP9wfhpgpXX73rOkbrTOnFOd7 WJoHCzvuSwgqRZTFrCQXT8aWiwC5pIGOdUY= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 31q653fun3-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 17 Jun 2020 13:44:39 -0700 Received: from intmgw001.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 17 Jun 2020 13:44:15 -0700 Received: by dev082.prn2.facebook.com (Postfix, from userid 572249) id AC8F83700B15; Wed, 17 Jun 2020 13:44:11 -0700 (PDT) Smtp-Origin-Hostprefix: dev From: Andrey Ignatov Smtp-Origin-Hostname: dev082.prn2.facebook.com To: CC: Andrey Ignatov , , , , Smtp-Origin-Cluster: prn2c23 Subject: [PATCH bpf-next 2/6] bpf: Introduce btf_find_by_name_kind_next() Date: Wed, 17 Jun 2020 13:43:43 -0700 Message-ID: <077d491bfa92c2a16f0843c2b0df0773ab8496ee.1592426215.git.rdna@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-17_11:2020-06-17,2020-06-17 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 clxscore=1015 priorityscore=1501 impostorscore=0 cotscore=-2147483648 suspectscore=13 spamscore=0 lowpriorityscore=0 mlxscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxlogscore=726 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006170154 X-FB-Internal: deliver Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Introduce btf_find_by_name_kind_next() function to find btf_id by name and kind starting from specified start_id to reuse the function in finding duplicates (e.g. structs with same name) in btf. Signed-off-by: Andrey Ignatov --- include/linux/btf.h | 2 ++ kernel/bpf/btf.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index 5c1ea99b480f..69e017594298 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -56,6 +56,8 @@ bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s, int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t); bool btf_type_is_void(const struct btf_type *t); s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind); +s32 btf_find_by_name_kind_next(const struct btf *btf, const char *name, u8 kind, + u32 start_id); const struct btf_type *btf_type_skip_modifiers(const struct btf *btf, u32 id, u32 *res_id); const struct btf_type *btf_type_resolve_ptr(const struct btf *btf, diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 3eb804618a53..e5c5305e859c 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -383,12 +383,18 @@ static bool btf_type_is_datasec(const struct btf_type *t) } s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) +{ + return btf_find_by_name_kind_next(btf, name, kind, 1); +} + +s32 btf_find_by_name_kind_next(const struct btf *btf, const char *name, u8 kind, + u32 start_id) { const struct btf_type *t; const char *tname; u32 i; - for (i = 1; i <= btf->nr_types; i++) { + for (i = start_id; i <= btf->nr_types; i++) { t = btf->types[i]; if (BTF_INFO_KIND(t->info) != kind) continue;