From patchwork Tue Mar 15 22:15:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12781885 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DF21C433F5 for ; Tue, 15 Mar 2022 22:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245650AbiCOWQc (ORCPT ); Tue, 15 Mar 2022 18:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbiCOWQa (ORCPT ); Tue, 15 Mar 2022 18:16:30 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 827EA5574F for ; Tue, 15 Mar 2022 15:15:16 -0700 (PDT) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.1.2/8.16.1.2) with ESMTP id 22FLfqgq019624 for ; Tue, 15 Mar 2022 15:15:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=VojZKIOiLxwYSZgUwP4QSusRUqVAZXE9L0TPyOFByJ4=; b=hmzV89OiquBwoKArOfve2540prSlcxDD0VhcoFqSyCVxXfg9AEDg1mobnlIAkAZ8mwKa 9c5xuWE8addKB+bqWUFAQqkJ4pCERe4icEn3Drx4gc0lOallBeY6kp2pJMI6F1iWYI6h 2B9Iq4dv/cG10/elqNW02dL5P+zerUq/muA= Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2175.outbound.protection.outlook.com [104.47.58.175]) by m0001303.ppops.net (PPS) with ESMTPS id 3etj2ueywh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 15 Mar 2022 15:15:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hfFdC6kg720Kd6FzO/dFUDM1OZnhR5ndUXw7DW1ImPKwKpcWCcZJVerPHeaTSjBlgnY7pa2bhE6HE54MoZ0Y59cqbf5o1uKvblmwcteqZHc4NK45q5uMvkMS7zWex/3jm8bJbYgkijLdz5lEQF0GoJhJaspIl+Ue/69nxzRu8QYDCDaoXa9pDCXFIr2PcBPnExHnuO0T9xpOYzrNBSKVPuJEy7TUzoN9r5XWquvSyT8+Qlnkz4u8iMDvsp3nS9KhR7relM4WcrGMWVxEi2U+zdJlHi373UmBthLj0Odr54UYD8QyjozQrCFc3Q2G9/lnuBKBpud7Jam49+bedqgTLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VojZKIOiLxwYSZgUwP4QSusRUqVAZXE9L0TPyOFByJ4=; b=gezOB+uFJvcj+g++6O2EyTpONPLLbrDd4GxOI46iCwLFOX/Xg1cL2Wr/wuk/wvhSGepDX5ksqRU1oBebwMDZumvvTfAi2R816nIxOSGmndLIoEYbcdhzUrNDpjaufKSxTyAD3OweGgIUGi85aiU14qD3iIwwulrd7a9An9HvRq2xKx48rKsBafEc+iFP+37blmt4MOLcY7DxeEANqj7w142KmLI7DgAomIqfViuc51FUY8A7fMYeh7+s8RYeJtE3GWen7Xfor3Tvf/xlYHl2mSlFS63D6vcueaHx+40FWtcfG4GA/fHrqv6UT6pxFm8rbXVIq4MHoiPEKVdgenaJlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none Received: from SJ0PR15MB5154.namprd15.prod.outlook.com (2603:10b6:a03:423::6) by BYAPR15MB2695.namprd15.prod.outlook.com (2603:10b6:a03:150::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.28; Tue, 15 Mar 2022 22:15:12 +0000 Received: from SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::90c1:20f8:4fc6:d7a3]) by SJ0PR15MB5154.namprd15.prod.outlook.com ([fe80::90c1:20f8:4fc6:d7a3%6]) with mapi id 15.20.5081.014; Tue, 15 Mar 2022 22:15:10 +0000 From: Delyan Kratunov To: "daniel@iogearbox.net" , "ast@kernel.org" , "andrii@kernel.org" , "bpf@vger.kernel.org" Subject: [PATCH bpf-next v3 2/5] libbpf: init btf_{key,value}_type_id on internal map open Thread-Topic: [PATCH bpf-next v3 2/5] libbpf: init btf_{key,value}_type_id on internal map open Thread-Index: AQHYOLoir9tCuOllkkm7a6Yf41ZA6w== Date: Tue, 15 Mar 2022 22:15:10 +0000 Message-ID: <249e598bc7a9b66397465518654e98a11719ce13.1647382072.git.delyank@fb.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7f6aa1da-9aca-4c97-79e5-08da06d14532 x-ms-traffictypediagnostic: BYAPR15MB2695:EE_ x-microsoft-antispam-prvs: x-fb-source: Internal x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: sRVlwYHbWRyZJRcIIhktTNJphKuxE48jWwEkYkEm2yqZuUyQNPl9WxH/lwdjfLAzyHfRw3yG9kNtDlcXy7GaCP8wt7v70ONW5pD/iqAikz9ya8kG0Z+ofNJeNFuIr8BNMezoHFMaOYfjMPwLRNGcUl2jqVroXcgtd9jHrWUbPnTAHiwoiV71Gb/SwkH4ZpSaK6wZoSSS7+XobAFbzj00nGZH9YnUoPFK4FeqsClJsEv7wf/XEvByMG2Jlpcar2nV5QmAkQW+bzuX2Iod8/eXYRkkWn28gIPhuVTKsMS1W/9WwrKGPnLKJvzeyEUzxKkeJ7DAVlcDQ8ZwCzU4rFJJsVAXZKZRWB7ZsMp9XG9llfnIWHEsCxsFQliVBfmKz5TN3J1+UtYLYt9SUxD47zunxrq7vrj87Me7VvHVVLdwfo1UFLKdHvYZYO6HWuWS5cObbmHvdBukbpprmQqok8bHipdAQb+BJpmWVTRwYqNTsWS9DgJzEArfoZ1rdh6xClBWWpLnF7Nx06quJF0HQRFypnEbuEy1BWHtvSfIXf/uMsWW0HsvuJ8maTCQEhPEwlaTiOM6ofp/RYSL8E7z1TmjuG42iHglJRZSL68HUJfTtolAm6fZgvRzb+fF8nBKhGlr0Ng5iUA+4mSCL1HmsuHqc9zQ9Xr0/tpg6SpkrMznLXV/ipfx5Lhs4/bOYqbBToqhwvxl8x+69XcaAZuL7Peyhg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR15MB5154.namprd15.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(66446008)(66946007)(6512007)(6506007)(2616005)(64756008)(38100700002)(8676002)(76116006)(66556008)(91956017)(122000001)(66476007)(2906002)(186003)(83380400001)(316002)(110136005)(6486002)(38070700005)(71200400001)(508600001)(86362001)(36756003)(8936002)(5660300002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?BmH8lkVTmYkmNYC2dp9qPcO?= =?iso-8859-1?q?I+bdeMKnnpWMapRW6K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IsQTVx/qIYaPhW7U49ObVT?= =?iso-8859-1?q?01jvZQ0FRqPR7Sk0lbqHKApPivyQDB/LrsBJ3TW3amB/j+BZsRnsQUBorv6Y?= =?iso-8859-1?q?mHtCQu17bruQBwA5HgXNlokP+U3JeHxzyszAInc4xIIWQvesBcx/aScFNE7g?= =?iso-8859-1?q?9wqXGyDwo9lLaVumap/f6Iy+DM0WUuqe/OVljf1PNWt77aRu2qRXnQmsZVyk?= =?iso-8859-1?q?2MrgFt3Wcduoj2XOXo2NbVR9tq4APDVJ/5yIA49IbDNxj74J4zuRoTRaO6yc?= =?iso-8859-1?q?r0kD8KXIFNIWIZ1GgwfPZni/ddJ/r4+plmF8SHYbDeFcNYl86Bq4SHYqXl0R?= =?iso-8859-1?q?/rt6Mnh2MyeSLYmZ9q/y49pXLeqjaQV7hFj1YFg9rZ0LZ6TusLirjiM17wtq?= =?iso-8859-1?q?B75fhlN6kvVtaoSS+6ueDnNwdHtcpLA5+iygolg2pNhzEjkUwtqXaJ15/lSt?= =?iso-8859-1?q?mdWG3anYG0cDe1UlXU9duRNMSlPQYcHb+6Oo4YSAaUx8fkk7/xIzWDImH8F9?= =?iso-8859-1?q?P032WzZLjX0jdP7wzMi5Ms0l2bMWAx0CZy3Sl/p132vSBZX2M/5SDATxBmFB?= =?iso-8859-1?q?Dl5xAeo21Dqm6mwcoDpPJ+cS248jRB97Wy5gAGIE9Z8C9/Bd0GUE=3D?= MIME-Version: 1.0 X-OriginatorOrg: fb.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR15MB5154.namprd15.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f6aa1da-9aca-4c97-79e5-08da06d14532 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Mar 2022 22:15:10.3807 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DP5JXSppg/MxJ8Da28by0/AsbOIjQkur7CGfy6z+lk5SAX+dOdLxZqa7WM4zV7Ht X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR15MB2695 X-Proofpoint-GUID: csqWurzJQhf-zYwNG4m6F0-wRYMkT1ud X-Proofpoint-ORIG-GUID: csqWurzJQhf-zYwNG4m6F0-wRYMkT1ud X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-15_11,2022-03-15_01,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net For internal and user BTF maps, look up the key and value btf types on open() and not load(), so that `bpf_map_btf_value_type_id` is usable in `bpftool gen`. Signed-off-by: Delyan Kratunov --- tools/lib/bpf/libbpf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index aa26163e4ca1..e98a8381aad8 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1517,6 +1517,9 @@ static char *internal_map_name(struct bpf_object *obj, const char *real_name) return strdup(map_name); } +static int +bpf_map_find_btf_info(struct bpf_object *obj, struct bpf_map *map); + static int bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type, const char *real_name, int sec_idx, void *data, size_t data_sz) @@ -1564,6 +1567,9 @@ bpf_object__init_internal_map(struct bpf_object *obj, enum libbpf_map_type type, return err; } + /* failures are fine because of maps like .rodata.str1.1 */ + (void) bpf_map_find_btf_info(obj, map); + if (data) memcpy(map->mmaped, data, data_sz); @@ -2534,6 +2540,10 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, fill_map_from_def(map->inner_map, &inner_def); } + err = bpf_map_find_btf_info(obj, map); + if (err) + return err; + return 0; } @@ -4873,7 +4883,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b if (bpf_map__is_struct_ops(map)) create_attr.btf_vmlinux_value_type_id = map->btf_vmlinux_value_type_id; - if (obj->btf && btf__fd(obj->btf) >= 0 && !bpf_map_find_btf_info(obj, map)) { + if (obj->btf && btf__fd(obj->btf) >= 0) { create_attr.btf_fd = btf__fd(obj->btf); create_attr.btf_key_type_id = map->btf_key_type_id; create_attr.btf_value_type_id = map->btf_value_type_id;