From patchwork Mon Feb 7 16:00:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yinjun Zhang X-Patchwork-Id: 12737600 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 93FC2C433EF for ; Mon, 7 Feb 2022 16:13:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231696AbiBGQNX (ORCPT ); Mon, 7 Feb 2022 11:13:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385424AbiBGQAz (ORCPT ); Mon, 7 Feb 2022 11:00:55 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2109.outbound.protection.outlook.com [40.107.101.109]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59DADC0401CC for ; Mon, 7 Feb 2022 08:00:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aynFlnNAx345KvU3EDP1/lyuEf13IAfaFTLxEJSDqSoZgzR/C7jb34u8rLkYAtQFVxkv2Ts/dHVqx5zbADu9x963dQZ2fQDAcQ7NSFb2XI1mZwJj+53KpxNJTQQyHOLeS6fm1B7sUmex6p3KXkoow8AQa3QbsdqTbuvuuuYVTGhfkASqyAyRyrPi7z2Su8//AB7GWnXfkS89giYVXjSGEzpGRqJeaa4dIh1M4G75BBma7UOEPythdd4wgXCdWf6r2P7nWcDBkqWHopdScuGiBM+eu90oKetV+Nyz3sUPYj7xB0UcnjiugrXHyYZbQoaGcNd8mDIUO9tXaukfy6QuMQ== 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=6xPf2t7eUSOg6esxn6NqXFrCTw8Z2HfTUVf+WmOf0sA=; b=EVp9FrwSIhwgQ+fpuImJzVgfsqEu6hJBbvUZBkutrM4Q7Uv1ov0iWjeLG6GXd0XweWXjwG3JcObuIildh7LaWGI60G/hQMtkQJ1Gk21cJ8rELSpX+NVwV+VTCiDa/VSO91qRVzlD5oFs35WxrDU4Jlg6y+8NLYnYu4wJ19Ev/cYWDwdrNn3akMgyOzyUgygX3rA9gHO7F77nRzI1efWTI2rgvWd3TiNqoxXHd35D/Ys7agn1EFZtmYjIo2UWZ5cWn6Zr/JIyNdHzT4zaCYZHxrXa/t+TmZnc4iAR5AqXCQDjQ9K9eJL9mnvUCL2mVAII7GwCk9Kl7FglfmB/senvVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6xPf2t7eUSOg6esxn6NqXFrCTw8Z2HfTUVf+WmOf0sA=; b=TDBPnZLbnN28PQ2nLwouxp9lnpZYprQ7BI+ykZAUnAneyaSAaTTjzsgtrEqa8fYBQanyyhf8m9dESgvkqQh8eL1pSrvOQeyFMMa/FCBaQAf7bhfF3rcGw4aPgSJyhN6uXBRBYAjqYJt+PwxzMRjp4kmwykUV/wgDCc1I496A7NI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from CH2PR13MB3702.namprd13.prod.outlook.com (2603:10b6:610:a1::20) by BY5PR13MB3332.namprd13.prod.outlook.com (2603:10b6:a03:1a5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Mon, 7 Feb 2022 16:00:52 +0000 Received: from CH2PR13MB3702.namprd13.prod.outlook.com ([fe80::84e8:4c19:d6d7:a8ee]) by CH2PR13MB3702.namprd13.prod.outlook.com ([fe80::84e8:4c19:d6d7:a8ee%4]) with mapi id 15.20.4975.011; Mon, 7 Feb 2022 16:00:52 +0000 From: Yinjun Zhang To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, niklas.soderlund@corigine.com, Yinjun Zhang , Simon Horman Subject: [PATCH bpf] bpftool: fix the error when lookup in no-btf maps Date: Tue, 8 Feb 2022 00:00:25 +0800 Message-Id: <1644249625-22479-1-git-send-email-yinjun.zhang@corigine.com> X-Mailer: git-send-email 1.8.3.1 X-ClientProxiedBy: BYAPR05CA0057.namprd05.prod.outlook.com (2603:10b6:a03:74::34) To CH2PR13MB3702.namprd13.prod.outlook.com (2603:10b6:610:a1::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b03540b-bd8a-40ac-9999-08d9ea5303fe X-MS-TrafficTypeDiagnostic: BY5PR13MB3332:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OgJ88AFffr2s6Iu65LDy0KdolNXYIbnuWad7eO97TFdGat3jL9i4ma8W0vVR30DZaEIU9j6e2QzbhoZ5B+dkTqrLM8YCRcKRuN0P//TBK2yYJOG5I07S/5KACw/S7lxbguzv2aBlRk69Cn5roeaXxtL2i3umU5k7BN0FnYqtDyi2ELqY8ihkRJnAu4Gs4+r9DhHA9qAWmtf96jOcfJH4rsprBXOwUm62NVc4/L2fYxkVZbOJTCr4nFvx9XBkE1RM5KSDP0KTje9PugHHyz7y4wbqrEPhH7uDWGilhuEtjyKEJS/n1rNxf2FlnqUh9bIsvzGOP4GlurtA2ogIk00gor1xQYJx6IfqBDQTwVmB5UawO/KfI+atZNvAmBTo3yWmMWg6h9Cdu4Jetuo+V61MTSyRIqusjJ45+8k8pYjQM1fWo9tv0DwXJcSAsFKRrP3vDimXTyrjskYSpMvZgdxcB66Pyqeoi14SMeQXSV/P/TLHKcO1yUcFzAqc9SW+o9u1pj2z3fF7fgeE+51nbzATZ1t6Wn93kJci/+5izFXrzrBZfEThzynkmp6iOS5qDKKJpJz5I/KQcxd8eKUqxJX6wwbgqfvjAbrV8G63+NwrvWlxPr4dFim3/5XlnQ0DRVkWdau5s2jddyGIYawoMlZiUXRAdJEzIshQeGLMvTORXocVhhmC9BolwKcqM3dKoZfOttA1nTtT5w4ysRCr7S87J7CmaIYMsA3wZFfQCusgvFvTyCsu1hdTecUE1tX4/zKb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR13MB3702.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(396003)(366004)(346002)(39830400003)(376002)(136003)(6512007)(316002)(6666004)(6506007)(54906003)(86362001)(52116002)(66476007)(8676002)(66946007)(4326008)(8936002)(83380400001)(66556008)(107886003)(2906002)(2616005)(26005)(186003)(5660300002)(44832011)(38100700002)(38350700002)(508600001)(36756003)(6486002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?tpAqHhFFSxoCvK5oYGt4aWjgD7z8?= =?utf-8?q?IMbYvt4kWZR/8mPD4DxrFsv+dhau19NUbRT52T4r+mS8cLMsiz6D5p65iiOMTz4ZF?= =?utf-8?q?h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rj+8ixVAHjsUDskhsK5inmw+35n/MPnIle/R4kLhNDqZ/6e6W0L?= =?utf-8?q?XVpEMmVgapVktSoh0znTF+tqbNt/JAWuxfL6R2795SFdqY0Hr7a3NqKZ4JNS5ujuG?= =?utf-8?q?Vr3/cZa1Tg5QnqJ8fG7UIn83uMMHGU1nOmo7Z0ZO9po1UJKwDmTp1ENlIIzbS94Zj?= =?utf-8?q?18ETqQRYJDQ4AHB5WwauufVjJi++6nBWkN9AK/8YGit+8QHMjlpR+n4ongSEnp0Uh?= =?utf-8?q?MI7lJja95Z5b1iGDIzTeQ8yw4YepoTh4GC+tUAAeq53pArTxpuMMoN6VrZSQ16p5H?= =?utf-8?q?qgr8Ijr3wY9Gy87KpKlNEHpXbpejCuec6NIWn6cNSnOdltadKAGJ7iZnCRMXTmLtz?= =?utf-8?q?Wudx9FAoUDmzEbFWEPElv9jFusQFDVoOEnxetAQXkuGPlowbJVEfFqN53gTwkad2k?= =?utf-8?q?VRhaD66BLtBavoIlMe/E0Ri73/gASG5AcrKTGJtgPmVUmpMsonQ7bIKhWp89HGxBE?= =?utf-8?q?doWyUHeiObEl1st0/Gn//WwC7aDQKWf9edFfzbfmBvO1O0/XvKWXpyWg+1D+Q69AW?= =?utf-8?q?2su45JBNKsowPPWLixzSceqEgV4TJhIipKU8RGSx6SvKYnl1tJKMFLqGegiB4wyOj?= =?utf-8?q?H3YB3h5J8X6TGkCFoPQopHpHhIx+4PJdw=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b03540b-bd8a-40ac-9999-08d9ea5303fe X-MS-Exchange-CrossTenant-AuthSource: CH2PR13MB3702.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2022 16:00:52.2337 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rQ/IukVJQn9wmCrPU/ZRhRDG0ksQ7JNnOwHLwCKUkNE3ilyT1+xFeb4HIqakQLNdvBymhTbt1AhlXLqKULipQxAqHU8PcDpmOBPLHjE9jQE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR13MB3332 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net When reworking btf__get_from_id() in commit a19f93cfafdf the error handling when calling bpf_btf_get_fd_by_id() changed. Before the rework if bpf_btf_get_fd_by_id() failed the error would not be propagated to callers of btf__get_from_id(), after the rework it is. This lead to a change in behavior in print_key_value() that now prints an error when trying to lookup keys in maps with no btf available. Fix this by following the way used in dumping maps to allow to look up keys in no-btf maps, by which it decides whether and where to get the btf info according to the btf value type. Fixes: a19f93cfafdf ("libbpf: Add internal helper to load BTF data by FD") Signed-off-by: Yinjun Zhang Reviewed-by: Niklas Söderlund Signed-off-by: Simon Horman Acked-by: Jiri Olsa --- tools/bpf/bpftool/map.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index cc530a229812..4fc772d66e3a 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -1054,11 +1054,9 @@ static void print_key_value(struct bpf_map_info *info, void *key, json_writer_t *btf_wtr; struct btf *btf; - btf = btf__load_from_kernel_by_id(info->btf_id); - if (libbpf_get_error(btf)) { - p_err("failed to get btf"); + btf = get_map_kv_btf(info); + if (libbpf_get_error(btf)) return; - } if (json_output) { print_entry_json(info, key, value, btf);