Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2147719rdb; Thu, 7 Dec 2023 22:17:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtPJM/SkJvo+wq+MzFKmhdGqlSRqPnSwHSYd4QiUzvRaTD2x05b7FMWRO+07ug1lQF7Sm2 X-Received: by 2002:a05:6870:d207:b0:1fb:75b:12f7 with SMTP id g7-20020a056870d20700b001fb075b12f7mr4602894oac.73.1702016242172; Thu, 07 Dec 2023 22:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702016242; cv=none; d=google.com; s=arc-20160816; b=tri8T6iPGXkscmkOKE0SGOVud3FZwfuymznXLmRcmZP/Al6uO7+kXd2/8h2srFSoLV 8Pvdlf1aTeRrNvxYKnbjwtdKZwjZsUsIGfr8jJPvNwjZTtksCAu4TK2GNbgGoSlNQIYY 87/rwOXiRO5YDTqWd3vWaZp93nhU09iAy53ISsVSrWfN6Yp9/kVSdQEJCDlOK+EdnlKm oH2qorXubIr3gk3RbsnHh3xadmX74cwA2cWswDGCUXZCl/ZWGrXes8Nu0eiiYmqMtkKE Rmugubin8hVqXKXHbcGY5aTVlP5NccKPWBIkuRxx/o8S5wLOXh9EEPF7D/dsJtu+lfZP jElQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+rljey37reCyDrPkcI18g/IC3m4eCS+5k4TU+Pl3Hf0=; fh=ZdPZcpOUrkEVH+FogHTPr8k6My9wbiXRCG7qq+q3nfo=; b=Otf1q1MHbnkR21dxyQKypbfS9esVvHKKVSFkqvAX5K8UcMwNysXNgTo6JXzBbi11DR 3WcXVCxu/a2V3BtinjH+x/7PpEmKSpLDAWzkvqOnJdaFV1sVK1ZrrwPYqD3yn8jMg0yy NYI4LQQ6izliEh5kdOt1kdshCJBP7vHvh0Du7D51Dm2fm4kevsIjQNvCkKjmwIfAv4dm IjnYEh2HzU/1K4JNWXMNK0s7KA+z4Xen8jNmJpUTEqeV2BxZT/uaE3Z8Ocw0Hf0SIlJe RtVFuhrpm/IdU081C+SSrMjw5Msf3eryBQKGGEdeSbhZn7ss+1Vqn13MR4H1v8HArGYC PQNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o62-20020a634141000000b005c662c8da88si1017229pga.146.2023.12.07.22.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 22:17:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A34DB80DEA49; Thu, 7 Dec 2023 22:17:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232891AbjLHGRL (ORCPT + 99 others); Fri, 8 Dec 2023 01:17:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjLHGRJ (ORCPT ); Fri, 8 Dec 2023 01:17:09 -0500 Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C35710FC; Thu, 7 Dec 2023 22:17:15 -0800 (PST) Received: by mail-io1-f49.google.com with SMTP id ca18e2360f4ac-7b6eb711498so60222739f.3; Thu, 07 Dec 2023 22:17:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702016234; x=1702621034; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+rljey37reCyDrPkcI18g/IC3m4eCS+5k4TU+Pl3Hf0=; b=l1F4N9UGpY0fhs3T4NXrYCnXmS/nhNlY8peQ9uf3GN+zfCE24HKpnoR1yq30eCQ9ma TA3Xy2TmOsOGtfjahVd1kBsLiiIs+XUbe+WnheJTC1pMezDh/dO4h58LhBnVj5Ry6RPx DMdo2lYXDcaxde3npPa5bf5JRZJH8Wfy3a8NPJUB8JVdZSbkUXeSM0KAK9fqo4933dc0 dGaGYtF0rFa2DSCyCAzahqeCUIMJX/aQtFgDs3qiuOeA7hAuzA/2xIwAzo/bpk5zkFjF 6hSan9y2Y9alUUmOmJxBzWAY23nE7Anw8BeQ0in2y6iNz00vt8HmbdXLeZobSxMzAoda qPdQ== X-Gm-Message-State: AOJu0YyF3VOyIssDQRo+NlCrnu9dYOWDCm2tbkARl6NqUB9FYqowyCWk lNapWoxStW3JDHfWHOOgaqltKpo0DvpBLLiB X-Received: by 2002:a05:6e02:1a44:b0:35d:59a2:332b with SMTP id u4-20020a056e021a4400b0035d59a2332bmr5204188ilv.47.1702016234149; Thu, 07 Dec 2023 22:17:14 -0800 (PST) Received: from localhost (c-24-1-27-177.hsd1.il.comcast.net. [24.1.27.177]) by smtp.gmail.com with ESMTPSA id bu13-20020a056e02350d00b0035d70b70d1csm214118ilb.2.2023.12.07.22.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 22:17:13 -0800 (PST) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, tj@kernel.org Subject: [PATCH bpf-next] bpf: Load vmlinux btf for any struct_ops map Date: Fri, 8 Dec 2023 00:17:03 -0600 Message-ID: <20231208061704.400463-1-void@manifault.com> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 07 Dec 2023 22:17:20 -0800 (PST) In libbpf, when determining whether we need to load vmlinux btf, we're currently (among other things) checking whether there is any struct_ops program present in the object. This works for most realistic struct_ops maps, as a struct_ops map is of course typically composed of one or more struct_ops programs. However, that technically need not be the case. A struct_ops interface could be defined which allows a map to be specified which one or more non-prog fields, and which provides default behavior if no struct_ops progs is actually provided otherwise. For sched_ext, for example, you technically only need to specify the name of the scheduler in the struct_ops map, with the core scheduler logic providing default behavior if no prog is actually specified. If we were to define and try to load such a struct_ops map, we would crash in libbpf when initializing it as obj->btf_vmlinux will be NULL: Reading symbols from minimal... (gdb) r Starting program: minimal_example [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. 0x000055555558308c in btf__type_cnt (btf=0x0) at btf.c:612 612 return btf->start_id + btf->nr_types; (gdb) bt type_name=0x5555555d99e3 "sched_ext_ops", kind=4) at btf.c:914 kind=4) at btf.c:942 type=0x7fffffffe558, type_id=0x7fffffffe548, ... data_member=0x7fffffffe568) at libbpf.c:948 kern_btf=0x0) at libbpf.c:1017 at libbpf.c:8059 So as to account for such bare-bones struct_ops maps, let's update obj_needs_vmlinux_btf() to also iterate over an obj's maps and check whether any of them are struct_ops maps. Signed-off-by: David Vernet --- tools/lib/bpf/libbpf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index ea9b8158c20d..ac54ebc0629f 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3054,9 +3054,15 @@ static bool prog_needs_vmlinux_btf(struct bpf_program *prog) return false; } +static bool map_needs_vmlinux_btf(struct bpf_map *map) +{ + return bpf_map__is_struct_ops(map); +} + static bool obj_needs_vmlinux_btf(const struct bpf_object *obj) { struct bpf_program *prog; + struct bpf_map *map; int i; /* CO-RE relocations need kernel BTF, only when btf_custom_path @@ -3081,6 +3087,11 @@ static bool obj_needs_vmlinux_btf(const struct bpf_object *obj) return true; } + bpf_object__for_each_map(map, obj) { + if (map_needs_vmlinux_btf(map)) + return true; + } + return false; } -- 2.42.1